@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
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
isStatus,
|
|
20
20
|
loggerFor,
|
|
21
21
|
promiseWithResolvers
|
|
22
|
-
} from "./cli-
|
|
22
|
+
} from "./cli-zp38xvtm.js";
|
|
23
23
|
import"./cli-51tf7ac3.js";
|
|
24
24
|
import"./cli-bc05qbss.js";
|
|
25
25
|
|
|
@@ -31,20 +31,6 @@ import * as cp from "node:child_process";
|
|
|
31
31
|
import * as crypto2 from "node:crypto";
|
|
32
32
|
import * as readline from "node:readline";
|
|
33
33
|
|
|
34
|
-
// node_modules/@earendil-works/pi-ai/node_modules/@anthropic-ai/sdk/lib/transform-json-schema.mjs
|
|
35
|
-
var SUPPORTED_STRING_FORMATS = new Set([
|
|
36
|
-
"date-time",
|
|
37
|
-
"time",
|
|
38
|
-
"date",
|
|
39
|
-
"duration",
|
|
40
|
-
"email",
|
|
41
|
-
"hostname",
|
|
42
|
-
"uri",
|
|
43
|
-
"ipv4",
|
|
44
|
-
"ipv6",
|
|
45
|
-
"uuid"
|
|
46
|
-
]);
|
|
47
|
-
|
|
48
34
|
// node_modules/@earendil-works/pi-ai/node_modules/@anthropic-ai/sdk/helpers/beta/json-schema.mjs
|
|
49
35
|
function betaTool(options) {
|
|
50
36
|
if (options.inputSchema.type !== "object") {
|
|
@@ -379,209 +365,215 @@ var OWNER_ONLY_FILE_MODE = 384;
|
|
|
379
365
|
var OWNER_ONLY_EXEC_MODE = 448;
|
|
380
366
|
var O_NOFOLLOW = C.O_NOFOLLOW ?? 0;
|
|
381
367
|
var O_NONBLOCK = C.O_NONBLOCK ?? 0;
|
|
368
|
+
var FileStoreError = /* @__PURE__ */ (() => {
|
|
382
369
|
|
|
383
|
-
class
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
370
|
+
class FileStoreError2 extends Error {
|
|
371
|
+
constructor(reason, relPath) {
|
|
372
|
+
super(`path ${JSON.stringify(relPath)} ${reason}`);
|
|
373
|
+
this.name = "FileStoreError";
|
|
374
|
+
this.reason = reason;
|
|
375
|
+
this.relPath = relPath;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
FileStoreError2.ESCAPES_ROOT = "escapes the store root";
|
|
379
|
+
FileStoreError2.IS_A_SYMLINK = "is a symlink";
|
|
380
|
+
FileStoreError2.NOT_A_FILE = "is not a regular file";
|
|
381
|
+
FileStoreError2.NOT_A_DIRECTORY = "is not a directory";
|
|
382
|
+
FileStoreError2.NOT_UTF8 = "is not valid utf-8";
|
|
383
|
+
FileStoreError2.MOVE_DESTINATION_EXISTS = "already exists";
|
|
384
|
+
return FileStoreError2;
|
|
385
|
+
})();
|
|
397
386
|
function isPathLegal(p) {
|
|
398
387
|
return p.startsWith("/") && !p.split("/").includes("..");
|
|
399
388
|
}
|
|
389
|
+
var FileStore = /* @__PURE__ */ (() => {
|
|
400
390
|
|
|
401
|
-
class
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
}
|
|
422
|
-
async createRoot() {
|
|
423
|
-
await makeDirAndAncestors(this.rootPath);
|
|
424
|
-
}
|
|
425
|
-
root() {
|
|
426
|
-
return { path: this.rootPath, removedOnDispose: this.removedOnDispose };
|
|
427
|
-
}
|
|
428
|
-
async dispose() {
|
|
429
|
-
if (!this.removedOnDispose)
|
|
430
|
-
return;
|
|
431
|
-
await fsp.rm(this.rootPath, { recursive: true, force: true });
|
|
432
|
-
}
|
|
433
|
-
async put(relPath, data, opts) {
|
|
434
|
-
const tail = relPath.replace(/\\/g, "/");
|
|
435
|
-
if (tail.endsWith("/") || tail.endsWith("/.") || tail === "" || tail === ".") {
|
|
436
|
-
throw new FileStoreError(FileStoreError.NOT_A_FILE, relPath);
|
|
391
|
+
class FileStore2 {
|
|
392
|
+
constructor(root, removedOnDispose, utf8Only = false) {
|
|
393
|
+
this.hashes = new Map;
|
|
394
|
+
this.rootPath = root;
|
|
395
|
+
this.removedOnDispose = removedOnDispose;
|
|
396
|
+
this.decoder = utf8Only ? new TextDecoder("utf-8", { fatal: true }) : undefined;
|
|
397
|
+
}
|
|
398
|
+
static async open(root, opts) {
|
|
399
|
+
if (!platformSupported()) {
|
|
400
|
+
throw new Error("FileStore requires O_NOFOLLOW support on this platform");
|
|
401
|
+
}
|
|
402
|
+
let removedOnDispose = false;
|
|
403
|
+
try {
|
|
404
|
+
await fsp.lstat(root);
|
|
405
|
+
} catch (e) {
|
|
406
|
+
if (e.code !== "ENOENT")
|
|
407
|
+
throw e;
|
|
408
|
+
removedOnDispose = true;
|
|
409
|
+
}
|
|
410
|
+
return new FileStore2(path.resolve(root), removedOnDispose, opts?.utf8 ?? false);
|
|
437
411
|
}
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
this.requireUtf8(relPath, payload);
|
|
441
|
-
await makeDirsBelowRoot(this.rootPath, path.dirname(dest));
|
|
442
|
-
await replaceViaTemp(dest, payload, opts?.executable ?? false);
|
|
443
|
-
}
|
|
444
|
-
async get(relPath) {
|
|
445
|
-
const dest = this.resolveUnderRoot(relPath);
|
|
446
|
-
let handle;
|
|
447
|
-
try {
|
|
448
|
-
handle = await openRegularFile(relPath, dest);
|
|
449
|
-
} catch (e) {
|
|
450
|
-
if (e.code === "ENOENT")
|
|
451
|
-
return null;
|
|
452
|
-
throw e;
|
|
412
|
+
async createRoot() {
|
|
413
|
+
await makeDirAndAncestors(this.rootPath);
|
|
453
414
|
}
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
const buf = await handle.readFile();
|
|
457
|
-
data = new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
458
|
-
} finally {
|
|
459
|
-
await handle.close();
|
|
415
|
+
root() {
|
|
416
|
+
return { path: this.rootPath, removedOnDispose: this.removedOnDispose };
|
|
460
417
|
}
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
}
|
|
464
|
-
async ls(under = "/") {
|
|
465
|
-
const base = this.resolveUnderRoot(under);
|
|
466
|
-
return new Set((await filenamesInDir(this.rootPath, under, base)).map(([rel]) => rel));
|
|
467
|
-
}
|
|
468
|
-
async findSymlinks(under = "/") {
|
|
469
|
-
const base = this.resolveUnderRoot(under);
|
|
470
|
-
return symlinksInDir(this.rootPath, under, base);
|
|
471
|
-
}
|
|
472
|
-
async hashtree(under = "/") {
|
|
473
|
-
const base = this.resolveUnderRoot(under);
|
|
474
|
-
const walkStartNs = _internals.nowNs();
|
|
475
|
-
const out = Object.create(null);
|
|
476
|
-
for (const [rel, full] of await filenamesInDir(this.rootPath, under, base)) {
|
|
477
|
-
const sha = await this.hashViaCache(rel, full, walkStartNs);
|
|
478
|
-
if (sha !== null)
|
|
479
|
-
out[rel] = sha;
|
|
480
|
-
}
|
|
481
|
-
return out;
|
|
482
|
-
}
|
|
483
|
-
async hashFile(relPath) {
|
|
484
|
-
const dest = this.resolveUnderRoot(relPath);
|
|
485
|
-
let st;
|
|
486
|
-
try {
|
|
487
|
-
st = await fsp.lstat(dest, { bigint: true });
|
|
488
|
-
} catch (e) {
|
|
489
|
-
if (e.code === "ENOENT")
|
|
490
|
-
return null;
|
|
491
|
-
throw e;
|
|
492
|
-
}
|
|
493
|
-
if (st.isSymbolicLink())
|
|
494
|
-
throw new FileStoreError(FileStoreError.IS_A_SYMLINK, relPath);
|
|
495
|
-
if (!st.isFile())
|
|
496
|
-
throw new FileStoreError(FileStoreError.NOT_A_FILE, relPath);
|
|
497
|
-
const rel = path.relative(this.rootPath, dest).split(path.sep).join("/");
|
|
498
|
-
return this.hashViaCache(rel, dest, _internals.nowNs());
|
|
499
|
-
}
|
|
500
|
-
async move(src, dst) {
|
|
501
|
-
const s = this.resolveUnderRoot(src);
|
|
502
|
-
const d = this.resolveUnderRoot(dst);
|
|
503
|
-
if (s === this.rootPath || d === this.rootPath)
|
|
504
|
-
return;
|
|
505
|
-
const dstExists = await fsp.stat(d).then(() => true, () => false);
|
|
506
|
-
if (dstExists)
|
|
507
|
-
throw new FileStoreError(FileStoreError.MOVE_DESTINATION_EXISTS, dst);
|
|
508
|
-
await makeDirsBelowRoot(this.rootPath, path.dirname(d));
|
|
509
|
-
await fsp.rename(s, d);
|
|
510
|
-
}
|
|
511
|
-
async remove(relPath) {
|
|
512
|
-
const dest = this.resolveUnderRoot(relPath);
|
|
513
|
-
if (dest === this.rootPath)
|
|
514
|
-
return;
|
|
515
|
-
let st;
|
|
516
|
-
try {
|
|
517
|
-
st = await fsp.lstat(dest, { bigint: true });
|
|
518
|
-
} catch (e) {
|
|
519
|
-
if (e.code === "ENOENT")
|
|
418
|
+
async dispose() {
|
|
419
|
+
if (!this.removedOnDispose)
|
|
520
420
|
return;
|
|
521
|
-
|
|
421
|
+
await fsp.rm(this.rootPath, { recursive: true, force: true });
|
|
522
422
|
}
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
423
|
+
async put(relPath, data, opts) {
|
|
424
|
+
const tail = relPath.replace(/\\/g, "/");
|
|
425
|
+
if (tail.endsWith("/") || tail.endsWith("/.") || tail === "" || tail === ".") {
|
|
426
|
+
throw new FileStoreError(FileStoreError.NOT_A_FILE, relPath);
|
|
427
|
+
}
|
|
428
|
+
const dest = this.resolveUnderRoot(relPath);
|
|
429
|
+
const payload = typeof data === "string" ? encodeUTF8(data) : data;
|
|
430
|
+
this.requireUtf8(relPath, payload);
|
|
431
|
+
await makeDirsBelowRoot(this.rootPath, path.dirname(dest));
|
|
432
|
+
await replaceViaTemp(dest, payload, opts?.executable ?? false);
|
|
433
|
+
}
|
|
434
|
+
async get(relPath) {
|
|
435
|
+
const dest = this.resolveUnderRoot(relPath);
|
|
436
|
+
let handle;
|
|
526
437
|
try {
|
|
527
|
-
await
|
|
438
|
+
handle = await openRegularFile(relPath, dest);
|
|
528
439
|
} catch (e) {
|
|
529
|
-
if (e.code
|
|
530
|
-
|
|
440
|
+
if (e.code === "ENOENT")
|
|
441
|
+
return null;
|
|
442
|
+
throw e;
|
|
443
|
+
}
|
|
444
|
+
let data;
|
|
445
|
+
try {
|
|
446
|
+
const buf = await handle.readFile();
|
|
447
|
+
data = new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
448
|
+
} finally {
|
|
449
|
+
await handle.close();
|
|
450
|
+
}
|
|
451
|
+
this.requireUtf8(relPath, data);
|
|
452
|
+
return data;
|
|
453
|
+
}
|
|
454
|
+
async ls(under = "/") {
|
|
455
|
+
const base = this.resolveUnderRoot(under);
|
|
456
|
+
return new Set((await filenamesInDir(this.rootPath, under, base)).map(([rel]) => rel));
|
|
457
|
+
}
|
|
458
|
+
async findSymlinks(under = "/") {
|
|
459
|
+
const base = this.resolveUnderRoot(under);
|
|
460
|
+
return symlinksInDir(this.rootPath, under, base);
|
|
461
|
+
}
|
|
462
|
+
async hashtree(under = "/") {
|
|
463
|
+
const base = this.resolveUnderRoot(under);
|
|
464
|
+
const walkStartNs = _internals.nowNs();
|
|
465
|
+
const out = Object.create(null);
|
|
466
|
+
for (const [rel, full] of await filenamesInDir(this.rootPath, under, base)) {
|
|
467
|
+
const sha = await this.hashViaCache(rel, full, walkStartNs);
|
|
468
|
+
if (sha !== null)
|
|
469
|
+
out[rel] = sha;
|
|
531
470
|
}
|
|
471
|
+
return out;
|
|
532
472
|
}
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
473
|
+
async hashFile(relPath) {
|
|
474
|
+
const dest = this.resolveUnderRoot(relPath);
|
|
475
|
+
let st;
|
|
476
|
+
try {
|
|
477
|
+
st = await fsp.lstat(dest, { bigint: true });
|
|
478
|
+
} catch (e) {
|
|
479
|
+
if (e.code === "ENOENT")
|
|
480
|
+
return null;
|
|
481
|
+
throw e;
|
|
482
|
+
}
|
|
483
|
+
if (st.isSymbolicLink())
|
|
484
|
+
throw new FileStoreError(FileStoreError.IS_A_SYMLINK, relPath);
|
|
485
|
+
if (!st.isFile())
|
|
486
|
+
throw new FileStoreError(FileStoreError.NOT_A_FILE, relPath);
|
|
487
|
+
const rel = path.relative(this.rootPath, dest).split(path.sep).join("/");
|
|
488
|
+
return this.hashViaCache(rel, dest, _internals.nowNs());
|
|
489
|
+
}
|
|
490
|
+
async move(src, dst) {
|
|
491
|
+
const s = this.resolveUnderRoot(src);
|
|
492
|
+
const d = this.resolveUnderRoot(dst);
|
|
493
|
+
if (s === this.rootPath || d === this.rootPath)
|
|
494
|
+
return;
|
|
495
|
+
const dstExists = await fsp.stat(d).then(() => true, () => false);
|
|
496
|
+
if (dstExists)
|
|
497
|
+
throw new FileStoreError(FileStoreError.MOVE_DESTINATION_EXISTS, dst);
|
|
498
|
+
await makeDirsBelowRoot(this.rootPath, path.dirname(d));
|
|
499
|
+
await fsp.rename(s, d);
|
|
500
|
+
}
|
|
501
|
+
async remove(relPath) {
|
|
502
|
+
const dest = this.resolveUnderRoot(relPath);
|
|
503
|
+
if (dest === this.rootPath)
|
|
504
|
+
return;
|
|
505
|
+
let st;
|
|
506
|
+
try {
|
|
507
|
+
st = await fsp.lstat(dest, { bigint: true });
|
|
508
|
+
} catch (e) {
|
|
509
|
+
if (e.code === "ENOENT")
|
|
510
|
+
return;
|
|
511
|
+
throw e;
|
|
512
|
+
}
|
|
513
|
+
if (st.isDirectory()) {
|
|
514
|
+
await fsp.rm(dest, { recursive: true, force: true });
|
|
515
|
+
} else {
|
|
516
|
+
try {
|
|
517
|
+
await fsp.unlink(dest);
|
|
518
|
+
} catch (e) {
|
|
519
|
+
if (e.code !== "ENOENT")
|
|
520
|
+
throw e;
|
|
521
|
+
}
|
|
522
|
+
}
|
|
539
523
|
}
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
this.
|
|
547
|
-
} catch {
|
|
548
|
-
throw new FileStoreError(FileStoreError.NOT_UTF8, relPath);
|
|
524
|
+
resolveUnderRoot(relPath) {
|
|
525
|
+
const norm = relPath.replace(/\\/g, "/").replace(/^\/+/, "");
|
|
526
|
+
const parts = norm.split("/").filter((p) => p !== "" && p !== ".");
|
|
527
|
+
if (path.posix.isAbsolute(norm) || parts.includes("..")) {
|
|
528
|
+
throw new FileStoreError(FileStoreError.ESCAPES_ROOT, relPath);
|
|
529
|
+
}
|
|
530
|
+
return parts.length === 0 ? this.rootPath : path.join(this.rootPath, ...parts);
|
|
549
531
|
}
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
throw e;
|
|
532
|
+
requireUtf8(relPath, data) {
|
|
533
|
+
if (!this.decoder)
|
|
534
|
+
return;
|
|
535
|
+
try {
|
|
536
|
+
this.decoder.decode(data);
|
|
537
|
+
} catch {
|
|
538
|
+
throw new FileStoreError(FileStoreError.NOT_UTF8, relPath);
|
|
539
|
+
}
|
|
559
540
|
}
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
const cached = this.hashes.get(rel);
|
|
563
|
-
let sha;
|
|
564
|
-
if (cached !== undefined && unchangedSinceHashed(cached, st)) {
|
|
565
|
-
sha = cached.sha;
|
|
566
|
-
} else {
|
|
541
|
+
async hashViaCache(rel, full, walkStartNs) {
|
|
542
|
+
let st;
|
|
567
543
|
try {
|
|
568
|
-
|
|
544
|
+
st = await fsp.lstat(full, { bigint: true });
|
|
569
545
|
} catch (e) {
|
|
570
|
-
|
|
571
|
-
if (code === "ENOENT" || e instanceof FileStoreError)
|
|
572
|
-
return null;
|
|
573
|
-
if (code === "ELOOP" || code === "EMLINK")
|
|
546
|
+
if (e.code === "ENOENT")
|
|
574
547
|
return null;
|
|
575
548
|
throw e;
|
|
576
549
|
}
|
|
550
|
+
if (!st.isFile())
|
|
551
|
+
return null;
|
|
552
|
+
const cached = this.hashes.get(rel);
|
|
553
|
+
let sha;
|
|
554
|
+
if (cached !== undefined && unchangedSinceHashed(cached, st)) {
|
|
555
|
+
sha = cached.sha;
|
|
556
|
+
} else {
|
|
557
|
+
try {
|
|
558
|
+
sha = await _internals.hashFile(full);
|
|
559
|
+
} catch (e) {
|
|
560
|
+
const code = e.code;
|
|
561
|
+
if (code === "ENOENT" || e instanceof FileStoreError)
|
|
562
|
+
return null;
|
|
563
|
+
if (code === "ELOOP" || code === "EMLINK")
|
|
564
|
+
return null;
|
|
565
|
+
throw e;
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
if (oldEnoughToCache(st, walkStartNs)) {
|
|
569
|
+
this.hashes.set(rel, { mtimeNs: st.mtimeNs, ctimeNs: st.ctimeNs, size: st.size, sha });
|
|
570
|
+
}
|
|
571
|
+
return sha;
|
|
577
572
|
}
|
|
578
|
-
if (oldEnoughToCache(st, walkStartNs)) {
|
|
579
|
-
this.hashes.set(rel, { mtimeNs: st.mtimeNs, ctimeNs: st.ctimeNs, size: st.size, sha });
|
|
580
|
-
}
|
|
581
|
-
return sha;
|
|
582
573
|
}
|
|
583
|
-
|
|
584
|
-
|
|
574
|
+
FileStore2.isPathLegal = isPathLegal;
|
|
575
|
+
return FileStore2;
|
|
576
|
+
})();
|
|
585
577
|
function platformSupported() {
|
|
586
578
|
return O_NOFOLLOW !== 0;
|
|
587
579
|
}
|
|
@@ -838,546 +830,549 @@ class DeletePass {
|
|
|
838
830
|
return true;
|
|
839
831
|
}
|
|
840
832
|
}
|
|
833
|
+
var SessionMemoryStores = /* @__PURE__ */ (() => {
|
|
841
834
|
|
|
842
|
-
class
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
try {
|
|
874
|
-
store = {
|
|
875
|
-
memoryStoreId: resource.memory_store_id,
|
|
876
|
-
files: await LocalFileStore.open(root, { utf8: true }),
|
|
877
|
-
readOnly: resource.access === "read_only",
|
|
878
|
-
baseline: new Map,
|
|
879
|
-
refusedShas: new Map,
|
|
880
|
-
pendingDeletes: new Map
|
|
881
|
-
};
|
|
882
|
-
if (!store.files.root().removedOnDispose) {
|
|
883
|
-
throw new SessionMemoryError(`something already exists at the memory store's path: ${root} ` + `(memory_store_id=${resource.memory_store_id}); ` + "it must not exist when the session starts");
|
|
884
|
-
}
|
|
835
|
+
class SessionMemoryStores2 {
|
|
836
|
+
constructor(client, opts) {
|
|
837
|
+
_SessionMemoryStores_instances.add(this);
|
|
838
|
+
_SessionMemoryStores_client.set(this, undefined);
|
|
839
|
+
_SessionMemoryStores_workdir.set(this, undefined);
|
|
840
|
+
_SessionMemoryStores_syncIntervalMs.set(this, undefined);
|
|
841
|
+
_SessionMemoryStores_syncDeletions.set(this, undefined);
|
|
842
|
+
_SessionMemoryStores_log.set(this, undefined);
|
|
843
|
+
_SessionMemoryStores_lastSyncAt.set(this, undefined);
|
|
844
|
+
_SessionMemoryStores_finished.set(this, false);
|
|
845
|
+
_SessionMemoryStores_stores.set(this, []);
|
|
846
|
+
__classPrivateFieldSet(this, _SessionMemoryStores_client, client, "f");
|
|
847
|
+
__classPrivateFieldSet(this, _SessionMemoryStores_workdir, opts.workdir, "f");
|
|
848
|
+
__classPrivateFieldSet(this, _SessionMemoryStores_syncIntervalMs, opts.syncIntervalMs ?? DEFAULT_MEMORY_SYNC_INTERVAL_MS, "f");
|
|
849
|
+
checkMemorySyncInterval(__classPrivateFieldGet(this, _SessionMemoryStores_syncIntervalMs, "f"), "syncIntervalMs");
|
|
850
|
+
__classPrivateFieldSet(this, _SessionMemoryStores_syncDeletions, opts.syncDeletions ?? "enabled", "f");
|
|
851
|
+
__classPrivateFieldSet(this, _SessionMemoryStores_log, loggerFor(client), "f");
|
|
852
|
+
__classPrivateFieldSet(this, _SessionMemoryStores_lastSyncAt, Date.now(), "f");
|
|
853
|
+
}
|
|
854
|
+
get roots() {
|
|
855
|
+
return __classPrivateFieldGet(this, _SessionMemoryStores_stores, "f").map((s) => s.files.root().path);
|
|
856
|
+
}
|
|
857
|
+
get readOnlyRoots() {
|
|
858
|
+
return __classPrivateFieldGet(this, _SessionMemoryStores_stores, "f").filter((s) => s.readOnly).map((s) => s.files.root().path);
|
|
859
|
+
}
|
|
860
|
+
async download(session) {
|
|
861
|
+
for (const resource of session.resources) {
|
|
862
|
+
if (resource.type !== "memory_store")
|
|
863
|
+
continue;
|
|
864
|
+
const root = __classPrivateFieldGet(this, _SessionMemoryStores_instances, "m", _SessionMemoryStores_storeRoot).call(this, resource);
|
|
865
|
+
let store;
|
|
885
866
|
try {
|
|
886
|
-
|
|
867
|
+
store = {
|
|
868
|
+
memoryStoreId: resource.memory_store_id,
|
|
869
|
+
files: await LocalFileStore.open(root, { utf8: true }),
|
|
870
|
+
readOnly: resource.access === "read_only",
|
|
871
|
+
baseline: new Map,
|
|
872
|
+
refusedShas: new Map,
|
|
873
|
+
pendingDeletes: new Map
|
|
874
|
+
};
|
|
875
|
+
if (!store.files.root().removedOnDispose) {
|
|
876
|
+
throw new SessionMemoryError(`something already exists at the memory store's path: ${root} ` + `(memory_store_id=${resource.memory_store_id}); ` + "it must not exist when the session starts");
|
|
877
|
+
}
|
|
878
|
+
try {
|
|
879
|
+
await store.files.createRoot();
|
|
880
|
+
} catch (e) {
|
|
881
|
+
if (!isErrno(e))
|
|
882
|
+
throw e;
|
|
883
|
+
throw new SessionMemoryError(`cannot create the memory store's folder: ${root} ` + `(memory_store_id=${resource.memory_store_id}): ${e}; ` + "the worker host must make this mount path writable", e);
|
|
884
|
+
}
|
|
885
|
+
await __classPrivateFieldGet(this, _SessionMemoryStores_instances, "m", _SessionMemoryStores_stampAndPull).call(this, store);
|
|
886
|
+
__classPrivateFieldGet(this, _SessionMemoryStores_log, "f").info("downloaded memories", {
|
|
887
|
+
count: store.baseline.size,
|
|
888
|
+
memory_store_id: store.memoryStoreId,
|
|
889
|
+
dest: store.files.root().path
|
|
890
|
+
});
|
|
891
|
+
__classPrivateFieldGet(this, _SessionMemoryStores_stores, "f").push(store);
|
|
887
892
|
} catch (e) {
|
|
888
|
-
if (
|
|
893
|
+
if (store)
|
|
894
|
+
await store.files.dispose().catch(() => {});
|
|
895
|
+
if (e instanceof SessionMemoryError)
|
|
889
896
|
throw e;
|
|
890
|
-
throw new SessionMemoryError(`
|
|
897
|
+
throw new SessionMemoryError(`failed to download memory store memory_store_id=${resource.memory_store_id}: ${e}`, e);
|
|
891
898
|
}
|
|
892
|
-
await __classPrivateFieldGet(this, _SessionMemoryStores_instances, "m", _SessionMemoryStores_stampAndPull).call(this, store);
|
|
893
|
-
__classPrivateFieldGet(this, _SessionMemoryStores_log, "f").info("downloaded memories", {
|
|
894
|
-
count: store.baseline.size,
|
|
895
|
-
memory_store_id: store.memoryStoreId,
|
|
896
|
-
dest: store.files.root().path
|
|
897
|
-
});
|
|
898
|
-
__classPrivateFieldGet(this, _SessionMemoryStores_stores, "f").push(store);
|
|
899
|
-
} catch (e) {
|
|
900
|
-
if (store)
|
|
901
|
-
await store.files.dispose().catch(() => {});
|
|
902
|
-
if (e instanceof SessionMemoryError)
|
|
903
|
-
throw e;
|
|
904
|
-
throw new SessionMemoryError(`failed to download memory store memory_store_id=${resource.memory_store_id}: ${e}`, e);
|
|
905
899
|
}
|
|
900
|
+
__classPrivateFieldSet(this, _SessionMemoryStores_lastSyncAt, Date.now(), "f");
|
|
906
901
|
}
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
902
|
+
async finish() {
|
|
903
|
+
if (__classPrivateFieldGet(this, _SessionMemoryStores_finished, "f")) {
|
|
904
|
+
throw new AnthropicError("finish() was already called: it is the session's last sync and runs once");
|
|
905
|
+
}
|
|
906
|
+
__classPrivateFieldSet(this, _SessionMemoryStores_finished, true, "f");
|
|
907
|
+
await this.syncAll(true);
|
|
908
|
+
}
|
|
909
|
+
async syncAll(final) {
|
|
910
|
+
await Promise.all(__classPrivateFieldGet(this, _SessionMemoryStores_stores, "f").map((store) => __classPrivateFieldGet(this, _SessionMemoryStores_instances, "m", _SessionMemoryStores_syncStore).call(this, store, final)));
|
|
911
|
+
__classPrivateFieldSet(this, _SessionMemoryStores_lastSyncAt, Date.now(), "f");
|
|
912
|
+
}
|
|
913
|
+
async syncIfDue() {
|
|
914
|
+
if (Date.now() - __classPrivateFieldGet(this, _SessionMemoryStores_lastSyncAt, "f") < __classPrivateFieldGet(this, _SessionMemoryStores_syncIntervalMs, "f"))
|
|
915
|
+
return;
|
|
916
|
+
await this.syncAll(false);
|
|
917
|
+
}
|
|
918
|
+
async flushWrites(signal) {
|
|
919
|
+
await Promise.all(__classPrivateFieldGet(this, _SessionMemoryStores_stores, "f").map((store) => __classPrivateFieldGet(this, _SessionMemoryStores_instances, "m", _SessionMemoryStores_flushStore).call(this, store, signal)));
|
|
920
|
+
}
|
|
921
|
+
async dispose() {
|
|
922
|
+
for (const store of __classPrivateFieldGet(this, _SessionMemoryStores_stores, "f")) {
|
|
923
|
+
const root = store.files.root();
|
|
924
|
+
try {
|
|
925
|
+
const scan = await __classPrivateFieldGet(this, _SessionMemoryStores_instances, "m", _SessionMemoryStores_scanMarker).call(this, store);
|
|
926
|
+
if (!scan.markerOk && Object.keys(scan.files).length > 0) {
|
|
927
|
+
__classPrivateFieldGet(this, _SessionMemoryStores_log, "f").warn(`${scan.distrustReason}; leaving the memory store folder on disk`, {
|
|
928
|
+
root: root.path,
|
|
929
|
+
memory_store_id: store.memoryStoreId
|
|
930
|
+
});
|
|
931
|
+
continue;
|
|
932
|
+
}
|
|
933
|
+
await store.files.dispose();
|
|
934
|
+
} catch (e) {
|
|
935
|
+
if (!(e instanceof FileStoreError) && !isErrno(e))
|
|
936
|
+
throw e;
|
|
937
|
+
__classPrivateFieldGet(this, _SessionMemoryStores_log, "f").warn("failed to remove the memory store folder", {
|
|
938
|
+
root: store.files.root().path,
|
|
939
|
+
memory_store_id: store.memoryStoreId,
|
|
940
|
+
error: String(e)
|
|
941
|
+
});
|
|
942
|
+
continue;
|
|
943
|
+
}
|
|
944
|
+
if (root.removedOnDispose) {
|
|
945
|
+
__classPrivateFieldGet(this, _SessionMemoryStores_log, "f").info("removed memory store dir", {
|
|
946
|
+
dest: root.path,
|
|
947
|
+
memory_store_id: store.memoryStoreId
|
|
948
|
+
});
|
|
949
|
+
}
|
|
950
|
+
}
|
|
912
951
|
}
|
|
913
|
-
__classPrivateFieldSet(this, _SessionMemoryStores_finished, true, "f");
|
|
914
|
-
await this.syncAll(true);
|
|
915
|
-
}
|
|
916
|
-
async syncAll(final) {
|
|
917
|
-
await Promise.all(__classPrivateFieldGet(this, _SessionMemoryStores_stores, "f").map((store) => __classPrivateFieldGet(this, _SessionMemoryStores_instances, "m", _SessionMemoryStores_syncStore).call(this, store, final)));
|
|
918
|
-
__classPrivateFieldSet(this, _SessionMemoryStores_lastSyncAt, Date.now(), "f");
|
|
919
|
-
}
|
|
920
|
-
async syncIfDue() {
|
|
921
|
-
if (Date.now() - __classPrivateFieldGet(this, _SessionMemoryStores_lastSyncAt, "f") < __classPrivateFieldGet(this, _SessionMemoryStores_syncIntervalMs, "f"))
|
|
922
|
-
return;
|
|
923
|
-
await this.syncAll(false);
|
|
924
|
-
}
|
|
925
|
-
async flushWrites(signal) {
|
|
926
|
-
await Promise.all(__classPrivateFieldGet(this, _SessionMemoryStores_stores, "f").map((store) => __classPrivateFieldGet(this, _SessionMemoryStores_instances, "m", _SessionMemoryStores_flushStore).call(this, store, signal)));
|
|
927
952
|
}
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
953
|
+
_SessionMemoryStores_client = new WeakMap, _SessionMemoryStores_workdir = new WeakMap, _SessionMemoryStores_syncIntervalMs = new WeakMap, _SessionMemoryStores_syncDeletions = new WeakMap, _SessionMemoryStores_log = new WeakMap, _SessionMemoryStores_lastSyncAt = new WeakMap, _SessionMemoryStores_finished = new WeakMap, _SessionMemoryStores_stores = new WeakMap, _SessionMemoryStores_instances = new WeakSet, _SessionMemoryStores_storeRoot = function _SessionMemoryStores_storeRoot2(resource) {
|
|
954
|
+
if (resource.mount_path) {
|
|
955
|
+
if (!isPathLegal(resource.mount_path)) {
|
|
956
|
+
throw new SessionMemoryError(`memory store mount_path is not a clean absolute path: ${JSON.stringify(resource.mount_path)} ` + `(memory_store_id=${resource.memory_store_id})`);
|
|
957
|
+
}
|
|
958
|
+
return resource.mount_path;
|
|
959
|
+
}
|
|
960
|
+
return path.join(__classPrivateFieldGet(this, _SessionMemoryStores_workdir, "f"), "memory", resource.name || resource.memory_store_id);
|
|
961
|
+
}, _SessionMemoryStores_scanMarker = async function _SessionMemoryStores_scanMarker2(store) {
|
|
962
|
+
const local = await store.files.hashtree();
|
|
963
|
+
const marker = local[MARKER_PATH];
|
|
964
|
+
delete local[MARKER_PATH];
|
|
965
|
+
if (marker === markerSha(store.memoryStoreId)) {
|
|
966
|
+
return { files: local, markerOk: true, distrustReason: null };
|
|
967
|
+
}
|
|
968
|
+
return {
|
|
969
|
+
files: local,
|
|
970
|
+
markerOk: false,
|
|
971
|
+
distrustReason: marker !== undefined ? "the marker file does not match this store" : "the marker file is gone"
|
|
972
|
+
};
|
|
973
|
+
}, _SessionMemoryStores_syncStore = async function _SessionMemoryStores_syncStore2(store, final) {
|
|
974
|
+
try {
|
|
975
|
+
const scan = await __classPrivateFieldGet(this, _SessionMemoryStores_instances, "m", _SessionMemoryStores_scanMarker).call(this, store);
|
|
976
|
+
const local = scan.files;
|
|
977
|
+
if (!scan.markerOk) {
|
|
978
|
+
if (Object.keys(local).length > 0) {
|
|
979
|
+
__classPrivateFieldGet(this, _SessionMemoryStores_log, "f").warn(`${scan.distrustReason}; leaving the memory store folder as found and not syncing`, {
|
|
980
|
+
root: store.files.root().path,
|
|
936
981
|
memory_store_id: store.memoryStoreId
|
|
937
982
|
});
|
|
938
|
-
|
|
983
|
+
return;
|
|
939
984
|
}
|
|
940
|
-
await
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
__classPrivateFieldGet(this,
|
|
945
|
-
|
|
946
|
-
memory_store_id: store.memoryStoreId,
|
|
947
|
-
error: String(e)
|
|
948
|
-
});
|
|
949
|
-
continue;
|
|
985
|
+
await __classPrivateFieldGet(this, _SessionMemoryStores_instances, "m", _SessionMemoryStores_recover).call(this, store, "the folder or its marker is gone");
|
|
986
|
+
return;
|
|
987
|
+
}
|
|
988
|
+
if (Object.keys(local).length === 0 && store.baseline.size > 1) {
|
|
989
|
+
await __classPrivateFieldGet(this, _SessionMemoryStores_instances, "m", _SessionMemoryStores_recover).call(this, store, "every memory file is gone at once");
|
|
990
|
+
return;
|
|
950
991
|
}
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
992
|
+
const remote = new Map;
|
|
993
|
+
for await (const [rel, item] of __classPrivateFieldGet(this, _SessionMemoryStores_instances, "m", _SessionMemoryStores_listMemories).call(this, store.memoryStoreId)) {
|
|
994
|
+
remote.set(rel, item);
|
|
995
|
+
}
|
|
996
|
+
const deletes = new DeletePass(__classPrivateFieldGet(this, _SessionMemoryStores_syncDeletions, "f"), Math.max(DELETE_CAP_FLOOR, Math.min(DELETE_CAP_CEILING, Math.floor(store.baseline.size / 4))), final);
|
|
997
|
+
const pulls = [];
|
|
998
|
+
const baseline = new Map;
|
|
999
|
+
const paths = [...new Set([...remote.keys(), ...Object.keys(local), ...store.baseline.keys()])].sort();
|
|
1000
|
+
for (const rel of paths) {
|
|
1001
|
+
const remoteItem = remote.get(rel);
|
|
1002
|
+
const localSha = local[rel];
|
|
1003
|
+
const baseSha = store.baseline.get(rel);
|
|
1004
|
+
let sha;
|
|
1005
|
+
if (localSha === undefined && baseSha !== undefined && remoteItem !== undefined && remoteItem.content_sha256 === baseSha && !store.readOnly) {
|
|
1006
|
+
sha = await __classPrivateFieldGet(this, _SessionMemoryStores_instances, "m", _SessionMemoryStores_corroboratedDelete).call(this, store, rel, remoteItem, baseSha, deletes);
|
|
1007
|
+
} else {
|
|
1008
|
+
sha = await __classPrivateFieldGet(this, _SessionMemoryStores_instances, "m", _SessionMemoryStores_syncPath).call(this, store, rel, remoteItem, localSha, pulls);
|
|
1009
|
+
}
|
|
1010
|
+
if (sha !== undefined)
|
|
1011
|
+
baseline.set(rel, sha);
|
|
1012
|
+
}
|
|
1013
|
+
store.baseline = baseline;
|
|
1014
|
+
await __classPrivateFieldGet(this, _SessionMemoryStores_instances, "m", _SessionMemoryStores_pullAll).call(this, store, pulls);
|
|
1015
|
+
if (deletes.suppressed > 0) {
|
|
1016
|
+
__classPrivateFieldGet(this, _SessionMemoryStores_log, "f").debug("remote deletes are disabled; locally deleted memories stay on the server", {
|
|
1017
|
+
count: deletes.suppressed,
|
|
954
1018
|
memory_store_id: store.memoryStoreId
|
|
955
1019
|
});
|
|
956
1020
|
}
|
|
1021
|
+
if (deletes.capped > 0) {
|
|
1022
|
+
__classPrivateFieldGet(this, _SessionMemoryStores_log, "f").warn(`delete cap reached: ${deletes.mode === "log_only" ? "would send" : "sent"} ` + `${deletes.attempted} deletes, held ${deletes.capped} for later syncs`, { memory_store_id: store.memoryStoreId });
|
|
1023
|
+
}
|
|
1024
|
+
} catch (e) {
|
|
1025
|
+
__classPrivateFieldGet(this, _SessionMemoryStores_log, "f").warn("memory sync failed", { memory_store_id: store.memoryStoreId, error: String(e) });
|
|
957
1026
|
}
|
|
958
|
-
}
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
return path.join(__classPrivateFieldGet(this, _SessionMemoryStores_workdir, "f"), "memory", resource.name || resource.memory_store_id);
|
|
968
|
-
}, _SessionMemoryStores_scanMarker = async function _SessionMemoryStores_scanMarker2(store) {
|
|
969
|
-
const local = await store.files.hashtree();
|
|
970
|
-
const marker = local[MARKER_PATH];
|
|
971
|
-
delete local[MARKER_PATH];
|
|
972
|
-
if (marker === markerSha(store.memoryStoreId)) {
|
|
973
|
-
return { files: local, markerOk: true, distrustReason: null };
|
|
974
|
-
}
|
|
975
|
-
return {
|
|
976
|
-
files: local,
|
|
977
|
-
markerOk: false,
|
|
978
|
-
distrustReason: marker !== undefined ? "the marker file does not match this store" : "the marker file is gone"
|
|
979
|
-
};
|
|
980
|
-
}, _SessionMemoryStores_syncStore = async function _SessionMemoryStores_syncStore2(store, final) {
|
|
981
|
-
try {
|
|
982
|
-
const scan = await __classPrivateFieldGet(this, _SessionMemoryStores_instances, "m", _SessionMemoryStores_scanMarker).call(this, store);
|
|
983
|
-
const local = scan.files;
|
|
984
|
-
if (!scan.markerOk) {
|
|
985
|
-
if (Object.keys(local).length > 0) {
|
|
986
|
-
__classPrivateFieldGet(this, _SessionMemoryStores_log, "f").warn(`${scan.distrustReason}; leaving the memory store folder as found and not syncing`, {
|
|
1027
|
+
}, _SessionMemoryStores_flushStore = async function _SessionMemoryStores_flushStore2(store, signal) {
|
|
1028
|
+
const dirty = new Map;
|
|
1029
|
+
const unsent = new Set;
|
|
1030
|
+
const push = async () => {
|
|
1031
|
+
if (store.readOnly)
|
|
1032
|
+
return;
|
|
1033
|
+
const scan = await __classPrivateFieldGet(this, _SessionMemoryStores_instances, "m", _SessionMemoryStores_scanMarker).call(this, store);
|
|
1034
|
+
if (!scan.markerOk) {
|
|
1035
|
+
__classPrivateFieldGet(this, _SessionMemoryStores_log, "f").warn(`${scan.distrustReason}; not uploading anything from the memory store folder`, {
|
|
987
1036
|
root: store.files.root().path,
|
|
988
1037
|
memory_store_id: store.memoryStoreId
|
|
989
1038
|
});
|
|
990
1039
|
return;
|
|
991
1040
|
}
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
return;
|
|
998
|
-
}
|
|
999
|
-
const remote = new Map;
|
|
1000
|
-
for await (const [rel, item] of __classPrivateFieldGet(this, _SessionMemoryStores_instances, "m", _SessionMemoryStores_listMemories).call(this, store.memoryStoreId)) {
|
|
1001
|
-
remote.set(rel, item);
|
|
1002
|
-
}
|
|
1003
|
-
const deletes = new DeletePass(__classPrivateFieldGet(this, _SessionMemoryStores_syncDeletions, "f"), Math.max(DELETE_CAP_FLOOR, Math.min(DELETE_CAP_CEILING, Math.floor(store.baseline.size / 4))), final);
|
|
1004
|
-
const pulls = [];
|
|
1005
|
-
const baseline = new Map;
|
|
1006
|
-
const paths = [...new Set([...remote.keys(), ...Object.keys(local), ...store.baseline.keys()])].sort();
|
|
1007
|
-
for (const rel of paths) {
|
|
1008
|
-
const remoteItem = remote.get(rel);
|
|
1009
|
-
const localSha = local[rel];
|
|
1010
|
-
const baseSha = store.baseline.get(rel);
|
|
1011
|
-
let sha;
|
|
1012
|
-
if (localSha === undefined && baseSha !== undefined && remoteItem !== undefined && remoteItem.content_sha256 === baseSha && !store.readOnly) {
|
|
1013
|
-
sha = await __classPrivateFieldGet(this, _SessionMemoryStores_instances, "m", _SessionMemoryStores_corroboratedDelete).call(this, store, rel, remoteItem, baseSha, deletes);
|
|
1014
|
-
} else {
|
|
1015
|
-
sha = await __classPrivateFieldGet(this, _SessionMemoryStores_instances, "m", _SessionMemoryStores_syncPath).call(this, store, rel, remoteItem, localSha, pulls);
|
|
1016
|
-
}
|
|
1017
|
-
if (sha !== undefined)
|
|
1018
|
-
baseline.set(rel, sha);
|
|
1019
|
-
}
|
|
1020
|
-
store.baseline = baseline;
|
|
1021
|
-
await __classPrivateFieldGet(this, _SessionMemoryStores_instances, "m", _SessionMemoryStores_pullAll).call(this, store, pulls);
|
|
1022
|
-
if (deletes.suppressed > 0) {
|
|
1023
|
-
__classPrivateFieldGet(this, _SessionMemoryStores_log, "f").debug("remote deletes are disabled; locally deleted memories stay on the server", {
|
|
1024
|
-
count: deletes.suppressed,
|
|
1025
|
-
memory_store_id: store.memoryStoreId
|
|
1026
|
-
});
|
|
1027
|
-
}
|
|
1028
|
-
if (deletes.capped > 0) {
|
|
1029
|
-
__classPrivateFieldGet(this, _SessionMemoryStores_log, "f").warn(`delete cap reached: ${deletes.mode === "log_only" ? "would send" : "sent"} ` + `${deletes.attempted} deletes, held ${deletes.capped} for later syncs`, { memory_store_id: store.memoryStoreId });
|
|
1030
|
-
}
|
|
1031
|
-
} catch (e) {
|
|
1032
|
-
__classPrivateFieldGet(this, _SessionMemoryStores_log, "f").warn("memory sync failed", { memory_store_id: store.memoryStoreId, error: String(e) });
|
|
1033
|
-
}
|
|
1034
|
-
}, _SessionMemoryStores_flushStore = async function _SessionMemoryStores_flushStore2(store, signal) {
|
|
1035
|
-
const dirty = new Map;
|
|
1036
|
-
const unsent = new Set;
|
|
1037
|
-
const push = async () => {
|
|
1038
|
-
if (store.readOnly)
|
|
1039
|
-
return;
|
|
1040
|
-
const scan = await __classPrivateFieldGet(this, _SessionMemoryStores_instances, "m", _SessionMemoryStores_scanMarker).call(this, store);
|
|
1041
|
-
if (!scan.markerOk) {
|
|
1042
|
-
__classPrivateFieldGet(this, _SessionMemoryStores_log, "f").warn(`${scan.distrustReason}; not uploading anything from the memory store folder`, {
|
|
1043
|
-
root: store.files.root().path,
|
|
1044
|
-
memory_store_id: store.memoryStoreId
|
|
1045
|
-
});
|
|
1046
|
-
return;
|
|
1047
|
-
}
|
|
1048
|
-
for (const [rel, sha] of Object.entries(scan.files)) {
|
|
1049
|
-
if (sha !== store.baseline.get(rel) && store.refusedShas.get(rel) !== sha) {
|
|
1050
|
-
dirty.set(rel, sha);
|
|
1051
|
-
unsent.add(rel);
|
|
1041
|
+
for (const [rel, sha] of Object.entries(scan.files)) {
|
|
1042
|
+
if (sha !== store.baseline.get(rel) && store.refusedShas.get(rel) !== sha) {
|
|
1043
|
+
dirty.set(rel, sha);
|
|
1044
|
+
unsent.add(rel);
|
|
1045
|
+
}
|
|
1052
1046
|
}
|
|
1053
|
-
|
|
1054
|
-
if (dirty.size === 0 || signal?.aborted)
|
|
1055
|
-
return;
|
|
1056
|
-
const remote = new Map;
|
|
1057
|
-
for await (const [rel, item] of __classPrivateFieldGet(this, _SessionMemoryStores_instances, "m", _SessionMemoryStores_listMemories).call(this, store.memoryStoreId)) {
|
|
1058
|
-
if (signal?.aborted)
|
|
1047
|
+
if (dirty.size === 0 || signal?.aborted)
|
|
1059
1048
|
return;
|
|
1060
|
-
remote
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
const baseSha = store.baseline.get(rel);
|
|
1066
|
-
const existing = remote.get(rel);
|
|
1067
|
-
if (existing !== undefined && existing.content_sha256 === localSha) {
|
|
1068
|
-
store.baseline.set(rel, existing.content_sha256);
|
|
1069
|
-
unsent.delete(rel);
|
|
1070
|
-
continue;
|
|
1049
|
+
const remote = new Map;
|
|
1050
|
+
for await (const [rel, item] of __classPrivateFieldGet(this, _SessionMemoryStores_instances, "m", _SessionMemoryStores_listMemories).call(this, store.memoryStoreId)) {
|
|
1051
|
+
if (signal?.aborted)
|
|
1052
|
+
return;
|
|
1053
|
+
remote.set(rel, item);
|
|
1071
1054
|
}
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1055
|
+
const uploads = [];
|
|
1056
|
+
for (const rel of [...dirty.keys()].sort()) {
|
|
1057
|
+
const localSha = dirty.get(rel);
|
|
1058
|
+
const baseSha = store.baseline.get(rel);
|
|
1059
|
+
const existing = remote.get(rel);
|
|
1060
|
+
if (existing !== undefined && existing.content_sha256 === localSha) {
|
|
1061
|
+
store.baseline.set(rel, existing.content_sha256);
|
|
1062
|
+
unsent.delete(rel);
|
|
1063
|
+
continue;
|
|
1064
|
+
}
|
|
1065
|
+
if (existing !== undefined && existing.content_sha256 !== baseSha) {
|
|
1066
|
+
__classPrivateFieldGet(this, _SessionMemoryStores_log, "f").warn("memory changed both locally and remotely; the flush leaves the remote version", {
|
|
1067
|
+
path: rel,
|
|
1068
|
+
memory_store_id: store.memoryStoreId
|
|
1069
|
+
});
|
|
1070
|
+
unsent.delete(rel);
|
|
1071
|
+
continue;
|
|
1072
|
+
}
|
|
1073
|
+
uploads.push([rel, localSha, existing]);
|
|
1079
1074
|
}
|
|
1080
|
-
|
|
1081
|
-
}
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1075
|
+
await __classPrivateFieldGet(this, _SessionMemoryStores_instances, "m", _SessionMemoryStores_uploadAll).call(this, store, uploads, unsent, signal);
|
|
1076
|
+
};
|
|
1077
|
+
try {
|
|
1078
|
+
await settledOrAborted(push(), signal);
|
|
1079
|
+
if (signal?.aborted && unsent.size > 0) {
|
|
1080
|
+
__classPrivateFieldGet(this, _SessionMemoryStores_log, "f").warn(`memory flush cut off part-way; ${unsent.size} of ${dirty.size} changed files had not finished uploading`, { memory_store_id: store.memoryStoreId });
|
|
1081
|
+
}
|
|
1082
|
+
} catch (e) {
|
|
1083
|
+
__classPrivateFieldGet(this, _SessionMemoryStores_log, "f").warn("memory flush failed", { memory_store_id: store.memoryStoreId, error: String(e) });
|
|
1088
1084
|
}
|
|
1089
|
-
}
|
|
1090
|
-
__classPrivateFieldGet(this, _SessionMemoryStores_log, "f").warn(
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
})
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
store.baseline = new Map;
|
|
1101
|
-
store.pendingDeletes.clear();
|
|
1102
|
-
await store.files.put(MARKER_PATH, `version ${MARKER_VERSION}
|
|
1085
|
+
}, _SessionMemoryStores_recover = async function _SessionMemoryStores_recover2(store, reason) {
|
|
1086
|
+
__classPrivateFieldGet(this, _SessionMemoryStores_log, "f").warn(`${reason}; re-downloading the memory store folder instead of syncing`, {
|
|
1087
|
+
root: store.files.root().path,
|
|
1088
|
+
memory_store_id: store.memoryStoreId
|
|
1089
|
+
});
|
|
1090
|
+
await store.files.createRoot();
|
|
1091
|
+
await __classPrivateFieldGet(this, _SessionMemoryStores_instances, "m", _SessionMemoryStores_stampAndPull).call(this, store);
|
|
1092
|
+
}, _SessionMemoryStores_stampAndPull = async function _SessionMemoryStores_stampAndPull2(store) {
|
|
1093
|
+
store.baseline = new Map;
|
|
1094
|
+
store.pendingDeletes.clear();
|
|
1095
|
+
await store.files.put(MARKER_PATH, `version ${MARKER_VERSION}
|
|
1103
1096
|
${store.memoryStoreId}`);
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1097
|
+
for await (const [rel, item] of __classPrivateFieldGet(this, _SessionMemoryStores_instances, "m", _SessionMemoryStores_listMemories).call(this, store.memoryStoreId, "full")) {
|
|
1098
|
+
if (await __classPrivateFieldGet(this, _SessionMemoryStores_instances, "m", _SessionMemoryStores_write).call(this, store, rel, item.content ?? "")) {
|
|
1099
|
+
store.baseline.set(rel, item.content_sha256);
|
|
1100
|
+
}
|
|
1107
1101
|
}
|
|
1108
|
-
}
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
if (localSha !== undefined) {
|
|
1112
|
-
store.pendingDeletes.delete(rel);
|
|
1113
|
-
}
|
|
1114
|
-
if (!remote) {
|
|
1115
|
-
if (localSha === undefined) {
|
|
1102
|
+
}, _SessionMemoryStores_syncPath = async function _SessionMemoryStores_syncPath2(store, rel, remote, localSha, pulls) {
|
|
1103
|
+
const baseSha = store.baseline.get(rel);
|
|
1104
|
+
if (localSha !== undefined) {
|
|
1116
1105
|
store.pendingDeletes.delete(rel);
|
|
1117
|
-
return;
|
|
1118
1106
|
}
|
|
1119
|
-
if (
|
|
1120
|
-
if (localSha ===
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1107
|
+
if (!remote) {
|
|
1108
|
+
if (localSha === undefined) {
|
|
1109
|
+
store.pendingDeletes.delete(rel);
|
|
1110
|
+
return;
|
|
1111
|
+
}
|
|
1112
|
+
if (baseSha !== undefined) {
|
|
1113
|
+
if (localSha === baseSha) {
|
|
1114
|
+
const fresh = await __classPrivateFieldGet(this, _SessionMemoryStores_instances, "m", _SessionMemoryStores_removeLocal).call(this, store, rel, baseSha);
|
|
1115
|
+
if (fresh === undefined)
|
|
1116
|
+
return;
|
|
1117
|
+
if (fresh === baseSha)
|
|
1118
|
+
return baseSha;
|
|
1119
|
+
localSha = fresh;
|
|
1120
|
+
}
|
|
1121
|
+
if (store.readOnly) {
|
|
1122
|
+
__classPrivateFieldGet(this, _SessionMemoryStores_log, "f").warn("memory deleted remotely but edited locally; keeping the file, " + "which a read-only store cannot push", { path: rel, memory_store_id: store.memoryStoreId });
|
|
1123
|
+
} else if (store.refusedShas.get(rel) !== localSha) {
|
|
1124
|
+
__classPrivateFieldGet(this, _SessionMemoryStores_log, "f").info("memory deleted remotely but edited locally; re-creating it from the file", {
|
|
1125
|
+
path: rel,
|
|
1126
|
+
memory_store_id: store.memoryStoreId
|
|
1127
|
+
});
|
|
1128
|
+
}
|
|
1129
|
+
}
|
|
1130
|
+
if (store.readOnly)
|
|
1131
|
+
return;
|
|
1132
|
+
if (store.refusedShas.get(rel) === localSha)
|
|
1133
|
+
return;
|
|
1134
|
+
return await __classPrivateFieldGet(this, _SessionMemoryStores_instances, "m", _SessionMemoryStores_upload).call(this, store, rel, localSha, undefined);
|
|
1135
|
+
}
|
|
1136
|
+
const remoteSha = remote.content_sha256;
|
|
1137
|
+
const remoteChanged = remoteSha !== baseSha;
|
|
1138
|
+
const locallyEdited = localSha !== undefined && localSha !== baseSha && localSha !== remoteSha;
|
|
1139
|
+
const localChanged = !store.readOnly && locallyEdited;
|
|
1140
|
+
if (localSha === undefined && baseSha !== undefined) {
|
|
1141
|
+
if (remoteChanged) {
|
|
1142
|
+
__classPrivateFieldGet(this, _SessionMemoryStores_log, "f").warn("memory deleted locally but changed remotely; restoring the remote version", {
|
|
1132
1143
|
path: rel,
|
|
1133
1144
|
memory_store_id: store.memoryStoreId
|
|
1134
1145
|
});
|
|
1146
|
+
store.pendingDeletes.delete(rel);
|
|
1147
|
+
pulls.push([rel, remote]);
|
|
1135
1148
|
}
|
|
1149
|
+
return baseSha;
|
|
1136
1150
|
}
|
|
1137
|
-
if (store.readOnly)
|
|
1138
|
-
return;
|
|
1139
|
-
if (store.refusedShas.get(rel) === localSha)
|
|
1140
|
-
return;
|
|
1141
|
-
return await __classPrivateFieldGet(this, _SessionMemoryStores_instances, "m", _SessionMemoryStores_upload).call(this, store, rel, localSha, undefined);
|
|
1142
|
-
}
|
|
1143
|
-
const remoteSha = remote.content_sha256;
|
|
1144
|
-
const remoteChanged = remoteSha !== baseSha;
|
|
1145
|
-
const locallyEdited = localSha !== undefined && localSha !== baseSha && localSha !== remoteSha;
|
|
1146
|
-
const localChanged = !store.readOnly && locallyEdited;
|
|
1147
|
-
if (localSha === undefined && baseSha !== undefined) {
|
|
1148
1151
|
if (remoteChanged) {
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1152
|
+
if (localSha === remoteSha)
|
|
1153
|
+
return remoteSha;
|
|
1154
|
+
if (locallyEdited) {
|
|
1155
|
+
__classPrivateFieldGet(this, _SessionMemoryStores_log, "f").warn("memory changed both locally and remotely; keeping the remote version", {
|
|
1156
|
+
path: rel,
|
|
1157
|
+
memory_store_id: store.memoryStoreId
|
|
1158
|
+
});
|
|
1159
|
+
}
|
|
1154
1160
|
pulls.push([rel, remote]);
|
|
1161
|
+
return baseSha;
|
|
1155
1162
|
}
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
+
if (localChanged) {
|
|
1164
|
+
if (store.refusedShas.get(rel) === localSha)
|
|
1165
|
+
return remoteSha;
|
|
1166
|
+
return await __classPrivateFieldGet(this, _SessionMemoryStores_instances, "m", _SessionMemoryStores_upload).call(this, store, rel, localSha, remote) ?? remoteSha;
|
|
1167
|
+
}
|
|
1168
|
+
return remoteSha;
|
|
1169
|
+
}, _SessionMemoryStores_removeLocal = async function _SessionMemoryStores_removeLocal2(store, rel, expectSha) {
|
|
1170
|
+
let freshSha;
|
|
1171
|
+
try {
|
|
1172
|
+
freshSha = await store.files.hashFile(rel);
|
|
1173
|
+
} catch (e) {
|
|
1174
|
+
if (!(e instanceof FileStoreError) && !isErrno(e))
|
|
1175
|
+
throw e;
|
|
1176
|
+
return expectSha;
|
|
1177
|
+
}
|
|
1178
|
+
if (freshSha === null)
|
|
1179
|
+
return;
|
|
1180
|
+
if (freshSha !== expectSha)
|
|
1181
|
+
return freshSha;
|
|
1182
|
+
try {
|
|
1183
|
+
await store.files.remove(rel);
|
|
1184
|
+
} catch (e) {
|
|
1185
|
+
if (!(e instanceof FileStoreError) && !isErrno(e))
|
|
1186
|
+
throw e;
|
|
1187
|
+
__classPrivateFieldGet(this, _SessionMemoryStores_log, "f").warn("failed to remove memory deleted remotely", {
|
|
1163
1188
|
path: rel,
|
|
1164
|
-
memory_store_id: store.memoryStoreId
|
|
1189
|
+
memory_store_id: store.memoryStoreId,
|
|
1190
|
+
error: String(e)
|
|
1165
1191
|
});
|
|
1192
|
+
return expectSha;
|
|
1166
1193
|
}
|
|
1167
|
-
pulls.push([rel, remote]);
|
|
1168
|
-
return baseSha;
|
|
1169
|
-
}
|
|
1170
|
-
if (localChanged) {
|
|
1171
|
-
if (store.refusedShas.get(rel) === localSha)
|
|
1172
|
-
return remoteSha;
|
|
1173
|
-
return await __classPrivateFieldGet(this, _SessionMemoryStores_instances, "m", _SessionMemoryStores_upload).call(this, store, rel, localSha, remote) ?? remoteSha;
|
|
1174
|
-
}
|
|
1175
|
-
return remoteSha;
|
|
1176
|
-
}, _SessionMemoryStores_removeLocal = async function _SessionMemoryStores_removeLocal2(store, rel, expectSha) {
|
|
1177
|
-
let freshSha;
|
|
1178
|
-
try {
|
|
1179
|
-
freshSha = await store.files.hashFile(rel);
|
|
1180
|
-
} catch (e) {
|
|
1181
|
-
if (!(e instanceof FileStoreError) && !isErrno(e))
|
|
1182
|
-
throw e;
|
|
1183
|
-
return expectSha;
|
|
1184
|
-
}
|
|
1185
|
-
if (freshSha === null)
|
|
1186
|
-
return;
|
|
1187
|
-
if (freshSha !== expectSha)
|
|
1188
|
-
return freshSha;
|
|
1189
|
-
try {
|
|
1190
|
-
await store.files.remove(rel);
|
|
1191
|
-
} catch (e) {
|
|
1192
|
-
if (!(e instanceof FileStoreError) && !isErrno(e))
|
|
1193
|
-
throw e;
|
|
1194
|
-
__classPrivateFieldGet(this, _SessionMemoryStores_log, "f").warn("failed to remove memory deleted remotely", {
|
|
1195
|
-
path: rel,
|
|
1196
|
-
memory_store_id: store.memoryStoreId,
|
|
1197
|
-
error: String(e)
|
|
1198
|
-
});
|
|
1199
|
-
return expectSha;
|
|
1200
|
-
}
|
|
1201
|
-
return;
|
|
1202
|
-
}, _SessionMemoryStores_write = async function _SessionMemoryStores_write2(store, rel, content) {
|
|
1203
|
-
try {
|
|
1204
|
-
await store.files.put(rel, content);
|
|
1205
|
-
} catch (e) {
|
|
1206
|
-
if (!(e instanceof FileStoreError) && !isErrno(e))
|
|
1207
|
-
throw e;
|
|
1208
|
-
__classPrivateFieldGet(this, _SessionMemoryStores_log, "f").warn("failed to write memory", {
|
|
1209
|
-
path: rel,
|
|
1210
|
-
memory_store_id: store.memoryStoreId,
|
|
1211
|
-
error: String(e)
|
|
1212
|
-
});
|
|
1213
|
-
return false;
|
|
1214
|
-
}
|
|
1215
|
-
return true;
|
|
1216
|
-
}, _SessionMemoryStores_pullAll = async function _SessionMemoryStores_pullAll2(store, pulls) {
|
|
1217
|
-
if (pulls.length === 0)
|
|
1218
1194
|
return;
|
|
1219
|
-
|
|
1220
|
-
let item;
|
|
1195
|
+
}, _SessionMemoryStores_write = async function _SessionMemoryStores_write2(store, rel, content) {
|
|
1221
1196
|
try {
|
|
1222
|
-
|
|
1223
|
-
memory_store_id: store.memoryStoreId,
|
|
1224
|
-
view: "full"
|
|
1225
|
-
});
|
|
1197
|
+
await store.files.put(rel, content);
|
|
1226
1198
|
} catch (e) {
|
|
1227
|
-
if (
|
|
1228
|
-
|
|
1229
|
-
__classPrivateFieldGet(this, _SessionMemoryStores_log, "f").warn("failed to
|
|
1199
|
+
if (!(e instanceof FileStoreError) && !isErrno(e))
|
|
1200
|
+
throw e;
|
|
1201
|
+
__classPrivateFieldGet(this, _SessionMemoryStores_log, "f").warn("failed to write memory", {
|
|
1230
1202
|
path: rel,
|
|
1231
1203
|
memory_store_id: store.memoryStoreId,
|
|
1232
1204
|
error: String(e)
|
|
1233
1205
|
});
|
|
1234
|
-
return;
|
|
1235
|
-
}
|
|
1236
|
-
if (await __classPrivateFieldGet(this, _SessionMemoryStores_instances, "m", _SessionMemoryStores_write).call(this, store, rel, item.content ?? "")) {
|
|
1237
|
-
store.baseline.set(rel, item.content_sha256);
|
|
1206
|
+
return false;
|
|
1238
1207
|
}
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1208
|
+
return true;
|
|
1209
|
+
}, _SessionMemoryStores_pullAll = async function _SessionMemoryStores_pullAll2(store, pulls) {
|
|
1210
|
+
if (pulls.length === 0)
|
|
1211
|
+
return;
|
|
1212
|
+
const pullOne = async (rel, listed) => {
|
|
1213
|
+
let item;
|
|
1214
|
+
try {
|
|
1215
|
+
item = await __classPrivateFieldGet(this, _SessionMemoryStores_client, "f").beta.memoryStores.memories.retrieve(listed.id, {
|
|
1216
|
+
memory_store_id: store.memoryStoreId,
|
|
1217
|
+
view: "full"
|
|
1218
|
+
});
|
|
1219
|
+
} catch (e) {
|
|
1220
|
+
if (isStatus(e, 404))
|
|
1221
|
+
return;
|
|
1222
|
+
__classPrivateFieldGet(this, _SessionMemoryStores_log, "f").warn("failed to fetch memory content", {
|
|
1223
|
+
path: rel,
|
|
1224
|
+
memory_store_id: store.memoryStoreId,
|
|
1225
|
+
error: String(e)
|
|
1226
|
+
});
|
|
1251
1227
|
return;
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1228
|
+
}
|
|
1229
|
+
if (await __classPrivateFieldGet(this, _SessionMemoryStores_instances, "m", _SessionMemoryStores_write).call(this, store, rel, item.content ?? "")) {
|
|
1230
|
+
store.baseline.set(rel, item.content_sha256);
|
|
1231
|
+
}
|
|
1232
|
+
};
|
|
1233
|
+
const queue = pulls[Symbol.iterator]();
|
|
1234
|
+
const worker = async () => {
|
|
1235
|
+
for (const [rel, listed] of queue)
|
|
1236
|
+
await pullOne(rel, listed);
|
|
1237
|
+
};
|
|
1238
|
+
await Promise.all(Array.from({ length: Math.min(FETCH_CONCURRENCY, pulls.length) }, worker));
|
|
1239
|
+
}, _SessionMemoryStores_uploadAll = async function _SessionMemoryStores_uploadAll2(store, uploads, unsent, signal) {
|
|
1240
|
+
const queue = uploads[Symbol.iterator]();
|
|
1241
|
+
const worker = async () => {
|
|
1242
|
+
for (const [rel, localSha, existing] of queue) {
|
|
1243
|
+
if (signal?.aborted)
|
|
1244
|
+
return;
|
|
1245
|
+
const sha = await __classPrivateFieldGet(this, _SessionMemoryStores_instances, "m", _SessionMemoryStores_upload).call(this, store, rel, localSha, existing);
|
|
1246
|
+
unsent.delete(rel);
|
|
1247
|
+
if (sha !== undefined)
|
|
1248
|
+
store.baseline.set(rel, sha);
|
|
1249
|
+
}
|
|
1250
|
+
};
|
|
1251
|
+
await Promise.all(Array.from({ length: Math.min(UPLOAD_CONCURRENCY, uploads.length) }, worker));
|
|
1252
|
+
}, _SessionMemoryStores_listMemories = async function* _SessionMemoryStores_listMemories2(memoryStoreId, view = "basic") {
|
|
1253
|
+
const limit = view === "basic" ? LIST_PAGE_SIZE : FULL_LIST_PAGE_SIZE;
|
|
1254
|
+
for await (const item of __classPrivateFieldGet(this, _SessionMemoryStores_client, "f").beta.memoryStores.memories.list(memoryStoreId, { view, limit })) {
|
|
1255
|
+
if (item.type !== "memory")
|
|
1256
|
+
continue;
|
|
1257
|
+
const rel = item.path.replace(/^\/+/, "");
|
|
1258
|
+
if (rel === MARKER_PATH) {
|
|
1259
|
+
__classPrivateFieldGet(this, _SessionMemoryStores_log, "f").warn("the server listed the reserved marker path; skipping", {
|
|
1260
|
+
path: item.path,
|
|
1261
|
+
memory_store_id: memoryStoreId
|
|
1262
|
+
});
|
|
1263
|
+
continue;
|
|
1264
|
+
}
|
|
1265
|
+
yield [rel, item];
|
|
1256
1266
|
}
|
|
1257
|
-
}
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1267
|
+
}, _SessionMemoryStores_upload = async function _SessionMemoryStores_upload2(store, rel, localSha, existing) {
|
|
1268
|
+
try {
|
|
1269
|
+
const data = await store.files.get(rel);
|
|
1270
|
+
if (data === null)
|
|
1271
|
+
return;
|
|
1272
|
+
const content = decodeUTF8(data);
|
|
1273
|
+
const item = existing ? await __classPrivateFieldGet(this, _SessionMemoryStores_client, "f").beta.memoryStores.memories.update(existing.id, {
|
|
1274
|
+
memory_store_id: store.memoryStoreId,
|
|
1275
|
+
content,
|
|
1276
|
+
precondition: { type: "content_sha256", content_sha256: existing.content_sha256 }
|
|
1277
|
+
}) : await __classPrivateFieldGet(this, _SessionMemoryStores_client, "f").beta.memoryStores.memories.create(store.memoryStoreId, {
|
|
1278
|
+
path: "/" + rel,
|
|
1279
|
+
content
|
|
1269
1280
|
});
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1281
|
+
store.refusedShas.delete(rel);
|
|
1282
|
+
return item.content_sha256;
|
|
1283
|
+
} catch (e) {
|
|
1284
|
+
if (existing && isStatus(e, 404)) {
|
|
1285
|
+
return await __classPrivateFieldGet(this, _SessionMemoryStores_instances, "m", _SessionMemoryStores_upload2).call(this, store, rel, localSha, undefined);
|
|
1286
|
+
}
|
|
1287
|
+
const permanent = e instanceof FileStoreError || isStatus(e, 400) || isStatus(e, 413);
|
|
1288
|
+
if (existing && isStatus(e, 409)) {
|
|
1289
|
+
__classPrivateFieldGet(this, _SessionMemoryStores_log, "f").warn("memory changed both locally and remotely; the upload was refused and the local edit loses", {
|
|
1290
|
+
path: rel,
|
|
1291
|
+
memory_store_id: store.memoryStoreId
|
|
1292
|
+
});
|
|
1293
|
+
} else if (permanent && localSha !== undefined) {
|
|
1294
|
+
store.refusedShas.set(rel, localSha);
|
|
1295
|
+
__classPrivateFieldGet(this, _SessionMemoryStores_log, "f").warn("the server rejected this memory file, so it stays un-synced until its content changes", { path: rel, memory_store_id: store.memoryStoreId, rejection: String(e) });
|
|
1296
|
+
} else {
|
|
1297
|
+
__classPrivateFieldGet(this, _SessionMemoryStores_log, "f").warn("failed to upload memory", {
|
|
1298
|
+
path: rel,
|
|
1299
|
+
memory_store_id: store.memoryStoreId,
|
|
1300
|
+
error: String(e)
|
|
1301
|
+
});
|
|
1302
|
+
}
|
|
1278
1303
|
return;
|
|
1279
|
-
const content = decodeUTF8(data);
|
|
1280
|
-
const item = existing ? await __classPrivateFieldGet(this, _SessionMemoryStores_client, "f").beta.memoryStores.memories.update(existing.id, {
|
|
1281
|
-
memory_store_id: store.memoryStoreId,
|
|
1282
|
-
content,
|
|
1283
|
-
precondition: { type: "content_sha256", content_sha256: existing.content_sha256 }
|
|
1284
|
-
}) : await __classPrivateFieldGet(this, _SessionMemoryStores_client, "f").beta.memoryStores.memories.create(store.memoryStoreId, {
|
|
1285
|
-
path: "/" + rel,
|
|
1286
|
-
content
|
|
1287
|
-
});
|
|
1288
|
-
store.refusedShas.delete(rel);
|
|
1289
|
-
return item.content_sha256;
|
|
1290
|
-
} catch (e) {
|
|
1291
|
-
if (existing && isStatus(e, 404)) {
|
|
1292
|
-
return await __classPrivateFieldGet(this, _SessionMemoryStores_instances, "m", _SessionMemoryStores_upload2).call(this, store, rel, localSha, undefined);
|
|
1293
1304
|
}
|
|
1294
|
-
|
|
1295
|
-
if (
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
memory_store_id: store.memoryStoreId
|
|
1299
|
-
});
|
|
1300
|
-
} else if (permanent && localSha !== undefined) {
|
|
1301
|
-
store.refusedShas.set(rel, localSha);
|
|
1302
|
-
__classPrivateFieldGet(this, _SessionMemoryStores_log, "f").warn("the server rejected this memory file, so it stays un-synced until its content changes", { path: rel, memory_store_id: store.memoryStoreId, rejection: String(e) });
|
|
1303
|
-
} else {
|
|
1304
|
-
__classPrivateFieldGet(this, _SessionMemoryStores_log, "f").warn("failed to upload memory", {
|
|
1305
|
-
path: rel,
|
|
1306
|
-
memory_store_id: store.memoryStoreId,
|
|
1307
|
-
error: String(e)
|
|
1308
|
-
});
|
|
1305
|
+
}, _SessionMemoryStores_corroboratedDelete = async function _SessionMemoryStores_corroboratedDelete2(store, rel, remote, baseSha, deletes) {
|
|
1306
|
+
if (deletes.mode === "disabled") {
|
|
1307
|
+
deletes.suppressed++;
|
|
1308
|
+
return baseSha;
|
|
1309
1309
|
}
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
store.pendingDeletes.delete(rel);
|
|
1339
|
-
return baseSha;
|
|
1340
|
-
}
|
|
1341
|
-
if (!deletes.takeSlot())
|
|
1342
|
-
return baseSha;
|
|
1343
|
-
if (deletes.mode === "log_only") {
|
|
1344
|
-
__classPrivateFieldGet(this, _SessionMemoryStores_log, "f").info("log-only: sync would delete this memory on the server", {
|
|
1345
|
-
path: rel,
|
|
1346
|
-
memory_store_id: store.memoryStoreId
|
|
1347
|
-
});
|
|
1348
|
-
return baseSha;
|
|
1349
|
-
}
|
|
1350
|
-
const sha = await __classPrivateFieldGet(this, _SessionMemoryStores_instances, "m", _SessionMemoryStores_deleteRemote).call(this, store, rel, remote, baseSha);
|
|
1351
|
-
if (sha === undefined) {
|
|
1352
|
-
store.pendingDeletes.delete(rel);
|
|
1353
|
-
}
|
|
1354
|
-
return sha;
|
|
1355
|
-
}, _SessionMemoryStores_deleteRemote = async function _SessionMemoryStores_deleteRemote2(store, rel, remote, baseSha) {
|
|
1356
|
-
try {
|
|
1357
|
-
await __classPrivateFieldGet(this, _SessionMemoryStores_client, "f").beta.memoryStores.memories.delete(remote.id, {
|
|
1358
|
-
memory_store_id: store.memoryStoreId,
|
|
1359
|
-
expected_content_sha256: baseSha
|
|
1360
|
-
});
|
|
1361
|
-
} catch (e) {
|
|
1362
|
-
if (isStatus(e, 404))
|
|
1363
|
-
return;
|
|
1364
|
-
if (isStatus(e, 409) || isStatus(e, 412)) {
|
|
1365
|
-
__classPrivateFieldGet(this, _SessionMemoryStores_log, "f").warn("memory deleted locally but changed remotely; keeping the remote version", {
|
|
1310
|
+
let firstAbsent = store.pendingDeletes.get(rel);
|
|
1311
|
+
if (firstAbsent === undefined) {
|
|
1312
|
+
firstAbsent = Date.now();
|
|
1313
|
+
store.pendingDeletes.set(rel, firstAbsent);
|
|
1314
|
+
}
|
|
1315
|
+
if (!deletes.waiveWindow && Date.now() - firstAbsent < DELETE_CORROBORATION_MS) {
|
|
1316
|
+
return baseSha;
|
|
1317
|
+
}
|
|
1318
|
+
let markerOk;
|
|
1319
|
+
let stillAbsent;
|
|
1320
|
+
try {
|
|
1321
|
+
markerOk = await store.files.hashFile(MARKER_PATH) === markerSha(store.memoryStoreId);
|
|
1322
|
+
stillAbsent = await store.files.hashFile(rel) === null;
|
|
1323
|
+
} catch (e) {
|
|
1324
|
+
if (!(e instanceof FileStoreError) && !isErrno(e))
|
|
1325
|
+
throw e;
|
|
1326
|
+
markerOk = stillAbsent = false;
|
|
1327
|
+
}
|
|
1328
|
+
if (!markerOk)
|
|
1329
|
+
return baseSha;
|
|
1330
|
+
if (!stillAbsent) {
|
|
1331
|
+
store.pendingDeletes.delete(rel);
|
|
1332
|
+
return baseSha;
|
|
1333
|
+
}
|
|
1334
|
+
if (!deletes.takeSlot())
|
|
1335
|
+
return baseSha;
|
|
1336
|
+
if (deletes.mode === "log_only") {
|
|
1337
|
+
__classPrivateFieldGet(this, _SessionMemoryStores_log, "f").info("log-only: sync would delete this memory on the server", {
|
|
1366
1338
|
path: rel,
|
|
1367
1339
|
memory_store_id: store.memoryStoreId
|
|
1368
1340
|
});
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1341
|
+
return baseSha;
|
|
1342
|
+
}
|
|
1343
|
+
const sha = await __classPrivateFieldGet(this, _SessionMemoryStores_instances, "m", _SessionMemoryStores_deleteRemote).call(this, store, rel, remote, baseSha);
|
|
1344
|
+
if (sha === undefined) {
|
|
1345
|
+
store.pendingDeletes.delete(rel);
|
|
1346
|
+
}
|
|
1347
|
+
return sha;
|
|
1348
|
+
}, _SessionMemoryStores_deleteRemote = async function _SessionMemoryStores_deleteRemote2(store, rel, remote, baseSha) {
|
|
1349
|
+
try {
|
|
1350
|
+
await __classPrivateFieldGet(this, _SessionMemoryStores_client, "f").beta.memoryStores.memories.delete(remote.id, {
|
|
1372
1351
|
memory_store_id: store.memoryStoreId,
|
|
1373
|
-
|
|
1352
|
+
expected_content_sha256: baseSha
|
|
1374
1353
|
});
|
|
1354
|
+
} catch (e) {
|
|
1355
|
+
if (isStatus(e, 404))
|
|
1356
|
+
return;
|
|
1357
|
+
if (isStatus(e, 409) || isStatus(e, 412)) {
|
|
1358
|
+
__classPrivateFieldGet(this, _SessionMemoryStores_log, "f").warn("memory deleted locally but changed remotely; keeping the remote version", {
|
|
1359
|
+
path: rel,
|
|
1360
|
+
memory_store_id: store.memoryStoreId
|
|
1361
|
+
});
|
|
1362
|
+
} else {
|
|
1363
|
+
__classPrivateFieldGet(this, _SessionMemoryStores_log, "f").warn("failed to delete memory", {
|
|
1364
|
+
path: rel,
|
|
1365
|
+
memory_store_id: store.memoryStoreId,
|
|
1366
|
+
error: String(e)
|
|
1367
|
+
});
|
|
1368
|
+
}
|
|
1369
|
+
return baseSha;
|
|
1375
1370
|
}
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
return;
|
|
1380
|
-
};
|
|
1371
|
+
__classPrivateFieldGet(this, _SessionMemoryStores_log, "f").info("propagated local deletion", { path: rel, memory_store_id: store.memoryStoreId });
|
|
1372
|
+
return;
|
|
1373
|
+
};
|
|
1374
|
+
return SessionMemoryStores2;
|
|
1375
|
+
})();
|
|
1381
1376
|
function isErrno(e) {
|
|
1382
1377
|
return typeof e === "object" && e !== null && typeof e.code === "string";
|
|
1383
1378
|
}
|
|
@@ -1473,120 +1468,123 @@ function scrubbedShellEnv() {
|
|
|
1473
1468
|
}
|
|
1474
1469
|
return env;
|
|
1475
1470
|
}
|
|
1471
|
+
var BashSession = /* @__PURE__ */ (() => {
|
|
1476
1472
|
|
|
1477
|
-
class
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1473
|
+
class BashSession2 {
|
|
1474
|
+
constructor(dir, env = scrubbedShellEnv()) {
|
|
1475
|
+
_BashSession_instances.add(this);
|
|
1476
|
+
_BashSession_proc.set(this, undefined);
|
|
1477
|
+
_BashSession_buf.set(this, "");
|
|
1478
|
+
_BashSession_truncated.set(this, false);
|
|
1479
|
+
_BashSession_closed.set(this, false);
|
|
1480
|
+
_BashSession_waiting.set(this, null);
|
|
1481
|
+
__classPrivateFieldSet(this, _BashSession_proc, cp.spawn("/bin/bash", ["--noprofile", "--norc"], {
|
|
1482
|
+
cwd: dir,
|
|
1483
|
+
env: { ...env, PS1: "", PS2: "", TERM: "dumb" },
|
|
1484
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
1485
|
+
detached: true
|
|
1486
|
+
}), "f");
|
|
1487
|
+
__classPrivateFieldGet(this, _BashSession_proc, "f").stdout.setEncoding("utf8");
|
|
1488
|
+
__classPrivateFieldGet(this, _BashSession_proc, "f").stderr.setEncoding("utf8");
|
|
1489
|
+
__classPrivateFieldGet(this, _BashSession_proc, "f").stdout.on("data", (d) => __classPrivateFieldGet(this, _BashSession_instances, "m", _BashSession_append).call(this, d));
|
|
1490
|
+
__classPrivateFieldGet(this, _BashSession_proc, "f").stderr.on("data", (d) => __classPrivateFieldGet(this, _BashSession_instances, "m", _BashSession_append).call(this, d));
|
|
1491
|
+
__classPrivateFieldGet(this, _BashSession_proc, "f").once("close", () => {
|
|
1492
|
+
__classPrivateFieldSet(this, _BashSession_closed, true, "f");
|
|
1493
|
+
const w = __classPrivateFieldGet(this, _BashSession_waiting, "f");
|
|
1494
|
+
__classPrivateFieldSet(this, _BashSession_waiting, null, "f");
|
|
1495
|
+
w?.resolve();
|
|
1496
|
+
});
|
|
1497
|
+
}
|
|
1498
|
+
get closed() {
|
|
1499
|
+
return __classPrivateFieldGet(this, _BashSession_closed, "f");
|
|
1500
|
+
}
|
|
1501
|
+
async exec(command, opts = {}) {
|
|
1502
|
+
if (__classPrivateFieldGet(this, _BashSession_closed, "f")) {
|
|
1503
|
+
throw new AnthropicError("bash session terminated");
|
|
1504
|
+
}
|
|
1505
|
+
const timeoutMs = opts.timeoutMs ?? BASH_DEFAULT_TIMEOUT_MS;
|
|
1506
|
+
const signal = opts.signal;
|
|
1507
|
+
signal?.throwIfAborted();
|
|
1508
|
+
__classPrivateFieldSet(this, _BashSession_buf, "", "f");
|
|
1509
|
+
__classPrivateFieldSet(this, _BashSession_truncated, false, "f");
|
|
1510
|
+
const sentinel = `__ANT_CMD_${crypto2.randomUUID()}_DONE__`;
|
|
1511
|
+
const sentinelSplit = `${sentinel.slice(0, 8)}''${sentinel.slice(8)}`;
|
|
1512
|
+
const wrapped = `{ ${command}
|
|
1513
|
+
} </dev/null 2>&1; printf '\\n${sentinelSplit}%d\\n' $?
|
|
1514
|
+
`;
|
|
1515
|
+
__classPrivateFieldGet(this, _BashSession_proc, "f").stdin.write(wrapped);
|
|
1516
|
+
if (__classPrivateFieldGet(this, _BashSession_buf, "f").indexOf(sentinel) < 0) {
|
|
1517
|
+
const { promise: sentinelSeen, resolve: resolve2 } = promiseWithResolvers();
|
|
1518
|
+
__classPrivateFieldSet(this, _BashSession_waiting, { sentinel, resolve: resolve2 }, "f");
|
|
1519
|
+
let timer;
|
|
1520
|
+
let onAbort;
|
|
1521
|
+
try {
|
|
1522
|
+
await Promise.race([
|
|
1523
|
+
sentinelSeen,
|
|
1524
|
+
new Promise((_, reject) => {
|
|
1525
|
+
timer = setTimeout(() => reject(new BashTimeoutError(timeoutMs)), timeoutMs);
|
|
1526
|
+
}),
|
|
1527
|
+
new Promise((_, reject) => {
|
|
1528
|
+
if (!signal)
|
|
1529
|
+
return;
|
|
1530
|
+
onAbort = () => reject(signal.reason);
|
|
1531
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
1532
|
+
})
|
|
1533
|
+
]);
|
|
1534
|
+
} finally {
|
|
1535
|
+
if (timer)
|
|
1536
|
+
clearTimeout(timer);
|
|
1537
|
+
if (onAbort && signal)
|
|
1538
|
+
signal.removeEventListener("abort", onAbort);
|
|
1539
|
+
__classPrivateFieldSet(this, _BashSession_waiting, null, "f");
|
|
1540
|
+
}
|
|
1541
|
+
}
|
|
1542
|
+
const idx = __classPrivateFieldGet(this, _BashSession_buf, "f").indexOf(sentinel);
|
|
1543
|
+
if (idx < 0) {
|
|
1544
|
+
throw new AnthropicError("bash session terminated");
|
|
1545
|
+
}
|
|
1546
|
+
const tail = __classPrivateFieldGet(this, _BashSession_buf, "f").slice(idx + sentinel.length);
|
|
1547
|
+
const m = tail.match(/^(-?\d+)/);
|
|
1548
|
+
const exitCode = m ? parseInt(m[1], 10) : -1;
|
|
1549
|
+
let out = __classPrivateFieldGet(this, _BashSession_buf, "f").slice(0, idx).replace(ANSI_RE, "").replace(/\n+$/, "");
|
|
1550
|
+
if (__classPrivateFieldGet(this, _BashSession_truncated, "f")) {
|
|
1551
|
+
out = `[output truncated]
|
|
1552
|
+
${out}`;
|
|
1553
|
+
}
|
|
1554
|
+
return { output: out, exitCode };
|
|
1555
|
+
}
|
|
1556
|
+
close() {
|
|
1557
|
+
if (__classPrivateFieldGet(this, _BashSession_closed, "f"))
|
|
1558
|
+
return;
|
|
1496
1559
|
__classPrivateFieldSet(this, _BashSession_closed, true, "f");
|
|
1497
1560
|
const w = __classPrivateFieldGet(this, _BashSession_waiting, "f");
|
|
1498
1561
|
__classPrivateFieldSet(this, _BashSession_waiting, null, "f");
|
|
1499
1562
|
w?.resolve();
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
return __classPrivateFieldGet(this, _BashSession_closed, "f");
|
|
1504
|
-
}
|
|
1505
|
-
async exec(command, opts = {}) {
|
|
1506
|
-
if (__classPrivateFieldGet(this, _BashSession_closed, "f")) {
|
|
1507
|
-
throw new AnthropicError("bash session terminated");
|
|
1508
|
-
}
|
|
1509
|
-
const timeoutMs = opts.timeoutMs ?? BASH_DEFAULT_TIMEOUT_MS;
|
|
1510
|
-
const signal = opts.signal;
|
|
1511
|
-
signal?.throwIfAborted();
|
|
1512
|
-
__classPrivateFieldSet(this, _BashSession_buf, "", "f");
|
|
1513
|
-
__classPrivateFieldSet(this, _BashSession_truncated, false, "f");
|
|
1514
|
-
const sentinel = `__ANT_CMD_${crypto2.randomUUID()}_DONE__`;
|
|
1515
|
-
const sentinelSplit = `${sentinel.slice(0, 8)}''${sentinel.slice(8)}`;
|
|
1516
|
-
const wrapped = `{ ${command}
|
|
1517
|
-
} </dev/null 2>&1; printf '\\n${sentinelSplit}%d\\n' $?
|
|
1518
|
-
`;
|
|
1519
|
-
__classPrivateFieldGet(this, _BashSession_proc, "f").stdin.write(wrapped);
|
|
1520
|
-
if (__classPrivateFieldGet(this, _BashSession_buf, "f").indexOf(sentinel) < 0) {
|
|
1521
|
-
const { promise: sentinelSeen, resolve: resolve2 } = promiseWithResolvers();
|
|
1522
|
-
__classPrivateFieldSet(this, _BashSession_waiting, { sentinel, resolve: resolve2 }, "f");
|
|
1523
|
-
let timer;
|
|
1524
|
-
let onAbort;
|
|
1563
|
+
__classPrivateFieldGet(this, _BashSession_proc, "f").stdout.destroy();
|
|
1564
|
+
__classPrivateFieldGet(this, _BashSession_proc, "f").stderr.destroy();
|
|
1565
|
+
__classPrivateFieldGet(this, _BashSession_proc, "f").stdin.destroy();
|
|
1525
1566
|
try {
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
timer = setTimeout(() => reject(new BashTimeoutError(timeoutMs)), timeoutMs);
|
|
1530
|
-
}),
|
|
1531
|
-
new Promise((_, reject) => {
|
|
1532
|
-
if (!signal)
|
|
1533
|
-
return;
|
|
1534
|
-
onAbort = () => reject(signal.reason);
|
|
1535
|
-
signal.addEventListener("abort", onAbort, { once: true });
|
|
1536
|
-
})
|
|
1537
|
-
]);
|
|
1538
|
-
} finally {
|
|
1539
|
-
if (timer)
|
|
1540
|
-
clearTimeout(timer);
|
|
1541
|
-
if (onAbort && signal)
|
|
1542
|
-
signal.removeEventListener("abort", onAbort);
|
|
1543
|
-
__classPrivateFieldSet(this, _BashSession_waiting, null, "f");
|
|
1567
|
+
process.kill(-__classPrivateFieldGet(this, _BashSession_proc, "f").pid, "SIGKILL");
|
|
1568
|
+
} catch {
|
|
1569
|
+
__classPrivateFieldGet(this, _BashSession_proc, "f").kill("SIGKILL");
|
|
1544
1570
|
}
|
|
1571
|
+
__classPrivateFieldGet(this, _BashSession_proc, "f").unref();
|
|
1545
1572
|
}
|
|
1546
|
-
const idx = __classPrivateFieldGet(this, _BashSession_buf, "f").indexOf(sentinel);
|
|
1547
|
-
if (idx < 0) {
|
|
1548
|
-
throw new AnthropicError("bash session terminated");
|
|
1549
|
-
}
|
|
1550
|
-
const tail = __classPrivateFieldGet(this, _BashSession_buf, "f").slice(idx + sentinel.length);
|
|
1551
|
-
const m = tail.match(/^(-?\d+)/);
|
|
1552
|
-
const exitCode = m ? parseInt(m[1], 10) : -1;
|
|
1553
|
-
let out = __classPrivateFieldGet(this, _BashSession_buf, "f").slice(0, idx).replace(ANSI_RE, "").replace(/\n+$/, "");
|
|
1554
|
-
if (__classPrivateFieldGet(this, _BashSession_truncated, "f")) {
|
|
1555
|
-
out = `[output truncated]
|
|
1556
|
-
${out}`;
|
|
1557
|
-
}
|
|
1558
|
-
return { output: out, exitCode };
|
|
1559
1573
|
}
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
__classPrivateFieldSet(this, _BashSession_waiting, null, "f");
|
|
1566
|
-
w?.resolve();
|
|
1567
|
-
__classPrivateFieldGet(this, _BashSession_proc, "f").stdout.destroy();
|
|
1568
|
-
__classPrivateFieldGet(this, _BashSession_proc, "f").stderr.destroy();
|
|
1569
|
-
__classPrivateFieldGet(this, _BashSession_proc, "f").stdin.destroy();
|
|
1570
|
-
try {
|
|
1571
|
-
process.kill(-__classPrivateFieldGet(this, _BashSession_proc, "f").pid, "SIGKILL");
|
|
1572
|
-
} catch {
|
|
1573
|
-
__classPrivateFieldGet(this, _BashSession_proc, "f").kill("SIGKILL");
|
|
1574
|
+
_BashSession_proc = new WeakMap, _BashSession_buf = new WeakMap, _BashSession_truncated = new WeakMap, _BashSession_closed = new WeakMap, _BashSession_waiting = new WeakMap, _BashSession_instances = new WeakSet, _BashSession_append = function _BashSession_append2(d) {
|
|
1575
|
+
__classPrivateFieldSet(this, _BashSession_buf, __classPrivateFieldGet(this, _BashSession_buf, "f") + d, "f");
|
|
1576
|
+
if (__classPrivateFieldGet(this, _BashSession_buf, "f").length > BASH_OUTPUT_LIMIT) {
|
|
1577
|
+
__classPrivateFieldSet(this, _BashSession_buf, __classPrivateFieldGet(this, _BashSession_buf, "f").slice(__classPrivateFieldGet(this, _BashSession_buf, "f").length - BASH_OUTPUT_LIMIT), "f");
|
|
1578
|
+
__classPrivateFieldSet(this, _BashSession_truncated, true, "f");
|
|
1574
1579
|
}
|
|
1575
|
-
__classPrivateFieldGet(this,
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
}
|
|
1584
|
-
if (__classPrivateFieldGet(this, _BashSession_waiting, "f") && __classPrivateFieldGet(this, _BashSession_buf, "f").indexOf(__classPrivateFieldGet(this, _BashSession_waiting, "f").sentinel) >= 0) {
|
|
1585
|
-
const w = __classPrivateFieldGet(this, _BashSession_waiting, "f");
|
|
1586
|
-
__classPrivateFieldSet(this, _BashSession_waiting, null, "f");
|
|
1587
|
-
w.resolve();
|
|
1588
|
-
}
|
|
1589
|
-
};
|
|
1580
|
+
if (__classPrivateFieldGet(this, _BashSession_waiting, "f") && __classPrivateFieldGet(this, _BashSession_buf, "f").indexOf(__classPrivateFieldGet(this, _BashSession_waiting, "f").sentinel) >= 0) {
|
|
1581
|
+
const w = __classPrivateFieldGet(this, _BashSession_waiting, "f");
|
|
1582
|
+
__classPrivateFieldSet(this, _BashSession_waiting, null, "f");
|
|
1583
|
+
w.resolve();
|
|
1584
|
+
}
|
|
1585
|
+
};
|
|
1586
|
+
return BashSession2;
|
|
1587
|
+
})();
|
|
1590
1588
|
function betaBashTool(ctx) {
|
|
1591
1589
|
rejectUnrestrictedPaths(ctx.unrestrictedPaths);
|
|
1592
1590
|
let session;
|
|
@@ -1717,66 +1715,69 @@ async function readRangeStreaming(abs, filePath, startLine, endLine, limit) {
|
|
|
1717
1715
|
}
|
|
1718
1716
|
return lines.text();
|
|
1719
1717
|
}
|
|
1718
|
+
var LineRangeCollector = /* @__PURE__ */ (() => {
|
|
1720
1719
|
|
|
1721
|
-
class
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1720
|
+
class LineRangeCollector2 {
|
|
1721
|
+
constructor(filePath, startLine, endLine, limit) {
|
|
1722
|
+
_LineRangeCollector_instances.add(this);
|
|
1723
|
+
_LineRangeCollector_filePath.set(this, undefined);
|
|
1724
|
+
_LineRangeCollector_startLine.set(this, undefined);
|
|
1725
|
+
_LineRangeCollector_endLine.set(this, undefined);
|
|
1726
|
+
_LineRangeCollector_start.set(this, undefined);
|
|
1727
|
+
_LineRangeCollector_end.set(this, undefined);
|
|
1728
|
+
_LineRangeCollector_limit.set(this, undefined);
|
|
1729
|
+
_LineRangeCollector_line.set(this, 0);
|
|
1730
|
+
_LineRangeCollector_collected.set(this, []);
|
|
1731
|
+
_LineRangeCollector_collectedBytes.set(this, 0);
|
|
1732
|
+
__classPrivateFieldSet(this, _LineRangeCollector_filePath, filePath, "f");
|
|
1733
|
+
__classPrivateFieldSet(this, _LineRangeCollector_startLine, startLine, "f");
|
|
1734
|
+
__classPrivateFieldSet(this, _LineRangeCollector_endLine, endLine, "f");
|
|
1735
|
+
__classPrivateFieldSet(this, _LineRangeCollector_start, Math.max(0, startLine - 1), "f");
|
|
1736
|
+
__classPrivateFieldSet(this, _LineRangeCollector_end, endLine > 0 ? endLine : Infinity, "f");
|
|
1737
|
+
__classPrivateFieldSet(this, _LineRangeCollector_limit, limit, "f");
|
|
1738
|
+
}
|
|
1739
|
+
rangeIsEmpty() {
|
|
1740
|
+
return __classPrivateFieldGet(this, _LineRangeCollector_end, "f") <= __classPrivateFieldGet(this, _LineRangeCollector_start, "f");
|
|
1741
|
+
}
|
|
1742
|
+
rangeIsCollected() {
|
|
1743
|
+
return __classPrivateFieldGet(this, _LineRangeCollector_line, "f") >= __classPrivateFieldGet(this, _LineRangeCollector_end, "f");
|
|
1744
|
+
}
|
|
1745
|
+
collectFrom(chunk) {
|
|
1746
|
+
var _a;
|
|
1747
|
+
let lineStart = 0;
|
|
1748
|
+
while (lineStart < chunk.length && !this.rangeIsCollected()) {
|
|
1749
|
+
const newline = chunk.indexOf(10, lineStart);
|
|
1750
|
+
const lineEnd = newline < 0 ? chunk.length : newline;
|
|
1751
|
+
if (__classPrivateFieldGet(this, _LineRangeCollector_line, "f") >= __classPrivateFieldGet(this, _LineRangeCollector_start, "f")) {
|
|
1752
|
+
__classPrivateFieldGet(this, _LineRangeCollector_instances, "m", _LineRangeCollector_collect).call(this, chunk.subarray(lineStart, lineEnd), newline >= 0);
|
|
1753
|
+
}
|
|
1754
|
+
if (newline < 0)
|
|
1755
|
+
break;
|
|
1756
|
+
__classPrivateFieldSet(this, _LineRangeCollector_line, (_a = __classPrivateFieldGet(this, _LineRangeCollector_line, "f"), _a++, _a), "f");
|
|
1757
|
+
lineStart = newline + 1;
|
|
1758
|
+
}
|
|
1759
|
+
}
|
|
1760
|
+
text() {
|
|
1761
|
+
return Buffer.concat(__classPrivateFieldGet(this, _LineRangeCollector_collected, "f"), __classPrivateFieldGet(this, _LineRangeCollector_collectedBytes, "f")).toString("utf8");
|
|
1759
1762
|
}
|
|
1760
1763
|
}
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
},
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
return new ToolError(`read: view_range [${__classPrivateFieldGet(this, _LineRangeCollector_startLine, "f")}, ${__classPrivateFieldGet(this, _LineRangeCollector_endLine, "f")}] of ${__classPrivateFieldGet(this, _LineRangeCollector_filePath, "f")} exceeds ${__classPrivateFieldGet(this, _LineRangeCollector_limit, "f")}-byte limit. ` + "Narrow the view_range to read a smaller portion.");
|
|
1779
|
-
};
|
|
1764
|
+
_LineRangeCollector_filePath = new WeakMap, _LineRangeCollector_startLine = new WeakMap, _LineRangeCollector_endLine = new WeakMap, _LineRangeCollector_start = new WeakMap, _LineRangeCollector_end = new WeakMap, _LineRangeCollector_limit = new WeakMap, _LineRangeCollector_line = new WeakMap, _LineRangeCollector_collected = new WeakMap, _LineRangeCollector_collectedBytes = new WeakMap, _LineRangeCollector_instances = new WeakSet, _LineRangeCollector_collect = function _LineRangeCollector_collect2(lineBytes, newlineTerminated) {
|
|
1765
|
+
__classPrivateFieldGet(this, _LineRangeCollector_collected, "f").push(lineBytes);
|
|
1766
|
+
__classPrivateFieldSet(this, _LineRangeCollector_collectedBytes, __classPrivateFieldGet(this, _LineRangeCollector_collectedBytes, "f") + lineBytes.length, "f");
|
|
1767
|
+
if (newlineTerminated && __classPrivateFieldGet(this, _LineRangeCollector_line, "f") + 1 < __classPrivateFieldGet(this, _LineRangeCollector_end, "f")) {
|
|
1768
|
+
__classPrivateFieldGet(this, _LineRangeCollector_collected, "f").push(NEWLINE);
|
|
1769
|
+
__classPrivateFieldSet(this, _LineRangeCollector_collectedBytes, __classPrivateFieldGet(this, _LineRangeCollector_collectedBytes, "f") + NEWLINE.length, "f");
|
|
1770
|
+
}
|
|
1771
|
+
if (__classPrivateFieldGet(this, _LineRangeCollector_collectedBytes, "f") > __classPrivateFieldGet(this, _LineRangeCollector_limit, "f"))
|
|
1772
|
+
throw __classPrivateFieldGet(this, _LineRangeCollector_instances, "m", _LineRangeCollector_overLimitError).call(this);
|
|
1773
|
+
}, _LineRangeCollector_overLimitError = function _LineRangeCollector_overLimitError2() {
|
|
1774
|
+
if (__classPrivateFieldGet(this, _LineRangeCollector_end, "f") - __classPrivateFieldGet(this, _LineRangeCollector_start, "f") === 1) {
|
|
1775
|
+
return new ToolError(`read: line ${__classPrivateFieldGet(this, _LineRangeCollector_start, "f") + 1} of ${__classPrivateFieldGet(this, _LineRangeCollector_filePath, "f")} alone exceeds ${__classPrivateFieldGet(this, _LineRangeCollector_limit, "f")}-byte limit. ` + "The read tool cannot return part of a line, so view_range cannot narrow this further.");
|
|
1776
|
+
}
|
|
1777
|
+
return new ToolError(`read: view_range [${__classPrivateFieldGet(this, _LineRangeCollector_startLine, "f")}, ${__classPrivateFieldGet(this, _LineRangeCollector_endLine, "f")}] of ${__classPrivateFieldGet(this, _LineRangeCollector_filePath, "f")} exceeds ${__classPrivateFieldGet(this, _LineRangeCollector_limit, "f")}-byte limit. ` + "Narrow the view_range to read a smaller portion.");
|
|
1778
|
+
};
|
|
1779
|
+
return LineRangeCollector2;
|
|
1780
|
+
})();
|
|
1780
1781
|
function betaWriteTool(ctx) {
|
|
1781
1782
|
rejectUnrestrictedPaths(ctx.unrestrictedPaths);
|
|
1782
1783
|
return betaTool({
|