@desplega.ai/agent-swarm 1.131.0 → 1.133.1

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 (265) hide show
  1. package/README.md +2 -2
  2. package/dist/{actions-w53mbns9.js → actions-cskpayd7.js} +11 -9
  3. package/dist/{anthropic-messages-rjmd2e7n.js → anthropic-messages-tpxtbx7b.js} +28 -12
  4. package/dist/{app-m9gwqsqv.js → app-ang77nbb.js} +8 -6
  5. package/dist/{assistant-bp65m6f3.js → assistant-b4exebdw.js} +16 -13
  6. package/dist/{azure-openai-responses-c0yjmbfd.js → azure-openai-responses-m3921t4y.js} +8 -8
  7. package/dist/{boot-reembed-62p0at2k.js → boot-reembed-ps2aftpb.js} +9 -7
  8. package/dist/{boot-reembed-xmfp6wdh.js → boot-reembed-znyk3nxb.js} +10 -8
  9. package/dist/{boot-scrub-logs-rr8q2dms.js → boot-scrub-logs-2ax3xgz1.js} +7 -5
  10. package/dist/{claude-adapter-2y47mrkd.js → claude-adapter-3ct8kgxw.js} +13 -9
  11. package/dist/{claude-managed-adapter-gv19tdew.js → claude-managed-adapter-akx4ntf2.js} +2 -2
  12. package/dist/{cli-t1xze5qh.js → cli-13w2hwkh.js} +1 -1
  13. package/dist/{cli-efxfnq6q.js → cli-1532szb1.js} +8 -6
  14. package/dist/{cli-d2tfkcga.js → cli-23d3rseb.js} +33 -17
  15. package/dist/{cli-nm5gtp1x.js → cli-2a75z9c5.js} +196 -7
  16. package/dist/{cli-fywms69x.js → cli-2t30rj0d.js} +1 -1
  17. package/dist/{cli-cvgjwnh1.js → cli-3c3tdgab.js} +10 -10
  18. package/dist/{cli-pm6xbh84.js → cli-3zzxa9jz.js} +46 -16
  19. package/dist/{cli-cdeg08wx.js → cli-4k6233gc.js} +1 -1
  20. package/dist/{cli-t55yw3a1.js → cli-5p2tz05r.js} +2 -2
  21. package/dist/{cli-0rcyq6d9.js → cli-5z2yhzvd.js} +125 -47
  22. package/dist/{cli-3kf51j15.js → cli-6zfq31nj.js} +9 -3
  23. package/dist/{cli-er3a4bb0.js → cli-8m9de10a.js} +6 -1
  24. package/dist/{cli-gm9cbhbq.js → cli-8t14vg9w.js} +27 -8
  25. package/dist/{cli-72q8m8gk.js → cli-9nfc2es8.js} +6 -6
  26. package/dist/{cli-5ze9rv97.js → cli-9ta3pwms.js} +11 -4
  27. package/dist/{cli-78xwvkhj.js → cli-avr0ns7z.js} +2 -2
  28. package/dist/{cli-n6h8qt8n.js → cli-c897wyhw.js} +12 -7
  29. package/dist/{cli-2q72qz2s.js → cli-dgk20ft7.js} +15 -6
  30. package/dist/cli-et1bbwqf.js +13 -0
  31. package/dist/{cli-bqw0mt1n.js → cli-f5w27pj3.js} +3 -3
  32. package/dist/{cli-2wadx7p2.js → cli-f8dre4bz.js} +2 -2
  33. package/dist/{cli-e7ckcg4v.js → cli-ftwpv451.js} +170 -387
  34. package/dist/{cli-g6b8x1h8.js → cli-g854s2dw.js} +1 -1
  35. package/dist/{cli-5kx36evn.js → cli-ggmdxeqa.js} +13 -8
  36. package/dist/cli-hkwfe3qj.js +530 -0
  37. package/dist/{cli-5dsbcjjw.js → cli-jqwnqx9m.js} +1 -1
  38. package/dist/{cli-9dr5qzc0.js → cli-ny122vh4.js} +21 -10
  39. package/dist/{cli-5v4rw6yd.js → cli-pvzqhbs9.js} +2 -2
  40. package/dist/cli-pzq5rjym.js +15 -0
  41. package/dist/{cli-xpxde7rm.js → cli-qes8ef67.js} +48 -30
  42. package/dist/{cli-sajgpkqg.js → cli-qs9hhsvb.js} +1723 -325
  43. package/dist/cli-qys3rhhz.js +27 -0
  44. package/dist/{cli-rzbpmxdr.js → cli-r6tpm37h.js} +2 -2
  45. package/dist/{cli-qv61hp37.js → cli-rch80c76.js} +2 -2
  46. package/dist/{cli-0258203w.js → cli-rpp0x4zy.js} +137 -17
  47. package/dist/{cli-5n6e5yfn.js → cli-s1k0wxhe.js} +12 -7
  48. package/dist/{cli-psh3c4va.js → cli-sfd9v7sj.js} +1 -1
  49. package/dist/{cli-70xqj0z3.js → cli-sh3ytsyj.js} +49 -39
  50. package/dist/{cli-zsspvvm2.js → cli-w1mp9jy7.js} +1 -1
  51. package/dist/{cli-d3x3x1c9.js → cli-xdb4mpnp.js} +2 -2
  52. package/dist/{cli-57khth04.js → cli-xmyqv00z.js} +120 -4
  53. package/dist/{cli-yw8vghx2.js → cli-xv8t8p3c.js} +65 -32
  54. package/dist/{cli-f1am9szv.js → cli-xxv5pn4f.js} +1 -1
  55. package/dist/{cli-t76vw5db.js → cli-y08jvxzx.js} +601 -140
  56. package/dist/{cli-a4jzdpa3.js → cli-zfbf3srj.js} +650 -245
  57. package/dist/{cli-a40rnf71.js → cli-zmq89k34.js} +6 -6
  58. package/dist/{cli-qmdnhpej.js → cli-zr9q011v.js} +23 -13
  59. package/dist/cli.js +22 -22
  60. package/dist/{codex-adapter-d24q75wk.js → codex-adapter-bef93pq4.js} +9 -7
  61. package/dist/{codex-hook-hq54t9ft.js → codex-hook-e8dba65p.js} +3 -2
  62. package/dist/{codex-session-runner-g50vcsex.js → codex-session-runner-5pkxys7x.js} +9 -7
  63. package/dist/{commands-c3nrc5hg.js → commands-e23s1bff.js} +9 -7
  64. package/dist/{db-nt7fg3tw.js → db-m3nabatn.js} +17 -5
  65. package/dist/{google-generative-ai-hysrd8qx.js → google-generative-ai-8maw55xh.js} +11 -8
  66. package/dist/{google-vertex-p5arrga0.js → google-vertex-8vjqmx8g.js} +11 -8
  67. package/dist/{handlers-fkr6swat.js → handlers-akazedvr.js} +16 -13
  68. package/dist/{hook-77wpvnjc.js → hook-ze4cpf0v.js} +55 -41
  69. package/dist/{hook-g019yehy.js → hook-zfqyyenw.js} +10 -7
  70. package/dist/{http-jewj0syk.js → http-sja0n6kw.js} +730 -150
  71. package/dist/index-0gr8vd6k.js +39 -0
  72. package/dist/{index-7n2xpbd4.js → index-354vkhdv.js} +154 -74
  73. package/dist/{index-070v4eyb.js → index-5qthek5t.js} +2 -3
  74. package/dist/{index-hfvggd0z.js → index-95t3cqq5.js} +16 -14
  75. package/dist/{index-9znhar3x.js → index-sea66619.js} +3 -4
  76. package/dist/{index-6gm5he8h.js → index-vpn36mma.js} +15 -13
  77. package/dist/{keepalive-j0fjvqfd.js → keepalive-3sp3meqj.js} +16 -10
  78. package/dist/{lead-1n8x30xe.js → lead-mefeewkf.js} +39 -36
  79. package/dist/{maintenance-gvev11sa.js → maintenance-8tbrbjfg.js} +10 -8
  80. package/dist/mistral-conversations-00zrp7g4.js +717 -0
  81. package/dist/{oauth-refresh-sweep-s9ecsvh0.js → oauth-refresh-sweep-srjwjz6m.js} +8 -6
  82. package/dist/{onboard-pvm5b38w.js → onboard-mt2tgyjg.js} +7 -7
  83. package/dist/{openai-codex-responses-5g27pd6f.js → openai-codex-responses-map32h2s.js} +18 -18
  84. package/dist/{openai-completions-3vkmfz2a.js → openai-completions-w871b1cq.js} +12 -11
  85. package/dist/{openai-responses-dg4t7j7a.js → openai-responses-b0j7xnw8.js} +15 -12
  86. package/dist/{opencode-adapter-1gm38aba.js → opencode-adapter-b39jefcj.js} +5 -3
  87. package/dist/{openrouter-images-g3gm8931.js → openrouter-images-srfkywy0.js} +4 -4
  88. package/dist/{otel-impl-p6jvgd9c.js → otel-impl-z6pxt3j9.js} +224 -9
  89. package/dist/{pi-mono-adapter-t091s27g.js → pi-mono-adapter-btvqmj58.js} +1138 -408
  90. package/dist/{pricing-refresh-k49rcyed.js → pricing-refresh-kyq8cezh.js} +9 -7
  91. package/dist/{rbac-roles-cr80g96t.js → rbac-roles-3ryfrfna.js} +8 -6
  92. package/dist/{rbac-roles-30pspvy7.js → rbac-roles-6qfvbee1.js} +9 -7
  93. package/dist/{render-v2-xm457ng1.js → render-v2-p61ppjey.js} +8 -6
  94. package/dist/{seed-pricing-yhpv35fr.js → seed-pricing-j56bbj4y.js} +8 -6
  95. package/dist/{setup-nytnmwwr.js → setup-tpr6c1kn.js} +2 -2
  96. package/dist/{worker-msytr2cw.js → worker-9w1v0mbb.js} +39 -36
  97. package/openapi.json +542 -16
  98. package/package.json +6 -6
  99. package/src/be/budget-refusal-notify.ts +14 -7
  100. package/src/be/db-queries/task-artifacts.ts +182 -0
  101. package/src/be/db.ts +783 -169
  102. package/src/be/events.ts +5 -0
  103. package/src/be/migrations/130_scratch_script_retention_grace.sql +6 -0
  104. package/src/be/migrations/131_session_logs_created_at_index.sql +2 -0
  105. package/src/be/migrations/132_multi_runtime_instances.sql +44 -0
  106. package/src/be/migrations/133_workflow_run_trigger_type.sql +12 -0
  107. package/src/be/migrations/135_backfill_task_pull_request_attachments.sql +228 -0
  108. package/src/be/migrations/136_task_requester_provenance.sql +37 -0
  109. package/src/be/migrations/137_memory_retrieval_composite_index.sql +1 -0
  110. package/src/be/multi-runtime.ts +430 -0
  111. package/src/be/scripts/db.ts +43 -1
  112. package/src/be/scripts/extract-schema.ts +3 -1
  113. package/src/be/scripts/retention.ts +164 -0
  114. package/src/be/scripts/run-saved.ts +16 -1
  115. package/src/be/scripts/typecheck.ts +3 -2
  116. package/src/be/seed-skills/index.ts +7 -0
  117. package/src/be/steering.ts +1 -1
  118. package/src/be/swarm-config-guard.ts +18 -0
  119. package/src/commands/credential-wait.ts +54 -0
  120. package/src/commands/onboard/steps/core-credentials.tsx +1 -1
  121. package/src/commands/onboard/steps/custom-templates.tsx +1 -1
  122. package/src/commands/onboard/steps/harness-credentials.tsx +1 -1
  123. package/src/commands/onboard/steps/health-check.tsx +1 -1
  124. package/src/commands/onboard/steps/start.tsx +1 -1
  125. package/src/commands/profile-sync-audit.ts +56 -0
  126. package/src/commands/profile-sync.ts +287 -15
  127. package/src/commands/provider-credentials.ts +46 -19
  128. package/src/commands/runner.ts +196 -33
  129. package/src/commands/templates.ts +22 -0
  130. package/src/github/handlers.ts +55 -9
  131. package/src/heartbeat/heartbeat.ts +71 -12
  132. package/src/hooks/hook.ts +49 -33
  133. package/src/http/active-sessions.ts +11 -1
  134. package/src/http/agents.ts +261 -30
  135. package/src/http/all-routes.ts +1 -0
  136. package/src/http/config.ts +13 -2
  137. package/src/http/core.ts +102 -4
  138. package/src/http/db-query-bounded.ts +313 -0
  139. package/src/http/db-query-shared.ts +249 -0
  140. package/src/http/db-query.ts +54 -42
  141. package/src/http/events.ts +2 -0
  142. package/src/http/index.ts +27 -2
  143. package/src/http/mcp-bridge.ts +37 -3
  144. package/src/http/mcp.ts +12 -0
  145. package/src/http/memory.ts +13 -2
  146. package/src/http/openapi.ts +1 -0
  147. package/src/http/poll.ts +70 -27
  148. package/src/http/route-def.ts +43 -9
  149. package/src/http/schedules.ts +2 -2
  150. package/src/http/scripts.ts +31 -4
  151. package/src/http/session-data.ts +44 -0
  152. package/src/http/tasks.ts +2 -2
  153. package/src/http/users.ts +74 -52
  154. package/src/http/webhooks.ts +5 -2
  155. package/src/http/workflows.ts +1 -4
  156. package/src/http/x.ts +14 -0
  157. package/src/integrations/kapso/inbound.ts +1 -1
  158. package/src/jira/outbound.ts +39 -8
  159. package/src/jira/webhook-lifecycle.ts +13 -2
  160. package/src/linear/outbound.ts +43 -10
  161. package/src/oauth/keepalive.ts +13 -2
  162. package/src/prompts/base-prompt.ts +1 -1
  163. package/src/prompts/session-templates.ts +45 -7
  164. package/src/providers/claude-adapter.ts +6 -0
  165. package/src/providers/claude-managed-models.ts +34 -10
  166. package/src/providers/codex-adapter.ts +6 -0
  167. package/src/providers/opencode-adapter.ts +6 -0
  168. package/src/providers/pi-mono-adapter.ts +8 -0
  169. package/src/providers/pricing-sources.md +24 -0
  170. package/src/queue-stall-alarm.ts +216 -0
  171. package/src/scheduler/scheduler.ts +7 -0
  172. package/src/script-workflows/executor.ts +2 -1
  173. package/src/scripts-runtime/executors/native.ts +2 -1
  174. package/src/scripts-runtime/executors/types.ts +5 -0
  175. package/src/scripts-runtime/loader.ts +5 -0
  176. package/src/scripts-runtime/swarm-config.ts +8 -0
  177. package/src/scripts-runtime/swarm-sdk.ts +7 -0
  178. package/src/scripts-runtime/types/stdlib.d.ts +1 -0
  179. package/src/scripts-runtime/types/swarm-sdk.d.ts +1 -0
  180. package/src/tests/budget-claim-gate.test.ts +20 -0
  181. package/src/tests/claude-adapter.test.ts +32 -0
  182. package/src/tests/claude-managed-adapter.test.ts +38 -7
  183. package/src/tests/codex-adapter.test.ts +30 -0
  184. package/src/tests/create-task-validation.test.ts +128 -0
  185. package/src/tests/credential-wait.test.ts +67 -1
  186. package/src/tests/db-query.test.ts +711 -2
  187. package/src/tests/http-api-integration.test.ts +81 -0
  188. package/src/tests/http-users.test.ts +166 -1
  189. package/src/tests/identity-field-budget.test.ts +176 -0
  190. package/src/tests/mcp-tools-user.test.ts +34 -0
  191. package/src/tests/mcp-user-route.test.ts +17 -0
  192. package/src/tests/metrics-http.test.ts +44 -0
  193. package/src/tests/multi-runtime-registration.test.ts +2703 -0
  194. package/src/tests/openapi-response-contract.test.ts +24 -0
  195. package/src/tests/openapi-route-headers.test.ts +83 -0
  196. package/src/tests/opencode-adapter.test.ts +40 -0
  197. package/src/tests/outbound-listener-rejection.test.ts +138 -0
  198. package/src/tests/pi-mono-adapter.test.ts +98 -0
  199. package/src/tests/profile-sync-warning.test.ts +277 -0
  200. package/src/tests/profile-sync.test.ts +232 -6
  201. package/src/tests/prompt-template-session.test.ts +32 -3
  202. package/src/tests/queue-stall-alarm.test.ts +226 -0
  203. package/src/tests/requester-comms.test.ts +32 -0
  204. package/src/tests/runner-requester-profile.test.ts +38 -0
  205. package/src/tests/sandboxed-process.test.ts +45 -0
  206. package/src/tests/schedule-target-type.test.ts +38 -0
  207. package/src/tests/script-connections.test.ts +16 -3
  208. package/src/tests/scripts-external-api.test.ts +8 -3
  209. package/src/tests/scripts-http.test.ts +12 -0
  210. package/src/tests/scripts-retention.test.ts +384 -0
  211. package/src/tests/scripts-runtime-identity.test.ts +375 -0
  212. package/src/tests/scripts-runtime.test.ts +4 -3
  213. package/src/tests/sdk-allowlist.test.ts +47 -0
  214. package/src/tests/send-task-requested-by.test.ts +9 -0
  215. package/src/tests/session-costs.test.ts +506 -1
  216. package/src/tests/shutdown-error-scrubbing.test.ts +92 -0
  217. package/src/tests/steering-core.test.ts +28 -0
  218. package/src/tests/task-artifacts.test.ts +386 -0
  219. package/src/tests/task-attachments-schema.test.ts +17 -1
  220. package/src/tests/task-completion-idempotency.test.ts +57 -0
  221. package/src/tests/task-pull-request-backfill-migration.test.ts +321 -0
  222. package/src/tests/update-profile-api.test.ts +67 -39
  223. package/src/tests/update-profile-auth.test.ts +48 -4
  224. package/src/tests/user-attribution-migration.test.ts +54 -0
  225. package/src/tests/user-identity.test.ts +72 -0
  226. package/src/tests/workflow-async-v2.test.ts +39 -1
  227. package/src/tests/workflow-http-v2.test.ts +3 -2
  228. package/src/tests/workflow-mcp-trigger-schema.test.ts +52 -3
  229. package/src/tests/workflow-retry-v2.test.ts +45 -1
  230. package/src/tests/workflow-swarm-script.test.ts +14 -5
  231. package/src/tools/db-query.ts +18 -8
  232. package/src/tools/get-task-details.ts +24 -3
  233. package/src/tools/manage-user.ts +36 -3
  234. package/src/tools/poll-task.ts +93 -14
  235. package/src/tools/script-common.ts +5 -0
  236. package/src/tools/send-task.ts +1 -4
  237. package/src/tools/store-progress.ts +13 -2
  238. package/src/tools/swarm-config/delete-config.ts +9 -0
  239. package/src/tools/swarm-config/set-config.ts +3 -2
  240. package/src/tools/task-action.ts +30 -0
  241. package/src/tools/task-tool-ctx.ts +8 -1
  242. package/src/tools/update-profile.ts +16 -21
  243. package/src/tools/utils.ts +5 -0
  244. package/src/tools/workflows/trigger-workflow.ts +7 -1
  245. package/src/types.ts +165 -1
  246. package/src/utils/github-pull-request.ts +76 -0
  247. package/src/utils/identity-field-budget.ts +73 -0
  248. package/src/utils/multi-runtime.ts +20 -0
  249. package/src/utils/requester-comms.ts +24 -0
  250. package/src/utils/sandboxed-process.ts +40 -14
  251. package/src/workflows/engine.ts +22 -2
  252. package/src/workflows/executors/swarm-script.ts +24 -1
  253. package/src/workflows/resume.ts +19 -11
  254. package/src/workflows/retry-poller.ts +1 -0
  255. package/src/workflows/triggers.ts +4 -0
  256. package/templates/schedules/daily-compounding-reflection/content.md +12 -3
  257. package/templates/skills/db-query-guidance/config.json +14 -0
  258. package/templates/skills/db-query-guidance/content.md +57 -0
  259. package/dist/cli-3te4jdkm.js +0 -225
  260. package/dist/cli-bmze986d.js +0 -7
  261. package/dist/cli-kh3ba2zf.js +0 -607
  262. package/dist/index-hp1kdbjj.js +0 -36
  263. package/dist/mistral-conversations-81fwav0j.js +0 -30578
  264. package/dist/otel-nqa12wf3.js +0 -3149
  265. package/dist/{pi-messages-tqj8q6b9.js → pi-messages-sssy32x4.js} +3 -3
