@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.
Files changed (558) hide show
  1. package/README.md +1 -1
  2. package/dist/commands/login.js +52 -12
  3. package/dist/commands/login.js.map +1 -1
  4. package/dist/index.js +1 -1
  5. package/dist/index.js.map +1 -1
  6. package/dist/surface.js +31 -13
  7. package/dist/surface.js.map +1 -1
  8. package/package.json +1 -1
  9. package/templates/bills-agent/README.md +2 -2
  10. package/templates/bills-agent/agents/bills-agent/.env.example +2 -2
  11. package/templates/bills-agent/agents/bills-agent/README.md +25 -18
  12. package/templates/bills-agent/agents/bills-agent/SYSTEM_PROMPT.md +13 -3
  13. package/templates/bills-agent/agents/bills-agent/agent.yaml +2 -1
  14. package/templates/bills-agent/agents/bills-agent/evals/adversarial/exfiltration.transcript.jsonl +1 -1
  15. package/templates/bills-agent/agents/bills-agent/evals/adversarial/false-authority.transcript.jsonl +1 -1
  16. package/templates/bills-agent/agents/bills-agent/evals/adversarial/prompt-injection.transcript.jsonl +1 -1
  17. package/templates/bills-agent/agents/bills-agent/mandate.example.json +1 -1
  18. package/templates/bills-agent/agents/bills-agent/runbook.md +1 -1
  19. package/templates/bills-agent/agents/bills-agent/scenarios/beneficiary-not-allowed.transcript.jsonl +1 -1
  20. package/templates/bills-agent/agents/bills-agent/scenarios/cap-exceeded.transcript.jsonl +1 -1
  21. package/templates/bills-agent/agents/bills-agent/scenarios/escalated-above-threshold.transcript.jsonl +4 -4
  22. package/templates/bills-agent/agents/bills-agent/scenarios/happy-path.transcript.jsonl +1 -1
  23. package/templates/bills-agent/agents/bills-agent/scenarios/mandate-revoked.json +1 -1
  24. package/templates/bills-agent/agents/bills-agent/scenarios/mandate-revoked.transcript.jsonl +4 -4
  25. package/templates/bills-agent/agents/bills-agent/scenarios/prompt-injection.transcript.jsonl +1 -1
  26. package/templates/bills-agent/agents/bills-agent/src/bills.ts +1 -1
  27. package/templates/bills-agent/agents/bills-agent/src/kit.ts +15 -28
  28. package/templates/bills-agent/agents/bills-agent/src/modules/embedded-consent.ts +42 -15
  29. package/templates/bills-agent/agents/bills-agent/src/modules/pix-out.ts +21 -3
  30. package/templates/bills-agent/agents/bills-agent/src/strings.ts +68 -0
  31. package/templates/bills-agent/agents/bills-agent/test/cli.test.ts +130 -2
  32. package/templates/bills-agent/agents/bills-agent/test/consent-money.test.ts +25 -0
  33. package/templates/bills-agent/agents/bills-agent/test/dates-and-approval.test.ts +98 -0
  34. package/templates/bills-agent/agents/bills-agent/test/eval-runs.test.ts +81 -0
  35. package/templates/bills-agent/agents/bills-agent/test/fixtures/excursao-300.transcript.jsonl +2 -2
  36. package/templates/bills-agent/agents/bills-agent/test/fixtures/material-400.transcript.jsonl +1 -1
  37. package/templates/bills-agent/agents/bills-agent/test/locale.test.ts +161 -0
  38. package/templates/bills-agent/agents/bills-agent/test/mandate-state.test.ts +108 -0
  39. package/templates/bills-agent/agents/bills-agent/test/refused-before-draft.test.ts +81 -0
  40. package/templates/bills-agent/agents/bills-agent/test/replay.test.ts +76 -0
  41. package/templates/bills-agent/agents/bills-agent/test/reply-and-outcome.test.ts +84 -0
  42. package/templates/bills-agent/agents/bills-agent/test/reply-language.test.ts +95 -0
  43. package/templates/bills-agent/agents/bills-agent/test/rerun-and-missing-transcript.test.ts +120 -0
  44. package/templates/bills-agent/agents/bills-agent/test/rerun-world-events.test.ts +55 -0
  45. package/templates/bills-agent/agents/bills-agent/tools.json +1 -1
  46. package/templates/bills-agent/packages/agent-core/README.md +21 -2
  47. package/templates/bills-agent/packages/agent-core/package.json +1 -1
  48. package/templates/bills-agent/packages/agent-core/src/agent.ts +33 -6
  49. package/templates/bills-agent/packages/agent-core/src/api/charge-rail.ts +15 -1
  50. package/templates/bills-agent/packages/agent-core/src/api/rail.ts +11 -5
  51. package/templates/bills-agent/packages/agent-core/src/api/sandbox-payer.ts +36 -0
  52. package/templates/bills-agent/packages/agent-core/src/bundle.ts +2 -0
  53. package/templates/bills-agent/packages/agent-core/src/channels.ts +18 -8
  54. package/templates/bills-agent/packages/agent-core/src/check.ts +25 -3
  55. package/templates/bills-agent/packages/agent-core/src/engine.ts +90 -9
  56. package/templates/bills-agent/packages/agent-core/src/escalate.ts +10 -0
  57. package/templates/bills-agent/packages/agent-core/src/index.ts +3 -0
  58. package/templates/bills-agent/packages/agent-core/src/language.ts +52 -0
  59. package/templates/bills-agent/packages/agent-core/src/locale.ts +88 -0
  60. package/templates/bills-agent/packages/agent-core/src/manifest.ts +4 -1
  61. package/templates/bills-agent/packages/agent-core/src/rail.ts +29 -1
  62. package/templates/bills-agent/packages/agent-core/src/receipt-verification.ts +30 -2
  63. package/templates/bills-agent/packages/agent-core/src/secrets.ts +53 -8
  64. package/templates/bills-agent/packages/agent-core/src/state-machine.ts +14 -0
  65. package/templates/bills-agent/packages/agent-core/src/strings.ts +175 -0
  66. package/templates/bills-agent/packages/agent-core/src/stubs/charge-rail.ts +15 -2
  67. package/templates/bills-agent/packages/agent-core/src/stubs/rail.ts +7 -4
  68. package/templates/bills-agent/packages/agent-core/src/types.ts +15 -2
  69. package/templates/bills-agent/packages/agent-core/test/actor-on-the-wire.test.ts +144 -0
  70. package/templates/bills-agent/packages/agent-core/test/attempt-replay.test.ts +2 -2
  71. package/templates/bills-agent/packages/agent-core/test/engine.test.ts +23 -0
  72. package/templates/bills-agent/packages/agent-core/test/helpers.ts +1 -1
  73. package/templates/bills-agent/packages/agent-core/test/language.test.ts +40 -0
  74. package/templates/bills-agent/packages/agent-core/test/locale.test.ts +137 -0
  75. package/templates/bills-agent/packages/agent-core/test/mandate-status.test.ts +2 -2
  76. package/templates/bills-agent/packages/agent-core/test/manifest.test.ts +2 -2
  77. package/templates/bills-agent/packages/agent-core/test/rail-errors.test.ts +74 -0
  78. package/templates/bills-agent/packages/agent-core/test/receipt-read-verification.test.ts +32 -0
  79. package/templates/bills-agent/packages/agent-core/test/receivables.test.ts +49 -0
  80. package/templates/bills-agent/packages/agent-core/test/recorded-turns.ts +29 -0
  81. package/templates/bills-agent/packages/agent-core/test/secrets.test.ts +40 -1
  82. package/templates/bills-agent/packages/agent-runtime/README.md +31 -4
  83. package/templates/bills-agent/packages/agent-runtime/src/channels/rules.ts +4 -2
  84. package/templates/bills-agent/packages/agent-runtime/src/channels/whatsapp/emulator.ts +11 -5
  85. package/templates/bills-agent/packages/agent-runtime/src/channels/whatsapp/index.ts +43 -21
  86. package/templates/bills-agent/packages/agent-runtime/src/channels/whatsapp/open.ts +3 -0
  87. package/templates/bills-agent/packages/agent-runtime/src/channels/whatsapp/present.ts +8 -12
  88. package/templates/bills-agent/packages/agent-runtime/src/channels/whatsapp/run.ts +8 -4
  89. package/templates/bills-agent/packages/agent-runtime/src/channels/whatsapp/session.ts +12 -9
  90. package/templates/bills-agent/packages/agent-runtime/src/cli.ts +30 -4
  91. package/templates/bills-agent/packages/agent-runtime/src/commands/check.ts +18 -2
  92. package/templates/bills-agent/packages/agent-runtime/src/commands/decide.ts +13 -4
  93. package/templates/bills-agent/packages/agent-runtime/src/commands/eval.ts +7 -2
  94. package/templates/bills-agent/packages/agent-runtime/src/commands/inspect.ts +11 -13
  95. package/templates/bills-agent/packages/agent-runtime/src/commands/poll-whatsapp.ts +32 -24
  96. package/templates/bills-agent/packages/agent-runtime/src/commands/poll.ts +12 -5
  97. package/templates/bills-agent/packages/agent-runtime/src/commands/rerun.ts +83 -10
  98. package/templates/bills-agent/packages/agent-runtime/src/commands/resume.ts +2 -1
  99. package/templates/bills-agent/packages/agent-runtime/src/commands/start-whatsapp.ts +10 -5
  100. package/templates/bills-agent/packages/agent-runtime/src/commands/start.ts +48 -17
  101. package/templates/bills-agent/packages/agent-runtime/src/commands/verify.ts +37 -12
  102. package/templates/bills-agent/packages/agent-runtime/src/commands/webhook.ts +11 -3
  103. package/templates/bills-agent/packages/agent-runtime/src/default-kit.ts +52 -22
  104. package/templates/bills-agent/packages/agent-runtime/src/env.ts +64 -0
  105. package/templates/bills-agent/packages/agent-runtime/src/index.ts +2 -0
  106. package/templates/bills-agent/packages/agent-runtime/src/inspect.ts +81 -10
  107. package/templates/bills-agent/packages/agent-runtime/src/kit.ts +34 -12
  108. package/templates/bills-agent/packages/agent-runtime/src/outcome.ts +118 -0
  109. package/templates/bills-agent/packages/agent-runtime/src/poll.ts +7 -7
  110. package/templates/bills-agent/packages/agent-runtime/src/runs.ts +51 -0
  111. package/templates/bills-agent/packages/agent-runtime/src/scenarios.ts +55 -8
  112. package/templates/bills-agent/packages/agent-runtime/src/setup.ts +75 -5
  113. package/templates/bills-agent/packages/agent-runtime/src/terminal.ts +71 -33
  114. package/templates/bills-agent/packages/agent-runtime/test/env-names.test.ts +56 -0
  115. package/templates/bills-agent/packages/agent-runtime/test/inspect-mandate-status.test.ts +80 -0
  116. package/templates/bills-agent/packages/agent-runtime/test/inspect.test.ts +63 -2
  117. package/templates/bills-agent/packages/agent-runtime/test/outcome.test.ts +72 -0
  118. package/templates/bills-agent/packages/agent-runtime/test/poll-payer.test.ts +64 -0
  119. package/templates/bills-agent/packages/agent-runtime/test/rerun-not-replayed.test.ts +46 -0
  120. package/templates/bills-agent/packages/agent-runtime/test/transition-line.test.ts +29 -0
  121. package/templates/bills-agent/packages/agent-runtime/test/verify-cli.test.ts +99 -6
  122. package/templates/bills-agent/packages/agent-runtime/test/whatsapp-rules.test.ts +8 -0
  123. package/templates/bills-agent/packages/agent-runtime/test/whatsapp-session.test.ts +77 -0
  124. package/templates/bills-agent/packages/agent-runtime/test/whatsapp-status-replies.test.ts +27 -1
  125. package/templates/checkout-agent/README.md +2 -2
  126. package/templates/checkout-agent/agents/checkout-agent/.env.example +6 -4
  127. package/templates/checkout-agent/agents/checkout-agent/README.md +16 -8
  128. package/templates/checkout-agent/agents/checkout-agent/SYSTEM_PROMPT.md +17 -7
  129. package/templates/checkout-agent/agents/checkout-agent/agent.yaml +4 -3
  130. package/templates/checkout-agent/agents/checkout-agent/channels/whatsapp/README.md +2 -2
  131. package/templates/checkout-agent/agents/checkout-agent/channels/whatsapp/templates.json +48 -4
  132. package/templates/checkout-agent/agents/checkout-agent/evals/adversarial/beneficiary-swap-human.json +1 -1
  133. package/templates/checkout-agent/agents/checkout-agent/evals/adversarial/beneficiary-swap.json +1 -1
  134. package/templates/checkout-agent/agents/checkout-agent/evals/adversarial/beneficiary-swap.transcript.jsonl +1 -1
  135. package/templates/checkout-agent/agents/checkout-agent/evals/adversarial/coupon-unknown.json +1 -1
  136. package/templates/checkout-agent/agents/checkout-agent/evals/adversarial/exfiltration.transcript.jsonl +1 -1
  137. package/templates/checkout-agent/agents/checkout-agent/evals/adversarial/fractioning.transcript.jsonl +1 -1
  138. package/templates/checkout-agent/agents/checkout-agent/evals/adversarial/payment-claimed.json +1 -1
  139. package/templates/checkout-agent/agents/checkout-agent/evals/adversarial/payment-claimed.transcript.jsonl +1 -1
  140. package/templates/checkout-agent/agents/checkout-agent/evals/adversarial/price-injected.json +1 -1
  141. package/templates/checkout-agent/agents/checkout-agent/evals/adversarial/prompt-injection.transcript.jsonl +1 -1
  142. package/templates/checkout-agent/agents/checkout-agent/evals/adversarial/quantity-swapped.transcript.jsonl +1 -1
  143. package/templates/checkout-agent/agents/checkout-agent/package.json +1 -1
  144. package/templates/checkout-agent/agents/checkout-agent/runbook.md +4 -4
  145. package/templates/checkout-agent/agents/checkout-agent/scenarios/beneficiary-not-allowed.transcript.jsonl +1 -1
  146. package/templates/checkout-agent/agents/checkout-agent/scenarios/cart-recomposed.transcript.jsonl +2 -2
  147. package/templates/checkout-agent/agents/checkout-agent/scenarios/cart-replaced.json +2 -2
  148. package/templates/checkout-agent/agents/checkout-agent/scenarios/cart-replaced.transcript.jsonl +2 -2
  149. package/templates/checkout-agent/agents/checkout-agent/scenarios/charge-expired.json +1 -1
  150. package/templates/checkout-agent/agents/checkout-agent/scenarios/charge-expired.transcript.jsonl +2 -2
  151. package/templates/checkout-agent/agents/checkout-agent/scenarios/coupon-unknown.transcript.jsonl +1 -1
  152. package/templates/checkout-agent/agents/checkout-agent/scenarios/escalated-above-threshold.transcript.jsonl +1 -1
  153. package/templates/checkout-agent/agents/checkout-agent/scenarios/happy-path.transcript.jsonl +2 -2
  154. package/templates/checkout-agent/agents/checkout-agent/scenarios/item-unavailable.transcript.jsonl +1 -1
  155. package/templates/checkout-agent/agents/checkout-agent/scenarios/mandate-revoked.transcript.jsonl +3 -3
  156. package/templates/checkout-agent/agents/checkout-agent/scenarios/payment-claimed.json +1 -1
  157. package/templates/checkout-agent/agents/checkout-agent/scenarios/payment-claimed.transcript.jsonl +2 -2
  158. package/templates/checkout-agent/agents/checkout-agent/scenarios/price-injected.transcript.jsonl +1 -1
  159. package/templates/checkout-agent/agents/checkout-agent/scenarios/prompt-injection.transcript.jsonl +1 -1
  160. package/templates/checkout-agent/agents/checkout-agent/src/catalog.ts +7 -7
  161. package/templates/checkout-agent/agents/checkout-agent/src/kit.ts +47 -43
  162. package/templates/checkout-agent/agents/checkout-agent/src/modules/bolepix-receivables.ts +20 -12
  163. package/templates/checkout-agent/agents/checkout-agent/src/modules/nfse-invoice.ts +4 -4
  164. package/templates/checkout-agent/agents/checkout-agent/src/modules/storefront-cart.ts +9 -6
  165. package/templates/checkout-agent/agents/checkout-agent/src/pricing.ts +44 -41
  166. package/templates/checkout-agent/agents/checkout-agent/src/strings.ts +179 -0
  167. package/templates/checkout-agent/agents/checkout-agent/test/check.test.ts +4 -1
  168. package/templates/checkout-agent/agents/checkout-agent/test/fixtures/order-marina.transcript.jsonl +1 -1
  169. package/templates/checkout-agent/agents/checkout-agent/test/fixtures/ordered-marina-awaiting-payer.transcript.jsonl +2 -2
  170. package/templates/checkout-agent/agents/checkout-agent/test/fixtures/tap-falar-agora-marina.transcript.jsonl +1 -1
  171. package/templates/checkout-agent/agents/checkout-agent/test/payable-instrument.test.ts +58 -0
  172. package/templates/checkout-agent/agents/checkout-agent/test/pricing.test.ts +2 -2
  173. package/templates/checkout-agent/agents/checkout-agent/test/rerun-unpaid.test.ts +47 -0
  174. package/templates/checkout-agent/agents/checkout-agent/test/scenario-reach-and-seconds.test.ts +55 -0
  175. package/templates/checkout-agent/agents/checkout-agent/test/whatsapp.test.ts +26 -10
  176. package/templates/checkout-agent/agents/checkout-agent/tools.json +1 -1
  177. package/templates/checkout-agent/packages/agent-core/README.md +21 -2
  178. package/templates/checkout-agent/packages/agent-core/package.json +1 -1
  179. package/templates/checkout-agent/packages/agent-core/src/agent.ts +33 -6
  180. package/templates/checkout-agent/packages/agent-core/src/api/charge-rail.ts +15 -1
  181. package/templates/checkout-agent/packages/agent-core/src/api/rail.ts +11 -5
  182. package/templates/checkout-agent/packages/agent-core/src/api/sandbox-payer.ts +36 -0
  183. package/templates/checkout-agent/packages/agent-core/src/bundle.ts +2 -0
  184. package/templates/checkout-agent/packages/agent-core/src/channels.ts +18 -8
  185. package/templates/checkout-agent/packages/agent-core/src/check.ts +25 -3
  186. package/templates/checkout-agent/packages/agent-core/src/engine.ts +90 -9
  187. package/templates/checkout-agent/packages/agent-core/src/escalate.ts +10 -0
  188. package/templates/checkout-agent/packages/agent-core/src/index.ts +3 -0
  189. package/templates/checkout-agent/packages/agent-core/src/language.ts +52 -0
  190. package/templates/checkout-agent/packages/agent-core/src/locale.ts +88 -0
  191. package/templates/checkout-agent/packages/agent-core/src/manifest.ts +4 -1
  192. package/templates/checkout-agent/packages/agent-core/src/rail.ts +29 -1
  193. package/templates/checkout-agent/packages/agent-core/src/receipt-verification.ts +30 -2
  194. package/templates/checkout-agent/packages/agent-core/src/secrets.ts +53 -8
  195. package/templates/checkout-agent/packages/agent-core/src/state-machine.ts +14 -0
  196. package/templates/checkout-agent/packages/agent-core/src/strings.ts +175 -0
  197. package/templates/checkout-agent/packages/agent-core/src/stubs/charge-rail.ts +15 -2
  198. package/templates/checkout-agent/packages/agent-core/src/stubs/rail.ts +7 -4
  199. package/templates/checkout-agent/packages/agent-core/src/types.ts +15 -2
  200. package/templates/checkout-agent/packages/agent-core/test/actor-on-the-wire.test.ts +144 -0
  201. package/templates/checkout-agent/packages/agent-core/test/attempt-replay.test.ts +2 -2
  202. package/templates/checkout-agent/packages/agent-core/test/engine.test.ts +23 -0
  203. package/templates/checkout-agent/packages/agent-core/test/helpers.ts +1 -1
  204. package/templates/checkout-agent/packages/agent-core/test/language.test.ts +40 -0
  205. package/templates/checkout-agent/packages/agent-core/test/locale.test.ts +137 -0
  206. package/templates/checkout-agent/packages/agent-core/test/mandate-status.test.ts +2 -2
  207. package/templates/checkout-agent/packages/agent-core/test/manifest.test.ts +2 -2
  208. package/templates/checkout-agent/packages/agent-core/test/rail-errors.test.ts +74 -0
  209. package/templates/checkout-agent/packages/agent-core/test/receipt-read-verification.test.ts +32 -0
  210. package/templates/checkout-agent/packages/agent-core/test/receivables.test.ts +49 -0
  211. package/templates/checkout-agent/packages/agent-core/test/recorded-turns.ts +29 -0
  212. package/templates/checkout-agent/packages/agent-core/test/secrets.test.ts +40 -1
  213. package/templates/checkout-agent/packages/agent-runtime/README.md +31 -4
  214. package/templates/checkout-agent/packages/agent-runtime/src/channels/rules.ts +4 -2
  215. package/templates/checkout-agent/packages/agent-runtime/src/channels/whatsapp/emulator.ts +11 -5
  216. package/templates/checkout-agent/packages/agent-runtime/src/channels/whatsapp/index.ts +43 -21
  217. package/templates/checkout-agent/packages/agent-runtime/src/channels/whatsapp/open.ts +3 -0
  218. package/templates/checkout-agent/packages/agent-runtime/src/channels/whatsapp/present.ts +8 -12
  219. package/templates/checkout-agent/packages/agent-runtime/src/channels/whatsapp/run.ts +8 -4
  220. package/templates/checkout-agent/packages/agent-runtime/src/channels/whatsapp/session.ts +12 -9
  221. package/templates/checkout-agent/packages/agent-runtime/src/cli.ts +30 -4
  222. package/templates/checkout-agent/packages/agent-runtime/src/commands/check.ts +18 -2
  223. package/templates/checkout-agent/packages/agent-runtime/src/commands/decide.ts +13 -4
  224. package/templates/checkout-agent/packages/agent-runtime/src/commands/eval.ts +7 -2
  225. package/templates/checkout-agent/packages/agent-runtime/src/commands/inspect.ts +11 -13
  226. package/templates/checkout-agent/packages/agent-runtime/src/commands/poll-whatsapp.ts +32 -24
  227. package/templates/checkout-agent/packages/agent-runtime/src/commands/poll.ts +12 -5
  228. package/templates/checkout-agent/packages/agent-runtime/src/commands/rerun.ts +83 -10
  229. package/templates/checkout-agent/packages/agent-runtime/src/commands/resume.ts +2 -1
  230. package/templates/checkout-agent/packages/agent-runtime/src/commands/start-whatsapp.ts +10 -5
  231. package/templates/checkout-agent/packages/agent-runtime/src/commands/start.ts +48 -17
  232. package/templates/checkout-agent/packages/agent-runtime/src/commands/verify.ts +37 -12
  233. package/templates/checkout-agent/packages/agent-runtime/src/commands/webhook.ts +11 -3
  234. package/templates/checkout-agent/packages/agent-runtime/src/default-kit.ts +52 -22
  235. package/templates/checkout-agent/packages/agent-runtime/src/env.ts +64 -0
  236. package/templates/checkout-agent/packages/agent-runtime/src/index.ts +2 -0
  237. package/templates/checkout-agent/packages/agent-runtime/src/inspect.ts +81 -10
  238. package/templates/checkout-agent/packages/agent-runtime/src/kit.ts +34 -12
  239. package/templates/checkout-agent/packages/agent-runtime/src/outcome.ts +118 -0
  240. package/templates/checkout-agent/packages/agent-runtime/src/poll.ts +7 -7
  241. package/templates/checkout-agent/packages/agent-runtime/src/runs.ts +51 -0
  242. package/templates/checkout-agent/packages/agent-runtime/src/scenarios.ts +55 -8
  243. package/templates/checkout-agent/packages/agent-runtime/src/setup.ts +75 -5
  244. package/templates/checkout-agent/packages/agent-runtime/src/terminal.ts +71 -33
  245. package/templates/checkout-agent/packages/agent-runtime/test/env-names.test.ts +56 -0
  246. package/templates/checkout-agent/packages/agent-runtime/test/inspect-mandate-status.test.ts +80 -0
  247. package/templates/checkout-agent/packages/agent-runtime/test/inspect.test.ts +63 -2
  248. package/templates/checkout-agent/packages/agent-runtime/test/outcome.test.ts +72 -0
  249. package/templates/checkout-agent/packages/agent-runtime/test/poll-payer.test.ts +64 -0
  250. package/templates/checkout-agent/packages/agent-runtime/test/rerun-not-replayed.test.ts +46 -0
  251. package/templates/checkout-agent/packages/agent-runtime/test/transition-line.test.ts +29 -0
  252. package/templates/checkout-agent/packages/agent-runtime/test/verify-cli.test.ts +99 -6
  253. package/templates/checkout-agent/packages/agent-runtime/test/whatsapp-rules.test.ts +8 -0
  254. package/templates/checkout-agent/packages/agent-runtime/test/whatsapp-session.test.ts +77 -0
  255. package/templates/checkout-agent/packages/agent-runtime/test/whatsapp-status-replies.test.ts +27 -1
  256. package/templates/collections-agent/README.md +2 -2
  257. package/templates/collections-agent/agents/collections-agent/.env.example +6 -3
  258. package/templates/collections-agent/agents/collections-agent/README.md +14 -9
  259. package/templates/collections-agent/agents/collections-agent/SYSTEM_PROMPT.md +16 -5
  260. package/templates/collections-agent/agents/collections-agent/agent.yaml +4 -3
  261. package/templates/collections-agent/agents/collections-agent/channels/whatsapp/README.md +21 -4
  262. package/templates/collections-agent/agents/collections-agent/channels/whatsapp/templates.json +49 -5
  263. package/templates/collections-agent/agents/collections-agent/mandate.example.json +1 -1
  264. package/templates/collections-agent/agents/collections-agent/runbook.md +3 -3
  265. package/templates/collections-agent/agents/collections-agent/src/agreements.ts +1 -1
  266. package/templates/collections-agent/agents/collections-agent/src/envelope.ts +15 -13
  267. package/templates/collections-agent/agents/collections-agent/src/kit.ts +38 -35
  268. package/templates/collections-agent/agents/collections-agent/src/modules/bolepix-receivables.ts +16 -8
  269. package/templates/collections-agent/agents/collections-agent/src/strings.ts +91 -0
  270. package/templates/collections-agent/agents/collections-agent/test/ambiguous-charge.test.ts +2 -2
  271. package/templates/collections-agent/agents/collections-agent/test/check.test.ts +4 -1
  272. package/templates/collections-agent/agents/collections-agent/test/cli.test.ts +1 -1
  273. package/templates/collections-agent/agents/collections-agent/test/envelope.test.ts +2 -2
  274. package/templates/collections-agent/agents/collections-agent/test/fixtures/accept-1103.transcript.jsonl +1 -1
  275. package/templates/collections-agent/agents/collections-agent/test/fixtures/tap-emitir-nova-1042.transcript.jsonl +1 -1
  276. package/templates/collections-agent/agents/collections-agent/test/payable-instrument.test.ts +56 -0
  277. package/templates/collections-agent/agents/collections-agent/test/rerun-clock.test.ts +54 -0
  278. package/templates/collections-agent/agents/collections-agent/test/whatsapp-poll.test.ts +69 -2
  279. package/templates/collections-agent/agents/collections-agent/test/whatsapp-status-replies.test.ts +16 -3
  280. package/templates/collections-agent/agents/collections-agent/test/whatsapp.test.ts +16 -4
  281. package/templates/collections-agent/agents/collections-agent/tools.json +2 -2
  282. package/templates/collections-agent/packages/agent-core/README.md +21 -2
  283. package/templates/collections-agent/packages/agent-core/package.json +1 -1
  284. package/templates/collections-agent/packages/agent-core/src/agent.ts +33 -6
  285. package/templates/collections-agent/packages/agent-core/src/api/charge-rail.ts +15 -1
  286. package/templates/collections-agent/packages/agent-core/src/api/rail.ts +11 -5
  287. package/templates/collections-agent/packages/agent-core/src/api/sandbox-payer.ts +36 -0
  288. package/templates/collections-agent/packages/agent-core/src/bundle.ts +2 -0
  289. package/templates/collections-agent/packages/agent-core/src/channels.ts +18 -8
  290. package/templates/collections-agent/packages/agent-core/src/check.ts +25 -3
  291. package/templates/collections-agent/packages/agent-core/src/engine.ts +90 -9
  292. package/templates/collections-agent/packages/agent-core/src/escalate.ts +10 -0
  293. package/templates/collections-agent/packages/agent-core/src/index.ts +3 -0
  294. package/templates/collections-agent/packages/agent-core/src/language.ts +52 -0
  295. package/templates/collections-agent/packages/agent-core/src/locale.ts +88 -0
  296. package/templates/collections-agent/packages/agent-core/src/manifest.ts +4 -1
  297. package/templates/collections-agent/packages/agent-core/src/rail.ts +29 -1
  298. package/templates/collections-agent/packages/agent-core/src/receipt-verification.ts +30 -2
  299. package/templates/collections-agent/packages/agent-core/src/secrets.ts +53 -8
  300. package/templates/collections-agent/packages/agent-core/src/state-machine.ts +14 -0
  301. package/templates/collections-agent/packages/agent-core/src/strings.ts +175 -0
  302. package/templates/collections-agent/packages/agent-core/src/stubs/charge-rail.ts +15 -2
  303. package/templates/collections-agent/packages/agent-core/src/stubs/rail.ts +7 -4
  304. package/templates/collections-agent/packages/agent-core/src/types.ts +15 -2
  305. package/templates/collections-agent/packages/agent-core/test/actor-on-the-wire.test.ts +144 -0
  306. package/templates/collections-agent/packages/agent-core/test/attempt-replay.test.ts +2 -2
  307. package/templates/collections-agent/packages/agent-core/test/engine.test.ts +23 -0
  308. package/templates/collections-agent/packages/agent-core/test/helpers.ts +1 -1
  309. package/templates/collections-agent/packages/agent-core/test/language.test.ts +40 -0
  310. package/templates/collections-agent/packages/agent-core/test/locale.test.ts +137 -0
  311. package/templates/collections-agent/packages/agent-core/test/mandate-status.test.ts +2 -2
  312. package/templates/collections-agent/packages/agent-core/test/manifest.test.ts +2 -2
  313. package/templates/collections-agent/packages/agent-core/test/rail-errors.test.ts +74 -0
  314. package/templates/collections-agent/packages/agent-core/test/receipt-read-verification.test.ts +32 -0
  315. package/templates/collections-agent/packages/agent-core/test/receivables.test.ts +49 -0
  316. package/templates/collections-agent/packages/agent-core/test/recorded-turns.ts +29 -0
  317. package/templates/collections-agent/packages/agent-core/test/secrets.test.ts +40 -1
  318. package/templates/collections-agent/packages/agent-runtime/README.md +31 -4
  319. package/templates/collections-agent/packages/agent-runtime/src/channels/rules.ts +4 -2
  320. package/templates/collections-agent/packages/agent-runtime/src/channels/whatsapp/emulator.ts +11 -5
  321. package/templates/collections-agent/packages/agent-runtime/src/channels/whatsapp/index.ts +43 -21
  322. package/templates/collections-agent/packages/agent-runtime/src/channels/whatsapp/open.ts +3 -0
  323. package/templates/collections-agent/packages/agent-runtime/src/channels/whatsapp/present.ts +8 -12
  324. package/templates/collections-agent/packages/agent-runtime/src/channels/whatsapp/run.ts +8 -4
  325. package/templates/collections-agent/packages/agent-runtime/src/channels/whatsapp/session.ts +12 -9
  326. package/templates/collections-agent/packages/agent-runtime/src/cli.ts +30 -4
  327. package/templates/collections-agent/packages/agent-runtime/src/commands/check.ts +18 -2
  328. package/templates/collections-agent/packages/agent-runtime/src/commands/decide.ts +13 -4
  329. package/templates/collections-agent/packages/agent-runtime/src/commands/eval.ts +7 -2
  330. package/templates/collections-agent/packages/agent-runtime/src/commands/inspect.ts +11 -13
  331. package/templates/collections-agent/packages/agent-runtime/src/commands/poll-whatsapp.ts +32 -24
  332. package/templates/collections-agent/packages/agent-runtime/src/commands/poll.ts +12 -5
  333. package/templates/collections-agent/packages/agent-runtime/src/commands/rerun.ts +83 -10
  334. package/templates/collections-agent/packages/agent-runtime/src/commands/resume.ts +2 -1
  335. package/templates/collections-agent/packages/agent-runtime/src/commands/start-whatsapp.ts +10 -5
  336. package/templates/collections-agent/packages/agent-runtime/src/commands/start.ts +48 -17
  337. package/templates/collections-agent/packages/agent-runtime/src/commands/verify.ts +37 -12
  338. package/templates/collections-agent/packages/agent-runtime/src/commands/webhook.ts +11 -3
  339. package/templates/collections-agent/packages/agent-runtime/src/default-kit.ts +52 -22
  340. package/templates/collections-agent/packages/agent-runtime/src/env.ts +64 -0
  341. package/templates/collections-agent/packages/agent-runtime/src/index.ts +2 -0
  342. package/templates/collections-agent/packages/agent-runtime/src/inspect.ts +81 -10
  343. package/templates/collections-agent/packages/agent-runtime/src/kit.ts +34 -12
  344. package/templates/collections-agent/packages/agent-runtime/src/outcome.ts +118 -0
  345. package/templates/collections-agent/packages/agent-runtime/src/poll.ts +7 -7
  346. package/templates/collections-agent/packages/agent-runtime/src/runs.ts +51 -0
  347. package/templates/collections-agent/packages/agent-runtime/src/scenarios.ts +55 -8
  348. package/templates/collections-agent/packages/agent-runtime/src/setup.ts +75 -5
  349. package/templates/collections-agent/packages/agent-runtime/src/terminal.ts +71 -33
  350. package/templates/collections-agent/packages/agent-runtime/test/env-names.test.ts +56 -0
  351. package/templates/collections-agent/packages/agent-runtime/test/inspect-mandate-status.test.ts +80 -0
  352. package/templates/collections-agent/packages/agent-runtime/test/inspect.test.ts +63 -2
  353. package/templates/collections-agent/packages/agent-runtime/test/outcome.test.ts +72 -0
  354. package/templates/collections-agent/packages/agent-runtime/test/poll-payer.test.ts +64 -0
  355. package/templates/collections-agent/packages/agent-runtime/test/rerun-not-replayed.test.ts +46 -0
  356. package/templates/collections-agent/packages/agent-runtime/test/transition-line.test.ts +29 -0
  357. package/templates/collections-agent/packages/agent-runtime/test/verify-cli.test.ts +99 -6
  358. package/templates/collections-agent/packages/agent-runtime/test/whatsapp-rules.test.ts +8 -0
  359. package/templates/collections-agent/packages/agent-runtime/test/whatsapp-session.test.ts +77 -0
  360. package/templates/collections-agent/packages/agent-runtime/test/whatsapp-status-replies.test.ts +27 -1
  361. package/templates/hello-agent/README.md +2 -2
  362. package/templates/hello-agent/agents/hello-agent/README.md +6 -0
  363. package/templates/hello-agent/agents/hello-agent/SYSTEM_PROMPT.md +27 -13
  364. package/templates/hello-agent/agents/hello-agent/agent.yaml +2 -1
  365. package/templates/hello-agent/agents/hello-agent/evals/adversarial/exfiltration.transcript.jsonl +1 -1
  366. package/templates/hello-agent/agents/hello-agent/evals/adversarial/prompt-injection.transcript.jsonl +1 -1
  367. package/templates/hello-agent/agents/hello-agent/mandate.example.json +1 -1
  368. package/templates/hello-agent/agents/hello-agent/scenarios/happy-path.json +1 -1
  369. package/templates/hello-agent/agents/hello-agent/scenarios/happy-path.transcript.jsonl +1 -1
  370. package/templates/hello-agent/agents/hello-agent/scenarios/prompt-injection.json +1 -1
  371. package/templates/hello-agent/agents/hello-agent/scenarios/prompt-injection.transcript.jsonl +1 -1
  372. package/templates/hello-agent/agents/hello-agent/src/bills.ts +9 -5
  373. package/templates/hello-agent/agents/hello-agent/src/kit.ts +4 -1
  374. package/templates/hello-agent/agents/hello-agent/tools.json +1 -1
  375. package/templates/hello-agent/packages/agent-core/README.md +21 -2
  376. package/templates/hello-agent/packages/agent-core/package.json +1 -1
  377. package/templates/hello-agent/packages/agent-core/src/agent.ts +33 -6
  378. package/templates/hello-agent/packages/agent-core/src/api/charge-rail.ts +15 -1
  379. package/templates/hello-agent/packages/agent-core/src/api/rail.ts +11 -5
  380. package/templates/hello-agent/packages/agent-core/src/api/sandbox-payer.ts +36 -0
  381. package/templates/hello-agent/packages/agent-core/src/bundle.ts +2 -0
  382. package/templates/hello-agent/packages/agent-core/src/channels.ts +18 -8
  383. package/templates/hello-agent/packages/agent-core/src/check.ts +25 -3
  384. package/templates/hello-agent/packages/agent-core/src/engine.ts +90 -9
  385. package/templates/hello-agent/packages/agent-core/src/escalate.ts +10 -0
  386. package/templates/hello-agent/packages/agent-core/src/index.ts +3 -0
  387. package/templates/hello-agent/packages/agent-core/src/language.ts +52 -0
  388. package/templates/hello-agent/packages/agent-core/src/locale.ts +88 -0
  389. package/templates/hello-agent/packages/agent-core/src/manifest.ts +4 -1
  390. package/templates/hello-agent/packages/agent-core/src/rail.ts +29 -1
  391. package/templates/hello-agent/packages/agent-core/src/receipt-verification.ts +30 -2
  392. package/templates/hello-agent/packages/agent-core/src/secrets.ts +53 -8
  393. package/templates/hello-agent/packages/agent-core/src/state-machine.ts +14 -0
  394. package/templates/hello-agent/packages/agent-core/src/strings.ts +175 -0
  395. package/templates/hello-agent/packages/agent-core/src/stubs/charge-rail.ts +15 -2
  396. package/templates/hello-agent/packages/agent-core/src/stubs/rail.ts +7 -4
  397. package/templates/hello-agent/packages/agent-core/src/types.ts +15 -2
  398. package/templates/hello-agent/packages/agent-core/test/actor-on-the-wire.test.ts +144 -0
  399. package/templates/hello-agent/packages/agent-core/test/attempt-replay.test.ts +2 -2
  400. package/templates/hello-agent/packages/agent-core/test/engine.test.ts +23 -0
  401. package/templates/hello-agent/packages/agent-core/test/helpers.ts +1 -1
  402. package/templates/hello-agent/packages/agent-core/test/language.test.ts +40 -0
  403. package/templates/hello-agent/packages/agent-core/test/locale.test.ts +137 -0
  404. package/templates/hello-agent/packages/agent-core/test/mandate-status.test.ts +2 -2
  405. package/templates/hello-agent/packages/agent-core/test/manifest.test.ts +2 -2
  406. package/templates/hello-agent/packages/agent-core/test/rail-errors.test.ts +74 -0
  407. package/templates/hello-agent/packages/agent-core/test/receipt-read-verification.test.ts +32 -0
  408. package/templates/hello-agent/packages/agent-core/test/receivables.test.ts +49 -0
  409. package/templates/hello-agent/packages/agent-core/test/recorded-turns.ts +29 -0
  410. package/templates/hello-agent/packages/agent-core/test/secrets.test.ts +40 -1
  411. package/templates/hello-agent/packages/agent-runtime/README.md +31 -4
  412. package/templates/hello-agent/packages/agent-runtime/src/channels/rules.ts +4 -2
  413. package/templates/hello-agent/packages/agent-runtime/src/channels/whatsapp/emulator.ts +11 -5
  414. package/templates/hello-agent/packages/agent-runtime/src/channels/whatsapp/index.ts +43 -21
  415. package/templates/hello-agent/packages/agent-runtime/src/channels/whatsapp/open.ts +3 -0
  416. package/templates/hello-agent/packages/agent-runtime/src/channels/whatsapp/present.ts +8 -12
  417. package/templates/hello-agent/packages/agent-runtime/src/channels/whatsapp/run.ts +8 -4
  418. package/templates/hello-agent/packages/agent-runtime/src/channels/whatsapp/session.ts +12 -9
  419. package/templates/hello-agent/packages/agent-runtime/src/cli.ts +30 -4
  420. package/templates/hello-agent/packages/agent-runtime/src/commands/check.ts +18 -2
  421. package/templates/hello-agent/packages/agent-runtime/src/commands/decide.ts +13 -4
  422. package/templates/hello-agent/packages/agent-runtime/src/commands/eval.ts +7 -2
  423. package/templates/hello-agent/packages/agent-runtime/src/commands/inspect.ts +11 -13
  424. package/templates/hello-agent/packages/agent-runtime/src/commands/poll-whatsapp.ts +32 -24
  425. package/templates/hello-agent/packages/agent-runtime/src/commands/poll.ts +12 -5
  426. package/templates/hello-agent/packages/agent-runtime/src/commands/rerun.ts +83 -10
  427. package/templates/hello-agent/packages/agent-runtime/src/commands/resume.ts +2 -1
  428. package/templates/hello-agent/packages/agent-runtime/src/commands/start-whatsapp.ts +10 -5
  429. package/templates/hello-agent/packages/agent-runtime/src/commands/start.ts +48 -17
  430. package/templates/hello-agent/packages/agent-runtime/src/commands/verify.ts +37 -12
  431. package/templates/hello-agent/packages/agent-runtime/src/commands/webhook.ts +11 -3
  432. package/templates/hello-agent/packages/agent-runtime/src/default-kit.ts +52 -22
  433. package/templates/hello-agent/packages/agent-runtime/src/env.ts +64 -0
  434. package/templates/hello-agent/packages/agent-runtime/src/index.ts +2 -0
  435. package/templates/hello-agent/packages/agent-runtime/src/inspect.ts +81 -10
  436. package/templates/hello-agent/packages/agent-runtime/src/kit.ts +34 -12
  437. package/templates/hello-agent/packages/agent-runtime/src/outcome.ts +118 -0
  438. package/templates/hello-agent/packages/agent-runtime/src/poll.ts +7 -7
  439. package/templates/hello-agent/packages/agent-runtime/src/runs.ts +51 -0
  440. package/templates/hello-agent/packages/agent-runtime/src/scenarios.ts +55 -8
  441. package/templates/hello-agent/packages/agent-runtime/src/setup.ts +75 -5
  442. package/templates/hello-agent/packages/agent-runtime/src/terminal.ts +71 -33
  443. package/templates/hello-agent/packages/agent-runtime/test/env-names.test.ts +56 -0
  444. package/templates/hello-agent/packages/agent-runtime/test/inspect-mandate-status.test.ts +80 -0
  445. package/templates/hello-agent/packages/agent-runtime/test/inspect.test.ts +63 -2
  446. package/templates/hello-agent/packages/agent-runtime/test/outcome.test.ts +72 -0
  447. package/templates/hello-agent/packages/agent-runtime/test/poll-payer.test.ts +64 -0
  448. package/templates/hello-agent/packages/agent-runtime/test/rerun-not-replayed.test.ts +46 -0
  449. package/templates/hello-agent/packages/agent-runtime/test/transition-line.test.ts +29 -0
  450. package/templates/hello-agent/packages/agent-runtime/test/verify-cli.test.ts +99 -6
  451. package/templates/hello-agent/packages/agent-runtime/test/whatsapp-rules.test.ts +8 -0
  452. package/templates/hello-agent/packages/agent-runtime/test/whatsapp-session.test.ts +77 -0
  453. package/templates/hello-agent/packages/agent-runtime/test/whatsapp-status-replies.test.ts +27 -1
  454. package/templates/kits.lock.json +12 -12
  455. package/templates/supplier-payments-agent/README.md +2 -2
  456. package/templates/supplier-payments-agent/agents/supplier-payments-agent/.env.example +2 -2
  457. package/templates/supplier-payments-agent/agents/supplier-payments-agent/README.md +12 -7
  458. package/templates/supplier-payments-agent/agents/supplier-payments-agent/SYSTEM_PROMPT.md +14 -3
  459. package/templates/supplier-payments-agent/agents/supplier-payments-agent/agent.yaml +2 -1
  460. package/templates/supplier-payments-agent/agents/supplier-payments-agent/evals/adversarial/exfiltration.transcript.jsonl +1 -1
  461. package/templates/supplier-payments-agent/agents/supplier-payments-agent/evals/adversarial/false-authority.transcript.jsonl +1 -1
  462. package/templates/supplier-payments-agent/agents/supplier-payments-agent/evals/adversarial/prompt-injection.transcript.jsonl +1 -1
  463. package/templates/supplier-payments-agent/agents/supplier-payments-agent/mandate.example.json +3 -3
  464. package/templates/supplier-payments-agent/agents/supplier-payments-agent/scenarios/beneficiary-not-allowed.transcript.jsonl +1 -1
  465. package/templates/supplier-payments-agent/agents/supplier-payments-agent/scenarios/cap-exceeded.transcript.jsonl +1 -1
  466. package/templates/supplier-payments-agent/agents/supplier-payments-agent/scenarios/escalated-above-threshold.transcript.jsonl +5 -5
  467. package/templates/supplier-payments-agent/agents/supplier-payments-agent/scenarios/happy-path.transcript.jsonl +1 -1
  468. package/templates/supplier-payments-agent/agents/supplier-payments-agent/scenarios/mandate-revoked.transcript.jsonl +5 -5
  469. package/templates/supplier-payments-agent/agents/supplier-payments-agent/scenarios/partial-batch-failure.json +1 -1
  470. package/templates/supplier-payments-agent/agents/supplier-payments-agent/scenarios/partial-batch-failure.transcript.jsonl +1 -1
  471. package/templates/supplier-payments-agent/agents/supplier-payments-agent/scenarios/prompt-injection.transcript.jsonl +1 -1
  472. package/templates/supplier-payments-agent/agents/supplier-payments-agent/src/kit.ts +37 -26
  473. package/templates/supplier-payments-agent/agents/supplier-payments-agent/src/modules/batch-payout.ts +41 -14
  474. package/templates/supplier-payments-agent/agents/supplier-payments-agent/src/modules/pix-out.ts +12 -3
  475. package/templates/supplier-payments-agent/agents/supplier-payments-agent/src/payables.ts +8 -8
  476. package/templates/supplier-payments-agent/agents/supplier-payments-agent/test/batch.test.ts +75 -10
  477. package/templates/supplier-payments-agent/agents/supplier-payments-agent/test/locale.test.ts +101 -0
  478. package/templates/supplier-payments-agent/agents/supplier-payments-agent/test/run-outcome.test.ts +127 -0
  479. package/templates/supplier-payments-agent/agents/supplier-payments-agent/tools.json +1 -1
  480. package/templates/supplier-payments-agent/packages/agent-core/README.md +21 -2
  481. package/templates/supplier-payments-agent/packages/agent-core/package.json +1 -1
  482. package/templates/supplier-payments-agent/packages/agent-core/src/agent.ts +33 -6
  483. package/templates/supplier-payments-agent/packages/agent-core/src/api/charge-rail.ts +15 -1
  484. package/templates/supplier-payments-agent/packages/agent-core/src/api/rail.ts +11 -5
  485. package/templates/supplier-payments-agent/packages/agent-core/src/api/sandbox-payer.ts +36 -0
  486. package/templates/supplier-payments-agent/packages/agent-core/src/bundle.ts +2 -0
  487. package/templates/supplier-payments-agent/packages/agent-core/src/channels.ts +18 -8
  488. package/templates/supplier-payments-agent/packages/agent-core/src/check.ts +25 -3
  489. package/templates/supplier-payments-agent/packages/agent-core/src/engine.ts +90 -9
  490. package/templates/supplier-payments-agent/packages/agent-core/src/escalate.ts +10 -0
  491. package/templates/supplier-payments-agent/packages/agent-core/src/index.ts +3 -0
  492. package/templates/supplier-payments-agent/packages/agent-core/src/language.ts +52 -0
  493. package/templates/supplier-payments-agent/packages/agent-core/src/locale.ts +88 -0
  494. package/templates/supplier-payments-agent/packages/agent-core/src/manifest.ts +4 -1
  495. package/templates/supplier-payments-agent/packages/agent-core/src/rail.ts +29 -1
  496. package/templates/supplier-payments-agent/packages/agent-core/src/receipt-verification.ts +30 -2
  497. package/templates/supplier-payments-agent/packages/agent-core/src/secrets.ts +53 -8
  498. package/templates/supplier-payments-agent/packages/agent-core/src/state-machine.ts +14 -0
  499. package/templates/supplier-payments-agent/packages/agent-core/src/strings.ts +175 -0
  500. package/templates/supplier-payments-agent/packages/agent-core/src/stubs/charge-rail.ts +15 -2
  501. package/templates/supplier-payments-agent/packages/agent-core/src/stubs/rail.ts +7 -4
  502. package/templates/supplier-payments-agent/packages/agent-core/src/types.ts +15 -2
  503. package/templates/supplier-payments-agent/packages/agent-core/test/actor-on-the-wire.test.ts +144 -0
  504. package/templates/supplier-payments-agent/packages/agent-core/test/attempt-replay.test.ts +2 -2
  505. package/templates/supplier-payments-agent/packages/agent-core/test/engine.test.ts +23 -0
  506. package/templates/supplier-payments-agent/packages/agent-core/test/helpers.ts +1 -1
  507. package/templates/supplier-payments-agent/packages/agent-core/test/language.test.ts +40 -0
  508. package/templates/supplier-payments-agent/packages/agent-core/test/locale.test.ts +137 -0
  509. package/templates/supplier-payments-agent/packages/agent-core/test/mandate-status.test.ts +2 -2
  510. package/templates/supplier-payments-agent/packages/agent-core/test/manifest.test.ts +2 -2
  511. package/templates/supplier-payments-agent/packages/agent-core/test/rail-errors.test.ts +74 -0
  512. package/templates/supplier-payments-agent/packages/agent-core/test/receipt-read-verification.test.ts +32 -0
  513. package/templates/supplier-payments-agent/packages/agent-core/test/receivables.test.ts +49 -0
  514. package/templates/supplier-payments-agent/packages/agent-core/test/recorded-turns.ts +29 -0
  515. package/templates/supplier-payments-agent/packages/agent-core/test/secrets.test.ts +40 -1
  516. package/templates/supplier-payments-agent/packages/agent-runtime/README.md +31 -4
  517. package/templates/supplier-payments-agent/packages/agent-runtime/src/channels/rules.ts +4 -2
  518. package/templates/supplier-payments-agent/packages/agent-runtime/src/channels/whatsapp/emulator.ts +11 -5
  519. package/templates/supplier-payments-agent/packages/agent-runtime/src/channels/whatsapp/index.ts +43 -21
  520. package/templates/supplier-payments-agent/packages/agent-runtime/src/channels/whatsapp/open.ts +3 -0
  521. package/templates/supplier-payments-agent/packages/agent-runtime/src/channels/whatsapp/present.ts +8 -12
  522. package/templates/supplier-payments-agent/packages/agent-runtime/src/channels/whatsapp/run.ts +8 -4
  523. package/templates/supplier-payments-agent/packages/agent-runtime/src/channels/whatsapp/session.ts +12 -9
  524. package/templates/supplier-payments-agent/packages/agent-runtime/src/cli.ts +30 -4
  525. package/templates/supplier-payments-agent/packages/agent-runtime/src/commands/check.ts +18 -2
  526. package/templates/supplier-payments-agent/packages/agent-runtime/src/commands/decide.ts +13 -4
  527. package/templates/supplier-payments-agent/packages/agent-runtime/src/commands/eval.ts +7 -2
  528. package/templates/supplier-payments-agent/packages/agent-runtime/src/commands/inspect.ts +11 -13
  529. package/templates/supplier-payments-agent/packages/agent-runtime/src/commands/poll-whatsapp.ts +32 -24
  530. package/templates/supplier-payments-agent/packages/agent-runtime/src/commands/poll.ts +12 -5
  531. package/templates/supplier-payments-agent/packages/agent-runtime/src/commands/rerun.ts +83 -10
  532. package/templates/supplier-payments-agent/packages/agent-runtime/src/commands/resume.ts +2 -1
  533. package/templates/supplier-payments-agent/packages/agent-runtime/src/commands/start-whatsapp.ts +10 -5
  534. package/templates/supplier-payments-agent/packages/agent-runtime/src/commands/start.ts +48 -17
  535. package/templates/supplier-payments-agent/packages/agent-runtime/src/commands/verify.ts +37 -12
  536. package/templates/supplier-payments-agent/packages/agent-runtime/src/commands/webhook.ts +11 -3
  537. package/templates/supplier-payments-agent/packages/agent-runtime/src/default-kit.ts +52 -22
  538. package/templates/supplier-payments-agent/packages/agent-runtime/src/env.ts +64 -0
  539. package/templates/supplier-payments-agent/packages/agent-runtime/src/index.ts +2 -0
  540. package/templates/supplier-payments-agent/packages/agent-runtime/src/inspect.ts +81 -10
  541. package/templates/supplier-payments-agent/packages/agent-runtime/src/kit.ts +34 -12
  542. package/templates/supplier-payments-agent/packages/agent-runtime/src/outcome.ts +118 -0
  543. package/templates/supplier-payments-agent/packages/agent-runtime/src/poll.ts +7 -7
  544. package/templates/supplier-payments-agent/packages/agent-runtime/src/runs.ts +51 -0
  545. package/templates/supplier-payments-agent/packages/agent-runtime/src/scenarios.ts +55 -8
  546. package/templates/supplier-payments-agent/packages/agent-runtime/src/setup.ts +75 -5
  547. package/templates/supplier-payments-agent/packages/agent-runtime/src/terminal.ts +71 -33
  548. package/templates/supplier-payments-agent/packages/agent-runtime/test/env-names.test.ts +56 -0
  549. package/templates/supplier-payments-agent/packages/agent-runtime/test/inspect-mandate-status.test.ts +80 -0
  550. package/templates/supplier-payments-agent/packages/agent-runtime/test/inspect.test.ts +63 -2
  551. package/templates/supplier-payments-agent/packages/agent-runtime/test/outcome.test.ts +72 -0
  552. package/templates/supplier-payments-agent/packages/agent-runtime/test/poll-payer.test.ts +64 -0
  553. package/templates/supplier-payments-agent/packages/agent-runtime/test/rerun-not-replayed.test.ts +46 -0
  554. package/templates/supplier-payments-agent/packages/agent-runtime/test/transition-line.test.ts +29 -0
  555. package/templates/supplier-payments-agent/packages/agent-runtime/test/verify-cli.test.ts +99 -6
  556. package/templates/supplier-payments-agent/packages/agent-runtime/test/whatsapp-rules.test.ts +8 -0
  557. package/templates/supplier-payments-agent/packages/agent-runtime/test/whatsapp-session.test.ts +77 -0
  558. package/templates/supplier-payments-agent/packages/agent-runtime/test/whatsapp-status-replies.test.ts +27 -1
