@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
@@ -1,5 +1,6 @@
1
1
  import { normalizeSlackReactionShortcode } from "../slack/reaction-shortcode";
2
2
  import { ProviderNameSchema } from "../types";
3
+ import { API_DRAIN_MAX_MS_LIMIT } from "../utils/api-drain";
3
4
  import { parseTaskToolManifest } from "../utils/task-tool-manifest";
4
5
  import { isTierConfigKey, validateTierConfigValue } from "./model-tier-keys";
5
6
 
@@ -167,6 +168,26 @@ function boundedIntegerValidators(
167
168
  );
168
169
  }
169
170
 
171
+ /**
172
+ * Blank or an http(s) URL with no query string or fragment. Returns `invalid`
173
+ * for anything else. Blank is allowed: it is how an operator reverts to the
174
+ * key's fallback without deleting the row.
175
+ */
176
+ function validateHttpBaseUrl(value: unknown, invalid: string): string | null {
177
+ if (typeof value !== "string") return invalid;
178
+ const trimmed = value.trim();
179
+ if (trimmed.length === 0) return null;
180
+
181
+ try {
182
+ const url = new URL(trimmed);
183
+ if (url.protocol !== "https:" && url.protocol !== "http:") return invalid;
184
+ if (url.search || url.hash) return invalid;
185
+ } catch {
186
+ return invalid;
187
+ }
188
+ return null;
189
+ }
190
+
170
191
  function validateFloatRange(
171
192
  key: string,
172
193
  value: unknown,
@@ -213,22 +234,17 @@ const VALIDATED_KEYS: Record<string, ConfigValidator> = {
213
234
  // or a fragment would build a nonsense URL — reject those here rather than
214
235
  // letting workers fail one request at a time. Blank is meaningful and allowed:
215
236
  // it is how an operator reverts to openrouter.ai without deleting the row.
216
- OPENROUTER_BASE_URL: (value) => {
217
- const invalid =
218
- "Invalid OPENROUTER_BASE_URL (must be an http(s) URL with no query string or fragment, e.g. https://api.example.com/v1 — leave blank for openrouter.ai)";
219
- if (typeof value !== "string") return invalid;
220
- const trimmed = value.trim();
221
- if (trimmed.length === 0) return null;
222
-
223
- try {
224
- const url = new URL(trimmed);
225
- if (url.protocol !== "https:" && url.protocol !== "http:") return invalid;
226
- if (url.search || url.hash) return invalid;
227
- } catch {
228
- return invalid;
229
- }
230
- return null;
231
- },
237
+ OPENROUTER_BASE_URL: (value) =>
238
+ validateHttpBaseUrl(
239
+ value,
240
+ "Invalid OPENROUTER_BASE_URL (must be an http(s) URL with no query string or fragment, e.g. https://api.example.com/v1. Leave blank for openrouter.ai)",
241
+ ),
242
+ // Browser-facing agent-fs URL for Comb. Blank falls back to AGENT_FS_API_URL.
243
+ AGENT_FS_PUBLIC_URL: (value) =>
244
+ validateHttpBaseUrl(
245
+ value,
246
+ "Invalid AGENT_FS_PUBLIC_URL (must be an http(s) URL with no query string or fragment, e.g. https://agent-fs.example.com. Leave blank to use AGENT_FS_API_URL)",
247
+ ),
232
248
  HARNESS_PROVIDER: (value) => {
233
249
  const parsed = ProviderNameSchema.safeParse(value);
234
250
  if (parsed.success) return null;
@@ -312,6 +328,7 @@ const VALIDATED_KEYS: Record<string, ConfigValidator> = {
312
328
  "DB_QUERY_BOUNDED_ENABLED",
313
329
  "DB_RETENTION_DRY_RUN",
314
330
  "MODEL_AUTO_UPGRADE",
331
+ "COMB_ENABLED",
315
332
  ]),
316
333
  ...enumValidator("SLACK_MODE", ["socket", "http"]),
317
334
  ...enumValidator("SLACK_THREAD_STEERING", ["off", "lead", "all"]),
@@ -378,6 +395,8 @@ const VALIDATED_KEYS: Record<string, ConfigValidator> = {
378
395
  ...integerValidators(["MODEL_LATEST_SOAK_DAYS"], 0),
379
396
  // 0 turns approval auto-cancellation off.
380
397
  ...integerValidators(["APPROVAL_REQUEST_AUTO_CANCELLATION_DAYS"], 0),
398
+ // 0 turns the shutdown drain off; the shutdown path clamps to the same limit.
399
+ ...boundedIntegerValidators(["API_DRAIN_MAX_MS"], 0, API_DRAIN_MAX_MS_LIMIT),
381
400
  // Below ~100 tokens the preamble can't fit a useful summary; above 20000
382
401
  // (~80k chars) it risks the SIGTERM-143 context-saturation failure mode
383
402
  // the cap exists to prevent (see context-preamble.ts).
@@ -55,12 +55,18 @@ export function buildCitationUrl(citation: CitationInput): string | null {
55
55
  if (!ref.trim() || /:\/\//.test(ref)) return null;
56
56
  if (kind === "task") return citationHttpUrl(`${getAppUrl()}/tasks/${encodeURIComponent(ref)}`);
57
57
  if (kind === "page" || kind === "agent-fs") {
58
+ // Stored, so an agent-fs file keeps its live URL (`comb: false`). The
59
+ // dashboard maps it to Comb when it renders, so turning COMB_ENABLED off
60
+ // later leaves no dead dashboard links behind.
58
61
  return citationHttpUrl(
59
- taskAttachmentDisplayUrl({
60
- kind,
61
- pageId: kind === "page" ? encodeURIComponent(ref) : undefined,
62
- path: kind === "agent-fs" ? ref : undefined,
63
- } as TaskAttachment),
62
+ taskAttachmentDisplayUrl(
63
+ {
64
+ kind,
65
+ pageId: kind === "page" ? encodeURIComponent(ref) : undefined,
66
+ path: kind === "agent-fs" ? ref : undefined,
67
+ } as TaskAttachment,
68
+ { comb: false },
69
+ ),
64
70
  );
65
71
  }
66
72
  // Memory/run routes and Slack workspace permalinks have no canonical builder here.
package/src/be/users.ts CHANGED
@@ -20,6 +20,7 @@
20
20
  */
21
21
 
22
22
  import { createHash, randomBytes, randomUUID } from "node:crypto";
23
+ import { scheduleOrgDomainRecompute } from "../telemetry-identity";
23
24
  import type { User } from "../types";
24
25
  import { getDbClient } from "./db";
25
26
 
@@ -369,6 +370,8 @@ export async function findOrCreateUserByEmail(
369
370
  await recordIdentityEvent(id, "identity_added", actor, null, { email, name });
370
371
  return rowToUser(row);
371
372
  });
373
+ // The org's email domain may come from this user (debounced, post-commit).
374
+ getDbClient().afterCommit(scheduleOrgDomainRecompute);
372
375
 
373
376
  return { user: created, created: true };
374
377
  }
package/src/cli.tsx CHANGED
@@ -279,7 +279,7 @@ const COMMAND_HELP: Record<
279
279
  "codex-hook": {
280
280
  usage: `${binName} codex-hook`,
281
281
  description:
282
- "Handle Codex CLI hook events from stdin (steering delivery).\nUsed internally by the codex hooks registered in the worker image.",
282
+ "Handle Codex CLI hook events from stdin (steering delivery, PR body leak guard).\nUsed internally by the codex hooks registered in the worker image.",
283
283
  options: " -h, --help Show this help",
284
284
  examples: ` ${binName} codex-hook`,
285
285
  },
@@ -745,7 +745,8 @@ if (args.showHelp || args.command === "help" || args.command === undefined) {
745
745
  } else if (args.command === "codex-hook") {
746
746
  const { handleCodexHook } = await import("./hooks/codex-hook.ts");
747
747
  await handleCodexHook();
748
- process.exit(0);
748
+ // Exit code 2 from the PreToolUse guard blocks the tool call.
749
+ process.exit(process.exitCode ?? 0);
749
750
  } else if (args.command === "session-summary-stdin") {
750
751
  const { runSessionSummaryFromStdin } = await import("./hooks/hook.ts");
751
752
  await runSessionSummaryFromStdin();
@@ -0,0 +1,39 @@
1
+ import { AgentFsProvider } from "../fs/agent-fs-provider";
2
+ import { getFileStorageProvider } from "../fs/registry";
3
+
4
+ /**
5
+ * The agent-fs provider (the swarm's bootstrap key) that Comb uses to read
6
+ * comments and post the "sent" replies. Null when the swarm has no agent-fs
7
+ * provider yet (no key, or the shared drive is not provisioned).
8
+ */
9
+ export function combAgentFs(): AgentFsProvider | null {
10
+ try {
11
+ const provider = getFileStorageProvider();
12
+ return provider instanceof AgentFsProvider ? provider : null;
13
+ } catch {
14
+ return null;
15
+ }
16
+ }
17
+
18
+ // `/status` waits this long for the first lookup. Later calls read the cache.
19
+ const STATUS_LOOKUP_WAIT_MS = 2_000;
20
+
21
+ /**
22
+ * The agent-fs user id of the swarm service account, for `/status`
23
+ * (`agent_fs.comb.service_user_id`). The dashboard trusts a "sent" reply only
24
+ * from this author. Null when agent-fs is not set up, the lookup fails, or it
25
+ * takes longer than `STATUS_LOOKUP_WAIT_MS` (the next poll reads the cache).
26
+ */
27
+ export async function getCombServiceUserId(): Promise<string | null> {
28
+ const agentFs = combAgentFs();
29
+ if (!agentFs) return null;
30
+ let timer: ReturnType<typeof setTimeout> | undefined;
31
+ const timeout = new Promise<null>((resolve) => {
32
+ timer = setTimeout(resolve, STATUS_LOOKUP_WAIT_MS, null);
33
+ });
34
+ try {
35
+ return await Promise.race([agentFs.getServiceUserId().catch(() => null), timeout]);
36
+ } finally {
37
+ clearTimeout(timer);
38
+ }
39
+ }
@@ -0,0 +1,37 @@
1
+ import {
2
+ getAgentFsDefaultDriveId,
3
+ getAgentFsDefaultOrgId,
4
+ getAgentFsLiveUrl,
5
+ isCombEnabled,
6
+ } from "../utils/constants";
7
+
8
+ /** The Comb block of `/status` (`agent_fs.comb`), before snake-casing. */
9
+ export interface CombConfig {
10
+ enabled: boolean;
11
+ /** Browser-facing agent-fs URL. */
12
+ apiUrl: string | null;
13
+ liveUrl: string;
14
+ orgId: string | null;
15
+ driveId: string | null;
16
+ }
17
+
18
+ function trimUrl(value: string | undefined): string | null {
19
+ const trimmed = value?.trim().replace(/\/+$/, "");
20
+ return trimmed || null;
21
+ }
22
+
23
+ /**
24
+ * Comb (the agent-fs review space in the dashboard) settings. Reads
25
+ * `process.env` on every call, because a config upsert reloads the env
26
+ * without a restart.
27
+ */
28
+ export function getCombConfig(): CombConfig {
29
+ const internalUrl = trimUrl(process.env.AGENT_FS_API_URL);
30
+ return {
31
+ enabled: isCombEnabled(),
32
+ apiUrl: trimUrl(process.env.AGENT_FS_PUBLIC_URL) ?? internalUrl,
33
+ liveUrl: getAgentFsLiveUrl(),
34
+ orgId: getAgentFsDefaultOrgId() ?? null,
35
+ driveId: getAgentFsDefaultDriveId() ?? null,
36
+ };
37
+ }
@@ -0,0 +1,37 @@
1
+ // The "sent" reply that "Send to swarm" posts on each comment. The dashboard
2
+ // keeps its own copy of the pattern and the rule in
3
+ // `apps/ui/src/lib/comb/markers.ts`. `src/tests/comb-markers.test.ts` checks
4
+ // that both copies agree.
5
+
6
+ export const SENT_MARKER_PREFIX = "[comb:sent task=";
7
+
8
+ /** The machine-readable "sent" reply. Group 1 is the task id. */
9
+ export const SENT_MARKER_RE = /^\[comb:sent task=([0-9a-f-]{36})\]/;
10
+
11
+ /** The opening of a "sent" reply for `taskId`. */
12
+ export function sentMarker(taskId: string): string {
13
+ return `${SENT_MARKER_PREFIX}${taskId}]`;
14
+ }
15
+
16
+ interface Authored {
17
+ body: string;
18
+ author: string;
19
+ }
20
+
21
+ /**
22
+ * The task id of the thread's "sent" reply, or null. The reply starts with
23
+ * the marker, and the swarm service account wrote it. Without a known service
24
+ * account, any author except the thread's own author counts.
25
+ */
26
+ export function sentTaskId(
27
+ thread: { author: string },
28
+ replies: ReadonlyArray<Authored>,
29
+ serviceUserId: string | null,
30
+ ): string | null {
31
+ for (const reply of replies) {
32
+ const bySwarm = serviceUserId ? reply.author === serviceUserId : reply.author !== thread.author;
33
+ const taskId = bySwarm ? SENT_MARKER_RE.exec(reply.body)?.[1] : undefined;
34
+ if (taskId) return taskId;
35
+ }
36
+ return null;
37
+ }