Repository navigation
Conversation
…erify CLI, MCP receipt tools - app.governance.ledger: append-only, hash-chained JSONL ledger (<runs_dir>/.ledger/receipts.jsonl). One entry per persisted receipt; prev_entry_hash chains entries, `supersedes` links a run's new receipt to the one it replaced (resume keeps the paused receipt in history). verify() catches edits, gaps, reorders, forged links, unsigned entries (require_signatures) and truncation (expect_head). Process + flock locking. - app.governance.signing: ReceiptSigner / SignatureVerifier protocols, HmacSigner (stdlib), Ed25519Signer/Verifier (new `signing` extra), KeyRing, domain-separated messages, detached sign_receipt/verify_receipt_signature. - app.governance.audit: audit_run() = verify_receipt + "anchored and latest" ledger check + entry signature, catching resealed or rolled-back receipts. - Supervisor/build_supervisor/EngineConfig accept receipt_ledger (off by default); the SDK anchors one entry per run (the final, usage-filled receipt). - `ds` CLI (app/cli.py): ds verify / ds ledger / ds keygen, exit 0/1/2. - MCP: get_receipt, verify_receipt, verify_ledger tools; ledger on by default (DS_RECEIPT_LEDGER), signing via DS_RECEIPT_HMAC_KEY or DS_RECEIPT_ED25519_KEY_FILE (bad keys fail at startup); dot-prefixed run ids refused. - Docs: governance.md section 4, mcp.md, README, CHANGELOG, AGENTS, ARCHITECTURE. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019KQ4WiPnTbxYH119mnxPiX
mypy on Windows rejected fcntl.flock (attr-defined) because the import was a try/except; gate it on sys.platform so mypy narrows on every OS. The keygen test asserted POSIX 0o600 mode bits, which Windows does not have. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
Summary
Receipts could already prove they hadn't been edited, but anyone able to rewrite
runs/<run_id>/could also rewritereceipt.jsonand recompute its hash. This PR closes that gap (seedocs/governance.md§4).app/governance/ledger.py): an append-only log at<runs_dir>/.ledger/receipts.jsonlwith one entry per saved receipt.prev_entry_hash).supersedeslinks a run's new receipt to the one it replaced, so a resumed run keeps itspausedreceipt in its history.verify()catches edited, deleted, reordered or re-linked entries. It also catches unsigned entries (require_signatures) and a cut-off tail (expect_head).flock).app/governance/signing.py):ReceiptSignerandSignatureVerifierprotocols.HmacSigneruses the stdlib and refuses keys under 32 bytes.Ed25519Signer/Ed25519Verifierneed the newsigningextra (cryptography).KeyRinghandles key rotation.sign_receipt/verify_receipt_signaturegive a standalone signature for a single receipt.audit_run(app/governance/audit.py): runsverify_receipton the stored receipt, then requires it to be anchored in the ledger and to be the run's latest entry. This catches a resealedreceipt.jsonand an older receipt restored over a newer one.EngineConfig(receipt_ledger=...). The SDK anchors one entry per run: the final receipt with token usage filled in.Supervisor(receipt_ledger=...)andbuild_supervisor(..., receipt_ledger=...).dsCLI (app/cli.py,[project.scripts]):ds verify,ds ledger,ds keygen.ds verifyoptions:--hmac-key-env,--public-key,--require-signatures,--policy-hash,--expect-head,--json.get_receipt,verify_receiptandverify_ledger.DS_RECEIPT_LEDGER;offturns it off).DS_RECEIPT_HMAC_KEYorDS_RECEIPT_ED25519_KEY_FILEis set; a bad key stops the server at startup.server_inforeports the ledger path and signing key id..are refused.governance.md,mcp.md, README, CHANGELOG, AGENTS, ARCHITECTURE.Type of change
Checklist
uv run ruff format .anduv run ruff check .passuv run mypypasses (app/cli.pyadded to the mypy file set)uv run pytestpasses: 797 passed, 6 skipped. New test files:test_receipt_ledger.py,test_receipt_signing.pyandtest_cli.py. MCP tests were extended intest_mcp_service.pyandtest_mcp_server.py.CHANGELOG.mdARCHITECTURE.md:governanceimports only models/policy/registry, and the CLI imports onlygovernance.Notes
receipt_version: 1). The task brief mentioned "receipts v2 with resume chaining", but no branch had it, so resume chaining lives in the ledger (supersedes) instead. A v2 receipt with aprevious_receipt_hashfield would change v1 hashes and could be a follow-up.headsomewhere you control and check it with--expect-head. When the auditor isn't the host, use Ed25519.engine_failedrun are never anchored.uv.lockchanges only for the newsigningextra.import dynamic_subgraphsandds verifyboth work.Generated by Claude Code