@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
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `npm run rerun <run-id> [--json]`: replays a recorded run against the
|
|
3
|
-
* deterministic provider, with no network, in a fresh state, and compares
|
|
4
|
-
* the sequence of states with the original bundle. The model's outputs are
|
|
5
|
-
* the recording; every decision of the core is recomputed.
|
|
6
|
-
*/
|
|
7
|
-
import { mkdtempSync, readFileSync } from "node:fs";
|
|
8
|
-
import { tmpdir } from "node:os";
|
|
9
|
-
import { join } from "node:path";
|
|
10
|
-
import { stderr, stdout } from "node:process";
|
|
11
|
-
import { ProofBundle, type ApprovalMode, type Execution } from "@codespar/agent-core";
|
|
12
|
-
import { handleExecution } from "../../channels/terminal/index.js";
|
|
13
|
-
import { runsDir, setup } from "../setup.js";
|
|
14
|
-
|
|
15
|
-
const argv = process.argv.slice(2);
|
|
16
|
-
const json = argv.includes("--json");
|
|
17
|
-
const runId = argv.find((a) => !a.startsWith("--"));
|
|
18
|
-
const say = (l: string) => stderr.write(l + "\n");
|
|
19
|
-
if (!runId) {
|
|
20
|
-
say("usage: npm run rerun <run-id> [--json]");
|
|
21
|
-
process.exit(2);
|
|
22
|
-
}
|
|
23
|
-
const original = ProofBundle.open(runsDir(), runId);
|
|
24
|
-
if (!original) {
|
|
25
|
-
say(`no bundle at runs/${runId}`);
|
|
26
|
-
process.exit(1);
|
|
27
|
-
}
|
|
28
|
-
const meta = original.readMeta() ?? {};
|
|
29
|
-
const mode = (meta["mode"] as ApprovalMode | undefined) ?? "human";
|
|
30
|
-
const originalTrail = original
|
|
31
|
-
.readEvents()
|
|
32
|
-
.filter((e) => e["type"] === "execution.transition")
|
|
33
|
-
.map((e) => (e["payload"] as { to: string }).to);
|
|
34
|
-
const originalDecisions = original.readEvents().filter((e) => e["type"] === "approval.created").map((e) => ((e["payload"] as { approver: { type: string } }).approver.type === "person" ? "approve" : "mandate"));
|
|
35
|
-
const userTurns = original.readTranscript().filter((l) => l.kind === "user").map((l) => l["text"] as string);
|
|
36
|
-
// The rail's answers are part of the recording: a payee the rail refused in the original run is refused in the rerun.
|
|
37
|
-
const events = original.readEvents();
|
|
38
|
-
const dispatched = new Map(events.filter((e) => e["type"] === "rail.dispatch").map((e) => [(e["payload"] as { attempt_id: string }).attempt_id, (e["payload"] as { payee: string }).payee]));
|
|
39
|
-
const refusedPayees = events
|
|
40
|
-
.filter((e) => e["type"] === "rail.outcome" && (e["payload"] as { status: string }).status === "failed")
|
|
41
|
-
.map((e) => dispatched.get((e["payload"] as { attempt_id: string }).attempt_id))
|
|
42
|
-
.filter((p): p is string => typeof p === "string");
|
|
43
|
-
const transcriptPath = join(original.dir, "transcript.jsonl");
|
|
44
|
-
readFileSync(transcriptPath, "utf8");
|
|
45
|
-
|
|
46
|
-
const s = setup({ mode, rail: "stub", provider: "replay", transcript: transcriptPath, runId: `${runId}_rerun_${Date.now().toString(36)}`, stateDir: mkdtempSync(join(tmpdir(), "bills-rerun-")), stubRail: { refusePayees: refusedPayees }, say });
|
|
47
|
-
try {
|
|
48
|
-
let decisionIndex = 0;
|
|
49
|
-
const runtime = s.makeRuntime();
|
|
50
|
-
const loop = s.makeLoop(runtime, (execution: Execution) => {
|
|
51
|
-
const decision = execution.state === "awaiting_approval" ? (originalDecisions[decisionIndex++] === "approve" ? "approve" : "deny") : "none";
|
|
52
|
-
return handleExecution(execution, { setup: s, approver: { id: "usr_rerun", channel: "terminal" }, decision, say });
|
|
53
|
-
});
|
|
54
|
-
for (const text of userTurns) await loop.turn(text);
|
|
55
|
-
const trail = s.store.listEvents({ run_id: s.runId }).filter((e) => e.type === "execution.transition").map((e) => (e.payload as { to: string }).to);
|
|
56
|
-
const outcomesOf = (list: Record<string, unknown>[]) => list.filter((e) => e["type"] === "rail.outcome").map((e) => (e["payload"] as { status: string }).status);
|
|
57
|
-
const originalOutcomes = outcomesOf(events);
|
|
58
|
-
const rerunOutcomes = outcomesOf(s.bundle.readEvents());
|
|
59
|
-
const same = JSON.stringify(trail) === JSON.stringify(originalTrail) && JSON.stringify(rerunOutcomes) === JSON.stringify(originalOutcomes);
|
|
60
|
-
if (json) stdout.write(JSON.stringify({ run_id: runId, rerun_id: s.runId, same_states: same, original: originalTrail, rerun: trail, original_outcomes: originalOutcomes, rerun_outcomes: rerunOutcomes, bundle_dir: s.bundle.dir }) + "\n");
|
|
61
|
-
say(same ? `rerun ok: ${trail.length} transition(s), same sequence as ${runId}` : `rerun DIFFERS: original ${JSON.stringify(originalTrail)} vs rerun ${JSON.stringify(trail)}`);
|
|
62
|
-
process.exit(same ? 0 : 1);
|
|
63
|
-
} finally {
|
|
64
|
-
s.close();
|
|
65
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `npm run resume [--json]`: after a crash or a restart. Executions left in
|
|
3
|
-
* `executing` are reconciled against the rail (idempotent on attempt_id),
|
|
4
|
-
* never repeated; stale open ones expire.
|
|
5
|
-
*/
|
|
6
|
-
import { stderr, stdout } from "node:process";
|
|
7
|
-
import { readDotEnv, setup } from "../setup.js";
|
|
8
|
-
|
|
9
|
-
const json = process.argv.includes("--json");
|
|
10
|
-
const say = (l: string) => stderr.write(l + "\n");
|
|
11
|
-
readDotEnv();
|
|
12
|
-
const s = setup({ say, runId: `run_resume_${Date.now().toString(36)}` });
|
|
13
|
-
try {
|
|
14
|
-
const resumed = [];
|
|
15
|
-
// Only resume dispatches, and only what the outbox proves was never sent; everything else is reconciled from the rail.
|
|
16
|
-
for (const stuck of s.engine.list({ state: "executing" })) {
|
|
17
|
-
const closed = await s.engine.resumePending(stuck.id);
|
|
18
|
-
resumed.push({ id: closed.id, state: closed.state, detail: closed.detail ?? null, receipt_ids: closed.outcomes.filter((o) => o.receipt_id).map((o) => o.receipt_id) });
|
|
19
|
-
say(closed.state === "executing" ? `${closed.id}: still executing — ${closed.detail}; nothing was re-sent` : `${closed.id}: executing -> ${closed.state}`);
|
|
20
|
-
}
|
|
21
|
-
const expired = s.engine.expireStale().map((e) => ({ id: e.id, state: e.state }));
|
|
22
|
-
for (const e of expired) say(`${e.id}: -> expired`);
|
|
23
|
-
const open = s.engine.list({ state: ["awaiting_approval", "approved"] }).map((e) => ({ id: e.id, state: e.state }));
|
|
24
|
-
for (const e of open) say(`${e.id}: still ${e.state}; decide it with npm run approve ${e.id} / npm run deny ${e.id}`);
|
|
25
|
-
if (json) stdout.write(JSON.stringify({ resumed, expired, open, bundle_dir: s.bundle.dir }) + "\n");
|
|
26
|
-
else say(resumed.length || expired.length ? "resume done" : "nothing to resume");
|
|
27
|
-
process.exit(resumed.some((r) => r.state === "executing") ? 3 : 0);
|
|
28
|
-
} finally {
|
|
29
|
-
s.close();
|
|
30
|
-
}
|
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `npm start` interactive terminal
|
|
3
|
-
* `npm start -- --input "pague a escola de outubro"` one turn, no prompt
|
|
4
|
-
* `npm start -- --scenario happy-path` a scenario pack, both modes it declares
|
|
5
|
-
*
|
|
6
|
-
* `--json` puts machine data on stdout (valid JSON, nothing else) and the
|
|
7
|
-
* human messages on stderr.
|
|
8
|
-
*/
|
|
9
|
-
import { stderr, stdout } from "node:process";
|
|
10
|
-
import { relative, resolve } from "node:path";
|
|
11
|
-
import { NotATestKeyError, isTestKey } from "@codespar/agent-core";
|
|
12
|
-
import { closeTerminal, defaultAsk, handleExecution, interactive } from "../channels/terminal/index.js";
|
|
13
|
-
import { runEmbeddedConsent, loadLocalMandate } from "./modules/embedded-consent.js";
|
|
14
|
-
import { checkScenario, listScenarios, loadScenario, runScenario, scenariosDir } from "./scenarios.js";
|
|
15
|
-
import { AGENT_DIR, MANDATE_PATH, NoMandateError, readDotEnv, resolveRailKind, setup, type RailKind } from "./setup.js";
|
|
16
|
-
import { loadMandate, createCodeSparClient } from "@codespar/agent-core";
|
|
17
|
-
|
|
18
|
-
interface Args {
|
|
19
|
-
input?: string;
|
|
20
|
-
scenario?: string;
|
|
21
|
-
mode?: "human" | "mandate";
|
|
22
|
-
json: boolean;
|
|
23
|
-
decision?: "approve" | "deny";
|
|
24
|
-
provider?: "anthropic" | "replay";
|
|
25
|
-
transcript?: string;
|
|
26
|
-
rail?: RailKind;
|
|
27
|
-
user: string;
|
|
28
|
-
help: boolean;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function parseArgs(argv: string[]): Args {
|
|
32
|
-
const args: Args = { json: false, user: "usr_terminal", help: false };
|
|
33
|
-
for (let i = 0; i < argv.length; i += 1) {
|
|
34
|
-
const a = argv[i]!;
|
|
35
|
-
const next = () => {
|
|
36
|
-
const v = argv[i + 1];
|
|
37
|
-
if (v === undefined) throw new Error(`${a} needs a value`);
|
|
38
|
-
i += 1;
|
|
39
|
-
return v;
|
|
40
|
-
};
|
|
41
|
-
if (a === "--input") args.input = next();
|
|
42
|
-
else if (a === "--scenario") args.scenario = next();
|
|
43
|
-
else if (a === "--mode") {
|
|
44
|
-
const v = next();
|
|
45
|
-
if (v !== "human" && v !== "mandate") throw new Error("--mode must be human or mandate");
|
|
46
|
-
args.mode = v;
|
|
47
|
-
} else if (a === "--json") args.json = true;
|
|
48
|
-
else if (a === "--approve") args.decision = "approve";
|
|
49
|
-
else if (a === "--deny") args.decision = "deny";
|
|
50
|
-
else if (a === "--provider") {
|
|
51
|
-
const v = next();
|
|
52
|
-
if (v !== "anthropic" && v !== "replay") throw new Error("--provider must be anthropic or replay");
|
|
53
|
-
args.provider = v;
|
|
54
|
-
} else if (a === "--transcript") args.transcript = next();
|
|
55
|
-
else if (a === "--rail") {
|
|
56
|
-
const v = next();
|
|
57
|
-
if (v !== "stub" && v !== "api") throw new Error("--rail must be stub or api");
|
|
58
|
-
args.rail = v;
|
|
59
|
-
} else if (a === "--user") args.user = next();
|
|
60
|
-
else if (a === "--help" || a === "-h") args.help = true;
|
|
61
|
-
else throw new Error(`unknown argument ${a}`);
|
|
62
|
-
}
|
|
63
|
-
return args;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const USAGE = `bills-agent
|
|
67
|
-
npm start interactive terminal
|
|
68
|
-
npm start -- --input "pague a escola de outubro" one turn (add --approve/--deny to decide, --json for machine output)
|
|
69
|
-
npm start -- --scenario <name> run a scenario pack (${"see scenarios/"})
|
|
70
|
-
options: --mode human|mandate --provider anthropic|replay --transcript <file> --rail stub|api --user <id> --json`;
|
|
71
|
-
|
|
72
|
-
export async function main(argv = process.argv.slice(2)): Promise<number> {
|
|
73
|
-
let args: Args;
|
|
74
|
-
try {
|
|
75
|
-
args = parseArgs(argv);
|
|
76
|
-
} catch (err) {
|
|
77
|
-
stderr.write(`${err instanceof Error ? err.message : String(err)}\n${USAGE}\n`);
|
|
78
|
-
return 2;
|
|
79
|
-
}
|
|
80
|
-
if (args.help) {
|
|
81
|
-
stderr.write(USAGE + "\n");
|
|
82
|
-
return 0;
|
|
83
|
-
}
|
|
84
|
-
readDotEnv();
|
|
85
|
-
const say = (line: string) => stderr.write(line + "\n");
|
|
86
|
-
|
|
87
|
-
if (args.scenario) return runScenarioCommand(args, say);
|
|
88
|
-
|
|
89
|
-
// Sandbox by construction: a live key dies here, before anything else runs.
|
|
90
|
-
const railKind = resolveRailKind(process.env, args.rail);
|
|
91
|
-
if (railKind === "api" && !isTestKey(process.env["CODESPAR_API_KEY"])) {
|
|
92
|
-
say(new NotATestKeyError().message);
|
|
93
|
-
return 1;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// Embedded consent: with a test key and no signed mandate, the mandate is born first.
|
|
97
|
-
if (railKind === "api" && !loadLocalMandate(MANDATE_PATH)) {
|
|
98
|
-
if (args.input) {
|
|
99
|
-
say(new NoMandateError().message);
|
|
100
|
-
return 1;
|
|
101
|
-
}
|
|
102
|
-
const api = createCodeSparClient({ apiKey: process.env["CODESPAR_API_KEY"], baseUrl: process.env["CODESPAR_API_URL"], projectId: process.env["CODESPAR_PROJECT_ID"] });
|
|
103
|
-
const example = loadMandate(resolve(AGENT_DIR, "mandate.example.json"));
|
|
104
|
-
await runEmbeddedConsent({ api, example, mandatePath: MANDATE_PATH, say, confirm: async (q: string) => /^(s|sim|y|yes)$/i.test((await defaultAsk(q)).trim()) });
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// One-shot without a model: replay the recorded happy-path when the input is its first turn.
|
|
108
|
-
let transcript = args.transcript;
|
|
109
|
-
const provider = args.provider ?? (process.env["ANTHROPIC_API_KEY"] && process.env["ANTHROPIC_API_KEY"] !== "sk-ant-your_key_here" ? "anthropic" : "replay");
|
|
110
|
-
if (provider === "replay" && !transcript && args.input) {
|
|
111
|
-
const match = listScenarios().map(loadScenario).find((s) => s.turns[0].input === args.input);
|
|
112
|
-
if (match) transcript = resolve(scenariosDir(), match.transcript);
|
|
113
|
-
else {
|
|
114
|
-
say(`no ANTHROPIC_API_KEY and no recorded transcript for that input. Set the key, pass --transcript, or use one of: ${listScenarios().map((n) => `"${loadScenario(n).turns[0].input}"`).join(", ")}`);
|
|
115
|
-
return 1;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
const s = setup({ mode: args.mode, rail: railKind, provider, transcript, say });
|
|
120
|
-
const approver = { id: args.user, channel: "terminal" };
|
|
121
|
-
try {
|
|
122
|
-
const runtime = s.makeRuntime();
|
|
123
|
-
if (!args.input) {
|
|
124
|
-
await interactive({ setup: s, approver, runtime, say });
|
|
125
|
-
return 0;
|
|
126
|
-
}
|
|
127
|
-
const loop = s.makeLoop(runtime, (execution) => handleExecution(execution, { setup: s, approver, decision: args.decision ?? "none", say }));
|
|
128
|
-
const result = await loop.turn(args.input);
|
|
129
|
-
const executions = s.engine.list().filter((e) => e.run_id === s.runId);
|
|
130
|
-
const payload = {
|
|
131
|
-
run_id: s.runId,
|
|
132
|
-
agent: `${s.manifest.manifest.name}@${s.manifest.manifest.version}`,
|
|
133
|
-
mode: s.mode,
|
|
134
|
-
rail: s.railKind,
|
|
135
|
-
mandate_id: s.mandate.id,
|
|
136
|
-
actor: s.engine.agentActor,
|
|
137
|
-
reply: result.reply,
|
|
138
|
-
tool_calls: result.tool_calls,
|
|
139
|
-
executions: executions.map((e) => ({
|
|
140
|
-
id: e.id,
|
|
141
|
-
state: e.state,
|
|
142
|
-
reason: e.reason ?? null,
|
|
143
|
-
escalation: e.escalation ?? null,
|
|
144
|
-
total_minor: e.total,
|
|
145
|
-
items: e.items.map((i) => ({ beneficiary: i.beneficiary, amount_minor: i.amount })),
|
|
146
|
-
approval_id: e.approval_id ?? null,
|
|
147
|
-
receipt_ids: e.outcomes.filter((o) => o.receipt_id).map((o) => o.receipt_id),
|
|
148
|
-
})),
|
|
149
|
-
receipts: s.bundle.listReceipts().map((f) => relative(process.cwd(), `${s.bundle.dir}/receipts/${f}`)),
|
|
150
|
-
bundle_dir: relative(process.cwd(), s.bundle.dir),
|
|
151
|
-
};
|
|
152
|
-
if (args.json) stdout.write(JSON.stringify(payload) + "\n");
|
|
153
|
-
else stdout.write(result.reply + "\n");
|
|
154
|
-
return executions.some((e) => e.state === "executing") ? 3 : 0;
|
|
155
|
-
} finally {
|
|
156
|
-
closeTerminal();
|
|
157
|
-
s.close();
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
async function runScenarioCommand(args: Args, say: (l: string) => void): Promise<number> {
|
|
162
|
-
const scenario = loadScenario(args.scenario!);
|
|
163
|
-
const modes = args.mode ? [args.mode] : scenario.modes;
|
|
164
|
-
const results = [];
|
|
165
|
-
for (const mode of modes) {
|
|
166
|
-
say(`== scenario ${scenario.name} — approval: ${mode}`);
|
|
167
|
-
say(scenario.description);
|
|
168
|
-
const run = await runScenario(scenario, { mode, say: args.json ? () => undefined : say });
|
|
169
|
-
const check = checkScenario(scenario, run);
|
|
170
|
-
for (const reply of run.replies) say(`agente: ${reply}`);
|
|
171
|
-
say(check.ok ? `== ok — bundle em ${relative(process.cwd(), run.bundle_dir)}` : `== FAIL: ${check.failures.join("; ")}`);
|
|
172
|
-
results.push({ mode, ok: check.ok, failures: check.failures, run });
|
|
173
|
-
}
|
|
174
|
-
if (args.json) stdout.write(JSON.stringify({ scenario: scenario.name, results }) + "\n");
|
|
175
|
-
return results.every((r) => r.ok) ? 0 : 1;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
if (process.argv[1] && import.meta.url === new URL(`file://${process.argv[1]}`).href) {
|
|
179
|
-
main()
|
|
180
|
-
.then((code) => process.exit(code))
|
|
181
|
-
.catch((err) => {
|
|
182
|
-
stderr.write(`${err instanceof Error ? err.stack ?? err.message : String(err)}\n`);
|
|
183
|
-
process.exit(1);
|
|
184
|
-
});
|
|
185
|
-
}
|
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The terminal channel: what `npm start` opens. No account, no server. The
|
|
3
|
-
* person typing is the PAYER (in production, over WhatsApp); the operator's
|
|
4
|
-
* approval in `human` mode is asked on the same keyboard, labelled as such.
|
|
5
|
-
* It shows what the core decided, presents the QR and the copy-and-paste
|
|
6
|
-
* when the receivable is payable, and tells the payer the outcome once.
|
|
7
|
-
*/
|
|
8
|
-
import { createInterface } from "node:readline/promises";
|
|
9
|
-
import { stdin, stderr, stdout } from "node:process";
|
|
10
|
-
import { relative } from "node:path";
|
|
11
|
-
import qrcode from "qrcode-terminal";
|
|
12
|
-
import type { ChargeInstrument, Execution } from "@codespar/agent-core";
|
|
13
|
-
import { formatBRL, formatDate } from "../../src/agreements.js";
|
|
14
|
-
import { pollUntilClosed, type PollResult } from "../../src/poll.js";
|
|
15
|
-
import type { Setup } from "../../src/setup.js";
|
|
16
|
-
|
|
17
|
-
export interface TerminalOptions {
|
|
18
|
-
setup: Setup;
|
|
19
|
-
approver: { id: string; channel: string };
|
|
20
|
-
/** Non-interactive decision for `--input`: approve, deny, or leave it awaiting. */
|
|
21
|
-
decision?: "approve" | "deny" | "none";
|
|
22
|
-
/** Seconds to wait for the payer after issuing. */
|
|
23
|
-
waitSeconds?: number | undefined;
|
|
24
|
-
/** Let the sandbox payer (the fixture, or the API's test route) pay once the receivable is payable. */
|
|
25
|
-
simulatePayer?: boolean | undefined;
|
|
26
|
-
say?: ((line: string) => void) | undefined;
|
|
27
|
-
ask?: ((question: string) => Promise<string>) | undefined;
|
|
28
|
-
/** Where the lines for the PAYER go (the conversation); `say` is the operator's console. */
|
|
29
|
-
tell?: ((line: string) => void) | undefined;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export function describeExecution(execution: Execution, setup: Setup): string[] {
|
|
33
|
-
const lines: string[] = [];
|
|
34
|
-
const debtor = execution.items[0]?.beneficiary ?? "?";
|
|
35
|
-
lines.push(` execucao ${execution.id}: ${execution.state}${execution.reason ? ` (${execution.reason})` : ""}`);
|
|
36
|
-
lines.push(` acordo de ${debtor} (${execution.items[0]?.alias ?? "?"})`);
|
|
37
|
-
for (const [i, item] of execution.items.entries()) lines.push(` - parcela ${i + 1}/${execution.items.length}: ${formatBRL(item.amount)}, vence ${item.due_date ? formatDate(item.due_date) : "?"}`);
|
|
38
|
-
lines.push(` total (calculado pelo core): ${formatBRL(execution.total)}`);
|
|
39
|
-
if (execution.escalation) lines.push(` escalado por: ${execution.escalation.trigger} — ${execution.escalation.detail}`);
|
|
40
|
-
if (execution.blocking_reasons.length) lines.push(` bloqueado: ${execution.blocking_reasons.join(", ")} — a politica nao autoriza; nao ha o que aprovar`);
|
|
41
|
-
if (execution.detail && execution.state !== "awaiting_approval") lines.push(` ${execution.detail}`);
|
|
42
|
-
for (const outcome of execution.outcomes) {
|
|
43
|
-
if (outcome.transaction_id) lines.push(` cobranca ${outcome.index + 1}: ${outcome.transaction_id} — ${outcome.status}${outcome.code ? ` (${outcome.code})` : ""}`);
|
|
44
|
-
if (outcome.receipt_id) lines.push(` registro: ${relative(process.cwd(), `${setup.bundle.dir}/receipts/${outcome.receipt_id}.json`)}`);
|
|
45
|
-
}
|
|
46
|
-
return lines;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/** What the payer reads when a receivable is payable: the QR as an image, the copy-and-paste under it, the bank line if any. */
|
|
50
|
-
export function presentInstrument(execution: Execution, instalment: number, chargeId: string, instrument: ChargeInstrument, tell: (line: string) => void): void {
|
|
51
|
-
const item = execution.items[instalment - 1];
|
|
52
|
-
const count = execution.items.length;
|
|
53
|
-
tell("");
|
|
54
|
-
tell(`${count > 1 ? `Parcela ${instalment}/${count}: ` : ""}${item ? formatBRL(item.amount) : ""}${instrument.due_date ? `, vence ${formatDate(instrument.due_date)}` : ""} — cobranca ${chargeId}`);
|
|
55
|
-
if (instrument.pix_copy_paste) {
|
|
56
|
-
qrcode.generate(instrument.pix_copy_paste, { small: true }, (qr: string) => {
|
|
57
|
-
for (const line of qr.split("\n")) tell(line);
|
|
58
|
-
});
|
|
59
|
-
tell("Pix copia e cola:");
|
|
60
|
-
tell(instrument.pix_copy_paste);
|
|
61
|
-
}
|
|
62
|
-
if (instrument.boleto_bank_line) {
|
|
63
|
-
tell("Ou pelo boleto, linha digitavel:");
|
|
64
|
-
tell(instrument.boleto_bank_line);
|
|
65
|
-
}
|
|
66
|
-
tell("");
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/** The one message per outcome, recorded so a duplicate event never sends it twice. */
|
|
70
|
-
export function announceOutcome(execution: Execution, setup: Setup, tell: (line: string) => void): boolean {
|
|
71
|
-
if (execution.state === "executing") return false;
|
|
72
|
-
if (!setup.engine.markTold(execution.id, execution.state)) return false;
|
|
73
|
-
let text: string;
|
|
74
|
-
if (execution.state === "settled") text = `Recebemos, acordo quitado. Obrigado! (${execution.outcomes.map((o) => o.transaction_id).filter(Boolean).join(", ")})`;
|
|
75
|
-
else if (execution.reason === "charge_expired") text = "A cobranca venceu sem pagamento. Se quiser, emito uma nova dentro das mesmas condicoes.";
|
|
76
|
-
else if (execution.reason === "charge_cancelled") text = "A cobranca foi cancelada. Nada foi pago.";
|
|
77
|
-
else if (execution.state === "failed") text = `Nao consegui emitir a cobranca (${execution.reason ?? "falha no trilho"}). Nada foi cobrado.`;
|
|
78
|
-
else if (execution.state === "denied") text = `Nao posso emitir nesses termos (${execution.reason ?? "recusado"}).`;
|
|
79
|
-
else text = `A proposta expirou sem decisao (${execution.state}).`;
|
|
80
|
-
tell(text);
|
|
81
|
-
setup.engine.note("message.debtor", execution.id, { state: execution.state, reason: execution.reason ?? null, text });
|
|
82
|
-
return true;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/** Decides an `awaiting_approval` execution, runs an `approved` one, and waits for the payer. Returns the final execution of this pass. */
|
|
86
|
-
export async function handleExecution(execution: Execution, options: TerminalOptions): Promise<Execution> {
|
|
87
|
-
const { setup, approver } = options;
|
|
88
|
-
const say = options.say ?? ((l: string) => stderr.write(l + "\n"));
|
|
89
|
-
const tell = options.tell ?? ((l: string) => stdout.write(l + "\n"));
|
|
90
|
-
const engine = setup.engine;
|
|
91
|
-
|
|
92
|
-
for (const line of describeExecution(execution, setup)) say(line);
|
|
93
|
-
|
|
94
|
-
let current = execution;
|
|
95
|
-
if (current.state === "awaiting_approval") {
|
|
96
|
-
let decision = options.decision;
|
|
97
|
-
if (!decision) {
|
|
98
|
-
if (current.blocking_reasons.length > 0) say(" (o unico desfecho possivel e negar; aperte Enter)");
|
|
99
|
-
const ask = options.ask ?? defaultAsk;
|
|
100
|
-
const answer = (await ask(" [operador] Aprovar a emissao desta cobranca? [s/N] ")).trim().toLowerCase();
|
|
101
|
-
decision = answer === "s" || answer === "sim" || answer === "y" || answer === "yes" ? "approve" : "deny";
|
|
102
|
-
}
|
|
103
|
-
if (decision === "approve") current = engine.approve(current.id, approver);
|
|
104
|
-
else if (decision === "deny") current = engine.deny(current.id, approver);
|
|
105
|
-
else {
|
|
106
|
-
say(" deixado em awaiting_approval (rode de novo com --approve ou --deny)");
|
|
107
|
-
return current;
|
|
108
|
-
}
|
|
109
|
-
say(` -> ${current.state}${current.reason ? ` (${current.reason})` : ""}`);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
if (current.state === "approved") {
|
|
113
|
-
current = await engine.execute(current.id);
|
|
114
|
-
say(` -> ${current.state}${current.reason ? ` (${current.reason})` : ""}`);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
if (current.state === "executing" && current.reason === "awaiting_settlement") {
|
|
118
|
-
const result = await waitForPayer(current.id, options);
|
|
119
|
-
current = result.execution;
|
|
120
|
-
say(` -> ${current.state}${current.reason ? ` (${current.reason})` : ""} apos ${result.rounds} consulta(s), ${result.seconds}s${result.timed_out ? " (tempo esgotado; `npm run poll` continua de onde parou)" : ""}`);
|
|
121
|
-
for (const outcome of current.outcomes) if (outcome.receipt_id) say(` registro: ${relative(process.cwd(), `${setup.bundle.dir}/receipts/${outcome.receipt_id}.json`)}`);
|
|
122
|
-
} else if (current.state === "executing") {
|
|
123
|
-
say(" desfecho desconhecido no trilho; rode `npm run resume` para reconciliar (nunca repita a emissao)");
|
|
124
|
-
}
|
|
125
|
-
announceOutcome(current, setup, tell);
|
|
126
|
-
return current;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
export async function waitForPayer(executionId: string, options: TerminalOptions): Promise<PollResult> {
|
|
130
|
-
const { setup } = options;
|
|
131
|
-
const say = options.say ?? ((l: string) => stderr.write(l + "\n"));
|
|
132
|
-
const tell = options.tell ?? ((l: string) => stdout.write(l + "\n"));
|
|
133
|
-
const waitSeconds = options.waitSeconds ?? (setup.railKind === "api" ? 60 : 0);
|
|
134
|
-
return pollUntilClosed(setup.engine, executionId, {
|
|
135
|
-
intervalMs: setup.pollIntervalMs,
|
|
136
|
-
timeoutMs: waitSeconds * 1000,
|
|
137
|
-
payer: options.simulatePayer ? setup.payer : undefined,
|
|
138
|
-
onInstrument: (e, n, id, instrument) => presentInstrument(e, n, id, instrument, tell),
|
|
139
|
-
onWait: (_e, round) => {
|
|
140
|
-
if (setup.railKind === "api" && round % 5 === 0) say(` aguardando o pagador... (${round} consultas)`);
|
|
141
|
-
},
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
let rl: ReturnType<typeof createInterface> | undefined;
|
|
146
|
-
|
|
147
|
-
export function defaultAsk(question: string): Promise<string> {
|
|
148
|
-
rl ??= createInterface({ input: stdin, output: stderr });
|
|
149
|
-
return rl.question(question);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
export function closeTerminal(): void {
|
|
153
|
-
rl?.close();
|
|
154
|
-
rl = undefined;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
export async function interactive(options: TerminalOptions & { runtime: import("@codespar/agent-core").AgentRuntime }): Promise<void> {
|
|
158
|
-
const { setup } = options;
|
|
159
|
-
const say = options.say ?? ((l: string) => stderr.write(l + "\n"));
|
|
160
|
-
const loop = setup.makeLoop(options.runtime, (execution) => handleExecution(execution, options));
|
|
161
|
-
say(`collections-agent ${setup.manifest.manifest.version} — approval: ${setup.mode} — trilho: ${setup.railKind} — politica ${setup.mandate.id}`);
|
|
162
|
-
say(`run ${setup.runId} — bundle em ${relative(process.cwd(), setup.bundle.dir)}`);
|
|
163
|
-
say('Voce e o pagador. Diga algo ("oi, recebi a mensagem sobre o acordo do pedido 1042"). Ctrl+D ou "sair" encerra.');
|
|
164
|
-
for (;;) {
|
|
165
|
-
let text: string;
|
|
166
|
-
try {
|
|
167
|
-
text = await defaultAsk("pagador> ");
|
|
168
|
-
} catch {
|
|
169
|
-
break;
|
|
170
|
-
}
|
|
171
|
-
const trimmed = text.trim();
|
|
172
|
-
if (!trimmed) continue;
|
|
173
|
-
if (["sair", "exit", "quit"].includes(trimmed.toLowerCase())) break;
|
|
174
|
-
const result = await loop.turn(trimmed);
|
|
175
|
-
stdout.write(result.reply + "\n");
|
|
176
|
-
}
|
|
177
|
-
closeTerminal();
|
|
178
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `npm run approve <execution-id> [--user <id>] [--json]`: decides an
|
|
3
|
-
* execution left in `awaiting_approval` (a `--input` run without
|
|
4
|
-
* `--approve`, a restart). Produces the section 4.2 artifact and runs the
|
|
5
|
-
* execution through the same last gate `npm start` uses, then waits for the
|
|
6
|
-
* payer (`--wait`, `--simulate-payer`).
|
|
7
|
-
*/
|
|
8
|
-
import { decideFromCli } from "./decide.js";
|
|
9
|
-
|
|
10
|
-
await decideFromCli("approve");
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `npm run check [--json]`: the manifest-coherence gate of section 4.3.
|
|
3
|
-
*/
|
|
4
|
-
import { stderr, stdout } from "node:process";
|
|
5
|
-
import { checkAgent } from "@codespar/agent-core";
|
|
6
|
-
import { AGENT_DIR } from "../setup.js";
|
|
7
|
-
|
|
8
|
-
const json = process.argv.includes("--json");
|
|
9
|
-
const report = checkAgent(AGENT_DIR);
|
|
10
|
-
if (json) stdout.write(JSON.stringify(report) + "\n");
|
|
11
|
-
for (const f of report.findings) stderr.write(`${f.level === "error" ? "ERROR" : "warn "} ${f.code}: ${f.message}\n`);
|
|
12
|
-
stderr.write(report.ok ? `check ok: ${report.agent} agrees with its agent.yaml\n` : `check FAILED for ${report.agent ?? "agent"}\n`);
|
|
13
|
-
process.exit(report.ok ? 0 : 1);
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { relative } from "node:path";
|
|
2
|
-
import { stderr, stdout } from "node:process";
|
|
3
|
-
import { handleExecution } from "../../channels/terminal/index.js";
|
|
4
|
-
import { readDotEnv, setup } from "../setup.js";
|
|
5
|
-
|
|
6
|
-
export async function decideFromCli(decision: "approve" | "deny"): Promise<never> {
|
|
7
|
-
const argv = process.argv.slice(2);
|
|
8
|
-
const json = argv.includes("--json");
|
|
9
|
-
const user = argv.includes("--user") ? argv[argv.indexOf("--user") + 1] : undefined;
|
|
10
|
-
const wait = argv.includes("--wait") ? Number(argv[argv.indexOf("--wait") + 1]) : undefined;
|
|
11
|
-
const simulatePayer = argv.includes("--simulate-payer");
|
|
12
|
-
const executionId = argv.find((a, i) => !a.startsWith("--") && argv[i - 1] !== "--user" && argv[i - 1] !== "--wait");
|
|
13
|
-
const say = (l: string) => stderr.write(l + "\n");
|
|
14
|
-
if (!executionId) {
|
|
15
|
-
say(`usage: npm run ${decision} <execution-id> [--user <id>] [--wait <seconds>] [--simulate-payer] [--json]`);
|
|
16
|
-
process.exit(2);
|
|
17
|
-
}
|
|
18
|
-
readDotEnv();
|
|
19
|
-
const s = setup({ say, runId: `run_${decision}_${Date.now().toString(36)}` });
|
|
20
|
-
try {
|
|
21
|
-
const execution = s.engine.get(executionId);
|
|
22
|
-
if (!execution) {
|
|
23
|
-
say(`unknown execution ${executionId}`);
|
|
24
|
-
process.exit(1);
|
|
25
|
-
}
|
|
26
|
-
if (execution.state !== "awaiting_approval") {
|
|
27
|
-
say(`${executionId} is ${execution.state}, not awaiting_approval; nothing to decide`);
|
|
28
|
-
process.exit(1);
|
|
29
|
-
}
|
|
30
|
-
const final = await handleExecution(execution, { setup: s, approver: { id: user ?? "usr_operator", channel: "terminal" }, decision, say, tell: json ? say : undefined, waitSeconds: wait, simulatePayer });
|
|
31
|
-
if (json) {
|
|
32
|
-
stdout.write(
|
|
33
|
-
JSON.stringify({
|
|
34
|
-
execution_id: final.id,
|
|
35
|
-
state: final.state,
|
|
36
|
-
reason: final.reason ?? null,
|
|
37
|
-
approval_id: final.approval_id ?? null,
|
|
38
|
-
charge_ids: final.outcomes.map((o) => o.transaction_id ?? null),
|
|
39
|
-
receipt_ids: final.outcomes.filter((o) => o.receipt_id).map((o) => o.receipt_id),
|
|
40
|
-
bundle_dir: relative(process.cwd(), s.bundle.dir),
|
|
41
|
-
}) + "\n",
|
|
42
|
-
);
|
|
43
|
-
}
|
|
44
|
-
process.exit(final.state === "executing" && final.reason !== "awaiting_settlement" ? 3 : 0);
|
|
45
|
-
} finally {
|
|
46
|
-
s.close();
|
|
47
|
-
}
|
|
48
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `npm run eval [--json] [--case <name>]`: the adversarial suite of section 9
|
|
3
|
-
* plus every scenario of section 12 in every mode it declares. Runs on the
|
|
4
|
-
* replay provider and the stub rail, with no model and no network. A
|
|
5
|
-
* regression blocks merge.
|
|
6
|
-
*/
|
|
7
|
-
import { stderr, stdout } from "node:process";
|
|
8
|
-
import { listAdversarialCases, loadAdversarialCase, runAdversarialCase } from "../adversarial.js";
|
|
9
|
-
import { checkScenario, listScenarios, loadScenario, runScenario } from "../scenarios.js";
|
|
10
|
-
|
|
11
|
-
const argv = process.argv.slice(2);
|
|
12
|
-
const json = argv.includes("--json");
|
|
13
|
-
const only = argv.includes("--case") ? argv[argv.indexOf("--case") + 1] : undefined;
|
|
14
|
-
const say = (l: string) => stderr.write(l + "\n");
|
|
15
|
-
|
|
16
|
-
const adversarial = [];
|
|
17
|
-
for (const name of listAdversarialCases()) {
|
|
18
|
-
if (only && only !== name) continue;
|
|
19
|
-
const result = await runAdversarialCase(loadAdversarialCase(name));
|
|
20
|
-
adversarial.push(result);
|
|
21
|
-
say(`${result.ok ? "ok " : "FAIL"} adversarial/${name} — ${result.attack} — states ${JSON.stringify(result.states)}${result.failures.length ? ` — ${result.failures.join("; ")}` : ""}`);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const scenarios = [];
|
|
25
|
-
for (const name of listScenarios()) {
|
|
26
|
-
if (only && only !== name) continue;
|
|
27
|
-
const scenario = loadScenario(name);
|
|
28
|
-
if (!scenario.rails.includes("stub")) continue;
|
|
29
|
-
for (const mode of scenario.modes) {
|
|
30
|
-
const check = checkScenario(scenario, await runScenario(scenario, { mode, rail: "stub" }));
|
|
31
|
-
scenarios.push({ name, mode, ok: check.ok, failures: check.failures, states: check.run.executions.map((e) => e.state), receipts: check.run.receipts, charges_issued: check.run.charges_issued, debtor_messages: check.run.debtor_messages });
|
|
32
|
-
say(`${check.ok ? "ok " : "FAIL"} scenario/${name} [${mode}] — states ${JSON.stringify(check.run.executions.map((e) => e.state))}, ${check.run.charges_issued} charge(s), ${check.run.receipts} record(s), ${check.run.debtor_messages} message(s)${check.failures.length ? ` — ${check.failures.join("; ")}` : ""}`);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const ok = adversarial.every((r) => r.ok) && scenarios.every((r) => r.ok);
|
|
37
|
-
if (json) stdout.write(JSON.stringify({ ok, adversarial, scenarios }) + "\n");
|
|
38
|
-
say(ok ? `eval ok: ${adversarial.length} adversarial case(s), ${scenarios.length} scenario run(s)` : "eval FAILED");
|
|
39
|
-
process.exit(ok ? 0 : 1);
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `npm run poll [--wait <seconds>] [--simulate-payer] [--json]`: keeps
|
|
3
|
-
* looking at every receivable still waiting for its payer until it closes
|
|
4
|
-
* or the wait runs out. This is the loop-closer for a terminal that has no
|
|
5
|
-
* webhook URL; `npm run webhook` is the other. Presents an instrument not yet
|
|
6
|
-
* shown, tells the payer the outcome once, fetches the paid record.
|
|
7
|
-
*/
|
|
8
|
-
import { stderr, stdout } from "node:process";
|
|
9
|
-
import { announceOutcome, waitForPayer } from "../../channels/terminal/index.js";
|
|
10
|
-
import { readDotEnv, setup } from "../setup.js";
|
|
11
|
-
|
|
12
|
-
const argv = process.argv.slice(2);
|
|
13
|
-
const json = argv.includes("--json");
|
|
14
|
-
const wait = argv.includes("--wait") ? Number(argv[argv.indexOf("--wait") + 1]) : undefined;
|
|
15
|
-
const simulatePayer = argv.includes("--simulate-payer");
|
|
16
|
-
const say = (l: string) => stderr.write(l + "\n");
|
|
17
|
-
const tell = (l: string) => (json ? stderr : stdout).write(l + "\n");
|
|
18
|
-
readDotEnv();
|
|
19
|
-
const s = setup({ say, runId: `run_poll_${Date.now().toString(36)}` });
|
|
20
|
-
try {
|
|
21
|
-
const results = [];
|
|
22
|
-
for (const open of s.engine.list({ state: "executing" })) {
|
|
23
|
-
if (open.reason !== "awaiting_settlement") continue;
|
|
24
|
-
const r = await waitForPayer(open.id, { setup: s, approver: { id: "usr_operator", channel: "terminal" }, say, tell, waitSeconds: wait, simulatePayer });
|
|
25
|
-
announceOutcome(r.execution, s, tell);
|
|
26
|
-
if (r.execution.state !== "executing") await s.engine.collectReceipts(r.execution.id);
|
|
27
|
-
results.push({ id: r.execution.id, state: r.execution.state, reason: r.execution.reason ?? null, rounds: r.rounds, seconds: r.seconds, timed_out: r.timed_out });
|
|
28
|
-
say(`${r.execution.id}: ${r.execution.state}${r.execution.reason ? ` (${r.execution.reason})` : ""} after ${r.rounds} look(s), ${r.seconds}s`);
|
|
29
|
-
}
|
|
30
|
-
if (json) stdout.write(JSON.stringify({ polled: results }) + "\n");
|
|
31
|
-
else if (!results.length) say("nothing waiting for a payer");
|
|
32
|
-
process.exit(results.some((r) => r.timed_out) ? 3 : 0);
|
|
33
|
-
} finally {
|
|
34
|
-
s.close();
|
|
35
|
-
}
|