Skip to content

feat(adf): auto-populate context modules from blast/surface/classify — reduce LM-agent cold-boot token cost #113

@stackbilt-admin

Description

@stackbilt-admin

Context

MCP-capable coding agents pay a fixed "cold-boot tax" every time they open a Charter-governed repo. A typical discovery sequence looks like:

  • ls, git log --oneline, git status
  • Read CLAUDE.md / README.md / top-level docs
  • grep for route handlers to understand the HTTP surface
  • Read package.json, wrangler.toml, tsconfig.json
  • Walk the import graph to identify load-bearing files
  • Re-derive module boundaries, sensitivity tags, and governance posture

In practice that's 15–30 tool calls and 10k–50k tokens of discovery before the agent produces anything useful — repeated across every session, every agent, every invocation.

Charter already emits most of the information an agent needs, via separate commands:

  • charter surface — routes, D1 schema, exported APIs
  • charter blast --summary — top hot files, cross-cutting warnings
  • .charter/config.json — repo identity (stack, preset) and sensitivity tags
  • charter adf populate — governance context (ADF module manifest)

The gap is that these are siloed — there's no single artifact an agent reads as its first action.

Proposal

Add charter context (CLI) and charter_brief (MCP tool) that compose surface, blast, config-file reads, and the ADF module manifest into a single pre-digested markdown brief.

Concrete moves

  1. charter context command in @stackbilt/cli — composes primitives in memory, emits markdown brief to stdout. Generators live alongside existing command adapters (no new package).
  2. On-disk mirror at .charter/context.md — same directory as existing generated artifacts like data-registry.yaml. Regenerated by post-commit hook; never hand-authored; .gitignored by charter init / charter bootstrap.
  3. charter_brief MCP tool in charter serve — re-runs extractions live (no on-disk dependency, always fresh). Name chosen to avoid collision with existing getProjectContext (which returns the full merged ADF bundle — different concept).
  4. Per-project-type canonical seed strategy for blast — derived from .charter/config.json stack/preset. Worker → routes + src/index.*; CLI → bin entries + command files; library → exported entry points.

Brief shape (sketch)

# <repo name> — repo brief (generated)

## Identity
<.charter/config.json: stack, preset; package.json: name, description, bin entries>

## Surface
<surface: N routes, M D1 tables, top 5 endpoints with methods>

## Hotspots
<blast: top 10 hot files, each with importers count, CROSS_CUTTING flag>

## Sensitivity
<.charter/config.json sensitivity tags: file pattern → class>

## Governance
<ADF module manifest: which modules are present, one-line descriptions>

## Generated
<git SHA, UTC timestamp>

Prerequisite

Blast Core-Out shipped in 0.11.0 (#110). classify is not a prerequisite — it's a change classifier (SURFACE/LOCAL/CROSS_CUTTING for commit descriptions), not a repo-identity primitive. Repo identity comes from .charter/config.json + package.json, which are already stable JSON formats.

Acceptance criteria

  • charter context prints a single pre-digested markdown brief to stdout.
  • Brief consumes Zod-validated surface + blast outputs (post-prereq refactor(surface,cli): Zod-Core-Out vertical slice for surface #114).
  • Per-project-type seed strategy for blast documented in charter context --help, keyed off .charter/config.json.
  • On-disk mirror at .charter/context.md; .gitignore updated automatically in charter init / charter bootstrap.
  • Post-commit hook recipe documented in CLI README.
  • charter serve registers charter_brief; tool handler re-runs primitives live (no stale-cache serving).
  • Brief size ≤2000 tokens for a repo with ≤300 source files.
  • CI enforcement: scripts/measure-brief-size.ts runs in CI and fails the workflow if Charter's self-generated brief exceeds the size threshold. Blocking, not advisory.
  • Measurable win: a fresh agent session can reach first useful action in ≤5 tool calls (brief read + targeted follow-ups), down from 15–30 a cold agent currently performs.

Non-goals

  • Auto-generating ADF modules (reverted per review). Writing to .ai/ collides with human-authored governance content. The brief is a separate artifact at .charter/context.md.
  • Cross-repo introduction — "manifests other repos consume programmatically." Separate post-1.0 RFC.
  • Replacing CLAUDE.md — stays authoritative for repo-specific rules; brief is a generated summary alongside.
  • Rewriting ADF — plumbing, not a new subsystem.
  • New package — generators live in @stackbilt/cli alongside existing command adapters (blast.ts, surface.ts). No @stackbilt/primitives layer.

Risks / tradeoffs

Sequencing

  1. Land refactor(surface,cli): Zod-Core-Out vertical slice for surface #114 (surface Core-Out prerequisite).
  2. Implement charter context + charter_brief MCP tool in @stackbilt/cli.
  3. Document post-commit hook recipe; update charter init / charter bootstrap to add .charter/context.md to .gitignore.
  4. Wire scripts/measure-brief-size.ts into CI.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesttype:featureNew capability or extension point

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions