Skip to content

feat(substrate): implement M4 goal-anchoring — the one missing paper capability#12

Merged
CodeWithJuber merged 1 commit into
masterfrom
claude/forgekit-docs-restructure-httt92
Jul 6, 2026
Merged

feat(substrate): implement M4 goal-anchoring — the one missing paper capability#12
CodeWithJuber merged 1 commit into
masterfrom
claude/forgekit-docs-restructure-httt92

Conversation

@CodeWithJuber

Copy link
Copy Markdown
Owner

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. substrateCheck had 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.jsgoalDrift(root, goal) — a deterministic goal-drift check (the paper's "re-read the goal against in-progress work"):

  • Compares the stated objective against the files you've actually changed (git diff HEAD + untracked), splitting them on-goal vs off-goal.
  • Reuses 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.
  • Filters out forge's own generated footprint (.forge/, emitted tool configs, AGENTS/CLAUDE.md) so it flags your work, not forge's.
  • Coarse and advisory by design (path/keyword match, not semantic); the ceiling is named in a ponytail: comment.

Surfaced two ways:

  • forge anchor "<goal>" [--json] — standalone mid-session "am I still on track?" check.
  • Folded into 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):

$ forge anchor "harden verifyToken in src/auth.js"
  changed: 2 file(s) · on-goal 1 · off-goal 1
  off-goal (unrelated to the stated goal — intended, or drift?):
    - src/report.js

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, and CHANGELOG.md all updated.

Checklist

  • npm test passes — 151/151 (4 new test/anchor.test.js: off-goal flagged, on-goal quiet, no-diff quiet, pure-drift flagged)
  • npm run check passes (Biome lint + format; new files formatted)
  • New public function has a test (goalDrift)
  • Conventional commit message (feat:)
  • CHANGELOG.md updated under ## [Unreleased]
  • No new runtime dependency (zero-dep: node:child_process + existing modules)
  • Substrate/docs updated (this changes forge substrate output + adds forge anchor)

Risk & rollback

  • Risk level: low — additive; the new field is quiet unless there's a git diff that drifts, and it's advisory (never blocks, never fails the process). No existing behavior changed.
  • Rollback plan: revert this commit; forge anchor and result.goalAnchor disappear, nothing else depends on them.

Extra checks (tick if applicable)

  • npm run typecheck passes (JSDoc-typed the injectable changed seam)
  • Input validated at boundaries; errors handled (git calls are try/caught → empty)
  • Logs contain no secrets/PII

🤖 Generated with Claude Code

https://claude.ai/code/session_01Eh3SNx15EeVbTmU4nH36XC


Generated by Claude Code

…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
CodeWithJuber marked this pull request as ready for review July 6, 2026 02:52
@CodeWithJuber
CodeWithJuber merged commit 0aefa45 into master Jul 6, 2026
7 checks 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