@humain/humain-code 0.4.18 → 0.5.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/CHANGELOG.md +247 -0
- package/dist/bundle/agent-monitor.js +1 -1
- package/dist/bundle/chunks/anthropic-messages-ZP5KUK52.js +67 -0
- package/dist/bundle/chunks/anthropic.js +2 -2
- package/dist/bundle/chunks/azure-openai-responses-QJFYQ3DF.js +15 -0
- package/dist/bundle/chunks/bedrock-converse-stream.js +152 -200
- package/dist/bundle/chunks/chunk-2GCMACT4.js +1956 -0
- package/dist/bundle/chunks/{chunk-7VY5IL74.js → chunk-476XBL3W.js} +3 -3
- package/dist/bundle/chunks/{chunk-P4UKLIQB.js → chunk-5C4VL2AR.js} +4 -4
- package/dist/bundle/chunks/{chunk-QEF72EIZ.js → chunk-A6B2QMA7.js} +40 -96
- package/dist/bundle/chunks/{chunk-3UXBFT4Q.js → chunk-A6YBWW4T.js} +1428 -1334
- package/dist/bundle/chunks/{chunk-OWLBGSXY.js → chunk-CN3Q5UNB.js} +388 -310
- package/dist/bundle/chunks/{chunk-SCIGZFN5.js → chunk-DNGJMRJW.js} +11 -11
- package/dist/bundle/chunks/{chunk-YMBXWW36.js → chunk-DR37WKFZ.js} +9 -8
- package/dist/bundle/chunks/chunk-DU6POZ7E.js +10 -0
- package/dist/bundle/chunks/{chunk-G6ABHCPB.js → chunk-FO2NYB6O.js} +655 -663
- package/dist/bundle/chunks/{chunk-RXOCQRBG.js → chunk-GEISZXXH.js} +1 -1
- package/dist/bundle/chunks/{chunk-OKALNPTJ.js → chunk-HIZWUSPN.js} +24 -24
- package/dist/bundle/chunks/{chunk-MVYV6MJY.js → chunk-HT5YN3LX.js} +1 -1
- package/dist/bundle/chunks/chunk-IDU5BNNI.js +15 -0
- package/dist/bundle/chunks/{chunk-TIFFHHW6.js → chunk-JCXXRCP6.js} +5 -5
- package/dist/bundle/chunks/{chunk-QYCOHSI7.js → chunk-KKCMWB63.js} +8 -7
- package/dist/bundle/chunks/{chunk-SCBU5WOP.js → chunk-M74U5X4S.js} +30 -23
- package/dist/bundle/chunks/{chunk-AWCJWXGD.js → chunk-MIJHJNNQ.js} +3 -2
- package/dist/bundle/chunks/{chunk-Y26OS23T.js → chunk-N7CQ3UV3.js} +4 -4
- package/dist/bundle/chunks/{chunk-XQZG5HPT.js → chunk-O4DO5RWS.js} +11 -6
- package/dist/bundle/chunks/chunk-OR25QDSS.js +365 -0
- package/dist/bundle/chunks/{chunk-7PRU6YW3.js → chunk-OZNC2W4B.js} +306 -286
- package/dist/bundle/chunks/{chunk-Z33NNMNB.js → chunk-PH7UP57J.js} +1 -1
- package/dist/bundle/chunks/{chunk-HPSQKIWK.js → chunk-PS7DGA7B.js} +1 -1
- package/dist/bundle/chunks/chunk-Q3SFYT2X.js +1965 -0
- package/dist/bundle/chunks/chunk-QW6PTCAB.js +10 -0
- package/dist/bundle/chunks/{chunk-5CDES42D.js → chunk-QWXPGBAG.js} +1 -1
- package/dist/bundle/chunks/{chunk-NCQ6WAQK.js → chunk-ROZV2IYD.js} +1 -1
- package/dist/bundle/chunks/{chunk-3XDL5ZE4.js → chunk-RTXDU3AA.js} +148 -122
- package/dist/bundle/chunks/{chunk-L5OUCJ7N.js → chunk-T3HXWZG4.js} +11 -11
- package/dist/bundle/chunks/{chunk-FZUJXM6D.js → chunk-UDB6NI4G.js} +309 -240
- package/dist/bundle/chunks/chunk-UTNHGOFS.js +88 -0
- package/dist/bundle/chunks/{chunk-H2FY3PEV.js → chunk-V62QBESW.js} +4 -3
- package/dist/bundle/chunks/{chunk-NSMMDV3N.js → chunk-XA7CJAYH.js} +4 -3
- package/dist/bundle/chunks/chunk-XQX7S3GM.js +7 -0
- package/dist/bundle/chunks/chunk-YFOLLX5D.js +23 -0
- package/dist/bundle/chunks/{chunk-YRCLNWFV.js → chunk-ZI7TK7HM.js} +1 -1
- package/dist/bundle/chunks/{chunk-V76YPIMT.js → chunk-ZR4GF4WU.js} +21 -15
- package/dist/bundle/chunks/{cli-2NKM2RNJ.js → cli-VXU7OWFU.js} +1 -1
- package/dist/bundle/chunks/cloudflare-workers-ai-system-one-T7TPP7SQ.js +4 -0
- package/dist/bundle/chunks/codemode-worker.js +27 -27
- package/dist/bundle/chunks/compat-S2IBVV6V.js +13 -0
- package/dist/bundle/chunks/{dist-ZJIYY3GA.js → dist-645GFIWH.js} +452 -448
- package/dist/bundle/chunks/{dist-XVXV2CL4.js → dist-IBUWEKEE.js} +3 -3
- package/dist/bundle/chunks/dist-YFMJEHPH.js +8 -0
- package/dist/bundle/chunks/{dist-cjs-AXBW3N4F.js → dist-cjs-HTASUQXQ.js} +82 -80
- package/dist/bundle/chunks/{easter-egg-3d-VGJ77XZQ.js → easter-egg-3d-YOPLCOVW.js} +2 -2
- package/dist/bundle/chunks/es-YEFEOGR3.js +1905 -0
- package/dist/bundle/chunks/{esm-GIR7QH65.js → esm-R6HJ4QEG.js} +5 -5
- package/dist/bundle/chunks/{event-streams-NXFTZDSF.js → event-streams-BR2IL6C5.js} +1 -1
- package/dist/bundle/chunks/{execute-ZBEZNJ4E.js → execute-2JXEKQ2X.js} +17 -8
- package/dist/bundle/chunks/{extract-RFWEHH6W.js → extract-OTCGZGTL.js} +50 -47
- package/dist/bundle/chunks/github-copilot.js +42 -40
- package/dist/bundle/chunks/google-generative-ai-HVPCGIZ6.js +21 -0
- package/dist/bundle/chunks/google-vertex-UM5MAALA.js +25 -0
- package/dist/bundle/chunks/host-ZHEL5XQW.js +2 -0
- package/dist/bundle/chunks/{https-proxy-agent-7CAXVAFH.js → https-proxy-agent-JQICCRPH.js} +1 -1
- package/dist/bundle/chunks/{llama-cpp-classify-AGCW7HYN.js → llama-cpp-classify-B3G57LVR.js} +5 -5
- package/dist/bundle/chunks/{mistral-conversations-G3GN6CMT.js → mistral-conversations-AH72RLXK.js} +11 -11
- package/dist/bundle/chunks/{node-A6SZ3T7E.js → node-SJPZTR4K.js} +190 -190
- package/dist/bundle/chunks/{node-DZCAT4Q6.js → node-VSA4ZN7D.js} +1 -1
- package/dist/bundle/chunks/openai-chatgpt.js +2 -2
- package/dist/bundle/chunks/{openai-codex-responses-FJFDAWHI.js → openai-codex-responses-L366637C.js} +48 -47
- package/dist/bundle/chunks/openai-codex.js +2 -2
- package/dist/bundle/chunks/openai-completions-ZP62QXJX.js +83 -0
- package/dist/bundle/chunks/{openai-decisions-HESOHYZB.js → openai-decisions-WOWUC65P.js} +1 -1
- package/dist/bundle/chunks/openai-responses-DXUGSUTN.js +26 -0
- package/dist/bundle/chunks/openrouter-images-5K47HDAT.js +8 -0
- package/dist/bundle/chunks/openrouter.js +2 -2
- package/dist/bundle/chunks/{pi-messages-SAOV3JNW.js → pi-messages-MOQQDZBK.js} +5 -4
- package/dist/bundle/chunks/radius.js +2 -2
- package/dist/bundle/chunks/{runtime-HJEUOD4R.js → runtime-5VFZTMWL.js} +1 -1
- package/dist/bundle/chunks/typesafe-system-one-43OCHGKP.js +3 -0
- package/dist/bundle/chunks/{undici-4BK3MVJV.js → undici-EK3EUI2E.js} +1 -1
- package/dist/bundle/chunks/virtual-modules-GU6AW5ZK.js +5 -0
- package/dist/bundle/cli-runtime.js +3 -3
- package/dist/bundle/flow/package.json +4 -4
- package/dist/bundle/index.js +6 -6
- package/dist/bundle/rpc-entry.js +3 -3
- package/dist/cli/args.d.ts +6 -0
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +11 -0
- package/dist/cli/args.js.map +1 -1
- package/dist/coordination/adapter/tool.d.ts.map +1 -1
- package/dist/coordination/adapter/tool.js +3 -1
- package/dist/coordination/adapter/tool.js.map +1 -1
- package/dist/coordination/broker/broker.d.ts +6 -2
- package/dist/coordination/broker/broker.d.ts.map +1 -1
- package/dist/coordination/broker/broker.js +20 -8
- package/dist/coordination/broker/broker.js.map +1 -1
- package/dist/coordination/client/client.d.ts.map +1 -1
- package/dist/coordination/client/client.js +4 -2
- package/dist/coordination/client/client.js.map +1 -1
- package/dist/coordination/transport/discovery.d.ts +10 -3
- package/dist/coordination/transport/discovery.d.ts.map +1 -1
- package/dist/coordination/transport/discovery.js +18 -5
- package/dist/coordination/transport/discovery.js.map +1 -1
- package/dist/core/agent-session.d.ts +35 -2
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +163 -40
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/anthropic-subscription-usage.d.ts +47 -0
- package/dist/core/anthropic-subscription-usage.d.ts.map +1 -0
- package/dist/core/anthropic-subscription-usage.js +170 -0
- package/dist/core/anthropic-subscription-usage.js.map +1 -0
- package/dist/core/bash-executor.d.ts.map +1 -1
- package/dist/core/bash-executor.js +7 -1
- package/dist/core/bash-executor.js.map +1 -1
- package/dist/core/client-identity.d.ts +13 -0
- package/dist/core/client-identity.d.ts.map +1 -0
- package/dist/core/client-identity.js +25 -0
- package/dist/core/client-identity.js.map +1 -0
- package/dist/core/codex-usage.d.ts +37 -1
- package/dist/core/codex-usage.d.ts.map +1 -1
- package/dist/core/codex-usage.js +104 -11
- package/dist/core/codex-usage.js.map +1 -1
- package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
- package/dist/core/compaction/branch-summarization.js +1 -2
- package/dist/core/compaction/branch-summarization.js.map +1 -1
- package/dist/core/compaction/compaction.d.ts +2 -2
- package/dist/core/compaction/compaction.d.ts.map +1 -1
- package/dist/core/compaction/compaction.js +20 -15
- package/dist/core/compaction/compaction.js.map +1 -1
- package/dist/core/export-html/index.d.ts.map +1 -1
- package/dist/core/export-html/index.js +2 -0
- package/dist/core/export-html/index.js.map +1 -1
- package/dist/core/export-html/template.html +1 -0
- package/dist/core/export-html/template.js +2 -1
- package/dist/core/export-html/vendor/marked-cjk-friendly.min.js +6 -0
- package/dist/core/export-html/vendor/marked.min.js +30 -29
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +3 -0
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +14 -0
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +86 -2
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/virtual-modules.d.ts.map +1 -1
- package/dist/core/extensions/virtual-modules.js +3 -0
- package/dist/core/extensions/virtual-modules.js.map +1 -1
- package/dist/core/model-config.d.ts +920 -0
- package/dist/core/model-config.d.ts.map +1 -1
- package/dist/core/model-config.js +48 -24
- package/dist/core/model-config.js.map +1 -1
- package/dist/core/model-registry.d.ts +18 -0
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +20 -0
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +14 -6
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/model-runtime.d.ts +9 -0
- package/dist/core/model-runtime.d.ts.map +1 -1
- package/dist/core/model-runtime.js +99 -12
- package/dist/core/model-runtime.js.map +1 -1
- package/dist/core/output-guard.d.ts +13 -1
- package/dist/core/output-guard.d.ts.map +1 -1
- package/dist/core/output-guard.js +101 -11
- package/dist/core/output-guard.js.map +1 -1
- package/dist/core/provider-composer.d.ts +2 -1
- package/dist/core/provider-composer.d.ts.map +1 -1
- package/dist/core/provider-composer.js +7 -3
- package/dist/core/provider-composer.js.map +1 -1
- package/dist/core/remote-catalog-provider.d.ts.map +1 -1
- package/dist/core/remote-catalog-provider.js +7 -2
- package/dist/core/remote-catalog-provider.js.map +1 -1
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +8 -9
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-manager.d.ts +4 -0
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +242 -26
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/system-prompt.d.ts +6 -1
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +93 -1
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/tools/grep.d.ts.map +1 -1
- package/dist/core/tools/grep.js +3 -1
- package/dist/core/tools/grep.js.map +1 -1
- package/dist/core/tools/ls.d.ts.map +1 -1
- package/dist/core/tools/ls.js +37 -12
- package/dist/core/tools/ls.js.map +1 -1
- package/dist/extensions/codemode/execute.d.ts.map +1 -1
- package/dist/extensions/codemode/execute.js +102 -24
- package/dist/extensions/codemode/execute.js.map +1 -1
- package/dist/extensions/index.d.ts.map +1 -1
- package/dist/extensions/index.js +3 -1
- package/dist/extensions/index.js.map +1 -1
- package/dist/extensions/mcp/config.d.ts.map +1 -1
- package/dist/extensions/mcp/config.js +3 -2
- package/dist/extensions/mcp/config.js.map +1 -1
- package/dist/extensions/usage/index.d.ts +15 -0
- package/dist/extensions/usage/index.d.ts.map +1 -0
- package/dist/extensions/usage/index.js +110 -0
- package/dist/extensions/usage/index.js.map +1 -0
- package/dist/extensions/usage/overview.d.ts +90 -0
- package/dist/extensions/usage/overview.d.ts.map +1 -0
- package/dist/extensions/usage/overview.js +215 -0
- package/dist/extensions/usage/overview.js.map +1 -0
- package/dist/extensions/usage/popup.d.ts +21 -0
- package/dist/extensions/usage/popup.d.ts.map +1 -0
- package/dist/extensions/usage/popup.js +98 -0
- package/dist/extensions/usage/popup.js.map +1 -0
- package/dist/humain/bedrock-provider/vendor/index.bundle.mjs +21 -2
- package/dist/humain/bundled-extension-names.d.ts +6 -0
- package/dist/humain/bundled-extension-names.d.ts.map +1 -0
- package/dist/humain/bundled-extension-names.js +9 -0
- package/dist/humain/bundled-extension-names.js.map +1 -0
- package/dist/humain/index.d.ts +2 -2
- package/dist/humain/index.d.ts.map +1 -1
- package/dist/humain/index.js +3 -2
- package/dist/humain/index.js.map +1 -1
- package/dist/humain/web-access/vendor/anysearch.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/anysearch.js +3 -3
- package/dist/humain/web-access/vendor/anysearch.js.map +1 -1
- package/dist/humain/web-access/vendor/bocha.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/bocha.js +3 -3
- package/dist/humain/web-access/vendor/bocha.js.map +1 -1
- package/dist/humain/web-access/vendor/brightdata-unlocker.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/brightdata-unlocker.js +2 -2
- package/dist/humain/web-access/vendor/brightdata-unlocker.js.map +1 -1
- package/dist/humain/web-access/vendor/brightdata.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/brightdata.js +3 -3
- package/dist/humain/web-access/vendor/brightdata.js.map +1 -1
- package/dist/humain/web-access/vendor/ceramic.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/ceramic.js +2 -2
- package/dist/humain/web-access/vendor/ceramic.js.map +1 -1
- package/dist/humain/web-access/vendor/curator-page.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/curator-page.js +3 -1
- package/dist/humain/web-access/vendor/curator-page.js.map +1 -1
- package/dist/humain/web-access/vendor/curator-server.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/curator-server.js +2 -0
- package/dist/humain/web-access/vendor/curator-server.js.map +1 -1
- package/dist/humain/web-access/vendor/deepseek.d.ts +11 -1
- package/dist/humain/web-access/vendor/deepseek.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/deepseek.js +170 -5
- package/dist/humain/web-access/vendor/deepseek.js.map +1 -1
- package/dist/humain/web-access/vendor/extract.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/extract.js +63 -6
- package/dist/humain/web-access/vendor/extract.js.map +1 -1
- package/dist/humain/web-access/vendor/gemini-search.d.ts +5 -3
- package/dist/humain/web-access/vendor/gemini-search.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/gemini-search.js +33 -7
- package/dist/humain/web-access/vendor/gemini-search.js.map +1 -1
- package/dist/humain/web-access/vendor/index.d.ts +1 -0
- package/dist/humain/web-access/vendor/index.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/index.js +18 -3
- package/dist/humain/web-access/vendor/index.js.map +1 -1
- package/dist/humain/web-access/vendor/jina-search.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/jina-search.js +6 -4
- package/dist/humain/web-access/vendor/jina-search.js.map +1 -1
- package/dist/humain/web-access/vendor/kagi.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/kagi.js +4 -4
- package/dist/humain/web-access/vendor/kagi.js.map +1 -1
- package/dist/humain/web-access/vendor/keenable.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/keenable.js +2 -2
- package/dist/humain/web-access/vendor/keenable.js.map +1 -1
- package/dist/humain/web-access/vendor/linkup.d.ts +6 -0
- package/dist/humain/web-access/vendor/linkup.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/linkup.js +167 -0
- package/dist/humain/web-access/vendor/linkup.js.map +1 -0
- package/dist/humain/web-access/vendor/mistral-search.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/mistral-search.js +3 -3
- package/dist/humain/web-access/vendor/mistral-search.js.map +1 -1
- package/dist/humain/web-access/vendor/ollama.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/ollama.js +4 -4
- package/dist/humain/web-access/vendor/ollama.js.map +1 -1
- package/dist/humain/web-access/vendor/parallel.js +6 -7
- package/dist/humain/web-access/vendor/parallel.js.map +1 -1
- package/dist/humain/web-access/vendor/perplexity.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/perplexity.js +4 -3
- package/dist/humain/web-access/vendor/perplexity.js.map +1 -1
- package/dist/humain/web-access/vendor/querit.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/querit.js +3 -3
- package/dist/humain/web-access/vendor/querit.js.map +1 -1
- package/dist/humain/web-access/vendor/search1api.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/search1api.js +3 -3
- package/dist/humain/web-access/vendor/search1api.js.map +1 -1
- package/dist/humain/web-access/vendor/searchinfinity.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/searchinfinity.js +3 -3
- package/dist/humain/web-access/vendor/searchinfinity.js.map +1 -1
- package/dist/humain/web-access/vendor/serpapi.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/serpapi.js +6 -5
- package/dist/humain/web-access/vendor/serpapi.js.map +1 -1
- package/dist/humain/web-access/vendor/serpbase.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/serpbase.js +4 -4
- package/dist/humain/web-access/vendor/serpbase.js.map +1 -1
- package/dist/humain/web-access/vendor/serpdive.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/serpdive.js +3 -3
- package/dist/humain/web-access/vendor/serpdive.js.map +1 -1
- package/dist/humain/web-access/vendor/serper.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/serper.js +5 -4
- package/dist/humain/web-access/vendor/serper.js.map +1 -1
- package/dist/humain/web-access/vendor/serply.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/serply.js +2 -2
- package/dist/humain/web-access/vendor/serply.js.map +1 -1
- package/dist/humain/web-access/vendor/utils.d.ts +3 -1
- package/dist/humain/web-access/vendor/utils.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/utils.js +27 -2
- package/dist/humain/web-access/vendor/utils.js.map +1 -1
- package/dist/humain/web-access/vendor/valyu.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/valyu.js +3 -3
- package/dist/humain/web-access/vendor/valyu.js.map +1 -1
- package/dist/humain/web-access/vendor/web-tool-core.d.ts +2 -0
- package/dist/humain/web-access/vendor/web-tool-core.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/web-tool-core.js +3 -0
- package/dist/humain/web-access/vendor/web-tool-core.js.map +1 -1
- package/dist/humain/web-access/vendor/xai-search.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/xai-search.js +51 -8
- package/dist/humain/web-access/vendor/xai-search.js.map +1 -1
- package/dist/humain/web-access/vendor/xcrawl.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/xcrawl.js +3 -3
- package/dist/humain/web-access/vendor/xcrawl.js.map +1 -1
- package/dist/humain/web-access/vendor/you.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/you.js +2 -2
- package/dist/humain/web-access/vendor/you.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +15 -2
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/assistant-message.d.ts +14 -2
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/assistant-message.js +62 -7
- package/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/dist/modes/interactive/components/config-selector.js +1 -1
- package/dist/modes/interactive/components/config-selector.js.map +1 -1
- package/dist/modes/interactive/components/custom-editor.d.ts +2 -0
- package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
- package/dist/modes/interactive/components/custom-editor.js +6 -1
- package/dist/modes/interactive/components/custom-editor.js.map +1 -1
- package/dist/modes/interactive/components/easter-egg-3d.js +1 -1
- package/dist/modes/interactive/components/easter-egg-3d.js.map +1 -1
- package/dist/modes/interactive/components/footer.d.ts +10 -2
- package/dist/modes/interactive/components/footer.d.ts.map +1 -1
- package/dist/modes/interactive/components/footer.js +141 -66
- package/dist/modes/interactive/components/footer.js.map +1 -1
- package/dist/modes/interactive/components/mermaid.d.ts.map +1 -1
- package/dist/modes/interactive/components/mermaid.js +16 -3
- package/dist/modes/interactive/components/mermaid.js.map +1 -1
- package/dist/modes/interactive/components/model-selector.js +1 -1
- package/dist/modes/interactive/components/model-selector.js.map +1 -1
- package/dist/modes/interactive/components/themed-text.d.ts.map +1 -1
- package/dist/modes/interactive/components/themed-text.js +3 -2
- package/dist/modes/interactive/components/themed-text.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +17 -6
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/components/user-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/user-message.js +3 -2
- package/dist/modes/interactive/components/user-message.js.map +1 -1
- package/dist/modes/interactive/components/visual-truncate.d.ts.map +1 -1
- package/dist/modes/interactive/components/visual-truncate.js +4 -2
- package/dist/modes/interactive/components/visual-truncate.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +13 -17
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +90 -122
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/print-mode.d.ts.map +1 -1
- package/dist/modes/print-mode.js +2 -5
- package/dist/modes/print-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-mode.js +2 -3
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/dist/package-manager-cli.d.ts.map +1 -1
- package/dist/package-manager-cli.js +2 -1
- package/dist/package-manager-cli.js.map +1 -1
- package/dist/utils/child-process.d.ts.map +1 -1
- package/dist/utils/child-process.js +3 -2
- package/dist/utils/child-process.js.map +1 -1
- package/dist/utils/clipboard-command.d.ts.map +1 -1
- package/dist/utils/clipboard-command.js +3 -0
- package/dist/utils/clipboard-command.js.map +1 -1
- package/dist/utils/pi-user-agent.d.ts +1 -0
- package/dist/utils/pi-user-agent.d.ts.map +1 -1
- package/dist/utils/pi-user-agent.js +3 -2
- package/dist/utils/pi-user-agent.js.map +1 -1
- package/dist/utils/shell.d.ts.map +1 -1
- package/dist/utils/shell.js +45 -13
- package/dist/utils/shell.js.map +1 -1
- package/dist/utils/tools-manager.d.ts.map +1 -1
- package/dist/utils/tools-manager.js +4 -3
- package/dist/utils/tools-manager.js.map +1 -1
- package/docs/codemode.md +2 -2
- package/docs/compaction.md +3 -3
- package/docs/coordination.md +1 -1
- package/docs/custom-provider.md +53 -1
- package/docs/docs.json +4 -0
- package/docs/environment-variables.md +2 -0
- package/docs/extensions.md +133 -10
- package/docs/models-configuration.md +197 -0
- package/docs/models.md +21 -5
- package/docs/settings.md +1 -1
- package/docs/slash-commands.md +10 -0
- package/docs/tui.md +70 -0
- package/docs/windows.md +16 -2
- package/examples/extensions/custom-provider-anthropic/package.json +2 -2
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/gondolin/package-lock.json +2 -2
- package/examples/extensions/gondolin/package.json +1 -1
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/examples/plugins/pi-example-plugin/package.json +2 -2
- package/npm-shrinkwrap.json +243 -219
- package/package.json +21 -20
- package/schemas/models.schema.json +84 -30
- package/src/coordination/UPSTREAM.md +36 -3
- package/src/coordination/upstream.json +3 -3
- package/src/humain/web-access/UPSTREAM.md +72 -1
- package/src/humain/web-access/upstream.json +5 -4
- package/dist/bundle/chunks/anthropic-messages-TSNY5MWH.js +0 -67
- package/dist/bundle/chunks/azure-openai-responses-Z4DCXO2G.js +0 -15
- package/dist/bundle/chunks/chunk-26EAEXO5.js +0 -167
- package/dist/bundle/chunks/chunk-2ZFUMXOZ.js +0 -1790
- package/dist/bundle/chunks/chunk-5K5RFXXO.js +0 -74
- package/dist/bundle/chunks/chunk-PY7SOXCA.js +0 -10
- package/dist/bundle/chunks/chunk-UGJAAWNC.js +0 -7
- package/dist/bundle/chunks/chunk-UGXYG7HN.js +0 -22
- package/dist/bundle/chunks/chunk-VEYTRNQC.js +0 -5
- package/dist/bundle/chunks/chunk-X3O5MCKJ.js +0 -7
- package/dist/bundle/chunks/chunk-YLYOJQQX.js +0 -1951
- package/dist/bundle/chunks/cloudflare-workers-ai-system-one-MUJQ6LT2.js +0 -4
- package/dist/bundle/chunks/compat-VDGEZSVM.js +0 -13
- package/dist/bundle/chunks/dist-LKDZAEUQ.js +0 -7
- package/dist/bundle/chunks/es-N6YFJOD7.js +0 -1901
- package/dist/bundle/chunks/google-generative-ai-4OVYRP24.js +0 -21
- package/dist/bundle/chunks/google-vertex-3WQAZJQD.js +0 -25
- package/dist/bundle/chunks/host-63SNKK5Y.js +0 -2
- package/dist/bundle/chunks/openai-completions-IC7WRLTI.js +0 -82
- package/dist/bundle/chunks/openai-responses-XXCYDFSM.js +0 -24
- package/dist/bundle/chunks/openrouter-images-DT2HMZNO.js +0 -8
- package/dist/bundle/chunks/typesafe-system-one-HCMGHK6A.js +0 -2
- package/dist/bundle/chunks/virtual-modules-CFJTDIXL.js +0 -5
- package/dist/core/provider-attribution.d.ts +0 -4
- package/dist/core/provider-attribution.d.ts.map +0 -1
- package/dist/core/provider-attribution.js +0 -85
- package/dist/core/provider-attribution.js.map +0 -1
- /package/dist/bundle/chunks/{chunk-WZMA7HAJ.js → chunk-XQRYOCHA.js} +0 -0
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { getCurrentSystemMessage, uuidv7, } from "@earendil-works/pi-ai";
|
|
2
2
|
import { randomUUID } from "crypto";
|
|
3
|
-
import { appendFileSync, closeSync,
|
|
4
|
-
import { readdir, stat } from "fs/promises";
|
|
3
|
+
import { appendFileSync, closeSync, existsSync, fstatSync, fsyncSync, mkdirSync, openSync, readdirSync, readSync, renameSync, statSync, writeFileSync, writeSync, } from "fs";
|
|
4
|
+
import { open, readdir, stat } from "fs/promises";
|
|
5
5
|
import { basename, join, resolve } from "path";
|
|
6
|
-
import { createInterface } from "readline";
|
|
7
6
|
import { StringDecoder } from "string_decoder";
|
|
8
7
|
import { APP_TITLE, getAgentDir as getDefaultAgentDir, getSessionsDir } from "../config.js";
|
|
9
8
|
import { normalizePath, resolvePath } from "../utils/paths.js";
|
|
@@ -532,6 +531,109 @@ function getMessageActivityTime(entry) {
|
|
|
532
531
|
const t = new Date(entry.timestamp).getTime();
|
|
533
532
|
return Number.isNaN(t) ? undefined : t;
|
|
534
533
|
}
|
|
534
|
+
/** Length of the start of a line that is enough to tell what a listing needs from it. */
|
|
535
|
+
const LINE_HEAD_BYTES = 256;
|
|
536
|
+
/** A message line as `JSON.stringify` writes it, up to its message's role (group 1). */
|
|
537
|
+
const MESSAGE_LINE_HEAD = /^\{"type":"message","id":"[^"\\]*","parentId":(?:null|"[^"\\]*"),"timestamp":"[^"\\]*","message":\{"role":"([^"\\]*)"/;
|
|
538
|
+
/**
|
|
539
|
+
* What a line after the header gives a session listing, told from its first bytes where they are enough:
|
|
540
|
+
* - "skip": an entry of a type the listing does not use. Such a line adds nothing whether it parses or not (a line has
|
|
541
|
+
* one "type": JSON.stringify writes no key twice).
|
|
542
|
+
* - "count": a message the listing only counts: not a user or assistant message (tool results, system prompts). These
|
|
543
|
+
* are most of a session's bytes. The line must end like a whole entry ("}}", the end of its message and its own), so a
|
|
544
|
+
* control-denied tombstone, whose flag follows its message, is parsed.
|
|
545
|
+
* - "parse": anything else, including every line whose start is not written the way `JSON.stringify` writes entries.
|
|
546
|
+
* HUMAIN: context edits are parsed, since control denials among them hide messages from the listing.
|
|
547
|
+
*/
|
|
548
|
+
function classifySessionLine(buffer, start, end) {
|
|
549
|
+
const head = buffer.toString("latin1", start, Math.min(end, start + LINE_HEAD_BYTES));
|
|
550
|
+
if (!head.startsWith('{"type":"'))
|
|
551
|
+
return "parse";
|
|
552
|
+
const typeEnd = head.indexOf('"', 9);
|
|
553
|
+
if (typeEnd === -1)
|
|
554
|
+
return "parse";
|
|
555
|
+
const type = head.slice(9, typeEnd);
|
|
556
|
+
if (type === "session_info" || type === "context_edit" || type.includes("\\"))
|
|
557
|
+
return "parse";
|
|
558
|
+
if (type !== "message")
|
|
559
|
+
return "skip";
|
|
560
|
+
const role = MESSAGE_LINE_HEAD.exec(head)?.[1];
|
|
561
|
+
if (role === undefined || role === "user" || role === "assistant")
|
|
562
|
+
return "parse";
|
|
563
|
+
return end - start >= 2 && buffer[end - 1] === 0x7d && buffer[end - 2] === 0x7d ? "count" : "parse";
|
|
564
|
+
}
|
|
565
|
+
/**
|
|
566
|
+
* Calls `onLine` with each line of a file as a byte range of `buffer`, split like readline splits them (at "\n", "\r\n"
|
|
567
|
+
* and a lone "\r"), until it returns false. Lines are not decoded: a listing decodes only the lines it parses. A "\n" or
|
|
568
|
+
* "\r" byte is never part of a multi-byte UTF-8 sequence, so decoding each line on its own gives the text that decoding
|
|
569
|
+
* the whole file and splitting it gives.
|
|
570
|
+
*/
|
|
571
|
+
async function forEachLineOfFile(filePath, signal, onLine) {
|
|
572
|
+
signal?.throwIfAborted();
|
|
573
|
+
const file = await open(filePath, "r");
|
|
574
|
+
try {
|
|
575
|
+
const chunk = Buffer.allocUnsafe(SESSION_READ_BUFFER_SIZE);
|
|
576
|
+
// The start of a line that continues in the next chunk, copied out of the reused chunk buffer.
|
|
577
|
+
let carry = [];
|
|
578
|
+
// The previous chunk ended with "\r": a "\n" that starts this chunk belongs to the same line break.
|
|
579
|
+
let skipLineFeed = false;
|
|
580
|
+
const emit = (buffer, start, end) => {
|
|
581
|
+
if (carry.length === 0)
|
|
582
|
+
return onLine(buffer, start, end);
|
|
583
|
+
const line = Buffer.concat([...carry, buffer.subarray(start, end)]);
|
|
584
|
+
carry = [];
|
|
585
|
+
return onLine(line, 0, line.length);
|
|
586
|
+
};
|
|
587
|
+
while (true) {
|
|
588
|
+
signal?.throwIfAborted();
|
|
589
|
+
const { bytesRead } = await file.read(chunk, 0, chunk.length, null);
|
|
590
|
+
if (bytesRead === 0)
|
|
591
|
+
break;
|
|
592
|
+
const buffer = chunk.subarray(0, bytesRead);
|
|
593
|
+
let pos = 0;
|
|
594
|
+
if (skipLineFeed) {
|
|
595
|
+
skipLineFeed = false;
|
|
596
|
+
if (buffer[0] === 0x0a)
|
|
597
|
+
pos = 1;
|
|
598
|
+
}
|
|
599
|
+
let nextLineFeed = buffer.indexOf(0x0a, pos);
|
|
600
|
+
let nextCarriageReturn = buffer.indexOf(0x0d, pos);
|
|
601
|
+
while (true) {
|
|
602
|
+
if (nextLineFeed !== -1 && nextLineFeed < pos)
|
|
603
|
+
nextLineFeed = buffer.indexOf(0x0a, pos);
|
|
604
|
+
if (nextCarriageReturn !== -1 && nextCarriageReturn < pos) {
|
|
605
|
+
nextCarriageReturn = buffer.indexOf(0x0d, pos);
|
|
606
|
+
}
|
|
607
|
+
const lineEnd = nextCarriageReturn === -1
|
|
608
|
+
? nextLineFeed
|
|
609
|
+
: nextLineFeed === -1
|
|
610
|
+
? nextCarriageReturn
|
|
611
|
+
: Math.min(nextLineFeed, nextCarriageReturn);
|
|
612
|
+
if (lineEnd === -1)
|
|
613
|
+
break;
|
|
614
|
+
if (!emit(buffer, pos, lineEnd))
|
|
615
|
+
return;
|
|
616
|
+
pos = lineEnd + 1;
|
|
617
|
+
if (lineEnd === nextCarriageReturn) {
|
|
618
|
+
if (pos === bytesRead)
|
|
619
|
+
skipLineFeed = true;
|
|
620
|
+
else if (buffer[pos] === 0x0a)
|
|
621
|
+
pos++;
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
if (pos < bytesRead)
|
|
625
|
+
carry.push(Buffer.from(buffer.subarray(pos)));
|
|
626
|
+
}
|
|
627
|
+
if (carry.length > 0) {
|
|
628
|
+
const line = Buffer.concat(carry);
|
|
629
|
+
carry = [];
|
|
630
|
+
onLine(line, 0, line.length);
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
finally {
|
|
634
|
+
await file.close();
|
|
635
|
+
}
|
|
636
|
+
}
|
|
535
637
|
async function buildSessionInfo(filePath, signal, fileStats) {
|
|
536
638
|
try {
|
|
537
639
|
const stats = fileStats ?? (await stat(filePath));
|
|
@@ -541,19 +643,24 @@ async function buildSessionInfo(filePath, signal, fileStats) {
|
|
|
541
643
|
const denialEntries = [];
|
|
542
644
|
let name;
|
|
543
645
|
let lastActivityTime;
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
646
|
+
await forEachLineOfFile(filePath, signal, (buffer, start, end) => {
|
|
647
|
+
if (header) {
|
|
648
|
+
const kind = classifySessionLine(buffer, start, end);
|
|
649
|
+
if (kind === "skip")
|
|
650
|
+
return true;
|
|
651
|
+
if (kind === "count") {
|
|
652
|
+
messageCount++;
|
|
653
|
+
return true;
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
const entry = parseSessionEntryLine(buffer.toString("utf8", start, end));
|
|
550
657
|
if (!entry)
|
|
551
|
-
|
|
658
|
+
return true;
|
|
552
659
|
if (!header) {
|
|
553
660
|
if (entry.type !== "session")
|
|
554
|
-
return
|
|
661
|
+
return false;
|
|
555
662
|
header = entry;
|
|
556
|
-
|
|
663
|
+
return true;
|
|
557
664
|
}
|
|
558
665
|
if ((entry.type === "context_edit" && entry.reason === "control-denied" && entry.replacement === null) ||
|
|
559
666
|
(entry.type === "message" && entry.controlDenied)) {
|
|
@@ -564,7 +671,7 @@ async function buildSessionInfo(filePath, signal, fileStats) {
|
|
|
564
671
|
name = entry.name?.trim() || undefined;
|
|
565
672
|
}
|
|
566
673
|
if (entry.type !== "message")
|
|
567
|
-
|
|
674
|
+
return true;
|
|
568
675
|
messageCount++;
|
|
569
676
|
const activityTime = getMessageActivityTime(entry);
|
|
570
677
|
if (typeof activityTime === "number") {
|
|
@@ -572,23 +679,26 @@ async function buildSessionInfo(filePath, signal, fileStats) {
|
|
|
572
679
|
}
|
|
573
680
|
const message = entry.message;
|
|
574
681
|
if (!isMessageWithContent(message))
|
|
575
|
-
|
|
682
|
+
return true;
|
|
576
683
|
if (message.role !== "user" && message.role !== "assistant")
|
|
577
|
-
|
|
684
|
+
return true;
|
|
578
685
|
const textContent = extractTextContent(message);
|
|
579
686
|
if (!textContent)
|
|
580
|
-
|
|
687
|
+
return true;
|
|
581
688
|
allMessages.push({ id: entry.id, role: message.role, text: textContent });
|
|
582
|
-
|
|
583
|
-
|
|
689
|
+
return true;
|
|
690
|
+
});
|
|
691
|
+
// TypeScript does not see the assignment in the callback.
|
|
692
|
+
const sessionHeader = header;
|
|
693
|
+
if (!sessionHeader)
|
|
584
694
|
return null;
|
|
585
695
|
// Denials can follow their targets on any branch. Filter only after reading the whole session.
|
|
586
696
|
const denied = getControlDeniedEntryIds(denialEntries);
|
|
587
697
|
const visibleMessages = allMessages.filter((message) => !denied.has(message.id));
|
|
588
698
|
const firstMessage = visibleMessages.find((message) => message.role === "user")?.text;
|
|
589
|
-
const cwd = typeof
|
|
590
|
-
const parentSessionPath =
|
|
591
|
-
const headerTime = typeof
|
|
699
|
+
const cwd = typeof sessionHeader.cwd === "string" ? sessionHeader.cwd : "";
|
|
700
|
+
const parentSessionPath = sessionHeader.parentSession;
|
|
701
|
+
const headerTime = typeof sessionHeader.timestamp === "string" ? new Date(sessionHeader.timestamp).getTime() : NaN;
|
|
592
702
|
const modified = typeof lastActivityTime === "number" && lastActivityTime > 0
|
|
593
703
|
? new Date(lastActivityTime)
|
|
594
704
|
: !Number.isNaN(headerTime)
|
|
@@ -596,11 +706,11 @@ async function buildSessionInfo(filePath, signal, fileStats) {
|
|
|
596
706
|
: stats.mtime;
|
|
597
707
|
return {
|
|
598
708
|
path: filePath,
|
|
599
|
-
id:
|
|
709
|
+
id: sessionHeader.id,
|
|
600
710
|
cwd,
|
|
601
711
|
name,
|
|
602
712
|
parentSessionPath,
|
|
603
|
-
created: new Date(
|
|
713
|
+
created: new Date(sessionHeader.timestamp),
|
|
604
714
|
modified,
|
|
605
715
|
messageCount,
|
|
606
716
|
firstMessage: firstMessage || "(no messages)",
|
|
@@ -632,12 +742,15 @@ async function mapWithConcurrency(items, limit, map, signal) {
|
|
|
632
742
|
function sortSessionInfos(sessions) {
|
|
633
743
|
return sessions.sort((a, b) => b.modified.getTime() - a.modified.getTime());
|
|
634
744
|
}
|
|
635
|
-
function buildSessionInfosWithConcurrency(files, onLoaded, signal) {
|
|
636
|
-
|
|
745
|
+
async function buildSessionInfosWithConcurrency(files, onLoaded, signal) {
|
|
746
|
+
const results = await mapWithConcurrency(files, MAX_CONCURRENT_SESSION_INFO_LOADS, async (file, index) => {
|
|
637
747
|
const info = await buildSessionInfo(file.path, signal, file.stats);
|
|
638
748
|
onLoaded(info, index);
|
|
639
749
|
return info;
|
|
640
750
|
}, signal);
|
|
751
|
+
// A listing cancelled while its last reads finished is cancelled all the same.
|
|
752
|
+
signal?.throwIfAborted();
|
|
753
|
+
return results;
|
|
641
754
|
}
|
|
642
755
|
async function listSessionsFromDir(dir, onProgress, signal) {
|
|
643
756
|
signal?.throwIfAborted();
|
|
@@ -666,6 +779,82 @@ async function listSessionsFromDir(dir, onProgress, signal) {
|
|
|
666
779
|
return [];
|
|
667
780
|
}
|
|
668
781
|
}
|
|
782
|
+
/** How long a session file stays open for appends after the last one. */
|
|
783
|
+
const APPEND_FILE_IDLE_MS = 1000;
|
|
784
|
+
/**
|
|
785
|
+
* A session file kept open for appends while they come in quick succession: opening and closing the file for every
|
|
786
|
+
* entry costs far more than a write on an open file, and a turn appends an entry per message and tool result. Each
|
|
787
|
+
* append still writes its whole line with write() before it returns, as appendFileSync did, so a crash loses no more.
|
|
788
|
+
*
|
|
789
|
+
* The file is checked by path before each append (a stat): when the path no longer names the open file (deleted,
|
|
790
|
+
* renamed, or replaced, as an atomic rewrite does), the open file is closed and the path is opened again, so the line
|
|
791
|
+
* goes where appending by path puts it. The file is closed after APPEND_FILE_IDLE_MS without appends, and when the
|
|
792
|
+
* session changes or is flushed.
|
|
793
|
+
*/
|
|
794
|
+
class SessionAppendFile {
|
|
795
|
+
path;
|
|
796
|
+
fd;
|
|
797
|
+
dev;
|
|
798
|
+
ino;
|
|
799
|
+
lastAppend = 0;
|
|
800
|
+
timer;
|
|
801
|
+
closed = false;
|
|
802
|
+
constructor(path) {
|
|
803
|
+
this.path = path;
|
|
804
|
+
this.fd = openSync(path, "a");
|
|
805
|
+
try {
|
|
806
|
+
const stats = fstatSync(this.fd);
|
|
807
|
+
this.dev = stats.dev;
|
|
808
|
+
this.ino = stats.ino;
|
|
809
|
+
}
|
|
810
|
+
catch (error) {
|
|
811
|
+
closeSync(this.fd);
|
|
812
|
+
throw error;
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
/** Whether `path` still names this open file. */
|
|
816
|
+
isFor(path) {
|
|
817
|
+
if (this.closed || path !== this.path)
|
|
818
|
+
return false;
|
|
819
|
+
const stats = statSync(path, { throwIfNoEntry: false });
|
|
820
|
+
return stats !== undefined && stats.ino === this.ino && stats.dev === this.dev;
|
|
821
|
+
}
|
|
822
|
+
append(line) {
|
|
823
|
+
const bytes = Buffer.from(line);
|
|
824
|
+
// A short write (a full disk): write the rest like appendFileSync would.
|
|
825
|
+
for (let offset = 0; offset < bytes.length;) {
|
|
826
|
+
offset += writeSync(this.fd, bytes, offset, bytes.length - offset);
|
|
827
|
+
}
|
|
828
|
+
this.lastAppend = performance.now();
|
|
829
|
+
if (!this.timer)
|
|
830
|
+
this.scheduleClose(APPEND_FILE_IDLE_MS);
|
|
831
|
+
}
|
|
832
|
+
close() {
|
|
833
|
+
if (this.closed)
|
|
834
|
+
return;
|
|
835
|
+
this.closed = true;
|
|
836
|
+
if (this.timer)
|
|
837
|
+
clearTimeout(this.timer);
|
|
838
|
+
this.timer = undefined;
|
|
839
|
+
try {
|
|
840
|
+
closeSync(this.fd);
|
|
841
|
+
}
|
|
842
|
+
catch {
|
|
843
|
+
// Nothing is buffered: every append was written before it returned.
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
scheduleClose(delay) {
|
|
847
|
+
this.timer = setTimeout(() => {
|
|
848
|
+
this.timer = undefined;
|
|
849
|
+
const idle = performance.now() - this.lastAppend;
|
|
850
|
+
if (idle >= APPEND_FILE_IDLE_MS)
|
|
851
|
+
this.close();
|
|
852
|
+
else
|
|
853
|
+
this.scheduleClose(APPEND_FILE_IDLE_MS - idle);
|
|
854
|
+
}, delay);
|
|
855
|
+
this.timer.unref();
|
|
856
|
+
}
|
|
857
|
+
}
|
|
669
858
|
/**
|
|
670
859
|
* Manages conversation sessions as append-only trees stored in JSONL files.
|
|
671
860
|
*
|
|
@@ -694,6 +883,8 @@ export class SessionManager {
|
|
|
694
883
|
projection;
|
|
695
884
|
projectionRevision = 0;
|
|
696
885
|
latestSessionInfo;
|
|
886
|
+
/** The session file, kept open between appends that come in quick succession. Not used on Windows. */
|
|
887
|
+
appendFile;
|
|
697
888
|
constructor(cwd, sessionDir, sessionFile, persist, newSessionOptions, preloadedFileEntries) {
|
|
698
889
|
this.cwd = resolvePath(cwd);
|
|
699
890
|
this.sessionDir = normalizePath(sessionDir);
|
|
@@ -716,6 +907,7 @@ export class SessionManager {
|
|
|
716
907
|
this._setSessionFile(sessionFile);
|
|
717
908
|
}
|
|
718
909
|
_setSessionFile(sessionFile, preloadedFileEntries) {
|
|
910
|
+
this._closeAppendFile();
|
|
719
911
|
this.sessionFile = resolvePath(sessionFile);
|
|
720
912
|
if (existsSync(this.sessionFile)) {
|
|
721
913
|
const entries = preloadedFileEntries ?? loadEntriesFromFile(this.sessionFile);
|
|
@@ -755,6 +947,7 @@ export class SessionManager {
|
|
|
755
947
|
cwd: this.cwd,
|
|
756
948
|
parentSession: options?.parentSession,
|
|
757
949
|
};
|
|
950
|
+
this._closeAppendFile();
|
|
758
951
|
this.fileEntries = [header];
|
|
759
952
|
this.leafPath = undefined;
|
|
760
953
|
this.projection = undefined;
|
|
@@ -868,9 +1061,31 @@ export class SessionManager {
|
|
|
868
1061
|
this._flushAll();
|
|
869
1062
|
}
|
|
870
1063
|
else {
|
|
871
|
-
|
|
1064
|
+
this._appendLine(this.sessionFile, `${JSON.stringify(entry)}\n`);
|
|
872
1065
|
}
|
|
873
1066
|
}
|
|
1067
|
+
_appendLine(path, line) {
|
|
1068
|
+
// An open file can keep others from deleting or renaming it on Windows.
|
|
1069
|
+
if (process.platform === "win32") {
|
|
1070
|
+
appendFileSync(path, line);
|
|
1071
|
+
return;
|
|
1072
|
+
}
|
|
1073
|
+
if (!this.appendFile?.isFor(path)) {
|
|
1074
|
+
this._closeAppendFile();
|
|
1075
|
+
this.appendFile = new SessionAppendFile(path);
|
|
1076
|
+
}
|
|
1077
|
+
try {
|
|
1078
|
+
this.appendFile.append(line);
|
|
1079
|
+
}
|
|
1080
|
+
catch (error) {
|
|
1081
|
+
this._closeAppendFile();
|
|
1082
|
+
throw error;
|
|
1083
|
+
}
|
|
1084
|
+
}
|
|
1085
|
+
_closeAppendFile() {
|
|
1086
|
+
this.appendFile?.close();
|
|
1087
|
+
this.appendFile = undefined;
|
|
1088
|
+
}
|
|
874
1089
|
_flushAll() {
|
|
875
1090
|
if (!this.persist || !this.sessionFile)
|
|
876
1091
|
return;
|
|
@@ -888,6 +1103,7 @@ export class SessionManager {
|
|
|
888
1103
|
/** Force buffered entries to disk. Used on dispose/eviction so orderly
|
|
889
1104
|
* teardown never drops a session that has content but no message yet. */
|
|
890
1105
|
flush() {
|
|
1106
|
+
this._closeAppendFile();
|
|
891
1107
|
if (!this.persist || !this.sessionFile || this.flushed)
|
|
892
1108
|
return;
|
|
893
1109
|
if (!this.fileEntries.some((e) => e.type !== "session"))
|