feat: context assembly + completeness gate — forge context (substrate-v2 P4)#29
Merged
CodeWithJuber merged 1 commit intoJul 7, 2026
Merged
Conversation
…-v2 P4)
'Incomplete context' fixed from the root
(docs/plans/substrate-v2/04-context-assembly.md): what enters the window
becomes a budgeted optimization, and sufficiency becomes a computed set.
- src/context.js: the required-knowledge set R(edit) is DERIVED — target
definitions, hop-1 dependents from the atlas, sibling tests, and team
lessons trusted past val >= 0.8 (an agent editing without them repeats a
mistake the ledger already paid for)
- selection: required coverage is pinned with a compression ladder
(full -> head -> pointer) — a tight budget downgrades granularity
instead of silently dropping coverage; optional items (trusted facts)
fill the rest greedily with per-source diminishing returns; items
resolving to the same file span are merged so nothing injects twice
- the gate: missing = R \ covered becomes derived clarifying questions
('the task names X but the repo doesn't define it — which file
implements it?'); forge substrate surfaces them, and FORGE_ENFORCE=1
turns them into a block — acting on missing context is acting on a guess
- forge context "<task>" [--budget N] [--json] CLI; exit 1 on incomplete
- deterministic end to end (same repo + task -> same bytes; tested)
295/295 tests (7 new), biome + tsc clean, smoke-tested live.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Fc2MvWJbQ1cyNQ76ymv4hs
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.
What & why
Phase P4 of the substrate-v2 plan (#24; P1 = #25/#26, P2 = #27, P3 = #28): the "incomplete context" fix — what enters the window becomes a budgeted optimization, and whether the context is sufficient becomes a computed set, not a feeling. Spec:
docs/plans/substrate-v2/04-context-assembly.md.R(edit)is derived (src/context.js): the target's definitions, its hop-1 dependents from the atlas (the callers you'd otherwise break blind), sibling tests, and team lessons trusted pastval ≥ 0.8— a lesson the ledger already paid for is required reading, not a nice-to-have.missing = R \ covered. Unresolvable entries become derived clarifying questions:"The task names \applyDiscountMatrix` but the repo doesn't define it — which file implements it (or is it new)?"` This upgrades M2: questions computed from a set difference instead of pattern-matched from lexical cues.forge substratesurfaces the assembly (context: COMPLETE — 3 required item(s), 69/6000 tokens) and its questions; underFORGE_ENFORCE=1an unassemblable context blocks the edit — acting on missing context is acting on a guess (the paper's 17:36 rule at the context layer).forge context "<task>" [--budget N] [--json]— prints the selection (item, granularity, tokens), the required/covered/missing sets, and exits 1 on incomplete (CI-friendly).Checklist
npm testpasses (295/295 — 7 new: derived R(edit) incl. the trust floor boundary, complete assembly, budget-squeeze downgrade preserving coverage, derived questions + enforced block, determinism)npm run checkpasses on changed filesrequiredSet,assemble,renderContext,tokensOf)feat:)CHANGELOG.mdupdated under## [Unreleased]04-context-assembly.md§1–§4 (candidates, knapsack + ladder, set-cover gate, substrate wiring)Risk & rollback
FORGE_ENFORCE=1with derived questions presentExtra checks (tick if applicable)
npm run typecheckpasses🤖 Generated with Claude Code
https://claude.ai/code/session_01Fc2MvWJbQ1cyNQ76ymv4hs
Generated by Claude Code