From bb1a7d308ee6db860d0efae8e2ae6b738109b39d Mon Sep 17 00:00:00 2001 From: Pavel Grigorenko Date: Fri, 16 Oct 2026 15:32:21 +0200 Subject: [PATCH 1/4] Ship an agent skill for the CLI An agent driving unicity-proof has no way to learn the parts of the interface that are not discoverable from --help. The costly one is that `verify ` alone reports Status OK for a valid timestamp that was never tied to a document: without --file or --hash the verdict says nothing about the file the caller is holding. Add skills/unicity-proof/SKILL.md covering that trap and the rest of the non-obvious behaviour: that exit 3 leaves the request possibly certified, that a token dumped to stderr as hex is recoverable without re-stamping, that the token file is the only receipt, why UNICITY_TRUST_BASE from a discovered .env is ignored, and that a stamp is evidence only if it precedes the outcome it commits to. The skill asserts exit codes, so it would rot silently as the CLI changes. SkillTest parses the documented codes and compares them against the constants in src/errors.ts, and checks the skill is listed in the package files so it reaches installs. No MCP server: a tool schema costs thousands of context tokens before any work happens, where this costs a few hundred and loads only when relevant. The CLI is already the better interface for any agent with a shell. --- README.md | 16 ++++++++ package.json | 1 + skills/unicity-proof/SKILL.md | 77 +++++++++++++++++++++++++++++++++++ tests/unit/SkillTest.ts | 19 +++++++++ 4 files changed, 113 insertions(+) create mode 100644 skills/unicity-proof/SKILL.md create mode 100644 tests/unit/SkillTest.ts diff --git a/README.md b/README.md index dde74f9..5839698 100644 --- a/README.md +++ b/README.md @@ -161,6 +161,22 @@ unicity-proof verify document.cbor --file document.pdf --json | jq -r .reference | 3 | Network error, aggregator rejection, or timeout. | | 130 | Interrupted. | +### Agents + +An agent skill ships in the package at `skills/unicity-proof/SKILL.md`. It is a +short briefing on the traps that matter — binding a proof to a document, what a +timeout does and does not mean, and why a verdict depends on its trust base. +Copy it where your agent looks for skills, for example: + +```bash +mkdir -p .claude/skills +cp "$(npm root -g)/@unicitylabs/proof-cli/skills/unicity-proof/SKILL.md" .claude/skills/unicity-proof/ +``` + +There is no MCP server, and none is planned while the CLI is the better +interface: a tool schema costs thousands of context tokens before any work +happens, where the skill costs a few hundred and is read only when relevant. + ### Testnet and custom gateways ```bash diff --git a/package.json b/package.json index 168808f..b486c1a 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ }, "files": [ "lib/**/*", + "skills/**/*", "LICENSE", "README.md" ], diff --git a/skills/unicity-proof/SKILL.md b/skills/unicity-proof/SKILL.md new file mode 100644 index 0000000..50d4ea2 --- /dev/null +++ b/skills/unicity-proof/SKILL.md @@ -0,0 +1,77 @@ +--- +name: unicity-proof +description: Use when stamping a file or digest to prove it existed at a point in time, when verifying or checking an existing proof or .cbor timestamp token, or when generating a signing key for stamps. Covers the hash-binding, exit-code and trust-base traps in the unicity-proof CLI. +--- + +# Unicity Proof CLI + +Stamps a SHA-256 digest into a Unicity token, proving the digest existed at a +certified time. Verification is fully offline. Stamping needs `UNICITY_API_KEY`; +`verify` and `inspect` need nothing. + +## Verifying: the mistake that matters + +`unicity-proof verify token.cbor` proves the token is a valid timestamp. It does +**not** prove it is a timestamp *of your document*. Whenever you hold the +document, bind the two: + +```bash +unicity-proof verify token.cbor --file document.pdf # or --hash <64 hex> +``` + +Then read `Expected hash matches`. Without `--file` or `--hash` that line tells +you the proof was never tied to anything — a bare `Status OK` on its own +establishes nothing about the file in front of you. + +Also read the `Trust base` line. A verdict is only as good as the root of trust +behind it, and `OK` against someone else's trust base means nothing. + +## Stamping + +The token file **is** the receipt. Default name is +`token_.cbor`; keep it with the document, because +without it the proof is gone. + +- **Exit 3 does not mean nothing happened.** The timeout fired and nothing was + written locally, but the network may still have certified the request. + Re-running `stamp` spends quota again. +- **A failed write after certification is recoverable.** The token is printed to + stderr as hex, and both `verify` and `inspect` accept hex, so save that text. + Do not re-stamp. +- `--sign` exits 2 unless a key is configured. Use it in any automated path that + must never silently produce an anonymous stamp. `--anonymous` forces the + opposite. + +## Stamp before the outcome is known + +A stamp is evidence only if it was made before the thing it commits to could be +known. Stamp first and reveal later; stamping after the fact proves nothing +about foresight. + +## Exit codes + +| Code | Meaning | +| --- | --- | +| `0` | Success. For `verify`: valid, and the hash matched if one was given. | +| `1` | Verification failed, hash mismatch, or the input is not a token. | +| `2` | Usage or configuration error. | +| `3` | Network error, aggregator rejection, or timeout. | +| `130` | Interrupted. | + +## Machine-readable output + +`--json` prints one JSON object on stdout; everything else goes to stderr. Large +integers are decimal strings. + +`--out -` writes raw token bytes to stdout with the summary on stderr. With +`--out - --json` the object goes to stdout instead and carries the token as hex +in its `token` field. + +## Trust bases + +`UNICITY_TRUST_BASE` is deliberately ignored when it comes from a `./.env` that +was merely found in the working directory: a token shipped next to a `.env` +would otherwise verify against whatever root of trust the sender chose. Pass +`--trust-base` explicitly to select one. + +Full flag and configuration reference: the project README. diff --git a/tests/unit/SkillTest.ts b/tests/unit/SkillTest.ts new file mode 100644 index 0000000..885bfe0 --- /dev/null +++ b/tests/unit/SkillTest.ts @@ -0,0 +1,19 @@ +import { readFile } from 'node:fs/promises'; +import path from 'node:path'; + +import { EXIT_INTERRUPTED, EXIT_NETWORK, EXIT_OK, EXIT_USAGE, EXIT_VERIFICATION_FAILED } from '../../src/errors.js'; + +const SKILL = path.resolve('skills/unicity-proof/SKILL.md'); + +describe('agent skill', () => { + it('documents exactly the exit codes the CLI returns', async () => { + const skill = await readFile(SKILL, 'utf8'); + const documented = [...skill.matchAll(/^\| `(\d+)` \|/gm)].map((match) => Number(match[1])); + expect(documented).toEqual([EXIT_OK, EXIT_VERIFICATION_FAILED, EXIT_USAGE, EXIT_NETWORK, EXIT_INTERRUPTED]); + }); + + it('ships inside the package', async () => { + const manifest = JSON.parse(await readFile(path.resolve('package.json'), 'utf8')) as { files: string[] }; + expect(manifest.files).toContain('skills/**/*'); + }); +}); From f024a65f4024888c9e68ed794ef80376014ba780 Mon Sep 17 00:00:00 2001 From: Pavel Grigorenko Date: Fri, 16 Oct 2026 15:33:27 +0200 Subject: [PATCH 2/4] Create the skill's destination directory before copying The documented install ran mkdir against .claude/skills and then copied into .claude/skills/unicity-proof/, which cp refuses when that directory does not exist: 'cannot create regular file ... Not a directory'. The documented sequence therefore failed on a fresh checkout and the skill never reached the agent. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5839698..8cc6dbf 100644 --- a/README.md +++ b/README.md @@ -169,7 +169,7 @@ timeout does and does not mean, and why a verdict depends on its trust base. Copy it where your agent looks for skills, for example: ```bash -mkdir -p .claude/skills +mkdir -p .claude/skills/unicity-proof cp "$(npm root -g)/@unicitylabs/proof-cli/skills/unicity-proof/SKILL.md" .claude/skills/unicity-proof/ ``` From 8c448e803f2879da7774ef2f8e11ce22e1215ed9 Mon Sep 17 00:00:00 2001 From: Pavel Grigorenko Date: Fri, 16 Oct 2026 15:39:20 +0200 Subject: [PATCH 3/4] Distinguish the six failures behind exit code 3 The skill stated that exit 3 means the timeout fired and the request may still have been certified. That holds only for SleepError. toExitCode also maps StampError, JsonRpcNetworkError, JsonRpcResponseError, JsonRpcDataError and a failed fetch to the same code, and none of those certify anything: a 429, a refused API key or an aggregator rejection leaves nothing on the network. An agent following the old text would treat an auth or rate-limit failure as possibly-certified and hesitate to retry, when the correct action is to fix the cause. Name the timeout as the only ambiguous case and quote the five gateway messages that distinguish the others, since describeError already prints which one happened. Those quoted strings can drift like the exit codes, so SkillTest now extracts them from the skill and asserts each appears in src/errors.ts or src/lib/errors.ts. --- skills/unicity-proof/SKILL.md | 10 +++++++--- tests/unit/SkillTest.ts | 15 +++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/skills/unicity-proof/SKILL.md b/skills/unicity-proof/SKILL.md index 50d4ea2..2cd74d9 100644 --- a/skills/unicity-proof/SKILL.md +++ b/skills/unicity-proof/SKILL.md @@ -32,9 +32,13 @@ The token file **is** the receipt. Default name is `token_.cbor`; keep it with the document, because without it the proof is gone. -- **Exit 3 does not mean nothing happened.** The timeout fired and nothing was - written locally, but the network may still have certified the request. - Re-running `stamp` spends quota again. +- **Exit 3 covers several failures and only one is ambiguous.** A timeout + waiting for the inclusion proof is the only case that can leave the request + certified while nothing was written locally; there, re-running spends quota + again. `Could not reach the gateway`, `Gateway returned HTTP ...`, + `Gateway rate limit reached`, `Gateway refused the API key` and + `Aggregator rejected the certification request` all certified nothing — fix + the cause rather than retrying blind. The stderr message says which happened. - **A failed write after certification is recoverable.** The token is printed to stderr as hex, and both `verify` and `inspect` accept hex, so save that text. Do not re-stamp. diff --git a/tests/unit/SkillTest.ts b/tests/unit/SkillTest.ts index 885bfe0..859f3a1 100644 --- a/tests/unit/SkillTest.ts +++ b/tests/unit/SkillTest.ts @@ -12,6 +12,21 @@ describe('agent skill', () => { expect(documented).toEqual([EXIT_OK, EXIT_VERIFICATION_FAILED, EXIT_USAGE, EXIT_NETWORK, EXIT_INTERRUPTED]); }); + it('quotes gateway messages the CLI can actually print', async () => { + const skill = await readFile(SKILL, 'utf8'); + const sources = `${await readFile(path.resolve('src/errors.ts'), 'utf8')}${await readFile( + path.resolve('src/lib/errors.ts'), + 'utf8', + )}`; + const quoted = [...skill.matchAll(/`(Could not reach|Gateway |Aggregator )([^`]*)`/g)].map((match) => + `${match[1]}${match[2]}`.replace(/ \.\.\.$/, ''), + ); + expect(quoted.length).toBeGreaterThan(0); + for (const message of quoted) { + expect(sources).toContain(message); + } + }); + it('ships inside the package', async () => { const manifest = JSON.parse(await readFile(path.resolve('package.json'), 'utf8')) as { files: string[] }; expect(manifest.files).toContain('skills/**/*'); From 20f8e6bd497b6165d76c87e8a9c516d480826140 Mon Sep 17 00:00:00 2001 From: Pavel Grigorenko Date: Fri, 16 Oct 2026 15:40:58 +0200 Subject: [PATCH 4/4] Stop claiming gateway errors prove nothing was certified certifyMintTransaction submits the certification request before it calls waitInclusionProof, and the polling path reaches the same gateway. A dropped connection or an HTTP error can therefore surface after the network has already accepted the request, and a lost submission response is ambiguous for the same reason. The previous text listed those messages as certifying nothing, which is the opposite error to the one it replaced. Only an explicit aggregator rejection is unambiguous. Say that, and say that the CLI does not track the request so it cannot resolve the rest. --- skills/unicity-proof/SKILL.md | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/skills/unicity-proof/SKILL.md b/skills/unicity-proof/SKILL.md index 2cd74d9..99a4490 100644 --- a/skills/unicity-proof/SKILL.md +++ b/skills/unicity-proof/SKILL.md @@ -32,13 +32,15 @@ The token file **is** the receipt. Default name is `token_.cbor`; keep it with the document, because without it the proof is gone. -- **Exit 3 covers several failures and only one is ambiguous.** A timeout - waiting for the inclusion proof is the only case that can leave the request - certified while nothing was written locally; there, re-running spends quota - again. `Could not reach the gateway`, `Gateway returned HTTP ...`, - `Gateway rate limit reached`, `Gateway refused the API key` and - `Aggregator rejected the certification request` all certified nothing — fix - the cause rather than retrying blind. The stderr message says which happened. +- **Exit 3 usually cannot tell you whether anything was certified.** `stamp` + submits the request before it waits for the inclusion proof, so a timeout, a + dropped connection or an HTTP error can all arrive after the network already + accepted it — and the CLI does not track the request, so it cannot say. + Assume it may have been certified: re-running spends quota again and can + produce a second token over the same digest. The one unambiguous message is + `Aggregator rejected the certification request`, where the aggregator refused + outright and nothing was certified. Always fix + `Gateway refused the API key` before retrying at all. - **A failed write after certification is recoverable.** The token is printed to stderr as hex, and both `verify` and `inspect` accept hex, so save that text. Do not re-stamp.