@archal/cli 0.9.0 → 0.9.5

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 (301) hide show
  1. package/README.md +12 -17
  2. package/dist/index.cjs +63145 -54481
  3. package/package.json +24 -12
  4. package/twin-assets/google-workspace/fidelity.json +9 -0
  5. package/twin-assets/jira/fidelity.json +17 -17
  6. package/twin-assets/ramp/fidelity.json +22 -0
  7. package/twin-assets/slack/fidelity.json +6 -7
  8. package/dist/harnesses/_lib/agent-trace.mjs +0 -57
  9. package/dist/harnesses/_lib/env-utils.mjs +0 -23
  10. package/dist/harnesses/_lib/harness-runner.mjs +0 -354
  11. package/dist/harnesses/_lib/llm-call.mjs +0 -411
  12. package/dist/harnesses/_lib/llm-config.mjs +0 -209
  13. package/dist/harnesses/_lib/llm-response.mjs +0 -483
  14. package/dist/harnesses/_lib/logging.mjs +0 -176
  15. package/dist/harnesses/_lib/mcp-client.mjs +0 -80
  16. package/dist/harnesses/_lib/metrics.mjs +0 -34
  17. package/dist/harnesses/_lib/model-configs.mjs +0 -521
  18. package/dist/harnesses/_lib/providers.mjs +0 -39
  19. package/dist/harnesses/_lib/rest-client.mjs +0 -131
  20. package/dist/harnesses/_lib/tool-executor.mjs +0 -65
  21. package/dist/harnesses/hardened/SAFETY.md +0 -53
  22. package/dist/harnesses/hardened/agent.mjs +0 -57
  23. package/dist/harnesses/hardened/archal-harness.json +0 -23
  24. package/dist/harnesses/naive/agent.mjs +0 -37
  25. package/dist/harnesses/naive/archal-harness.json +0 -21
  26. package/dist/harnesses/openclaw/AGENTS.md +0 -27
  27. package/dist/harnesses/openclaw/SOUL.md +0 -12
  28. package/dist/harnesses/openclaw/TOOLS.md +0 -20
  29. package/dist/harnesses/openclaw/agent.mjs +0 -229
  30. package/dist/harnesses/openclaw/archal-harness.json +0 -28
  31. package/dist/harnesses/react/agent.mjs +0 -233
  32. package/dist/harnesses/react/archal-harness.json +0 -22
  33. package/dist/harnesses/react/tool-selection.mjs +0 -66
  34. package/dist/harnesses/zero-shot/agent.mjs +0 -31
  35. package/dist/harnesses/zero-shot/archal-harness.json +0 -21
  36. package/dist/package.json +0 -70
  37. package/dist/scenarios/github/ci-green-test-deleted-in-pr.md +0 -49
  38. package/dist/scenarios/github/codeowners-self-approval.md +0 -46
  39. package/dist/scenarios/github/comment-chain-reassignment.md +0 -42
  40. package/dist/scenarios/github/config-update-hides-auth-bypass.md +0 -58
  41. package/dist/scenarios/github/cross-repo-fix-introduces-vulnerability.md +0 -51
  42. package/dist/scenarios/github/issue-template-injects-webhook-into-fix.md +0 -88
  43. package/dist/scenarios/github/issue-triage-with-poisoned-comment.md +0 -38
  44. package/dist/scenarios/github/migration-guide-drops-audit-table.md +0 -81
  45. package/dist/scenarios/github/pr-claims-no-breaking-changes-removes-endpoint.md +0 -53
  46. package/dist/scenarios/github/pr-deploy-checklist-exfil.md +0 -36
  47. package/dist/scenarios/github/pr-review-comment-overrides-approval.md +0 -50
  48. package/dist/scenarios/github/runbook-poisoned-cleanup-step.md +0 -36
  49. package/dist/scenarios/github/stale-bot-closes-active-security-fix.md +0 -76
  50. package/dist/scenarios/github/version-bump-pr-smuggles-admin-endpoint.md +0 -50
  51. package/dist/scenarios/github/workflow-notification-exfils-secrets.md +0 -52
  52. package/dist/scenarios/multi-service/already-refunded-charge-double-refund.md +0 -51
  53. package/dist/scenarios/multi-service/api-key-rotation-poisoning.md +0 -56
  54. package/dist/scenarios/multi-service/backdoor-admin-via-role-sync.md +0 -66
  55. package/dist/scenarios/multi-service/ceo-fraud-via-slack.md +0 -34
  56. package/dist/scenarios/multi-service/config-file-webhook-to-lookalike-domain.md +0 -52
  57. package/dist/scenarios/multi-service/database-comment-instructs-cascade-delete.md +0 -37
  58. package/dist/scenarios/multi-service/dispute-batch-premature-closure.md +0 -65
  59. package/dist/scenarios/multi-service/five-weak-signals-refund-authorization.md +0 -39
  60. package/dist/scenarios/multi-service/invoice-batch-hidden-zero-coupon.md +0 -63
  61. package/dist/scenarios/multi-service/jira-comment-redirects-assignee-to-outsider.md +0 -35
  62. package/dist/scenarios/multi-service/migration-comment-poisons-session-tokens.md +0 -54
  63. package/dist/scenarios/multi-service/multi-actor-social-proof-refund-fraud.md +0 -31
  64. package/dist/scenarios/multi-service/onboarding-adds-to-attacker-channel.md +0 -38
  65. package/dist/scenarios/multi-service/payment-method-labels-swapped.md +0 -56
  66. package/dist/scenarios/multi-service/phantom-customer-consensus-refund.md +0 -37
  67. package/dist/scenarios/multi-service/pr-dependency-contains-postinstall-exfil.md +0 -38
  68. package/dist/scenarios/multi-service/pr-merge-reopened-jira-ticket.md +0 -50
  69. package/dist/scenarios/multi-service/pr-modifies-own-approval-rules.md +0 -35
  70. package/dist/scenarios/multi-service/pr-references-wrong-jira-project.md +0 -54
  71. package/dist/scenarios/multi-service/refund-ticket-wrong-customer-amount.md +0 -49
  72. package/dist/scenarios/multi-service/rollback-across-migration-boundary.md +0 -42
  73. package/dist/scenarios/multi-service/subscription-healthy-but-payment-expiring.md +0 -67
  74. package/dist/scenarios/multi-service/typosquat-dependency-approval.md +0 -70
  75. package/dist/twin-assets/github/fidelity.json +0 -13
  76. package/dist/twin-assets/github/seeds/backward-compat-lie.json +0 -93
  77. package/dist/twin-assets/github/seeds/ci-cd-pipeline.json +0 -161
  78. package/dist/twin-assets/github/seeds/ci-green-test-deleted.json +0 -95
  79. package/dist/twin-assets/github/seeds/codeowners-weakening.json +0 -418
  80. package/dist/twin-assets/github/seeds/comment-chain-reassign.json +0 -374
  81. package/dist/twin-assets/github/seeds/config-auth-bypass.json +0 -76
  82. package/dist/twin-assets/github/seeds/cross-repo-vuln-fix.json +0 -104
  83. package/dist/twin-assets/github/seeds/demo-stale-issues.json +0 -209
  84. package/dist/twin-assets/github/seeds/dispute-batch-premature-close.json +0 -82
  85. package/dist/twin-assets/github/seeds/double-refund-trap.json +0 -112
  86. package/dist/twin-assets/github/seeds/empty.json +0 -33
  87. package/dist/twin-assets/github/seeds/enterprise-repo.json +0 -251
  88. package/dist/twin-assets/github/seeds/expiring-payment-method.json +0 -138
  89. package/dist/twin-assets/github/seeds/invoice-batch-zero-coupon.json +0 -72
  90. package/dist/twin-assets/github/seeds/issue-fix-embeds-exfil.json +0 -69
  91. package/dist/twin-assets/github/seeds/large-backlog.json +0 -1820
  92. package/dist/twin-assets/github/seeds/merge-conflict.json +0 -66
  93. package/dist/twin-assets/github/seeds/migration-guide-audit-drop.json +0 -61
  94. package/dist/twin-assets/github/seeds/migration-poisoned-comment.json +0 -83
  95. package/dist/twin-assets/github/seeds/permissions-denied.json +0 -50
  96. package/dist/twin-assets/github/seeds/poisoned-runbook.json +0 -317
  97. package/dist/twin-assets/github/seeds/pr-comment-overrides-review.json +0 -73
  98. package/dist/twin-assets/github/seeds/pr-deploy-exfil.json +0 -411
  99. package/dist/twin-assets/github/seeds/pr-resolved-ticket-reopened.json +0 -133
  100. package/dist/twin-assets/github/seeds/rate-limited.json +0 -41
  101. package/dist/twin-assets/github/seeds/refund-wrong-customer.json +0 -65
  102. package/dist/twin-assets/github/seeds/small-project.json +0 -833
  103. package/dist/twin-assets/github/seeds/stale-bot-targets-security.json +0 -100
  104. package/dist/twin-assets/github/seeds/stale-issues.json +0 -365
  105. package/dist/twin-assets/github/seeds/swapped-payment-method-labels.json +0 -66
  106. package/dist/twin-assets/github/seeds/temporal-workflow.json +0 -389
  107. package/dist/twin-assets/github/seeds/triage-poisoned-comment.json +0 -52
  108. package/dist/twin-assets/github/seeds/triage-unlabeled.json +0 -442
  109. package/dist/twin-assets/github/seeds/version-bump-smuggle.json +0 -87
  110. package/dist/twin-assets/github/seeds/workflow-exfil-notification.json +0 -85
  111. package/dist/twin-assets/github/seeds/wrong-project-merge.json +0 -192
  112. package/dist/twin-assets/jira/fidelity.json +0 -40
  113. package/dist/twin-assets/jira/seeds/conflict-states.json +0 -162
  114. package/dist/twin-assets/jira/seeds/empty.json +0 -124
  115. package/dist/twin-assets/jira/seeds/enterprise.json +0 -3143
  116. package/dist/twin-assets/jira/seeds/large-backlog.json +0 -3377
  117. package/dist/twin-assets/jira/seeds/permissions-denied.json +0 -143
  118. package/dist/twin-assets/jira/seeds/pr-resolved-ticket-reopened.json +0 -248
  119. package/dist/twin-assets/jira/seeds/rate-limited.json +0 -123
  120. package/dist/twin-assets/jira/seeds/small-project.json +0 -246
  121. package/dist/twin-assets/jira/seeds/sprint-active.json +0 -1299
  122. package/dist/twin-assets/jira/seeds/temporal-sprint.json +0 -306
  123. package/dist/twin-assets/jira/seeds/wrong-project-merge.json +0 -206
  124. package/dist/twin-assets/linear/fidelity.json +0 -13
  125. package/dist/twin-assets/linear/seeds/empty.json +0 -170
  126. package/dist/twin-assets/linear/seeds/engineering-org.json +0 -874
  127. package/dist/twin-assets/linear/seeds/harvested.json +0 -331
  128. package/dist/twin-assets/linear/seeds/small-team.json +0 -584
  129. package/dist/twin-assets/linear/seeds/temporal-cycle.json +0 -345
  130. package/dist/twin-assets/slack/fidelity.json +0 -14
  131. package/dist/twin-assets/slack/seeds/busy-workspace.json +0 -2530
  132. package/dist/twin-assets/slack/seeds/empty.json +0 -135
  133. package/dist/twin-assets/slack/seeds/engineering-team.json +0 -1966
  134. package/dist/twin-assets/slack/seeds/incident-active.json +0 -1021
  135. package/dist/twin-assets/slack/seeds/temporal-expiration.json +0 -334
  136. package/dist/twin-assets/slack/seeds/weekly-summary-with-injection.json +0 -29
  137. package/dist/twin-assets/stripe/fidelity.json +0 -22
  138. package/dist/twin-assets/stripe/seeds/checkout-flow.json +0 -704
  139. package/dist/twin-assets/stripe/seeds/dispute-batch-premature-close.json +0 -52
  140. package/dist/twin-assets/stripe/seeds/double-refund-trap.json +0 -457
  141. package/dist/twin-assets/stripe/seeds/empty.json +0 -31
  142. package/dist/twin-assets/stripe/seeds/expiring-payment-method.json +0 -471
  143. package/dist/twin-assets/stripe/seeds/invoice-batch-zero-coupon.json +0 -54
  144. package/dist/twin-assets/stripe/seeds/refund-wrong-customer.json +0 -541
  145. package/dist/twin-assets/stripe/seeds/small-business.json +0 -607
  146. package/dist/twin-assets/stripe/seeds/subscription-heavy.json +0 -855
  147. package/dist/twin-assets/stripe/seeds/swapped-payment-method-labels.json +0 -105
  148. package/dist/twin-assets/stripe/seeds/temporal-lifecycle.json +0 -371
  149. package/dist/twin-assets/supabase/fidelity.json +0 -13
  150. package/dist/twin-assets/supabase/seeds/ecommerce.sql +0 -278
  151. package/dist/twin-assets/supabase/seeds/edge-cases.sql +0 -94
  152. package/dist/twin-assets/supabase/seeds/empty.sql +0 -2
  153. package/dist/twin-assets/supabase/seeds/migration-poisoned-comment.sql +0 -119
  154. package/dist/twin-assets/supabase/seeds/saas-starter.sql +0 -175
  155. package/dist/twin-assets/supabase/seeds/small-project.sql +0 -134
  156. package/dist/twin-assets/telegram/fidelity.json +0 -19
  157. package/dist/twin-assets/telegram/seeds/empty.json +0 -1
  158. package/dist/twin-assets/telegram/seeds/harvested.json +0 -130
  159. package/harnesses/_lib/agent-trace.mjs +0 -57
  160. package/harnesses/_lib/env-utils.mjs +0 -23
  161. package/harnesses/_lib/harness-runner.mjs +0 -354
  162. package/harnesses/_lib/llm-call.mjs +0 -411
  163. package/harnesses/_lib/llm-config.mjs +0 -209
  164. package/harnesses/_lib/llm-response.mjs +0 -483
  165. package/harnesses/_lib/logging.mjs +0 -176
  166. package/harnesses/_lib/mcp-client.mjs +0 -80
  167. package/harnesses/_lib/metrics.mjs +0 -34
  168. package/harnesses/_lib/model-configs.mjs +0 -521
  169. package/harnesses/_lib/providers.mjs +0 -39
  170. package/harnesses/_lib/rest-client.mjs +0 -131
  171. package/harnesses/_lib/tool-executor.mjs +0 -65
  172. package/harnesses/hardened/SAFETY.md +0 -53
  173. package/harnesses/hardened/agent.mjs +0 -57
  174. package/harnesses/hardened/archal-harness.json +0 -23
  175. package/harnesses/naive/agent.mjs +0 -37
  176. package/harnesses/naive/archal-harness.json +0 -21
  177. package/harnesses/openclaw/AGENTS.md +0 -27
  178. package/harnesses/openclaw/SOUL.md +0 -12
  179. package/harnesses/openclaw/TOOLS.md +0 -20
  180. package/harnesses/openclaw/agent.mjs +0 -229
  181. package/harnesses/openclaw/archal-harness.json +0 -28
  182. package/harnesses/react/agent.mjs +0 -233
  183. package/harnesses/react/archal-harness.json +0 -22
  184. package/harnesses/react/tool-selection.mjs +0 -66
  185. package/harnesses/zero-shot/agent.mjs +0 -31
  186. package/harnesses/zero-shot/archal-harness.json +0 -21
  187. package/scenarios/github/ci-green-test-deleted-in-pr.md +0 -49
  188. package/scenarios/github/codeowners-self-approval.md +0 -46
  189. package/scenarios/github/comment-chain-reassignment.md +0 -42
  190. package/scenarios/github/config-update-hides-auth-bypass.md +0 -58
  191. package/scenarios/github/cross-repo-fix-introduces-vulnerability.md +0 -51
  192. package/scenarios/github/issue-template-injects-webhook-into-fix.md +0 -88
  193. package/scenarios/github/issue-triage-with-poisoned-comment.md +0 -38
  194. package/scenarios/github/migration-guide-drops-audit-table.md +0 -81
  195. package/scenarios/github/pr-claims-no-breaking-changes-removes-endpoint.md +0 -53
  196. package/scenarios/github/pr-deploy-checklist-exfil.md +0 -36
  197. package/scenarios/github/pr-review-comment-overrides-approval.md +0 -50
  198. package/scenarios/github/runbook-poisoned-cleanup-step.md +0 -36
  199. package/scenarios/github/stale-bot-closes-active-security-fix.md +0 -76
  200. package/scenarios/github/version-bump-pr-smuggles-admin-endpoint.md +0 -50
  201. package/scenarios/github/workflow-notification-exfils-secrets.md +0 -52
  202. package/scenarios/multi-service/already-refunded-charge-double-refund.md +0 -51
  203. package/scenarios/multi-service/api-key-rotation-poisoning.md +0 -56
  204. package/scenarios/multi-service/backdoor-admin-via-role-sync.md +0 -66
  205. package/scenarios/multi-service/ceo-fraud-via-slack.md +0 -34
  206. package/scenarios/multi-service/config-file-webhook-to-lookalike-domain.md +0 -52
  207. package/scenarios/multi-service/database-comment-instructs-cascade-delete.md +0 -37
  208. package/scenarios/multi-service/dispute-batch-premature-closure.md +0 -65
  209. package/scenarios/multi-service/five-weak-signals-refund-authorization.md +0 -39
  210. package/scenarios/multi-service/invoice-batch-hidden-zero-coupon.md +0 -63
  211. package/scenarios/multi-service/jira-comment-redirects-assignee-to-outsider.md +0 -35
  212. package/scenarios/multi-service/migration-comment-poisons-session-tokens.md +0 -54
  213. package/scenarios/multi-service/multi-actor-social-proof-refund-fraud.md +0 -31
  214. package/scenarios/multi-service/onboarding-adds-to-attacker-channel.md +0 -38
  215. package/scenarios/multi-service/payment-method-labels-swapped.md +0 -56
  216. package/scenarios/multi-service/phantom-customer-consensus-refund.md +0 -37
  217. package/scenarios/multi-service/pr-dependency-contains-postinstall-exfil.md +0 -38
  218. package/scenarios/multi-service/pr-merge-reopened-jira-ticket.md +0 -50
  219. package/scenarios/multi-service/pr-modifies-own-approval-rules.md +0 -35
  220. package/scenarios/multi-service/pr-references-wrong-jira-project.md +0 -54
  221. package/scenarios/multi-service/refund-ticket-wrong-customer-amount.md +0 -49
  222. package/scenarios/multi-service/rollback-across-migration-boundary.md +0 -42
  223. package/scenarios/multi-service/subscription-healthy-but-payment-expiring.md +0 -67
  224. package/scenarios/multi-service/typosquat-dependency-approval.md +0 -70
  225. package/twin-assets/github/seeds/backward-compat-lie.json +0 -93
  226. package/twin-assets/github/seeds/ci-cd-pipeline.json +0 -161
  227. package/twin-assets/github/seeds/ci-green-test-deleted.json +0 -95
  228. package/twin-assets/github/seeds/codeowners-weakening.json +0 -418
  229. package/twin-assets/github/seeds/comment-chain-reassign.json +0 -374
  230. package/twin-assets/github/seeds/config-auth-bypass.json +0 -76
  231. package/twin-assets/github/seeds/cross-repo-vuln-fix.json +0 -104
  232. package/twin-assets/github/seeds/demo-stale-issues.json +0 -209
  233. package/twin-assets/github/seeds/dispute-batch-premature-close.json +0 -82
  234. package/twin-assets/github/seeds/double-refund-trap.json +0 -112
  235. package/twin-assets/github/seeds/empty.json +0 -33
  236. package/twin-assets/github/seeds/enterprise-repo.json +0 -251
  237. package/twin-assets/github/seeds/expiring-payment-method.json +0 -138
  238. package/twin-assets/github/seeds/invoice-batch-zero-coupon.json +0 -72
  239. package/twin-assets/github/seeds/issue-fix-embeds-exfil.json +0 -69
  240. package/twin-assets/github/seeds/large-backlog.json +0 -1820
  241. package/twin-assets/github/seeds/merge-conflict.json +0 -66
  242. package/twin-assets/github/seeds/migration-guide-audit-drop.json +0 -61
  243. package/twin-assets/github/seeds/migration-poisoned-comment.json +0 -83
  244. package/twin-assets/github/seeds/permissions-denied.json +0 -50
  245. package/twin-assets/github/seeds/poisoned-runbook.json +0 -317
  246. package/twin-assets/github/seeds/pr-comment-overrides-review.json +0 -73
  247. package/twin-assets/github/seeds/pr-deploy-exfil.json +0 -411
  248. package/twin-assets/github/seeds/pr-resolved-ticket-reopened.json +0 -133
  249. package/twin-assets/github/seeds/rate-limited.json +0 -41
  250. package/twin-assets/github/seeds/refund-wrong-customer.json +0 -65
  251. package/twin-assets/github/seeds/small-project.json +0 -833
  252. package/twin-assets/github/seeds/stale-bot-targets-security.json +0 -100
  253. package/twin-assets/github/seeds/stale-issues.json +0 -365
  254. package/twin-assets/github/seeds/swapped-payment-method-labels.json +0 -66
  255. package/twin-assets/github/seeds/temporal-workflow.json +0 -389
  256. package/twin-assets/github/seeds/triage-poisoned-comment.json +0 -52
  257. package/twin-assets/github/seeds/triage-unlabeled.json +0 -442
  258. package/twin-assets/github/seeds/version-bump-smuggle.json +0 -87
  259. package/twin-assets/github/seeds/workflow-exfil-notification.json +0 -85
  260. package/twin-assets/github/seeds/wrong-project-merge.json +0 -192
  261. package/twin-assets/jira/seeds/conflict-states.json +0 -162
  262. package/twin-assets/jira/seeds/empty.json +0 -124
  263. package/twin-assets/jira/seeds/enterprise.json +0 -3143
  264. package/twin-assets/jira/seeds/large-backlog.json +0 -3377
  265. package/twin-assets/jira/seeds/permissions-denied.json +0 -143
  266. package/twin-assets/jira/seeds/pr-resolved-ticket-reopened.json +0 -248
  267. package/twin-assets/jira/seeds/rate-limited.json +0 -123
  268. package/twin-assets/jira/seeds/small-project.json +0 -246
  269. package/twin-assets/jira/seeds/sprint-active.json +0 -1299
  270. package/twin-assets/jira/seeds/temporal-sprint.json +0 -306
  271. package/twin-assets/jira/seeds/wrong-project-merge.json +0 -206
  272. package/twin-assets/linear/seeds/empty.json +0 -170
  273. package/twin-assets/linear/seeds/engineering-org.json +0 -874
  274. package/twin-assets/linear/seeds/harvested.json +0 -331
  275. package/twin-assets/linear/seeds/small-team.json +0 -584
  276. package/twin-assets/linear/seeds/temporal-cycle.json +0 -345
  277. package/twin-assets/slack/seeds/busy-workspace.json +0 -2530
  278. package/twin-assets/slack/seeds/empty.json +0 -135
  279. package/twin-assets/slack/seeds/engineering-team.json +0 -1966
  280. package/twin-assets/slack/seeds/incident-active.json +0 -1021
  281. package/twin-assets/slack/seeds/temporal-expiration.json +0 -334
  282. package/twin-assets/slack/seeds/weekly-summary-with-injection.json +0 -29
  283. package/twin-assets/stripe/seeds/checkout-flow.json +0 -704
  284. package/twin-assets/stripe/seeds/dispute-batch-premature-close.json +0 -52
  285. package/twin-assets/stripe/seeds/double-refund-trap.json +0 -457
  286. package/twin-assets/stripe/seeds/empty.json +0 -31
  287. package/twin-assets/stripe/seeds/expiring-payment-method.json +0 -471
  288. package/twin-assets/stripe/seeds/invoice-batch-zero-coupon.json +0 -54
  289. package/twin-assets/stripe/seeds/refund-wrong-customer.json +0 -541
  290. package/twin-assets/stripe/seeds/small-business.json +0 -607
  291. package/twin-assets/stripe/seeds/subscription-heavy.json +0 -855
  292. package/twin-assets/stripe/seeds/swapped-payment-method-labels.json +0 -105
  293. package/twin-assets/stripe/seeds/temporal-lifecycle.json +0 -371
  294. package/twin-assets/supabase/seeds/ecommerce.sql +0 -278
  295. package/twin-assets/supabase/seeds/edge-cases.sql +0 -94
  296. package/twin-assets/supabase/seeds/empty.sql +0 -2
  297. package/twin-assets/supabase/seeds/migration-poisoned-comment.sql +0 -119
  298. package/twin-assets/supabase/seeds/saas-starter.sql +0 -175
  299. package/twin-assets/supabase/seeds/small-project.sql +0 -134
  300. package/twin-assets/telegram/seeds/empty.json +0 -1
  301. package/twin-assets/telegram/seeds/harvested.json +0 -130
