Skip to content

CORE (signing sitting): v3 V3-03: tool I/O digest on post-tool-use receipts (R2) - #71

Merged
githubscum merged 5 commits into
mainfrom
lotor-lane/v3-03-tool-io-digest
Oct 22, 2026
Merged

githubscum merged 5 commits into
mainfrom
lotor-lane/v3-03-tool-io-digest

Conversation

@githubscum

@githubscum githubscum commented Oct 22, 2026 •

Copy link
Copy Markdown
Owner

What it does

Rung R2 (tool I/O) from the v3 spec, work order V3-03. The post-tool-use receipt gets a toolIo field that says what the tool returned without holding any of it:

"toolIo": { "schema": "toolio/1",
            "response": { "recorded": true, "digest": "<64 hex>", "bytes": 54, "error": false } }

or, when there was nothing to see:

"toolIo": { "schema": "toolio/1", "response": { "recorded": false, "reason": "absent" } }

Lotor captures; it never judges intent. The module hashes, measures and copies the host's own error flag. It never reads meaning into a response.

The hook wiring is NOT applied in this PR. It is bin/, so it is staged as a patch for the signing sitting (see below). Everything that is not core is on the branch and tested.

Files

  • src/toolio/index.js (new): describeToolResponse, canonicalResponseText, reportedError, TOOLIO_SCHEMA. The header comment is the full contract.
  • src/parser/index.js: canonicalize is now exported, so R2 uses the same canonicalizer as params/1 instead of a third copy. One word plus a comment; the function is unchanged and the params/1 pin still passes.
  • test/toolio-digest.test.js (new, 22 tests, green).
  • test/hook-post-tool-use-toolio.test.js (new, 5 tests, TODO until the patch lands).
  • test/core-classification.test.js: src/toolio added to GRANTABLE, with the reason. Owner decision, see below.
  • proposals/v3-03-tool-io-digest-2026-10-22.patch + .md: the staged hook diff and why.
  • KNOWN-LIMITS.md: limit 78. CHANGELOG.md, docs/receipt-coverage.md: entries saying the field is staged, not yet live.

