Repository navigation
fix(cli): derive config from the target dir/--db instead of a cwd-pinned singleton - #2338
Merged
Merged
Conversation
…ned singleton (#2137) ctx.config was a process-wide singleton, lazily resolved exactly once from process.cwd(), regardless of any dir positional or --db flag a command received. This silently ignored the target project's own .codegraphrc.json for `embed`'s embeddings.provider/model (the whole v3.16.0 remote embedding feature did nothing when invoked from elsewhere), coChange tuning, and query.excludeTests across every command using resolveNoTests()/resolveQueryOpts() (~38 call sites) — returning different rows, not just different formatting. audit.ts and complexity.ts additionally passed the stale ctx.config straight through, short-circuiting the already-correct resolveDbConfig(customDbPath) fallback at the feature layer added for issues #1881/#2017. Fix: embed.ts, co-change.ts, and resolveNoTests() in src/cli/shared/options.ts now call resolveDbConfig(opts.db, or the resolved [dir] positional for embed) directly, matching the pattern already established for read-only queries. audit.ts/complexity.ts drop their config pass-through so the feature layer's own fallback runs. check.ts's already-dead config pass-through is removed too, since it was a loaded gun for the same regression. models.ts is left on the cwd singleton — it has no target directory to derive from. No README/CLAUDE.md/ROADMAP.md changes — internal CLI config-resolution plumbing, no new commands, flags, or architecture. docs check acknowledged. Impact: 13 functions changed, 0 affected
Contributor
Greptile SummaryThe PR replaces cwd-pinned CLI configuration reads with configuration derived from each command’s target directory or database path.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart LR
CLI["CLI command"] --> Target{"Target supplied?"}
Target -->|"--db"| DB["Database path"]
Target -->|"positional dir"| Dir["Project directory"]
Target -->|"neither"| CWD["process.cwd()"]
DB --> Resolve["resolveDbConfig"]
Dir --> Resolve
CWD --> Resolve
Resolve --> Config["Target-specific layered config"]
Config --> Query["Query test filtering"]
Config --> CoChange["Co-change settings"]
Config --> Embed["Embedding provider/model"]
DB --> Feature["Audit / complexity / check feature fallback"]
Feature --> Resolve
Reviews (2): Last reviewed commit: "Merge branch 'main' into fix/issue-2137-..." | Re-trigger Greptile |
Contributor
Codegraph Impact Analysis13 functions changed → 2 callers affected across 2 files
|
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Summary
Closes #2137
ctx.config(src/cli/shared/options.ts) is a process-wide singleton, lazily resolved exactly once fromprocess.cwd(), regardless of anydirpositional argument or--db <path>flag a specific command receives. This meant a command invoked from a different cwd than its target project (or with an explicit--dbpointing elsewhere) silently read the wrong project's.codegraphrc.json(or none at all).Confirmed impact:
embed'sembeddings.provider/embeddings.model(validate + execute) — the entire v3.16.0 remote embedding provider feature silently did nothing whencodegraph embedwas invoked from outside the target project's directory, falling back to a local HuggingFace model instead of erroring or using the configured remote endpoint.resolveNoTests()/resolveQueryOpts()— used viactx.resolveNoTests/ctx.resolveQueryOptsacross ~38 commands — readquery.excludeTestsfrom the same stale singleton. This changes which rows a query returns, not just display formatting.co-change --analyze'scoChange.*tuning fields (since/minSupport/minJaccard/maxFilesPerCommit/execMaxBufferBytes).auditandcomplexityadditionally passed the stalectx.configstraight through to the feature layer, short-circuiting the already-correctresolveDbConfig(customDbPath)fallback added for loadConfig() resolves from process.cwd() instead of the resolved --db path in several read-only query functions #1881/loadConfig() still resolves from process.cwd() in triageData, sequenceData, communitiesData, briefData, statsData, searchData/multiSearchData, and resolveAnalysisOpts #2017 (opts.config || resolveDbConfig(customDbPath)— the truthy CLI value always won).Fix
resolveNoTests()insrc/cli/shared/options.tsnow callsresolveDbConfig(opts.db)directly instead of reading the singleton — a single-file change that covers all ~38 call sites with no call-site changes needed, sinceoptsis already threaded through everywhere.embed.tsderives config viaresolveDbConfig(opts.db ?? root)in bothvalidate()andexecute(), whererootis the resolved[dir]positional.co-change.tsderivescoChange.*viaresolveDbConfig(opts.db).audit.ts/complexity.tsstop passingconfig/config: ctx.configto the feature layer, letting the existingresolveDbConfig(customDbPath)fallback (loadConfig() resolves from process.cwd() instead of the resolved --db path in several read-only query functions #1881/loadConfig() still resolves from process.cwd() in triageData, sequenceData, communitiesData, briefData, statsData, searchData/multiSearchData, and resolveAnalysisOpts #2017) do its job.check.ts's already-deadconfigpass-through (the value was already being dropped downstream) is removed too — it was a loaded gun for reintroducing this exact bug if anyone ever forwarded it.models.tsis intentionally left on theprocess.cwd()singleton — it has nodir/--dbtarget to derive config from.Test plan
tests/unit/cli-shared-options-config-resolution.test.ts:resolveNoTests()readsquery.excludeTestsfrom theopts.dbproject's config (notprocess.cwd()), falls back to cwd config when noopts.dbis given, and CLI flag precedence (--no-tests/--include-tests) still wins.tests/unit/embed-command.test.tsto mockresolveDbConfiginstead of a fakectx.config, covering the same validate()/execute() scenarios as before plus the new resolution path.npm testsuite passes (4593 tests).npx tsc --noEmitclean.npm run lintclean.