Skip to content

FLT-369 plan v5: Forge provenance ledger (smallest experiment)

Author: Clahadore (Claude). Builder: Cedric (Codex), in a worktree. C# / .NET 10. v1 went to CedricFocus, Jenny, Gronktayvius General, Gronktayvius Red Team and Susie Franny: four APPROVE WITH CHANGES, one REJECT. Round 2 (v2): CedricFocus REJECT, Susie APPROVE WITH CHANGES. Round 3 (v3): CedricFocus REJECT with three named fixes, adopted as written in v4. Section 8 maps them. Section 7 maps round 2. Section 6 maps v1. No seat has reviewed v4 itself; Cedric's stop check on v4 found B1 (same-session Bash replacement names the wrong prompt); v5 fixes it (section 9).

Purpose: attribution and debugging. NOT a security control. Nothing in Forge or FLT-359 may allow or deny on any ledger or decision field. Same-user agents can tamper with it. Out of scope: signing, Merkle trees, Verse4Verse app changes, external-origin channels, per-person memory, other PCs, commit trailers.

1. Pass test (each under a minute, with command and output attached)

# Question Command
Q1 What did Andrew directly ask today, in Claude Code on this PC? prov asked --today
Q2 What did agent X spawn? prov spawned <WT-xxxx, session or agent id>
Q3 Which session wrote file Y, and on whose prompt? prov who <file>[:line]
Q4 Did Andrew ask for this rule, or did an agent add it? prov why <file>:<line>

Every query prints its coverage (date range, harnesses covered, dropped events in the window). Fail: a Write/Edit file cannot be linked to its prompt, or prov why claims Andrew asked when he only asked for a spec, or only quoted the rule. Machines cannot judge intent from text, so the only verdict that claims his intent is one he typed a confirmation for.

Q2 and Q3 are forward-only. Pre-declared result for the real case, Verse4Verse/docs/SPEC.md:43 (717d2a0, 2026-10-24): that commit has no hook events, so the expected verdict is UNKNOWN plus any POSSIBLE transcript hits. Any verdict claiming Andrew's request is a failure. The forward path is proved by a scripted soak (section 4, step 8).

2. Measured evidence (AndyGreatRoomPC, 2026-11-04, Claude Code probe via claude -p --settings)

  • Every hook payload carries prompt_id: UserPromptSubmit, PreToolUse, PostToolUse, Stop, SubagentStop.
  • Transcript user lines carry promptId, equal to the hook's prompt_id (checked on both probe prompts).
  • At UserPromptSubmit the transcript line does not exist yet. By the first tool call or Stop it does.
  • UserPromptSubmit also fires for task-notifications, whose transcript line has origin.kind: task-notification.
  • Subagent tool calls keep the parent's prompt_id and add agent_id and agent_type. SubagentStop has agent_transcript_path.
  • CLAUDE_ENV_FILE is set for SessionStart only. A line written there reached Bash. CLAUDE_CODE_ENTRYPOINT is inherited by nested runs, so it is not a signal.
  • Survey of 150 transcripts: origin.kind == human (704 lines) is what marks typed prompts. promptSource is sdk for both typed and session-started prompts. Session-started and council prompts have no origin and turnOrigin: sdk; peer has from; scheduled has turnOrigin: scheduled.
  • Desktop session json %APPDATA%\Claude\claude-code-sessions\...\local_<id>.json: cliSessionId equals the hook session_id, and spawnedFrom.sessionId is the parent's local_ id. Verified for this session.
  • DispatchJob.SchemaVersion is a documented precedent for an unsigned field outside JobSigner.CanonicalString (fleet-dispatch/src/FleetDispatch.Core/DispatchJob.cs).

Still unverified, step 1 must capture: live desktop human payload; interactive entrypoint: cli; the October transcript schema; additionalContext on PostToolUse and SessionStart; non-zero-exit behaviour; PowerShell tool env.

3. Design

3.1 Repo

New private repo forge-provenance: Forge.Provenance.Core, prov.exe (console, queries), prov-hook.exe (WinExe, no console window), Forge.Provenance.Tests. Installed to C:\Tools\forge-provenance\.

3.2 Append-only facts, computed views

Hooks append raw facts and never edit a line. Trace, origin and verdict are folds at query time. Event: v, ts (ISO-8601 with offset), host, kind, session, promptId, toolUseId, agentId, agentType, wt, ticket, model, repo{root,remote}, path{relative,original}, digest, detail, transcript{path}, actorProvenance (harness-hook | caller-supplied), dedupKey. Kinds: prompt, classification, tool, file-write, spawn, dispatch, ssh, commit, decision, session-start. origin values in views: human-confirmed, agent, scheduled, system, unknown.

