@desplega.ai/agent-swarm 2.8.2 → 2.8.3

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 (258) hide show
  1. package/dist/acp-adapter-xq6s2z6t.js +14 -0
  2. package/dist/{actions-kxek041g.js → actions-ewz7bp4g.js} +20 -19
  3. package/dist/{amp-adapter-ce7jjke4.js → amp-adapter-f25tqhnf.js} +3 -3
  4. package/dist/{app-v6zz8yh0.js → app-mkptw0k7.js} +4 -4
  5. package/dist/{assistant-m0sw9xx2.js → assistant-c47rfe77.js} +23 -22
  6. package/dist/{boot-args-schema-66bk37wv.js → boot-args-schema-4vb0xsat.js} +1 -1
  7. package/dist/{boot-reembed-edjpwsc1.js → boot-reembed-1ghy2sab.js} +1 -1
  8. package/dist/{boot-reembed-y27n09tz.js → boot-reembed-htr73hbs.js} +1 -1
  9. package/dist/{boot-scrub-sweep-1xc35965.js → boot-scrub-sweep-yrytg42z.js} +4 -4
  10. package/dist/{boot-seeds-7hjj91qj.js → boot-seeds-n2b3dx4e.js} +4 -4
  11. package/dist/{boxd-ent8ch04.js → boxd-jmfqgkqa.js} +1 -1
  12. package/dist/{claude-adapter-stw7jdcf.js → claude-adapter-r33pqnzx.js} +8 -9
  13. package/dist/{claude-managed-adapter-jh6c523j.js → claude-managed-adapter-hddmxjyj.js} +4 -4
  14. package/dist/{claude-managed-setup-y6z2perp.js → claude-managed-setup-hfvry1bd.js} +5 -5
  15. package/dist/{claude-sdk-session-vvya8wqk.js → claude-sdk-session-0hamqzc7.js} +10 -11
  16. package/dist/{cli-v1dv1r37.js → cli-0bcgyj5b.js} +74 -3
  17. package/dist/{cli-t2tma8gb.js → cli-0vksaxvr.js} +2 -2
  18. package/dist/{cli-mrt48bx7.js → cli-15204js0.js} +1 -1
  19. package/dist/{cli-8aes17e4.js → cli-1m96dc36.js} +3 -3
  20. package/dist/{cli-2r0jcc3k.js → cli-2d0cghfn.js} +1 -1
  21. package/dist/{cli-0cq8y6m7.js → cli-4ax9mvvg.js} +4 -4
  22. package/dist/{cli-tekytdq9.js → cli-4dpkjc2e.js} +6 -6
  23. package/dist/{cli-x1wa213s.js → cli-4e1hfbpq.js} +5 -5
  24. package/dist/{cli-7349va39.js → cli-500c09j9.js} +921 -431
  25. package/dist/{cli-9mb2q6pb.js → cli-54qr8mcd.js} +2 -2
  26. package/dist/{cli-m88rpzkh.js → cli-5a7szzfh.js} +2 -2
  27. package/dist/{cli-bst1vp7e.js → cli-5y2fvw4z.js} +13 -5
  28. package/dist/{cli-vj75tyaw.js → cli-6yygkr0w.js} +7 -7
  29. package/dist/{cli-kjtwrhea.js → cli-7c5tgqhf.js} +5 -5
  30. package/dist/{cli-2gxeg5gr.js → cli-8476gtwf.js} +1 -1
  31. package/dist/{cli-zh9rsbqf.js → cli-922z7gwm.js} +3 -3
  32. package/dist/{cli-jrzkw01m.js → cli-93t5s4zq.js} +2 -2
  33. package/dist/{cli-gyt3zydq.js → cli-9zmb7ptc.js} +9 -9
  34. package/dist/{cli-dzpc6en0.js → cli-am1ptset.js} +2 -2
  35. package/dist/{cli-w401b9tq.js → cli-awwptga4.js} +1 -1
  36. package/dist/{cli-26ctbcdp.js → cli-bhsfbmk8.js} +3 -3
  37. package/dist/{cli-mxn1qvbn.js → cli-bj6qhgte.js} +14 -32
  38. package/dist/{cli-g70vxtjh.js → cli-c0xjnr8z.js} +2 -2
  39. package/dist/{cli-jdknh18m.js → cli-c3ng0mb4.js} +13 -13
  40. package/dist/{cli-f4e8r23x.js → cli-c71n3bxq.js} +11 -6
  41. package/dist/{cli-6rc5frdm.js → cli-crpf163n.js} +25 -18
  42. package/dist/{cli-1qkz151v.js → cli-dpsfwh7n.js} +13 -21
  43. package/dist/{cli-xzm9vcfg.js → cli-dtdht77h.js} +2 -2
  44. package/dist/{cli-a0z912j7.js → cli-e2w34h6z.js} +137 -62
  45. package/dist/{cli-eddnyg3t.js → cli-emekyyhr.js} +1 -1
  46. package/dist/{cli-d84byzn8.js → cli-f1kwb5fc.js} +109 -33
  47. package/dist/{cli-0jzra9ad.js → cli-gn9y6fn7.js} +2 -2
  48. package/dist/{cli-vdektqgf.js → cli-gpz1d0t2.js} +4 -4
  49. package/dist/{cli-rcecc3yq.js → cli-h9yy18gy.js} +84 -36
  50. package/dist/{cli-m5akxq8q.js → cli-j8cjdzan.js} +1 -1
  51. package/dist/{cli-m9s2qff2.js → cli-jg5txpm6.js} +187 -93
  52. package/dist/{cli-b98a65ed.js → cli-k2rw11py.js} +3 -3
  53. package/dist/{cli-3e875j5p.js → cli-k96cecs7.js} +276 -47
  54. package/dist/{cli-3vjhs18n.js → cli-kd56bmk4.js} +1 -1
  55. package/dist/{cli-3sy2xags.js → cli-kmemts3w.js} +12 -12
  56. package/dist/{cli-f6bahpn5.js → cli-knva3nmx.js} +2 -2
  57. package/dist/{cli-959kp5h2.js → cli-kw44j53p.js} +13 -13
  58. package/dist/{cli-bsywb58a.js → cli-mdpbjnzq.js} +10 -10
  59. package/dist/{cli-2kvhc7x8.js → cli-me0r8gzr.js} +35 -76
  60. package/dist/{cli-4vzgeta4.js → cli-mwwmka77.js} +14 -14
  61. package/dist/{cli-q24n86d2.js → cli-n5t077me.js} +2 -2
  62. package/dist/{cli-rvhdmjvt.js → cli-nx2n3z6p.js} +1 -1
  63. package/dist/{cli-28fq781p.js → cli-pe4d96rb.js} +1 -1
  64. package/dist/{cli-3rkdne1h.js → cli-pxwtcgcp.js} +2 -2
  65. package/dist/{cli-n6vtrcht.js → cli-qmqt520k.js} +2 -2
  66. package/dist/{cli-pchypa1s.js → cli-qps8je6j.js} +17 -2
  67. package/dist/{cli-97ae65rz.js → cli-rjvsf9qa.js} +5 -5
  68. package/dist/{cli-e1p3n5gq.js → cli-rqfvkx5t.js} +6 -6
  69. package/dist/{cli-3vmb0n58.js → cli-s7zz734a.js} +1 -1
  70. package/dist/{cli-rmzsadkf.js → cli-s8p8hhty.js} +2 -2
  71. package/dist/{cli-j24zbska.js → cli-sdvcrq5x.js} +5 -5
  72. package/dist/{cli-5y340nzn.js → cli-sg27rk2t.js} +5 -5
  73. package/dist/{cli-d6521kb5.js → cli-skmhsnqh.js} +1 -1
  74. package/dist/{cli-5mrq3ake.js → cli-t4dv07kr.js} +1 -1
  75. package/dist/{cli-z1w943va.js → cli-t5ys4ebm.js} +3 -3
  76. package/dist/{cli-f4r3g076.js → cli-tas6ckky.js} +2 -2
  77. package/dist/{cli-1pz0330a.js → cli-tf79ryyy.js} +1 -1
  78. package/dist/{cli-kc7v1nfv.js → cli-tnzebztn.js} +1 -1
  79. package/dist/{cli-pfs8adn4.js → cli-vx421edw.js} +3 -3
  80. package/dist/{cli-kchjb7qy.js → cli-x3ex5bqf.js} +1 -1
  81. package/dist/cli-yss07azk.js +142 -0
  82. package/dist/{cli-fwy8kfd6.js → cli-z8cvws4c.js} +98 -16
  83. package/dist/{cli-g5mtmf6t.js → cli-zdaypkq9.js} +146 -52
  84. package/dist/{cli-fpjmegdb.js → cli-zeaehgyd.js} +2 -2
  85. package/dist/{cli-837vfs2x.js → cli-ztq5z4e1.js} +4 -4
  86. package/dist/cli.js +20 -20
  87. package/dist/{codex-adapter-zerf5qsp.js → codex-adapter-2brxx5ta.js} +7 -8
  88. package/dist/{codex-hook-30gyhzxe.js → codex-hook-c930c3ea.js} +1 -1
  89. package/dist/{codex-login-bcda78ge.js → codex-login-cbrs1h5w.js} +1 -1
  90. package/dist/{codex-session-runner-89s304py.js → codex-session-runner-y9anfj0r.js} +8 -9
  91. package/dist/{commands-jeh1b51j.js → commands-wn9q06qr.js} +3 -3
  92. package/dist/{controller-mctfbrse.js → controller-fw608czd.js} +4 -4
  93. package/dist/{controllers-connect-nxa1ddwn.js → controllers-connect-63j5rdcm.js} +20 -20
  94. package/dist/{cursor-adapter-qj8vehv6.js → cursor-adapter-6mb9jme8.js} +2 -2
  95. package/dist/{db-2dvay0es.js → db-0m6v5tq4.js} +3 -3
  96. package/dist/{db-b36qn6k3.js → db-y4wfrzbm.js} +4 -2
  97. package/dist/{devin-adapter-xedz98zv.js → devin-adapter-r0yx3gv8.js} +1 -1
  98. package/dist/{dispatcher-gndbta01.js → dispatcher-9tq2zzdj.js} +17 -17
  99. package/dist/{docker-866qpzt9.js → docker-j75atvpt.js} +2 -2
  100. package/dist/{dsh-adapter-f75sz821.js → dsh-adapter-t09sv4tq.js} +2 -2
  101. package/dist/{e2b-jbm7mj93.js → e2b-7s9dscap.js} +2 -2
  102. package/dist/{e2b-3gpc2n3w.js → e2b-a7vzs2vj.js} +2 -2
  103. package/dist/{easter-egg-3d-533knw22.js → easter-egg-3d-fbwvmwhe.js} +1 -1
  104. package/dist/{embedding-space-4p05vb2x.js → embedding-space-wh8de1t9.js} +6 -6
  105. package/dist/{embeddings-m6768mgh.js → embeddings-3hpbdtjr.js} +1 -1
  106. package/dist/{event-bus-e66gh7cc.js → event-bus-tr6h3gv8.js} +1 -1
  107. package/dist/{execute-b3mrb1mv.js → execute-4bdf8sdy.js} +1 -1
  108. package/dist/{external-channel-gjv3jne3.js → external-channel-ts2fwqh0.js} +2 -2
  109. package/dist/fx-adapter-1rnxnf56.js +17 -0
  110. package/dist/grok-adapter-efhmf1r8.js +17 -0
  111. package/dist/handlers-anrr3py9.js +32 -0
  112. package/dist/{heartbeat-a1tv60gt.js → heartbeat-2ze5fzpc.js} +20 -20
  113. package/dist/{hook-8h5dzcgq.js → hook-ca54yd4s.js} +5 -5
  114. package/dist/{hook-cyaps9ba.js → hook-gaehe2w5.js} +7 -7
  115. package/dist/{http-t15mhbd9.js → http-jfg8t2yk.js} +3861 -1798
  116. package/dist/{index-tvfafeyy.js → index-3gv6sc4z.js} +1 -1
  117. package/dist/{index-qav6455f.js → index-3yvzbhxd.js} +97 -22
  118. package/dist/index-8w2aznds.js +33 -0
  119. package/dist/{index-w1zqf680.js → index-csgrxedz.js} +1 -1
  120. package/dist/index-qnjvr362.js +37 -0
  121. package/dist/index-yzxd3sn9.js +32 -0
  122. package/dist/{keepalive-91s7hzrb.js → keepalive-k2a3qe73.js} +4 -4
  123. package/dist/lead-zhxqbfdv.js +69 -0
  124. package/dist/{maintenance-7pjmy5xy.js → maintenance-gb5sd5nc.js} +1 -1
  125. package/dist/{node-4c5jqxr3.js → node-7qsx5kvm.js} +1 -1
  126. package/dist/{oauth-refresh-sweep-rzqfm94j.js → oauth-refresh-sweep-y7rm6bkb.js} +3 -3
  127. package/dist/{onboard-74st7pag.js → onboard-jmc5qerv.js} +3 -3
  128. package/dist/{opencode-adapter-arn7gm8q.js → opencode-adapter-7eade9ev.js} +6 -7
  129. package/dist/{otel-impl-rnzey8cb.js → otel-impl-8j1xhxqd.js} +2 -2
  130. package/dist/{pi-mono-adapter-6mkwq64n.js → pi-mono-adapter-yqmaf32x.js} +13 -13
  131. package/dist/{pricing-refresh-ha21jhk7.js → pricing-refresh-1nj722h6.js} +2 -2
  132. package/dist/{rbac-roles-wqhma4dr.js → rbac-roles-b1mtr6dr.js} +3 -3
  133. package/dist/{rbac-roles-59dxachk.js → rbac-roles-n1f3frk1.js} +2 -2
  134. package/dist/{render-v2-14kpzx12.js → render-v2-1gfpd8rj.js} +4 -4
  135. package/dist/{resume-gsa5fb5f.js → resume-w1s1eh5v.js} +7 -7
  136. package/dist/{runtime-1hv06jsn.js → runtime-84g5egsc.js} +1 -1
  137. package/dist/{session-access-skm7bnp6.js → session-access-y6z1txk4.js} +4 -4
  138. package/dist/{session-source-backfill-pbqzbncv.js → session-source-backfill-gxxwfh12.js} +3 -3
  139. package/dist/{setup-5yermsem.js → setup-r91gstyk.js} +1 -1
  140. package/dist/{virtual-modules-gazyapte.js → virtual-modules-cgnj6kme.js} +3 -3
  141. package/dist/{work-objects-xj0ck0w4.js → work-objects-qcxzg61c.js} +20 -20
  142. package/dist/worker-7j2907g6.js +69 -0
  143. package/dist/{worker-follow-up-911xc0b8.js → worker-follow-up-y2d2h7km.js} +17 -17
  144. package/dist/{x-2fyrt5pp.js → x-qhxq2ama.js} +2 -2
  145. package/openapi.json +1214 -108
  146. package/package.json +3 -3
  147. package/src/be/db/tasks/read.ts +33 -0
  148. package/src/be/db.ts +32 -7
  149. package/src/be/migrations/289_automation_savings_daily.sql +47 -0
  150. package/src/be/migrations/291_task_slack_participants.sql +4 -0
  151. package/src/be/migrations/293_savings_component_links.sql +58 -0
  152. package/src/be/migrations/296_automation_savings_daily_read_index.sql +6 -0
  153. package/src/be/model-profile-check.ts +10 -2
  154. package/src/be/savings/compute.ts +511 -16
  155. package/src/be/savings/model.ts +282 -14
  156. package/src/be/savings/read.ts +1500 -0
  157. package/src/be/savings/rollup.ts +571 -0
  158. package/src/be/scripts/run-credential.ts +15 -3
  159. package/src/be/scripts/typecheck.ts +86 -4
  160. package/src/be/seed-scripts/catalog/dreaming-learnings.ts +10 -2
  161. package/src/be/seed-scripts/catalog/dreaming-memtax-create.ts +70 -4
  162. package/src/be/swarm-config-guard.ts +8 -0
  163. package/src/be/users.ts +29 -2
  164. package/src/commands/runner.ts +159 -41
  165. package/src/extensions/contract-types.generated.ts +1 -1
  166. package/src/http/index.ts +8 -1
  167. package/src/http/poll.ts +14 -1
  168. package/src/http/requested-by.ts +97 -1
  169. package/src/http/savings.ts +676 -190
  170. package/src/http/scripts.ts +26 -15
  171. package/src/http/tasks.ts +43 -5
  172. package/src/prompts/session-templates.ts +80 -3
  173. package/src/providers/acp-targets.ts +1 -1
  174. package/src/providers/amp-adapter.ts +1 -1
  175. package/src/providers/claude-adapter.ts +0 -20
  176. package/src/providers/claude-flag-settings.ts +12 -10
  177. package/src/providers/codex-adapter.ts +9 -34
  178. package/src/providers/opencode-adapter.ts +34 -12
  179. package/src/scheduler/scheduler.ts +20 -14
  180. package/src/scripts-runtime/ctx.ts +1 -1
  181. package/src/scripts-runtime/executors/quickjs-bundle.ts +1 -0
  182. package/src/scripts-runtime/executors/quickjs-prelude.ts +162 -2
  183. package/src/scripts-runtime/executors/quickjs-runner.ts +4 -1
  184. package/src/scripts-runtime/stdlib/fetch.ts +113 -15
  185. package/src/scripts-runtime/stdlib/index.ts +3 -1
  186. package/src/scripts-runtime/stdlib/retry.ts +174 -0
  187. package/src/scripts-runtime/swarm-sdk.ts +186 -17
  188. package/src/scripts-runtime/types/stdlib.d.ts +86 -4
  189. package/src/scripts-runtime/types/swarm-extension.d.ts +26 -0
  190. package/src/scripts-runtime/types/swarm-sdk.d.ts +60 -2
  191. package/src/slack/actions.ts +1 -0
  192. package/src/slack/assistant.ts +2 -0
  193. package/src/slack/enrich.ts +144 -50
  194. package/src/slack/handlers.ts +37 -95
  195. package/src/slack/templates.ts +9 -0
  196. package/src/slack/thread-buffer.ts +45 -71
  197. package/src/slack/thread-participants.ts +187 -0
  198. package/src/tests/base-prompt.test.ts +5 -4
  199. package/src/tests/claude-adapter-binary.test.ts +7 -1
  200. package/src/tests/claude-adapter.test.ts +10 -64
  201. package/src/tests/claude-flag-settings.test.ts +15 -11
  202. package/src/tests/claude-hook-credentials.test.ts +0 -1
  203. package/src/tests/claude-sdk-lifecycle.test.ts +5 -1
  204. package/src/tests/codex-adapter.test.ts +17 -78
  205. package/src/tests/create-task-vcs-repo.test.ts +136 -0
  206. package/src/tests/db-task-read-contract.test.ts +2 -0
  207. package/src/tests/db-task-write-contract.test.ts +1 -0
  208. package/src/tests/docs-index-footprint.test.js +3 -3
  209. package/src/tests/dreaming-learnings.test.ts +104 -0
  210. package/src/tests/extensions-pre-task.test.ts +4 -2
  211. package/src/tests/fetch-resolved-env.test.ts +47 -1
  212. package/src/tests/opencode-adapter.test.ts +53 -6
  213. package/src/tests/prompt-template-session.test.ts +17 -1
  214. package/src/tests/runner-requester-profile.test.ts +139 -1
  215. package/src/tests/savings-compound.test.ts +774 -0
  216. package/src/tests/savings-compute.test.ts +7 -198
  217. package/src/tests/savings-fleet-latency.test.ts +143 -0
  218. package/src/tests/savings-fleet-read.test.ts +195 -0
  219. package/src/tests/savings-fleet-scale.test.ts +222 -0
  220. package/src/tests/savings-model.test.ts +212 -0
  221. package/src/tests/savings-read.test.ts +367 -0
  222. package/src/tests/savings-rollup.test.ts +766 -0
  223. package/src/tests/savings-scripts.test.ts +611 -0
  224. package/src/tests/script-connections.test.ts +2 -0
  225. package/src/tests/script-executor-conformance.test.ts +444 -0
  226. package/src/tests/scripts-http.test.ts +55 -0
  227. package/src/tests/scripts-runtime-fetch.test.ts +2 -2
  228. package/src/tests/secret-rules.test.ts +124 -1
  229. package/src/tests/secret-scrubber.test.ts +1 -1
  230. package/src/tests/slack-dm-implicit-mention.test.ts +20 -1
  231. package/src/tests/slack-identity-resolution.test.ts +23 -0
  232. package/src/tests/slack-inbound-files.test.ts +2 -1
  233. package/src/tests/slack-thread-participants.test.ts +429 -0
  234. package/src/tests/tool-annotations.test.ts +30 -0
  235. package/src/types.ts +31 -0
  236. package/src/utils/mcp-server-fetcher.test.ts +89 -0
  237. package/src/utils/mcp-server-fetcher.ts +13 -5
  238. package/src/utils/request-auth-context.ts +24 -0
  239. package/src/utils/secret-rules.generated.ts +1 -1
  240. package/src/utils/secret-scrubber.ts +154 -29
  241. package/src/workflows/executors/swarm-script.ts +23 -19
  242. package/templates/skills/swarm-scripts/SKILL.md +5 -4
  243. package/templates/skills/swarm-scripts/content.md +5 -4
  244. package/templates/skills/work-on-task/SKILL.md +1 -1
  245. package/templates/skills/work-on-task/content.md +1 -1
  246. package/templates/workflows/dreaming/content.md +1 -1
  247. package/dist/acp-adapter-fqzkxyra.js +0 -15
  248. package/dist/cli-4bd1rck6.js +0 -4
  249. package/dist/cli-xf3qw745.js +0 -104
  250. package/dist/fx-adapter-rpsgb1tw.js +0 -18
  251. package/dist/grok-adapter-n2m3zjg1.js +0 -18
  252. package/dist/handlers-nv8edn19.js +0 -32
  253. package/dist/index-ksmyd6kc.js +0 -37
  254. package/dist/index-rjnrje98.js +0 -32
  255. package/dist/index-tv3413wy.js +0 -33
  256. package/dist/lead-3hmddvrm.js +0 -70
  257. package/dist/worker-qgg0m2gw.js +0 -70
  258. package/src/providers/ctx-mode-env.ts +0 -10
