feat: Proof-Carrying Memory ledger core (substrate-v2 P1)#25
Merged
CodeWithJuber merged 1 commit intoJul 7, 2026
Merged
Conversation
The PCM protocol's keystone (ADR-0006, docs/plans/substrate-v2/01): - src/ledger.js — pure core: canonical JSON + content-addressed claim ids, oracle taxonomy (only independent signals move confidence), time-decayed Beta-posterior val (decays toward uncertainty, never false), Eq. 3 retrieval, zero-dep MinHash similarity + union-find clustering, and a join-semilattice merge property-tested for commutativity/associativity/ idempotence (teammate ledgers converge in any merge order) - src/ledger_store.js — git-native .forge/ledger/: one immutable file per claim (id-sharded), append-only hash-deduped evidence logs (union-merge safe via .gitattributes), tombstones, attic, LEDGER.md, normal-form verify - src/ledger_bridge.js — P1 migration seam: cortex shadow-writes lesson events (create/confirm/human-revert), forge remember + recall add shadow facts, forge ledger import back-fills legacy history idempotently - forge ledger stats|verify|show|import CLI - SECRET_RE moves to the ledger core (recall.js re-exports) so no claim kind can persist a credential Legacy stores remain the read path in P1; the read-path flip lands with P2 merge tooling. 253/253 tests (31 new), biome + tsc clean. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Fc2MvWJbQ1cyNQ76ymv4hs
CodeWithJuber
marked this pull request as ready for review
July 7, 2026 16:04
This was referenced Jul 7, 2026
Merged
Merged
Merged
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 P1 of the merged substrate-v2 plan (#24): the Proof-Carrying Memory (PCM) ledger — the keystone store every later phase (team sync, reuse cache, context assembly, dashboard) builds on. Spec:
docs/plans/substrate-v2/01-pcm-protocol.md, ADR-0006.src/ledger.js(pure core, no fs): canonical JSON with sorted keys/NFC → content-addressed claim ids (provenance and evidence excluded, so teammates who independently learn the same thing mint the same claim); an oracle taxonomy where only independent signals (tests, CI, human accept/revert) may move confidence;val= time-decayed Beta posterior that decays toward uncertainty (0.5), never toward false; the paper's Eq. 3 retrieval score; dependency-free MinHash similarity + union-find consolidation clustering; and a join-semilattice merge — property-tested for commutativity, associativity, and idempotence, so teammate ledgers converge under any merge order with zero conflicts.src/ledger_store.js: the git-native.forge/ledger/layout — one immutable canonical-JSON file per claim (id-sharded), append-only hash-deduped evidence logs (union-merge-safe;.gitattributesadded), tombstones, attic, generatedLEDGER.md, and a CI-friendly normal-formverify. Corrupt or tampered files (address mismatch) are quarantined on read, never trusted.src/ledger_bridge.js(the P1 migration seam): cortex shadow-writes every lesson event — create mints a claim with zero evidence (creation is not confirmation), recurrence appends acortex.episodeconfirm, a human reversal appends ahuman.revertcontradiction;forge remember/forge recall addshadow facts;forge ledger importback-fills legacy lessons (aggregate counts → dated outcomes) and facts, idempotently.forge ledger stats | verify | show <id> | import(all--json-capable).SECRET_REnow lives in the ledger core so no claim kind can persist a credential;recall.jsre-exports it for compatibility.Legacy stores stay the read path in P1 (every existing test/hook/guard unchanged — the P1 acceptance gate from the plan); the read-path flip lands with P2's merge tooling.
Checklist
npm testpasses (253/253 — 31 new ledger tests incl. property tests: id stability, decay monotonicity, semilattice laws)npm run checkpasses (Biome lint + format)feat:)CHANGELOG.mdupdated under## [Unreleased]dependenciesstill empty — pure stdlib)docs/plans/substrate-v2/01-pcm-protocol.md§7 (module plan)Risk & rollback
SECRET_RErelocation (regex byte-identical, re-exported).forge/ledger/directories are inert data safe to deleteExtra checks (tick if applicable)
npm run typecheckpasses{ok:false, reason}; corrupt files skipped with debug logging, never fatal)forge ledger verify)An adversarial multi-angle review pass (8 finder angles + verification) is running; surviving findings land as a follow-up commit on this PR.
🤖 Generated with Claude Code
https://claude.ai/code/session_01Fc2MvWJbQ1cyNQ76ymv4hs
Generated by Claude Code