@humain/humain-code 0.5.4 → 0.6.1
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 +170 -0
- package/dist/bundle/agent-monitor.js +1 -1
- package/dist/bundle/chunks/anthropic-messages-FGFIMZUF.js +66 -0
- package/dist/bundle/chunks/azure-openai-responses-6JNTC7KO.js +15 -0
- package/dist/bundle/chunks/bedrock-converse-stream.js +261 -237
- package/dist/bundle/chunks/chunk-2H3LUS62.js +1966 -0
- package/dist/bundle/chunks/{chunk-GEISZXXH.js → chunk-4ZBGTJJM.js} +1 -1
- package/dist/bundle/chunks/{chunk-QWXPGBAG.js → chunk-5JSLXC2A.js} +1 -1
- package/dist/bundle/chunks/{chunk-L2VKM23Q.js → chunk-6DE7LJKV.js} +21 -21
- package/dist/bundle/chunks/{chunk-V62QBESW.js → chunk-6E6RHNOU.js} +11 -10
- package/dist/bundle/chunks/chunk-7RZ5BS7U.js +2 -0
- package/dist/bundle/chunks/chunk-AHSNQWZU.js +24 -0
- package/dist/bundle/chunks/{chunk-UJLCKIMZ.js → chunk-AOH2O5CP.js} +3469 -3133
- package/dist/bundle/chunks/{chunk-ODJUBJK2.js → chunk-B7NJMF7B.js} +11 -11
- package/dist/bundle/chunks/chunk-BQ3TMEWD.js +7 -0
- package/dist/bundle/chunks/{chunk-KKCMWB63.js → chunk-C6VERWRZ.js} +1 -1
- package/dist/bundle/chunks/{chunk-CN3Q5UNB.js → chunk-CFHOPLW5.js} +658 -574
- package/dist/bundle/chunks/chunk-CVC2GV26.js +1986 -0
- package/dist/bundle/chunks/{chunk-DU6POZ7E.js → chunk-DHW3REC5.js} +1 -1
- package/dist/bundle/chunks/{chunk-UTNHGOFS.js → chunk-EDONIPUJ.js} +38 -38
- package/dist/bundle/chunks/{chunk-FO2NYB6O.js → chunk-FDGW5ZTG.js} +1147 -1110
- package/dist/bundle/chunks/{chunk-XQX7S3GM.js → chunk-GICL5V54.js} +1 -1
- package/dist/bundle/chunks/chunk-H7Y4QY7K.js +11 -0
- package/dist/bundle/chunks/chunk-HW6HMUXS.js +188 -0
- package/dist/bundle/chunks/chunk-I6AQOITY.js +53 -0
- package/dist/bundle/chunks/{chunk-ZI7TK7HM.js → chunk-IADQJFNH.js} +21 -17
- package/dist/bundle/chunks/chunk-J7AP2BUJ.js +3 -0
- package/dist/bundle/chunks/chunk-JFE52VSN.js +120 -0
- package/dist/bundle/chunks/{chunk-MIJHJNNQ.js → chunk-LDGCU6PD.js} +127 -3
- package/dist/bundle/chunks/{chunk-PS7DGA7B.js → chunk-M4CHQBAI.js} +1 -1
- package/dist/bundle/chunks/{chunk-YDBNMIA3.js → chunk-NN53K2QQ.js} +19 -1
- package/dist/bundle/chunks/{chunk-RTXDU3AA.js → chunk-ONR6Q3II.js} +255 -195
- package/dist/bundle/chunks/{chunk-Y3OPKKDR.js → chunk-P4P7OZ7R.js} +34 -32
- package/dist/bundle/chunks/{chunk-OZNC2W4B.js → chunk-PCTLFSQG.js} +444 -411
- package/dist/bundle/chunks/{chunk-YFBDR4IW.js → chunk-PNGNZXOI.js} +3 -3
- package/dist/bundle/chunks/{chunk-UDB6NI4G.js → chunk-RGUZULEE.js} +593 -481
- package/dist/bundle/chunks/chunk-RO5YPAJH.js +23 -0
- package/dist/bundle/chunks/{chunk-A6B2QMA7.js → chunk-RU7ADKA7.js} +176 -162
- package/dist/bundle/chunks/{chunk-JCXXRCP6.js → chunk-T3KDZFM4.js} +16 -16
- package/dist/bundle/chunks/{chunk-HT5YN3LX.js → chunk-TEOMXMW6.js} +3 -3
- package/dist/bundle/chunks/{chunk-HIZWUSPN.js → chunk-VEGJT52D.js} +77 -77
- package/dist/bundle/chunks/{chunk-IDU5BNNI.js → chunk-XMZGB3H4.js} +12 -3
- package/dist/bundle/chunks/chunk-YEPHPMQC.js +647 -0
- package/dist/bundle/chunks/{chunk-XA7CJAYH.js → chunk-YRUIJ5AH.js} +48 -42
- package/dist/bundle/chunks/{cli-ENEFJH2B.js → cli-BNCWK54K.js} +21 -17
- package/dist/bundle/chunks/{cloudflare-workers-ai-system-one-T7TPP7SQ.js → cloudflare-workers-ai-system-one-KI6W3USX.js} +1 -1
- package/dist/bundle/chunks/codemode-worker.js +81 -75
- package/dist/bundle/chunks/compat-I5VPOXFT.js +13 -0
- package/dist/bundle/chunks/dist-J5IUPLMH.js +37 -0
- package/dist/bundle/chunks/{dist-RKNCFFGM.js → dist-SKBR3C7C.js} +720 -696
- package/dist/bundle/chunks/dist-TVRQXUY6.js +8 -0
- package/dist/bundle/chunks/{dist-cjs-HTASUQXQ.js → dist-cjs-2SKN226B.js} +77 -77
- package/dist/bundle/chunks/{easter-egg-3d-YOPLCOVW.js → easter-egg-3d-673VRP6Y.js} +1 -1
- package/dist/bundle/chunks/{esm-R6HJ4QEG.js → esm-WPALMLUO.js} +3 -3
- package/dist/bundle/chunks/{event-streams-BR2IL6C5.js → event-streams-7YGFEPBZ.js} +1 -1
- package/dist/bundle/chunks/{execute-2JXEKQ2X.js → execute-PIUR5MUV.js} +23 -23
- package/dist/bundle/chunks/{extract-OTCGZGTL.js → extract-4O5Z5725.js} +74 -71
- package/dist/bundle/chunks/github-copilot.js +50 -51
- package/dist/bundle/chunks/google-generative-ai-635YZEHN.js +22 -0
- package/dist/bundle/chunks/google-vertex-I3ZJ3SB2.js +26 -0
- package/dist/bundle/chunks/host-OQOEIWHK.js +2 -0
- package/dist/bundle/chunks/image-resize-worker.js +3 -2
- package/dist/bundle/chunks/kimi-coding.js +13 -14
- package/dist/bundle/chunks/{llama-cpp-classify-B3G57LVR.js → llama-cpp-classify-PP63BYDF.js} +1 -1
- package/dist/bundle/chunks/meta.js +10 -10
- package/dist/bundle/chunks/mistral-conversations-OKG5GKXR.js +42 -0
- package/dist/bundle/chunks/{node-VSA4ZN7D.js → node-UGQUSQE6.js} +1 -1
- package/dist/bundle/chunks/{node-SJPZTR4K.js → node-UNHECG4X.js} +168 -157
- package/dist/bundle/chunks/openai-codex-responses-6JYZIFT4.js +100 -0
- package/dist/bundle/chunks/openai-completions-YBNI6CAP.js +82 -0
- package/dist/bundle/chunks/{openai-decisions-WOWUC65P.js → openai-decisions-5G5YBFRQ.js} +1 -1
- package/dist/bundle/chunks/openai-responses-C3APJ6MK.js +27 -0
- package/dist/bundle/chunks/{openrouter-images-5K47HDAT.js → openrouter-images-FCJT7C7I.js} +2 -2
- package/dist/bundle/chunks/{pdfjs-EK6K7CXX.js → pdfjs-AKD6EBKN.js} +196 -175
- package/dist/bundle/chunks/pdfjs-decoders-OFXX4HDZ.js +2 -0
- package/dist/bundle/chunks/pdfjs-jbig2-TXR26KRI.js +278 -0
- package/dist/bundle/chunks/pdfjs-jbig2_nowasm_fallback-FH3KJM4H.js +326 -0
- package/dist/bundle/chunks/pdfjs-openjpeg-SKR7C34X.js +671 -0
- package/dist/bundle/chunks/pdfjs-openjpeg_nowasm_fallback-VUBL7UEE.js +974 -0
- package/dist/bundle/chunks/pi-messages-UHYZYEOC.js +25 -0
- package/dist/bundle/chunks/radius.js +8 -8
- package/dist/bundle/chunks/{runtime-K3F2QDQP.js → runtime-KE3HDSRT.js} +1 -1
- package/dist/bundle/chunks/{turndown.cjs-U7XOXH4O.js → turndown.cjs-WKGZX7NZ.js} +1 -1
- package/dist/bundle/chunks/{typesafe-system-one-43OCHGKP.js → typesafe-system-one-VYVAMWQV.js} +1 -1
- package/dist/bundle/chunks/{undici-EK3EUI2E.js → undici-C6S56CGI.js} +1 -1
- package/dist/bundle/chunks/virtual-modules-KDUZIB3W.js +23 -0
- package/dist/bundle/cli-runtime.js +3 -3
- package/dist/bundle/flow/package.json +5 -5
- package/dist/bundle/index.js +10 -10
- package/dist/bundle/rpc-entry.js +3 -3
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +9 -8
- package/dist/cli/args.js.map +1 -1
- package/dist/config.d.ts +12 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +29 -5
- package/dist/config.js.map +1 -1
- package/dist/coordination/adapter/tool.d.ts +8 -5
- package/dist/coordination/adapter/tool.d.ts.map +1 -1
- package/dist/coordination/adapter/tool.js +32 -6
- package/dist/coordination/adapter/tool.js.map +1 -1
- package/dist/coordination/client/client.d.ts.map +1 -1
- package/dist/coordination/client/client.js +19 -1
- package/dist/coordination/client/client.js.map +1 -1
- package/dist/core/agent-session-runtime.js +3 -3
- package/dist/core/agent-session-runtime.js.map +1 -1
- package/dist/core/agent-session.d.ts +23 -3
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +142 -39
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/anthropic-subscription-usage.d.ts +4 -0
- package/dist/core/anthropic-subscription-usage.d.ts.map +1 -1
- package/dist/core/anthropic-subscription-usage.js +71 -1
- package/dist/core/anthropic-subscription-usage.js.map +1 -1
- package/dist/core/bug-report.d.ts +4 -4
- package/dist/core/codex-reset.d.ts +45 -0
- package/dist/core/codex-reset.d.ts.map +1 -0
- package/dist/core/codex-reset.js +190 -0
- package/dist/core/codex-reset.js.map +1 -0
- package/dist/core/codex-usage.d.ts +4 -2
- package/dist/core/codex-usage.d.ts.map +1 -1
- package/dist/core/codex-usage.js +9 -4
- package/dist/core/codex-usage.js.map +1 -1
- package/dist/core/compaction/branch-summarization.d.ts +3 -1
- package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
- package/dist/core/compaction/branch-summarization.js +25 -10
- package/dist/core/compaction/branch-summarization.js.map +1 -1
- package/dist/core/compaction/compaction.d.ts +37 -3
- package/dist/core/compaction/compaction.d.ts.map +1 -1
- package/dist/core/compaction/compaction.js +274 -65
- package/dist/core/compaction/compaction.js.map +1 -1
- package/dist/core/compaction/utils.d.ts +19 -6
- package/dist/core/compaction/utils.d.ts.map +1 -1
- package/dist/core/compaction/utils.js +49 -11
- package/dist/core/compaction/utils.js.map +1 -1
- package/dist/core/exec.d.ts +9 -1
- package/dist/core/exec.d.ts.map +1 -1
- package/dist/core/exec.js +105 -61
- package/dist/core/exec.js.map +1 -1
- package/dist/core/export-html/template.css +9 -0
- package/dist/core/export-html/template.html +2 -0
- package/dist/core/export-html/template.js +200 -62
- package/dist/core/export-html/tool-renderer.d.ts.map +1 -1
- package/dist/core/export-html/tool-renderer.js +3 -0
- package/dist/core/export-html/tool-renderer.js.map +1 -1
- package/dist/core/extensions/index.d.ts +1 -1
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +7 -6
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/pi-ai-extension-view.d.ts +19 -0
- package/dist/core/extensions/pi-ai-extension-view.d.ts.map +1 -0
- package/dist/core/extensions/pi-ai-extension-view.js +22 -0
- package/dist/core/extensions/pi-ai-extension-view.js.map +1 -0
- package/dist/core/extensions/types.d.ts +27 -4
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/extensions/virtual-modules.d.ts.map +1 -1
- package/dist/core/extensions/virtual-modules.js +8 -7
- package/dist/core/extensions/virtual-modules.js.map +1 -1
- package/dist/core/http-dispatcher.d.ts +7 -0
- package/dist/core/http-dispatcher.d.ts.map +1 -1
- package/dist/core/http-dispatcher.js +107 -0
- package/dist/core/http-dispatcher.js.map +1 -1
- package/dist/core/keybindings.d.ts +56 -0
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js +14 -2
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/mcp-servers.d.ts +9 -4
- package/dist/core/mcp-servers.d.ts.map +1 -1
- package/dist/core/mcp-servers.js +15 -5
- package/dist/core/mcp-servers.js.map +1 -1
- package/dist/core/model-config.d.ts +1691 -2042
- package/dist/core/model-config.d.ts.map +1 -1
- package/dist/core/model-config.js +2 -3
- package/dist/core/model-config.js.map +1 -1
- package/dist/core/model-registry.d.ts +35 -4
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +70 -8
- 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 +16 -10
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/model-runtime.d.ts.map +1 -1
- package/dist/core/model-runtime.js +21 -17
- package/dist/core/model-runtime.js.map +1 -1
- package/dist/core/package-manager.d.ts +29 -0
- package/dist/core/package-manager.d.ts.map +1 -1
- package/dist/core/package-manager.js +311 -60
- package/dist/core/package-manager.js.map +1 -1
- package/dist/core/pi-ai-schemas.d.ts +164 -0
- package/dist/core/pi-ai-schemas.d.ts.map +1 -0
- package/dist/core/pi-ai-schemas.js +21 -0
- package/dist/core/pi-ai-schemas.js.map +1 -0
- package/dist/core/pi-manifest.d.ts +1 -0
- package/dist/core/pi-manifest.d.ts.map +1 -1
- package/dist/core/pi-manifest.js +4 -0
- package/dist/core/pi-manifest.js.map +1 -1
- package/dist/core/project-trust.js +1 -1
- package/dist/core/project-trust.js.map +1 -1
- package/dist/core/resource-loader.d.ts +4 -1
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +38 -23
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +4 -1
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-manager.d.ts +7 -0
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +66 -26
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/settings-defaults.d.ts +2 -0
- package/dist/core/settings-defaults.d.ts.map +1 -1
- package/dist/core/settings-defaults.js +2 -0
- package/dist/core/settings-defaults.js.map +1 -1
- package/dist/core/settings-manager.d.ts +19 -8
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +70 -16
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/settings-schema.d.ts +15 -2
- package/dist/core/settings-schema.d.ts.map +1 -1
- package/dist/core/settings-schema.js +37 -3
- package/dist/core/settings-schema.js.map +1 -1
- package/dist/core/skills.d.ts.map +1 -1
- package/dist/core/skills.js +6 -14
- package/dist/core/skills.js.map +1 -1
- package/dist/core/slash-commands.js +2 -2
- package/dist/core/slash-commands.js.map +1 -1
- package/dist/core/source-info.d.ts +9 -0
- package/dist/core/source-info.d.ts.map +1 -1
- package/dist/core/source-info.js +13 -0
- package/dist/core/source-info.js.map +1 -1
- package/dist/core/subscription-credits.d.ts +14 -0
- package/dist/core/subscription-credits.d.ts.map +1 -0
- package/dist/core/subscription-credits.js +10 -0
- package/dist/core/subscription-credits.js.map +1 -0
- package/dist/core/subscription-reset-status.d.ts +10 -0
- package/dist/core/subscription-reset-status.d.ts.map +1 -0
- package/dist/core/subscription-reset-status.js +2 -0
- package/dist/core/subscription-reset-status.js.map +1 -0
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +5 -6
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/tools/bash.d.ts +2 -2
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/edit.d.ts +3 -3
- package/dist/core/tools/edit.d.ts.map +1 -1
- package/dist/core/tools/edit.js +2 -4
- package/dist/core/tools/edit.js.map +1 -1
- package/dist/core/tools/find.d.ts +2 -2
- package/dist/core/tools/find.d.ts.map +1 -1
- package/dist/core/tools/find.js.map +1 -1
- package/dist/core/tools/grep.d.ts +2 -2
- package/dist/core/tools/grep.d.ts.map +1 -1
- package/dist/core/tools/grep.js +7 -3
- package/dist/core/tools/grep.js.map +1 -1
- package/dist/core/tools/ls.d.ts +2 -2
- package/dist/core/tools/ls.d.ts.map +1 -1
- package/dist/core/tools/ls.js.map +1 -1
- package/dist/core/tools/read.d.ts +2 -2
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js.map +1 -1
- package/dist/core/tools/render-utils.d.ts +4 -0
- package/dist/core/tools/render-utils.d.ts.map +1 -1
- package/dist/core/tools/render-utils.js +42 -12
- package/dist/core/tools/render-utils.js.map +1 -1
- package/dist/core/tools/renderers/edit.d.ts.map +1 -1
- package/dist/core/tools/renderers/edit.js +3 -3
- package/dist/core/tools/renderers/edit.js.map +1 -1
- package/dist/core/tools/renderers/write.d.ts.map +1 -1
- package/dist/core/tools/renderers/write.js +37 -29
- package/dist/core/tools/renderers/write.js.map +1 -1
- package/dist/core/tools/subagent.d.ts +9 -8
- package/dist/core/tools/subagent.d.ts.map +1 -1
- package/dist/core/tools/subagent.js +8 -5
- package/dist/core/tools/subagent.js.map +1 -1
- package/dist/core/tools/tool-definition-wrapper.d.ts +11 -1
- package/dist/core/tools/tool-definition-wrapper.d.ts.map +1 -1
- package/dist/core/tools/tool-definition-wrapper.js.map +1 -1
- package/dist/core/tools/write.d.ts +2 -2
- package/dist/core/tools/write.d.ts.map +1 -1
- package/dist/core/tools/write.js.map +1 -1
- package/dist/core/trust-manager.d.ts.map +1 -1
- package/dist/core/trust-manager.js +14 -8
- package/dist/core/trust-manager.js.map +1 -1
- package/dist/core/usage-totals.d.ts.map +1 -1
- package/dist/core/usage-totals.js +2 -0
- package/dist/core/usage-totals.js.map +1 -1
- package/dist/extensions/codemode/renderer.d.ts.map +1 -1
- package/dist/extensions/codemode/renderer.js +17 -9
- package/dist/extensions/codemode/renderer.js.map +1 -1
- package/dist/extensions/codemode/tool.d.ts +2 -1
- package/dist/extensions/codemode/tool.d.ts.map +1 -1
- package/dist/extensions/codemode/tool.js +33 -8
- package/dist/extensions/codemode/tool.js.map +1 -1
- package/dist/extensions/llama/ui.d.ts.map +1 -1
- package/dist/extensions/llama/ui.js +16 -4
- package/dist/extensions/llama/ui.js.map +1 -1
- package/dist/extensions/mcp/cli.d.ts.map +1 -1
- package/dist/extensions/mcp/cli.js +34 -8
- package/dist/extensions/mcp/cli.js.map +1 -1
- package/dist/extensions/mcp/index.js +4 -3
- package/dist/extensions/mcp/index.js.map +1 -1
- package/dist/extensions/mcp/oauth.d.ts +1 -1
- package/dist/extensions/mcp/oauth.d.ts.map +1 -1
- package/dist/extensions/mcp/oauth.js +7 -3
- package/dist/extensions/mcp/oauth.js.map +1 -1
- package/dist/extensions/mcp/ui.d.ts +1 -0
- package/dist/extensions/mcp/ui.d.ts.map +1 -1
- package/dist/extensions/mcp/ui.js +56 -28
- package/dist/extensions/mcp/ui.js.map +1 -1
- package/dist/extensions/tool-search/tool.d.ts +21 -6
- package/dist/extensions/tool-search/tool.d.ts.map +1 -1
- package/dist/extensions/tool-search/tool.js +104 -36
- package/dist/extensions/tool-search/tool.js.map +1 -1
- package/dist/extensions/usage/confirmation.d.ts +40 -0
- package/dist/extensions/usage/confirmation.d.ts.map +1 -0
- package/dist/extensions/usage/confirmation.js +198 -0
- package/dist/extensions/usage/confirmation.js.map +1 -0
- package/dist/extensions/usage/index.d.ts +4 -4
- package/dist/extensions/usage/index.d.ts.map +1 -1
- package/dist/extensions/usage/index.js +352 -33
- package/dist/extensions/usage/index.js.map +1 -1
- package/dist/extensions/usage/overview.d.ts +8 -1
- package/dist/extensions/usage/overview.d.ts.map +1 -1
- package/dist/extensions/usage/overview.js +54 -11
- package/dist/extensions/usage/overview.js.map +1 -1
- package/dist/extensions/usage/popup.d.ts +37 -6
- package/dist/extensions/usage/popup.d.ts.map +1 -1
- package/dist/extensions/usage/popup.js +396 -45
- package/dist/extensions/usage/popup.js.map +1 -1
- package/dist/humain/bedrock-provider/vendor/index.bundle.mjs +564 -130
- package/dist/humain/node-provider.d.ts.map +1 -1
- package/dist/humain/node-provider.js +1 -0
- package/dist/humain/node-provider.js.map +1 -1
- package/dist/humain/web-access/host.d.ts +2 -1
- package/dist/humain/web-access/host.d.ts.map +1 -1
- package/dist/humain/web-access/host.js +1 -1
- package/dist/humain/web-access/host.js.map +1 -1
- package/dist/humain/web-access/vendor/brave-rate-limit.d.ts +2 -0
- package/dist/humain/web-access/vendor/brave-rate-limit.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/brave-rate-limit.js +2 -2
- package/dist/humain/web-access/vendor/brave-rate-limit.js.map +1 -1
- package/dist/humain/web-access/vendor/cloudflare-search.d.ts +5 -0
- package/dist/humain/web-access/vendor/cloudflare-search.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/cloudflare-search.js +230 -0
- package/dist/humain/web-access/vendor/cloudflare-search.js.map +1 -0
- package/dist/humain/web-access/vendor/curator-page.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/curator-page.js +18 -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 +12 -0
- package/dist/humain/web-access/vendor/curator-server.js.map +1 -1
- package/dist/humain/web-access/vendor/duckduckgo-rate-limit.d.ts +33 -0
- package/dist/humain/web-access/vendor/duckduckgo-rate-limit.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/duckduckgo-rate-limit.js +84 -0
- package/dist/humain/web-access/vendor/duckduckgo-rate-limit.js.map +1 -0
- package/dist/humain/web-access/vendor/duckduckgo.d.ts +3 -0
- package/dist/humain/web-access/vendor/duckduckgo.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/duckduckgo.js +54 -49
- package/dist/humain/web-access/vendor/duckduckgo.js.map +1 -1
- package/dist/humain/web-access/vendor/exa.d.ts +8 -3
- package/dist/humain/web-access/vendor/exa.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/exa.js +129 -14
- package/dist/humain/web-access/vendor/exa.js.map +1 -1
- package/dist/humain/web-access/vendor/extract.d.ts +1 -1
- package/dist/humain/web-access/vendor/extract.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/extract.js +68 -10
- package/dist/humain/web-access/vendor/extract.js.map +1 -1
- package/dist/humain/web-access/vendor/fetch-params.d.ts +2 -1
- package/dist/humain/web-access/vendor/fetch-params.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/fetch-params.js +2 -2
- package/dist/humain/web-access/vendor/fetch-params.js.map +1 -1
- package/dist/humain/web-access/vendor/field-extract.d.ts +38 -0
- package/dist/humain/web-access/vendor/field-extract.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/field-extract.js +350 -0
- package/dist/humain/web-access/vendor/field-extract.js.map +1 -0
- package/dist/humain/web-access/vendor/gemini-search.d.ts +15 -4
- package/dist/humain/web-access/vendor/gemini-search.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/gemini-search.js +198 -16
- package/dist/humain/web-access/vendor/gemini-search.js.map +1 -1
- package/dist/humain/web-access/vendor/github-api.js +1 -1
- package/dist/humain/web-access/vendor/github-api.js.map +1 -1
- package/dist/humain/web-access/vendor/github-extract.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/github-extract.js +3 -2
- package/dist/humain/web-access/vendor/github-extract.js.map +1 -1
- package/dist/humain/web-access/vendor/index.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/index.js +137 -118
- package/dist/humain/web-access/vendor/index.js.map +1 -1
- package/dist/humain/web-access/vendor/mistral-search.js +1 -1
- package/dist/humain/web-access/vendor/mistral-search.js.map +1 -1
- package/dist/humain/web-access/vendor/ninerouter.d.ts +4 -0
- package/dist/humain/web-access/vendor/ninerouter.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/ninerouter.js +110 -0
- package/dist/humain/web-access/vendor/ninerouter.js.map +1 -0
- package/dist/humain/web-access/vendor/offtopic-judge.d.ts +27 -0
- package/dist/humain/web-access/vendor/offtopic-judge.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/offtopic-judge.js +61 -0
- package/dist/humain/web-access/vendor/offtopic-judge.js.map +1 -0
- package/dist/humain/web-access/vendor/openai-search.d.ts +1 -1
- package/dist/humain/web-access/vendor/openai-search.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/openai-search.js +39 -13
- package/dist/humain/web-access/vendor/openai-search.js.map +1 -1
- package/dist/humain/web-access/vendor/outcrawl.d.ts +4 -0
- package/dist/humain/web-access/vendor/outcrawl.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/outcrawl.js +196 -0
- package/dist/humain/web-access/vendor/outcrawl.js.map +1 -0
- package/dist/humain/web-access/vendor/page-query.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/page-query.js +13 -3
- package/dist/humain/web-access/vendor/page-query.js.map +1 -1
- package/dist/humain/web-access/vendor/pdf-extract.d.ts +1 -3
- package/dist/humain/web-access/vendor/pdf-extract.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/pdf-extract.js +0 -2
- package/dist/humain/web-access/vendor/pdf-extract.js.map +1 -1
- package/dist/humain/web-access/vendor/perplexity.d.ts +3 -0
- package/dist/humain/web-access/vendor/perplexity.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/perplexity.js.map +1 -1
- package/dist/humain/web-access/vendor/query-rewrite.d.ts +2 -2
- package/dist/humain/web-access/vendor/query-rewrite.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/query-rewrite.js +39 -13
- package/dist/humain/web-access/vendor/query-rewrite.js.map +1 -1
- package/dist/humain/web-access/vendor/searchapi.d.ts +4 -0
- package/dist/humain/web-access/vendor/searchapi.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/searchapi.js +195 -0
- package/dist/humain/web-access/vendor/searchapi.js.map +1 -0
- package/dist/humain/web-access/vendor/sofya.d.ts +4 -0
- package/dist/humain/web-access/vendor/sofya.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/sofya.js +193 -0
- package/dist/humain/web-access/vendor/sofya.js.map +1 -0
- package/dist/humain/web-access/vendor/source-check.d.ts +5 -1
- package/dist/humain/web-access/vendor/source-check.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/source-check.js +34 -16
- package/dist/humain/web-access/vendor/source-check.js.map +1 -1
- package/dist/humain/web-access/vendor/ssrf-protection.d.ts +7 -0
- package/dist/humain/web-access/vendor/ssrf-protection.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/ssrf-protection.js +24 -1
- package/dist/humain/web-access/vendor/ssrf-protection.js.map +1 -1
- package/dist/humain/web-access/vendor/summary-model-scope.d.ts +8 -3
- package/dist/humain/web-access/vendor/summary-model-scope.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/summary-model-scope.js +15 -1
- package/dist/humain/web-access/vendor/summary-model-scope.js.map +1 -1
- package/dist/humain/web-access/vendor/summary-review.d.ts +7 -2
- package/dist/humain/web-access/vendor/summary-review.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/summary-review.js +32 -28
- package/dist/humain/web-access/vendor/summary-review.js.map +1 -1
- package/dist/humain/web-access/vendor/tabstack.d.ts +6 -0
- package/dist/humain/web-access/vendor/tabstack.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/tabstack.js +236 -0
- package/dist/humain/web-access/vendor/tabstack.js.map +1 -0
- package/dist/humain/web-access/vendor/tool-arguments.js +1 -1
- package/dist/humain/web-access/vendor/tool-arguments.js.map +1 -1
- package/dist/humain/web-access/vendor/upgrade-notice.d.ts +8 -0
- package/dist/humain/web-access/vendor/upgrade-notice.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/upgrade-notice.js +46 -0
- package/dist/humain/web-access/vendor/upgrade-notice.js.map +1 -0
- package/dist/humain/web-access/vendor/utils.d.ts +9 -0
- package/dist/humain/web-access/vendor/utils.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/utils.js +113 -27
- package/dist/humain/web-access/vendor/utils.js.map +1 -1
- package/dist/humain/web-access/vendor/web-tool-contract.d.ts +4 -0
- package/dist/humain/web-access/vendor/web-tool-contract.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/web-tool-contract.js.map +1 -1
- package/dist/humain/web-access/vendor/web-tool-core.d.ts +17 -1
- package/dist/humain/web-access/vendor/web-tool-core.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/web-tool-core.js +99 -22
- package/dist/humain/web-access/vendor/web-tool-core.js.map +1 -1
- package/dist/humain/web-access/vendor/xai-search.d.ts +1 -1
- package/dist/humain/web-access/vendor/xai-search.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/xai-search.js +6 -5
- package/dist/humain/web-access/vendor/xai-search.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +20 -9
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/assistant-code-block.d.ts +34 -0
- package/dist/modes/interactive/components/assistant-code-block.d.ts.map +1 -0
- package/dist/modes/interactive/components/assistant-code-block.js +160 -0
- package/dist/modes/interactive/components/assistant-code-block.js.map +1 -0
- package/dist/modes/interactive/components/assistant-message.d.ts +31 -10
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/assistant-message.js +276 -73
- package/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/dist/modes/interactive/components/compaction-summary-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/compaction-summary-message.js +2 -1
- package/dist/modes/interactive/components/compaction-summary-message.js.map +1 -1
- package/dist/modes/interactive/components/config-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/config-selector.js +4 -17
- package/dist/modes/interactive/components/config-selector.js.map +1 -1
- package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
- package/dist/modes/interactive/components/custom-editor.js +7 -0
- package/dist/modes/interactive/components/custom-editor.js.map +1 -1
- package/dist/modes/interactive/components/custom-entry.d.ts.map +1 -1
- package/dist/modes/interactive/components/custom-entry.js +2 -1
- package/dist/modes/interactive/components/custom-entry.js.map +1 -1
- package/dist/modes/interactive/components/custom-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/custom-message.js +2 -1
- package/dist/modes/interactive/components/custom-message.js.map +1 -1
- package/dist/modes/interactive/components/diff.d.ts.map +1 -1
- package/dist/modes/interactive/components/diff.js +3 -1
- package/dist/modes/interactive/components/diff.js.map +1 -1
- package/dist/modes/interactive/components/extension-editor.d.ts +2 -0
- package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -1
- package/dist/modes/interactive/components/extension-editor.js +4 -0
- package/dist/modes/interactive/components/extension-editor.js.map +1 -1
- package/dist/modes/interactive/components/footer.d.ts +4 -1
- package/dist/modes/interactive/components/footer.d.ts.map +1 -1
- package/dist/modes/interactive/components/footer.js +6 -5
- package/dist/modes/interactive/components/footer.js.map +1 -1
- package/dist/modes/interactive/components/login-dialog.d.ts +5 -0
- package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
- package/dist/modes/interactive/components/login-dialog.js +107 -11
- package/dist/modes/interactive/components/login-dialog.js.map +1 -1
- package/dist/modes/interactive/components/markdown-transform.d.ts +2 -1
- package/dist/modes/interactive/components/markdown-transform.d.ts.map +1 -1
- package/dist/modes/interactive/components/markdown-transform.js +3 -2
- package/dist/modes/interactive/components/markdown-transform.js.map +1 -1
- package/dist/modes/interactive/components/mermaid.d.ts.map +1 -1
- package/dist/modes/interactive/components/mermaid.js +18 -6
- package/dist/modes/interactive/components/mermaid.js.map +1 -1
- package/dist/modes/interactive/components/model-selector.d.ts +1 -0
- package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/model-selector.js +17 -6
- package/dist/modes/interactive/components/model-selector.js.map +1 -1
- package/dist/modes/interactive/components/oauth-selector.d.ts +1 -0
- package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/oauth-selector.js +13 -4
- package/dist/modes/interactive/components/oauth-selector.js.map +1 -1
- package/dist/modes/interactive/components/scoped-models-selector.d.ts +1 -0
- package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/scoped-models-selector.js +14 -3
- package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
- package/dist/modes/interactive/components/session-selector-search.d.ts +4 -0
- package/dist/modes/interactive/components/session-selector-search.d.ts.map +1 -1
- package/dist/modes/interactive/components/session-selector-search.js +86 -22
- package/dist/modes/interactive/components/session-selector-search.js.map +1 -1
- package/dist/modes/interactive/components/session-selector.d.ts +2 -1
- package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/session-selector.js +16 -24
- package/dist/modes/interactive/components/session-selector.js.map +1 -1
- package/dist/modes/interactive/components/settings-submenu.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-submenu.js +2 -0
- package/dist/modes/interactive/components/settings-submenu.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts +2 -0
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +15 -5
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/components/tree-selector.d.ts +1 -0
- package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/tree-selector.js +5 -6
- package/dist/modes/interactive/components/tree-selector.js.map +1 -1
- package/dist/modes/interactive/components/user-message-selector.d.ts +1 -0
- package/dist/modes/interactive/components/user-message-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/user-message-selector.js +9 -1
- package/dist/modes/interactive/components/user-message-selector.js.map +1 -1
- package/dist/modes/interactive/components/user-message.d.ts +4 -3
- package/dist/modes/interactive/components/user-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/user-message.js +20 -18
- package/dist/modes/interactive/components/user-message.js.map +1 -1
- package/dist/modes/interactive/external-editor.d.ts +1 -0
- package/dist/modes/interactive/external-editor.d.ts.map +1 -1
- package/dist/modes/interactive/external-editor.js +16 -4
- package/dist/modes/interactive/external-editor.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +6 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +259 -83
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/model-search.d.ts +10 -0
- package/dist/modes/interactive/model-search.d.ts.map +1 -1
- package/dist/modes/interactive/model-search.js +21 -0
- package/dist/modes/interactive/model-search.js.map +1 -1
- package/dist/modes/interactive/oauth-account-format.d.ts +10 -1
- package/dist/modes/interactive/oauth-account-format.d.ts.map +1 -1
- package/dist/modes/interactive/oauth-account-format.js +42 -0
- package/dist/modes/interactive/oauth-account-format.js.map +1 -1
- package/dist/modes/interactive/theme/theme.d.ts +10 -0
- package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
- package/dist/modes/interactive/theme/theme.js +28 -24
- package/dist/modes/interactive/theme/theme.js.map +1 -1
- package/dist/modes/print-mode.d.ts.map +1 -1
- package/dist/modes/print-mode.js +3 -2
- package/dist/modes/print-mode.js.map +1 -1
- package/dist/package-manager-cli.d.ts.map +1 -1
- package/dist/package-manager-cli.js +55 -4
- package/dist/package-manager-cli.js.map +1 -1
- package/dist/utils/ansi.d.ts.map +1 -1
- package/dist/utils/ansi.js +5 -2
- package/dist/utils/ansi.js.map +1 -1
- package/dist/utils/clipboard-command.d.ts.map +1 -1
- package/dist/utils/clipboard-command.js +4 -0
- package/dist/utils/clipboard-command.js.map +1 -1
- package/dist/utils/clipboard-image.d.ts +8 -0
- package/dist/utils/clipboard-image.d.ts.map +1 -1
- package/dist/utils/clipboard-image.js +31 -1
- package/dist/utils/clipboard-image.js.map +1 -1
- package/dist/utils/git.d.ts +1 -1
- package/dist/utils/git.d.ts.map +1 -1
- package/dist/utils/git.js.map +1 -1
- package/dist/utils/image-resize-core.d.ts.map +1 -1
- package/dist/utils/image-resize-core.js +5 -3
- package/dist/utils/image-resize-core.js.map +1 -1
- package/dist/utils/open-browser.d.ts.map +1 -1
- package/dist/utils/open-browser.js +96 -6
- package/dist/utils/open-browser.js.map +1 -1
- package/dist/utils/paths.d.ts +17 -0
- package/dist/utils/paths.d.ts.map +1 -1
- package/dist/utils/paths.js +42 -1
- package/dist/utils/paths.js.map +1 -1
- package/dist/utils/shell.d.ts +2 -1
- package/dist/utils/shell.d.ts.map +1 -1
- package/dist/utils/shell.js +12 -2
- package/dist/utils/shell.js.map +1 -1
- package/dist/utils/syntax-highlight.d.ts +5 -0
- package/dist/utils/syntax-highlight.d.ts.map +1 -1
- package/dist/utils/syntax-highlight.js +156 -11
- package/dist/utils/syntax-highlight.js.map +1 -1
- package/dist/utils/tools-manager.d.ts.map +1 -1
- package/dist/utils/tools-manager.js +30 -35
- package/dist/utils/tools-manager.js.map +1 -1
- package/docs/cli.md +22 -12
- package/docs/compaction.md +32 -8
- package/docs/coordination.md +2 -0
- package/docs/custom-provider.md +4 -2
- package/docs/environment-variables.md +2 -0
- package/docs/extensions.md +3169 -229
- package/docs/flow.md +2 -0
- package/docs/keybindings.md +24 -2
- package/docs/llama-cpp.md +30 -19
- package/docs/mcp.md +4 -2
- package/docs/message-types.md +7 -7
- package/docs/packages.md +27 -1
- package/docs/sessions.md +11 -3
- package/docs/settings.md +21 -9
- package/docs/slash-commands.md +51 -11
- package/docs/terminal-setup.md +3 -1
- package/docs/tmux.md +6 -0
- package/docs/tui.md +3 -1
- package/docs/windows.md +27 -0
- package/examples/extensions/README.md +2 -1
- package/examples/extensions/custom-provider-anthropic/index.ts +27 -31
- package/examples/extensions/custom-provider-anthropic/package-lock.json +7 -7
- package/examples/extensions/custom-provider-anthropic/package.json +2 -2
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/debug-provider.ts +2 -2
- package/examples/extensions/gondolin/package-lock.json +14 -24
- package/examples/extensions/gondolin/package.json +2 -2
- package/examples/extensions/preset.ts +2 -0
- package/examples/extensions/reload-runtime.ts +17 -5
- package/examples/extensions/todo.ts +7 -0
- package/examples/extensions/tools.ts +2 -0
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/examples/tsconfig.json +252 -0
- package/npm-shrinkwrap.json +289 -277
- package/package.json +29 -29
- package/schemas/keybindings.schema.json +28 -0
- package/schemas/models.schema.json +36 -36
- package/schemas/settings.schema.json +49 -0
- package/src/humain/ponytail/UPSTREAM.md +16 -2
- package/src/humain/ponytail/upstream.json +4 -4
- package/src/humain/web-access/UPSTREAM.md +48 -1
- package/src/humain/web-access/upstream.json +9 -6
- package/src/humain/web-access/vendor/CHANGELOG.md +1223 -0
- package/dist/bundle/chunks/anthropic-messages-ZP5KUK52.js +0 -67
- package/dist/bundle/chunks/azure-openai-responses-QJFYQ3DF.js +0 -15
- package/dist/bundle/chunks/chunk-2GCMACT4.js +0 -1956
- package/dist/bundle/chunks/chunk-AO6FF5JL.js +0 -21
- package/dist/bundle/chunks/chunk-EY3LZOUP.js +0 -1963
- package/dist/bundle/chunks/chunk-M74U5X4S.js +0 -119
- package/dist/bundle/chunks/chunk-N7CQ3UV3.js +0 -80
- package/dist/bundle/chunks/chunk-OR25QDSS.js +0 -365
- package/dist/bundle/chunks/chunk-PH7UP57J.js +0 -6
- package/dist/bundle/chunks/chunk-QW6PTCAB.js +0 -10
- package/dist/bundle/chunks/chunk-ROZV2IYD.js +0 -125
- package/dist/bundle/chunks/chunk-YFOLLX5D.js +0 -23
- package/dist/bundle/chunks/chunk-ZR4GF4WU.js +0 -54
- package/dist/bundle/chunks/compat-CJBWWYHE.js +0 -13
- package/dist/bundle/chunks/dist-IBUWEKEE.js +0 -24
- package/dist/bundle/chunks/dist-YFMJEHPH.js +0 -8
- package/dist/bundle/chunks/google-generative-ai-HVPCGIZ6.js +0 -21
- package/dist/bundle/chunks/google-vertex-UM5MAALA.js +0 -25
- package/dist/bundle/chunks/host-ZHEL5XQW.js +0 -2
- package/dist/bundle/chunks/mistral-conversations-AH72RLXK.js +0 -44
- package/dist/bundle/chunks/openai-codex-responses-L366637C.js +0 -98
- package/dist/bundle/chunks/openai-completions-ZP62QXJX.js +0 -83
- package/dist/bundle/chunks/openai-responses-DXUGSUTN.js +0 -26
- package/dist/bundle/chunks/pi-messages-MOQQDZBK.js +0 -23
- package/dist/bundle/chunks/virtual-modules-5D6QIJPN.js +0 -5
- package/examples/extensions/sandbox/index.ts +0 -321
- package/examples/extensions/sandbox/package-lock.json +0 -66
- package/examples/extensions/sandbox/package.json +0 -19
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
import { Type } from "typebox";
|
|
11
11
|
export const TOOL_SEARCH_TOOL_NAME = "tool_search";
|
|
12
12
|
export const DEFAULT_TOOL_SEARCH_LIMIT = 8;
|
|
13
|
+
const wordSegmenter = new Intl.Segmenter(undefined, { granularity: "word" });
|
|
13
14
|
const STOP_WORDS = new Set([
|
|
14
15
|
"a",
|
|
15
16
|
"an",
|
|
@@ -43,15 +44,22 @@ function stem(term) {
|
|
|
43
44
|
return term.slice(0, -1);
|
|
44
45
|
return term;
|
|
45
46
|
}
|
|
46
|
-
/**
|
|
47
|
+
/** Unicode word segmentation with identifier boundaries and English stop words/singular forms. */
|
|
47
48
|
export function tokenize(text) {
|
|
48
|
-
|
|
49
|
+
const normalized = text
|
|
50
|
+
.normalize("NFC")
|
|
49
51
|
.replace(/([a-z0-9])([A-Z])/g, "$1 $2")
|
|
50
52
|
.replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2")
|
|
51
53
|
.toLowerCase()
|
|
52
|
-
.
|
|
53
|
-
|
|
54
|
-
|
|
54
|
+
.replace(/[^\p{L}\p{M}\p{N}]+/gu, " ");
|
|
55
|
+
// The segmenter costs about 15 times a split. Plain ASCII splits into the same words at spaces, so only other
|
|
56
|
+
// text, such as Chinese written without spaces, goes through it.
|
|
57
|
+
const words = /^[a-z0-9 ]*$/.test(normalized)
|
|
58
|
+
? normalized.split(" ")
|
|
59
|
+
: Array.from(wordSegmenter.segment(normalized), (segment) => (segment.isWordLike ? segment.segment : ""));
|
|
60
|
+
return words
|
|
61
|
+
.filter((word) => word.length > 0 && !STOP_WORDS.has(word))
|
|
62
|
+
.map((word) => (/^[a-z0-9]+$/.test(word) ? stem(word) : word));
|
|
55
63
|
}
|
|
56
64
|
function isObject(value) {
|
|
57
65
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -77,18 +85,71 @@ function schemaText(schema, parts) {
|
|
|
77
85
|
}
|
|
78
86
|
}
|
|
79
87
|
/**
|
|
80
|
-
* Search text of a tool: the
|
|
81
|
-
*
|
|
82
|
-
* description and instructions.
|
|
88
|
+
* Search text of a tool: the description and the schema descriptions and property names, and
|
|
89
|
+
* separately the namespace name, description, and instructions. The ranker reads the name from `name`.
|
|
83
90
|
*/
|
|
84
91
|
export function createToolSearchDocument(tool, namespace) {
|
|
85
|
-
const parts = [tool.
|
|
92
|
+
const parts = [tool.description];
|
|
86
93
|
schemaText(tool.parameters, parts);
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
94
|
+
const namespaceText = namespace
|
|
95
|
+
? [namespace.name, namespace.description ?? "", namespace.instructions ?? ""].join(" ")
|
|
96
|
+
: "";
|
|
97
|
+
return { name: tool.name, text: parts.filter((part) => part.trim()).join(" "), namespaceText };
|
|
90
98
|
}
|
|
91
|
-
/**
|
|
99
|
+
/** Lowercase with characters invalid in script identifiers as `_`, so `dev-radius` matches `dev_radius`. */
|
|
100
|
+
function normalizeName(name) {
|
|
101
|
+
return name
|
|
102
|
+
.trim()
|
|
103
|
+
.toLowerCase()
|
|
104
|
+
.replace(/[^a-z0-9_$]/g, "_");
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Whether the whole query is the tool's name: its full name or a suffix after a `__` separator, so
|
|
108
|
+
* `thread_read` and `app__thread_read` both name `mcp__app__thread_read`.
|
|
109
|
+
*/
|
|
110
|
+
function isExactNameQuery(query, name) {
|
|
111
|
+
const normalized = normalizeName(name);
|
|
112
|
+
return normalized === query || normalized.endsWith(`__${query}`);
|
|
113
|
+
}
|
|
114
|
+
function indexDocument(document) {
|
|
115
|
+
const textCounts = new Map();
|
|
116
|
+
for (const term of tokenize(document.text))
|
|
117
|
+
textCounts.set(term, (textCounts.get(term) ?? 0) + 1);
|
|
118
|
+
const segments = document.name.split("__");
|
|
119
|
+
return {
|
|
120
|
+
name: document.name,
|
|
121
|
+
nameTerms: new Set(tokenize(document.name)),
|
|
122
|
+
localNameTerms: [...new Set(tokenize(segments[segments.length - 1]))],
|
|
123
|
+
textCounts,
|
|
124
|
+
textLength: [...textCounts.values()].reduce((sum, count) => sum + count, 0),
|
|
125
|
+
namespaceTerms: new Set(tokenize(document.namespaceText ?? "")),
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* A query term in the name counts this many times its IDF. The text part of a term is at most
|
|
130
|
+
* `k1 + 1` (2.2) times its IDF and about 1 for a single mention, so a name match beats any number of
|
|
131
|
+
* mentions in the description.
|
|
132
|
+
*/
|
|
133
|
+
const NAME_WEIGHT = 3;
|
|
134
|
+
/**
|
|
135
|
+
* A query term in the namespace name, description, or instructions counts this many times its IDF. They
|
|
136
|
+
* are shared by every tool of the server, so they help find the server but not the tool in it.
|
|
137
|
+
*/
|
|
138
|
+
const NAMESPACE_WEIGHT = 0.5;
|
|
139
|
+
/**
|
|
140
|
+
* Okapi BM25 over the description, with the name and the namespace as separate fields:
|
|
141
|
+
* - a tool that matches more of the query's terms, in any field, ranks above one that matches
|
|
142
|
+
* fewer, whatever their scores: for `screenshot window`, a tool whose description has both words
|
|
143
|
+
* beats `window`, whose name has one;
|
|
144
|
+
* - a query term in the name scores more than any number of mentions in the description;
|
|
145
|
+
* - a tool whose whole local name is in the query (`app` in `peekaboo app` for
|
|
146
|
+
* `mcp__peekaboo__app`) gets a bonus worth one more match of every query term, so among tools
|
|
147
|
+
* matching as many terms it mostly wins over tools that only mention the words;
|
|
148
|
+
* - a query that is exactly a tool's name ranks that tool first, before coverage.
|
|
149
|
+
*
|
|
150
|
+
* The description alone is length-normalized, so a long name or long namespace instructions do
|
|
151
|
+
* not lower a tool's score. Ties keep document order.
|
|
152
|
+
*/
|
|
92
153
|
export class Bm25Ranker {
|
|
93
154
|
k1;
|
|
94
155
|
b;
|
|
@@ -97,35 +158,42 @@ export class Bm25Ranker {
|
|
|
97
158
|
this.b = options.b ?? 0.75;
|
|
98
159
|
}
|
|
99
160
|
rank(query, documents, limit) {
|
|
100
|
-
const queryTerms =
|
|
101
|
-
if (queryTerms.
|
|
161
|
+
const queryTerms = new Set(tokenize(query));
|
|
162
|
+
if (queryTerms.size === 0 || documents.length === 0 || limit <= 0)
|
|
102
163
|
return [];
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
return
|
|
108
|
-
});
|
|
109
|
-
const lengths = termCounts.map((counts) => [...counts.values()].reduce((sum, count) => sum + count, 0));
|
|
110
|
-
const averageLength = lengths.reduce((sum, length) => sum + length, 0) / documents.length || 1;
|
|
111
|
-
const idf = new Map(queryTerms.map((term) => {
|
|
112
|
-
const frequency = termCounts.filter((counts) => counts.has(term)).length;
|
|
113
|
-
return [term, Math.log(1 + (documents.length - frequency + 0.5) / (frequency + 0.5))];
|
|
164
|
+
const indexed = documents.map(indexDocument);
|
|
165
|
+
const averageLength = indexed.reduce((sum, document) => sum + document.textLength, 0) / indexed.length || 1;
|
|
166
|
+
const idf = new Map([...queryTerms].map((term) => {
|
|
167
|
+
const frequency = indexed.filter((document) => document.nameTerms.has(term) || document.textCounts.has(term) || document.namespaceTerms.has(term)).length;
|
|
168
|
+
return [term, Math.log(1 + (indexed.length - frequency + 0.5) / (frequency + 0.5))];
|
|
114
169
|
}));
|
|
170
|
+
const fullNameBonus = [...idf.values()].reduce((sum, value) => sum + value, 0);
|
|
171
|
+
const exactQuery = normalizeName(query);
|
|
115
172
|
const matches = [];
|
|
116
|
-
|
|
173
|
+
for (const document of indexed) {
|
|
174
|
+
const norm = this.k1 * (1 - this.b + (this.b * document.textLength) / averageLength);
|
|
117
175
|
let score = 0;
|
|
176
|
+
let covered = 0;
|
|
118
177
|
for (const term of queryTerms) {
|
|
119
|
-
const count =
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
178
|
+
const count = document.textCounts.get(term) ?? 0;
|
|
179
|
+
const weight = (document.nameTerms.has(term) ? NAME_WEIGHT : 0) +
|
|
180
|
+
(document.namespaceTerms.has(term) ? NAMESPACE_WEIGHT : 0) +
|
|
181
|
+
(count * (this.k1 + 1)) / (count + norm);
|
|
182
|
+
if (weight > 0)
|
|
183
|
+
covered++;
|
|
184
|
+
score += (idf.get(term) ?? 0) * weight;
|
|
124
185
|
}
|
|
125
|
-
if (score
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
186
|
+
if (score === 0)
|
|
187
|
+
continue;
|
|
188
|
+
const local = document.localNameTerms;
|
|
189
|
+
if (local.length > 0 && local.every((term) => queryTerms.has(term)))
|
|
190
|
+
score += fullNameBonus;
|
|
191
|
+
matches.push({ name: document.name, score, covered, exact: isExactNameQuery(exactQuery, document.name) });
|
|
192
|
+
}
|
|
193
|
+
return matches
|
|
194
|
+
.sort((a, b) => Number(b.exact) - Number(a.exact) || b.covered - a.covered || b.score - a.score)
|
|
195
|
+
.slice(0, limit)
|
|
196
|
+
.map(({ name, score }) => ({ name, score }));
|
|
129
197
|
}
|
|
130
198
|
}
|
|
131
199
|
export const toolSearchSchema = Type.Object({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool.js","sourceRoot":"","sources":["../../../src/extensions/tool-search/tool.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAS5C,MAAM,CAAC,MAAM,qBAAqB,GAAG,aAAa,CAAC;AACnD,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,CAAC;AAkB3C,MAAM,UAAU,GAAwB,IAAI,GAAG,CAAC;IAC/C,GAAG;IACH,IAAI;IACJ,KAAK;IACL,KAAK;IACL,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,KAAK;IACL,MAAM;IACN,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,MAAM;IACN,KAAK;IACL,MAAM;IACN,IAAI;IACJ,MAAM;CACN,CAAC,CAAC;AAEH,wFAAwF;AACxF,SAAS,IAAI,CAAC,IAAY;IACzB,IAAI,IAAI,C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AAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;YACpE,MAAM,GAAG,GAAG,KAAK,IAAI,yBAAyB,CAAC;YAC/C,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC;gBAAE,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;YAC5F,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,aAAa,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YAC5E,MAAM,IAAI,GACT,KAAK,CAAC,MAAM,KAAK,CAAC;gBACjB,CAAC,CAAC,0BAA0B;gBAC5B,CAAC,CAAC,UAAU,KAAK,CAAC,MAAM,QAAQ,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,8CAA8C,KAAK;qBAC7G,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;qBAC7E,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YAClB,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,MAAM,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC;QACnG,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["/**\n * Tool discovery: a BM25 ranker over tool metadata, shared by `searchTools()` in codemode scripts and\n * the optional `tool_search` tool.\n *\n * `tool_search` searches tools that are not declared to\n * the model (`codemode` and `deferred` exposure) and loads the matches, so they are declared for the\n * next model call. Loading goes through the active tool set, so it is recorded in the transcript\n * like any other tool change and survives `/tree`, resume, and fork on that branch.\n */\n\nimport { type Static, Type } from \"typebox\";\nimport type {\n\tExtensionAPI,\n\tToolDefinition,\n\tToolExposure,\n\tToolInfo,\n\tToolNamespace,\n} from \"../../core/extensions/types.ts\";\n\nexport const TOOL_SEARCH_TOOL_NAME = \"tool_search\";\nexport const DEFAULT_TOOL_SEARCH_LIMIT = 8;\n\n/** A tool as the ranker sees it: its name and the text built by {@link createToolSearchDocument}. */\nexport interface ToolSearchDocument {\n\tname: string;\n\ttext: string;\n}\n\nexport interface ToolSearchMatch {\n\tname: string;\n\tscore: number;\n}\n\n/** Ranks tools for a query. BM25 today; a hybrid ranker with embeddings can replace it. */\nexport interface ToolRanker {\n\trank(query: string, documents: readonly ToolSearchDocument[], limit: number): ToolSearchMatch[];\n}\n\nconst STOP_WORDS: ReadonlySet<string> = new Set([\n\t\"a\",\n\t\"an\",\n\t\"and\",\n\t\"are\",\n\t\"as\",\n\t\"at\",\n\t\"be\",\n\t\"by\",\n\t\"for\",\n\t\"from\",\n\t\"in\",\n\t\"is\",\n\t\"it\",\n\t\"of\",\n\t\"on\",\n\t\"or\",\n\t\"that\",\n\t\"the\",\n\t\"this\",\n\t\"to\",\n\t\"with\",\n]);\n\n/** Naive singular form, so `issues` matches `issue` and `searches` matches `search`. */\nfunction stem(term: string): string {\n\tif (term.length > 4 && term.endsWith(\"ies\")) return `${term.slice(0, -3)}y`;\n\tif (term.length > 4 && /(ches|shes|sses|xes|zes)$/.test(term)) return term.slice(0, -2);\n\tif (term.length > 3 && term.endsWith(\"s\") && !term.endsWith(\"ss\")) return term.slice(0, -1);\n\treturn term;\n}\n\n/** Lowercase terms, split at camelCase boundaries and non-alphanumerics, without stop words. */\nexport function tokenize(text: string): string[] {\n\treturn text\n\t\t.replace(/([a-z0-9])([A-Z])/g, \"$1 $2\")\n\t\t.replace(/([A-Z]+)([A-Z][a-z])/g, \"$1 $2\")\n\t\t.toLowerCase()\n\t\t.split(/[^a-z0-9]+/)\n\t\t.filter((term) => term.length > 0 && !STOP_WORDS.has(term))\n\t\t.map(stem);\n}\n\nfunction isObject(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\n/** Schema descriptions and property names, recursively. */\nfunction schemaText(schema: unknown, parts: string[]): void {\n\tif (!isObject(schema)) return;\n\tif (typeof schema.description === \"string\") parts.push(schema.description);\n\tif (isObject(schema.properties)) {\n\t\tfor (const [name, property] of Object.entries(schema.properties)) {\n\t\t\tparts.push(name);\n\t\t\tschemaText(property, parts);\n\t\t}\n\t}\n\tschemaText(schema.items, parts);\n\tfor (const key of [\"anyOf\", \"oneOf\", \"allOf\"]) {\n\t\tconst variants = schema[key];\n\t\tif (Array.isArray(variants)) for (const variant of variants) schemaText(variant, parts);\n\t}\n}\n\n/**\n * Search text of a tool: the name, the name with `_`\n * as spaces, the description, schema descriptions and property names, and the namespace with its\n * description and instructions.\n */\nexport function createToolSearchDocument(\n\ttool: Pick<ToolInfo, \"name\" | \"description\" | \"parameters\">,\n\tnamespace?: ToolNamespace,\n): ToolSearchDocument {\n\tconst parts = [tool.name, tool.name.replaceAll(\"_\", \" \"), tool.description];\n\tschemaText(tool.parameters, parts);\n\tif (namespace) parts.push(namespace.name, namespace.description ?? \"\", namespace.instructions ?? \"\");\n\treturn { name: tool.name, text: parts.filter((part) => part.trim()).join(\" \") };\n}\n\n/** Okapi BM25 with the usual parameters. Ties keep document order. */\nexport class Bm25Ranker implements ToolRanker {\n\tprivate readonly k1: number;\n\tprivate readonly b: number;\n\n\tconstructor(options: { k1?: number; b?: number } = {}) {\n\t\tthis.k1 = options.k1 ?? 1.2;\n\t\tthis.b = options.b ?? 0.75;\n\t}\n\n\trank(query: string, documents: readonly ToolSearchDocument[], limit: number): ToolSearchMatch[] {\n\t\tconst queryTerms = [...new Set(tokenize(query))];\n\t\tif (queryTerms.length === 0 || documents.length === 0 || limit <= 0) return [];\n\t\tconst termCounts = documents.map((document) => {\n\t\t\tconst counts = new Map<string, number>();\n\t\t\tfor (const term of tokenize(document.text)) counts.set(term, (counts.get(term) ?? 0) + 1);\n\t\t\treturn counts;\n\t\t});\n\t\tconst lengths = termCounts.map((counts) => [...counts.values()].reduce((sum, count) => sum + count, 0));\n\t\tconst averageLength = lengths.reduce((sum, length) => sum + length, 0) / documents.length || 1;\n\t\tconst idf = new Map(\n\t\t\tqueryTerms.map((term) => {\n\t\t\t\tconst frequency = termCounts.filter((counts) => counts.has(term)).length;\n\t\t\t\treturn [term, Math.log(1 + (documents.length - frequency + 0.5) / (frequency + 0.5))] as const;\n\t\t\t}),\n\t\t);\n\t\tconst matches: ToolSearchMatch[] = [];\n\t\tdocuments.forEach((document, index) => {\n\t\t\tlet score = 0;\n\t\t\tfor (const term of queryTerms) {\n\t\t\t\tconst count = termCounts[index].get(term);\n\t\t\t\tif (!count) continue;\n\t\t\t\tconst norm = this.k1 * (1 - this.b + (this.b * lengths[index]) / averageLength);\n\t\t\t\tscore += (idf.get(term) ?? 0) * ((count * (this.k1 + 1)) / (count + norm));\n\t\t\t}\n\t\t\tif (score > 0) matches.push({ name: document.name, score });\n\t\t});\n\t\treturn matches.sort((a, b) => b.score - a.score).slice(0, limit);\n\t}\n}\n\nexport const toolSearchSchema = Type.Object({\n\tquery: Type.String({ description: \"Search query for deferred tools.\" }),\n\tlimit: Type.Optional(\n\t\tType.Number({ description: `Maximum number of tools to return. Defaults to ${DEFAULT_TOOL_SEARCH_LIMIT}.` }),\n\t),\n});\n\nexport type ToolSearchInput = Static<typeof toolSearchSchema>;\n\nexport interface ToolSearchResultTool {\n\tname: string;\n\tdescription: string;\n}\n\nexport interface ToolSearchToolDetails {\n\t/** Tools loaded by this call. */\n\tloaded: string[];\n}\n\nexport interface ToolSearchToolOptions {\n\t/**\n\t * The session's tools. `tool_search` searches the tools that are not declared to the model and\n\t * activates the matches. Without it, the tool finds nothing. An `ExtensionAPI` fits.\n\t */\n\ttools?: Pick<ExtensionAPI, \"getAllTools\" | \"getActiveTools\" | \"setActiveTools\">;\n}\n\n/** Whether `tool_search` can load a tool with this exposure. */\nfunction isSearchable(exposure: ToolExposure): boolean {\n\treturn exposure === \"codemode\" || exposure === \"deferred\";\n}\n\n/**\n * Rank the searchable tools that are not active yet and activate the matches, so the next model\n * call declares them. Activation is recorded in the transcript like any tool change.\n */\nfunction searchAndLoad(\n\ttools: NonNullable<ToolSearchToolOptions[\"tools\"]>,\n\tquery: string,\n\tlimit: number,\n): ToolSearchResultTool[] {\n\tconst active = tools.getActiveTools();\n\tconst candidates = tools.getAllTools().filter((tool) => isSearchable(tool.exposure) && !active.includes(tool.name));\n\tconst documents = candidates.map((tool) => createToolSearchDocument(tool, tool.namespace));\n\tconst matches = new Bm25Ranker().rank(query, documents, limit);\n\tif (matches.length > 0) tools.setActiveTools([...active, ...matches.map((match) => match.name)]);\n\treturn matches.map((match) => ({\n\t\tname: match.name,\n\t\tdescription: candidates.find((tool) => tool.name === match.name)?.description ?? \"\",\n\t}));\n}\n\n/**\n * The `tool_search` description. It does not list the searchable tools or their namespaces, so it\n * stays the same while tools are registered, for example when MCP servers connect.\n */\nexport const TOOL_SEARCH_DESCRIPTION = `# Tool discovery\\n\\nSearches over deferred tool metadata with BM25 and exposes matching tools for the next model call.\\n\\nSome of the tools, such as tools of MCP servers, may not have been provided to you upfront, and you should use this tool (\\`${TOOL_SEARCH_TOOL_NAME}\\`) to search for the required tools. For MCP tool discovery, always use \\`${TOOL_SEARCH_TOOL_NAME}\\`.`;\n\nexport function createToolSearchToolDefinition(\n\toptions: ToolSearchToolOptions = {},\n): ToolDefinition<typeof toolSearchSchema, ToolSearchToolDetails> {\n\treturn {\n\t\tname: TOOL_SEARCH_TOOL_NAME,\n\t\tlabel: TOOL_SEARCH_TOOL_NAME,\n\t\tdescription: TOOL_SEARCH_DESCRIPTION,\n\t\tpromptSnippet: \"Search for tools that are not loaded yet and load the matches\",\n\t\tparameters: toolSearchSchema,\n\t\t// Searching is not something scripts need; it changes what the model sees.\n\t\texposure: \"model-only\",\n\t\t// A query can match any tool that is not declared yet.\n\t\treachesTools: () => \"all\",\n\t\tasync execute(_toolCallId, { query, limit }) {\n\t\t\tif (query.trim() === \"\") throw new Error(\"query must not be empty\");\n\t\t\tconst max = limit ?? DEFAULT_TOOL_SEARCH_LIMIT;\n\t\t\tif (!Number.isInteger(max) || max <= 0) throw new Error(\"limit must be a positive integer\");\n\t\t\tconst tools = options.tools ? searchAndLoad(options.tools, query, max) : [];\n\t\t\tconst text =\n\t\t\t\ttools.length === 0\n\t\t\t\t\t? \"No matching tools found.\"\n\t\t\t\t\t: `Loaded ${tools.length} tool${tools.length === 1 ? \"\" : \"s\"}. They are available from your next call:\\n${tools\n\t\t\t\t\t\t\t.map((tool) => `- ${tool.name}: ${tool.description.trim().split(/\\r?\\n/)[0]}`)\n\t\t\t\t\t\t\t.join(\"\\n\")}`;\n\t\t\treturn { content: [{ type: \"text\", text }], details: { loaded: tools.map((tool) => tool.name) } };\n\t\t},\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"tool.js","sourceRoot":"","sources":["../../../src/extensions/tool-search/tool.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAS5C,MAAM,CAAC,MAAM,qBAAqB,GAAG,aAAa,CAAC;AACnD,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,CAAC;AAqB3C,MAAM,aAAa,GAAG,IAAI,IAAI,CAAC,SAAS,CAAC,SAAS,EAAE,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC,CAAC;AAE7E,MAAM,UAAU,GAAwB,IAAI,GAAG,CAAC;IAC/C,GAAG;IACH,IAAI;IACJ,KAAK;IACL,KAAK;IACL,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,KAAK;IACL,MAAM;IACN,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IA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EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,MAAM,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC;QACnG,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["/**\n * Tool discovery: a BM25 ranker over tool metadata, shared by `searchTools()` in codemode scripts and\n * the optional `tool_search` tool.\n *\n * `tool_search` searches tools that are not declared to\n * the model (`codemode` and `deferred` exposure) and loads the matches, so they are declared for the\n * next model call. Loading goes through the active tool set, so it is recorded in the transcript\n * like any other tool change and survives `/tree`, resume, and fork on that branch.\n */\n\nimport { type Static, Type } from \"typebox\";\nimport type {\n\tExtensionAPI,\n\tToolDefinition,\n\tToolExposure,\n\tToolInfo,\n\tToolNamespace,\n} from \"../../core/extensions/types.ts\";\n\nexport const TOOL_SEARCH_TOOL_NAME = \"tool_search\";\nexport const DEFAULT_TOOL_SEARCH_LIMIT = 8;\n\n/** A tool as the ranker sees it: its name and the texts built by {@link createToolSearchDocument}. */\nexport interface ToolSearchDocument {\n\tname: string;\n\t/** Description, schema descriptions, and property names. */\n\ttext: string;\n\t/** Name, description, and instructions of the tool's namespace. */\n\tnamespaceText?: string;\n}\n\nexport interface ToolSearchMatch {\n\tname: string;\n\tscore: number;\n}\n\n/** Ranks tools for a query. BM25 today; a hybrid ranker with embeddings can replace it. */\nexport interface ToolRanker {\n\trank(query: string, documents: readonly ToolSearchDocument[], limit: number): ToolSearchMatch[];\n}\n\nconst wordSegmenter = new Intl.Segmenter(undefined, { granularity: \"word\" });\n\nconst STOP_WORDS: ReadonlySet<string> = new Set([\n\t\"a\",\n\t\"an\",\n\t\"and\",\n\t\"are\",\n\t\"as\",\n\t\"at\",\n\t\"be\",\n\t\"by\",\n\t\"for\",\n\t\"from\",\n\t\"in\",\n\t\"is\",\n\t\"it\",\n\t\"of\",\n\t\"on\",\n\t\"or\",\n\t\"that\",\n\t\"the\",\n\t\"this\",\n\t\"to\",\n\t\"with\",\n]);\n\n/** Naive singular form, so `issues` matches `issue` and `searches` matches `search`. */\nfunction stem(term: string): string {\n\tif (term.length > 4 && term.endsWith(\"ies\")) return `${term.slice(0, -3)}y`;\n\tif (term.length > 4 && /(ches|shes|sses|xes|zes)$/.test(term)) return term.slice(0, -2);\n\tif (term.length > 3 && term.endsWith(\"s\") && !term.endsWith(\"ss\")) return term.slice(0, -1);\n\treturn term;\n}\n\n/** Unicode word segmentation with identifier boundaries and English stop words/singular forms. */\nexport function tokenize(text: string): string[] {\n\tconst normalized = text\n\t\t.normalize(\"NFC\")\n\t\t.replace(/([a-z0-9])([A-Z])/g, \"$1 $2\")\n\t\t.replace(/([A-Z]+)([A-Z][a-z])/g, \"$1 $2\")\n\t\t.toLowerCase()\n\t\t.replace(/[^\\p{L}\\p{M}\\p{N}]+/gu, \" \");\n\t// The segmenter costs about 15 times a split. Plain ASCII splits into the same words at spaces, so only other\n\t// text, such as Chinese written without spaces, goes through it.\n\tconst words = /^[a-z0-9 ]*$/.test(normalized)\n\t\t? normalized.split(\" \")\n\t\t: Array.from(wordSegmenter.segment(normalized), (segment) => (segment.isWordLike ? segment.segment : \"\"));\n\treturn words\n\t\t.filter((word) => word.length > 0 && !STOP_WORDS.has(word))\n\t\t.map((word) => (/^[a-z0-9]+$/.test(word) ? stem(word) : word));\n}\n\nfunction isObject(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\n/** Schema descriptions and property names, recursively. */\nfunction schemaText(schema: unknown, parts: string[]): void {\n\tif (!isObject(schema)) return;\n\tif (typeof schema.description === \"string\") parts.push(schema.description);\n\tif (isObject(schema.properties)) {\n\t\tfor (const [name, property] of Object.entries(schema.properties)) {\n\t\t\tparts.push(name);\n\t\t\tschemaText(property, parts);\n\t\t}\n\t}\n\tschemaText(schema.items, parts);\n\tfor (const key of [\"anyOf\", \"oneOf\", \"allOf\"]) {\n\t\tconst variants = schema[key];\n\t\tif (Array.isArray(variants)) for (const variant of variants) schemaText(variant, parts);\n\t}\n}\n\n/**\n * Search text of a tool: the description and the schema descriptions and property names, and\n * separately the namespace name, description, and instructions. The ranker reads the name from `name`.\n */\nexport function createToolSearchDocument(\n\ttool: Pick<ToolInfo, \"name\" | \"description\" | \"parameters\">,\n\tnamespace?: ToolNamespace,\n): ToolSearchDocument {\n\tconst parts = [tool.description];\n\tschemaText(tool.parameters, parts);\n\tconst namespaceText = namespace\n\t\t? [namespace.name, namespace.description ?? \"\", namespace.instructions ?? \"\"].join(\" \")\n\t\t: \"\";\n\treturn { name: tool.name, text: parts.filter((part) => part.trim()).join(\" \"), namespaceText };\n}\n\n/** Lowercase with characters invalid in script identifiers as `_`, so `dev-radius` matches `dev_radius`. */\nfunction normalizeName(name: string): string {\n\treturn name\n\t\t.trim()\n\t\t.toLowerCase()\n\t\t.replace(/[^a-z0-9_$]/g, \"_\");\n}\n\n/**\n * Whether the whole query is the tool's name: its full name or a suffix after a `__` separator, so\n * `thread_read` and `app__thread_read` both name `mcp__app__thread_read`.\n */\nfunction isExactNameQuery(query: string, name: string): boolean {\n\tconst normalized = normalizeName(name);\n\treturn normalized === query || normalized.endsWith(`__${query}`);\n}\n\n/** A document split into the fields the ranker weighs differently. */\ninterface IndexedDocument {\n\tname: string;\n\t/** Terms of the name, for example `mcp`, `app`, `thread`, `read` for `mcp__app__thread_read`. */\n\tnameTerms: ReadonlySet<string>;\n\t/** Terms of the last `__` segment of the name, the part models say: `thread`, `read`. */\n\tlocalNameTerms: readonly string[];\n\ttextCounts: ReadonlyMap<string, number>;\n\ttextLength: number;\n\tnamespaceTerms: ReadonlySet<string>;\n}\n\nfunction indexDocument(document: ToolSearchDocument): IndexedDocument {\n\tconst textCounts = new Map<string, number>();\n\tfor (const term of tokenize(document.text)) textCounts.set(term, (textCounts.get(term) ?? 0) + 1);\n\tconst segments = document.name.split(\"__\");\n\treturn {\n\t\tname: document.name,\n\t\tnameTerms: new Set(tokenize(document.name)),\n\t\tlocalNameTerms: [...new Set(tokenize(segments[segments.length - 1]))],\n\t\ttextCounts,\n\t\ttextLength: [...textCounts.values()].reduce((sum, count) => sum + count, 0),\n\t\tnamespaceTerms: new Set(tokenize(document.namespaceText ?? \"\")),\n\t};\n}\n\n/**\n * A query term in the name counts this many times its IDF. The text part of a term is at most\n * `k1 + 1` (2.2) times its IDF and about 1 for a single mention, so a name match beats any number of\n * mentions in the description.\n */\nconst NAME_WEIGHT = 3;\n\n/**\n * A query term in the namespace name, description, or instructions counts this many times its IDF. They\n * are shared by every tool of the server, so they help find the server but not the tool in it.\n */\nconst NAMESPACE_WEIGHT = 0.5;\n\n/**\n * Okapi BM25 over the description, with the name and the namespace as separate fields:\n * - a tool that matches more of the query's terms, in any field, ranks above one that matches\n * fewer, whatever their scores: for `screenshot window`, a tool whose description has both words\n * beats `window`, whose name has one;\n * - a query term in the name scores more than any number of mentions in the description;\n * - a tool whose whole local name is in the query (`app` in `peekaboo app` for\n * `mcp__peekaboo__app`) gets a bonus worth one more match of every query term, so among tools\n * matching as many terms it mostly wins over tools that only mention the words;\n * - a query that is exactly a tool's name ranks that tool first, before coverage.\n *\n * The description alone is length-normalized, so a long name or long namespace instructions do\n * not lower a tool's score. Ties keep document order.\n */\nexport class Bm25Ranker implements ToolRanker {\n\tprivate readonly k1: number;\n\tprivate readonly b: number;\n\n\tconstructor(options: { k1?: number; b?: number } = {}) {\n\t\tthis.k1 = options.k1 ?? 1.2;\n\t\tthis.b = options.b ?? 0.75;\n\t}\n\n\trank(query: string, documents: readonly ToolSearchDocument[], limit: number): ToolSearchMatch[] {\n\t\tconst queryTerms = new Set(tokenize(query));\n\t\tif (queryTerms.size === 0 || documents.length === 0 || limit <= 0) return [];\n\t\tconst indexed = documents.map(indexDocument);\n\t\tconst averageLength = indexed.reduce((sum, document) => sum + document.textLength, 0) / indexed.length || 1;\n\t\tconst idf = new Map(\n\t\t\t[...queryTerms].map((term) => {\n\t\t\t\tconst frequency = indexed.filter(\n\t\t\t\t\t(document) =>\n\t\t\t\t\t\tdocument.nameTerms.has(term) || document.textCounts.has(term) || document.namespaceTerms.has(term),\n\t\t\t\t).length;\n\t\t\t\treturn [term, Math.log(1 + (indexed.length - frequency + 0.5) / (frequency + 0.5))] as const;\n\t\t\t}),\n\t\t);\n\t\tconst fullNameBonus = [...idf.values()].reduce((sum, value) => sum + value, 0);\n\t\tconst exactQuery = normalizeName(query);\n\t\tconst matches: (ToolSearchMatch & { covered: number; exact: boolean })[] = [];\n\t\tfor (const document of indexed) {\n\t\t\tconst norm = this.k1 * (1 - this.b + (this.b * document.textLength) / averageLength);\n\t\t\tlet score = 0;\n\t\t\tlet covered = 0;\n\t\t\tfor (const term of queryTerms) {\n\t\t\t\tconst count = document.textCounts.get(term) ?? 0;\n\t\t\t\tconst weight =\n\t\t\t\t\t(document.nameTerms.has(term) ? NAME_WEIGHT : 0) +\n\t\t\t\t\t(document.namespaceTerms.has(term) ? NAMESPACE_WEIGHT : 0) +\n\t\t\t\t\t(count * (this.k1 + 1)) / (count + norm);\n\t\t\t\tif (weight > 0) covered++;\n\t\t\t\tscore += (idf.get(term) ?? 0) * weight;\n\t\t\t}\n\t\t\tif (score === 0) continue;\n\t\t\tconst local = document.localNameTerms;\n\t\t\tif (local.length > 0 && local.every((term) => queryTerms.has(term))) score += fullNameBonus;\n\t\t\tmatches.push({ name: document.name, score, covered, exact: isExactNameQuery(exactQuery, document.name) });\n\t\t}\n\t\treturn matches\n\t\t\t.sort((a, b) => Number(b.exact) - Number(a.exact) || b.covered - a.covered || b.score - a.score)\n\t\t\t.slice(0, limit)\n\t\t\t.map(({ name, score }) => ({ name, score }));\n\t}\n}\n\nexport const toolSearchSchema = Type.Object({\n\tquery: Type.String({ description: \"Search query for deferred tools.\" }),\n\tlimit: Type.Optional(\n\t\tType.Number({ description: `Maximum number of tools to return. Defaults to ${DEFAULT_TOOL_SEARCH_LIMIT}.` }),\n\t),\n});\n\nexport type ToolSearchInput = Static<typeof toolSearchSchema>;\n\nexport interface ToolSearchResultTool {\n\tname: string;\n\tdescription: string;\n}\n\nexport interface ToolSearchToolDetails {\n\t/** Tools loaded by this call. */\n\tloaded: string[];\n}\n\nexport interface ToolSearchToolOptions {\n\t/**\n\t * The session's tools. `tool_search` searches the tools that are not declared to the model and\n\t * activates the matches. Without it, the tool finds nothing. An `ExtensionAPI` fits.\n\t */\n\ttools?: Pick<ExtensionAPI, \"getAllTools\" | \"getActiveTools\" | \"setActiveTools\">;\n}\n\n/** Whether `tool_search` can load a tool with this exposure. */\nfunction isSearchable(exposure: ToolExposure): boolean {\n\treturn exposure === \"codemode\" || exposure === \"deferred\";\n}\n\n/**\n * Rank the searchable tools that are not active yet and activate the matches, so the next model\n * call declares them. Activation is recorded in the transcript like any tool change.\n */\nfunction searchAndLoad(\n\ttools: NonNullable<ToolSearchToolOptions[\"tools\"]>,\n\tquery: string,\n\tlimit: number,\n): ToolSearchResultTool[] {\n\tconst active = tools.getActiveTools();\n\tconst candidates = tools.getAllTools().filter((tool) => isSearchable(tool.exposure) && !active.includes(tool.name));\n\tconst documents = candidates.map((tool) => createToolSearchDocument(tool, tool.namespace));\n\tconst matches = new Bm25Ranker().rank(query, documents, limit);\n\tif (matches.length > 0) tools.setActiveTools([...active, ...matches.map((match) => match.name)]);\n\treturn matches.map((match) => ({\n\t\tname: match.name,\n\t\tdescription: candidates.find((tool) => tool.name === match.name)?.description ?? \"\",\n\t}));\n}\n\n/**\n * The `tool_search` description. It does not list the searchable tools or their namespaces, so it\n * stays the same while tools are registered, for example when MCP servers connect.\n */\nexport const TOOL_SEARCH_DESCRIPTION = `# Tool discovery\\n\\nSearches over deferred tool metadata with BM25 and exposes matching tools for the next model call.\\n\\nSome of the tools, such as tools of MCP servers, may not have been provided to you upfront, and you should use this tool (\\`${TOOL_SEARCH_TOOL_NAME}\\`) to search for the required tools. For MCP tool discovery, always use \\`${TOOL_SEARCH_TOOL_NAME}\\`.`;\n\nexport function createToolSearchToolDefinition(\n\toptions: ToolSearchToolOptions = {},\n): ToolDefinition<typeof toolSearchSchema, ToolSearchToolDetails> {\n\treturn {\n\t\tname: TOOL_SEARCH_TOOL_NAME,\n\t\tlabel: TOOL_SEARCH_TOOL_NAME,\n\t\tdescription: TOOL_SEARCH_DESCRIPTION,\n\t\tpromptSnippet: \"Search for tools that are not loaded yet and load the matches\",\n\t\tparameters: toolSearchSchema,\n\t\t// Searching is not something scripts need; it changes what the model sees.\n\t\texposure: \"model-only\",\n\t\t// A query can match any tool that is not declared yet.\n\t\treachesTools: () => \"all\",\n\t\tasync execute(_toolCallId, { query, limit }) {\n\t\t\tif (query.trim() === \"\") throw new Error(\"query must not be empty\");\n\t\t\tconst max = limit ?? DEFAULT_TOOL_SEARCH_LIMIT;\n\t\t\tif (!Number.isInteger(max) || max <= 0) throw new Error(\"limit must be a positive integer\");\n\t\t\tconst tools = options.tools ? searchAndLoad(options.tools, query, max) : [];\n\t\t\tconst text =\n\t\t\t\ttools.length === 0\n\t\t\t\t\t? \"No matching tools found.\"\n\t\t\t\t\t: `Loaded ${tools.length} tool${tools.length === 1 ? \"\" : \"s\"}. They are available from your next call:\\n${tools\n\t\t\t\t\t\t\t.map((tool) => `- ${tool.name}: ${tool.description.trim().split(/\\r?\\n/)[0]}`)\n\t\t\t\t\t\t\t.join(\"\\n\")}`;\n\t\t\treturn { content: [{ type: \"text\", text }], details: { loaded: tools.map((tool) => tool.name) } };\n\t\t},\n\t};\n}\n"]}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { type Component, type TuiMouseEvent, type TuiMouseEventResult } from "@earendil-works/pi-tui";
|
|
2
|
+
import type { KeybindingsManager } from "../../core/keybindings.ts";
|
|
3
|
+
import type { Theme } from "../../modes/interactive/theme/theme.ts";
|
|
4
|
+
export interface UsageConfirmationOptions {
|
|
5
|
+
title: string;
|
|
6
|
+
body: readonly string[];
|
|
7
|
+
confirmLabel: string;
|
|
8
|
+
}
|
|
9
|
+
/** Account-bound content is supplied by the caller; this component performs no provider action. */
|
|
10
|
+
export declare class UsageConfirmationComponent implements Component {
|
|
11
|
+
readonly options: Readonly<UsageConfirmationOptions>;
|
|
12
|
+
private readonly theme;
|
|
13
|
+
private readonly keybindings;
|
|
14
|
+
private readonly done;
|
|
15
|
+
private readonly requestRender;
|
|
16
|
+
private readonly getHeight;
|
|
17
|
+
private disposed;
|
|
18
|
+
private confirmSelected;
|
|
19
|
+
private scrollTop;
|
|
20
|
+
private reviewedThrough;
|
|
21
|
+
private viewportHeight;
|
|
22
|
+
private bodyRows;
|
|
23
|
+
private renderedWidth;
|
|
24
|
+
private renderedHeight;
|
|
25
|
+
private ready;
|
|
26
|
+
private reviewed;
|
|
27
|
+
private regions;
|
|
28
|
+
constructor(theme: Theme, keybindings: KeybindingsManager, options: UsageConfirmationOptions, done: (confirmed: boolean) => void, requestRender: () => void, getHeight: () => number);
|
|
29
|
+
private height;
|
|
30
|
+
private finish;
|
|
31
|
+
dispose(): void;
|
|
32
|
+
invalidate(): void;
|
|
33
|
+
private canConfirm;
|
|
34
|
+
private scrollBy;
|
|
35
|
+
handleInput(data: string): void;
|
|
36
|
+
handleMouse(event: TuiMouseEvent): TuiMouseEventResult;
|
|
37
|
+
private key;
|
|
38
|
+
render(width: number): string[];
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=confirmation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"confirmation.d.ts","sourceRoot":"","sources":["../../../src/extensions/usage/confirmation.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,SAAS,EAGd,KAAK,aAAa,EAClB,KAAK,mBAAmB,EAIxB,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAEpE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,wCAAwC,CAAC;AAEpE,MAAM,WAAW,wBAAwB;IACxC,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,SAAS,MAAM,E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AM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAiF9B;CACD"}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { stripTerminalSequences, truncateToWidth, visibleWidth, wrapTextWithAnsi, } from "@earendil-works/pi-tui";
|
|
2
|
+
import { formatKeyText } from "../../modes/interactive/components/keybinding-hints.js";
|
|
3
|
+
function plainText(text) {
|
|
4
|
+
return stripTerminalSequences(text).replace(/[\u0000-\u0009\u000b\u000c\u000e-\u001f\u007f-\u009f\u202a-\u202e\u2066-\u2069]/g, " ");
|
|
5
|
+
}
|
|
6
|
+
/** Account-bound content is supplied by the caller; this component performs no provider action. */
|
|
7
|
+
export class UsageConfirmationComponent {
|
|
8
|
+
options;
|
|
9
|
+
theme;
|
|
10
|
+
keybindings;
|
|
11
|
+
done;
|
|
12
|
+
requestRender;
|
|
13
|
+
getHeight;
|
|
14
|
+
disposed = false;
|
|
15
|
+
confirmSelected = false;
|
|
16
|
+
scrollTop = 0;
|
|
17
|
+
reviewedThrough = 0;
|
|
18
|
+
viewportHeight = 0;
|
|
19
|
+
bodyRows = [];
|
|
20
|
+
renderedWidth = 0;
|
|
21
|
+
renderedHeight = 0;
|
|
22
|
+
ready = false;
|
|
23
|
+
reviewed = false;
|
|
24
|
+
regions = [];
|
|
25
|
+
constructor(theme, keybindings, options, done, requestRender, getHeight) {
|
|
26
|
+
this.theme = theme;
|
|
27
|
+
this.keybindings = keybindings;
|
|
28
|
+
this.options = Object.freeze({
|
|
29
|
+
title: plainText(options.title),
|
|
30
|
+
body: Object.freeze(options.body.map(plainText)),
|
|
31
|
+
confirmLabel: plainText(options.confirmLabel),
|
|
32
|
+
});
|
|
33
|
+
this.done = done;
|
|
34
|
+
this.requestRender = requestRender;
|
|
35
|
+
this.getHeight = getHeight;
|
|
36
|
+
}
|
|
37
|
+
height() {
|
|
38
|
+
const height = this.getHeight();
|
|
39
|
+
return Number.isFinite(height) ? Math.max(0, Math.floor(height)) : 0;
|
|
40
|
+
}
|
|
41
|
+
finish(confirmed) {
|
|
42
|
+
if (this.disposed)
|
|
43
|
+
return;
|
|
44
|
+
this.disposed = true;
|
|
45
|
+
this.regions = [];
|
|
46
|
+
this.done(confirmed);
|
|
47
|
+
}
|
|
48
|
+
dispose() {
|
|
49
|
+
this.finish(false);
|
|
50
|
+
}
|
|
51
|
+
invalidate() {
|
|
52
|
+
if (this.disposed)
|
|
53
|
+
return;
|
|
54
|
+
this.ready = false;
|
|
55
|
+
this.regions = [];
|
|
56
|
+
}
|
|
57
|
+
canConfirm() {
|
|
58
|
+
return this.ready && this.reviewed && this.renderedHeight === this.height();
|
|
59
|
+
}
|
|
60
|
+
scrollBy(delta) {
|
|
61
|
+
// Do not let coalesced input skip text that has never appeared in a rendered frame.
|
|
62
|
+
const max = Math.min(this.reviewedThrough, Math.max(0, this.bodyRows.length - this.viewportHeight));
|
|
63
|
+
const next = Math.max(0, Math.min(max, this.scrollTop + Math.trunc(delta)));
|
|
64
|
+
if (!Number.isFinite(next) || next === this.scrollTop)
|
|
65
|
+
return false;
|
|
66
|
+
this.scrollTop = next;
|
|
67
|
+
this.invalidate();
|
|
68
|
+
this.requestRender();
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
handleInput(data) {
|
|
72
|
+
if (this.disposed)
|
|
73
|
+
return;
|
|
74
|
+
const kb = this.keybindings;
|
|
75
|
+
if (kb.matches(data, "tui.select.cancel") || kb.matches(data, "app.clear"))
|
|
76
|
+
this.finish(false);
|
|
77
|
+
else if (kb.matches(data, "tui.select.confirm")) {
|
|
78
|
+
if (!this.confirmSelected)
|
|
79
|
+
this.finish(false);
|
|
80
|
+
else if (this.canConfirm())
|
|
81
|
+
this.finish(true);
|
|
82
|
+
}
|
|
83
|
+
else if (kb.matches(data, "app.usage.nextTab") || kb.matches(data, "app.usage.previousTab")) {
|
|
84
|
+
this.confirmSelected = !this.confirmSelected;
|
|
85
|
+
this.requestRender();
|
|
86
|
+
}
|
|
87
|
+
else if (kb.matches(data, "tui.select.up"))
|
|
88
|
+
this.scrollBy(-1);
|
|
89
|
+
else if (kb.matches(data, "tui.select.down"))
|
|
90
|
+
this.scrollBy(1);
|
|
91
|
+
else if (kb.matches(data, "tui.select.pageUp"))
|
|
92
|
+
this.scrollBy(-this.viewportHeight);
|
|
93
|
+
else if (kb.matches(data, "tui.select.pageDown"))
|
|
94
|
+
this.scrollBy(this.viewportHeight);
|
|
95
|
+
}
|
|
96
|
+
handleMouse(event) {
|
|
97
|
+
if (this.disposed || !this.ready || event.width !== this.renderedWidth || this.height() !== this.renderedHeight)
|
|
98
|
+
return { handled: true, render: false };
|
|
99
|
+
if (event.type === "wheel" &&
|
|
100
|
+
event.x >= 0 &&
|
|
101
|
+
event.x < this.renderedWidth &&
|
|
102
|
+
event.y >= 1 &&
|
|
103
|
+
event.y < 1 + this.viewportHeight) {
|
|
104
|
+
return { handled: true, render: this.scrollBy(event.wheelDelta ?? 0), focus: true };
|
|
105
|
+
}
|
|
106
|
+
if (event.type !== "click" || event.button !== "left")
|
|
107
|
+
return { handled: true, render: false };
|
|
108
|
+
const region = this.regions.find((item) => event.y === item.y && event.x >= item.x && event.x < item.x + item.width);
|
|
109
|
+
if (region && (!region.confirmed || this.canConfirm()))
|
|
110
|
+
this.finish(region.confirmed);
|
|
111
|
+
return { handled: true, render: false };
|
|
112
|
+
}
|
|
113
|
+
key(action) {
|
|
114
|
+
const key = this.keybindings.getKeys(action)[0];
|
|
115
|
+
return key ? formatKeyText(key) : "";
|
|
116
|
+
}
|
|
117
|
+
render(width) {
|
|
118
|
+
if (this.disposed)
|
|
119
|
+
return [];
|
|
120
|
+
this.regions = [];
|
|
121
|
+
this.ready = false;
|
|
122
|
+
width = Number.isFinite(width) ? Math.max(0, Math.floor(width)) : 0;
|
|
123
|
+
const height = this.height();
|
|
124
|
+
if (width !== this.renderedWidth || height !== this.renderedHeight) {
|
|
125
|
+
this.scrollTop = 0;
|
|
126
|
+
this.reviewedThrough = 0;
|
|
127
|
+
}
|
|
128
|
+
this.renderedWidth = width;
|
|
129
|
+
this.renderedHeight = height;
|
|
130
|
+
this.reviewed = false;
|
|
131
|
+
if (width === 0 || height === 0)
|
|
132
|
+
return [];
|
|
133
|
+
const theme = this.theme;
|
|
134
|
+
const buttons = ["Cancel", this.options.confirmLabel].map((label, index) => ({
|
|
135
|
+
confirmed: index === 1,
|
|
136
|
+
text: `${this.confirmSelected === (index === 1) ? ">" : " "} [${truncateToWidth(label.replace(/[\r\n]/g, " "), Math.max(0, width - 4), "…")}]`,
|
|
137
|
+
}));
|
|
138
|
+
const stacked = buttons.reduce((total, button) => total + visibleWidth(button.text), 2) > width;
|
|
139
|
+
const buttonHeight = stacked ? 2 : 1;
|
|
140
|
+
const pair = (...actions) => actions
|
|
141
|
+
.map((action) => this.key(action))
|
|
142
|
+
.filter(Boolean)
|
|
143
|
+
.join("/");
|
|
144
|
+
const hints = [
|
|
145
|
+
[pair("tui.select.up", "tui.select.down"), "scroll"],
|
|
146
|
+
[pair("tui.select.pageUp", "tui.select.pageDown"), "page"],
|
|
147
|
+
[pair("app.usage.nextTab", "app.usage.previousTab"), "choose"],
|
|
148
|
+
[this.key("tui.select.confirm"), "select"],
|
|
149
|
+
[pair("tui.select.cancel", "app.clear"), "cancel"],
|
|
150
|
+
]
|
|
151
|
+
.filter(([key]) => key)
|
|
152
|
+
.map(([key, label]) => `${key} ${label}`);
|
|
153
|
+
const hintRows = wrapTextWithAnsi(hints.join(" · "), width);
|
|
154
|
+
const fixedHints = hintRows.slice(0, Math.max(0, height - buttonHeight - 5));
|
|
155
|
+
this.bodyRows = [
|
|
156
|
+
...(/[\r\n]/.test(this.options.title) || visibleWidth(this.options.title) > width ? [this.options.title] : []),
|
|
157
|
+
...this.options.body,
|
|
158
|
+
`Action: ${this.options.confirmLabel}`,
|
|
159
|
+
...hintRows.slice(fixedHints.length),
|
|
160
|
+
].flatMap((line) => wrapTextWithAnsi(line, width));
|
|
161
|
+
this.viewportHeight = Math.max(0, height - 2 - buttonHeight - fixedHints.length);
|
|
162
|
+
if (height < 6 || width < 12 || this.viewportHeight < 1) {
|
|
163
|
+
return buttons.map((button) => truncateToWidth(theme.fg("muted", button.text), width)).slice(0, height);
|
|
164
|
+
}
|
|
165
|
+
this.scrollTop = Math.min(this.scrollTop, Math.max(0, this.bodyRows.length - this.viewportHeight));
|
|
166
|
+
const body = this.bodyRows.slice(this.scrollTop, this.scrollTop + this.viewportHeight);
|
|
167
|
+
this.reviewedThrough = Math.max(this.reviewedThrough, this.scrollTop + body.length);
|
|
168
|
+
this.reviewed =
|
|
169
|
+
this.reviewedThrough === this.bodyRows.length && this.bodyRows.every((row) => visibleWidth(row) <= width);
|
|
170
|
+
const output = [
|
|
171
|
+
theme.bold(truncateToWidth(this.options.title.replace(/[\r\n]/g, " "), width, "…")),
|
|
172
|
+
...body,
|
|
173
|
+
...Array.from({ length: Math.max(0, this.viewportHeight - body.length) }, () => ""),
|
|
174
|
+
theme.fg(this.reviewed ? "success" : "warning", this.reviewed
|
|
175
|
+
? "Reviewed. Choose an action."
|
|
176
|
+
: `Review ${this.scrollTop + body.length}/${this.bodyRows.length} to enable.`),
|
|
177
|
+
];
|
|
178
|
+
let x = 0;
|
|
179
|
+
const buttonRows = [];
|
|
180
|
+
for (const button of buttons) {
|
|
181
|
+
this.regions.push({
|
|
182
|
+
x: stacked ? 2 : x + 2,
|
|
183
|
+
y: output.length + (stacked ? buttonRows.length : 0),
|
|
184
|
+
width: Math.max(0, visibleWidth(button.text) - 2),
|
|
185
|
+
confirmed: button.confirmed,
|
|
186
|
+
});
|
|
187
|
+
const styled = theme.fg(button.confirmed && !this.reviewed ? "muted" : "accent", button.text);
|
|
188
|
+
if (stacked || buttonRows.length === 0)
|
|
189
|
+
buttonRows.push(styled);
|
|
190
|
+
else
|
|
191
|
+
buttonRows[0] += ` ${styled}`;
|
|
192
|
+
x += visibleWidth(button.text) + 2;
|
|
193
|
+
}
|
|
194
|
+
this.ready = true;
|
|
195
|
+
return [...output, ...buttonRows, ...fixedHints.map((line) => theme.fg("dim", line))].map((line) => truncateToWidth(line, width));
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
//# sourceMappingURL=confirmation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"confirmation.js","sourceRoot":"","sources":["../../../src/extensions/usage/confirmation.ts"],"names":[],"mappings":"AAAA,OAAO,EAGN,sBAAsB,EAGtB,eAAe,EACf,YAAY,EACZ,gBAAgB,GAChB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,aAAa,EAAE,MAAM,wDAAwD,CAAC;AASvF,SAAS,SAAS,CAAC,IAAY;IAC9B,OAAO,sBAAsB,CAAC,IAAI,CAAC,CAAC,OAAO,CAC1C,kFAAkF,EAClF,GAAG,CACH,CAAC;AACH,CAAC;AAED,mGAAmG;AACnG,MAAM,OAAO,0BAA0B;IAC7B,OAAO,CAAqC;IACpC,KAAK,CAAQ;IACb,WAAW,CAAqB;IAChC,IAAI,CAA+B;IACnC,aAAa,CAAa;IAC1B,SAAS,CAAe;IACjC,QAAQ,GAAG,KAAK,CAAC;IACjB,eAAe,GAAG,KAAK,CAAC;IACxB,SAAS,GAAG,CAAC,CAAC;IACd,eAAe,GAAG,CAAC,CAAC;IACpB,cAAc,GAAG,CAAC,CAAC;IACnB,QAAQ,GAAa,EAAE,CAAC;IACxB,aAAa,GAAG,CAAC,CAAC;IAClB,cAAc,GAAG,CAAC,CAAC;IACnB,KAAK,GAAG,KAAK,CAAC;IACd,QAAQ,GAAG,KAAK,CAAC;IACjB,OAAO,GAAkE,EAAE,CAAC;IAEpF,YACC,KAAY,EACZ,WAA+B,EAC/B,OAAiC,EACjC,IAAkC,EAClC,aAAyB,EACzB,SAAuB;QAEvB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC;YAC5B,KA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AE,MAAM,CAAC,MAAM,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;gBACpD,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;gBACjD,SAAS,EAAE,MAAM,CAAC,SAAS;aAC3B,CAAC,CAAC;YACH,MAAM,MAAM,GAAG,KAAK,CAAC,EAAE,CAAC,MAAM,CAAC,SAAS,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;YAC9F,IAAI,OAAO,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC;gBAAE,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;;gBAC3D,UAAU,CAAC,CAAC,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;YACpC,CAAC,IAAI,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACpC,CAAC;QACD,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,OAAO,CAAC,GAAG,MAAM,EAAE,GAAG,UAAU,EAAE,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAClG,eAAe,CAAC,IAAI,EAAE,KAAK,CAAC,CAC5B,CAAC;IACH,CAAC;CACD","sourcesContent":["import {\n\ttype Component,\n\ttype Keybinding,\n\tstripTerminalSequences,\n\ttype TuiMouseEvent,\n\ttype TuiMouseEventResult,\n\ttruncateToWidth,\n\tvisibleWidth,\n\twrapTextWithAnsi,\n} from \"@earendil-works/pi-tui\";\nimport type { KeybindingsManager } from \"../../core/keybindings.ts\";\nimport { formatKeyText } from \"../../modes/interactive/components/keybinding-hints.ts\";\nimport type { Theme } from \"../../modes/interactive/theme/theme.ts\";\n\nexport interface UsageConfirmationOptions {\n\ttitle: string;\n\tbody: readonly string[];\n\tconfirmLabel: string;\n}\n\nfunction plainText(text: string): string {\n\treturn stripTerminalSequences(text).replace(\n\t\t/[\\u0000-\\u0009\\u000b\\u000c\\u000e-\\u001f\\u007f-\\u009f\\u202a-\\u202e\\u2066-\\u2069]/g,\n\t\t\" \",\n\t);\n}\n\n/** Account-bound content is supplied by the caller; this component performs no provider action. */\nexport class UsageConfirmationComponent implements Component {\n\treadonly options: Readonly<UsageConfirmationOptions>;\n\tprivate readonly theme: Theme;\n\tprivate readonly keybindings: KeybindingsManager;\n\tprivate readonly done: (confirmed: boolean) => void;\n\tprivate readonly requestRender: () => void;\n\tprivate readonly getHeight: () => number;\n\tprivate disposed = false;\n\tprivate confirmSelected = false;\n\tprivate scrollTop = 0;\n\tprivate reviewedThrough = 0;\n\tprivate viewportHeight = 0;\n\tprivate bodyRows: string[] = [];\n\tprivate renderedWidth = 0;\n\tprivate renderedHeight = 0;\n\tprivate ready = false;\n\tprivate reviewed = false;\n\tprivate regions: { x: number; y: number; width: number; confirmed: boolean }[] = [];\n\n\tconstructor(\n\t\ttheme: Theme,\n\t\tkeybindings: KeybindingsManager,\n\t\toptions: UsageConfirmationOptions,\n\t\tdone: (confirmed: boolean) => void,\n\t\trequestRender: () => void,\n\t\tgetHeight: () => number,\n\t) {\n\t\tthis.theme = theme;\n\t\tthis.keybindings = keybindings;\n\t\tthis.options = Object.freeze({\n\t\t\ttitle: plainText(options.title),\n\t\t\tbody: Object.freeze(options.body.map(plainText)),\n\t\t\tconfirmLabel: plainText(options.confirmLabel),\n\t\t});\n\t\tthis.done = done;\n\t\tthis.requestRender = requestRender;\n\t\tthis.getHeight = getHeight;\n\t}\n\n\tprivate height(): number {\n\t\tconst height = this.getHeight();\n\t\treturn Number.isFinite(height) ? Math.max(0, Math.floor(height)) : 0;\n\t}\n\n\tprivate finish(confirmed: boolean): void {\n\t\tif (this.disposed) return;\n\t\tthis.disposed = true;\n\t\tthis.regions = [];\n\t\tthis.done(confirmed);\n\t}\n\n\tdispose(): void {\n\t\tthis.finish(false);\n\t}\n\n\tinvalidate(): void {\n\t\tif (this.disposed) return;\n\t\tthis.ready = false;\n\t\tthis.regions = [];\n\t}\n\n\tprivate canConfirm(): boolean {\n\t\treturn this.ready && this.reviewed && this.renderedHeight === this.height();\n\t}\n\n\tprivate scrollBy(delta: number): boolean {\n\t\t// Do not let coalesced input skip text that has never appeared in a rendered frame.\n\t\tconst max = Math.min(this.reviewedThrough, Math.max(0, this.bodyRows.length - this.viewportHeight));\n\t\tconst next = Math.max(0, Math.min(max, this.scrollTop + Math.trunc(delta)));\n\t\tif (!Number.isFinite(next) || next === this.scrollTop) return false;\n\t\tthis.scrollTop = next;\n\t\tthis.invalidate();\n\t\tthis.requestRender();\n\t\treturn true;\n\t}\n\n\thandleInput(data: string): void {\n\t\tif (this.disposed) return;\n\t\tconst kb = this.keybindings;\n\t\tif (kb.matches(data, \"tui.select.cancel\") || kb.matches(data, \"app.clear\")) this.finish(false);\n\t\telse if (kb.matches(data, \"tui.select.confirm\")) {\n\t\t\tif (!this.confirmSelected) this.finish(false);\n\t\t\telse if (this.canConfirm()) this.finish(true);\n\t\t} else if (kb.matches(data, \"app.usage.nextTab\") || kb.matches(data, \"app.usage.previousTab\")) {\n\t\t\tthis.confirmSelected = !this.confirmSelected;\n\t\t\tthis.requestRender();\n\t\t} else if (kb.matches(data, \"tui.select.up\")) this.scrollBy(-1);\n\t\telse if (kb.matches(data, \"tui.select.down\")) this.scrollBy(1);\n\t\telse if (kb.matches(data, \"tui.select.pageUp\")) this.scrollBy(-this.viewportHeight);\n\t\telse if (kb.matches(data, \"tui.select.pageDown\")) this.scrollBy(this.viewportHeight);\n\t}\n\n\thandleMouse(event: TuiMouseEvent): TuiMouseEventResult {\n\t\tif (this.disposed || !this.ready || event.width !== this.renderedWidth || this.height() !== this.renderedHeight)\n\t\t\treturn { handled: true, render: false };\n\t\tif (\n\t\t\tevent.type === \"wheel\" &&\n\t\t\tevent.x >= 0 &&\n\t\t\tevent.x < this.renderedWidth &&\n\t\t\tevent.y >= 1 &&\n\t\t\tevent.y < 1 + this.viewportHeight\n\t\t) {\n\t\t\treturn { handled: true, render: this.scrollBy(event.wheelDelta ?? 0), focus: true };\n\t\t}\n\t\tif (event.type !== \"click\" || event.button !== \"left\") return { handled: true, render: false };\n\t\tconst region = this.regions.find(\n\t\t\t(item) => event.y === item.y && event.x >= item.x && event.x < item.x + item.width,\n\t\t);\n\t\tif (region && (!region.confirmed || this.canConfirm())) this.finish(region.confirmed);\n\t\treturn { handled: true, render: false };\n\t}\n\n\tprivate key(action: Keybinding): string {\n\t\tconst key = this.keybindings.getKeys(action)[0];\n\t\treturn key ? formatKeyText(key) : \"\";\n\t}\n\n\trender(width: number): string[] {\n\t\tif (this.disposed) return [];\n\t\tthis.regions = [];\n\t\tthis.ready = false;\n\t\twidth = Number.isFinite(width) ? Math.max(0, Math.floor(width)) : 0;\n\t\tconst height = this.height();\n\t\tif (width !== this.renderedWidth || height !== this.renderedHeight) {\n\t\t\tthis.scrollTop = 0;\n\t\t\tthis.reviewedThrough = 0;\n\t\t}\n\t\tthis.renderedWidth = width;\n\t\tthis.renderedHeight = height;\n\t\tthis.reviewed = false;\n\t\tif (width === 0 || height === 0) return [];\n\t\tconst theme = this.theme;\n\t\tconst buttons = [\"Cancel\", this.options.confirmLabel].map((label, index) => ({\n\t\t\tconfirmed: index === 1,\n\t\t\ttext: `${this.confirmSelected === (index === 1) ? \">\" : \" \"} [${truncateToWidth(label.replace(/[\\r\\n]/g, \" \"), Math.max(0, width - 4), \"…\")}]`,\n\t\t}));\n\t\tconst stacked = buttons.reduce((total, button) => total + visibleWidth(button.text), 2) > width;\n\t\tconst buttonHeight = stacked ? 2 : 1;\n\t\tconst pair = (...actions: Keybinding[]): string =>\n\t\t\tactions\n\t\t\t\t.map((action) => this.key(action))\n\t\t\t\t.filter(Boolean)\n\t\t\t\t.join(\"/\");\n\t\tconst hints = [\n\t\t\t[pair(\"tui.select.up\", \"tui.select.down\"), \"scroll\"],\n\t\t\t[pair(\"tui.select.pageUp\", \"tui.select.pageDown\"), \"page\"],\n\t\t\t[pair(\"app.usage.nextTab\", \"app.usage.previousTab\"), \"choose\"],\n\t\t\t[this.key(\"tui.select.confirm\"), \"select\"],\n\t\t\t[pair(\"tui.select.cancel\", \"app.clear\"), \"cancel\"],\n\t\t]\n\t\t\t.filter(([key]) => key)\n\t\t\t.map(([key, label]) => `${key} ${label}`);\n\t\tconst hintRows = wrapTextWithAnsi(hints.join(\" · \"), width);\n\t\tconst fixedHints = hintRows.slice(0, Math.max(0, height - buttonHeight - 5));\n\t\tthis.bodyRows = [\n\t\t\t...(/[\\r\\n]/.test(this.options.title) || visibleWidth(this.options.title) > width ? [this.options.title] : []),\n\t\t\t...this.options.body,\n\t\t\t`Action: ${this.options.confirmLabel}`,\n\t\t\t...hintRows.slice(fixedHints.length),\n\t\t].flatMap((line) => wrapTextWithAnsi(line, width));\n\t\tthis.viewportHeight = Math.max(0, height - 2 - buttonHeight - fixedHints.length);\n\t\tif (height < 6 || width < 12 || this.viewportHeight < 1) {\n\t\t\treturn buttons.map((button) => truncateToWidth(theme.fg(\"muted\", button.text), width)).slice(0, height);\n\t\t}\n\t\tthis.scrollTop = Math.min(this.scrollTop, Math.max(0, this.bodyRows.length - this.viewportHeight));\n\t\tconst body = this.bodyRows.slice(this.scrollTop, this.scrollTop + this.viewportHeight);\n\t\tthis.reviewedThrough = Math.max(this.reviewedThrough, this.scrollTop + body.length);\n\t\tthis.reviewed =\n\t\t\tthis.reviewedThrough === this.bodyRows.length && this.bodyRows.every((row) => visibleWidth(row) <= width);\n\t\tconst output = [\n\t\t\ttheme.bold(truncateToWidth(this.options.title.replace(/[\\r\\n]/g, \" \"), width, \"…\")),\n\t\t\t...body,\n\t\t\t...Array.from({ length: Math.max(0, this.viewportHeight - body.length) }, () => \"\"),\n\t\t\ttheme.fg(\n\t\t\t\tthis.reviewed ? \"success\" : \"warning\",\n\t\t\t\tthis.reviewed\n\t\t\t\t\t? \"Reviewed. Choose an action.\"\n\t\t\t\t\t: `Review ${this.scrollTop + body.length}/${this.bodyRows.length} to enable.`,\n\t\t\t),\n\t\t];\n\t\tlet x = 0;\n\t\tconst buttonRows: string[] = [];\n\t\tfor (const button of buttons) {\n\t\t\tthis.regions.push({\n\t\t\t\tx: stacked ? 2 : x + 2,\n\t\t\t\ty: output.length + (stacked ? buttonRows.length : 0),\n\t\t\t\twidth: Math.max(0, visibleWidth(button.text) - 2),\n\t\t\t\tconfirmed: button.confirmed,\n\t\t\t});\n\t\t\tconst styled = theme.fg(button.confirmed && !this.reviewed ? \"muted\" : \"accent\", button.text);\n\t\t\tif (stacked || buttonRows.length === 0) buttonRows.push(styled);\n\t\t\telse buttonRows[0] += ` ${styled}`;\n\t\t\tx += visibleWidth(button.text) + 2;\n\t\t}\n\t\tthis.ready = true;\n\t\treturn [...output, ...buttonRows, ...fixedHints.map((line) => theme.fg(\"dim\", line))].map((line) =>\n\t\t\ttruncateToWidth(line, width),\n\t\t);\n\t}\n}\n"]}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* limits from Anthropic's subscription usage endpoint with Claude Code's cached limits as the fallback. It sends no
|
|
5
|
-
* request to any other endpoint.
|
|
2
|
+
* Session usage and saved subscription accounts. Provider reads never switch accounts. An explicit, confirmed Codex
|
|
3
|
+
* action can redeem one exact banked reset; Claude reset and billing actions open the provider's official usage page.
|
|
6
4
|
*/
|
|
7
5
|
import type { ExtensionFactory } from "../../core/extensions/types.ts";
|
|
8
6
|
export interface UsageExtensionOptions {
|
|
9
7
|
/** Home directory holding Claude Code's `.claude.json`. Defaults to the user's home. */
|
|
10
8
|
home?: string;
|
|
9
|
+
/** Browser launcher, injected by tests. No credentials are placed in provider URLs. */
|
|
10
|
+
openUrl?: (url: string) => void;
|
|
11
11
|
}
|
|
12
12
|
export declare function createUsageExtension(options?: UsageExtensionOptions): ExtensionFactory;
|
|
13
13
|
declare const _default: ExtensionFactory;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/extensions/usage/index.ts"],"names":[],"mappings":"AACA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/extensions/usage/index.ts"],"names":[],"mappings":"AACA;;;GAGG;AAKH,OAAO,KAAK,EAAoB,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAuBzF,MAAM,WAAW,qBAAqB;IACrC,wFAAwF;IACxF,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,uFAAuF;IACvF,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;CAChC;AAoED,wBAAgB,oBAAoB,CAAC,OAAO,GAAE,qBAA0B,GAAG,gBAAgB,CA+V1F"}
|