feat(substrate): opt-in, verified LLM adjudication across the cognitive substrate#14
Merged
CodeWithJuber merged 1 commit intoJul 6, 2026
Conversation
…ve substrate Move the substrate's lexical judgments beyond static rules/regex with a thin, opt-in LLM layer that is never trusted blindly. One shared fail-safe primitive (src/adjudicate.js: a `claude -p` proposer, injectable runner, secret-refusing) is wired into every faculty; the model only PROPOSES and a per-faculty reconcile verifies each proposal against the deterministic rubric, the code graph, or a grep before it can move a verdict — the paper's tabayyun gate. - M2 assumption gate (preflight.js): LLM completeness/questions, bounded ±band by the rubric; the gate only ever tightens, questions must be grounded. - M1 routing (route.js): LLM complexity band is raise-only (max with rubric), so it never under-provisions on the model's word. - Impact/atlas (atlas.js): LLM proposes the coupled edges the regex misses; kept only if the file is real AND a grep confirms the reference. - M4 goal-drift (anchor.js): rescues an off-goal file off->on only, and only with a goal-referencing reason. - Memory (lessons.js): explicit `val` term — retrieval is now relevance x freshness x validity x scope; outcome-confirmed lessons rank first. - Orchestrator (substrate.js): threads an `llm` option + per-faculty `llm.provenance`, adds a `guarantees.llmVerified` bucket. Ambient hook stays deterministic unless FORGE_LLM_AMBIENT=1. Off by default (FORGE_LLM=1 to enable) — behaviour is byte-identical with the flag off. Zero new runtime dependency; any failure falls back to the deterministic path and never blocks. Cortex distiller now shares the primitive. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HGZUYFdUb4EViXV5tRid19
CodeWithJuber
marked this pull request as ready for review
July 6, 2026 04:53
11 tasks
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 substrate's "logic algorithm" (the M1–M6 mechanisms + faculties in the white paper) was implemented almost entirely with static regex term-lists, keyword/stop sets, and hand-tuned weights — the module headers themselves flag these as temporary "SEAMS." This PR moves those lexical judgments beyond regex with a thin, opt-in LLM layer that is never trusted blindly, honoring the paper's load-bearing principle (Panickssery et al. C12; tabayyun, 49:6): the model may propose, but an external check arbitrates — an LLM is never its own judge.
One shared fail-safe primitive —
src/adjudicate.js(aclaude -pproposer with an injectable runner and secret refusal) — is wired thinly into every faculty. Each faculty keeps its deterministic rubric as the judge and adds a small*LLMproposer + areconcilestep:preflight.js) — LLM completeness/questions, bounded ±band by the rubric (can't flip a clearly-specified/vague task); the gate only ever tightens; extra questions must be grounded in a flagged dimension or a real repo entity.route.js) — LLM complexity band is raise-only (maxwith the rubric), so it never under-provisions on the model's word; escalation still gates on a verified failure.atlas.js) — LLM proposes the coupled edges the regex misses (dynamic dispatch, DI, reflection); a candidate is kept only if the file is real AND a grep confirms the reference, taggedsource:"llm-verified".anchor.js) — rescues an off-goal file off→on only, and only with a goal-referencing reason (preserves the "errs toward on-goal" invariant).valterm (lessons.js) — retrieval is now the paper'srelevance × freshness × validity × scope;validity()is a ground-truth Beta posterior so outcome-confirmed lessons rank above merely-recent ones.substrate.js) — threads anllmoption, exposes per-facultyllm.provenance(deterministic/llm-verified/llm-agreed) in--json, and adds aguarantees.llmVerifiedbucket.Off by default (
FORGE_LLM=1to enable;FORGE_LLM_AMBIENT=1for the Claude Code hook, which stays deterministic otherwise). Behaviour is byte-identical with the flag off, any failure falls back to the deterministic path, and it never blocks. Zero new runtime dependency — access is a CLI shell-out. The Cortex distiller now shares the same primitive.Checklist
npm testpasses (Node 18/20/22) — 180 tests pass (151 baseline + 29 new)npm run checkpasses (Biome lint + format) — clean on all changed filesfeat:/fix:/docs:…)CHANGELOG.mdupdated under## [Unreleased]forge substrate,forge impact, router/gate, or MCP substrate toolsRisk & rollback
FORGE_LLMunset (feature is inert). No schema/data migrations.Extra checks (tick if applicable)
npm run typecheckpassesadjudicatecatches all failures →nullSECRET_REVerification
forge substrate "make the auth better"(default) → deterministic, unchanged.FORGE_LLM=1 forge substrate "..." --json→ model consulted;routereturned a verified raise, other faculties fell back safely; the gate correctly stayedASK FIRST.🤖 Generated with Claude Code
https://claude.ai/code/session_01HGZUYFdUb4EViXV5tRid19
Generated by Claude Code