/treeship-commerce:add-treeship-receipts [shopping | merchant | both] (default: whatever the project has)from treeship-commerce
Adds Treeship tamper-evident receipts to a commerce-agents deployment. Wraps the tool-call executor to produce signed, offline-verifiable records of provenance decisions, approvals, and checkout actions.
Ships in treeship-commerce. Installing the plugin adds it to Claude Code.
Add Treeship receipts to the user's commerce agent. Requested role:
$ARGUMENTS
Without a role, read the project and infer it; with both roles present, wire both. Treeship records; it does not gate. The reference's provenance gates, guardrails, and host approval decide what runs, exactly as before, and every decision they make becomes a signed receipt that verifies offline. Say that once, early, so the user does not expect the agent's behaviour to change.
anthropics/commerce-agents): the current repo, a local clone, or a fresh clone. Treeship needs it only for the tests and the demos; the deployment imports treeship_commerce and its own reference packages.executor_class seam: ShoppingAgent(...) / MerchantAgent(...) (Messages API), ShoppingToolset(...) / MerchantToolset(...) (Agent SDK), or build_server(...) in a *-mcp-server (Managed Agents). A project from /scaffold-commerce-agent names its runtime in the ## Commerce agent decision record of CLAUDE.md; read it, and read the approval surface entry for a merchant agent.treeship --version must print 0.29.0 or later, and treeship init --config .treeship/config.json must have run in the deployment's working directory (or TREESHIP_CONFIG must point at one). Without a ship, receipts are dropped and counted, never invented; say so and offer to run treeship init --config .treeship/config.json.pip install "treeship-sdk>=0.29.0" "treeship-commerce>=0.29.0"
Pin both in the project's dependency file. treeship-commerce declares the SDK floor it needs; do not lower it, because signed approvals require the SDK's attest_action(subject=).
Every tool call on all three runtimes runs through BaseToolExecutor.execute, so one wrapper covers the runtime the project uses. Build the receipted class once and pass it where the runtime takes executor_class:
from treeship_sdk import Treeship
from treeship_commerce import TreeshipReceipts, receipted
from treeship_commerce.lifecycle import start_session
ts = Treeship()
root = start_session(ts, name="commerce:<store>", actor="agent://shopping") # or agent://merchant
def make_recorder(executor):
return TreeshipReceipts(
ts,
actor="agent://shopping", # match the role
session_id=executor._session.session_id, # only its 12-hex tag is ever written
parent_id=root,
)
Executor = receipted(ShoppingToolExecutor, recorder=make_recorder) # or MerchantToolExecutor
| Runtime | Where Executor goes |
|---|---|
| Messages API | ShoppingAgent(..., executor_class=Executor) / MerchantAgent(..., executor_class=Executor) |
| Agent SDK | ShoppingToolset(..., executor_class=Executor) / MerchantToolset(..., executor_class=Executor) |
| Managed Agents | build_server(..., executor_class=Executor) |
A project that constructs executors itself can attach(executor, TreeshipReceipts(...)) instead; attach refuses a plain reference executor, because one that silently recorded nothing is the failure this exists to remove.
Pin, in the user's words, the two facts the receipts rely on: the actor URI is the role, and the session_id handed to the recorder is the commerce session id (the reference's request credential). The recorder writes only session_tag(session_id), the same twelve hex characters the reference's own log lines carry, so logs and receipts correlate without either holding the id.
Wrap the storefront backend once, where the runtime is built:
from treeship_commerce import receipted_backend, order_placed
backend = receipted_backend(MyStorefront())
checkout_handoff(session, cart) now also signs a hand-off receipt: cart digest, item count, subtotal, currency, and a digest of each hosted URL with its seller. The URL is never written. Then find where the host learns the order was placed on its own checkout page, and add the host's half there:
await order_placed(receipts, order_ref=order.order_id, amount=order.total, currency=order.currency)
receipts is the recorder for that session (TreeshipReceipts.for_session(session_id) finds it, or the host keeps the one it built). If the host has no order-placed hook yet, say so and leave a TODO at the checkout page's success path; an order receipt without a hand-off says handoff_recorded: false rather than inventing a parent, so a partial wiring is honest, not wrong.
The reference gates apply_change on state.approved_change_ids, an in-process set the host fills from its y/N. Make the yes a signed, scoped, single-use grant:
from treeship_commerce import MerchantApprovals, approved, approving
approvals = MerchantApprovals(ts, approver="human://operator", actor="agent://merchant")
Executor = approved(receipted(MerchantToolExecutor, recorder=make_recorder), approvals)
Then, by runtime, from the decision record's approval surface:
toolset = approving(MerchantToolset(..., executor_class=Executor), approvals). The console's host_approve / host_clear calls are unchanged and now mint and forget grants.state.approved_change_ids, also call approvals.grant(change_id, summary=change.summary).always_ask prompt is the approval surface and the click is outside the process. Nothing can sign it; an apply there is receipted with no approval claim. Say this plainly and do not add enforce=True on that runtime, since it would hold every apply.approver is a URI for the human principal, from the host's own authentication; never a display name and never invented. The actor must equal the recorder's actor or the grant's scope refuses the apply it was minted for.
Default is recording only: a missing or spent grant is written as approval: "unproven" with the CLI's reason, and the reference's gate still holds the call. Offer approved(..., enforce=True) only when the user says the receipt should be the authority; then a missing or spent grant holds the apply after its intent receipt, so the hold is itself signed.
At the end of a commerce session:
from treeship_commerce.lifecycle import close_session
sealed = close_session(ts, summary="...") # a .treeship package
treeship package verify <sealed package> # every receipt, the Merkle root, the journal check
treeship approval uses <grant-id> # a merchant grant's one use
treeship session report # publish, deliberately, for a shareable receipt page
Add the verify line to the project's CI next to its evals, so a receipt chain that stops verifying fails the build.
TREESHIP_BIN set; a receipted executor changes no tool result.treeship session status shows receipts, and dropped == 0 on the recorder.approval: "unproven" with max_uses (1/1) in its note.cart_digest equals cart_digest(card_payload["cart"]).enforce is on.What the command file sets; muted values are Claude Code's defaults
7-day visitors to each command page
npx claudepluginhub zerkerlabs/treeship --plugin treeship-commerceOther plugins' commands for the same job