@desplega.ai/agent-swarm 1.160.0 → 1.162.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.
- package/README.md +4 -3
- package/dist/{acp-adapter-2mjwcsfh.js → acp-adapter-74m73ae9.js} +163 -49
- package/dist/{actions-e43rxskr.js → actions-4sr14gnt.js} +42 -38
- package/dist/{anthropic-messages-5qx80j9k.js → anthropic-messages-8xxrzky9.js} +22 -26
- package/dist/{app-mc7xfagn.js → app-pt68fbwp.js} +17 -14
- package/dist/{artifact-3v5t9jtg.js → artifact-fey7dvj9.js} +3 -2
- package/dist/{assistant-sedkzv3b.js → assistant-cv3jytks.js} +43 -39
- package/dist/{azure-openai-responses-nfb21z9a.js → azure-openai-responses-f5cqsyj8.js} +15 -10
- package/dist/{boot-reembed-m3656j2n.js → boot-reembed-4ht4gqth.js} +17 -14
- package/dist/{boot-reembed-cqz9swn5.js → boot-reembed-nxpcvpj9.js} +16 -13
- package/dist/{boot-scrub-logs-xbxf5d7w.js → boot-scrub-logs-k93kyw8k.js} +13 -10
- package/dist/boot-seeds-1skcrs0e.js +32 -0
- package/dist/{claude-adapter-dc6289mc.js → claude-adapter-r5g0tzge.js} +39 -30
- package/dist/{claude-managed-adapter-naaw51me.js → claude-managed-adapter-yxkfxg8j.js} +6 -5
- package/dist/{claude-managed-setup-eacvchx0.js → claude-managed-setup-pkyrgshb.js} +27 -27
- package/dist/{claude-sdk-session-bqp2xvym.js → claude-sdk-session-jxyxnrwd.js} +8041 -7910
- package/dist/{cli-4derpgyk.js → cli-2hhfhfq5.js} +6 -1
- package/dist/{cli-rykfmgwg.js → cli-2x0e561b.js} +1 -1
- package/dist/{cli-tzx2ke1v.js → cli-2zy95vhm.js} +137 -64
- package/dist/{cli-0x01kwrd.js → cli-4cwxn7gp.js} +47 -186
- package/dist/{cli-xjcywfsf.js → cli-4dcpaefp.js} +12 -11
- package/dist/{cli-v7fn5gms.js → cli-4x0csdjq.js} +164 -76
- package/dist/{cli-12tszpk9.js → cli-5bcd7sfy.js} +91 -29
- package/dist/{cli-jz4w45qt.js → cli-5k6k8ta3.js} +190 -50
- package/dist/{cli-tpq83z89.js → cli-5xhpb3kv.js} +20 -19
- package/dist/{cli-r1mxd1xh.js → cli-7af8yhav.js} +6 -179
- package/dist/{cli-jajnsm8q.js → cli-7tre70zp.js} +18160 -31345
- package/dist/{cli-447dt1h3.js → cli-8ev9xqnx.js} +218 -25
- package/dist/cli-bsky8g7w.js +449 -0
- package/dist/{cli-0z2v4nhw.js → cli-cat6h73s.js} +1 -1
- package/dist/{cli-25fcq4b4.js → cli-cebmgwsc.js} +15 -11
- package/dist/{cli-shkxm1vn.js → cli-cvatsam7.js} +189 -13
- package/dist/{cli-2658f6at.js → cli-cvk6yzw5.js} +6 -8
- package/dist/cli-dbmwby6a.js +9 -0
- package/dist/{cli-ptr8h7kp.js → cli-eg0b3p0k.js} +5 -218
- package/dist/cli-f9w1semm.js +413 -0
- package/dist/{cli-523679eh.js → cli-g739zqzt.js} +6 -5
- package/dist/{cli-dv6cdjs2.js → cli-gd4favx9.js} +28 -7
- package/dist/{cli-c8a36vcc.js → cli-gpqpmns7.js} +2 -2
- package/dist/{cli-5nbmpy8w.js → cli-hb5c2x5y.js} +1 -1
- package/dist/{cli-741yb0xx.js → cli-hmsw1gpy.js} +55 -169
- package/dist/{cli-qydf22qq.js → cli-jf7wmv1r.js} +2562 -735
- package/dist/{cli-mfe5btp9.js → cli-jxs2ygaw.js} +317 -121
- package/dist/{cli-kmcpfwn2.js → cli-jyy6pm2f.js} +19 -3
- package/dist/cli-kdkwd3yr.js +615 -0
- package/dist/{cli-6cs6wzxt.js → cli-kh04eqwe.js} +2 -2
- package/dist/{cli-9hsgwz4w.js → cli-kp42yek0.js} +1309 -391
- package/dist/cli-ma3zvh39.js +10404 -0
- package/dist/{cli-ybgv4kw2.js → cli-mbssg1xv.js} +9 -2
- package/dist/{cli-jsp14b6c.js → cli-mzfth0bp.js} +38 -1
- package/dist/{cli-r2ap2czm.js → cli-nexqx4ve.js} +6 -0
- package/dist/{cli-f8gy6r2r.js → cli-nq7yqw7b.js} +19 -8
- package/dist/{cli-10nhj6xq.js → cli-nt8hecg9.js} +34 -33
- package/dist/cli-p0r8sxj5.js +303 -0
- package/dist/{cli-58e8yr0d.js → cli-pkd6s2wy.js} +4 -2
- package/dist/{cli-a8dvhzrt.js → cli-q24re23n.js} +7 -5
- package/dist/cli-qjjvzwzd.js +222 -0
- package/dist/cli-qrgt5bqf.js +189 -0
- package/dist/{cli-et8m9xsv.js → cli-rfjw9jw2.js} +22 -10
- package/dist/{cli-7e398j1h.js → cli-rj0gqwwp.js} +3 -3
- package/dist/{cli-btfv8y88.js → cli-rnyzn44p.js} +2 -2
- package/dist/{cli-d5czme6m.js → cli-s3hwpt9v.js} +4754 -4945
- package/dist/{cli-0jwe9034.js → cli-sptrj5f5.js} +3 -3
- package/dist/{cli-0q3avq3s.js → cli-sqvfa090.js} +19 -11
- package/dist/{cli-azhgzetg.js → cli-swfmp1fx.js} +27 -27
- package/dist/{cli-jyk0ynw2.js → cli-t845n9xk.js} +23 -10
- package/dist/{cli-zpep9q5e.js → cli-tcen9p5w.js} +20 -15
- package/dist/{cli-74h9hscv.js → cli-tre4bdgq.js} +1 -1
- package/dist/{cli-pm1rst0h.js → cli-twrh04ap.js} +30 -15
- package/dist/{cli-phsaj4xq.js → cli-v0pvvhfq.js} +1 -1
- package/dist/{cli-ydmcgve1.js → cli-vc9bp061.js} +5 -5
- package/dist/{cli-g2whhdrf.js → cli-vxe6qa4h.js} +1 -1
- package/dist/{cli-vctdqs5h.js → cli-vy3ed88x.js} +15 -2
- package/dist/{cli-br0qdrnp.js → cli-vyqs9ya8.js} +18 -18
- package/dist/{cli-cpvsaqsw.js → cli-w0bwte75.js} +8 -5
- package/dist/cli-wbvnn6tk.js +861 -0
- package/dist/{cli-r94z9p1z.js → cli-wgbezhw2.js} +3 -0
- package/dist/{cli-evvtk35y.js → cli-wjgs5wxe.js} +7 -7
- package/dist/cli-wxkkd0e0.js +33 -0
- package/dist/{cli-0wgxmwf6.js → cli-xk79303e.js} +20 -7
- package/dist/{cli-ktmyrtpn.js → cli-xqpk3rp7.js} +33 -10
- package/dist/{cli-ygwm91nt.js → cli-yy6dew39.js} +1 -1
- package/dist/cli-zp38xvtm.js +9487 -0
- package/dist/{cli-tfky2838.js → cli-zvhd3f64.js} +4 -4
- package/dist/{cli-jayjpjmb.js → cli-zxqx25nz.js} +66 -23
- package/dist/cli.js +40 -32
- package/dist/{cloudflare-workers-ai-system-one-k6fbxw9d.js → cloudflare-workers-ai-system-one-k8ddqjkq.js} +8 -6
- package/dist/{codex-adapter-nmxcatww.js → codex-adapter-esvmnhn7.js} +24 -23
- package/dist/{codex-hook-20me6byw.js → codex-hook-m73jmqgx.js} +19 -3
- package/dist/{codex-login-w6fz4xbz.js → codex-login-cf7mzsgg.js} +2 -2
- package/dist/{codex-session-runner-90aa80ev.js → codex-session-runner-ban9excr.js} +24 -23
- package/dist/{commands-8wcq1kn7.js → commands-75413p2n.js} +13 -10
- package/dist/{db-j40kc4se.js → db-7f5pecwg.js} +17 -10
- package/dist/{dispatcher-4zqy768d.js → dispatcher-fh9at8nz.js} +41 -37
- package/dist/dsh-adapter-wpze65d4.js +24 -0
- package/dist/{e2b-ez07znam.js → e2b-gjgdjp91.js} +12 -9
- package/dist/easter-egg-3d-3w5c2n4c.js +1057 -0
- package/dist/{execute-6e7qeyk4.js → execute-f50wg9nh.js} +203 -49
- package/dist/{google-generative-ai-k6n5nbpp.js → google-generative-ai-jxxpnegy.js} +2 -2
- package/dist/{google-vertex-44xxtcvp.js → google-vertex-x7q1angm.js} +5 -5
- package/dist/{handlers-kjdce1w5.js → handlers-w13787bb.js} +44 -40
- package/dist/{hook-r2t4bqfg.js → hook-46g1jrvx.js} +34 -20
- package/dist/{hook-czx13n12.js → hook-4tpts2ry.js} +25 -21
- package/dist/{http-3bbb19be.js → http-19pzbfrt.js} +1440 -283
- package/dist/{index-668me3f0.js → index-8fd4dm4h.js} +42 -38
- package/dist/{index-fg0dsp6c.js → index-dqmp15bq.js} +41 -37
- package/dist/{index-kkv84jq9.js → index-qb4q1y3e.js} +41 -37
- package/dist/index-s75wc4wd.js +33 -0
- package/dist/{index-zg7vp46x.js → index-scptvdxg.js} +64 -38
- package/dist/{keepalive-yra8dy57.js → keepalive-xa5ts9cd.js} +15 -12
- package/dist/{lead-va0pad2c.js → lead-qp4xkvjq.js} +59 -54
- package/dist/{maintenance-hqewtmyg.js → maintenance-rm5885hm.js} +17 -14
- package/dist/{mistral-conversations-pc3ntnxt.js → mistral-conversations-rw7fbt22.js} +4 -4
- package/dist/{node-a5e00qhp.js → node-8zkdq42h.js} +834 -833
- package/dist/node-f0ykebbv.js +2107 -0
- package/dist/node-wyamey5r.js +19 -0
- package/dist/{oauth-refresh-sweep-7rdt1m9n.js → oauth-refresh-sweep-1csdfebf.js} +14 -11
- package/dist/{onboard-j6ms6d0x.js → onboard-r6b78cs4.js} +10 -10
- package/dist/{openai-codex-responses-bbancrr0.js → openai-codex-responses-efvrgrq3.js} +4 -4
- package/dist/{openai-completions-jpaj5g2b.js → openai-completions-bbbrrz4z.js} +12 -8
- package/dist/{openai-responses-200k1wx4.js → openai-responses-9jjyrcm1.js} +15 -10
- package/dist/{opencode-adapter-89rabkw2.js → opencode-adapter-kb3g6pkf.js} +12 -9
- package/dist/{otel-impl-a792rjz0.js → otel-impl-0y9knpky.js} +6 -6
- package/dist/{pi-mono-adapter-g7qzvr3v.js → pi-mono-adapter-z6s1bme2.js} +128 -37
- package/dist/{pricing-refresh-wx0tp7cb.js → pricing-refresh-mth26tgp.js} +15 -12
- package/dist/{rbac-roles-8tzawacv.js → rbac-roles-kwntb23q.js} +17 -12
- package/dist/rbac-roles-vpk4ebm8.js +45 -0
- package/dist/{registry-v5wytg0s.js → registry-km6t1jd2.js} +1 -1
- package/dist/{render-v2-mm7zswb8.js → render-v2-hcm7h00y.js} +17 -14
- package/dist/{runtime-zyssgse0.js → runtime-vfjsfsc5.js} +5 -4
- package/dist/{setup-8y70ys6t.js → setup-hbyzd65h.js} +2 -2
- package/dist/{virtual-modules-6nmk7h3n.js → virtual-modules-9bv7ry91.js} +9 -7
- package/dist/{work-objects-fg6xkb0n.js → work-objects-m09sxnhe.js} +44 -40
- package/dist/{worker-wmwhxsph.js → worker-0h35rvk4.js} +59 -54
- package/dist/{x-n3e0v3xa.js → x-f1gt1pz3.js} +2 -2
- package/openapi.json +699 -26
- package/package.json +19 -11
- package/src/azure-devops/api.ts +121 -0
- package/src/azure-devops/auth.ts +78 -0
- package/src/azure-devops/handlers.ts +413 -0
- package/src/azure-devops/index.ts +27 -0
- package/src/azure-devops/templates.ts +108 -0
- package/src/azure-devops/types.ts +90 -0
- package/src/be/api-drain.ts +184 -0
- package/src/be/db/tasks/read.ts +32 -7
- package/src/be/db/tasks/write.ts +21 -4
- package/src/be/db-client.ts +11 -2
- package/src/be/db-retention.ts +95 -32
- package/src/be/db.ts +44 -19
- package/src/be/memory/constants.ts +16 -0
- package/src/be/memory/graph-expansion.ts +8 -1
- package/src/be/memory/index-content.ts +20 -1
- package/src/be/memory/key-guard.ts +93 -0
- package/src/be/memory/key-paths.ts +103 -0
- package/src/be/memory/link-resolver.ts +29 -3
- package/src/be/memory/providers/sqlite-store.ts +152 -45
- package/src/be/memory/raters/llm-summarizer.ts +10 -4
- package/src/be/memory/raters/llm.ts +15 -5
- package/src/be/memory/raters/store.ts +6 -3
- package/src/be/memory/raters/types.ts +11 -0
- package/src/be/memory/reranker.ts +38 -7
- package/src/be/memory/types.ts +12 -1
- package/src/be/migrations/190_memory_rating_model.sql +7 -0
- package/src/be/migrations/191_context_versions_previous_index.sql +8 -0
- package/src/be/migrations/192_favorites_agent_fs_path.sql +36 -0
- package/src/be/onboarding.ts +7 -1
- package/src/be/pricing-normalize.ts +4 -2
- package/src/be/scripts/typecheck.ts +4 -3
- package/src/be/seed-pricing.ts +16 -0
- package/src/be/seed-prompt-templates.ts +1 -0
- package/src/be/swarm-config-guard.ts +46 -17
- package/src/be/task-citations.ts +11 -5
- package/src/be/users.ts +3 -0
- package/src/cli.tsx +3 -2
- package/src/comb/agent-fs.ts +39 -0
- package/src/comb/config.ts +37 -0
- package/src/comb/markers.ts +37 -0
- package/src/comb/review-batch.ts +486 -0
- package/src/comb/templates.ts +88 -0
- package/src/commands/claude-managed-setup.ts +33 -31
- package/src/commands/context-preamble.ts +4 -1
- package/src/commands/hook.ts +2 -1
- package/src/commands/provider-credentials.ts +28 -15
- package/src/commands/runner.ts +458 -110
- package/src/commands/templates.ts +10 -0
- package/src/e2b/env.ts +2 -0
- package/src/extensions/catalog.generated.json +17 -0
- package/src/extensions/contract-types.generated.ts +1 -1
- package/src/fs/agent-fs-provider.ts +106 -2
- package/src/github/handlers.ts +10 -74
- package/src/github/reactions.ts +119 -138
- package/src/github/task-reactions.ts +34 -11
- package/src/heartbeat/heartbeat.ts +4 -0
- package/src/hooks/codex-hook.ts +25 -1
- package/src/hooks/hook.ts +14 -1
- package/src/hooks/pr-body-guard.ts +983 -0
- package/src/http/agents.ts +1 -1
- package/src/http/all-routes.ts +1 -0
- package/src/http/assets.ts +5 -17
- package/src/http/comb.ts +131 -0
- package/src/http/core.ts +14 -1
- package/src/http/extensions.ts +51 -27
- package/src/http/fs.ts +9 -17
- package/src/http/index.ts +27 -9
- package/src/http/mcp-user.ts +8 -13
- package/src/http/mcp.ts +19 -12
- package/src/http/memory.ts +80 -14
- package/src/http/onboarding.ts +21 -2
- package/src/http/poll.ts +30 -3
- package/src/http/realtime.ts +62 -0
- package/src/http/request-principal.ts +22 -0
- package/src/http/session-data.ts +6 -4
- package/src/http/stats.ts +1 -0
- package/src/http/status.ts +34 -2
- package/src/http/tasks.ts +17 -3
- package/src/http/users.ts +1 -1
- package/src/http/webhooks.ts +120 -2
- package/src/kv-reserved-namespaces.ts +10 -5
- package/src/providers/claude-adapter.ts +84 -16
- package/src/providers/claude-managed-adapter.ts +29 -2
- package/src/providers/codex-adapter.ts +1 -1
- package/src/providers/codex-skill-resolver.ts +6 -0
- package/src/providers/dsh-adapter.ts +204 -7
- package/src/providers/opencode-adapter.ts +24 -3
- package/src/providers/pi-mono-adapter.ts +154 -5
- package/src/providers/pi-mono-extension.ts +1 -1
- package/src/providers/pricing-sources.md +5 -1
- package/src/providers/reasoning-effort.ts +10 -2
- package/src/providers/types.ts +1 -1
- package/src/rbac/legacy-policy.ts +3 -0
- package/src/rbac/permissions.ts +14 -0
- package/src/realtime/auth.ts +63 -1
- package/src/realtime/tickets.ts +52 -0
- package/src/realtime/transport.ts +51 -22
- package/src/scripts-runtime/types/stdlib.d.ts +13 -5
- package/src/scripts-runtime/types/swarm-extension.d.ts +7 -3
- package/src/scripts-runtime/types/swarm-sdk.d.ts +13 -5
- package/src/tasks/context-key.ts +38 -1
- package/src/telemetry-context.ts +175 -0
- package/src/telemetry-contract/EVENTS.md +81 -0
- package/src/telemetry-contract/SOURCE.json +9 -0
- package/src/telemetry-contract/catalog.json +1335 -0
- package/src/telemetry-contract/index.ts +60 -0
- package/src/telemetry-contract/types.gen.ts +1971 -0
- package/src/telemetry-identity.ts +129 -0
- package/src/telemetry-snapshot.ts +211 -0
- package/src/telemetry-trigger.ts +125 -0
- package/src/telemetry-types.typetest.ts +40 -0
- package/src/telemetry.ts +271 -67
- package/src/tests/api-drain-e2e.test.ts +249 -0
- package/src/tests/api-drain-worker-e2e.test.ts +216 -0
- package/src/tests/api-drain.test.ts +351 -0
- package/src/tests/azure-devops-auth.test.ts +100 -0
- package/src/tests/azure-devops-handlers.test.ts +324 -0
- package/src/tests/azure-devops-webhook-malformed.test.ts +96 -0
- package/src/tests/claude-default-route.test.ts +260 -0
- package/src/tests/claude-managed-adapter.test.ts +47 -0
- package/src/tests/claude-managed-setup.test.ts +48 -0
- package/src/tests/claude-prompt-body-once.test.ts +117 -0
- package/src/tests/claude-routes-e2e.test.ts +316 -0
- package/src/tests/comb-config-guard.test.ts +38 -0
- package/src/tests/comb-links.test.ts +162 -0
- package/src/tests/comb-markers.test.ts +68 -0
- package/src/tests/comb-review-batch.test.ts +770 -0
- package/src/tests/comb-status.test.ts +152 -0
- package/src/tests/context-versions-retention.test.ts +314 -0
- package/src/tests/core-auth.test.ts +7 -0
- package/src/tests/db-retention.test.ts +14 -14
- package/src/tests/db-task-read-contract.test.ts +3 -0
- package/src/tests/db-task-write-contract.test.ts +3 -0
- package/src/tests/docs-index-footprint.test.js +3 -3
- package/src/tests/dsh-adapter.test.ts +134 -2
- package/src/tests/dsh-usage.test.ts +153 -0
- package/src/tests/extensions-catalog.test.ts +1 -0
- package/src/tests/extensions-example-deploy-awareness.test.ts +301 -0
- package/src/tests/extensions-http.test.ts +137 -10
- package/src/tests/extensions-mcp-tools.test.ts +28 -0
- package/src/tests/favorites-agent-fs-path.test.ts +226 -0
- package/src/tests/fetch-resolved-env.test.ts +24 -0
- package/src/tests/fixtures/azure-devops/pull-request-commented.json +129 -0
- package/src/tests/fixtures/azure-devops/pull-request-created.json +88 -0
- package/src/tests/fixtures/fake-claude-routes.ts +229 -0
- package/src/tests/github-handlers-reactions.test.ts +486 -0
- package/src/tests/github-reactions.test.ts +280 -0
- package/src/tests/harness-cli-version.test.ts +62 -0
- package/src/tests/http-api-integration.test.ts +21 -0
- package/src/tests/http-task-write-ownership.test.ts +24 -1
- package/src/tests/internal-ai/complete-structured.test.ts +94 -0
- package/src/tests/internal-ai/credentials.test.ts +22 -0
- package/src/tests/internal-ai/models.test.ts +36 -2
- package/src/tests/internal-ai/schema-parity.test.ts +25 -1
- package/src/tests/internal-ai/summarize-session.test.ts +23 -7
- package/src/tests/mcp-user-route.test.ts +133 -0
- package/src/tests/memory-key-paths.test.ts +1055 -0
- package/src/tests/memory-link-resolver.test.ts +34 -0
- package/src/tests/memory-rate-endpoint.test.ts +66 -0
- package/src/tests/memory-rater-llm-summarizer.test.ts +2 -1
- package/src/tests/memory-rater-llm.test.ts +73 -0
- package/src/tests/memory-rater-store.test.ts +31 -0
- package/src/tests/memory-reranker.test.ts +40 -0
- package/src/tests/onboarding.test.ts +108 -0
- package/src/tests/opencode-adapter.test.ts +57 -0
- package/src/tests/opencode-plugin.test.ts +4 -0
- package/src/tests/pi-codemode.test.ts +82 -4
- package/src/tests/pi-mono-adapter.test.ts +265 -2
- package/src/tests/pr-body-leaks.test.ts +789 -0
- package/src/tests/preload.ts +14 -0
- package/src/tests/provider-registration.test.ts +0 -2
- package/src/tests/providers/pi-cost.test.ts +190 -4
- package/src/tests/rbac-engine.test.ts +25 -1
- package/src/tests/realtime-room-auth.test.ts +104 -1
- package/src/tests/realtime-tickets.test.ts +74 -0
- package/src/tests/realtime-transport.test.ts +131 -4
- package/src/tests/runner-api-drain.test.ts +301 -0
- package/src/tests/runner-fallback-output.test.ts +61 -0
- package/src/tests/runner-fenced-json-output.test.ts +178 -0
- package/src/tests/runner-slot-reconcile.test.ts +199 -0
- package/src/tests/script-connections.test.ts +6 -0
- package/src/tests/send-task-requested-by.test.ts +133 -15
- package/src/tests/session-costs-recompute-all-providers.test.ts +23 -0
- package/src/tests/task-lifecycle-telemetry.test.ts +8 -3
- package/src/tests/task-reactions.test.ts +29 -6
- package/src/tests/telemetry-context.test.ts +314 -0
- package/src/tests/telemetry-init.test.ts +51 -19
- package/src/tests/telemetry-snapshot.test.ts +229 -0
- package/src/tests/telemetry-trigger.test.ts +200 -0
- package/src/tests/template-registry-helpers.ts +1 -0
- package/src/tests/vcs-azure-devops.test.ts +73 -0
- package/src/tests/webhooks-task-blocked.test.ts +23 -0
- package/src/tests/workflow-agent-task-retry.test.ts +363 -0
- package/src/tests/workflow-definition-telemetry.test.ts +4 -4
- package/src/tests/workflow-llm.test.ts +14 -0
- package/src/tools/context-diff.ts +20 -0
- package/src/tools/extension-install.ts +27 -16
- package/src/tools/memory-edit.ts +47 -3
- package/src/tools/memory-search.ts +13 -1
- package/src/tools/memory-store.ts +55 -3
- package/src/tools/poll-task.ts +20 -1
- package/src/tools/send-task.ts +9 -1
- package/src/tools/task-action.ts +11 -0
- package/src/types.ts +45 -8
- package/src/utils/api-drain.ts +24 -0
- package/src/utils/constants.ts +57 -16
- package/src/utils/credentials.test.ts +31 -1
- package/src/utils/credentials.ts +20 -9
- package/src/utils/dsh-usage.ts +53 -0
- package/src/utils/harness-cli-version.ts +6 -4
- package/src/utils/internal-ai/complete-structured.ts +26 -3
- package/src/utils/internal-ai/credentials.ts +23 -9
- package/src/utils/internal-ai/index.ts +8 -1
- package/src/utils/internal-ai/models.ts +34 -8
- package/src/utils/internal-ai/summarize-session.ts +22 -8
- package/src/utils/pr-body-leaks.ts +172 -0
- package/src/utils/secret-scrubber.ts +8 -0
- package/src/utils/task-attachment-links.ts +14 -8
- package/src/vcs/azure-devops.ts +80 -0
- package/src/vcs/index.ts +5 -1
- package/src/vcs/types.ts +2 -2
- package/src/workflows/recovery.ts +26 -1
- package/src/workflows/resume.ts +31 -4
- package/src/workflows/task-step-routing.ts +75 -2
- package/templates/community/open-prompt-showreel/PLAYBOOK.md +336 -0
- package/templates/community/open-prompt-showreel/README.md +33 -0
- package/templates/community/open-prompt-showreel/example/tla-races/facts.ts +145 -0
- package/templates/community/open-prompt-showreel/example/tla-races/facts.v3.json +140 -0
- package/templates/community/open-prompt-showreel/example/tla-races/music.mist-city.json +8 -0
- package/templates/community/open-prompt-showreel/example/tla-races/reel.html +805 -0
- package/templates/community/open-prompt-showreel/example/tla-races/smoke.sh +48 -0
- package/templates/community/open-prompt-showreel/lead-prompt.md +89 -0
- package/templates/community/open-prompt-showreel/setup.sh +167 -0
- package/templates/community/open-prompt-showreel/skills/motion-design-replication/SKILL.md +85 -0
- package/templates/community/open-prompt-showreel/skills/motion-design-video-analysis/SKILL.md +115 -0
- package/templates/community/open-prompt-showreel/skills/open-prompt-showreel/SKILL.md +147 -0
- package/templates/community/open-prompt-showreel/skills/video-generation/SKILL.md +195 -0
- package/templates/community/open-prompt-showreel/tools/fetch-music.sh +65 -0
- package/templates/community/open-prompt-showreel/tools/music-analyze.py +69 -0
- package/templates/community/open-prompt-showreel/tools/music-current.sh +34 -0
- package/templates/community/open-prompt-showreel/tools/music-cut.sh +36 -0
- package/templates/community/open-prompt-showreel/tools/music-refine.py +39 -0
- package/templates/community/open-prompt-showreel/tools/render.mjs +157 -0
- package/templates/community/open-prompt-showreel/tools/sheet.sh +44 -0
- package/templates/community/open-prompt-showreel/tools/web-compress.sh +17 -0
- package/templates/community/open-prompt-showreel/tools/x-reencode.sh +21 -0
- package/templates/extensions/README.md +1 -0
- package/templates/extensions/deploy-awareness/README.md +28 -0
- package/templates/extensions/deploy-awareness/hooks.ts +152 -0
- package/templates/extensions/deploy-awareness/manifest.json +8 -0
- package/templates/skills/memory/config.json +2 -2
- package/templates/skills/memory/content.md +59 -5
- package/templates/skills/swarm-extensions/config.json +1 -1
- package/templates/skills/swarm-extensions/content.md +28 -5
- package/tsconfig.json +3 -0
- package/dist/boot-seeds-gsetbs5y.js +0 -28
- package/dist/cli-j490egb5.js +0 -5632
- package/dist/cli-tjf4cn8z.js +0 -9119
- package/dist/cli-tmqt7dpj.js +0 -572
- package/dist/dsh-adapter-mpnzgztj.js +0 -19
- package/dist/index-7aj368tw.js +0 -30
|
@@ -34,9 +34,17 @@ const emit = (event) => console.log(JSON.stringify(event));
|
|
|
34
34
|
emit({ type: "session", sessionId: "dsh-test-session" });
|
|
35
35
|
const mode = process.env.DSH_TEST_MODE;
|
|
36
36
|
if (mode === "abort") { setInterval(() => {}, 1000); }
|
|
37
|
+
else if (mode === "mcp-fail") {
|
|
38
|
+
console.error("dsh: warning: 1 entry did not activate\\nswarm-mcp (@deepseek-ai/dsh-mcp-client): Error: mcp-client(agent-swarm): initial connection or tool synchronization failed");
|
|
39
|
+
setInterval(() => {}, 1000);
|
|
40
|
+
}
|
|
37
41
|
else {
|
|
42
|
+
if (mode === "usage") {
|
|
43
|
+
emit({ type: "status", phase: "step_end", turn: 1, step: 1, usage: { inputTokens: 1000, outputTokens: 50, cacheReadTokens: 9000 } });
|
|
44
|
+
emit({ type: "status", phase: "step_end", turn: 1, step: 2, usage: { inputTokens: 200, outputTokens: 30, cacheReadTokens: 10000, cacheWriteTokens: 5, reasoningTokens: 20 } });
|
|
45
|
+
}
|
|
38
46
|
if (mode === "malformed") console.log("bad json");
|
|
39
|
-
emit({ type: "status", phase: "turn_end", reason: { kind: mode === "failure" ? "error" : "completed" } });
|
|
47
|
+
emit({ type: "status", phase: "turn_end", turn: 1, reason: { kind: mode === "failure" ? "error" : "completed" } });
|
|
40
48
|
if (mode !== "missing-final") {
|
|
41
49
|
// A split UTF-8 character plus a final line without a newline exercises both decoders.
|
|
42
50
|
const line = Buffer.from(JSON.stringify({ type: "final", text: "Done ✓" }));
|
|
@@ -168,6 +176,130 @@ describe("dsh harness", () => {
|
|
|
168
176
|
});
|
|
169
177
|
}
|
|
170
178
|
|
|
179
|
+
test("wires the swarm MCP, runs unsandboxed inside the container, and logs the model", async () => {
|
|
180
|
+
const config = await fixture();
|
|
181
|
+
config.apiUrl = "http://api.test:3013";
|
|
182
|
+
config.apiKey = "swarm-test-key";
|
|
183
|
+
config.contextKey = "task:ctx";
|
|
184
|
+
const events: ProviderEvent[] = [];
|
|
185
|
+
const session = await new DshAdapter().createSession(config);
|
|
186
|
+
session.onEvent((event) => events.push(event));
|
|
187
|
+
expect((await session.waitForCompletion()).isError).toBe(false);
|
|
188
|
+
const { patch } = await Bun.file(join(config.cwd, "invocation.json")).json();
|
|
189
|
+
expect(patch).toContainEqual({
|
|
190
|
+
id: "sandbox-policy",
|
|
191
|
+
config: { mode: "danger-full-access", workspaceRoot: config.cwd },
|
|
192
|
+
});
|
|
193
|
+
expect(patch).toContainEqual({ id: "approval", config: { policy: "never" } });
|
|
194
|
+
const mcp = patch.find((entry: { insert?: unknown[] }) => entry.insert)?.insert;
|
|
195
|
+
expect(mcp).toHaveLength(1);
|
|
196
|
+
expect(mcp[0]).toMatchObject({
|
|
197
|
+
id: "swarm-mcp",
|
|
198
|
+
name: "@deepseek-ai/dsh-mcp-client",
|
|
199
|
+
config: {
|
|
200
|
+
serverName: "agent-swarm",
|
|
201
|
+
transport: "streamable-http",
|
|
202
|
+
url: "http://api.test:3013/mcp",
|
|
203
|
+
failOnStartupError: true,
|
|
204
|
+
},
|
|
205
|
+
});
|
|
206
|
+
// X-Runtime-Instance-ID rides along only in multi-runtime mode.
|
|
207
|
+
expect(mcp[0].config.headers).toMatchObject({
|
|
208
|
+
Authorization: "Bearer swarm-test-key",
|
|
209
|
+
"X-Agent-ID": "agent-test",
|
|
210
|
+
"X-Source-Task-Id": "task-test",
|
|
211
|
+
"X-Context-Key": "task:ctx",
|
|
212
|
+
});
|
|
213
|
+
expect(events[0]).toEqual({
|
|
214
|
+
type: "raw_log",
|
|
215
|
+
content: JSON.stringify({
|
|
216
|
+
type: "model",
|
|
217
|
+
provider: "deepseek-official",
|
|
218
|
+
model: "deepseek-v4-pro",
|
|
219
|
+
}),
|
|
220
|
+
});
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
test("fails fast when the swarm MCP client does not activate", async () => {
|
|
224
|
+
const config = await fixture("mcp-fail");
|
|
225
|
+
const result = await (await new DshAdapter().createSession(config)).waitForCompletion();
|
|
226
|
+
expect(result.isError).toBe(true);
|
|
227
|
+
expect(result.exitCode).not.toBe(0);
|
|
228
|
+
expect(result.failureReason).toStartWith("dsh could not connect to the swarm MCP server");
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
test("maps step usage to context snapshots and a dsh cost record", async () => {
|
|
232
|
+
const config = await fixture("usage");
|
|
233
|
+
config.model = "openrouter/deepseek/deepseek-v4.1-flash";
|
|
234
|
+
config.env = { ...config.env, OPENROUTER_API_KEY: "openrouter-test-key" };
|
|
235
|
+
const events: ProviderEvent[] = [];
|
|
236
|
+
const session = await new DshAdapter().createSession(config);
|
|
237
|
+
session.onEvent((event) => events.push(event));
|
|
238
|
+
const result = await session.waitForCompletion();
|
|
239
|
+
const context = events.filter((event) => event.type === "context_usage");
|
|
240
|
+
expect(context.map((event) => event.contextUsedTokens)).toEqual([10050, 10235]);
|
|
241
|
+
expect(context[0]).toMatchObject({ outputTokens: 50, contextFormula: "input-cache-output" });
|
|
242
|
+
expect(context[0]?.contextTotalTokens).toBeGreaterThan(200_000);
|
|
243
|
+
expect(result.cost).toMatchObject({
|
|
244
|
+
sessionId: "dsh-test-session",
|
|
245
|
+
taskId: "task-test",
|
|
246
|
+
agentId: "agent-test",
|
|
247
|
+
totalCostUsd: 0,
|
|
248
|
+
inputTokens: 1200,
|
|
249
|
+
outputTokens: 80,
|
|
250
|
+
cacheReadTokens: 19000,
|
|
251
|
+
cacheWriteTokens: 5,
|
|
252
|
+
reasoningOutputTokens: 20,
|
|
253
|
+
numTurns: 1,
|
|
254
|
+
model: "openrouter/deepseek/deepseek-v4.1-flash",
|
|
255
|
+
isError: false,
|
|
256
|
+
provider: "dsh",
|
|
257
|
+
});
|
|
258
|
+
expect(events).toContainEqual(expect.objectContaining({ type: "result", cost: result.cost }));
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
test("reports no cost when dsh sent no usage", async () => {
|
|
262
|
+
const result = await (
|
|
263
|
+
await new DshAdapter().createSession(await fixture())
|
|
264
|
+
).waitForCompletion();
|
|
265
|
+
expect(result.cost).toBeUndefined();
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
test("passes a supported effort to dsh and declares it for OpenRouter models", async () => {
|
|
269
|
+
const direct = await fixture();
|
|
270
|
+
direct.reasoningEffort = "max";
|
|
271
|
+
const directResult = await (await new DshAdapter().createSession(direct)).waitForCompletion();
|
|
272
|
+
expect(directResult.appliedReasoningEffort).toBe("max");
|
|
273
|
+
const directPatch = (await Bun.file(join(direct.cwd, "invocation.json")).json()).patch;
|
|
274
|
+
expect(directPatch[0].config).toEqual({
|
|
275
|
+
provider: "deepseek-official",
|
|
276
|
+
model: "deepseek-v4-pro",
|
|
277
|
+
reasoningEffort: "max",
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
const routed = await fixture();
|
|
281
|
+
routed.model = "openrouter/deepseek/deepseek-v4.1-flash";
|
|
282
|
+
routed.reasoningEffort = "high";
|
|
283
|
+
routed.env = { ...routed.env, OPENROUTER_API_KEY: "openrouter-test-key" };
|
|
284
|
+
await (await new DshAdapter().createSession(routed)).waitForCompletion();
|
|
285
|
+
const routedPatch = (await Bun.file(join(routed.cwd, "invocation.json")).json()).patch;
|
|
286
|
+
expect(routedPatch[0].config.reasoningEffort).toBe("high");
|
|
287
|
+
expect(routedPatch[2].config.providers.openrouter.models).toEqual([
|
|
288
|
+
{
|
|
289
|
+
id: "deepseek/deepseek-v4.1-flash",
|
|
290
|
+
reasoningEfforts: { low: "low", high: "high", max: "max" },
|
|
291
|
+
},
|
|
292
|
+
]);
|
|
293
|
+
|
|
294
|
+
// A level the model does not offer is dropped, not sent.
|
|
295
|
+
const unsupported = await fixture();
|
|
296
|
+
unsupported.reasoningEffort = "medium";
|
|
297
|
+
const unsupportedResult = await (
|
|
298
|
+
await new DshAdapter().createSession(unsupported)
|
|
299
|
+
).waitForCompletion();
|
|
300
|
+
expect(unsupportedResult.appliedReasoningEffort).toBeNull();
|
|
301
|
+
});
|
|
302
|
+
|
|
171
303
|
test("defaults to OpenRouter and honors its base URL when both keys exist", async () => {
|
|
172
304
|
const config = await fixture();
|
|
173
305
|
config.model = undefined;
|
|
@@ -222,7 +354,7 @@ describe("dsh harness", () => {
|
|
|
222
354
|
await rename(join(config.cwd, "dsh"), join(config.cwd, "npx"));
|
|
223
355
|
config.env = { ...config.env, DSH_BINARY: "", PATH: config.cwd };
|
|
224
356
|
await expect(new DshAdapter().createSession(config)).rejects.toThrow(
|
|
225
|
-
"dsh CLI not found. Install @deepseek-ai/dsh@0.2.
|
|
357
|
+
"dsh CLI not found. Install @deepseek-ai/dsh@0.2.1-alpha.1",
|
|
226
358
|
);
|
|
227
359
|
expect(await Bun.file(join(config.cwd, "invocation.json")).exists()).toBe(false);
|
|
228
360
|
});
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { afterEach, describe, expect, test } from "bun:test";
|
|
2
|
+
import { chmod, mkdtemp, rm } from "node:fs/promises";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { normalizeSessionLogs, type SessionLogRecord } from "../../apps/ui/src/logs-parser";
|
|
6
|
+
import { DshAdapter } from "../providers/dsh-adapter";
|
|
7
|
+
import type { ProviderEvent } from "../providers/types";
|
|
8
|
+
import { addDshStepUsage, type DshStepUsage, normalizeDshStepUsage } from "../utils/dsh-usage";
|
|
9
|
+
|
|
10
|
+
// Real step_end rows from a 4-step dsh run on OpenRouter. Step 1 hit a cold
|
|
11
|
+
// cache (no cache field). Step 2 omits cacheReadTokens although its
|
|
12
|
+
// totalTokens carries 96,256 cached tokens: dsh-headless drops an optional
|
|
13
|
+
// bucket when any attempt of a retried step did not report it.
|
|
14
|
+
const STEPS = [
|
|
15
|
+
{ inputTokens: 96456, outputTokens: 250, totalTokens: 96706 },
|
|
16
|
+
{ inputTokens: 1691, outputTokens: 133, totalTokens: 98080 },
|
|
17
|
+
{ inputTokens: 1364, outputTokens: 250, totalTokens: 99406, cacheReadTokens: 97792 },
|
|
18
|
+
{ inputTokens: 520, outputTokens: 114, totalTokens: 99706, cacheReadTokens: 99072 },
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
const directories: string[] = [];
|
|
22
|
+
afterEach(async () => {
|
|
23
|
+
await Promise.all(
|
|
24
|
+
directories.splice(0).map((path) => rm(path, { recursive: true, force: true })),
|
|
25
|
+
);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
function dshLines(): Record<string, unknown>[] {
|
|
29
|
+
const lines: Record<string, unknown>[] = [
|
|
30
|
+
{ type: "session", sessionId: "dsh-usage-session" },
|
|
31
|
+
{ type: "status", phase: "turn_start", turn: 1 },
|
|
32
|
+
];
|
|
33
|
+
STEPS.forEach((usage, i) => {
|
|
34
|
+
lines.push({ type: "status", phase: "step_start", turn: 1, step: i + 1 });
|
|
35
|
+
if (i < 3) {
|
|
36
|
+
const callId = `call-${i + 1}`;
|
|
37
|
+
lines.push({
|
|
38
|
+
type: "tool_call",
|
|
39
|
+
callId,
|
|
40
|
+
tool: i < 2 ? "mcp__agent-swarm__get-tasks" : "mcp__agent-swarm__store-progress",
|
|
41
|
+
input: { mineOnly: true },
|
|
42
|
+
});
|
|
43
|
+
lines.push({ type: "tool_result", callId, status: "ok", result: "ok" });
|
|
44
|
+
}
|
|
45
|
+
lines.push({ type: "status", phase: "step_end", turn: 1, step: i + 1, usage });
|
|
46
|
+
});
|
|
47
|
+
lines.push({ type: "text", text: "Done" });
|
|
48
|
+
lines.push({ type: "status", phase: "turn_end", turn: 1, reason: { kind: "completed" } });
|
|
49
|
+
lines.push({ type: "final", text: "Done" });
|
|
50
|
+
return lines;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
describe("dsh usage normalization", () => {
|
|
54
|
+
test("derives a missing cacheReadTokens from totalTokens", () => {
|
|
55
|
+
const steps = STEPS.map((usage) => normalizeDshStepUsage(usage) as DshStepUsage);
|
|
56
|
+
expect(steps.map((step) => step.cacheRead)).toEqual([0, 96256, 97792, 99072]);
|
|
57
|
+
// Present fields win: the derived value equals the reported one on steps 3-4.
|
|
58
|
+
expect(normalizeDshStepUsage({ ...STEPS[2], totalTokens: 1 })?.cacheRead).toBe(97792);
|
|
59
|
+
expect(
|
|
60
|
+
normalizeDshStepUsage({
|
|
61
|
+
inputTokens: 10,
|
|
62
|
+
outputTokens: 5,
|
|
63
|
+
totalTokens: 40,
|
|
64
|
+
cacheWriteTokens: 5,
|
|
65
|
+
})?.cacheRead,
|
|
66
|
+
).toBe(20);
|
|
67
|
+
expect(normalizeDshStepUsage(undefined)).toBeNull();
|
|
68
|
+
expect(steps.reduce<DshStepUsage | undefined>(addDshStepUsage, undefined)).toEqual({
|
|
69
|
+
input: 100031,
|
|
70
|
+
output: 747,
|
|
71
|
+
cacheRead: 293120,
|
|
72
|
+
cacheWrite: 0,
|
|
73
|
+
reasoning: 0,
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test("the cost row and the log turn summary count the same tokens and turns", async () => {
|
|
78
|
+
const cwd = await mkdtemp(join(tmpdir(), "dsh-usage-test-"));
|
|
79
|
+
directories.push(cwd);
|
|
80
|
+
const binary = join(cwd, "dsh");
|
|
81
|
+
await Bun.write(
|
|
82
|
+
binary,
|
|
83
|
+
`#!${process.execPath}
|
|
84
|
+
await Bun.stdin.text();
|
|
85
|
+
for (const line of ${JSON.stringify(dshLines())}) console.log(JSON.stringify(line));
|
|
86
|
+
`,
|
|
87
|
+
);
|
|
88
|
+
await chmod(binary, 0o700);
|
|
89
|
+
const session = await new DshAdapter().createSession({
|
|
90
|
+
prompt: "go",
|
|
91
|
+
systemPrompt: "",
|
|
92
|
+
model: "openrouter/qwen/qwen3.8-flash",
|
|
93
|
+
role: "worker",
|
|
94
|
+
agentId: "agent-test",
|
|
95
|
+
taskId: "task-test",
|
|
96
|
+
apiUrl: "http://unused.invalid",
|
|
97
|
+
apiKey: "unused",
|
|
98
|
+
cwd,
|
|
99
|
+
logFile: join(cwd, "log.jsonl"),
|
|
100
|
+
env: { DSH_BINARY: binary, OPENROUTER_API_KEY: "openrouter-test-key" },
|
|
101
|
+
});
|
|
102
|
+
const events: ProviderEvent[] = [];
|
|
103
|
+
session.onEvent((event) => events.push(event));
|
|
104
|
+
const result = await session.waitForCompletion();
|
|
105
|
+
|
|
106
|
+
expect(result.cost).toMatchObject({
|
|
107
|
+
inputTokens: 100031,
|
|
108
|
+
cacheReadTokens: 293120,
|
|
109
|
+
outputTokens: 747,
|
|
110
|
+
numTurns: 1,
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
// Progress comes from tool calls, never from dsh phase names.
|
|
114
|
+
expect(events.filter((event) => event.type === "progress")).toEqual([]);
|
|
115
|
+
expect(
|
|
116
|
+
events.flatMap((event) => (event.type === "tool_start" ? [event.toolName] : [])),
|
|
117
|
+
).toEqual([
|
|
118
|
+
"mcp__agent-swarm__get-tasks",
|
|
119
|
+
"mcp__agent-swarm__get-tasks",
|
|
120
|
+
"mcp__agent-swarm__store-progress",
|
|
121
|
+
]);
|
|
122
|
+
expect(events).toContainEqual({
|
|
123
|
+
type: "tool_end",
|
|
124
|
+
toolCallId: "call-3",
|
|
125
|
+
toolName: "mcp__agent-swarm__store-progress",
|
|
126
|
+
result: "ok",
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
// The log viewer reads the same raw lines the runner stores.
|
|
130
|
+
const records: SessionLogRecord[] = events
|
|
131
|
+
.flatMap((event) => (event.type === "raw_log" ? [event.content] : []))
|
|
132
|
+
.map((content, i) => ({
|
|
133
|
+
id: `line-${i}`,
|
|
134
|
+
taskId: "task-test",
|
|
135
|
+
sessionId: "session-1",
|
|
136
|
+
iteration: 1,
|
|
137
|
+
cli: "dsh",
|
|
138
|
+
content,
|
|
139
|
+
lineNumber: i,
|
|
140
|
+
createdAt: "2026-10-01T19:24:00.000Z",
|
|
141
|
+
}));
|
|
142
|
+
const turn = normalizeSessionLogs(records).items.find(
|
|
143
|
+
(item) => (item.meta as { type?: string } | undefined)?.type === "turn.completed",
|
|
144
|
+
);
|
|
145
|
+
const meta = turn?.meta as { steps: number; usage: Record<string, number> };
|
|
146
|
+
expect(meta.steps).toBe(4);
|
|
147
|
+
expect(meta.usage).toEqual({
|
|
148
|
+
input_tokens: result.cost!.inputTokens + result.cost!.cacheReadTokens!,
|
|
149
|
+
cached_input_tokens: result.cost!.cacheReadTokens,
|
|
150
|
+
output_tokens: result.cost!.outputTokens,
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
});
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
import { afterAll, beforeAll, beforeEach, describe, expect, spyOn, test } from "bun:test";
|
|
2
|
+
import { closeDb, getDbClient, getKv, initDb, upsertSwarmConfig } from "../be/db";
|
|
3
|
+
import { getExtensionById, installExtension } from "../be/extensions/db";
|
|
4
|
+
import { getCatalogEntry } from "../extensions/catalog";
|
|
5
|
+
import { enableExtension, stopExtensionRuntime } from "../extensions/lifecycle";
|
|
6
|
+
import { __resetInjectedEnvTracking, loadGlobalConfigsIntoEnv } from "../http/core";
|
|
7
|
+
import { createTaskWithSiblingAwareness } from "../tasks/sibling-awareness";
|
|
8
|
+
import { refreshSecretScrubberCache } from "../utils/secret-scrubber";
|
|
9
|
+
|
|
10
|
+
const TEST_DB_PATH = "./test-extensions-example-deploy-awareness.sqlite";
|
|
11
|
+
const DOKPLOY_KEY = "deploy-awareness-test-dokploy-key-abcdef";
|
|
12
|
+
const DOKPLOY_URL = "https://dokploy.test";
|
|
13
|
+
const COMPOSE_ID = "compose-under-test";
|
|
14
|
+
|
|
15
|
+
type DokployRequest = { url: string; apiKey: string | null };
|
|
16
|
+
type Deployment = { status: string; createdAt: string; startedAt?: string };
|
|
17
|
+
|
|
18
|
+
let fetchSpy: ReturnType<typeof spyOn>;
|
|
19
|
+
let requests: DokployRequest[];
|
|
20
|
+
let respond: (req: Request) => Response | Promise<Response>;
|
|
21
|
+
let savedEnv: NodeJS.ProcessEnv;
|
|
22
|
+
|
|
23
|
+
const minutesAgo = (minutes: number) => new Date(Date.now() - minutes * 60_000).toISOString();
|
|
24
|
+
const note = (startedAt: string) =>
|
|
25
|
+
`Note: a prod deploy started at ${startedAt.slice(11, 16)} UTC is in progress; your worker may restart in the next few minutes. Checkpoint with store-progress before long steps.`;
|
|
26
|
+
|
|
27
|
+
function deployments(list: Deployment[]) {
|
|
28
|
+
respond = () => Response.json(list);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async function removeDbFiles(): Promise<void> {
|
|
32
|
+
for (const suffix of ["", "-wal", "-shm"]) {
|
|
33
|
+
await Bun.file(TEST_DB_PATH + suffix)
|
|
34
|
+
.delete()
|
|
35
|
+
.catch(() => {});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async function enableTemplate(config: Record<string, unknown> = {}) {
|
|
40
|
+
const template = getCatalogEntry("deploy-awareness");
|
|
41
|
+
if (!template) throw new Error("deploy-awareness is missing from the catalog");
|
|
42
|
+
const installed = await installExtension({
|
|
43
|
+
manifest: template.manifest,
|
|
44
|
+
files: template.files,
|
|
45
|
+
config: { composeId: COMPOSE_ID, ...config },
|
|
46
|
+
});
|
|
47
|
+
return await enableExtension(installed.extension.id);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const createTask = async (description = "do the thing") =>
|
|
51
|
+
(await createTaskWithSiblingAwareness(description, { source: "api" }, { origin: "rest" })).task;
|
|
52
|
+
|
|
53
|
+
beforeAll(async () => {
|
|
54
|
+
savedEnv = { ...process.env };
|
|
55
|
+
await removeDbFiles();
|
|
56
|
+
initDb(TEST_DB_PATH);
|
|
57
|
+
await upsertSwarmConfig({
|
|
58
|
+
scope: "global",
|
|
59
|
+
key: "DOKPLOY_API_KEY",
|
|
60
|
+
value: DOKPLOY_KEY,
|
|
61
|
+
isSecret: true,
|
|
62
|
+
});
|
|
63
|
+
// The API server does this at boot, which is how the key reaches process.env in prod.
|
|
64
|
+
await loadGlobalConfigsIntoEnv(true);
|
|
65
|
+
|
|
66
|
+
// Calls to Dokploy (the default host and the .test hosts these tests use) land here, so a
|
|
67
|
+
// request to a host the test never expected is recorded instead of leaving the process.
|
|
68
|
+
// Anything else, such as the background pricing refresh, goes to the real fetch. An aborted
|
|
69
|
+
// signal rejects, like the real fetch.
|
|
70
|
+
const realFetch = globalThis.fetch;
|
|
71
|
+
fetchSpy = spyOn(globalThis, "fetch").mockImplementation((async (
|
|
72
|
+
input: RequestInfo | URL,
|
|
73
|
+
init?: RequestInit,
|
|
74
|
+
) => {
|
|
75
|
+
const request = new Request(input, init);
|
|
76
|
+
const { hostname } = new URL(request.url);
|
|
77
|
+
if (hostname !== "app.dokploy.com" && !hostname.endsWith(".test")) {
|
|
78
|
+
return await realFetch(input, init);
|
|
79
|
+
}
|
|
80
|
+
requests.push({ url: request.url, apiKey: request.headers.get("x-api-key") });
|
|
81
|
+
return await Promise.race([
|
|
82
|
+
Promise.resolve(respond(request)),
|
|
83
|
+
new Promise<never>((_, reject) =>
|
|
84
|
+
request.signal.addEventListener("abort", () => reject(request.signal.reason), {
|
|
85
|
+
once: true,
|
|
86
|
+
}),
|
|
87
|
+
),
|
|
88
|
+
]);
|
|
89
|
+
}) as unknown as typeof fetch);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
afterAll(async () => {
|
|
93
|
+
await stopExtensionRuntime();
|
|
94
|
+
fetchSpy.mockRestore();
|
|
95
|
+
closeDb();
|
|
96
|
+
await removeDbFiles();
|
|
97
|
+
for (const key of Object.keys(process.env)) if (!(key in savedEnv)) delete process.env[key];
|
|
98
|
+
Object.assign(process.env, savedEnv);
|
|
99
|
+
__resetInjectedEnvTracking();
|
|
100
|
+
refreshSecretScrubberCache();
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
beforeEach(async () => {
|
|
104
|
+
await stopExtensionRuntime();
|
|
105
|
+
await getDbClient().run("DELETE FROM extensions");
|
|
106
|
+
await getDbClient().run("DELETE FROM kv_entries");
|
|
107
|
+
process.env.DOKPLOY_API_KEY = DOKPLOY_KEY;
|
|
108
|
+
process.env.DOKPLOY_BASE_URL = DOKPLOY_URL;
|
|
109
|
+
requests = [];
|
|
110
|
+
deployments([]);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
describe("deploy-awareness extension", () => {
|
|
114
|
+
test("appends the note while the newest deployment is running", async () => {
|
|
115
|
+
const startedAt = minutesAgo(2);
|
|
116
|
+
// Out of order on purpose: compose.one lists deployments in no chronological order.
|
|
117
|
+
deployments([
|
|
118
|
+
{ status: "done", createdAt: minutesAgo(180) },
|
|
119
|
+
{ status: "running", createdAt: startedAt, startedAt },
|
|
120
|
+
{ status: "done", createdAt: minutesAgo(120) },
|
|
121
|
+
]);
|
|
122
|
+
const extension = await enableTemplate();
|
|
123
|
+
|
|
124
|
+
const description = await createTask("fix the flaky test");
|
|
125
|
+
|
|
126
|
+
expect(description).toBe(`fix the flaky test\n\n${note(startedAt)}`);
|
|
127
|
+
expect(requests).toEqual([
|
|
128
|
+
{
|
|
129
|
+
url: `${DOKPLOY_URL}/api/deployment.allByCompose?composeId=${COMPOSE_ID}`,
|
|
130
|
+
apiKey: DOKPLOY_KEY,
|
|
131
|
+
},
|
|
132
|
+
]);
|
|
133
|
+
// The key must not reach the description or the cache entry.
|
|
134
|
+
expect(description).not.toContain(DOKPLOY_KEY);
|
|
135
|
+
const cached = await getKv(
|
|
136
|
+
`task:agent:${extension.agentId}`,
|
|
137
|
+
"ext:deploy-awareness:deploy-status",
|
|
138
|
+
);
|
|
139
|
+
expect(JSON.stringify(cached)).not.toContain(DOKPLOY_KEY);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
test("leaves the description alone when the newest deployment is done", async () => {
|
|
143
|
+
// An older record stuck in "running" must not count.
|
|
144
|
+
deployments([
|
|
145
|
+
{ status: "running", createdAt: minutesAgo(300), startedAt: minutesAgo(300) },
|
|
146
|
+
{ status: "done", createdAt: minutesAgo(10) },
|
|
147
|
+
]);
|
|
148
|
+
await enableTemplate();
|
|
149
|
+
|
|
150
|
+
expect(await createTask("quiet deploy")).toBe("quiet deploy");
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
test("ignores a running deployment older than staleAfterMs", async () => {
|
|
154
|
+
deployments([{ status: "running", createdAt: minutesAgo(90), startedAt: minutesAgo(90) }]);
|
|
155
|
+
await enableTemplate({ staleAfterMs: 30 * 60_000 });
|
|
156
|
+
|
|
157
|
+
expect(await createTask("stuck record")).toBe("stuck record");
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
test("a second task inside the window reuses the check, and the next window checks again", async () => {
|
|
161
|
+
const startedAt = minutesAgo(1);
|
|
162
|
+
deployments([{ status: "running", createdAt: startedAt, startedAt }]);
|
|
163
|
+
await enableTemplate({ cacheTtlMs: 120_000 });
|
|
164
|
+
|
|
165
|
+
expect(await createTask("first")).toContain(note(startedAt));
|
|
166
|
+
expect(await createTask("second")).toContain(note(startedAt));
|
|
167
|
+
expect(requests).toHaveLength(1);
|
|
168
|
+
|
|
169
|
+
const clock = spyOn(Date, "now").mockReturnValue(Date.now() + 121_000);
|
|
170
|
+
try {
|
|
171
|
+
deployments([{ status: "done", createdAt: startedAt }]);
|
|
172
|
+
expect(await createTask("third")).toBe("third");
|
|
173
|
+
expect(requests).toHaveLength(2);
|
|
174
|
+
} finally {
|
|
175
|
+
clock.mockRestore();
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
test("tasks created together share one Dokploy call", async () => {
|
|
180
|
+
const startedAt = minutesAgo(1);
|
|
181
|
+
deployments([{ status: "running", createdAt: startedAt, startedAt }]);
|
|
182
|
+
await enableTemplate();
|
|
183
|
+
|
|
184
|
+
const created = await Promise.all([createTask("a"), createTask("b"), createTask("c")]);
|
|
185
|
+
|
|
186
|
+
expect(created.every((description) => description.includes(note(startedAt)))).toBe(true);
|
|
187
|
+
expect(requests).toHaveLength(1);
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
test("a Dokploy error adds no note, still creates the task, and is cached", async () => {
|
|
191
|
+
respond = () => new Response("boom", { status: 500 });
|
|
192
|
+
const extension = await enableTemplate();
|
|
193
|
+
|
|
194
|
+
expect(await createTask("during outage")).toBe("during outage");
|
|
195
|
+
expect(await createTask("still down")).toBe("still down");
|
|
196
|
+
expect(requests).toHaveLength(1);
|
|
197
|
+
expect((await getExtensionById(extension.id))?.status).toBe("enabled");
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
test("failures never auto-disable the extension", async () => {
|
|
201
|
+
respond = () => new Response("boom", { status: 500 });
|
|
202
|
+
const extension = await enableTemplate({ cacheTtlMs: 0 });
|
|
203
|
+
|
|
204
|
+
// The default limit is five consecutive handler failures.
|
|
205
|
+
for (let i = 0; i < 6; i++) expect(await createTask(`outage ${i}`)).toBe(`outage ${i}`);
|
|
206
|
+
|
|
207
|
+
expect(requests).toHaveLength(6);
|
|
208
|
+
expect((await getExtensionById(extension.id))?.status).toBe("enabled");
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
test("a hung Dokploy call is cut off at timeoutMs and the task is created", async () => {
|
|
212
|
+
respond = () => new Promise<Response>(() => {});
|
|
213
|
+
await enableTemplate({ timeoutMs: 100 });
|
|
214
|
+
|
|
215
|
+
const started = Date.now();
|
|
216
|
+
expect(await createTask("slow dokploy")).toBe("slow dokploy");
|
|
217
|
+
expect(Date.now() - started).toBeLessThan(2_000);
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
test("an unset DOKPLOY_API_KEY skips the Dokploy call", async () => {
|
|
221
|
+
deployments([{ status: "running", createdAt: minutesAgo(1) }]);
|
|
222
|
+
await enableTemplate();
|
|
223
|
+
delete process.env.DOKPLOY_API_KEY;
|
|
224
|
+
|
|
225
|
+
expect(await createTask("no key")).toBe("no key");
|
|
226
|
+
expect(requests).toHaveLength(0);
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
test("DOKPLOY_BASE_URL defaults to app.dokploy.com", async () => {
|
|
230
|
+
deployments([{ status: "done", createdAt: minutesAgo(5) }]);
|
|
231
|
+
await enableTemplate();
|
|
232
|
+
delete process.env.DOKPLOY_BASE_URL;
|
|
233
|
+
|
|
234
|
+
await createTask("default host");
|
|
235
|
+
|
|
236
|
+
expect(requests).toEqual([
|
|
237
|
+
{
|
|
238
|
+
url: `https://app.dokploy.com/api/deployment.allByCompose?composeId=${COMPOSE_ID}`,
|
|
239
|
+
apiKey: DOKPLOY_KEY,
|
|
240
|
+
},
|
|
241
|
+
]);
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
// The old config let a lead name any env var as the key and any host as the target. Both
|
|
245
|
+
// fields are gone, so a config that still carries them must change nothing.
|
|
246
|
+
test("a baseUrl or apiKeySecret in the extension config is not a lever", async () => {
|
|
247
|
+
const encryptionKey = "deploy-awareness-test-encryption-key-123456";
|
|
248
|
+
process.env.SECRETS_ENCRYPTION_KEY = encryptionKey;
|
|
249
|
+
const startedAt = minutesAgo(1);
|
|
250
|
+
deployments([{ status: "running", createdAt: startedAt, startedAt }]);
|
|
251
|
+
await enableTemplate({
|
|
252
|
+
baseUrl: "https://attacker.test",
|
|
253
|
+
apiKeySecret: "SECRETS_ENCRYPTION_KEY",
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
expect(await createTask("lever")).toContain(note(startedAt));
|
|
257
|
+
|
|
258
|
+
expect(requests).toEqual([
|
|
259
|
+
{
|
|
260
|
+
url: `${DOKPLOY_URL}/api/deployment.allByCompose?composeId=${COMPOSE_ID}`,
|
|
261
|
+
apiKey: DOKPLOY_KEY,
|
|
262
|
+
},
|
|
263
|
+
]);
|
|
264
|
+
expect(JSON.stringify(requests)).not.toContain(encryptionKey);
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
test.each([
|
|
268
|
+
["an http URL", "http://dokploy.test"],
|
|
269
|
+
["a non-http scheme", "ftp://dokploy.test"],
|
|
270
|
+
["a value that is not a URL", "dokploy.test"],
|
|
271
|
+
])("%s in DOKPLOY_BASE_URL sends no request and the task is still created", async (_name, url) => {
|
|
272
|
+
deployments([{ status: "running", createdAt: minutesAgo(1) }]);
|
|
273
|
+
const extension = await enableTemplate();
|
|
274
|
+
process.env.DOKPLOY_BASE_URL = url;
|
|
275
|
+
const warn = spyOn(console, "warn").mockImplementation(() => {});
|
|
276
|
+
try {
|
|
277
|
+
expect(await createTask("insecure host")).toBe("insecure host");
|
|
278
|
+
|
|
279
|
+
expect(requests).toHaveLength(0);
|
|
280
|
+
const logged = warn.mock.calls.map((call) => call.join(" ")).join("\n");
|
|
281
|
+
expect(logged).toContain("DOKPLOY_BASE_URL");
|
|
282
|
+
expect(logged).not.toContain(url);
|
|
283
|
+
expect(logged).not.toContain(DOKPLOY_KEY);
|
|
284
|
+
} finally {
|
|
285
|
+
warn.mockRestore();
|
|
286
|
+
}
|
|
287
|
+
expect((await getExtensionById(extension.id))?.status).toBe("enabled");
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
test("a description that already carries the note is not checked or changed again", async () => {
|
|
291
|
+
const startedAt = minutesAgo(1);
|
|
292
|
+
deployments([{ status: "running", createdAt: startedAt, startedAt }]);
|
|
293
|
+
// No cache reuse, so a check would show up in `requests`.
|
|
294
|
+
await enableTemplate({ cacheTtlMs: 0 });
|
|
295
|
+
const first = await createTask("resume me");
|
|
296
|
+
expect(requests).toHaveLength(1);
|
|
297
|
+
|
|
298
|
+
expect(await createTask(first)).toBe(first);
|
|
299
|
+
expect(requests).toHaveLength(1);
|
|
300
|
+
});
|
|
301
|
+
});
|