12 Commits

Author SHA1 Message Date
b110508926 feat: expose operator vault state for the console
Adds buildOperatorState (bucket balances, held total, today's UTC-day spend
vs caps, pending escalations) and OperatorRuntime.state(), read from the
vault executor (on-chain reads when OperatorVault is configured), served at
GET /v1/operator/state for the operator org.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 16:59:41 +03:00
2134532ba3 fix: drop Solana from the Tameion branch while keeping fail-closed confirmation
The cherry-picked fail-closed payment fixes imported @settlekit/solana, which
does not exist on this branch, breaking tsc -b and the api/worker suites.
Solana verification, env and session references are removed; arc/base/
ethereum keep the per-network verifier registry and the worker keeps
payTo-bound verification. A solana network is now rejected as unsupported
(400 on checkout/observe, unsupported in the worker). Also adds the missing
packages/circle project reference to the api, points the api/worker test
scripts at the root vitest config, and removes the operator's
vitest.apps.config.ts workaround.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 16:55:28 +03:00
0a86d7af03 fix: harden operator against double execution and payee swaps
- Events and escalation resolutions are claimed atomically in the store
  (operator_claims, INSERT ... ON CONFLICT DO NOTHING) before any money
  moves, so concurrent API/worker processes cannot execute twice; claims
  are released only when nothing was executed.
- x402 purchases pin the policy-approved payee and price: the settler
  refuses a re-read challenge that names another payTo or a higher price.
- A broadcast vault transaction whose receipt is unavailable or reverted
  is recorded as failed with its txHash (VaultTxError) for reconciliation.
- verifyDecision never reports a decision that moved money as valid
  without checking its DecisionAnchored logs on Arc.
- The worker's shared runtime reads the current run's clock and logger.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 16:40:43 +03:00
b7d674bbc2 feat: add live Arc e2e script for the operator
scripts/operator-arc-e2e.ts (refuses without LIVE=1) deploys OperatorVault
from the Foundry artifact when no vault is given, sets caps and allowlist as
the owner, pays the vault from a customer wallet, lets the operator allocate
the sale, pays a small bill, escalates a larger one in the vault, has the
owner approve it on-chain, then verifies every decision's chain, commitment
and DecisionAnchored log and prints the proof. Adds reusable arc-live
helpers (deploy, USDC transfer, balance, signer address).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 16:27:02 +03:00
1e20ece9df feat: add operator tick job to the worker
Each run expires stale escalations (vault-held ones on-chain, bills closed
as rejected), turns confirmed Arc payments into the operator vault without
a decision into revenue.received (payer read from the USDC transfer), raises
bill.due for open bills inside the due window, and emits one tick per UTC
day. Event ids are deterministic so nothing is decided twice. The API and
worker only run the operator with OPERATOR_VAULT_ADDRESS set or an explicit
OPERATOR_SIMULATION=1; otherwise the job no-ops and the routes answer 503.

Registered with one export in jobs/index.ts and one scheduler entry in
runtime.ts (the scheduler lists jobs explicitly).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 16:23:29 +03:00
2a4864dd49 feat: add operator API routes and public proof endpoints
/v1/operator (API key or dashboard session, scoped to the vault's org):
POST /events (caller org forced, duplicate event ids replay the recorded
decision, single-flight per event), GET /decisions[/:id], POST|GET /bills,
GET /escalations, owner-only POST /escalations/:id/approve|reject, GET and
owner-only PUT /policy which refuses drift from on-chain caps and allowlist.
/v1/public/operator: GET /proof (cached aggregates, demo org excluded) and
GET /verify/:id. Mounted with one route line in app.ts ahead of the v1
API-key group. Escalated bills close when the owner resolves them.

App-level operator tests run through vitest.apps.config.ts because the api
and worker tsconfigs reference packages/solana, absent on this branch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 16:15:22 +03:00
bb5daed488 feat: add operator proof, verification, policy admin and runtime
computeProof aggregates the hash-chained logs (orgs, counterparties, USDC
in/out, outcomes incl. blocked by policy and blocked on-chain, latency,
model cost, Arcscan anchors) and always excludes the demo org.
verifyDecision recomputes the chain prefix and the pre-execution commitment
and checks each transaction receipt on Arc for DecisionAnchored from the
vault. PolicyAdmin parses USDC policy bodies and refuses caps or allowlist
entries that drift from the vault. createOperatorRuntime assembles store,
DCW or viem vault executors (or a clearly labelled local simulation),
Claude or heuristic engine, screening, x402, alerts and bill intake from env.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 16:01:08 +03:00
341b977c28 feat: add AP bill intake and escalation notifications
BillIntake accepts manual bills or raw invoice text; Claude extracts vendor,
amount, due date and wallet through a single record_invoice tool, and the
wallet must appear verbatim in the invoice. Payees missing from the policy
allowlist are escalated at intake with their own decision record; due bills
go straight to the operator. Escalation notifications go to email via
@settlekit/notifications and to a Discord webhook (mentions disabled) behind
an AlertChannel interface; channel failures never block an escalation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 15:53:29 +03:00
fee0101b44 feat: add OperatorVault executor over Circle DCW and viem
VaultExecutor reads the vault through viem, simulates every write as the
signer so vault reverts surface as VaultError codes without spending gas,
then sends through a VaultTransport: Circle developer-controlled wallet
contract execution (buildContractExecutionRequest via createContractExecution,
pollTransaction to COMPLETE, deterministic idempotency keys) on ARC-TESTNET,
or a viem private-key signer when DCW cannot target the chain. pay() reads
the Escalated log for vault escalation ids. Includes per-request Circle
entity-secret ciphertext (RSA-OAEP SHA-256) and Arc viem client factories.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 15:47:56 +03:00
8c1d704a96 feat: add Claude operator agent, tools and decision service
OperatorAgent drives the Anthropic SDK tool runner (betaZodTool) over read
tools (treasury state, open bills, counterparty risk, payment history, x402
quotes) and policy-checked action tools that require rationale,
alternatives and confidence. claude-sonnet-5 handles revenue and ticks,
claude-opus-5-5 bills, refunds and disputes; at most 12 iterations, with
HeuristicOperator fallback when no key is set or the API fails.

OperatorService turns each event into one hash-chained DecisionRecord with
the tool trace, verdict, usage cost and outcome. The vault anchors a
pre-execution commitment hash of the reasoning; owner approvals, rejections
and 72h expiries are recorded as decisions too. Invoice and customer text
is passed as escaped untrusted data.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 15:41:33 +03:00
f30aef513d feat: add operator heuristic engine, executors, escalations and stores
Deterministic HeuristicOperator for revenue, bills, refunds, disputes and
ticks with rationale, alternatives and confidence. LocalExecutor simulates
OperatorVault independently for parity tests; executeProposal routes
proposals and holds off-chain escalations. 72h escalation queue, and
in-memory plus self-creating Postgres jsonb stores (doc projection) that
reject decision-chain forks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 15:17:34 +03:00
858a1a1485 feat: add @settlekit/operator policy, allocation and decision log
OperatorPolicy.evaluate mirrors OperatorVault check order (deny reasons map
1:1 to vault errors), reuses @settlekit/treasury for allowlist and UTC-day
window, and adds stricter off-chain gates (risk, compliance, min float,
x402 budget). Exact bigint revenue split, validated operator events, and a
sha256 hash-chained decision log with tamper detection.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 15:17:30 +03:00