@desplega.ai/agent-swarm 1.143.0 → 1.145.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 +2 -0
- package/dist/{acp-adapter-qhzzpz4b.js → acp-adapter-580t41c0.js} +5 -5
- package/dist/{actions-6s03jvk8.js → actions-m662tjng.js} +20 -19
- package/dist/{anthropic-messages-jc89gynp.js → anthropic-messages-vs2rabzp.js} +5 -5
- package/dist/app-zb3rndm8.js +28 -0
- package/dist/{artifact-wpy087er.js → artifact-gj9arwrr.js} +5 -5
- package/dist/{assistant-42xa0m4e.js → assistant-0qt42nzg.js} +22 -21
- package/dist/{azure-openai-responses-5qwmjys3.js → azure-openai-responses-cqar64rc.js} +5 -5
- package/dist/{boot-reembed-vx4fkhgd.js → boot-reembed-072x00vn.js} +15 -14
- package/dist/{boot-reembed-we49a2kr.js → boot-reembed-65zz2smt.js} +16 -15
- package/dist/{boot-scrub-logs-zefgmq2b.js → boot-scrub-logs-yz0ams04.js} +12 -11
- package/dist/{claude-adapter-nm0essg1.js → claude-adapter-paj270y2.js} +36 -25
- package/dist/{claude-wqn3dtca.js → claude-k04qfvsv.js} +1 -1
- package/dist/{claude-managed-adapter-vtseey1x.js → claude-managed-adapter-sactwn31.js} +5 -5
- package/dist/{claude-managed-setup-3zqp51cr.js → claude-managed-setup-w619jncn.js} +2 -2
- package/dist/claude-sdk-session-swt80j9z.js +39101 -0
- package/dist/{cli-qh4sqfws.js → cli-07jd68a1.js} +1 -1
- package/dist/{cli-9zjf3ahs.js → cli-123q2get.js} +56 -21
- package/dist/{cli-dcn5dc6j.js → cli-1ebpar1q.js} +14 -14
- package/dist/{cli-s9y6zv37.js → cli-1fj0chdk.js} +5 -5
- package/dist/{cli-7jcc9y1r.js → cli-1m2e086m.js} +1 -1
- package/dist/{cli-ppwm8c6e.js → cli-2daksqps.js} +4 -1
- package/dist/{cli-f64gdfxc.js → cli-2djtr51b.js} +1 -1
- package/dist/{cli-a4ajmfvp.js → cli-3aqnbv8r.js} +2 -2
- package/dist/{cli-mez7x2z0.js → cli-4j8k1m4w.js} +4 -4
- package/dist/{cli-vjkzg867.js → cli-4xz3pmrq.js} +13 -13
- package/dist/{cli-nkn0ka5p.js → cli-51tf7ac3.js} +1 -1
- package/dist/{cli-gy07xk4s.js → cli-53rm0rrz.js} +1 -1
- package/dist/{cli-787ph852.js → cli-55qrx3q8.js} +3 -3
- package/dist/{cli-sshnjch3.js → cli-59ej1c07.js} +10 -448
- package/dist/{cli-f3s9dry0.js → cli-5bfdm1ah.js} +1 -1
- package/dist/{cli-zxrec1gh.js → cli-65vqzz3v.js} +64 -41
- package/dist/{cli-9w49enmh.js → cli-76yrvwsa.js} +9 -3
- package/dist/{cli-87zrjxdb.js → cli-7fnkj1hj.js} +2 -2
- package/dist/{cli-dwwz52tw.js → cli-7nxes1hs.js} +1 -1
- package/dist/{cli-w2jy8x2r.js → cli-81r683bv.js} +5 -5
- package/dist/{cli-rnyttbh0.js → cli-87rg4p7x.js} +1 -1
- package/dist/{cli-mnm7w46e.js → cli-8fc8de14.js} +1 -1
- package/dist/{cli-56anwfxj.js → cli-9xvdm3bx.js} +12 -12
- package/dist/{cli-63erbyda.js → cli-a0g1gbt5.js} +3 -3
- package/dist/{cli-vsap7a8d.js → cli-aehm1rbq.js} +1 -1
- package/dist/{cli-cppy3dz4.js → cli-anktweqr.js} +6 -6
- package/dist/{cli-jmkqrhpm.js → cli-axs8e6d4.js} +1 -1
- package/dist/{cli-a3pkfpqs.js → cli-b5b30yzk.js} +2 -2
- package/dist/{cli-pq2ee5ja.js → cli-bc05qbss.js} +38 -1
- package/dist/{cli-497b685t.js → cli-bd957dgb.js} +1 -1
- package/dist/{cli-00w4hbam.js → cli-btbzvq95.js} +1 -1
- package/dist/{cli-8e1r79yq.js → cli-bxdhw615.js} +6 -6
- package/dist/{cli-xbyjkasx.js → cli-c2mk1kgf.js} +1 -1
- package/dist/{cli-35h7kw0d.js → cli-c71mg51n.js} +1 -1
- package/dist/{cli-gpt9kf01.js → cli-cg4vnyh4.js} +13 -13
- package/dist/{cli-s9yg23fg.js → cli-cmp8g3sw.js} +8 -3
- package/dist/{cli-d62cd9qs.js → cli-cn6mmc7f.js} +3 -3
- package/dist/{cli-srjj750f.js → cli-ct0et58h.js} +9 -9
- package/dist/{cli-ewvk4ceg.js → cli-dc9k2ba9.js} +10 -4
- package/dist/{cli-rx5cxzn2.js → cli-dpvkp2et.js} +1 -1
- package/dist/{cli-tdtmw1r5.js → cli-dt553ktb.js} +1 -1
- package/dist/{cli-a1rrkrb4.js → cli-e29gmdmw.js} +1 -1
- package/dist/{cli-nanaxrz6.js → cli-ej6gbxfb.js} +1 -1
- package/dist/cli-eree7rnv.js +25 -0
- package/dist/{cli-wtyyc7ev.js → cli-f567d5c1.js} +60 -22
- package/dist/cli-f7kvq46p.js +32 -0
- package/dist/{cli-b4g3p5y2.js → cli-fs1kkqgr.js} +5 -5
- package/dist/{cli-2z3qhdg0.js → cli-gh8y8f36.js} +1 -1
- package/dist/{cli-vr2nfxtt.js → cli-gxnzc6wh.js} +11 -11
- package/dist/{cli-4kj5adw0.js → cli-gzky0gkr.js} +4 -4
- package/dist/{cli-jepmgn7r.js → cli-j490egb5.js} +1 -1
- package/dist/{cli-7pnwg2vx.js → cli-jmb7g47h.js} +918 -174
- package/dist/{cli-wrfhh2qz.js → cli-jnf5zghe.js} +2 -2
- package/dist/{cli-q6d0vvey.js → cli-jyetr64j.js} +3 -3
- package/dist/{cli-whrvct19.js → cli-knd276ed.js} +1 -1
- package/dist/{cli-r3bxcgrj.js → cli-kpev657q.js} +2 -2
- package/dist/{cli-6garengg.js → cli-m1xa8be7.js} +6 -6
- package/dist/{cli-mjf432kq.js → cli-m4j6trn4.js} +3 -3
- package/dist/{cli-rzhcrw2p.js → cli-n011tws7.js} +1 -1
- package/dist/{cli-tkf8n6cw.js → cli-pdz9qde4.js} +2 -2
- package/dist/{cli-9y5b02vr.js → cli-pp9ax9pa.js} +1 -1
- package/dist/{cli-pmz8qr82.js → cli-pw9rj5t9.js} +1 -1
- package/dist/{cli-qntkxysp.js → cli-pzxba7gw.js} +209 -165
- package/dist/{cli-m4dadbv4.js → cli-q34a0e10.js} +2 -2
- package/dist/{cli-qf9kpsve.js → cli-q51yprfq.js} +2 -2
- package/dist/{cli-c5ddbdfj.js → cli-qa66qaf0.js} +2 -2
- package/dist/{cli-g814jbst.js → cli-qghpvca2.js} +1 -1
- package/dist/{cli-wvdvxjep.js → cli-qgm2pfpq.js} +1 -1
- package/dist/{cli-dx3dz0ms.js → cli-rembwgt8.js} +2 -2
- package/dist/{cli-mvsztzgn.js → cli-rs6ec3b9.js} +13 -14
- package/dist/{cli-hgkw1x1k.js → cli-rvqz34y5.js} +6 -6
- package/dist/{cli-qe636hdh.js → cli-s2f20r5w.js} +4 -4
- package/dist/{cli-6t2fgxpv.js → cli-s2qjdd6z.js} +2 -2
- package/dist/{cli-s35981d0.js → cli-sd0mxa3c.js} +2 -2
- package/dist/{cli-1cwhyvta.js → cli-sxbwep7h.js} +1 -1
- package/dist/{cli-65d93ves.js → cli-tcvj7j2r.js} +3 -3
- package/dist/{cli-tpa83vxb.js → cli-tqtvj5pt.js} +1 -1
- package/dist/{cli-6hy7hej2.js → cli-txgcknmy.js} +1 -1
- package/dist/{cli-qjwdtyxn.js → cli-v0asr5yv.js} +279 -200
- package/dist/{cli-0v7jxbvz.js → cli-vj6h9kc2.js} +1 -1
- package/dist/{cli-3cgfyfzm.js → cli-w1d1bgkk.js} +3 -3
- package/dist/{cli-pqv5gvyf.js → cli-w5e1d1vv.js} +1 -1
- package/dist/{cli-vn8s7wtf.js → cli-wvp6bvy4.js} +2 -2
- package/dist/{cli-mkq1rk7b.js → cli-xqcq9y5e.js} +1 -1
- package/dist/{cli-8p37s71j.js → cli-xvkmedgn.js} +2 -2
- package/dist/{cli-jdtvfcyw.js → cli-xytwff7f.js} +2 -2
- package/dist/{cli-g2p9bd1z.js → cli-yatxqynm.js} +1 -1
- package/dist/{cli-z6nsjrh1.js → cli-ygbjp3z8.js} +41 -6
- package/dist/{cli-9bnajfes.js → cli-z96t0thj.js} +1 -1
- package/dist/{cli-bdyxycq6.js → cli-z9fprcrf.js} +7829 -1008
- package/dist/cli-zf8jjwex.js +34 -0
- package/dist/cli.js +44 -38
- package/dist/{codex-adapter-zvh2pgah.js → codex-adapter-k98vaw2r.js} +17 -17
- package/dist/{codex-hook-79p3xs7j.js → codex-hook-9pf19cks.js} +5 -5
- package/dist/{codex-login-x7603481.js → codex-login-vx7ghkzj.js} +1 -1
- package/dist/{codex-session-runner-bs8tsjx5.js → codex-session-runner-tngtphx7.js} +17 -17
- package/dist/{commands-c73m6m2j.js → commands-y8nbr3fv.js} +12 -11
- package/dist/{db-n2bgwkr3.js → db-30p4h2t1.js} +16 -11
- package/dist/{devin-adapter-8qmhqpy3.js → devin-adapter-8vgkwh29.js} +1 -1
- package/dist/{devtools-j2rnj8w7.js → devtools-qpc3j21w.js} +3 -3
- package/dist/{e2b-b7jt70fc.js → e2b-6hb103d8.js} +11 -11
- package/dist/{es5-fmqrjzy3.js → es5-tj3tn4jj.js} +1 -1
- package/dist/{event-bus-n8sb35pw.js → event-bus-sfx8dx3t.js} +3 -2
- package/dist/{getMachineId-bsd-wpzbhkm6.js → getMachineId-bsd-xj3bn2fv.js} +3 -3
- package/dist/{getMachineId-darwin-45zabjy0.js → getMachineId-darwin-07jzjcx6.js} +3 -3
- package/dist/{getMachineId-linux-warnp5pd.js → getMachineId-linux-ahngynxd.js} +2 -2
- package/dist/{getMachineId-unsupported-5spent2a.js → getMachineId-unsupported-vy43b44z.js} +2 -2
- package/dist/{getMachineId-win-v4bvcw7a.js → getMachineId-win-8x66cynz.js} +3 -3
- package/dist/{google-generative-ai-nnw57f3t.js → google-generative-ai-tsskx7te.js} +5 -5
- package/dist/{google-vertex-rxwnws1y.js → google-vertex-ppw8ydpa.js} +6 -6
- package/dist/{handlers-s768yzzt.js → handlers-yfp1qn81.js} +23 -22
- package/dist/{hook-m950r3r8.js → hook-21jexvfx.js} +15 -15
- package/dist/hook-dcw4jfbj.js +35 -0
- package/dist/{http-5rqpbf9g.js → http-r4kq5g8d.js} +1241 -431
- package/dist/{index-shne41sd.js → index-1kq5hw2p.js} +12 -12
- package/dist/index-1p8wdstt.js +7 -0
- package/dist/{index-e19s2m8k.js → index-2sp0384z.js} +8 -8
- package/dist/{index-qgvkk4mz.js → index-53zyht4z.js} +589 -29
- package/dist/{index-t36q2v4t.js → index-66xz5e9j.js} +2 -2
- package/dist/{index-emvxcy98.js → index-8bn5jm6d.js} +3 -3
- package/dist/{index-ns5kksc1.js → index-8fdjzb2f.js} +4 -4
- package/dist/{index-1nsdwvn5.js → index-aa3sa6s8.js} +8 -8
- package/dist/{index-yqweff5n.js → index-bxmwzbgw.js} +2 -2
- package/dist/{index-g9tttwkm.js → index-f6cryxwe.js} +2 -2
- package/dist/{index-d9f3yqc5.js → index-gay66b9w.js} +30 -29
- package/dist/{index-agykc6k2.js → index-n5t1gzfb.js} +4 -4
- package/dist/index-nqvf26za.js +53 -0
- package/dist/index-nzerxd5z.js +7 -0
- package/dist/{index-3e03k6e4.js → index-pyymnzat.js} +5 -5
- package/dist/index-q3qja6ta.js +54 -0
- package/dist/{index-pdxc8kfh.js → index-qv6atbab.js} +5 -5
- package/dist/{index-ptcqm8bc.js → index-rja32qa7.js} +5 -5
- package/dist/{index-gqnmr60d.js → index-tzg5srfp.js} +5 -5
- package/dist/{index-20xqmn3v.js → index-vhncw983.js} +3 -3
- package/dist/{index-7m8yxkw5.js → index-xk036zsk.js} +7 -7
- package/dist/index-zyazbzcb.js +6 -0
- package/dist/{keepalive-sc7pvszh.js → keepalive-xs8fa55y.js} +14 -13
- package/dist/lead-d9m2t4s0.js +95 -0
- package/dist/maintenance-3zh82g6z.js +30 -0
- package/dist/{mistral-conversations-gnnamk9c.js → mistral-conversations-4ryk7h83.js} +2 -2
- package/dist/{multipart-parser-6gftesw0.js → multipart-parser-c33er1yp.js} +2 -2
- package/dist/{node-0zgg64ps.js → node-agg3zs4s.js} +1 -1
- package/dist/{node-nxwyzp1j.js → node-x1g4v0pq.js} +3 -3
- package/dist/{oauth-refresh-sweep-xrydav2q.js → oauth-refresh-sweep-03snsye5.js} +13 -12
- package/dist/{onboard-972xcrsh.js → onboard-0cg1925x.js} +7 -7
- package/dist/{openai-codex-responses-y1qgyvmt.js → openai-codex-responses-g7w48y30.js} +5 -5
- package/dist/{openai-completions-ccrxm4b6.js → openai-completions-0bqmsajw.js} +4 -4
- package/dist/{openai-responses-6r5d4z8y.js → openai-responses-nmeyptke.js} +5 -5
- package/dist/{opencode-adapter-krfzs6pd.js → opencode-adapter-fef1mrn2.js} +9 -9
- package/dist/{openrouter-images-71hthwh9.js → openrouter-images-qx18fyp8.js} +2 -2
- package/dist/{otel-impl-q0mt4sy8.js → otel-impl-0ab95z27.js} +11 -11
- package/dist/{photon_rs-8dwt2pzy.js → photon_rs-q3vet37k.js} +1 -1
- package/dist/{pi-messages-kmr52r41.js → pi-messages-79jvzz1d.js} +3 -3
- package/dist/{pi-mono-adapter-9tb0c3jh.js → pi-mono-adapter-dtkz4e7j.js} +37 -37
- package/dist/pricing-refresh-e5jhzz4j.js +23 -0
- package/dist/{rbac-roles-vxy05wcn.js → rbac-roles-2w3cmrkc.js} +13 -12
- package/dist/rbac-roles-p1mf40z3.js +33 -0
- package/dist/{registry-6nvn6bj0.js → registry-9kdck5ye.js} +1 -1
- package/dist/render-v2-xhawry3k.js +40 -0
- package/dist/seed-pricing-t223sw91.js +20 -0
- package/dist/{setup-frgenxn8.js → setup-zcs0rce7.js} +7 -7
- package/dist/{token-xg5711x5.js → token-78fepns5.js} +3 -3
- package/dist/token-util-0rrc1ybd.js +6 -0
- package/dist/worker-qnp2ka62.js +95 -0
- package/dist/{x-xkfh0w0v.js → x-n2phr5vm.js} +3 -3
- package/openapi.json +962 -4
- package/package.json +9 -3
- package/src/artifact-sdk/browser-sdk.ts +7 -3
- package/src/be/db.ts +41 -3
- package/src/be/migrations/145_slack_render_v2_delegation.sql +12 -0
- package/src/be/scripts/typecheck.ts +35 -0
- package/src/be/seed-skills/bundled-files.generated.json +4 -0
- package/src/be/swarm-config-guard.ts +9 -0
- package/src/commands/runner.ts +54 -7
- package/src/http/agents.ts +267 -91
- package/src/http/all-routes.ts +2 -0
- package/src/http/auth.ts +25 -1
- package/src/http/db-query-shared.ts +43 -22
- package/src/http/index.ts +30 -6
- package/src/http/kv.ts +16 -1
- package/src/http/memory.ts +37 -3
- package/src/http/page-proxy.ts +8 -5
- package/src/http/pages-public.ts +7 -6
- package/src/http/pages.ts +16 -3
- package/src/http/realtime.ts +28 -0
- package/src/http/rooms.ts +314 -0
- package/src/http/route-def.ts +8 -2
- package/src/http/tasks.ts +1 -1
- package/src/http/utils.ts +104 -7
- package/src/kv-reserved-namespaces.ts +6 -0
- package/src/providers/claude-adapter.ts +120 -309
- package/src/providers/claude-sdk-session.ts +586 -0
- package/src/providers/claude-session-events.ts +247 -0
- package/src/rbac/legacy-policy.ts +1 -0
- package/src/rbac/permissions.ts +4 -0
- package/src/realtime/auth.ts +130 -0
- package/src/realtime/browser.generated.txt +69 -0
- package/src/realtime/browser.ts +382 -0
- package/src/realtime/bus.ts +33 -0
- package/src/realtime/document.ts +529 -0
- package/src/realtime/rooms.ts +575 -0
- package/src/realtime/transport.ts +406 -0
- package/src/realtime/tsconfig.browser.json +14 -0
- package/src/scripts-runtime/ctx.ts +1 -2
- package/src/scripts-runtime/sdk-allowlist.ts +6 -0
- package/src/scripts-runtime/swarm-sdk.ts +35 -7
- package/src/scripts-runtime/types/stdlib.d.ts +65 -0
- package/src/scripts-runtime/types/swarm-sdk.d.ts +65 -0
- package/src/server-user.ts +28 -16
- package/src/server.ts +10 -0
- package/src/slack/ack.ts +39 -19
- package/src/slack/closure.ts +66 -0
- package/src/slack/render-v2.ts +404 -36
- package/src/tasks/terminal-result-guard.ts +14 -1
- package/src/tests/agents-harness-provider.test.ts +254 -0
- package/src/tests/artifact-sdk.test.ts +12 -2
- package/src/tests/claude-hook-credentials.test.ts +84 -0
- package/src/tests/claude-sdk-lifecycle.test.ts +262 -0
- package/src/tests/claude-sdk-live-lifecycle.test.ts +272 -0
- package/src/tests/claude-sdk-process.fixture.ts +223 -0
- package/src/tests/claude-sdk-transport.test.ts +289 -0
- package/src/tests/claude-worker-parity.test.ts +574 -0
- package/src/tests/db-query.test.ts +73 -0
- package/src/tests/db-retention.test.ts +2 -1
- package/src/tests/docs-index-footprint.test.js +4 -3
- package/src/tests/e2e-claude-transport.test.ts +204 -0
- package/src/tests/e2e-nightly-report.test.ts +41 -4
- package/src/tests/fetch-resolved-env.test.ts +126 -0
- package/src/tests/harness-provider-resolution.test.ts +7 -0
- package/src/tests/internal-ai/complete-structured.test.ts +2 -0
- package/src/tests/memory-edit-authorization.test.ts +295 -0
- package/src/tests/page-proxy.test.ts +223 -27
- package/src/tests/page-session.test.ts +32 -0
- package/src/tests/page-viewer-auth.test.ts +182 -0
- package/src/tests/pages-public-html.test.ts +3 -0
- package/src/tests/rbac-engine.test.ts +1 -0
- package/src/tests/realtime-room-auth.test.ts +68 -0
- package/src/tests/realtime-room-surfaces.test.ts +329 -0
- package/src/tests/realtime-rooms.test.ts +343 -0
- package/src/tests/realtime-transport.test.ts +551 -0
- package/src/tests/runner-session-outcome.test.ts +28 -0
- package/src/tests/sandboxed-process.test.ts +20 -8
- package/src/tests/seed-skills-bundled-files.test.ts +1 -0
- package/src/tests/send-task-output-schema.test.ts +247 -0
- package/src/tests/slack-closure.test.ts +183 -0
- package/src/tests/slack-relay-obligations.test.ts +10 -0
- package/src/tests/slack-render-v2-delegation.test.ts +373 -0
- package/src/tests/slack-render-v2.test.ts +1107 -5
- package/src/tests/spec-base-url.test.ts +2 -1
- package/src/tests/structured-output.test.ts +31 -0
- package/src/tests/tool-annotations.test.ts +41 -6
- package/src/tools/kv/kv-delete.ts +5 -1
- package/src/tools/kv/kv-incr.ts +5 -1
- package/src/tools/kv/kv-set.ts +5 -1
- package/src/tools/kv/kv-write-auth.ts +6 -1
- package/src/tools/memory-edit.ts +37 -2
- package/src/tools/rooms.ts +171 -0
- package/src/tools/send-task.ts +29 -0
- package/src/tools/tool-config.ts +26 -22
- package/src/types.ts +3 -1
- package/src/utils/claude-transport.ts +36 -0
- package/src/utils/internal-ai/complete-structured.ts +2 -1
- package/src/utils/page-session.ts +21 -28
- package/src/utils/request-auth-context.ts +6 -2
- package/src/utils/sandboxed-process.ts +31 -22
- package/src/workflows/event-bus.ts +6 -10
- package/src/workflows/executors/swarm-script.ts +2 -0
- package/src/workflows/json-schema-validator.ts +52 -0
- package/templates/skills/pages/content.md +147 -8
- package/templates/skills/pages/files/examples/multiplayer-board.html +416 -0
- package/tsconfig.json +1 -0
- package/dist/app-zej2afh5.js +0 -27
- package/dist/cli-95m51ztz.js +0 -28
- package/dist/hook-xn3pevet.js +0 -35
- package/dist/index-1qthq7vc.js +0 -6
- package/dist/index-ag4bxqkp.js +0 -53
- package/dist/index-tcnvv8w6.js +0 -7
- package/dist/index-vb4b1nts.js +0 -52
- package/dist/index-w91qbfv1.js +0 -7
- package/dist/lead-5zcqts8e.js +0 -93
- package/dist/maintenance-45j327y6.js +0 -29
- package/dist/pricing-refresh-s7n1nec8.js +0 -22
- package/dist/rbac-roles-hpph0s5w.js +0 -32
- package/dist/render-v2-8vk0y1js.js +0 -35
- package/dist/seed-pricing-an8qdaxz.js +0 -19
- package/dist/token-util-zy908s1a.js +0 -6
- package/dist/worker-0w9fdwds.js +0 -93
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import { afterEach, describe, expect, test } from "bun:test";
|
|
2
|
+
import { mkdir, mkdtemp, rm } from "node:fs/promises";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { ClaudeAdapter } from "../providers/claude-adapter";
|
|
6
|
+
import type { ProviderEvent, ProviderSession, ProviderSessionConfig } from "../providers/types";
|
|
7
|
+
import { runChild } from "./test-proc";
|
|
8
|
+
|
|
9
|
+
const runLive = process.env.RUN_CLAUDE_SDK_LIFECYCLE === "1";
|
|
10
|
+
const liveTest = runLive ? test : test.skip;
|
|
11
|
+
const temporaryDirectories: string[] = [];
|
|
12
|
+
|
|
13
|
+
async function temporaryDirectory(): Promise<string> {
|
|
14
|
+
const path = await mkdtemp(join(tmpdir(), "claude-sdk-live-lifecycle-"));
|
|
15
|
+
await Promise.all([
|
|
16
|
+
mkdir(join(path, "home")),
|
|
17
|
+
mkdir(join(path, "claude-config")),
|
|
18
|
+
mkdir(join(path, "tmp")),
|
|
19
|
+
]);
|
|
20
|
+
temporaryDirectories.push(path);
|
|
21
|
+
return path;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function liveConfig(directory: string, prompt: string): ProviderSessionConfig {
|
|
25
|
+
const oauthToken = process.env.CLAUDE_CODE_OAUTH_TOKEN;
|
|
26
|
+
if (!oauthToken) throw new Error("CLAUDE_CODE_OAUTH_TOKEN is required for this live test");
|
|
27
|
+
const executable = process.env.CLAUDE_SDK_LIFECYCLE_BINARY?.trim() || Bun.which("claude") || "";
|
|
28
|
+
if (!executable) throw new Error("Claude Code was not found on PATH");
|
|
29
|
+
return {
|
|
30
|
+
prompt,
|
|
31
|
+
systemPrompt: "",
|
|
32
|
+
model: process.env.CLAUDE_SDK_LIFECYCLE_MODEL || "claude-haiku-4-5",
|
|
33
|
+
role: "worker",
|
|
34
|
+
agentId: crypto.randomUUID(),
|
|
35
|
+
taskId: crypto.randomUUID(),
|
|
36
|
+
apiUrl: "",
|
|
37
|
+
apiKey: "",
|
|
38
|
+
cwd: directory,
|
|
39
|
+
logFile: join(directory, "session.jsonl"),
|
|
40
|
+
additionalArgs: ["--max-turns", "6"],
|
|
41
|
+
env: {
|
|
42
|
+
PATH: process.env.PATH ?? "/usr/bin:/bin",
|
|
43
|
+
USER: process.env.USER ?? "worker",
|
|
44
|
+
LANG: process.env.LANG ?? "C.UTF-8",
|
|
45
|
+
TMPDIR: join(directory, "tmp"),
|
|
46
|
+
HOME: join(directory, "home"),
|
|
47
|
+
CLAUDE_CONFIG_DIR: join(directory, "claude-config"),
|
|
48
|
+
CLAUDECODE: "",
|
|
49
|
+
CLAUDE_CODE_OAUTH_TOKEN: oauthToken,
|
|
50
|
+
CLAUDE_TRANSPORT: "sdk",
|
|
51
|
+
CLAUDE_QUEUE_STEERING: "1",
|
|
52
|
+
CLAUDE_BINARY: executable,
|
|
53
|
+
SWARM_USE_CLAUDE_BRIDGE: "0",
|
|
54
|
+
} as Record<string, string>,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async function settleWithin<T>(promise: Promise<T>, timeoutMs: number): Promise<T> {
|
|
59
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
60
|
+
try {
|
|
61
|
+
return await Promise.race([
|
|
62
|
+
promise,
|
|
63
|
+
new Promise<never>((_, reject) => {
|
|
64
|
+
timer = setTimeout(() => reject(new Error(`Timed out after ${timeoutMs}ms`)), timeoutMs);
|
|
65
|
+
}),
|
|
66
|
+
]);
|
|
67
|
+
} finally {
|
|
68
|
+
if (timer) clearTimeout(timer);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async function waitForFile(path: string, timeoutMs: number): Promise<void> {
|
|
73
|
+
const deadline = Date.now() + timeoutMs;
|
|
74
|
+
while (!(await Bun.file(path).exists())) {
|
|
75
|
+
if (Date.now() >= deadline) throw new Error(`Timed out waiting for ${path}`);
|
|
76
|
+
await Bun.sleep(100);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function processExists(pid: number): boolean {
|
|
81
|
+
try {
|
|
82
|
+
process.kill(pid, 0);
|
|
83
|
+
return true;
|
|
84
|
+
} catch (error) {
|
|
85
|
+
if ((error as NodeJS.ErrnoException).code === "ESRCH") return false;
|
|
86
|
+
throw error;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async function waitForProcessExit(pid: number, timeoutMs: number): Promise<boolean> {
|
|
91
|
+
const deadline = Date.now() + timeoutMs;
|
|
92
|
+
while ((await processIsRunning(pid)) && Date.now() < deadline) await Bun.sleep(100);
|
|
93
|
+
return !(await processIsRunning(pid));
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async function commandForPid(pid: number): Promise<string> {
|
|
97
|
+
const result = await runChild(["/bin/ps", "-p", String(pid), "-o", "command="], {
|
|
98
|
+
timeoutMs: 1_000,
|
|
99
|
+
});
|
|
100
|
+
return result.stdout.trim();
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
async function processIsRunning(pid: number): Promise<boolean> {
|
|
104
|
+
if (!processExists(pid)) return false;
|
|
105
|
+
const status = await runChild(["/bin/ps", "-p", String(pid), "-o", "stat="], {
|
|
106
|
+
timeoutMs: 1_000,
|
|
107
|
+
});
|
|
108
|
+
const state = status.stdout.trim();
|
|
109
|
+
return state !== "" && !state.startsWith("Z");
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
async function cleanFixturePid(pid: number, marker: string): Promise<void> {
|
|
113
|
+
if (!processExists(pid)) return;
|
|
114
|
+
if (!(await commandForPid(pid)).includes(marker)) return;
|
|
115
|
+
try {
|
|
116
|
+
process.kill(pid, "SIGKILL");
|
|
117
|
+
} catch (error) {
|
|
118
|
+
if ((error as NodeJS.ErrnoException).code !== "ESRCH") throw error;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
async function abortQuietly(session: ProviderSession | undefined): Promise<void> {
|
|
123
|
+
if (!session) return;
|
|
124
|
+
await session.abort("live lifecycle cleanup").catch(() => {});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
afterEach(async () => {
|
|
128
|
+
await Promise.all(temporaryDirectories.splice(0).map((path) => rm(path, { recursive: true })));
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
describe("Claude SDK live lifecycle", () => {
|
|
132
|
+
liveTest(
|
|
133
|
+
"delivers simultaneous queued messages and reports explicit compaction",
|
|
134
|
+
async () => {
|
|
135
|
+
const directory = await temporaryDirectory();
|
|
136
|
+
let session: ProviderSession | undefined;
|
|
137
|
+
try {
|
|
138
|
+
session = await new ClaudeAdapter(async () => {}).createSession(
|
|
139
|
+
liveConfig(
|
|
140
|
+
directory,
|
|
141
|
+
"Reply with INITIAL_ACK. Continue until every queued message is handled.",
|
|
142
|
+
),
|
|
143
|
+
);
|
|
144
|
+
const events: ProviderEvent[] = [];
|
|
145
|
+
let completedResults = 0;
|
|
146
|
+
let warmupDelivery: ReturnType<NonNullable<ProviderSession["deliverSteering"]>>;
|
|
147
|
+
let compactionRequested = false;
|
|
148
|
+
let markersRequested = false;
|
|
149
|
+
let compactionDelivery: ReturnType<NonNullable<ProviderSession["deliverSteering"]>>;
|
|
150
|
+
let markerDeliveries: Promise<unknown[]>;
|
|
151
|
+
session.onEvent((event) => {
|
|
152
|
+
events.push(event);
|
|
153
|
+
if (event.type === "result") completedResults++;
|
|
154
|
+
if (event.type === "result" && completedResults === 1) {
|
|
155
|
+
warmupDelivery = session!.deliverSteering!({
|
|
156
|
+
mode: "queue",
|
|
157
|
+
text: "Reply with SECOND_ACK only.",
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
if (event.type === "result" && completedResults === 2 && !compactionRequested) {
|
|
161
|
+
compactionRequested = true;
|
|
162
|
+
compactionDelivery = session!.deliverSteering!({ mode: "queue", text: "/compact" });
|
|
163
|
+
}
|
|
164
|
+
if (event.type === "compaction" && !markersRequested) {
|
|
165
|
+
markersRequested = true;
|
|
166
|
+
markerDeliveries = Promise.all([
|
|
167
|
+
session!.deliverSteering!({
|
|
168
|
+
mode: "queue",
|
|
169
|
+
text: "Reply with both exact markers QUEUE_ALPHA and QUEUE_BETA.",
|
|
170
|
+
}),
|
|
171
|
+
session!.deliverSteering!({
|
|
172
|
+
mode: "queue",
|
|
173
|
+
text: "Confirm both exact markers QUEUE_ALPHA and QUEUE_BETA.",
|
|
174
|
+
}),
|
|
175
|
+
]);
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
const result = await settleWithin(session.waitForCompletion(), 90_000);
|
|
179
|
+
expect(await warmupDelivery!).toEqual({ delivered: true, mode: "queue" });
|
|
180
|
+
expect(await compactionDelivery!).toEqual({ delivered: true, mode: "queue" });
|
|
181
|
+
expect(await markerDeliveries!).toEqual([
|
|
182
|
+
{ delivered: true, mode: "queue" },
|
|
183
|
+
{ delivered: true, mode: "queue" },
|
|
184
|
+
]);
|
|
185
|
+
expect(result).toMatchObject({ exitCode: 0, isError: false });
|
|
186
|
+
expect(result.output).toContain("QUEUE_ALPHA");
|
|
187
|
+
expect(result.output).toContain("QUEUE_BETA");
|
|
188
|
+
expect(events.some((event) => event.type === "compaction")).toBeTrue();
|
|
189
|
+
const compaction = events.find((event) => event.type === "compaction");
|
|
190
|
+
if (compaction?.type === "compaction") {
|
|
191
|
+
console.log(
|
|
192
|
+
JSON.stringify({
|
|
193
|
+
probe: "claude-sdk-compaction",
|
|
194
|
+
preCompactTokens: compaction.preCompactTokens,
|
|
195
|
+
trigger: compaction.compactTrigger,
|
|
196
|
+
}),
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
expect(events).toContainEqual(
|
|
200
|
+
expect.objectContaining({
|
|
201
|
+
type: "session_init",
|
|
202
|
+
providerMeta: { transport: "sdk" },
|
|
203
|
+
}),
|
|
204
|
+
);
|
|
205
|
+
} finally {
|
|
206
|
+
await abortQuietly(session);
|
|
207
|
+
}
|
|
208
|
+
},
|
|
209
|
+
{ timeout: 100_000 },
|
|
210
|
+
);
|
|
211
|
+
|
|
212
|
+
liveTest(
|
|
213
|
+
"cancels the Claude fixture and its child process",
|
|
214
|
+
async () => {
|
|
215
|
+
const directory = await temporaryDirectory();
|
|
216
|
+
const stateFile = join(directory, "fixture-pids.json");
|
|
217
|
+
await Bun.write(
|
|
218
|
+
join(directory, "hold.ts"),
|
|
219
|
+
`const child = Bun.spawn(["/bin/sleep", "60"], { stdin: "ignore", stdout: "ignore", stderr: "ignore" });\n` +
|
|
220
|
+
`await Bun.write(process.argv[2], JSON.stringify({ fixturePid: process.pid, childPid: child.pid }));\n` +
|
|
221
|
+
`await child.exited;\n`,
|
|
222
|
+
);
|
|
223
|
+
let session: ProviderSession | undefined;
|
|
224
|
+
let fixturePid: number | undefined;
|
|
225
|
+
let childPid: number | undefined;
|
|
226
|
+
try {
|
|
227
|
+
session = await new ClaudeAdapter(async () => {}).createSession(
|
|
228
|
+
liveConfig(
|
|
229
|
+
directory,
|
|
230
|
+
"Use Bash to run exactly: bun hold.ts fixture-pids.json. Wait for it to finish.",
|
|
231
|
+
),
|
|
232
|
+
);
|
|
233
|
+
await waitForFile(stateFile, 45_000);
|
|
234
|
+
const pids = JSON.parse(await Bun.file(stateFile).text()) as {
|
|
235
|
+
fixturePid: number;
|
|
236
|
+
childPid: number;
|
|
237
|
+
};
|
|
238
|
+
fixturePid = pids.fixturePid;
|
|
239
|
+
childPid = pids.childPid;
|
|
240
|
+
expect(processExists(fixturePid)).toBeTrue();
|
|
241
|
+
expect(processExists(childPid)).toBeTrue();
|
|
242
|
+
|
|
243
|
+
const cancellationStartedAt = performance.now();
|
|
244
|
+
await settleWithin(session.abort("live fixture cancellation"), 5_000);
|
|
245
|
+
const cancellationElapsedMs = Math.round(performance.now() - cancellationStartedAt);
|
|
246
|
+
expect(cancellationElapsedMs).toBeLessThan(5_000);
|
|
247
|
+
const result = await settleWithin(session.waitForCompletion(), 10_000);
|
|
248
|
+
expect(result).toMatchObject({
|
|
249
|
+
exitCode: 130,
|
|
250
|
+
isError: true,
|
|
251
|
+
errorCategory: "cancelled",
|
|
252
|
+
failureReason: "live fixture cancellation",
|
|
253
|
+
});
|
|
254
|
+
expect(await waitForProcessExit(fixturePid, 5_000)).toBeTrue();
|
|
255
|
+
expect(await waitForProcessExit(childPid, 5_000)).toBeTrue();
|
|
256
|
+
console.log(
|
|
257
|
+
JSON.stringify({
|
|
258
|
+
probe: "claude-sdk-cancellation",
|
|
259
|
+
cancellationElapsedMs,
|
|
260
|
+
fixtureExited: true,
|
|
261
|
+
childExited: true,
|
|
262
|
+
}),
|
|
263
|
+
);
|
|
264
|
+
} finally {
|
|
265
|
+
await abortQuietly(session);
|
|
266
|
+
if (fixturePid) await cleanFixturePid(fixturePid, "hold.ts");
|
|
267
|
+
if (childPid) await cleanFixturePid(childPid, "/bin/sleep 60");
|
|
268
|
+
}
|
|
269
|
+
},
|
|
270
|
+
{ timeout: 75_000 },
|
|
271
|
+
);
|
|
272
|
+
});
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
const mode = process.env.CLAUDE_SDK_FIXTURE_MODE;
|
|
2
|
+
const stateFile = process.env.CLAUDE_SDK_FIXTURE_STATE_FILE;
|
|
3
|
+
const sessionId = "11111111-1111-4111-8111-111111111111";
|
|
4
|
+
|
|
5
|
+
if (process.argv.includes("--version")) {
|
|
6
|
+
if (process.env.CLAUDE_SDK_FIXTURE_UNKNOWN_VERSION === "1") process.exit(1);
|
|
7
|
+
console.log("2.1.263 (Claude Code)");
|
|
8
|
+
process.exit(0);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
if (!mode || !stateFile) {
|
|
12
|
+
console.error("CLAUDE_SDK_FIXTURE_MODE and CLAUDE_SDK_FIXTURE_STATE_FILE are required");
|
|
13
|
+
process.exit(2);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function writeMessage(message: Record<string, unknown>): void {
|
|
17
|
+
console.log(JSON.stringify(message));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function assistantMessage(text: string, turn: number): Record<string, unknown> {
|
|
21
|
+
return {
|
|
22
|
+
type: "assistant",
|
|
23
|
+
message: {
|
|
24
|
+
id: `message-${turn}`,
|
|
25
|
+
type: "message",
|
|
26
|
+
role: "assistant",
|
|
27
|
+
model: "claude-haiku-4-5",
|
|
28
|
+
content: [{ type: "text", text }],
|
|
29
|
+
stop_reason: "end_turn",
|
|
30
|
+
stop_sequence: null,
|
|
31
|
+
usage: {
|
|
32
|
+
input_tokens: turn * 10,
|
|
33
|
+
output_tokens: turn,
|
|
34
|
+
cache_read_input_tokens: 0,
|
|
35
|
+
cache_creation_input_tokens: 0,
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
parent_tool_use_id: null,
|
|
39
|
+
uuid: crypto.randomUUID(),
|
|
40
|
+
session_id: sessionId,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function resultMessage(
|
|
45
|
+
result: string,
|
|
46
|
+
turn: number,
|
|
47
|
+
queuedTurnCount: number,
|
|
48
|
+
): Record<string, unknown> {
|
|
49
|
+
return {
|
|
50
|
+
type: "result",
|
|
51
|
+
subtype: "success",
|
|
52
|
+
duration_ms: turn,
|
|
53
|
+
duration_api_ms: turn,
|
|
54
|
+
is_error: false,
|
|
55
|
+
num_turns: turn,
|
|
56
|
+
result,
|
|
57
|
+
stop_reason: "end_turn",
|
|
58
|
+
total_cost_usd: turn / 1000,
|
|
59
|
+
usage: {
|
|
60
|
+
input_tokens: turn * 10,
|
|
61
|
+
output_tokens: turn,
|
|
62
|
+
cache_read_input_tokens: 0,
|
|
63
|
+
cache_creation_input_tokens: 0,
|
|
64
|
+
},
|
|
65
|
+
modelUsage: {},
|
|
66
|
+
permission_denials: [],
|
|
67
|
+
queued_turn_count: queuedTurnCount,
|
|
68
|
+
uuid: crypto.randomUUID(),
|
|
69
|
+
session_id: sessionId,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function errorResultMessage(): Record<string, unknown> {
|
|
74
|
+
return {
|
|
75
|
+
type: "result",
|
|
76
|
+
subtype: "error_during_execution",
|
|
77
|
+
duration_ms: 1,
|
|
78
|
+
duration_api_ms: 1,
|
|
79
|
+
is_error: true,
|
|
80
|
+
num_turns: 0,
|
|
81
|
+
stop_reason: null,
|
|
82
|
+
total_cost_usd: 0,
|
|
83
|
+
usage: {
|
|
84
|
+
input_tokens: 0,
|
|
85
|
+
output_tokens: 0,
|
|
86
|
+
cache_read_input_tokens: 0,
|
|
87
|
+
cache_creation_input_tokens: 0,
|
|
88
|
+
},
|
|
89
|
+
modelUsage: {},
|
|
90
|
+
permission_denials: [],
|
|
91
|
+
queued_turn_count: 0,
|
|
92
|
+
errors: [],
|
|
93
|
+
uuid: crypto.randomUUID(),
|
|
94
|
+
session_id: sessionId,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function emitInit(): void {
|
|
99
|
+
writeMessage({
|
|
100
|
+
type: "system",
|
|
101
|
+
subtype: "init",
|
|
102
|
+
session_id: sessionId,
|
|
103
|
+
model: "claude-haiku-4-5",
|
|
104
|
+
tools: [],
|
|
105
|
+
mcp_servers: [],
|
|
106
|
+
plugins: [],
|
|
107
|
+
permissionMode: "bypassPermissions",
|
|
108
|
+
slash_commands: [],
|
|
109
|
+
apiKeySource: "none",
|
|
110
|
+
cwd: process.cwd(),
|
|
111
|
+
claude_code_version: "2.1.263",
|
|
112
|
+
output_style: "default",
|
|
113
|
+
skills: [],
|
|
114
|
+
uuid: crypto.randomUUID(),
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function answerInitialize(requestId: string): void {
|
|
119
|
+
writeMessage({
|
|
120
|
+
type: "control_response",
|
|
121
|
+
response: {
|
|
122
|
+
subtype: "success",
|
|
123
|
+
request_id: requestId,
|
|
124
|
+
response: {
|
|
125
|
+
commands: [],
|
|
126
|
+
agents: [],
|
|
127
|
+
output_style: "default",
|
|
128
|
+
available_output_styles: [],
|
|
129
|
+
models: [],
|
|
130
|
+
account: {},
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const decoder = new TextDecoder();
|
|
137
|
+
let buffer = "";
|
|
138
|
+
let initialized = false;
|
|
139
|
+
const userMessages: string[] = [];
|
|
140
|
+
const argv = process.argv.slice(2);
|
|
141
|
+
|
|
142
|
+
if (mode === "cancel") {
|
|
143
|
+
const child = Bun.spawn(["/bin/sleep", "60"], {
|
|
144
|
+
stdin: "ignore",
|
|
145
|
+
stdout: "ignore",
|
|
146
|
+
stderr: "ignore",
|
|
147
|
+
});
|
|
148
|
+
await Bun.write(stateFile, JSON.stringify({ fixturePid: process.pid, childPid: child.pid }));
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
async function handleLine(line: string): Promise<boolean> {
|
|
152
|
+
if (!line.trim()) return false;
|
|
153
|
+
const message = JSON.parse(line) as {
|
|
154
|
+
type?: string;
|
|
155
|
+
request_id?: string;
|
|
156
|
+
request?: { subtype?: string };
|
|
157
|
+
message?: { content?: unknown };
|
|
158
|
+
};
|
|
159
|
+
if (message.type === "control_request" && message.request?.subtype === "initialize") {
|
|
160
|
+
answerInitialize(message.request_id ?? "fixture-initialize");
|
|
161
|
+
if (!initialized) {
|
|
162
|
+
initialized = true;
|
|
163
|
+
emitInit();
|
|
164
|
+
}
|
|
165
|
+
return false;
|
|
166
|
+
}
|
|
167
|
+
if (message.type !== "user") return false;
|
|
168
|
+
const content = message.message?.content;
|
|
169
|
+
const text =
|
|
170
|
+
typeof content === "string"
|
|
171
|
+
? content
|
|
172
|
+
: Array.isArray(content)
|
|
173
|
+
? content
|
|
174
|
+
.filter(
|
|
175
|
+
(block): block is { type: "text"; text: string } =>
|
|
176
|
+
typeof block === "object" &&
|
|
177
|
+
block !== null &&
|
|
178
|
+
(block as { type?: unknown }).type === "text" &&
|
|
179
|
+
typeof (block as { text?: unknown }).text === "string",
|
|
180
|
+
)
|
|
181
|
+
.map((block) => block.text)
|
|
182
|
+
.join("")
|
|
183
|
+
: "";
|
|
184
|
+
userMessages.push(text);
|
|
185
|
+
|
|
186
|
+
if (mode === "stderr-error") {
|
|
187
|
+
writeMessage(errorResultMessage());
|
|
188
|
+
await Bun.sleep(25);
|
|
189
|
+
console.error("Error: rate limit exceeded in fixture stderr tail");
|
|
190
|
+
return true;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if (mode !== "queue" || userMessages.length < 3) return false;
|
|
194
|
+
await Bun.write(stateFile, JSON.stringify({ argv, userMessages }));
|
|
195
|
+
for (let index = 0; index < userMessages.length; index++) {
|
|
196
|
+
const turn = index + 1;
|
|
197
|
+
writeMessage(assistantMessage(`accepted:${userMessages[index]}`, turn));
|
|
198
|
+
writeMessage(resultMessage(`accepted:${userMessages[index]}`, turn, 2 - index));
|
|
199
|
+
if (turn === 2) {
|
|
200
|
+
writeMessage({
|
|
201
|
+
type: "system",
|
|
202
|
+
subtype: "compact_boundary",
|
|
203
|
+
compact_metadata: { trigger: "auto", pre_tokens: 1234, post_tokens: 321 },
|
|
204
|
+
uuid: crypto.randomUUID(),
|
|
205
|
+
session_id: sessionId,
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
return true;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
for await (const chunk of Bun.stdin.stream()) {
|
|
213
|
+
buffer += decoder.decode(chunk, { stream: true });
|
|
214
|
+
let newline = buffer.indexOf("\n");
|
|
215
|
+
while (newline >= 0) {
|
|
216
|
+
const line = buffer.slice(0, newline);
|
|
217
|
+
buffer = buffer.slice(newline + 1);
|
|
218
|
+
if (await handleLine(line)) process.exit(0);
|
|
219
|
+
newline = buffer.indexOf("\n");
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (buffer.trim()) await handleLine(buffer);
|