Causality comes from prompt_id, which is immutable per event, so nothing inherits from "the session's current prompt" within a session. W3C-format traceId and spanId are derived deterministically from the root prompt id and event, for OTel compatibility.

3.3 Classification

  • prompt event at UserPromptSubmit has origin unset.
  • The prompt event records the transcript's byte length at that moment. First PreToolUse/PostToolUse of that prompt and Stop scan forward from that offset, whole lines, to the line with the matching promptId and append one classification event with dedupKey: classification:<promptId>. Races may append twice; the fold takes the first. This persists the answer past transcript cleanup. Never a tail window, so an oversized prompt still resolves. An unresolved prompt is a coverage gap.
  • prov also classifies at query time for prompts with none yet. Unresolved stays unknown. Only origin.kind == human gives human-confirmed. promptSource is never consulted, and there is a negative test.
  • prov emit (CLI for non-hook callers) hard-codes caller-supplied. It cannot emit a human-confirmed fact. Q1 and Q4 ignore caller-supplied events.

3.4 Storage and writer

%LOCALAPPDATA%\forge-provenance\ledger\<host>-<local yyyy-MM-dd of ts>.jsonl; --today uses the same zone. Backfill goes to a separate backfill\ store, marked backfilled, deduped on transcript uuid, never read by asked. Serialize with source-generated System.Text.Json to one line (newlines escaped). Under the lock, if the file's last byte is not a newline, write one first so a torn tail cannot swallow the next event. Then one Write, flush. Cross-session lock: a lock file opened FileShare.None, retry up to 250 ms; the OS releases it on process death, so there is no abandoned-mutex case. Readers skip any line that does not parse and count them in prov health. Drops: on failure one single-line append write of {action, ts} to drops-<date>.jsonl, tested under a two-session hammer. All queries show drops for the window. Drop records are a hint, not proof of coverage, since that write can fail too. Positive coverage comes from reconciling against the transcript, an independent record, not from pairing ledger events with each other. At Stop, and at query time for turns with none, read the transcript from the prompt's offset and append turn-coverage {promptId, transcriptToolUses, ledgerToolUses, missing, failedOrCancelled, complete}. This persists past transcript cleanup. A turn with no turn-coverage, or complete: false, is a gap. A session is certified only if every prompt id in its transcript is in the ledger. prov asked --today prints ledger count against a direct scan of today's transcripts, and lists any human prompt the ledger missed. A gap blocks categorical verdicts. Refuse the ledger directory if its final path after reparse is under a sync root or has a cloud attribute. Directory ACL: current user. Session ids must match ^[A-Za-z0-9_-]{1,128}$ or the event is dropped.

3.5 Hooks

~/.claude/settings.json on this PC only, quoted absolute path to prov-hook.exe. prov install backs up settings. prov uninstall removes only provenance-owned entries from the current settings, preserving other sessions' edits; the backup is for explicit recovery only. prov wipe ends the experiment. - SessionStart, UserPromptSubmit, Stop, SubagentStop. - PreToolUse and PostToolUse: Agent|Task|SendMessage|mcp__ccd_session__start_session|Bash|PowerShell|Write|Edit|MultiEdit|NotebookEdit. Reconciliation covers every tool use in the transcript, including those.

Contract: the hook never affects the tool. It exits 0 on every path, including startup failure. Stdout is empty, except a schema-checked additionalContext with a fixed template, an integer count and decision ids, never rule text and never a permission field. Budget: 100 ms p95 for the uncontended append path, measured separately cold and warm, reported. Hash capped at 5 MB, otherwise hash-deferred. Normal publish with ReadyToRun. Native AOT only if measurement demands it.

