Skip to content

feat(agent-sdk): context-bundle contract + token budgeter (F1)#35

Merged
officialCodeWork merged 1 commit into
developmentfrom
build/phase-5/step-5.2-context-bundle
Jul 15, 2026
Merged

feat(agent-sdk): context-bundle contract + token budgeter (F1)#35
officialCodeWork merged 1 commit into
developmentfrom
build/phase-5/step-5.2-context-bundle

Conversation

@officialCodeWork

Copy link
Copy Markdown
Owner

Step 5.2 — Context-bundle contract

Failure mode F1 (wrong-sized output blows the agent's context window). The ContextBundle is the budgeted payload resolveContext produces.

  • Sections: match (instances + evidence), lineage (per-instance data sources), journeys (slice around the match, depth 2), blastRadius / tests / history (empty until 5.3 / 5.4 / 5.6), and warnings (staleness, incomplete flags, trims).
  • Budgeter: a deterministic ~4-chars-per-token estimate; when over budgetTokens, sections are emptied in reverse priority (history → tests → journeys → blastRadius → lineage; match is never dropped, only reduced to top-1), and each trim is logged to warnings.
  • JSON Schema (schemas/context-bundle.schema.json) committed + drift-gated, mirroring the core schema setup.

CLI

$ ui-lineage bundle "the 'All users' page is broken" -b 4000
{ "status": "matched", "match": [{ "component": "UsersPage", … }], "journeys": [ … ],
  "budget": { "tokens": 4000, "used": 560 }, "warnings": [] }

Tests

  • agent-sdk: budget compliance at 2k/4k/8k, trim order, out-of-domain decline, schema drift gate.
  • parser-react: bundle over a real scanned graph (b3 fixture) — match/lineage/journeys populated, every bundle ≤ budget.

Verification

41 core + 14 agent-sdk + 3 vision + 107 parser tests pass; pnpm eval green; bundle has no leaked @coderadar imports.

🤖 Generated with Claude Code

New ContextBundle type + buildBundle (TRACKER step 5.2), bundled into ui-lineage:

- Sections: match (instances + evidence), lineage (per-instance data sources),
  journeys (slice around the match, depth 2), blastRadius / tests / history
  (empty until 5.3/5.4/5.6), and warnings (staleness, incomplete flags, trims).
- Budgeter: a deterministic ~4-chars-per-token estimate; when over budgetTokens,
  sections are emptied in reverse priority (history → tests → journeys →
  blastRadius → lineage; match reduced to top-1 last), each trim logged to
  warnings.
- JSON Schema (schemas/context-bundle.schema.json) committed + drift-gated,
  mirroring the core schema setup.

CLI `bundle <text> --budget N` emits the JSON bundle; lib re-exports
buildBundle/ContextBundle. Tests: agent-sdk budget compliance at 2k/4k/8k +
trim order + decline; parser-react integration over a real scanned graph.
41 core + 14 agent-sdk + 3 vision + 107 parser tests pass; eval green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@officialCodeWork
officialCodeWork merged commit c104d41 into development Jul 15, 2026
1 check passed
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.

2 participants