@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
|
@@ -2,6 +2,13 @@ import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
|
2
2
|
import { tmpdir } from "node:os";
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
import { DEFAULT_MODEL_TIER_MAP } from "../types";
|
|
5
|
+
import {
|
|
6
|
+
CONTEXT_FORMULA,
|
|
7
|
+
clampContextPercent,
|
|
8
|
+
getContextWindowSize,
|
|
9
|
+
} from "../utils/context-window";
|
|
10
|
+
import { addDshStepUsage, type DshStepUsage, normalizeDshStepUsage } from "../utils/dsh-usage";
|
|
11
|
+
import { swarmRuntimeInstanceId } from "../utils/multi-runtime";
|
|
5
12
|
import { getOpenRouterBaseUrl } from "../utils/openrouter-base-url";
|
|
6
13
|
import {
|
|
7
14
|
detachedProcessGroup,
|
|
@@ -10,7 +17,13 @@ import {
|
|
|
10
17
|
} from "../utils/process-group";
|
|
11
18
|
import { registerVolatileSecret, scrubSecrets } from "../utils/secret-scrubber";
|
|
12
19
|
import { resolveSlashSkillPrompt } from "./codex-skill-resolver";
|
|
20
|
+
import {
|
|
21
|
+
applyReasoningEffort,
|
|
22
|
+
type ReasoningEffort,
|
|
23
|
+
reasoningCapability,
|
|
24
|
+
} from "./reasoning-effort";
|
|
13
25
|
import type {
|
|
26
|
+
CostData,
|
|
14
27
|
CredStatus,
|
|
15
28
|
ProviderAdapter,
|
|
16
29
|
ProviderEvent,
|
|
@@ -21,7 +34,7 @@ import type {
|
|
|
21
34
|
} from "./types";
|
|
22
35
|
|
|
23
36
|
// npm's `latest` is older and lacks the JSON/stdin contract used here.
|
|
24
|
-
export const DSH_PACKAGE = "@deepseek-ai/dsh@0.2.
|
|
37
|
+
export const DSH_PACKAGE = "@deepseek-ai/dsh@0.2.1-alpha.1";
|
|
25
38
|
|
|
26
39
|
export function checkDshCredentials(env: Record<string, string | undefined>): CredStatus {
|
|
27
40
|
return env.DEEPSEEK_API_KEY?.trim() || env.OPENROUTER_API_KEY?.trim()
|
|
@@ -33,6 +46,40 @@ export function checkDshCredentials(env: Record<string, string | undefined>): Cr
|
|
|
33
46
|
};
|
|
34
47
|
}
|
|
35
48
|
|
|
49
|
+
/** What the adapter resolved before spawning; dsh's stream never echoes it back. */
|
|
50
|
+
interface DshRun {
|
|
51
|
+
/** The swarm model string (`openrouter/<id>` or a bare DeepSeek id). */
|
|
52
|
+
model: string;
|
|
53
|
+
/** dsh route the patch selected: `openrouter` or `deepseek-official`. */
|
|
54
|
+
route: string;
|
|
55
|
+
/** Model id dsh sends on that route. */
|
|
56
|
+
modelId: string;
|
|
57
|
+
reasoningEffort: ReasoningEffort | null;
|
|
58
|
+
taskId: string;
|
|
59
|
+
agentId: string;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Catalog key for the context-window lookup: the direct API's ids live under `deepseek/`. */
|
|
63
|
+
function contextWindowKey(model: string): string {
|
|
64
|
+
return model.startsWith("openrouter/") ? model : `deepseek/${model}`;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** MCP server name; dsh exposes its tools as `mcp__agent-swarm__<tool>`. */
|
|
68
|
+
const DSH_MCP_SERVER_NAME = "agent-swarm";
|
|
69
|
+
/** Patch entry id of the inserted MCP client; dsh names it in activation errors. */
|
|
70
|
+
const DSH_MCP_ENTRY_ID = "swarm-mcp";
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* pi-ai treats a hand-declared OpenRouter model as non-reasoning, so every
|
|
74
|
+
* effort but `off` fails with UNSUPPORTED_REASONING_EFFORT. Declare the levels
|
|
75
|
+
* the catalog lists for the model, each sent to OpenRouter under its own name.
|
|
76
|
+
*/
|
|
77
|
+
function openRouterEfforts(model: string): Record<string, string> {
|
|
78
|
+
return Object.fromEntries(
|
|
79
|
+
reasoningCapability("dsh", model).levels.map((level) => [level, level]),
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
36
83
|
class DshSession implements ProviderSession {
|
|
37
84
|
sessionId: string | undefined;
|
|
38
85
|
private listeners: ((event: ProviderEvent) => void)[] = [];
|
|
@@ -42,12 +89,31 @@ class DshSession implements ProviderSession {
|
|
|
42
89
|
private stderr = "";
|
|
43
90
|
private aborted = false;
|
|
44
91
|
private completion: Promise<ProviderResult>;
|
|
92
|
+
private readonly startedAt = Date.now();
|
|
93
|
+
private readonly contextWindow: number;
|
|
94
|
+
/** Highest dsh turn seen. A dsh turn runs one or more steps (model calls). */
|
|
95
|
+
private turns = 0;
|
|
96
|
+
private tokens: DshStepUsage | undefined;
|
|
97
|
+
/** dsh tool_result carries only the call id; the runner wants the tool name. */
|
|
98
|
+
private toolNames = new Map<string, string>();
|
|
45
99
|
|
|
46
100
|
constructor(
|
|
47
101
|
private proc: Bun.Subprocess<"pipe", "pipe", "pipe">,
|
|
48
102
|
private directory: string,
|
|
49
103
|
prompt: string,
|
|
104
|
+
private runInfo: DshRun,
|
|
50
105
|
) {
|
|
106
|
+
this.contextWindow = getContextWindowSize(contextWindowKey(runInfo.model));
|
|
107
|
+
// The stream carries no model id, so log what the patch told dsh to call.
|
|
108
|
+
this.emit({
|
|
109
|
+
type: "raw_log",
|
|
110
|
+
content: JSON.stringify({
|
|
111
|
+
type: "model",
|
|
112
|
+
provider: runInfo.route,
|
|
113
|
+
model: runInfo.modelId,
|
|
114
|
+
...(runInfo.reasoningEffort ? { reasoningEffort: runInfo.reasoningEffort } : {}),
|
|
115
|
+
}),
|
|
116
|
+
});
|
|
51
117
|
this.completion = this.run(prompt);
|
|
52
118
|
}
|
|
53
119
|
|
|
@@ -76,8 +142,25 @@ class DshSession implements ProviderSession {
|
|
|
76
142
|
this.output = event.text;
|
|
77
143
|
} else if (event.type === "error" && typeof event.message === "string") {
|
|
78
144
|
this.failure = event.message;
|
|
145
|
+
} else if (event.type === "tool_call" && typeof event.tool === "string") {
|
|
146
|
+
// The runner turns tool_start into readable task progress, as for the
|
|
147
|
+
// other harnesses. dsh phase names (step_end, ...) are not progress.
|
|
148
|
+
const toolCallId = String(event.callId ?? "");
|
|
149
|
+
this.toolNames.set(toolCallId, event.tool);
|
|
150
|
+
this.emit({
|
|
151
|
+
type: "tool_start",
|
|
152
|
+
toolCallId,
|
|
153
|
+
toolName: event.tool,
|
|
154
|
+
args: event.input ?? {},
|
|
155
|
+
});
|
|
156
|
+
} else if (event.type === "tool_result") {
|
|
157
|
+
const toolCallId = String(event.callId ?? "");
|
|
158
|
+
const toolName = this.toolNames.get(toolCallId) ?? "tool";
|
|
159
|
+
this.toolNames.delete(toolCallId);
|
|
160
|
+
this.emit({ type: "tool_end", toolCallId, toolName, result: event.result });
|
|
79
161
|
} else if (event.type === "status" && typeof event.phase === "string") {
|
|
80
|
-
|
|
162
|
+
if (typeof event.turn === "number") this.turns = Math.max(this.turns, event.turn);
|
|
163
|
+
if (event.phase === "step_end") this.recordStep(event.usage);
|
|
81
164
|
if (event.phase === "turn_end" && event.reason?.kind !== "completed") {
|
|
82
165
|
this.failure =
|
|
83
166
|
typeof event.reason?.error?.message === "string"
|
|
@@ -90,6 +173,47 @@ class DshSession implements ProviderSession {
|
|
|
90
173
|
}
|
|
91
174
|
}
|
|
92
175
|
|
|
176
|
+
private recordStep(usage: unknown): void {
|
|
177
|
+
const step = normalizeDshStepUsage(usage);
|
|
178
|
+
if (!step) return;
|
|
179
|
+
this.tokens = addDshStepUsage(this.tokens, step);
|
|
180
|
+
const { input, output, cacheRead, cacheWrite } = step;
|
|
181
|
+
// One step is one model call, so its prompt plus reply is the context in use.
|
|
182
|
+
const used = input + cacheRead + cacheWrite + output;
|
|
183
|
+
if (used > 0) {
|
|
184
|
+
this.emit({
|
|
185
|
+
type: "context_usage",
|
|
186
|
+
contextUsedTokens: used,
|
|
187
|
+
contextTotalTokens: this.contextWindow,
|
|
188
|
+
contextPercent: clampContextPercent(used, this.contextWindow) ?? 0,
|
|
189
|
+
outputTokens: output,
|
|
190
|
+
contextFormula: CONTEXT_FORMULA,
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
private buildCost(isError: boolean): CostData | undefined {
|
|
196
|
+
if (!this.sessionId || !this.tokens) return undefined;
|
|
197
|
+
return {
|
|
198
|
+
sessionId: this.sessionId,
|
|
199
|
+
taskId: this.runInfo.taskId,
|
|
200
|
+
agentId: this.runInfo.agentId,
|
|
201
|
+
// dsh reports tokens, not money; the API prices them from the dsh rows.
|
|
202
|
+
totalCostUsd: 0,
|
|
203
|
+
inputTokens: this.tokens.input,
|
|
204
|
+
outputTokens: this.tokens.output,
|
|
205
|
+
cacheReadTokens: this.tokens.cacheRead,
|
|
206
|
+
cacheWriteTokens: this.tokens.cacheWrite,
|
|
207
|
+
reasoningOutputTokens: this.tokens.reasoning,
|
|
208
|
+
durationMs: Date.now() - this.startedAt,
|
|
209
|
+
// dsh turns, matching the log viewer's turn rows; steps are model calls.
|
|
210
|
+
numTurns: this.turns,
|
|
211
|
+
model: this.runInfo.model,
|
|
212
|
+
isError,
|
|
213
|
+
provider: "dsh",
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
|
|
93
217
|
private async readStdout(): Promise<void> {
|
|
94
218
|
const decoder = new TextDecoder();
|
|
95
219
|
let buffer = "";
|
|
@@ -111,6 +235,16 @@ class DshSession implements ProviderSession {
|
|
|
111
235
|
const content = scrubSecrets(decoder.decode(chunk, { stream: true }));
|
|
112
236
|
this.stderr = (this.stderr + content).slice(-8000);
|
|
113
237
|
this.emit({ type: "raw_stderr", content });
|
|
238
|
+
// dsh downgrades a failed plugin to a "did not activate" warning even
|
|
239
|
+
// with failOnStartupError, then runs on without the swarm tools. A
|
|
240
|
+
// session that cannot reach store-progress must not pass as healthy.
|
|
241
|
+
if (
|
|
242
|
+
!this.failure &&
|
|
243
|
+
this.stderr.includes(`${DSH_MCP_ENTRY_ID} (@deepseek-ai/dsh-mcp-client)`)
|
|
244
|
+
) {
|
|
245
|
+
this.failure = `dsh could not connect to the swarm MCP server: ${this.stderr.trim().slice(0, 500)}`;
|
|
246
|
+
await terminateProcessGroup(this.proc.pid);
|
|
247
|
+
}
|
|
114
248
|
}
|
|
115
249
|
}
|
|
116
250
|
|
|
@@ -132,18 +266,28 @@ class DshSession implements ProviderSession {
|
|
|
132
266
|
: this.failure || this.stderr.trim() || `dsh exited ${exitCode} without a final result`
|
|
133
267
|
: undefined;
|
|
134
268
|
if (failureReason) this.emit({ type: "error", message: failureReason });
|
|
269
|
+
const cost = this.buildCost(isError);
|
|
270
|
+
if (cost) this.emit({ type: "result", cost, output: this.output, isError });
|
|
135
271
|
return {
|
|
136
272
|
exitCode: isError ? exitCode || 1 : 0,
|
|
137
273
|
sessionId: this.sessionId,
|
|
274
|
+
cost,
|
|
138
275
|
output: this.output,
|
|
139
276
|
isError,
|
|
140
277
|
failureReason,
|
|
278
|
+
appliedReasoningEffort: this.runInfo.reasoningEffort,
|
|
141
279
|
};
|
|
142
280
|
} catch (error) {
|
|
143
281
|
await terminateProcessGroup(this.proc.pid);
|
|
144
282
|
const failureReason = scrubSecrets(String(error));
|
|
145
283
|
this.emit({ type: "error", message: failureReason });
|
|
146
|
-
return {
|
|
284
|
+
return {
|
|
285
|
+
exitCode: 1,
|
|
286
|
+
sessionId: this.sessionId,
|
|
287
|
+
cost: this.buildCost(true),
|
|
288
|
+
isError: true,
|
|
289
|
+
failureReason,
|
|
290
|
+
};
|
|
147
291
|
} finally {
|
|
148
292
|
await rm(this.directory, { recursive: true, force: true });
|
|
149
293
|
}
|
|
@@ -162,7 +306,7 @@ class DshSession implements ProviderSession {
|
|
|
162
306
|
export class DshAdapter implements ProviderAdapter {
|
|
163
307
|
readonly name = "dsh";
|
|
164
308
|
readonly traits: ProviderTraits = {
|
|
165
|
-
hasMcp:
|
|
309
|
+
hasMcp: true,
|
|
166
310
|
hasToolSearch: false,
|
|
167
311
|
nativeSkillDiscovery: false,
|
|
168
312
|
hasLocalEnvironment: true,
|
|
@@ -191,16 +335,24 @@ export class DshAdapter implements ProviderAdapter {
|
|
|
191
335
|
providerLabel: "dsh",
|
|
192
336
|
skillsDir: join(env.HOME ?? "/home/worker", ".agents", "skills"),
|
|
193
337
|
});
|
|
338
|
+
const route = openrouter ? "openrouter" : "deepseek-official";
|
|
339
|
+
const effort = applyReasoningEffort("dsh", model, config.reasoningEffort);
|
|
340
|
+
const reasoningEffort = effort.kind === "dsh-effort" ? effort.reasoningEffort : null;
|
|
194
341
|
const directory = await mkdtemp(join(tmpdir(), "swarm-dsh-"));
|
|
195
342
|
try {
|
|
196
343
|
const patchPath = join(directory, "patch.json");
|
|
344
|
+
const runtimeInstanceId = swarmRuntimeInstanceId();
|
|
197
345
|
// JSON is valid YAML. Values stay data, including arbitrary system prompts.
|
|
198
346
|
await writeFile(
|
|
199
347
|
patchPath,
|
|
200
348
|
JSON.stringify([
|
|
201
349
|
{
|
|
202
350
|
id: "agent-default-model",
|
|
203
|
-
config: {
|
|
351
|
+
config: {
|
|
352
|
+
provider: route,
|
|
353
|
+
model: modelId,
|
|
354
|
+
...(reasoningEffort ? { reasoningEffort } : {}),
|
|
355
|
+
},
|
|
204
356
|
},
|
|
205
357
|
{ id: "system-prompt", config: { personaPrefix: config.systemPrompt } },
|
|
206
358
|
openrouter
|
|
@@ -213,12 +365,50 @@ export class DshAdapter implements ProviderAdapter {
|
|
|
213
365
|
baseURL: getOpenRouterBaseUrl(env),
|
|
214
366
|
api: "openai-completions",
|
|
215
367
|
// Declare the selected ID even if the bundled catalog predates it.
|
|
216
|
-
models: [
|
|
368
|
+
models: [
|
|
369
|
+
reasoningEffort
|
|
370
|
+
? { id: modelId, reasoningEfforts: openRouterEfforts(model) }
|
|
371
|
+
: { id: modelId },
|
|
372
|
+
],
|
|
217
373
|
},
|
|
218
374
|
},
|
|
219
375
|
},
|
|
220
376
|
}
|
|
221
377
|
: { id: "llm-deepseek", config: { apiKeyEnv: keyEnv } },
|
|
378
|
+
// The worker container is the sandbox, as for codex
|
|
379
|
+
// (`danger-full-access`). dsh's workspace-write policy only lets
|
|
380
|
+
// writes through to the cwd and /tmp, has no setting for more
|
|
381
|
+
// roots, and refuses escalation headless, so a dsh agent could not
|
|
382
|
+
// write /workspace/shared or /workspace/personal.
|
|
383
|
+
{
|
|
384
|
+
id: "sandbox-policy",
|
|
385
|
+
config: { mode: "danger-full-access", workspaceRoot: config.cwd },
|
|
386
|
+
},
|
|
387
|
+
{ id: "approval", config: { policy: "never" } },
|
|
388
|
+
// dsh does not mount its MCP client in the headless profile; insert
|
|
389
|
+
// one for the swarm server, with the same per-task identity headers
|
|
390
|
+
// the other adapters send.
|
|
391
|
+
{
|
|
392
|
+
insert: [
|
|
393
|
+
{
|
|
394
|
+
id: DSH_MCP_ENTRY_ID,
|
|
395
|
+
name: "@deepseek-ai/dsh-mcp-client",
|
|
396
|
+
config: {
|
|
397
|
+
serverName: DSH_MCP_SERVER_NAME,
|
|
398
|
+
transport: "streamable-http",
|
|
399
|
+
url: `${config.apiUrl}/mcp`,
|
|
400
|
+
headers: {
|
|
401
|
+
Authorization: `Bearer ${config.apiKey}`,
|
|
402
|
+
"X-Agent-ID": config.agentId,
|
|
403
|
+
"X-Source-Task-Id": config.taskId,
|
|
404
|
+
...(config.contextKey ? { "X-Context-Key": config.contextKey } : {}),
|
|
405
|
+
...(runtimeInstanceId ? { "X-Runtime-Instance-ID": runtimeInstanceId } : {}),
|
|
406
|
+
},
|
|
407
|
+
failOnStartupError: true,
|
|
408
|
+
},
|
|
409
|
+
},
|
|
410
|
+
],
|
|
411
|
+
},
|
|
222
412
|
]),
|
|
223
413
|
{ mode: 0o600 },
|
|
224
414
|
);
|
|
@@ -232,7 +422,14 @@ export class DshAdapter implements ProviderAdapter {
|
|
|
232
422
|
detached: detachedProcessGroup,
|
|
233
423
|
}),
|
|
234
424
|
);
|
|
235
|
-
return new DshSession(proc, directory, prompt
|
|
425
|
+
return new DshSession(proc, directory, prompt, {
|
|
426
|
+
model,
|
|
427
|
+
route,
|
|
428
|
+
modelId,
|
|
429
|
+
reasoningEffort,
|
|
430
|
+
taskId: config.taskId,
|
|
431
|
+
agentId: config.agentId,
|
|
432
|
+
});
|
|
236
433
|
} catch (error) {
|
|
237
434
|
await rm(directory, { recursive: true, force: true });
|
|
238
435
|
throw error;
|
|
@@ -130,6 +130,9 @@ const MODEL_CACHE_REFRESH_TIMEOUT_MS = 15_000;
|
|
|
130
130
|
// "Timeout waiting for server to start after 5000ms". Override via
|
|
131
131
|
// OPENCODE_SERVER_TIMEOUT_MS.
|
|
132
132
|
const DEFAULT_SERVER_START_TIMEOUT_MS = 30_000;
|
|
133
|
+
// Event-stream reconnects before the session gives up on a dead local server.
|
|
134
|
+
// The SDK backs off 3s, 6s, 12s, 24s between attempts, so ~45s in total.
|
|
135
|
+
export const OPENCODE_SSE_MAX_RETRY_ATTEMPTS = 5;
|
|
133
136
|
|
|
134
137
|
function serverStartTimeoutMs(): number {
|
|
135
138
|
return Number(process.env.OPENCODE_SERVER_TIMEOUT_MS) || DEFAULT_SERVER_START_TIMEOUT_MS;
|
|
@@ -1039,15 +1042,33 @@ export class OpencodeAdapter implements ProviderAdapter {
|
|
|
1039
1042
|
const opcVersion = readPkgVersion("@opencode-ai/sdk");
|
|
1040
1043
|
session.emitSessionInit("opencode", opcVersion ? { version: opcVersion } : undefined);
|
|
1041
1044
|
|
|
1042
|
-
// Subscribe to SSE events and drive the session
|
|
1045
|
+
// Subscribe to SSE events and drive the session. The SDK's SSE client
|
|
1046
|
+
// retries a dropped connection forever by default, so a dead `opencode
|
|
1047
|
+
// serve` child would keep the stream (and the session promise) pending
|
|
1048
|
+
// and hold the worker's slot. Cap the retries so the stream ends.
|
|
1043
1049
|
client.event
|
|
1044
|
-
.subscribe({
|
|
1050
|
+
.subscribe({
|
|
1051
|
+
query: { directory: config.cwd },
|
|
1052
|
+
sseMaxRetryAttempts: OPENCODE_SSE_MAX_RETRY_ATTEMPTS,
|
|
1053
|
+
})
|
|
1045
1054
|
.then(async ({ stream }) => {
|
|
1046
1055
|
for await (const event of stream) {
|
|
1047
1056
|
session.handleOpencodeEvent(event as OpencodeEvent);
|
|
1048
1057
|
if (session.isFinished) break;
|
|
1049
1058
|
}
|
|
1050
|
-
//
|
|
1059
|
+
// The stream ended without session.idle: the opencode server closed
|
|
1060
|
+
// or died. Settle the session so the runner releases the slot.
|
|
1061
|
+
if (!session.isFinished) {
|
|
1062
|
+
session.handleOpencodeEvent({
|
|
1063
|
+
type: "session.error",
|
|
1064
|
+
properties: {
|
|
1065
|
+
sessionID: sessionId,
|
|
1066
|
+
error: {
|
|
1067
|
+
message: "runner exited without result: opencode event stream ended",
|
|
1068
|
+
} as never,
|
|
1069
|
+
},
|
|
1070
|
+
});
|
|
1071
|
+
}
|
|
1051
1072
|
})
|
|
1052
1073
|
.catch((err: unknown) => {
|
|
1053
1074
|
session.handleOpencodeEvent({
|
|
@@ -35,6 +35,9 @@ import {
|
|
|
35
35
|
} from "@earendil-works/pi-coding-agent";
|
|
36
36
|
import { type TSchema, Type } from "typebox";
|
|
37
37
|
import "./pi-codemode-runtime";
|
|
38
|
+
// Registers the reprompt template in the code registry (the runner loads it too).
|
|
39
|
+
import "../commands/templates";
|
|
40
|
+
import { resolveTemplateAsync } from "../prompts/resolver";
|
|
38
41
|
import { CORE_TOOLS } from "../tools/tool-config";
|
|
39
42
|
import { classifyAwsSdkError } from "../utils/aws-error-classifier";
|
|
40
43
|
import { parseEnvFlag } from "../utils/env-flag";
|
|
@@ -341,6 +344,18 @@ export function isPiCodemodeEnabled(env: NodeJS.ProcessEnv = process.env): boole
|
|
|
341
344
|
return parseEnvFlag(env.PI_CODEMODE, false);
|
|
342
345
|
}
|
|
343
346
|
|
|
347
|
+
/**
|
|
348
|
+
* `PI_CODEMODE_MODELS`: expose pi's `models` API (`classify()`,
|
|
349
|
+
* `generateImages()`, the model catalog) to codemode scripts. Off by default
|
|
350
|
+
* and only effective while `PI_CODEMODE` is on, so a stray `true` never turns
|
|
351
|
+
* model calls on by itself. pi adds a script's `models.*` usage to the
|
|
352
|
+
* `codemode` tool result and `getSessionStats()` sums it into the session
|
|
353
|
+
* cost the adapter reports (see `src/tests/providers/pi-cost.test.ts`).
|
|
354
|
+
*/
|
|
355
|
+
export function isPiCodemodeModelsEnabled(env: NodeJS.ProcessEnv = process.env): boolean {
|
|
356
|
+
return isPiCodemodeEnabled(env) && parseEnvFlag(env.PI_CODEMODE_MODELS, false);
|
|
357
|
+
}
|
|
358
|
+
|
|
344
359
|
/**
|
|
345
360
|
* Tools that stay declared to the model when deferral is on: the lifecycle
|
|
346
361
|
* set Claude also keeps out of ToolSearch, plus any tool the server preloads
|
|
@@ -735,6 +750,40 @@ export function extractPiAssistantText(message: unknown): string {
|
|
|
735
750
|
return extractTextContent(msg.content);
|
|
736
751
|
}
|
|
737
752
|
|
|
753
|
+
/** What one assistant `message_end` carried, by block type only (never content). */
|
|
754
|
+
interface AssistantTurnShape {
|
|
755
|
+
stopReason?: string;
|
|
756
|
+
blockTypes: string[];
|
|
757
|
+
outputTokens?: number;
|
|
758
|
+
hasText: boolean;
|
|
759
|
+
hasToolCall: boolean;
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
/** Keep log labels to short identifier-like tokens so a log line can never carry content. */
|
|
763
|
+
function safeLabel(value: unknown): string {
|
|
764
|
+
return typeof value === "string" && /^[A-Za-z0-9_-]{1,32}$/.test(value) ? value : "other";
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
function describeAssistantTurn(message: unknown): AssistantTurnShape {
|
|
768
|
+
const msg = (message ?? {}) as {
|
|
769
|
+
content?: unknown;
|
|
770
|
+
stopReason?: unknown;
|
|
771
|
+
usage?: { output?: unknown };
|
|
772
|
+
};
|
|
773
|
+
const blocks = Array.isArray(msg.content) ? msg.content : [];
|
|
774
|
+
const blockTypes = blocks.map((b) => safeLabel((b as { type?: unknown } | null)?.type));
|
|
775
|
+
const output = msg.usage?.output;
|
|
776
|
+
return {
|
|
777
|
+
stopReason: typeof msg.stopReason === "string" ? safeLabel(msg.stopReason) : undefined,
|
|
778
|
+
blockTypes: typeof msg.content === "string" && msg.content.trim() ? ["text"] : blockTypes,
|
|
779
|
+
outputTokens: typeof output === "number" ? output : undefined,
|
|
780
|
+
hasText: extractTextContent(msg.content) !== "",
|
|
781
|
+
hasToolCall: blockTypes.includes("toolCall"),
|
|
782
|
+
};
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
const TERMINAL_STORE_PROGRESS_STATUSES = new Set(["completed", "failed"]);
|
|
786
|
+
|
|
738
787
|
export class PiMonoSession implements ProviderSession {
|
|
739
788
|
private listeners: Array<(event: ProviderEvent) => void> = [];
|
|
740
789
|
private eventQueue: ProviderEvent[] = [];
|
|
@@ -779,6 +828,16 @@ export class PiMonoSession implements ProviderSession {
|
|
|
779
828
|
* task. Checked by `deliverSteering()`.
|
|
780
829
|
*/
|
|
781
830
|
private sessionEnded = false;
|
|
831
|
+
/** Shape of the most recent assistant turn; the last one before idle is the final turn. */
|
|
832
|
+
private lastAssistantTurn: AssistantTurnShape | null = null;
|
|
833
|
+
/** `store-progress` calls with a terminal status that are still running, by tool call id. */
|
|
834
|
+
private pendingTerminalStoreProgress = new Set<string>();
|
|
835
|
+
/** A terminal `store-progress` call (completed or failed) finished without error. */
|
|
836
|
+
private terminalStoreProgressDone = false;
|
|
837
|
+
/** The one-per-session empty-final-turn reprompt has been spent (or skipped for good). */
|
|
838
|
+
private emptyTurnReprompted = false;
|
|
839
|
+
/** `abort()` was called: never prompt a session someone is trying to stop. */
|
|
840
|
+
private abortRequested = false;
|
|
782
841
|
|
|
783
842
|
constructor(
|
|
784
843
|
agentSession: AgentSession,
|
|
@@ -859,6 +918,8 @@ export class PiMonoSession implements ProviderSession {
|
|
|
859
918
|
errorMessage?: string;
|
|
860
919
|
};
|
|
861
920
|
if (endMsg.role === "assistant") {
|
|
921
|
+
const turn = describeAssistantTurn(event.message);
|
|
922
|
+
this.lastAssistantTurn = turn;
|
|
862
923
|
if (endMsg.stopReason === "error") {
|
|
863
924
|
// Candidate terminal failure. May still be cleared by a successful
|
|
864
925
|
// retry (auto_retry_end success / a later good message_end).
|
|
@@ -867,6 +928,16 @@ export class PiMonoSession implements ProviderSession {
|
|
|
867
928
|
}
|
|
868
929
|
// A successful assistant turn means any prior error has recovered.
|
|
869
930
|
this.terminalError = null;
|
|
931
|
+
if (!turn.hasText && !turn.hasToolCall) {
|
|
932
|
+
// Nothing else records these turns: no text and no tool call leaves
|
|
933
|
+
// no trace in session logs. Block types only, never content.
|
|
934
|
+
const tokens =
|
|
935
|
+
turn.outputTokens === undefined ? "" : `, outputTokens=${turn.outputTokens}`;
|
|
936
|
+
this.emit({
|
|
937
|
+
type: "raw_stderr",
|
|
938
|
+
content: `[pi-mono] assistant turn ended with no text and no tool call (stopReason=${turn.stopReason ?? "none"}, content=[${turn.blockTypes.join(",")}]${tokens})\n`,
|
|
939
|
+
});
|
|
940
|
+
}
|
|
870
941
|
}
|
|
871
942
|
// Only assistant text should be printed or used as fallback output.
|
|
872
943
|
const text = extractPiAssistantText(event.message);
|
|
@@ -912,6 +983,14 @@ export class PiMonoSession implements ProviderSession {
|
|
|
912
983
|
break;
|
|
913
984
|
}
|
|
914
985
|
case "tool_execution_start": {
|
|
986
|
+
const status = (event.args as { status?: unknown } | null)?.status;
|
|
987
|
+
if (
|
|
988
|
+
event.toolName.endsWith("store-progress") &&
|
|
989
|
+
typeof status === "string" &&
|
|
990
|
+
TERMINAL_STORE_PROGRESS_STATUSES.has(status)
|
|
991
|
+
) {
|
|
992
|
+
this.pendingTerminalStoreProgress.add(event.toolCallId);
|
|
993
|
+
}
|
|
915
994
|
const model = this.reportedModel();
|
|
916
995
|
this.emit({
|
|
917
996
|
type: "raw_log",
|
|
@@ -936,6 +1015,9 @@ export class PiMonoSession implements ProviderSession {
|
|
|
936
1015
|
break;
|
|
937
1016
|
}
|
|
938
1017
|
case "tool_execution_end":
|
|
1018
|
+
if (this.pendingTerminalStoreProgress.delete(event.toolCallId) && !event.isError) {
|
|
1019
|
+
this.terminalStoreProgressDone = true;
|
|
1020
|
+
}
|
|
939
1021
|
this.emit({
|
|
940
1022
|
type: "raw_log",
|
|
941
1023
|
content: JSON.stringify({
|
|
@@ -986,6 +1068,8 @@ export class PiMonoSession implements ProviderSession {
|
|
|
986
1068
|
// Wait for the agent to finish (poll until not streaming)
|
|
987
1069
|
await this.waitForIdle();
|
|
988
1070
|
|
|
1071
|
+
await this.repromptAfterEmptyFinalTurn();
|
|
1072
|
+
|
|
989
1073
|
// Gather cost data
|
|
990
1074
|
const stats = this.agentSession.getSessionStats();
|
|
991
1075
|
const cost = this.buildCostData(stats);
|
|
@@ -1059,6 +1143,56 @@ export class PiMonoSession implements ProviderSession {
|
|
|
1059
1143
|
}
|
|
1060
1144
|
}
|
|
1061
1145
|
|
|
1146
|
+
/**
|
|
1147
|
+
* Some models end a session on an assistant turn with no text block and no
|
|
1148
|
+
* tool call (thinking only, or empty content). pi treats that as a clean end,
|
|
1149
|
+
* so a task that needed `store-progress` finishes without a result. Send one
|
|
1150
|
+
* reprompt through the normal prompt path, then wait for idle again.
|
|
1151
|
+
*
|
|
1152
|
+
* Skipped when the final turn has text or a tool call, when it errored or was
|
|
1153
|
+
* aborted, when a terminal `store-progress` call already succeeded, and after
|
|
1154
|
+
* the first reprompt (a second empty turn is not retried).
|
|
1155
|
+
*/
|
|
1156
|
+
private async repromptAfterEmptyFinalTurn(): Promise<void> {
|
|
1157
|
+
if (this.emptyTurnReprompted || !this.finalTurnNeedsReprompt()) return;
|
|
1158
|
+
this.emptyTurnReprompted = true;
|
|
1159
|
+
try {
|
|
1160
|
+
const reprompt = await resolveTemplateAsync("task.nudge.empty_final_turn", {});
|
|
1161
|
+
if (reprompt.skipped || !reprompt.text.trim()) return;
|
|
1162
|
+
// Workers render templates over HTTP, so abort() or a late event can land
|
|
1163
|
+
// while the render is pending. Re-check before starting a new model turn.
|
|
1164
|
+
if (!this.finalTurnNeedsReprompt()) return;
|
|
1165
|
+
this.emit({
|
|
1166
|
+
type: "raw_stderr",
|
|
1167
|
+
content: "[pi-mono] final turn had no text and no tool call; sending one reprompt\n",
|
|
1168
|
+
});
|
|
1169
|
+
await this.agentSession.prompt(reprompt.text, { source: "rpc" });
|
|
1170
|
+
await this.waitForIdle();
|
|
1171
|
+
} catch (err) {
|
|
1172
|
+
// The original outcome stands: a failed nudge must not turn a finished
|
|
1173
|
+
// session into a failed one.
|
|
1174
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
1175
|
+
this.emit({
|
|
1176
|
+
type: "raw_stderr",
|
|
1177
|
+
content: `[pi-mono] empty-turn reprompt failed: ${message}\n`,
|
|
1178
|
+
});
|
|
1179
|
+
}
|
|
1180
|
+
}
|
|
1181
|
+
|
|
1182
|
+
/** True while the session is still entitled to the one empty-turn reprompt. */
|
|
1183
|
+
private finalTurnNeedsReprompt(): boolean {
|
|
1184
|
+
const turn = this.lastAssistantTurn;
|
|
1185
|
+
return !(
|
|
1186
|
+
this.abortRequested ||
|
|
1187
|
+
this.terminalError ||
|
|
1188
|
+
this.terminalStoreProgressDone ||
|
|
1189
|
+
!turn ||
|
|
1190
|
+
turn.hasText ||
|
|
1191
|
+
turn.hasToolCall ||
|
|
1192
|
+
turn.stopReason === "aborted"
|
|
1193
|
+
);
|
|
1194
|
+
}
|
|
1195
|
+
|
|
1062
1196
|
private waitForIdle(): Promise<void> {
|
|
1063
1197
|
return new Promise<void>((resolve) => {
|
|
1064
1198
|
// Check if already idle
|
|
@@ -1115,6 +1249,7 @@ export class PiMonoSession implements ProviderSession {
|
|
|
1115
1249
|
}
|
|
1116
1250
|
|
|
1117
1251
|
async abort(): Promise<void> {
|
|
1252
|
+
this.abortRequested = true;
|
|
1118
1253
|
await this.agentSession.abort();
|
|
1119
1254
|
}
|
|
1120
1255
|
|
|
@@ -1141,6 +1276,8 @@ export interface PiSessionFeatures {
|
|
|
1141
1276
|
installedMcp?: boolean;
|
|
1142
1277
|
/** PI_CODEMODE is on. */
|
|
1143
1278
|
codemode?: boolean;
|
|
1279
|
+
/** PI_CODEMODE_MODELS is on, with codemode: scripts get the `models` API. */
|
|
1280
|
+
codemodeModels?: boolean;
|
|
1144
1281
|
}
|
|
1145
1282
|
|
|
1146
1283
|
/**
|
|
@@ -1162,7 +1299,13 @@ export function piExtensionFactories(
|
|
|
1162
1299
|
const factories: ExtensionFactory[] = [swarmExtension];
|
|
1163
1300
|
if (features.toolDeferral) factories.push(createToolSearchExtension());
|
|
1164
1301
|
if (features.installedMcp) factories.push(createSwarmMcpExtension());
|
|
1165
|
-
if (features.codemode)
|
|
1302
|
+
if (features.codemode) {
|
|
1303
|
+
factories.push(
|
|
1304
|
+
createBoundedCodemodeExtension(DEFAULT_CODEMODE_LIMITS, {
|
|
1305
|
+
models: features.codemodeModels === true,
|
|
1306
|
+
}),
|
|
1307
|
+
);
|
|
1308
|
+
}
|
|
1166
1309
|
return factories;
|
|
1167
1310
|
}
|
|
1168
1311
|
|
|
@@ -1192,13 +1335,16 @@ const DEFAULT_CODEMODE_LIMITS: CodemodeLimits = {
|
|
|
1192
1335
|
* the sandbox, which interrupts the QuickJS worker and fails the codemode call.
|
|
1193
1336
|
*
|
|
1194
1337
|
* "on" keeps declared tools declared; "only" would hide the lifecycle tools
|
|
1195
|
-
* behind scripts. `models
|
|
1196
|
-
*
|
|
1338
|
+
* behind scripts. `models` stays off unless `PI_CODEMODE_MODELS` asks for it.
|
|
1339
|
+
* pi 1.0 puts a script's `models.*` usage on the `codemode` tool result and
|
|
1340
|
+
* `getSessionStats()` sums it, so model calls from scripts do not bypass the
|
|
1341
|
+
* session's cost accounting.
|
|
1197
1342
|
*/
|
|
1198
1343
|
export function createBoundedCodemodeExtension(
|
|
1199
1344
|
limits: CodemodeLimits = DEFAULT_CODEMODE_LIMITS,
|
|
1345
|
+
options: { models?: boolean } = {},
|
|
1200
1346
|
): ExtensionFactory {
|
|
1201
|
-
const codemode = createCodemodeExtension({ mode: "on", models:
|
|
1347
|
+
const codemode = createCodemodeExtension({ mode: "on", models: options.models === true });
|
|
1202
1348
|
return (pi) =>
|
|
1203
1349
|
codemode(
|
|
1204
1350
|
new Proxy(pi, {
|
|
@@ -1482,9 +1628,12 @@ export class PiMonoAdapter implements ProviderAdapter {
|
|
|
1482
1628
|
toolDeferral: deferTools,
|
|
1483
1629
|
installedMcp: Object.keys(piMcpServers).length > 0,
|
|
1484
1630
|
codemode: isPiCodemodeEnabled(),
|
|
1631
|
+
codemodeModels: isPiCodemodeModelsEnabled(),
|
|
1485
1632
|
};
|
|
1486
1633
|
if (features.codemode) {
|
|
1487
|
-
console.log(
|
|
1634
|
+
console.log(
|
|
1635
|
+
`\x1b[2m[${config.role}]\x1b[0m codemode on${features.codemodeModels ? " (models)" : ""}`,
|
|
1636
|
+
);
|
|
1488
1637
|
}
|
|
1489
1638
|
|
|
1490
1639
|
// 5. Create resource loader with system prompt + extensions. SDK sessions
|
|
@@ -405,7 +405,7 @@ export async function summarizeSessionForPi(
|
|
|
405
405
|
}
|
|
406
406
|
|
|
407
407
|
if (wantRatings && result.ratings && result.ratings.length > 0) {
|
|
408
|
-
const ratingEvents = _buildRatings(result.ratings, retrievals);
|
|
408
|
+
const ratingEvents = _buildRatings(result.ratings, retrievals, result.model);
|
|
409
409
|
if (ratingEvents.length > 0) {
|
|
410
410
|
await _postRatings({
|
|
411
411
|
apiUrl: config.apiUrl,
|
|
@@ -48,10 +48,14 @@ rate by hand should also update this file.
|
|
|
48
48
|
default full id (e.g. `opus → claude-opus-4-7`). Pi-mono uses the same
|
|
49
49
|
shortname forms, so they're projected under `provider='pi'` as well.
|
|
50
50
|
- OpenAI models → rows under `provider='codex'`.
|
|
51
|
-
- OpenRouter models → rows under `provider='opencode'
|
|
51
|
+
- OpenRouter models → rows under `provider='opencode'`, `provider='pi'` and
|
|
52
|
+
`provider='dsh'` (dsh strips `openrouter/` at lookup). Any `google/...`
|
|
52
53
|
row additionally gets projected under `provider='gemini'` (both the
|
|
53
54
|
stripped name and the full `google/...` id) so internal-ai callers find
|
|
54
55
|
a hit either way.
|
|
56
|
+
- DeepSeek direct-API models (models.dev `deepseek` section, bare ids) →
|
|
57
|
+
rows under `provider='dsh'`. dsh's `deepseek-flash` id is not in that
|
|
58
|
+
section and stays `unpriced`.
|
|
55
59
|
|
|
56
60
|
- **Snapshot refresh procedure**:
|
|
57
61
|
- Run `bun run scripts/refresh-modelsdev-pricing.ts` (Phase 2 — adds the
|