@humain/humain-code 0.4.18 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (444) hide show
  1. package/CHANGELOG.md +247 -0
  2. package/dist/bundle/agent-monitor.js +1 -1
  3. package/dist/bundle/chunks/anthropic-messages-ZP5KUK52.js +67 -0
  4. package/dist/bundle/chunks/anthropic.js +2 -2
  5. package/dist/bundle/chunks/azure-openai-responses-QJFYQ3DF.js +15 -0
  6. package/dist/bundle/chunks/bedrock-converse-stream.js +152 -200
  7. package/dist/bundle/chunks/chunk-2GCMACT4.js +1956 -0
  8. package/dist/bundle/chunks/{chunk-7VY5IL74.js → chunk-476XBL3W.js} +3 -3
  9. package/dist/bundle/chunks/{chunk-P4UKLIQB.js → chunk-5C4VL2AR.js} +4 -4
  10. package/dist/bundle/chunks/{chunk-QEF72EIZ.js → chunk-A6B2QMA7.js} +40 -96
  11. package/dist/bundle/chunks/{chunk-3UXBFT4Q.js → chunk-A6YBWW4T.js} +1428 -1334
  12. package/dist/bundle/chunks/{chunk-OWLBGSXY.js → chunk-CN3Q5UNB.js} +388 -310
  13. package/dist/bundle/chunks/{chunk-SCIGZFN5.js → chunk-DNGJMRJW.js} +11 -11
  14. package/dist/bundle/chunks/{chunk-YMBXWW36.js → chunk-DR37WKFZ.js} +9 -8
  15. package/dist/bundle/chunks/chunk-DU6POZ7E.js +10 -0
  16. package/dist/bundle/chunks/{chunk-G6ABHCPB.js → chunk-FO2NYB6O.js} +655 -663
  17. package/dist/bundle/chunks/{chunk-RXOCQRBG.js → chunk-GEISZXXH.js} +1 -1
  18. package/dist/bundle/chunks/{chunk-OKALNPTJ.js → chunk-HIZWUSPN.js} +24 -24
  19. package/dist/bundle/chunks/{chunk-MVYV6MJY.js → chunk-HT5YN3LX.js} +1 -1
  20. package/dist/bundle/chunks/chunk-IDU5BNNI.js +15 -0
  21. package/dist/bundle/chunks/{chunk-TIFFHHW6.js → chunk-JCXXRCP6.js} +5 -5
  22. package/dist/bundle/chunks/{chunk-QYCOHSI7.js → chunk-KKCMWB63.js} +8 -7
  23. package/dist/bundle/chunks/{chunk-SCBU5WOP.js → chunk-M74U5X4S.js} +30 -23
  24. package/dist/bundle/chunks/{chunk-AWCJWXGD.js → chunk-MIJHJNNQ.js} +3 -2
  25. package/dist/bundle/chunks/{chunk-Y26OS23T.js → chunk-N7CQ3UV3.js} +4 -4
  26. package/dist/bundle/chunks/{chunk-XQZG5HPT.js → chunk-O4DO5RWS.js} +11 -6
  27. package/dist/bundle/chunks/chunk-OR25QDSS.js +365 -0
  28. package/dist/bundle/chunks/{chunk-7PRU6YW3.js → chunk-OZNC2W4B.js} +306 -286
  29. package/dist/bundle/chunks/{chunk-Z33NNMNB.js → chunk-PH7UP57J.js} +1 -1
  30. package/dist/bundle/chunks/{chunk-HPSQKIWK.js → chunk-PS7DGA7B.js} +1 -1
  31. package/dist/bundle/chunks/chunk-Q3SFYT2X.js +1965 -0
  32. package/dist/bundle/chunks/chunk-QW6PTCAB.js +10 -0
  33. package/dist/bundle/chunks/{chunk-5CDES42D.js → chunk-QWXPGBAG.js} +1 -1
  34. package/dist/bundle/chunks/{chunk-NCQ6WAQK.js → chunk-ROZV2IYD.js} +1 -1
  35. package/dist/bundle/chunks/{chunk-3XDL5ZE4.js → chunk-RTXDU3AA.js} +148 -122
  36. package/dist/bundle/chunks/{chunk-L5OUCJ7N.js → chunk-T3HXWZG4.js} +11 -11
  37. package/dist/bundle/chunks/{chunk-FZUJXM6D.js → chunk-UDB6NI4G.js} +309 -240
  38. package/dist/bundle/chunks/chunk-UTNHGOFS.js +88 -0
  39. package/dist/bundle/chunks/{chunk-H2FY3PEV.js → chunk-V62QBESW.js} +4 -3
  40. package/dist/bundle/chunks/{chunk-NSMMDV3N.js → chunk-XA7CJAYH.js} +4 -3
  41. package/dist/bundle/chunks/chunk-XQX7S3GM.js +7 -0
  42. package/dist/bundle/chunks/chunk-YFOLLX5D.js +23 -0
  43. package/dist/bundle/chunks/{chunk-YRCLNWFV.js → chunk-ZI7TK7HM.js} +1 -1
  44. package/dist/bundle/chunks/{chunk-V76YPIMT.js → chunk-ZR4GF4WU.js} +21 -15
  45. package/dist/bundle/chunks/{cli-2NKM2RNJ.js → cli-VXU7OWFU.js} +1 -1
  46. package/dist/bundle/chunks/cloudflare-workers-ai-system-one-T7TPP7SQ.js +4 -0
  47. package/dist/bundle/chunks/codemode-worker.js +27 -27
  48. package/dist/bundle/chunks/compat-S2IBVV6V.js +13 -0
  49. package/dist/bundle/chunks/{dist-ZJIYY3GA.js → dist-645GFIWH.js} +452 -448
  50. package/dist/bundle/chunks/{dist-XVXV2CL4.js → dist-IBUWEKEE.js} +3 -3
  51. package/dist/bundle/chunks/dist-YFMJEHPH.js +8 -0
  52. package/dist/bundle/chunks/{dist-cjs-AXBW3N4F.js → dist-cjs-HTASUQXQ.js} +82 -80
  53. package/dist/bundle/chunks/{easter-egg-3d-VGJ77XZQ.js → easter-egg-3d-YOPLCOVW.js} +2 -2
  54. package/dist/bundle/chunks/es-YEFEOGR3.js +1905 -0
  55. package/dist/bundle/chunks/{esm-GIR7QH65.js → esm-R6HJ4QEG.js} +5 -5
  56. package/dist/bundle/chunks/{event-streams-NXFTZDSF.js → event-streams-BR2IL6C5.js} +1 -1
  57. package/dist/bundle/chunks/{execute-ZBEZNJ4E.js → execute-2JXEKQ2X.js} +17 -8
  58. package/dist/bundle/chunks/{extract-RFWEHH6W.js → extract-OTCGZGTL.js} +50 -47
  59. package/dist/bundle/chunks/github-copilot.js +42 -40
  60. package/dist/bundle/chunks/google-generative-ai-HVPCGIZ6.js +21 -0
  61. package/dist/bundle/chunks/google-vertex-UM5MAALA.js +25 -0
  62. package/dist/bundle/chunks/host-ZHEL5XQW.js +2 -0
  63. package/dist/bundle/chunks/{https-proxy-agent-7CAXVAFH.js → https-proxy-agent-JQICCRPH.js} +1 -1
  64. package/dist/bundle/chunks/{llama-cpp-classify-AGCW7HYN.js → llama-cpp-classify-B3G57LVR.js} +5 -5
  65. package/dist/bundle/chunks/{mistral-conversations-G3GN6CMT.js → mistral-conversations-AH72RLXK.js} +11 -11
  66. package/dist/bundle/chunks/{node-A6SZ3T7E.js → node-SJPZTR4K.js} +190 -190
  67. package/dist/bundle/chunks/{node-DZCAT4Q6.js → node-VSA4ZN7D.js} +1 -1
  68. package/dist/bundle/chunks/openai-chatgpt.js +2 -2
  69. package/dist/bundle/chunks/{openai-codex-responses-FJFDAWHI.js → openai-codex-responses-L366637C.js} +48 -47
  70. package/dist/bundle/chunks/openai-codex.js +2 -2
  71. package/dist/bundle/chunks/openai-completions-ZP62QXJX.js +83 -0
  72. package/dist/bundle/chunks/{openai-decisions-HESOHYZB.js → openai-decisions-WOWUC65P.js} +1 -1
  73. package/dist/bundle/chunks/openai-responses-DXUGSUTN.js +26 -0
  74. package/dist/bundle/chunks/openrouter-images-5K47HDAT.js +8 -0
  75. package/dist/bundle/chunks/openrouter.js +2 -2
  76. package/dist/bundle/chunks/{pi-messages-SAOV3JNW.js → pi-messages-MOQQDZBK.js} +5 -4
  77. package/dist/bundle/chunks/radius.js +2 -2
  78. package/dist/bundle/chunks/{runtime-HJEUOD4R.js → runtime-5VFZTMWL.js} +1 -1
  79. package/dist/bundle/chunks/typesafe-system-one-43OCHGKP.js +3 -0
  80. package/dist/bundle/chunks/{undici-4BK3MVJV.js → undici-EK3EUI2E.js} +1 -1
  81. package/dist/bundle/chunks/virtual-modules-GU6AW5ZK.js +5 -0
  82. package/dist/bundle/cli-runtime.js +3 -3
  83. package/dist/bundle/flow/package.json +4 -4
  84. package/dist/bundle/index.js +6 -6
  85. package/dist/bundle/rpc-entry.js +3 -3
  86. package/dist/cli/args.d.ts +6 -0
  87. package/dist/cli/args.d.ts.map +1 -1
  88. package/dist/cli/args.js +11 -0
  89. package/dist/cli/args.js.map +1 -1
  90. package/dist/coordination/adapter/tool.d.ts.map +1 -1
  91. package/dist/coordination/adapter/tool.js +3 -1
  92. package/dist/coordination/adapter/tool.js.map +1 -1
  93. package/dist/coordination/broker/broker.d.ts +6 -2
  94. package/dist/coordination/broker/broker.d.ts.map +1 -1
  95. package/dist/coordination/broker/broker.js +20 -8
  96. package/dist/coordination/broker/broker.js.map +1 -1
  97. package/dist/coordination/client/client.d.ts.map +1 -1
  98. package/dist/coordination/client/client.js +4 -2
  99. package/dist/coordination/client/client.js.map +1 -1
  100. package/dist/coordination/transport/discovery.d.ts +10 -3
  101. package/dist/coordination/transport/discovery.d.ts.map +1 -1
  102. package/dist/coordination/transport/discovery.js +18 -5
  103. package/dist/coordination/transport/discovery.js.map +1 -1
  104. package/dist/core/agent-session.d.ts +35 -2
  105. package/dist/core/agent-session.d.ts.map +1 -1
  106. package/dist/core/agent-session.js +163 -40
  107. package/dist/core/agent-session.js.map +1 -1
  108. package/dist/core/anthropic-subscription-usage.d.ts +47 -0
  109. package/dist/core/anthropic-subscription-usage.d.ts.map +1 -0
  110. package/dist/core/anthropic-subscription-usage.js +170 -0
  111. package/dist/core/anthropic-subscription-usage.js.map +1 -0
  112. package/dist/core/bash-executor.d.ts.map +1 -1
  113. package/dist/core/bash-executor.js +7 -1
  114. package/dist/core/bash-executor.js.map +1 -1
  115. package/dist/core/client-identity.d.ts +13 -0
  116. package/dist/core/client-identity.d.ts.map +1 -0
  117. package/dist/core/client-identity.js +25 -0
  118. package/dist/core/client-identity.js.map +1 -0
  119. package/dist/core/codex-usage.d.ts +37 -1
  120. package/dist/core/codex-usage.d.ts.map +1 -1
  121. package/dist/core/codex-usage.js +104 -11
  122. package/dist/core/codex-usage.js.map +1 -1
  123. package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
  124. package/dist/core/compaction/branch-summarization.js +1 -2
  125. package/dist/core/compaction/branch-summarization.js.map +1 -1
  126. package/dist/core/compaction/compaction.d.ts +2 -2
  127. package/dist/core/compaction/compaction.d.ts.map +1 -1
  128. package/dist/core/compaction/compaction.js +20 -15
  129. package/dist/core/compaction/compaction.js.map +1 -1
  130. package/dist/core/export-html/index.d.ts.map +1 -1
  131. package/dist/core/export-html/index.js +2 -0
  132. package/dist/core/export-html/index.js.map +1 -1
  133. package/dist/core/export-html/template.html +1 -0
  134. package/dist/core/export-html/template.js +2 -1
  135. package/dist/core/export-html/vendor/marked-cjk-friendly.min.js +6 -0
  136. package/dist/core/export-html/vendor/marked.min.js +30 -29
  137. package/dist/core/extensions/loader.d.ts.map +1 -1
  138. package/dist/core/extensions/loader.js +3 -0
  139. package/dist/core/extensions/loader.js.map +1 -1
  140. package/dist/core/extensions/runner.d.ts +14 -0
  141. package/dist/core/extensions/runner.d.ts.map +1 -1
  142. package/dist/core/extensions/runner.js +86 -2
  143. package/dist/core/extensions/runner.js.map +1 -1
  144. package/dist/core/extensions/virtual-modules.d.ts.map +1 -1
  145. package/dist/core/extensions/virtual-modules.js +3 -0
  146. package/dist/core/extensions/virtual-modules.js.map +1 -1
  147. package/dist/core/model-config.d.ts +920 -0
  148. package/dist/core/model-config.d.ts.map +1 -1
  149. package/dist/core/model-config.js +48 -24
  150. package/dist/core/model-config.js.map +1 -1
  151. package/dist/core/model-registry.d.ts +18 -0
  152. package/dist/core/model-registry.d.ts.map +1 -1
  153. package/dist/core/model-registry.js +20 -0
  154. package/dist/core/model-registry.js.map +1 -1
  155. package/dist/core/model-resolver.d.ts.map +1 -1
  156. package/dist/core/model-resolver.js +14 -6
  157. package/dist/core/model-resolver.js.map +1 -1
  158. package/dist/core/model-runtime.d.ts +9 -0
  159. package/dist/core/model-runtime.d.ts.map +1 -1
  160. package/dist/core/model-runtime.js +99 -12
  161. package/dist/core/model-runtime.js.map +1 -1
  162. package/dist/core/output-guard.d.ts +13 -1
  163. package/dist/core/output-guard.d.ts.map +1 -1
  164. package/dist/core/output-guard.js +101 -11
  165. package/dist/core/output-guard.js.map +1 -1
  166. package/dist/core/provider-composer.d.ts +2 -1
  167. package/dist/core/provider-composer.d.ts.map +1 -1
  168. package/dist/core/provider-composer.js +7 -3
  169. package/dist/core/provider-composer.js.map +1 -1
  170. package/dist/core/remote-catalog-provider.d.ts.map +1 -1
  171. package/dist/core/remote-catalog-provider.js +7 -2
  172. package/dist/core/remote-catalog-provider.js.map +1 -1
  173. package/dist/core/sdk.d.ts.map +1 -1
  174. package/dist/core/sdk.js +8 -9
  175. package/dist/core/sdk.js.map +1 -1
  176. package/dist/core/session-manager.d.ts +4 -0
  177. package/dist/core/session-manager.d.ts.map +1 -1
  178. package/dist/core/session-manager.js +242 -26
  179. package/dist/core/session-manager.js.map +1 -1
  180. package/dist/core/system-prompt.d.ts +6 -1
  181. package/dist/core/system-prompt.d.ts.map +1 -1
  182. package/dist/core/system-prompt.js +93 -1
  183. package/dist/core/system-prompt.js.map +1 -1
  184. package/dist/core/tools/grep.d.ts.map +1 -1
  185. package/dist/core/tools/grep.js +3 -1
  186. package/dist/core/tools/grep.js.map +1 -1
  187. package/dist/core/tools/ls.d.ts.map +1 -1
  188. package/dist/core/tools/ls.js +37 -12
  189. package/dist/core/tools/ls.js.map +1 -1
  190. package/dist/extensions/codemode/execute.d.ts.map +1 -1
  191. package/dist/extensions/codemode/execute.js +102 -24
  192. package/dist/extensions/codemode/execute.js.map +1 -1
  193. package/dist/extensions/index.d.ts.map +1 -1
  194. package/dist/extensions/index.js +3 -1
  195. package/dist/extensions/index.js.map +1 -1
  196. package/dist/extensions/mcp/config.d.ts.map +1 -1
  197. package/dist/extensions/mcp/config.js +3 -2
  198. package/dist/extensions/mcp/config.js.map +1 -1
  199. package/dist/extensions/usage/index.d.ts +15 -0
  200. package/dist/extensions/usage/index.d.ts.map +1 -0
  201. package/dist/extensions/usage/index.js +110 -0
  202. package/dist/extensions/usage/index.js.map +1 -0
  203. package/dist/extensions/usage/overview.d.ts +90 -0
  204. package/dist/extensions/usage/overview.d.ts.map +1 -0
  205. package/dist/extensions/usage/overview.js +215 -0
  206. package/dist/extensions/usage/overview.js.map +1 -0
  207. package/dist/extensions/usage/popup.d.ts +21 -0
  208. package/dist/extensions/usage/popup.d.ts.map +1 -0
  209. package/dist/extensions/usage/popup.js +98 -0
  210. package/dist/extensions/usage/popup.js.map +1 -0
  211. package/dist/humain/bedrock-provider/vendor/index.bundle.mjs +21 -2
  212. package/dist/humain/bundled-extension-names.d.ts +6 -0
  213. package/dist/humain/bundled-extension-names.d.ts.map +1 -0
  214. package/dist/humain/bundled-extension-names.js +9 -0
  215. package/dist/humain/bundled-extension-names.js.map +1 -0
  216. package/dist/humain/index.d.ts +2 -2
  217. package/dist/humain/index.d.ts.map +1 -1
  218. package/dist/humain/index.js +3 -2
  219. package/dist/humain/index.js.map +1 -1
  220. package/dist/humain/web-access/vendor/anysearch.d.ts.map +1 -1
  221. package/dist/humain/web-access/vendor/anysearch.js +3 -3
  222. package/dist/humain/web-access/vendor/anysearch.js.map +1 -1
  223. package/dist/humain/web-access/vendor/bocha.d.ts.map +1 -1
  224. package/dist/humain/web-access/vendor/bocha.js +3 -3
  225. package/dist/humain/web-access/vendor/bocha.js.map +1 -1
  226. package/dist/humain/web-access/vendor/brightdata-unlocker.d.ts.map +1 -1
  227. package/dist/humain/web-access/vendor/brightdata-unlocker.js +2 -2
  228. package/dist/humain/web-access/vendor/brightdata-unlocker.js.map +1 -1
  229. package/dist/humain/web-access/vendor/brightdata.d.ts.map +1 -1
  230. package/dist/humain/web-access/vendor/brightdata.js +3 -3
  231. package/dist/humain/web-access/vendor/brightdata.js.map +1 -1
  232. package/dist/humain/web-access/vendor/ceramic.d.ts.map +1 -1
  233. package/dist/humain/web-access/vendor/ceramic.js +2 -2
  234. package/dist/humain/web-access/vendor/ceramic.js.map +1 -1
  235. package/dist/humain/web-access/vendor/curator-page.d.ts.map +1 -1
  236. package/dist/humain/web-access/vendor/curator-page.js +3 -1
  237. package/dist/humain/web-access/vendor/curator-page.js.map +1 -1
  238. package/dist/humain/web-access/vendor/curator-server.d.ts.map +1 -1
  239. package/dist/humain/web-access/vendor/curator-server.js +2 -0
  240. package/dist/humain/web-access/vendor/curator-server.js.map +1 -1
  241. package/dist/humain/web-access/vendor/deepseek.d.ts +11 -1
  242. package/dist/humain/web-access/vendor/deepseek.d.ts.map +1 -1
  243. package/dist/humain/web-access/vendor/deepseek.js +170 -5
  244. package/dist/humain/web-access/vendor/deepseek.js.map +1 -1
  245. package/dist/humain/web-access/vendor/extract.d.ts.map +1 -1
  246. package/dist/humain/web-access/vendor/extract.js +63 -6
  247. package/dist/humain/web-access/vendor/extract.js.map +1 -1
  248. package/dist/humain/web-access/vendor/gemini-search.d.ts +5 -3
  249. package/dist/humain/web-access/vendor/gemini-search.d.ts.map +1 -1
  250. package/dist/humain/web-access/vendor/gemini-search.js +33 -7
  251. package/dist/humain/web-access/vendor/gemini-search.js.map +1 -1
  252. package/dist/humain/web-access/vendor/index.d.ts +1 -0
  253. package/dist/humain/web-access/vendor/index.d.ts.map +1 -1
  254. package/dist/humain/web-access/vendor/index.js +18 -3
  255. package/dist/humain/web-access/vendor/index.js.map +1 -1
  256. package/dist/humain/web-access/vendor/jina-search.d.ts.map +1 -1
  257. package/dist/humain/web-access/vendor/jina-search.js +6 -4
  258. package/dist/humain/web-access/vendor/jina-search.js.map +1 -1
  259. package/dist/humain/web-access/vendor/kagi.d.ts.map +1 -1
  260. package/dist/humain/web-access/vendor/kagi.js +4 -4
  261. package/dist/humain/web-access/vendor/kagi.js.map +1 -1
  262. package/dist/humain/web-access/vendor/keenable.d.ts.map +1 -1
  263. package/dist/humain/web-access/vendor/keenable.js +2 -2
  264. package/dist/humain/web-access/vendor/keenable.js.map +1 -1
  265. package/dist/humain/web-access/vendor/linkup.d.ts +6 -0
  266. package/dist/humain/web-access/vendor/linkup.d.ts.map +1 -0
  267. package/dist/humain/web-access/vendor/linkup.js +167 -0
  268. package/dist/humain/web-access/vendor/linkup.js.map +1 -0
  269. package/dist/humain/web-access/vendor/mistral-search.d.ts.map +1 -1
  270. package/dist/humain/web-access/vendor/mistral-search.js +3 -3
  271. package/dist/humain/web-access/vendor/mistral-search.js.map +1 -1
  272. package/dist/humain/web-access/vendor/ollama.d.ts.map +1 -1
  273. package/dist/humain/web-access/vendor/ollama.js +4 -4
  274. package/dist/humain/web-access/vendor/ollama.js.map +1 -1
  275. package/dist/humain/web-access/vendor/parallel.js +6 -7
  276. package/dist/humain/web-access/vendor/parallel.js.map +1 -1
  277. package/dist/humain/web-access/vendor/perplexity.d.ts.map +1 -1
  278. package/dist/humain/web-access/vendor/perplexity.js +4 -3
  279. package/dist/humain/web-access/vendor/perplexity.js.map +1 -1
  280. package/dist/humain/web-access/vendor/querit.d.ts.map +1 -1
  281. package/dist/humain/web-access/vendor/querit.js +3 -3
  282. package/dist/humain/web-access/vendor/querit.js.map +1 -1
  283. package/dist/humain/web-access/vendor/search1api.d.ts.map +1 -1
  284. package/dist/humain/web-access/vendor/search1api.js +3 -3
  285. package/dist/humain/web-access/vendor/search1api.js.map +1 -1
  286. package/dist/humain/web-access/vendor/searchinfinity.d.ts.map +1 -1
  287. package/dist/humain/web-access/vendor/searchinfinity.js +3 -3
  288. package/dist/humain/web-access/vendor/searchinfinity.js.map +1 -1
  289. package/dist/humain/web-access/vendor/serpapi.d.ts.map +1 -1
  290. package/dist/humain/web-access/vendor/serpapi.js +6 -5
  291. package/dist/humain/web-access/vendor/serpapi.js.map +1 -1
  292. package/dist/humain/web-access/vendor/serpbase.d.ts.map +1 -1
  293. package/dist/humain/web-access/vendor/serpbase.js +4 -4
  294. package/dist/humain/web-access/vendor/serpbase.js.map +1 -1
  295. package/dist/humain/web-access/vendor/serpdive.d.ts.map +1 -1
  296. package/dist/humain/web-access/vendor/serpdive.js +3 -3
  297. package/dist/humain/web-access/vendor/serpdive.js.map +1 -1
  298. package/dist/humain/web-access/vendor/serper.d.ts.map +1 -1
  299. package/dist/humain/web-access/vendor/serper.js +5 -4
  300. package/dist/humain/web-access/vendor/serper.js.map +1 -1
  301. package/dist/humain/web-access/vendor/serply.d.ts.map +1 -1
  302. package/dist/humain/web-access/vendor/serply.js +2 -2
  303. package/dist/humain/web-access/vendor/serply.js.map +1 -1
  304. package/dist/humain/web-access/vendor/utils.d.ts +3 -1
  305. package/dist/humain/web-access/vendor/utils.d.ts.map +1 -1
  306. package/dist/humain/web-access/vendor/utils.js +27 -2
  307. package/dist/humain/web-access/vendor/utils.js.map +1 -1
  308. package/dist/humain/web-access/vendor/valyu.d.ts.map +1 -1
  309. package/dist/humain/web-access/vendor/valyu.js +3 -3
  310. package/dist/humain/web-access/vendor/valyu.js.map +1 -1
  311. package/dist/humain/web-access/vendor/web-tool-core.d.ts +2 -0
  312. package/dist/humain/web-access/vendor/web-tool-core.d.ts.map +1 -1
  313. package/dist/humain/web-access/vendor/web-tool-core.js +3 -0
  314. package/dist/humain/web-access/vendor/web-tool-core.js.map +1 -1
  315. package/dist/humain/web-access/vendor/xai-search.d.ts.map +1 -1
  316. package/dist/humain/web-access/vendor/xai-search.js +51 -8
  317. package/dist/humain/web-access/vendor/xai-search.js.map +1 -1
  318. package/dist/humain/web-access/vendor/xcrawl.d.ts.map +1 -1
  319. package/dist/humain/web-access/vendor/xcrawl.js +3 -3
  320. package/dist/humain/web-access/vendor/xcrawl.js.map +1 -1
  321. package/dist/humain/web-access/vendor/you.d.ts.map +1 -1
  322. package/dist/humain/web-access/vendor/you.js +2 -2
  323. package/dist/humain/web-access/vendor/you.js.map +1 -1
  324. package/dist/main.d.ts.map +1 -1
  325. package/dist/main.js +15 -2
  326. package/dist/main.js.map +1 -1
  327. package/dist/modes/interactive/components/assistant-message.d.ts +14 -2
  328. package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
  329. package/dist/modes/interactive/components/assistant-message.js +62 -7
  330. package/dist/modes/interactive/components/assistant-message.js.map +1 -1
  331. package/dist/modes/interactive/components/config-selector.js +1 -1
  332. package/dist/modes/interactive/components/config-selector.js.map +1 -1
  333. package/dist/modes/interactive/components/custom-editor.d.ts +2 -0
  334. package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
  335. package/dist/modes/interactive/components/custom-editor.js +6 -1
  336. package/dist/modes/interactive/components/custom-editor.js.map +1 -1
  337. package/dist/modes/interactive/components/easter-egg-3d.js +1 -1
  338. package/dist/modes/interactive/components/easter-egg-3d.js.map +1 -1
  339. package/dist/modes/interactive/components/footer.d.ts +10 -2
  340. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  341. package/dist/modes/interactive/components/footer.js +141 -66
  342. package/dist/modes/interactive/components/footer.js.map +1 -1
  343. package/dist/modes/interactive/components/mermaid.d.ts.map +1 -1
  344. package/dist/modes/interactive/components/mermaid.js +16 -3
  345. package/dist/modes/interactive/components/mermaid.js.map +1 -1
  346. package/dist/modes/interactive/components/model-selector.js +1 -1
  347. package/dist/modes/interactive/components/model-selector.js.map +1 -1
  348. package/dist/modes/interactive/components/themed-text.d.ts.map +1 -1
  349. package/dist/modes/interactive/components/themed-text.js +3 -2
  350. package/dist/modes/interactive/components/themed-text.js.map +1 -1
  351. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  352. package/dist/modes/interactive/components/tool-execution.js +17 -6
  353. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  354. package/dist/modes/interactive/components/user-message.d.ts.map +1 -1
  355. package/dist/modes/interactive/components/user-message.js +3 -2
  356. package/dist/modes/interactive/components/user-message.js.map +1 -1
  357. package/dist/modes/interactive/components/visual-truncate.d.ts.map +1 -1
  358. package/dist/modes/interactive/components/visual-truncate.js +4 -2
  359. package/dist/modes/interactive/components/visual-truncate.js.map +1 -1
  360. package/dist/modes/interactive/interactive-mode.d.ts +13 -17
  361. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  362. package/dist/modes/interactive/interactive-mode.js +90 -122
  363. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  364. package/dist/modes/print-mode.d.ts.map +1 -1
  365. package/dist/modes/print-mode.js +2 -5
  366. package/dist/modes/print-mode.js.map +1 -1
  367. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  368. package/dist/modes/rpc/rpc-mode.js +2 -3
  369. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  370. package/dist/package-manager-cli.d.ts.map +1 -1
  371. package/dist/package-manager-cli.js +2 -1
  372. package/dist/package-manager-cli.js.map +1 -1
  373. package/dist/utils/child-process.d.ts.map +1 -1
  374. package/dist/utils/child-process.js +3 -2
  375. package/dist/utils/child-process.js.map +1 -1
  376. package/dist/utils/clipboard-command.d.ts.map +1 -1
  377. package/dist/utils/clipboard-command.js +3 -0
  378. package/dist/utils/clipboard-command.js.map +1 -1
  379. package/dist/utils/pi-user-agent.d.ts +1 -0
  380. package/dist/utils/pi-user-agent.d.ts.map +1 -1
  381. package/dist/utils/pi-user-agent.js +3 -2
  382. package/dist/utils/pi-user-agent.js.map +1 -1
  383. package/dist/utils/shell.d.ts.map +1 -1
  384. package/dist/utils/shell.js +45 -13
  385. package/dist/utils/shell.js.map +1 -1
  386. package/dist/utils/tools-manager.d.ts.map +1 -1
  387. package/dist/utils/tools-manager.js +4 -3
  388. package/dist/utils/tools-manager.js.map +1 -1
  389. package/docs/codemode.md +2 -2
  390. package/docs/compaction.md +3 -3
  391. package/docs/coordination.md +1 -1
  392. package/docs/custom-provider.md +53 -1
  393. package/docs/docs.json +4 -0
  394. package/docs/environment-variables.md +2 -0
  395. package/docs/extensions.md +133 -10
  396. package/docs/models-configuration.md +197 -0
  397. package/docs/models.md +21 -5
  398. package/docs/settings.md +1 -1
  399. package/docs/slash-commands.md +10 -0
  400. package/docs/tui.md +70 -0
  401. package/docs/windows.md +16 -2
  402. package/examples/extensions/custom-provider-anthropic/package.json +2 -2
  403. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  404. package/examples/extensions/gondolin/package-lock.json +2 -2
  405. package/examples/extensions/gondolin/package.json +1 -1
  406. package/examples/extensions/sandbox/package-lock.json +2 -2
  407. package/examples/extensions/sandbox/package.json +2 -2
  408. package/examples/extensions/with-deps/package.json +1 -1
  409. package/examples/plugins/pi-example-plugin/package.json +2 -2
  410. package/npm-shrinkwrap.json +243 -219
  411. package/package.json +21 -20
  412. package/schemas/models.schema.json +84 -30
  413. package/src/coordination/UPSTREAM.md +36 -3
  414. package/src/coordination/upstream.json +3 -3
  415. package/src/humain/web-access/UPSTREAM.md +72 -1
  416. package/src/humain/web-access/upstream.json +5 -4
  417. package/dist/bundle/chunks/anthropic-messages-TSNY5MWH.js +0 -67
  418. package/dist/bundle/chunks/azure-openai-responses-Z4DCXO2G.js +0 -15
  419. package/dist/bundle/chunks/chunk-26EAEXO5.js +0 -167
  420. package/dist/bundle/chunks/chunk-2ZFUMXOZ.js +0 -1790
  421. package/dist/bundle/chunks/chunk-5K5RFXXO.js +0 -74
  422. package/dist/bundle/chunks/chunk-PY7SOXCA.js +0 -10
  423. package/dist/bundle/chunks/chunk-UGJAAWNC.js +0 -7
  424. package/dist/bundle/chunks/chunk-UGXYG7HN.js +0 -22
  425. package/dist/bundle/chunks/chunk-VEYTRNQC.js +0 -5
  426. package/dist/bundle/chunks/chunk-X3O5MCKJ.js +0 -7
  427. package/dist/bundle/chunks/chunk-YLYOJQQX.js +0 -1951
  428. package/dist/bundle/chunks/cloudflare-workers-ai-system-one-MUJQ6LT2.js +0 -4
  429. package/dist/bundle/chunks/compat-VDGEZSVM.js +0 -13
  430. package/dist/bundle/chunks/dist-LKDZAEUQ.js +0 -7
  431. package/dist/bundle/chunks/es-N6YFJOD7.js +0 -1901
  432. package/dist/bundle/chunks/google-generative-ai-4OVYRP24.js +0 -21
  433. package/dist/bundle/chunks/google-vertex-3WQAZJQD.js +0 -25
  434. package/dist/bundle/chunks/host-63SNKK5Y.js +0 -2
  435. package/dist/bundle/chunks/openai-completions-IC7WRLTI.js +0 -82
  436. package/dist/bundle/chunks/openai-responses-XXCYDFSM.js +0 -24
  437. package/dist/bundle/chunks/openrouter-images-DT2HMZNO.js +0 -8
  438. package/dist/bundle/chunks/typesafe-system-one-HCMGHK6A.js +0 -2
  439. package/dist/bundle/chunks/virtual-modules-CFJTDIXL.js +0 -5
  440. package/dist/core/provider-attribution.d.ts +0 -4
  441. package/dist/core/provider-attribution.d.ts.map +0 -1
  442. package/dist/core/provider-attribution.js +0 -85
  443. package/dist/core/provider-attribution.js.map +0 -1
  444. /package/dist/bundle/chunks/{chunk-WZMA7HAJ.js → chunk-XQRYOCHA.js} +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/extensions/mcp/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EACN,SAAS,EACT,UAAU,EACV,SAAS,EACT,SAAS,EACT,YAAY,EACZ,YAAY,EACZ,UAAU,EACV,MAAM,EACN,QAAQ,EACR,aAAa,GACb,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,QAAQ,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAGN,YAAY,EACZ,uBAAuB,GACvB,MAAM,2BAA2B,CAAC;AASnC,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAyB/D,MAAM,aAAa,GAAG,CAAC,SAAS,EAAE,UAAU,EAAE,cAAc,CAAC,CAAC;AAE9D,qFAAqF;AACrF,SAAS,UAAU,CAAC,KAA8B;IACjD,OAAO,KAAK,CAAC,OAAO,KAAK,SAAS,IAAI,KAAK,CAAC,GAAG,KAAK,SAAS,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS,CAAC;AAC3F,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC/B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC7E,CAAC;AAQD,SAAS,cAAc,CAAC,IAAY,EAAE,KAA2B,EAAE,KAAqB;I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O,EAAE,MAAM,CAAC;YAAE,OAAO;QACnC,MAAM,MAAM,GAAG,CAAC,IAAI,IAAI,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;QAChE,MAAM,UAAU,GAAG,SAAS,CAAC;QAC7B,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,GAAG,UAAU,EAAE,MAAM,CAAC,CAAC;QAClE,0FAA0F;QAC1F,MAAM,IAAI,GAAG,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC;QAC5E,IAAI,CAAC;YACJ,aAAa,CAAC,QAAQ,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;YAC3F,SAAS,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;YAC1B,UAAU,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;QAClC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,MAAM,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;YAClC,MAAM,KAAK,CAAC;QACb,CAAC;IACF,CAAC;YAAS,CAAC;QACV,OAAO,EAAE,CAAC;IACX,CAAC;AACF,CAAC","sourcesContent":["/**\n * MCP server configuration.\n *\n * Servers are read from `mcp.json` in the agent directory and, for trusted projects, from\n * `<project>/.pi/mcp.json`. Both use the `mcpServers` shape shared by other MCP clients, so\n * existing configurations can be copied over. Project entries replace global entries with the\n * same name.\n *\n * A project entry without `command`, `url`, or `type` overrides only `enabled`, `exposure`, and\n * `toolExposure` of the global server with the same name, for example to turn it off in one project:\n * `{ \"mcpServers\": { \"internal-tools\": { \"enabled\": false } } }`. The rest of the global entry is kept,\n * including credentials the project could not set itself.\n *\n * ```json\n * {\n * \"mcpServers\": {\n * \"filesystem\": { \"command\": \"npx\", \"args\": [\"-y\", \"@modelcontextprotocol/server-filesystem\", \".\"] },\n * \"docs\": { \"url\": \"https://example.com/mcp\", \"headers\": { \"Authorization\": \"Bearer ${DOCS_TOKEN}\" } },\n * \"sentry\": { \"url\": \"https://mcp.sentry.dev/mcp\" }\n * }\n * }\n * ```\n *\n * HTTP servers without an `Authorization` header use OAuth when they answer 401 (sign in with `/mcp`).\n * `\"auth\": { \"provider\": \"<provider>\" }` sends the token of a `/login` provider instead. Project files\n * cannot use it, so a repository cannot pick where the credential goes.\n *\n * The top-level `autoEnableCodemode` (default true) activates the codemode tool when a server\n * with `codemode` exposure connects. A project value overrides the global one.\n */\n\nimport { randomUUID } from \"node:crypto\";\nimport {\n\tchmodSync,\n\texistsSync,\n\tlstatSync,\n\tmkdirSync,\n\treadFileSync,\n\trealpathSync,\n\trenameSync,\n\trmSync,\n\tstatSync,\n\twriteFileSync,\n} from \"node:fs\";\nimport { basename, dirname, join } from \"node:path\";\nimport lockfile from \"proper-lockfile\";\nimport { CONFIG_DIR_NAME } from \"../../config.ts\";\nimport {\n\ttype McpExposure,\n\ttype McpServerConfig,\n\tmcpNamespace,\n\tvalidateMcpServerConfig,\n} from \"../../core/mcp-servers.ts\";\n\nexport type {\n\tMcpExposure,\n\tMcpHttpServerConfig,\n\tMcpOAuthConfig,\n\tMcpServerConfig,\n\tMcpStdioServerConfig,\n} from \"../../core/mcp-servers.ts\";\nexport { getMcpToolExposure } from \"../../core/mcp-servers.ts\";\n\nexport interface McpServerEntry {\n\tname: string;\n\tconfig: McpServerConfig;\n\t/** Config file that defined the entry, or the path of the extension that registered it. */\n\tsource: string;\n\t/**\n\t * The global or the project `mcp.json`, or `extension` for servers registered with\n\t * `pi.registerMcpServer()`. Changes to extension servers are not saved.\n\t */\n\tscope?: \"global\" | \"project\" | \"extension\";\n\t/** Project `mcp.json` with an override of this global server's `enabled`, `exposure`, or `toolExposure`. */\n\toverride?: string;\n}\n\nexport interface LoadedMcpConfig {\n\tservers: McpServerEntry[];\n\t/** Activate the codemode tool when `codemode` servers connect. Default: true. */\n\tautoEnableCodemode?: boolean;\n\terrors: string[];\n\t/** The project `mcp.json` when the project is trusted, where `/mcp` saves project overrides. */\n\tprojectConfig?: string;\n}\n\nconst OVERRIDE_KEYS = [\"enabled\", \"exposure\", \"toolExposure\"];\n\n/** Whether an entry overrides a server defined elsewhere instead of defining one. */\nfunction isOverride(value: Record<string, unknown>): boolean {\n\treturn value.command === undefined && value.url === undefined && value.type === undefined;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\ninterface McpConfigState {\n\tservers: Map<string, McpServerEntry>;\n\tautoEnableCodemode?: boolean;\n\terrors: string[];\n}\n\nfunction readConfigFile(path: string, scope: \"global\" | \"project\", state: McpConfigState): void {\n\tconst { servers, errors } = state;\n\tif (!existsSync(path)) return;\n\tlet parsed: unknown;\n\ttry {\n\t\tparsed = JSON.parse(readFileSync(path, \"utf8\"));\n\t} catch (error) {\n\t\terrors.push(`${path}: ${error instanceof Error ? error.message : String(error)}`);\n\t\treturn;\n\t}\n\tif (!isRecord(parsed) || (parsed.mcpServers !== undefined && !isRecord(parsed.mcpServers))) {\n\t\terrors.push(`${path}: expected an object with an \"mcpServers\" object`);\n\t\treturn;\n\t}\n\tif (typeof parsed.autoEnableCodemode === \"boolean\") state.autoEnableCodemode = parsed.autoEnableCodemode;\n\telse if (parsed.autoEnableCodemode !== undefined) errors.push(`${path}: autoEnableCodemode must be a boolean`);\n\tfor (const [name, value] of Object.entries(parsed.mcpServers ?? {})) {\n\t\tif (scope === \"project\" && isRecord(value) && isOverride(value)) {\n\t\t\tconst base = servers.get(name);\n\t\t\tconst extra = Object.keys(value).filter((key) => !OVERRIDE_KEYS.includes(key));\n\t\t\tif (!base) {\n\t\t\t\terrors.push(`${path}: server \"${name}\" needs \"command\" or \"url\", or a global server to override`);\n\t\t\t} else if (extra.length > 0) {\n\t\t\t\terrors.push(`${path}: server \"${name}\": an override can only set ${OVERRIDE_KEYS.join(\", \")}`);\n\t\t\t} else {\n\t\t\t\tconst config = validateMcpServerConfig(name, { ...base.config, ...value });\n\t\t\t\tif (typeof config === \"string\") errors.push(`${path}: ${config}`);\n\t\t\t\telse servers.set(name, { ...base, config, override: path });\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tconst config = validateMcpServerConfig(name, value);\n\t\tif (typeof config === \"string\") {\n\t\t\terrors.push(`${path}: ${config}`);\n\t\t\tcontinue;\n\t\t}\n\t\t// Names that differ only in `-` and `_` would share a namespace.\n\t\tconst clash = [...servers.keys()].find((other) => other !== name && mcpNamespace(other) === mcpNamespace(name));\n\t\tif (clash) {\n\t\t\terrors.push(`${path}: server \"${name}\" conflicts with \"${clash}\"`);\n\t\t\tcontinue;\n\t\t}\n\t\tif (scope === \"project\" && \"url\" in config && config.auth) {\n\t\t\terrors.push(`${path}: server \"${name}\": auth is only allowed in the global mcp.json`);\n\t\t\tcontinue;\n\t\t}\n\t\tservers.set(name, { name, config, source: path, scope });\n\t}\n}\n\n/**\n * Load global and (when trusted) project MCP configuration. Disabled servers are included with\n * `enabled: false`, so they can be enabled again.\n */\nexport function loadMcpConfig(options: { agentDir: string; cwd: string; projectTrusted: boolean }): LoadedMcpConfig {\n\tconst state: McpConfigState = { servers: new Map(), errors: [] };\n\treadConfigFile(join(options.agentDir, \"mcp.json\"), \"global\", state);\n\tconst projectConfig = options.projectTrusted ? join(options.cwd, CONFIG_DIR_NAME, \"mcp.json\") : undefined;\n\tif (projectConfig) readConfigFile(projectConfig, \"project\", state);\n\treturn {\n\t\tservers: [...state.servers.values()],\n\t\t...(state.autoEnableCodemode === undefined ? {} : { autoEnableCodemode: state.autoEnableCodemode }),\n\t\terrors: state.errors,\n\t\t...(projectConfig ? { projectConfig } : {}),\n\t};\n}\n\n/** Settings `/mcp` changes. `enabled: true` and `exposure: \"codemode\"` are the defaults and remove the key. */\nexport interface McpServerConfigPatch {\n\tenabled?: boolean;\n\texposure?: McpExposure;\n}\n\n/**\n * Change one server's settings in the `mcp.json` that defines or overrides it. With `override`, a\n * missing entry is added as an override. Overrides keep default values, since they replace the global\n * server's. Other content is kept; the file is rewritten with its indentation.\n */\nexport function updateMcpServerConfig(\n\tpath: string,\n\tname: string,\n\tpatch: McpServerConfigPatch,\n\toptions: { override?: boolean } = {},\n): void {\n\teditMcpServers(path, (servers, parsed) => {\n\t\tlet server = servers?.[name];\n\t\tif (server === undefined && options.override) {\n\t\t\tserver = {};\n\t\t\tparsed.mcpServers = { ...servers, [name]: server };\n\t\t}\n\t\tif (!isRecord(server)) throw new Error(`${path} does not define MCP server \"${name}\"`);\n\t\tconst keepDefaults = isOverride(server);\n\t\tif (patch.enabled !== undefined) {\n\t\t\tif (patch.enabled && !keepDefaults) delete server.enabled;\n\t\t\telse server.enabled = patch.enabled;\n\t\t}\n\t\tif (patch.exposure !== undefined) {\n\t\t\tif (patch.exposure === \"codemode\" && !keepDefaults) delete server.exposure;\n\t\t\telse server.exposure = patch.exposure;\n\t\t}\n\t\treturn true;\n\t});\n}\n\n/**\n * Add a server to an `mcp.json`, creating the file when missing. An existing entry with the same\n * name is replaced. Returns true when an entry was replaced.\n */\nexport function addMcpServerConfig(path: string, name: string, config: McpServerConfig): boolean {\n\treturn updateMcpConfigLocked(path, (servers) => {\n\t\tconst replaced = servers[name] !== undefined;\n\t\tservers[name] = config;\n\t\treturn replaced;\n\t});\n}\n\n/**\n * Add a server only when no entry has the same MCP namespace (`-` and `_` are equivalent). The check runs\n * inside the same locked read-modify-write as the write and counts every raw entry, valid or not. Returns\n * false, leaving the file untouched, when the name is occupied.\n */\nexport function addMcpServerConfigIfAbsent(path: string, name: string, config: McpServerConfig): boolean {\n\treturn updateMcpConfigLocked(path, (servers) => {\n\t\tconst namespace = mcpNamespace(name);\n\t\tif (Object.keys(servers).some((existing) => mcpNamespace(existing) === namespace)) return false;\n\t\tservers[name] = config;\n\t\treturn true;\n\t});\n}\n\n/**\n * Run `mutate` on the raw `mcpServers` of an `mcp.json` while holding a cross-process lock, so the read,\n * the decision and the write cannot interleave with another process. `mutate` may change `servers` in\n * place; the file is rewritten atomically only when its content changed. A missing file or directory is\n * treated as empty and created on write. Returns what `mutate` returns.\n */\nexport function updateMcpConfigLocked<T>(path: string, mutate: (servers: Record<string, unknown>) => T): T {\n\tlet result: T | undefined;\n\teditMcpServers(path, (servers, parsed) => {\n\t\tconst target = servers ?? {};\n\t\tconst before = JSON.stringify(target);\n\t\tresult = mutate(target);\n\t\tif (JSON.stringify(target) === before) return false;\n\t\tparsed.mcpServers = target;\n\t\treturn true;\n\t});\n\treturn result as T;\n}\n\n/** Raw `mcpServers` entries of an `mcp.json`, including ones that fail validation. Empty when missing. */\nexport function readRawMcpServers(path: string): Record<string, unknown> {\n\tif (!existsSync(path)) return {};\n\tconst { servers } = parseMcpFile(path, readFileSync(path, \"utf8\"));\n\treturn { ...servers };\n}\n\n/** Remove a server from an `mcp.json`. Returns false when the file does not define it. */\nexport function removeMcpServerConfig(path: string, name: string): boolean {\n\tif (!existsSync(path)) return false;\n\tlet removed = false;\n\teditMcpServers(path, (servers) => {\n\t\tif (!servers || servers[name] === undefined) return false;\n\t\tdelete servers[name];\n\t\tremoved = true;\n\t\treturn true;\n\t});\n\treturn removed;\n}\n\nfunction parseMcpFile(\n\tpath: string,\n\ttext: string | undefined,\n): { parsed: Record<string, unknown>; servers: Record<string, unknown> | undefined } {\n\tconst parsed: unknown = text === undefined ? {} : JSON.parse(text);\n\tif (!isRecord(parsed) || (parsed.mcpServers !== undefined && !isRecord(parsed.mcpServers))) {\n\t\tthrow new Error(`${path}: expected an object with an \"mcpServers\" object`);\n\t}\n\treturn { parsed, servers: isRecord(parsed.mcpServers) ? parsed.mcpServers : undefined };\n}\n\n/** Canonical identity of an `mcp.json`: its real path, or the real parent plus basename when it does not exist yet. */\nfunction canonicalMcpPath(path: string): string {\n\tmkdirSync(dirname(path), { recursive: true });\n\tlet isSymlink = false;\n\ttry {\n\t\tisSymlink = lstatSync(path).isSymbolicLink();\n\t} catch (error) {\n\t\tif ((error as NodeJS.ErrnoException).code !== \"ENOENT\") throw error;\n\t\treturn join(realpathSync(dirname(path)), basename(path));\n\t}\n\ttry {\n\t\treturn realpathSync(path);\n\t} catch (error) {\n\t\tif (isSymlink && (error as NodeJS.ErrnoException).code === \"ENOENT\") {\n\t\t\tthrow new Error(`Refusing to modify ${path}: it is a dangling symlink. Create its target or remove the link.`);\n\t\t}\n\t\tthrow error;\n\t}\n}\n\nfunction acquireMcpLockSync(path: string): () => void {\n\tconst dir = dirname(path);\n\tconst maxAttempts = 50;\n\tconst delayMs = 20;\n\tfor (let attempt = 1; ; attempt++) {\n\t\ttry {\n\t\t\treturn lockfile.lockSync(dir, { realpath: false, lockfilePath: `${path}.lock` });\n\t\t} catch (error) {\n\t\t\tconst code =\n\t\t\t\ttypeof error === \"object\" && error !== null && \"code\" in error\n\t\t\t\t\t? String((error as { code?: unknown }).code)\n\t\t\t\t\t: undefined;\n\t\t\tif (code !== \"ELOCKED\" || attempt === maxAttempts) throw error;\n\t\t\tconst start = Date.now();\n\t\t\twhile (Date.now() - start < delayMs) {\n\t\t\t\t// Sleep synchronously to avoid changing callers to async.\n\t\t\t}\n\t\t}\n\t}\n}\n\n/**\n * Under a cross-process lock, read an `mcp.json` (an empty config when missing), let `edit` change its\n * `mcpServers`, and write it back atomically with its indentation when `edit` returns true. Other\n * content is kept.\n */\nfunction editMcpServers(\n\tpath: string,\n\tedit: (servers: Record<string, unknown> | undefined, parsed: Record<string, unknown>) => boolean,\n): void {\n\t// Lock, read and replace all use one canonical identity, so symlink aliases share a lock.\n\tconst canonical = canonicalMcpPath(path);\n\tconst release = acquireMcpLockSync(canonical);\n\ttry {\n\t\t// The path may have been retargeted between canonicalization and acquiring the lock.\n\t\tif (canonicalMcpPath(path) !== canonical) {\n\t\t\tthrow new Error(`Refusing to modify ${path}: it changed while waiting for the lock. Retry.`);\n\t\t}\n\t\tconst text = existsSync(canonical) ? readFileSync(canonical, \"utf8\") : undefined;\n\t\tconst { parsed, servers } = parseMcpFile(path, text);\n\t\tif (!edit(servers, parsed)) return;\n\t\tconst indent = (text && /^([ \\t]+)\\S/m.exec(text)?.[1]) || \" \";\n\t\tconst targetPath = canonical;\n\t\tconst tempPath = join(dirname(targetPath), `${randomUUID()}.tmp`);\n\t\t// Never broaden an existing file's permissions (it may hold auth headers or env secrets).\n\t\tconst mode = text !== undefined ? statSync(targetPath).mode & 0o777 : 0o600;\n\t\ttry {\n\t\t\twriteFileSync(tempPath, `${JSON.stringify(parsed, null, indent)}\\n`, { flag: \"wx\", mode });\n\t\t\tchmodSync(tempPath, mode);\n\t\t\trenameSync(tempPath, targetPath);\n\t\t} catch (error) {\n\t\t\trmSync(tempPath, { force: true });\n\t\t\tthrow error;\n\t\t}\n\t} finally {\n\t\trelease();\n\t}\n}\n"]}
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/extensions/mcp/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EACN,SAAS,EACT,UAAU,EACV,SAAS,EACT,SAAS,EACT,YAAY,EACZ,YAAY,EACZ,UAAU,EACV,MAAM,EACN,QAAQ,EACR,aAAa,GACb,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,QAAQ,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAGN,YAAY,EACZ,uBAAuB,GACvB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,MAAM,q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CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;YAC1B,UAAU,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;QAClC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,MAAM,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;YAClC,MAAM,KAAK,CAAC;QACb,CAAC;IACF,CAAC;YAAS,CAAC;QACV,OAAO,EAAE,CAAC;IACX,CAAC;AACF,CAAC","sourcesContent":["/**\n * MCP server configuration.\n *\n * Servers are read from `mcp.json` in the agent directory and, for trusted projects, from\n * `<project>/.pi/mcp.json`. Both use the `mcpServers` shape shared by other MCP clients, so\n * existing configurations can be copied over. Project entries replace global entries with the\n * same name.\n *\n * A project entry without `command`, `url`, or `type` overrides only `enabled`, `exposure`, and\n * `toolExposure` of the global server with the same name, for example to turn it off in one project:\n * `{ \"mcpServers\": { \"internal-tools\": { \"enabled\": false } } }`. The rest of the global entry is kept,\n * including credentials the project could not set itself.\n *\n * ```json\n * {\n * \"mcpServers\": {\n * \"filesystem\": { \"command\": \"npx\", \"args\": [\"-y\", \"@modelcontextprotocol/server-filesystem\", \".\"] },\n * \"docs\": { \"url\": \"https://example.com/mcp\", \"headers\": { \"Authorization\": \"Bearer ${DOCS_TOKEN}\" } },\n * \"sentry\": { \"url\": \"https://mcp.sentry.dev/mcp\" }\n * }\n * }\n * ```\n *\n * HTTP servers without an `Authorization` header use OAuth when they answer 401 (sign in with `/mcp`).\n * `\"auth\": { \"provider\": \"<provider>\" }` sends the token of a `/login` provider instead. Project files\n * cannot use it, so a repository cannot pick where the credential goes.\n *\n * The top-level `autoEnableCodemode` (default true) activates the codemode tool when a server\n * with `codemode` exposure connects. A project value overrides the global one.\n */\n\nimport { randomUUID } from \"node:crypto\";\nimport {\n\tchmodSync,\n\texistsSync,\n\tlstatSync,\n\tmkdirSync,\n\treadFileSync,\n\trealpathSync,\n\trenameSync,\n\trmSync,\n\tstatSync,\n\twriteFileSync,\n} from \"node:fs\";\nimport { basename, dirname, join } from \"node:path\";\nimport lockfile from \"proper-lockfile\";\nimport { CONFIG_DIR_NAME } from \"../../config.ts\";\nimport {\n\ttype McpExposure,\n\ttype McpServerConfig,\n\tmcpNamespace,\n\tvalidateMcpServerConfig,\n} from \"../../core/mcp-servers.ts\";\nimport { stripBom } from \"../../utils/text.ts\";\n\nexport type {\n\tMcpExposure,\n\tMcpHttpServerConfig,\n\tMcpOAuthConfig,\n\tMcpServerConfig,\n\tMcpStdioServerConfig,\n} from \"../../core/mcp-servers.ts\";\nexport { getMcpToolExposure } from \"../../core/mcp-servers.ts\";\n\nexport interface McpServerEntry {\n\tname: string;\n\tconfig: McpServerConfig;\n\t/** Config file that defined the entry, or the path of the extension that registered it. */\n\tsource: string;\n\t/**\n\t * The global or the project `mcp.json`, or `extension` for servers registered with\n\t * `pi.registerMcpServer()`. Changes to extension servers are not saved.\n\t */\n\tscope?: \"global\" | \"project\" | \"extension\";\n\t/** Project `mcp.json` with an override of this global server's `enabled`, `exposure`, or `toolExposure`. */\n\toverride?: string;\n}\n\nexport interface LoadedMcpConfig {\n\tservers: McpServerEntry[];\n\t/** Activate the codemode tool when `codemode` servers connect. Default: true. */\n\tautoEnableCodemode?: boolean;\n\terrors: string[];\n\t/** The project `mcp.json` when the project is trusted, where `/mcp` saves project overrides. */\n\tprojectConfig?: string;\n}\n\nconst OVERRIDE_KEYS = [\"enabled\", \"exposure\", \"toolExposure\"];\n\n/** Whether an entry overrides a server defined elsewhere instead of defining one. */\nfunction isOverride(value: Record<string, unknown>): boolean {\n\treturn value.command === undefined && value.url === undefined && value.type === undefined;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\ninterface McpConfigState {\n\tservers: Map<string, McpServerEntry>;\n\tautoEnableCodemode?: boolean;\n\terrors: string[];\n}\n\nfunction readConfigFile(path: string, scope: \"global\" | \"project\", state: McpConfigState): void {\n\tconst { servers, errors } = state;\n\tif (!existsSync(path)) return;\n\tlet parsed: unknown;\n\ttry {\n\t\tparsed = JSON.parse(stripBom(readFileSync(path, \"utf8\")));\n\t} catch (error) {\n\t\terrors.push(`${path}: ${error instanceof Error ? error.message : String(error)}`);\n\t\treturn;\n\t}\n\tif (!isRecord(parsed) || (parsed.mcpServers !== undefined && !isRecord(parsed.mcpServers))) {\n\t\terrors.push(`${path}: expected an object with an \"mcpServers\" object`);\n\t\treturn;\n\t}\n\tif (typeof parsed.autoEnableCodemode === \"boolean\") state.autoEnableCodemode = parsed.autoEnableCodemode;\n\telse if (parsed.autoEnableCodemode !== undefined) errors.push(`${path}: autoEnableCodemode must be a boolean`);\n\tfor (const [name, value] of Object.entries(parsed.mcpServers ?? {})) {\n\t\tif (scope === \"project\" && isRecord(value) && isOverride(value)) {\n\t\t\tconst base = servers.get(name);\n\t\t\tconst extra = Object.keys(value).filter((key) => !OVERRIDE_KEYS.includes(key));\n\t\t\tif (!base) {\n\t\t\t\terrors.push(`${path}: server \"${name}\" needs \"command\" or \"url\", or a global server to override`);\n\t\t\t} else if (extra.length > 0) {\n\t\t\t\terrors.push(`${path}: server \"${name}\": an override can only set ${OVERRIDE_KEYS.join(\", \")}`);\n\t\t\t} else {\n\t\t\t\tconst config = validateMcpServerConfig(name, { ...base.config, ...value });\n\t\t\t\tif (typeof config === \"string\") errors.push(`${path}: ${config}`);\n\t\t\t\telse servers.set(name, { ...base, config, override: path });\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tconst config = validateMcpServerConfig(name, value);\n\t\tif (typeof config === \"string\") {\n\t\t\terrors.push(`${path}: ${config}`);\n\t\t\tcontinue;\n\t\t}\n\t\t// Names that differ only in `-` and `_` would share a namespace.\n\t\tconst clash = [...servers.keys()].find((other) => other !== name && mcpNamespace(other) === mcpNamespace(name));\n\t\tif (clash) {\n\t\t\terrors.push(`${path}: server \"${name}\" conflicts with \"${clash}\"`);\n\t\t\tcontinue;\n\t\t}\n\t\tif (scope === \"project\" && \"url\" in config && config.auth) {\n\t\t\terrors.push(`${path}: server \"${name}\": auth is only allowed in the global mcp.json`);\n\t\t\tcontinue;\n\t\t}\n\t\tservers.set(name, { name, config, source: path, scope });\n\t}\n}\n\n/**\n * Load global and (when trusted) project MCP configuration. Disabled servers are included with\n * `enabled: false`, so they can be enabled again.\n */\nexport function loadMcpConfig(options: { agentDir: string; cwd: string; projectTrusted: boolean }): LoadedMcpConfig {\n\tconst state: McpConfigState = { servers: new Map(), errors: [] };\n\treadConfigFile(join(options.agentDir, \"mcp.json\"), \"global\", state);\n\tconst projectConfig = options.projectTrusted ? join(options.cwd, CONFIG_DIR_NAME, \"mcp.json\") : undefined;\n\tif (projectConfig) readConfigFile(projectConfig, \"project\", state);\n\treturn {\n\t\tservers: [...state.servers.values()],\n\t\t...(state.autoEnableCodemode === undefined ? {} : { autoEnableCodemode: state.autoEnableCodemode }),\n\t\terrors: state.errors,\n\t\t...(projectConfig ? { projectConfig } : {}),\n\t};\n}\n\n/** Settings `/mcp` changes. `enabled: true` and `exposure: \"codemode\"` are the defaults and remove the key. */\nexport interface McpServerConfigPatch {\n\tenabled?: boolean;\n\texposure?: McpExposure;\n}\n\n/**\n * Change one server's settings in the `mcp.json` that defines or overrides it. With `override`, a\n * missing entry is added as an override. Overrides keep default values, since they replace the global\n * server's. Other content is kept; the file is rewritten with its indentation.\n */\nexport function updateMcpServerConfig(\n\tpath: string,\n\tname: string,\n\tpatch: McpServerConfigPatch,\n\toptions: { override?: boolean } = {},\n): void {\n\teditMcpServers(path, (servers, parsed) => {\n\t\tlet server = servers?.[name];\n\t\tif (server === undefined && options.override) {\n\t\t\tserver = {};\n\t\t\tparsed.mcpServers = { ...servers, [name]: server };\n\t\t}\n\t\tif (!isRecord(server)) throw new Error(`${path} does not define MCP server \"${name}\"`);\n\t\tconst keepDefaults = isOverride(server);\n\t\tif (patch.enabled !== undefined) {\n\t\t\tif (patch.enabled && !keepDefaults) delete server.enabled;\n\t\t\telse server.enabled = patch.enabled;\n\t\t}\n\t\tif (patch.exposure !== undefined) {\n\t\t\tif (patch.exposure === \"codemode\" && !keepDefaults) delete server.exposure;\n\t\t\telse server.exposure = patch.exposure;\n\t\t}\n\t\treturn true;\n\t});\n}\n\n/**\n * Add a server to an `mcp.json`, creating the file when missing. An existing entry with the same\n * name is replaced. Returns true when an entry was replaced.\n */\nexport function addMcpServerConfig(path: string, name: string, config: McpServerConfig): boolean {\n\treturn updateMcpConfigLocked(path, (servers) => {\n\t\tconst replaced = servers[name] !== undefined;\n\t\tservers[name] = config;\n\t\treturn replaced;\n\t});\n}\n\n/**\n * Add a server only when no entry has the same MCP namespace (`-` and `_` are equivalent). The check runs\n * inside the same locked read-modify-write as the write and counts every raw entry, valid or not. Returns\n * false, leaving the file untouched, when the name is occupied.\n */\nexport function addMcpServerConfigIfAbsent(path: string, name: string, config: McpServerConfig): boolean {\n\treturn updateMcpConfigLocked(path, (servers) => {\n\t\tconst namespace = mcpNamespace(name);\n\t\tif (Object.keys(servers).some((existing) => mcpNamespace(existing) === namespace)) return false;\n\t\tservers[name] = config;\n\t\treturn true;\n\t});\n}\n\n/**\n * Run `mutate` on the raw `mcpServers` of an `mcp.json` while holding a cross-process lock, so the read,\n * the decision and the write cannot interleave with another process. `mutate` may change `servers` in\n * place; the file is rewritten atomically only when its content changed. A missing file or directory is\n * treated as empty and created on write. Returns what `mutate` returns.\n */\nexport function updateMcpConfigLocked<T>(path: string, mutate: (servers: Record<string, unknown>) => T): T {\n\tlet result: T | undefined;\n\teditMcpServers(path, (servers, parsed) => {\n\t\tconst target = servers ?? {};\n\t\tconst before = JSON.stringify(target);\n\t\tresult = mutate(target);\n\t\tif (JSON.stringify(target) === before) return false;\n\t\tparsed.mcpServers = target;\n\t\treturn true;\n\t});\n\treturn result as T;\n}\n\n/** Raw `mcpServers` entries of an `mcp.json`, including ones that fail validation. Empty when missing. */\nexport function readRawMcpServers(path: string): Record<string, unknown> {\n\tif (!existsSync(path)) return {};\n\tconst { servers } = parseMcpFile(path, readFileSync(path, \"utf8\"));\n\treturn { ...servers };\n}\n\n/** Remove a server from an `mcp.json`. Returns false when the file does not define it. */\nexport function removeMcpServerConfig(path: string, name: string): boolean {\n\tif (!existsSync(path)) return false;\n\tlet removed = false;\n\teditMcpServers(path, (servers) => {\n\t\tif (!servers || servers[name] === undefined) return false;\n\t\tdelete servers[name];\n\t\tremoved = true;\n\t\treturn true;\n\t});\n\treturn removed;\n}\n\nfunction parseMcpFile(\n\tpath: string,\n\ttext: string | undefined,\n): { parsed: Record<string, unknown>; servers: Record<string, unknown> | undefined } {\n\tconst parsed: unknown = text === undefined ? {} : JSON.parse(stripBom(text));\n\tif (!isRecord(parsed) || (parsed.mcpServers !== undefined && !isRecord(parsed.mcpServers))) {\n\t\tthrow new Error(`${path}: expected an object with an \"mcpServers\" object`);\n\t}\n\treturn { parsed, servers: isRecord(parsed.mcpServers) ? parsed.mcpServers : undefined };\n}\n\n/** Canonical identity of an `mcp.json`: its real path, or the real parent plus basename when it does not exist yet. */\nfunction canonicalMcpPath(path: string): string {\n\tmkdirSync(dirname(path), { recursive: true });\n\tlet isSymlink = false;\n\ttry {\n\t\tisSymlink = lstatSync(path).isSymbolicLink();\n\t} catch (error) {\n\t\tif ((error as NodeJS.ErrnoException).code !== \"ENOENT\") throw error;\n\t\treturn join(realpathSync(dirname(path)), basename(path));\n\t}\n\ttry {\n\t\treturn realpathSync(path);\n\t} catch (error) {\n\t\tif (isSymlink && (error as NodeJS.ErrnoException).code === \"ENOENT\") {\n\t\t\tthrow new Error(`Refusing to modify ${path}: it is a dangling symlink. Create its target or remove the link.`);\n\t\t}\n\t\tthrow error;\n\t}\n}\n\nfunction acquireMcpLockSync(path: string): () => void {\n\tconst dir = dirname(path);\n\tconst maxAttempts = 50;\n\tconst delayMs = 20;\n\tfor (let attempt = 1; ; attempt++) {\n\t\ttry {\n\t\t\treturn lockfile.lockSync(dir, { realpath: false, lockfilePath: `${path}.lock` });\n\t\t} catch (error) {\n\t\t\tconst code =\n\t\t\t\ttypeof error === \"object\" && error !== null && \"code\" in error\n\t\t\t\t\t? String((error as { code?: unknown }).code)\n\t\t\t\t\t: undefined;\n\t\t\tif (code !== \"ELOCKED\" || attempt === maxAttempts) throw error;\n\t\t\tconst start = Date.now();\n\t\t\twhile (Date.now() - start < delayMs) {\n\t\t\t\t// Sleep synchronously to avoid changing callers to async.\n\t\t\t}\n\t\t}\n\t}\n}\n\n/**\n * Under a cross-process lock, read an `mcp.json` (an empty config when missing), let `edit` change its\n * `mcpServers`, and write it back atomically with its indentation when `edit` returns true. Other\n * content is kept.\n */\nfunction editMcpServers(\n\tpath: string,\n\tedit: (servers: Record<string, unknown> | undefined, parsed: Record<string, unknown>) => boolean,\n): void {\n\t// Lock, read and replace all use one canonical identity, so symlink aliases share a lock.\n\tconst canonical = canonicalMcpPath(path);\n\tconst release = acquireMcpLockSync(canonical);\n\ttry {\n\t\t// The path may have been retargeted between canonicalization and acquiring the lock.\n\t\tif (canonicalMcpPath(path) !== canonical) {\n\t\t\tthrow new Error(`Refusing to modify ${path}: it changed while waiting for the lock. Retry.`);\n\t\t}\n\t\tconst text = existsSync(canonical) ? readFileSync(canonical, \"utf8\") : undefined;\n\t\tconst { parsed, servers } = parseMcpFile(path, text);\n\t\tif (!edit(servers, parsed)) return;\n\t\tconst indent = (text && /^([ \\t]+)\\S/m.exec(text)?.[1]) || \" \";\n\t\tconst targetPath = canonical;\n\t\tconst tempPath = join(dirname(targetPath), `${randomUUID()}.tmp`);\n\t\t// Never broaden an existing file's permissions (it may hold auth headers or env secrets).\n\t\tconst mode = text !== undefined ? statSync(targetPath).mode & 0o777 : 0o600;\n\t\ttry {\n\t\t\twriteFileSync(tempPath, `${JSON.stringify(parsed, null, indent)}\\n`, { flag: \"wx\", mode });\n\t\t\tchmodSync(tempPath, mode);\n\t\t\trenameSync(tempPath, targetPath);\n\t\t} catch (error) {\n\t\t\trmSync(tempPath, { force: true });\n\t\t\tthrow error;\n\t\t}\n\t} finally {\n\t\trelease();\n\t}\n}\n"]}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * The `/usage` command as a built-in extension: session tokens, cost and context, plus subscription limits: every limit
3
+ * window of the active OpenAI Codex account (the usage route /accounts reads) and, for a Claude subscription, live
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.
6
+ */
7
+ import type { ExtensionFactory } from "../../core/extensions/types.ts";
8
+ export interface UsageExtensionOptions {
9
+ /** Home directory holding Claude Code's `.claude.json`. Defaults to the user's home. */
10
+ home?: string;
11
+ }
12
+ export declare function createUsageExtension(options?: UsageExtensionOptions): ExtensionFactory;
13
+ declare const _default: ExtensionFactory;
14
+ export default _default;
15
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/extensions/usage/index.ts"],"names":[],"mappings":"AACA;;;;;GAKG;AAGH,OAAO,KAAK,EAAoB,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAgBzF,MAAM,WAAW,qBAAqB;IACrC,wFAAwF;IACxF,IAAI,CAAC,EAAE,MAAM,CAAC;CACd;AA0DD,wBAAgB,oBAAoB,CAAC,OAAO,GAAE,qBAA0B,GAAG,gBAAgB,CAgD1F"}
@@ -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,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACtD,OAAO;gBACN,IAAI,EAAE,eAAe,CAAC,IAAI,C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AAM,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,EAEzB,MAAM,4CAA4C,CAAC;AACpD,OAAO,KAAK,EAEX,uBAAuB,EAGvB,MAAM,2BAA2B,CAAC;AAGnC,MAAM,MAAM,OAAO,GAAG,QAAQ,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,CAAC;AAEjE,MAAM,WAAW,QAAQ;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,oDAAoD;IACpD,IAAI,EAAE,MAAM,CAAC;IACb,oDAAoD;IACpD,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,wEAAwE;IACxE,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,OAAO,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,SAAS;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,OAAO,CAAC;CACf;AAED,MAAM,WAAW,aAAa;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,QAAQ,EAAE,CAAC;IACjB,KAAK,EAAE,SAAS,EAAE,CAAC;IACnB,KAAK,EAAE,MAAM,EAAE,CAAC;CAChB;A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IAAC,KAAK,EAAE,SAAS,EAAE,CAAA;CAAE,GAAG;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CAiB9D;AAED,sGAAsG;AACtG,wBAAgB,SAAS,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAO5C;AAED;;;;;GAKG;AACH,wBAAsB,qBAAqB,CAC1C,IAAI,GAAE,MAAkB,EACxB,GAAG,GAAE,MAAmB,GACtB,OAAO,CAAC;IAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,CAwBzE"}
@@ -0,0 +1,215 @@
1
+ // 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