@desplega.ai/agent-swarm 2.5.2 → 2.5.4

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 (236) hide show
  1. package/dist/{acp-adapter-csh0zz3b.js → acp-adapter-ek38cwsv.js} +5 -5
  2. package/dist/{actions-6xx079d1.js → actions-92mepq03.js} +19 -19
  3. package/dist/{amp-adapter-8n6f0hz8.js → amp-adapter-9gaxg015.js} +4 -4
  4. package/dist/{app-ft6r6v23.js → app-ctn8gsgx.js} +3 -3
  5. package/dist/{assistant-vt2cyfzd.js → assistant-zyr5kz47.js} +21 -21
  6. package/dist/{boot-reembed-tgrfy27t.js → boot-reembed-dwzfttdr.js} +1 -1
  7. package/dist/{boot-reembed-r3e808ky.js → boot-reembed-w75maga2.js} +1 -1
  8. package/dist/{boot-scrub-sweep-masdwxkm.js → boot-scrub-sweep-e9kq43kf.js} +3 -3
  9. package/dist/{boot-seeds-0n82qc7q.js → boot-seeds-x28v3fhb.js} +4 -4
  10. package/dist/{claude-adapter-s7j47k06.js → claude-adapter-f0afqnne.js} +5 -5
  11. package/dist/{claude-managed-adapter-gt6pa35d.js → claude-managed-adapter-x81a7r65.js} +3 -3
  12. package/dist/{claude-managed-setup-3hzrgrnk.js → claude-managed-setup-bqzwjd9x.js} +2 -2
  13. package/dist/{claude-sdk-session-0zrdzyx2.js → claude-sdk-session-7b7whkaq.js} +9307 -9254
  14. package/dist/{cli-a5ebc95n.js → cli-0shx9j93.js} +16 -13
  15. package/dist/{cli-4qkg9968.js → cli-19202kew.js} +4 -4
  16. package/dist/{cli-cyfgxnvb.js → cli-1r5ad7j5.js} +19 -17
  17. package/dist/{cli-jmcjbjkt.js → cli-25n3mv5d.js} +9 -7
  18. package/dist/cli-2655k16q.js +140 -0
  19. package/dist/{cli-wadzapwb.js → cli-277c31dw.js} +1 -1
  20. package/dist/{cli-n6kmqngw.js → cli-4b2z6n0m.js} +29 -7
  21. package/dist/{cli-7ccf7akh.js → cli-5bnsc0e1.js} +9 -7
  22. package/dist/{cli-qrjv7t18.js → cli-621ce7kw.js} +1 -1
  23. package/dist/{cli-xzge46sj.js → cli-64mh9mf3.js} +20 -6
  24. package/dist/{cli-b6tnjdvx.js → cli-6a1xg1p7.js} +6 -2
  25. package/dist/{cli-ydg6ep51.js → cli-6n8axjv1.js} +1 -1
  26. package/dist/{cli-e91vshb1.js → cli-7p4jxgtt.js} +5 -5
  27. package/dist/{cli-f3pfn4x3.js → cli-9j129brq.js} +9 -3
  28. package/dist/{cli-xw9q173h.js → cli-9s05422w.js} +1 -1
  29. package/dist/{cli-15xd0j7w.js → cli-abs8ndtr.js} +12 -12
  30. package/dist/{cli-h5d22pfs.js → cli-asq5ydm4.js} +219 -309
  31. package/dist/{cli-w9etnnxk.js → cli-bf8ma3f1.js} +120 -50
  32. package/dist/{cli-0vgy5wfw.js → cli-bvpgr9ny.js} +2 -2
  33. package/dist/{cli-3e9vs93g.js → cli-c61mbdds.js} +4 -4
  34. package/dist/{cli-e5bxnjps.js → cli-c952c7ac.js} +5 -5
  35. package/dist/{cli-p859hcc8.js → cli-dew6x255.js} +1 -1
  36. package/dist/{cli-tx00c0h6.js → cli-dqygeeh5.js} +17 -1
  37. package/dist/{cli-gpv60278.js → cli-e42vss7b.js} +2 -2
  38. package/dist/{cli-b63d08rs.js → cli-eftzyh9y.js} +1 -1
  39. package/dist/{cli-fgn7yg5r.js → cli-ethgy7ha.js} +1 -1
  40. package/dist/{cli-86zpfje5.js → cli-ff1tm9n9.js} +1 -1
  41. package/dist/{cli-cf63dnxj.js → cli-g9vd9ece.js} +37 -12
  42. package/dist/{cli-j3dwd4kz.js → cli-gbfxp48k.js} +770 -126
  43. package/dist/{cli-n2918sed.js → cli-gn5af0x5.js} +21 -21
  44. package/dist/{cli-d172svcw.js → cli-gwhjmh8g.js} +4 -4
  45. package/dist/{cli-stxdrqs2.js → cli-hh5we352.js} +24 -5
  46. package/dist/{cli-0ebey9hg.js → cli-j6rktc91.js} +1 -1
  47. package/dist/{cli-csh8fnbg.js → cli-jb30dzvk.js} +473 -58
  48. package/dist/{cli-vaxw3bg0.js → cli-jbnn4vxb.js} +3 -3
  49. package/dist/{cli-ha22h0eg.js → cli-k4tjsdx9.js} +45 -40
  50. package/dist/{cli-f55b6ky0.js → cli-m4ecdxvz.js} +40 -13
  51. package/dist/{cli-mntxtkhn.js → cli-mz9afxxf.js} +2 -1
  52. package/dist/{cli-ta8bd7th.js → cli-pzatvw94.js} +1 -1
  53. package/dist/{cli-3qv8naq8.js → cli-rr7zx19j.js} +1591 -353
  54. package/dist/{cli-b1tv22wr.js → cli-s682zgqz.js} +1 -1
  55. package/dist/{cli-bpbcpd8b.js → cli-sbwsxvtd.js} +1 -1
  56. package/dist/{cli-0xk505e8.js → cli-sxgtf5fw.js} +1 -1
  57. package/dist/{cli-6y43v79h.js → cli-tsma7p8v.js} +1 -1
  58. package/dist/{cli-edtm741g.js → cli-wghjkr0e.js} +5 -5
  59. package/dist/{cli-aaqnqpyw.js → cli-wx2nj19m.js} +30 -11
  60. package/dist/{cli-y3dzwyy3.js → cli-x0f2v69c.js} +180 -60
  61. package/dist/{cli-kcnwn85g.js → cli-xtrz6bzs.js} +7 -7
  62. package/dist/{cli-14v1sxxy.js → cli-xzfq4at3.js} +7 -7
  63. package/dist/cli.js +20 -20
  64. package/dist/{codex-adapter-brh2tcxr.js → codex-adapter-wch12q99.js} +3 -3
  65. package/dist/{codex-hook-e2he7aca.js → codex-hook-brpnycn5.js} +1 -1
  66. package/dist/{codex-session-runner-0dnj21qs.js → codex-session-runner-41pfcr95.js} +2 -2
  67. package/dist/{commands-1cnvseqx.js → commands-9849dkj6.js} +2 -2
  68. package/dist/{controller-kc7s9xhn.js → controller-ja0sd95p.js} +29 -3
  69. package/dist/{controllers-connect-jzx7t4bn.js → controllers-connect-xp05dj6x.js} +20 -20
  70. package/dist/{cursor-adapter-qpwp5sfg.js → cursor-adapter-623qxqew.js} +1 -2
  71. package/dist/{db-4vq88jkc.js → db-47vj40dy.js} +3 -3
  72. package/dist/{db-v5ytg5pw.js → db-w759qmx0.js} +2 -2
  73. package/dist/{dispatcher-trtcrqae.js → dispatcher-7b8e4z2j.js} +17 -17
  74. package/dist/{docker-nfy2gc8t.js → docker-s84hjs91.js} +2 -2
  75. package/dist/{dsh-adapter-f20xwn1z.js → dsh-adapter-2ezw3xea.js} +2 -3
  76. package/dist/{external-channel-n9bymc2n.js → external-channel-e2s028da.js} +2 -2
  77. package/dist/{grok-adapter-4kpmmnr6.js → grok-adapter-ys7gaqee.js} +6 -6
  78. package/dist/{handlers-ptsraqa8.js → handlers-wy1dr6ja.js} +20 -20
  79. package/dist/{heartbeat-60qtxtjf.js → heartbeat-w3mntghj.js} +20 -20
  80. package/dist/{hook-rbktcstg.js → hook-3jjywnpb.js} +9 -3
  81. package/dist/{hook-ngtvh729.js → hook-g7kvv6x9.js} +3 -2
  82. package/dist/{http-z8xy72gp.js → http-tkp7d4kb.js} +2984 -2483
  83. package/dist/{index-r70q0xjx.js → index-1ef1myq2.js} +17 -17
  84. package/dist/{index-a9nsavhx.js → index-3n8m9ea2.js} +1 -1
  85. package/dist/{index-cbxkmfc5.js → index-9pn1pfkf.js} +1 -1
  86. package/dist/{index-s193j5fh.js → index-nmm79qgr.js} +20 -20
  87. package/dist/{index-6srwvd5b.js → index-p4xfz37z.js} +1 -1
  88. package/dist/{index-06qkmcx6.js → index-q7m26kvs.js} +33 -23
  89. package/dist/{index-1cscynkb.js → index-xdaahthb.js} +17 -17
  90. package/dist/{keepalive-a9srcphj.js → keepalive-v4ta8wgg.js} +3 -3
  91. package/dist/{lead-3devneqy.js → lead-sawnyqxk.js} +35 -35
  92. package/dist/{maintenance-0er16h2y.js → maintenance-84n1ex21.js} +1 -1
  93. package/dist/{oauth-refresh-sweep-b65jcyw2.js → oauth-refresh-sweep-vjnnandw.js} +2 -2
  94. package/dist/{onboard-wqywz5py.js → onboard-sfmpe4np.js} +2 -2
  95. package/dist/{opencode-adapter-e56086m1.js → opencode-adapter-jmpst4q4.js} +4 -4
  96. package/dist/{otel-impl-vk32s884.js → otel-impl-v6cc0zve.js} +1 -1
  97. package/dist/{pi-mono-adapter-tzps8f38.js → pi-mono-adapter-fk8fkcf6.js} +33 -6
  98. package/dist/{pricing-refresh-t27anv4z.js → pricing-refresh-fsk1e1zc.js} +3 -3
  99. package/dist/{rbac-roles-452665y0.js → rbac-roles-prmkdnkw.js} +2 -2
  100. package/dist/{rbac-roles-bmcgsxjn.js → rbac-roles-zxmxqa39.js} +1 -1
  101. package/dist/{render-v2-0ttsk2j4.js → render-v2-pjwxvnkw.js} +3 -3
  102. package/dist/{resume-a26kvr41.js → resume-frdtgfa0.js} +9 -5
  103. package/dist/{session-access-dgh9nkwk.js → session-access-fpez4y5q.js} +4 -4
  104. package/dist/{setup-9vc9qahm.js → setup-mq6m3m8q.js} +1 -1
  105. package/dist/{work-objects-vn8nkxwn.js → work-objects-kfahhjsq.js} +20 -20
  106. package/dist/{worker-1x1h8vnm.js → worker-v5e5rxj3.js} +35 -35
  107. package/openapi.json +3078 -2424
  108. package/package.json +7 -7
  109. package/plugin/commands/create-pr.md +2 -2
  110. package/plugin/pi-skills/create-pr/SKILL.md +2 -2
  111. package/src/be/approval-config-question.ts +389 -0
  112. package/src/be/automation-preflight.ts +37 -3
  113. package/src/be/db/approvals.ts +48 -0
  114. package/src/be/db/session-tree.ts +73 -15
  115. package/src/be/db/skill-search.ts +87 -0
  116. package/src/be/db/tasks/read.ts +29 -2
  117. package/src/be/db/tasks/write.ts +15 -5
  118. package/src/be/db/workflow-idempotency.ts +183 -0
  119. package/src/be/db/workflow-runs.ts +366 -8
  120. package/src/be/db.ts +92 -22
  121. package/src/be/migrations/239_skills_fts.sql +40 -0
  122. package/src/be/migrations/240_workflow_run_parent_step_attempt.sql +37 -0
  123. package/src/be/migrations/241_skills_meta_fts.sql +39 -0
  124. package/src/be/migrations/242_workflow_idempotency_keys.sql +40 -0
  125. package/src/be/sealed-json.ts +1 -0
  126. package/src/be/seed-scripts/catalog/compound-insights.inline.ts +2 -2
  127. package/src/be/seed-scripts/catalog/compound-insights.ts +2 -2
  128. package/src/be/seed-skills/bundled-files.generated.json +1 -1
  129. package/src/be/sql-connections.ts +7 -1
  130. package/src/be/swarm-config-guard.ts +25 -0
  131. package/src/be/users.ts +9 -0
  132. package/src/commands/controller.ts +33 -0
  133. package/src/commands/runner.ts +6 -2
  134. package/src/extensions/apply-task-create.ts +57 -11
  135. package/src/extensions/catalog.generated.json +4 -4
  136. package/src/extensions/contract-types.generated.ts +1 -1
  137. package/src/extensions/contract.ts +25 -0
  138. package/src/extensions/dispatcher.ts +4 -0
  139. package/src/extensions/post-bridge.ts +8 -0
  140. package/src/hooks/context-bound-note.ts +196 -0
  141. package/src/hooks/hook.ts +12 -0
  142. package/src/http/approval-requests.ts +209 -38
  143. package/src/http/config.ts +70 -53
  144. package/src/http/idempotency-key.ts +117 -0
  145. package/src/http/sessions.ts +27 -2
  146. package/src/http/workflows.ts +129 -24
  147. package/src/integrations/chat-sdk/inbound.ts +5 -4
  148. package/src/prompts/context-bound-note.ts +48 -0
  149. package/src/prompts/session-templates.ts +25 -1
  150. package/src/providers/amp-adapter.ts +30 -8
  151. package/src/providers/claude-adapter.ts +29 -4
  152. package/src/providers/claude-managed-adapter.ts +26 -0
  153. package/src/providers/claude-sdk-session.ts +10 -0
  154. package/src/providers/claude-session-events.ts +13 -0
  155. package/src/providers/codex-adapter.ts +12 -0
  156. package/src/providers/dsh-adapter.ts +1 -1
  157. package/src/providers/opencode-adapter.ts +18 -0
  158. package/src/providers/pi-mono-adapter.ts +35 -0
  159. package/src/runtime-providers/docker.ts +6 -2
  160. package/src/scripts-runtime/types/swarm-extension.d.ts +35 -0
  161. package/src/tests/amp-adapter.test.ts +97 -0
  162. package/src/tests/approval-config-question.test.ts +702 -0
  163. package/src/tests/approval-requests.test.ts +10 -7
  164. package/src/tests/approval-sweeps.test.ts +12 -6
  165. package/src/tests/base-prompt.test.ts +1 -1
  166. package/src/tests/chat-sdk-inbound.test.ts +20 -0
  167. package/src/tests/claude-hook-output.test.ts +79 -1
  168. package/src/tests/claude-managed-adapter.test.ts +275 -0
  169. package/src/tests/codex-adapter.test.ts +163 -0
  170. package/src/tests/context-bound-note.test.ts +269 -0
  171. package/src/tests/dsh-adapter.test.ts +1 -1
  172. package/src/tests/entrypoint-gitlab-credential-helper.test.ts +273 -0
  173. package/src/tests/extensions-example-comms-adherence-gate.test.ts +321 -12
  174. package/src/tests/extensions-pre-task.test.ts +273 -0
  175. package/src/tests/fetch-resolved-env.test.ts +17 -0
  176. package/src/tests/fixtures/extensions/record-blocks/hooks.ts +10 -0
  177. package/src/tests/fixtures/extensions/record-blocks/manifest.json +7 -0
  178. package/src/tests/fixtures/fake-amp.ts +22 -8
  179. package/src/tests/fixtures/held-template-render.ts +42 -0
  180. package/src/tests/fixtures/workflow-idempotency-trigger.child.ts +73 -0
  181. package/src/tests/list-endpoint-slimming.test.ts +33 -0
  182. package/src/tests/migration-240-workflow-run-parent-step-attempt.test.ts +55 -0
  183. package/src/tests/openapi-route-headers.test.ts +2 -0
  184. package/src/tests/opencode-adapter.test.ts +134 -0
  185. package/src/tests/pi-mono-adapter.test.ts +105 -0
  186. package/src/tests/prompt-template-session.test.ts +4 -3
  187. package/src/tests/runner-push-delivery.test.ts +25 -0
  188. package/src/tests/runtime-controller-liveness.test.ts +133 -0
  189. package/src/tests/runtime-providers-docker.test.ts +2 -0
  190. package/src/tests/script-connections.test.ts +9 -0
  191. package/src/tests/script-run-config-scope.test.ts +91 -3
  192. package/src/tests/session-logs.test.ts +70 -0
  193. package/src/tests/sessions-tree.test.ts +205 -1
  194. package/src/tests/skill-search-long-content.test.ts +193 -0
  195. package/src/tests/skill-search.test.ts +173 -22
  196. package/src/tests/workflow-cascade-cancel.test.ts +1169 -0
  197. package/src/tests/workflow-foreach-supersede-retry.test.ts +488 -0
  198. package/src/tests/workflow-idempotency.test.ts +915 -0
  199. package/src/tests/workflow-sub-workflow.test.ts +538 -1
  200. package/src/tools/request-human-input.ts +27 -5
  201. package/src/tools/workflows/cancel-workflow-run.ts +1 -1
  202. package/src/types.ts +7 -0
  203. package/src/utils/context-window.ts +8 -6
  204. package/src/workflows/approval-cancel.ts +15 -13
  205. package/src/workflows/approval-notifications.ts +15 -4
  206. package/src/workflows/checkpoint.ts +72 -35
  207. package/src/workflows/engine.ts +262 -93
  208. package/src/workflows/executors/base.ts +6 -0
  209. package/src/workflows/executors/foreach.ts +2 -2
  210. package/src/workflows/executors/human-in-the-loop.ts +25 -1
  211. package/src/workflows/executors/sub-workflow.ts +45 -16
  212. package/src/workflows/foreach-driver.ts +10 -3
  213. package/src/workflows/foreach-join.ts +29 -6
  214. package/src/workflows/recovery.ts +68 -1
  215. package/src/workflows/resume.ts +228 -77
  216. package/src/workflows/retry-poller.ts +74 -7
  217. package/src/workflows/task-step-routing.ts +29 -7
  218. package/templates/ai-toolbox.manifest.json +8 -8
  219. package/templates/community/open-prompt-showreel/PLAYBOOK.md +5 -6
  220. package/templates/community/open-prompt-showreel/lead-prompt.md +1 -1
  221. package/templates/community/open-prompt-showreel/skills/open-prompt-showreel/SKILL.md +4 -4
  222. package/templates/extensions/comms-adherence-gate/README.md +38 -13
  223. package/templates/extensions/comms-adherence-gate/hooks.ts +272 -69
  224. package/templates/extensions/comms-adherence-gate/manifest.json +2 -2
  225. package/templates/skills/agent-browser/SKILL.md +4 -4
  226. package/templates/skills/agent-browser/content.md +4 -4
  227. package/templates/skills/code-quality/config.json +1 -1
  228. package/templates/skills/code-quality/content.md +2 -2
  229. package/templates/skills/delegate-work/content.md +29 -25
  230. package/templates/skills/delegate-work/files/scripts/codex-exec.sh +5 -5
  231. package/templates/skills/qa/content.md +2 -2
  232. package/templates/skills/researching/content.md +2 -0
  233. package/templates/skills/turso-interaction/content.md +1 -1
  234. package/templates/skills/work-on-task/SKILL.md +1 -1
  235. package/templates/skills/work-on-task/content.md +1 -1
  236. package/templates/skills/workflow-iterate/content.md +8 -1
