@desplega.ai/agent-swarm 1.161.0 → 1.162.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 (224) hide show
  1. package/README.md +3 -2
  2. package/dist/{acp-adapter-xx489vvb.js → acp-adapter-74m73ae9.js} +1 -1
  3. package/dist/{actions-ykjkn0m9.js → actions-4sr14gnt.js} +34 -31
  4. package/dist/{anthropic-messages-5qx80j9k.js → anthropic-messages-8xxrzky9.js} +22 -26
  5. package/dist/{app-0hdqa4k1.js → app-pt68fbwp.js} +13 -11
  6. package/dist/{artifact-3v5t9jtg.js → artifact-fey7dvj9.js} +3 -2
  7. package/dist/{assistant-am2g5g8a.js → assistant-cv3jytks.js} +37 -34
  8. package/dist/{azure-openai-responses-fszbkp0e.js → azure-openai-responses-f5cqsyj8.js} +15 -10
  9. package/dist/{boot-reembed-xy9t7avg.js → boot-reembed-4ht4gqth.js} +13 -11
  10. package/dist/{boot-reembed-gt5gjkt4.js → boot-reembed-nxpcvpj9.js} +12 -10
  11. package/dist/{boot-scrub-logs-9x0985y5.js → boot-scrub-logs-k93kyw8k.js} +9 -7
  12. package/dist/{boot-seeds-trv0d4vg.js → boot-seeds-1skcrs0e.js} +13 -10
  13. package/dist/{claude-adapter-jb6e1e54.js → claude-adapter-r5g0tzge.js} +23 -20
  14. package/dist/{claude-managed-setup-d1q9hv2b.js → claude-managed-setup-pkyrgshb.js} +3 -2
  15. package/dist/{claude-sdk-session-zga700s2.js → claude-sdk-session-jxyxnrwd.js} +5565 -5512
  16. package/dist/{cli-we0q7t0e.js → cli-2zy95vhm.js} +137 -64
  17. package/dist/{cli-35pj2yva.js → cli-4cwxn7gp.js} +38 -11
  18. package/dist/{cli-ad4qxm6j.js → cli-4dcpaefp.js} +2 -2
  19. package/dist/{cli-82c1pacn.js → cli-4x0csdjq.js} +71 -37
  20. package/dist/{cli-sqm3r5ps.js → cli-5bcd7sfy.js} +14 -18
  21. package/dist/{cli-d56tgd45.js → cli-5k6k8ta3.js} +2 -2
  22. package/dist/{cli-1er0rhz8.js → cli-5xhpb3kv.js} +15 -15
  23. package/dist/{cli-yrg7c73k.js → cli-7af8yhav.js} +10 -183
  24. package/dist/{cli-r6fsxc76.js → cli-7tre70zp.js} +513 -961
  25. package/dist/{cli-bh7jed3k.js → cli-8ev9xqnx.js} +34 -18
  26. package/dist/cli-bsky8g7w.js +449 -0
  27. package/dist/{cli-hn04t9db.js → cli-cebmgwsc.js} +14 -10
  28. package/dist/{cli-cfkrztza.js → cli-cvatsam7.js} +2 -2
  29. package/dist/{cli-2658f6at.js → cli-cvk6yzw5.js} +6 -8
  30. package/dist/{cli-ptr8h7kp.js → cli-eg0b3p0k.js} +5 -218
  31. package/dist/{cli-zb6xbk61.js → cli-g739zqzt.js} +4 -4
  32. package/dist/{cli-dv6cdjs2.js → cli-gd4favx9.js} +28 -7
  33. package/dist/{cli-5p3x4zna.js → cli-gpqpmns7.js} +2 -2
  34. package/dist/{cli-5nbmpy8w.js → cli-hb5c2x5y.js} +1 -1
  35. package/dist/{cli-jpf7e1zq.js → cli-hmsw1gpy.js} +3 -3
  36. package/dist/{cli-1cz0c18q.js → cli-jf7wmv1r.js} +2521 -733
  37. package/dist/{cli-qwsnmjdd.js → cli-jxs2ygaw.js} +168 -61
  38. package/dist/cli-kdkwd3yr.js +615 -0
  39. package/dist/{cli-hgmnf38m.js → cli-kh04eqwe.js} +1 -1
  40. package/dist/{cli-0383bp7f.js → cli-kp42yek0.js} +425 -90
  41. package/dist/{cli-ybgv4kw2.js → cli-mbssg1xv.js} +9 -2
  42. package/dist/{cli-jsp14b6c.js → cli-mzfth0bp.js} +38 -1
  43. package/dist/{cli-8g6mc14k.js → cli-nq7yqw7b.js} +16 -5
  44. package/dist/{cli-ee8bc46j.js → cli-nt8hecg9.js} +33 -32
  45. package/dist/{cli-9s68w752.js → cli-p0r8sxj5.js} +1 -1
  46. package/dist/{cli-58e8yr0d.js → cli-pkd6s2wy.js} +4 -2
  47. package/dist/{cli-17xpf7cm.js → cli-q24re23n.js} +6 -4
  48. package/dist/cli-qjjvzwzd.js +222 -0
  49. package/dist/cli-qrgt5bqf.js +189 -0
  50. package/dist/{cli-et8m9xsv.js → cli-rfjw9jw2.js} +22 -10
  51. package/dist/{cli-798vkbks.js → cli-rj0gqwwp.js} +2 -2
  52. package/dist/{cli-121ph74b.js → cli-rnyzn44p.js} +1 -1
  53. package/dist/{cli-vnnz5ncg.js → cli-s3hwpt9v.js} +95 -16
  54. package/dist/{cli-7119ja3w.js → cli-sptrj5f5.js} +2 -2
  55. package/dist/{cli-a8c82p2t.js → cli-sqvfa090.js} +13 -6
  56. package/dist/{cli-phfg8vy8.js → cli-swfmp1fx.js} +26 -26
  57. package/dist/{cli-nsdxtcbg.js → cli-tcen9p5w.js} +8 -5
  58. package/dist/{cli-9m03pzga.js → cli-vc9bp061.js} +5 -5
  59. package/dist/{cli-rtx9dygp.js → cli-vxe6qa4h.js} +1 -1
  60. package/dist/{cli-ecfxwnyb.js → cli-vy3ed88x.js} +1 -1
  61. package/dist/{cli-0c7ata9h.js → cli-vyqs9ya8.js} +6 -6
  62. package/dist/cli-wbvnn6tk.js +861 -0
  63. package/dist/{cli-kgd3p0bm.js → cli-wjgs5wxe.js} +6 -6
  64. package/dist/cli-wxkkd0e0.js +33 -0
  65. package/dist/{cli-akfj32vj.js → cli-xqpk3rp7.js} +5 -4
  66. package/dist/cli-zp38xvtm.js +9487 -0
  67. package/dist/{cli-3zc55ctx.js → cli-zvhd3f64.js} +2 -2
  68. package/dist/{cli-ze1d3wzv.js → cli-zxqx25nz.js} +5 -5
  69. package/dist/cli.js +32 -25
  70. package/dist/{cloudflare-workers-ai-system-one-k6fbxw9d.js → cloudflare-workers-ai-system-one-k8ddqjkq.js} +8 -6
  71. package/dist/{codex-adapter-04v97vep.js → codex-adapter-esvmnhn7.js} +13 -13
  72. package/dist/{codex-hook-20me6byw.js → codex-hook-m73jmqgx.js} +19 -3
  73. package/dist/{codex-session-runner-ax69mqq3.js → codex-session-runner-ban9excr.js} +13 -13
  74. package/dist/{commands-18gy08n1.js → commands-75413p2n.js} +9 -7
  75. package/dist/{db-d2pvjpyt.js → db-7f5pecwg.js} +11 -7
  76. package/dist/{dispatcher-8wbwyzjg.js → dispatcher-fh9at8nz.js} +33 -30
  77. package/dist/{dsh-adapter-ysqk9snv.js → dsh-adapter-wpze65d4.js} +3 -3
  78. package/dist/{e2b-esmt1r16.js → e2b-gjgdjp91.js} +10 -9
  79. package/dist/{pi-logo-animation-e9a0t68z.js → easter-egg-3d-3w5c2n4c.js} +122 -68
  80. package/dist/{execute-cmagrbrz.js → execute-f50wg9nh.js} +29 -6
  81. package/dist/{google-generative-ai-k6n5nbpp.js → google-generative-ai-jxxpnegy.js} +2 -2
  82. package/dist/{google-vertex-44xxtcvp.js → google-vertex-x7q1angm.js} +5 -5
  83. package/dist/{handlers-6b69m5kp.js → handlers-w13787bb.js} +36 -33
  84. package/dist/{hook-srnkt0hb.js → hook-46g1jrvx.js} +28 -15
  85. package/dist/{hook-k3mydf2n.js → hook-4tpts2ry.js} +20 -17
  86. package/dist/{http-hrf80ca1.js → http-19pzbfrt.js} +964 -176
  87. package/dist/{index-9rxdvj6w.js → index-8fd4dm4h.js} +34 -31
  88. package/dist/{index-1asbaj62.js → index-dqmp15bq.js} +35 -32
  89. package/dist/{index-45evq4ee.js → index-qb4q1y3e.js} +33 -30
  90. package/dist/{index-k4nj18qs.js → index-s75wc4wd.js} +12 -10
  91. package/dist/{index-xmevk2b9.js → index-scptvdxg.js} +27 -25
  92. package/dist/{keepalive-sfdz6ksp.js → keepalive-xa5ts9cd.js} +11 -9
  93. package/dist/{lead-ej91e9hw.js → lead-qp4xkvjq.js} +45 -41
  94. package/dist/{maintenance-80dnd7ke.js → maintenance-rm5885hm.js} +13 -11
  95. package/dist/{mistral-conversations-pc3ntnxt.js → mistral-conversations-rw7fbt22.js} +4 -4
  96. package/dist/{node-a5e00qhp.js → node-8zkdq42h.js} +834 -833
  97. package/dist/{oauth-refresh-sweep-m1etk2mx.js → oauth-refresh-sweep-1csdfebf.js} +10 -8
  98. package/dist/{onboard-0q8sdfqc.js → onboard-r6b78cs4.js} +10 -10
  99. package/dist/{openai-codex-responses-n7n683p2.js → openai-codex-responses-efvrgrq3.js} +4 -4
  100. package/dist/{openai-completions-jpaj5g2b.js → openai-completions-bbbrrz4z.js} +12 -8
  101. package/dist/{openai-responses-9a3nme9j.js → openai-responses-9jjyrcm1.js} +15 -10
  102. package/dist/{opencode-adapter-4wcgmvgf.js → opencode-adapter-kb3g6pkf.js} +2 -2
  103. package/dist/{otel-impl-hnqm9mxq.js → otel-impl-0y9knpky.js} +5 -5
  104. package/dist/{pi-mono-adapter-d6sqm9wr.js → pi-mono-adapter-z6s1bme2.js} +100 -19
  105. package/dist/{pricing-refresh-y60z64pm.js → pricing-refresh-mth26tgp.js} +11 -9
  106. package/dist/{rbac-roles-8pa0754b.js → rbac-roles-kwntb23q.js} +13 -9
  107. package/dist/rbac-roles-vpk4ebm8.js +45 -0
  108. package/dist/{registry-v5wytg0s.js → registry-km6t1jd2.js} +1 -1
  109. package/dist/{render-v2-418s1vj7.js → render-v2-hcm7h00y.js} +13 -11
  110. package/dist/{runtime-3pknc168.js → runtime-vfjsfsc5.js} +4 -4
  111. package/dist/{setup-yghdkj4x.js → setup-hbyzd65h.js} +2 -2
  112. package/dist/{virtual-modules-jcceevt5.js → virtual-modules-9bv7ry91.js} +9 -8
  113. package/dist/{work-objects-j1sz20v9.js → work-objects-m09sxnhe.js} +36 -33
  114. package/dist/{worker-d4gcvkjt.js → worker-0h35rvk4.js} +45 -41
  115. package/openapi.json +491 -12
  116. package/package.json +13 -6
  117. package/src/be/api-drain.ts +184 -0
  118. package/src/be/db/tasks/read.ts +31 -6
  119. package/src/be/db/tasks/write.ts +5 -4
  120. package/src/be/db.ts +42 -18
  121. package/src/be/memory/link-resolver.ts +29 -3
  122. package/src/be/migrations/192_favorites_agent_fs_path.sql +36 -0
  123. package/src/be/onboarding.ts +7 -1
  124. package/src/be/seed-prompt-templates.ts +1 -0
  125. package/src/be/swarm-config-guard.ts +35 -16
  126. package/src/be/task-citations.ts +11 -5
  127. package/src/be/users.ts +3 -0
  128. package/src/cli.tsx +3 -2
  129. package/src/comb/agent-fs.ts +39 -0
  130. package/src/comb/config.ts +37 -0
  131. package/src/comb/markers.ts +37 -0
  132. package/src/comb/review-batch.ts +486 -0
  133. package/src/comb/templates.ts +88 -0
  134. package/src/commands/context-preamble.ts +4 -1
  135. package/src/commands/hook.ts +2 -1
  136. package/src/commands/runner.ts +262 -68
  137. package/src/commands/templates.ts +10 -0
  138. package/src/extensions/contract-types.generated.ts +1 -1
  139. package/src/fs/agent-fs-provider.ts +106 -2
  140. package/src/heartbeat/heartbeat.ts +4 -0
  141. package/src/hooks/codex-hook.ts +25 -1
  142. package/src/hooks/hook.ts +13 -0
  143. package/src/hooks/pr-body-guard.ts +983 -0
  144. package/src/http/all-routes.ts +1 -0
  145. package/src/http/assets.ts +5 -17
  146. package/src/http/comb.ts +131 -0
  147. package/src/http/core.ts +2 -1
  148. package/src/http/fs.ts +9 -17
  149. package/src/http/index.ts +23 -9
  150. package/src/http/onboarding.ts +21 -2
  151. package/src/http/poll.ts +30 -3
  152. package/src/http/realtime.ts +62 -0
  153. package/src/http/request-principal.ts +22 -0
  154. package/src/http/status.ts +34 -2
  155. package/src/kv-reserved-namespaces.ts +10 -5
  156. package/src/providers/dsh-adapter.ts +1 -1
  157. package/src/providers/pi-mono-adapter.ts +123 -0
  158. package/src/rbac/legacy-policy.ts +1 -0
  159. package/src/rbac/permissions.ts +4 -0
  160. package/src/realtime/auth.ts +63 -1
  161. package/src/realtime/tickets.ts +52 -0
  162. package/src/realtime/transport.ts +51 -22
  163. package/src/scripts-runtime/types/swarm-extension.d.ts +3 -1
  164. package/src/telemetry-context.ts +175 -0
  165. package/src/telemetry-contract/EVENTS.md +81 -0
  166. package/src/telemetry-contract/SOURCE.json +9 -0
  167. package/src/telemetry-contract/catalog.json +1335 -0
  168. package/src/telemetry-contract/index.ts +60 -0
  169. package/src/telemetry-contract/types.gen.ts +1971 -0
  170. package/src/telemetry-identity.ts +129 -0
  171. package/src/telemetry-snapshot.ts +211 -0
  172. package/src/telemetry-trigger.ts +125 -0
  173. package/src/telemetry-types.typetest.ts +40 -0
  174. package/src/telemetry.ts +271 -67
  175. package/src/tests/api-drain-e2e.test.ts +249 -0
  176. package/src/tests/api-drain-worker-e2e.test.ts +216 -0
  177. package/src/tests/api-drain.test.ts +351 -0
  178. package/src/tests/comb-config-guard.test.ts +38 -0
  179. package/src/tests/comb-links.test.ts +162 -0
  180. package/src/tests/comb-markers.test.ts +68 -0
  181. package/src/tests/comb-review-batch.test.ts +770 -0
  182. package/src/tests/comb-status.test.ts +152 -0
  183. package/src/tests/db-task-read-contract.test.ts +2 -0
  184. package/src/tests/db-task-write-contract.test.ts +1 -0
  185. package/src/tests/docs-index-footprint.test.js +3 -3
  186. package/src/tests/dsh-adapter.test.ts +1 -1
  187. package/src/tests/favorites-agent-fs-path.test.ts +226 -0
  188. package/src/tests/memory-link-resolver.test.ts +34 -0
  189. package/src/tests/onboarding.test.ts +108 -0
  190. package/src/tests/pi-mono-adapter.test.ts +265 -2
  191. package/src/tests/pr-body-leaks.test.ts +789 -0
  192. package/src/tests/preload.ts +8 -0
  193. package/src/tests/rbac-engine.test.ts +19 -0
  194. package/src/tests/realtime-room-auth.test.ts +104 -1
  195. package/src/tests/realtime-tickets.test.ts +74 -0
  196. package/src/tests/realtime-transport.test.ts +131 -4
  197. package/src/tests/runner-api-drain.test.ts +301 -0
  198. package/src/tests/runner-fallback-output.test.ts +61 -0
  199. package/src/tests/runner-fenced-json-output.test.ts +178 -0
  200. package/src/tests/script-connections.test.ts +2 -0
  201. package/src/tests/send-task-requested-by.test.ts +133 -15
  202. package/src/tests/task-lifecycle-telemetry.test.ts +8 -3
  203. package/src/tests/telemetry-context.test.ts +314 -0
  204. package/src/tests/telemetry-init.test.ts +51 -19
  205. package/src/tests/telemetry-snapshot.test.ts +229 -0
  206. package/src/tests/telemetry-trigger.test.ts +200 -0
  207. package/src/tests/template-registry-helpers.ts +1 -0
  208. package/src/tests/workflow-agent-task-retry.test.ts +363 -0
  209. package/src/tests/workflow-definition-telemetry.test.ts +4 -4
  210. package/src/tools/poll-task.ts +20 -1
  211. package/src/tools/send-task.ts +9 -1
  212. package/src/tools/task-action.ts +11 -0
  213. package/src/types.ts +2 -1
  214. package/src/utils/api-drain.ts +24 -0
  215. package/src/utils/constants.ts +57 -16
  216. package/src/utils/pr-body-leaks.ts +172 -0
  217. package/src/utils/task-attachment-links.ts +14 -8
  218. package/src/workflows/recovery.ts +26 -1
  219. package/src/workflows/resume.ts +31 -4
  220. package/src/workflows/task-step-routing.ts +75 -2
  221. package/tsconfig.json +3 -0
  222. package/dist/cli-tjf4cn8z.js +0 -9119
  223. package/dist/cli-tsk3nz8a.js +0 -582
  224. package/dist/{cli-t6v2ah3r.js → cli-twrh04ap.js} +3 -3
