@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
@@ -7,16 +7,14 @@ import {
7
7
  buildClaudeShortnameMap,
8
8
  init_src2
9
9
  } from "./cli-nwyw3zhg.js";
10
+ import {
11
+ __esm
12
+ } from "./cli-242037k3.js";
10
13
 
11
14
  // src/utils/context-window.ts
12
- init_src2();
13
- init_runtime_model_catalog();
14
- var CONTEXT_FORMULA = "input-cache-output";
15
- var DEFAULT_CONTEXT_WINDOW = 200000;
16
15
  function stripAnthropicDateSuffix(model) {
17
16
  return model.replace(/-(\d{8})$/, "");
18
17
  }
19
- var shortnameMap = null;
20
18
  function resolveClaudeShortname(model) {
21
19
  const section = runtimeCatalogSection("anthropic");
22
20
  if (!shortnameMap || shortnameMap.section !== section) {
@@ -29,8 +27,11 @@ function catalogContext(provider, model) {
29
27
  return typeof context === "number" && context > 0 ? context : undefined;
30
28
  }
31
29
  function getContextWindowSize(model) {
30
+ return getKnownContextWindowSize(model) ?? DEFAULT_CONTEXT_WINDOW;
31
+ }
32
+ function getKnownContextWindowSize(model) {
32
33
  if (!model)
33
- return DEFAULT_CONTEXT_WINDOW;
34
+ return;
34
35
  const slash = model.indexOf("/");
35
36
  if (slash > 0) {
36
37
  const scoped = catalogContext(model.slice(0, slash), model.slice(slash + 1));
@@ -49,12 +50,9 @@ function getContextWindowSize(model) {
49
50
  return dated;
50
51
  }
51
52
  const shortname = resolveClaudeShortname(model);
52
- if (shortname) {
53
- const resolved = catalogContext("anthropic", shortname);
54
- if (resolved)
55
- return resolved;
56
- }
57
- return DEFAULT_CONTEXT_WINDOW;
53
+ if (shortname)
54
+ return catalogContext("anthropic", shortname);
55
+ return;
58
56
  }
59
57
  function computeContextUsedUnified(parts) {
60
58
  return (parts.inputTokens ?? 0) + (parts.cacheReadTokens ?? 0) + (parts.cacheCreateTokens ?? 0) + (parts.outputTokens ?? 0);
@@ -67,5 +65,10 @@ function clampContextPercent(used, total) {
67
65
  return null;
68
66
  return Math.min(100, Math.max(0, raw));
69
67
  }
68
+ var CONTEXT_FORMULA = "input-cache-output", DEFAULT_CONTEXT_WINDOW = 200000, shortnameMap = null;
69
+ var init_context_window = __esm(() => {
70
+ init_src2();
71
+ init_runtime_model_catalog();
72
+ });
70
73
 
71
- export { CONTEXT_FORMULA, getContextWindowSize, computeContextUsedUnified, clampContextPercent };
74
+ export { CONTEXT_FORMULA, getContextWindowSize, getKnownContextWindowSize, computeContextUsedUnified, clampContextPercent, init_context_window };
@@ -15,17 +15,17 @@ import {
15
15
  init_secret_registry,
16
16
  upsertSwarmConfig2,
17
17
  init_db3
18
- } from "./cli-kxawjrxg.js";
18
+ } from "./cli-jb30dzvk.js";
19
19
  import {
20
20
  createRuntimeProvider,
21
21
  init_runtime_providers
22
- } from "./cli-p859hcc8.js";
22
+ } from "./cli-dew6x255.js";
23
23
  import {
24
24
  closeSessionTokenConnections,
25
25
  init_session_token_connections,
26
26
  insertSessionToken,
27
27
  init_users
28
- } from "./cli-e8jyq7d8.js";
28
+ } from "./cli-6a1xg1p7.js";
29
29
  import {
30
30
  RuntimeControllerCreateSchema,
31
31
  RuntimeControllerUpdateSchema,
@@ -21,11 +21,11 @@ import {
21
21
  upsertSwarmConfig2,
22
22
  getResolvedConfig2,
23
23
  init_db3
24
- } from "./cli-kxawjrxg.js";
24
+ } from "./cli-jb30dzvk.js";
25
25
  import {
26
26
  createWorkerTaskFollowUp,
27
27
  canClaim
28
- } from "./cli-aecdcr77.js";
28
+ } from "./cli-asq5ydm4.js";
29
29
  import {
30
30
  getRuntimeController2,
31
31
  getRuntimeControllerTarget2,
@@ -36,7 +36,7 @@ import {
36
36
  getPoolForAgent2,
37
37
  resolvePoolDelivery2,
38
38
  init_db
39
- } from "./cli-vwn81jbs.js";
39
+ } from "./cli-19202kew.js";
40
40
  import {
41
41
  runtimeStaleThresholdMinutes,
42
42
  getRuntimeInstanceById,
@@ -44,7 +44,7 @@ import {
44
44
  markRuntimeTerminated,
45
45
  listRuntimeInstancesForAgent,
46
46
  listRuntimeInstancesForPool
47
- } from "./cli-jjznk3f7.js";
47
+ } from "./cli-gbfxp48k.js";
48
48
  import {
49
49
  isMultiRuntimeEnabled
50
50
  } from "./cli-e8xyjvfc.js";