@@ -349,46 +349,124 @@ class ParseError extends Error {
349
349
  super(message), this.name = "ParseError", this.type = options.type, this.field = options.field, this.value = options.value, this.line = options.line;
350
350
  }
351
351
  }
352
+ var LF = 10;
353
+ var CR = 13;
354
+ var SPACE = 32;
352
355
  function noop(_arg) {}
353
- function createParser(callbacks) {
354
- if (typeof callbacks == "function")
355
- throw new TypeError("`callbacks` must be an object, got a function instead. Did you mean `{onEvent: fn}`?");
356
- const { onEvent = noop, onError = noop, onRetry = noop, onComment } = callbacks;
357
- let incompleteLine = "", isFirstChunk = true, id, data = "", eventType = "";
358
- function feed(newChunk) {
359
- const chunk = isFirstChunk ? newChunk.replace(/^\xEF\xBB\xBF/, "") : newChunk, [complete, incomplete] = splitLines(`${incompleteLine}${chunk}`);
360
- for (const line of complete)
361
- parseLine(line);
362
- incompleteLine = incomplete, isFirstChunk = false;
363
- }
364
- function parseLine(line) {
365
- if (line === "") {
356
+ function createParser(config) {
357
+ if (typeof config == "function")
358
+ throw new TypeError("`config` must be an object, got a function instead. Did you mean `createParser({onEvent: fn})`?");
359
+ const { onEvent = noop, onError = noop, onRetry = noop, onComment, maxBufferSize } = config, pendingFragments = [];
360
+ let pendingFragmentsLength = 0, isFirstChunk = true, id, data = "", dataLines = 0, eventType, terminated = false;
361
+ function feed(chunk) {
362
+ if (terminated)
363
+ throw new Error("Cannot feed parser: it was terminated after exceeding the configured max buffer size. Call `reset()` to resume parsing.");
364
+ if (isFirstChunk && (isFirstChunk = false, chunk.charCodeAt(0) === 239 && chunk.charCodeAt(1) === 187 && chunk.charCodeAt(2) === 191 && (chunk = chunk.slice(3))), pendingFragments.length === 0) {
365
+ const trailing2 = processLines(chunk);
366
+ trailing2 !== "" && (pendingFragments.push(trailing2), pendingFragmentsLength = trailing2.length), checkBufferSize();
367
+ return;
368
+ }
369
+ if (chunk.indexOf(`
370
+ `) === -1 && chunk.indexOf("\r") === -1) {
371
+ pendingFragments.push(chunk), pendingFragmentsLength += chunk.length, checkBufferSize();
372
+ return;
373
+ }
374
+ pendingFragments.push(chunk);
375
+ const input = pendingFragments.join("");
376
+ pendingFragments.length = 0, pendingFragmentsLength = 0;
377
+ const trailing = processLines(input);
378
+ trailing !== "" && (pendingFragments.push(trailing), pendingFragmentsLength = trailing.length), checkBufferSize();
379
+ }
380
+ function checkBufferSize() {
381
+ maxBufferSize !== undefined && (pendingFragmentsLength + data.length <= maxBufferSize || (terminated = true, pendingFragments.length = 0, pendingFragmentsLength = 0, id = undefined, data = "", dataLines = 0, eventType = undefined, onError(new ParseError(`Buffered data exceeded max buffer size of ${maxBufferSize} characters`, {
382
+ type: "max-buffer-size-exceeded"
383
+ }))));
384
+ }
385
+ function processLines(chunk) {
386
+ let searchIndex = 0;
387
+ if (chunk.indexOf("\r") === -1) {
388
+ let lfIndex = chunk.indexOf(`
389
+ `, searchIndex);
390
+ for (;lfIndex !== -1; ) {
391
+ if (searchIndex === lfIndex) {
392
+ dataLines > 0 && onEvent({ id, event: eventType, data }), id = undefined, data = "", dataLines = 0, eventType = undefined, searchIndex = lfIndex + 1, lfIndex = chunk.indexOf(`
393
+ `, searchIndex);
394
+ continue;
395
+ }
396
+ const firstCharCode = chunk.charCodeAt(searchIndex);
397
+ if (isDataPrefix(chunk, searchIndex, firstCharCode)) {
398
+ const valueStart = chunk.charCodeAt(searchIndex + 5) === SPACE ? searchIndex + 6 : searchIndex + 5, value = chunk.slice(valueStart, lfIndex);
399
+ if (dataLines === 0 && chunk.charCodeAt(lfIndex + 1) === LF) {
400
+ onEvent({ id, event: eventType, data: value }), id = undefined, data = "", eventType = undefined, searchIndex = lfIndex + 2, lfIndex = chunk.indexOf(`
401
+ `, searchIndex);
402
+ continue;
403
+ }
404
+ data = dataLines === 0 ? value : `${data}
405
+ ${value}`, dataLines++;
406
+ } else
407
+ isEventPrefix(chunk, searchIndex, firstCharCode) ? eventType = chunk.slice(chunk.charCodeAt(searchIndex + 6) === SPACE ? searchIndex + 7 : searchIndex + 6, lfIndex) || undefined : parseLine(chunk, searchIndex, lfIndex);
408
+ searchIndex = lfIndex + 1, lfIndex = chunk.indexOf(`
409
+ `, searchIndex);
410
+ }
411
+ return chunk.slice(searchIndex);
412
+ }
413
+ for (;searchIndex < chunk.length; ) {
414
+ const crIndex = chunk.indexOf("\r", searchIndex), lfIndex = chunk.indexOf(`
415
+ `, searchIndex);
416
+ let lineEnd = -1;
417
+ if (crIndex !== -1 && lfIndex !== -1 ? lineEnd = crIndex < lfIndex ? crIndex : lfIndex : crIndex !== -1 ? crIndex === chunk.length - 1 ? lineEnd = -1 : lineEnd = crIndex : lfIndex !== -1 && (lineEnd = lfIndex), lineEnd === -1)
418
+ break;
419
+ parseLine(chunk, searchIndex, lineEnd), searchIndex = lineEnd + 1, chunk.charCodeAt(searchIndex - 1) === CR && chunk.charCodeAt(searchIndex) === LF && searchIndex++;
420
+ }
421
+ return chunk.slice(searchIndex);
422
+ }
423
+ function parseLine(chunk, start, end) {
424
+ if (start === end) {
366
425
  dispatchEvent();
367
426
  return;
368
427
  }
369
- if (line.startsWith(":")) {
370
- onComment && onComment(line.slice(line.startsWith(": ") ? 2 : 1));
428
+ const firstCharCode = chunk.charCodeAt(start);
429
+ if (isDataPrefix(chunk, start, firstCharCode)) {
430
+ const valueStart = chunk.charCodeAt(start + 5) === SPACE ? start + 6 : start + 5, value2 = chunk.slice(valueStart, end);
431
+ data = dataLines === 0 ? value2 : `${data}
432
+ ${value2}`, dataLines++;
433
+ return;
434
+ }
435
+ if (isEventPrefix(chunk, start, firstCharCode)) {
436
+ eventType = chunk.slice(chunk.charCodeAt(start + 6) === SPACE ? start + 7 : start + 6, end) || undefined;
437
+ return;
438
+ }
439
+ if (firstCharCode === 105 && chunk.charCodeAt(start + 1) === 100 && chunk.charCodeAt(start + 2) === 58) {
440
+ const value2 = chunk.slice(chunk.charCodeAt(start + 3) === SPACE ? start + 4 : start + 3, end);
441
+ value2.includes("\x00") || (id = value2);
442
+ return;
443
+ }
444
+ if (firstCharCode === 58) {
445
+ if (onComment) {
446
+ const line2 = chunk.slice(start, end);
447
+ onComment(line2.slice(chunk.charCodeAt(start + 1) === SPACE ? 2 : 1));
448
+ }
371
449
  return;
372
450
  }
373
- const fieldSeparatorIndex = line.indexOf(":");
374
- if (fieldSeparatorIndex !== -1) {
375
- const field = line.slice(0, fieldSeparatorIndex), offset = line[fieldSeparatorIndex + 1] === " " ? 2 : 1, value = line.slice(fieldSeparatorIndex + offset);
376
- processField(field, value, line);
451
+ const line = chunk.slice(start, end), fieldSeparatorIndex = line.indexOf(":");
452
+ if (fieldSeparatorIndex === -1) {
453
+ processField(line, "", line);
377
454
  return;
378
455
  }
379
- processField(line, "", line);
456
+ const field = line.slice(0, fieldSeparatorIndex), offset = line.charCodeAt(fieldSeparatorIndex + 1) === SPACE ? 2 : 1, value = line.slice(fieldSeparatorIndex + offset);
457
+ processField(field, value, line);
380
458
  }
381
459
  function processField(field, value, line) {
382
460
  switch (field) {
383
461
  case "event":
384
- eventType = value;
462
+ eventType = value || undefined;
385
463
  break;
386
464
  case "data":
387
- data = `${data}${value}
388
- `;
465
+ data = dataLines === 0 ? value : `${data}
466
+ ${value}`, dataLines++;
389
467
  break;
390
468
  case "id":
391
- id = value.includes("\x00") ? undefined : value;
469
+ value.includes("\x00") || (id = value);
392
470
  break;
393
471
  case "retry":
394
472
  /^\d+$/.test(value) ? onRetry(parseInt(value, 10)) : onError(new ParseError(`Invalid \`retry\` value: "${value}"`, {
@@ -403,40 +481,31 @@ function createParser(callbacks) {
403
481
  }
404
482
  }
405
483
  function dispatchEvent() {
406
- data.length > 0 && onEvent({
484
+ dataLines > 0 && onEvent({
407
485
  id,
408
- event: eventType || undefined,
409
- data: data.endsWith(`
410
- `) ? data.slice(0, -1) : data
411
- }), id = undefined, data = "", eventType = "";
486
+ event: eventType,
487
+ data
488
+ }), id = undefined, data = "", dataLines = 0, eventType = undefined;
412
489
  }
413
490
  function reset(options = {}) {
414
- incompleteLine && options.consume && parseLine(incompleteLine), isFirstChunk = true, id = undefined, data = "", eventType = "", incompleteLine = "";
491
+ if (options.consume && pendingFragments.length > 0) {
492
+ const incompleteLine = pendingFragments.join("");
493
+ parseLine(incompleteLine, 0, incompleteLine.length);
494
+ }
495
+ isFirstChunk = true, id = undefined, data = "", dataLines = 0, eventType = undefined, pendingFragments.length = 0, pendingFragmentsLength = 0, terminated = false;
415
496
  }
416
497
  return { feed, reset };
417
498
  }
418
- function splitLines(chunk) {
419
- const lines = [];
420
- let incompleteLine = "", searchIndex = 0;
421
- for (;searchIndex < chunk.length; ) {
422
- const crIndex = chunk.indexOf("\r", searchIndex), lfIndex = chunk.indexOf(`
423
- `, searchIndex);
424
- let lineEnd = -1;
425
- if (crIndex !== -1 && lfIndex !== -1 ? lineEnd = Math.min(crIndex, lfIndex) : crIndex !== -1 ? crIndex === chunk.length - 1 ? lineEnd = -1 : lineEnd = crIndex : lfIndex !== -1 && (lineEnd = lfIndex), lineEnd === -1) {
426
- incompleteLine = chunk.slice(searchIndex);
427
- break;
428
- } else {
429
- const line = chunk.slice(searchIndex, lineEnd);
430
- lines.push(line), searchIndex = lineEnd + 1, chunk[searchIndex - 1] === "\r" && chunk[searchIndex] === `
431
- ` && searchIndex++;
432
- }
433
- }
434
- return [lines, incompleteLine];
499
+ function isDataPrefix(chunk, i, firstCharCode) {
500
+ return firstCharCode === 100 && chunk.charCodeAt(i + 1) === 97 && chunk.charCodeAt(i + 2) === 116 && chunk.charCodeAt(i + 3) === 97 && chunk.charCodeAt(i + 4) === 58;
501
+ }
502
+ function isEventPrefix(chunk, i, firstCharCode) {
503
+ return firstCharCode === 101 && chunk.charCodeAt(i + 1) === 118 && chunk.charCodeAt(i + 2) === 101 && chunk.charCodeAt(i + 3) === 110 && chunk.charCodeAt(i + 4) === 116 && chunk.charCodeAt(i + 5) === 58;
435
504
  }
436
505
 
437
506
  // node_modules/eventsource-parser/dist/stream.js
438
507
  class EventSourceParserStream extends TransformStream {
439
- constructor({ onError, onRetry, onComment } = {}) {
508
+ constructor({ onError, onRetry, onComment, maxBufferSize } = {}) {
440
509
  let parser;
441
510
  super({
442
511
  start(controller) {
@@ -445,10 +514,11 @@ class EventSourceParserStream extends TransformStream {
445
514
  controller.enqueue(event);
446
515
  },
447
516
  onError(error) {
448
- onError === "terminate" ? controller.error(error) : typeof onError == "function" && onError(error);
517
+ typeof onError == "function" && onError(error), (onError === "terminate" || error.type === "max-buffer-size-exceeded") && controller.error(error);
449
518
  },
450
519
  onRetry,
451
- onComment
520
+ onComment,
521
+ maxBufferSize
452
522
  });
453
523
  },
454
524
  transform(chunk) {
@@ -4,11 +4,11 @@ import {
4
4
  getActivePricingRow2,
5
5
  insertPricingRow2,
6
6
  init_db3
7
- } from "./cli-csh8fnbg.js";
7
+ } from "./cli-jb30dzvk.js";
8
8
  import {
9
9
  loadModelsDevCache,
10
10
  buildModelsDevSeedRows
11
- } from "./cli-bpbcpd8b.js";
11
+ } from "./cli-sbwsxvtd.js";
12
12
  import {
13
13
  setRuntimeModelCatalog,
14
14
  init_runtime_model_catalog
@@ -7,20 +7,20 @@ import {
7
7
  tierConfigKey,
8
8
  init_model_tier_keys,
9
9
  init_db3
10
- } from "./cli-csh8fnbg.js";
10
+ } from "./cli-jb30dzvk.js";
11
11
  import {
12
12
  ensureRbacSeedsSynced2,
13
13
  init_rbac_roles
14
- } from "./cli-86zpfje5.js";
14
+ } from "./cli-ff1tm9n9.js";
15
15
  import {
16
16
  seedPricingFromModelsDev
17
- } from "./cli-bpbcpd8b.js";
17
+ } from "./cli-sbwsxvtd.js";
18
18
  import {
19
19
  MODEL_TIERS,
20
20
  DEFAULT_MODEL_TIER_MAP,
21
21
  ProviderNameSchema,
22
22
  init_types
23
- } from "./cli-mntxtkhn.js";
23
+ } from "./cli-mz9afxxf.js";
24
24
 
25
25
  // src/be/boot-seeds.ts
26
26
  init_db3();
@@ -11,16 +11,16 @@ import {
11
11
  import {
12
12
  summarizeSession
13
13
  } from "./cli-mmhj8vd7.js";
14
+ import {
15
+ getOpenRouterAttributionHeaders,
16
+ init_openrouter_base_url
17
+ } from "./cli-dfyv0jdy.js";
14
18
  import {
15
19
  resolveTemplateFromCode,
16
20
  resolveTemplateAsync,
17
21
  init_resolver,
18
22
  init_session_templates
19
- } from "./cli-tx00c0h6.js";
20
- import {
21
- getOpenRouterAttributionHeaders,
22
- init_openrouter_base_url
23
- } from "./cli-dfyv0jdy.js";
23
+ } from "./cli-dqygeeh5.js";
24
24
  import {
25
25
  isSessionSummarySkipped,
26
26
  init_env_flag
@@ -13,7 +13,7 @@ async function createRuntimeProvider(kind, target = {}) {
13
13
  return new StaticRuntimeProvider;
14
14
  }
15
15
  case "docker": {
16
- const { DockerRuntimeProvider } = await import("./docker-nfy2gc8t.js");
16
+ const { DockerRuntimeProvider } = await import("./docker-s84hjs91.js");
17
17
  return new DockerRuntimeProvider;
18
18
  }
19
19
  case "e2b": {
@@ -385,7 +385,7 @@ agent-fs is the shared drive between agents and people. Documents (reports, dige
385
385
  Pages: only for polished artifacts shared with a wider audience or explicitly requested; see \`pages\` skill.
386
386
  A tool a person will use, with data and actions: build an app. See the \`apps\` skill.
387
387
  Link env: \`APP_URL\` for pages, \`MCP_BASE_URL\` for the API, \`AGENT_FS_LIVE_URL\` for files. Report missing variables.
388
- For a file anyone outside the swarm opens, use an \`agent-fs share-create\` link; \`AGENT_FS_LIVE_URL\` links are for signed-in teammates.
388
+ Give people the live app link \`\${AGENT_FS_LIVE_URL}/file/~/<org>/<drive>/<path>\`. Make an \`agent-fs share-create\` link only when the requester asks for one or the reader has no agent-fs login.
389
389
  `,
390
390
  variables: [],
391
391
  category: "system"
@@ -482,6 +482,22 @@ Task: {{task}}{{progressLine}}
482
482
  ],
483
483
  category: "system"
484
484
  });
485
+ registerTemplate({
486
+ eventType: "system.agent.context.bound_note",
487
+ header: "",
488
+ defaultBody: "Context is {{contextTokens}} tokens{{contextShare}}. Keep this task bounded: finish the current step, store-progress, and complete or defer instead of starting new exploration.",
489
+ variables: [
490
+ {
491
+ name: "contextTokens",
492
+ description: "Prompt size of the latest request (input + cache read + cache write tokens)"
493
+ },
494
+ {
495
+ name: "contextShare",
496
+ description: `How full the model's context window is, e.g. " (21% of the 1,000,000-token window)". Empty when the window is unknown`
497
+ }
498
+ ],
499
+ category: "system"
500
+ });
485
501
  registerTemplate({
486
502
  eventType: "system.agent.cursor.first_message",
487
503
  header: "",
@@ -8,12 +8,12 @@ import {
8
8
  } from "./cli-4sydckyj.js";
9
9
  import {
10
10
  init_templates3
11
- } from "./cli-0ebey9hg.js";
11
+ } from "./cli-j6rktc91.js";
12
12
  import {
13
13
  resolveTemplateAsync,
14
14
  init_resolver,
15
15
  init_session_templates
16
- } from "./cli-tx00c0h6.js";
16
+ } from "./cli-dqygeeh5.js";
17
17
  import {
18
18
  MAX_PROFILE_FILE_LENGTH,
19
19
  getAppUrl,
@@ -4,7 +4,7 @@ import {
4
4
  claimKv2,
5
5
  deleteKv2,
6
6
  init_db3
7
- } from "./cli-csh8fnbg.js";
7
+ } from "./cli-jb30dzvk.js";
8
8
  import {
9
9
  isEnvFlagEnabled,
10
10
  init_env_flag
@@ -6,7 +6,7 @@ import {
6
6
  getResolvedConfig2,
7
7
  getAllUsers2,
8
8
  init_db3
9
- } from "./cli-csh8fnbg.js";
9
+ } from "./cli-jb30dzvk.js";
10
10
  import {
11
11
  scrubSecrets,
12
12
  init_secret_scrubber
@@ -4,7 +4,7 @@ import {
4
4
  invalidateTelemetryUserRole,
5
5
  init_telemetry_identity,
6
6
  init_db3
7
- } from "./cli-csh8fnbg.js";
7
+ } from "./cli-jb30dzvk.js";
8
8
  import {
9
9
  PermissionVerbSchema,
10
10
  init_rbac
@@ -1,12 +1,11 @@
1
1
  import {
2
- runStopHookSessionSummarySubprocess
3
- } from "./cli-f3pfn4x3.js";
2
+ contextStatePath,
3
+ contextBoundNoteMarkerPath,
4
+ recordContextState
5
+ } from "./cli-2655k16q.js";
4
6
  import {
5
- CONTEXT_FORMULA,
6
- getContextWindowSize,
7
- computeContextUsedUnified,
8
- clampContextPercent
9
- } from "./cli-a5ebc95n.js";
7
+ runStopHookSessionSummarySubprocess
8
+ } from "./cli-9j129brq.js";
10
9
  import {
11
10
  redactRateLimitEventLine,
12
11
  SessionErrorTracker,
@@ -37,6 +36,13 @@ import {
37
36
  import {
38
37
  fetchInstalledMcpServers
39
38
  } from "./cli-bst1vp7e.js";
39
+ import {
40
+ CONTEXT_FORMULA,
41
+ getContextWindowSize,
42
+ computeContextUsedUnified,
43
+ clampContextPercent,
44
+ init_context_window
45
+ } from "./cli-0shx9j93.js";
40
46
  import {
41
47
  resolveClaudeTransport,
42
48
  isClaudeBridgeEffective
@@ -47,7 +53,7 @@ import {
47
53
  import {
48
54
  withFileLock,
49
55
  init_file_lock
50
- } from "./cli-gpv60278.js";
56
+ } from "./cli-e42vss7b.js";
51
57
  import {
52
58
  CLAUDE_CREDENTIALS_HINT,
53
59
  validateClaudeCredentials,
@@ -95,6 +101,7 @@ import {
95
101
  import { homedir as homedir2 } from "node:os";
96
102
  import { dirname, join as join2, resolve as resolve2 } from "node:path";
97
103
  import { promisify } from "node:util";
104
+ init_context_window();
98
105
  init_credentials();
99
106
  init_env_flag();
100
107
  init_file_lock();
@@ -284,6 +291,7 @@ function mergeClaudeSettingsArgs(argLists, cwd) {
284
291
  }
285
292
 
286
293
  // src/providers/claude-session-events.ts
294
+ init_context_window();
287
295
  init_secret_scrubber();
288
296
  function finiteNumber(value) {
289
297
  return typeof value === "number" && Number.isFinite(value) ? value : undefined;
@@ -348,6 +356,7 @@ function normalizeClaudeMessage(json, state) {
348
356
  let model;
349
357
  let contextWindowSize;
350
358
  let assistantText;
359
+ let requestContextTokens;
351
360
  if (json.type === "system" && json.subtype === "init" && json.session_id) {
352
361
  sessionId = json.session_id;
353
362
  model = typeof json.model === "string" ? json.model : undefined;
@@ -416,6 +425,9 @@ function normalizeClaudeMessage(json, state) {
416
425
  outputTokens: usage.output_tokens ?? 0,
417
426
  contextFormula: CONTEXT_FORMULA
418
427
  });
428
+ if (!json.parent_tool_use_id) {
429
+ requestContextTokens = (usage.input_tokens ?? 0) + (usage.cache_read_input_tokens ?? 0) + (usage.cache_creation_input_tokens ?? 0);
430
+ }
419
431
  }
420
432
  }
421
433
  if (json.type === "user" && Array.isArray(json.message?.content)) {
@@ -434,6 +446,7 @@ function normalizeClaudeMessage(json, state) {
434
446
  contextWindowSize,
435
447
  cost,
436
448
  assistantText,
449
+ requestContextTokens,
437
450
  isResult: json.type === "result"
438
451
  };
439
452
  }
@@ -475,9 +488,16 @@ async function writeTaskFile(key, data) {
475
488
  return filePath;
476
489
  }
477
490
  async function cleanupTaskFile2(key) {
478
- try {
479
- await unlink(getTaskFilePath(key));
480
- } catch {}
491
+ const taskFilePath = getTaskFilePath(key);
492
+ for (const path of [
493
+ taskFilePath,
494
+ contextStatePath(taskFilePath),
495
+ contextBoundNoteMarkerPath(taskFilePath)
496
+ ]) {
497
+ try {
498
+ await unlink(path);
499
+ } catch {}
500
+ }
481
501
  }
482
502
  function parseClaudeBinary(raw) {
483
503
  const trimmed = (raw ?? "claude").trim();
@@ -911,6 +931,7 @@ class ClaudeSession {
911
931
  systemPromptFile;
912
932
  appliedReasoningEffort;
913
933
  lastAssistantText = "";
934
+ lastContextTokens;
914
935
  transcript;
915
936
  backgroundKeepalive;
916
937
  deliverSteering;
@@ -1174,6 +1195,10 @@ ${scrubSecrets(stderrOutput)}`);
1174
1195
  setCost(normalized.cost);
1175
1196
  if (normalized.assistantText)
1176
1197
  this.lastAssistantText = normalized.assistantText;
1198
+ if (normalized.requestContextTokens !== undefined && normalized.requestContextTokens !== this.lastContextTokens) {
1199
+ this.lastContextTokens = normalized.requestContextTokens;
1200
+ recordContextState(getTaskFilePath(this.taskFileKey), normalized.requestContextTokens, this.model);
1201
+ }
1177
1202
  this.transcript.push(...normalized.transcriptEntries);
1178
1203
  for (const event of normalized.events)
1179
1204
  this.emit(event);
@@ -1236,7 +1261,7 @@ class ClaudeAdapter2 {
1236
1261
  if (transport === "sdk" && isClaudeBridgeEffective(sourceEnv)) {
1237
1262
  throw new Error("CLAUDE_TRANSPORT=sdk cannot run with an effective Claude Bridge configuration. Select CLI transport or disable the bridge.");
1238
1263
  }
1239
- const claudeSdk = transport === "sdk" ? await import("./claude-sdk-session-0zrdzyx2.js") : undefined;
1264
+ const claudeSdk = transport === "sdk" ? await import("./claude-sdk-session-7b7whkaq.js") : undefined;
1240
1265
  claudeSdk?.validateClaudeSdkAdditionalArgs([
1241
1266
  ...claudeBinaryArgv.slice(1),
1242
1267
  ...config.additionalArgs ?? []