@@ -1,21 +1,21 @@
1
1
  import {
2
2
  renderSteeringDelivery
3
- } from "./cli-f1am9szv.js";
3
+ } from "./cli-xxv5pn4f.js";
4
4
  import {
5
5
  checkCodexCredentials
6
- } from "./cli-5kx36evn.js";
6
+ } from "./cli-ggmdxeqa.js";
7
7
  import {
8
8
  checkClaudeManagedCredentials
9
- } from "./cli-qmdnhpej.js";
9
+ } from "./cli-zr9q011v.js";
10
10
  import {
11
11
  checkDevinCredentials
12
12
  } from "./cli-9b13ggd1.js";
13
13
  import {
14
14
  checkOpencodeCredentials
15
- } from "./cli-n6h8qt8n.js";
15
+ } from "./cli-c897wyhw.js";
16
16
  import {
17
17
  checkClaudeCredentials
18
- } from "./cli-3kf51j15.js";
18
+ } from "./cli-6zfq31nj.js";
19
19
  import {
20
20
  MAX_RATE_LIMIT_RESET_MS,
21
21
  isCodexCreditsExhaustedMessage,
@@ -35,7 +35,7 @@ import {
35
35
  withSpan,
36
36
  withSpanContext,
37
37
  writeSkillsToFilesystem
38
- } from "./cli-t76vw5db.js";
38
+ } from "./cli-y08jvxzx.js";
39
39
  import {
40
40
  authJsonToCredentialSelection,
41
41
  credentialsToAuthJson,
@@ -44,10 +44,10 @@ import {
44
44
  import {
45
45
  ensure,
46
46
  initialize
47
- } from "./cli-5ze9rv97.js";
47
+ } from "./cli-9ta3pwms.js";
48
48
  import {
49
49
  validateJsonSchema
50
- } from "./cli-yw8vghx2.js";
50
+ } from "./cli-xv8t8p3c.js";
51
51
  import {
52
52
  getOpenRouterBaseUrl
53
53
  } from "./cli-3dpj7atn.js";