@@ -0,0 +1,172 @@
1
+ /**
2
+ * Leak patterns for PR bodies on public repos.
3
+ *
4
+ * A swarm-authored PR body must explain why the change exists without
5
+ * internal identifiers: Slack ids, timestamps and links, dashboard and
6
+ * agent-fs links, swarm task/run/memory refs, or quotes from private chat.
7
+ *
8
+ * Callers:
9
+ * - `scripts/check-pr-body.ts` (CI backstop via `.github/workflows/pr-body.yml`)
10
+ * - `src/hooks/pr-body-guard.ts` (PreToolUse guard for `gh pr create|edit`)
11
+ *
12
+ * Results name the category only. Never echo the matched text: the report
13
+ * itself may be published (CI logs on a public repo, hook output in a PR).
14
+ *
15
+ * Calibration policy for swarm refs (`swarm-task-ref`):
16
+ * - Prose and inline code are checked: `task 1a2b3c4d`, `parentTaskId: <id>`.
17
+ * - Fenced code blocks are not: a test fixture or example such as
18
+ * `const taskId = "<uuid>";` is code, not provenance. Cost: a pasted log
19
+ * inside a fence that carries a real task id passes.
20
+ * - A bare "run" is not a swarm ref: "CI run 3f2a9c1d" is usually a CI run
21
+ * label and a commit SHA. Only "swarm run", "workflow run" or "run id"
22
+ * followed by a hex id counts. Cost: "run <id>" alone passes.
23
+ * Every other category is checked everywhere, fences included.
24
+ */
25
+
26
+ export type LeakCategory =
27
+ | "slack-id"
28
+ | "slack-ts"
29
+ | "slack-link"
30
+ | "swarm-dashboard-link"
31
+ | "agent-fs-link"
32
+ | "swarm-task-ref"
33
+ | "private-chat-quote"
34
+ | "agent-fs-path";
35
+
36
+ /**
37
+ * The agent-fs path rule (`thoughts/<uuid>/...`) stays off until maintainers
38
+ * decide on the QA convention. The repo review guidance asks for "durable
39
+ * copies: thoughts/<agent-id>/..." lines next to QA evidence embeds.
40
+ */
41
+ export const AGENT_FS_PATH_RULE_ENABLED = false;
42
+
43
+ type LeakRule = {
44
+ category: LeakCategory;
45
+ pattern: RegExp;
46
+ enabled: boolean;
47
+ /** Skip fenced code blocks (see the calibration policy above). */
48
+ proseOnly?: boolean;
49
+ };
50
+
51
+ const UUID = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}";
52
+
53
+ /** Words that attribute text to a person in private chat. Not part of a path or file name (`slack-render.ts`). */
54
+ const CHAT = String.raw`(?<![\w/.-])(?:Slack|DMs?|direct message|private (?:chat|message))(?![\w-]|\.\w)`;
55
+ const SPEECH = String.raw`(?::|\b(?:said|says|wrote|writes|asked|asks|verbatim)\b)`;
56
+
57
+ export const LEAK_RULES: readonly LeakRule[] = [
58
+ {
59
+ // Channel, DM, group and user ids: C0AR967K0KZ, D0A..., U0A...
60
+ category: "slack-id",
61
+ pattern: /\b[CDGUW]0(?=[A-Z0-9]*[A-Z])(?=[A-Z0-9]*\d)[A-Z0-9]{8,10}\b/,
62
+ enabled: true,
63
+ },
64
+ {
65
+ // Message ts: 10-digit epoch seconds (2020-2033), a dot, 6 digits.
66
+ category: "slack-ts",
67
+ pattern: /\b1[6-9]\d{8}\.\d{6}\b/,
68
+ enabled: true,
69
+ },
70
+ {
71
+ category: "slack-link",
72
+ pattern: /\bslack\.com\/(?:archives|client)\//i,
73
+ enabled: true,
74
+ },
75
+ {
76
+ // Dashboard links that carry an id: tasks, workflow runs, schedules, ...
77
+ category: "swarm-dashboard-link",
78
+ pattern: /\bapp\.agent-swarm\.dev\/[^\s)"'<>]*[0-9a-f]{8}/i,
79
+ enabled: true,
80
+ },
81
+ {
82
+ category: "agent-fs-link",
83
+ pattern: /\blive\.agent-fs\.dev\b/i,
84
+ enabled: true,
85
+ },
86
+ {
87
+ // "task 1a2b3c4d", "taskId: `1a2b3c4d-...`", "memory id ...", "schedule 1a2b3c4d"
88
+ category: "swarm-task-ref",
89
+ pattern:
90
+ /\b(?:swarm\s+)?(?:task|memory|schedule)s?(?:[\s_-]*id)?\s*[:#=]?\s*[`'"]?(?=[0-9]*[a-f])[0-9a-f]{8}\b/i,
91
+ enabled: true,
92
+ proseOnly: true,
93
+ },
94
+ {
95
+ // "swarm run 1a2b3c4d", "workflow run ...", "run_id: ...". Not a bare "run <sha>".
96
+ category: "swarm-task-ref",
97
+ pattern:
98
+ /\b(?:(?:swarm|workflow)\s+runs?(?:[\s_-]*id)?|runs?[\s_-]*id)\s*[:#=]?\s*[`'"]?(?=[0-9]*[a-f])[0-9a-f]{8}\b/i,
99
+ enabled: true,
100
+ proseOnly: true,
101
+ },
102
+ {
103
+ // camelCase fields: parentTaskId, sourceRunId, memoryId
104
+ category: "swarm-task-ref",
105
+ pattern: /(?:Task|Run|Memory|Schedule)Ids?\s*[:=]?\s*[`'"]?(?=[0-9]*[a-f])[0-9a-f]{8}\b/,
106
+ enabled: true,
107
+ proseOnly: true,
108
+ },
109
+ {
110
+ // `Taras in DM: "..."`, `From the Slack thread, he wrote "..."`
111
+ category: "private-chat-quote",
112
+ pattern: new RegExp(
113
+ String.raw`${CHAT}[^\n"“]{0,60}?${SPEECH}[^\n"“]{0,20}["“][^"”\n]{12,}`,
114
+ "i",
115
+ ),
116
+ enabled: true,
117
+ },
118
+ {
119
+ // Same attribution, with the quote as a markdown blockquote on the next line.
120
+ category: "private-chat-quote",
121
+ pattern: new RegExp(String.raw`${CHAT}[^\n]{0,60}${SPEECH}[ \t]*\n[ \t]*>`, "i"),
122
+ enabled: true,
123
+ },
124
+ {
125
+ category: "agent-fs-path",
126
+ pattern: new RegExp(String.raw`\bthoughts/${UUID}/`, "i"),
127
+ enabled: AGENT_FS_PATH_RULE_ENABLED,
128
+ },
129
+ ];
130
+
131
+ /**
132
+ * Presigned object-storage URLs (QA evidence embeds). Exempt until maintainers
133
+ * decide on the QA convention; the repo review guidance requires them.
134
+ */
135
+ const PRESIGNED_URL = /https?:\/\/[^\s)"'<>]*[?&]X-Amz-(?:Signature|Credential)=[^\s)"'<>]*/gi;
136
+
137
+ /** Well-known placeholder UUIDs used in docs and fixtures. */
138
+ const PLACEHOLDER_UUIDS = new RegExp(
139
+ [
140
+ String.raw`\b([0-9a-f])\1{7}-\1{4}-\1{4}-\1{4}-\1{12}\b`,
141
+ String.raw`\b123e4567-e89b-12d3-a456-426614174000\b`,
142
+ String.raw`\b550e8400-e29b-41d4-a716-446655440000\b`,
143
+ ].join("|"),
144
+ "gi",
145
+ );
146
+
147
+ /** Fenced code blocks (``` or ~~~). An unclosed fence runs to the end, as in CommonMark. */
148
+ const FENCED_CODE = /^[ \t]*(`{3,}|~{3,})[^\n]*\n[\s\S]*?(?:^[ \t]*\1[`~]*[ \t]*$|$(?![\s\S]))/gm;
149
+
150
+ /** Returns the distinct leak categories found in `body`, in rule order. Empty means clean. */
151
+ export function findPrBodyLeaks(body: string): LeakCategory[] {
152
+ const text = body
153
+ .replace(/\r\n/g, "\n")
154
+ .replace(PRESIGNED_URL, "<presigned-url>")
155
+ .replace(PLACEHOLDER_UUIDS, "<placeholder-uuid>");
156
+ const prose = text.replace(FENCED_CODE, "<code-block>");
157
+ const found: LeakCategory[] = [];
158
+ for (const rule of LEAK_RULES) {
159
+ if (
160
+ rule.enabled &&
161
+ !found.includes(rule.category) &&
162
+ rule.pattern.test(rule.proseOnly ? prose : text)
163
+ ) {
164
+ found.push(rule.category);
165
+ }
166
+ }
167
+ return found;
168
+ }
169
+
170
+ /** GitHub logins whose PR bodies get the leak check in CI. */
171
+ export const isSwarmBotLogin = (login: string | undefined) =>
172
+ /^desplega-bot(\[bot\])?$/i.test(login?.trim() ?? "");
@@ -1,5 +1,5 @@
1
1
  import type { TaskAttachment } from "../types";
2
- import { buildAgentFsLiveUrl, getAppUrl } from "./constants";
2
+ import { buildAgentFsLiveUrl, buildCombFileUrl, getAppUrl } from "./constants";
3
3
 
4
4
  function shellQuote(value: string): string {
5
5
  return `'${value.replace(/'/g, `'\\''`)}'`;
@@ -23,19 +23,25 @@ export function taskAttachmentFetchCommand(
23
23
  return `curl -s -H "Authorization: Bearer \${AGENT_SWARM_API_KEY:-$API_KEY}" -H "X-Agent-ID: $AGENT_ID" "${url}" --create-dirs -o ${outPath}`;
24
24
  }
25
25
 
26
- export function taskAttachmentDisplayUrl(attachment: TaskAttachment): string {
26
+ /**
27
+ * The link a human (Slack, prompts, citations) sees for an attachment. An
28
+ * agent-fs file links to the dashboard (Comb) when Comb is on and `APP_URL` is
29
+ * set, else to the agent-fs live UI, else to the raw `agent-fs:<path>`.
30
+ * `comb: false` skips the dashboard link.
31
+ */
32
+ export function taskAttachmentDisplayUrl(
33
+ attachment: TaskAttachment,
34
+ opts: { comb?: boolean } = {},
35
+ ): string {
27
36
  if (attachment.kind === "url") return attachment.url ?? "";
28
37
  if (attachment.kind === "page") {
29
38
  return attachment.pageId ? `${getAppUrl()}/pages/${attachment.pageId}` : "page:";
30
39
  }
31
40
 
32
41
  if (attachment.providerId === "agent-fs" || attachment.kind === "agent-fs") {
33
- const liveUrl = buildAgentFsLiveUrl({
34
- path: attachment.path,
35
- orgId: attachment.orgId,
36
- driveId: attachment.driveId,
37
- });
38
- return liveUrl ?? `agent-fs:${attachment.path ?? ""}`;
42
+ const file = { path: attachment.path, orgId: attachment.orgId, driveId: attachment.driveId };
43
+ const combUrl = opts.comb === false ? null : buildCombFileUrl(file);
44
+ return combUrl ?? buildAgentFsLiveUrl(file) ?? `agent-fs:${attachment.path ?? ""}`;
39
45
  }
40
46
 
41
47
  if (attachment.providerId === "local-fs" || attachment.kind === "shared-fs") {
@@ -24,6 +24,7 @@ import {
24
24
  checkpointPortStepAndResolveSuccessors,
25
25
  completeTaskStepAndResolveSuccessors,
26
26
  failStepAndRunIfWaiting,
27
+ scheduleTaskStepRetry,
27
28
  } from "./task-step-routing";
28
29
 
29
30
  /**
@@ -171,6 +172,24 @@ async function recoverWaitingRuns(registry: ExecutorRegistry): Promise<number> {
171
172
  if (!run || run.status !== "waiting" || !workflow) continue;
172
173
 
173
174
  const taskCompleted = stuck.taskStatus === "completed";
175
+ if (stuck.taskStatus === "failed") {
176
+ // Same retry policy as the live task.failed handler: this sweep can
177
+ // reach a failed task first, and must not bypass the node's retry.
178
+ // `stuck` is a snapshot: the live handler and retry poller may have
179
+ // redriven the step to a new task since, so every claim below is
180
+ // fenced on `stuck.taskId` still being the task bound to the step.
181
+ const failedStep = await getWorkflowRunStep(stuck.stepId);
182
+ if (!failedStep) continue;
183
+ const retry = await scheduleTaskStepRetry(
184
+ workflow.definition,
185
+ stuck.runId,
186
+ failedStep,
187
+ stuck.taskId,
188
+ "Task failed (recovered)",
189
+ );
190
+ if (retry === "scheduled") recovered++;
191
+ if (retry !== "not-eligible") continue;
192
+ }
174
193
  if (!taskCompleted && (workflow.definition.onNodeFailure ?? "fail") === "fail") {
175
194
  // Preserve the fail-fast recovery policy for failed/cancelled tasks.
176
195
  // Claimed: this sweep runs on every heartbeat, so the live task.failed
@@ -178,7 +197,12 @@ async function recoverWaitingRuns(registry: ExecutorRegistry): Promise<number> {
178
197
  // would kill a run that is already advancing.
179
198
  const reason =
180
199
  stuck.taskStatus === "failed" ? "Task failed (recovered)" : "Task cancelled (recovered)";
181
- const claimed = await failStepAndRunIfWaiting(stuck.stepId, stuck.runId, reason);
200
+ const claimed = await failStepAndRunIfWaiting(
201
+ stuck.stepId,
202
+ stuck.runId,
203
+ reason,
204
+ stuck.taskId,
205
+ );
182
206
  if (!claimed) continue;
183
207
  recovered++;
184
208
  continue;
@@ -202,6 +226,7 @@ async function recoverWaitingRuns(registry: ExecutorRegistry): Promise<number> {
202
226
  stepOutput,
203
227
  ctx,
204
228
  taskCompleted ? undefined : reason,
229
+ stuck.taskId,
205
230
  );
206
231
  if (!routing.claimed) continue;
207
232
  if (routing.foreachChild && !routing.joined) {
@@ -38,6 +38,7 @@ import {
38
38
  checkpointPortStepAndResolveSuccessors,
39
39
  completeTaskStepAndResolveSuccessors,
40
40
  failStepAndRunIfWaiting,
41
+ scheduleTaskStepRetry,
41
42
  } from "./task-step-routing";
42
43
  import { matchesFilter } from "./wait-filter";
43
44
 
@@ -87,7 +88,9 @@ export function setupWorkflowResumeListener(
87
88
  try {
88
89
  const event = data as TaskEvent;
89
90
  if (!event.workflowRunId || !event.workflowRunStepId) return;
90
- await handleTaskFailure(event, event.failureReason ?? "Task failed", registry);
91
+ await handleTaskFailure(event, event.failureReason ?? "Task failed", registry, {
92
+ retryable: true,
93
+ });
91
94
  } catch (err) {
92
95
  console.error("[workflows] Handle task failure error:", err);
93
96
  }
@@ -98,7 +101,7 @@ export function setupWorkflowResumeListener(
98
101
  try {
99
102
  const event = data as TaskEvent;
100
103
  if (!event.workflowRunId || !event.workflowRunStepId) return;
101
- await handleTaskFailure(event, "Task was cancelled", registry);
104
+ await handleTaskFailure(event, "Task was cancelled", registry, { retryable: false });
102
105
  } catch (err) {
103
106
  console.error("[workflows] Handle task cancellation error:", err);
104
107
  }
@@ -213,7 +216,10 @@ export async function finalizeOrWait(runId: string): Promise<void> {
213
216
  if (run?.status === "waiting") await updateWorkflowRun(runId, { status: "running" });
214
217
  return;
215
218
  }
216
- const hasWaiting = steps.some((s) => s.status === "waiting");
219
+ // A step queued for the retry poller is still live, like a waiting one.
220
+ const hasWaiting = steps.some(
221
+ (s) => s.status === "waiting" || (s.status === "failed" && s.nextRetryAt != null),
222
+ );
217
223
  if (hasWaiting) {
218
224
  await updateWorkflowRun(runId, { status: "waiting" });
219
225
  } else {
@@ -227,7 +233,10 @@ export async function finalizeOrWait(runId: string): Promise<void> {
227
233
  }
228
234
 
229
235
  /**
230
- * Handle task failure/cancellation — respects workflow's onNodeFailure config.
236
+ * Handle task failure/cancellation.
237
+ * A failed (never cancelled) task of an agent-task node with `retry` and
238
+ * attempts left is re-dispatched through the retry poller first.
239
+ * Otherwise the workflow's onNodeFailure config applies:
231
240
  * 'fail' (default): mark the entire run as failed.
232
241
  * 'continue': treat as completed with error output, let convergence proceed.
233
242
  */
@@ -235,6 +244,7 @@ async function handleTaskFailure(
235
244
  event: TaskEvent,
236
245
  reason: string,
237
246
  registry: ExecutorRegistry,
247
+ options: { retryable: boolean },
238
248
  ): Promise<void> {
239
249
  const run = await getWorkflowRun(event.workflowRunId!);
240
250
  if (!run || (run.status !== "waiting" && run.status !== "running")) return;
@@ -246,6 +256,23 @@ async function handleTaskFailure(
246
256
  const workflow = await getWorkflow(run.workflowId);
247
257
  if (!workflow) return;
248
258
 
259
+ if (options.retryable) {
260
+ const retry = await scheduleTaskStepRetry(
261
+ workflow.definition,
262
+ run.id,
263
+ step,
264
+ event.taskId,
265
+ reason,
266
+ );
267
+ if (retry === "scheduled") {
268
+ console.log(
269
+ `[workflows] Task ${event.taskId} failed; step ${step.nodeId} of run ${run.id} queued for retry ${step.retryCount + 1}`,
270
+ );
271
+ return;
272
+ }
273
+ if (retry === "not-claimed") return;
274
+ }
275
+
249
276
  const onFailure = workflow.definition.onNodeFailure ?? "fail";
250
277
 
251
278
  if (onFailure === "fail") {
@@ -1,11 +1,18 @@
1
1
  import {
2
+ detachTaskFromWorkflowRunStep,
2
3
  getDbClient,
4
+ getTaskById,
3
5
  getWorkflowRunStep,
4
6
  updateWorkflowRun,
5
7
  updateWorkflowRunStep,
6
8
  } from "../be/db";
7
- import type { WorkflowDefinition, WorkflowNode, WorkflowRunStep } from "../types";
8
- import { checkpointStep } from "./checkpoint";
9
+ import {
10
+ RetryPolicySchema,
11
+ type WorkflowDefinition,
12
+ type WorkflowNode,
13
+ type WorkflowRunStep,
14
+ } from "../types";
15
+ import { checkpointStep, checkpointStepFailure } from "./checkpoint";
9
16
  import { getSuccessors } from "./definition";
10
17
  import { joinForeach, resolveForeachParent } from "./foreach-join";
11
18
 
@@ -15,21 +22,36 @@ export interface PortStepRoutingResult {
15
22
  successors: WorkflowNode[];
16
23
  }
17
24
 
25
+ /**
26
+ * True while `taskId` is still the task bound to `stepId`. A retry detaches
27
+ * the failed task and the poller binds a fresh one to the same step, so a
28
+ * caller holding an older snapshot (the recovery sweep) can find the step
29
+ * `waiting` again on a task it never saw. Call inside the claim transaction.
30
+ */
31
+ async function isTaskBoundToStep(taskId: string, stepId: string): Promise<boolean> {
32
+ const task = await getTaskById(taskId);
33
+ return task?.workflowRunStepId === stepId;
34
+ }
35
+
18
36
  /**
19
37
  * Atomically fail a waiting step and its run. Returns false when another
20
38
  * handler already moved the step out of `waiting` — the same task terminal
21
39
  * event can reach both the live bus listener and a recovery sweep, and a
22
40
  * blind write here would stomp a run another handler is already advancing.
41
+ * With `ownerTaskId`, also returns false when that task is no longer the one
42
+ * bound to the step (a stale snapshot of a step that was since redriven).
23
43
  */
24
44
  export async function failStepAndRunIfWaiting(
25
45
  stepId: string,
26
46
  runId: string,
27
47
  reason: string,
48
+ ownerTaskId?: string,
28
49
  ): Promise<boolean> {
29
50
  const now = new Date().toISOString();
30
51
  return await getDbClient().transaction(async () => {
31
52
  const current = await getWorkflowRunStep(stepId);
32
53
  if (!current || current.status !== "waiting") return false;
54
+ if (ownerTaskId && !(await isTaskBoundToStep(ownerTaskId, stepId))) return false;
33
55
  await updateWorkflowRunStep(stepId, {
34
56
  status: "failed",
35
57
  error: reason,
@@ -69,6 +91,54 @@ export async function checkpointPortStepAndResolveSuccessors(
69
91
  });
70
92
  }
71
93
 
94
+ /**
95
+ * Outcome of `scheduleTaskStepRetry`:
96
+ * - `scheduled`: the step is queued for the retry poller; the caller stops.
97
+ * - `not-claimed`: another handler already moved the step out of `waiting`,
98
+ * or the failed task is no longer the one bound to the step (it was
99
+ * already retried and a fresh task now owns it); the caller stops.
100
+ * - `not-eligible`: no retry applies (no `node.retry`, not an agent-task node,
101
+ * or retries exhausted); the caller applies `onNodeFailure` as before.
102
+ */
103
+ export type TaskStepRetryOutcome = "scheduled" | "not-claimed" | "not-eligible";
104
+
105
+ /**
106
+ * Apply a node's `retry` policy to a FAILED agent-task step task. The sync
107
+ * executor path does this in `executeStep`; an async agent-task step only
108
+ * learns about the failure here, from `task.failed` or the recovery sweep.
109
+ *
110
+ * In one transaction: re-claim the step while it is still `waiting` AND still
111
+ * bound to the failed task, detach that task (the executor reuses any task
112
+ * bound to the step, so a bound failed task would park the retry forever), and
113
+ * record the failure with `nextRetryAt` so the retry poller re-dispatches a new
114
+ * task. Bounded by `maxRetries` via the step's persisted `retryCount`, read
115
+ * only after ownership is confirmed: a stale caller's step snapshot may carry
116
+ * the counter of a newer attempt.
117
+ */
118
+ export async function scheduleTaskStepRetry(
119
+ def: WorkflowDefinition,
120
+ runId: string,
121
+ step: WorkflowRunStep,
122
+ taskId: string,
123
+ reason: string,
124
+ ): Promise<TaskStepRetryOutcome> {
125
+ const node = def.nodes.find((n) => n.id === step.nodeId);
126
+ if (!node || node.type !== "agent-task" || !node.retry) return "not-eligible";
127
+ const parsed = RetryPolicySchema.safeParse(node.retry);
128
+ if (!parsed.success) return "not-eligible";
129
+ const policy = parsed.data;
130
+
131
+ return await getDbClient().transaction(async (): Promise<TaskStepRetryOutcome> => {
132
+ const current = await getWorkflowRunStep(step.id);
133
+ if (!current || current.status !== "waiting") return "not-claimed";
134
+ if (!(await isTaskBoundToStep(taskId, step.id))) return "not-claimed";
135
+ if (current.retryCount >= policy.maxRetries) return "not-eligible";
136
+ await detachTaskFromWorkflowRunStep(taskId);
137
+ await checkpointStepFailure(runId, step.id, reason, current.retryCount, policy);
138
+ return "scheduled";
139
+ });
140
+ }
141
+
72
142
  export interface TaskStepRoutingResult {
73
143
  /**
74
144
  * False when another handler already moved the step out of `waiting` — the
@@ -100,6 +170,7 @@ export async function completeTaskStepAndResolveSuccessors(
100
170
  output: unknown,
101
171
  ctx: Record<string, unknown>,
102
172
  failureReason?: string,
173
+ ownerTaskId?: string,
103
174
  ): Promise<TaskStepRoutingResult> {
104
175
  // The task step, optional foreach join checkpoint, workflow context, and
105
176
  // running status must commit together. A crash after this transaction is
@@ -109,6 +180,8 @@ export async function completeTaskStepAndResolveSuccessors(
109
180
  // own awaits, so the claim is only authoritative here.
110
181
  const current = await getWorkflowRunStep(step.id);
111
182
  if (!current || current.status !== "waiting") return UNCLAIMED;
183
+ // A stale snapshot of a step since redriven to a fresh task must not route it.
184
+ if (ownerTaskId && !(await isTaskBoundToStep(ownerTaskId, step.id))) return UNCLAIMED;
112
185
 
113
186
  const foreachParent = resolveForeachParent(def, step.nodeId);
114
187
  if (foreachParent) {
package/tsconfig.json CHANGED
@@ -47,6 +47,9 @@
47
47
  "docs-site",
48
48
  "assets/video-source",
49
49
  "mockups",
50
+ // Claude Code mod: built against the `claude-code` types the engine lays
51
+ // beside it; checked with `claude plugin validate` and `bun run test:claude-mod`.
52
+ "claude-mod",
50
53
  // Bundled skill assets shipped verbatim to agents. Their imports describe
51
54
  // what an agent writes in /workspace, not this repo's layout, so they are
52
55
  // deliberately not typechecked here.