@@ -59,11 +59,11 @@ import {
59
59
  canProvisionKind,
60
60
  createRuntimeProvider,
61
61
  init_runtime_providers
62
- } from "./cli-p859hcc8.js";
62
+ } from "./cli-dew6x255.js";
63
63
  import {
64
64
  mintRuntimeToken,
65
65
  init_users
66
- } from "./cli-e8jyq7d8.js";
66
+ } from "./cli-6a1xg1p7.js";
67
67
  import {
68
68
  TERMINAL_TASK_STATUSES,
69
69
  isTerminalTaskStatus,
@@ -524,7 +524,7 @@ async function recoverSessions(runtimeId, reason) {
524
524
  }
525
525
  if (!sessions.length)
526
526
  return;
527
- const { remediateTaskForDeadRuntime } = await import("./heartbeat-vtesda5d.js");
527
+ const { remediateTaskForDeadRuntime } = await import("./heartbeat-w3mntghj.js");
528
528
  for (const session of sessions) {
529
529
  try {
530
530
  const task = await getTaskById2(session.taskId);
@@ -1,7 +1,3 @@
1
- import {
2
- getContextWindowSize,
3
- clampContextPercent
4
- } from "./cli-a5ebc95n.js";
5
1
  import {
6
2
  swarmRuntimeInstanceId
7
3
  } from "./cli-e8xyjvfc.js";
@@ -11,6 +7,11 @@ import {
11
7
  import {
12
8
  applyReasoningEffort
13
9
  } from "./cli-bn0rewsy.js";
10
+ import {
11
+ getContextWindowSize,
12
+ clampContextPercent,
13
+ init_context_window
14
+ } from "./cli-0shx9j93.js";
14
15
  import {
15
16
  DEFAULT_MODEL_TIER_MAP,
16
17
  init_types
@@ -20,7 +21,7 @@ import {
20
21
  resolveTemplateAsync,
21
22
  init_resolver,
22
23
  init_session_templates
23
- } from "./cli-tx00c0h6.js";
24
+ } from "./cli-dqygeeh5.js";
24
25
  import {
25
26
  parseEnvFlag,
26
27
  init_env_flag
@@ -40,10 +41,11 @@ init_src2();
40
41
  init_session_templates();
41
42
  init_resolver();
42
43
  init_types();
44
+ init_context_window();
45
+ init_env_flag();
43
46
  import { mkdtemp, rm } from "node:fs/promises";
44
47
  import { tmpdir } from "node:os";
45
48
  import { join } from "node:path";
46
- init_env_flag();
47
49
  init_secret_scrubber();
48
50
  var CURSOR_MCP_SERVER_NAME = "agent-swarm";
49
51
  var NATIVE_SYSTEM_PROMPT_ENV = "CURSOR_NATIVE_SYSTEM_PROMPT";
@@ -0,0 +1,140 @@
1
+ import {
2
+ getKnownContextWindowSize,
3
+ clampContextPercent,
4
+ init_context_window
5
+ } from "./cli-0shx9j93.js";
6
+ import {
7
+ resolveTemplateFromCode,
8
+ resolveTemplateAsync,
9
+ init_resolver,
10
+ init_session_templates
11
+ } from "./cli-dqygeeh5.js";
12
+
13
+ // src/hooks/context-bound-note.ts
14
+ import { renameSync, writeFileSync } from "node:fs";
15
+ import { readFile, writeFile } from "node:fs/promises";
16
+
17
+ // src/prompts/context-bound-note.ts
18
+ init_session_templates();
19
+ init_resolver();
20
+ var CONTEXT_BOUND_NOTE_TEMPLATE = "system.agent.context.bound_note";
21
+ function contextShare(contextTokens, model) {
22
+ if (!model)
23
+ return "";
24
+ try {
25
+ init_context_window();
26
+ const window = getKnownContextWindowSize(model);
27
+ const percent = clampContextPercent(contextTokens, window);
28
+ if (!window || percent === null)
29
+ return "";
30
+ return ` (${Math.round(percent)}% of the ${window.toLocaleString("en-US")}-token window)`;
31
+ } catch {
32
+ return "";
33
+ }
34
+ }
35
+ async function renderContextBoundNote(contextTokens, model) {
36
+ const variables = {
37
+ contextTokens: Math.round(contextTokens).toLocaleString("en-US"),
38
+ contextShare: contextShare(contextTokens, model)
39
+ };
40
+ try {
41
+ const result = await resolveTemplateAsync(CONTEXT_BOUND_NOTE_TEMPLATE, variables);
42
+ return result.skipped ? "" : result.text;
43
+ } catch {
44
+ return resolveTemplateFromCode(CONTEXT_BOUND_NOTE_TEMPLATE, variables).text;
45
+ }
46
+ }
47
+
48
+ // src/hooks/context-bound-note.ts
49
+ function contextBoundNoteThreshold(env = process.env) {
50
+ const raw = env.CONTEXT_BOUND_NOTE_TOKENS?.trim();
51
+ if (!raw || !/^\d+$/.test(raw))
52
+ return 0;
53
+ const parsed = Number(raw);
54
+ return Number.isSafeInteger(parsed) ? parsed : 0;
55
+ }
56
+ function reachesThreshold(contextTokens, threshold) {
57
+ return threshold > 0 && typeof contextTokens === "number" && Number.isFinite(contextTokens) && contextTokens >= threshold;
58
+ }
59
+ async function deliverContextBoundNote(contextTokens, model, inject) {
60
+ try {
61
+ const note = await renderContextBoundNote(contextTokens, model);
62
+ if (note)
63
+ await inject(note);
64
+ } catch {}
65
+ }
66
+ function contextStatePath(taskFilePath) {
67
+ return `${taskFilePath}.context.json`;
68
+ }
69
+ function contextBoundNoteMarkerPath(taskFilePath) {
70
+ return `${taskFilePath}.bound-note`;
71
+ }
72
+ function recordContextState(taskFilePath, contextTokens, model) {
73
+ const path = contextStatePath(taskFilePath);
74
+ const tmp = `${path}.tmp`;
75
+ try {
76
+ writeFileSync(tmp, JSON.stringify({ contextTokens, model, updatedAt: new Date().toISOString() }));
77
+ renameSync(tmp, path);
78
+ } catch {}
79
+ }
80
+ async function claimContextBoundNote(taskFilePath, threshold) {
81
+ if (!taskFilePath || threshold <= 0)
82
+ return null;
83
+ let contextTokens;
84
+ let model;
85
+ try {
86
+ const state = JSON.parse(await readFile(contextStatePath(taskFilePath), "utf8"));
87
+ contextTokens = state?.contextTokens;
88
+ model = state?.model;
89
+ } catch {
90
+ return null;
91
+ }
92
+ if (!reachesThreshold(contextTokens, threshold))
93
+ return null;
94
+ try {
95
+ await writeFile(contextBoundNoteMarkerPath(taskFilePath), new Date().toISOString(), {
96
+ flag: "wx"
97
+ });
98
+ } catch {
99
+ return null;
100
+ }
101
+ return { contextTokens, model: typeof model === "string" && model ? model : undefined };
102
+ }
103
+ async function injectClaimedContextBoundNote(taskFilePath, threshold, inject) {
104
+ const state = await claimContextBoundNote(taskFilePath, threshold).catch(() => null);
105
+ if (state)
106
+ await deliverContextBoundNote(state.contextTokens, state.model, inject);
107
+ }
108
+ function createContextBoundNote(options) {
109
+ let state = "idle";
110
+ let held = "";
111
+ const tryDeliver = async (note) => {
112
+ try {
113
+ if (!options.canDeliver()) {
114
+ held = note;
115
+ state = "held";
116
+ return;
117
+ }
118
+ state = "done";
119
+ await options.inject(note);
120
+ } catch {}
121
+ };
122
+ return async (contextTokens) => {
123
+ if (state === "held")
124
+ return tryDeliver(held);
125
+ if (state !== "idle" || !reachesThreshold(contextTokens, options.threshold))
126
+ return;
127
+ state = "rendering";
128
+ let note = "";
129
+ try {
130
+ note = await renderContextBoundNote(contextTokens, options.model?.());
131
+ } catch {}
132
+ if (!note) {
133
+ state = "done";
134
+ return;
135
+ }
136
+ await tryDeliver(note);
137
+ };
138
+ }
139
+
140
+ export { contextBoundNoteThreshold, contextStatePath, contextBoundNoteMarkerPath, recordContextState, injectClaimedContextBoundNote, createContextBoundNote };
@@ -4,7 +4,7 @@ import {
4
4
  import {
5
5
  normalizeOrgWebsite,
6
6
  init_org_website
7
- } from "./cli-kxawjrxg.js";
7
+ } from "./cli-jb30dzvk.js";
8
8
 
9
9
  // src/utils/lead-monitor-channels.ts
10
10
  function isLeadChannelMonitoringEnabled(env = process.env) {
@@ -1,21 +1,26 @@
1
1
  import {
2
2
  Anthropic
3
- } from "./cli-p6zs9h4y.js";
3
+ } from "./cli-rr7zx19j.js";
4
+ import {
5
+ contextBoundNoteThreshold,
6
+ createContextBoundNote
7
+ } from "./cli-2655k16q.js";
4
8
  import {
5
9
  checkToolLoop
6
10
  } from "./cli-0726awxw.js";
7
- import {
8
- CONTEXT_FORMULA,
9
- getContextWindowSize,
10
- computeContextUsedUnified,
11
- clampContextPercent
12
- } from "./cli-a5ebc95n.js";
13
11
  import {
14
12
  readPkgVersion
15
13
  } from "./cli-kr5tjjtz.js";
16
14
  import {
17
15
  createSwarmEventHandler
18
16
  } from "./cli-4zsenjhy.js";
17
+ import {
18
+ CONTEXT_FORMULA,
19
+ getContextWindowSize,
20
+ computeContextUsedUnified,
21
+ clampContextPercent,
22
+ init_context_window
23
+ } from "./cli-0shx9j93.js";
19
24
  import {
20
25
  runtimeCatalogModel,
21
26
  init_runtime_model_catalog
@@ -29,6 +34,7 @@ import {
29
34
  } from "./cli-nwyw3zhg.js";
30
35
 
31
36
  // src/providers/claude-managed-adapter.ts
37
+ init_context_window();
32
38
  init_secret_scrubber();
33
39
 
34
40
  // src/providers/claude-managed-models.ts
@@ -183,6 +189,9 @@ class ClaudeManagedSession {
183
189
  taskId;
184
190
  aborted = false;
185
191
  settled = false;
192
+ lastRequestContextTokens;
193
+ observeContextBound;
194
+ openToolCalls = new Set;
186
195
  constructor(client, sessionId, config, userMessageContent, seenEventIds = new Set) {
187
196
  this.client = client;
188
197
  this._sessionId = sessionId;
@@ -194,6 +203,12 @@ class ClaudeManagedSession {
194
203
  this.completionPromise = new Promise((resolve) => {
195
204
  this.resolveCompletion = resolve;
196
205
  });
206
+ this.observeContextBound = createContextBoundNote({
207
+ threshold: contextBoundNoteThreshold(config.env ?? process.env),
208
+ model: () => this.cost.model,
209
+ canDeliver: () => !this.settled && !this.aborted && this.openToolCalls.size > 0,
210
+ inject: (note) => this.deliverSteering({ mode: "steer", text: note })
211
+ });
197
212
  if (config.taskId && config.apiUrl && config.apiKey) {
198
213
  const abortRef = { current: this.abortController };
199
214
  const handler = createClaudeManagedSwarmEventHandler({
@@ -308,6 +323,8 @@ class ClaudeManagedSession {
308
323
  case "agent.tool_use": {
309
324
  const tu = event;
310
325
  this.runToolLoopCheck(tu.name, tu.input);
326
+ this.openToolCalls.add(tu.id);
327
+ this.observeContextBound(this.lastRequestContextTokens);
311
328
  this.emit({
312
329
  type: "tool_start",
313
330
  toolCallId: tu.id,
@@ -320,6 +337,8 @@ class ClaudeManagedSession {
320
337
  const tu = event;
321
338
  const fqToolName = `${tu.mcp_server_name}:${tu.name}`;
322
339
  this.runToolLoopCheck(fqToolName, tu.input);
340
+ this.openToolCalls.add(tu.id);
341
+ this.observeContextBound(this.lastRequestContextTokens);
323
342
  this.emit({
324
343
  type: "tool_start",
325
344
  toolCallId: tu.id,
@@ -330,6 +349,7 @@ class ClaudeManagedSession {
330
349
  }
331
350
  case "agent.tool_result": {
332
351
  const tr = event;
352
+ this.openToolCalls.delete(tr.tool_use_id);
333
353
  this.emit({
334
354
  type: "tool_end",
335
355
  toolCallId: tr.tool_use_id,
@@ -341,6 +361,7 @@ class ClaudeManagedSession {
341
361
  }
342
362
  case "agent.mcp_tool_result": {
343
363
  const tr = event;
364
+ this.openToolCalls.delete(tr.mcp_tool_use_id);
344
365
  this.emit({
345
366
  type: "tool_end",
346
367
  toolCallId: tr.mcp_tool_use_id,
@@ -372,6 +393,7 @@ class ClaudeManagedSession {
372
393
  case "span.model_request_end": {
373
394
  const sp = event;
374
395
  const usage = sp.model_usage;
396
+ this.lastRequestContextTokens = usage.input_tokens + usage.cache_read_input_tokens + usage.cache_creation_input_tokens;
375
397
  this.cost.inputTokens = (this.cost.inputTokens ?? 0) + usage.input_tokens;
376
398
  this.cost.outputTokens = (this.cost.outputTokens ?? 0) + usage.output_tokens;
377
399
  this.cost.cacheReadTokens = (this.cost.cacheReadTokens ?? 0) + usage.cache_read_input_tokens;
@@ -1,8 +1,3 @@
1
- import {
2
- CONTEXT_FORMULA,
3
- getContextWindowSize,
4
- clampContextPercent
5
- } from "./cli-a5ebc95n.js";
6
1
  import {
7
2
  swarmRuntimeInstanceId
8
3
  } from "./cli-e8xyjvfc.js";
@@ -18,6 +13,12 @@ import {
18
13
  reasoningCapability,
19
14
  applyReasoningEffort
20
15
  } from "./cli-bn0rewsy.js";
16
+ import {
17
+ CONTEXT_FORMULA,
18
+ getContextWindowSize,
19
+ clampContextPercent,
20
+ init_context_window
21
+ } from "./cli-0shx9j93.js";
21
22
  import {
22
23
  DEFAULT_MODEL_TIER_MAP,
23
24
  init_types
@@ -35,6 +36,7 @@ import {
35
36
 
36
37
  // src/providers/dsh-adapter.ts
37
38
  init_types();
39
+ init_context_window();
38
40
  import { mkdtemp, rm, writeFile } from "node:fs/promises";
39
41
  import { tmpdir } from "node:os";
40
42
  import { join } from "node:path";
@@ -2,7 +2,7 @@ import {
2
2
  isGrokOpenRouterModel,
3
3
  grokTargetProfile,
4
4
  ACPAdapter2
5
- } from "./cli-8s5wx3nz.js";
5
+ } from "./cli-m4ecdxvz.js";
6
6
  import {
7
7
  getOpenRouterBaseUrl,
8
8
  getOpenRouterAttributionHeaders,
@@ -5,10 +5,9 @@ import {
5
5
  postRatings
6
6
  } from "./cli-3h26v7yj.js";
7
7
  import {
8
- CONTEXT_FORMULA,
9
- computeContextUsedUnified,
10
- clampContextPercent
11
- } from "./cli-a5ebc95n.js";
8
+ contextBoundNoteThreshold,
9
+ createContextBoundNote
10
+ } from "./cli-2655k16q.js";
12
11
  import {
13
12
  SessionErrorTracker
14
13
  } from "./cli-gx4rm0qx.js";
@@ -46,6 +45,12 @@ import {
46
45
  import {
47
46
  createSwarmEventHandler
48
47
  } from "./cli-4zsenjhy.js";
48
+ import {
49
+ CONTEXT_FORMULA,
50
+ computeContextUsedUnified,
51
+ clampContextPercent,
52
+ init_context_window
53
+ } from "./cli-0shx9j93.js";
49
54
  import {
50
55
  hasCodexOAuthPoolSlots
51
56
  } from "./cli-j4bwnpkm.js";
@@ -60,7 +65,7 @@ import {
60
65
  import {
61
66
  init_package,
62
67
  package_default
63
- } from "./cli-y561h5a9.js";
68
+ } from "./cli-xtrz6bzs.js";
64
69
  import {
65
70
  isEnvFlagEnabled,
66
71
  isSessionSummarySkipped,
@@ -88,6 +93,7 @@ function codexUserHome() {
88
93
  import { existsSync as nodeExistsSync } from "node:fs";
89
94
  import { join as join2 } from "node:path";
90
95
  init_api_key();
96
+ init_context_window();
91
97
  init_env_flag();
92
98
  init_secret_scrubber();
93
99
 
@@ -1048,6 +1054,7 @@ class CodexSession {
1048
1054
  errorTracker = new SessionErrorTracker;
1049
1055
  appliedReasoningEffort;
1050
1056
  pendingResult = null;
1057
+ observeContextBound;
1051
1058
  constructor(thread, config, resolvedModel, initialEvents = [], skillsDir, summarizeDeps = {}) {
1052
1059
  this.thread = thread;
1053
1060
  this.config = config;
@@ -1056,6 +1063,12 @@ class CodexSession {
1056
1063
  this.skillsDir = skillsDir ?? process.env.CODEX_SKILLS_DIR ?? join2(codexUserHome(), ".codex", "skills");
1057
1064
  this.summarizeDeps = summarizeDeps;
1058
1065
  this.logFileHandle = Bun.file(config.logFile).writer();
1066
+ this.observeContextBound = createContextBoundNote({
1067
+ threshold: contextBoundNoteThreshold(config.env ?? process.env),
1068
+ model: () => this.resolvedModel,
1069
+ canDeliver: () => this.acceptsSteering && !this.settled && !this.aborted,
1070
+ inject: (note) => this.deliverSteering({ mode: "steer", text: note })
1071
+ });
1059
1072
  const reasoningApplication = applyReasoningEffort("codex", resolvedModel, config.reasoningEffort);
1060
1073
  this.appliedReasoningEffort = reasoningApplication.kind === "codex-config" ? config.reasoningEffort ?? null : null;
1061
1074
  this.completionPromise = new Promise((resolve) => {
@@ -1361,6 +1374,7 @@ class CodexSession {
1361
1374
  break;
1362
1375
  case "context.updated":
1363
1376
  this.emitContextUsage(event.usage, event.contextWindow ?? this.contextWindow);
1377
+ this.observeContextBound(event.usage.input_tokens);
1364
1378
  break;
1365
1379
  case "error": {
1366
1380
  const { message } = this.formatTerminalError(event.message, event.codexErrorInfo);
@@ -5,7 +5,7 @@ import {
5
5
  validateRuntimeTokenTtlHours,
6
6
  init_swarm_config_guard,
7
7
  init_db3
8
- } from "./cli-kxawjrxg.js";
8
+ } from "./cli-jb30dzvk.js";
9
9
  import {
10
10
  registerVolatileSecret,
11
11
  unregisterVolatileSecret,
@@ -285,6 +285,10 @@ async function mintRuntimeToken(agentId, runtimeId, ttlMs = runtimeTokenTtlMs())
285
285
  async function mintScriptRunToken(agentId, ttlMs) {
286
286
  return await insertSessionToken(agentId, null, null, ttlMs, null, undefined, null, null, true);
287
287
  }
288
+ async function isScriptRunToken(tokenId) {
289
+ const row = await getDbClient2().get("SELECT scriptRun FROM session_tokens WHERE id = ?", [tokenId]);
290
+ return row?.scriptRun === 1;
291
+ }
288
292
  async function insertSessionToken(agentId, taskId, runtimeId, ttlMs, parentRuntimeId = null, expiresAtCeiling, controllerId = null, parentTokenId = null, scriptRun = false) {
289
293
  const plaintext = `${SESSION_TOKEN_PREFIX}${base62(randomBytes(24))}`;
290
294
  const tokenId = randomUUID().replace(/-/g, "");
@@ -449,4 +453,4 @@ var init_users = __esm(() => {
449
453
  };
450
454
  });
451
455
 
452
- export { registerSessionTokenConnection, closeSessionTokenConnections, init_session_token_connections, findUserById, findUserByExternalId, findUserByEmail, findUsersByName, getUserIdentities, listUserEvents, listUserTokens, recordIdentityEvent, findOrCreateUserByEmail, linkIdentity, unlinkIdentity, mintToken, revokeToken, resolveUserByToken, InvalidRuntimeTokenError, mintSessionToken, mintRuntimeToken, mintScriptRunToken, insertSessionToken, revokeSessionToken, revokeRuntimeTokensForRuntime, AgentTokenExistsError, mintAgentToken, rotateAgentToken, revokeAgentTokens, resolveSessionToken, fingerprintApiKey, init_users };
456
+ export { registerSessionTokenConnection, closeSessionTokenConnections, init_session_token_connections, findUserById, findUserByExternalId, findUserByEmail, findUsersByName, getUserIdentities, listUserEvents, listUserTokens, recordIdentityEvent, findOrCreateUserByEmail, linkIdentity, unlinkIdentity, mintToken, revokeToken, resolveUserByToken, InvalidRuntimeTokenError, mintSessionToken, mintRuntimeToken, mintScriptRunToken, isScriptRunToken, insertSessionToken, revokeSessionToken, revokeRuntimeTokensForRuntime, AgentTokenExistsError, mintAgentToken, rotateAgentToken, revokeAgentTokens, resolveSessionToken, fingerprintApiKey, init_users };
@@ -40,14 +40,14 @@ import {
40
40
  getResolvedConfig2,
41
41
  getMcpServerById2,
42
42
  init_db3
43
- } from "./cli-kxawjrxg.js";
43
+ } from "./cli-jb30dzvk.js";
44
44
  import {
45
45
  generateRandomCodeVerifier,
46
46
  generateRandomState,
47
47
  calculatePKCECodeChallenge,
48
48
  oauthAppRowToProviderConfig,
49
49
  ensureAuthorizationTokenOrThrow
50
- } from "./cli-egjggehm.js";
50
+ } from "./cli-tsma7p8v.js";
51
51
  import {
52
52
  detachedProcessGroup,
53
53
  registerProcessGroup,
@@ -60,7 +60,7 @@ import {
60
60
  mintScriptRunToken,
61
61
  revokeSessionToken,
62
62
  init_users
63
- } from "./cli-e8jyq7d8.js";
63
+ } from "./cli-6a1xg1p7.js";
64
64
  import {
65
65
  defaultAssetKey,
66
66
  init_key
@@ -176111,7 +176111,7 @@ async function resolveSqlDsn(connection, agentId) {
176111
176111
  assertPostgresDsn(dsn);
176112
176112
  return dsn;
176113
176113
  }
176114
- var asTemplate = (text) => Object.assign([text], { raw: [text] });
176114
+ var asTemplate = (text) => Object.freeze(Object.defineProperty([text], "raw", { value: Object.freeze([text]) }));
176115
176115
  var defaultExecutor = async (dsn, query, params, take) => {
176116
176116
  const sql = new Bun.SQL({
176117
176117
  adapter: "postgres",
@@ -8,10 +8,14 @@ import {
8
8
  import {
9
9
  materializeClaudeMd,
10
10
  stopClaudeMd
11
- } from "./cli-ta8bd7th.js";
11
+ } from "./cli-pzatvw94.js";
12
12
  import {
13
13
  summarizeSession
14
14
  } from "./cli-mmhj8vd7.js";
15
+ import {
16
+ contextBoundNoteThreshold,
17
+ injectClaimedContextBoundNote
18
+ } from "./cli-2655k16q.js";
15
19
  import {
16
20
  guardGhPrBody,
17
21
  guardGhPrRoom
@@ -27,11 +31,11 @@ import {
27
31
  warnProfileFileTooLarge,
28
32
  buildIndependentIdentityPayloads,
29
33
  init_profile_sync
30
- } from "./cli-gpv60278.js";
34
+ } from "./cli-e42vss7b.js";
31
35
  import {
32
36
  init_package,
33
37
  package_default
34
- } from "./cli-y561h5a9.js";
38
+ } from "./cli-xtrz6bzs.js";
35
39
  import {
36
40
  MAX_PROFILE_FILE_LENGTH,
37
41
  getMcpBaseUrl,
@@ -833,6 +837,8 @@ You do not have a pre-defined agent ID, you will receive one when you join the s
833
837
  const maybeTaskId = msg.tool_response?.task?.id;
834
838
  outputToolContext("PostToolUse", `Task sent successfully.${maybeTaskId ? ` Task ID: ${maybeTaskId}.` : ""} Monitor progress using the get-task-details tool periodically.`);
835
839
  }
840
+ } else if (!msg.agent_id) {
841
+ await injectClaimedContextBoundNote(process.env.TASK_FILE, contextBoundNoteThreshold(), (note) => outputToolContext("PostToolUse", note));
836
842
  }
837
843
  }
838
844
  break;