@desplega.ai/agent-swarm 1.162.0 → 1.164.0

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 (240) hide show
  1. package/README.md +2 -1
  2. package/dist/{acp-adapter-74m73ae9.js → acp-adapter-8t22d18g.js} +2 -2
  3. package/dist/{actions-4sr14gnt.js → actions-49xrhww7.js} +32 -29
  4. package/dist/amp-adapter-p230tajt.js +34 -0
  5. package/dist/{anthropic-messages-8xxrzky9.js → anthropic-messages-hst62ws9.js} +3 -3
  6. package/dist/{app-pt68fbwp.js → app-tgzw3f3d.js} +11 -10
  7. package/dist/{assistant-cv3jytks.js → assistant-dgfjm07j.js} +33 -30
  8. package/dist/{azure-openai-responses-f5cqsyj8.js → azure-openai-responses-mh8tvf78.js} +9 -68
  9. package/dist/{boot-reembed-4ht4gqth.js → boot-reembed-0qzs614r.js} +13 -12
  10. package/dist/{boot-reembed-nxpcvpj9.js → boot-reembed-dgp6peyx.js} +12 -11
  11. package/dist/{boot-scrub-logs-k93kyw8k.js → boot-scrub-logs-fxnk021a.js} +10 -9
  12. package/dist/{boot-seeds-1skcrs0e.js → boot-seeds-xe7adjvm.js} +14 -13
  13. package/dist/{claude-adapter-r5g0tzge.js → claude-adapter-hx0n8a31.js} +22 -20
  14. package/dist/{claude-managed-adapter-yxkfxg8j.js → claude-managed-adapter-hskapeen.js} +3 -3
  15. package/dist/{claude-managed-setup-pkyrgshb.js → claude-managed-setup-p7mt6dfq.js} +1 -1
  16. package/dist/{claude-sdk-session-jxyxnrwd.js → claude-sdk-session-d61a9c8x.js} +22 -20
  17. package/dist/{cli-twrh04ap.js → cli-0y30kqz4.js} +3 -3
  18. package/dist/{cli-5xhpb3kv.js → cli-0z9dj97t.js} +9 -9
  19. package/dist/{cli-t845n9xk.js → cli-1nzb8ftr.js} +2 -2
  20. package/dist/{cli-kdkwd3yr.js → cli-1wd1n2ya.js} +38 -10
  21. package/dist/{cli-vxe6qa4h.js → cli-23az412e.js} +1 -1
  22. package/dist/{cli-bsky8g7w.js → cli-26x4d89j.js} +1 -1
  23. package/dist/{cli-swfmp1fx.js → cli-2ar0x7cz.js} +9 -9
  24. package/dist/cli-2ksgp01n.js +933 -0
  25. package/dist/{cli-rnyzn44p.js → cli-2zhhnz2h.js} +1 -1
  26. package/dist/{cli-vc9bp061.js → cli-3qaw32we.js} +5 -5
  27. package/dist/{cli-vy3ed88x.js → cli-402m8btc.js} +31 -3
  28. package/dist/{cli-5bcd7sfy.js → cli-43fh8fzw.js} +3 -3
  29. package/dist/{cli-5k6k8ta3.js → cli-4f7s6k3q.js} +13 -5
  30. package/dist/{cli-sqvfa090.js → cli-4ntg6tkp.js} +6 -5
  31. package/dist/{cli-kh04eqwe.js → cli-4y9bnpvy.js} +1 -1
  32. package/dist/{cli-qjjvzwzd.js → cli-5c2j5yvx.js} +1 -1
  33. package/dist/{cli-2zy95vhm.js → cli-6891ft0y.js} +2 -2
  34. package/dist/{cli-tre4bdgq.js → cli-6behs2bt.js} +1 -1
  35. package/dist/cli-7mm2r1kp.js +17 -0
  36. package/dist/cli-7xcgj20z.js +68 -0
  37. package/dist/{cli-4cwxn7gp.js → cli-812vt3ht.js} +2 -2
  38. package/dist/{cli-mbssg1xv.js → cli-8kt0bmgx.js} +1 -1
  39. package/dist/{cli-wjgs5wxe.js → cli-8rpq35c0.js} +7 -7
  40. package/dist/{cli-jxs2ygaw.js → cli-9m8fk2v7.js} +74 -29
  41. package/dist/{cli-pkd6s2wy.js → cli-9q3wt23f.js} +2 -2
  42. package/dist/{cli-s3hwpt9v.js → cli-9s6fsg07.js} +30 -10
  43. package/dist/{cli-xqpk3rp7.js → cli-9x3bwfd3.js} +28 -5
  44. package/dist/{cli-qrgt5bqf.js → cli-agamgm0p.js} +1 -1
  45. package/dist/{cli-13hw4z91.js → cli-b0f70z24.js} +1 -1
  46. package/dist/{cli-gpqpmns7.js → cli-cgrvsz2t.js} +2 -2
  47. package/dist/{cli-2hhfhfq5.js → cli-cn53e7vc.js} +8 -1
  48. package/dist/{cli-p0r8sxj5.js → cli-crjazzsg.js} +222 -4
  49. package/dist/{cli-tcen9p5w.js → cli-d37n8b7c.js} +5 -5
  50. package/dist/{cli-wxkkd0e0.js → cli-dgh781z9.js} +3 -3
  51. package/dist/cli-dsdg2wrk.js +516 -0
  52. package/dist/{cli-q24re23n.js → cli-e2xnc4m5.js} +4 -4
  53. package/dist/{cli-f7kvq46p.js → cli-erxeg64j.js} +20 -0
  54. package/dist/{cli-8ev9xqnx.js → cli-fajbc7sa.js} +17 -219
  55. package/dist/{cli-g739zqzt.js → cli-fj86xr3c.js} +2 -2
  56. package/dist/{cli-zvhd3f64.js → cli-fpbvcf55.js} +3 -3
  57. package/dist/{cli-kp42yek0.js → cli-fyra5y8k.js} +424 -71
  58. package/dist/{cli-jyy6pm2f.js → cli-g3qgrzck.js} +15 -3
  59. package/dist/{cli-eg0b3p0k.js → cli-g5erf0zt.js} +23 -14
  60. package/dist/{cli-cvatsam7.js → cli-gcvzvq3e.js} +4 -4
  61. package/dist/{cli-89s4ngw3.js → cli-gvcgmx69.js} +1 -1
  62. package/dist/{cli-7tre70zp.js → cli-j261c831.js} +138 -128
  63. package/dist/{cli-sptrj5f5.js → cli-j3me0jw2.js} +2 -2
  64. package/dist/{cli-zxqx25nz.js → cli-k6w44yvq.js} +6 -6
  65. package/dist/cli-ndx5yz5n.js +3299 -0
  66. package/dist/{cli-ykk5jaax.js → cli-nexwh8zg.js} +34 -29
  67. package/dist/{cli-rfjw9jw2.js → cli-ng97fjq7.js} +2 -2
  68. package/dist/{cli-4x0csdjq.js → cli-ngne1dng.js} +2 -2
  69. package/dist/{cli-4dcpaefp.js → cli-pfzrhb8n.js} +2 -2
  70. package/dist/{cli-hb5c2x5y.js → cli-q38n4bq0.js} +2 -2
  71. package/dist/{cli-cebmgwsc.js → cli-r109nq7n.js} +4 -4
  72. package/dist/{cli-nq7yqw7b.js → cli-t7g0vmtc.js} +4 -4
  73. package/dist/{cli-jf7wmv1r.js → cli-tsvj33y0.js} +58 -19
  74. package/dist/{cli-7af8yhav.js → cli-vbr859rz.js} +7 -4
  75. package/dist/{cli-nt8hecg9.js → cli-wk3v6h55.js} +67 -38
  76. package/dist/{cli-vyqs9ya8.js → cli-wwvk0tsy.js} +7 -7
  77. package/dist/{cli-rj0gqwwp.js → cli-y2de3bzp.js} +1 -1
  78. package/dist/{cli-hmsw1gpy.js → cli-y74170pb.js} +4 -4
  79. package/dist/cli-ydt3zkwv.js +70 -0
  80. package/dist/{cli-xk79303e.js → cli-yj790e19.js} +9 -1
  81. package/dist/cli-zt3w1cn1.js +137 -0
  82. package/dist/{cli-trc24wk2.js → cli-zxg80zs9.js} +1 -1
  83. package/dist/cli.js +23 -22
  84. package/dist/{cloudflare-workers-ai-system-one-k8ddqjkq.js → cloudflare-workers-ai-system-one-tt484t61.js} +2 -2
  85. package/dist/{codex-adapter-esvmnhn7.js → codex-adapter-e3pky8aj.js} +14 -13
  86. package/dist/{codex-hook-m73jmqgx.js → codex-hook-b1fb7c2k.js} +4 -3
  87. package/dist/{codex-session-runner-ban9excr.js → codex-session-runner-1gq27w2t.js} +14 -13
  88. package/dist/{commands-75413p2n.js → commands-q07ezjzn.js} +10 -9
  89. package/dist/cursor-adapter-50cz7yba.js +32 -0
  90. package/dist/{db-7f5pecwg.js → db-wwt0sq9q.js} +18 -9
  91. package/dist/{dispatcher-fh9at8nz.js → dispatcher-wrg35vdd.js} +31 -28
  92. package/dist/{dsh-adapter-wpze65d4.js → dsh-adapter-sa6rxfpc.js} +6 -6
  93. package/dist/{e2b-gjgdjp91.js → e2b-v5np73yj.js} +4 -4
  94. package/dist/{easter-egg-3d-3w5c2n4c.js → easter-egg-3d-h2hx9b64.js} +2 -2
  95. package/dist/{event-bus-sfx8dx3t.js → event-bus-vkbhzt4n.js} +1 -1
  96. package/dist/{execute-f50wg9nh.js → execute-6gczxy8v.js} +42 -13
  97. package/dist/{google-generative-ai-jxxpnegy.js → google-generative-ai-d6nphg3q.js} +3 -3
  98. package/dist/{google-vertex-x7q1angm.js → google-vertex-cpshkref.js} +3 -3
  99. package/dist/{handlers-w13787bb.js → handlers-rv3gxvsp.js} +34 -31
  100. package/dist/{hook-46g1jrvx.js → hook-bcf5m80y.js} +15 -13
  101. package/dist/{hook-4tpts2ry.js → hook-z8b1jm2d.js} +16 -14
  102. package/dist/{http-19pzbfrt.js → http-56f7yt97.js} +932 -134
  103. package/dist/{index-scptvdxg.js → index-0kncjnrm.js} +30 -23
  104. package/dist/{index-dqmp15bq.js → index-1e6cg96n.js} +31 -28
  105. package/dist/{index-qb4q1y3e.js → index-8xgdb3k8.js} +31 -28
  106. package/dist/index-adw4zr9j.js +1020 -0
  107. package/dist/{index-h5gs261z.js → index-etdrp7yp.js} +140 -140
  108. package/dist/{index-8fd4dm4h.js → index-f9zscmft.js} +32 -29
  109. package/dist/index-fdk1t4d6.js +91297 -0
  110. package/dist/{index-s75wc4wd.js → index-jvb37h77.js} +12 -11
  111. package/dist/{keepalive-xa5ts9cd.js → keepalive-rp8daj4s.js} +12 -11
  112. package/dist/{lead-qp4xkvjq.js → lead-dfp77erc.js} +45 -40
  113. package/dist/{maintenance-rm5885hm.js → maintenance-wtmw3jqv.js} +13 -12
  114. package/dist/{mistral-conversations-rw7fbt22.js → mistral-conversations-8445ddjn.js} +2 -2
  115. package/dist/{oauth-refresh-sweep-1csdfebf.js → oauth-refresh-sweep-yhzqt95v.js} +11 -10
  116. package/dist/{onboard-r6b78cs4.js → onboard-9z8rwbcy.js} +2 -2
  117. package/dist/{openai-codex-responses-efvrgrq3.js → openai-codex-responses-9ynm88zy.js} +3 -3
  118. package/dist/{openai-completions-bbbrrz4z.js → openai-completions-nhqwjmaw.js} +2 -2
  119. package/dist/{openai-responses-9jjyrcm1.js → openai-responses-xx1c4kgm.js} +3 -3
  120. package/dist/{opencode-adapter-kb3g6pkf.js → opencode-adapter-1nxb6555.js} +5 -5
  121. package/dist/{otel-impl-0y9knpky.js → otel-impl-b83gaxw2.js} +1 -1
  122. package/dist/{pi-mono-adapter-z6s1bme2.js → pi-mono-adapter-ddxz8pjp.js} +18 -17
  123. package/dist/{pricing-refresh-mth26tgp.js → pricing-refresh-tmjvazb6.js} +12 -11
  124. package/dist/{rbac-roles-kwntb23q.js → rbac-roles-pa0gzjws.js} +11 -10
  125. package/dist/{rbac-roles-vpk4ebm8.js → rbac-roles-rhexa9s2.js} +12 -11
  126. package/dist/{render-v2-hcm7h00y.js → render-v2-ask84n8y.js} +11 -10
  127. package/dist/{runtime-vfjsfsc5.js → runtime-ckjnj3vf.js} +4 -4
  128. package/dist/{setup-hbyzd65h.js → setup-5ga5gdsy.js} +2 -2
  129. package/dist/{typesafe-system-one-2ef30pec.js → typesafe-system-one-datfr82p.js} +2 -2
  130. package/dist/{virtual-modules-9bv7ry91.js → virtual-modules-bmp3zwjf.js} +12 -11
  131. package/dist/{work-objects-m09sxnhe.js → work-objects-snnh0t7j.js} +34 -31
  132. package/dist/{worker-0h35rvk4.js → worker-rxyymrhb.js} +45 -40
  133. package/openapi.json +997 -39
  134. package/package.json +6 -5
  135. package/src/be/db/active-sessions.ts +30 -0
  136. package/src/be/db/approvals.ts +54 -0
  137. package/src/be/db.ts +25 -4
  138. package/src/be/mcp-server-checked-update.ts +34 -0
  139. package/src/be/mcp-server-stdio-gate.ts +34 -0
  140. package/src/be/memory/key-browser.ts +304 -0
  141. package/src/be/memory/providers/sqlite-store.ts +16 -3
  142. package/src/be/migrations/194_memory_orphan_chunks.sql +15 -0
  143. package/src/be/migrations/195_approval_request_approvals.sql +6 -0
  144. package/src/be/model-validation.ts +12 -2
  145. package/src/be/multi-runtime.ts +4 -3
  146. package/src/be/pricing-normalize.ts +11 -0
  147. package/src/be/repo-checked-update.ts +37 -0
  148. package/src/be/repo-merge-policy.ts +15 -0
  149. package/src/be/seed-pricing.ts +48 -1
  150. package/src/be/swarm-config-guard.ts +1 -0
  151. package/src/commands/provider-credentials.ts +44 -2
  152. package/src/extensions/contract-types.generated.ts +1 -1
  153. package/src/extensions/contract.ts +100 -0
  154. package/src/extensions/dispatcher.ts +19 -0
  155. package/src/extensions/post-bridge.ts +191 -0
  156. package/src/github/handlers.ts +128 -2
  157. package/src/gitlab/workflow-action-name.ts +15 -0
  158. package/src/heartbeat/heartbeat.ts +4 -3
  159. package/src/http/active-sessions.ts +6 -5
  160. package/src/http/agents.ts +10 -1
  161. package/src/http/approval-requests.ts +271 -35
  162. package/src/http/index.ts +1 -1
  163. package/src/http/mcp-servers.ts +74 -50
  164. package/src/http/memory.ts +275 -6
  165. package/src/http/repos.ts +58 -18
  166. package/src/http/request-principal.ts +19 -0
  167. package/src/http/session-cost-recompute.ts +64 -0
  168. package/src/http/session-data.ts +11 -0
  169. package/src/http/tasks.ts +9 -1
  170. package/src/http/webhooks.ts +17 -5
  171. package/src/prompts/base-prompt.ts +9 -4
  172. package/src/prompts/resolver.ts +1 -1
  173. package/src/prompts/session-templates.ts +28 -0
  174. package/src/providers/amp-adapter.ts +1232 -0
  175. package/src/providers/cursor-adapter.ts +638 -0
  176. package/src/providers/index.ts +9 -1
  177. package/src/providers/pricing-sources.md +39 -0
  178. package/src/providers/reasoning-effort.ts +15 -1
  179. package/src/providers/types.ts +11 -1
  180. package/src/rbac/legacy-policy.ts +23 -8
  181. package/src/rbac/permissions.ts +27 -1
  182. package/src/scripts-runtime/types/swarm-extension.d.ts +119 -0
  183. package/src/tests/amp-adapter.test.ts +822 -0
  184. package/src/tests/amp-budget-export-failed.test.ts +133 -0
  185. package/src/tests/amp-pricing-helpers.ts +16 -0
  186. package/src/tests/amp-pricing.test.ts +218 -0
  187. package/src/tests/api-drain-worker-e2e.test.ts +18 -7
  188. package/src/tests/approval-respond-auth.test.ts +371 -0
  189. package/src/tests/base-prompt.test.ts +13 -0
  190. package/src/tests/claude-adapter-binary.test.ts +24 -0
  191. package/src/tests/claude-adapter.test.ts +8 -0
  192. package/src/tests/cursor-adapter.test.ts +690 -0
  193. package/src/tests/db-task-read-contract.test.ts +5 -0
  194. package/src/tests/db-task-write-contract.test.ts +5 -0
  195. package/src/tests/docs-index-footprint.test.js +3 -3
  196. package/src/tests/extensions-post-bridge.test.ts +669 -0
  197. package/src/tests/extensions-run-context.test.ts +61 -0
  198. package/src/tests/fixtures/fake-amp.ts +304 -0
  199. package/src/tests/github-handlers-inline-comments.test.ts +147 -1
  200. package/src/tests/gitlab-workflow-event-names.test.ts +136 -0
  201. package/src/tests/mcp-input-ergonomics.test.ts +15 -10
  202. package/src/tests/mcp-server-stdio-gate.test.ts +438 -0
  203. package/src/tests/memory-http-access.test.ts +221 -0
  204. package/src/tests/memory-keys-endpoint.test.ts +406 -0
  205. package/src/tests/memory-store.test.ts +166 -0
  206. package/src/tests/model-tier-resolution.test.ts +3 -3
  207. package/src/tests/pricing-refresh.test.ts +5 -4
  208. package/src/tests/prompt-template-session.test.ts +5 -3
  209. package/src/tests/provider-process-group.test.ts +41 -0
  210. package/src/tests/provider-registration.test.ts +3 -1
  211. package/src/tests/rbac-charact-misc-tools.test.ts +18 -3
  212. package/src/tests/rbac-engine.test.ts +15 -11
  213. package/src/tests/rbac-wire-e2e.test.ts +4 -9
  214. package/src/tests/repo-allow-merge-gate.test.ts +382 -0
  215. package/src/tests/script-connections.test.ts +4 -0
  216. package/src/tests/send-task-requester-gate.test.ts +260 -0
  217. package/src/tests/session-activity-liveness.test.ts +248 -0
  218. package/src/tests/session-costs-golden.test.ts +28 -0
  219. package/src/tests/webhooks-task-blocked.test.ts +4 -4
  220. package/src/tests/write-gate.ts +68 -0
  221. package/src/tests/x402-client.test.ts +124 -0
  222. package/src/tests/x402-spending-tracker.test.ts +66 -0
  223. package/src/tools/mcp-servers/mcp-server-create.ts +23 -1
  224. package/src/tools/mcp-servers/mcp-server-update.ts +46 -28
  225. package/src/tools/memory-delete.ts +3 -3
  226. package/src/tools/repos/update-repo.ts +26 -5
  227. package/src/tools/send-task.ts +24 -1
  228. package/src/tools/steer-task.ts +1 -1
  229. package/src/types.ts +37 -2
  230. package/src/utils/amp-models.ts +114 -0
  231. package/src/utils/credentials.ts +8 -0
  232. package/src/utils/process-group.ts +79 -0
  233. package/src/workflows/event-bus.ts +28 -0
  234. package/src/x402/client.ts +36 -14
  235. package/src/x402/spending-tracker.ts +64 -3
  236. package/templates/skills/agent-browser/SKILL.md +5 -0
  237. package/templates/skills/agent-browser/content.md +5 -0
  238. package/templates/skills/heartbeat-runbook/content.md +1 -0
  239. package/templates/skills/swarm-extensions/content.md +4 -0
  240. package/dist/cli-y89t4nca.js +0 -67