@@ -57,11 +57,12 @@ import {
57
57
  import {
58
58
  contentSha256,
59
59
  init_profile_sync,
60
+ prependProfileSyncRejectionBanner,
60
61
  resolveClaudeMdPath,
61
62
  syncProfileFilesToServer,
62
63
  writeIdentityBaselines,
63
64
  writeProfileFileFromDb
64
- } from "./cli-0258203w.js";
65
+ } from "./cli-rpp0x4zy.js";
65
66
  import {
66
67
  taskAttachmentDisplayUrl
67
68
  } from "./cli-t930g0xh.js";
@@ -74,21 +75,24 @@ import {
74
75
  initTelemetry,
75
76
  init_defaults,
76
77
  init_telemetry,
77
- init_templates,
78
78
  init_types,
79
79
  resolveTaskModelSelection,
80
80
  telemetry
81
- } from "./cli-a4jzdpa3.js";
81
+ } from "./cli-zfbf3srj.js";
82
+ import {
83
+ getBasePrompt,
84
+ init_base_prompt,
85
+ init_templates
86
+ } from "./cli-hkwfe3qj.js";
82
87
  import {
83
88
  configureHttpResolver,
84
89
  init_resolver,
85
- init_session_templates,
86
90
  init_steering_enabled,
87
91
  init_template,
88
92
  interpolate,
89
93
  isSteeringEnabled,
90
94
  resolveTemplateAsync
91
- } from "./cli-xpxde7rm.js";
95
+ } from "./cli-qes8ef67.js";
92
96
  import {
93
97
  getMcpBaseUrl,
94
98
  init_constants
@@ -108,330 +112,7 @@ import {
108
112
  // src/commands/runner.ts
109
113
  import { existsSync, statSync } from "node:fs";
110
114
  import { mkdir, readFile, stat, writeFile } from "node:fs/promises";
111
-
112
- // src/prompts/base-prompt.ts
113
- init_steering_enabled();
114
- init_resolver();
115
- init_session_templates();
116
- var BOOTSTRAP_MAX_CHARS = 20000;
117
- var BOOTSTRAP_TOTAL_MAX_CHARS = 120000;
118
- var REPO_CLAUDE_MD_MAX_CHARS = 12000;
119
- var truncationNotice = (file) => `
120
-
121
- [...truncated, see /workspace/${file} for full content]
122
- `;
123
- function areSlackPromptToolsEnabled(env = process.env) {
124
- const slackDisable = env.SLACK_DISABLE;
125
- if (slackDisable === "true" || slackDisable === "1")
126
- return false;
127
- return Boolean(env.SLACK_BOT_TOKEN && env.SLACK_APP_TOKEN);
128
- }
129
- var getBasePrompt = async (args) => {
130
- const { role, agentId, swarmUrl, traits } = args;
131
- const {
132
- hasMcp = true,
133
- hasLocalEnvironment: hasLocalEnv = true,
134
- nativeSkillDiscovery = true
135
- } = traits ?? {};
136
- const steerModes = traits?.steerModes ?? [];
137
- const vars = { role, agentId, swarmUrl };
138
- let compositeEventType;
139
- if (!hasMcp) {
140
- compositeEventType = "system.session.worker.remote";
141
- } else if (args.provider === "pi") {
142
- compositeEventType = role === "lead" ? "system.session.lead.pi" : "system.session.worker.pi";
143
- } else if (role === "lead") {
144
- compositeEventType = "system.session.lead";
145
- } else {
146
- compositeEventType = "system.session.worker";
147
- }
148
- const compositeResult = await resolveTemplateAsync(compositeEventType, vars);
149
- let prompt = compositeResult.text;
150
- const scriptsOnly = args.scriptsOnly ?? process.env.SCRIPTS_ONLY_MCP === "true";
151
- const scriptsOnlyMode = hasMcp && scriptsOnly;
152
- if (scriptsOnlyMode) {
153
- const scriptsOnlyResult = await resolveTemplateAsync("system.agent.scripts_only_mode", {});
154
- prompt += `
155
- ${scriptsOnlyResult.text}`;
156
- }
157
- const slackPromptToolsEnabled = areSlackPromptToolsEnabled();
158
- const serverHasCapability = (cap, whenUnknown) => args.serverCapabilities ? args.serverCapabilities.includes(cap) : whenUnknown;
159
- if (hasMcp && slackPromptToolsEnabled && !scriptsOnlyMode && serverHasCapability("slack", true)) {
160
- const slackResult = await resolveTemplateAsync("system.agent.slack", {});
161
- prompt += slackResult.text;
162
- }
163
- if (role !== "lead" && args.slackContext && hasMcp && slackPromptToolsEnabled && (scriptsOnlyMode || serverHasCapability("slack", true))) {
164
- const slackResult = await resolveTemplateAsync(scriptsOnlyMode ? "system.agent.scripts_only_mode.slack" : "system.agent.worker.slack", {
165
- slackChannelId: args.slackContext.channelId,
166
- slackThreadTs: args.slackContext.threadTs ?? ""
167
- });
168
- prompt += slackResult.text;
169
- }
170
- if (hasMcp && !scriptsOnlyMode && serverHasCapability("messaging", true)) {
171
- const messagingResult = await resolveTemplateAsync("system.agent.messaging", {});
172
- prompt += messagingResult.text;
173
- }
174
- if (hasMcp && isSteeringEnabled() && steerModes.length > 0 && !scriptsOnlyMode && serverHasCapability("core", true)) {
175
- const steeringResult = await resolveTemplateAsync("system.agent.steering", {});
176
- prompt += steeringResult.text;
177
- }
178
- if (!hasLocalEnv) {
179
- prompt += `
180
-
181
- ## Your Identity
182
-
183
- `;
184
- if (args.name) {
185
- prompt += `**Name:** ${args.name}
186
- `;
187
- if (args.description) {
188
- prompt += `**Description:** ${args.description}
189
- `;
190
- }
191
- prompt += `
192
- `;
193
- }
194
- prompt += `You are part of an agent swarm managed by the Desplega platform. `;
195
- prompt += `You receive tasks from the swarm's lead agent and execute them independently. `;
196
- prompt += `Focus on quality work and clear communication of results.
197
- `;
198
- } else if (args.soulMd || args.identityMd || args.name) {
199
- prompt += `
200
-
201
- ## Your Identity
202
-
203
- `;
204
- if (args.name) {
205
- prompt += `**Name:** ${args.name}
206
- `;
207
- if (args.description) {
208
- prompt += `**Description:** ${args.description}
209
- `;
210
- }
211
- prompt += `
212
- `;
213
- }
214
- if (args.soulMd) {
215
- prompt += `${args.soulMd}
216
- `;
217
- }
218
- if (args.identityMd) {
219
- prompt += `${args.identityMd}
220
- `;
221
- }
222
- }
223
- if (hasMcp && args.skillsSummary && args.skillsSummary.length > 0) {
224
- const discovery = "To browse the full catalog use the `skill-list` MCP tool, find one by intent with `skill-search`, and read a skill's content with `skill-get`.";
225
- if (nativeSkillDiscovery) {
226
- const count = args.skillsSummary.length;
227
- const where = hasLocalEnv ? "Your harness loads them from its skills directory (each skill is a folder with a SKILL.md — e.g. ~/.claude/skills/, ~/.codex/skills/, ~/.pi/agent/skills/, ~/.opencode/skills/) and most harnesses surface them natively." : "This session has no local skills directory, so reach them through the MCP tools.";
228
- prompt += `
229
-
230
- ## Installed Skills
231
-
232
- You have ${count} skill${count === 1 ? "" : "s"} installed. ${where} ${discovery}
233
- `;
234
- } else {
235
- const summaries = args.skillsSummary.map((s) => `- ${hasLocalEnv ? "/" : ""}${s.name}: ${s.description}`).join(`
236
- `);
237
- const howTo = hasLocalEnv ? "To use one, read its SKILL.md from your skills directory and follow its instructions." : "To use one, read its content with the `skill-get` MCP tool and follow its instructions.";
238
- prompt += `
239
-
240
- ## Installed Skills
241
-
242
- The following skills are available. ${howTo}
243
-
244
- ${summaries}
245
-
246
- ${discovery}
247
- `;
248
- }
249
- }
250
- if (hasMcp && args.mcpServersSummary) {
251
- prompt += `
252
-
253
- ## Installed MCP Servers
254
-
255
- The following MCP servers are configured for your use:
256
- ${args.mcpServersSummary}
257
- `;
258
- }
259
- if (args.repoContext) {
260
- prompt += `
261
-
262
- ## Repository Context
263
-
264
- `;
265
- if (args.repoContext.warning) {
266
- prompt += `WARNING: ${args.repoContext.warning}
267
-
268
- `;
269
- }
270
- if (hasLocalEnv) {
271
- if (args.repoContext.claudeMd) {
272
- prompt += `The following CLAUDE.md is from the repository cloned at \`${args.repoContext.clonePath}\`. `;
273
- prompt += `**IMPORTANT: These instructions apply ONLY when working within the \`${args.repoContext.clonePath}\` directory.** `;
274
- prompt += `Do NOT apply these rules to files outside that directory.
275
-
276
- `;
277
- prompt += `${truncateRepoClaudeMd(args.repoContext.claudeMd, args.repoContext.clonePath, REPO_CLAUDE_MD_MAX_CHARS)}
278
- `;
279
- } else if (!args.repoContext.warning) {
280
- prompt += `Repository is cloned at \`${args.repoContext.clonePath}\` but has no CLAUDE.md file.
281
- `;
282
- }
283
- if (args.repoContext.autoStashes && args.repoContext.autoStashes.length > 0) {
284
- const stashes = args.repoContext.autoStashes.map((stash) => `- ${stash.ref}: ${stash.message}`).join(`
285
- `);
286
- prompt += `
287
- Pending auto-stashed work exists in this repo:
288
- ${stashes}
289
- Restore if relevant with \`git stash apply <ref>\` or \`git stash pop <ref>\`.
290
- `;
291
- }
292
- }
293
- const g = args.repoContext.guidelines;
294
- if (g === null || g === undefined) {
295
- prompt += `
296
- ### Repository Guidelines
297
-
298
- No repository guidelines defined. If you need to push code, ask the lead or user to define guidelines first.
299
- `;
300
- } else {
301
- const hasAnyContent = g.prChecks.length > 0 || g.mergeChecks.length > 0 || g.review.length > 0 || g.allowMerge;
302
- if (hasAnyContent) {
303
- prompt += `
304
- ### Repository Guidelines (MANDATORY)
305
-
306
- `;
307
- if (g.prChecks.length > 0) {
308
- prompt += `**PR Checks — Run ALL before pushing code or creating a PR:**
309
- `;
310
- g.prChecks.forEach((check, i) => {
311
- prompt += `${i + 1}. \`${check}\`
312
- `;
313
- });
314
- prompt += `If ANY check fails, fix the issue before pushing. Do NOT push code with failing checks.
315
- Do NOT use \`--no-verify\` or any flag that bypasses git hooks.
316
-
317
- `;
318
- }
319
- prompt += `**Merge Policy:**
320
- `;
321
- prompt += `- Auto-merge: ${g.allowMerge ? "Allowed" : "Not allowed (default)"}
322
- `;
323
- if (g.mergeChecks.length > 0) {
324
- prompt += `- Before merging, verify:
325
- `;
326
- g.mergeChecks.forEach((check) => {
327
- prompt += ` - ${check}
328
- `;
329
- });
330
- }
331
- prompt += `
332
- `;
333
- if (g.review.length > 0) {
334
- prompt += `**Review Guidance:**
335
- `;
336
- g.review.forEach((item) => {
337
- prompt += `- ${item}
338
- `;
339
- });
340
- prompt += `
341
- `;
342
- }
343
- }
344
- }
345
- }
346
- if (hasLocalEnv) {
347
- let conditionalSuffix = "";
348
- if (process.env.AGENT_FS_API_URL) {
349
- const sharedOrgId = process.env.AGENT_FS_SHARED_ORG_ID || "YOUR_SHARED_ORG_ID";
350
- const agentFsResult = await resolveTemplateAsync("system.agent.agent_fs", {
351
- agentId,
352
- sharedOrgId
353
- });
354
- conditionalSuffix += agentFsResult.text;
355
- }
356
- if (args.serverCapabilities ? args.serverCapabilities.includes("services") : !args.capabilities || args.capabilities.includes("services")) {
357
- const servicesResult = await resolveTemplateAsync("system.agent.services", {
358
- agentId,
359
- swarmUrl
360
- });
361
- conditionalSuffix += servicesResult.text;
362
- }
363
- if (!args.capabilities || args.capabilities.includes("artifacts")) {
364
- const artifactsResult = await resolveTemplateAsync("system.agent.artifacts", {});
365
- conditionalSuffix += artifactsResult.text;
366
- }
367
- if (serverHasCapability("pages", !args.capabilities || args.capabilities.includes("pages"))) {
368
- const appsResult = await resolveTemplateAsync("system.agent.apps", {});
369
- conditionalSuffix += appsResult.text;
370
- }
371
- if (args.capabilities) {
372
- conditionalSuffix += `
373
- ### Capabilities enabled for this agent:
374
-
375
- - ${args.capabilities.join(`
376
- - `)}
377
- `;
378
- }
379
- const protectedLength = prompt.length + conditionalSuffix.length;
380
- const totalBudget = Math.max(0, BOOTSTRAP_TOTAL_MAX_CHARS - protectedLength);
381
- let totalUsed = 0;
382
- if (args.claudeMd) {
383
- const perSectionBudget = Math.min(BOOTSTRAP_MAX_CHARS, totalBudget - totalUsed);
384
- const section = truncateSection(args.claudeMd, "## Agent Instructions", "CLAUDE.md", perSectionBudget);
385
- prompt += section;
386
- totalUsed += section.length;
387
- }
388
- if (args.toolsMd) {
389
- const perSectionBudget = Math.min(BOOTSTRAP_MAX_CHARS, totalBudget - totalUsed);
390
- const section = truncateSection(args.toolsMd, "## Your Tools & Capabilities", "TOOLS.md", perSectionBudget);
391
- prompt += section;
392
- totalUsed += section.length;
393
- }
394
- prompt += conditionalSuffix;
395
- }
396
- return prompt;
397
- };
398
- function truncateRepoClaudeMd(content, clonePath, budget) {
399
- if (content.length <= budget)
400
- return content;
401
- const notice = `
402
-
403
- [...truncated — see ${clonePath}/CLAUDE.md for full content]
404
- `;
405
- const contentBudget = budget - notice.length;
406
- if (contentBudget <= 0)
407
- return notice.trimStart();
408
- return content.slice(0, contentBudget) + notice;
409
- }
410
- function truncateSection(content, header, fileName, budget) {
411
- if (!content || budget <= 0)
412
- return "";
413
- const fullSection = `
414
-
415
- ${header}
416
-
417
- ${content}
418
- `;
419
- if (fullSection.length <= budget)
420
- return fullSection;
421
- const headerStr = `
422
-
423
- ${header}
424
-
425
- `;
426
- const notice = truncationNotice(fileName);
427
- const contentBudget = budget - headerStr.length - notice.length;
428
- if (contentBudget > 0) {
429
- return headerStr + content.slice(0, contentBudget) + notice;
430
- }
431
- return "";
432
- }
433
-
434
- // src/commands/runner.ts
115
+ init_base_prompt();
435
116
  init_defaults();
436
117
 
437
118
  // src/prompts/memories.ts
@@ -495,19 +176,19 @@ async function materializeCodexAuthJson(_slot, creds, deps = {}) {
495
176
  async function createProviderAdapter(provider) {
496
177
  switch (provider) {
497
178
  case "claude": {
498
- const { ClaudeAdapter } = await import("./claude-adapter-2y47mrkd.js");
179
+ const { ClaudeAdapter } = await import("./claude-adapter-3ct8kgxw.js");
499
180
  return new ClaudeAdapter;
500
181
  }
501
182
  case "pi": {
502
- const { PiMonoAdapter } = await import("./pi-mono-adapter-t091s27g.js");
183
+ const { PiMonoAdapter } = await import("./pi-mono-adapter-btvqmj58.js");
503
184
  return new PiMonoAdapter;
504
185
  }
505
186
  case "codex": {
506
- const { CodexAdapter } = await import("./codex-adapter-d24q75wk.js");
187
+ const { CodexAdapter } = await import("./codex-adapter-bef93pq4.js");
507
188
  return new CodexAdapter;
508
189
  }
509
190
  case "claude-managed": {
510
- const { ClaudeManagedAdapter } = await import("./claude-managed-adapter-gv19tdew.js");
191
+ const { ClaudeManagedAdapter } = await import("./claude-managed-adapter-akx4ntf2.js");
511
192
  return new ClaudeManagedAdapter;
512
193
  }
513
194
  case "devin": {
@@ -515,7 +196,7 @@ async function createProviderAdapter(provider) {
515
196
  return new DevinAdapter;
516
197
  }
517
198
  case "opencode": {
518
- const { OpencodeAdapter } = await import("./opencode-adapter-1gm38aba.js");
199
+ const { OpencodeAdapter } = await import("./opencode-adapter-b39jefcj.js");
519
200
  return new OpencodeAdapter;
520
201
  }
521
202
  default:
@@ -1201,7 +882,7 @@ async function checkProviderCredentials(provider, env, opts) {
1201
882
  case "opencode":
1202
883
  return checkOpencodeCredentials(env, opts);
1203
884
  case "pi": {
1204
- const { checkPiMonoCredentials } = await import("./pi-mono-adapter-t091s27g.js");
885
+ const { checkPiMonoCredentials } = await import("./pi-mono-adapter-btvqmj58.js");
1205
886
  return checkPiMonoCredentials(env, opts);
1206
887
  }
1207
888
  default:
@@ -1417,20 +1098,32 @@ async function buildCredStatusReport(provider, env, opts = {}, kind) {
1417
1098
  bedrock
1418
1099
  };
1419
1100
  }
1420
- async function reportCredStatus(apiUrl, apiKey, agentId, credStatus) {
1101
+ async function sendCredStatusReport(apiUrl, apiKey, agentId, runtimeInstanceId, report) {
1102
+ const res = await fetch(`${apiUrl}/api/agents/${encodeURIComponent(agentId)}/credential-status`, {
1103
+ method: "PUT",
1104
+ headers: {
1105
+ Authorization: `Bearer ${apiKey}`,
1106
+ "X-Agent-ID": agentId,
1107
+ ...runtimeInstanceId ? { "X-Runtime-Instance-ID": runtimeInstanceId } : {},
1108
+ "Content-Type": "application/json"
1109
+ },
1110
+ body: JSON.stringify({
1111
+ ready: report.ready,
1112
+ missing: report.missing,
1113
+ ...report.credStatus ? { cred_status: report.credStatus } : {}
1114
+ })
1115
+ });
1116
+ if (!res.ok) {
1117
+ const body = await res.text().catch(() => "");
1118
+ throw new Error(`credential-status report failed: ${res.status} ${body}`.trim());
1119
+ }
1120
+ }
1121
+ async function reportCredStatus(apiUrl, apiKey, agentId, runtimeInstanceId, credStatus) {
1421
1122
  try {
1422
- await fetch(`${apiUrl}/api/agents/${encodeURIComponent(agentId)}/credential-status`, {
1423
- method: "PUT",
1424
- headers: {
1425
- Authorization: `Bearer ${apiKey}`,
1426
- "X-Agent-ID": agentId,
1427
- "Content-Type": "application/json"
1428
- },
1429
- body: JSON.stringify({
1430
- ready: credStatus.ready,
1431
- missing: credStatus.missing,
1432
- cred_status: credStatus
1433
- })
1123
+ await sendCredStatusReport(apiUrl, apiKey, agentId, runtimeInstanceId, {
1124
+ ready: credStatus.ready,
1125
+ missing: credStatus.missing,
1126
+ credStatus
1434
1127
  });
1435
1128
  } catch (err) {
1436
1129
  console.warn(`[cred-status] POST failed (non-fatal): ${err}`);
@@ -1557,6 +1250,29 @@ async function awaitCredentials(opts) {
1557
1250
  } catch {}
1558
1251
  return status;
1559
1252
  }
1253
+ async function retryBootStep(step, opts = {}) {
1254
+ const label = opts.label ?? "boot step";
1255
+ const attempts = opts.attempts ?? 5;
1256
+ const sleep = opts.sleep ?? ((ms) => Bun.sleep(ms));
1257
+ const log = opts.log ?? ((line) => console.warn(line));
1258
+ const maxDelayMs = opts.maxDelayMs ?? 1e4;
1259
+ let delayMs = opts.initialDelayMs ?? 1000;
1260
+ let lastError;
1261
+ for (let attempt = 1;attempt <= attempts; attempt++) {
1262
+ try {
1263
+ await step();
1264
+ return;
1265
+ } catch (err) {
1266
+ lastError = err;
1267
+ if (attempt < attempts) {
1268
+ log(`[boot] ${label} failed (attempt ${attempt}/${attempts}, retry in ${delayMs}ms): ${err}`);
1269
+ await sleep(delayMs);
1270
+ delayMs = Math.min(delayMs * 2, maxDelayMs);
1271
+ }
1272
+ }
1273
+ }
1274
+ throw lastError instanceof Error ? lastError : new Error(`${label} failed after ${attempts} attempt(s): ${lastError}`);
1275
+ }
1560
1276
 
1561
1277
  // src/commands/runner.ts
1562
1278
  init_profile_sync();
@@ -1856,6 +1572,9 @@ async function pingServer(config, _role) {
1856
1572
  if (config.apiKey) {
1857
1573
  headers.Authorization = `Bearer ${config.apiKey}`;
1858
1574
  }
1575
+ if (config.runtimeInstanceId) {
1576
+ headers["X-Runtime-Instance-ID"] = config.runtimeInstanceId;
1577
+ }
1859
1578
  try {
1860
1579
  await fetch(`${config.apiUrl}/ping`, {
1861
1580
  method: "POST",
@@ -1870,6 +1589,9 @@ async function closeAgent(config, role) {
1870
1589
  if (config.apiKey) {
1871
1590
  headers.Authorization = `Bearer ${config.apiKey}`;
1872
1591
  }
1592
+ if (config.runtimeInstanceId) {
1593
+ headers["X-Runtime-Instance-ID"] = config.runtimeInstanceId;
1594
+ }
1873
1595
  try {
1874
1596
  console.log(`[${role}] Marking agent as offline...`);
1875
1597
  await fetch(`${config.apiUrl}/close`, {
@@ -2883,7 +2605,8 @@ async function registerActiveSession(config, session) {
2883
2605
  taskId: session.taskId,
2884
2606
  triggerType: session.triggerType,
2885
2607
  taskDescription: session.taskDescription,
2886
- runnerSessionId: session.runnerSessionId
2608
+ runnerSessionId: session.runnerSessionId,
2609
+ runtimeInstanceId: config.runtimeInstanceId
2887
2610
  })
2888
2611
  });
2889
2612
  } catch {}
@@ -2957,15 +2680,24 @@ async function triggerHeartbeatSweep(config) {
2957
2680
  }
2958
2681
  }
2959
2682
  async function buildRequesterProfilePrompt(requestedBy) {
2960
- if (!requestedBy?.role && !requestedBy?.notes)
2683
+ const comms = requestedBy?.comms;
2684
+ const commsParts = [
2685
+ comms?.tone ? `tone: ${comms.tone}` : undefined,
2686
+ comms?.language ? `language: ${comms.language}` : undefined,
2687
+ comms?.verbosity ? `verbosity: ${comms.verbosity}` : undefined
2688
+ ].filter((part) => Boolean(part));
2689
+ if (!requestedBy?.role && !requestedBy?.notes && commsParts.length === 0)
2961
2690
  return "";
2962
- const notes = requestedBy.notes?.trim();
2691
+ const commsSection = commsParts.length > 0 ? `
2692
+ Their communication preferences: ${commsParts.join(", ")}.` : "";
2693
+ const notes = requestedBy?.notes?.trim();
2963
2694
  const notesSection = notes ? `
2964
2695
  Their stated notes for how you should respond and act:
2965
2696
  ${notes}` : "";
2966
2697
  const result = await resolveTemplateAsync("task.requester.profile", {
2967
- requester_name: requestedBy.name,
2968
- requester_role_suffix: requestedBy.role ? ` (${requestedBy.role})` : "",
2698
+ requester_name: requestedBy?.name ?? "",
2699
+ requester_role_suffix: requestedBy?.role ? ` (${requestedBy.role})` : "",
2700
+ requester_comms_section: commsSection,
2969
2701
  requester_notes_section: notesSection
2970
2702
  });
2971
2703
  return result.skipped ? "" : result.text.trim();
@@ -2990,7 +2722,8 @@ async function registerAgent(opts) {
2990
2722
  capabilities: opts.capabilities,
2991
2723
  maxTasks: opts.maxTasks,
2992
2724
  provider,
2993
- harness_provider: harnessProvider
2725
+ harness_provider: harnessProvider,
2726
+ runtimeInstanceId: opts.runtimeInstanceId
2994
2727
  })
2995
2728
  });
2996
2729
  if (!response.ok) {
@@ -3025,6 +2758,9 @@ async function pollForTriggerOnce(opts) {
3025
2758
  const headers = {
3026
2759
  "X-Agent-ID": opts.agentId
3027
2760
  };
2761
+ if (opts.runtimeInstanceId) {
2762
+ headers["X-Runtime-Instance-ID"] = opts.runtimeInstanceId;
2763
+ }
3028
2764
  if (opts.apiKey) {
3029
2765
  headers.Authorization = `Bearer ${opts.apiKey}`;
3030
2766
  }
@@ -3477,7 +3213,7 @@ async function spawnProviderProcess(adapter, opts, logDir, isYolo) {
3477
3213
  function bufferEvent(evt) {
3478
3214
  eventBuffer.push(evt);
3479
3215
  if (eventBuffer.length >= EVENT_BUFFER_MAX) {
3480
- flushEvents();
3216
+ flushEvents().catch((err) => console.error("[runner] event flush failed:", scrubSecrets(err instanceof Error ? err.message : String(err))));
3481
3217
  }
3482
3218
  }
3483
3219
  async function flushEvents() {
@@ -3989,7 +3725,7 @@ async function checkCompletedProcesses(state, role, apiConfig, cancelledSignaled
3989
3725
  vcsCheckTimestamps.delete(taskId);
3990
3726
  cancelledSignaled?.delete(taskId);
3991
3727
  if (apiConfig) {
3992
- removeActiveSession(apiConfig, taskId);
3728
+ removeActiveSession(apiConfig, taskId).catch((err) => console.error("[runner] active-session removal failed:", scrubSecrets(err instanceof Error ? err.message : String(err))));
3993
3729
  }
3994
3730
  if (apiConfig && workingDir && !vcsDetectedTasks.has(taskId)) {
3995
3731
  await detectVcsForTask(apiConfig.apiUrl, apiConfig.apiKey, taskId, workingDir);
@@ -4365,7 +4101,9 @@ ${additionalSystemPrompt}` : basePrompt;
4365
4101
  const SERVER_CAPS_REFRESH_INTERVAL_MS = 300000;
4366
4102
  let lastBedrockRefreshAt = 0;
4367
4103
  const BEDROCK_REFRESH_INTERVAL_MS = 5 * 60 * 1000;
4368
- const apiConfig = { apiUrl, apiKey, agentId };
4104
+ const runtimeInstanceId = crypto.randomUUID();
4105
+ process.env.SWARM_RUNTIME_INSTANCE_ID = runtimeInstanceId;
4106
+ const apiConfig = { apiUrl, apiKey, agentId, runtimeInstanceId };
4369
4107
  setupShutdownHandlers(role, apiConfig, () => state);
4370
4108
  const agentName = process.env.AGENT_NAME || cachedTemplate?.config.displayName || `${role}-${agentId.slice(0, 8)}`;
4371
4109
  const applySwarmConfigDrift = async (freshEnv, resolvedProvider, nextScriptsOnly) => {
@@ -4428,21 +4166,25 @@ ${additionalSystemPrompt}` : basePrompt;
4428
4166
  console.log(`[${role}] [config] Server capabilities updated (${next.length} flags) — system prompt rebuilt`);
4429
4167
  }
4430
4168
  };
4169
+ const registerCurrentRuntime = async () => {
4170
+ const reg = await registerAgent({
4171
+ apiUrl,
4172
+ apiKey,
4173
+ agentId,
4174
+ name: agentName,
4175
+ role,
4176
+ isLead,
4177
+ capabilities,
4178
+ maxTasks: state.maxConcurrent,
4179
+ harnessProvider: state.harnessProvider,
4180
+ runtimeInstanceId
4181
+ });
4182
+ lastServerCapsRefreshAt = Date.now();
4183
+ await applyServerCapabilities(reg.serverCapabilities);
4184
+ };
4431
4185
  const reregisterAgent = async () => {
4432
4186
  try {
4433
- const reg = await registerAgent({
4434
- apiUrl,
4435
- apiKey,
4436
- agentId,
4437
- name: agentName,
4438
- role,
4439
- isLead,
4440
- capabilities,
4441
- maxTasks: state.maxConcurrent,
4442
- harnessProvider: state.harnessProvider
4443
- });
4444
- lastServerCapsRefreshAt = Date.now();
4445
- await applyServerCapabilities(reg.serverCapabilities);
4187
+ await registerCurrentRuntime();
4446
4188
  } catch (err) {
4447
4189
  console.warn(`[${role}] [config] Re-register failed (non-fatal): ${err}`);
4448
4190
  }
@@ -4457,7 +4199,8 @@ ${additionalSystemPrompt}` : basePrompt;
4457
4199
  isLead,
4458
4200
  capabilities,
4459
4201
  maxTasks: maxConcurrent,
4460
- harnessProvider: bootProvider
4202
+ harnessProvider: bootProvider,
4203
+ runtimeInstanceId
4461
4204
  });
4462
4205
  lastServerCapsRefreshAt = Date.now();
4463
4206
  await applyServerCapabilities(reg.serverCapabilities);
@@ -4492,6 +4235,7 @@ ${additionalSystemPrompt}` : basePrompt;
4492
4235
  headers: {
4493
4236
  Authorization: `Bearer ${apiKey}`,
4494
4237
  "X-Agent-ID": agentId,
4238
+ "X-Runtime-Instance-ID": runtimeInstanceId,
4495
4239
  "Content-Type": "application/json"
4496
4240
  },
4497
4241
  body: JSON.stringify({ ready: status.ready, missing: status.missing })
@@ -4506,10 +4250,32 @@ ${additionalSystemPrompt}` : basePrompt;
4506
4250
  throw err;
4507
4251
  }
4508
4252
  try {
4509
- const snapshot = await buildCredStatusReport(state.harnessProvider, process.env, {}, "boot");
4510
- await reportCredStatus(apiUrl, apiKey, agentId, snapshot);
4253
+ await retryBootStep(registerCurrentRuntime, {
4254
+ label: "runtime re-registration",
4255
+ log: (line) => console.warn(`[${role}] ${line}`)
4256
+ });
4257
+ } catch (error) {
4258
+ console.error(`[${role}] Failed to re-register after credential wait: ${error}`);
4259
+ process.exit(1);
4260
+ }
4261
+ let bootCredSnapshot;
4262
+ try {
4263
+ bootCredSnapshot = await buildCredStatusReport(state.harnessProvider, process.env, {}, "boot");
4511
4264
  } catch (err) {
4512
- console.warn(`[${role}] cred_status boot report failed (non-fatal): ${err}`);
4265
+ console.warn(`[${role}] cred_status boot snapshot failed (non-fatal): ${err}`);
4266
+ }
4267
+ try {
4268
+ await retryBootStep(() => sendCredStatusReport(apiUrl, apiKey, agentId, runtimeInstanceId, {
4269
+ ready: bootCredSnapshot?.ready ?? true,
4270
+ missing: bootCredSnapshot?.missing ?? [],
4271
+ credStatus: bootCredSnapshot
4272
+ }), {
4273
+ label: "credential readiness report",
4274
+ log: (line) => console.warn(`[${role}] ${line}`)
4275
+ });
4276
+ } catch (error) {
4277
+ console.error(`[${role}] Failed to report credential readiness after recovery: ${error}`);
4278
+ process.exit(1);
4513
4279
  }
4514
4280
  }
4515
4281
  await cleanupActiveSessions(apiConfig);
@@ -4759,6 +4525,14 @@ ${additionalSystemPrompt}` : basePrompt;
4759
4525
  console.log(`[${role}] Injected context preamble into resumed follow-up task prompt (parent: ${task.parentTaskId.slice(0, 8)})`);
4760
4526
  }
4761
4527
  }
4528
+ const resumeWithSyncWarning = await prependProfileSyncRejectionBanner(resumePrompt, {
4529
+ ...apiConfig,
4530
+ claudeMdPath: resolveClaudeMdPath([state.harnessProvider])
4531
+ });
4532
+ resumePrompt = resumeWithSyncWarning.prompt;
4533
+ if (resumeWithSyncWarning.injected) {
4534
+ console.warn(`[${role}] Injected persisted profile sync rejection warning`);
4535
+ }
4762
4536
  const resumeCandidates = [
4763
4537
  {
4764
4538
  source: "task",
@@ -4862,7 +4636,7 @@ ${additionalSystemPrompt}` : basePrompt;
4862
4636
  triggerType: "task_resumed",
4863
4637
  taskDescription: task.task?.slice(0, 200),
4864
4638
  runnerSessionId: resumeRunnerSessionId
4865
- });
4639
+ }).catch((err) => console.error("[runner] active-session registration failed:", scrubSecrets(err instanceof Error ? err.message : String(err))));
4866
4640
  console.log(`[${role}] Resumed task ${task.id.slice(0, 8)} (${state.activeTasks.size}/${state.maxConcurrent} active)`);
4867
4641
  }
4868
4642
  console.log(`[${role}] All paused tasks resumed. Entering normal polling...`);
@@ -4911,10 +4685,10 @@ ${additionalSystemPrompt}` : basePrompt;
4911
4685
  const currentHarness = state.harnessProvider;
4912
4686
  if (currentHarness !== cachedCredHarnessProvider) {
4913
4687
  cachedCredHarnessProvider = currentHarness;
4914
- buildCredStatusReport(currentHarness, process.env, {}, "post_task").then((snap) => reportCredStatus(apiUrl, apiKey, agentId, snap)).catch((err) => console.warn(`[${role}] cred_status post_task report failed (non-fatal): ${err}`));
4688
+ buildCredStatusReport(currentHarness, process.env, {}, "post_task").then((snap) => reportCredStatus(apiUrl, apiKey, agentId, runtimeInstanceId, snap)).catch((err) => console.warn(`[${role}] cred_status post_task report failed (non-fatal): ${err}`));
4915
4689
  } else if (currentHarness === "pi" && isBedrockSdkMode(process.env) && Date.now() - lastBedrockRefreshAt > BEDROCK_REFRESH_INTERVAL_MS) {
4916
4690
  lastBedrockRefreshAt = Date.now();
4917
- buildCredStatusReport(currentHarness, process.env, {}, "post_task").then((snap) => reportCredStatus(apiUrl, apiKey, agentId, snap)).catch((err) => console.warn(`[${role}] bedrock enumeration refresh failed (non-fatal): ${err}`));
4691
+ buildCredStatusReport(currentHarness, process.env, {}, "post_task").then((snap) => reportCredStatus(apiUrl, apiKey, agentId, runtimeInstanceId, snap)).catch((err) => console.warn(`[${role}] bedrock enumeration refresh failed (non-fatal): ${err}`));
4918
4692
  }
4919
4693
  }
4920
4694
  const now = Date.now();
@@ -4927,7 +4701,7 @@ ${additionalSystemPrompt}` : basePrompt;
4927
4701
  if (!task.workingDir)
4928
4702
  continue;
4929
4703
  vcsCheckTimestamps.set(taskId, now);
4930
- detectVcsForTask(apiUrl, apiKey, taskId, task.workingDir);
4704
+ detectVcsForTask(apiUrl, apiKey, taskId, task.workingDir).catch((err) => console.error("[runner] VCS detection failed:", scrubSecrets(err instanceof Error ? err.message : String(err))));
4931
4705
  }
4932
4706
  if (state.activeTasks.size > 0) {
4933
4707
  for (const [taskId, task] of state.activeTasks) {
@@ -4976,6 +4750,7 @@ ${additionalSystemPrompt}` : basePrompt;
4976
4750
  apiKey,
4977
4751
  agentId,
4978
4752
  pollInterval: PollIntervalMs,
4753
+ runtimeInstanceId,
4979
4754
  pollTimeout: effectiveTimeout
4980
4755
  });
4981
4756
  if (trigger) {
@@ -5035,6 +4810,14 @@ ${additionalSystemPrompt}` : basePrompt;
5035
4810
  console.log(`[${role}] Injected ${isResumeTask ? "resume" : "context"} preamble for ${isResumeTask ? "resume" : "follow-up"} task (parent: ${taskObj.parentTaskId.slice(0, 8)})`);
5036
4811
  }
5037
4812
  }
4813
+ const triggerWithSyncWarning = await prependProfileSyncRejectionBanner(triggerPrompt, {
4814
+ ...apiConfig,
4815
+ claudeMdPath: resolveClaudeMdPath([state.harnessProvider])
4816
+ });
4817
+ triggerPrompt = triggerWithSyncWarning.prompt;
4818
+ if (triggerWithSyncWarning.injected) {
4819
+ console.warn(`[${role}] Injected persisted profile sync rejection warning`);
4820
+ }
5038
4821
  let resumeSessionId;
5039
4822
  if (taskObj?.parentTaskId) {
5040
4823
  const parentSession = await fetchProviderSessionInfo(apiUrl, apiKey, taskObj.parentTaskId);
@@ -5205,7 +4988,7 @@ Note: The task requested working directory "${taskDir}" but it does not exist. F
5205
4988
  triggerType: trigger.type,
5206
4989
  taskDescription: taskDesc,
5207
4990
  runnerSessionId: taskRunnerSessionId
5208
- });
4991
+ }).catch((err) => console.error("[runner] active-session registration failed:", scrubSecrets(err instanceof Error ? err.message : String(err))));
5209
4992
  console.log(`[${role}] Started task ${runningTask.taskId.slice(0, 8)} (${state.activeTasks.size}/${state.maxConcurrent} active, trigger: ${trigger.type})`);
5210
4993
  }
5211
4994
  } else {