Skip to content

fix(cli): register the documented context command (#1611) - #1613

Merged
colbymchenry merged 2 commits into
mainfrom
fix/1611-register-context-command
Aug 26, 2026
Merged

fix(cli): register the documented context command (#1611)#1613
colbymchenry merged 2 commits into
mainfrom
fix/1611-register-context-command

Conversation

@colbymchenry

Copy link
Copy Markdown
Owner

Fixes #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.ai/code/session_01LxZj6W6Y1SHXwvpT3uwJpK

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
@colbymchenry
colbymchenry merged commit c382225 into main Aug 26, 2026
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)
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.

Missing 'context' CLI command breaks Memorix 1.8.1 integration (Context Builder exists in package but is not registered)

1 participant