@@ -0,0 +1,516 @@
1
+ import {
2
+ resolveSlashSkillPrompt
3
+ } from "./cli-wgbezhw2.js";
4
+ import {
5
+ clampContextPercent,
6
+ getContextWindowSize
7
+ } from "./cli-6behs2bt.js";
8
+ import {
9
+ applyReasoningEffort
10
+ } from "./cli-cn53e7vc.js";
11
+ import {
12
+ swarmRuntimeInstanceId
13
+ } from "./cli-re8z5p8p.js";
14
+ import {
15
+ DEFAULT_MODEL_TIER_MAP,
16
+ init_types
17
+ } from "./cli-9x3bwfd3.js";
18
+ import {
19
+ init_session_templates
20
+ } from "./cli-g5erf0zt.js";
21
+ import {
22
+ init_resolver,
23
+ resolveTemplateAsync,
24
+ resolveTemplateFromCode
25
+ } from "./cli-5c2j5yvx.js";
26
+ import {
27
+ init_env_flag,
28
+ parseEnvFlag
29
+ } from "./cli-ej6gbxfb.js";
30
+ import {
31
+ cursorCatalogRef,
32
+ init_src
33
+ } from "./cli-g3qgrzck.js";
34
+ import {
35
+ init_secret_scrubber,
36
+ registerVolatileSecret,
37
+ scrubSecrets
38
+ } from "./cli-nexqx4ve.js";
39
+ import {
40
+ __require
41
+ } from "./cli-bc05qbss.js";
42
+
43
+ // src/providers/cursor-adapter.ts
44
+ init_src();
45
+ init_session_templates();
46
+ init_resolver();
47
+ init_types();
48
+ import { mkdtemp, rm } from "node:fs/promises";
49
+ import { tmpdir } from "node:os";
50
+ import { join } from "node:path";
51
+ init_env_flag();
52
+ init_secret_scrubber();
53
+ var CURSOR_SDK_VERSION = "1.0.36";
54
+ var CURSOR_MCP_SERVER_NAME = "agent-swarm";
55
+ var NATIVE_SYSTEM_PROMPT_ENV = "CURSOR_NATIVE_SYSTEM_PROMPT";
56
+ var FIRST_MESSAGE_TEMPLATE = "system.agent.cursor.first_message";
57
+ function checkCursorCredentials(env) {
58
+ return env.CURSOR_API_KEY?.trim() ? { ready: true, missing: [], satisfiedBy: "env" } : { ready: false, missing: ["CURSOR_API_KEY"], hint: "Set CURSOR_API_KEY for cursor." };
59
+ }
60
+ async function liveTestCursorKey(apiKey) {
61
+ const { Cursor } = await import("./index-fdk1t4d6.js");
62
+ try {
63
+ await Cursor.me({ apiKey });
64
+ return { ok: true };
65
+ } catch (error) {
66
+ return {
67
+ ok: false,
68
+ error: scrubSecrets(`Cursor rejected CURSOR_API_KEY: ${errorMessage(error)}`)
69
+ };
70
+ }
71
+ }
72
+ function errorMessage(error) {
73
+ return error instanceof Error ? error.message : String(error);
74
+ }
75
+ var MODEL_LIST_TTL_MS = 600000;
76
+ var modelListCache;
77
+ async function listCursorModels(apiKey) {
78
+ if (modelListCache?.key === apiKey && Date.now() - modelListCache.at < MODEL_LIST_TTL_MS) {
79
+ return modelListCache.models;
80
+ }
81
+ const { Cursor } = await import("./index-fdk1t4d6.js");
82
+ const models = await Cursor.models.list({ apiKey });
83
+ modelListCache = { key: apiKey, at: Date.now(), models };
84
+ return models;
85
+ }
86
+ var EFFORT_PARAM_IDS = ["reasoning_effort", "reasoning", "effort"];
87
+ var EFFORT_VALUE_ALIASES = {
88
+ off: ["none"],
89
+ low: ["low"],
90
+ medium: ["medium"],
91
+ high: ["high"],
92
+ xhigh: ["xhigh", "extra-high"],
93
+ max: ["max"]
94
+ };
95
+ function cursorModelSelection(modelId, effort, models) {
96
+ const item = models.find((m) => m.id === modelId || m.aliases?.includes(modelId));
97
+ const selection = { id: item?.id ?? modelId };
98
+ if (!effort || !item)
99
+ return { selection, appliedEffort: null };
100
+ const param = item.parameters?.find((p) => EFFORT_PARAM_IDS.includes(p.id));
101
+ const value = param?.values.map((v) => v.value).find((v) => EFFORT_VALUE_ALIASES[effort].includes(v));
102
+ if (param && value) {
103
+ selection.params = [{ id: param.id, value }];
104
+ return { selection, appliedEffort: effort };
105
+ }
106
+ const thinking = item.parameters?.find((p) => p.id === "thinking");
107
+ if (effort === "off" && thinking?.values.some((v) => v.value === "false")) {
108
+ selection.params = [{ id: "thinking", value: "false" }];
109
+ return { selection, appliedEffort: effort };
110
+ }
111
+ return { selection, appliedEffort: null };
112
+ }
113
+ function contextWindowFor(model) {
114
+ const { providerId, modelId } = cursorCatalogRef(model);
115
+ return providerId === "cursor" ? null : getContextWindowSize(`${providerId}/${modelId}`);
116
+ }
117
+ function uncachedInput(usage) {
118
+ return Math.max(0, usage.inputTokens - usage.cacheReadTokens - usage.cacheWriteTokens);
119
+ }
120
+ function translateCursorMessage(message) {
121
+ switch (message.type) {
122
+ case "assistant": {
123
+ const text = message.message.content.filter((block) => block.type === "text").map((block) => block.text).join("");
124
+ return text ? [{ type: "message", role: "assistant", content: text }] : [];
125
+ }
126
+ case "tool_call": {
127
+ const toolName = cursorToolName(message.name, message.args);
128
+ if (message.status === "running") {
129
+ return [
130
+ { type: "tool_start", toolCallId: message.call_id, toolName, args: message.args ?? {} }
131
+ ];
132
+ }
133
+ return [
134
+ {
135
+ type: "tool_end",
136
+ toolCallId: message.call_id,
137
+ toolName,
138
+ result: message.status === "error" ? { error: message.result } : message.result
139
+ }
140
+ ];
141
+ }
142
+ case "thinking":
143
+ return [{ type: "custom", name: "cursor_thinking", data: { text: message.text } }];
144
+ case "task":
145
+ return message.text ? [{ type: "progress", message: message.text }] : [];
146
+ default:
147
+ return [];
148
+ }
149
+ }
150
+ function cursorToolName(name, args) {
151
+ if (name !== "mcp" || !args || typeof args !== "object")
152
+ return name;
153
+ const { providerIdentifier, toolName } = args;
154
+ if (typeof toolName !== "string" || !toolName)
155
+ return name;
156
+ return `mcp__${typeof providerIdentifier === "string" && providerIdentifier ? providerIdentifier : CURSOR_MCP_SERVER_NAME}__${toolName}`;
157
+ }
158
+ async function composeFirstMessage(systemPrompt, prompt) {
159
+ if (!systemPrompt.trim())
160
+ return prompt;
161
+ const variables = { systemPrompt, prompt };
162
+ try {
163
+ const result = await resolveTemplateAsync(FIRST_MESSAGE_TEMPLATE, variables);
164
+ if (!result.skipped && result.text.trim())
165
+ return result.text;
166
+ } catch {}
167
+ return resolveTemplateFromCode(FIRST_MESSAGE_TEMPLATE, variables).text;
168
+ }
169
+ function isSystemPromptUnavailable(message) {
170
+ return Boolean(message?.includes("--system-prompt"));
171
+ }
172
+ var QUEUE_NOT_SENT = "cursor session ended before the queued message was sent";
173
+
174
+ class CursorSession {
175
+ agent;
176
+ info;
177
+ directory;
178
+ sessionId;
179
+ listeners = [];
180
+ pending = [];
181
+ startedAt = Date.now();
182
+ contextWindow;
183
+ currentRun;
184
+ queue = [];
185
+ ended = false;
186
+ aborted = false;
187
+ usage;
188
+ runs = 0;
189
+ output;
190
+ failure;
191
+ assistantText = "";
192
+ completion;
193
+ constructor(agent, firstMessage, info, directory) {
194
+ this.agent = agent;
195
+ this.info = info;
196
+ this.directory = directory;
197
+ this.contextWindow = contextWindowFor(info.model.id);
198
+ this.announce(info.recreateWithoutSystemPrompt ? "native" : "first-message");
199
+ this.completion = this.run(firstMessage);
200
+ }
201
+ announce(systemPrompt) {
202
+ this.sessionId = this.agent.agentId;
203
+ this.emit({ type: "session_init", sessionId: this.agent.agentId, provider: "cursor" });
204
+ this.emit({
205
+ type: "raw_log",
206
+ content: JSON.stringify({
207
+ type: "model",
208
+ provider: "cursor",
209
+ model: this.info.model,
210
+ systemPrompt
211
+ })
212
+ });
213
+ }
214
+ onEvent(listener) {
215
+ this.listeners.push(listener);
216
+ for (const event of this.pending.splice(0))
217
+ listener(event);
218
+ }
219
+ emit(event) {
220
+ if (this.listeners.length === 0)
221
+ this.pending.push(event);
222
+ else
223
+ for (const listener of this.listeners)
224
+ listener(event);
225
+ }
226
+ flushText() {
227
+ if (!this.assistantText)
228
+ return;
229
+ this.emit({ type: "message", role: "assistant", content: this.assistantText });
230
+ this.assistantText = "";
231
+ }
232
+ handle(message) {
233
+ this.emit({ type: "raw_log", content: scrubSecrets(JSON.stringify(message)) });
234
+ if (message.type === "status" && message.status === "ERROR" && message.message) {
235
+ this.failure = scrubSecrets(message.message);
236
+ }
237
+ for (const event of translateCursorMessage(message)) {
238
+ if (event.type === "message") {
239
+ this.assistantText += event.content;
240
+ continue;
241
+ }
242
+ this.flushText();
243
+ this.emit(event);
244
+ }
245
+ }
246
+ recordRun(usage, toolRounds) {
247
+ const calls = toolRounds + 1;
248
+ const used = Math.round((usage.inputTokens + usage.cacheWriteTokens + usage.outputTokens) / calls);
249
+ if (used <= 0)
250
+ return;
251
+ this.emit({
252
+ type: "context_usage",
253
+ contextUsedTokens: used,
254
+ contextTotalTokens: this.contextWindow,
255
+ contextPercent: clampContextPercent(used, this.contextWindow),
256
+ outputTokens: Math.round(usage.outputTokens / calls),
257
+ contextFormula: "peak-proxy"
258
+ });
259
+ }
260
+ addUsage(usage) {
261
+ if (!usage)
262
+ return;
263
+ const prev = this.usage;
264
+ this.usage = prev ? {
265
+ inputTokens: prev.inputTokens + usage.inputTokens,
266
+ outputTokens: prev.outputTokens + usage.outputTokens,
267
+ cacheReadTokens: prev.cacheReadTokens + usage.cacheReadTokens,
268
+ cacheWriteTokens: prev.cacheWriteTokens + usage.cacheWriteTokens,
269
+ totalTokens: prev.totalTokens + usage.totalTokens,
270
+ reasoningTokens: (prev.reasoningTokens ?? 0) + (usage.reasoningTokens ?? 0)
271
+ } : { ...usage };
272
+ }
273
+ buildCost(isError) {
274
+ if (!this.sessionId || !this.usage)
275
+ return;
276
+ return {
277
+ sessionId: this.sessionId,
278
+ taskId: this.info.taskId,
279
+ agentId: this.info.agentId,
280
+ totalCostUsd: 0,
281
+ inputTokens: uncachedInput(this.usage),
282
+ outputTokens: this.usage.outputTokens,
283
+ cacheReadTokens: this.usage.cacheReadTokens,
284
+ cacheWriteTokens: this.usage.cacheWriteTokens,
285
+ reasoningOutputTokens: this.usage.reasoningTokens || undefined,
286
+ durationMs: Date.now() - this.startedAt,
287
+ numTurns: this.runs,
288
+ model: this.info.model.id,
289
+ isError,
290
+ provider: "cursor"
291
+ };
292
+ }
293
+ async sendAndDrain(text, onAccepted) {
294
+ if (this.aborted)
295
+ return "cancelled";
296
+ let toolRounds = 0;
297
+ const run = await this.agent.send(text, {
298
+ onDelta: ({ update }) => {
299
+ if (update.type === "tool-requests-listed")
300
+ toolRounds += 1;
301
+ }
302
+ });
303
+ this.currentRun = run;
304
+ this.runs += 1;
305
+ if (this.aborted) {
306
+ await run.cancel().catch(() => {});
307
+ const result2 = await run.wait().catch(() => {
308
+ return;
309
+ });
310
+ this.addUsage(result2?.usage);
311
+ return "cancelled";
312
+ }
313
+ onAccepted?.();
314
+ for await (const message of run.stream())
315
+ this.handle(message);
316
+ this.flushText();
317
+ const result = await run.wait();
318
+ this.addUsage(result.usage);
319
+ if (result.usage)
320
+ this.recordRun(result.usage, toolRounds);
321
+ if (result.result)
322
+ this.output = result.result;
323
+ if (result.status === "error") {
324
+ this.failure = scrubSecrets(result.error?.message ?? this.failure ?? "cursor run failed");
325
+ }
326
+ return result.status;
327
+ }
328
+ async run(firstMessage) {
329
+ try {
330
+ let status = await this.sendAndDrain(firstMessage);
331
+ if (status === "error" && this.runs === 1 && !this.aborted && isSystemPromptUnavailable(this.failure)) {
332
+ const recreate = this.info.recreateWithoutSystemPrompt;
333
+ if (recreate) {
334
+ this.emit({
335
+ type: "progress",
336
+ message: "Cursor systemPrompt unavailable for this account; using the first message"
337
+ });
338
+ this.agent.close();
339
+ this.agent = await recreate();
340
+ this.announce("first-message");
341
+ this.failure = undefined;
342
+ this.output = undefined;
343
+ this.runs = 0;
344
+ status = await this.sendAndDrain(await composeFirstMessage(this.info.systemPrompt, firstMessage));
345
+ }
346
+ }
347
+ while (status === "finished" && !this.aborted) {
348
+ const next = this.queue.shift();
349
+ if (next === undefined)
350
+ break;
351
+ try {
352
+ status = await this.sendAndDrain(next.text, () => next.settle({ delivered: true, mode: "queue" }));
353
+ } finally {
354
+ next.settle({ delivered: false, reason: QUEUE_NOT_SENT });
355
+ }
356
+ }
357
+ this.ended = true;
358
+ const isError = this.aborted || status !== "finished";
359
+ const failureReason = isError ? this.aborted || status === "cancelled" ? "cursor session aborted" : this.failure || `cursor run ended with status ${status}` : undefined;
360
+ if (failureReason)
361
+ this.emit({ type: "error", message: failureReason });
362
+ const cost = this.buildCost(isError);
363
+ if (cost)
364
+ this.emit({ type: "result", cost, output: this.output, isError });
365
+ return {
366
+ exitCode: isError ? 1 : 0,
367
+ sessionId: this.sessionId,
368
+ cost,
369
+ output: this.output,
370
+ isError,
371
+ failureReason,
372
+ appliedReasoningEffort: this.info.appliedEffort
373
+ };
374
+ } catch (error) {
375
+ this.ended = true;
376
+ const failureReason = scrubSecrets(errorMessage(error));
377
+ this.emit({ type: "error", message: failureReason });
378
+ return {
379
+ exitCode: 1,
380
+ sessionId: this.sessionId,
381
+ cost: this.buildCost(true),
382
+ isError: true,
383
+ failureReason,
384
+ appliedReasoningEffort: this.info.appliedEffort
385
+ };
386
+ } finally {
387
+ this.ended = true;
388
+ this.settleQueued(QUEUE_NOT_SENT);
389
+ this.agent.close();
390
+ await rm(this.directory, { recursive: true, force: true });
391
+ }
392
+ }
393
+ settleQueued(reason) {
394
+ for (const item of this.queue.splice(0))
395
+ item.settle({ delivered: false, reason });
396
+ }
397
+ waitForCompletion() {
398
+ return this.completion;
399
+ }
400
+ async abort() {
401
+ this.aborted = true;
402
+ this.settleQueued("cursor session aborted before the queued message was sent");
403
+ const run = this.currentRun;
404
+ if (run && run.status === "running")
405
+ await run.cancel().catch(() => {});
406
+ }
407
+ async deliverSteering({ mode, text }) {
408
+ if (this.ended || this.aborted) {
409
+ return { delivered: false, reason: "cursor session already completed" };
410
+ }
411
+ const run = this.currentRun;
412
+ if (mode === "steer" && run?.steer && run.status === "running") {
413
+ try {
414
+ const outcome = await run.steer(text);
415
+ if (outcome === "complete_delivered")
416
+ return { delivered: true, mode: "steer" };
417
+ } catch (error) {
418
+ return { delivered: false, reason: scrubSecrets(errorMessage(error)) };
419
+ }
420
+ }
421
+ if (this.ended || this.aborted) {
422
+ return { delivered: false, reason: "cursor session already completed" };
423
+ }
424
+ return new Promise((resolve) => {
425
+ let settled = false;
426
+ this.queue.push({
427
+ text,
428
+ settle: (result) => {
429
+ if (settled)
430
+ return;
431
+ settled = true;
432
+ resolve(result);
433
+ }
434
+ });
435
+ });
436
+ }
437
+ }
438
+
439
+ class CursorAdapter {
440
+ name = "cursor";
441
+ traits = {
442
+ hasMcp: true,
443
+ hasToolSearch: false,
444
+ nativeSkillDiscovery: false,
445
+ hasLocalEnvironment: true,
446
+ steerModes: ["steer", "queue"]
447
+ };
448
+ async createSession(config) {
449
+ const env = { ...process.env, ...config.env };
450
+ const apiKey = env.CURSOR_API_KEY?.trim();
451
+ if (!apiKey)
452
+ throw new Error("cursor requires CURSOR_API_KEY");
453
+ registerVolatileSecret(apiKey, "CURSOR_API_KEY");
454
+ const { Agent, JsonlLocalAgentStore } = await import("./index-fdk1t4d6.js");
455
+ const modelId = config.model || DEFAULT_MODEL_TIER_MAP.cursor.regular;
456
+ const effort = applyReasoningEffort("cursor", modelId, config.reasoningEffort);
457
+ const requested = effort.kind === "cursor-effort" ? effort.reasoningEffort : undefined;
458
+ let models = [];
459
+ try {
460
+ models = await listCursorModels(apiKey);
461
+ } catch {}
462
+ const { selection, appliedEffort } = cursorModelSelection(modelId, requested, models);
463
+ const prompt = await resolveSlashSkillPrompt(config.prompt, {
464
+ providerLabel: "cursor",
465
+ skillsDir: join(env.HOME ?? "/home/worker", ".agents", "skills")
466
+ });
467
+ const runtimeInstanceId = swarmRuntimeInstanceId();
468
+ const swarmMcp = {
469
+ type: "http",
470
+ url: `${config.apiUrl}/mcp`,
471
+ headers: {
472
+ Authorization: `Bearer ${config.apiKey}`,
473
+ "X-Agent-ID": config.agentId,
474
+ "X-Source-Task-Id": config.taskId,
475
+ ...config.contextKey ? { "X-Context-Key": config.contextKey } : {},
476
+ ...runtimeInstanceId ? { "X-Runtime-Instance-ID": runtimeInstanceId } : {}
477
+ }
478
+ };
479
+ const directory = await mkdtemp(join(tmpdir(), "swarm-cursor-"));
480
+ const nativeSystemPrompt = parseEnvFlag(env[NATIVE_SYSTEM_PROMPT_ENV], false);
481
+ const create = (withSystemPrompt) => Agent.create({
482
+ apiKey,
483
+ model: selection,
484
+ name: `swarm-${config.taskId}`,
485
+ mcpServers: { [CURSOR_MCP_SERVER_NAME]: swarmMcp },
486
+ ...withSystemPrompt && config.systemPrompt ? { systemPrompt: config.systemPrompt } : {},
487
+ local: {
488
+ cwd: config.cwd,
489
+ store: new JsonlLocalAgentStore(directory),
490
+ sandboxOptions: { enabled: false }
491
+ }
492
+ });
493
+ try {
494
+ const agent = await create(nativeSystemPrompt);
495
+ return new CursorSession(agent, nativeSystemPrompt ? prompt : await composeFirstMessage(config.systemPrompt, prompt), {
496
+ model: selection,
497
+ appliedEffort,
498
+ taskId: config.taskId,
499
+ agentId: config.agentId,
500
+ systemPrompt: config.systemPrompt,
501
+ recreateWithoutSystemPrompt: nativeSystemPrompt ? () => create(false) : undefined
502
+ }, directory);
503
+ } catch (error) {
504
+ await rm(directory, { recursive: true, force: true });
505
+ throw new Error(scrubSecrets(`cursor agent create failed: ${errorMessage(error)}`));
506
+ }
507
+ }
508
+ async canResume(_sessionId) {
509
+ return false;
510
+ }
511
+ formatCommand(commandName) {
512
+ return `/${commandName}`;
513
+ }
514
+ }
515
+
516
+ export { CURSOR_SDK_VERSION, checkCursorCredentials, liveTestCursorKey, cursorModelSelection, translateCursorMessage, composeFirstMessage, CursorAdapter };
@@ -17,13 +17,13 @@ import {
17
17
  recoverIncompleteRuns,
18
18
  repointTrackerSyncBySwarmId,
19
19
  resolveLeadOnlyRecoveryAssignment
20
- } from "./cli-kp42yek0.js";
20
+ } from "./cli-fyra5y8k.js";
21
21
  import {
22
22
  isMultiRuntimeEnabled
23
23
  } from "./cli-re8z5p8p.js";