@@ -0,0 +1,187 @@
1
+ /**
2
+ * One read of a Slack thread for a new task: the `<thread_context>` block and
3
+ * the people in the thread with their trust level. Shared by the mention path
4
+ * (`handlers.ts`) and the follow-up buffer (`thread-buffer.ts`).
5
+ */
6
+
7
+ import type { WebClient } from "@slack/web-api";
8
+ import { getFirstTaskInThread } from "../be/db";
9
+ import { resolveTemplate } from "../prompts/resolver";
10
+ import type { SlackParticipantTrust, TaskSlackParticipant, TaskSlackParticipants } from "../types";
11
+ import {
12
+ getOurSlackTeamId,
13
+ resolveSlackParticipant,
14
+ rewriteSlackMentions,
15
+ type SlackParticipantResolution,
16
+ } from "./enrich";
17
+ import { extractSlackMessageText, type SlackMessageLike } from "./message-text";
18
+ import "./templates";
19
+
20
+ /** People listed in the prompt; the rest render as `<N more...>`. */
21
+ export const SLACK_PARTICIPANT_CAP = 10;
22
+ /** Messages kept in `<thread_context>`: the root plus the newest replies. */
23
+ const THREAD_CONTEXT_MESSAGES = 20;
24
+ // shortcut: one page of replies, so a thread past 200 messages loses its tail; page with the cursor when that matters.
25
+ const THREAD_FETCH_LIMIT = 200;
26
+
27
+ interface ThreadMessage extends SlackMessageLike {
28
+ ts?: string;
29
+ user?: string;
30
+ user_team?: string;
31
+ bot_id?: string;
32
+ subtype?: string;
33
+ }
34
+
35
+ /** One message of the batch that triggers the task, oldest first. */
36
+ export interface SlackSender {
37
+ userId: string;
38
+ text: string;
39
+ userTeam?: string;
40
+ }
41
+
42
+ export interface SlackThreadSnapshot {
43
+ /** The rendered `<thread_context>` block, or "" when there is no history. */
44
+ threadContext: string;
45
+ participants: TaskSlackParticipants;
46
+ trust: ReadonlyMap<string, SlackParticipantTrust>;
47
+ /** The newest sender: owns `requestedByUserId`. */
48
+ newest: SlackParticipantResolution;
49
+ }
50
+
51
+ /**
52
+ * `label: text` with every continuation line indented. Author labels start at
53
+ * column 0 and message lines never do, so a multi-line message cannot forge
54
+ * another person's `<@U…>: …` line.
55
+ */
56
+ export function formatAuthoredMessage(label: string, text: string): string {
57
+ return `${label}: ${text.split(/\r\n|[\n\r\u2028\u2029]/).join("\n ")}`;
58
+ }
59
+
60
+ export function isUntrusted(trust: SlackParticipantTrust | undefined): boolean {
61
+ return trust === "external" || trust === "unknown";
62
+ }
63
+
64
+ export async function buildSlackThreadSnapshot(
65
+ client: WebClient,
66
+ opts: {
67
+ channelId: string;
68
+ /** Absent for a top-level message. */
69
+ threadTs?: string;
70
+ /** Messages already in the task body (the batch itself). */
71
+ excludeTs: ReadonlySet<string>;
72
+ botUserId?: string;
73
+ senders: readonly SlackSender[];
74
+ sampleEventType: string;
75
+ },
76
+ ): Promise<SlackThreadSnapshot> {
77
+ const { botUserId, senders } = opts;
78
+ const newestSender = senders.at(-1);
79
+ if (!newestSender) throw new Error("buildSlackThreadSnapshot needs at least one sender");
80
+
81
+ let messages: ThreadMessage[] = [];
82
+ if (opts.threadTs) {
83
+ try {
84
+ const result = await client.conversations.replies({
85
+ channel: opts.channelId,
86
+ ts: opts.threadTs,
87
+ limit: THREAD_FETCH_LIMIT,
88
+ });
89
+ messages = (result.messages ?? []) as ThreadMessage[];
90
+ } catch (error) {
91
+ console.error("[Slack] Failed to fetch thread context:", error);
92
+ }
93
+ }
94
+ const isBot = (m: ThreadMessage) =>
95
+ m.user === botUserId || m.bot_id !== undefined || m.subtype === "bot_message";
96
+
97
+ // Latest message per human, newest first: the order of non-batch participants.
98
+ const latest = new Map<string, { text: string; userTeam?: string }>();
99
+ for (const m of [...messages].reverse()) {
100
+ if (!m.user || isBot(m) || latest.has(m.user)) continue;
101
+ latest.set(m.user, { text: extractSlackMessageText(m), userTeam: m.user_team });
102
+ }
103
+ for (const sender of senders) {
104
+ latest.set(sender.userId, { text: sender.text, userTeam: sender.userTeam });
105
+ }
106
+
107
+ const starterId = opts.threadTs
108
+ ? (await getFirstTaskInThread(opts.channelId, opts.threadTs))?.slackUserId
109
+ : undefined;
110
+ const askers = new Set(senders.map((sender) => sender.userId));
111
+ const ordered = [
112
+ ...new Set([
113
+ newestSender.userId,
114
+ ...(starterId ? [starterId] : []),
115
+ ...senders.map((sender) => sender.userId).reverse(),
116
+ ...latest.keys(),
117
+ ]),
118
+ ].filter((id) => id !== botUserId);
119
+ const listed = ordered.slice(0, SLACK_PARTICIPANT_CAP);
120
+
121
+ const ourTeamId = [...latest.values()].some((entry) => entry.userTeam)
122
+ ? await getOurSlackTeamId(client)
123
+ : undefined;
124
+ // shortcut: people past the cap are not resolved, so their trust is unknown to the "untrusted present" rule; resolve them too if the cap ever hides one.
125
+ const people: TaskSlackParticipant[] = await Promise.all(
126
+ listed.map(async (slackUserId) => {
127
+ const resolution = await resolveSlackParticipant(client, slackUserId, {
128
+ sampleEventType: opts.sampleEventType,
129
+ sampleContext: latest.get(slackUserId)?.text ?? "",
130
+ userTeam: latest.get(slackUserId)?.userTeam,
131
+ ourTeamId,
132
+ });
133
+ return {
134
+ slackUserId,
135
+ ...(resolution.userId && { userId: resolution.userId }),
136
+ trust: resolution.trust,
137
+ ...(slackUserId === starterId && { starter: true }),
138
+ ...(slackUserId === newestSender.userId && { newest: true }),
139
+ ...(askers.has(slackUserId) && { asked: true }),
140
+ };
141
+ }),
142
+ );
143
+ const trust = new Map(people.map((person) => [person.slackUserId, person.trust]));
144
+ const newestPerson = people[0];
145
+
146
+ return {
147
+ threadContext: await renderThreadContext(messages, opts.excludeTs, isBot, botUserId, trust),
148
+ participants: { people, more: ordered.length - listed.length },
149
+ trust,
150
+ newest: { userId: newestPerson?.userId, trust: newestPerson?.trust ?? "unknown" },
151
+ };
152
+ }
153
+
154
+ async function renderThreadContext(
155
+ messages: ThreadMessage[],
156
+ excludeTs: ReadonlySet<string>,
157
+ isBot: (m: ThreadMessage) => boolean,
158
+ botUserId: string | undefined,
159
+ trust: ReadonlyMap<string, SlackParticipantTrust>,
160
+ ): Promise<string> {
161
+ const previous = messages.filter(
162
+ (m) => !(m.ts && excludeTs.has(m.ts)) && extractSlackMessageText(m) !== "",
163
+ );
164
+ if (previous.length === 0) return "";
165
+ // conversations.replies is oldest first: keep the root and the newest replies.
166
+ const window =
167
+ previous.length > THREAD_CONTEXT_MESSAGES
168
+ ? [previous[0]!, ...previous.slice(-(THREAD_CONTEXT_MESSAGES - 1))]
169
+ : previous;
170
+
171
+ // Author identity comes from the identity primitive (resolved name or the
172
+ // UNKNOWN sentinel), never a raw Slack display name.
173
+ const lines = window.map((m) => {
174
+ const text = extractSlackMessageText(m);
175
+ if (isBot(m))
176
+ return formatAuthoredMessage(
177
+ "[Agent]",
178
+ text.length > 500 ? `${text.slice(0, 500)}...` : text,
179
+ );
180
+ return formatAuthoredMessage(m.user ? `<@${m.user}>` : "Unknown", text);
181
+ });
182
+ let body = await rewriteSlackMentions(lines.join("\n"), botUserId, trust);
183
+ if ([...trust.values()].some(isUntrusted)) {
184
+ body = `${resolveTemplate("slack.message.thread_context_untrusted", {}).text}\n${body}`;
185
+ }
186
+ return resolveTemplate("slack.message.thread_context", { thread_messages: body }).text;
187
+ }
@@ -1148,21 +1148,22 @@ describe("truncateRepoClaudeMd", () => {
1148
1148
  describe("getBasePrompt: size budget", () => {
1149
1149
  // Include task-output budget, exceptions, and the two citation-scoping lines (when to cite, when not to).
1150
1150
  // Keep tight role-specific ceilings to catch unrelated prompt growth.
1151
- test("a fresh claude worker stays under 5,750 characters", async () => {
1151
+ // +150 for the multi-person thread line in the communication block (~105 chars).
1152
+ test("a fresh claude worker stays under 5,900 characters", async () => {
1152
1153
  const result = await getBasePrompt({ ...minimalArgs, name: "Ada", traits: localTraits });
1153
- expect(result.length).toBeLessThan(5_750);
1154
+ expect(result.length).toBeLessThan(5_900);
1154
1155
  });
1155
1156
 
1156
1157
  // The lead ceiling includes the swarm-docs pointer (~190 chars), which renders
1157
1158
  // while the skill list is still unknown.
1158
- test("a fresh claude lead stays under 6,100 characters", async () => {
1159
+ test("a fresh claude lead stays under 6,250 characters", async () => {
1159
1160
  const result = await getBasePrompt({
1160
1161
  ...minimalArgs,
1161
1162
  role: "lead",
1162
1163
  name: "Cora",
1163
1164
  traits: localTraits,
1164
1165
  });
1165
- expect(result.length).toBeLessThan(6_100);
1166
+ expect(result.length).toBeLessThan(6_250);
1166
1167
  });
1167
1168
 
1168
1169
  test("Picateclas spawn-OOM hardening: the kitchen sink stays below MAX_ARG_STRLEN", async () => {
@@ -49,7 +49,11 @@ import {
49
49
  resolveClaudeBridgeEnabled,
50
50
  resolveClaudeTrustDirs,
51
51
  } from "../providers/claude-adapter";
52
- import { ClaudeSettingsConfigError, userClaudeMdExclude } from "../providers/claude-flag-settings";
52
+ import {
53
+ ClaudeSettingsConfigError,
54
+ LEGACY_CONTEXT_MODE_CLAUDE_PLUGIN,
55
+ userClaudeMdExclude,
56
+ } from "../providers/claude-flag-settings";
53
57
  import type { ProviderSessionConfig } from "../providers/types";
54
58
  import { setFlockForTests } from "../utils/file-lock";
55
59
  import { holdFileLock } from "./fixtures/hold-file-lock";
@@ -784,6 +788,7 @@ describe("CLAUDE_BINARY env override", () => {
784
788
  expect(at).toBeGreaterThan(0);
785
789
  expect(JSON.parse(argv[at + 1] ?? "")).toEqual({
786
790
  claudeMdExcludes: [WORKSPACE_CLAUDE_MD_PATH, userClaudeMdExclude()],
791
+ enabledPlugins: { [LEGACY_CONTEXT_MODE_CLAUDE_PLUGIN]: false },
787
792
  });
788
793
  });
789
794
 
@@ -826,6 +831,7 @@ describe("CLAUDE_BINARY env override", () => {
826
831
  "/other/CLAUDE.md",
827
832
  userClaudeMdExclude(),
828
833
  ],
834
+ enabledPlugins: { [LEGACY_CONTEXT_MODE_CLAUDE_PLUGIN]: false },
829
835
  });
830
836
  expect(argv[0]).toBe("claude");
831
837
  expect(argv.slice(argv.indexOf("--max-turns"), argv.indexOf("--max-turns") + 2)).toEqual([
@@ -830,23 +830,6 @@ describe("mergeMcpConfig (issue #369)", () => {
830
830
  const merged = mergeMcpConfig({ mcpServers: {} }, {}, TASK_ID);
831
831
  expect(Object.keys(merged.mcpServers)).toHaveLength(0);
832
832
  });
833
-
834
- test("preserves a context-mode entry through the merge", () => {
835
- const base = {
836
- mcpServers: {
837
- "agent-swarm": {
838
- type: "http",
839
- url: "http://localhost:3013/mcp",
840
- headers: { Authorization: "Bearer KEY", "X-Agent-ID": "a1" },
841
- },
842
- "plugin_context-mode_context-mode": { command: "context-mode" },
843
- },
844
- };
845
- const merged = mergeMcpConfig(base, null, TASK_ID);
846
- expect(merged.mcpServers["plugin_context-mode_context-mode"]).toEqual({
847
- command: "context-mode",
848
- });
849
- });
850
833
  });
851
834
 
852
835
  describe("createSessionMcpConfig", () => {
@@ -924,13 +907,7 @@ describe("createSessionMcpConfig", () => {
924
907
  const written = await readWritten(path!);
925
908
  expect(written.mcpServers["agent-swarm"]).toBeDefined();
926
909
  expect(written.mcpServers.Datadog).toBeDefined();
927
- // context-mode is injected by default (see CONTEXT_MODE_DISABLED gate); the
928
- // two differently-named .mcp.json servers still merge alongside it.
929
- expect(Object.keys(written.mcpServers).sort()).toEqual([
930
- "Datadog",
931
- "agent-swarm",
932
- "plugin_context-mode_context-mode",
933
- ]);
910
+ expect(Object.keys(written.mcpServers).sort()).toEqual(["Datadog", "agent-swarm"]);
934
911
  });
935
912
 
936
913
  test("ancestor wins over repo-local on agent-swarm key conflict", async () => {
@@ -1010,45 +987,16 @@ describe("createSessionMcpConfig", () => {
1010
987
  expect(written.mcpServers["from-api"]).toBeDefined();
1011
988
  });
1012
989
 
1013
- test("includes context-mode entry when CONTEXT_MODE_DISABLED is unset", async () => {
1014
- const prev = process.env.CONTEXT_MODE_DISABLED;
1015
- delete process.env.CONTEXT_MODE_DISABLED;
1016
- try {
1017
- await writeFile(
1018
- join(sandbox, ".mcp.json"),
1019
- JSON.stringify({
1020
- mcpServers: {
1021
- "agent-swarm": {
1022
- type: "http",
1023
- url: "http://swarm/mcp",
1024
- headers: { Authorization: "Bearer SWARM", "X-Agent-ID": "a1" },
1025
- },
1026
- },
1027
- }),
1028
- );
1029
- const cwd = join(sandbox, "repos", "foo");
1030
- await mkdir(cwd, { recursive: true });
1031
-
1032
- const path = await createSessionMcpConfig(cwd, "task-ctx-on");
1033
- const written = await readWritten(path!);
1034
- expect(written.mcpServers["plugin_context-mode_context-mode"]).toEqual({
1035
- command: "context-mode",
1036
- });
1037
- // Coexists with the swarm entry.
1038
- expect(written.mcpServers["agent-swarm"]).toBeDefined();
1039
- } finally {
1040
- if (prev === undefined) delete process.env.CONTEXT_MODE_DISABLED;
1041
- else process.env.CONTEXT_MODE_DISABLED = prev;
1042
- }
1043
- });
1044
-
990
+ // context-mode is removed. The deprecated CONTEXT_MODE_DISABLED flag is a
991
+ // no-op: no value adds the old `plugin_context-mode_context-mode` server.
1045
992
  test.each([
993
+ undefined,
1046
994
  "true",
1047
- "1",
1048
- "TRUE",
1049
- ])("excludes context-mode entry when CONTEXT_MODE_DISABLED='%s'", async (value) => {
995
+ "false",
996
+ ])("never injects a context-mode server (CONTEXT_MODE_DISABLED=%s)", async (value) => {
1050
997
  const prev = process.env.CONTEXT_MODE_DISABLED;
1051
- process.env.CONTEXT_MODE_DISABLED = value;
998
+ if (value === undefined) delete process.env.CONTEXT_MODE_DISABLED;
999
+ else process.env.CONTEXT_MODE_DISABLED = value;
1052
1000
  try {
1053
1001
  await writeFile(
1054
1002
  join(sandbox, ".mcp.json"),
@@ -1065,11 +1013,9 @@ describe("createSessionMcpConfig", () => {
1065
1013
  const cwd = join(sandbox, "repos", "foo");
1066
1014
  await mkdir(cwd, { recursive: true });
1067
1015
 
1068
- const path = await createSessionMcpConfig(cwd, "task-ctx-off");
1016
+ const path = await createSessionMcpConfig(cwd, "task-ctx-removed");
1069
1017
  const written = await readWritten(path!);
1070
- expect(written.mcpServers["plugin_context-mode_context-mode"]).toBeUndefined();
1071
- // The swarm entry is still present.
1072
- expect(written.mcpServers["agent-swarm"]).toBeDefined();
1018
+ expect(Object.keys(written.mcpServers)).toEqual(["agent-swarm"]);
1073
1019
  } finally {
1074
1020
  if (prev === undefined) delete process.env.CONTEXT_MODE_DISABLED;
1075
1021
  else process.env.CONTEXT_MODE_DISABLED = prev;
@@ -5,14 +5,16 @@ import { join } from "node:path";
5
5
  import {
6
6
  ClaudeSettingsConfigError,
7
7
  claudeFlagSettings,
8
+ LEGACY_CONTEXT_MODE_CLAUDE_PLUGIN,
8
9
  mergeClaudeSettingsArgs,
9
10
  userClaudeMdExclude,
10
11
  WORKSPACE_CLAUDE_MD_EXCLUDE,
11
12
  } from "../providers/claude-flag-settings";
12
13
 
13
14
  let directory: string;
14
- // Own CONTEXT_MODE_DISABLED: an ambient value would change every expectation.
15
+ // Own CONTEXT_MODE_DISABLED: the deprecated flag must not change any expectation.
15
16
  let prevContextModeDisabled: string | undefined;
17
+ const LEGACY_PLUGIN_OFF = { [LEGACY_CONTEXT_MODE_CLAUDE_PLUGIN]: false };
16
18
 
17
19
  beforeEach(async () => {
18
20
  directory = await mkdtemp(join(tmpdir(), "claude-flag-settings-"));
@@ -32,6 +34,7 @@ describe("mergeClaudeSettingsArgs", () => {
32
34
  expect(merged.argLists).toEqual([["--max-turns", "3"]]);
33
35
  expect(merged.settings).toEqual({
34
36
  claudeMdExcludes: [WORKSPACE_CLAUDE_MD_EXCLUDE, userClaudeMdExclude()],
37
+ enabledPlugins: LEGACY_PLUGIN_OFF,
35
38
  });
36
39
  });
37
40
 
@@ -60,6 +63,7 @@ describe("mergeClaudeSettingsArgs", () => {
60
63
  "/b/CLAUDE.md",
61
64
  userClaudeMdExclude(),
62
65
  ],
66
+ enabledPlugins: LEGACY_PLUGIN_OFF,
63
67
  });
64
68
  });
65
69
 
@@ -116,21 +120,22 @@ describe("mergeClaudeSettingsArgs", () => {
116
120
  model: "b",
117
121
  env: {},
118
122
  claudeMdExcludes: [WORKSPACE_CLAUDE_MD_EXCLUDE, userClaudeMdExclude()],
123
+ enabledPlugins: LEGACY_PLUGIN_OFF,
119
124
  });
120
125
  });
121
126
  });
122
127
 
123
- describe("CONTEXT_MODE_DISABLED", () => {
124
- // The plugin id the worker image installs.
128
+ describe("legacy context-mode plugin", () => {
129
+ // The plugin id older worker images installed (pinned literal, not the export).
125
130
  const CONTEXT_MODE_CLAUDE_PLUGIN = "context-mode@context-mode";
126
131
 
127
- test("unset: the context-mode plugin is left to the user settings", () => {
128
- expect(claudeFlagSettings().enabledPlugins).toBeUndefined();
129
- expect(mergeClaudeSettingsArgs([[]], directory).settings.enabledPlugins).toBeUndefined();
130
- });
131
-
132
- test.each(["true", "1"])("=%s turns the context-mode plugin off for the session", (value) => {
133
- process.env.CONTEXT_MODE_DISABLED = value;
132
+ test.each([
133
+ undefined,
134
+ "true",
135
+ "false",
136
+ ])("always turned off, whatever CONTEXT_MODE_DISABLED is (%s)", (value) => {
137
+ if (value === undefined) delete process.env.CONTEXT_MODE_DISABLED;
138
+ else process.env.CONTEXT_MODE_DISABLED = value;
134
139
  expect(claudeFlagSettings().enabledPlugins).toEqual({ [CONTEXT_MODE_CLAUDE_PLUGIN]: false });
135
140
  expect(mergeClaudeSettingsArgs([[]], directory).settings.enabledPlugins).toEqual({
136
141
  [CONTEXT_MODE_CLAUDE_PLUGIN]: false,
@@ -138,7 +143,6 @@ describe("CONTEXT_MODE_DISABLED", () => {
138
143
  });
139
144
 
140
145
  test("overrides a caller that enables the plugin and keeps the caller's other plugins", () => {
141
- process.env.CONTEXT_MODE_DISABLED = "true";
142
146
  const caller = { enabledPlugins: { [CONTEXT_MODE_CLAUDE_PLUGIN]: true, "other@market": true } };
143
147
  const merged = mergeClaudeSettingsArgs([["--settings", JSON.stringify(caller)]], directory);
144
148
  expect(merged.settings.enabledPlugins).toEqual({
@@ -58,7 +58,6 @@ for (const transport of ["cli", "sdk"] as const) {
58
58
  CLAUDE_TRANSPORT: transport,
59
59
  CLAUDE_QUEUE_STEERING: "1",
60
60
  CLAUDECODE: "",
61
- CONTEXT_MODE_DISABLED: "true",
62
61
  // Synthetic values ensure this probe cannot authenticate or incur model charges.
63
62
  CLAUDE_CODE_OAUTH_TOKEN: "example-synthetic-not-an-oauth-token",
64
63
  ANTHROPIC_API_KEY: "example-synthetic-not-an-api-key",
@@ -4,7 +4,10 @@ import { tmpdir } from "node:os";
4
4
  import { join } from "node:path";
5
5
  import { createSteeringDispatchState, pollAndDispatchSteering } from "../commands/runner";
6
6
  import { ClaudeAdapter, getTaskFilePath } from "../providers/claude-adapter";
7
- import { userClaudeMdExclude } from "../providers/claude-flag-settings";
7
+ import {
8
+ LEGACY_CONTEXT_MODE_CLAUDE_PLUGIN,
9
+ userClaudeMdExclude,
10
+ } from "../providers/claude-flag-settings";
8
11
  import type { ProviderEvent, ProviderSessionConfig } from "../providers/types";
9
12
  import type { SteeringMessage } from "../types";
10
13
  import { CHILD_PROCESS_TEST_BUDGET_MS, runChild } from "./test-proc";
@@ -413,6 +416,7 @@ describe("Claude SDK production adapter lifecycle", () => {
413
416
  "/workspace/CLAUDE.md",
414
417
  userClaudeMdExclude(),
415
418
  ],
419
+ enabledPlugins: { [LEGACY_CONTEXT_MODE_CLAUDE_PLUGIN]: false },
416
420
  });
417
421
  expect(argv).not.toContain(settingsFile);
418
422
  // The version probe carries the same merged settings value.
@@ -1623,21 +1623,9 @@ describe("computeCodexCostUsd", () => {
1623
1623
  describe("buildCodexConfig", () => {
1624
1624
  // Save and restore the global fetch so we don't leak mocks between tests.
1625
1625
  const originalFetch = globalThis.fetch;
1626
- // These tests assert the EXACT set of mcp_servers keys, which is only the
1627
- // installed-server merge logic. Disable the always-on context-mode entry so
1628
- // those exact-key assertions stay valid; a dedicated block below verifies
1629
- // the context-mode + features behavior. Save/restore the env to avoid leaks.
1630
- let prevContextModeDisabled: string | undefined;
1631
-
1632
- beforeEach(() => {
1633
- prevContextModeDisabled = process.env.CONTEXT_MODE_DISABLED;
1634
- process.env.CONTEXT_MODE_DISABLED = "true";
1635
- });
1636
1626
 
1637
1627
  afterEach(() => {
1638
1628
  globalThis.fetch = originalFetch;
1639
- if (prevContextModeDisabled === undefined) delete process.env.CONTEXT_MODE_DISABLED;
1640
- else process.env.CONTEXT_MODE_DISABLED = prevContextModeDisabled;
1641
1629
  });
1642
1630
 
1643
1631
  // Helper: build a ProviderSessionConfig pointed at a mock endpoint.
@@ -1937,12 +1925,12 @@ describe("buildCodexConfig", () => {
1937
1925
  });
1938
1926
  });
1939
1927
 
1940
- // ─── Phase 3: buildCodexConfig — context-mode MCP + hook feature flags ───────
1928
+ // ─── buildCodexConfig — removed context-mode + hook feature flags ────────────
1941
1929
 
1942
- describe("buildCodexConfig — context-mode + features", () => {
1930
+ describe("buildCodexConfig — legacy context-mode + features", () => {
1943
1931
  const originalFetch = globalThis.fetch;
1944
- // Explicitly own CONTEXT_MODE_DISABLED here. Save the ambient value up front
1945
- // and restore it after every test so we never leak the mutation to siblings.
1932
+ // Own CONTEXT_MODE_DISABLED: the deprecated flag must be a no-op. Restore
1933
+ // the ambient value after every test so we never leak the mutation.
1946
1934
  let prevContextModeDisabled: string | undefined;
1947
1935
 
1948
1936
  beforeEach(() => {
@@ -1980,49 +1968,22 @@ describe("buildCodexConfig — context-mode + features", () => {
1980
1968
  };
1981
1969
  }
1982
1970
 
1983
- test("includes the 'context-mode' mcp_servers entry by default", async () => {
1984
- delete process.env.CONTEXT_MODE_DISABLED;
1985
- globalThis.fetch = stubFetch({ servers: [], total: 0 });
1986
- const merged = await buildCodexConfig(cfg(), "gpt-5.4", () => {});
1987
- const mcp = merged.mcp_servers as Record<string, Record<string, unknown>>;
1988
-
1989
- expect(Object.keys(mcp).sort()).toEqual(["agent-swarm", "context-mode"]);
1990
- expect(mcp["context-mode"]?.command).toBe("context-mode");
1991
- expect(mcp["context-mode"]?.enabled).toBe(true);
1992
- expect(mcp["context-mode"]?.startup_timeout_sec).toBe(30);
1993
- expect(mcp["context-mode"]?.tool_timeout_sec).toBe(120);
1994
- });
1995
-
1971
+ // context-mode is removed: no value of the deprecated flag, from either env
1972
+ // source, adds its MCP server, and a stale install of the plugin (older
1973
+ // images) is always turned off so its own MCP server, skills and hooks
1974
+ // never load.
1996
1975
  test.each([
1997
- "true",
1998
- "1",
1999
- "TRUE",
2000
- ])("excludes the 'context-mode' entry when CONTEXT_MODE_DISABLED=%s", async (value) => {
2001
- process.env.CONTEXT_MODE_DISABLED = value;
2002
- globalThis.fetch = stubFetch({ servers: [], total: 0 });
2003
- const merged = await buildCodexConfig(cfg(), "gpt-5.4", () => {});
2004
- const mcp = merged.mcp_servers as Record<string, Record<string, unknown>>;
2005
-
2006
- expect(Object.keys(mcp)).toEqual(["agent-swarm"]);
2007
- expect(mcp["context-mode"]).toBeUndefined();
2008
- });
2009
-
2010
- test("CONTEXT_MODE_DISABLED also turns the installed context-mode plugin off", async () => {
2011
- process.env.CONTEXT_MODE_DISABLED = "true";
2012
- globalThis.fetch = stubFetch({ servers: [], total: 0 });
2013
- const merged = await buildCodexConfig(cfg(), "gpt-5.4", () => {});
2014
-
2015
- // The plugin registers its own MCP server, skills and hooks.
2016
- expect(merged.plugins).toEqual({ "context-mode@context-mode": { enabled: false } });
2017
- });
2018
-
2019
- // Production builds this config in the codex-session-runner subprocess,
2020
- // whose process.env lacks swarm config rows; they arrive via config.env.
2021
- test("honors CONTEXT_MODE_DISABLED from config.env when process.env lacks it", async () => {
2022
- delete process.env.CONTEXT_MODE_DISABLED;
1976
+ [undefined, undefined],
1977
+ ["true", undefined],
1978
+ ["false", undefined],
1979
+ [undefined, "true"],
1980
+ ["true", "false"],
1981
+ ])("CONTEXT_MODE_DISABLED process=%s config=%s is a no-op", async (procValue, envValue) => {
1982
+ if (procValue === undefined) delete process.env.CONTEXT_MODE_DISABLED;
1983
+ else process.env.CONTEXT_MODE_DISABLED = procValue;
2023
1984
  globalThis.fetch = stubFetch({ servers: [], total: 0 });
2024
1985
  const merged = await buildCodexConfig(
2025
- cfg({ env: { CONTEXT_MODE_DISABLED: "true" } }),
1986
+ cfg(envValue === undefined ? {} : { env: { CONTEXT_MODE_DISABLED: envValue } }),
2026
1987
  "gpt-5.4",
2027
1988
  () => {},
2028
1989
  );
@@ -2032,28 +1993,6 @@ describe("buildCodexConfig — context-mode + features", () => {
2032
1993
  expect(merged.plugins).toEqual({ "context-mode@context-mode": { enabled: false } });
2033
1994
  });
2034
1995
 
2035
- test("config.env CONTEXT_MODE_DISABLED=false overrides a process.env true", async () => {
2036
- process.env.CONTEXT_MODE_DISABLED = "true";
2037
- globalThis.fetch = stubFetch({ servers: [], total: 0 });
2038
- const merged = await buildCodexConfig(
2039
- cfg({ env: { CONTEXT_MODE_DISABLED: "false" } }),
2040
- "gpt-5.4",
2041
- () => {},
2042
- );
2043
- const mcp = merged.mcp_servers as Record<string, Record<string, unknown>>;
2044
-
2045
- expect(Object.keys(mcp).sort()).toEqual(["agent-swarm", "context-mode"]);
2046
- expect(merged.plugins).toBeUndefined();
2047
- });
2048
-
2049
- test("leaves the installed context-mode plugin alone by default", async () => {
2050
- delete process.env.CONTEXT_MODE_DISABLED;
2051
- globalThis.fetch = stubFetch({ servers: [], total: 0 });
2052
- const merged = await buildCodexConfig(cfg(), "gpt-5.4", () => {});
2053
-
2054
- expect(merged.plugins).toBeUndefined();
2055
- });
2056
-
2057
1996
  test("disables apps and enables hooks", async () => {
2058
1997
  delete process.env.CONTEXT_MODE_DISABLED;
2059
1998
  globalThis.fetch = stubFetch({ servers: [], total: 0 });