feat: charter context command + charter_brief MCP tool (closes #113)#153
Merged
Conversation
Adds `charter context` CLI command and `charter_brief` MCP tool. Generates a pre-digested repo brief (identity, surface, hotspots, sensitivity, governance) within a 2000-token budget — replacing 15-30 cold-boot discovery tool calls for AI agents entering a Charter-governed repo. - `packages/cli/src/commands/context.ts`: BriefModel build-then-render pattern, blast seed strategy by preset, truncation algorithm (hotspots→tables→routes→ON_DEMAND), --stdout-only / --verbose / --write flags - `packages/cli/src/commands/serve.ts`: registers `charter_brief` MCP tool - `packages/cli/src/commands/init.ts`: adds `context.md` to .charter/.gitignore - `packages/cli/src/commands/bootstrap.ts`: post-commit hook next-step for refresh - `packages/cli/src/__tests__/context.test.ts`: 3 tests (sections, token ceiling, --write) - `scripts/measure-brief-size.mjs`: CI gate — fails if brief > 2000 tokens - `scripts/eval-brief-coverage.mjs`: CI gate — fixture-based orientation coverage eval - `.github/workflows/ci.yml`: adds both CI gates after build step - `docs/cli-reference.md`: full charter context reference section - `README.md`: charter context quick-start and charter_brief MCP mention Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Remove dead `assert` import from eval-brief-coverage.mjs - Fix misleading "fixture" comment (script runs live against local repo) - Add mutual-exclusion guard: --stdout-only + --write now exits RUNTIME_ERROR with a clear message instead of silently doing nothing - Add Step 5 hard-slice fallback in truncation loop to guarantee brief never exceeds CHAR_CEILING regardless of ON_DEMAND trigger list length Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
Summary
charter contextCLI command that generates a pre-digested repo brief (identity, surface, hotspots, sensitivity, governance) within a 2,000-token budgetcharter_briefas an MCP tool incharter serve— replaces 15–30 cold-boot discovery tool calls when AI agents enter a Charter-governed repoWhat's in the brief
Key design decisions
BriefModelstruct assembled first, then sections rendered and truncated to fit the 8,000-char (≈2,000 token) ceilingworker → src/index.*,frontend → src/App.*,backend → src/main.*,fullstack → both## Truncatedmarker so agents know--verboseskips ceiling — for human review;--stdout-onlyand--writecontrol output destinationTest plan
pnpm run test)packages/cli/src/__tests__/context.test.ts— 3 new tests: all 5 sections present, token ceiling respected,--writecreates.charter/context.mdnode packages/cli/dist/bin.js context --format jsonin this repo and confirm outputscripts/measure-brief-size.mjsexits 0scripts/eval-brief-coverage.mjsexits 0🤖 Generated with Claude Code