feat(substrate): implement M4 goal-anchoring — the one missing paper capability#12
Merged
Merged
Conversation
…capability The docs mapped "M4 goal-anchoring -> substrate" but no goal-drift logic existed. Of the paper's 11 capabilities, this was the only one that was documented but never built; the other 10 already ship a real mechanism. - src/anchor.js: goalDrift(root, goal) — a deterministic goal-drift check. Re-reads the stated objective against files actually changed (git diff HEAD + untracked, minus forge's own generated config) and splits them on-goal vs off-goal. Reuses referencedEntities + the atlas (a symbol-named goal anchors to the file its symbol lives in). Coarse/advisory by design, ceiling named. - forge anchor "<goal>" [--json] CLI command. - Folded into forge substrate (result.goalAnchor): quiet on a clean tree, speaks mid-session when work wandered off-goal — render + ambient advisory. - test/anchor.test.js: 4 tests (off-goal flagged, on-goal quiet, no-diff quiet, pure-drift flagged). Full suite 151/151; typecheck + biome check clean. - Docs made honest: the 11-point mapping now points M4 at `anchor`; README command list, GUIDE (worked example + workflow), and CHANGELOG updated. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Eh3SNx15EeVbTmU4nH36XC
CodeWithJuber
marked this pull request as ready for review
July 6, 2026 02:52
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
The white paper defines 11 capabilities (5 faculties + 6 mechanisms). Auditing forge against them, ten already ship a real mechanism — but M4 goal-anchoring was documented (
docs → "M4 goal-anchoring → substrate") yet never implemented.substrateCheckhad zero drift logic. This PR builds it, so all 11 now map to something real. Done with a ponytail discipline — smallest correct thing, reuse what's here, keep the rest untouched.New:
src/anchor.js→goalDrift(root, goal)— a deterministic goal-drift check (the paper's "re-read the goal against in-progress work"):git diff HEAD+ untracked), splitting them on-goal vs off-goal.referencedEntities(goal keywords/symbols/files) and the atlas — a symbol-named goal (change verifyToken) anchors to the file its symbol lives in (src/auth.js), which name-matching alone would miss..forge/, emitted tool configs,AGENTS/CLAUDE.md) so it flags your work, not forge's.ponytail:comment.Surfaced two ways:
forge anchor "<goal>" [--json]— standalone mid-session "am I still on track?" check.forge substrate(result.goalAnchor): quiet on a clean tree, speaks only once a diff has drifted — in both the full render and the ambient Claude-Code advisory.Live example (two files changed, goal names one):
Docs made honest: the 11-point mapping now points M4 at
anchor; README command list,docs/GUIDE.md(worked example + everyday-workflow step), the substrate README checks table, andCHANGELOG.mdall updated.Checklist
npm testpasses — 151/151 (4 newtest/anchor.test.js: off-goal flagged, on-goal quiet, no-diff quiet, pure-drift flagged)npm run checkpasses (Biome lint + format; new files formatted)goalDrift)feat:)CHANGELOG.mdupdated under## [Unreleased]node:child_process+ existing modules)forge substrateoutput + addsforge anchor)Risk & rollback
forge anchorandresult.goalAnchordisappear, nothing else depends on them.Extra checks (tick if applicable)
npm run typecheckpasses (JSDoc-typed the injectablechangedseam)🤖 Generated with Claude Code
https://claude.ai/code/session_01Eh3SNx15EeVbTmU4nH36XC
Generated by Claude Code