Skip to content

refactor: route repo-root resolution through shared helper (57 files)#86

Merged
NagyVikt merged 1 commit into
mainfrom
improve/lazy-repo-sweep
Jun 29, 2026
Merged

refactor: route repo-root resolution through shared helper (57 files)#86
NagyVikt merged 1 commit into
mainfrom
improve/lazy-repo-sweep

Conversation

@NagyVikt

Copy link
Copy Markdown
Contributor

Summary

Mechanical sweep following #84. 57 modules each duplicated the same baked const REPO_ROOT = process.env.CUE_REPO_ROOT ?? SOUL_REPO_ROOT ?? resolve(<import.meta>) plus derived consts. Each now imports the shared lazy repoRoot() from src/lib/repo-root.ts (added in #84). Net −72 LOC — kills 57 copies of the env-read in favor of one source of truth.

Transform (codemod, then verified)

  • Delete the per-file bake; REPO_ROOTrepoRoot() (derived consts become join(repoRoot(), …) — same eager eval timing as before, zero behavior change).
  • Clean now-unused node:path/node:url imports.
  • Collision aliasing: 3 files already declared a local lowercase repoRoot (different identifier) → import aliased to cueRepoRoot there (profile-linter.ts, skill-quality.ts, profile-generator.ts).
  • score.ts: its REPO_ROOT was dead code — removed entirely.

Correctness (why it's safe)

  • repoRoot()'s fallback is anchored to repo-root.ts's own location → always the canonical repo root, independent of caller depth. Verified equivalent even for the depth-1 src/index.ts (old resolve(HERE,"..") from src/ = repo root; new = repo root).
  • Token replace was /\bREPO_ROOT\b/g — independent review confirmed zero string/comment contamination.

Excluded (intentional)

status.ts + skill-dependencies.ts (fleet actively editing — avoids conflicts), launch.ts (inline reads, fleet-touched), dashboard-server.ts (env-free, location-locked by design). ~15 other non-matching-pattern files remain for a future pass.

Verification

typecheck exit 0 · biome lint exit 0 (10 pre-existing warnings, 0 errors) · full suite 1360 pass / 0 fail. Independent review: DONE, no CRITICAL/HIGH, no blockers.

Sweep follow-up to #84. 57 modules each baked an identical
`const REPO_ROOT = process.env.CUE_REPO_ROOT ?? SOUL_REPO_ROOT ?? resolve(<import.meta>)`
plus derived `const SKILLS_ROOT/PROFILES_DIR/...` off it. Replace each with the
shared lazy repoRoot() from src/lib/repo-root.ts (added in #84).

Behavior-preserving: repoRoot() returns the same value the bake would, and its
fallback is the canonical repo root regardless of caller location. Derived consts
become join(repoRoot(), ...) — eager, same as before; the #84 hot modules remain
fully lazy. Net -72 LOC (kills 57 duplicated env-reads → one source of truth).

Three files already declared a local `repoRoot` (different identifier); the
import is aliased to cueRepoRoot there. score.ts's REPO_ROOT was dead code and
is dropped. Excluded: status.ts + skill-dependencies.ts (fleet is editing them),
launch.ts (inline reads, fleet-touched), dashboard-server.ts (env-free by design).

typecheck + biome lint clean; full suite 1360 pass, 0 fail.
@NagyVikt NagyVikt merged commit 96c1080 into main Jun 29, 2026
4 checks passed
@NagyVikt NagyVikt deleted the improve/lazy-repo-sweep branch June 29, 2026 09:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant