@desplega.ai/agent-swarm 2.5.3 → 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 (197) hide show
  1. package/dist/{acp-adapter-gr2fcyyj.js → acp-adapter-ek38cwsv.js} +4 -4
  2. package/dist/{actions-wv766ghf.js → actions-92mepq03.js} +17 -17
  3. package/dist/{amp-adapter-speb906t.js → amp-adapter-9gaxg015.js} +2 -2
  4. package/dist/{app-ag29n14f.js → app-ctn8gsgx.js} +3 -3
  5. package/dist/{assistant-3x8bz3eg.js → assistant-zyr5kz47.js} +19 -19
  6. package/dist/{boot-reembed-jsmfrpzf.js → boot-reembed-dwzfttdr.js} +1 -1
  7. package/dist/{boot-reembed-5b3d2eea.js → boot-reembed-w75maga2.js} +1 -1
  8. package/dist/{boot-scrub-sweep-s73gerxy.js → boot-scrub-sweep-e9kq43kf.js} +3 -3
  9. package/dist/{boot-seeds-5zmax2wr.js → boot-seeds-x28v3fhb.js} +4 -4
  10. package/dist/{claude-adapter-hswdnm3t.js → claude-adapter-f0afqnne.js} +4 -4
  11. package/dist/{claude-managed-adapter-cvbzj1h6.js → claude-managed-adapter-x81a7r65.js} +3 -3
  12. package/dist/{claude-managed-setup-3k8m3hhc.js → claude-managed-setup-bqzwjd9x.js} +1 -1
  13. package/dist/{claude-sdk-session-fkbyk66x.js → claude-sdk-session-7b7whkaq.js} +9307 -9254
  14. package/dist/{cli-a5ebc95n.js → cli-0shx9j93.js} +16 -13
  15. package/dist/{cli-vwn81jbs.js → cli-19202kew.js} +3 -3
  16. package/dist/{cli-svrj71pg.js → cli-1r5ad7j5.js} +7 -7
  17. package/dist/{cli-hhxjnjzs.js → cli-25n3mv5d.js} +8 -6
  18. package/dist/cli-2655k16q.js +140 -0
  19. package/dist/{cli-hcpj2xqz.js → cli-277c31dw.js} +1 -1
  20. package/dist/{cli-35gtk1p6.js → cli-4b2z6n0m.js} +29 -7
  21. package/dist/{cli-40jsnrjm.js → cli-5bnsc0e1.js} +7 -5
  22. package/dist/{cli-fzcn3d87.js → cli-621ce7kw.js} +1 -1
  23. package/dist/{cli-s49hpn37.js → cli-64mh9mf3.js} +19 -5
  24. package/dist/{cli-e8jyq7d8.js → cli-6a1xg1p7.js} +6 -2
  25. package/dist/{cli-p9rafdrb.js → cli-7p4jxgtt.js} +4 -4
  26. package/dist/{cli-w1zwctj2.js → cli-9j129brq.js} +9 -3
  27. package/dist/{cli-ce0ak9ms.js → cli-abs8ndtr.js} +11 -11
  28. package/dist/{cli-aecdcr77.js → cli-asq5ydm4.js} +123 -50
  29. package/dist/{cli-n45mr7zh.js → cli-bvpgr9ny.js} +2 -2
  30. package/dist/{cli-210xd1f4.js → cli-c61mbdds.js} +3 -3
  31. package/dist/{cli-e5bxnjps.js → cli-c952c7ac.js} +5 -5
  32. package/dist/{cli-p859hcc8.js → cli-dew6x255.js} +1 -1
  33. package/dist/{cli-tx00c0h6.js → cli-dqygeeh5.js} +17 -1
  34. package/dist/{cli-gpv60278.js → cli-e42vss7b.js} +2 -2
  35. package/dist/{cli-s53vp709.js → cli-eftzyh9y.js} +1 -1
  36. package/dist/{cli-3ngdk5te.js → cli-ethgy7ha.js} +1 -1
  37. package/dist/{cli-99xgw26r.js → cli-ff1tm9n9.js} +1 -1
  38. package/dist/{cli-ewm3pwbq.js → cli-g9vd9ece.js} +37 -12
  39. package/dist/{cli-jjznk3f7.js → cli-gbfxp48k.js} +62 -28
  40. package/dist/{cli-z21whrrg.js → cli-gn5af0x5.js} +14 -14
  41. package/dist/{cli-1fc85mvt.js → cli-gwhjmh8g.js} +4 -4
  42. package/dist/{cli-avdvgcay.js → cli-hh5we352.js} +24 -5
  43. package/dist/{cli-0ebey9hg.js → cli-j6rktc91.js} +1 -1
  44. package/dist/{cli-kxawjrxg.js → cli-jb30dzvk.js} +332 -36
  45. package/dist/{cli-25j01dpj.js → cli-jbnn4vxb.js} +3 -3
  46. package/dist/{cli-qzme5949.js → cli-k4tjsdx9.js} +44 -39
  47. package/dist/{cli-8s5wx3nz.js → cli-m4ecdxvz.js} +40 -13
  48. package/dist/{cli-ta8bd7th.js → cli-pzatvw94.js} +1 -1
  49. package/dist/{cli-p6zs9h4y.js → cli-rr7zx19j.js} +767 -249
  50. package/dist/{cli-502eqv93.js → cli-s682zgqz.js} +1 -1
  51. package/dist/{cli-fsdprwrg.js → cli-sbwsxvtd.js} +1 -1
  52. package/dist/{cli-0xk505e8.js → cli-sxgtf5fw.js} +1 -1
  53. package/dist/{cli-egjggehm.js → cli-tsma7p8v.js} +1 -1
  54. package/dist/{cli-qgf8emrn.js → cli-wghjkr0e.js} +5 -5
  55. package/dist/{cli-p0rzjkya.js → cli-wx2nj19m.js} +29 -10
  56. package/dist/{cli-e2ar4bp1.js → cli-x0f2v69c.js} +111 -42
  57. package/dist/{cli-y561h5a9.js → cli-xtrz6bzs.js} +5 -5
  58. package/dist/{cli-gpsz7g88.js → cli-xzfq4at3.js} +7 -7
  59. package/dist/cli.js +18 -18
  60. package/dist/{codex-adapter-n8ka66vf.js → codex-adapter-wch12q99.js} +2 -2
  61. package/dist/{codex-hook-e2he7aca.js → codex-hook-brpnycn5.js} +1 -1
  62. package/dist/{codex-session-runner-fsebts37.js → codex-session-runner-41pfcr95.js} +2 -2
  63. package/dist/{commands-t04rt2pc.js → commands-9849dkj6.js} +2 -2
  64. package/dist/{controller-rgna04r2.js → controller-ja0sd95p.js} +27 -1
  65. package/dist/{controllers-connect-bqm1rtft.js → controllers-connect-xp05dj6x.js} +16 -16
  66. package/dist/{cursor-adapter-swr2k95y.js → cursor-adapter-623qxqew.js} +1 -2
  67. package/dist/{db-a4m7haw0.js → db-47vj40dy.js} +3 -3
  68. package/dist/{db-24ck09xy.js → db-w759qmx0.js} +2 -2
  69. package/dist/{dispatcher-nwf9ss0q.js → dispatcher-7b8e4z2j.js} +15 -15
  70. package/dist/{docker-nfy2gc8t.js → docker-s84hjs91.js} +2 -2
  71. package/dist/{dsh-adapter-kpdnhjst.js → dsh-adapter-2ezw3xea.js} +1 -2
  72. package/dist/{external-channel-j1e2p34p.js → external-channel-e2s028da.js} +2 -2
  73. package/dist/{grok-adapter-qtjz0whk.js → grok-adapter-ys7gaqee.js} +5 -5
  74. package/dist/{handlers-19xr6dnz.js → handlers-wy1dr6ja.js} +18 -18
  75. package/dist/{heartbeat-vtesda5d.js → heartbeat-w3mntghj.js} +17 -17
  76. package/dist/{hook-8wqaszda.js → hook-3jjywnpb.js} +9 -3
  77. package/dist/{hook-b2hhj6rd.js → hook-g7kvv6x9.js} +3 -2
  78. package/dist/{http-mxcqhhcs.js → http-tkp7d4kb.js} +267 -75
  79. package/dist/{index-srg522m6.js → index-1ef1myq2.js} +15 -15
  80. package/dist/{index-1r8wfpzs.js → index-3n8m9ea2.js} +1 -1
  81. package/dist/{index-kw2mmat7.js → index-nmm79qgr.js} +17 -17
  82. package/dist/{index-n1vbvta9.js → index-q7m26kvs.js} +24 -22
  83. package/dist/{index-spwxjgay.js → index-xdaahthb.js} +15 -15
  84. package/dist/{keepalive-dsd8rtgx.js → keepalive-v4ta8wgg.js} +3 -3
  85. package/dist/{lead-zyerk1x2.js → lead-sawnyqxk.js} +33 -33
  86. package/dist/{maintenance-jqmqwnet.js → maintenance-84n1ex21.js} +1 -1
  87. package/dist/{oauth-refresh-sweep-q2c3bnvm.js → oauth-refresh-sweep-vjnnandw.js} +2 -2
  88. package/dist/{onboard-w4yd7s8t.js → onboard-sfmpe4np.js} +2 -2
  89. package/dist/{opencode-adapter-9tppvxar.js → opencode-adapter-jmpst4q4.js} +3 -3
  90. package/dist/{otel-impl-f36byzbd.js → otel-impl-v6cc0zve.js} +1 -1
  91. package/dist/{pi-mono-adapter-tqsge1ay.js → pi-mono-adapter-fk8fkcf6.js} +33 -6
  92. package/dist/{pricing-refresh-xvak5p4v.js → pricing-refresh-fsk1e1zc.js} +3 -3
  93. package/dist/{rbac-roles-gfn30fb8.js → rbac-roles-prmkdnkw.js} +2 -2
  94. package/dist/{rbac-roles-682k2mt5.js → rbac-roles-zxmxqa39.js} +1 -1
  95. package/dist/{render-v2-hgytz8nn.js → render-v2-pjwxvnkw.js} +3 -3
  96. package/dist/{resume-2dvq348g.js → resume-frdtgfa0.js} +8 -6
  97. package/dist/{session-access-7f21ekq9.js → session-access-fpez4y5q.js} +4 -4
  98. package/dist/{setup-epffxtbk.js → setup-mq6m3m8q.js} +1 -1
  99. package/dist/{work-objects-xz1a5rqk.js → work-objects-kfahhjsq.js} +18 -18
  100. package/dist/{worker-42t8emjt.js → worker-v5e5rxj3.js} +33 -33
  101. package/openapi.json +68 -3
  102. package/package.json +5 -5
  103. package/plugin/commands/create-pr.md +2 -2
  104. package/plugin/pi-skills/create-pr/SKILL.md +2 -2
  105. package/src/be/db/approvals.ts +48 -0
  106. package/src/be/db/tasks/write.ts +15 -5
  107. package/src/be/db/workflow-idempotency.ts +183 -0
  108. package/src/be/db/workflow-runs.ts +318 -7
  109. package/src/be/db.ts +67 -17
  110. package/src/be/migrations/242_workflow_idempotency_keys.sql +40 -0
  111. package/src/be/sealed-json.ts +1 -0
  112. package/src/be/seed-scripts/catalog/compound-insights.inline.ts +2 -2
  113. package/src/be/seed-scripts/catalog/compound-insights.ts +2 -2
  114. package/src/be/seed-skills/bundled-files.generated.json +1 -1
  115. package/src/be/sql-connections.ts +7 -1
  116. package/src/be/swarm-config-guard.ts +2 -0
  117. package/src/be/users.ts +9 -0
  118. package/src/commands/controller.ts +33 -0
  119. package/src/commands/runner.ts +6 -2
  120. package/src/extensions/apply-task-create.ts +57 -11
  121. package/src/extensions/contract-types.generated.ts +1 -1
  122. package/src/extensions/contract.ts +25 -0
  123. package/src/extensions/dispatcher.ts +4 -0
  124. package/src/extensions/post-bridge.ts +8 -0
  125. package/src/hooks/context-bound-note.ts +196 -0
  126. package/src/hooks/hook.ts +12 -0
  127. package/src/http/config.ts +48 -16
  128. package/src/http/idempotency-key.ts +117 -0
  129. package/src/http/workflows.ts +129 -24
  130. package/src/prompts/context-bound-note.ts +48 -0
  131. package/src/prompts/session-templates.ts +25 -1
  132. package/src/providers/amp-adapter.ts +30 -8
  133. package/src/providers/claude-adapter.ts +29 -4
  134. package/src/providers/claude-managed-adapter.ts +26 -0
  135. package/src/providers/claude-sdk-session.ts +10 -0
  136. package/src/providers/claude-session-events.ts +13 -0
  137. package/src/providers/codex-adapter.ts +12 -0
  138. package/src/providers/opencode-adapter.ts +18 -0
  139. package/src/providers/pi-mono-adapter.ts +35 -0
  140. package/src/runtime-providers/docker.ts +6 -2
  141. package/src/scripts-runtime/types/swarm-extension.d.ts +35 -0
  142. package/src/tests/amp-adapter.test.ts +97 -0
  143. package/src/tests/approval-requests.test.ts +10 -7
  144. package/src/tests/approval-sweeps.test.ts +12 -6
  145. package/src/tests/base-prompt.test.ts +1 -1
  146. package/src/tests/claude-hook-output.test.ts +79 -1
  147. package/src/tests/claude-managed-adapter.test.ts +275 -0
  148. package/src/tests/codex-adapter.test.ts +163 -0
  149. package/src/tests/context-bound-note.test.ts +269 -0
  150. package/src/tests/extensions-pre-task.test.ts +273 -0
  151. package/src/tests/fetch-resolved-env.test.ts +17 -0
  152. package/src/tests/fixtures/extensions/record-blocks/hooks.ts +10 -0
  153. package/src/tests/fixtures/extensions/record-blocks/manifest.json +7 -0
  154. package/src/tests/fixtures/fake-amp.ts +22 -8
  155. package/src/tests/fixtures/held-template-render.ts +42 -0
  156. package/src/tests/fixtures/workflow-idempotency-trigger.child.ts +73 -0
  157. package/src/tests/openapi-route-headers.test.ts +2 -0
  158. package/src/tests/opencode-adapter.test.ts +134 -0
  159. package/src/tests/pi-mono-adapter.test.ts +105 -0
  160. package/src/tests/prompt-template-session.test.ts +4 -3
  161. package/src/tests/runner-push-delivery.test.ts +25 -0
  162. package/src/tests/runtime-controller-liveness.test.ts +133 -0
  163. package/src/tests/runtime-providers-docker.test.ts +2 -0
  164. package/src/tests/script-connections.test.ts +3 -0
  165. package/src/tests/script-run-config-scope.test.ts +91 -3
  166. package/src/tests/session-logs.test.ts +70 -0
  167. package/src/tests/sessions-tree.test.ts +37 -0
  168. package/src/tests/workflow-cascade-cancel.test.ts +1169 -0
  169. package/src/tests/workflow-foreach-supersede-retry.test.ts +488 -0
  170. package/src/tests/workflow-idempotency.test.ts +915 -0
  171. package/src/tools/workflows/cancel-workflow-run.ts +1 -1
  172. package/src/utils/context-window.ts +8 -6
  173. package/src/workflows/approval-cancel.ts +15 -13
  174. package/src/workflows/approval-notifications.ts +5 -1
  175. package/src/workflows/checkpoint.ts +6 -3
  176. package/src/workflows/engine.ts +30 -8
  177. package/src/workflows/executors/foreach.ts +2 -2
  178. package/src/workflows/foreach-driver.ts +10 -3
  179. package/src/workflows/foreach-join.ts +29 -6
  180. package/src/workflows/recovery.ts +6 -1
  181. package/src/workflows/resume.ts +168 -56
  182. package/src/workflows/retry-poller.ts +49 -3
  183. package/src/workflows/task-step-routing.ts +29 -7
  184. package/templates/ai-toolbox.manifest.json +8 -8
  185. package/templates/community/open-prompt-showreel/PLAYBOOK.md +5 -6
  186. package/templates/community/open-prompt-showreel/lead-prompt.md +1 -1
  187. package/templates/community/open-prompt-showreel/skills/open-prompt-showreel/SKILL.md +4 -4
  188. package/templates/skills/agent-browser/SKILL.md +4 -4
  189. package/templates/skills/agent-browser/content.md +4 -4
  190. package/templates/skills/code-quality/config.json +1 -1
  191. package/templates/skills/code-quality/content.md +2 -2
  192. package/templates/skills/delegate-work/content.md +29 -25
  193. package/templates/skills/delegate-work/files/scripts/codex-exec.sh +5 -5
  194. package/templates/skills/qa/content.md +2 -2
  195. package/templates/skills/researching/content.md +2 -0
  196. package/templates/skills/work-on-task/SKILL.md +1 -1
  197. package/templates/skills/work-on-task/content.md +1 -1
