fix(cli): register the documented context command (#1611) - #1613
Merged
Conversation
The usage header has advertised 'codegraph context <task> Build context for a task' since the first commit, and the ContextBuilder behind the public buildContext API has always shipped in the package — but the command was never registered with commander, so it errored with "unknown command 'context'". External integrations built against the documented contract (Memorix 1.8.1 invokes 'codegraph context --path <root> --format json --max-nodes 8 --no-code <task>') silently fell back to their own heuristics. Register 'context <task...>' next to the other read commands, mapping flags 1:1 onto BuildContextOptions: --path (resolved like every sibling command), --format markdown|json (validated, default markdown), --max-nodes (positive int, validated), --no-code (includeCode=false). JSON goes to stdout verbatim and unmixed — error()/warnings write to stderr — so the output is machine-parseable. Covered end-to-end against the built binary, including the exact Memorix invocation shape and the uninitialized-project failure path. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LxZj6W6Y1SHXwvpT3uwJpK
Goodhhw
pushed a commit
to Goodhhw/codegraph
that referenced
this pull request
Aug 29, 2026
… (colbymchenry#1613) Fixes colbymchenry#1611. ## What `codegraph context <task>` has been advertised in the CLI usage header since the first commit, and the ContextBuilder behind the public `buildContext` API has always shipped in the package — but the command was never registered with commander (verified via `git log -S`: this is drift present from day one, not a removal). Invoking it errored with `unknown command 'context'`, which broke external integrations built against the documented contract — Memorix 1.8.1 invokes `codegraph context --path <project-root> --format json --max-nodes 8 --no-code <task>` and silently falls back to its own heuristic index when the command is missing. ## How Registers `context <task...>` next to the other read commands (`query`/`explore` pattern), mapping flags 1:1 onto `BuildContextOptions`: - `-p, --path <path>` — resolved exactly like every sibling command (nearest initialized project) - `-f, --format <format>` — `markdown` (default) or `json`, unknown values rejected with exit 1 - `-n, --max-nodes <number>` — positive integer, validated - `--no-code` — structure only (`includeCode: false`) JSON output is clean, machine-parseable stdout — `error()` and warnings go to stderr — and the uninitialized-project path matches the sibling commands' error text and exit code. The usage-header line needed no change; the registered syntax matches what it has always advertised. ## Tested New `__tests__/cli-context-command.test.ts` (modeled on `cli-query-command.test.ts`, spawning the built binary against a temp fixture): JSON parseability + shape, `--max-nodes` bounding, the exact Memorix invocation shape (`--format json --max-nodes 8 --no-code`), markdown default, uninitialized-project failure, unknown-format rejection. `npx vitest run __tests__/cli-context-command.test.ts __tests__/context.test.ts __tests__/context-ranking.test.ts __tests__/cli-query-command.test.ts` → 4 files, 39 tests, all green. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01LxZj6W6Y1SHXwvpT3uwJpK (cherry picked from commit c382225)
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.
Fixes #1611.
What
codegraph context <task>has been advertised in the CLI usage header since the first commit, and the ContextBuilder behind the publicbuildContextAPI has always shipped in the package — but the command was never registered with commander (verified viagit log -S: this is drift present from day one, not a removal). Invoking it errored withunknown command 'context', which broke external integrations built against the documented contract — Memorix 1.8.1 invokescodegraph context --path <project-root> --format json --max-nodes 8 --no-code <task>and silently falls back to its own heuristic index when the command is missing.How
Registers
context <task...>next to the other read commands (query/explorepattern), mapping flags 1:1 ontoBuildContextOptions:-p, --path <path>— resolved exactly like every sibling command (nearest initialized project)-f, --format <format>—markdown(default) orjson, unknown values rejected with exit 1-n, --max-nodes <number>— positive integer, validated--no-code— structure only (includeCode: false)JSON output is clean, machine-parseable stdout —
error()and warnings go to stderr — and the uninitialized-project path matches the sibling commands' error text and exit code. The usage-header line needed no change; the registered syntax matches what it has always advertised.Tested
New
__tests__/cli-context-command.test.ts(modeled oncli-query-command.test.ts, spawning the built binary against a temp fixture): JSON parseability + shape,--max-nodesbounding, the exact Memorix invocation shape (--format json --max-nodes 8 --no-code), markdown default, uninitialized-project failure, unknown-format rejection.npx vitest run __tests__/cli-context-command.test.ts __tests__/context.test.ts __tests__/context-ranking.test.ts __tests__/cli-query-command.test.ts→ 4 files, 39 tests, all green.🤖 Generated with Claude Code
https://claude.ai/code/session_01LxZj6W6Y1SHXwvpT3uwJpK