Skip to content

feat: charter context command + charter_brief MCP tool (closes #113)#153

Merged
stackbilt-admin merged 3 commits into
mainfrom
codex/charter-context-brief
May 19, 2026
Merged

feat: charter context command + charter_brief MCP tool (closes #113)#153
stackbilt-admin merged 3 commits into
mainfrom
codex/charter-context-brief

Conversation

@stackbilt-admin
Copy link
Copy Markdown
Member

Summary

  • Adds charter context CLI command that generates a pre-digested repo brief (identity, surface, hotspots, sensitivity, governance) within a 2,000-token budget
  • Registers charter_brief as an MCP tool in charter serve — replaces 15–30 cold-boot discovery tool calls when AI agents enter a Charter-governed repo
  • Two new CI gates enforce the token budget and orientation coverage on every build

What's in the brief

Section Source
Identity git SHA, preset, project name
Surface route count by method, auth coverage
Hotspots blast top-N files by fan-in
Sensitivity ON_DEMAND ADF modules
Governance drift score, pattern count, security-sensitive flag

Key design decisions

  • Build-then-render patternBriefModel struct assembled first, then sections rendered and truncated to fit the 8,000-char (≈2,000 token) ceiling
  • Preset-aware blast seedsworker → src/index.*, frontend → src/App.*, backend → src/main.*, fullstack → both
  • Truncation order — hotspots tail first → D1 table rows → route rows → ON_DEMAND list; appends ## Truncated marker so agents know
  • --verbose skips ceiling — for human review; --stdout-only and --write control output destination

Test plan

  • 444 tests pass (pnpm run test)
  • packages/cli/src/__tests__/context.test.ts — 3 new tests: all 5 sections present, token ceiling respected, --write creates .charter/context.md
  • Run node packages/cli/dist/bin.js context --format json in this repo and confirm output
  • Verify scripts/measure-brief-size.mjs exits 0
  • Verify scripts/eval-brief-coverage.mjs exits 0

🤖 Generated with Claude Code

Kurt Overmier and others added 3 commits May 19, 2026 06:31
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>
@stackbilt-admin stackbilt-admin merged commit 0d3c980 into main May 19, 2026
1 of 3 checks passed
@stackbilt-admin stackbilt-admin deleted the codex/charter-context-brief branch May 19, 2026 12:14
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.

1 participant