@@ -4,7 +4,7 @@ import {
4
4
  invalidateTelemetryUserRole,
5
5
  init_telemetry_identity,
6
6
  init_db3
7
- } from "./cli-kxawjrxg.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-w1zwctj2.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-fkbyk66x.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 ?? []
@@ -8,7 +8,11 @@ import {
8
8
  updateAgentStatus2,
9
9
  updateAgentMaxTasks2,
10
10
  getActiveTaskCount2,
11
+ approvalCancellationNotificationKey,
12
+ init_approvals,
11
13
  getTaskById2,
14
+ getRunLineageBlock,
15
+ getWorkflowRunStatus,
12
16
  getChildWorkflowRunId,
13
17
  isParentStepAttemptCurrent,
14
18
  createForeachChildSteps,
@@ -51,18 +55,18 @@ import {
51
55
  releaseApprovalCancellationNotificationClaim2,
52
56
  updateApprovalRequestNotifications2,
53
57
  init_db3
54
- } from "./cli-kxawjrxg.js";
58
+ } from "./cli-jb30dzvk.js";
55
59
  import {
56
60
  isMultiRuntimeEnabled
57
61
  } from "./cli-e8xyjvfc.js";
58
62
  import {
59
63
  getSlackApp2
60
- } from "./cli-ce0ak9ms.js";
64
+ } from "./cli-abs8ndtr.js";
61
65
  import {
62
66
  externalChannelToolError2,
63
67
  isBlockExternalEnabled2,
64
68
  getChannelBlockReason2
65
- } from "./cli-s53vp709.js";
69
+ } from "./cli-eftzyh9y.js";
66
70
  import {
67
71
  DEFAULT_MODEL,
68
72
  resolveCredential
@@ -70,7 +74,7 @@ import {
70
74
  import {
71
75
  revokeRuntimeTokensForRuntime,
72
76
  init_users
73
- } from "./cli-e8jyq7d8.js";
77
+ } from "./cli-6a1xg1p7.js";
74
78
  import {
75
79
  TERMINAL_TASK_STATUSES,
76
80
  init_types
@@ -84,18 +88,18 @@ import {
84
88
  selectCredential,
85
89
  init_credentials
86
90
  } from "./cli-zw88zjba.js";
87
- import {
88
- deepInterpolate,
89
- init_template,
90
- resolveTemplate,
91
- init_resolver
92
- } from "./cli-tx00c0h6.js";
93
91
  import {
94
92
  DEFAULT_OPENROUTER_BASE_URL,
95
93
  getOpenRouterBaseUrl,
96
94
  getOpenRouterAttributionHeaders,
97
95
  init_openrouter_base_url
98
96
  } from "./cli-dfyv0jdy.js";
97
+ import {
98
+ deepInterpolate,
99
+ init_template,
100
+ resolveTemplate,
101
+ init_resolver
102
+ } from "./cli-dqygeeh5.js";
99
103
  import {
100
104
  init_zod
101
105
  } from "./cli-4chz1hye.js";
@@ -145,7 +149,7 @@ async function notifyAutomationPreflightFailure(preflight) {
145
149
  return;
146
150
  }
147
151
  try {
148
- const { getSlackApp } = await import("./app-ag29n14f.js");
152
+ const { getSlackApp } = await import("./app-ctn8gsgx.js");
149
153
  const app = getSlackApp();
150
154
  if (!app) {
151
155
  console.warn("[Automation Preflight] Slack not available, cannot send notification");
@@ -958,6 +962,7 @@ init_secret_scrubber();
958
962
 
959
963
  // src/workflows/approval-notifications.ts
960
964
  init_db3();
965
+ init_approvals();
961
966
  init_resolver();
962
967
 
963
968
  // src/slack/dm.ts
@@ -1124,7 +1129,7 @@ async function postApprovalCancellationUpdates(approvals, reason, client = getSl
1124
1129
  for (const notification of slackThreads) {
1125
1130
  if (notification.channel !== "slack" || !notification.messageTs)
1126
1131
  continue;
1127
- const notificationKey = `${notification.target}:${notification.messageTs}`;
1132
+ const notificationKey = approvalCancellationNotificationKey(notification.target, notification.messageTs);
1128
1133
  const claim = await claimApprovalCancellationNotification2(approval.id, notificationKey);
1129
1134
  if (!claim)
1130
1135
  continue;
@@ -3441,16 +3446,18 @@ class SystemOneDecisionExecutor extends BaseExecutor {
3441
3446
 
3442
3447
  // src/workflows/foreach-join.ts
3443
3448
  init_db3();
3449
+ init_workflow_runs();
3444
3450
 
3445
3451
  // src/workflows/checkpoint.ts
3446
3452
  init_db3();
3453
+ init_workflow_runs();
3447
3454
  async function holdsFence(runId, stepId, fence) {
3448
3455
  const row = await getDbClient2().get(`SELECT 1 AS found
3449
3456
  FROM workflow_run_steps s
3450
3457
  JOIN workflow_runs r ON r.id = s.runId
3451
3458
  WHERE s.id = ? AND s.runId = ? AND s.status = 'running' AND s.retryCount = ?
3452
3459
  AND r.status IN ('running', 'waiting')`, [stepId, runId, fence.retryCount]);
3453
- return row != null;
3460
+ return row != null && await getRunLineageBlock(runId) == null;
3454
3461
  }
3455
3462
  async function checkpointStep(runId, stepId, nodeId, result, ctx, options = {}) {
3456
3463
  return getDbClient2().transaction(async () => {
@@ -3511,6 +3518,8 @@ async function checkpointStepFailure(runId, stepId, error, retryCount, retryPoli
3511
3518
  }
3512
3519
  async function checkpointStepWaiting(runId, stepId, ctx, options = {}) {
3513
3520
  return getDbClient2().transaction(async () => {
3521
+ if (await getRunLineageBlock(runId))
3522
+ return false;
3514
3523
  const step = await getDbClient2().get(`UPDATE workflow_run_steps
3515
3524
  SET status = 'waiting'
3516
3525
  WHERE id = ? AND runId = ? AND status = 'running'
@@ -3547,6 +3556,7 @@ function calculateBackoff(policy, attempt) {
3547
3556
 
3548
3557
  // src/workflows/foreach-driver.ts
3549
3558
  init_db3();
3559
+ init_workflow_runs();
3550
3560
 
3551
3561
  // src/workflows/constants.ts
3552
3562
  var FAILED_TASK_OUTPUT_PREFIX = "[FAILED:";
@@ -3943,12 +3953,16 @@ async function resolveRenderedWorkflowInputs(input) {
3943
3953
  async function startWorkflowExecution2(workflow, triggerData, registry, options = {}) {
3944
3954
  const preflight = preflightAutomation(workflowPreflightInput(workflow), await getAutomationSetupStates());
3945
3955
  if (preflight.state === "needs_setup" && !options.parentStepId) {
3946
- const { runId, recorded } = await recordWorkflowPreflightFailure({
3947
- workflowId: workflow.id,
3948
- triggerType: options.triggerType ?? "manual",
3949
- triggerData,
3950
- failureReason: preflight.failureReason,
3951
- createdBy: options.requestedByUserId
3956
+ const { runId, recorded } = await getDbClient2().transaction(async () => {
3957
+ const failure = await recordWorkflowPreflightFailure({
3958
+ workflowId: workflow.id,
3959
+ triggerType: options.triggerType ?? "manual",
3960
+ triggerData,
3961
+ failureReason: preflight.failureReason,
3962
+ createdBy: options.requestedByUserId
3963
+ });
3964
+ await options.accept?.({ runId: failure.runId, skipped: false });
3965
+ return failure;
3952
3966
  });
3953
3967
  if (recorded)
3954
3968
  await notifyAutomationPreflightFailure(preflight);
@@ -4067,6 +4081,7 @@ async function createRunWithInitialState(workflow, triggerData, options, initial
4067
4081
  });
4068
4082
  await updateWorkflowRun2(runId, initial.status ? { status: initial.status, error: initial.error, finishedAt: initial.finishedAt } : { context: initial.context });
4069
4083
  const preflightAlert = initial.status === "failed" && initial.preflight ? await isFirstWorkflowPreflightFailureToday(workflow.id, runId) : undefined;
4084
+ await options.accept?.({ runId, skipped: initial.status === "skipped" });
4070
4085
  return { runId, created: true, preflightAlert };
4071
4086
  });
4072
4087
  }
@@ -4228,6 +4243,8 @@ async function walkGraphOwned(def, runId, ctx, startNodes, registry, workflowId,
4228
4243
  const run = await getWorkflowRun2(runId);
4229
4244
  if (!run || run.status !== "running")
4230
4245
  return;
4246
+ if (await getRunLineageBlock(runId))
4247
+ return;
4231
4248
  const finalSteps = await getWorkflowRunStepsByRunId2(runId);
4232
4249
  if (hasRunningStep(finalSteps))
4233
4250
  return;
@@ -4336,6 +4353,8 @@ async function executeStep(def, runId, ctx, node, registry, workflowId, secretKe
4336
4353
  if (!run || run.status !== "running" && run.status !== "waiting") {
4337
4354
  return { halted: true };
4338
4355
  }
4356
+ if (await getRunLineageBlock(runId))
4357
+ return { halted: true };
4339
4358
  if (node.type !== "foreach") {
4340
4359
  const current = await getCurrentStepForNode2(runId, node.id, getAllPredecessors(def, node.id));
4341
4360
  if (current && (current.status !== "running" || executingSteps.has(current.id))) {
@@ -4517,7 +4536,7 @@ async function runClaimedStep(def, runId, ctx, node, registry, existingStep, ste
4517
4536
  }
4518
4537
  const waiting = await checkpointStepWaiting(runId, stepId, ctx);
4519
4538
  if (waiting && result.waitFor === "workflow.child.finished") {
4520
- const { resumeFromChildRun } = await import("./resume-2dvq348g.js");
4539
+ const { resumeFromChildRun } = await import("./resume-frdtgfa0.js");
4521
4540
  await resumeFromChildRun(stepId, registry);
4522
4541
  }
4523
4542
  return { outcome: waiting ? "waiting" : "completed", successors: [] };
@@ -4809,7 +4828,7 @@ class ForeachExecutor extends BaseExecutor {
4809
4828
  };
4810
4829
  }));
4811
4830
  const childSteps = (await this.deps.db.getWorkflowRunStepsByRunId(meta.runId)).filter((step) => parseSyntheticNodeId(step.nodeId)?.parentNodeId === meta.nodeId);
4812
- if (childSteps.every((step) => FOREACH_TERMINAL_STEP_STATUSES.has(step.status))) {
4831
+ if (childSteps.every(isForeachChildSettled)) {
4813
4832
  return { status: "success", output: buildForeachAggregate(childSteps) };
4814
4833
  }
4815
4834
  return {
@@ -4979,7 +4998,7 @@ async function runForeachDrive(runId, parentNodeId, registry) {
4979
4998
  if (drive.successors.length > 0) {
4980
4999
  await walkGraph(workflow.definition, runId, ctx, drive.successors, registry, workflow.id, getSecretInputKeys(workflow.input));
4981
5000
  } else {
4982
- const { finalizeOrWait } = await import("./resume-2dvq348g.js");
5001
+ const { finalizeOrWait } = await import("./resume-frdtgfa0.js");
4983
5002
  await finalizeOrWait(runId);
4984
5003
  }
4985
5004
  return drive;
@@ -5018,6 +5037,11 @@ async function claimChildren(def, runId, parentNode) {
5018
5037
  const claimed = [];
5019
5038
  try {
5020
5039
  await getDbClient2().transaction(async () => {
5040
+ const status = await getWorkflowRunStatus(runId);
5041
+ if (status !== "running" && status !== "waiting")
5042
+ return;
5043
+ if (await getRunLineageBlock(runId))
5044
+ return;
5021
5045
  const children = latestForeachChildren(def, parentNode.id, await getWorkflowRunStepsByRunId2(runId));
5022
5046
  for (const child of children) {
5023
5047
  if (child.status === "running" && !ownedChildren.has(child.id)) {
@@ -5025,7 +5049,7 @@ async function claimChildren(def, runId, parentNode) {
5025
5049
  claimed.push(child);
5026
5050
  }
5027
5051
  }
5028
- const inFlight = children.filter((child) => child.status === "running" || child.status === "waiting").length;
5052
+ const inFlight = children.filter((child) => child.status === "running" || child.status === "waiting" || isRetryPending(child)).length;
5029
5053
  let free = foreachConcurrencyCap(parentNode) - inFlight;
5030
5054
  for (const child of children) {
5031
5055
  if (free <= 0)
@@ -5121,7 +5145,7 @@ async function startChild(input) {
5121
5145
  const parked = await getDbClient2().get("UPDATE workflow_run_steps SET status = 'waiting' WHERE id = ? AND status = 'running' RETURNING id", [child.id]);
5122
5146
  if (parked && result.waitFor === "workflow.child.finished") {
5123
5147
  ownedChildren.delete(child.id);
5124
- const { resumeFromChildRun } = await import("./resume-2dvq348g.js");
5148
+ const { resumeFromChildRun } = await import("./resume-frdtgfa0.js");
5125
5149
  await resumeFromChildRun(child.id, registry);
5126
5150
  }
5127
5151
  return null;
@@ -5162,6 +5186,12 @@ var FOREACH_TERMINAL_STEP_STATUSES = new Set([
5162
5186
  "cancelled",
5163
5187
  "skipped"
5164
5188
  ]);
5189
+ function isRetryPending(step) {
5190
+ return step.status === "failed" && step.nextRetryAt != null;
5191
+ }
5192
+ function isForeachChildSettled(step) {
5193
+ return FOREACH_TERMINAL_STEP_STATUSES.has(step.status) && !isRetryPending(step);
5194
+ }
5165
5195
  function parseSyntheticNodeId(nodeId) {
5166
5196
  const separatorIndex = nodeId.indexOf("#");
5167
5197
  if (separatorIndex <= 0 || separatorIndex === nodeId.length - 1)
@@ -5184,7 +5214,7 @@ async function joinForeach(def, runId, childStep, ctx) {
5184
5214
  throw new Error(`Step "${childStep.nodeId}" is not a foreach child`);
5185
5215
  }
5186
5216
  const children = latestForeachChildren(def, parent.id, await getWorkflowRunStepsByRunId2(runId));
5187
- if (children.some((step) => !FOREACH_TERMINAL_STEP_STATUSES.has(step.status))) {
5217
+ if (children.some((step) => !isForeachChildSettled(step))) {
5188
5218
  return { joined: false, parentNodeId: parent.id, successors: [] };
5189
5219
  }
5190
5220
  const parentStep = await getLatestStepForNode2(runId, parent.id);
@@ -5274,6 +5304,8 @@ async function settleForeachChild(def, runId, childStepId, outcome, ctx, options
5274
5304
  });
5275
5305
  if (run.status !== "running" && run.status !== "waiting")
5276
5306
  return unclaimed;
5307
+ if (await getRunLineageBlock(runId))
5308
+ return unclaimed;
5277
5309
  if (outcome.status !== "completed" && effectiveFailurePolicy(parent, def) === "fail-fast") {
5278
5310
  const reason = options.runError ?? outcome.error ?? `foreach item ${current.nodeId} failed`;
5279
5311
  await cancelQueuedForeachChildren(def, runId, parent.id, current.nodeId);
@@ -5303,9 +5335,11 @@ async function cancelQueuedForeachChildren(def, runId, parentNodeId, failedChild
5303
5335
  await getDbClient2().transaction(async () => {
5304
5336
  const children = latestForeachChildren(def, parentNodeId, await getWorkflowRunStepsByRunId2(runId));
5305
5337
  for (const child of children) {
5306
- if (child.status !== "pending")
5338
+ if (child.status !== "pending" && !isRetryPending(child))
5307
5339
  continue;
5308
- const row = await getDbClient2().get("UPDATE workflow_run_steps SET status = 'cancelled', error = ?, finishedAt = ? WHERE id = ? AND status = 'pending' RETURNING id", [error, finishedAt, child.id]);
5340
+ const row = await getDbClient2().get(`UPDATE workflow_run_steps SET status = 'cancelled', error = ?, finishedAt = ?, nextRetryAt = NULL
5341
+ WHERE id = ? AND (status = 'pending' OR (status = 'failed' AND nextRetryAt IS NOT NULL))
5342
+ RETURNING id`, [error, finishedAt, child.id]);
5309
5343
  if (row)
5310
5344
  cancelled++;
5311
5345
  }
@@ -5732,4 +5766,4 @@ function applyDefinitionPatch(def, patch) {
5732
5766
  return { definition: patchedDef, errors };
5733
5767
  }
5734
5768
 
5735
- export { notifyAutomationPreflightFailure, automationIntegrationFixUrl, isNeedsSetupFailure, preflightAutomation, renderAutomationTokens, getAutomationSetupStates, schedulePreflightInput, listEnabledAutomationPreflightInputs, recordSchedulePreflightFailure, BaseExecutor, AGENT_MAX_TASKS_CONFIG_KEY, reconcileAgentMaxTasksPolicy, resetAgentMaxTasksMirror, upsertSwarmConfigWithPolicyMirror, runtimeStaleThresholdMinutes, upsertRuntimeInstance, getRuntimeInstanceById, insertProvisioningRuntime, markRuntimeTerminated, touchRuntimeInstance, markRuntimeInstanceOffline, countActiveRuntimeInstancesForAgent, listRuntimeInstancesForAgent, setRuntimeCredentialReady, reconcileAgentStatusFromRuntimes, agentsWithLiveRuntime, expireStaleRuntimeInstances, listRuntimeInstancesForPool, ConfigQuestionSettingsSchema, ConfigStateSchema, readConfigState, normalizeApprovalQuestions, isConfigQuestion, parseConfigAnswer, skippedConfigResult, keptConfigResult, applyConfigAnswer, resolveSlackConversationId, dispatchApprovalNotifications, postApprovalCancellationUpdates, createApprovalFollowUpTask, HumanInTheLoopExecutor, resolveWorkflowLlmConfig, SYSTEM_ONE_PROVIDER_IDS, SystemOneExtractionExecutor, SYSTEM_ONE_DECISION_NODE_TYPE, SystemOneDecisionConfigSchema, SystemOneDecisionExecutor, checkpointStep, checkpointStepFailure, checkpointStepWaiting, FAILED_TASK_OUTPUT_PREFIX, FOREACH_ITEMS_WAIT_FOR, loadCompletedStepRouting, resolveInputValue, getSecretInputKeys, validateJsonSchema, findJsonSchemaShapeErrors, getMaxWorkflowStepsPerRun, findWorkflowReadinessProblems, formatReadinessProblems, workflowSaveWarnings, withSaveWarnings, runStepValidation, TriggerSchemaError, startWorkflowExecution2, ParentStepNotCurrentError, failRunOnUnreadableReplay, isWorkflowRunActive, isStepExecuting, holdWorkflowRun, walkGraph, hasRunningStep, findReadyNodes, scriptBodyInterpolationError, ForeachExecutor, rebuildNodeExecutionInput, isForeachChildOwned, parkAndDriveForeach, startForeachDrive, runForeachDrive, FOREACH_TERMINAL_STEP_STATUSES, parseSyntheticNodeId, resolveForeachParent, settleForeachChild, resolveStepNode, stepFailureMode, getNextTargets, generateEdges, resolveValidationPort, getSuccessors, definitionNodeIds, validateDefinition, applyDefinitionPatch };
5769
+ export { notifyAutomationPreflightFailure, automationIntegrationFixUrl, isNeedsSetupFailure, preflightAutomation, renderAutomationTokens, getAutomationSetupStates, schedulePreflightInput, listEnabledAutomationPreflightInputs, recordSchedulePreflightFailure, BaseExecutor, AGENT_MAX_TASKS_CONFIG_KEY, reconcileAgentMaxTasksPolicy, resetAgentMaxTasksMirror, upsertSwarmConfigWithPolicyMirror, runtimeStaleThresholdMinutes, upsertRuntimeInstance, getRuntimeInstanceById, insertProvisioningRuntime, markRuntimeTerminated, touchRuntimeInstance, markRuntimeInstanceOffline, countActiveRuntimeInstancesForAgent, listRuntimeInstancesForAgent, setRuntimeCredentialReady, reconcileAgentStatusFromRuntimes, agentsWithLiveRuntime, expireStaleRuntimeInstances, listRuntimeInstancesForPool, ConfigQuestionSettingsSchema, ConfigStateSchema, readConfigState, normalizeApprovalQuestions, isConfigQuestion, parseConfigAnswer, skippedConfigResult, keptConfigResult, applyConfigAnswer, resolveSlackConversationId, dispatchApprovalNotifications, postApprovalCancellationUpdates, createApprovalFollowUpTask, HumanInTheLoopExecutor, resolveWorkflowLlmConfig, SYSTEM_ONE_PROVIDER_IDS, SystemOneExtractionExecutor, SYSTEM_ONE_DECISION_NODE_TYPE, SystemOneDecisionConfigSchema, SystemOneDecisionExecutor, checkpointStep, checkpointStepFailure, checkpointStepWaiting, FAILED_TASK_OUTPUT_PREFIX, FOREACH_ITEMS_WAIT_FOR, loadCompletedStepRouting, resolveInputValue, getSecretInputKeys, validateJsonSchema, findJsonSchemaShapeErrors, getMaxWorkflowStepsPerRun, findWorkflowReadinessProblems, formatReadinessProblems, workflowSaveWarnings, withSaveWarnings, runStepValidation, TriggerSchemaError, startWorkflowExecution2, ParentStepNotCurrentError, failRunOnUnreadableReplay, isWorkflowRunActive, isStepExecuting, holdWorkflowRun, walkGraph, hasRunningStep, findReadyNodes, scriptBodyInterpolationError, ForeachExecutor, rebuildNodeExecutionInput, isForeachChildOwned, parkAndDriveForeach, startForeachDrive, runForeachDrive, FOREACH_TERMINAL_STEP_STATUSES, isRetryPending, parseSyntheticNodeId, resolveForeachParent, settleForeachChild, resolveStepNode, stepFailureMode, getNextTargets, generateEdges, resolveValidationPort, getSuccessors, definitionNodeIds, validateDefinition, applyDefinitionPatch };
@@ -66,7 +66,7 @@ import {
66
66
  getStaleApprovalRequests2,
67
67
  upsertKv2,
68
68
  init_db3
69
- } from "./cli-kxawjrxg.js";
69
+ } from "./cli-jb30dzvk.js";
70
70
  import {
71
71
  poolTaskRunsOnHarness,
72
72
  isRuntimePoolWakeable,
@@ -87,48 +87,48 @@ import {
87
87
  createRerouteDecisionTask,
88
88
  createPoolStarvationDecisionTask,
89
89
  canClaim
90
- } from "./cli-aecdcr77.js";
90
+ } from "./cli-asq5ydm4.js";
91
91
  import {
92
92
  runtimeStaleThresholdMinutes,
93
93
  countActiveRuntimeInstancesForAgent,
94
94
  agentsWithLiveRuntime,
95
95
  expireStaleRuntimeInstances,
96
96
  createApprovalFollowUpTask
97
- } from "./cli-jjznk3f7.js";
97
+ } from "./cli-gbfxp48k.js";
98
98
  import {
99
99
  listRuntimePools2,
100
100
  init_db
101
- } from "./cli-vwn81jbs.js";
101
+ } from "./cli-19202kew.js";
102
102
  import {
103
103
  remediateStalledRuntime
104
- } from "./cli-svrj71pg.js";
104
+ } from "./cli-1r5ad7j5.js";
105
105
  import {
106
106
  runSavedScriptAsAgent
107
- } from "./cli-p9rafdrb.js";
107
+ } from "./cli-7p4jxgtt.js";
108
108
  import {
109
109
  mintToken,
110
110
  init_users
111
- } from "./cli-e8jyq7d8.js";
111
+ } from "./cli-6a1xg1p7.js";
112
112
  import {
113
113
  TERMINAL_TASK_STATUSES,
114
114
  SUPERSEDED_WORKFLOW_TASK_REASON,
115
115
  init_types
116
116
  } from "./cli-mz9afxxf.js";
117
- import {
118
- registerTemplate,
119
- init_registry,
120
- resolveTemplate,
121
- init_resolver
122
- } from "./cli-tx00c0h6.js";
123
117
  import {
124
118
  DEFAULT_OPENROUTER_BASE_URL,
125
119
  getOpenRouterBaseUrl,
126
120
  init_openrouter_base_url
127
121
  } from "./cli-dfyv0jdy.js";
122
+ import {
123
+ registerTemplate,
124
+ init_registry,
125
+ resolveTemplate,
126
+ init_resolver
127
+ } from "./cli-dqygeeh5.js";
128
128
  import {
129
129
  init_package,
130
130
  package_default
131
- } from "./cli-y561h5a9.js";
131
+ } from "./cli-xtrz6bzs.js";
132
132
  import {
133
133
  isEnvFlagEnabled,
134
134
  init_env_flag
@@ -9,16 +9,16 @@ import {
9
9
  init_active_sessions,
10
10
  getSteeringMessageById2,
11
11
  init_db3
12
- } from "./cli-kxawjrxg.js";
12
+ } from "./cli-jb30dzvk.js";
13
13
  import {
14
14
  getUserGrant2,
15
15
  init_rbac_roles
16
- } from "./cli-99xgw26r.js";
16
+ } from "./cli-ff1tm9n9.js";
17
17
  import {
18
18
  findUserById,
19
19
  findUserByExternalId,
20
20
  init_users
21
- } from "./cli-e8jyq7d8.js";
21
+ } from "./cli-6a1xg1p7.js";
22
22
  import {
23
23
  isRbacEnabled,
24
24
  can,
@@ -503,7 +503,7 @@ function route(def) {
503
503
  try {
504
504
  const rawBody = def.body ? await parseBody(req, def.maxBodyBytes) : undefined;
505
505
  if (def.session && "bodyTaskIds" in def.session) {
506
- const { bodySessionDenial } = await import("./session-access-7f21ekq9.js");
506
+ const { bodySessionDenial } = await import("./session-access-fpez4y5q.js");
507
507
  const denial = await bodySessionDenial(req, def.session.bodyTaskIds(rawBody));
508
508
  if (denial) {
509
509
  jsonError(res, denial, 403);
@@ -1,8 +1,7 @@
1
1
  import {
2
- CONTEXT_FORMULA,
3
- getContextWindowSize,
4
- clampContextPercent
5
- } from "./cli-a5ebc95n.js";
2
+ contextBoundNoteThreshold,
3
+ createContextBoundNote
4
+ } from "./cli-2655k16q.js";
6
5
  import {
7
6
  swarmRuntimeInstanceId
8
7
  } from "./cli-e8xyjvfc.js";
@@ -23,13 +22,19 @@ import {
23
22
  autoIndexMemoryFile,
24
23
  fetchConcurrentContext,
25
24
  summarizeTranscript
26
- } from "./cli-e5bxnjps.js";
25
+ } from "./cli-c952c7ac.js";
27
26
  import {
28
27
  applyReasoningEffort
29
28
  } from "./cli-bn0rewsy.js";
30
29
  import {
31
30
  fetchInstalledMcpServers
32
31
  } from "./cli-bst1vp7e.js";
32
+ import {
33
+ CONTEXT_FORMULA,
34
+ getContextWindowSize,
35
+ clampContextPercent,
36
+ init_context_window
37
+ } from "./cli-0shx9j93.js";
33
38
  import {
34
39
  splitCredentialPool,
35
40
  openAICompatibleKeyLabels,
@@ -68,6 +73,7 @@ import {
68
73
  init_src2();
69
74
  import { existsSync, readFileSync } from "node:fs";
70
75
  import { dirname, join } from "node:path";
76
+ init_context_window();
71
77
  init_credentials();
72
78
  init_env_flag();
73
79
  init_openrouter_base_url();
@@ -502,6 +508,7 @@ class OpencodeSession {
502
508
  toolNames = new Map;
503
509
  textByMessage = new Map;
504
510
  transcript = [];
511
+ observeContextBound;
505
512
  constructor(host, _sessionId, model, swarm, cwd, appliedReasoningEffort = null, billing) {
506
513
  this.host = host;
507
514
  this._sessionId = _sessionId;
@@ -513,6 +520,17 @@ class OpencodeSession {
513
520
  this.completionPromise = new Promise((resolve) => {
514
521
  this.completionResolve = resolve;
515
522
  });
523
+ this.observeContextBound = createContextBoundNote({
524
+ threshold: contextBoundNoteThreshold(swarm.env ?? process.env),
525
+ model: () => this.model,
526
+ canDeliver: () => !this.completed && !this.aborted,
527
+ inject: (note) => host.sessions.synthetic({
528
+ sessionID: _sessionId,
529
+ text: note,
530
+ delivery: "steer",
531
+ resume: false
532
+ })
533
+ });
516
534
  }
517
535
  get sessionId() {
518
536
  return this._sessionId;
@@ -624,6 +642,7 @@ class OpencodeSession {
624
642
  this.steps++;
625
643
  const t = ev.data.tokens;
626
644
  const contextUsed = t.input + t.cache.read + t.cache.write + t.output;
645
+ this.observeContextBound(t.input + t.cache.read + t.cache.write);
627
646
  const contextTotal = getContextWindowSize(this.model || "default");
628
647
  if (contextTotal > 0 && contextUsed > 0) {
629
648
  this.emit({
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  registerTemplate,
3
3
  init_registry
4
- } from "./cli-tx00c0h6.js";
4
+ } from "./cli-dqygeeh5.js";
5
5
  import {
6
6
  __esm
7
7
  } from "./cli-242037k3.js";