Coverage limit, stated in query output: Codex, agy, Grok and Muse have no hooks here. Their work appears only as a spawn or dispatch event and at any commit seen on this PC. Cedric building this ticket is itself uncovered. This is an accepted limit of the attribution soak only and would block any security use. A follow-up ticket adds their hooks. All prov output, including stored prompts, is untrusted text. Any future UI renders it with textContent or default Razor/Blazor encoding, never an HTML sink.

  • Subagents: agent_id with parent's prompt_id. Exact.
  • Child processes: SessionStart writes one line to CLAUDE_ENV_FILE, export FORGE_PROV_SESSION=<id>, after the regex check. It is constant, so never stale. A child's SessionStart reads the parent session's current-prompt file (written with temp + File.Replace by UserPromptSubmit only, so there is one writer per session) and records parentSession, parentPrompt, parentResolvedBy: session-current. Limit: a background child that starts after a newer prompt attaches to the newer prompt, so it is labelled inferred, not exact.
  • Desktop sessions: at query, spawnedFrom.sessionId to cliSessionId through the session json files, then the parent's start_session tool events by time. Labelled inferred.
  • task-notification prompts: link to the originating tool use via the notification's tool-use id.
  • Peer: origin.from.
  • TRACEPARENT present in env: validated by W3C regex, stored as a claim, never overrides the fields above.

3.7 Dispatch

Add DispatchJob.Traceparent, unsigned, outside CanonicalString, doc comment says advisory and never authorizes. Executor validates, and always sets or clears TRACEPARENT and FORGE_PROV_SESSION in the child, so a job with no field never inherits ambient. Missing prov.exe never fails a job. Tests: golden canonical bytes of a pre-change job, byte equal when only Traceparent differs; old job parses on new executor; new job JSON parses on the old model. Reviewed as its own diff on a fleet-dispatch worktree. ssh: best-effort label from the command text, no remote propagation.

3.8 Files and commits

  • file-write: repo-relative path, repo root and remote, worktree, and digests from the PostToolUse payload, not disk, so they bind to the operation: tool_response.content for Write and per-line hashes of structuredPatch added lines for Write and Edit (tool_response keys verified for Write: type, filePath, content, structuredPatch, originalFile, userModified; Edit shape captured in step 1). Reading disk afterwards can capture another session's bytes, so it is only ever labelled observed.
  • Commit detection is by HEAD change: Pre and Post Bash/PowerShell run git rev-parse HEAD under the locked config, which handles linked worktrees, packed refs and detached HEAD; tested on all three. If changed, git diff-tree gives (path, blob oid), and git patch-id is recorded.
  • commit event never claims authorship. executor: exact only if that tool call's command text contains git commit (or a merge or cherry-pick verb); otherwise executor: candidate, because a concurrent session sharing that worktree can move HEAD.
  • prov who lookup: introducing commit via git log -S/-G for a line, or latest for a file; then a file-write whose operation-bound line hash covers that line, same repo and path; then patch-id across rebases. Content match alone gives writer: candidate. writer: exact needs an operation chain that connects the operation to the revision, regardless of session or prompt: (a) a sequence of Write/Edit operations on that path where each operation's payload originalFile digest equals the previous operation's output digest, so nothing changed the file between them; (b) the last operation's output, computed from the payload, normalized, equals the committed blob; (c) the queried line's hash first appears in exactly one operation of that chain. Everything else is writer: candidates, listing all: a broken chain, a whole-file mismatch, or a payload without originalFile. Shell calls between operations do not break the chain by themselves, because (a) and (b) detect any change they made. Accepted residual: a Bash rewrite producing a byte-identical whole file still matches, and in that case the bytes are what that chain wrote. No match: the commit executor and writer: unknown. Uncommitted Write/Edit files use the same line-hash match against the current file. Bash-only writes report writer: unknown, accepted limit. Tests: identical content by two sessions, overwrite between a tool's completion and its hook, concurrent commit, A writes a rule, B removes it by Bash, C re-adds identical text by Bash and commits, which must not name A as exact; and same session P1 Write, P2 Bash replacement containing identical line R, commit, which must not name P1 as exact and must not support AGENT-ADDED; and Write, then dotnet test and git add by Bash with file unchanged, then commit, which IS exact.
  • All git calls from prov use a locked config: --no-pager, GIT_CONFIG_NOSYSTEM, empty global, -c clearing pager, fsmonitor, hooksPath and external diff. Never UseShellExecute.

3.9 Decision record