24
24
  import {
25
25
  createApprovalFollowUpTask
26
- } from "./cli-5xhpb3kv.js";
26
+ } from "./cli-0z9dj97t.js";
27
27
  import {
28
28
  MAX_EMPTY_POLLS,
29
29
  assignUnassignedTaskPending,
@@ -74,13 +74,13 @@ import {
74
74
  settleSupersededTaskDependents,
75
75
  supersedeTask,
76
76
  updateAgentStatus
77
- } from "./cli-jf7wmv1r.js";
77
+ } from "./cli-tsvj33y0.js";
78
78
  import {
79
79
  init_registry,
80
80
  init_resolver,
81
81
  registerTemplate,
82
82
  resolveTemplate
83
- } from "./cli-qjjvzwzd.js";
83
+ } from "./cli-5c2j5yvx.js";
84
84
  import {
85
85
  init_env_flag,
86
86
  isEnvFlagEnabled
@@ -10,11 +10,18 @@ import {
10
10
  // src/workflows/event-bus.ts
11
11
  class InProcessEventBus {
12
12
  bus;
13
+ prefixHandlers = new Map;
13
14
  constructor(bus = new InProcessBus) {
14
15
  this.bus = bus;
15
16
  }
16
17
  emit(event, data) {
17
18
  this.bus.publish(`workflow:${event}`, data);
19
+ for (const [prefix, handlers] of this.prefixHandlers) {
20
+ if (!event.startsWith(prefix))
21
+ continue;
22
+ for (const handler of [...handlers])
23
+ handler(event, data);
24
+ }
18
25
  }
19
26
  on(event, handler) {
20
27
  this.bus.subscribe(`workflow:${event}`, handler);
@@ -22,6 +29,19 @@ class InProcessEventBus {
22
29
  off(event, handler) {
23
30
  this.bus.unsubscribe(`workflow:${event}`, handler);
24
31
  }
32
+ onPrefix(prefix, handler) {
33
+ const handlers = this.prefixHandlers.get(prefix) ?? new Set;
34
+ handlers.add(handler);
35
+ this.prefixHandlers.set(prefix, handlers);
36
+ }
37
+ offPrefix(prefix, handler) {
38
+ const handlers = this.prefixHandlers.get(prefix);
39
+ if (!handlers)
40
+ return;
41
+ handlers.delete(handler);
42
+ if (handlers.size === 0)
43
+ this.prefixHandlers.delete(prefix);
44
+ }
25
45
  }
26
46
  var workflowEventBus;
27
47
  var init_event_bus = __esm(() => {