@@ -0,0 +1,29 @@
1
+ import { readdirSync, readFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+
4
+ /**
5
+ * Every turn a person types in a recorded scenario or WhatsApp conversation
6
+ * under `root/agents`: all Portuguese. `root` is this repository, with every
7
+ * agent, or a scaffold made by `codespar init --template`, with one.
8
+ */
9
+ export function recordedTurns(root: string): string[] {
10
+ const out: string[] = [];
11
+ for (const agent of readdirSync(join(root, "agents"))) {
12
+ for (const dir of ["scenarios", join("channels", "whatsapp")]) {
13
+ let files: string[] = [];
14
+ try {
15
+ files = readdirSync(join(root, "agents", agent, dir)).filter((f) => f.endsWith(".json") && f !== "templates.json");
16
+ } catch {
17
+ continue;
18
+ }
19
+ for (const f of files) {
20
+ const doc = JSON.parse(readFileSync(join(root, "agents", agent, dir, f), "utf8")) as { turns?: Array<{ input?: string; text?: string }> };
21
+ for (const t of doc.turns ?? []) {
22
+ const text = t.input ?? t.text;
23
+ if (typeof text === "string") out.push(text);
24
+ }
25
+ }
26
+ }
27
+ }
28
+ return out;
29
+ }
@@ -1,6 +1,6 @@
1
1
  import { describe, expect, it } from "vitest";
2
2
  import { createCodeSparClient } from "../src/api/client.js";
3
- import { assertTestKey, isTestKey, NotATestKeyError, redactKey } from "../src/secrets.js";
3
+ import { assertTestKey, CODESPAR_KEY_PLACEHOLDER, isTestKey, NotATestKeyError, redactKey, testKeyMessage, testKeyProblem } from "../src/secrets.js";
4
4
 
5
5
  // Built at runtime so the secret scan (which refuses key-shaped literals) stays honest about this file.
6
6
  const TEST = ["csk", "test", "0123456789abcdef"].join("_");
@@ -21,6 +21,45 @@ describe("sandbox by construction", () => {
21
21
  expect(createCodeSparClient({ apiKey: TEST })).toBeDefined();
22
22
  });
23
23
 
24
+ it("tells the three mistakes apart (#50): no key, the placeholder, a key that is not a test key", () => {
25
+ for (const missing of [undefined, "", " "]) expect(testKeyProblem(missing)).toBe("missing");
26
+ expect(testKeyProblem(CODESPAR_KEY_PLACEHOLDER)).toBe("placeholder");
27
+ expect(testKeyProblem(LIVE)).toBe("not_test");
28
+ expect(testKeyProblem("csk_test_")).toBe("not_test");
29
+ expect(testKeyProblem(TEST)).toBeUndefined();
30
+ expect(isTestKey(CODESPAR_KEY_PLACEHOLDER)).toBe(false);
31
+ for (const [key, problem] of [[undefined, "missing"], [CODESPAR_KEY_PLACEHOLDER, "placeholder"], [LIVE, "not_test"]] as const) {
32
+ try {
33
+ assertTestKey(key);
34
+ throw new Error("accepted");
35
+ } catch (err) {
36
+ expect(err).toBeInstanceOf(NotATestKeyError);
37
+ expect((err as NotATestKeyError).problem).toBe(problem);
38
+ }
39
+ }
40
+ });
41
+
42
+ it("gives each its own remediation, naming the file the agent reads", () => {
43
+ const file = "agents/bills-agent/.env";
44
+ const missing = testKeyMessage("missing", file);
45
+ const placeholder = testKeyMessage("placeholder", file);
46
+ const live = testKeyMessage("not_test", file);
47
+ expect(missing).toContain("CODESPAR_API_KEY is not set");
48
+ expect(missing).toContain(`copy ${file}.example to ${file}`);
49
+ expect(missing).not.toContain("live");
50
+ expect(placeholder).toContain(`still the placeholder from .env.example (${CODESPAR_KEY_PLACEHOLDER})`);
51
+ expect(placeholder).toContain(file);
52
+ expect(placeholder).not.toContain("live");
53
+ expect(live).toContain("a live key is refused");
54
+ expect(new Set([missing, placeholder, live]).size).toBe(3);
55
+ expect(new NotATestKeyError("missing", file).message).toBe(missing);
56
+ });
57
+
58
+ it("refuses to build a client on the placeholder too, before any network", () => {
59
+ expect(() => createCodeSparClient({ apiKey: CODESPAR_KEY_PLACEHOLDER })).toThrow(/placeholder/);
60
+ expect(() => createCodeSparClient({ apiKey: undefined })).toThrow(/is not set/);
61
+ });
62
+
24
63
  it("redacts keys for logs", () => {
25
64
  expect(redactKey(TEST)).toBe("csk_test_…cdef");
26
65
  expect(redactKey(TEST)).not.toContain("0123456789");
@@ -33,11 +33,33 @@ nothing else.
33
33
  `--conversation`, `--scripted`), `consent`, `approve`, `deny`, `resume`,
34
34
  `rerun`, `reconcile`, `inspect` (`--json`, `--html <file>`), `poll`
35
35
  (`--channel`, `--conversation`, `--backend`, `--wait`, `--simulate-payer`,
36
- `--payer`, `--now`, `--json`), `webhook`, `check`, `eval`.
36
+ `--payer`, `--now`, `--json`), `webhook`, `check`, `eval`, `verify`
37
+ (`--from-api`, `--json`, `--keys`/`--url`, `--approval`), which needs no
38
+ agent directory.
39
+ - What a report says about a settlement the API replayed: the terminal line
40
+ "já estava pago", `replayed` on the executions of a paying agent's one-shot
41
+ `--json`, and "replayed, not paid by this run" in `inspect`. The first two
42
+ read agent-core's `isReplayedSettlement`; `inspect` reads the same mark from
43
+ the bundle's rail answers (`docs/OPEN_QUESTIONS.md` §39c).
44
+ - What `verify` prints: the verdict, the chain it recomputed, the approval it
45
+ matched and, off a body that bound, `sandbox` and `money_moved` as the chain
46
+ sealed them. Nothing else of the API's read, which still carries
47
+ `mandate.sig` (§47).
37
48
  - Setup: the manifest, the guardrails, the tools file, the system prompt, the
38
49
  local state, the signer, the proof bundle, the provider (Anthropic with a
39
50
  real key, replay without one), and the pinned clock (`--now`,
40
- `CODESPAR_AGENT_NOW`).
51
+ `CODESPAR_AGENT_NOW`), which also pins the `today` the list tools return.
52
+ - The locale of what the code prints (#64). `setup` resolves it once per run:
53
+ `--locale`, else `locale:` in `agent.yaml`, else `pt-BR`, and records it in
54
+ the bundle's `run.json`. The terminal's own lines come from agent-core's
55
+ `CORE_STRINGS` and the kit's from `kit.strings`, both in that locale; the
56
+ parsers do not change with it (`parseApproval`, `parseBatchGesture` read both
57
+ languages whatever is shown). A command that tells an outcome later (`poll`,
58
+ `webhook`, `approve`) tells the counterparty in the locale of the run that
59
+ proposed it, and `poll --channel whatsapp` sends the template copy in the
60
+ conversation's recorded language and refuses a `--locale` that disagrees.
61
+ The model's reply language is a different thing, read per turn from what
62
+ the person types.
41
63
  - The section 9 adversarial runner and the section 12 scenario runner.
42
64
  - The `csk_test_` guard and the `.env.example` placeholder rule.
43
65
 
@@ -57,11 +79,16 @@ export const agent = defineAgent(import.meta.url, {
57
79
  ```
58
80
 
59
81
  `AgentKit` (in `src/kit.ts`) is the whole seam: the rail adapter
60
- (`buildRail`), the tool handlers, the `policyExtension`, the console labels,
61
- what a one-shot prints as JSON, and — for an agent whose money comes IN — the
82
+ (`buildRail`), the tool handlers, the `policyExtension`, the console words
83
+ (`strings`, one entry per locale, and `labels`, which holds what must not vary
84
+ by locale: who approves and the record kinds), what a one-shot prints as JSON, and — for an agent whose money comes IN — the
62
85
  sandbox payer and the one message per outcome. An agent that declares none of
63
86
  it gets `defaultKit`: the stub rail, the example mandate, no tools.
64
87
 
88
+ `npm run check` fails when a key of `kit.strings` or of `CORE_STRINGS` is
89
+ missing from one locale (`strings_incomplete`), so an English run never prints
90
+ `undefined` where a Portuguese one prints a word.
91
+
65
92
  `defineAgent(import.meta.url, kit)` finds the nearest `agent.yaml` above the
66
93
  module, which is what makes every path (`scenarios/`, `evals/`, `.codespar/`,
67
94
  `runs/`) and every test-only environment variable (`BILLS_STATE_DIR`,
@@ -24,7 +24,7 @@
24
24
  * Every rule can only REFUSE. None of them rewrites a message: a message
25
25
  * that is edited on the way out is not the message the transcript shows.
26
26
  */
27
- import { isOutsideHours, localClock } from "@codespar/agent-core";
27
+ import { CORE_STRINGS, isOutsideHours, localClock, type Locale } from "@codespar/agent-core";
28
28
  import type { Conversation, OutboundBody } from "./types.js";
29
29
 
30
30
  export interface ChannelRefusal {
@@ -44,6 +44,8 @@ export interface RuleContext {
44
44
  now: () => Date;
45
45
  /** Agreement aliases this agent knows, so "names another agreement" is decidable. */
46
46
  knownSubjects?: readonly string[] | undefined;
47
+ /** The language of the refusal details. It never changes what is refused. Default pt-BR. */
48
+ locale?: Locale | undefined;
47
49
  }
48
50
 
49
51
  /** `123.456.789-00`, `12345678900`, `12.345.678/0001-95`, `12345678000195`. */
@@ -90,7 +92,7 @@ export function checkOutbound(to: string, body: OutboundBody, ctx: RuleContext):
90
92
  if (isOutsideHours(`${close}-${open}`, ctx.now(), ctx.hours.timezone)) {
91
93
  return {
92
94
  rule: "collection_hours",
93
- detail: `fora do horario de cobranca (${ctx.hours.window} ${ctx.hours.timezone}); agora sao ${localClock(ctx.now(), ctx.hours.timezone)}`,
95
+ detail: CORE_STRINGS[ctx.locale ?? "pt-BR"].outsideCollectionHours(ctx.hours.window, ctx.hours.timezone, localClock(ctx.now(), ctx.hours.timezone)),
94
96
  };
95
97
  }
96
98
  }
@@ -25,7 +25,7 @@
25
25
  * fetches `@dyvit/whatsapp-simulator-cli` at a pinned version and runs it;
26
26
  * `npm run whatsapp:emulator` is the command.
27
27
  */
28
- import type { ConversationScript } from "@codespar/agent-core";
28
+ import { CORE_STRINGS, type ConversationScript, type Locale } from "@codespar/agent-core";
29
29
  import type { ChannelBackend, InboundMessage, OutboundBody, SentMessage, StatusUpdate } from "../types.js";
30
30
  import { WhatsAppCloudApi, type CloudApiOptions } from "./cloud-api.js";
31
31
 
@@ -129,6 +129,8 @@ export interface EmulatorBackendOptions extends CloudApiOptions {
129
129
  ask?: ((question: string) => Promise<string>) | undefined;
130
130
  /** Where the console draws the conversation as it goes. */
131
131
  render: (line: string) => void;
132
+ /** The language of the console lines above. Default pt-BR. */
133
+ locale?: Locale | undefined;
132
134
  }
133
135
 
134
136
  /**
@@ -147,7 +149,7 @@ export class WhatsAppEmulator implements ChannelBackend {
147
149
  private closed = false;
148
150
 
149
151
  constructor(private readonly options: EmulatorBackendOptions) {
150
- const { driver: _driver, script: _script, pinAt: _pinAt, ask: _ask, render: _render, ...api } = options;
152
+ const { driver: _driver, script: _script, pinAt: _pinAt, ask: _ask, render: _render, locale: _locale, ...api } = options;
151
153
  this.api = new WhatsAppCloudApi(api);
152
154
  }
153
155
 
@@ -156,7 +158,7 @@ export class WhatsAppEmulator implements ChannelBackend {
156
158
  await this.options.driver.health();
157
159
  if (this.options.pinAt) await this.options.driver.pin(this.options.pinAt);
158
160
  this.options.render("");
159
- this.options.render(` ┌─ WhatsApp (dyvit-wa-sim, emulador local da Cloud API — sem rede externa, sem conta Meta)`);
161
+ this.options.render(this.text.waEmulatorOpen);
160
162
  }
161
163
 
162
164
  async next(): Promise<InboundMessage | undefined> {
@@ -193,7 +195,7 @@ export class WhatsAppEmulator implements ChannelBackend {
193
195
  if (!this.options.ask) return undefined;
194
196
  let answer: string;
195
197
  try {
196
- answer = await this.options.ask(" │ voce> ");
198
+ answer = await this.options.ask(this.text.waYou);
197
199
  } catch {
198
200
  return undefined;
199
201
  }
@@ -207,10 +209,14 @@ export class WhatsAppEmulator implements ChannelBackend {
207
209
  return this.api.deliver(to, body);
208
210
  }
209
211
 
212
+ private get text() {
213
+ return CORE_STRINGS[this.options.locale ?? "pt-BR"];
214
+ }
215
+
210
216
  async close(): Promise<void> {
211
217
  if (this.closed) return;
212
218
  this.closed = true;
213
219
  await this.api.close();
214
- this.options.render(" └─ fim da conversa");
220
+ this.options.render(this.text.waEmulatorClosed);
215
221
  }
216
222
  }
@@ -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 latest state the provider reported per message id, this process. */
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
- /** What the agent declared about a template it is about to send. The language is the registry's, never the sender's guess. */
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?.(` [whatsapp] toque ignorado (${refusal.rule}): ${refusal.detail}`);
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.set(status.message_id, status.status);
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 latest status the provider reported for a message this process saw a status for. */
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?.(` [whatsapp] recusado (${refusal.rule}): ${refusal.detail}`);
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?.(` [whatsapp] recusado pelo backend (${sent.refused.rule}): ${sent.refused.detail}`);
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}: [toque: ${line.reply?.title ?? "?"}]${line.refused ? ` (ignorado: ${line.refused.rule})` : ` -> ${line.text ?? ""}`}`;
321
- const who = line.direction === "in" ? `${line.contact}:` : "loja:";
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
- ? `[copia e cola] ${line.text ?? ""}`
346
+ ? `${text.waCopyPaste} ${line.text ?? ""}`
325
347
  : line.kind === "media"
326
- ? "[imagem: QR Pix]"
348
+ ? text.waQrImage
327
349
  : line.kind === "template"
328
350
  ? line.text ?? "[template]"
329
351
  : line.text ?? "";
330
- return line.refused ? `${who} (nao enviada: ${line.refused.rule}) ${what}` : `${who} ${what}`;
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 { ChargeInstrument, Execution } from "@codespar/agent-core";
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 money = new Intl.NumberFormat("pt-BR", { style: "currency", currency });
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 ? `Parcela ${instalment}/${count}: ` : "",
26
+ count > 1 ? text.instalmentOf(instalment, count) : "",
26
27
  item ? money.format(item.amount / 100) : "",
27
- instrument.due_date ? `, vence ${formatDate(instrument.due_date)}` : "",
28
- ` — cobranca ${chargeId}`,
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: "Ou pelo boleto, linha digitavel:" });
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(`${s.manifest.manifest.name} ${s.manifest.manifest.version} — canal: whatsapp (${channel.backend}) — approval: ${s.mode} — trilho: ${s.railKind} — ${s.kit.labels.mandateWord} ${s.mandate.id}`);
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
- private readonly templates: Map<string, WhatsAppTemplate>;
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(templates.map((t) => [t.name, t]));
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 declaration, for a caller that has to build a send: the language is the registry's, never the caller's guess. */
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 declared = this.templates.get(body.template);
84
- if (!declared) {
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
- if (declared.language !== body.language) {
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 ${declared.language}, not ${body.language}; a template approved in one language does not exist in another`,
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 { readDotEnv } from "./setup.js";
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
- readDotEnv(agent.dir);
46
- return run(agent, command, rest);
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
- return agent.kit.consent({ agentDir: agent.dir, argv, say: (l) => void stderr.write(l + "\n") });
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);