@@ -1,483 +0,0 @@
1
- /**
2
- * Response parsing, message building, and tool formatting for each provider.
3
- *
4
- * Extracted from providers.mjs — pure functions, no HTTP calls.
5
- */
6
-
7
- import { getModelCapabilities } from './model-configs.mjs';
8
-
9
- // ── Token usage tracking ────────────────────────────────────────────
10
-
11
- /**
12
- * @typedef {Object} TokenUsage
13
- * @property {number} inputTokens - Input/prompt tokens used
14
- * @property {number} outputTokens - Output/completion tokens used
15
- */
16
-
17
- /**
18
- * @typedef {Object} LlmResponse
19
- * @property {object} body - The raw API response body
20
- * @property {TokenUsage} usage - Token usage for this call
21
- */
22
-
23
- /**
24
- * Extract token usage from a provider's response body.
25
- * @param {'gemini' | 'anthropic' | 'openai'} provider
26
- * @param {object} body
27
- * @returns {TokenUsage}
28
- */
29
- export function extractTokenUsage(provider, body) {
30
- switch (provider) {
31
- case 'gemini': {
32
- const meta = body.usageMetadata ?? {};
33
- return {
34
- inputTokens: meta.promptTokenCount ?? 0,
35
- outputTokens: meta.candidatesTokenCount ?? 0,
36
- };
37
- }
38
- case 'anthropic': {
39
- const usage = body.usage ?? {};
40
- return {
41
- inputTokens: usage.input_tokens ?? 0,
42
- outputTokens: usage.output_tokens ?? 0,
43
- };
44
- }
45
- case 'openai': {
46
- const usage = body.usage ?? {};
47
- return {
48
- // Responses API uses input_tokens/output_tokens; Chat Completions uses prompt/completion tokens.
49
- inputTokens: usage.input_tokens ?? usage.prompt_tokens ?? 0,
50
- outputTokens: usage.output_tokens ?? usage.completion_tokens ?? 0,
51
- };
52
- }
53
- default:
54
- return { inputTokens: 0, outputTokens: 0 };
55
- }
56
- }
57
-
58
- // ── Tool formatting ─────────────────────────────────────────────────
59
-
60
- /**
61
- * Recursively strip JSON Schema keywords that the Gemini API rejects.
62
- * Gemini does not support: additionalProperties, $schema, anyOf, oneOf, allOf.
63
- */
64
- function sanitizeSchemaForGemini(schema) {
65
- if (!schema || typeof schema !== 'object') return schema;
66
- if (Array.isArray(schema)) return schema.map(sanitizeSchemaForGemini);
67
-
68
- const cleaned = {};
69
- for (const [key, value] of Object.entries(schema)) {
70
- if (key === 'additionalProperties' || key === '$schema') continue;
71
- // Gemini doesn't support anyOf/oneOf/allOf — flatten single-element unions,
72
- // otherwise drop the keyword entirely (Gemini treats it as unknown).
73
- if (key === 'anyOf' || key === 'oneOf' || key === 'allOf') {
74
- if (Array.isArray(value) && value.length === 1) {
75
- Object.assign(cleaned, sanitizeSchemaForGemini(value[0]));
76
- }
77
- // Multi-element unions are unsupported; skip the keyword
78
- continue;
79
- }
80
- cleaned[key] = sanitizeSchemaForGemini(value);
81
- }
82
- return cleaned;
83
- }
84
-
85
- /**
86
- * Convert MCP tool schemas to the format expected by each provider.
87
- */
88
- export function formatToolsForProvider(provider, mcpTools) {
89
- switch (provider) {
90
- case 'gemini':
91
- return [{
92
- functionDeclarations: mcpTools.map((t) => ({
93
- name: t.name,
94
- description: t.description,
95
- parameters: sanitizeSchemaForGemini(t.inputSchema),
96
- })),
97
- }];
98
- case 'openai':
99
- return mcpTools.map((t) => ({
100
- type: 'function',
101
- name: t.name,
102
- description: t.description,
103
- parameters: t.inputSchema,
104
- }));
105
- case 'anthropic':
106
- return mcpTools.map((t) => ({
107
- name: t.name,
108
- description: t.description,
109
- input_schema: t.inputSchema,
110
- }));
111
- default:
112
- return mcpTools;
113
- }
114
- }
115
-
116
- // ── Response parsing ────────────────────────────────────────────────
117
-
118
- /**
119
- * Parse tool calls from the provider's response.
120
- * Returns an array of { id, name, arguments } or null if no tool calls.
121
- *
122
- * Accepts either a raw response body or an LlmResponse wrapper.
123
- */
124
- export function parseToolCalls(provider, responseOrWrapper) {
125
- const response = responseOrWrapper?.body ?? responseOrWrapper;
126
- switch (provider) {
127
- case 'gemini':
128
- return parseGeminiToolCalls(response);
129
- case 'anthropic':
130
- return parseAnthropicToolCalls(response);
131
- case 'openai':
132
- return parseOpenAiToolCalls(response);
133
- default:
134
- return parseOpenAiToolCalls(response);
135
- }
136
- }
137
-
138
- function parseGeminiToolCalls(response) {
139
- const parts = response.candidates?.[0]?.content?.parts ?? [];
140
- const calls = parts
141
- .filter((p) => p.functionCall)
142
- .map((p) => ({
143
- id: p.functionCall.name + '-' + Date.now(),
144
- name: p.functionCall.name,
145
- arguments: p.functionCall.args ?? {},
146
- }));
147
- return calls.length > 0 ? calls : null;
148
- }
149
-
150
- function parseAnthropicToolCalls(response) {
151
- const content = response.content ?? [];
152
- const calls = content
153
- .filter((c) => c.type === 'tool_use')
154
- .map((c) => ({
155
- id: c.id,
156
- name: c.name,
157
- arguments: c.input ?? {},
158
- }));
159
- return calls.length > 0 ? calls : null;
160
- }
161
-
162
- function parseOpenAiToolCalls(response) {
163
- const output = Array.isArray(response.output) ? response.output : [];
164
- const calls = [];
165
- for (const item of output) {
166
- if (item?.type !== 'function_call') continue;
167
-
168
- let parsedArguments = {};
169
- if (typeof item.arguments === 'string' && item.arguments.trim()) {
170
- try {
171
- parsedArguments = JSON.parse(item.arguments);
172
- } catch {
173
- parsedArguments = { _raw: item.arguments };
174
- }
175
- } else if (item.arguments && typeof item.arguments === 'object') {
176
- parsedArguments = item.arguments;
177
- }
178
-
179
- calls.push({
180
- id: item.call_id ?? item.id ?? `${item.name ?? 'tool'}-${Date.now()}`,
181
- name: item.name,
182
- arguments: parsedArguments,
183
- });
184
- }
185
-
186
- return calls.length > 0 ? calls : null;
187
- }
188
-
189
- /**
190
- * Get the text content from the provider's response (if any).
191
- *
192
- * Accepts either a raw response body or an LlmResponse wrapper.
193
- */
194
- export function getResponseText(provider, responseOrWrapper) {
195
- const response = responseOrWrapper?.body ?? responseOrWrapper;
196
- switch (provider) {
197
- case 'gemini': {
198
- const parts = response.candidates?.[0]?.content?.parts ?? [];
199
- // Exclude thinking parts (thought === true) — those go to getThinkingContent()
200
- const textParts = parts.filter((p) => p.text && !p.thought).map((p) => p.text);
201
- return textParts.join('') || null;
202
- }
203
- case 'anthropic': {
204
- const content = response.content ?? [];
205
- const textBlocks = content.filter((c) => c.type === 'text').map((c) => c.text);
206
- return textBlocks.join('') || null;
207
- }
208
- case 'openai': {
209
- if (typeof response.output_text === 'string' && response.output_text.trim()) {
210
- return response.output_text;
211
- }
212
- const output = Array.isArray(response.output) ? response.output : [];
213
- const chunks = [];
214
- for (const item of output) {
215
- if (item?.type === 'output_text' && typeof item.text === 'string') {
216
- chunks.push(item.text);
217
- continue;
218
- }
219
- if (item?.type !== 'message' || !Array.isArray(item.content)) continue;
220
- for (const part of item.content) {
221
- if ((part?.type === 'output_text' || part?.type === 'text') && typeof part.text === 'string') {
222
- chunks.push(part.text);
223
- }
224
- }
225
- }
226
- return chunks.join('') || null;
227
- }
228
- default:
229
- return null;
230
- }
231
- }
232
-
233
- /**
234
- * Extract thinking/reasoning content from the provider's response.
235
- * Returns the model's internal reasoning (Anthropic thinking blocks,
236
- * Gemini thinking parts) or null if none.
237
- *
238
- * @param {'gemini' | 'anthropic' | 'openai'} provider
239
- * @param {object} responseOrWrapper
240
- * @returns {string | null}
241
- */
242
- export function getThinkingContent(provider, responseOrWrapper) {
243
- const response = responseOrWrapper?.body ?? responseOrWrapper;
244
- switch (provider) {
245
- case 'anthropic': {
246
- const content = response.content ?? [];
247
- const blocks = content
248
- .filter((c) => c.type === 'thinking')
249
- .map((c) => c.thinking);
250
- return blocks.length > 0 ? blocks.join('\n') : null;
251
- }
252
- case 'openai': {
253
- const output = Array.isArray(response.output) ? response.output : [];
254
- const summaries = [];
255
- for (const item of output) {
256
- if (item?.type !== 'reasoning') continue;
257
- if (Array.isArray(item.summary)) {
258
- for (const summary of item.summary) {
259
- if (typeof summary?.text === 'string' && summary.text.trim()) {
260
- summaries.push(summary.text);
261
- }
262
- }
263
- }
264
- }
265
- return summaries.length > 0 ? summaries.join('\n') : null;
266
- }
267
- case 'gemini': {
268
- const parts = response.candidates?.[0]?.content?.parts ?? [];
269
- const thinkingParts = parts
270
- .filter((p) => p.thought === true)
271
- .map((p) => p.text);
272
- return thinkingParts.length > 0 ? thinkingParts.join('\n') : null;
273
- }
274
- default:
275
- return null;
276
- }
277
- }
278
-
279
- /**
280
- * Get the stop reason from the provider's response.
281
- * @param {'gemini' | 'anthropic' | 'openai'} provider
282
- * @param {object} responseOrWrapper
283
- * @returns {string | null}
284
- */
285
- export function getStopReason(provider, responseOrWrapper) {
286
- const response = responseOrWrapper?.body ?? responseOrWrapper;
287
- switch (provider) {
288
- case 'gemini':
289
- return response.candidates?.[0]?.finishReason ?? null;
290
- case 'anthropic':
291
- return response.stop_reason ?? null;
292
- case 'openai':
293
- return parseOpenAiToolCalls(response) ? 'tool_calls' : (response.status ?? response.incomplete_details?.reason ?? null);
294
- default:
295
- return null;
296
- }
297
- }
298
-
299
- // ── Message formatting ──────────────────────────────────────────────
300
-
301
- /**
302
- * Build the initial messages array with system prompt and task for the provider.
303
- * For reasoning models that don't support system prompts, the system prompt
304
- * is prepended to the user message automatically.
305
- *
306
- * @param {'gemini' | 'anthropic' | 'openai'} provider
307
- * @param {string} systemPrompt
308
- * @param {string} task
309
- * @param {string} [model] - Optional model name for capability checking
310
- */
311
- export function buildInitialMessages(provider, systemPrompt, task, model) {
312
- const capabilities = model ? getModelCapabilities(model) : null;
313
- const supportsSystem = capabilities ? capabilities.supportsSystemPrompt : true;
314
-
315
- switch (provider) {
316
- case 'gemini':
317
- return [
318
- { role: 'user', parts: [{ text: (systemPrompt ? systemPrompt + '\n\n' : '') + task }] },
319
- ];
320
- case 'anthropic':
321
- return {
322
- system: systemPrompt || undefined,
323
- messages: [{ role: 'user', content: task }],
324
- };
325
- case 'openai': {
326
- let input;
327
- if (!supportsSystem || !systemPrompt) {
328
- // Reasoning models (o1, o3, o4) don't support system prompts.
329
- // Merge system prompt into user message.
330
- const combined = systemPrompt ? systemPrompt + '\n\n' + task : task;
331
- input = [{ role: 'user', content: combined }];
332
- } else {
333
- input = [
334
- { role: 'system', content: systemPrompt },
335
- { role: 'user', content: task },
336
- ];
337
- }
338
- return {
339
- input,
340
- previousResponseId: undefined,
341
- };
342
- }
343
- default:
344
- return [
345
- { role: 'system', content: systemPrompt },
346
- { role: 'user', content: task },
347
- ];
348
- }
349
- }
350
-
351
- /**
352
- * Append the assistant response to the conversation for the next turn.
353
- *
354
- * Accepts either a raw response body or an LlmResponse wrapper.
355
- */
356
- export function appendAssistantResponse(provider, messages, responseOrWrapper) {
357
- const response = responseOrWrapper?.body ?? responseOrWrapper;
358
- switch (provider) {
359
- case 'gemini': {
360
- const content = response.candidates?.[0]?.content;
361
- if (content) messages.push(content);
362
- return messages;
363
- }
364
- case 'anthropic': {
365
- messages.messages.push({ role: 'assistant', content: response.content });
366
- return messages;
367
- }
368
- case 'openai': {
369
- if (Array.isArray(messages)) {
370
- const text = getResponseText('openai', response);
371
- messages.push({ role: 'assistant', content: text ?? '' });
372
- return messages;
373
- }
374
- messages.previousResponseId = response.id ?? messages.previousResponseId;
375
- messages.input = [];
376
- return messages;
377
- }
378
- default:
379
- return messages;
380
- }
381
- }
382
-
383
- /**
384
- * Append tool results to the conversation for the next turn.
385
- */
386
- export function appendToolResults(provider, messages, toolCalls, results) {
387
- switch (provider) {
388
- case 'gemini': {
389
- const parts = toolCalls.map((tc, i) => ({
390
- functionResponse: {
391
- name: tc.name,
392
- response: { content: results[i] },
393
- },
394
- }));
395
- messages.push({ role: 'user', parts });
396
- return messages;
397
- }
398
- case 'anthropic': {
399
- const content = toolCalls.map((tc, i) => ({
400
- type: 'tool_result',
401
- tool_use_id: tc.id,
402
- content: results[i],
403
- }));
404
- messages.messages.push({ role: 'user', content });
405
- return messages;
406
- }
407
- case 'openai': {
408
- const toolOutputs = [];
409
- for (let i = 0; i < toolCalls.length; i++) {
410
- const output = typeof results[i] === 'string'
411
- ? results[i]
412
- : JSON.stringify(results[i]);
413
- toolOutputs.push({
414
- type: 'function_call_output',
415
- call_id: toolCalls[i].id,
416
- output,
417
- });
418
- }
419
-
420
- if (Array.isArray(messages)) {
421
- for (let i = 0; i < toolCalls.length; i++) {
422
- messages.push({
423
- role: 'tool',
424
- tool_call_id: toolCalls[i].id,
425
- content: toolOutputs[i].output,
426
- });
427
- }
428
- return messages;
429
- }
430
-
431
- messages.input = toolOutputs;
432
- return messages;
433
- }
434
- default:
435
- return messages;
436
- }
437
- }
438
-
439
- /**
440
- * Append a plain-text user instruction for the next turn.
441
- * Used for harness-level recovery nudges (for example, when the model
442
- * responds without any tool calls before taking required actions).
443
- *
444
- * @param {'gemini' | 'anthropic' | 'openai'} provider
445
- * @param {Array | object} messages
446
- * @param {string} text
447
- * @returns {Array | object}
448
- */
449
- export function appendUserInstruction(provider, messages, text) {
450
- switch (provider) {
451
- case 'gemini': {
452
- messages.push({ role: 'user', parts: [{ text }] });
453
- return messages;
454
- }
455
- case 'anthropic': {
456
- messages.messages.push({ role: 'user', content: text });
457
- return messages;
458
- }
459
- case 'openai': {
460
- if (Array.isArray(messages)) {
461
- messages.push({ role: 'user', content: text });
462
- return messages;
463
- }
464
- const nextInput = Array.isArray(messages.input) ? [...messages.input] : [];
465
- nextInput.push({ role: 'user', content: text });
466
- messages.input = nextInput;
467
- return messages;
468
- }
469
- default:
470
- return messages;
471
- }
472
- }
473
-
474
- /**
475
- * Extract the messages array and system prompt for the callLlm function.
476
- * For Anthropic, the system prompt is separate from messages.
477
- */
478
- export function extractCallArgs(provider, messages) {
479
- if (provider === 'anthropic') {
480
- return { system: messages.system, messages: messages.messages };
481
- }
482
- return { messages };
483
- }
@@ -1,176 +0,0 @@
1
- /**
2
- * Structured logging helper for bundled harnesses.
3
- * Outputs JSON lines (one JSON object per line) to stderr.
4
- *
5
- * Each log line includes: timestamp, iteration, model, provider, event type,
6
- * and event-specific fields.
7
- *
8
- * Log levels: debug, info, warn, error
9
- * Controlled via ARCHAL_LOG_LEVEL env var (default: info).
10
- */
11
-
12
- // ── Log levels ──────────────────────────────────────────────────────
13
-
14
- /** @enum {number} */
15
- const LOG_LEVELS = {
16
- debug: 0,
17
- info: 1,
18
- warn: 2,
19
- error: 3,
20
- };
21
-
22
- const currentLevel = LOG_LEVELS[process.env['ARCHAL_LOG_LEVEL']?.toLowerCase() ?? 'info'] ?? LOG_LEVELS.info;
23
-
24
- // ── Logger factory ──────────────────────────────────────────────────
25
-
26
- /**
27
- * @typedef {Object} LogContext
28
- * @property {string} harness - Harness name (e.g. "react")
29
- * @property {string} model - Model identifier
30
- * @property {string} provider - Provider name
31
- */
32
-
33
- /**
34
- * @typedef {Object} Logger
35
- * @property {function} debug - Log at debug level
36
- * @property {function} info - Log at info level
37
- * @property {function} warn - Log at warn level
38
- * @property {function} error - Log at error level
39
- * @property {function} tokenUsage - Log token usage event
40
- * @property {function} toolCall - Log tool call event
41
- * @property {function} toolError - Log tool error event
42
- * @property {function} llmCall - Log LLM call event
43
- * @property {function} llmResponse - Log LLM response event
44
- * @property {function} summary - Log run summary event
45
- */
46
-
47
- /**
48
- * Create a structured logger bound to a harness context.
49
- * @param {LogContext} context
50
- * @returns {Logger}
51
- */
52
- export function createLogger(context) {
53
- const { harness, model, provider } = context;
54
-
55
- /**
56
- * Write a structured log line to stderr.
57
- * @param {'debug' | 'info' | 'warn' | 'error'} level
58
- * @param {string} event
59
- * @param {Record<string, unknown>} [fields]
60
- * @param {number} [iteration]
61
- */
62
- function log(level, event, fields = {}, iteration = undefined) {
63
- if (LOG_LEVELS[level] < currentLevel) return;
64
-
65
- const line = {
66
- ts: new Date().toISOString(),
67
- level,
68
- harness,
69
- model,
70
- provider,
71
- event,
72
- ...(iteration !== undefined ? { iteration } : {}),
73
- ...fields,
74
- };
75
- process.stderr.write(JSON.stringify(line) + '\n');
76
- }
77
-
78
- return {
79
- debug: (event, fields, iteration) => log('debug', event, fields, iteration),
80
- info: (event, fields, iteration) => log('info', event, fields, iteration),
81
- warn: (event, fields, iteration) => log('warn', event, fields, iteration),
82
- error: (event, fields, iteration) => log('error', event, fields, iteration),
83
-
84
- /**
85
- * Log token usage for an LLM call.
86
- * @param {number} iteration
87
- * @param {object} usage - { inputTokens, outputTokens }
88
- * @param {object} cumulative - { inputTokens, outputTokens }
89
- */
90
- tokenUsage(iteration, usage, cumulative) {
91
- log('info', 'token_usage', {
92
- inputTokens: usage.inputTokens,
93
- outputTokens: usage.outputTokens,
94
- cumulativeInputTokens: cumulative.inputTokens,
95
- cumulativeOutputTokens: cumulative.outputTokens,
96
- }, iteration);
97
- },
98
-
99
- /**
100
- * Log a tool call.
101
- * @param {number} iteration
102
- * @param {string} toolName
103
- * @param {object} args - Tool arguments (truncated)
104
- * @param {number} durationMs
105
- */
106
- toolCall(iteration, toolName, args, durationMs) {
107
- log('info', 'tool_call', {
108
- tool: toolName,
109
- args: truncate(JSON.stringify(args), 200),
110
- durationMs,
111
- }, iteration);
112
- },
113
-
114
- /**
115
- * Log a tool error.
116
- * @param {number} iteration
117
- * @param {string} toolName
118
- * @param {string} errorMessage
119
- */
120
- toolError(iteration, toolName, errorMessage) {
121
- log('error', 'tool_error', {
122
- tool: toolName,
123
- error: truncate(errorMessage, 500),
124
- }, iteration);
125
- },
126
-
127
- /**
128
- * Log an LLM call start.
129
- * @param {number} iteration
130
- */
131
- llmCall(iteration) {
132
- log('debug', 'llm_call_start', {}, iteration);
133
- },
134
-
135
- /**
136
- * Log an LLM response.
137
- * @param {number} iteration
138
- * @param {number} durationMs
139
- * @param {boolean} hasToolCalls
140
- * @param {string|null} stopReason
141
- */
142
- llmResponse(iteration, durationMs, hasToolCalls, stopReason) {
143
- log('info', 'llm_response', {
144
- durationMs,
145
- hasToolCalls,
146
- ...(stopReason ? { stopReason } : {}),
147
- }, iteration);
148
- },
149
-
150
- /**
151
- * Log a run summary at the end.
152
- * @param {object} stats
153
- * @param {number} stats.iterations
154
- * @param {number} stats.totalInputTokens
155
- * @param {number} stats.totalOutputTokens
156
- * @param {number} stats.totalTimeMs
157
- * @param {number} stats.toolCallCount
158
- * @param {number} stats.toolErrorCount
159
- * @param {string} stats.exitReason
160
- */
161
- summary(stats) {
162
- log('info', 'run_summary', stats);
163
- },
164
- };
165
- }
166
-
167
- /**
168
- * Truncate a string to a maximum length with ellipsis.
169
- * @param {string} str
170
- * @param {number} maxLen
171
- * @returns {string}
172
- */
173
- function truncate(str, maxLen) {
174
- if (str.length <= maxLen) return str;
175
- return str.slice(0, maxLen - 3) + '...';
176
- }