.forge/decisions.jsonl, git-tracked, append-only. Untrusted cache of claims. Events: propose and resolve; current state is a fold, latest resolve wins. Fields: schemaVersion, id, ts, rule (redacted), ruleDigest (first 8 hex of sha256 of the normalized rule), kind, origin (quote or agent-proposed), source (path:line), evidenceEventId, binding. An id reused with another ruleDigest is rejected. No core bit in v1: EVERY agent-proposed restriction goes to Andrew. binding is false until accepted. - prov decide add --rule --source (--quote "..." | --agent-proposed). A quote must be found in the typed field of one human-confirmed prompt, same repo, before the rule's introducing commit if there is one, minimum 5 words. Typed field means the hook's prompt with <system-reminder>, pasted-content blocks and attachments removed. Failing that, it is recorded agent-proposed with quoteUnverified. - prov ignores origin, status and binding in the file unless evidenceEventId verifies against this PC's ledger. Otherwise it reports claim, no evidence here. - A verified quote is recorded as cited: an agent's claim that these words are the source, which the output shows for Andrew to read. It is not confirmation, because "remove the rule 'X'" contains the same words. cited and agent-proposed both stay binding: false. agent-proposed restrictions enter the pending list. cited ones are listed by prov decide cited, not pending. - Acceptance cannot be set by an agent. There is no --accept flag. It is derived at query time from a later human-confirmed typed field, same repo, whose ENTIRE trimmed text equals D-<n> accept <digest> or D-<n> reject <digest>, where the digest is that decision's ruleDigest. Surrounding prose, quotes or a code fence means it does not count. prov decide pending prints the two ready-to-copy lines. Negation, questions, generic "yes", several ids, a fenced example or a stale digest leave it pending. Among valid confirmations for the current digest, the latest wins; verdict precedence applies after that selection. Tests cover each, accept then reject, reject then accept, and a rule changed after acceptance. - Putting it to Andrew: SessionStart and the first human prompt per day per repo inject a fixed status line, with no imperative: provenance: N pending decisions, not binding: D-12, D-13. Suppressed when N is 0 and when the store cannot be read. A human-origin session reports them to Andrew per the ticket; this is stated in the repo's agent docs, not in injected text. This reaches builder sessions too. No outbound message. Residual: the sentence is still in the spec and an agent may obey it. prov why and the pending line are the mitigation; a CI check is a follow-up. - Backstop: PostToolUse Write/Edit on docs and spec files. Added lines matching a reminder list (never|must not|do not|no |banned|prohibited|not allowed|forbidden|always|hard stop) with no decision append a local decision candidate to the ledger, not the repo, and count as pending. Keyword coverage is a reminder, never relied on.

3.10 prov why, the crux

Finds the introducing commit, the record, the chain, then one verdict, in this precedence: 1. REJECTED: Andrew typed the reject line. 2. ANDREW-CONFIRMED: Andrew typed the accept line for this exact rule. The only verdict that claims his intent. 3. CITED, read his words: a record with a verified quote at or before the commit. Prints the full prompt around the slice. Makes no claim about intent. 4. POSSIBLE, read the quote: a text occurrence in a human prompt at or before the commit, with no record, even exact. Prints it. 5. AGENT-ADDED (within coverage): writer: exact, chain certified per 3.4, every session on that repo up to the commit certified or scanned directly from its transcript, root prompt shown, no human prompt in scope mentions it. Prints the root prompt, e.g. "write a spec", and what coverage means. 6. UNKNOWN: everything else, including writer: candidates, a gap or a commit without events. Absence of evidence is never AGENT-ADDED.

git author is never used as a human signal.

3.11 Privacy

Human typed prompts stored verbatim after redaction. Others: sha256 and 200 chars. Bash 500 chars. Redact the full string, then truncate. Redactor failure stores hash and metadata only. Patterns are linear time. Planted tokens (GitHub, Google, JWT, connection strings) fail a test if stored. Decision quotes pass the same redactor before reaching git. Prompts over 64 KB spill beside the ledger. Probe fixtures from scratch runs may be committed. Fixtures from real desktop sessions are gitignored, with a committed synthetic copy of the shape and an origin comment. No expiry during the soak; prov wipe at exit.

4. Build steps

# Step Check
1 Capture remaining unknowns from section 2 Fixtures with origin comments, answers written down
2 Core: events, writer, redactor, ids Tests incl. 2 sessions writing, killed writer and torn tail, prompt with newline and fake event stays one line, planted tokens; Stryker.NET break 70 on Core
3 Hooks Contract tests from fixtures; missing origin is not human; promptSource negative; stdout has no permission field; startup failure exits 0; latency reported
4 Q1 to Q3 Golden tests on a recorded ledger; rebased commit; worktree path; executor differs from writer
5 Decisions and prov why "write a spec" root gives AGENT-ADDED; later human turn quoting the rule is POSSIBLE; "remove the rule X" with a record gives CITED, never ANDREW-CONFIRMED; pasted text ignored; fake quote stays agent-proposed; agent cannot accept; strict line grammar negatives; rule changed after accept; gap and candidates give UNKNOWN
6 Dispatch change in fleet-dispatch worktree Section 3.7 tests; existing suite green
7 CI, council code review on both repos, land, prov install on this PC only dotnet list package --vulnerable, secret scan, Semgrep; prov health shows events; no console flash
8 One-day soak, then answer Q1 to Q4, incl. SPEC.md:43 A scripted run with expected verdicts written first: human prompt, Claude spawn, Write, Bash-only rewrite, new spec restriction. Commands, output and timings on FLT-369. An unfinished day is reported as partial

