@humain/humain-code 0.4.18 → 0.5.3
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 +284 -1
- package/README.md +3 -1
- package/dist/agent-monitor/client.d.ts +2 -2
- package/dist/agent-monitor/client.d.ts.map +1 -1
- package/dist/agent-monitor/client.js +3 -2
- package/dist/agent-monitor/client.js.map +1 -1
- package/dist/bundle/agent-monitor.js +1 -1
- package/dist/bundle/chunks/anthropic-messages-ZP5KUK52.js +67 -0
- package/dist/bundle/chunks/anthropic.js +10 -9
- package/dist/bundle/chunks/azure-openai-responses-QJFYQ3DF.js +15 -0
- package/dist/bundle/chunks/bedrock-converse-stream.js +152 -200
- package/dist/bundle/chunks/chunk-2GCMACT4.js +1956 -0
- package/dist/bundle/chunks/{chunk-QEF72EIZ.js → chunk-A6B2QMA7.js} +40 -96
- package/dist/bundle/chunks/{chunk-YMBXWW36.js → chunk-AO6FF5JL.js} +9 -8
- package/dist/bundle/chunks/{chunk-OWLBGSXY.js → chunk-CN3Q5UNB.js} +388 -310
- package/dist/bundle/chunks/{chunk-SCIGZFN5.js → chunk-DNGJMRJW.js} +11 -11
- package/dist/bundle/chunks/chunk-DU6POZ7E.js +10 -0
- package/dist/bundle/chunks/chunk-EY3LZOUP.js +1963 -0
- package/dist/bundle/chunks/{chunk-G6ABHCPB.js → chunk-FO2NYB6O.js} +655 -663
- package/dist/bundle/chunks/{chunk-RXOCQRBG.js → chunk-GEISZXXH.js} +1 -1
- package/dist/bundle/chunks/{chunk-OKALNPTJ.js → chunk-HIZWUSPN.js} +24 -24
- package/dist/bundle/chunks/{chunk-MVYV6MJY.js → chunk-HT5YN3LX.js} +1 -1
- package/dist/bundle/chunks/chunk-IDU5BNNI.js +15 -0
- package/dist/bundle/chunks/{chunk-TIFFHHW6.js → chunk-JCXXRCP6.js} +5 -5
- package/dist/bundle/chunks/{chunk-QYCOHSI7.js → chunk-KKCMWB63.js} +8 -7
- package/dist/bundle/chunks/{chunk-L5OUCJ7N.js → chunk-L2VKM23Q.js} +87 -13
- package/dist/bundle/chunks/{chunk-SCBU5WOP.js → chunk-M74U5X4S.js} +30 -23
- package/dist/bundle/chunks/{chunk-AWCJWXGD.js → chunk-MIJHJNNQ.js} +3 -2
- package/dist/bundle/chunks/{chunk-Y26OS23T.js → chunk-N7CQ3UV3.js} +4 -4
- package/dist/bundle/chunks/{chunk-XQZG5HPT.js → chunk-O4DO5RWS.js} +11 -6
- package/dist/bundle/chunks/{chunk-P4UKLIQB.js → chunk-ODJUBJK2.js} +4 -4
- package/dist/bundle/chunks/chunk-OR25QDSS.js +365 -0
- package/dist/bundle/chunks/{chunk-7PRU6YW3.js → chunk-OZNC2W4B.js} +306 -286
- package/dist/bundle/chunks/{chunk-Z33NNMNB.js → chunk-PH7UP57J.js} +1 -1
- package/dist/bundle/chunks/{chunk-HPSQKIWK.js → chunk-PS7DGA7B.js} +1 -1
- package/dist/bundle/chunks/chunk-QW6PTCAB.js +10 -0
- package/dist/bundle/chunks/{chunk-5CDES42D.js → chunk-QWXPGBAG.js} +1 -1
- package/dist/bundle/chunks/{chunk-NCQ6WAQK.js → chunk-ROZV2IYD.js} +1 -1
- package/dist/bundle/chunks/{chunk-3XDL5ZE4.js → chunk-RTXDU3AA.js} +148 -122
- package/dist/bundle/chunks/{chunk-FZUJXM6D.js → chunk-UDB6NI4G.js} +309 -240
- package/dist/bundle/chunks/{chunk-3UXBFT4Q.js → chunk-UJLCKIMZ.js} +1906 -1661
- package/dist/bundle/chunks/chunk-UTNHGOFS.js +88 -0
- package/dist/bundle/chunks/{chunk-H2FY3PEV.js → chunk-V62QBESW.js} +4 -3
- package/dist/bundle/chunks/{chunk-NSMMDV3N.js → chunk-XA7CJAYH.js} +4 -3
- package/dist/bundle/chunks/chunk-XQX7S3GM.js +7 -0
- package/dist/bundle/chunks/{chunk-7VY5IL74.js → chunk-Y3OPKKDR.js} +3 -77
- package/dist/bundle/chunks/chunk-YFOLLX5D.js +23 -0
- package/dist/bundle/chunks/{chunk-YRCLNWFV.js → chunk-ZI7TK7HM.js} +1 -1
- package/dist/bundle/chunks/{chunk-V76YPIMT.js → chunk-ZR4GF4WU.js} +21 -15
- package/dist/bundle/chunks/{cli-2NKM2RNJ.js → cli-ENEFJH2B.js} +1 -1
- package/dist/bundle/chunks/cloudflare-workers-ai-system-one-T7TPP7SQ.js +4 -0
- package/dist/bundle/chunks/codemode-worker.js +27 -27
- package/dist/bundle/chunks/compat-CJBWWYHE.js +13 -0
- package/dist/bundle/chunks/{dist-XVXV2CL4.js → dist-IBUWEKEE.js} +3 -3
- package/dist/bundle/chunks/{dist-ZJIYY3GA.js → dist-RKNCFFGM.js} +452 -448
- package/dist/bundle/chunks/dist-YFMJEHPH.js +8 -0
- package/dist/bundle/chunks/{dist-cjs-AXBW3N4F.js → dist-cjs-HTASUQXQ.js} +82 -80
- package/dist/bundle/chunks/{easter-egg-3d-VGJ77XZQ.js → easter-egg-3d-YOPLCOVW.js} +2 -2
- package/dist/bundle/chunks/es-YEFEOGR3.js +1905 -0
- package/dist/bundle/chunks/{esm-GIR7QH65.js → esm-R6HJ4QEG.js} +5 -5
- package/dist/bundle/chunks/{event-streams-NXFTZDSF.js → event-streams-BR2IL6C5.js} +1 -1
- package/dist/bundle/chunks/{execute-ZBEZNJ4E.js → execute-2JXEKQ2X.js} +17 -8
- package/dist/bundle/chunks/{extract-RFWEHH6W.js → extract-OTCGZGTL.js} +50 -47
- package/dist/bundle/chunks/github-copilot.js +44 -40
- package/dist/bundle/chunks/google-generative-ai-HVPCGIZ6.js +21 -0
- package/dist/bundle/chunks/google-vertex-UM5MAALA.js +25 -0
- package/dist/bundle/chunks/host-ZHEL5XQW.js +2 -0
- package/dist/bundle/chunks/{https-proxy-agent-7CAXVAFH.js → https-proxy-agent-JQICCRPH.js} +1 -1
- package/dist/bundle/chunks/{llama-cpp-classify-AGCW7HYN.js → llama-cpp-classify-B3G57LVR.js} +5 -5
- package/dist/bundle/chunks/{mistral-conversations-G3GN6CMT.js → mistral-conversations-AH72RLXK.js} +11 -11
- package/dist/bundle/chunks/{node-A6SZ3T7E.js → node-SJPZTR4K.js} +190 -190
- package/dist/bundle/chunks/{node-DZCAT4Q6.js → node-VSA4ZN7D.js} +1 -1
- package/dist/bundle/chunks/openai-chatgpt.js +2 -2
- package/dist/bundle/chunks/{openai-codex-responses-FJFDAWHI.js → openai-codex-responses-L366637C.js} +48 -47
- package/dist/bundle/chunks/openai-codex.js +10 -9
- package/dist/bundle/chunks/openai-completions-ZP62QXJX.js +83 -0
- package/dist/bundle/chunks/{openai-decisions-HESOHYZB.js → openai-decisions-WOWUC65P.js} +1 -1
- package/dist/bundle/chunks/openai-responses-DXUGSUTN.js +26 -0
- package/dist/bundle/chunks/openrouter-images-5K47HDAT.js +8 -0
- package/dist/bundle/chunks/openrouter.js +10 -9
- package/dist/bundle/chunks/{pi-messages-SAOV3JNW.js → pi-messages-MOQQDZBK.js} +5 -4
- package/dist/bundle/chunks/radius.js +9 -8
- package/dist/bundle/chunks/{runtime-HJEUOD4R.js → runtime-K3F2QDQP.js} +1 -1
- package/dist/bundle/chunks/typesafe-system-one-43OCHGKP.js +3 -0
- package/dist/bundle/chunks/{undici-4BK3MVJV.js → undici-EK3EUI2E.js} +1 -1
- package/dist/bundle/chunks/virtual-modules-5D6QIJPN.js +5 -0
- package/dist/bundle/cli-runtime.js +3 -3
- package/dist/bundle/flow/package.json +4 -4
- package/dist/bundle/index.js +6 -6
- package/dist/bundle/rpc-entry.js +3 -3
- package/dist/cli/args.d.ts +6 -0
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +11 -0
- package/dist/cli/args.js.map +1 -1
- package/dist/coordination/adapter/tool.d.ts.map +1 -1
- package/dist/coordination/adapter/tool.js +3 -1
- package/dist/coordination/adapter/tool.js.map +1 -1
- package/dist/coordination/broker/broker.d.ts +6 -2
- package/dist/coordination/broker/broker.d.ts.map +1 -1
- package/dist/coordination/broker/broker.js +20 -8
- package/dist/coordination/broker/broker.js.map +1 -1
- package/dist/coordination/client/client.d.ts.map +1 -1
- package/dist/coordination/client/client.js +4 -2
- package/dist/coordination/client/client.js.map +1 -1
- package/dist/coordination/transport/discovery.d.ts +10 -3
- package/dist/coordination/transport/discovery.d.ts.map +1 -1
- package/dist/coordination/transport/discovery.js +18 -5
- package/dist/coordination/transport/discovery.js.map +1 -1
- package/dist/core/agent-session.d.ts +35 -2
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +163 -40
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/anthropic-subscription-usage.d.ts +47 -0
- package/dist/core/anthropic-subscription-usage.d.ts.map +1 -0
- package/dist/core/anthropic-subscription-usage.js +170 -0
- package/dist/core/anthropic-subscription-usage.js.map +1 -0
- package/dist/core/bash-executor.d.ts.map +1 -1
- package/dist/core/bash-executor.js +7 -1
- package/dist/core/bash-executor.js.map +1 -1
- package/dist/core/client-identity.d.ts +13 -0
- package/dist/core/client-identity.d.ts.map +1 -0
- package/dist/core/client-identity.js +25 -0
- package/dist/core/client-identity.js.map +1 -0
- package/dist/core/codex-usage.d.ts +37 -1
- package/dist/core/codex-usage.d.ts.map +1 -1
- package/dist/core/codex-usage.js +104 -11
- package/dist/core/codex-usage.js.map +1 -1
- package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
- package/dist/core/compaction/branch-summarization.js +1 -2
- package/dist/core/compaction/branch-summarization.js.map +1 -1
- package/dist/core/compaction/compaction.d.ts +2 -2
- package/dist/core/compaction/compaction.d.ts.map +1 -1
- package/dist/core/compaction/compaction.js +20 -15
- package/dist/core/compaction/compaction.js.map +1 -1
- package/dist/core/export-html/index.d.ts.map +1 -1
- package/dist/core/export-html/index.js +2 -0
- package/dist/core/export-html/index.js.map +1 -1
- package/dist/core/export-html/template.html +1 -0
- package/dist/core/export-html/template.js +2 -1
- package/dist/core/export-html/vendor/marked-cjk-friendly.min.js +6 -0
- package/dist/core/export-html/vendor/marked.min.js +30 -29
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +3 -0
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +14 -0
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +86 -2
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/virtual-modules.d.ts.map +1 -1
- package/dist/core/extensions/virtual-modules.js +3 -0
- package/dist/core/extensions/virtual-modules.js.map +1 -1
- package/dist/core/model-config.d.ts +920 -0
- package/dist/core/model-config.d.ts.map +1 -1
- package/dist/core/model-config.js +48 -24
- package/dist/core/model-config.js.map +1 -1
- package/dist/core/model-registry.d.ts +18 -0
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +20 -0
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +33 -7
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/model-runtime.d.ts +9 -0
- package/dist/core/model-runtime.d.ts.map +1 -1
- package/dist/core/model-runtime.js +123 -14
- package/dist/core/model-runtime.js.map +1 -1
- package/dist/core/output-guard.d.ts +13 -1
- package/dist/core/output-guard.d.ts.map +1 -1
- package/dist/core/output-guard.js +101 -11
- package/dist/core/output-guard.js.map +1 -1
- package/dist/core/provider-composer.d.ts +2 -1
- package/dist/core/provider-composer.d.ts.map +1 -1
- package/dist/core/provider-composer.js +7 -3
- package/dist/core/provider-composer.js.map +1 -1
- package/dist/core/remote-catalog-provider.d.ts.map +1 -1
- package/dist/core/remote-catalog-provider.js +7 -2
- package/dist/core/remote-catalog-provider.js.map +1 -1
- package/dist/core/safe-credential-error.d.ts +11 -0
- package/dist/core/safe-credential-error.d.ts.map +1 -0
- package/dist/core/safe-credential-error.js +14 -0
- package/dist/core/safe-credential-error.js.map +1 -0
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +12 -10
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-manager.d.ts +4 -0
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +242 -26
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/settings-schema.d.ts +3 -0
- package/dist/core/settings-schema.d.ts.map +1 -1
- package/dist/core/settings-schema.js +6 -0
- package/dist/core/settings-schema.js.map +1 -1
- package/dist/core/system-prompt.d.ts +6 -1
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +93 -1
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/tools/grep.d.ts.map +1 -1
- package/dist/core/tools/grep.js +3 -1
- package/dist/core/tools/grep.js.map +1 -1
- package/dist/core/tools/ls.d.ts.map +1 -1
- package/dist/core/tools/ls.js +37 -12
- package/dist/core/tools/ls.js.map +1 -1
- package/dist/extensions/codemode/execute.d.ts.map +1 -1
- package/dist/extensions/codemode/execute.js +102 -24
- package/dist/extensions/codemode/execute.js.map +1 -1
- package/dist/extensions/index.d.ts.map +1 -1
- package/dist/extensions/index.js +3 -1
- package/dist/extensions/index.js.map +1 -1
- package/dist/extensions/mcp/config.d.ts.map +1 -1
- package/dist/extensions/mcp/config.js +3 -2
- package/dist/extensions/mcp/config.js.map +1 -1
- package/dist/extensions/usage/index.d.ts +15 -0
- package/dist/extensions/usage/index.d.ts.map +1 -0
- package/dist/extensions/usage/index.js +110 -0
- package/dist/extensions/usage/index.js.map +1 -0
- package/dist/extensions/usage/overview.d.ts +90 -0
- package/dist/extensions/usage/overview.d.ts.map +1 -0
- package/dist/extensions/usage/overview.js +215 -0
- package/dist/extensions/usage/overview.js.map +1 -0
- package/dist/extensions/usage/popup.d.ts +21 -0
- package/dist/extensions/usage/popup.d.ts.map +1 -0
- package/dist/extensions/usage/popup.js +98 -0
- package/dist/extensions/usage/popup.js.map +1 -0
- package/dist/humain/bedrock-provider/vendor/index.bundle.mjs +21 -2
- package/dist/humain/bundled-extension-names.d.ts +6 -0
- package/dist/humain/bundled-extension-names.d.ts.map +1 -0
- package/dist/humain/bundled-extension-names.js +9 -0
- package/dist/humain/bundled-extension-names.js.map +1 -0
- package/dist/humain/gateway/catalog.d.ts +36 -0
- package/dist/humain/gateway/catalog.d.ts.map +1 -0
- package/dist/humain/gateway/catalog.js +74 -0
- package/dist/humain/gateway/catalog.js.map +1 -0
- package/dist/humain/gateway/client.d.ts +58 -0
- package/dist/humain/gateway/client.d.ts.map +1 -0
- package/dist/humain/gateway/client.js +212 -0
- package/dist/humain/gateway/client.js.map +1 -0
- package/dist/humain/gateway/constants.d.ts +23 -0
- package/dist/humain/gateway/constants.d.ts.map +1 -0
- package/dist/humain/gateway/constants.js +32 -0
- package/dist/humain/gateway/constants.js.map +1 -0
- package/dist/humain/gateway/http.d.ts +18 -0
- package/dist/humain/gateway/http.d.ts.map +1 -0
- package/dist/humain/gateway/http.js +274 -0
- package/dist/humain/gateway/http.js.map +1 -0
- package/dist/humain/gateway/login.d.ts +13 -0
- package/dist/humain/gateway/login.d.ts.map +1 -0
- package/dist/humain/gateway/login.js +121 -0
- package/dist/humain/gateway/login.js.map +1 -0
- package/dist/humain/gateway/provider.d.ts +34 -0
- package/dist/humain/gateway/provider.d.ts.map +1 -0
- package/dist/humain/gateway/provider.js +253 -0
- package/dist/humain/gateway/provider.js.map +1 -0
- package/dist/humain/gateway/secret-store.d.ts +19 -0
- package/dist/humain/gateway/secret-store.d.ts.map +1 -0
- package/dist/humain/gateway/secret-store.js +252 -0
- package/dist/humain/gateway/secret-store.js.map +1 -0
- package/dist/humain/gateway/session-store.d.ts +42 -0
- package/dist/humain/gateway/session-store.d.ts.map +1 -0
- package/dist/humain/gateway/session-store.js +175 -0
- package/dist/humain/gateway/session-store.js.map +1 -0
- package/dist/humain/index.d.ts +2 -2
- package/dist/humain/index.d.ts.map +1 -1
- package/dist/humain/index.js +5 -2
- package/dist/humain/index.js.map +1 -1
- package/dist/humain/login-menu.d.ts +14 -0
- package/dist/humain/login-menu.d.ts.map +1 -0
- package/dist/humain/login-menu.js +21 -0
- package/dist/humain/login-menu.js.map +1 -0
- package/dist/humain/node-http.d.ts.map +1 -1
- package/dist/humain/node-http.js +6 -31
- package/dist/humain/node-http.js.map +1 -1
- package/dist/humain/redact-assistant-message.d.ts +4 -0
- package/dist/humain/redact-assistant-message.d.ts.map +1 -0
- package/dist/humain/redact-assistant-message.js +34 -0
- package/dist/humain/redact-assistant-message.js.map +1 -0
- package/dist/humain/web-access/vendor/anysearch.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/anysearch.js +3 -3
- package/dist/humain/web-access/vendor/anysearch.js.map +1 -1
- package/dist/humain/web-access/vendor/bocha.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/bocha.js +3 -3
- package/dist/humain/web-access/vendor/bocha.js.map +1 -1
- package/dist/humain/web-access/vendor/brightdata-unlocker.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/brightdata-unlocker.js +2 -2
- package/dist/humain/web-access/vendor/brightdata-unlocker.js.map +1 -1
- package/dist/humain/web-access/vendor/brightdata.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/brightdata.js +3 -3
- package/dist/humain/web-access/vendor/brightdata.js.map +1 -1
- package/dist/humain/web-access/vendor/ceramic.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/ceramic.js +2 -2
- package/dist/humain/web-access/vendor/ceramic.js.map +1 -1
- package/dist/humain/web-access/vendor/curator-page.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/curator-page.js +3 -1
- package/dist/humain/web-access/vendor/curator-page.js.map +1 -1
- package/dist/humain/web-access/vendor/curator-server.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/curator-server.js +2 -0
- package/dist/humain/web-access/vendor/curator-server.js.map +1 -1
- package/dist/humain/web-access/vendor/deepseek.d.ts +11 -1
- package/dist/humain/web-access/vendor/deepseek.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/deepseek.js +170 -5
- package/dist/humain/web-access/vendor/deepseek.js.map +1 -1
- package/dist/humain/web-access/vendor/extract.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/extract.js +63 -6
- package/dist/humain/web-access/vendor/extract.js.map +1 -1
- package/dist/humain/web-access/vendor/gemini-search.d.ts +5 -3
- package/dist/humain/web-access/vendor/gemini-search.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/gemini-search.js +33 -7
- package/dist/humain/web-access/vendor/gemini-search.js.map +1 -1
- package/dist/humain/web-access/vendor/index.d.ts +1 -0
- package/dist/humain/web-access/vendor/index.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/index.js +18 -3
- package/dist/humain/web-access/vendor/index.js.map +1 -1
- package/dist/humain/web-access/vendor/jina-search.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/jina-search.js +6 -4
- package/dist/humain/web-access/vendor/jina-search.js.map +1 -1
- package/dist/humain/web-access/vendor/kagi.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/kagi.js +4 -4
- package/dist/humain/web-access/vendor/kagi.js.map +1 -1
- package/dist/humain/web-access/vendor/keenable.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/keenable.js +2 -2
- package/dist/humain/web-access/vendor/keenable.js.map +1 -1
- package/dist/humain/web-access/vendor/linkup.d.ts +6 -0
- package/dist/humain/web-access/vendor/linkup.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/linkup.js +167 -0
- package/dist/humain/web-access/vendor/linkup.js.map +1 -0
- package/dist/humain/web-access/vendor/mistral-search.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/mistral-search.js +3 -3
- package/dist/humain/web-access/vendor/mistral-search.js.map +1 -1
- package/dist/humain/web-access/vendor/ollama.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/ollama.js +4 -4
- package/dist/humain/web-access/vendor/ollama.js.map +1 -1
- package/dist/humain/web-access/vendor/parallel.js +6 -7
- package/dist/humain/web-access/vendor/parallel.js.map +1 -1
- package/dist/humain/web-access/vendor/perplexity.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/perplexity.js +4 -3
- package/dist/humain/web-access/vendor/perplexity.js.map +1 -1
- package/dist/humain/web-access/vendor/querit.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/querit.js +3 -3
- package/dist/humain/web-access/vendor/querit.js.map +1 -1
- package/dist/humain/web-access/vendor/search1api.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/search1api.js +3 -3
- package/dist/humain/web-access/vendor/search1api.js.map +1 -1
- package/dist/humain/web-access/vendor/searchinfinity.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/searchinfinity.js +3 -3
- package/dist/humain/web-access/vendor/searchinfinity.js.map +1 -1
- package/dist/humain/web-access/vendor/serpapi.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/serpapi.js +6 -5
- package/dist/humain/web-access/vendor/serpapi.js.map +1 -1
- package/dist/humain/web-access/vendor/serpbase.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/serpbase.js +4 -4
- package/dist/humain/web-access/vendor/serpbase.js.map +1 -1
- package/dist/humain/web-access/vendor/serpdive.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/serpdive.js +3 -3
- package/dist/humain/web-access/vendor/serpdive.js.map +1 -1
- package/dist/humain/web-access/vendor/serper.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/serper.js +5 -4
- package/dist/humain/web-access/vendor/serper.js.map +1 -1
- package/dist/humain/web-access/vendor/serply.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/serply.js +2 -2
- package/dist/humain/web-access/vendor/serply.js.map +1 -1
- package/dist/humain/web-access/vendor/utils.d.ts +3 -1
- package/dist/humain/web-access/vendor/utils.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/utils.js +27 -2
- package/dist/humain/web-access/vendor/utils.js.map +1 -1
- package/dist/humain/web-access/vendor/valyu.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/valyu.js +3 -3
- package/dist/humain/web-access/vendor/valyu.js.map +1 -1
- package/dist/humain/web-access/vendor/web-tool-core.d.ts +2 -0
- package/dist/humain/web-access/vendor/web-tool-core.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/web-tool-core.js +3 -0
- package/dist/humain/web-access/vendor/web-tool-core.js.map +1 -1
- package/dist/humain/web-access/vendor/xai-search.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/xai-search.js +51 -8
- package/dist/humain/web-access/vendor/xai-search.js.map +1 -1
- package/dist/humain/web-access/vendor/xcrawl.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/xcrawl.js +3 -3
- package/dist/humain/web-access/vendor/xcrawl.js.map +1 -1
- package/dist/humain/web-access/vendor/you.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/you.js +2 -2
- package/dist/humain/web-access/vendor/you.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +32 -6
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/assistant-message.d.ts +14 -2
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/assistant-message.js +62 -7
- package/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/dist/modes/interactive/components/config-selector.js +1 -1
- package/dist/modes/interactive/components/config-selector.js.map +1 -1
- package/dist/modes/interactive/components/custom-editor.d.ts +2 -0
- package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
- package/dist/modes/interactive/components/custom-editor.js +6 -1
- package/dist/modes/interactive/components/custom-editor.js.map +1 -1
- package/dist/modes/interactive/components/easter-egg-3d.js +1 -1
- package/dist/modes/interactive/components/easter-egg-3d.js.map +1 -1
- package/dist/modes/interactive/components/footer.d.ts +10 -2
- package/dist/modes/interactive/components/footer.d.ts.map +1 -1
- package/dist/modes/interactive/components/footer.js +141 -66
- package/dist/modes/interactive/components/footer.js.map +1 -1
- package/dist/modes/interactive/components/login-dialog.d.ts +1 -1
- package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
- package/dist/modes/interactive/components/login-dialog.js +3 -2
- package/dist/modes/interactive/components/login-dialog.js.map +1 -1
- package/dist/modes/interactive/components/mermaid.d.ts.map +1 -1
- package/dist/modes/interactive/components/mermaid.js +16 -3
- package/dist/modes/interactive/components/mermaid.js.map +1 -1
- package/dist/modes/interactive/components/model-selector.d.ts +11 -0
- package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/model-selector.js +17 -4
- package/dist/modes/interactive/components/model-selector.js.map +1 -1
- package/dist/modes/interactive/components/radius-login-selector.d.ts +5 -4
- package/dist/modes/interactive/components/radius-login-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/radius-login-selector.js +11 -9
- package/dist/modes/interactive/components/radius-login-selector.js.map +1 -1
- package/dist/modes/interactive/components/themed-text.d.ts.map +1 -1
- package/dist/modes/interactive/components/themed-text.js +3 -2
- package/dist/modes/interactive/components/themed-text.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +17 -6
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/components/user-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/user-message.js +3 -2
- package/dist/modes/interactive/components/user-message.js.map +1 -1
- package/dist/modes/interactive/components/visual-truncate.d.ts.map +1 -1
- package/dist/modes/interactive/components/visual-truncate.js +4 -2
- package/dist/modes/interactive/components/visual-truncate.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +15 -17
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +143 -158
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/print-mode.d.ts.map +1 -1
- package/dist/modes/print-mode.js +2 -5
- package/dist/modes/print-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-mode.js +2 -3
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/dist/package-manager-cli.d.ts.map +1 -1
- package/dist/package-manager-cli.js +2 -1
- package/dist/package-manager-cli.js.map +1 -1
- package/dist/utils/child-process.d.ts.map +1 -1
- package/dist/utils/child-process.js +3 -2
- package/dist/utils/child-process.js.map +1 -1
- package/dist/utils/clipboard-command.d.ts.map +1 -1
- package/dist/utils/clipboard-command.js +3 -0
- package/dist/utils/clipboard-command.js.map +1 -1
- package/dist/utils/pi-user-agent.d.ts +1 -0
- package/dist/utils/pi-user-agent.d.ts.map +1 -1
- package/dist/utils/pi-user-agent.js +3 -2
- package/dist/utils/pi-user-agent.js.map +1 -1
- package/dist/utils/shell.d.ts.map +1 -1
- package/dist/utils/shell.js +45 -13
- package/dist/utils/shell.js.map +1 -1
- package/dist/utils/sleep.d.ts +1 -1
- package/dist/utils/sleep.d.ts.map +1 -1
- package/dist/utils/sleep.js +10 -6
- package/dist/utils/sleep.js.map +1 -1
- package/dist/utils/tools-manager.d.ts.map +1 -1
- package/dist/utils/tools-manager.js +4 -3
- package/dist/utils/tools-manager.js.map +1 -1
- package/docs/codemode.md +2 -2
- package/docs/compaction.md +3 -3
- package/docs/coordination.md +1 -1
- package/docs/custom-provider.md +53 -1
- package/docs/docs.json +4 -0
- package/docs/environment-variables.md +2 -0
- package/docs/extensions.md +133 -10
- package/docs/humain-code.md +13 -1
- package/docs/index.md +1 -1
- package/docs/models-configuration.md +197 -0
- package/docs/models.md +24 -6
- package/docs/providers.md +58 -2
- package/docs/quickstart.md +8 -1
- package/docs/settings.md +1 -1
- package/docs/slash-commands.md +10 -0
- package/docs/tui.md +70 -0
- package/docs/windows.md +16 -2
- package/examples/extensions/custom-provider-anthropic/package.json +2 -2
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/gondolin/package-lock.json +2 -2
- package/examples/extensions/gondolin/package.json +1 -1
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/examples/plugins/pi-example-plugin/package.json +2 -2
- package/npm-shrinkwrap.json +243 -219
- package/package.json +21 -20
- package/schemas/models.schema.json +84 -30
- package/schemas/settings.schema.json +19 -0
- package/src/coordination/UPSTREAM.md +36 -3
- package/src/coordination/upstream.json +3 -3
- package/src/humain/web-access/UPSTREAM.md +72 -1
- package/src/humain/web-access/upstream.json +5 -4
- package/dist/bundle/chunks/anthropic-messages-TSNY5MWH.js +0 -67
- package/dist/bundle/chunks/azure-openai-responses-Z4DCXO2G.js +0 -15
- package/dist/bundle/chunks/chunk-26EAEXO5.js +0 -167
- package/dist/bundle/chunks/chunk-2ZFUMXOZ.js +0 -1790
- package/dist/bundle/chunks/chunk-5K5RFXXO.js +0 -74
- package/dist/bundle/chunks/chunk-PY7SOXCA.js +0 -10
- package/dist/bundle/chunks/chunk-UGJAAWNC.js +0 -7
- package/dist/bundle/chunks/chunk-UGXYG7HN.js +0 -22
- package/dist/bundle/chunks/chunk-VEYTRNQC.js +0 -5
- package/dist/bundle/chunks/chunk-X3O5MCKJ.js +0 -7
- package/dist/bundle/chunks/chunk-YLYOJQQX.js +0 -1951
- package/dist/bundle/chunks/cloudflare-workers-ai-system-one-MUJQ6LT2.js +0 -4
- package/dist/bundle/chunks/compat-VDGEZSVM.js +0 -13
- package/dist/bundle/chunks/dist-LKDZAEUQ.js +0 -7
- package/dist/bundle/chunks/es-N6YFJOD7.js +0 -1901
- package/dist/bundle/chunks/google-generative-ai-4OVYRP24.js +0 -21
- package/dist/bundle/chunks/google-vertex-3WQAZJQD.js +0 -25
- package/dist/bundle/chunks/host-63SNKK5Y.js +0 -2
- package/dist/bundle/chunks/openai-completions-IC7WRLTI.js +0 -82
- package/dist/bundle/chunks/openai-responses-XXCYDFSM.js +0 -24
- package/dist/bundle/chunks/openrouter-images-DT2HMZNO.js +0 -8
- package/dist/bundle/chunks/typesafe-system-one-HCMGHK6A.js +0 -2
- package/dist/bundle/chunks/virtual-modules-CFJTDIXL.js +0 -5
- package/dist/core/provider-attribution.d.ts +0 -4
- package/dist/core/provider-attribution.d.ts.map +0 -1
- package/dist/core/provider-attribution.js +0 -85
- package/dist/core/provider-attribution.js.map +0 -1
- /package/dist/bundle/chunks/{chunk-WZMA7HAJ.js → chunk-XQRYOCHA.js} +0 -0
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
// Derived from Pi-Bolt (MIT, Copyright (c) 2026 OpenSec (Pi-Bolt)), commit a6df6a2c; modified for HUMAIN Code CLI.
|
|
2
|
+
/**
|
|
3
|
+
* The `/usage` command as a built-in extension: session tokens, cost and context, plus subscription limits: every limit
|
|
4
|
+
* window of the active OpenAI Codex account (the usage route /accounts reads) and, for a Claude subscription, live
|
|
5
|
+
* limits from Anthropic's subscription usage endpoint with Claude Code's cached limits as the fallback. It sends no
|
|
6
|
+
* request to any other endpoint.
|
|
7
|
+
*/
|
|
8
|
+
import { addUsageToTotals, createUsageTotals, getSessionUsage } from "../../core/usage-totals.js";
|
|
9
|
+
import { buildUsageOverview, CLAUDE_UNAVAILABLE, claudeUsageBars, codexUsageBars, formatAge, readClaudeCachedUsage, } from "./overview.js";
|
|
10
|
+
import { UsagePopupComponent } from "./popup.js";
|
|
11
|
+
const FETCH_TIMEOUT_MS = 10_000;
|
|
12
|
+
/** Subscription limits of the selected model's account, and lines explaining where they come from. */
|
|
13
|
+
async function accountLimits(ctx, providerId, options) {
|
|
14
|
+
if (providerId === "anthropic") {
|
|
15
|
+
let live;
|
|
16
|
+
let liveError;
|
|
17
|
+
try {
|
|
18
|
+
live = await ctx.modelRegistry.getAnthropicUsage({ signal: AbortSignal.timeout(FETCH_TIMEOUT_MS) });
|
|
19
|
+
liveError =
|
|
20
|
+
live === undefined
|
|
21
|
+
? "No active Claude account. Run /login."
|
|
22
|
+
: live.status === "unavailable"
|
|
23
|
+
? CLAUDE_UNAVAILABLE[live.reason]
|
|
24
|
+
: "Claude reported no usage limits.";
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
liveError = "Claude usage is unavailable.";
|
|
28
|
+
}
|
|
29
|
+
const now = Date.now();
|
|
30
|
+
if (live?.status === "ok" && live.windows.length > 0) {
|
|
31
|
+
return {
|
|
32
|
+
bars: claudeUsageBars(live.windows, now),
|
|
33
|
+
lines: [{ label: "limits", value: `live from Anthropic, fetched ${formatAge(now - live.fetchedAt)} ago` }],
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
// Live usage is unavailable: fall back to Claude Code's cached copy, and name the live failure only if that fails too.
|
|
37
|
+
const claude = await readClaudeCachedUsage(options.home, now);
|
|
38
|
+
if ("error" in claude || claude.bars.length === 0) {
|
|
39
|
+
const cacheError = "error" in claude ? claude.error : "No cached Claude Code usage in ~/.claude.json.";
|
|
40
|
+
return {
|
|
41
|
+
lines: [
|
|
42
|
+
{ label: "limits", value: liveError, tone: "error" },
|
|
43
|
+
{ label: "cached", value: cacheError, tone: "warning" },
|
|
44
|
+
],
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
const age = claude.fetchedAtMs === undefined ? "age unknown" : `from ${formatAge(now - claude.fetchedAtMs)} ago`;
|
|
48
|
+
return { bars: claude.bars, lines: [{ label: "limits", value: `Claude Code's cached numbers, ${age}` }] };
|
|
49
|
+
}
|
|
50
|
+
if (providerId === "openai-codex") {
|
|
51
|
+
let codex;
|
|
52
|
+
try {
|
|
53
|
+
codex = codexUsageBars(await ctx.modelRegistry.getCodexUsage({ signal: AbortSignal.timeout(FETCH_TIMEOUT_MS) }));
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
codex = { error: "Codex usage is unavailable." };
|
|
57
|
+
}
|
|
58
|
+
if ("error" in codex)
|
|
59
|
+
return { lines: [{ label: "limits", value: codex.error, tone: "error" }] };
|
|
60
|
+
return { bars: codex.bars, lines: [{ label: "limits", value: "active Codex account" }, ...codex.lines] };
|
|
61
|
+
}
|
|
62
|
+
return { lines: [] };
|
|
63
|
+
}
|
|
64
|
+
export function createUsageExtension(options = {}) {
|
|
65
|
+
return (pi) => {
|
|
66
|
+
pi.registerCommand("usage", {
|
|
67
|
+
description: "Show token and cost usage",
|
|
68
|
+
handler: async (_args, ctx) => {
|
|
69
|
+
if (ctx.mode !== "tui") {
|
|
70
|
+
ctx.ui.notify("/usage is available in interactive mode", "warning");
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const model = ctx.model;
|
|
74
|
+
if (!model) {
|
|
75
|
+
ctx.ui.notify("No model selected.", "warning");
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const totals = createUsageTotals();
|
|
79
|
+
for (const { usage } of getSessionUsage(ctx.sessionManager.getEntries()))
|
|
80
|
+
addUsageToTotals(totals, usage);
|
|
81
|
+
const providerId = model.provider;
|
|
82
|
+
const subscriptionBacked = ctx.modelRegistry.isUsingOAuth(model) &&
|
|
83
|
+
ctx.modelRegistry.getProvider(providerId)?.auth.oauth?.isSubscription === true;
|
|
84
|
+
// Limits read from a subscription do not apply to API-key use of the same provider.
|
|
85
|
+
const limits = subscriptionBacked ? await accountLimits(ctx, providerId, options) : { lines: [] };
|
|
86
|
+
const header = ctx.sessionManager.getHeader();
|
|
87
|
+
const overview = buildUsageOverview({
|
|
88
|
+
providerId,
|
|
89
|
+
modelId: model.id,
|
|
90
|
+
stats: {
|
|
91
|
+
tokens: { input: totals.input, output: totals.output },
|
|
92
|
+
cost: totals.cost,
|
|
93
|
+
contextUsage: ctx.getContextUsage(),
|
|
94
|
+
},
|
|
95
|
+
durationMs: header?.timestamp ? Date.now() - new Date(header.timestamp).getTime() : null,
|
|
96
|
+
usageIncomplete: totals.usageIncomplete === true,
|
|
97
|
+
// Only warn about unexposed limits when there is nothing to show.
|
|
98
|
+
subscriptionBacked: subscriptionBacked && (limits.bars?.length ?? 0) === 0 && limits.lines.length === 0,
|
|
99
|
+
accountBars: limits.bars,
|
|
100
|
+
});
|
|
101
|
+
overview.lines.push(...limits.lines);
|
|
102
|
+
await ctx.ui.custom((_tui, theme, keybindings, done) => {
|
|
103
|
+
return new UsagePopupComponent(theme, keybindings, overview, () => done());
|
|
104
|
+
});
|
|
105
|
+
},
|
|
106
|
+
});
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
export default createUsageExtension();
|
|
110
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/extensions/usage/index.ts"],"names":[],"mappings":"AAAA,mHAAmH;AACnH;;;;;GAKG;AAIH,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAClG,OAAO,EACN,kBAAkB,EAClB,kBAAkB,EAClB,eAAe,EACf,cAAc,EACd,SAAS,EACT,qBAAqB,GAGrB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEjD,MAAM,gBAAgB,GAAG,MAAM,CAAC;AAOhC,sGAAsG;AACtG,KAAK,UAAU,aAAa,CAC3B,GAAqB,EACrB,UAAkB,EAClB,OAA8B;IAE9B,IAAI,UAAU,KAAK,WAAW,EAAE,CAAC;QAChC,IAAI,IAAsC,CAAC;QAC3C,IAAI,SAAiB,CAAC;QACtB,IAAI,CAAC;YACJ,IAAI,GAAG,MAAM,GAAG,CAAC,aAAa,CAAC,iBAAiB,CAAC,EAAE,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,gBAAgB,CAAC,EAAE,CAAC,CAAC;YACpG,SAAS;gBACR,IAAI,KAAK,SAAS;oBACjB,CAAC,CAAC,uCAAuC;oBACzC,CAAC,CAAC,IAAI,CAAC,MAAM,KAAK,aAAa;wBAC9B,CAAC,CAAC,kBAAkB,CAAC,IAAI,CAAC,MAAM,CAAC;wBACjC,CAAC,CAAC,kCAAkC,CAAC;QACzC,CAAC;QAAC,MAAM,CAAC;YACR,SAAS,GAAG,8BAA8B,CAAC;QAC5C,CAAC;QACD,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACvB,IAAI,IAAI,EAAE,MAAM,KAAK,IAAI,I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BAClE,kBAAkB,EAAE,kBAAkB,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,IAAI,CAAC,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC;oBACvG,WAAW,EAAE,MAAM,CAAC,IAAI;iBACxB,CAAC,CAAC;gBACH,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;gBAErC,MAAM,GAAG,CAAC,EAAE,CAAC,MAAM,CAAO,CAAC,IAAI,EAAE,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,EAAE;oBAC5D,OAAO,IAAI,mBAAmB,CAAC,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC;gBAC5E,CAAC,CAAC,CAAC;YACJ,CAAC;SACD,CAAC,CAAC;IACJ,CAAC,CAAC;AACH,CAAC;AAED,eAAe,oBAAoB,EAAE,CAAC","sourcesContent":["// Derived from Pi-Bolt (MIT, Copyright (c) 2026 OpenSec (Pi-Bolt)), commit a6df6a2c; modified for HUMAIN Code CLI.\n/**\n * The `/usage` command as a built-in extension: session tokens, cost and context, plus subscription limits: every limit\n * window of the active OpenAI Codex account (the usage route /accounts reads) and, for a Claude subscription, live\n * limits from Anthropic's subscription usage endpoint with Claude Code's cached limits as the fallback. It sends no\n * request to any other endpoint.\n */\n\nimport type { AnthropicUsageResult } from \"../../core/anthropic-subscription-usage.ts\";\nimport type { ExtensionContext, ExtensionFactory } from \"../../core/extensions/types.ts\";\nimport { addUsageToTotals, createUsageTotals, getSessionUsage } from \"../../core/usage-totals.ts\";\nimport {\n\tbuildUsageOverview,\n\tCLAUDE_UNAVAILABLE,\n\tclaudeUsageBars,\n\tcodexUsageBars,\n\tformatAge,\n\treadClaudeCachedUsage,\n\ttype UsageBar,\n\ttype UsageLine,\n} from \"./overview.ts\";\nimport { UsagePopupComponent } from \"./popup.ts\";\n\nconst FETCH_TIMEOUT_MS = 10_000;\n\nexport interface UsageExtensionOptions {\n\t/** Home directory holding Claude Code's `.claude.json`. Defaults to the user's home. */\n\thome?: string;\n}\n\n/** Subscription limits of the selected model's account, and lines explaining where they come from. */\nasync function accountLimits(\n\tctx: ExtensionContext,\n\tproviderId: string,\n\toptions: UsageExtensionOptions,\n): Promise<{ bars?: UsageBar[]; lines: UsageLine[] }> {\n\tif (providerId === \"anthropic\") {\n\t\tlet live: AnthropicUsageResult | undefined;\n\t\tlet liveError: string;\n\t\ttry {\n\t\t\tlive = await ctx.modelRegistry.getAnthropicUsage({ signal: AbortSignal.timeout(FETCH_TIMEOUT_MS) });\n\t\t\tliveError =\n\t\t\t\tlive === undefined\n\t\t\t\t\t? \"No active Claude account. Run /login.\"\n\t\t\t\t\t: live.status === \"unavailable\"\n\t\t\t\t\t\t? CLAUDE_UNAVAILABLE[live.reason]\n\t\t\t\t\t\t: \"Claude reported no usage limits.\";\n\t\t} catch {\n\t\t\tliveError = \"Claude usage is unavailable.\";\n\t\t}\n\t\tconst now = Date.now();\n\t\tif (live?.status === \"ok\" && live.windows.length > 0) {\n\t\t\treturn {\n\t\t\t\tbars: claudeUsageBars(live.windows, now),\n\t\t\t\tlines: [{ label: \"limits\", value: `live from Anthropic, fetched ${formatAge(now - live.fetchedAt)} ago` }],\n\t\t\t};\n\t\t}\n\t\t// Live usage is unavailable: fall back to Claude Code's cached copy, and name the live failure only if that fails too.\n\t\tconst claude = await readClaudeCachedUsage(options.home, now);\n\t\tif (\"error\" in claude || claude.bars.length === 0) {\n\t\t\tconst cacheError = \"error\" in claude ? claude.error : \"No cached Claude Code usage in ~/.claude.json.\";\n\t\t\treturn {\n\t\t\t\tlines: [\n\t\t\t\t\t{ label: \"limits\", value: liveError, tone: \"error\" },\n\t\t\t\t\t{ label: \"cached\", value: cacheError, tone: \"warning\" },\n\t\t\t\t],\n\t\t\t};\n\t\t}\n\t\tconst age = claude.fetchedAtMs === undefined ? \"age unknown\" : `from ${formatAge(now - claude.fetchedAtMs)} ago`;\n\t\treturn { bars: claude.bars, lines: [{ label: \"limits\", value: `Claude Code's cached numbers, ${age}` }] };\n\t}\n\tif (providerId === \"openai-codex\") {\n\t\tlet codex: ReturnType<typeof codexUsageBars>;\n\t\ttry {\n\t\t\tcodex = codexUsageBars(\n\t\t\t\tawait ctx.modelRegistry.getCodexUsage({ signal: AbortSignal.timeout(FETCH_TIMEOUT_MS) }),\n\t\t\t);\n\t\t} catch {\n\t\t\tcodex = { error: \"Codex usage is unavailable.\" };\n\t\t}\n\t\tif (\"error\" in codex) return { lines: [{ label: \"limits\", value: codex.error, tone: \"error\" }] };\n\t\treturn { bars: codex.bars, lines: [{ label: \"limits\", value: \"active Codex account\" }, ...codex.lines] };\n\t}\n\treturn { lines: [] };\n}\n\nexport function createUsageExtension(options: UsageExtensionOptions = {}): ExtensionFactory {\n\treturn (pi) => {\n\t\tpi.registerCommand(\"usage\", {\n\t\t\tdescription: \"Show token and cost usage\",\n\t\t\thandler: async (_args, ctx) => {\n\t\t\t\tif (ctx.mode !== \"tui\") {\n\t\t\t\t\tctx.ui.notify(\"/usage is available in interactive mode\", \"warning\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst model = ctx.model;\n\t\t\t\tif (!model) {\n\t\t\t\t\tctx.ui.notify(\"No model selected.\", \"warning\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst totals = createUsageTotals();\n\t\t\t\tfor (const { usage } of getSessionUsage(ctx.sessionManager.getEntries())) addUsageToTotals(totals, usage);\n\n\t\t\t\tconst providerId = model.provider;\n\t\t\t\tconst subscriptionBacked =\n\t\t\t\t\tctx.modelRegistry.isUsingOAuth(model) &&\n\t\t\t\t\tctx.modelRegistry.getProvider(providerId)?.auth.oauth?.isSubscription === true;\n\t\t\t\t// Limits read from a subscription do not apply to API-key use of the same provider.\n\t\t\t\tconst limits = subscriptionBacked ? await accountLimits(ctx, providerId, options) : { lines: [] };\n\n\t\t\t\tconst header = ctx.sessionManager.getHeader();\n\t\t\t\tconst overview = buildUsageOverview({\n\t\t\t\t\tproviderId,\n\t\t\t\t\tmodelId: model.id,\n\t\t\t\t\tstats: {\n\t\t\t\t\t\ttokens: { input: totals.input, output: totals.output },\n\t\t\t\t\t\tcost: totals.cost,\n\t\t\t\t\t\tcontextUsage: ctx.getContextUsage(),\n\t\t\t\t\t},\n\t\t\t\t\tdurationMs: header?.timestamp ? Date.now() - new Date(header.timestamp).getTime() : null,\n\t\t\t\t\tusageIncomplete: totals.usageIncomplete === true,\n\t\t\t\t\t// Only warn about unexposed limits when there is nothing to show.\n\t\t\t\t\tsubscriptionBacked: subscriptionBacked && (limits.bars?.length ?? 0) === 0 && limits.lines.length === 0,\n\t\t\t\t\taccountBars: limits.bars,\n\t\t\t\t});\n\t\t\t\toverview.lines.push(...limits.lines);\n\n\t\t\t\tawait ctx.ui.custom<void>((_tui, theme, keybindings, done) => {\n\t\t\t\t\treturn new UsagePopupComponent(theme, keybindings, overview, () => done());\n\t\t\t\t});\n\t\t\t},\n\t\t});\n\t};\n}\n\nexport default createUsageExtension();\n"]}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A provider-agnostic model for the `/usage` popup: bounded quotas render as progress bars, key/value rows render as
|
|
3
|
+
* plain lines, and notes carry warnings the UI should surface (e.g. a provider whose subscription limits are not
|
|
4
|
+
* exposed through its API).
|
|
5
|
+
*/
|
|
6
|
+
import { type AnthropicUsageUnavailableReason, type AnthropicUsageWindow } from "../../core/anthropic-subscription-usage.ts";
|
|
7
|
+
import type { CodexUsageDetailsResult } from "../../core/codex-usage.ts";
|
|
8
|
+
export type BarTone = "accent" | "warning" | "error" | "success";
|
|
9
|
+
export interface UsageBar {
|
|
10
|
+
id: string;
|
|
11
|
+
label: string;
|
|
12
|
+
/** Consumed amount, in the same unit as `total`. */
|
|
13
|
+
used: number;
|
|
14
|
+
/** Total limit; null means unlimited or unknown. */
|
|
15
|
+
total: number | null;
|
|
16
|
+
/** Pre-formatted right-hand label, e.g. "4.2% / 1.0M" or "35% used". */
|
|
17
|
+
display: string;
|
|
18
|
+
tone: BarTone;
|
|
19
|
+
note?: string;
|
|
20
|
+
}
|
|
21
|
+
export interface UsageLine {
|
|
22
|
+
label: string;
|
|
23
|
+
value: string;
|
|
24
|
+
tone?: BarTone;
|
|
25
|
+
}
|
|
26
|
+
export interface UsageOverview {
|
|
27
|
+
providerId: string;
|
|
28
|
+
modelId: string;
|
|
29
|
+
bars: UsageBar[];
|
|
30
|
+
lines: UsageLine[];
|
|
31
|
+
notes: string[];
|
|
32
|
+
}
|
|
33
|
+
/** Minimal stats shape the builder needs, decoupled from AgentSession. */
|
|
34
|
+
export interface UsageStatsInput {
|
|
35
|
+
tokens: {
|
|
36
|
+
input: number;
|
|
37
|
+
output: number;
|
|
38
|
+
};
|
|
39
|
+
cost: number;
|
|
40
|
+
contextUsage?: {
|
|
41
|
+
tokens: number | null;
|
|
42
|
+
contextWindow: number;
|
|
43
|
+
percent: number | null;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
export declare function formatTokens(count: number): string;
|
|
47
|
+
export declare function formatDuration(ms: number): string;
|
|
48
|
+
export declare function buildUsageOverview(opts: {
|
|
49
|
+
providerId: string;
|
|
50
|
+
modelId: string;
|
|
51
|
+
stats: UsageStatsInput;
|
|
52
|
+
durationMs: number | null;
|
|
53
|
+
/** The cost is a lower bound: some usage was not reported. */
|
|
54
|
+
usageIncomplete?: boolean;
|
|
55
|
+
subscriptionBacked: boolean;
|
|
56
|
+
accountBars?: UsageBar[];
|
|
57
|
+
}): UsageOverview;
|
|
58
|
+
/** Claude subscription windows (live or cached) as bars. */
|
|
59
|
+
export declare function claudeUsageBars(windows: readonly AnthropicUsageWindow[], now?: number): UsageBar[];
|
|
60
|
+
/**
|
|
61
|
+
* Parse Claude Code's `cachedUsageUtilization` (stored in ~/.claude.json), a cached copy of Anthropic's subscription
|
|
62
|
+
* usage response, into progress bars. The `utilization` values are percentages of the limit consumed.
|
|
63
|
+
*/
|
|
64
|
+
export declare function parseClaudeUtilization(raw: unknown, now?: number): UsageBar[];
|
|
65
|
+
export declare const CLAUDE_UNAVAILABLE: Record<AnthropicUsageUnavailableReason, string>;
|
|
66
|
+
/**
|
|
67
|
+
* Every limit window of the active Codex account as one bar each (main 5h and weekly first), plus its credits, or the
|
|
68
|
+
* reason they are unavailable. The usage route is the one /accounts reads; its fields are parsed by core/codex-usage.ts.
|
|
69
|
+
*/
|
|
70
|
+
export declare function codexUsageBars(result: CodexUsageDetailsResult | undefined, now?: number): {
|
|
71
|
+
bars: UsageBar[];
|
|
72
|
+
lines: UsageLine[];
|
|
73
|
+
} | {
|
|
74
|
+
error: string;
|
|
75
|
+
};
|
|
76
|
+
/** Age of cached numbers, e.g. 40s -> "under a minute", 12m -> "12 min", 3h -> "3 h", 2d -> "2 d". */
|
|
77
|
+
export declare function formatAge(ms: number): string;
|
|
78
|
+
/**
|
|
79
|
+
* Read Claude Code's cached subscription usage. Claude Code fetches this with its own OAuth token and stores it in
|
|
80
|
+
* ~/.claude.json with the fetch time. The 5h / weekly limits belong to the Claude subscription, so they apply only when
|
|
81
|
+
* HUMAIN Code CLI is signed in to Anthropic with a subscription; they are as old as Claude Code's last fetch. The file
|
|
82
|
+
* also holds Claude Code's credentials: errors never quote it.
|
|
83
|
+
*/
|
|
84
|
+
export declare function readClaudeCachedUsage(home?: string, now?: number): Promise<{
|
|
85
|
+
bars: UsageBar[];
|
|
86
|
+
fetchedAtMs?: number;
|
|
87
|
+
} | {
|
|
88
|
+
error: string;
|
|
89
|
+
}>;
|
|
90
|
+
//# sourceMappingURL=overview.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"overview.d.ts","sourceRoot":"","sources":["../../../src/extensions/usage/overview.ts"],"names":[],"mappings":"AACA;;;;GAIG;AAKH,OAAO,EACN,KAAK,+BAA+B,EACpC,KAAK,oBAAoB,EAEz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
|
+
// Derived from Pi-Bolt (MIT, Copyright (c) 2026 OpenSec (Pi-Bolt)), commit a6df6a2c; modified for HUMAIN Code CLI.
|
|
2
|
+
/**
|
|
3
|
+
* A provider-agnostic model for the `/usage` popup: bounded quotas render as progress bars, key/value rows render as
|
|
4
|
+
* plain lines, and notes carry warnings the UI should surface (e.g. a provider whose subscription limits are not
|
|
5
|
+
* exposed through its API).
|
|
6
|
+
*/
|
|
7
|
+
import { readFile } from "node:fs/promises";
|
|
8
|
+
import { homedir } from "node:os";
|
|
9
|
+
import { join } from "node:path";
|
|
10
|
+
import { parseAnthropicSubscriptionUsage, } from "../../core/anthropic-subscription-usage.js";
|
|
11
|
+
import { formatOAuthAccountResetTime } from "../../modes/interactive/oauth-account-format.js";
|
|
12
|
+
export function formatTokens(count) {
|
|
13
|
+
if (count < 1000)
|
|
14
|
+
return count.toString();
|
|
15
|
+
if (count < 10000)
|
|
16
|
+
return `${(count / 1000).toFixed(1)}k`;
|
|
17
|
+
if (count < 1000000)
|
|
18
|
+
return `${Math.round(count / 1000)}k`;
|
|
19
|
+
if (count < 10000000)
|
|
20
|
+
return `${(count / 1000000).toFixed(1)}M`;
|
|
21
|
+
return `${Math.round(count / 1000000)}M`;
|
|
22
|
+
}
|
|
23
|
+
export function formatDuration(ms) {
|
|
24
|
+
const totalSeconds = Math.max(0, Math.floor(ms / 1000));
|
|
25
|
+
const hours = Math.floor(totalSeconds / 3600);
|
|
26
|
+
const minutes = Math.floor((totalSeconds % 3600) / 60);
|
|
27
|
+
const seconds = totalSeconds % 60;
|
|
28
|
+
if (hours > 0)
|
|
29
|
+
return `${hours}h ${minutes}m ${seconds}s`;
|
|
30
|
+
if (minutes > 0)
|
|
31
|
+
return `${minutes}m ${seconds}s`;
|
|
32
|
+
return `${seconds}s`;
|
|
33
|
+
}
|
|
34
|
+
function percentTone(percent) {
|
|
35
|
+
if (percent > 90)
|
|
36
|
+
return "error";
|
|
37
|
+
if (percent > 70)
|
|
38
|
+
return "warning";
|
|
39
|
+
return "accent";
|
|
40
|
+
}
|
|
41
|
+
function contextTone(percent) {
|
|
42
|
+
return percent === null ? "accent" : percentTone(percent);
|
|
43
|
+
}
|
|
44
|
+
export function buildUsageOverview(opts) {
|
|
45
|
+
const { providerId, modelId, stats, durationMs, usageIncomplete, subscriptionBacked, accountBars } = opts;
|
|
46
|
+
const bars = [];
|
|
47
|
+
const lines = [];
|
|
48
|
+
const notes = [];
|
|
49
|
+
if (accountBars)
|
|
50
|
+
bars.push(...accountBars);
|
|
51
|
+
// Context window is the one "used vs left" bar that is always available.
|
|
52
|
+
const cu = stats.contextUsage;
|
|
53
|
+
if (cu) {
|
|
54
|
+
bars.push({
|
|
55
|
+
id: "context",
|
|
56
|
+
label: "Context",
|
|
57
|
+
used: cu.tokens ?? 0,
|
|
58
|
+
total: cu.contextWindow,
|
|
59
|
+
display: `${cu.percent !== null ? `${cu.percent.toFixed(1)}%` : "?"} / ${formatTokens(cu.contextWindow)}`,
|
|
60
|
+
tone: contextTone(cu.percent),
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
// Session usage (works for every provider).
|
|
64
|
+
lines.push({ label: "tokens", value: `↑${formatTokens(stats.tokens.input)} ↓${formatTokens(stats.tokens.output)}` });
|
|
65
|
+
lines.push(usageIncomplete
|
|
66
|
+
? { label: "cost", value: `≥$${stats.cost.toFixed(3)} (usage incomplete)`, tone: "warning" }
|
|
67
|
+
: { label: "cost", value: `$${stats.cost.toFixed(3)}` });
|
|
68
|
+
if (durationMs !== null) {
|
|
69
|
+
lines.push({ label: "time", value: formatDuration(durationMs) });
|
|
70
|
+
}
|
|
71
|
+
if (subscriptionBacked) {
|
|
72
|
+
notes.push("Subscription limits (weekly / 5h) are not exposed by this provider's API. See its usage dashboard.");
|
|
73
|
+
}
|
|
74
|
+
return { providerId, modelId, bars, lines, notes };
|
|
75
|
+
}
|
|
76
|
+
/** A percent-of-limit bar with its reset time; a reached limit uses the blocked tone. */
|
|
77
|
+
function limitBar(id, label, usedPercent, resetsAt, limitReached, now) {
|
|
78
|
+
const used = Math.min(100, Math.max(0, usedPercent));
|
|
79
|
+
const reset = resetsAt === undefined
|
|
80
|
+
? undefined
|
|
81
|
+
: `${resetsAt <= now ? "reset at" : "resets"} ${formatOAuthAccountResetTime(resetsAt)}`;
|
|
82
|
+
const notes = [reset, limitReached ? "limit reached" : undefined].filter((note) => note !== undefined);
|
|
83
|
+
return {
|
|
84
|
+
id,
|
|
85
|
+
label,
|
|
86
|
+
used,
|
|
87
|
+
total: 100,
|
|
88
|
+
display: `${used.toFixed(0)}% used`,
|
|
89
|
+
tone: limitReached ? "error" : percentTone(used),
|
|
90
|
+
...(notes.length > 0 ? { note: notes.join(", ") } : {}),
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
/** Claude subscription windows (live or cached) as bars. */
|
|
94
|
+
export function claudeUsageBars(windows, now = Date.now()) {
|
|
95
|
+
return windows.map((window) => limitBar(`claude-${window.id}`, window.label, window.usedPercent, window.resetsAt, window.usedPercent >= 100, now));
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Parse Claude Code's `cachedUsageUtilization` (stored in ~/.claude.json), a cached copy of Anthropic's subscription
|
|
99
|
+
* usage response, into progress bars. The `utilization` values are percentages of the limit consumed.
|
|
100
|
+
*/
|
|
101
|
+
export function parseClaudeUtilization(raw, now = Date.now()) {
|
|
102
|
+
if (!raw || typeof raw !== "object")
|
|
103
|
+
return [];
|
|
104
|
+
const u = raw.utilization ?? raw;
|
|
105
|
+
if (!u || typeof u !== "object")
|
|
106
|
+
return [];
|
|
107
|
+
const bars = claudeUsageBars(parseAnthropicSubscriptionUsage(u), now);
|
|
108
|
+
// Dollar-denominated limits (e.g. usage credits) use used_dollars / limit_dollars.
|
|
109
|
+
for (const [key, value] of Object.entries(u)) {
|
|
110
|
+
if (!value || typeof value !== "object")
|
|
111
|
+
continue;
|
|
112
|
+
const { used_dollars: used, limit_dollars: total } = value;
|
|
113
|
+
if (typeof used !== "number" || typeof total !== "number" || !Number.isFinite(used) || !(total > 0))
|
|
114
|
+
continue;
|
|
115
|
+
bars.push({
|
|
116
|
+
id: `claude-${key}`,
|
|
117
|
+
label: "Credits",
|
|
118
|
+
used,
|
|
119
|
+
total,
|
|
120
|
+
display: `$${used.toFixed(2)} / $${total.toFixed(2)}`,
|
|
121
|
+
tone: percentTone((used / total) * 100),
|
|
122
|
+
});
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
125
|
+
return bars;
|
|
126
|
+
}
|
|
127
|
+
export const CLAUDE_UNAVAILABLE = {
|
|
128
|
+
expired_credential: "Claude sign-in expired. Run /login.",
|
|
129
|
+
unauthorized: "Claude usage was refused (HTTP 401/403).",
|
|
130
|
+
rate_limited: "Claude usage is rate limited (HTTP 429). Try again later.",
|
|
131
|
+
http_error: "Claude usage is unavailable (HTTP error).",
|
|
132
|
+
timeout: "Claude usage timed out.",
|
|
133
|
+
network: "Claude usage is unreachable.",
|
|
134
|
+
malformed: "Claude usage returned an unexpected response.",
|
|
135
|
+
};
|
|
136
|
+
const CODEX_UNAVAILABLE = {
|
|
137
|
+
expired_credential: "Codex sign-in expired. Run /login.",
|
|
138
|
+
unauthorized: "Codex usage was refused (HTTP 401/403).",
|
|
139
|
+
rate_limited: "Codex usage is rate limited (HTTP 429). Try again later.",
|
|
140
|
+
http_error: "Codex usage is unavailable (HTTP error).",
|
|
141
|
+
timeout: "Codex usage timed out.",
|
|
142
|
+
network: "Codex usage is unreachable.",
|
|
143
|
+
malformed: "Codex usage returned an unexpected response.",
|
|
144
|
+
no_weekly_window: "Codex reported no weekly limit.",
|
|
145
|
+
};
|
|
146
|
+
function codexCreditsLine(credits) {
|
|
147
|
+
if (credits.unlimited)
|
|
148
|
+
return { label: "credits", value: "unlimited" };
|
|
149
|
+
if (!credits.hasCredits)
|
|
150
|
+
return { label: "credits", value: "none" };
|
|
151
|
+
return { label: "credits", value: credits.balance !== undefined ? `balance ${credits.balance}` : "available" };
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Every limit window of the active Codex account as one bar each (main 5h and weekly first), plus its credits, or the
|
|
155
|
+
* reason they are unavailable. The usage route is the one /accounts reads; its fields are parsed by core/codex-usage.ts.
|
|
156
|
+
*/
|
|
157
|
+
export function codexUsageBars(result, now = Date.now()) {
|
|
158
|
+
if (!result)
|
|
159
|
+
return { error: "No active Codex account. Run /login." };
|
|
160
|
+
if (result.status === "unavailable")
|
|
161
|
+
return { error: CODEX_UNAVAILABLE[result.reason] };
|
|
162
|
+
if (result.windows.length === 0 && !result.credits)
|
|
163
|
+
return { error: "Codex reported no usage limits." };
|
|
164
|
+
return {
|
|
165
|
+
bars: result.windows.map((window) => limitBar(`codex-${window.id}`, window.label, window.usedPercent, window.resetsAt, window.limitReached === true, now)),
|
|
166
|
+
lines: result.credits ? [codexCreditsLine(result.credits)] : [],
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
/** Age of cached numbers, e.g. 40s -> "under a minute", 12m -> "12 min", 3h -> "3 h", 2d -> "2 d". */
|
|
170
|
+
export function formatAge(ms) {
|
|
171
|
+
const minutes = Math.floor(Math.max(0, ms) / 60_000);
|
|
172
|
+
if (minutes < 1)
|
|
173
|
+
return "under a minute";
|
|
174
|
+
if (minutes < 60)
|
|
175
|
+
return `${minutes} min`;
|
|
176
|
+
const hours = Math.floor(minutes / 60);
|
|
177
|
+
if (hours < 48)
|
|
178
|
+
return `${hours} h`;
|
|
179
|
+
return `${Math.floor(hours / 24)} d`;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Read Claude Code's cached subscription usage. Claude Code fetches this with its own OAuth token and stores it in
|
|
183
|
+
* ~/.claude.json with the fetch time. The 5h / weekly limits belong to the Claude subscription, so they apply only when
|
|
184
|
+
* HUMAIN Code CLI is signed in to Anthropic with a subscription; they are as old as Claude Code's last fetch. The file
|
|
185
|
+
* also holds Claude Code's credentials: errors never quote it.
|
|
186
|
+
*/
|
|
187
|
+
export async function readClaudeCachedUsage(home = homedir(), now = Date.now()) {
|
|
188
|
+
let text;
|
|
189
|
+
try {
|
|
190
|
+
text = await readFile(join(home, ".claude.json"), "utf8");
|
|
191
|
+
}
|
|
192
|
+
catch (err) {
|
|
193
|
+
if (err.code === "ENOENT")
|
|
194
|
+
return { error: "~/.claude.json not found." };
|
|
195
|
+
return { error: "Could not read ~/.claude.json." };
|
|
196
|
+
}
|
|
197
|
+
let data;
|
|
198
|
+
try {
|
|
199
|
+
data = JSON.parse(text);
|
|
200
|
+
}
|
|
201
|
+
catch {
|
|
202
|
+
return { error: "~/.claude.json is not valid JSON." };
|
|
203
|
+
}
|
|
204
|
+
const cached = data && typeof data === "object"
|
|
205
|
+
? data.cachedUsageUtilization
|
|
206
|
+
: undefined;
|
|
207
|
+
if (!cached || typeof cached !== "object")
|
|
208
|
+
return { error: "No cached Claude Code usage in ~/.claude.json." };
|
|
209
|
+
const fetchedAt = cached.fetchedAtMs;
|
|
210
|
+
return {
|
|
211
|
+
bars: parseClaudeUtilization(cached, now),
|
|
212
|
+
fetchedAtMs: typeof fetchedAt === "number" && Number.isFinite(fetchedAt) ? fetchedAt : undefined,
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
//# sourceMappingURL=overview.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"overview.js","sourceRoot":"","sources":["../../../src/extensions/usage/overview.ts"],"names":[],"mappings":"AAAA,mHAAmH;AACnH;;;;GAIG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAGN,+BAA+B,GAC/B,MAAM,4CAA4C,CAAC;AAOpD,OAAO,EAAE,2BAA2B,EAAE,MAAM,iDAAiD,CAAC;AAsC9F,MAAM,UAAU,YAAY,CAAC,KAAa;IACzC,IAAI,KAAK,GAAG,IAA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AC,KAAK,CAAC,IAAI,CAAC,CAAC;IACzB,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,EAAE,KAAK,EAAE,mCAAmC,EAAE,CAAC;IACvD,CAAC;IACD,MAAM,MAAM,GACX,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ;QAC/B,CAAC,CAAE,IAA6C,CAAC,sBAAsB;QACvE,CAAC,CAAC,SAAS,CAAC;IACd,IAAI,CAAC,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ;QAAE,OAAO,EAAE,KAAK,EAAE,gDAAgD,EAAE,CAAC;IAC9G,MAAM,SAAS,GAAI,MAAoC,CAAC,WAAW,CAAC;IACpE,OAAO;QACN,IAAI,EAAE,sBAAsB,CAAC,MAAM,EAAE,GAAG,CAAC;QACzC,WAAW,EAAE,OAAO,SAAS,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS;KAChG,CAAC;AACH,CAAC","sourcesContent":["// Derived from Pi-Bolt (MIT, Copyright (c) 2026 OpenSec (Pi-Bolt)), commit a6df6a2c; modified for HUMAIN Code CLI.\n/**\n * A provider-agnostic model for the `/usage` popup: bounded quotas render as progress bars, key/value rows render as\n * plain lines, and notes carry warnings the UI should surface (e.g. a provider whose subscription limits are not\n * exposed through its API).\n */\n\nimport { readFile } from \"node:fs/promises\";\nimport { homedir } from \"node:os\";\nimport { join } from \"node:path\";\nimport {\n\ttype AnthropicUsageUnavailableReason,\n\ttype AnthropicUsageWindow,\n\tparseAnthropicSubscriptionUsage,\n} from \"../../core/anthropic-subscription-usage.ts\";\nimport type {\n\tCodexCreditsStatus,\n\tCodexUsageDetailsResult,\n\tCodexUsageUnavailableReason,\n\tCodexUsageWindow,\n} from \"../../core/codex-usage.ts\";\nimport { formatOAuthAccountResetTime } from \"../../modes/interactive/oauth-account-format.ts\";\n\nexport type BarTone = \"accent\" | \"warning\" | \"error\" | \"success\";\n\nexport interface UsageBar {\n\tid: string;\n\tlabel: string;\n\t/** Consumed amount, in the same unit as `total`. */\n\tused: number;\n\t/** Total limit; null means unlimited or unknown. */\n\ttotal: number | null;\n\t/** Pre-formatted right-hand label, e.g. \"4.2% / 1.0M\" or \"35% used\". */\n\tdisplay: string;\n\ttone: BarTone;\n\tnote?: string;\n}\n\nexport interface UsageLine {\n\tlabel: string;\n\tvalue: string;\n\ttone?: BarTone;\n}\n\nexport interface UsageOverview {\n\tproviderId: string;\n\tmodelId: string;\n\tbars: UsageBar[];\n\tlines: UsageLine[];\n\tnotes: string[];\n}\n\n/** Minimal stats shape the builder needs, decoupled from AgentSession. */\nexport interface UsageStatsInput {\n\ttokens: { input: number; output: number };\n\tcost: number;\n\tcontextUsage?: { tokens: number | null; contextWindow: number; percent: number | null };\n}\n\nexport function formatTokens(count: number): string {\n\tif (count < 1000) return count.toString();\n\tif (count < 10000) return `${(count / 1000).toFixed(1)}k`;\n\tif (count < 1000000) return `${Math.round(count / 1000)}k`;\n\tif (count < 10000000) return `${(count / 1000000).toFixed(1)}M`;\n\treturn `${Math.round(count / 1000000)}M`;\n}\n\nexport function formatDuration(ms: number): string {\n\tconst totalSeconds = Math.max(0, Math.floor(ms / 1000));\n\tconst hours = Math.floor(totalSeconds / 3600);\n\tconst minutes = Math.floor((totalSeconds % 3600) / 60);\n\tconst seconds = totalSeconds % 60;\n\tif (hours > 0) return `${hours}h ${minutes}m ${seconds}s`;\n\tif (minutes > 0) return `${minutes}m ${seconds}s`;\n\treturn `${seconds}s`;\n}\n\nfunction percentTone(percent: number): BarTone {\n\tif (percent > 90) return \"error\";\n\tif (percent > 70) return \"warning\";\n\treturn \"accent\";\n}\n\nfunction contextTone(percent: number | null): BarTone {\n\treturn percent === null ? \"accent\" : percentTone(percent);\n}\n\nexport function buildUsageOverview(opts: {\n\tproviderId: string;\n\tmodelId: string;\n\tstats: UsageStatsInput;\n\tdurationMs: number | null;\n\t/** The cost is a lower bound: some usage was not reported. */\n\tusageIncomplete?: boolean;\n\tsubscriptionBacked: boolean;\n\taccountBars?: UsageBar[];\n}): UsageOverview {\n\tconst { providerId, modelId, stats, durationMs, usageIncomplete, subscriptionBacked, accountBars } = opts;\n\n\tconst bars: UsageBar[] = [];\n\tconst lines: UsageLine[] = [];\n\tconst notes: string[] = [];\n\n\tif (accountBars) bars.push(...accountBars);\n\n\t// Context window is the one \"used vs left\" bar that is always available.\n\tconst cu = stats.contextUsage;\n\tif (cu) {\n\t\tbars.push({\n\t\t\tid: \"context\",\n\t\t\tlabel: \"Context\",\n\t\t\tused: cu.tokens ?? 0,\n\t\t\ttotal: cu.contextWindow,\n\t\t\tdisplay: `${cu.percent !== null ? `${cu.percent.toFixed(1)}%` : \"?\"} / ${formatTokens(cu.contextWindow)}`,\n\t\t\ttone: contextTone(cu.percent),\n\t\t});\n\t}\n\n\t// Session usage (works for every provider).\n\tlines.push({ label: \"tokens\", value: `↑${formatTokens(stats.tokens.input)} ↓${formatTokens(stats.tokens.output)}` });\n\tlines.push(\n\t\tusageIncomplete\n\t\t\t? { label: \"cost\", value: `≥$${stats.cost.toFixed(3)} (usage incomplete)`, tone: \"warning\" }\n\t\t\t: { label: \"cost\", value: `$${stats.cost.toFixed(3)}` },\n\t);\n\tif (durationMs !== null) {\n\t\tlines.push({ label: \"time\", value: formatDuration(durationMs) });\n\t}\n\n\tif (subscriptionBacked) {\n\t\tnotes.push(\"Subscription limits (weekly / 5h) are not exposed by this provider's API. See its usage dashboard.\");\n\t}\n\n\treturn { providerId, modelId, bars, lines, notes };\n}\n\n/** A percent-of-limit bar with its reset time; a reached limit uses the blocked tone. */\nfunction limitBar(\n\tid: string,\n\tlabel: string,\n\tusedPercent: number,\n\tresetsAt: number | undefined,\n\tlimitReached: boolean,\n\tnow: number,\n): UsageBar {\n\tconst used = Math.min(100, Math.max(0, usedPercent));\n\tconst reset =\n\t\tresetsAt === undefined\n\t\t\t? undefined\n\t\t\t: `${resetsAt <= now ? \"reset at\" : \"resets\"} ${formatOAuthAccountResetTime(resetsAt)}`;\n\tconst notes = [reset, limitReached ? \"limit reached\" : undefined].filter((note) => note !== undefined);\n\treturn {\n\t\tid,\n\t\tlabel,\n\t\tused,\n\t\ttotal: 100,\n\t\tdisplay: `${used.toFixed(0)}% used`,\n\t\ttone: limitReached ? \"error\" : percentTone(used),\n\t\t...(notes.length > 0 ? { note: notes.join(\", \") } : {}),\n\t};\n}\n\n/** Claude subscription windows (live or cached) as bars. */\nexport function claudeUsageBars(windows: readonly AnthropicUsageWindow[], now: number = Date.now()): UsageBar[] {\n\treturn windows.map((window) =>\n\t\tlimitBar(\n\t\t\t`claude-${window.id}`,\n\t\t\twindow.label,\n\t\t\twindow.usedPercent,\n\t\t\twindow.resetsAt,\n\t\t\twindow.usedPercent >= 100,\n\t\t\tnow,\n\t\t),\n\t);\n}\n\n/**\n * Parse Claude Code's `cachedUsageUtilization` (stored in ~/.claude.json), a cached copy of Anthropic's subscription\n * usage response, into progress bars. The `utilization` values are percentages of the limit consumed.\n */\nexport function parseClaudeUtilization(raw: unknown, now: number = Date.now()): UsageBar[] {\n\tif (!raw || typeof raw !== \"object\") return [];\n\n\tconst u = (raw as { utilization?: Record<string, unknown> }).utilization ?? (raw as Record<string, unknown>);\n\tif (!u || typeof u !== \"object\") return [];\n\tconst bars = claudeUsageBars(parseAnthropicSubscriptionUsage(u), now);\n\n\t// Dollar-denominated limits (e.g. usage credits) use used_dollars / limit_dollars.\n\tfor (const [key, value] of Object.entries(u)) {\n\t\tif (!value || typeof value !== \"object\") continue;\n\t\tconst { used_dollars: used, limit_dollars: total } = value as {\n\t\t\tused_dollars?: unknown;\n\t\t\tlimit_dollars?: unknown;\n\t\t};\n\t\tif (typeof used !== \"number\" || typeof total !== \"number\" || !Number.isFinite(used) || !(total > 0)) continue;\n\t\tbars.push({\n\t\t\tid: `claude-${key}`,\n\t\t\tlabel: \"Credits\",\n\t\t\tused,\n\t\t\ttotal,\n\t\t\tdisplay: `$${used.toFixed(2)} / $${total.toFixed(2)}`,\n\t\t\ttone: percentTone((used / total) * 100),\n\t\t});\n\t\tbreak;\n\t}\n\n\treturn bars;\n}\n\nexport const CLAUDE_UNAVAILABLE: Record<AnthropicUsageUnavailableReason, string> = {\n\texpired_credential: \"Claude sign-in expired. Run /login.\",\n\tunauthorized: \"Claude usage was refused (HTTP 401/403).\",\n\trate_limited: \"Claude usage is rate limited (HTTP 429). Try again later.\",\n\thttp_error: \"Claude usage is unavailable (HTTP error).\",\n\ttimeout: \"Claude usage timed out.\",\n\tnetwork: \"Claude usage is unreachable.\",\n\tmalformed: \"Claude usage returned an unexpected response.\",\n};\n\nconst CODEX_UNAVAILABLE: Record<CodexUsageUnavailableReason, string> = {\n\texpired_credential: \"Codex sign-in expired. Run /login.\",\n\tunauthorized: \"Codex usage was refused (HTTP 401/403).\",\n\trate_limited: \"Codex usage is rate limited (HTTP 429). Try again later.\",\n\thttp_error: \"Codex usage is unavailable (HTTP error).\",\n\ttimeout: \"Codex usage timed out.\",\n\tnetwork: \"Codex usage is unreachable.\",\n\tmalformed: \"Codex usage returned an unexpected response.\",\n\tno_weekly_window: \"Codex reported no weekly limit.\",\n};\n\nfunction codexCreditsLine(credits: CodexCreditsStatus): UsageLine {\n\tif (credits.unlimited) return { label: \"credits\", value: \"unlimited\" };\n\tif (!credits.hasCredits) return { label: \"credits\", value: \"none\" };\n\treturn { label: \"credits\", value: credits.balance !== undefined ? `balance ${credits.balance}` : \"available\" };\n}\n\n/**\n * Every limit window of the active Codex account as one bar each (main 5h and weekly first), plus its credits, or the\n * reason they are unavailable. The usage route is the one /accounts reads; its fields are parsed by core/codex-usage.ts.\n */\nexport function codexUsageBars(\n\tresult: CodexUsageDetailsResult | undefined,\n\tnow: number = Date.now(),\n): { bars: UsageBar[]; lines: UsageLine[] } | { error: string } {\n\tif (!result) return { error: \"No active Codex account. Run /login.\" };\n\tif (result.status === \"unavailable\") return { error: CODEX_UNAVAILABLE[result.reason] };\n\tif (result.windows.length === 0 && !result.credits) return { error: \"Codex reported no usage limits.\" };\n\treturn {\n\t\tbars: result.windows.map((window: CodexUsageWindow) =>\n\t\t\tlimitBar(\n\t\t\t\t`codex-${window.id}`,\n\t\t\t\twindow.label,\n\t\t\t\twindow.usedPercent,\n\t\t\t\twindow.resetsAt,\n\t\t\t\twindow.limitReached === true,\n\t\t\t\tnow,\n\t\t\t),\n\t\t),\n\t\tlines: result.credits ? [codexCreditsLine(result.credits)] : [],\n\t};\n}\n\n/** Age of cached numbers, e.g. 40s -> \"under a minute\", 12m -> \"12 min\", 3h -> \"3 h\", 2d -> \"2 d\". */\nexport function formatAge(ms: number): string {\n\tconst minutes = Math.floor(Math.max(0, ms) / 60_000);\n\tif (minutes < 1) return \"under a minute\";\n\tif (minutes < 60) return `${minutes} min`;\n\tconst hours = Math.floor(minutes / 60);\n\tif (hours < 48) return `${hours} h`;\n\treturn `${Math.floor(hours / 24)} d`;\n}\n\n/**\n * Read Claude Code's cached subscription usage. Claude Code fetches this with its own OAuth token and stores it in\n * ~/.claude.json with the fetch time. The 5h / weekly limits belong to the Claude subscription, so they apply only when\n * HUMAIN Code CLI is signed in to Anthropic with a subscription; they are as old as Claude Code's last fetch. The file\n * also holds Claude Code's credentials: errors never quote it.\n */\nexport async function readClaudeCachedUsage(\n\thome: string = homedir(),\n\tnow: number = Date.now(),\n): Promise<{ bars: UsageBar[]; fetchedAtMs?: number } | { error: string }> {\n\tlet text: string;\n\ttry {\n\t\ttext = await readFile(join(home, \".claude.json\"), \"utf8\");\n\t} catch (err) {\n\t\tif ((err as NodeJS.ErrnoException).code === \"ENOENT\") return { error: \"~/.claude.json not found.\" };\n\t\treturn { error: \"Could not read ~/.claude.json.\" };\n\t}\n\tlet data: unknown;\n\ttry {\n\t\tdata = JSON.parse(text);\n\t} catch {\n\t\treturn { error: \"~/.claude.json is not valid JSON.\" };\n\t}\n\tconst cached =\n\t\tdata && typeof data === \"object\"\n\t\t\t? (data as { cachedUsageUtilization?: unknown }).cachedUsageUtilization\n\t\t\t: undefined;\n\tif (!cached || typeof cached !== \"object\") return { error: \"No cached Claude Code usage in ~/.claude.json.\" };\n\tconst fetchedAt = (cached as { fetchedAtMs?: unknown }).fetchedAtMs;\n\treturn {\n\t\tbars: parseClaudeUtilization(cached, now),\n\t\tfetchedAtMs: typeof fetchedAt === \"number\" && Number.isFinite(fetchedAt) ? fetchedAt : undefined,\n\t};\n}\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type Component, type Focusable, 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
|
+
import type { UsageOverview } from "./overview.ts";
|
|
5
|
+
/**
|
|
6
|
+
* A read-only view showing account/session usage with tqdm-style progress
|
|
7
|
+
* bars. Esc (or a click) closes it.
|
|
8
|
+
*/
|
|
9
|
+
export declare class UsagePopupComponent implements Component, Focusable {
|
|
10
|
+
focused: boolean;
|
|
11
|
+
private readonly theme;
|
|
12
|
+
private readonly keybindings;
|
|
13
|
+
private readonly overview;
|
|
14
|
+
private readonly onClose;
|
|
15
|
+
constructor(theme: Theme, keybindings: KeybindingsManager, overview: UsageOverview, onClose: () => void);
|
|
16
|
+
handleInput(data: string): void;
|
|
17
|
+
handleMouse(event: TuiMouseEvent): TuiMouseEventResult;
|
|
18
|
+
invalidate(): void;
|
|
19
|
+
render(width: number): string[];
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=popup.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"popup.d.ts","sourceRoot":"","sources":["../../../src/extensions/usage/popup.ts"],"names":[],"mappings":"AACA,OAAO,EACN,KAAK,SAAS,EACd,KAAK,SAAS,EACd,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;AACpE,OAAO,KAAK,EAAuB,aAAa,EAAE,MAAM,eAAe,CAAC;AAqBxE;;;GAGG;AACH,qBAAa,mBAAoB,YAAW,SAAS,EAAE,SAAS;IAC/D,OAAO,UAAS;IAEhB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAQ;IAC9B,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAqB;IACjD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAgB;IACzC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAa;IAErC,YAAY,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAE,QAAQ,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,IAAI,EAKtG;IAED,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAI9B;IAED,WAAW,CAAC,KAAK,EAAE,aAAa,GAAG,mBAAmB,CAGrD;IAED,UAAU,IAAI,IAAI,CAAG;IAErB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAwD9B;CACD"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
// Derived from Pi-Bolt (MIT, Copyright (c) 2026 OpenSec (Pi-Bolt)), commit a6df6a2c; modified for HUMAIN Code CLI.
|
|
2
|
+
import { truncateToWidth, visibleWidth, wrapTextWithAnsi, } from "@earendil-works/pi-tui";
|
|
3
|
+
import { formatKeyText } from "../../modes/interactive/components/keybinding-hints.js";
|
|
4
|
+
const BAR_WIDTH = 24;
|
|
5
|
+
const MIN_BAR_WIDTH = 8;
|
|
6
|
+
const MAX_LABEL_WIDTH = 28;
|
|
7
|
+
const TONE_COLOR = {
|
|
8
|
+
accent: "accent",
|
|
9
|
+
warning: "warning",
|
|
10
|
+
error: "error",
|
|
11
|
+
success: "success",
|
|
12
|
+
};
|
|
13
|
+
function renderBar(theme, bar, width) {
|
|
14
|
+
const frac = bar.total && bar.total > 0 ? Math.min(1, Math.max(0, bar.used / bar.total)) : 0;
|
|
15
|
+
const filled = Math.round(frac * width);
|
|
16
|
+
const fill = theme.fg(TONE_COLOR[bar.tone], "█".repeat(filled));
|
|
17
|
+
const empty = theme.fg("muted", "░".repeat(width - filled));
|
|
18
|
+
return `${fill}${empty}`;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* A read-only view showing account/session usage with tqdm-style progress
|
|
22
|
+
* bars. Esc (or a click) closes it.
|
|
23
|
+
*/
|
|
24
|
+
export class UsagePopupComponent {
|
|
25
|
+
focused = false;
|
|
26
|
+
theme;
|
|
27
|
+
keybindings;
|
|
28
|
+
overview;
|
|
29
|
+
onClose;
|
|
30
|
+
constructor(theme, keybindings, overview, onClose) {
|
|
31
|
+
this.theme = theme;
|
|
32
|
+
this.keybindings = keybindings;
|
|
33
|
+
this.overview = overview;
|
|
34
|
+
this.onClose = onClose;
|
|
35
|
+
}
|
|
36
|
+
handleInput(data) {
|
|
37
|
+
if (this.keybindings.matches(data, "tui.select.cancel") || this.keybindings.matches(data, "app.clear")) {
|
|
38
|
+
this.onClose();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
handleMouse(event) {
|
|
42
|
+
if (event.type === "click")
|
|
43
|
+
this.onClose();
|
|
44
|
+
return { handled: true, render: false };
|
|
45
|
+
}
|
|
46
|
+
invalidate() { }
|
|
47
|
+
render(width) {
|
|
48
|
+
const theme = this.theme;
|
|
49
|
+
const { providerId, modelId, bars, lines, notes } = this.overview;
|
|
50
|
+
const out = [];
|
|
51
|
+
const pad = " ";
|
|
52
|
+
const row = (label, value, tone) => {
|
|
53
|
+
const padded = label.padEnd(13);
|
|
54
|
+
const coloredValue = tone ? theme.fg(TONE_COLOR[tone], value) : value;
|
|
55
|
+
return `${pad}${theme.fg("dim", padded)} ${coloredValue}`;
|
|
56
|
+
};
|
|
57
|
+
out.push(theme.bold("Usage"));
|
|
58
|
+
out.push(theme.fg("dim", `${providerId} · ${modelId}`));
|
|
59
|
+
out.push("");
|
|
60
|
+
if (bars.length > 0) {
|
|
61
|
+
// One row per bar keeps several limit windows on screen: label, bar, percentage, then the note when it fits.
|
|
62
|
+
const labelWidth = Math.min(MAX_LABEL_WIDTH, Math.max(...bars.map((bar) => visibleWidth(bar.label))));
|
|
63
|
+
const displayWidth = Math.max(...bars.map((bar) => visibleWidth(bar.display)));
|
|
64
|
+
const barWidth = Math.max(MIN_BAR_WIDTH, Math.min(BAR_WIDTH, width - pad.length - labelWidth - 1 - 2 - displayWidth));
|
|
65
|
+
for (const bar of bars) {
|
|
66
|
+
const truncated = truncateToWidth(bar.label, labelWidth, "…");
|
|
67
|
+
const label = truncated + " ".repeat(Math.max(0, labelWidth - visibleWidth(truncated)));
|
|
68
|
+
const head = `${pad}${theme.fg("dim", label)} ${renderBar(theme, bar, barWidth)} ${theme.fg("dim", bar.display)}`;
|
|
69
|
+
const note = bar.note ? theme.fg("dim", bar.note) : undefined;
|
|
70
|
+
if (note && visibleWidth(head) + 2 + visibleWidth(note) <= width)
|
|
71
|
+
out.push(`${head} ${note}`);
|
|
72
|
+
else {
|
|
73
|
+
out.push(head);
|
|
74
|
+
if (note)
|
|
75
|
+
out.push(`${pad}${" ".repeat(labelWidth + 1)}${note}`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
out.push("");
|
|
79
|
+
}
|
|
80
|
+
out.push(theme.bold("This session"));
|
|
81
|
+
for (const line of lines) {
|
|
82
|
+
out.push(row(line.label, line.value, line.tone));
|
|
83
|
+
}
|
|
84
|
+
if (notes.length > 0) {
|
|
85
|
+
out.push("");
|
|
86
|
+
for (const note of notes) {
|
|
87
|
+
for (const wrapped of wrapTextWithAnsi(note, Math.max(1, width)))
|
|
88
|
+
out.push(theme.fg("warning", wrapped));
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
const closeKey = formatKeyText(this.keybindings.getKeys("tui.select.cancel")[0] ?? "escape");
|
|
92
|
+
out.push("");
|
|
93
|
+
out.push(theme.fg("muted", `${closeKey} to close`));
|
|
94
|
+
// A line wider than the terminal aborts rendering.
|
|
95
|
+
return out.map((line) => truncateToWidth(line, width, "…"));
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=popup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"popup.js","sourceRoot":"","sources":["../../../src/extensions/usage/popup.ts"],"names":[],"mappings":"AAAA,mHAAmH;AACnH,OAAO,EAKN,eAAe,EACf,YAAY,EACZ,gBAAgB,GAChB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,aAAa,EAAE,MAAM,wDAAwD,CAAC;AAIvF,MAAM,SAAS,GAAG,EAAE,CAAC;AACrB,MAAM,aAAa,GAAG,CAAC,CAAC;AACxB,MAAM,eAAe,GAAG,EAAE,CAAC;AAE3B,MAAM,UAAU,GAAG;IAClB,MAAM,EAAE,QAAQ;IAChB,OAAO,EAAE,SAAS;IAClB,KAAK,EAAE,OAAO;IACd,OAAO,EAAE,SAAS;CACT,CAAC;AAEX,SAAS,SAAS,CAAC,KAAY,EAAE,GAAa,EAAE,KAAa;IAC5D,MAAM,IAAI,GAAG,GAAG,CAAC,KAAK,IAAI,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC,IAAI,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC7F,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,KAAK,CAAC,CAAC;IACxC,MAAM,IAAI,GAAG,KAAK,CAAC,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;IAChE,MAAM,KAAK,GAAG,KAAK,CAA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AAI,CAAC,cAAc,CAAC,CAAC,CAAC;QACrC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YAC1B,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAClD,CAAC;QAED,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACtB,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YACb,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;gBAC1B,KAAK,MAAM,OAAO,IAAI,gBAAgB,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;oBAAE,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC;YAC1G,CAAC;QACF,CAAC;QAED,MAAM,QAAQ,GAAG,aAAa,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,IAAI,QAAQ,CAAC,CAAC;QAC7F,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACb,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,QAAQ,WAAW,CAAC,CAAC,CAAC;QAEpD,mDAAmD;QACnD,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,eAAe,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC;IAC7D,CAAC;CACD","sourcesContent":["// Derived from Pi-Bolt (MIT, Copyright (c) 2026 OpenSec (Pi-Bolt)), commit a6df6a2c; modified for HUMAIN Code CLI.\nimport {\n\ttype Component,\n\ttype Focusable,\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\";\nimport type { UsageBar, UsageLine, UsageOverview } from \"./overview.ts\";\n\nconst BAR_WIDTH = 24;\nconst MIN_BAR_WIDTH = 8;\nconst MAX_LABEL_WIDTH = 28;\n\nconst TONE_COLOR = {\n\taccent: \"accent\",\n\twarning: \"warning\",\n\terror: \"error\",\n\tsuccess: \"success\",\n} as const;\n\nfunction renderBar(theme: Theme, bar: UsageBar, width: number): string {\n\tconst frac = bar.total && bar.total > 0 ? Math.min(1, Math.max(0, bar.used / bar.total)) : 0;\n\tconst filled = Math.round(frac * width);\n\tconst fill = theme.fg(TONE_COLOR[bar.tone], \"█\".repeat(filled));\n\tconst empty = theme.fg(\"muted\", \"░\".repeat(width - filled));\n\treturn `${fill}${empty}`;\n}\n\n/**\n * A read-only view showing account/session usage with tqdm-style progress\n * bars. Esc (or a click) closes it.\n */\nexport class UsagePopupComponent implements Component, Focusable {\n\tfocused = false;\n\n\tprivate readonly theme: Theme;\n\tprivate readonly keybindings: KeybindingsManager;\n\tprivate readonly overview: UsageOverview;\n\tprivate readonly onClose: () => void;\n\n\tconstructor(theme: Theme, keybindings: KeybindingsManager, overview: UsageOverview, onClose: () => void) {\n\t\tthis.theme = theme;\n\t\tthis.keybindings = keybindings;\n\t\tthis.overview = overview;\n\t\tthis.onClose = onClose;\n\t}\n\n\thandleInput(data: string): void {\n\t\tif (this.keybindings.matches(data, \"tui.select.cancel\") || this.keybindings.matches(data, \"app.clear\")) {\n\t\t\tthis.onClose();\n\t\t}\n\t}\n\n\thandleMouse(event: TuiMouseEvent): TuiMouseEventResult {\n\t\tif (event.type === \"click\") this.onClose();\n\t\treturn { handled: true, render: false };\n\t}\n\n\tinvalidate(): void {}\n\n\trender(width: number): string[] {\n\t\tconst theme = this.theme;\n\t\tconst { providerId, modelId, bars, lines, notes } = this.overview;\n\t\tconst out: string[] = [];\n\t\tconst pad = \" \";\n\n\t\tconst row = (label: string, value: string, tone?: UsageLine[\"tone\"]): string => {\n\t\t\tconst padded = label.padEnd(13);\n\t\t\tconst coloredValue = tone ? theme.fg(TONE_COLOR[tone], value) : value;\n\t\t\treturn `${pad}${theme.fg(\"dim\", padded)} ${coloredValue}`;\n\t\t};\n\n\t\tout.push(theme.bold(\"Usage\"));\n\t\tout.push(theme.fg(\"dim\", `${providerId} · ${modelId}`));\n\t\tout.push(\"\");\n\n\t\tif (bars.length > 0) {\n\t\t\t// One row per bar keeps several limit windows on screen: label, bar, percentage, then the note when it fits.\n\t\t\tconst labelWidth = Math.min(MAX_LABEL_WIDTH, Math.max(...bars.map((bar) => visibleWidth(bar.label))));\n\t\t\tconst displayWidth = Math.max(...bars.map((bar) => visibleWidth(bar.display)));\n\t\t\tconst barWidth = Math.max(\n\t\t\t\tMIN_BAR_WIDTH,\n\t\t\t\tMath.min(BAR_WIDTH, width - pad.length - labelWidth - 1 - 2 - displayWidth),\n\t\t\t);\n\t\t\tfor (const bar of bars) {\n\t\t\t\tconst truncated = truncateToWidth(bar.label, labelWidth, \"…\");\n\t\t\t\tconst label = truncated + \" \".repeat(Math.max(0, labelWidth - visibleWidth(truncated)));\n\t\t\t\tconst head = `${pad}${theme.fg(\"dim\", label)} ${renderBar(theme, bar, barWidth)} ${theme.fg(\"dim\", bar.display)}`;\n\t\t\t\tconst note = bar.note ? theme.fg(\"dim\", bar.note) : undefined;\n\t\t\t\tif (note && visibleWidth(head) + 2 + visibleWidth(note) <= width) out.push(`${head} ${note}`);\n\t\t\t\telse {\n\t\t\t\t\tout.push(head);\n\t\t\t\t\tif (note) out.push(`${pad}${\" \".repeat(labelWidth + 1)}${note}`);\n\t\t\t\t}\n\t\t\t}\n\t\t\tout.push(\"\");\n\t\t}\n\n\t\tout.push(theme.bold(\"This session\"));\n\t\tfor (const line of lines) {\n\t\t\tout.push(row(line.label, line.value, line.tone));\n\t\t}\n\n\t\tif (notes.length > 0) {\n\t\t\tout.push(\"\");\n\t\t\tfor (const note of notes) {\n\t\t\t\tfor (const wrapped of wrapTextWithAnsi(note, Math.max(1, width))) out.push(theme.fg(\"warning\", wrapped));\n\t\t\t}\n\t\t}\n\n\t\tconst closeKey = formatKeyText(this.keybindings.getKeys(\"tui.select.cancel\")[0] ?? \"escape\");\n\t\tout.push(\"\");\n\t\tout.push(theme.fg(\"muted\", `${closeKey} to close`));\n\n\t\t// A line wider than the terminal aborts rendering.\n\t\treturn out.map((line) => truncateToWidth(line, width, \"…\"));\n\t}\n}\n"]}
|