@codespar/cli 0.18.1 → 0.20.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 +1 -1
- package/dist/commands/login.js +52 -12
- package/dist/commands/login.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/surface.js +31 -13
- package/dist/surface.js.map +1 -1
- package/package.json +1 -1
- package/templates/bills-agent/README.md +2 -2
- package/templates/bills-agent/agents/bills-agent/.env.example +2 -2
- package/templates/bills-agent/agents/bills-agent/README.md +25 -18
- package/templates/bills-agent/agents/bills-agent/SYSTEM_PROMPT.md +13 -3
- package/templates/bills-agent/agents/bills-agent/agent.yaml +2 -1
- package/templates/bills-agent/agents/bills-agent/evals/adversarial/exfiltration.transcript.jsonl +1 -1
- package/templates/bills-agent/agents/bills-agent/evals/adversarial/false-authority.transcript.jsonl +1 -1
- package/templates/bills-agent/agents/bills-agent/evals/adversarial/prompt-injection.transcript.jsonl +1 -1
- package/templates/bills-agent/agents/bills-agent/mandate.example.json +1 -1
- package/templates/bills-agent/agents/bills-agent/runbook.md +1 -1
- package/templates/bills-agent/agents/bills-agent/scenarios/beneficiary-not-allowed.transcript.jsonl +1 -1
- package/templates/bills-agent/agents/bills-agent/scenarios/cap-exceeded.transcript.jsonl +1 -1
- package/templates/bills-agent/agents/bills-agent/scenarios/escalated-above-threshold.transcript.jsonl +4 -4
- package/templates/bills-agent/agents/bills-agent/scenarios/happy-path.transcript.jsonl +1 -1
- package/templates/bills-agent/agents/bills-agent/scenarios/mandate-revoked.json +1 -1
- package/templates/bills-agent/agents/bills-agent/scenarios/mandate-revoked.transcript.jsonl +4 -4
- package/templates/bills-agent/agents/bills-agent/scenarios/prompt-injection.transcript.jsonl +1 -1
- package/templates/bills-agent/agents/bills-agent/src/bills.ts +1 -1
- package/templates/bills-agent/agents/bills-agent/src/kit.ts +15 -28
- package/templates/bills-agent/agents/bills-agent/src/modules/embedded-consent.ts +42 -15
- package/templates/bills-agent/agents/bills-agent/src/modules/pix-out.ts +21 -3
- package/templates/bills-agent/agents/bills-agent/src/strings.ts +68 -0
- package/templates/bills-agent/agents/bills-agent/test/cli.test.ts +130 -2
- package/templates/bills-agent/agents/bills-agent/test/consent-money.test.ts +25 -0
- package/templates/bills-agent/agents/bills-agent/test/dates-and-approval.test.ts +98 -0
- package/templates/bills-agent/agents/bills-agent/test/eval-runs.test.ts +81 -0
- package/templates/bills-agent/agents/bills-agent/test/fixtures/excursao-300.transcript.jsonl +2 -2
- package/templates/bills-agent/agents/bills-agent/test/fixtures/material-400.transcript.jsonl +1 -1
- package/templates/bills-agent/agents/bills-agent/test/locale.test.ts +161 -0
- package/templates/bills-agent/agents/bills-agent/test/mandate-state.test.ts +108 -0
- package/templates/bills-agent/agents/bills-agent/test/refused-before-draft.test.ts +81 -0
- package/templates/bills-agent/agents/bills-agent/test/replay.test.ts +76 -0
- package/templates/bills-agent/agents/bills-agent/test/reply-and-outcome.test.ts +84 -0
- package/templates/bills-agent/agents/bills-agent/test/reply-language.test.ts +95 -0
- package/templates/bills-agent/agents/bills-agent/test/rerun-and-missing-transcript.test.ts +120 -0
- package/templates/bills-agent/agents/bills-agent/test/rerun-world-events.test.ts +55 -0
- package/templates/bills-agent/agents/bills-agent/tools.json +1 -1
- package/templates/bills-agent/packages/agent-core/README.md +21 -2
- package/templates/bills-agent/packages/agent-core/package.json +1 -1
- package/templates/bills-agent/packages/agent-core/src/agent.ts +33 -6
- package/templates/bills-agent/packages/agent-core/src/api/charge-rail.ts +15 -1
- package/templates/bills-agent/packages/agent-core/src/api/rail.ts +11 -5
- package/templates/bills-agent/packages/agent-core/src/api/sandbox-payer.ts +36 -0
- package/templates/bills-agent/packages/agent-core/src/bundle.ts +2 -0
- package/templates/bills-agent/packages/agent-core/src/channels.ts +18 -8
- package/templates/bills-agent/packages/agent-core/src/check.ts +25 -3
- package/templates/bills-agent/packages/agent-core/src/engine.ts +90 -9
- package/templates/bills-agent/packages/agent-core/src/escalate.ts +10 -0
- package/templates/bills-agent/packages/agent-core/src/index.ts +3 -0
- package/templates/bills-agent/packages/agent-core/src/language.ts +52 -0
- package/templates/bills-agent/packages/agent-core/src/locale.ts +88 -0
- package/templates/bills-agent/packages/agent-core/src/manifest.ts +4 -1
- package/templates/bills-agent/packages/agent-core/src/rail.ts +29 -1
- package/templates/bills-agent/packages/agent-core/src/receipt-verification.ts +30 -2
- package/templates/bills-agent/packages/agent-core/src/secrets.ts +53 -8
- package/templates/bills-agent/packages/agent-core/src/state-machine.ts +14 -0
- package/templates/bills-agent/packages/agent-core/src/strings.ts +175 -0
- package/templates/bills-agent/packages/agent-core/src/stubs/charge-rail.ts +15 -2
- package/templates/bills-agent/packages/agent-core/src/stubs/rail.ts +7 -4
- package/templates/bills-agent/packages/agent-core/src/types.ts +15 -2
- package/templates/bills-agent/packages/agent-core/test/actor-on-the-wire.test.ts +144 -0
- package/templates/bills-agent/packages/agent-core/test/attempt-replay.test.ts +2 -2
- package/templates/bills-agent/packages/agent-core/test/engine.test.ts +23 -0
- package/templates/bills-agent/packages/agent-core/test/helpers.ts +1 -1
- package/templates/bills-agent/packages/agent-core/test/language.test.ts +40 -0
- package/templates/bills-agent/packages/agent-core/test/locale.test.ts +137 -0
- package/templates/bills-agent/packages/agent-core/test/mandate-status.test.ts +2 -2
- package/templates/bills-agent/packages/agent-core/test/manifest.test.ts +2 -2
- package/templates/bills-agent/packages/agent-core/test/rail-errors.test.ts +74 -0
- package/templates/bills-agent/packages/agent-core/test/receipt-read-verification.test.ts +32 -0
- package/templates/bills-agent/packages/agent-core/test/receivables.test.ts +49 -0
- package/templates/bills-agent/packages/agent-core/test/recorded-turns.ts +29 -0
- package/templates/bills-agent/packages/agent-core/test/secrets.test.ts +40 -1
- package/templates/bills-agent/packages/agent-runtime/README.md +31 -4
- package/templates/bills-agent/packages/agent-runtime/src/channels/rules.ts +4 -2
- package/templates/bills-agent/packages/agent-runtime/src/channels/whatsapp/emulator.ts +11 -5
- package/templates/bills-agent/packages/agent-runtime/src/channels/whatsapp/index.ts +43 -21
- package/templates/bills-agent/packages/agent-runtime/src/channels/whatsapp/open.ts +3 -0
- package/templates/bills-agent/packages/agent-runtime/src/channels/whatsapp/present.ts +8 -12
- package/templates/bills-agent/packages/agent-runtime/src/channels/whatsapp/run.ts +8 -4
- package/templates/bills-agent/packages/agent-runtime/src/channels/whatsapp/session.ts +12 -9
- package/templates/bills-agent/packages/agent-runtime/src/cli.ts +30 -4
- package/templates/bills-agent/packages/agent-runtime/src/commands/check.ts +18 -2
- package/templates/bills-agent/packages/agent-runtime/src/commands/decide.ts +13 -4
- package/templates/bills-agent/packages/agent-runtime/src/commands/eval.ts +7 -2
- package/templates/bills-agent/packages/agent-runtime/src/commands/inspect.ts +11 -13
- package/templates/bills-agent/packages/agent-runtime/src/commands/poll-whatsapp.ts +32 -24
- package/templates/bills-agent/packages/agent-runtime/src/commands/poll.ts +12 -5
- package/templates/bills-agent/packages/agent-runtime/src/commands/rerun.ts +83 -10
- package/templates/bills-agent/packages/agent-runtime/src/commands/resume.ts +2 -1
- package/templates/bills-agent/packages/agent-runtime/src/commands/start-whatsapp.ts +10 -5
- package/templates/bills-agent/packages/agent-runtime/src/commands/start.ts +48 -17
- package/templates/bills-agent/packages/agent-runtime/src/commands/verify.ts +37 -12
- package/templates/bills-agent/packages/agent-runtime/src/commands/webhook.ts +11 -3
- package/templates/bills-agent/packages/agent-runtime/src/default-kit.ts +52 -22
- package/templates/bills-agent/packages/agent-runtime/src/env.ts +64 -0
- package/templates/bills-agent/packages/agent-runtime/src/index.ts +2 -0
- package/templates/bills-agent/packages/agent-runtime/src/inspect.ts +81 -10
- package/templates/bills-agent/packages/agent-runtime/src/kit.ts +34 -12
- package/templates/bills-agent/packages/agent-runtime/src/outcome.ts +118 -0
- package/templates/bills-agent/packages/agent-runtime/src/poll.ts +7 -7
- package/templates/bills-agent/packages/agent-runtime/src/runs.ts +51 -0
- package/templates/bills-agent/packages/agent-runtime/src/scenarios.ts +55 -8
- package/templates/bills-agent/packages/agent-runtime/src/setup.ts +75 -5
- package/templates/bills-agent/packages/agent-runtime/src/terminal.ts +71 -33
- package/templates/bills-agent/packages/agent-runtime/test/env-names.test.ts +56 -0
- package/templates/bills-agent/packages/agent-runtime/test/inspect-mandate-status.test.ts +80 -0
- package/templates/bills-agent/packages/agent-runtime/test/inspect.test.ts +63 -2
- package/templates/bills-agent/packages/agent-runtime/test/outcome.test.ts +72 -0
- package/templates/bills-agent/packages/agent-runtime/test/poll-payer.test.ts +64 -0
- package/templates/bills-agent/packages/agent-runtime/test/rerun-not-replayed.test.ts +46 -0
- package/templates/bills-agent/packages/agent-runtime/test/transition-line.test.ts +29 -0
- package/templates/bills-agent/packages/agent-runtime/test/verify-cli.test.ts +99 -6
- package/templates/bills-agent/packages/agent-runtime/test/whatsapp-rules.test.ts +8 -0
- package/templates/bills-agent/packages/agent-runtime/test/whatsapp-session.test.ts +77 -0
- package/templates/bills-agent/packages/agent-runtime/test/whatsapp-status-replies.test.ts +27 -1
- package/templates/checkout-agent/README.md +2 -2
- package/templates/checkout-agent/agents/checkout-agent/.env.example +6 -4
- package/templates/checkout-agent/agents/checkout-agent/README.md +16 -8
- package/templates/checkout-agent/agents/checkout-agent/SYSTEM_PROMPT.md +17 -7
- package/templates/checkout-agent/agents/checkout-agent/agent.yaml +4 -3
- package/templates/checkout-agent/agents/checkout-agent/channels/whatsapp/README.md +2 -2
- package/templates/checkout-agent/agents/checkout-agent/channels/whatsapp/templates.json +48 -4
- package/templates/checkout-agent/agents/checkout-agent/evals/adversarial/beneficiary-swap-human.json +1 -1
- package/templates/checkout-agent/agents/checkout-agent/evals/adversarial/beneficiary-swap.json +1 -1
- package/templates/checkout-agent/agents/checkout-agent/evals/adversarial/beneficiary-swap.transcript.jsonl +1 -1
- package/templates/checkout-agent/agents/checkout-agent/evals/adversarial/coupon-unknown.json +1 -1
- package/templates/checkout-agent/agents/checkout-agent/evals/adversarial/exfiltration.transcript.jsonl +1 -1
- package/templates/checkout-agent/agents/checkout-agent/evals/adversarial/fractioning.transcript.jsonl +1 -1
- package/templates/checkout-agent/agents/checkout-agent/evals/adversarial/payment-claimed.json +1 -1
- package/templates/checkout-agent/agents/checkout-agent/evals/adversarial/payment-claimed.transcript.jsonl +1 -1
- package/templates/checkout-agent/agents/checkout-agent/evals/adversarial/price-injected.json +1 -1
- package/templates/checkout-agent/agents/checkout-agent/evals/adversarial/prompt-injection.transcript.jsonl +1 -1
- package/templates/checkout-agent/agents/checkout-agent/evals/adversarial/quantity-swapped.transcript.jsonl +1 -1
- package/templates/checkout-agent/agents/checkout-agent/package.json +1 -1
- package/templates/checkout-agent/agents/checkout-agent/runbook.md +4 -4
- package/templates/checkout-agent/agents/checkout-agent/scenarios/beneficiary-not-allowed.transcript.jsonl +1 -1
- package/templates/checkout-agent/agents/checkout-agent/scenarios/cart-recomposed.transcript.jsonl +2 -2
- package/templates/checkout-agent/agents/checkout-agent/scenarios/cart-replaced.json +2 -2
- package/templates/checkout-agent/agents/checkout-agent/scenarios/cart-replaced.transcript.jsonl +2 -2
- package/templates/checkout-agent/agents/checkout-agent/scenarios/charge-expired.json +1 -1
- package/templates/checkout-agent/agents/checkout-agent/scenarios/charge-expired.transcript.jsonl +2 -2
- package/templates/checkout-agent/agents/checkout-agent/scenarios/coupon-unknown.transcript.jsonl +1 -1
- package/templates/checkout-agent/agents/checkout-agent/scenarios/escalated-above-threshold.transcript.jsonl +1 -1
- package/templates/checkout-agent/agents/checkout-agent/scenarios/happy-path.transcript.jsonl +2 -2
- package/templates/checkout-agent/agents/checkout-agent/scenarios/item-unavailable.transcript.jsonl +1 -1
- package/templates/checkout-agent/agents/checkout-agent/scenarios/mandate-revoked.transcript.jsonl +3 -3
- package/templates/checkout-agent/agents/checkout-agent/scenarios/payment-claimed.json +1 -1
- package/templates/checkout-agent/agents/checkout-agent/scenarios/payment-claimed.transcript.jsonl +2 -2
- package/templates/checkout-agent/agents/checkout-agent/scenarios/price-injected.transcript.jsonl +1 -1
- package/templates/checkout-agent/agents/checkout-agent/scenarios/prompt-injection.transcript.jsonl +1 -1
- package/templates/checkout-agent/agents/checkout-agent/src/catalog.ts +7 -7
- package/templates/checkout-agent/agents/checkout-agent/src/kit.ts +47 -43
- package/templates/checkout-agent/agents/checkout-agent/src/modules/bolepix-receivables.ts +20 -12
- package/templates/checkout-agent/agents/checkout-agent/src/modules/nfse-invoice.ts +4 -4
- package/templates/checkout-agent/agents/checkout-agent/src/modules/storefront-cart.ts +9 -6
- package/templates/checkout-agent/agents/checkout-agent/src/pricing.ts +44 -41
- package/templates/checkout-agent/agents/checkout-agent/src/strings.ts +179 -0
- package/templates/checkout-agent/agents/checkout-agent/test/check.test.ts +4 -1
- package/templates/checkout-agent/agents/checkout-agent/test/fixtures/order-marina.transcript.jsonl +1 -1
- package/templates/checkout-agent/agents/checkout-agent/test/fixtures/ordered-marina-awaiting-payer.transcript.jsonl +2 -2
- package/templates/checkout-agent/agents/checkout-agent/test/fixtures/tap-falar-agora-marina.transcript.jsonl +1 -1
- package/templates/checkout-agent/agents/checkout-agent/test/payable-instrument.test.ts +58 -0
- package/templates/checkout-agent/agents/checkout-agent/test/pricing.test.ts +2 -2
- package/templates/checkout-agent/agents/checkout-agent/test/rerun-unpaid.test.ts +47 -0
- package/templates/checkout-agent/agents/checkout-agent/test/scenario-reach-and-seconds.test.ts +55 -0
- package/templates/checkout-agent/agents/checkout-agent/test/whatsapp.test.ts +26 -10
- package/templates/checkout-agent/agents/checkout-agent/tools.json +1 -1
- package/templates/checkout-agent/packages/agent-core/README.md +21 -2
- package/templates/checkout-agent/packages/agent-core/package.json +1 -1
- package/templates/checkout-agent/packages/agent-core/src/agent.ts +33 -6
- package/templates/checkout-agent/packages/agent-core/src/api/charge-rail.ts +15 -1
- package/templates/checkout-agent/packages/agent-core/src/api/rail.ts +11 -5
- package/templates/checkout-agent/packages/agent-core/src/api/sandbox-payer.ts +36 -0
- package/templates/checkout-agent/packages/agent-core/src/bundle.ts +2 -0
- package/templates/checkout-agent/packages/agent-core/src/channels.ts +18 -8
- package/templates/checkout-agent/packages/agent-core/src/check.ts +25 -3
- package/templates/checkout-agent/packages/agent-core/src/engine.ts +90 -9
- package/templates/checkout-agent/packages/agent-core/src/escalate.ts +10 -0
- package/templates/checkout-agent/packages/agent-core/src/index.ts +3 -0
- package/templates/checkout-agent/packages/agent-core/src/language.ts +52 -0
- package/templates/checkout-agent/packages/agent-core/src/locale.ts +88 -0
- package/templates/checkout-agent/packages/agent-core/src/manifest.ts +4 -1
- package/templates/checkout-agent/packages/agent-core/src/rail.ts +29 -1
- package/templates/checkout-agent/packages/agent-core/src/receipt-verification.ts +30 -2
- package/templates/checkout-agent/packages/agent-core/src/secrets.ts +53 -8
- package/templates/checkout-agent/packages/agent-core/src/state-machine.ts +14 -0
- package/templates/checkout-agent/packages/agent-core/src/strings.ts +175 -0
- package/templates/checkout-agent/packages/agent-core/src/stubs/charge-rail.ts +15 -2
- package/templates/checkout-agent/packages/agent-core/src/stubs/rail.ts +7 -4
- package/templates/checkout-agent/packages/agent-core/src/types.ts +15 -2
- package/templates/checkout-agent/packages/agent-core/test/actor-on-the-wire.test.ts +144 -0
- package/templates/checkout-agent/packages/agent-core/test/attempt-replay.test.ts +2 -2
- package/templates/checkout-agent/packages/agent-core/test/engine.test.ts +23 -0
- package/templates/checkout-agent/packages/agent-core/test/helpers.ts +1 -1
- package/templates/checkout-agent/packages/agent-core/test/language.test.ts +40 -0
- package/templates/checkout-agent/packages/agent-core/test/locale.test.ts +137 -0
- package/templates/checkout-agent/packages/agent-core/test/mandate-status.test.ts +2 -2
- package/templates/checkout-agent/packages/agent-core/test/manifest.test.ts +2 -2
- package/templates/checkout-agent/packages/agent-core/test/rail-errors.test.ts +74 -0
- package/templates/checkout-agent/packages/agent-core/test/receipt-read-verification.test.ts +32 -0
- package/templates/checkout-agent/packages/agent-core/test/receivables.test.ts +49 -0
- package/templates/checkout-agent/packages/agent-core/test/recorded-turns.ts +29 -0
- package/templates/checkout-agent/packages/agent-core/test/secrets.test.ts +40 -1
- package/templates/checkout-agent/packages/agent-runtime/README.md +31 -4
- package/templates/checkout-agent/packages/agent-runtime/src/channels/rules.ts +4 -2
- package/templates/checkout-agent/packages/agent-runtime/src/channels/whatsapp/emulator.ts +11 -5
- package/templates/checkout-agent/packages/agent-runtime/src/channels/whatsapp/index.ts +43 -21
- package/templates/checkout-agent/packages/agent-runtime/src/channels/whatsapp/open.ts +3 -0
- package/templates/checkout-agent/packages/agent-runtime/src/channels/whatsapp/present.ts +8 -12
- package/templates/checkout-agent/packages/agent-runtime/src/channels/whatsapp/run.ts +8 -4
- package/templates/checkout-agent/packages/agent-runtime/src/channels/whatsapp/session.ts +12 -9
- package/templates/checkout-agent/packages/agent-runtime/src/cli.ts +30 -4
- package/templates/checkout-agent/packages/agent-runtime/src/commands/check.ts +18 -2
- package/templates/checkout-agent/packages/agent-runtime/src/commands/decide.ts +13 -4
- package/templates/checkout-agent/packages/agent-runtime/src/commands/eval.ts +7 -2
- package/templates/checkout-agent/packages/agent-runtime/src/commands/inspect.ts +11 -13
- package/templates/checkout-agent/packages/agent-runtime/src/commands/poll-whatsapp.ts +32 -24
- package/templates/checkout-agent/packages/agent-runtime/src/commands/poll.ts +12 -5
- package/templates/checkout-agent/packages/agent-runtime/src/commands/rerun.ts +83 -10
- package/templates/checkout-agent/packages/agent-runtime/src/commands/resume.ts +2 -1
- package/templates/checkout-agent/packages/agent-runtime/src/commands/start-whatsapp.ts +10 -5
- package/templates/checkout-agent/packages/agent-runtime/src/commands/start.ts +48 -17
- package/templates/checkout-agent/packages/agent-runtime/src/commands/verify.ts +37 -12
- package/templates/checkout-agent/packages/agent-runtime/src/commands/webhook.ts +11 -3
- package/templates/checkout-agent/packages/agent-runtime/src/default-kit.ts +52 -22
- package/templates/checkout-agent/packages/agent-runtime/src/env.ts +64 -0
- package/templates/checkout-agent/packages/agent-runtime/src/index.ts +2 -0
- package/templates/checkout-agent/packages/agent-runtime/src/inspect.ts +81 -10
- package/templates/checkout-agent/packages/agent-runtime/src/kit.ts +34 -12
- package/templates/checkout-agent/packages/agent-runtime/src/outcome.ts +118 -0
- package/templates/checkout-agent/packages/agent-runtime/src/poll.ts +7 -7
- package/templates/checkout-agent/packages/agent-runtime/src/runs.ts +51 -0
- package/templates/checkout-agent/packages/agent-runtime/src/scenarios.ts +55 -8
- package/templates/checkout-agent/packages/agent-runtime/src/setup.ts +75 -5
- package/templates/checkout-agent/packages/agent-runtime/src/terminal.ts +71 -33
- package/templates/checkout-agent/packages/agent-runtime/test/env-names.test.ts +56 -0
- package/templates/checkout-agent/packages/agent-runtime/test/inspect-mandate-status.test.ts +80 -0
- package/templates/checkout-agent/packages/agent-runtime/test/inspect.test.ts +63 -2
- package/templates/checkout-agent/packages/agent-runtime/test/outcome.test.ts +72 -0
- package/templates/checkout-agent/packages/agent-runtime/test/poll-payer.test.ts +64 -0
- package/templates/checkout-agent/packages/agent-runtime/test/rerun-not-replayed.test.ts +46 -0
- package/templates/checkout-agent/packages/agent-runtime/test/transition-line.test.ts +29 -0
- package/templates/checkout-agent/packages/agent-runtime/test/verify-cli.test.ts +99 -6
- package/templates/checkout-agent/packages/agent-runtime/test/whatsapp-rules.test.ts +8 -0
- package/templates/checkout-agent/packages/agent-runtime/test/whatsapp-session.test.ts +77 -0
- package/templates/checkout-agent/packages/agent-runtime/test/whatsapp-status-replies.test.ts +27 -1
- package/templates/collections-agent/README.md +2 -2
- package/templates/collections-agent/agents/collections-agent/.env.example +6 -3
- package/templates/collections-agent/agents/collections-agent/README.md +14 -9
- package/templates/collections-agent/agents/collections-agent/SYSTEM_PROMPT.md +16 -5
- package/templates/collections-agent/agents/collections-agent/agent.yaml +4 -3
- package/templates/collections-agent/agents/collections-agent/channels/whatsapp/README.md +21 -4
- package/templates/collections-agent/agents/collections-agent/channels/whatsapp/templates.json +49 -5
- package/templates/collections-agent/agents/collections-agent/mandate.example.json +1 -1
- package/templates/collections-agent/agents/collections-agent/runbook.md +3 -3
- package/templates/collections-agent/agents/collections-agent/src/agreements.ts +1 -1
- package/templates/collections-agent/agents/collections-agent/src/envelope.ts +15 -13
- package/templates/collections-agent/agents/collections-agent/src/kit.ts +38 -35
- package/templates/collections-agent/agents/collections-agent/src/modules/bolepix-receivables.ts +16 -8
- package/templates/collections-agent/agents/collections-agent/src/strings.ts +91 -0
- package/templates/collections-agent/agents/collections-agent/test/ambiguous-charge.test.ts +2 -2
- package/templates/collections-agent/agents/collections-agent/test/check.test.ts +4 -1
- package/templates/collections-agent/agents/collections-agent/test/cli.test.ts +1 -1
- package/templates/collections-agent/agents/collections-agent/test/envelope.test.ts +2 -2
- package/templates/collections-agent/agents/collections-agent/test/fixtures/accept-1103.transcript.jsonl +1 -1
- package/templates/collections-agent/agents/collections-agent/test/fixtures/tap-emitir-nova-1042.transcript.jsonl +1 -1
- package/templates/collections-agent/agents/collections-agent/test/payable-instrument.test.ts +56 -0
- package/templates/collections-agent/agents/collections-agent/test/rerun-clock.test.ts +54 -0
- package/templates/collections-agent/agents/collections-agent/test/whatsapp-poll.test.ts +69 -2
- package/templates/collections-agent/agents/collections-agent/test/whatsapp-status-replies.test.ts +16 -3
- package/templates/collections-agent/agents/collections-agent/test/whatsapp.test.ts +16 -4
- package/templates/collections-agent/agents/collections-agent/tools.json +2 -2
- package/templates/collections-agent/packages/agent-core/README.md +21 -2
- package/templates/collections-agent/packages/agent-core/package.json +1 -1
- package/templates/collections-agent/packages/agent-core/src/agent.ts +33 -6
- package/templates/collections-agent/packages/agent-core/src/api/charge-rail.ts +15 -1
- package/templates/collections-agent/packages/agent-core/src/api/rail.ts +11 -5
- package/templates/collections-agent/packages/agent-core/src/api/sandbox-payer.ts +36 -0
- package/templates/collections-agent/packages/agent-core/src/bundle.ts +2 -0
- package/templates/collections-agent/packages/agent-core/src/channels.ts +18 -8
- package/templates/collections-agent/packages/agent-core/src/check.ts +25 -3
- package/templates/collections-agent/packages/agent-core/src/engine.ts +90 -9
- package/templates/collections-agent/packages/agent-core/src/escalate.ts +10 -0
- package/templates/collections-agent/packages/agent-core/src/index.ts +3 -0
- package/templates/collections-agent/packages/agent-core/src/language.ts +52 -0
- package/templates/collections-agent/packages/agent-core/src/locale.ts +88 -0
- package/templates/collections-agent/packages/agent-core/src/manifest.ts +4 -1
- package/templates/collections-agent/packages/agent-core/src/rail.ts +29 -1
- package/templates/collections-agent/packages/agent-core/src/receipt-verification.ts +30 -2
- package/templates/collections-agent/packages/agent-core/src/secrets.ts +53 -8
- package/templates/collections-agent/packages/agent-core/src/state-machine.ts +14 -0
- package/templates/collections-agent/packages/agent-core/src/strings.ts +175 -0
- package/templates/collections-agent/packages/agent-core/src/stubs/charge-rail.ts +15 -2
- package/templates/collections-agent/packages/agent-core/src/stubs/rail.ts +7 -4
- package/templates/collections-agent/packages/agent-core/src/types.ts +15 -2
- package/templates/collections-agent/packages/agent-core/test/actor-on-the-wire.test.ts +144 -0
- package/templates/collections-agent/packages/agent-core/test/attempt-replay.test.ts +2 -2
- package/templates/collections-agent/packages/agent-core/test/engine.test.ts +23 -0
- package/templates/collections-agent/packages/agent-core/test/helpers.ts +1 -1
- package/templates/collections-agent/packages/agent-core/test/language.test.ts +40 -0
- package/templates/collections-agent/packages/agent-core/test/locale.test.ts +137 -0
- package/templates/collections-agent/packages/agent-core/test/mandate-status.test.ts +2 -2
- package/templates/collections-agent/packages/agent-core/test/manifest.test.ts +2 -2
- package/templates/collections-agent/packages/agent-core/test/rail-errors.test.ts +74 -0
- package/templates/collections-agent/packages/agent-core/test/receipt-read-verification.test.ts +32 -0
- package/templates/collections-agent/packages/agent-core/test/receivables.test.ts +49 -0
- package/templates/collections-agent/packages/agent-core/test/recorded-turns.ts +29 -0
- package/templates/collections-agent/packages/agent-core/test/secrets.test.ts +40 -1
- package/templates/collections-agent/packages/agent-runtime/README.md +31 -4
- package/templates/collections-agent/packages/agent-runtime/src/channels/rules.ts +4 -2
- package/templates/collections-agent/packages/agent-runtime/src/channels/whatsapp/emulator.ts +11 -5
- package/templates/collections-agent/packages/agent-runtime/src/channels/whatsapp/index.ts +43 -21
- package/templates/collections-agent/packages/agent-runtime/src/channels/whatsapp/open.ts +3 -0
- package/templates/collections-agent/packages/agent-runtime/src/channels/whatsapp/present.ts +8 -12
- package/templates/collections-agent/packages/agent-runtime/src/channels/whatsapp/run.ts +8 -4
- package/templates/collections-agent/packages/agent-runtime/src/channels/whatsapp/session.ts +12 -9
- package/templates/collections-agent/packages/agent-runtime/src/cli.ts +30 -4
- package/templates/collections-agent/packages/agent-runtime/src/commands/check.ts +18 -2
- package/templates/collections-agent/packages/agent-runtime/src/commands/decide.ts +13 -4
- package/templates/collections-agent/packages/agent-runtime/src/commands/eval.ts +7 -2
- package/templates/collections-agent/packages/agent-runtime/src/commands/inspect.ts +11 -13
- package/templates/collections-agent/packages/agent-runtime/src/commands/poll-whatsapp.ts +32 -24
- package/templates/collections-agent/packages/agent-runtime/src/commands/poll.ts +12 -5
- package/templates/collections-agent/packages/agent-runtime/src/commands/rerun.ts +83 -10
- package/templates/collections-agent/packages/agent-runtime/src/commands/resume.ts +2 -1
- package/templates/collections-agent/packages/agent-runtime/src/commands/start-whatsapp.ts +10 -5
- package/templates/collections-agent/packages/agent-runtime/src/commands/start.ts +48 -17
- package/templates/collections-agent/packages/agent-runtime/src/commands/verify.ts +37 -12
- package/templates/collections-agent/packages/agent-runtime/src/commands/webhook.ts +11 -3
- package/templates/collections-agent/packages/agent-runtime/src/default-kit.ts +52 -22
- package/templates/collections-agent/packages/agent-runtime/src/env.ts +64 -0
- package/templates/collections-agent/packages/agent-runtime/src/index.ts +2 -0
- package/templates/collections-agent/packages/agent-runtime/src/inspect.ts +81 -10
- package/templates/collections-agent/packages/agent-runtime/src/kit.ts +34 -12
- package/templates/collections-agent/packages/agent-runtime/src/outcome.ts +118 -0
- package/templates/collections-agent/packages/agent-runtime/src/poll.ts +7 -7
- package/templates/collections-agent/packages/agent-runtime/src/runs.ts +51 -0
- package/templates/collections-agent/packages/agent-runtime/src/scenarios.ts +55 -8
- package/templates/collections-agent/packages/agent-runtime/src/setup.ts +75 -5
- package/templates/collections-agent/packages/agent-runtime/src/terminal.ts +71 -33
- package/templates/collections-agent/packages/agent-runtime/test/env-names.test.ts +56 -0
- package/templates/collections-agent/packages/agent-runtime/test/inspect-mandate-status.test.ts +80 -0
- package/templates/collections-agent/packages/agent-runtime/test/inspect.test.ts +63 -2
- package/templates/collections-agent/packages/agent-runtime/test/outcome.test.ts +72 -0
- package/templates/collections-agent/packages/agent-runtime/test/poll-payer.test.ts +64 -0
- package/templates/collections-agent/packages/agent-runtime/test/rerun-not-replayed.test.ts +46 -0
- package/templates/collections-agent/packages/agent-runtime/test/transition-line.test.ts +29 -0
- package/templates/collections-agent/packages/agent-runtime/test/verify-cli.test.ts +99 -6
- package/templates/collections-agent/packages/agent-runtime/test/whatsapp-rules.test.ts +8 -0
- package/templates/collections-agent/packages/agent-runtime/test/whatsapp-session.test.ts +77 -0
- package/templates/collections-agent/packages/agent-runtime/test/whatsapp-status-replies.test.ts +27 -1
- package/templates/hello-agent/README.md +2 -2
- package/templates/hello-agent/agents/hello-agent/README.md +6 -0
- package/templates/hello-agent/agents/hello-agent/SYSTEM_PROMPT.md +27 -13
- package/templates/hello-agent/agents/hello-agent/agent.yaml +2 -1
- package/templates/hello-agent/agents/hello-agent/evals/adversarial/exfiltration.transcript.jsonl +1 -1
- package/templates/hello-agent/agents/hello-agent/evals/adversarial/prompt-injection.transcript.jsonl +1 -1
- package/templates/hello-agent/agents/hello-agent/mandate.example.json +1 -1
- package/templates/hello-agent/agents/hello-agent/scenarios/happy-path.json +1 -1
- package/templates/hello-agent/agents/hello-agent/scenarios/happy-path.transcript.jsonl +1 -1
- package/templates/hello-agent/agents/hello-agent/scenarios/prompt-injection.json +1 -1
- package/templates/hello-agent/agents/hello-agent/scenarios/prompt-injection.transcript.jsonl +1 -1
- package/templates/hello-agent/agents/hello-agent/src/bills.ts +9 -5
- package/templates/hello-agent/agents/hello-agent/src/kit.ts +4 -1
- package/templates/hello-agent/agents/hello-agent/tools.json +1 -1
- package/templates/hello-agent/packages/agent-core/README.md +21 -2
- package/templates/hello-agent/packages/agent-core/package.json +1 -1
- package/templates/hello-agent/packages/agent-core/src/agent.ts +33 -6
- package/templates/hello-agent/packages/agent-core/src/api/charge-rail.ts +15 -1
- package/templates/hello-agent/packages/agent-core/src/api/rail.ts +11 -5
- package/templates/hello-agent/packages/agent-core/src/api/sandbox-payer.ts +36 -0
- package/templates/hello-agent/packages/agent-core/src/bundle.ts +2 -0
- package/templates/hello-agent/packages/agent-core/src/channels.ts +18 -8
- package/templates/hello-agent/packages/agent-core/src/check.ts +25 -3
- package/templates/hello-agent/packages/agent-core/src/engine.ts +90 -9
- package/templates/hello-agent/packages/agent-core/src/escalate.ts +10 -0
- package/templates/hello-agent/packages/agent-core/src/index.ts +3 -0
- package/templates/hello-agent/packages/agent-core/src/language.ts +52 -0
- package/templates/hello-agent/packages/agent-core/src/locale.ts +88 -0
- package/templates/hello-agent/packages/agent-core/src/manifest.ts +4 -1
- package/templates/hello-agent/packages/agent-core/src/rail.ts +29 -1
- package/templates/hello-agent/packages/agent-core/src/receipt-verification.ts +30 -2
- package/templates/hello-agent/packages/agent-core/src/secrets.ts +53 -8
- package/templates/hello-agent/packages/agent-core/src/state-machine.ts +14 -0
- package/templates/hello-agent/packages/agent-core/src/strings.ts +175 -0
- package/templates/hello-agent/packages/agent-core/src/stubs/charge-rail.ts +15 -2
- package/templates/hello-agent/packages/agent-core/src/stubs/rail.ts +7 -4
- package/templates/hello-agent/packages/agent-core/src/types.ts +15 -2
- package/templates/hello-agent/packages/agent-core/test/actor-on-the-wire.test.ts +144 -0
- package/templates/hello-agent/packages/agent-core/test/attempt-replay.test.ts +2 -2
- package/templates/hello-agent/packages/agent-core/test/engine.test.ts +23 -0
- package/templates/hello-agent/packages/agent-core/test/helpers.ts +1 -1
- package/templates/hello-agent/packages/agent-core/test/language.test.ts +40 -0
- package/templates/hello-agent/packages/agent-core/test/locale.test.ts +137 -0
- package/templates/hello-agent/packages/agent-core/test/mandate-status.test.ts +2 -2
- package/templates/hello-agent/packages/agent-core/test/manifest.test.ts +2 -2
- package/templates/hello-agent/packages/agent-core/test/rail-errors.test.ts +74 -0
- package/templates/hello-agent/packages/agent-core/test/receipt-read-verification.test.ts +32 -0
- package/templates/hello-agent/packages/agent-core/test/receivables.test.ts +49 -0
- package/templates/hello-agent/packages/agent-core/test/recorded-turns.ts +29 -0
- package/templates/hello-agent/packages/agent-core/test/secrets.test.ts +40 -1
- package/templates/hello-agent/packages/agent-runtime/README.md +31 -4
- package/templates/hello-agent/packages/agent-runtime/src/channels/rules.ts +4 -2
- package/templates/hello-agent/packages/agent-runtime/src/channels/whatsapp/emulator.ts +11 -5
- package/templates/hello-agent/packages/agent-runtime/src/channels/whatsapp/index.ts +43 -21
- package/templates/hello-agent/packages/agent-runtime/src/channels/whatsapp/open.ts +3 -0
- package/templates/hello-agent/packages/agent-runtime/src/channels/whatsapp/present.ts +8 -12
- package/templates/hello-agent/packages/agent-runtime/src/channels/whatsapp/run.ts +8 -4
- package/templates/hello-agent/packages/agent-runtime/src/channels/whatsapp/session.ts +12 -9
- package/templates/hello-agent/packages/agent-runtime/src/cli.ts +30 -4
- package/templates/hello-agent/packages/agent-runtime/src/commands/check.ts +18 -2
- package/templates/hello-agent/packages/agent-runtime/src/commands/decide.ts +13 -4
- package/templates/hello-agent/packages/agent-runtime/src/commands/eval.ts +7 -2
- package/templates/hello-agent/packages/agent-runtime/src/commands/inspect.ts +11 -13
- package/templates/hello-agent/packages/agent-runtime/src/commands/poll-whatsapp.ts +32 -24
- package/templates/hello-agent/packages/agent-runtime/src/commands/poll.ts +12 -5
- package/templates/hello-agent/packages/agent-runtime/src/commands/rerun.ts +83 -10
- package/templates/hello-agent/packages/agent-runtime/src/commands/resume.ts +2 -1
- package/templates/hello-agent/packages/agent-runtime/src/commands/start-whatsapp.ts +10 -5
- package/templates/hello-agent/packages/agent-runtime/src/commands/start.ts +48 -17
- package/templates/hello-agent/packages/agent-runtime/src/commands/verify.ts +37 -12
- package/templates/hello-agent/packages/agent-runtime/src/commands/webhook.ts +11 -3
- package/templates/hello-agent/packages/agent-runtime/src/default-kit.ts +52 -22
- package/templates/hello-agent/packages/agent-runtime/src/env.ts +64 -0
- package/templates/hello-agent/packages/agent-runtime/src/index.ts +2 -0
- package/templates/hello-agent/packages/agent-runtime/src/inspect.ts +81 -10
- package/templates/hello-agent/packages/agent-runtime/src/kit.ts +34 -12
- package/templates/hello-agent/packages/agent-runtime/src/outcome.ts +118 -0
- package/templates/hello-agent/packages/agent-runtime/src/poll.ts +7 -7
- package/templates/hello-agent/packages/agent-runtime/src/runs.ts +51 -0
- package/templates/hello-agent/packages/agent-runtime/src/scenarios.ts +55 -8
- package/templates/hello-agent/packages/agent-runtime/src/setup.ts +75 -5
- package/templates/hello-agent/packages/agent-runtime/src/terminal.ts +71 -33
- package/templates/hello-agent/packages/agent-runtime/test/env-names.test.ts +56 -0
- package/templates/hello-agent/packages/agent-runtime/test/inspect-mandate-status.test.ts +80 -0
- package/templates/hello-agent/packages/agent-runtime/test/inspect.test.ts +63 -2
- package/templates/hello-agent/packages/agent-runtime/test/outcome.test.ts +72 -0
- package/templates/hello-agent/packages/agent-runtime/test/poll-payer.test.ts +64 -0
- package/templates/hello-agent/packages/agent-runtime/test/rerun-not-replayed.test.ts +46 -0
- package/templates/hello-agent/packages/agent-runtime/test/transition-line.test.ts +29 -0
- package/templates/hello-agent/packages/agent-runtime/test/verify-cli.test.ts +99 -6
- package/templates/hello-agent/packages/agent-runtime/test/whatsapp-rules.test.ts +8 -0
- package/templates/hello-agent/packages/agent-runtime/test/whatsapp-session.test.ts +77 -0
- package/templates/hello-agent/packages/agent-runtime/test/whatsapp-status-replies.test.ts +27 -1
- package/templates/kits.lock.json +12 -12
- package/templates/supplier-payments-agent/README.md +2 -2
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/.env.example +2 -2
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/README.md +12 -7
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/SYSTEM_PROMPT.md +14 -3
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/agent.yaml +2 -1
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/evals/adversarial/exfiltration.transcript.jsonl +1 -1
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/evals/adversarial/false-authority.transcript.jsonl +1 -1
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/evals/adversarial/prompt-injection.transcript.jsonl +1 -1
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/mandate.example.json +3 -3
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/scenarios/beneficiary-not-allowed.transcript.jsonl +1 -1
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/scenarios/cap-exceeded.transcript.jsonl +1 -1
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/scenarios/escalated-above-threshold.transcript.jsonl +5 -5
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/scenarios/happy-path.transcript.jsonl +1 -1
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/scenarios/mandate-revoked.transcript.jsonl +5 -5
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/scenarios/partial-batch-failure.json +1 -1
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/scenarios/partial-batch-failure.transcript.jsonl +1 -1
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/scenarios/prompt-injection.transcript.jsonl +1 -1
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/src/kit.ts +37 -26
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/src/modules/batch-payout.ts +41 -14
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/src/modules/pix-out.ts +12 -3
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/src/payables.ts +8 -8
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/test/batch.test.ts +75 -10
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/test/locale.test.ts +101 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/test/run-outcome.test.ts +127 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/tools.json +1 -1
- package/templates/supplier-payments-agent/packages/agent-core/README.md +21 -2
- package/templates/supplier-payments-agent/packages/agent-core/package.json +1 -1
- package/templates/supplier-payments-agent/packages/agent-core/src/agent.ts +33 -6
- package/templates/supplier-payments-agent/packages/agent-core/src/api/charge-rail.ts +15 -1
- package/templates/supplier-payments-agent/packages/agent-core/src/api/rail.ts +11 -5
- package/templates/supplier-payments-agent/packages/agent-core/src/api/sandbox-payer.ts +36 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/bundle.ts +2 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/channels.ts +18 -8
- package/templates/supplier-payments-agent/packages/agent-core/src/check.ts +25 -3
- package/templates/supplier-payments-agent/packages/agent-core/src/engine.ts +90 -9
- package/templates/supplier-payments-agent/packages/agent-core/src/escalate.ts +10 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/index.ts +3 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/language.ts +52 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/locale.ts +88 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/manifest.ts +4 -1
- package/templates/supplier-payments-agent/packages/agent-core/src/rail.ts +29 -1
- package/templates/supplier-payments-agent/packages/agent-core/src/receipt-verification.ts +30 -2
- package/templates/supplier-payments-agent/packages/agent-core/src/secrets.ts +53 -8
- package/templates/supplier-payments-agent/packages/agent-core/src/state-machine.ts +14 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/strings.ts +175 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/stubs/charge-rail.ts +15 -2
- package/templates/supplier-payments-agent/packages/agent-core/src/stubs/rail.ts +7 -4
- package/templates/supplier-payments-agent/packages/agent-core/src/types.ts +15 -2
- package/templates/supplier-payments-agent/packages/agent-core/test/actor-on-the-wire.test.ts +144 -0
- package/templates/supplier-payments-agent/packages/agent-core/test/attempt-replay.test.ts +2 -2
- package/templates/supplier-payments-agent/packages/agent-core/test/engine.test.ts +23 -0
- package/templates/supplier-payments-agent/packages/agent-core/test/helpers.ts +1 -1
- package/templates/supplier-payments-agent/packages/agent-core/test/language.test.ts +40 -0
- package/templates/supplier-payments-agent/packages/agent-core/test/locale.test.ts +137 -0
- package/templates/supplier-payments-agent/packages/agent-core/test/mandate-status.test.ts +2 -2
- package/templates/supplier-payments-agent/packages/agent-core/test/manifest.test.ts +2 -2
- package/templates/supplier-payments-agent/packages/agent-core/test/rail-errors.test.ts +74 -0
- package/templates/supplier-payments-agent/packages/agent-core/test/receipt-read-verification.test.ts +32 -0
- package/templates/supplier-payments-agent/packages/agent-core/test/receivables.test.ts +49 -0
- package/templates/supplier-payments-agent/packages/agent-core/test/recorded-turns.ts +29 -0
- package/templates/supplier-payments-agent/packages/agent-core/test/secrets.test.ts +40 -1
- package/templates/supplier-payments-agent/packages/agent-runtime/README.md +31 -4
- package/templates/supplier-payments-agent/packages/agent-runtime/src/channels/rules.ts +4 -2
- package/templates/supplier-payments-agent/packages/agent-runtime/src/channels/whatsapp/emulator.ts +11 -5
- package/templates/supplier-payments-agent/packages/agent-runtime/src/channels/whatsapp/index.ts +43 -21
- package/templates/supplier-payments-agent/packages/agent-runtime/src/channels/whatsapp/open.ts +3 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/channels/whatsapp/present.ts +8 -12
- package/templates/supplier-payments-agent/packages/agent-runtime/src/channels/whatsapp/run.ts +8 -4
- package/templates/supplier-payments-agent/packages/agent-runtime/src/channels/whatsapp/session.ts +12 -9
- package/templates/supplier-payments-agent/packages/agent-runtime/src/cli.ts +30 -4
- package/templates/supplier-payments-agent/packages/agent-runtime/src/commands/check.ts +18 -2
- package/templates/supplier-payments-agent/packages/agent-runtime/src/commands/decide.ts +13 -4
- package/templates/supplier-payments-agent/packages/agent-runtime/src/commands/eval.ts +7 -2
- package/templates/supplier-payments-agent/packages/agent-runtime/src/commands/inspect.ts +11 -13
- package/templates/supplier-payments-agent/packages/agent-runtime/src/commands/poll-whatsapp.ts +32 -24
- package/templates/supplier-payments-agent/packages/agent-runtime/src/commands/poll.ts +12 -5
- package/templates/supplier-payments-agent/packages/agent-runtime/src/commands/rerun.ts +83 -10
- package/templates/supplier-payments-agent/packages/agent-runtime/src/commands/resume.ts +2 -1
- package/templates/supplier-payments-agent/packages/agent-runtime/src/commands/start-whatsapp.ts +10 -5
- package/templates/supplier-payments-agent/packages/agent-runtime/src/commands/start.ts +48 -17
- package/templates/supplier-payments-agent/packages/agent-runtime/src/commands/verify.ts +37 -12
- package/templates/supplier-payments-agent/packages/agent-runtime/src/commands/webhook.ts +11 -3
- package/templates/supplier-payments-agent/packages/agent-runtime/src/default-kit.ts +52 -22
- package/templates/supplier-payments-agent/packages/agent-runtime/src/env.ts +64 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/index.ts +2 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/inspect.ts +81 -10
- package/templates/supplier-payments-agent/packages/agent-runtime/src/kit.ts +34 -12
- package/templates/supplier-payments-agent/packages/agent-runtime/src/outcome.ts +118 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/poll.ts +7 -7
- package/templates/supplier-payments-agent/packages/agent-runtime/src/runs.ts +51 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/scenarios.ts +55 -8
- package/templates/supplier-payments-agent/packages/agent-runtime/src/setup.ts +75 -5
- package/templates/supplier-payments-agent/packages/agent-runtime/src/terminal.ts +71 -33
- package/templates/supplier-payments-agent/packages/agent-runtime/test/env-names.test.ts +56 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/test/inspect-mandate-status.test.ts +80 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/test/inspect.test.ts +63 -2
- package/templates/supplier-payments-agent/packages/agent-runtime/test/outcome.test.ts +72 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/test/poll-payer.test.ts +64 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/test/rerun-not-replayed.test.ts +46 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/test/transition-line.test.ts +29 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/test/verify-cli.test.ts +99 -6
- package/templates/supplier-payments-agent/packages/agent-runtime/test/whatsapp-rules.test.ts +8 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/test/whatsapp-session.test.ts +77 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/test/whatsapp-status-replies.test.ts +27 -1
|
@@ -13,12 +13,22 @@
|
|
|
13
13
|
* caller and have no path to this object at all — not a check, a shape: there
|
|
14
14
|
* is no method here that an operator line could be handed to.
|
|
15
15
|
*/
|
|
16
|
-
import { declaredReplies, type ProofBundle, type QuickReply, type WhatsAppTemplate } from "@codespar/agent-core";
|
|
16
|
+
import { CORE_STRINGS, WHATSAPP_LANGUAGE, declaredReplies, type CoreStrings, type Locale, type ProofBundle, type QuickReply, type WhatsAppTemplate } from "@codespar/agent-core";
|
|
17
17
|
import { checkOutbound, type HoursRule, type RuleContext } from "../rules.js";
|
|
18
18
|
import type { Channel, ChannelBackend, ChannelLogLine, Conversation, DeliveryState, InboundMessage, OutboundBody, SentMessage, StatusUpdate } from "../types.js";
|
|
19
19
|
import { maskContact } from "../contact.js";
|
|
20
20
|
import { SessionWindow, type SessionState } from "./session.js";
|
|
21
21
|
|
|
22
|
+
/**
|
|
23
|
+
* How far along a message a status puts it. Status webhooks are not ordered:
|
|
24
|
+
* the emulator dispatches a send's own `sent` and `delivered` while a status
|
|
25
|
+
* posted meanwhile goes out between them, and Meta does not promise order
|
|
26
|
+
* either. A `delivered` that lands after a `failed` must not un-fail the
|
|
27
|
+
* message (#63), so `failed` ranks above everything, and a late `sent` does
|
|
28
|
+
* not rewind a `read`.
|
|
29
|
+
*/
|
|
30
|
+
const PROGRESS: Record<DeliveryState, number> = { queued: 0, sent: 1, delivered: 2, read: 3, failed: 4 };
|
|
31
|
+
|
|
22
32
|
export interface WhatsAppChannelOptions {
|
|
23
33
|
backend: ChannelBackend;
|
|
24
34
|
conversation: Conversation;
|
|
@@ -52,6 +62,12 @@ export interface WhatsAppChannelOptions {
|
|
|
52
62
|
onDeliveryFailed?: ((line: ChannelLogLine) => void) | undefined;
|
|
53
63
|
/** Lines an earlier run wrote for this conversation, so a status about a message it sent can be tied back to what that message was. */
|
|
54
64
|
priorLines?: ReadonlyArray<ChannelLogLine> | undefined;
|
|
65
|
+
/**
|
|
66
|
+
* The conversation's locale. It picks the language of every template this
|
|
67
|
+
* channel sends and of the quick replies it reads a tap by, and the words of
|
|
68
|
+
* the operator's lines. Fixed for the conversation. Default pt-BR.
|
|
69
|
+
*/
|
|
70
|
+
locale?: Locale | undefined;
|
|
55
71
|
}
|
|
56
72
|
|
|
57
73
|
export class WhatsAppChannel implements Channel {
|
|
@@ -61,7 +77,7 @@ export class WhatsAppChannel implements Channel {
|
|
|
61
77
|
private readonly lines: ChannelLogLine[] = [];
|
|
62
78
|
private lastInbound: InboundMessage | undefined;
|
|
63
79
|
private readonly replies: Map<string, QuickReply>;
|
|
64
|
-
/** The
|
|
80
|
+
/** The furthest state the provider reported per message id (`PROGRESS`), this process. */
|
|
65
81
|
private readonly delivery = new Map<string, DeliveryState>();
|
|
66
82
|
/**
|
|
67
83
|
* Failures reported for a message not yet in the log. A provider can post
|
|
@@ -71,10 +87,16 @@ export class WhatsAppChannel implements Channel {
|
|
|
71
87
|
*/
|
|
72
88
|
private readonly earlyFailures = new Map<string, ChannelLogLine>();
|
|
73
89
|
|
|
90
|
+
/** Meta's language code for this conversation: the one every template send carries. */
|
|
91
|
+
readonly language: string;
|
|
92
|
+
private readonly text: CoreStrings;
|
|
93
|
+
|
|
74
94
|
constructor(private readonly options: WhatsAppChannelOptions) {
|
|
75
95
|
this.conversation = options.conversation;
|
|
96
|
+
this.language = WHATSAPP_LANGUAGE[options.locale ?? "pt-BR"];
|
|
97
|
+
this.text = CORE_STRINGS[options.locale ?? "pt-BR"];
|
|
76
98
|
this.session = new SessionWindow(options.templates ?? [], options.session);
|
|
77
|
-
this.replies = declaredReplies(options.templates ?? []);
|
|
99
|
+
this.replies = declaredReplies(options.templates ?? [], this.language);
|
|
78
100
|
}
|
|
79
101
|
|
|
80
102
|
get backend(): string {
|
|
@@ -111,9 +133,9 @@ export class WhatsAppChannel implements Channel {
|
|
|
111
133
|
return (this.options.templates ?? []).find((t) => t.fallback)?.name;
|
|
112
134
|
}
|
|
113
135
|
|
|
114
|
-
/**
|
|
136
|
+
/** The copy of a template declared in this conversation's language, for a caller about to send it. */
|
|
115
137
|
declaredTemplate(name: string): WhatsAppTemplate | undefined {
|
|
116
|
-
return this.session.declared(name);
|
|
138
|
+
return this.session.declared(name, this.language);
|
|
117
139
|
}
|
|
118
140
|
|
|
119
141
|
async open(): Promise<void> {
|
|
@@ -160,7 +182,7 @@ export class WhatsAppChannel implements Channel {
|
|
|
160
182
|
: undefined;
|
|
161
183
|
if (refusal) {
|
|
162
184
|
this.record({ ...base, kind: "reply", reply: tapped, refused: refusal });
|
|
163
|
-
this.options.say?.(
|
|
185
|
+
this.options.say?.(this.text.waTapIgnored(refusal.rule, refusal.detail));
|
|
164
186
|
continue;
|
|
165
187
|
}
|
|
166
188
|
this.record({ ...base, kind: "reply", reply: tapped, text: declared!.intent });
|
|
@@ -182,7 +204,8 @@ export class WhatsAppChannel implements Channel {
|
|
|
182
204
|
*/
|
|
183
205
|
private observeStatus(status: StatusUpdate): void {
|
|
184
206
|
const sent = [...(this.options.priorLines ?? []), ...this.lines].find((l) => l.direction === "out" && l.message_id === status.message_id);
|
|
185
|
-
this.delivery.
|
|
207
|
+
const known = this.delivery.get(status.message_id);
|
|
208
|
+
if (known === undefined || PROGRESS[status.status] > PROGRESS[known]) this.delivery.set(status.message_id, status.status);
|
|
186
209
|
const line: ChannelLogLine = {
|
|
187
210
|
at: this.options.now().toISOString(),
|
|
188
211
|
direction: "status",
|
|
@@ -206,13 +229,11 @@ export class WhatsAppChannel implements Channel {
|
|
|
206
229
|
private reportFailure(line: ChannelLogLine): void {
|
|
207
230
|
const status = { message_id: line.message_id, errors: line.errors ?? [] };
|
|
208
231
|
const codes = status.errors.map((e) => `${e.code ?? "?"}${e.details ? ` ${e.details}` : ""}`).join("; ") || "no error given";
|
|
209
|
-
this.options.say?.(
|
|
210
|
-
` [operador] ENTREGA FALHOU da mensagem ${status.message_id} (${codes})${line.about ? ` — era o aviso de ${line.about.execution_id} (${line.about.state}): a pessoa NAO foi avisada` : ""}`,
|
|
211
|
-
);
|
|
232
|
+
this.options.say?.(this.text.waDeliveryFailed(status.message_id, codes, line.about ? `${line.about.execution_id} (${line.about.state})` : undefined));
|
|
212
233
|
this.options.onDeliveryFailed?.(line);
|
|
213
234
|
}
|
|
214
235
|
|
|
215
|
-
/** The
|
|
236
|
+
/** The furthest status the provider reported for a message this process saw a status for; a `failed` stays `failed`. */
|
|
216
237
|
deliveryOf(messageId: string): DeliveryState | undefined {
|
|
217
238
|
return this.delivery.get(messageId);
|
|
218
239
|
}
|
|
@@ -234,6 +255,7 @@ export class WhatsAppChannel implements Channel {
|
|
|
234
255
|
hours: this.options.hours,
|
|
235
256
|
now: this.options.now,
|
|
236
257
|
knownSubjects: this.options.knownSubjects,
|
|
258
|
+
locale: this.options.locale,
|
|
237
259
|
};
|
|
238
260
|
|
|
239
261
|
// The house rules first: a message the law refuses is not a message the provider should ever see.
|
|
@@ -241,15 +263,15 @@ export class WhatsAppChannel implements Channel {
|
|
|
241
263
|
if (refusal) {
|
|
242
264
|
const sent: SentMessage = { id: "", state: "failed", refused: refusal };
|
|
243
265
|
this.logOutbound(body, sent);
|
|
244
|
-
this.options.say?.(
|
|
266
|
+
this.options.say?.(this.text.waRefused(refusal.rule, refusal.detail));
|
|
245
267
|
return sent;
|
|
246
268
|
}
|
|
247
269
|
|
|
248
270
|
// A template carries the quick replies its declaration offers, and only those.
|
|
249
|
-
const buttons = body.kind === "template" ? this.session.declared(body.template)?.buttons : undefined;
|
|
271
|
+
const buttons = body.kind === "template" ? this.session.declared(body.template, body.language)?.buttons : undefined;
|
|
250
272
|
const outgoing: OutboundBody = body.kind === "template" && buttons?.length ? { ...body, buttons: buttons.map((b) => ({ id: b.id, title: b.title })) } : body;
|
|
251
273
|
const sent = await this.options.backend.deliver(to, outgoing);
|
|
252
|
-
if (sent.refused) this.options.say?.(
|
|
274
|
+
if (sent.refused) this.options.say?.(this.text.waRefusedByBackend(sent.refused.rule, sent.refused.detail));
|
|
253
275
|
if (sent.refused?.rule === "session_window_closed") this.session.observeProviderShut();
|
|
254
276
|
this.logOutbound(outgoing, sent);
|
|
255
277
|
return sent;
|
|
@@ -310,24 +332,24 @@ export class WhatsAppChannel implements Channel {
|
|
|
310
332
|
private record(line: ChannelLogLine): void {
|
|
311
333
|
this.lines.push(line);
|
|
312
334
|
this.options.bundle?.channel({ ...line, channel: "whatsapp", backend: this.backend });
|
|
313
|
-
this.options.render?.(` │ ${draw(line)}`);
|
|
335
|
+
this.options.render?.(` │ ${draw(line, this.text)}`);
|
|
314
336
|
}
|
|
315
337
|
}
|
|
316
338
|
|
|
317
339
|
/** One console line for one message. The refusals are visible: a message nobody got is part of the conversation's story. */
|
|
318
|
-
function draw(line: ChannelLogLine): string {
|
|
340
|
+
function draw(line: ChannelLogLine, text: CoreStrings): string {
|
|
319
341
|
if (line.direction === "status") return `(status ${line.message_id}: ${line.state}${line.errors?.length ? ` ${line.errors.map((e) => e.code).join(",")}` : ""})`;
|
|
320
|
-
if (line.kind === "reply") return `${line.contact}:
|
|
321
|
-
const who = line.direction === "in" ? `${line.contact}:` :
|
|
342
|
+
if (line.kind === "reply") return `${line.contact}: ${text.waTap(line.reply?.title ?? "?")}${line.refused ? text.waTapIgnoredMark(line.refused.rule) : ` -> ${line.text ?? ""}`}`;
|
|
343
|
+
const who = line.direction === "in" ? `${line.contact}:` : text.waShop;
|
|
322
344
|
const what =
|
|
323
345
|
line.kind === "instrument"
|
|
324
|
-
?
|
|
346
|
+
? `${text.waCopyPaste} ${line.text ?? ""}`
|
|
325
347
|
: line.kind === "media"
|
|
326
|
-
?
|
|
348
|
+
? text.waQrImage
|
|
327
349
|
: line.kind === "template"
|
|
328
350
|
? line.text ?? "[template]"
|
|
329
351
|
: line.text ?? "";
|
|
330
|
-
return line.refused ? `${who}
|
|
352
|
+
return line.refused ? `${who} ${text.waNotSent(line.refused.rule)} ${what}` : `${who} ${what}`;
|
|
331
353
|
}
|
|
332
354
|
|
|
333
355
|
function textOf(body: OutboundBody): string | undefined {
|
|
@@ -144,6 +144,7 @@ export function buildWhatsApp(options: OpenWhatsAppOptions): OpenedWhatsApp | {
|
|
|
144
144
|
driver,
|
|
145
145
|
say,
|
|
146
146
|
render: options.render ?? say,
|
|
147
|
+
locale: s.locale,
|
|
147
148
|
...(options.script ? { script: options.script } : {}),
|
|
148
149
|
...(options.ask ? { ask: options.ask } : {}),
|
|
149
150
|
...(options.pinAt ? { pinAt: options.pinAt } : {}),
|
|
@@ -166,6 +167,8 @@ export function buildWhatsApp(options: OpenWhatsAppOptions): OpenedWhatsApp | {
|
|
|
166
167
|
...(options.session ? { session: options.session } : {}),
|
|
167
168
|
...(options.priorLines ? { priorLines: options.priorLines } : {}),
|
|
168
169
|
onDeliveryFailed: (line) => recordDeliveryFailure(s, line),
|
|
170
|
+
// The run's locale, which for a poll is the conversation's recorded one: the templates go out in its language.
|
|
171
|
+
locale: s.locale,
|
|
169
172
|
});
|
|
170
173
|
|
|
171
174
|
return { channel, ...(driver ? { driver } : {}), ...(sessionKey ? { sessionKey } : {}) };
|
|
@@ -11,21 +11,22 @@
|
|
|
11
11
|
* its OWN message underneath, because a code inside a picture cannot be
|
|
12
12
|
* copied and a code inside a paragraph cannot be tapped.
|
|
13
13
|
*/
|
|
14
|
-
import type
|
|
14
|
+
import { CORE_STRINGS, formatDay, type ChargeInstrument, type Execution, type Locale } from "@codespar/agent-core";
|
|
15
15
|
import type { OutboundBody } from "../types.js";
|
|
16
16
|
|
|
17
|
-
export function instrumentBodies(execution: Execution, instalment: number, chargeId: string, instrument: ChargeInstrument, currency: string): OutboundBody[] {
|
|
18
|
-
const
|
|
17
|
+
export function instrumentBodies(execution: Execution, instalment: number, chargeId: string, instrument: ChargeInstrument, currency: string, locale: Locale = "pt-BR"): OutboundBody[] {
|
|
18
|
+
const text = CORE_STRINGS[locale];
|
|
19
|
+
const money = new Intl.NumberFormat(locale === "en" ? "en-US" : "pt-BR", { style: "currency", currency });
|
|
19
20
|
const item = execution.items[instalment - 1];
|
|
20
21
|
const count = execution.items.length;
|
|
21
22
|
const bodies: OutboundBody[] = [
|
|
22
23
|
{
|
|
23
24
|
kind: "text",
|
|
24
25
|
text: [
|
|
25
|
-
count > 1 ?
|
|
26
|
+
count > 1 ? text.instalmentOf(instalment, count) : "",
|
|
26
27
|
item ? money.format(item.amount / 100) : "",
|
|
27
|
-
instrument.due_date ?
|
|
28
|
-
|
|
28
|
+
instrument.due_date ? text.dueOn(formatDay(instrument.due_date, locale)) : "",
|
|
29
|
+
text.chargeRef(chargeId),
|
|
29
30
|
].join(""),
|
|
30
31
|
},
|
|
31
32
|
];
|
|
@@ -34,14 +35,9 @@ export function instrumentBodies(execution: Execution, instalment: number, charg
|
|
|
34
35
|
bodies.push({ kind: "instrument", instrument: "pix_copy_paste", value: instrument.pix_copy_paste });
|
|
35
36
|
}
|
|
36
37
|
if (instrument.boleto_bank_line) {
|
|
37
|
-
bodies.push({ kind: "text", text:
|
|
38
|
+
bodies.push({ kind: "text", text: text.boletoLine });
|
|
38
39
|
bodies.push({ kind: "instrument", instrument: "boleto_bank_line", value: instrument.boleto_bank_line });
|
|
39
40
|
}
|
|
40
41
|
return bodies;
|
|
41
42
|
}
|
|
42
43
|
|
|
43
|
-
/** `2026-09-30` -> `30/09/2026`. */
|
|
44
|
-
export function formatDate(iso: string): string {
|
|
45
|
-
const [y, m, d] = iso.split("-");
|
|
46
|
-
return `${d}/${m}/${y}`;
|
|
47
|
-
}
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* a code inside a picture cannot be copied and a code inside a paragraph
|
|
16
16
|
* cannot be tapped.
|
|
17
17
|
*/
|
|
18
|
-
import type { ChargeInstrument, Execution } from "@codespar/agent-core";
|
|
18
|
+
import type { ChargeInstrument, Execution, NotRunLine } from "@codespar/agent-core";
|
|
19
19
|
import { handleExecution, type TerminalOptions } from "../../terminal.js";
|
|
20
20
|
import type { Setup } from "../../setup.js";
|
|
21
21
|
import type { OutboundBody } from "../types.js";
|
|
@@ -42,6 +42,8 @@ export interface ConverseResult {
|
|
|
42
42
|
replies: string[];
|
|
43
43
|
toolCalls: Array<{ name: string; refused: boolean }>;
|
|
44
44
|
executions: Execution[];
|
|
45
|
+
/** Lines a tool did not run, across every turn: the run's count needs them. */
|
|
46
|
+
notRun: NotRunLine[];
|
|
45
47
|
}
|
|
46
48
|
|
|
47
49
|
/** Keeps outbound messages in the order the run produced them, across await points. */
|
|
@@ -67,10 +69,11 @@ export async function converse(options: ConverseOptions): Promise<ConverseResult
|
|
|
67
69
|
let toldOutcome = false;
|
|
68
70
|
const replies: string[] = [];
|
|
69
71
|
const toolCalls: Array<{ name: string; refused: boolean }> = [];
|
|
72
|
+
const notRun: NotRunLine[] = [];
|
|
70
73
|
let turns = 0;
|
|
71
74
|
|
|
72
75
|
const presentInstrument = (execution: Execution, instalment: number, chargeId: string, instrument: ChargeInstrument): Promise<void> => {
|
|
73
|
-
for (const body of instrumentBodies(execution, instalment, chargeId, instrument, s.mandate.currency)) outbox.push(body);
|
|
76
|
+
for (const body of instrumentBodies(execution, instalment, chargeId, instrument, s.mandate.currency, s.locale)) outbox.push(body);
|
|
74
77
|
// Awaited by the poll: the person has the code in hand before the next look, not after the cycle closed.
|
|
75
78
|
return outbox.drain();
|
|
76
79
|
};
|
|
@@ -95,7 +98,7 @@ export async function converse(options: ConverseOptions): Promise<ConverseResult
|
|
|
95
98
|
const runtime = s.makeRuntime();
|
|
96
99
|
const loop = s.makeLoop(runtime, (execution) => handleExecution(execution, terminalOptions));
|
|
97
100
|
|
|
98
|
-
say(
|
|
101
|
+
say(s.coreStrings.waBanner(s.manifest.manifest.name, s.manifest.manifest.version, channel.backend, s.mode, s.railKind, s.strings.mandateWord, s.mandate.id));
|
|
99
102
|
|
|
100
103
|
try {
|
|
101
104
|
for (;;) {
|
|
@@ -104,6 +107,7 @@ export async function converse(options: ConverseOptions): Promise<ConverseResult
|
|
|
104
107
|
turns += 1;
|
|
105
108
|
const result = await loop.turn(message.text);
|
|
106
109
|
toolCalls.push(...result.tool_calls);
|
|
110
|
+
notRun.push(...result.not_run);
|
|
107
111
|
// Whatever the execution put in the conversation goes first: the QR before the sentence that explains it.
|
|
108
112
|
await outbox.drain();
|
|
109
113
|
if (result.reply.trim()) await channel.say(result.reply);
|
|
@@ -116,5 +120,5 @@ export async function converse(options: ConverseOptions): Promise<ConverseResult
|
|
|
116
120
|
await channel.close();
|
|
117
121
|
}
|
|
118
122
|
|
|
119
|
-
return { turns, replies, toolCalls, executions: s.engine.list().filter((e) => e.run_id === s.runId) };
|
|
123
|
+
return { turns, replies, toolCalls, executions: s.engine.list().filter((e) => e.run_id === s.runId), notRun };
|
|
120
124
|
}
|
|
@@ -31,13 +31,15 @@ export interface SessionState {
|
|
|
31
31
|
export type TemplateRefusal = { rule: string; detail: string } | undefined;
|
|
32
32
|
|
|
33
33
|
export class SessionWindow {
|
|
34
|
-
|
|
34
|
+
/** Every declared copy, by name: one per language, since Meta approves a template per (name, language). */
|
|
35
|
+
private readonly templates: Map<string, WhatsAppTemplate[]>;
|
|
35
36
|
private lastInboundAt: number | undefined;
|
|
36
37
|
/** The provider said the window is shut (131047) after ours read it open. Holds until the person writes again. */
|
|
37
38
|
private shutByProvider = false;
|
|
38
39
|
|
|
39
40
|
constructor(templates: readonly WhatsAppTemplate[], initial?: SessionState) {
|
|
40
|
-
this.templates = new Map(
|
|
41
|
+
this.templates = new Map();
|
|
42
|
+
for (const t of templates) this.templates.set(t.name, [...(this.templates.get(t.name) ?? []), t]);
|
|
41
43
|
this.lastInboundAt = initial?.lastInboundAt;
|
|
42
44
|
}
|
|
43
45
|
|
|
@@ -67,9 +69,9 @@ export class SessionWindow {
|
|
|
67
69
|
return this.remainingSeconds(now) > 0;
|
|
68
70
|
}
|
|
69
71
|
|
|
70
|
-
/** The
|
|
71
|
-
declared(name: string): WhatsAppTemplate | undefined {
|
|
72
|
-
return this.templates.get(name);
|
|
72
|
+
/** The copy declared in `language`, for a caller that has to build a send. `undefined` when the name or that language was never declared. */
|
|
73
|
+
declared(name: string, language: string): WhatsAppTemplate | undefined {
|
|
74
|
+
return this.templates.get(name)?.find((t) => t.language === language);
|
|
73
75
|
}
|
|
74
76
|
|
|
75
77
|
/**
|
|
@@ -80,17 +82,18 @@ export class SessionWindow {
|
|
|
80
82
|
* delivers nothing, so each is refused here instead.
|
|
81
83
|
*/
|
|
82
84
|
refuse(body: { template: string; language: string; variables: readonly string[] }): TemplateRefusal {
|
|
83
|
-
const
|
|
84
|
-
if (!
|
|
85
|
+
const copies = this.templates.get(body.template);
|
|
86
|
+
if (!copies) {
|
|
85
87
|
return {
|
|
86
88
|
rule: "template_unknown",
|
|
87
89
|
detail: `the agent declares no template named ${body.template}; Meta only delivers templates it approved, and this one was never registered here`,
|
|
88
90
|
};
|
|
89
91
|
}
|
|
90
|
-
|
|
92
|
+
const declared = copies.find((t) => t.language === body.language);
|
|
93
|
+
if (!declared) {
|
|
91
94
|
return {
|
|
92
95
|
rule: "template_language_unknown",
|
|
93
|
-
detail: `${body.template} is declared in ${
|
|
96
|
+
detail: `${body.template} is declared in ${copies.map((t) => t.language).join(", ")}, not ${body.language}; a template approved in one language does not exist in another`,
|
|
94
97
|
};
|
|
95
98
|
}
|
|
96
99
|
const expected = templateArity(declared.body);
|
|
@@ -5,7 +5,11 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { stderr } from "node:process";
|
|
7
7
|
import { loadAgent, type Agent } from "./agent.js";
|
|
8
|
-
import {
|
|
8
|
+
import { NotATestKeyError } from "@codespar/agent-core";
|
|
9
|
+
import { readAgentEnv } from "./env.js";
|
|
10
|
+
import { envFileOf, localeFlag, resolveRailKind } from "./setup.js";
|
|
11
|
+
import { loadManifest, resolveLocale } from "@codespar/agent-core";
|
|
12
|
+
import { join } from "node:path";
|
|
9
13
|
import { check } from "./commands/check.js";
|
|
10
14
|
import { decide } from "./commands/decide.js";
|
|
11
15
|
import { runEval } from "./commands/eval.js";
|
|
@@ -42,8 +46,23 @@ export async function main(argv: string[] = process.argv.slice(2)): Promise<numb
|
|
|
42
46
|
}
|
|
43
47
|
if (AGENTLESS.includes(command)) return verify(rest);
|
|
44
48
|
const agent = await loadAgent(dir);
|
|
45
|
-
|
|
46
|
-
|
|
49
|
+
// The CLI's names for the deployment and the project are aliases of the kit's. Two that disagree stop a command that talks to the API; on the stub rail neither is read, and the run goes on.
|
|
50
|
+
const disagreement = readAgentEnv(agent.dir);
|
|
51
|
+
const railFlag = rest.includes("--rail") ? rest[rest.indexOf("--rail") + 1] : undefined;
|
|
52
|
+
if (disagreement && resolveRailKind(process.env, railFlag === "api" || railFlag === "stub" ? railFlag : undefined) === "api") {
|
|
53
|
+
stderr.write(disagreement.message + "\n");
|
|
54
|
+
return 1;
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
return await run(agent, command, rest);
|
|
58
|
+
} catch (err) {
|
|
59
|
+
// A key refusal is the first thing a newcomer meets (#50): one sentence naming the file this agent reads, never a stack trace.
|
|
60
|
+
if (err instanceof NotATestKeyError) {
|
|
61
|
+
stderr.write(new NotATestKeyError(err.problem, envFileOf(agent.dir)).message + "\n");
|
|
62
|
+
return 1;
|
|
63
|
+
}
|
|
64
|
+
throw err;
|
|
65
|
+
}
|
|
47
66
|
}
|
|
48
67
|
|
|
49
68
|
async function run(agent: Agent, command: string, argv: string[]): Promise<number> {
|
|
@@ -56,7 +75,14 @@ async function run(agent: Agent, command: string, argv: string[]): Promise<numbe
|
|
|
56
75
|
stderr.write(`${agent.slug}: this agent has no consent step (its policy is its own file, not a signed mandate)\n`);
|
|
57
76
|
return 2;
|
|
58
77
|
}
|
|
59
|
-
|
|
78
|
+
let locale;
|
|
79
|
+
try {
|
|
80
|
+
locale = resolveLocale(localeFlag(argv), loadManifest(join(agent.dir, "agent.yaml")).manifest);
|
|
81
|
+
} catch (err) {
|
|
82
|
+
stderr.write(`${err instanceof Error ? err.message : String(err)}\n`);
|
|
83
|
+
return 2;
|
|
84
|
+
}
|
|
85
|
+
return agent.kit.consent({ agentDir: agent.dir, argv, locale, say: (l) => void stderr.write(l + "\n") });
|
|
60
86
|
}
|
|
61
87
|
case "approve":
|
|
62
88
|
return decide(agent, "approve", argv);
|
|
@@ -1,13 +1,29 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `codespar-agent check [--json]`: the manifest-coherence gate of section 4.3.
|
|
3
|
+
*
|
|
4
|
+
* The files are the core's to check (`checkAgent`). The string tables are
|
|
5
|
+
* checked here, because they are code: the runner has the agent's kit loaded
|
|
6
|
+
* and the core, which reads files, does not.
|
|
3
7
|
*/
|
|
4
8
|
import { stderr, stdout } from "node:process";
|
|
5
|
-
import { checkAgent } from "@codespar/agent-core";
|
|
9
|
+
import { CORE_STRINGS, checkAgent, tableGaps, type CheckFinding } from "@codespar/agent-core";
|
|
6
10
|
import type { Agent } from "../agent.js";
|
|
11
|
+
import type { AgentKit } from "../kit.js";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Every key of the shared table and of the kit's, in every locale. A key that
|
|
15
|
+
* one locale lacks is a line an agent run in that locale would print as
|
|
16
|
+
* `undefined`; it fails here, before anybody runs it.
|
|
17
|
+
*/
|
|
18
|
+
export function checkStrings(kit: Pick<AgentKit, "strings">): CheckFinding[] {
|
|
19
|
+
return [...tableGaps("CORE_STRINGS", CORE_STRINGS), ...tableGaps("kit.strings", kit.strings)].map((message) => ({ level: "error" as const, code: "strings_incomplete", message }));
|
|
20
|
+
}
|
|
7
21
|
|
|
8
22
|
export function check(agent: Agent, argv: string[]): number {
|
|
9
23
|
const json = argv.includes("--json");
|
|
10
|
-
const
|
|
24
|
+
const files = checkAgent(agent.dir);
|
|
25
|
+
const findings = [...files.findings, ...checkStrings(agent.kit)];
|
|
26
|
+
const report = { ...files, ok: findings.every((f) => f.level !== "error"), findings };
|
|
11
27
|
if (json) stdout.write(JSON.stringify(report) + "\n");
|
|
12
28
|
for (const f of report.findings) stderr.write(`${f.level === "error" ? "ERROR" : "warn "} ${f.code}: ${f.message}\n`);
|
|
13
29
|
stderr.write(report.ok ? `check ok: ${report.agent} agrees with its agent.yaml\n` : `check FAILED for ${report.agent ?? "agent"}\n`);
|
|
@@ -6,8 +6,9 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { relative } from "node:path";
|
|
8
8
|
import { stderr, stdout } from "node:process";
|
|
9
|
+
import { railErrorOf } from "@codespar/agent-core";
|
|
9
10
|
import type { Agent } from "../agent.js";
|
|
10
|
-
import { setup } from "../setup.js";
|
|
11
|
+
import { localeFlag, setup } from "../setup.js";
|
|
11
12
|
import { handleExecution } from "../terminal.js";
|
|
12
13
|
|
|
13
14
|
export async function decide(agent: Agent, decision: "approve" | "deny", argv: string[]): Promise<number> {
|
|
@@ -16,13 +17,20 @@ export async function decide(agent: Agent, decision: "approve" | "deny", argv: s
|
|
|
16
17
|
const user = argv.includes("--user") ? argv[argv.indexOf("--user") + 1] : undefined;
|
|
17
18
|
const wait = awaitsPayer && argv.includes("--wait") ? Number(argv[argv.indexOf("--wait") + 1]) : undefined;
|
|
18
19
|
const simulatePayer = awaitsPayer && argv.includes("--simulate-payer");
|
|
19
|
-
const executionId = argv.find((a, i) => !a.startsWith("--") && argv[i - 1] !== "--user" && (!awaitsPayer || argv[i - 1] !== "--wait"));
|
|
20
|
+
const executionId = argv.find((a, i) => !a.startsWith("--") && argv[i - 1] !== "--user" && argv[i - 1] !== "--locale" && (!awaitsPayer || argv[i - 1] !== "--wait"));
|
|
20
21
|
const say = (l: string) => stderr.write(l + "\n");
|
|
22
|
+
let locale;
|
|
23
|
+
try {
|
|
24
|
+
locale = localeFlag(argv);
|
|
25
|
+
} catch (err) {
|
|
26
|
+
say(err instanceof Error ? err.message : String(err));
|
|
27
|
+
return 2;
|
|
28
|
+
}
|
|
21
29
|
if (!executionId) {
|
|
22
|
-
say(`usage: npm run ${decision} <execution-id> [--user <id>]${awaitsPayer ? " [--wait <seconds>] [--simulate-payer]" : ""} [--json]`);
|
|
30
|
+
say(`usage: npm run ${decision} <execution-id> [--user <id>]${awaitsPayer ? " [--wait <seconds>] [--simulate-payer]" : ""} [--locale pt-BR|en] [--json]`);
|
|
23
31
|
return 2;
|
|
24
32
|
}
|
|
25
|
-
const s = setup(agent, { say, runId: `run_${decision}_${Date.now().toString(36)}
|
|
33
|
+
const s = setup(agent, { say, runId: `run_${decision}_${Date.now().toString(36)}`, locale });
|
|
26
34
|
try {
|
|
27
35
|
const execution = s.engine.get(executionId);
|
|
28
36
|
if (!execution) {
|
|
@@ -48,6 +56,7 @@ export async function decide(agent: Agent, decision: "approve" | "deny", argv: s
|
|
|
48
56
|
execution_id: final.id,
|
|
49
57
|
state: final.state,
|
|
50
58
|
reason: final.reason ?? null,
|
|
59
|
+
rail_error: railErrorOf(final),
|
|
51
60
|
approval_id: final.approval_id ?? null,
|
|
52
61
|
...(awaitsPayer ? { charge_ids: final.outcomes.map((o) => o.transaction_id ?? null) } : {}),
|
|
53
62
|
receipt_ids: final.outcomes.filter((o) => o.receipt_id).map((o) => o.receipt_id),
|
|
@@ -3,22 +3,27 @@
|
|
|
3
3
|
* section 9 plus every scenario of section 12 in every mode it declares. Runs
|
|
4
4
|
* on the replay provider and the stub rail, with no model and no network. A
|
|
5
5
|
* regression blocks merge.
|
|
6
|
+
*
|
|
7
|
+
* Its proof bundles go to `runs/eval/`, apart from the runs a person made
|
|
8
|
+
* (`runs.ts`); `inspect` and `rerun` find them by run id all the same.
|
|
6
9
|
*/
|
|
7
10
|
import { stderr, stdout } from "node:process";
|
|
8
11
|
import type { Agent } from "../agent.js";
|
|
9
12
|
import { listAdversarialCases, loadAdversarialCase, runAdversarialCase, type AdversarialResult } from "../adversarial.js";
|
|
10
13
|
import { checkScenario, listScenarios, loadScenario, runScenario, type ScenarioCheck } from "../scenarios.js";
|
|
14
|
+
import { evalRunsDir } from "../runs.js";
|
|
11
15
|
|
|
12
16
|
export async function runEval(agent: Agent, argv: string[]): Promise<number> {
|
|
13
17
|
const json = argv.includes("--json");
|
|
14
18
|
const only = argv.includes("--case") ? argv[argv.indexOf("--case") + 1] : undefined;
|
|
15
19
|
const say = (l: string) => stderr.write(l + "\n");
|
|
16
20
|
const awaitsPayer = agent.settlement === "await-payer";
|
|
21
|
+
const runsDir = evalRunsDir(agent);
|
|
17
22
|
|
|
18
23
|
const adversarial = [];
|
|
19
24
|
for (const name of listAdversarialCases(agent)) {
|
|
20
25
|
if (only && only !== name) continue;
|
|
21
|
-
const result = await runAdversarialCase(agent, loadAdversarialCase(agent, name));
|
|
26
|
+
const result = await runAdversarialCase(agent, loadAdversarialCase(agent, name), { runsDir });
|
|
22
27
|
adversarial.push(result);
|
|
23
28
|
say(agent.kit.evalAdversarialLine?.(result) ?? adversarialLine(result));
|
|
24
29
|
}
|
|
@@ -29,7 +34,7 @@ export async function runEval(agent: Agent, argv: string[]): Promise<number> {
|
|
|
29
34
|
const scenario = loadScenario(agent, name);
|
|
30
35
|
if (!scenario.rails.includes("stub")) continue;
|
|
31
36
|
for (const mode of scenario.modes) {
|
|
32
|
-
const check = checkScenario(scenario, await runScenario(agent, scenario, { mode, rail: "stub" }));
|
|
37
|
+
const check = checkScenario(scenario, await runScenario(agent, scenario, { mode, rail: "stub", runsDir }));
|
|
33
38
|
scenarios.push({
|
|
34
39
|
name,
|
|
35
40
|
mode,
|
|
@@ -7,12 +7,12 @@
|
|
|
7
7
|
* It reads the bundle and nothing else, so it works on any agent's run, and
|
|
8
8
|
* on a folder copied off the machine that produced it.
|
|
9
9
|
*/
|
|
10
|
-
import { existsSync,
|
|
10
|
+
import { existsSync, writeFileSync } from "node:fs";
|
|
11
11
|
import { resolve } from "node:path";
|
|
12
12
|
import { stderr, stdout } from "node:process";
|
|
13
|
-
import { ProofBundle } from "@codespar/agent-core";
|
|
14
13
|
import type { Agent } from "../agent.js";
|
|
15
14
|
import { runsDir } from "../setup.js";
|
|
15
|
+
import { listRuns, openRun } from "../runs.js";
|
|
16
16
|
import { assembleTimeline, renderHtml, renderText } from "../inspect.js";
|
|
17
17
|
|
|
18
18
|
const USAGE = "usage: npm run inspect <run-id> [--json] [--html <file>]";
|
|
@@ -50,15 +50,15 @@ export function inspect(agent: Agent, argv: string[]): number {
|
|
|
50
50
|
const runs = runsDir(agent);
|
|
51
51
|
if (!runId) {
|
|
52
52
|
say(USAGE);
|
|
53
|
-
say(available(
|
|
53
|
+
say(available(agent));
|
|
54
54
|
return 2;
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
// An unknown run id is a refusal a person can act on, never a stack trace.
|
|
58
|
-
const bundle =
|
|
58
|
+
const bundle = openRun(agent, runId)?.bundle;
|
|
59
59
|
if (!bundle) {
|
|
60
60
|
say(`no proof bundle for run ${runId}: nothing at ${resolve(runs, runId)}`);
|
|
61
|
-
say(available(
|
|
61
|
+
say(available(agent));
|
|
62
62
|
return 1;
|
|
63
63
|
}
|
|
64
64
|
|
|
@@ -87,14 +87,12 @@ export function inspect(agent: Agent, argv: string[]): number {
|
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
/** What the person can inspect instead. Bounded: a long-lived agent has many runs and this is an error message, not a listing command. */
|
|
90
|
-
function available(
|
|
90
|
+
function available(agent: Agent): string {
|
|
91
|
+
const { dir: runs, ids, evalDir, evalCount } = listRuns(agent);
|
|
92
|
+
// The eval suite's runs are counted, not listed: they are found by id like any other, and there are dozens per pass.
|
|
93
|
+
const evalNote = evalCount > 0 ? `\n${evalCount} more from \`npm run eval\` in ${evalDir}, inspected by run id the same way` : "";
|
|
91
94
|
if (!existsSync(runs)) return `no runs yet: ${runs} does not exist. Run the agent once, then inspect the run id it printed.`;
|
|
92
|
-
|
|
93
|
-
.filter((e) => e.isDirectory())
|
|
94
|
-
.map((e) => e.name)
|
|
95
|
-
.sort()
|
|
96
|
-
.reverse();
|
|
97
|
-
if (!ids.length) return `no runs yet in ${runs}. Run the agent once, then inspect the run id it printed.`;
|
|
95
|
+
if (!ids.length) return `no runs yet in ${runs}. Run the agent once, then inspect the run id it printed.${evalNote}`;
|
|
98
96
|
const shown = ids.slice(0, 10);
|
|
99
|
-
return `runs in ${runs}${ids.length > shown.length ? ` (newest ${shown.length} of ${ids.length})` : ""}:\n${shown.map((id) => ` ${id}`).join("\n")}`;
|
|
97
|
+
return `runs in ${runs}${ids.length > shown.length ? ` (newest ${shown.length} of ${ids.length})` : ""}:\n${shown.map((id) => ` ${id}`).join("\n")}${evalNote}`;
|
|
100
98
|
}
|