5. Questions for the seats

  1. Does this resolve your v1 findings? Name any that remain.
  2. Anything new this design broke?
  3. Final verdict.

6. Finding to change map

  • Text occurrence is not an instruction (Cedric, Jenny, Gronk, Red Team): 3.10, typed field in 3.9.
  • Absence becomes AGENT-ADDED (Cedric): rule 5 requires a known chain and coverage; rule 6.
  • Mutable session state, session race, root rotation race (Cedric, Susie, Jenny, Gronk): 3.2 and 3.3, prompt_id plus folds; one writer per session in 3.6.
  • Join key undefined (Susie): prompt_id to promptId, section 2.
  • Commit conflated with writer, worktrees, rebase, blame (Cedric, Jenny, Gronk, Red Team): 3.8.
  • core.hooksPath (all): dropped. Commit event joins sha to session. Real-actor trailers go to a follow-up.
  • Stale env carrier, caller-controlled trace (all): 3.3 and 3.6.
  • Decision row shape, laundering, resolve evidence, binding (all): 3.9.
  • Builder has no coverage (Susie): accepted limit of this soak, 3.5. Follow-up adds Codex hooks.
  • Redactor, fixtures, retention (Susie, Red Team): 3.11.
  • Writer lock, torn tail, drop counter (all): 3.4.
  • Hook safety, absolute path, uninstall (Red Team): 3.5.
  • Dispatch ambient inheritance, golden bytes (Gronk, Red Team): 3.7.
  • Prompt injection through context line (Red Team): fixed template in 3.5 and 3.9.
  • Q1 wider than capture (Gronk): section 1 wording plus coverage line.
  • backfill and day files (Jenny, Gronk): 3.4.

7. Round 2 finding to change map

  • Verified quote does not establish intent (Cedric 1): 3.10 removes ANDREW-ASKED. CITED makes no intent claim; only a typed confirmation does.
  • Acceptance ambiguous, not bound to content (Cedric 2): strict line grammar and ruleDigest, 3.9.
  • Matching bytes are not causal authorship, HEAD change is not execution (Cedric 3): operation-bound payload digests, exact vs candidates, executor: candidate, 3.8.
  • .git/HEAD in linked worktrees (Cedric 4, Susie F1): git rev-parse under locked config, 3.8.
  • Storage failure and torn tail invalidate coverage (Cedric 5, Susie F2): positive coverage and newline repair, 3.4.
  • Bounded transcript scan (Cedric 6): forward scan from recorded offset, 3.3.
  • Uninstall clobbers edits (Cedric 7): owned entries only, 3.5.
  • Classification dedup (Susie F3): 3.3. Safe-render contract (F4): 3.5. Reword builder gap (F5): 3.5, section 6. Non-directive line (F6): 3.9.

8. Round 3 finding to change map

  • Quoted confirmation becomes claimed intent: entire trimmed typed field must equal the command, 3.9.
  • Unique line hash is not causal authorship: writer: candidate by default, exact needs operation-to-revision evidence, 3.8, and AGENT-ADDED needs exact, 3.10.
  • Event pairs cannot establish coverage: reconcile against the transcript, Pre hooks on mutations, 3.4 and 3.5.
  • Decision ordering build note: latest valid confirmation for current digest, then precedence, 3.9.
  • Deferred contracts: step 1 remains a gate before the adapters.

9. Stop-check finding to change map

  • B1, same-session replacement (Cedric, BLOCKERS.md): 3.8 replaces session and interval conditions with an operation chain proved from payloads. Blanket invalidation on any shell call was rejected because it would make AGENT-ADDED unreachable: Bash runs between nearly every write and commit.

Known limitations

  • An in-place transcript rewrite that keeps the first 4 KB and the same file id is not detected.