@codespar/cli 0.14.0 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +44 -17
- package/dist/commands/audit-replay.js +267 -0
- package/dist/commands/audit-replay.js.map +1 -0
- package/dist/commands/init.js +28 -0
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/login.js +2 -1
- package/dist/commands/login.js.map +1 -1
- package/dist/commands/mandate-verify.js +75 -27
- package/dist/commands/mandate-verify.js.map +1 -1
- package/dist/config.js +17 -1
- package/dist/config.js.map +1 -1
- package/dist/did.js +262 -41
- package/dist/did.js.map +1 -1
- package/dist/index.js +33 -7
- package/dist/index.js.map +1 -1
- package/dist/surface.js +4 -1
- package/dist/surface.js.map +1 -1
- package/package.json +1 -1
- package/templates/bills-agent/README.md +8 -5
- package/templates/bills-agent/agents/bills-agent/.env.example +3 -3
- package/templates/bills-agent/agents/bills-agent/AGENTS.md +1 -1
- package/templates/bills-agent/agents/bills-agent/CLAUDE.md +1 -1
- package/templates/bills-agent/agents/bills-agent/README.md +62 -22
- package/templates/bills-agent/agents/bills-agent/SYSTEM_PROMPT.md +1 -1
- package/templates/bills-agent/agents/bills-agent/agent.yaml +2 -2
- package/templates/bills-agent/agents/bills-agent/package.json +14 -11
- package/templates/bills-agent/agents/bills-agent/src/kit.ts +193 -0
- package/templates/bills-agent/agents/bills-agent/test/adversarial.test.ts +8 -7
- package/templates/bills-agent/agents/bills-agent/test/check.test.ts +19 -2
- package/templates/bills-agent/agents/bills-agent/test/cli.test.ts +72 -24
- package/templates/bills-agent/agents/bills-agent/test/fixtures/excursao-300.transcript.jsonl +2 -0
- package/templates/bills-agent/agents/bills-agent/test/fixtures/material-400.transcript.jsonl +2 -0
- package/templates/bills-agent/agents/bills-agent/test/inspect.test.ts +124 -0
- package/templates/bills-agent/agents/bills-agent/test/provider.test.ts +25 -0
- package/templates/bills-agent/agents/bills-agent/test/scenarios.test.ts +10 -9
- package/templates/bills-agent/agents/bills-agent/tsconfig.json +0 -1
- package/templates/bills-agent/package.json +5 -2
- package/templates/bills-agent/packages/agent-core/README.md +2 -0
- package/templates/bills-agent/packages/agent-core/package.json +1 -1
- package/templates/bills-agent/packages/agent-core/src/api/charge-rail.ts +27 -6
- package/templates/bills-agent/packages/agent-core/src/api/rail.ts +16 -0
- package/templates/bills-agent/packages/agent-core/src/api/sandbox-payer.ts +20 -7
- package/templates/bills-agent/packages/agent-core/src/approval.ts +16 -2
- package/templates/bills-agent/packages/agent-core/src/bundle.ts +50 -4
- package/templates/bills-agent/packages/agent-core/src/channels.ts +140 -0
- package/templates/bills-agent/packages/agent-core/src/check.ts +90 -8
- package/templates/bills-agent/packages/agent-core/src/clock.ts +42 -0
- package/templates/bills-agent/packages/agent-core/src/engine.ts +119 -18
- package/templates/bills-agent/packages/agent-core/src/hash.ts +13 -0
- package/templates/bills-agent/packages/agent-core/src/index.ts +3 -0
- package/templates/bills-agent/packages/agent-core/src/manifest.ts +1 -1
- package/templates/bills-agent/packages/agent-core/src/rail.ts +16 -2
- package/templates/bills-agent/packages/agent-core/src/receipt-verification.ts +401 -0
- package/templates/bills-agent/packages/agent-core/src/state-machine.ts +3 -1
- package/templates/bills-agent/packages/agent-core/src/stubs/charge-rail.ts +2 -0
- package/templates/bills-agent/packages/agent-core/src/stubs/rail.ts +19 -2
- package/templates/bills-agent/packages/agent-core/src/types.ts +28 -0
- package/templates/bills-agent/packages/agent-core/test/approval.test.ts +36 -2
- package/templates/bills-agent/packages/agent-core/test/bundle.test.ts +85 -0
- package/templates/bills-agent/packages/agent-core/test/clock.test.ts +25 -0
- package/templates/bills-agent/packages/agent-core/test/engine.test.ts +73 -1
- package/templates/bills-agent/packages/agent-core/test/fixtures/staging-receipt-keys.json +18 -0
- package/templates/bills-agent/packages/agent-core/test/fixtures/staging-receipt.json +24 -0
- package/templates/bills-agent/packages/agent-core/test/helpers.ts +1 -1
- package/templates/bills-agent/packages/agent-core/test/manifest.test.ts +2 -2
- package/templates/bills-agent/packages/agent-core/test/receipt-verification.test.ts +316 -0
- package/templates/bills-agent/packages/agent-core/test/receivables.test.ts +51 -0
- package/templates/bills-agent/packages/agent-runtime/README.md +68 -0
- package/templates/bills-agent/packages/agent-runtime/bin.mjs +32 -0
- package/templates/bills-agent/packages/agent-runtime/package.json +23 -0
- package/templates/bills-agent/{agents/bills-agent → packages/agent-runtime}/src/adversarial.ts +36 -44
- package/templates/bills-agent/packages/agent-runtime/src/agent.ts +68 -0
- package/templates/bills-agent/packages/agent-runtime/src/channels/contact.ts +13 -0
- package/templates/bills-agent/packages/agent-runtime/src/channels/index.ts +72 -0
- package/templates/bills-agent/packages/agent-runtime/src/channels/rules.ts +120 -0
- package/templates/bills-agent/packages/agent-runtime/src/channels/types.ts +124 -0
- package/templates/bills-agent/packages/agent-runtime/src/channels/whatsapp/cloud-api.ts +358 -0
- package/templates/bills-agent/packages/agent-runtime/src/channels/whatsapp/emulator.ts +206 -0
- package/templates/bills-agent/packages/agent-runtime/src/channels/whatsapp/evidence.ts +109 -0
- package/templates/bills-agent/packages/agent-runtime/src/channels/whatsapp/index.ts +225 -0
- package/templates/bills-agent/packages/agent-runtime/src/channels/whatsapp/open.ts +143 -0
- package/templates/bills-agent/packages/agent-runtime/src/channels/whatsapp/present.ts +47 -0
- package/templates/bills-agent/packages/agent-runtime/src/channels/whatsapp/run.ts +113 -0
- package/templates/bills-agent/packages/agent-runtime/src/channels/whatsapp/session.ts +113 -0
- package/templates/bills-agent/packages/agent-runtime/src/cli.ts +98 -0
- package/templates/bills-agent/packages/agent-runtime/src/commands/check.ts +15 -0
- package/templates/bills-agent/packages/agent-runtime/src/commands/decide.ts +63 -0
- package/templates/bills-agent/packages/agent-runtime/src/commands/eval.ts +58 -0
- package/templates/bills-agent/packages/agent-runtime/src/commands/inspect.ts +100 -0
- package/templates/bills-agent/packages/agent-runtime/src/commands/poll-whatsapp.ts +317 -0
- package/templates/bills-agent/packages/agent-runtime/src/commands/poll.ts +144 -0
- package/templates/bills-agent/packages/agent-runtime/src/commands/reconcile.ts +42 -0
- package/templates/bills-agent/packages/agent-runtime/src/commands/rerun.ts +86 -0
- package/templates/bills-agent/packages/agent-runtime/src/commands/resume.ts +43 -0
- package/templates/bills-agent/packages/agent-runtime/src/commands/start-whatsapp.ts +131 -0
- package/templates/bills-agent/packages/agent-runtime/src/commands/start.ts +245 -0
- package/templates/bills-agent/packages/agent-runtime/src/commands/verify.ts +129 -0
- package/templates/bills-agent/packages/agent-runtime/src/commands/webhook.ts +39 -0
- package/templates/bills-agent/packages/agent-runtime/src/default-kit.ts +83 -0
- package/templates/bills-agent/packages/agent-runtime/src/index.ts +12 -0
- package/templates/bills-agent/packages/agent-runtime/src/inspect.ts +797 -0
- package/templates/bills-agent/packages/agent-runtime/src/kit.ts +206 -0
- package/templates/{collections-agent/agents/collections-agent → bills-agent/packages/agent-runtime}/src/poll.ts +22 -11
- package/templates/{collections-agent/agents/collections-agent → bills-agent/packages/agent-runtime}/src/scenarios.ts +50 -34
- package/templates/bills-agent/{agents/bills-agent → packages/agent-runtime}/src/setup.ts +88 -66
- package/templates/bills-agent/packages/agent-runtime/src/terminal.ts +154 -0
- package/templates/{collections-agent/agents/collections-agent/channels/webhook/index.ts → bills-agent/packages/agent-runtime/src/webhook.ts} +1 -1
- package/templates/bills-agent/packages/agent-runtime/test/inspect.test.ts +336 -0
- package/templates/bills-agent/packages/agent-runtime/test/verify-cli.test.ts +127 -0
- package/templates/bills-agent/packages/agent-runtime/test/whatsapp-cloud-api.test.ts +232 -0
- package/templates/bills-agent/packages/agent-runtime/test/whatsapp-emulator.integration.test.ts +204 -0
- package/templates/bills-agent/packages/agent-runtime/test/whatsapp-evidence.test.ts +94 -0
- package/templates/bills-agent/packages/agent-runtime/test/whatsapp-rules.test.ts +174 -0
- package/templates/bills-agent/packages/agent-runtime/test/whatsapp-session.test.ts +135 -0
- package/templates/bills-agent/packages/agent-runtime/tsconfig.json +9 -0
- package/templates/bills-agent/vitest.config.ts +1 -1
- package/templates/collections-agent/README.md +8 -5
- package/templates/collections-agent/agents/collections-agent/.env.example +14 -0
- package/templates/collections-agent/agents/collections-agent/AGENTS.md +6 -4
- package/templates/collections-agent/agents/collections-agent/CLAUDE.md +6 -4
- package/templates/collections-agent/agents/collections-agent/README.md +184 -16
- package/templates/collections-agent/agents/collections-agent/agent.yaml +3 -3
- package/templates/collections-agent/agents/collections-agent/channels/whatsapp/README.md +111 -0
- package/templates/collections-agent/agents/collections-agent/channels/whatsapp/acordo-1042.json +11 -0
- package/templates/collections-agent/agents/collections-agent/channels/whatsapp/acordo-1103.json +11 -0
- package/templates/collections-agent/agents/collections-agent/channels/whatsapp/templates.json +23 -0
- package/templates/collections-agent/agents/collections-agent/package.json +12 -10
- package/templates/collections-agent/agents/collections-agent/runbook.md +52 -1
- package/templates/collections-agent/agents/collections-agent/src/kit.ts +265 -0
- package/templates/collections-agent/agents/collections-agent/test/adversarial.test.ts +9 -8
- package/templates/collections-agent/agents/collections-agent/test/check.test.ts +43 -1
- package/templates/collections-agent/agents/collections-agent/test/cli.test.ts +56 -18
- package/templates/collections-agent/agents/collections-agent/test/fixtures/agreed-1042-awaiting-payer.transcript.jsonl +4 -0
- package/templates/collections-agent/agents/collections-agent/test/scenarios.test.ts +11 -10
- package/templates/collections-agent/agents/collections-agent/test/webhook.test.ts +4 -7
- package/templates/collections-agent/agents/collections-agent/test/whatsapp-poll.test.ts +271 -0
- package/templates/collections-agent/agents/collections-agent/test/whatsapp.test.ts +213 -0
- package/templates/collections-agent/agents/collections-agent/tsconfig.json +0 -1
- package/templates/collections-agent/package.json +3 -1
- package/templates/collections-agent/packages/agent-core/README.md +2 -0
- package/templates/collections-agent/packages/agent-core/package.json +1 -1
- package/templates/collections-agent/packages/agent-core/src/api/charge-rail.ts +27 -6
- package/templates/collections-agent/packages/agent-core/src/api/rail.ts +16 -0
- package/templates/collections-agent/packages/agent-core/src/api/sandbox-payer.ts +20 -7
- package/templates/collections-agent/packages/agent-core/src/approval.ts +16 -2
- package/templates/collections-agent/packages/agent-core/src/bundle.ts +50 -4
- package/templates/collections-agent/packages/agent-core/src/channels.ts +140 -0
- package/templates/collections-agent/packages/agent-core/src/check.ts +90 -8
- package/templates/collections-agent/packages/agent-core/src/clock.ts +42 -0
- package/templates/collections-agent/packages/agent-core/src/engine.ts +119 -18
- package/templates/collections-agent/packages/agent-core/src/hash.ts +13 -0
- package/templates/collections-agent/packages/agent-core/src/index.ts +3 -0
- package/templates/collections-agent/packages/agent-core/src/manifest.ts +1 -1
- package/templates/collections-agent/packages/agent-core/src/rail.ts +16 -2
- package/templates/collections-agent/packages/agent-core/src/receipt-verification.ts +401 -0
- package/templates/collections-agent/packages/agent-core/src/state-machine.ts +3 -1
- package/templates/collections-agent/packages/agent-core/src/stubs/charge-rail.ts +2 -0
- package/templates/collections-agent/packages/agent-core/src/stubs/rail.ts +19 -2
- package/templates/collections-agent/packages/agent-core/src/types.ts +28 -0
- package/templates/collections-agent/packages/agent-core/test/approval.test.ts +36 -2
- package/templates/collections-agent/packages/agent-core/test/bundle.test.ts +85 -0
- package/templates/collections-agent/packages/agent-core/test/clock.test.ts +25 -0
- package/templates/collections-agent/packages/agent-core/test/engine.test.ts +73 -1
- package/templates/collections-agent/packages/agent-core/test/fixtures/staging-receipt-keys.json +18 -0
- package/templates/collections-agent/packages/agent-core/test/fixtures/staging-receipt.json +24 -0
- package/templates/collections-agent/packages/agent-core/test/helpers.ts +1 -1
- package/templates/collections-agent/packages/agent-core/test/manifest.test.ts +2 -2
- package/templates/collections-agent/packages/agent-core/test/receipt-verification.test.ts +316 -0
- package/templates/collections-agent/packages/agent-core/test/receivables.test.ts +51 -0
- package/templates/collections-agent/packages/agent-runtime/README.md +68 -0
- package/templates/collections-agent/packages/agent-runtime/bin.mjs +32 -0
- package/templates/collections-agent/packages/agent-runtime/package.json +23 -0
- package/templates/collections-agent/{agents/collections-agent → packages/agent-runtime}/src/adversarial.ts +29 -50
- package/templates/collections-agent/packages/agent-runtime/src/agent.ts +68 -0
- package/templates/collections-agent/packages/agent-runtime/src/channels/contact.ts +13 -0
- package/templates/collections-agent/packages/agent-runtime/src/channels/index.ts +72 -0
- package/templates/collections-agent/packages/agent-runtime/src/channels/rules.ts +120 -0
- package/templates/collections-agent/packages/agent-runtime/src/channels/types.ts +124 -0
- package/templates/collections-agent/packages/agent-runtime/src/channels/whatsapp/cloud-api.ts +358 -0
- package/templates/collections-agent/packages/agent-runtime/src/channels/whatsapp/emulator.ts +206 -0
- package/templates/collections-agent/packages/agent-runtime/src/channels/whatsapp/evidence.ts +109 -0
- package/templates/collections-agent/packages/agent-runtime/src/channels/whatsapp/index.ts +225 -0
- package/templates/collections-agent/packages/agent-runtime/src/channels/whatsapp/open.ts +143 -0
- package/templates/collections-agent/packages/agent-runtime/src/channels/whatsapp/present.ts +47 -0
- package/templates/collections-agent/packages/agent-runtime/src/channels/whatsapp/run.ts +113 -0
- package/templates/collections-agent/packages/agent-runtime/src/channels/whatsapp/session.ts +113 -0
- package/templates/collections-agent/packages/agent-runtime/src/cli.ts +98 -0
- package/templates/collections-agent/packages/agent-runtime/src/commands/check.ts +15 -0
- package/templates/collections-agent/packages/agent-runtime/src/commands/decide.ts +63 -0
- package/templates/collections-agent/packages/agent-runtime/src/commands/eval.ts +58 -0
- package/templates/collections-agent/packages/agent-runtime/src/commands/inspect.ts +100 -0
- package/templates/collections-agent/packages/agent-runtime/src/commands/poll-whatsapp.ts +317 -0
- package/templates/collections-agent/packages/agent-runtime/src/commands/poll.ts +144 -0
- package/templates/collections-agent/packages/agent-runtime/src/commands/reconcile.ts +42 -0
- package/templates/collections-agent/packages/agent-runtime/src/commands/rerun.ts +86 -0
- package/templates/collections-agent/packages/agent-runtime/src/commands/resume.ts +43 -0
- package/templates/collections-agent/packages/agent-runtime/src/commands/start-whatsapp.ts +131 -0
- package/templates/collections-agent/packages/agent-runtime/src/commands/start.ts +245 -0
- package/templates/collections-agent/packages/agent-runtime/src/commands/verify.ts +129 -0
- package/templates/collections-agent/packages/agent-runtime/src/commands/webhook.ts +39 -0
- package/templates/collections-agent/packages/agent-runtime/src/default-kit.ts +83 -0
- package/templates/collections-agent/packages/agent-runtime/src/index.ts +12 -0
- package/templates/collections-agent/packages/agent-runtime/src/inspect.ts +797 -0
- package/templates/collections-agent/packages/agent-runtime/src/kit.ts +206 -0
- package/templates/collections-agent/packages/agent-runtime/src/poll.ts +105 -0
- package/templates/{bills-agent/agents/bills-agent → collections-agent/packages/agent-runtime}/src/scenarios.ts +98 -26
- package/templates/collections-agent/packages/agent-runtime/src/setup.ts +229 -0
- package/templates/collections-agent/packages/agent-runtime/src/terminal.ts +154 -0
- package/templates/collections-agent/packages/agent-runtime/src/webhook.ts +131 -0
- package/templates/collections-agent/packages/agent-runtime/test/inspect.test.ts +336 -0
- package/templates/collections-agent/packages/agent-runtime/test/verify-cli.test.ts +127 -0
- package/templates/collections-agent/packages/agent-runtime/test/whatsapp-cloud-api.test.ts +232 -0
- package/templates/collections-agent/packages/agent-runtime/test/whatsapp-emulator.integration.test.ts +204 -0
- package/templates/collections-agent/packages/agent-runtime/test/whatsapp-evidence.test.ts +94 -0
- package/templates/collections-agent/packages/agent-runtime/test/whatsapp-rules.test.ts +174 -0
- package/templates/collections-agent/packages/agent-runtime/test/whatsapp-session.test.ts +135 -0
- package/templates/collections-agent/packages/agent-runtime/tsconfig.json +9 -0
- package/templates/collections-agent/vitest.config.ts +1 -1
- package/templates/hello-agent/LICENSE +21 -0
- package/templates/hello-agent/README.md +23 -0
- package/templates/hello-agent/_gitignore +10 -0
- package/templates/hello-agent/agents/hello-agent/.env.example +5 -0
- package/templates/hello-agent/agents/hello-agent/AGENTS.md +15 -0
- package/templates/hello-agent/agents/hello-agent/CLAUDE.md +15 -0
- package/templates/hello-agent/agents/hello-agent/README.md +33 -0
- package/templates/hello-agent/agents/hello-agent/SYSTEM_PROMPT.md +19 -0
- package/templates/hello-agent/agents/hello-agent/agent.yaml +19 -0
- package/templates/hello-agent/agents/hello-agent/evals/adversarial/beneficiary-swap.json +6 -0
- package/templates/hello-agent/agents/hello-agent/evals/adversarial/beneficiary-swap.transcript.jsonl +2 -0
- package/templates/hello-agent/agents/hello-agent/evals/adversarial/exfiltration.json +6 -0
- package/templates/hello-agent/agents/hello-agent/evals/adversarial/exfiltration.transcript.jsonl +2 -0
- package/templates/hello-agent/agents/hello-agent/evals/adversarial/false-authority.json +6 -0
- package/templates/hello-agent/agents/hello-agent/evals/adversarial/false-authority.transcript.jsonl +2 -0
- package/templates/hello-agent/agents/hello-agent/evals/adversarial/fractioning.json +6 -0
- package/templates/hello-agent/agents/hello-agent/evals/adversarial/fractioning.transcript.jsonl +2 -0
- package/templates/hello-agent/agents/hello-agent/evals/adversarial/model-total.json +6 -0
- package/templates/hello-agent/agents/hello-agent/evals/adversarial/model-total.transcript.jsonl +2 -0
- package/templates/hello-agent/agents/hello-agent/evals/adversarial/prompt-injection.json +6 -0
- package/templates/hello-agent/agents/hello-agent/evals/adversarial/prompt-injection.transcript.jsonl +2 -0
- package/templates/hello-agent/agents/hello-agent/evals/adversarial/webhook-replay.json +6 -0
- package/templates/hello-agent/agents/hello-agent/evals/eval.yaml +7 -0
- package/templates/hello-agent/agents/hello-agent/guardrails.json +8 -0
- package/templates/hello-agent/agents/hello-agent/mandate.example.json +17 -0
- package/templates/hello-agent/agents/hello-agent/package.json +19 -0
- package/templates/hello-agent/agents/hello-agent/runbook.md +10 -0
- package/templates/hello-agent/agents/hello-agent/scenarios/happy-path.json +6 -0
- package/templates/hello-agent/agents/hello-agent/scenarios/happy-path.transcript.jsonl +2 -0
- package/templates/hello-agent/agents/hello-agent/scenarios/prompt-injection.json +6 -0
- package/templates/hello-agent/agents/hello-agent/scenarios/prompt-injection.transcript.jsonl +2 -0
- package/templates/hello-agent/agents/hello-agent/src/bills.ts +23 -0
- package/templates/hello-agent/agents/hello-agent/src/kit.ts +33 -0
- package/templates/hello-agent/agents/hello-agent/tools.json +11 -0
- package/templates/hello-agent/agents/hello-agent/tsconfig.json +9 -0
- package/templates/hello-agent/package.json +30 -0
- package/templates/hello-agent/packages/agent-core/README.md +21 -0
- package/templates/hello-agent/packages/agent-core/package.json +24 -0
- package/templates/hello-agent/packages/agent-core/src/agent.ts +125 -0
- package/templates/hello-agent/packages/agent-core/src/api/charge-rail.ts +175 -0
- package/templates/hello-agent/packages/agent-core/src/api/client.ts +53 -0
- package/templates/hello-agent/packages/agent-core/src/api/mandate-status.ts +58 -0
- package/templates/hello-agent/packages/agent-core/src/api/rail.ts +117 -0
- package/templates/hello-agent/packages/agent-core/src/api/sandbox-payer.ts +58 -0
- package/templates/hello-agent/packages/agent-core/src/approval.ts +123 -0
- package/templates/hello-agent/packages/agent-core/src/bundle.ts +159 -0
- package/templates/hello-agent/packages/agent-core/src/channels.ts +140 -0
- package/templates/hello-agent/packages/agent-core/src/check.ts +253 -0
- package/templates/hello-agent/packages/agent-core/src/clock.ts +42 -0
- package/templates/hello-agent/packages/agent-core/src/engine.ts +885 -0
- package/templates/hello-agent/packages/agent-core/src/escalate.ts +85 -0
- package/templates/hello-agent/packages/agent-core/src/events.ts +40 -0
- package/templates/hello-agent/packages/agent-core/src/guardrails.ts +45 -0
- package/templates/hello-agent/packages/agent-core/src/hash.ts +62 -0
- package/templates/hello-agent/packages/agent-core/src/ids.ts +10 -0
- package/templates/hello-agent/packages/agent-core/src/index.ts +32 -0
- package/templates/hello-agent/packages/agent-core/src/mandate.ts +100 -0
- package/templates/hello-agent/packages/agent-core/src/manifest.ts +76 -0
- package/templates/hello-agent/packages/agent-core/src/providers/anthropic.ts +76 -0
- package/templates/hello-agent/packages/agent-core/src/providers/replay.ts +63 -0
- package/templates/hello-agent/packages/agent-core/src/providers/types.ts +39 -0
- package/templates/hello-agent/packages/agent-core/src/rail.ts +101 -0
- package/templates/hello-agent/packages/agent-core/src/receipt-verification.ts +401 -0
- package/templates/hello-agent/packages/agent-core/src/revocation.ts +30 -0
- package/templates/hello-agent/packages/agent-core/src/secrets.ts +30 -0
- package/templates/hello-agent/packages/agent-core/src/state/store.ts +307 -0
- package/templates/hello-agent/packages/agent-core/src/state-machine.ts +148 -0
- package/templates/hello-agent/packages/agent-core/src/stubs/charge-rail.ts +195 -0
- package/templates/hello-agent/packages/agent-core/src/stubs/mandate-status.ts +57 -0
- package/templates/hello-agent/packages/agent-core/src/stubs/rail.ts +141 -0
- package/templates/hello-agent/packages/agent-core/src/tools.ts +55 -0
- package/templates/hello-agent/packages/agent-core/src/types.ts +134 -0
- package/templates/hello-agent/packages/agent-core/test/approval.test.ts +117 -0
- package/templates/hello-agent/packages/agent-core/test/bundle.test.ts +85 -0
- package/templates/hello-agent/packages/agent-core/test/clock.test.ts +25 -0
- package/templates/hello-agent/packages/agent-core/test/engine.test.ts +596 -0
- package/templates/hello-agent/packages/agent-core/test/escalate.test.ts +42 -0
- package/templates/hello-agent/packages/agent-core/test/fixtures/staging-receipt-keys.json +18 -0
- package/templates/hello-agent/packages/agent-core/test/fixtures/staging-receipt.json +24 -0
- package/templates/hello-agent/packages/agent-core/test/helpers.ts +139 -0
- package/templates/hello-agent/packages/agent-core/test/mandate-status.test.ts +153 -0
- package/templates/hello-agent/packages/agent-core/test/manifest.test.ts +45 -0
- package/templates/hello-agent/packages/agent-core/test/receipt-verification.test.ts +316 -0
- package/templates/hello-agent/packages/agent-core/test/receivables.test.ts +316 -0
- package/templates/hello-agent/packages/agent-core/test/secrets.test.ts +28 -0
- package/templates/hello-agent/packages/agent-core/test/state-machine.test.ts +67 -0
- package/templates/hello-agent/packages/agent-core/test/transitions.type-test.ts +59 -0
- package/templates/hello-agent/packages/agent-core/tsconfig.json +10 -0
- package/templates/hello-agent/packages/agent-runtime/README.md +68 -0
- package/templates/hello-agent/packages/agent-runtime/bin.mjs +32 -0
- package/templates/hello-agent/packages/agent-runtime/package.json +23 -0
- package/templates/hello-agent/packages/agent-runtime/src/adversarial.ts +169 -0
- package/templates/hello-agent/packages/agent-runtime/src/agent.ts +68 -0
- package/templates/hello-agent/packages/agent-runtime/src/channels/contact.ts +13 -0
- package/templates/hello-agent/packages/agent-runtime/src/channels/index.ts +72 -0
- package/templates/hello-agent/packages/agent-runtime/src/channels/rules.ts +120 -0
- package/templates/hello-agent/packages/agent-runtime/src/channels/types.ts +124 -0
- package/templates/hello-agent/packages/agent-runtime/src/channels/whatsapp/cloud-api.ts +358 -0
- package/templates/hello-agent/packages/agent-runtime/src/channels/whatsapp/emulator.ts +206 -0
- package/templates/hello-agent/packages/agent-runtime/src/channels/whatsapp/evidence.ts +109 -0
- package/templates/hello-agent/packages/agent-runtime/src/channels/whatsapp/index.ts +225 -0
- package/templates/hello-agent/packages/agent-runtime/src/channels/whatsapp/open.ts +143 -0
- package/templates/hello-agent/packages/agent-runtime/src/channels/whatsapp/present.ts +47 -0
- package/templates/hello-agent/packages/agent-runtime/src/channels/whatsapp/run.ts +113 -0
- package/templates/hello-agent/packages/agent-runtime/src/channels/whatsapp/session.ts +113 -0
- package/templates/hello-agent/packages/agent-runtime/src/cli.ts +98 -0
- package/templates/hello-agent/packages/agent-runtime/src/commands/check.ts +15 -0
- package/templates/hello-agent/packages/agent-runtime/src/commands/decide.ts +63 -0
- package/templates/hello-agent/packages/agent-runtime/src/commands/eval.ts +58 -0
- package/templates/hello-agent/packages/agent-runtime/src/commands/inspect.ts +100 -0
- package/templates/hello-agent/packages/agent-runtime/src/commands/poll-whatsapp.ts +317 -0
- package/templates/hello-agent/packages/agent-runtime/src/commands/poll.ts +144 -0
- package/templates/hello-agent/packages/agent-runtime/src/commands/reconcile.ts +42 -0
- package/templates/hello-agent/packages/agent-runtime/src/commands/rerun.ts +86 -0
- package/templates/hello-agent/packages/agent-runtime/src/commands/resume.ts +43 -0
- package/templates/hello-agent/packages/agent-runtime/src/commands/start-whatsapp.ts +131 -0
- package/templates/hello-agent/packages/agent-runtime/src/commands/start.ts +245 -0
- package/templates/hello-agent/packages/agent-runtime/src/commands/verify.ts +129 -0
- package/templates/hello-agent/packages/agent-runtime/src/commands/webhook.ts +39 -0
- package/templates/hello-agent/packages/agent-runtime/src/default-kit.ts +83 -0
- package/templates/hello-agent/packages/agent-runtime/src/index.ts +12 -0
- package/templates/hello-agent/packages/agent-runtime/src/inspect.ts +797 -0
- package/templates/hello-agent/packages/agent-runtime/src/kit.ts +206 -0
- package/templates/hello-agent/packages/agent-runtime/src/poll.ts +105 -0
- package/templates/hello-agent/packages/agent-runtime/src/scenarios.ts +268 -0
- package/templates/hello-agent/packages/agent-runtime/src/setup.ts +229 -0
- package/templates/hello-agent/packages/agent-runtime/src/terminal.ts +154 -0
- package/templates/hello-agent/packages/agent-runtime/src/webhook.ts +131 -0
- package/templates/hello-agent/packages/agent-runtime/test/inspect.test.ts +336 -0
- package/templates/hello-agent/packages/agent-runtime/test/verify-cli.test.ts +127 -0
- package/templates/hello-agent/packages/agent-runtime/test/whatsapp-cloud-api.test.ts +232 -0
- package/templates/hello-agent/packages/agent-runtime/test/whatsapp-emulator.integration.test.ts +204 -0
- package/templates/hello-agent/packages/agent-runtime/test/whatsapp-evidence.test.ts +94 -0
- package/templates/hello-agent/packages/agent-runtime/test/whatsapp-rules.test.ts +174 -0
- package/templates/hello-agent/packages/agent-runtime/test/whatsapp-session.test.ts +135 -0
- package/templates/hello-agent/packages/agent-runtime/tsconfig.json +9 -0
- package/templates/hello-agent/tsconfig.base.json +16 -0
- package/templates/hello-agent/vitest.config.ts +12 -0
- package/templates/kits.lock.json +60 -12
- package/templates/supplier-payments-agent/LICENSE +21 -0
- package/templates/supplier-payments-agent/README.md +23 -0
- package/templates/supplier-payments-agent/_gitignore +10 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/.env.example +7 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/AGENTS.md +21 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/CLAUDE.md +21 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/README.md +118 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/SYSTEM_PROMPT.md +29 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/agent.yaml +26 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/evals/adversarial/batch-tampering.json +12 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/evals/adversarial/batch-tampering.transcript.jsonl +3 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/evals/adversarial/beneficiary-swap-mandate.json +9 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/evals/adversarial/beneficiary-swap.json +10 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/evals/adversarial/beneficiary-swap.transcript.jsonl +2 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/evals/adversarial/exfiltration.json +13 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/evals/adversarial/exfiltration.transcript.jsonl +3 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/evals/adversarial/false-authority.json +9 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/evals/adversarial/false-authority.transcript.jsonl +3 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/evals/adversarial/fractioning.json +15 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/evals/adversarial/fractioning.transcript.jsonl +6 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/evals/adversarial/model-total.json +10 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/evals/adversarial/model-total.transcript.jsonl +2 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/evals/adversarial/prompt-injection.json +9 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/evals/adversarial/prompt-injection.transcript.jsonl +2 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/evals/adversarial/webhook-replay.json +9 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/evals/eval.yaml +9 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/guardrails.json +15 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/mandate.example.json +70 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/package.json +26 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/runbook.md +19 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/scenarios/beneficiary-not-allowed.json +14 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/scenarios/beneficiary-not-allowed.transcript.jsonl +2 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/scenarios/cap-exceeded.json +12 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/scenarios/cap-exceeded.transcript.jsonl +2 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/scenarios/escalated-above-threshold.json +20 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/scenarios/escalated-above-threshold.transcript.jsonl +7 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/scenarios/happy-path.json +19 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/scenarios/happy-path.transcript.jsonl +3 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/scenarios/mandate-revoked.json +21 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/scenarios/mandate-revoked.transcript.jsonl +9 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/scenarios/partial-batch-failure.json +21 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/scenarios/partial-batch-failure.transcript.jsonl +3 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/scenarios/prompt-injection.json +12 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/scenarios/prompt-injection.transcript.jsonl +2 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/src/kit.ts +176 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/src/modules/batch-payout.ts +345 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/src/modules/pix-out.ts +118 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/src/payables.ts +76 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/test/adversarial.test.ts +53 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/test/batch.test.ts +384 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/test/check.test.ts +109 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/test/scenarios.test.ts +81 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/tools.json +53 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/tsconfig.json +9 -0
- package/templates/supplier-payments-agent/package.json +36 -0
- package/templates/supplier-payments-agent/packages/agent-core/README.md +21 -0
- package/templates/supplier-payments-agent/packages/agent-core/package.json +24 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/agent.ts +125 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/api/charge-rail.ts +175 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/api/client.ts +53 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/api/mandate-status.ts +58 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/api/rail.ts +117 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/api/sandbox-payer.ts +58 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/approval.ts +123 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/bundle.ts +159 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/channels.ts +140 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/check.ts +253 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/clock.ts +42 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/engine.ts +885 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/escalate.ts +85 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/events.ts +40 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/guardrails.ts +45 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/hash.ts +62 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/ids.ts +10 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/index.ts +32 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/mandate.ts +100 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/manifest.ts +76 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/providers/anthropic.ts +76 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/providers/replay.ts +63 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/providers/types.ts +39 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/rail.ts +101 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/receipt-verification.ts +401 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/revocation.ts +30 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/secrets.ts +30 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/state/store.ts +307 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/state-machine.ts +148 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/stubs/charge-rail.ts +195 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/stubs/mandate-status.ts +57 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/stubs/rail.ts +141 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/tools.ts +55 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/types.ts +134 -0
- package/templates/supplier-payments-agent/packages/agent-core/test/approval.test.ts +117 -0
- package/templates/supplier-payments-agent/packages/agent-core/test/bundle.test.ts +85 -0
- package/templates/supplier-payments-agent/packages/agent-core/test/clock.test.ts +25 -0
- package/templates/supplier-payments-agent/packages/agent-core/test/engine.test.ts +596 -0
- package/templates/supplier-payments-agent/packages/agent-core/test/escalate.test.ts +42 -0
- package/templates/supplier-payments-agent/packages/agent-core/test/fixtures/staging-receipt-keys.json +18 -0
- package/templates/supplier-payments-agent/packages/agent-core/test/fixtures/staging-receipt.json +24 -0
- package/templates/supplier-payments-agent/packages/agent-core/test/helpers.ts +139 -0
- package/templates/supplier-payments-agent/packages/agent-core/test/mandate-status.test.ts +153 -0
- package/templates/supplier-payments-agent/packages/agent-core/test/manifest.test.ts +45 -0
- package/templates/supplier-payments-agent/packages/agent-core/test/receipt-verification.test.ts +316 -0
- package/templates/supplier-payments-agent/packages/agent-core/test/receivables.test.ts +316 -0
- package/templates/supplier-payments-agent/packages/agent-core/test/secrets.test.ts +28 -0
- package/templates/supplier-payments-agent/packages/agent-core/test/state-machine.test.ts +67 -0
- package/templates/supplier-payments-agent/packages/agent-core/test/transitions.type-test.ts +59 -0
- package/templates/supplier-payments-agent/packages/agent-core/tsconfig.json +10 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/README.md +68 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/bin.mjs +32 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/package.json +23 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/adversarial.ts +169 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/agent.ts +68 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/channels/contact.ts +13 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/channels/index.ts +72 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/channels/rules.ts +120 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/channels/types.ts +124 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/channels/whatsapp/cloud-api.ts +358 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/channels/whatsapp/emulator.ts +206 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/channels/whatsapp/evidence.ts +109 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/channels/whatsapp/index.ts +225 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/channels/whatsapp/open.ts +143 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/channels/whatsapp/present.ts +47 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/channels/whatsapp/run.ts +113 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/channels/whatsapp/session.ts +113 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/cli.ts +98 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/commands/check.ts +15 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/commands/decide.ts +63 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/commands/eval.ts +58 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/commands/inspect.ts +100 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/commands/poll-whatsapp.ts +317 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/commands/poll.ts +144 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/commands/reconcile.ts +42 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/commands/rerun.ts +86 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/commands/resume.ts +43 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/commands/start-whatsapp.ts +131 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/commands/start.ts +245 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/commands/verify.ts +129 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/commands/webhook.ts +39 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/default-kit.ts +83 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/index.ts +12 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/inspect.ts +797 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/kit.ts +206 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/poll.ts +105 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/scenarios.ts +268 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/setup.ts +229 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/terminal.ts +154 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/webhook.ts +131 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/test/inspect.test.ts +336 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/test/verify-cli.test.ts +127 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/test/whatsapp-cloud-api.test.ts +232 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/test/whatsapp-emulator.integration.test.ts +204 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/test/whatsapp-evidence.test.ts +94 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/test/whatsapp-rules.test.ts +174 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/test/whatsapp-session.test.ts +135 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/tsconfig.json +9 -0
- package/templates/supplier-payments-agent/tsconfig.base.json +16 -0
- package/templates/supplier-payments-agent/vitest.config.ts +12 -0
- package/templates/bills-agent/agents/bills-agent/channels/terminal/index.ts +0 -108
- package/templates/bills-agent/agents/bills-agent/src/commands/approve.ts +0 -9
- package/templates/bills-agent/agents/bills-agent/src/commands/check.ts +0 -13
- package/templates/bills-agent/agents/bills-agent/src/commands/consent.ts +0 -26
- package/templates/bills-agent/agents/bills-agent/src/commands/decide.ts +0 -45
- package/templates/bills-agent/agents/bills-agent/src/commands/deny.ts +0 -7
- package/templates/bills-agent/agents/bills-agent/src/commands/eval.ts +0 -37
- package/templates/bills-agent/agents/bills-agent/src/commands/reconcile.ts +0 -38
- package/templates/bills-agent/agents/bills-agent/src/commands/rerun.ts +0 -65
- package/templates/bills-agent/agents/bills-agent/src/commands/resume.ts +0 -30
- package/templates/bills-agent/agents/bills-agent/src/main.ts +0 -185
- package/templates/collections-agent/agents/collections-agent/channels/terminal/index.ts +0 -178
- package/templates/collections-agent/agents/collections-agent/src/commands/approve.ts +0 -10
- package/templates/collections-agent/agents/collections-agent/src/commands/check.ts +0 -13
- package/templates/collections-agent/agents/collections-agent/src/commands/decide.ts +0 -48
- package/templates/collections-agent/agents/collections-agent/src/commands/deny.ts +0 -7
- package/templates/collections-agent/agents/collections-agent/src/commands/eval.ts +0 -39
- package/templates/collections-agent/agents/collections-agent/src/commands/poll.ts +0 -35
- package/templates/collections-agent/agents/collections-agent/src/commands/reconcile.ts +0 -38
- package/templates/collections-agent/agents/collections-agent/src/commands/rerun.ts +0 -55
- package/templates/collections-agent/agents/collections-agent/src/commands/resume.ts +0 -30
- package/templates/collections-agent/agents/collections-agent/src/commands/webhook.ts +0 -36
- package/templates/collections-agent/agents/collections-agent/src/main.ts +0 -193
- package/templates/collections-agent/agents/collections-agent/src/setup.ts +0 -250
|
@@ -2,7 +2,8 @@ import { existsSync, mkdtempSync, readFileSync, readdirSync } from "node:fs";
|
|
|
2
2
|
import { tmpdir } from "node:os";
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
import { describe, expect, it } from "vitest";
|
|
5
|
-
import { checkScenario, listScenarios, loadScenario, runScenario, type ScenarioRun } from "
|
|
5
|
+
import { checkScenario, listScenarios, loadScenario, runScenario, type ScenarioRun } from "@codespar/agent-runtime";
|
|
6
|
+
import { agent } from "../src/kit.js";
|
|
6
7
|
|
|
7
8
|
const runsDir = mkdtempSync(join(tmpdir(), "bills-runs-"));
|
|
8
9
|
|
|
@@ -10,14 +11,14 @@ describe("section 12: scenario packs, on the replay provider", () => {
|
|
|
10
11
|
const required = ["happy-path", "cap-exceeded", "beneficiary-not-allowed", "prompt-injection", "escalated-above-threshold", "mandate-revoked"];
|
|
11
12
|
|
|
12
13
|
it("ships every scenario the spec asks for", () => {
|
|
13
|
-
for (const name of required) expect(listScenarios()).toContain(name);
|
|
14
|
+
for (const name of required) expect(listScenarios(agent)).toContain(name);
|
|
14
15
|
});
|
|
15
16
|
|
|
16
17
|
for (const name of required) {
|
|
17
|
-
const scenario = loadScenario(name);
|
|
18
|
+
const scenario = loadScenario(agent, name);
|
|
18
19
|
for (const mode of scenario.modes) {
|
|
19
20
|
it(`${name} [${mode}] ends in the states the pack declares`, async () => {
|
|
20
|
-
const run = await runScenario(scenario, { mode, runsDir });
|
|
21
|
+
const run = await runScenario(agent, scenario, { mode, runsDir });
|
|
21
22
|
const check = checkScenario(scenario, run);
|
|
22
23
|
expect(check.failures).toEqual([]);
|
|
23
24
|
expect(check.ok).toBe(true);
|
|
@@ -36,9 +37,9 @@ describe("section 12: scenario packs, on the replay provider", () => {
|
|
|
36
37
|
}
|
|
37
38
|
|
|
38
39
|
it("happy-path: the same trail and the same receipts in human and in mandate", async () => {
|
|
39
|
-
const scenario = loadScenario("happy-path");
|
|
40
|
-
const human = await runScenario(scenario, { mode: "human", runsDir });
|
|
41
|
-
const mandate = await runScenario(scenario, { mode: "mandate", runsDir });
|
|
40
|
+
const scenario = loadScenario(agent, "happy-path");
|
|
41
|
+
const human = await runScenario(agent, scenario, { mode: "human", runsDir });
|
|
42
|
+
const mandate = await runScenario(agent, scenario, { mode: "mandate", runsDir });
|
|
42
43
|
expect(human.executions.map((e) => e.trail)).toEqual(mandate.executions.map((e) => e.trail));
|
|
43
44
|
expect(normalizeReceipts(human)).toEqual(normalizeReceipts(mandate));
|
|
44
45
|
// In human, the artifact is a person's; in mandate the person still decided because the amount escalated.
|
|
@@ -51,9 +52,9 @@ describe("section 12: scenario packs, on the replay provider", () => {
|
|
|
51
52
|
|
|
52
53
|
it("nothing reaches executing without an approval artifact carrying its items_hash", async () => {
|
|
53
54
|
for (const name of required) {
|
|
54
|
-
const scenario = loadScenario(name);
|
|
55
|
+
const scenario = loadScenario(agent, name);
|
|
55
56
|
for (const mode of scenario.modes) {
|
|
56
|
-
const run = await runScenario(scenario, { mode, runsDir });
|
|
57
|
+
const run = await runScenario(agent, scenario, { mode, runsDir });
|
|
57
58
|
const approvalPath = join(run.bundle_dir, "approval.json");
|
|
58
59
|
const artifacts = existsSync(approvalPath) ? (JSON.parse(readFileSync(approvalPath, "utf8")) as Array<{ execution_id: string; items_hash: string }>) : [];
|
|
59
60
|
for (const e of run.executions) {
|
|
@@ -7,20 +7,23 @@
|
|
|
7
7
|
"type": "module",
|
|
8
8
|
"workspaces": [
|
|
9
9
|
"packages/agent-core",
|
|
10
|
+
"packages/agent-runtime",
|
|
10
11
|
"agents/bills-agent"
|
|
11
12
|
],
|
|
12
13
|
"scripts": {
|
|
13
14
|
"start": "npm start --workspace=agents/bills-agent --",
|
|
14
15
|
"check": "npm run check --workspaces --if-present --",
|
|
15
16
|
"test": "vitest run --pool=forks --maxWorkers=1",
|
|
16
|
-
"typecheck": "tsc --noEmit -p packages/agent-core/tsconfig.json && tsc --noEmit -p agents/bills-agent/tsconfig.json",
|
|
17
|
+
"typecheck": "tsc --noEmit -p packages/agent-core/tsconfig.json && tsc --noEmit -p packages/agent-runtime/tsconfig.json && tsc --noEmit -p agents/bills-agent/tsconfig.json",
|
|
17
18
|
"approve": "npm run approve --workspace=agents/bills-agent --",
|
|
18
19
|
"consent": "npm run consent --workspace=agents/bills-agent --",
|
|
19
20
|
"deny": "npm run deny --workspace=agents/bills-agent --",
|
|
20
21
|
"eval": "npm run eval --workspace=agents/bills-agent --",
|
|
22
|
+
"inspect": "npm run inspect --workspace=agents/bills-agent --",
|
|
21
23
|
"reconcile": "npm run reconcile --workspace=agents/bills-agent --",
|
|
22
24
|
"rerun": "npm run rerun --workspace=agents/bills-agent --",
|
|
23
|
-
"resume": "npm run resume --workspace=agents/bills-agent --"
|
|
25
|
+
"resume": "npm run resume --workspace=agents/bills-agent --",
|
|
26
|
+
"verify": "npm run verify --workspace=agents/bills-agent --"
|
|
24
27
|
},
|
|
25
28
|
"devDependencies": {
|
|
26
29
|
"@types/node": "22.20.4",
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
The primitives every CodeSpar starter-kit agent inherits (spec v5.1.1, section 4): the execution state machine, the approval artifact, the `agent.yaml` manifest, `escalate_above`, `actor`, local state in SQLite, the proof bundle, the rail contract and the two providers.
|
|
4
4
|
|
|
5
|
+
This package is the decisions. The RUNNER around them — the terminal channel, `codespar-agent start|consent|approve|deny|resume|rerun|reconcile|poll|webhook|check|eval`, the setup that wires this package to an agent directory, and the scenario and adversarial runners — is [`@codespar/agent-runtime`](../agent-runtime), which depends on this one and is what an agent's `package.json` scripts call (#13). Nothing here knows an agent's name.
|
|
6
|
+
|
|
5
7
|
## The state machine, and what the types do and do not prove
|
|
6
8
|
|
|
7
9
|
`transition(execution, to, input)` accepts only a `to` that the table in `state-machine.ts` lists for `execution.state`. On a **narrowed** value (`Execution<"drafted">`, `Execution<"executing">`, ...) a transition outside the table is a compile error, and `test/transitions.type-test.ts` keeps that true with `@ts-expect-error` lines that `tsc` refuses to leave unused. An **un-narrowed** `Execution` (the union, which is what a row read back from SQLite is) compiles for any target; the engine narrows with casts at its call sites. So the guard that always holds is the runtime one: `transition()` throws `IllegalTransitionError` on any pair the table does not list, whatever the static type said. The type test proves the table is closed; the runtime check enforces it.
|
|
@@ -79,10 +79,12 @@ export class CodeSparChargeRail implements PaymentRail {
|
|
|
79
79
|
|
|
80
80
|
async pay(payment: RailPayment): Promise<RailOutcome> {
|
|
81
81
|
if (!payment.due_date) return { status: "failed", code: "due_date_required", message: "a receivable needs a due_date; the immediate Pix charge cannot be read back or replayed" };
|
|
82
|
+
if (!payment.consumer_id) return { status: "failed", code: "consumer_id_required", message: "a receivable settles into the principal's account; the policy names no consumer_id" };
|
|
82
83
|
let view: ChargeView;
|
|
83
84
|
try {
|
|
84
85
|
view = (await this.api.post("/v1/charges", {
|
|
85
86
|
body: {
|
|
87
|
+
consumer_id: payment.consumer_id,
|
|
86
88
|
amount: payment.amount_minor / 100,
|
|
87
89
|
currency: payment.currency,
|
|
88
90
|
method: "boleto",
|
|
@@ -108,15 +110,32 @@ export class CodeSparChargeRail implements PaymentRail {
|
|
|
108
110
|
return outcome.status === "in_flight" ? { status: "uncertain", code: "issuance_unconfirmed", message: "the create answered no readable state" } : outcome;
|
|
109
111
|
}
|
|
110
112
|
|
|
111
|
-
|
|
113
|
+
/**
|
|
114
|
+
* By the charge id when the create handed one back; by our idempotency key only when it did not (the create's answer was lost).
|
|
115
|
+
* The route's doc says the read accepts the caller's key as the id; on staging (2026-09-23) it answered `charge_not_found` for
|
|
116
|
+
* the key and the charge for the id, so the id comes first and the key is the fallback, not the other way round.
|
|
117
|
+
*/
|
|
118
|
+
async lookup(attemptId: string, _payment: RailPayment, transactionId?: string): Promise<RailLookup> {
|
|
119
|
+
const byId = transactionId ? await this.read(transactionId) : { kind: "missing" as const };
|
|
120
|
+
if (byId.kind === "view") return outcomeOf(byId.view);
|
|
121
|
+
if (byId.kind === "in_flight") return { status: "in_flight" };
|
|
122
|
+
if (byId.kind === "uncertain") return byId.outcome;
|
|
123
|
+
const byKey = await this.read(attemptId);
|
|
124
|
+
if (byKey.kind === "view") return outcomeOf(byKey.view);
|
|
125
|
+
if (byKey.kind === "in_flight") return { status: "in_flight" };
|
|
126
|
+
if (byKey.kind === "uncertain") return byKey.outcome;
|
|
127
|
+
return undefined;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
private async read(chargeRef: string): Promise<{ kind: "view"; view: ChargeView } | { kind: "missing" } | { kind: "in_flight" } | { kind: "uncertain"; outcome: Extract<RailOutcome, { status: "uncertain" }> }> {
|
|
112
131
|
try {
|
|
113
|
-
const view = (await this.api.get("/v1/charges/{chargeId}", { path: { chargeId:
|
|
114
|
-
return
|
|
132
|
+
const view = (await this.api.get("/v1/charges/{chargeId}", { path: { chargeId: chargeRef } })) as ChargeView;
|
|
133
|
+
return { kind: "view", view };
|
|
115
134
|
} catch (err) {
|
|
116
135
|
const failure = describeApiError(err);
|
|
117
|
-
if (failure.status === 404) return
|
|
118
|
-
if (failure.status === 409) return {
|
|
119
|
-
return { status: "uncertain", code: failure.code, message: failure.message };
|
|
136
|
+
if (failure.status === 404) return { kind: "missing" };
|
|
137
|
+
if (failure.status === 409) return { kind: "in_flight" };
|
|
138
|
+
return { kind: "uncertain", outcome: { status: "uncertain", code: failure.code, message: failure.message } };
|
|
120
139
|
}
|
|
121
140
|
}
|
|
122
141
|
|
|
@@ -133,6 +152,8 @@ export class CodeSparChargeRail implements PaymentRail {
|
|
|
133
152
|
payment: { amount_minor: view.amount_minor, payee: null, attempt_id: chargeId, money_moved: false, sandbox: true, at: raw.settled_at ?? new Date().toISOString() },
|
|
134
153
|
chain: null,
|
|
135
154
|
receipt_sig: null,
|
|
155
|
+
receipt_sig_ed25519: null,
|
|
156
|
+
receipt_sig_kid: null,
|
|
136
157
|
actor,
|
|
137
158
|
raw: view,
|
|
138
159
|
};
|
|
@@ -18,6 +18,16 @@ import type { PaymentRail, RailLookup, RailOutcome, RailPayment, RailReceipt } f
|
|
|
18
18
|
import type { Actor } from "../types.js";
|
|
19
19
|
import { describeApiError, isUncertain } from "./client.js";
|
|
20
20
|
|
|
21
|
+
/** The asymmetric seal as the API serves it, or nulls when this deployment
|
|
22
|
+
* does not serve one. Never throws on a shape it does not recognise: a
|
|
23
|
+
* receipt is evidence of a payment that already happened, and refusing to
|
|
24
|
+
* record it over an unexpected field would trade the record for the proof. */
|
|
25
|
+
function readEd25519Seal(body: unknown): { receipt_sig_ed25519: string | null; receipt_sig_kid: string | null } {
|
|
26
|
+
const r = body as { receipt_sig_ed25519?: unknown; receipt_sig_kid?: unknown };
|
|
27
|
+
const str = (v: unknown): string | null => (typeof v === "string" && v.length > 0 ? v : null);
|
|
28
|
+
return { receipt_sig_ed25519: str(r.receipt_sig_ed25519), receipt_sig_kid: str(r.receipt_sig_kid) };
|
|
29
|
+
}
|
|
30
|
+
|
|
21
31
|
export class CodeSparRail implements PaymentRail {
|
|
22
32
|
readonly name = "codespar" as const;
|
|
23
33
|
|
|
@@ -89,6 +99,12 @@ export class CodeSparRail implements PaymentRail {
|
|
|
89
99
|
},
|
|
90
100
|
chain: r.chain,
|
|
91
101
|
receipt_sig: r.receipt_sig,
|
|
102
|
+
// ent#1633 landed after `@codespar/sdk@0.16.6` was generated, so the
|
|
103
|
+
// typed response does not carry these two yet. Read off the body
|
|
104
|
+
// defensively rather than pinning a new SDK for two nullable strings:
|
|
105
|
+
// a deployment that predates the change answers null, which is the
|
|
106
|
+
// same answer the columns hold and reads as `unsigned`.
|
|
107
|
+
...readEd25519Seal(r),
|
|
92
108
|
actor,
|
|
93
109
|
raw: r,
|
|
94
110
|
};
|
|
@@ -6,11 +6,15 @@
|
|
|
6
6
|
* project's triggers, and every record it leaves carries `simulated: true`
|
|
7
7
|
* plus `settled_against: "sandbox_fixture"`. No money moves anywhere. A
|
|
8
8
|
* live-environment key is refused with `sandbox_pay_not_permitted` before
|
|
9
|
-
* anything is read.
|
|
10
|
-
*
|
|
9
|
+
* anything is read. Since `@codespar/sdk@0.16.5` the route is in the SDK's
|
|
10
|
+
* OpenAPI document, so this is the client's own typed call (same base URL,
|
|
11
|
+
* key and project header as every other call); until 0.16.4 it was a plain
|
|
12
|
+
* `fetch`, see docs/OPEN_QUESTIONS.md section 31c. The key is checked for
|
|
13
|
+
* the `csk_test_` prefix before a client exists, like every other call.
|
|
11
14
|
*/
|
|
12
|
-
import
|
|
13
|
-
import {
|
|
15
|
+
import { ApiClient } from "@codespar/sdk";
|
|
16
|
+
import type { ApiFailure } from "./client.js";
|
|
17
|
+
import { createCodeSparClient, describeApiError } from "./client.js";
|
|
14
18
|
|
|
15
19
|
export interface SandboxPaidState {
|
|
16
20
|
charge_id: string;
|
|
@@ -32,12 +36,21 @@ export interface SandboxPaidState {
|
|
|
32
36
|
|
|
33
37
|
export type SandboxPayResult = { ok: true; state: SandboxPaidState } | { ok: false; failure: ApiFailure };
|
|
34
38
|
|
|
35
|
-
|
|
39
|
+
/** Where the payer route lives when no client exists yet: the same three things `createCodeSparClient` takes. */
|
|
40
|
+
export interface SandboxPayerTarget {
|
|
41
|
+
apiKey: string | undefined;
|
|
42
|
+
baseUrl?: string | undefined;
|
|
43
|
+
projectId?: string | undefined;
|
|
44
|
+
timeoutMs?: number;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export async function paySandboxCharge(target: ApiClient | SandboxPayerTarget, chargeRef: string, amountMinor?: number): Promise<SandboxPayResult> {
|
|
48
|
+
const api = target instanceof ApiClient ? target : createCodeSparClient(target);
|
|
36
49
|
try {
|
|
37
|
-
const state =
|
|
50
|
+
const state = await api.post("/v1/test/charges/{chargeId}/pay", {
|
|
38
51
|
path: { chargeId: chargeRef },
|
|
39
52
|
body: amountMinor !== undefined ? { amount_minor: amountMinor } : {},
|
|
40
|
-
}
|
|
53
|
+
});
|
|
41
54
|
return { ok: true, state };
|
|
42
55
|
} catch (err) {
|
|
43
56
|
return { ok: false, failure: describeApiError(err) };
|
|
@@ -13,7 +13,7 @@ import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "n
|
|
|
13
13
|
import { dirname, join } from "node:path";
|
|
14
14
|
import { canonicalJson, hexEqual, hmacSha256Hex, itemsHash } from "./hash.js";
|
|
15
15
|
import type { Execution } from "./state-machine.js";
|
|
16
|
-
import type { Actor, ApprovalArtifact, EscalationTrigger } from "./types.js";
|
|
16
|
+
import type { Actor, ApprovalArtifact, EscalationTrigger, ExecutionBatch } from "./types.js";
|
|
17
17
|
import { newId } from "./ids.js";
|
|
18
18
|
|
|
19
19
|
export const APPROVAL_KEY_ID = "local-dev-stub";
|
|
@@ -74,6 +74,10 @@ export function createApprovalArtifact(signer: ApprovalSigner, input: CreateAppr
|
|
|
74
74
|
mandate: execution.mandate,
|
|
75
75
|
items: execution.items,
|
|
76
76
|
items_hash: itemsHash(execution.items),
|
|
77
|
+
// The SET this line belongs to, when it belongs to one. Omitted — never
|
|
78
|
+
// null — on an execution that is not part of a batch, so the payload a
|
|
79
|
+
// bills-agent artifact signs is unchanged by this field existing.
|
|
80
|
+
...(execution.batch ? { batch: execution.batch } : {}),
|
|
77
81
|
...(input.escalation ? { escalation: input.escalation } : {}),
|
|
78
82
|
actor: input.actor,
|
|
79
83
|
};
|
|
@@ -85,7 +89,13 @@ export function createApprovalArtifact(signer: ApprovalSigner, input: CreateAppr
|
|
|
85
89
|
|
|
86
90
|
export type ApprovalCheck =
|
|
87
91
|
| { ok: true }
|
|
88
|
-
| { ok: false; problem: "signature_invalid" | "items_hash_mismatch" | "expired" | "wrong_execution" | "wrong_mandate" };
|
|
92
|
+
| { ok: false; problem: "signature_invalid" | "items_hash_mismatch" | "expired" | "wrong_execution" | "wrong_mandate" | "batch_mismatch" };
|
|
93
|
+
|
|
94
|
+
/** Two batch bindings are the same binding, or one is absent and so is the other. */
|
|
95
|
+
function sameBatch(a: ExecutionBatch | undefined, b: ExecutionBatch | undefined): boolean {
|
|
96
|
+
if (a === undefined || b === undefined) return a === b;
|
|
97
|
+
return a.ref === b.ref && a.batch_hash === b.batch_hash && a.index === b.index && a.count === b.count;
|
|
98
|
+
}
|
|
89
99
|
|
|
90
100
|
/**
|
|
91
101
|
* The rule that makes the artifact proof: before `executing`, recompute the
|
|
@@ -104,6 +114,10 @@ export function checkApprovalArtifact(
|
|
|
104
114
|
return { ok: false, problem: "wrong_mandate" };
|
|
105
115
|
}
|
|
106
116
|
if (itemsHash(execution.items) !== artifact.items_hash) return { ok: false, problem: "items_hash_mismatch" };
|
|
117
|
+
// The line's own list is attested by the hash above; this is the list the
|
|
118
|
+
// line was one OF. An execution that gained, lost or moved its place in a
|
|
119
|
+
// batch after approval is not the one that was approved.
|
|
120
|
+
if (!sameBatch(artifact.batch, execution.batch)) return { ok: false, problem: "batch_mismatch" };
|
|
107
121
|
if (new Date(artifact.expires_at).getTime() <= now.getTime()) return { ok: false, problem: "expired" };
|
|
108
122
|
return { ok: true };
|
|
109
123
|
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* payee keys are masked the way a bank statement masks them.
|
|
5
5
|
*/
|
|
6
6
|
import { appendFileSync, existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
7
|
-
import { join } from "node:path";
|
|
7
|
+
import { basename, join } from "node:path";
|
|
8
8
|
import type { Mandate } from "./mandate.js";
|
|
9
9
|
import type { RailReceipt } from "./rail.js";
|
|
10
10
|
import type { ApprovalArtifact } from "./types.js";
|
|
@@ -47,6 +47,29 @@ export class ProofBundle {
|
|
|
47
47
|
appendFileSync(join(this.dir, "events.jsonl"), JSON.stringify(event) + "\n");
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
+
/**
|
|
51
|
+
* The conversation, when the run had one: every message in and out of a
|
|
52
|
+
* channel, in order, with what the channel did with it. Separate from the
|
|
53
|
+
* transcript, which is the MODEL's side, because on a channel the two are
|
|
54
|
+
* not the same thing — a message the channel refused never reached the
|
|
55
|
+
* person, and the QR and the copy-and-paste were sent by the runner.
|
|
56
|
+
*
|
|
57
|
+
* It carries no contact in the clear: the channel masks it before it gets
|
|
58
|
+
* here, because the bundle travels.
|
|
59
|
+
*/
|
|
60
|
+
channel(line: Record<string, unknown>): void {
|
|
61
|
+
appendFileSync(join(this.dir, "channel.jsonl"), JSON.stringify(line) + "\n");
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
readChannel(): Record<string, unknown>[] {
|
|
65
|
+
const path = join(this.dir, "channel.jsonl");
|
|
66
|
+
if (!existsSync(path)) return [];
|
|
67
|
+
return readFileSync(path, "utf8")
|
|
68
|
+
.split("\n")
|
|
69
|
+
.filter(Boolean)
|
|
70
|
+
.map((l) => JSON.parse(l) as Record<string, unknown>);
|
|
71
|
+
}
|
|
72
|
+
|
|
50
73
|
readEvents(): Record<string, unknown>[] {
|
|
51
74
|
const path = join(this.dir, "events.jsonl");
|
|
52
75
|
if (!existsSync(path)) return [];
|
|
@@ -74,11 +97,34 @@ export class ProofBundle {
|
|
|
74
97
|
writeFileSync(join(this.dir, "mandate.snapshot.json"), JSON.stringify({ ...safe, beneficiaries: safe.beneficiaries.map((b) => ({ ...b, payee: maskPayee(b.payee) })), merchant_allowlist: safe.merchant_allowlist.map(maskPayee) }, null, 2) + "\n");
|
|
75
98
|
}
|
|
76
99
|
|
|
100
|
+
/** Returns the path INSIDE the bundle (`receipts/<id>.json`): a bundle travels, and an absolute path names the machine that wrote it. */
|
|
77
101
|
receipt(receipt: RailReceipt): string {
|
|
78
|
-
const
|
|
102
|
+
const relative = join("receipts", `${receipt.receipt_id}.json`);
|
|
79
103
|
const { raw: _raw, ...safe } = receipt;
|
|
80
|
-
writeFileSync(
|
|
81
|
-
return
|
|
104
|
+
writeFileSync(join(this.dir, relative), JSON.stringify({ ...safe, payment: { ...safe.payment, payee: safe.payment.payee ? maskPayee(safe.payment.payee) : null } }, null, 2) + "\n");
|
|
105
|
+
return relative;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** The masked mandate as it stood when the run started. Absent on a bundle whose run never got that far. */
|
|
109
|
+
readMandateSnapshot(): Record<string, unknown> | undefined {
|
|
110
|
+
const path = join(this.dir, "mandate.snapshot.json");
|
|
111
|
+
return existsSync(path) ? (JSON.parse(readFileSync(path, "utf8")) as Record<string, unknown>) : undefined;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** One receipt by its file name, as `listReceipts()` returns it. */
|
|
115
|
+
readReceipt(file: string): Record<string, unknown> | undefined {
|
|
116
|
+
const path = join(this.dir, "receipts", basename(file));
|
|
117
|
+
return existsSync(path) ? (JSON.parse(readFileSync(path, "utf8")) as Record<string, unknown>) : undefined;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Section 11: `verify.json` is the output of `codespar audit replay`, which
|
|
122
|
+
* is not a registered command of the CLI, so nothing here writes it and
|
|
123
|
+
* nothing here reimplements the hash-chain check. The reader exists so a
|
|
124
|
+
* bundle that gains one later is noticed rather than ignored.
|
|
125
|
+
*/
|
|
126
|
+
hasVerify(): boolean {
|
|
127
|
+
return existsSync(join(this.dir, "verify.json"));
|
|
82
128
|
}
|
|
83
129
|
|
|
84
130
|
listReceipts(): string[] {
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The channels an agent can be reached on, and the one artifact an agent
|
|
3
|
+
* ships per channel.
|
|
4
|
+
*
|
|
5
|
+
* The NAMES live here because `agent.yaml` declares them and `npm run check`
|
|
6
|
+
* has to confirm the declaration against what the agent ships; the BEHAVIOUR
|
|
7
|
+
* lives in `@codespar/agent-runtime`, which owns the runner. That split is
|
|
8
|
+
* the same one `tools.json` and `guardrails.json` already have: the core
|
|
9
|
+
* owns the shape, the runtime owns what happens.
|
|
10
|
+
*
|
|
11
|
+
* `terminal` is every agent's: `npm start` opens it and needs no account.
|
|
12
|
+
* `whatsapp` is the second channel, and an agent that declares it ships the
|
|
13
|
+
* conversations the local Cloud API emulator drives, under
|
|
14
|
+
* `channels/whatsapp/`.
|
|
15
|
+
*/
|
|
16
|
+
import { z } from "zod";
|
|
17
|
+
|
|
18
|
+
export const CHANNELS = ["terminal", "whatsapp"] as const;
|
|
19
|
+
export type ChannelName = (typeof CHANNELS)[number];
|
|
20
|
+
|
|
21
|
+
/** E.164, the only contact shape WhatsApp addresses. */
|
|
22
|
+
export const E164 = /^\+[1-9]\d{6,14}$/;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* A scripted conversation, which is what an agent ships for a channel whose
|
|
26
|
+
* other side is a person rather than a keyboard.
|
|
27
|
+
*
|
|
28
|
+
* It exists for two readers. A local emulator of the Cloud API drives it with
|
|
29
|
+
* no Meta account, which is what makes the WhatsApp gate runnable in the CI;
|
|
30
|
+
* and `npm run check` parses it, so a conversation that no longer names a
|
|
31
|
+
* contact or an agreement fails the manifest gate instead of failing a run.
|
|
32
|
+
*
|
|
33
|
+
* It scripts ONE side. What the agent answers comes from the model or from a
|
|
34
|
+
* recorded transcript, never from here, for the same reason a scenario pack
|
|
35
|
+
* asserts a final state and not a wording.
|
|
36
|
+
*/
|
|
37
|
+
export const ConversationScriptSchema = z
|
|
38
|
+
.object({
|
|
39
|
+
name: z.string().regex(/^[a-z0-9-]+$/),
|
|
40
|
+
description: z.string().min(1),
|
|
41
|
+
channel: z.literal("whatsapp"),
|
|
42
|
+
/** The contact the conversation is bound to: the person who owes, and nobody else. */
|
|
43
|
+
contact: z.string().regex(E164, "contact must be E.164, e.g. +5511987654321"),
|
|
44
|
+
/**
|
|
45
|
+
* What this conversation is allowed to be about — an agreement alias for a
|
|
46
|
+
* collections agent. The channel refuses an outbound message that names a
|
|
47
|
+
* different one, which is the secrecy rule as code rather than as prose.
|
|
48
|
+
*/
|
|
49
|
+
subject: z.string().min(1).optional(),
|
|
50
|
+
/** The person's turns, in order. */
|
|
51
|
+
turns: z
|
|
52
|
+
.array(
|
|
53
|
+
z
|
|
54
|
+
.object({
|
|
55
|
+
text: z.string().min(1),
|
|
56
|
+
/** Seconds after the previous inbound turn, on the run's clock. Keeps a scripted run deterministic. */
|
|
57
|
+
after_seconds: z.number().int().nonnegative().default(0),
|
|
58
|
+
})
|
|
59
|
+
.strict(),
|
|
60
|
+
)
|
|
61
|
+
.nonempty(),
|
|
62
|
+
})
|
|
63
|
+
.strict();
|
|
64
|
+
|
|
65
|
+
export type ConversationScript = z.infer<typeof ConversationScriptSchema>;
|
|
66
|
+
|
|
67
|
+
export function parseConversationScript(text: string): ConversationScript {
|
|
68
|
+
return ConversationScriptSchema.parse(JSON.parse(text));
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* The reserved file name inside `channels/whatsapp/`: the template registry,
|
|
73
|
+
* which is not a conversation. Everything else in that directory is one, so
|
|
74
|
+
* a conversation may not be called `templates`.
|
|
75
|
+
*/
|
|
76
|
+
export const TEMPLATE_REGISTRY_FILE = "templates.json";
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* One template the agent declares it sends.
|
|
80
|
+
*
|
|
81
|
+
* `body` is here for a reader, not for a sender: it is the text AS SUBMITTED
|
|
82
|
+
* to Meta, and it is the only way somebody opening this repository can tell
|
|
83
|
+
* what `{{1}}` means. Nothing composes a message from it — Meta holds the
|
|
84
|
+
* approved copy and renders it — but the number of placeholders in it IS
|
|
85
|
+
* checked against the variables a send carries, because a count that does not
|
|
86
|
+
* match is a `132000` from the Cloud API and there is no reason to learn that
|
|
87
|
+
* in production.
|
|
88
|
+
*/
|
|
89
|
+
export const WhatsAppTemplateSchema = z
|
|
90
|
+
.object({
|
|
91
|
+
/** Meta's own naming rule for a template. */
|
|
92
|
+
name: z.string().regex(/^[a-z0-9_]+$/, "a template name is lower-case letters, digits and underscores"),
|
|
93
|
+
/** Meta's language code, e.g. `pt_BR`. A template approved in one language does not exist in another. */
|
|
94
|
+
language: z.string().regex(/^[a-z]{2}(_[A-Z]{2})?$/, 'expected a language code, e.g. "pt_BR"'),
|
|
95
|
+
description: z.string().min(1),
|
|
96
|
+
body: z.string().min(1),
|
|
97
|
+
})
|
|
98
|
+
.strict();
|
|
99
|
+
|
|
100
|
+
export type WhatsAppTemplate = z.infer<typeof WhatsAppTemplateSchema>;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* `channels/whatsapp/templates.json`: the LOCAL registry of the templates an
|
|
104
|
+
* agent uses.
|
|
105
|
+
*
|
|
106
|
+
* Outside the 24 hours that follow the person's last message WhatsApp carries
|
|
107
|
+
* an approved template and nothing else, so an agent that ever speaks after
|
|
108
|
+
* that has to own one. Whether META approved it is NOT knowable from here —
|
|
109
|
+
* it is a status inside a Business account, and this repository has none — so
|
|
110
|
+
* what this file proves is narrower and worth stating exactly: the agent
|
|
111
|
+
* declared the name, so a send of a name nobody declared is refused here
|
|
112
|
+
* instead of 400-ing at Meta. Registering the template and getting it approved
|
|
113
|
+
* stays the developer's, and the README says so.
|
|
114
|
+
*/
|
|
115
|
+
export const TemplateRegistrySchema = z
|
|
116
|
+
.object({
|
|
117
|
+
channel: z.literal("whatsapp"),
|
|
118
|
+
templates: z.array(WhatsAppTemplateSchema).nonempty(),
|
|
119
|
+
})
|
|
120
|
+
.strict()
|
|
121
|
+
.superRefine((registry, ctx) => {
|
|
122
|
+
const seen = new Set<string>();
|
|
123
|
+
for (const [i, template] of registry.templates.entries()) {
|
|
124
|
+
if (seen.has(template.name)) ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["templates", i, "name"], message: `${template.name} is declared twice` });
|
|
125
|
+
seen.add(template.name);
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
export type TemplateRegistry = z.infer<typeof TemplateRegistrySchema>;
|
|
130
|
+
|
|
131
|
+
export function parseTemplateRegistry(text: string): TemplateRegistry {
|
|
132
|
+
return TemplateRegistrySchema.parse(JSON.parse(text));
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** The highest `{{n}}` in a template body, which is how many variables a send of it must carry. */
|
|
136
|
+
export function templateArity(body: string): number {
|
|
137
|
+
let highest = 0;
|
|
138
|
+
for (const match of body.matchAll(/\{\{\s*(\d+)\s*\}\}/g)) highest = Math.max(highest, Number(match[1]));
|
|
139
|
+
return highest;
|
|
140
|
+
}
|