Skip to content

fix(cli): derive config from the target dir/--db instead of a cwd-pinned singleton - #2338

Merged
carlos-alm merged 2 commits into
mainfrom
fix/issue-2137-shared-ctx-config
Aug 7, 2026
Merged

carlos-alm merged 2 commits into
mainfrom
fix/issue-2137-shared-ctx-config

Conversation

@carlos-alm

Copy link
Copy Markdown
Contributor

Summary

Closes #2137

ctx.config (src/cli/shared/options.ts) is a process-wide singleton, lazily resolved exactly once from process.cwd(), regardless of any dir positional 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 --db pointing elsewhere) silently read the wrong project's .codegraphrc.json (or none at all).

Confirmed impact:

Fix

Test plan

  • New tests/unit/cli-shared-options-config-resolution.test.ts: resolveNoTests() reads query.excludeTests from the opts.db project's config (not process.cwd()), falls back to cwd config when no opts.db is given, and CLI flag precedence (--no-tests/--include-tests) still wins.
  • Updated tests/unit/embed-command.test.ts to mock resolveDbConfig instead of a fake ctx.config, covering the same validate()/execute() scenarios as before plus the new resolution path.
  • Full npm test suite passes (4593 tests).
  • npx tsc --noEmit clean.
  • npm run lint clean.

…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
@greptile-apps

greptile-apps Bot commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR replaces cwd-pinned CLI configuration reads with configuration derived from each command’s target directory or database path.

  • Resolves query test filtering and co-change settings against --db.
  • Resolves embedding provider and model settings against --db or the positional project directory.
  • Allows audit, complexity, and check feature-layer fallbacks to derive their own target-specific configuration.
  • Adds and updates regression coverage for target-project configuration resolution.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
src/cli/shared/options.ts Query test filtering now resolves configuration from the supplied database target while preserving CLI flag precedence.
src/cli/commands/embed.ts Validation and execution now use the target project’s embedding and LLM configuration consistently.
src/cli/commands/co-change.ts Co-change defaults now come from configuration associated with the selected database.
src/cli/commands/audit.ts Removes the stale CLI config override so the feature layer can resolve configuration from the custom database path.
src/cli/commands/complexity.ts Removes the cwd-derived config override and restores the existing target-aware feature fallback.
src/cli/commands/check.ts Removes an unused config pass-through without changing the downstream configuration resolution path.
tests/unit/cli-shared-options-config-resolution.test.ts Adds regression coverage for database-targeted config lookup, cwd fallback, and query flag precedence.
tests/unit/embed-command.test.ts Updates embedding command tests to exercise the new target-derived configuration dependency.
tests/unit/withrepo-config-resolution.test.ts Updates terminology to match the current database configuration resolver.

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
Loading

Reviews (2): Last reviewed commit: "Merge branch 'main' into fix/issue-2137-..." | Re-trigger Greptile

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Codegraph Impact Analysis

13 functions changed → 2 callers affected across 2 files

  • command.execute in src/cli/commands/audit.ts:29 (0 transitive callers)
  • execute in src/cli/commands/audit.ts:29 (0 transitive callers)
  • command.execute in src/cli/commands/check.ts:47 (0 transitive callers)
  • execute in src/cli/commands/check.ts:47 (0 transitive callers)
  • command.execute in src/cli/commands/co-change.ts:23 (0 transitive callers)
  • execute in src/cli/commands/co-change.ts:23 (0 transitive callers)
  • command.execute in src/cli/commands/complexity.ts:31 (0 transitive callers)
  • execute in src/cli/commands/complexity.ts:31 (0 transitive callers)
  • command.validate in src/cli/commands/embed.ts:52 (0 transitive callers)
  • validate in src/cli/commands/embed.ts:52 (0 transitive callers)
  • command.execute in src/cli/commands/embed.ts:77 (0 transitive callers)
  • execute in src/cli/commands/embed.ts:77 (0 transitive callers)
  • resolveNoTests in src/cli/shared/options.ts:51 (2 transitive callers)

@carlos-alm
carlos-alm merged commit 7b71986 into main Aug 7, 2026
23 checks passed
@carlos-alm
carlos-alm deleted the fix/issue-2137-shared-ctx-config branch August 7, 2026 23:53
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 7, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: CLI's shared ctx.config is resolved once from process.cwd(), ignoring the target dir/--db path for every command

1 participant