Skip to content

feat(substrate): enforcement & stewardship — opt-in gate, dotfile learn-loop, verify timeout (Tranche C)#19

Merged
CodeWithJuber merged 1 commit into
masterfrom
claude/logic-algorithm-implementation-c09485
Jul 6, 2026
Merged

feat(substrate): enforcement & stewardship — opt-in gate, dotfile learn-loop, verify timeout (Tranche C)#19
CodeWithJuber merged 1 commit into
masterfrom
claude/logic-algorithm-implementation-c09485

Conversation

@CodeWithJuber

Copy link
Copy Markdown
Owner

What & why

Tranche C — the paper's mandatory-gate spine (Eq 5 / M2 "halt on insufficient input"), made
real but opt-in, plus two enforcement/stewardship fixes.

Opt-in enforcing gate (FORGE_ENFORCE=1)

The assumption gate has always been advisory ("never blocks"). This adds an opt-in mode where it
can halt: on the Claude Code ambient path it blocks a prompt with no concrete anchor at all
("fix it", "make it better") — or an action into a very large predicted blast radius — and
returns the clarifying questions via a UserPromptSubmit block decision. Low-false-positive by
design
: a specified task is never blocked. Off by default — behaviour is unchanged unless you
set the flag. enforceDecision() in src/substrate.js.

Reconciled the two hook manifests (the dead learn-loop bug)

global/settings.template.json (the dotfile install) wired only cortex.sh preflight — 1 of 6
modes — so those users got the substrate advisory but never captured events or distilled
lessons
: the entire Cortex learning loop was dead for them, while plugin users had it. The
template now wires all six modes (session-start, prompt, preflight, pre-edit, capture,
stop), matching hooks/hooks.json.

forge verify can't hang

runTests now bounds the test run with a timeout (FORGE_VERIFY_TIMEOUT_MS, default 10 min); a
timeout is reported honestly as "did not complete", never as a pass.

On reversibility (auto git-snapshot) — deliberately deferred

I assessed the "stage/rollback before a flagged edit" limb and chose not to auto-run git inside a
hook
— auto git operations are too risky to enable by default and can interfere with the user's
own workflow. The enforcing gate + the existing protect-paths guard cover the safety limb without
it; a forge snapshot-style explicit command is a cleaner future home if wanted.

Checklist

  • npm test passes (Node 18/20/22) — 218 tests (+3)
  • npm run check passes (Biome lint + format)
  • New public function has tests (enforceDecision: off / vacuous / specified / blast)
  • Conventional commit message (feat:)
  • CHANGELOG.md updated under ## [Unreleased]
  • No new runtime dependency
  • Substrate/docs updated (FORGE_ENFORCE, FORGE_VERIFY_TIMEOUT_MS in GUIDE)

Risk & rollback

  • Risk level: low — the gate is off by default and low-false-positive when on; the manifest
    change only adds the same hooks the plugin already runs; the verify timeout only bounds a hang.
  • Rollback plan: revert the commit; leave FORGE_ENFORCE unset (feature inert).

Extra checks

  • npm run typecheck passes
  • settings.template.json validated as JSON; all 6 cortex modes confirmed wired
  • Logs contain no secrets/PII

Verification

Full suite + typecheck + Biome green. enforceDecision unit tests cover: off-by-default never
blocks; enforcing blocks a hard-underspecified prompt and a >threshold blast radius; a specified
task is never blocked. Manual: the reconciled template parses and now lists all six cortex.sh
modes.

Next: Tranche D (DX & evidence — uniform --json, broader doctor, guard hardening, model_tiers,
eval harness).

🤖 Generated with Claude Code

https://claude.ai/code/session_01HGZUYFdUb4EViXV5tRid19


Generated by Claude Code

…rn-loop, verify timeout (Tranche C)

Realizes the paper's mandatory-gate spine (Eq 5 / M2 "halt on insufficient
input") as an opt-in, and fixes two enforcement/stewardship gaps.

- Opt-in enforcing gate (FORGE_ENFORCE=1): the assumption gate can now BLOCK, not
  just advise. On the ambient path it halts a prompt with no concrete anchor
  ("fix it") or an action into a very large predicted blast radius, returning the
  clarifying questions. Low-false-positive by design (a specified task is never
  blocked) and OFF by default. enforceDecision() in src/substrate.js; wired into
  the preflight hook via a UserPromptSubmit block decision.
- Reconciled the two hook manifests: global/settings.template.json wired only
  cortex.sh preflight (1 of 6 modes), so the dotfile install captured no events
  and distilled no lessons — the learn loop was dead for those users. It now wires
  all six modes (session-start/prompt/preflight/pre-edit/capture/stop) to match
  hooks/hooks.json.
- forge verify can't hang: runTests is bounded by FORGE_VERIFY_TIMEOUT_MS
  (default 10 min); a timeout is reported honestly, never as a pass.

Reversibility-via-auto-git-snapshot was assessed and deferred: auto git operations
inside a hook are too risky to enable by default; the enforcing gate + protect-paths
guard cover the safety limb without it.

218 tests pass (+3), typecheck + Biome clean, zero new runtime deps.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HGZUYFdUb4EViXV5tRid19
@CodeWithJuber CodeWithJuber marked this pull request as ready for review July 6, 2026 08:10
@CodeWithJuber CodeWithJuber merged commit 5faf7ad 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