refactor(indexer,authz): split god-file, dedupe workspace-access checks#25
Merged
Merged
Conversation
- Split lib/indexer.ts (803 lines, 6 mixed concerns) into
lib/indexer/{constants,util,clone,scan,analyze,score,viz,index}.ts,
matching the directory-import convention already used by
lib/agents/, lib/codeintel/, lib/gitops/. Zero callsite changes.
Dropped an unused SymbolGraph type import found in the process.
- Added authz.requireWorkspace(), consolidating the repoAccessDenied()
+ getWorkspaceDir()-or-404 sequence that was hand-copied across 8
call sites in 4 route files (fs, git, search, timeline) — the same
copy-paste gap class that caused the Phase 0.6 cross-tenant leak.
Also removed fs/route.ts's workspaceOr404, a one-line no-op wrapper.
Verified: tsc --noEmit clean, full suite 265/265, next build clean,
lint baseline unchanged (pre-existing findings only, none in touched
files), and a live next dev smoke test — 404 "Repo not found"
preserved exactly on all 4 refactored routes, plus a real end-to-end
index of octocat/Hello-World through the split modules.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Scope
Targeted, audit-driven organizational refactor (not a rewrite) — see
docs/PROGRESS_TRACKER.md(2026-07-23 entry) for the full audit writeup.What changed
1. Split
lib/indexer.ts(803 lines, 6 mixed concerns) intolib/indexer/:constants.ts— scan constants (LANG_BY_EXT, CODE_EXTS, SKIP_DIRS, MAX_FILES)util.ts— event-loop yielding helperclone.ts— git clone / local-dir resolution / credential redactionscan.ts— file walk + import-graph resolutionanalyze.ts— rule-based issue detection, dependency/test hygiene, churnscore.ts— health-score modelviz.ts— viz graph / file tree / module graph buildersindex.ts— orchestrator (indexRepo,cleanup) + public re-exportsMatches the directory-import convention already used by
lib/agents/,lib/codeintel/,lib/gitops/. Zero callsite changes — all 4 existing importers (store.ts,agents/executor.ts,gitops/historicalAnalysis.ts,api/repos/[id]/git/route.ts) resolve unchanged. Also dropped an unusedSymbolGraphtype import found in the process.2. Added
authz.requireWorkspace(), deduping therepoAccessDenied()+getWorkspaceDir()-or-404 sequence that was hand-copied across 8 call sites in 4 route files (fs,git,search,timeline) — the same copy-paste-gap class that caused the Phase 0.6 cross-tenant leak documented in the tracker. Also removedfs/route.ts'sworkspaceOr404, a one-line no-op wrapper aroundgetWorkspaceDir.Why this scope
Audited the repo against its own established conventions rather than a generic template: no debug leftovers, no genuine circular deps (3
madgeflags all resolve toimport type-only edges, erased at compile time), no naming-consistency issues. Per the project's own god-file bar (indexer.ts's own rule flags >600 LOC as a maintainability issue), exactly one file crossed it — the one split here.api.ts(473) andsettings/page.tsx(582) stayed under that bar and were deliberately left alone.Verification
tsc --noEmit— cleanvitest run— 265/265 passingnext build— cleannpm run lint— baseline unchanged (pre-existing findings only, none in touched files)next devsmoke test: 404 "Repo not found" preserved exactly on all 4 refactored routes for a nonexistent/unowned repo id, then a real end-to-end index ofoctocat/Hello-Worldthrough the split indexer modules (health score computed correctly; fs/git/search all correctly gated throughrequireWorkspace).No behavior change intended or observed — pure move + dedup.