Design decisions

  • Beside, not instead of. responseDigest (16-hex, unordered, 'empty' for absent) and responseOk stay exactly as they are, so old readers and old receipts keep working. Same move as paramsDigestCanonical beside paramsDigest.
  • Canonical form toolio/1: CRLF folded to LF in every string leaf (keys untouched, lone CR kept as content), keys sorted recursively, arrays in order, JSON.stringify, UTF-8. digest is the full SHA-256 (no 16-hex truncation, same birthday-bound reason as paramsDigestCanonical). bytes is the length of that canonical text, so it is stable across checkouts and is not the raw size the tool emitted.
  • Line endings. The same file read from a core.autocrlf=true checkout and an LF checkout gives the same digest. The digest depends on the response only, never on source bytes. (The existing matcherHash/parserVersionHash stamps hash Function.toString(), which carries the checkout's line endings. This field does not repeat that.) Tested with explicit \r\n escapes in fixtures, and against this test file's own on-disk bytes, so the result cannot depend on the checkout the suite runs in.
  • Error flag, tri-state, copied not inferred. is_error/isError boolean, then a boolean error, then a non-empty string or object error, then an HTTP-shaped status/statusCode. Nothing recognizable gives null, which means "no signal", not "succeeded". The word "error" in stderr is content, and judging it is the meter's job. Note: Claude Code's Bash response carries no error flag, so real Bash receipts will mostly read null.
  • Coverage stays where the hook already writes. The hook only writes a receipt for egress-shaped Bash calls. I did not add a receipt per tool call. Every append re-reads the whole chain under the lock, so that is a cost (E5) the owner should pick with a measurement in hand. V3-04's per-step receipt is the natural carrier: describeToolResponse is receipt-agnostic, and putting it there is one line. Recorded as limit 78.
  • Hook edit kept to one import and one property, so V3-04 and V3-02 rebase cleanly.

Privacy guarantee

No response content, prefix, excerpt or response key name is ever returned by the module or written to the receipt. The toolIo shape is closed (schema, response; recorded, digest, bytes, error or recorded, reason), and a test fails if any other key appears. A canary test plants a GitHub-token-shaped secret in values, a secret-shaped key name, and nested copies, and asserts that none of them, nor a 16-character slice of the token, appear. The wiring tests repeat the canary check on the real hook's receipt.

What does leave, stated plainly: the size, and a digest that is dictionary-reversible for short or guessable responses (a "yes", an exit code, a 6-digit code, a file the reader already has). paramsDigest has had the same property since v1; R2 widens it from what was asked to what came back. A keyed HMAC would close it, and would also stop two installs (or the meter's evals) comparing digests. That trade is yours. Limit 78.

How absence is recorded

recorded: false with reason, and no digest, bytes or error key at all:

  • absent: the host payload had no tool_response
  • null: the host sent tool_response: null
  • unserializable: a circular value, BigInt or bare function (does not throw)

An empty string or empty object is recorded, with a real digest (bytes: 2), because an empty answer is still an answer. The legacy 'empty' sentinel never appears in toolIo.

Tests

Fail-first: on main, test/toolio-digest.test.js fails at import (ERR_MODULE_NOT_FOUND; checked by moving src/toolio aside). The five wiring tests fail against the unpatched hook and are reported as TODO.

  • Pin: 78d33f99…5874, 54 bytes, derived out of band with printf | sha256sum, not by running the code.
  • Digest stability: key order (top and nested), CRLF vs LF (objects, bare strings, a real file in both spellings), a lone CR still differs, array order and content changes still differ.
  • Error flag: every recognized signal, null on Bash-shaped and string responses, and flipping the flag changes the digest too.
  • Absence: absent, null, unserializable, plus empty-but-present.
  • No leak: the canary test above.
  • Chain fidelity (E2), on a real signed chain in a temp LOTOR_HOME: receipts with recorded and unrecorded toolIo verify; tampering with the digest, the byte count or the error flag, upgrading an unrecorded response to a recorded one, or stripping the field each break verification at that entry.

npm test summary (this branch, Windows, Node 24.18, CRLF checkout):

ℹ tests 1084
ℹ suites 186
ℹ pass 1079
ℹ fail 0
ℹ cancelled 0
ℹ skipped 0
ℹ todo 5

Main at 5198a07 on the same machine: 1056 tests, 1056 pass. The 5 TODO are the wiring tests. Nothing else is left failing. No pin or stamp test failed; I did not re-stamp the KNOWN-LIMITS pin.

E5 cost, measured on this machine: about 0.03 ms per call at 1 KB, 1 ms at 100 KB, 9.5 ms at 1 MB, 155 ms at 10 MB. The field adds about 155 bytes per receipt regardless of response size. No new chain I/O.

Why the hook edit is a patch and not a commit

bin/hook-post-tool-use.js is self-mod protected. The live gate on the build machine gates any bin/*.js edit, this clone included (it already refused one shell command on this clone that named a protected path). So I did not attempt the edit, and I did not route around the gate. The diff is in proposals/v3-03-tool-io-digest-2026-10-22.patch:

  1. hunk 1: import { describeToolResponse } from '../src/toolio/index.js';
  2. hunk 2: toolIo: describeToolResponse(toolResponse), on the egress-event receipt, beside the legacy fields
  3. hunk 3: flips WIRED to true in test/hook-post-tool-use-toolio.test.js

Checked on this branch with git apply --check --cached: exit 0, no offset. To check the wiring before staging, I ran the five wiring tests against a scratch copy of the hook (outside the repo, never registered) with the same toolIo line added: 5 of 5 pass.

What the owner does at the signing sitting

  1. git apply proposals/v3-03-tool-io-digest-2026-10-22.patch, signing the one bin/ file. Limit 73: make it one signed operation for that file (the patch, one Edit covering both hunks, or one whole-file Write). Two separately staged hunks will purge each other.
  2. npm test: expect 1084 tests, 1084 pass, 0 todo.
  3. Decide the classification of src/toolio. I put it in GRANTABLE (reporting, not enforcement; same line as parser, ingest, harness and toolpins, which hooks already import). Once wired it runs inside a core hook's process. If you want it core, that means adding it to CORE_DIRS in src/grant/core-paths.js and to selfModFragmentsForBase() in src/policy/index.js, both core, same sitting.
  4. Re-stamp the KNOWN-LIMITS pin (npm run limits-pin -- --stamp) after merge. This branch adds limit 78 and touches src/, and I left the pin alone.
  5. Decide the two open trades in limit 78: per-call coverage (or wait for V3-04's per-step receipt) and a keyed digest.

Overlap with other lanes

🤖 Generated with Claude Code

…ring staged

src/toolio/index.js builds a toolio/1 object describing what a tool
returned without holding it: full SHA-256 over a canonical serialization
(CRLF folded to LF in every string leaf, keys sorted with the params/1
canonicalizer, now exported from src/parser), the UTF-8 byte length, and
the host's own error flag (tri-state; null means no signal). A missing,
null or unserializable response is recorded:false with a reason and no
digest key, never an empty digest.

test/toolio-digest.test.js: 22 tests, green. Pin derived out of band,
key order, CRLF vs LF (including the suite's own checkout), error flag,
absence, canary leak test, and chain fidelity on a real signed chain.

The two-line hook wiring is core and is NOT applied: it is staged in
proposals/v3-03-tool-io-digest-2026-10-22.patch for the signing sitting.
Its five tests in test/hook-post-tool-use-toolio.test.js run as TODO
until that patch flips WIRED. src/toolio classified grantable in
test/core-classification.test.js (owner to confirm). KNOWN-LIMITS 75
recorded; the limits pin is not re-stamped.

Suite: 1084 tests, 1079 pass, 0 fail, 5 todo.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
githubscum added a commit that referenced this pull request Oct 22, 2026
The KNOWN-LIMITS numbering test requires contiguous entries, so numbers
follow the merge order #65, #66, #64, #63, #60, #62, #61, #67, #68, #69,
#70, #71: #62 takes 75, #61 takes 76, this PR takes 77. Every citation on
this branch moves with it (KNOWN-LIMITS.md heading and the limit 53 note,
src/views/matcher-history.js header, test/matcher-history.test.js comment).

On this branch alone the numbering test reports 75 and 76 missing; that
clears once #62 and #61 are on main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The KNOWN-LIMITS numbering test requires contiguous entries, so numbers
follow the merge order #65, #66, #64, #63, #60, #62, #61, #67, #68, #69,
#70, #71: #62 takes 75, #61 takes 76, #67 takes 77, this PR takes 78.
Every citation on this branch moves with it: KNOWN-LIMITS.md heading,
CHANGELOG.md, docs/receipt-coverage.md, and the V3-03 proposal note. The
staged .patch carries no limit number and is unchanged.

On this branch alone the numbering test reports 75, 76 and 77 missing;
that clears once #62, #61 and #67 are on main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@githubscum

Copy link
Copy Markdown
Owner Author

Merge-order fix: limit renumbered 75 -> 78 (commit 0066849)

Numbers assume the owner's merge order: #65, #66, #64, #63, #60, #62, #61, #67, #68, #69, #70, #71. #62 takes 75, #61 takes 76, #67 takes 77, this PR takes 78.

Expected conflicts at merge time (not rebased, per instruction):

  1. KNOWN-LIMITS.md, end of file: keep everything already there (75, 76, 77), then this PR's 78.
  2. test/core-classification.test.js, the GRANTABLE block: v3 V3-05: observe reach rungs from the response, never the request #60 adds reach and CORE (signing sitting): v3 V3-04: reasoning trace chained per step (R3) #69 adds reasoning at the same spot this PR adds toolio. Keep all three entries with their comments; add a trailing comma to the line before toolio.
  3. Staged hook patch vs CORE (signing sitting): v3 V3-04: reasoning trace chained per step (R3) #69's: this PR's proposals/v3-03-tool-io-digest-2026-10-22.patch and CORE (signing sitting): v3 V3-04: reasoning trace chained per step (R3) #69's proposals/v3-04-hook-post-tool-use.patch both edit the post-tool-use hook. They do not overlap. On the fully merged tree I applied each in a throwaway index: either order applies cleanly, the second one landing at a line offset (+11 or +1). So at the signing sitting, apply both; if you want exact hunk headers, re-cut the second after the first lands.

Simulated the full merge order locally with those resolutions: 1225 tests, 1218 pass, 0 fail, 7 todo (all staged-patch tests).

githubscum and others added 2 commits October 22, 2026 12:24
F1: toolIo carries a code stamp. `hash` is the first 16 hex of SHA-256 over
the source of every function in src/toolio/ that shapes the record, beside
`schema`, mirroring parser: { schema, hash }. Source CRLF is folded before
hashing, so CRLF and LF checkouts of one commit stamp the same (tested by
importing both spellings of the module).

F2: responseOk vs toolIo.error. Precedence documented in the module header,
limit 78 and docs/receipt-coverage.md: toolIo is authoritative when recorded.
The agreement table, including the three divergent inputs, is pinned against
the real hook's legacy field in a test that runs today.

F3: no more distinct-values-one-digest. The module walks the value once into
null-prototype objects (an own __proto__ key is data) and calls anything
without an exact JSON form unserializable (undefined, functions, toJSON,
Dates, Maps, class instances, NaN, holes, symbols, BigInt, cycles). It no
longer imports the params/1 canonicalizer, so src/parser is back to main;
output is byte-identical for every value without an own __proto__ key and
the pin is unchanged. The params/1 __proto__ hole is recorded in limit 78,
not fixed: fixing it moves digests already on gate receipts.

F4: a runnable leak test on the full receipt: the real unpatched hook's
receipt plus the staged field in the staged position, signed onto a real
chain, chain file scanned on disk. F6 test renamed, F7 tamper assertions made
consistent, F8 engine-error receipt asserted to carry no toolIo.

Also: the staged patch failed `git apply --check` in a core.autocrlf=true
checkout (two blank context lines written as empty lines). They are now a
single space; the check passes in CRLF and LF form.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The self-mod gate blocks an Edit to the hook even in a scratch worktree, and
this lane did not route around it. The proposal now states that the six
wiring tests are the sitting's to confirm, not a result already in hand.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@githubscum

Copy link
Copy Markdown
Owner Author

Review fixes: second-family review (minimax-m3), V3-03

Pushed d1a9bb1 (fixes) and 950ac05 (proposal correction). Every finding was checked by running it before anything was fixed. F1 to F4 all reproduced.

Fixed

  • F1, no code stamp. toolIo now carries hash: the first 16 hex of SHA-256 over the source of every function in src/toolio/ that shapes the record, sitting beside schema the way parser: { schema, hash } does. Source CRLF is folded before hashing, so a CRLF checkout and an LF checkout of one commit give the same stamp. The test proves this by importing both spellings of the module. A tamper test shows a rewritten stamp breaks chain verification. The review's other half, that canonicalize is unstamped, no longer applies to toolio, because toolio stopped importing it (see F3). src/parser/ is back to byte-identical with main. No existing pin changed. PINNED_DIGEST / PINNED_BYTES hold.
  • F3, distinct responses with one digest. All three cases reproduced: JSON.parse('{"__proto__":{"a":1},"b":2}') and {b:2} gave the same digest, and so did toJSON, nested undefined and nested functions. The module now walks the value once into null-prototype objects, so an own __proto__ is data. Anything without an exact JSON form becomes recorded: false, reason: 'unserializable': undefined, functions, own or inherited toJSON (a Date), Map, class instances, NaN/Infinity, array holes, symbols, BigInt, cycles. Output is byte-identical to params/1 for every value without an own __proto__ key. One fold remains and is accepted: -0 serializes as 0.
  • F2, responseOk vs toolIo.error. Documented precedence: when toolIo.response.recorded is true, toolIo is authoritative. Written in the module header, limit 78 and docs/receipt-coverage.md. A test that runs today pins the full agreement table against the real hook's legacy responseOk. The two agree on 10 inputs and disagree on exactly error: false, error: '', error: 0. A todo-gated wired test asserts the same disagreement on the real receipt. responseOk is not tightened, because that is a core edit, so it is the owner's call and is not staged.
  • F4, receipt-level leak test. A new non-TODO test takes the receipt the real, unpatched hook writes and adds the staged field in the staged position (after responseOk, before matcherHash). It signs that onto a real chain with the real store and scans the chain file on disk, hashes and signatures included, for the canary, a slice of it, a secret-shaped key name and an excerpt. Mutation check: adding an excerpt field to the module makes it fail. The proposal now treats "6 pass, 0 todo after the apply" as a gate on landing, not an expectation.
  • F6 renamed to "a real source file, with CRLF injected in memory, digests the same as its LF spelling".
  • F7 every tamper case now asserts ok === false and brokenAt.
  • F8 a non-TODO test runs the hook's engine-error path and asserts that the policy-warn receipt has no toolIo.
  • F5 handled as documentation, not code. The proposal now says the GRANTABLE entry records a decision and is not fail-first evidence.

Not fixed, and why

  • CRLF fold flag (WO item under F3). The review shows no information loss from the CRLF fold. It lists the fold as a disclosed, deliberate design (limit 78), and none of its three collision cases involves line endings. So no fold flag was added and bytes stays post-fold.
  • Adding canonicalize to parserVersionHash and null-prototyping it. This is a real pre-existing hole: params/1 has the same __proto__ collision, on gate receipts that src/views/autograph.js matches. Fixing it moves params/1 digests already on chains and needs a marker decision, so it is recorded in limit 78 and left for its own change.

Found while fixing

  • The staged patch did not apply on a core.autocrlf=true checkout. git apply --check failed there with "corrupt patch at ...patch:29" before this change too. Two blank context lines were empty lines, not a single space, so after CRLF conversion they no longer read as context. They are now a single space. git apply --check passes in the CRLF working tree, on the committed LF blob and with the file stripped to LF.

What was and was not run

Nothing merged, approved or opened.

…-io-digest

# Conflicts:
#	KNOWN-LIMITS.md
#	test/core-classification.test.js
@githubscum
githubscum merged commit 2c99307 into main Oct 22, 2026
githubscum added a commit that referenced this pull request Oct 22, 2026
Applied in the live install, each step signed by the owner:
- store: tail-only append (proposals/store-tail-append, #72); PENDING_LANDING flipped
  in the same change. Precondition: live chain 37,173 entries, seq continuous.
- hooks: V3-02 session-open reach certificate (#70), V3-04 per-step reasoning (#69),
  V3-03 tool I/O digest (#71), applied from git's stored patches.
- chain: canonicaliser keeps an own __proto__ key in the hash (found while fixing #70);
  existing hashes unchanged (live chain had zero such keys).
- tests: hook-wiring todo markers removed.

npm test: 1292 tests, 1292 pass, 0 fail, 0 todo.
Deferred to the post-merge evaluation: the #68 matcher line-ending fix, the
KNOWN-LIMITS pin re-stamp (needs re-verification of every limit), verifyChain seq
continuity, keyed digests, R2 on every tool call.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant