@humain/humain-code 0.4.15 → 0.4.18

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 (322) hide show
  1. package/CHANGELOG.md +86 -0
  2. package/README.md +1 -1
  3. package/dist/bundle/agent-monitor.js +1 -1
  4. package/dist/bundle/chunks/anthropic-messages-TSNY5MWH.js +67 -0
  5. package/dist/bundle/chunks/azure-openai-responses-Z4DCXO2G.js +15 -0
  6. package/dist/bundle/chunks/bedrock-converse-stream.js +59 -42
  7. package/dist/bundle/chunks/{chunk-W2QRCQBX.js → chunk-26EAEXO5.js} +18 -16
  8. package/dist/bundle/chunks/chunk-2ZFUMXOZ.js +1790 -0
  9. package/dist/bundle/chunks/{chunk-W5YJZKPF.js → chunk-3UXBFT4Q.js} +2264 -2432
  10. package/dist/bundle/chunks/{chunk-OX2IBCCA.js → chunk-3XDL5ZE4.js} +88 -82
  11. package/dist/bundle/chunks/{chunk-LUL775V7.js → chunk-5K5RFXXO.js} +4 -4
  12. package/dist/bundle/chunks/{chunk-AIXI6RIE.js → chunk-7PRU6YW3.js} +114 -82
  13. package/dist/bundle/chunks/{chunk-DUSJT2W4.js → chunk-7VY5IL74.js} +1 -1
  14. package/dist/bundle/chunks/chunk-AWCJWXGD.js +212 -0
  15. package/dist/bundle/chunks/chunk-FZUJXM6D.js +816 -0
  16. package/dist/bundle/chunks/{chunk-KK3KUUMM.js → chunk-G6ABHCPB.js} +115 -95
  17. package/dist/bundle/chunks/{chunk-NNKA2PAP.js → chunk-HPSQKIWK.js} +1 -1
  18. package/dist/bundle/chunks/chunk-IJYVMOB4.js +6 -0
  19. package/dist/bundle/chunks/{chunk-36Q5UVQL.js → chunk-L5OUCJ7N.js} +9 -9
  20. package/dist/bundle/chunks/chunk-NCQ6WAQK.js +125 -0
  21. package/dist/bundle/chunks/chunk-NSMMDV3N.js +131 -0
  22. package/dist/bundle/chunks/{chunk-Z74ZYQPX.js → chunk-OKALNPTJ.js} +80 -210
  23. package/dist/bundle/chunks/{chunk-UHLW4KJ7.js → chunk-OWLBGSXY.js} +94 -91
  24. package/dist/bundle/chunks/{chunk-JRX7GYW3.js → chunk-P4UKLIQB.js} +8 -8
  25. package/dist/bundle/chunks/chunk-PY7SOXCA.js +10 -0
  26. package/dist/bundle/chunks/chunk-Q7VXYXY3.js +7 -0
  27. package/dist/bundle/chunks/{chunk-COF5P635.js → chunk-QEF72EIZ.js} +13 -13
  28. package/dist/bundle/chunks/{chunk-EYIYBQAR.js → chunk-RXOCQRBG.js} +1 -1
  29. package/dist/bundle/chunks/{chunk-BVHXWQLD.js → chunk-SCBU5WOP.js} +1 -1
  30. package/dist/bundle/chunks/{chunk-DNGJMRJW.js → chunk-SCIGZFN5.js} +11 -11
  31. package/dist/bundle/chunks/{chunk-UDVC7A5S.js → chunk-TIFFHHW6.js} +16 -14
  32. package/dist/bundle/chunks/{chunk-L3J4P5JR.js → chunk-UGJAAWNC.js} +1 -1
  33. package/dist/bundle/chunks/chunk-V76YPIMT.js +48 -0
  34. package/dist/bundle/chunks/{chunk-Y3RFGBG2.js → chunk-X3O5MCKJ.js} +1 -1
  35. package/dist/bundle/chunks/chunk-Y26OS23T.js +80 -0
  36. package/dist/bundle/chunks/chunk-YDBNMIA3.js +34 -0
  37. package/dist/bundle/chunks/chunk-YLYOJQQX.js +1951 -0
  38. package/dist/bundle/chunks/{chunk-TJG52LZB.js → chunk-YMBXWW36.js} +1 -1
  39. package/dist/bundle/chunks/{cli-SRI4UOSL.js → cli-2NKM2RNJ.js} +1 -1
  40. package/dist/bundle/chunks/{cloudflare-workers-ai-system-one-JGN7NZCV.js → cloudflare-workers-ai-system-one-MUJQ6LT2.js} +1 -1
  41. package/dist/bundle/chunks/{compat-2S3PCPEI.js → compat-VDGEZSVM.js} +8 -8
  42. package/dist/bundle/chunks/dist-LKDZAEUQ.js +7 -0
  43. package/dist/bundle/chunks/{dist-JXEXN6S2.js → dist-XVXV2CL4.js} +1 -1
  44. package/dist/bundle/chunks/{dist-SGQMXO45.js → dist-ZJIYY3GA.js} +1416 -866
  45. package/dist/bundle/chunks/dist-cjs-AXBW3N4F.js +182 -0
  46. package/dist/bundle/chunks/{easter-egg-3d-ZJ2JUFOA.js → easter-egg-3d-VGJ77XZQ.js} +1 -1
  47. package/dist/bundle/chunks/es-N6YFJOD7.js +1901 -0
  48. package/dist/bundle/chunks/{esm-NCUV2DF7.js → esm-GIR7QH65.js} +1 -1
  49. package/dist/bundle/chunks/{execute-LRTXH4YJ.js → execute-ZBEZNJ4E.js} +10 -9
  50. package/dist/bundle/chunks/{extract-OZW5JHG6.js → extract-RFWEHH6W.js} +16 -15
  51. package/dist/bundle/chunks/github-copilot.js +34 -47
  52. package/dist/bundle/chunks/{google-generative-ai-YXXFSTX7.js → google-generative-ai-4OVYRP24.js} +2 -2
  53. package/dist/bundle/chunks/{google-vertex-3IVWLYJ5.js → google-vertex-3WQAZJQD.js} +2 -2
  54. package/dist/bundle/chunks/host-63SNKK5Y.js +2 -0
  55. package/dist/bundle/chunks/jiti-static-loader-7OZNBOCI.js +2 -0
  56. package/dist/bundle/chunks/{mistral-conversations-Y7GWO3QB.js → mistral-conversations-G3GN6CMT.js} +20 -20
  57. package/dist/bundle/chunks/{node-ELWNZC34.js → node-A6SZ3T7E.js} +185 -185
  58. package/dist/bundle/chunks/{node-SPBTZUUS.js → node-DZCAT4Q6.js} +1 -1
  59. package/dist/bundle/chunks/{openai-codex-responses-NSXWHIDT.js → openai-codex-responses-FJFDAWHI.js} +17 -17
  60. package/dist/bundle/chunks/openai-completions-IC7WRLTI.js +82 -0
  61. package/dist/bundle/chunks/{openai-decisions-QWEISDVO.js → openai-decisions-HESOHYZB.js} +1 -1
  62. package/dist/bundle/chunks/openai-responses-XXCYDFSM.js +24 -0
  63. package/dist/bundle/chunks/{openrouter-images-BMVMAROU.js → openrouter-images-DT2HMZNO.js} +1 -1
  64. package/dist/bundle/chunks/pdfjs-EK6K7CXX.js +3593 -0
  65. package/dist/bundle/chunks/{pi-messages-XNEG23NU.js → pi-messages-SAOV3JNW.js} +1 -1
  66. package/dist/bundle/chunks/{runtime-VGSK3QCM.js → runtime-HJEUOD4R.js} +1 -1
  67. package/dist/bundle/chunks/{typesafe-system-one-62YHYXZV.js → typesafe-system-one-HCMGHK6A.js} +1 -1
  68. package/dist/bundle/chunks/{undici-7EW63V4X.js → undici-4BK3MVJV.js} +1 -1
  69. package/dist/bundle/chunks/virtual-modules-CFJTDIXL.js +5 -0
  70. package/dist/bundle/cli-runtime.js +3 -3
  71. package/dist/bundle/cli.js +2 -2
  72. package/dist/bundle/flow/package.json +6 -5
  73. package/dist/bundle/index.js +8 -8
  74. package/dist/bundle/rpc-entry.js +3 -3
  75. package/dist/cli/credential-print.d.ts.map +1 -1
  76. package/dist/cli/credential-print.js +4 -4
  77. package/dist/cli/credential-print.js.map +1 -1
  78. package/dist/coordination/adapter/index.d.ts.map +1 -1
  79. package/dist/coordination/adapter/index.js +1 -1
  80. package/dist/coordination/adapter/index.js.map +1 -1
  81. package/dist/coordination/adapter/integration-notices.d.ts +1 -1
  82. package/dist/coordination/adapter/integration-notices.d.ts.map +1 -1
  83. package/dist/coordination/adapter/integration-notices.js +5 -2
  84. package/dist/coordination/adapter/integration-notices.js.map +1 -1
  85. package/dist/coordination/broker/extension-state.js +3 -3
  86. package/dist/coordination/broker/extension-state.js.map +1 -1
  87. package/dist/coordination/transport/framing.d.ts.map +1 -1
  88. package/dist/coordination/transport/framing.js +2 -1
  89. package/dist/coordination/transport/framing.js.map +1 -1
  90. package/dist/core/account-reporting.d.ts +3 -1
  91. package/dist/core/account-reporting.d.ts.map +1 -1
  92. package/dist/core/account-reporting.js +12 -2
  93. package/dist/core/account-reporting.js.map +1 -1
  94. package/dist/core/agent-session-services.d.ts.map +1 -1
  95. package/dist/core/agent-session-services.js +39 -36
  96. package/dist/core/agent-session-services.js.map +1 -1
  97. package/dist/core/agent-session.d.ts +4 -2
  98. package/dist/core/agent-session.d.ts.map +1 -1
  99. package/dist/core/agent-session.js +5 -4
  100. package/dist/core/agent-session.js.map +1 -1
  101. package/dist/core/codex-usage.d.ts +11 -2
  102. package/dist/core/codex-usage.d.ts.map +1 -1
  103. package/dist/core/codex-usage.js +74 -2
  104. package/dist/core/codex-usage.js.map +1 -1
  105. package/dist/core/export-html/template.js +21 -16
  106. package/dist/core/model-config.d.ts +33 -8
  107. package/dist/core/model-config.d.ts.map +1 -1
  108. package/dist/core/model-config.js +22 -4
  109. package/dist/core/model-config.js.map +1 -1
  110. package/dist/core/model-resolver.d.ts +56 -43
  111. package/dist/core/model-resolver.d.ts.map +1 -1
  112. package/dist/core/model-resolver.js +256 -361
  113. package/dist/core/model-resolver.js.map +1 -1
  114. package/dist/core/model-runtime.d.ts +6 -3
  115. package/dist/core/model-runtime.d.ts.map +1 -1
  116. package/dist/core/model-runtime.js +19 -5
  117. package/dist/core/model-runtime.js.map +1 -1
  118. package/dist/core/models-store.d.ts.map +1 -1
  119. package/dist/core/models-store.js +7 -2
  120. package/dist/core/models-store.js.map +1 -1
  121. package/dist/core/oauth-account-pool.d.ts +9 -1
  122. package/dist/core/oauth-account-pool.d.ts.map +1 -1
  123. package/dist/core/oauth-account-pool.js +63 -12
  124. package/dist/core/oauth-account-pool.js.map +1 -1
  125. package/dist/core/prompt-templates.d.ts.map +1 -1
  126. package/dist/core/prompt-templates.js +7 -2
  127. package/dist/core/prompt-templates.js.map +1 -1
  128. package/dist/core/settings-defaults.d.ts +2 -0
  129. package/dist/core/settings-defaults.d.ts.map +1 -1
  130. package/dist/core/settings-defaults.js +2 -0
  131. package/dist/core/settings-defaults.js.map +1 -1
  132. package/dist/core/settings-manager.d.ts +4 -2
  133. package/dist/core/settings-manager.d.ts.map +1 -1
  134. package/dist/core/settings-manager.js +11 -0
  135. package/dist/core/settings-manager.js.map +1 -1
  136. package/dist/core/settings-schema.d.ts +4 -0
  137. package/dist/core/settings-schema.d.ts.map +1 -1
  138. package/dist/core/settings-schema.js +8 -0
  139. package/dist/core/settings-schema.js.map +1 -1
  140. package/dist/core/slash-commands.js +1 -1
  141. package/dist/core/slash-commands.js.map +1 -1
  142. package/dist/core/tools/render-utils.d.ts +2 -0
  143. package/dist/core/tools/render-utils.d.ts.map +1 -1
  144. package/dist/core/tools/render-utils.js +21 -0
  145. package/dist/core/tools/render-utils.js.map +1 -1
  146. package/dist/core/tools/renderers/read.d.ts.map +1 -1
  147. package/dist/core/tools/renderers/read.js +7 -10
  148. package/dist/core/tools/renderers/read.js.map +1 -1
  149. package/dist/core/tools/subagent.d.ts.map +1 -1
  150. package/dist/core/tools/subagent.js +4 -7
  151. package/dist/core/tools/subagent.js.map +1 -1
  152. package/dist/core/trace/redaction.d.ts.map +1 -1
  153. package/dist/core/trace/redaction.js +3 -1
  154. package/dist/core/trace/redaction.js.map +1 -1
  155. package/dist/extensions/codemode/execute.d.ts.map +1 -1
  156. package/dist/extensions/codemode/execute.js +12 -0
  157. package/dist/extensions/codemode/execute.js.map +1 -1
  158. package/dist/extensions/codemode/index.d.ts.map +1 -1
  159. package/dist/extensions/codemode/index.js +5 -0
  160. package/dist/extensions/codemode/index.js.map +1 -1
  161. package/dist/humain/bedrock-provider/vendor/index.bundle.mjs +74 -20
  162. package/dist/humain/flow-accounts-host.d.ts.map +1 -1
  163. package/dist/humain/flow-accounts-host.js +3 -0
  164. package/dist/humain/flow-accounts-host.js.map +1 -1
  165. package/dist/humain/node-provider.d.ts.map +1 -1
  166. package/dist/humain/node-provider.js +2 -0
  167. package/dist/humain/node-provider.js.map +1 -1
  168. package/dist/humain/trace-capture/index.js +3 -3
  169. package/dist/humain/trace-capture/index.js.map +1 -1
  170. package/dist/humain/web-access/vendor/credential-source.d.ts +2 -0
  171. package/dist/humain/web-access/vendor/credential-source.d.ts.map +1 -1
  172. package/dist/humain/web-access/vendor/credential-source.js +50 -4
  173. package/dist/humain/web-access/vendor/credential-source.js.map +1 -1
  174. package/dist/humain/web-access/vendor/curator-page.d.ts.map +1 -1
  175. package/dist/humain/web-access/vendor/curator-page.js +3 -1
  176. package/dist/humain/web-access/vendor/curator-page.js.map +1 -1
  177. package/dist/humain/web-access/vendor/curator-server.d.ts.map +1 -1
  178. package/dist/humain/web-access/vendor/curator-server.js +2 -0
  179. package/dist/humain/web-access/vendor/curator-server.js.map +1 -1
  180. package/dist/humain/web-access/vendor/deepseek.d.ts +4 -0
  181. package/dist/humain/web-access/vendor/deepseek.d.ts.map +1 -0
  182. package/dist/humain/web-access/vendor/deepseek.js +201 -0
  183. package/dist/humain/web-access/vendor/deepseek.js.map +1 -0
  184. package/dist/humain/web-access/vendor/extract.d.ts.map +1 -1
  185. package/dist/humain/web-access/vendor/extract.js +4 -2
  186. package/dist/humain/web-access/vendor/extract.js.map +1 -1
  187. package/dist/humain/web-access/vendor/gemini-adc.d.ts.map +1 -1
  188. package/dist/humain/web-access/vendor/gemini-adc.js +49 -5
  189. package/dist/humain/web-access/vendor/gemini-adc.js.map +1 -1
  190. package/dist/humain/web-access/vendor/gemini-search.d.ts +3 -3
  191. package/dist/humain/web-access/vendor/gemini-search.d.ts.map +1 -1
  192. package/dist/humain/web-access/vendor/gemini-search.js +11 -4
  193. package/dist/humain/web-access/vendor/gemini-search.js.map +1 -1
  194. package/dist/humain/web-access/vendor/index.d.ts.map +1 -1
  195. package/dist/humain/web-access/vendor/index.js +16 -1
  196. package/dist/humain/web-access/vendor/index.js.map +1 -1
  197. package/dist/humain/web-access/vendor/page-query.d.ts.map +1 -1
  198. package/dist/humain/web-access/vendor/page-query.js +12 -6
  199. package/dist/humain/web-access/vendor/page-query.js.map +1 -1
  200. package/dist/humain/web-access/vendor/query-rewrite.d.ts.map +1 -1
  201. package/dist/humain/web-access/vendor/query-rewrite.js +11 -4
  202. package/dist/humain/web-access/vendor/query-rewrite.js.map +1 -1
  203. package/dist/humain/web-access/vendor/searxng.d.ts.map +1 -1
  204. package/dist/humain/web-access/vendor/searxng.js +2 -1
  205. package/dist/humain/web-access/vendor/searxng.js.map +1 -1
  206. package/dist/humain/web-access/vendor/ssrf-protection.d.ts +1 -0
  207. package/dist/humain/web-access/vendor/ssrf-protection.d.ts.map +1 -1
  208. package/dist/humain/web-access/vendor/ssrf-protection.js +10 -0
  209. package/dist/humain/web-access/vendor/ssrf-protection.js.map +1 -1
  210. package/dist/humain/web-access/vendor/summary-review.d.ts.map +1 -1
  211. package/dist/humain/web-access/vendor/summary-review.js +17 -6
  212. package/dist/humain/web-access/vendor/summary-review.js.map +1 -1
  213. package/dist/humain/web-access/vendor/utils.d.ts +2 -0
  214. package/dist/humain/web-access/vendor/utils.d.ts.map +1 -1
  215. package/dist/humain/web-access/vendor/utils.js +18 -0
  216. package/dist/humain/web-access/vendor/utils.js.map +1 -1
  217. package/dist/humain/web-access/vendor/web-tool-core.d.ts +2 -0
  218. package/dist/humain/web-access/vendor/web-tool-core.d.ts.map +1 -1
  219. package/dist/humain/web-access/vendor/web-tool-core.js.map +1 -1
  220. package/dist/index.d.ts +1 -0
  221. package/dist/index.d.ts.map +1 -1
  222. package/dist/index.js.map +1 -1
  223. package/dist/main.d.ts.map +1 -1
  224. package/dist/main.js +1 -0
  225. package/dist/main.js.map +1 -1
  226. package/dist/modes/interactive/components/settings-selector.d.ts +3 -1
  227. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  228. package/dist/modes/interactive/components/settings-selector.js +10 -0
  229. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  230. package/dist/modes/interactive/components/status-indicator.d.ts +5 -0
  231. package/dist/modes/interactive/components/status-indicator.d.ts.map +1 -1
  232. package/dist/modes/interactive/components/status-indicator.js +27 -2
  233. package/dist/modes/interactive/components/status-indicator.js.map +1 -1
  234. package/dist/modes/interactive/components/tool-execution.d.ts +2 -1
  235. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  236. package/dist/modes/interactive/components/tool-execution.js +4 -2
  237. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  238. package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
  239. package/dist/modes/interactive/components/tree-selector.js +2 -9
  240. package/dist/modes/interactive/components/tree-selector.js.map +1 -1
  241. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  242. package/dist/modes/interactive/interactive-mode.js +28 -14
  243. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  244. package/dist/modes/interactive/oauth-account-format.d.ts +4 -4
  245. package/dist/modes/interactive/oauth-account-format.d.ts.map +1 -1
  246. package/dist/modes/interactive/oauth-account-format.js +5 -2
  247. package/dist/modes/interactive/oauth-account-format.js.map +1 -1
  248. package/dist/modes/interactive/session-share.d.ts.map +1 -1
  249. package/dist/modes/interactive/session-share.js +9 -2
  250. package/dist/modes/interactive/session-share.js.map +1 -1
  251. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  252. package/dist/modes/rpc/rpc-mode.js +8 -3
  253. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  254. package/dist/utils/tools-manager.d.ts.map +1 -1
  255. package/dist/utils/tools-manager.js +2 -1
  256. package/dist/utils/tools-manager.js.map +1 -1
  257. package/docs/cli.md +3 -3
  258. package/docs/codemode.md +3 -1
  259. package/docs/coordination.md +6 -0
  260. package/docs/docs.json +4 -0
  261. package/docs/environment-variables.md +4 -0
  262. package/docs/flow.md +6 -0
  263. package/docs/humain-code-forge-flow-walkthrough.md +1 -1
  264. package/docs/humain-code.md +2 -4
  265. package/docs/json.md +2 -2
  266. package/docs/llama-cpp.md +1 -1
  267. package/docs/nvidia-rtx-llama-cpp.md +96 -0
  268. package/docs/rpc-commands.md +1 -1
  269. package/docs/rpc.md +9 -1
  270. package/docs/sessions.md +1 -1
  271. package/docs/settings.md +2 -0
  272. package/docs/trace.md +4 -0
  273. package/docs/usage.md +1 -1
  274. package/examples/extensions/custom-provider-anthropic/package-lock.json +16 -6
  275. package/examples/extensions/custom-provider-anthropic/package.json +2 -2
  276. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  277. package/examples/extensions/gondolin/package-lock.json +16 -16
  278. package/examples/extensions/gondolin/package.json +1 -1
  279. package/examples/extensions/minimal-mode.ts +4 -4
  280. package/examples/extensions/sandbox/package-lock.json +6 -6
  281. package/examples/extensions/sandbox/package.json +2 -2
  282. package/examples/extensions/with-deps/package-lock.json +2 -2
  283. package/examples/extensions/with-deps/package.json +1 -1
  284. package/examples/plugins/pi-example-plugin/package.json +2 -2
  285. package/examples/rpc-subagent-progress-host.ts +6 -2
  286. package/npm-shrinkwrap.json +129 -171
  287. package/package.json +19 -19
  288. package/schemas/models.schema.json +9 -5
  289. package/schemas/settings.schema.json +32 -0
  290. package/src/coordination/UPSTREAM.md +31 -1
  291. package/src/coordination/upstream.json +3 -3
  292. package/src/humain/adhd/UPSTREAM.md +8 -0
  293. package/src/humain/caveman/UPSTREAM.md +19 -3
  294. package/src/humain/caveman/upstream.json +2 -2
  295. package/src/humain/ponytail/UPSTREAM.md +23 -2
  296. package/src/humain/ponytail/upstream.json +8 -8
  297. package/src/humain/ponytail/vendor/skills/ponytail/SKILL.md +1 -1
  298. package/src/humain/ponytail/vendor/skills/ponytail-debt/SKILL.md +1 -2
  299. package/src/humain/ponytail/vendor/skills/ponytail-gain/SKILL.md +0 -1
  300. package/src/humain/web-access/UPSTREAM.md +45 -1
  301. package/src/humain/web-access/upstream.json +4 -4
  302. package/dist/bundle/chunks/anthropic-messages-YSAHA7QM.js +0 -67
  303. package/dist/bundle/chunks/azure-openai-responses-Z5XYDPHS.js +0 -15
  304. package/dist/bundle/chunks/chunk-2TTB6GIB.js +0 -47
  305. package/dist/bundle/chunks/chunk-5JHUWRJN.js +0 -1790
  306. package/dist/bundle/chunks/chunk-A7QKOI62.js +0 -572
  307. package/dist/bundle/chunks/chunk-FRUFMISJ.js +0 -505
  308. package/dist/bundle/chunks/chunk-MF2NEHP4.js +0 -1575
  309. package/dist/bundle/chunks/chunk-MG5PX4KU.js +0 -31
  310. package/dist/bundle/chunks/chunk-OEOXBLWI.js +0 -540
  311. package/dist/bundle/chunks/chunk-RYC5BYVE.js +0 -5
  312. package/dist/bundle/chunks/chunk-YJ3NQWES.js +0 -9
  313. package/dist/bundle/chunks/dist-MNSGVI4C.js +0 -7
  314. package/dist/bundle/chunks/dist-cjs-4BMVQ74V.js +0 -179
  315. package/dist/bundle/chunks/es-YEFEOGR3.js +0 -1905
  316. package/dist/bundle/chunks/host-2RMBOGA7.js +0 -2
  317. package/dist/bundle/chunks/jiti-static-loader-2RCDI6B4.js +0 -2
  318. package/dist/bundle/chunks/openai-completions-WGBQHTYA.js +0 -79
  319. package/dist/bundle/chunks/openai-responses-OKGCSIEY.js +0 -23
  320. package/dist/bundle/chunks/pdfjs-6UVU6XFX.js +0 -3564
  321. package/dist/bundle/chunks/virtual-modules-7HDINPIK.js +0 -5
  322. /package/dist/bundle/chunks/{chunk-XQRYOCHA.js → chunk-WZMA7HAJ.js} +0 -0
@@ -20,7 +20,7 @@ export const defaultModelPerProvider = {
20
20
  deepseek: "deepseek-v4-pro",
21
21
  google: "gemini-3.1-pro-preview",
22
22
  "google-vertex": "gemini-3.1-pro-preview",
23
- "github-copilot": "gpt-5.4",
23
+ "github-copilot": "gpt-5.6-terra",
24
24
  openrouter: "moonshotai/kimi-k2.6",
25
25
  "vercel-ai-gateway": "zai/glm-5.1",
26
26
  xai: "grok-4.7",
@@ -47,93 +47,172 @@ export const defaultModelPerProvider = {
47
47
  "qwen-token-plan-cn": "qwen3.7-max",
48
48
  "qwen-token-plan-individual": "qwen3.8-max",
49
49
  "humain-node": "humain-m3-research-preview",
50
- xiaomi: "mimo-v2.5-pro",
51
- "xiaomi-token-plan-cn": "mimo-v2.5-pro",
52
- "xiaomi-token-plan-ams": "mimo-v2.5-pro",
53
- "xiaomi-token-plan-sgp": "mimo-v2.5-pro",
50
+ xiaomi: "mimo-v2.6-pro",
51
+ "xiaomi-token-plan-cn": "mimo-v2.6-pro",
52
+ "xiaomi-token-plan-ams": "mimo-v2.6-pro",
53
+ "xiaomi-token-plan-sgp": "mimo-v2.6-pro",
54
54
  };
55
- /**
56
- * Helper to check if a model ID looks like an alias (no date suffix)
57
- * Dates are typically in format: -20241022 or -20250929
58
- */
59
- function isAlias(id) {
60
- // Check if ID ends with -latest
61
- if (id.endsWith("-latest"))
62
- return true;
63
- // Check if ID ends with a date pattern (-YYYYMMDD)
64
- const datePattern = /-\d{8}$/;
65
- return !datePattern.test(id);
55
+ function splitThinkingSuffix(text) {
56
+ const colonIndex = text.lastIndexOf(":");
57
+ const suffix = text.substring(colonIndex + 1);
58
+ if (colonIndex === -1 || !isValidThinkingLevel(suffix))
59
+ return undefined;
60
+ return { base: text.substring(0, colonIndex), thinkingLevel: suffix };
66
61
  }
67
- /**
68
- * Find an exact model reference match.
69
- * Supports either a bare model id or a canonical provider/modelId reference.
70
- * When matching by bare id, ambiguous matches across providers are rejected.
71
- */
72
- export function findExactModelReferenceMatch(modelReference, availableModels) {
73
- const trimmedReference = modelReference.trim();
74
- if (!trimmedReference) {
62
+ function splitProviderPrefix(text, models) {
63
+ const slashIndex = text.indexOf("/");
64
+ if (slashIndex === -1)
75
65
  return undefined;
76
- }
77
- const normalizedReference = trimmedReference.toLowerCase();
78
- const canonicalMatches = availableModels.filter((model) => `${model.provider}/${model.id}`.toLowerCase() === normalizedReference);
79
- if (canonicalMatches.length === 1) {
80
- return canonicalMatches[0];
81
- }
82
- if (canonicalMatches.length > 1) {
66
+ const prefix = text.substring(0, slashIndex).trim().toLowerCase();
67
+ const modelText = text.substring(slashIndex + 1).trim();
68
+ if (!prefix || !modelText)
83
69
  return undefined;
84
- }
85
- const slashIndex = trimmedReference.indexOf("/");
86
- if (slashIndex !== -1) {
87
- const provider = trimmedReference.substring(0, slashIndex).trim();
88
- const modelId = trimmedReference.substring(slashIndex + 1).trim();
89
- if (provider && modelId) {
90
- const providerMatches = availableModels.filter((model) => model.provider.toLowerCase() === provider.toLowerCase() &&
91
- model.id.toLowerCase() === modelId.toLowerCase());
92
- if (providerMatches.length === 1) {
93
- return providerMatches[0];
94
- }
95
- if (providerMatches.length > 1) {
96
- return undefined;
97
- }
98
- }
99
- }
100
- const idMatches = availableModels.filter((model) => model.id.toLowerCase() === normalizedReference);
101
- return idMatches.length === 1 ? idMatches[0] : undefined;
70
+ const provider = models.find((model) => model.provider.toLowerCase() === prefix)?.provider;
71
+ return provider ? { provider, modelText } : undefined;
102
72
  }
103
73
  /**
104
- * Try to match a pattern to a model from the available models list.
105
- * Returns the matched model or undefined if no match found.
74
+ * `usable` only breaks ties between providers, so a unique match resolves even without credentials
75
+ * (`--api-key` first-time setup).
106
76
  */
107
- function tryMatchModel(modelPattern, availableModels) {
108
- const exactMatch = findExactModelReferenceMatch(modelPattern, availableModels);
109
- if (exactMatch) {
110
- return exactMatch;
111
- }
112
- // No exact match - fall back to partial matching
113
- const matches = availableModels.filter((m) => m.id.toLowerCase().includes(modelPattern.toLowerCase()) ||
114
- m.name?.toLowerCase().includes(modelPattern.toLowerCase()));
115
- if (matches.length === 0) {
77
+ export function resolveModelReference(request, models, usable) {
78
+ const text = request.text.trim();
79
+ if (!text)
80
+ return { status: "not-found" };
81
+ const constraint = request.provider?.toLowerCase();
82
+ const pool = constraint ? models.filter((model) => model.provider.toLowerCase() === constraint) : models;
83
+ const result = resolveText(text, request, pool, usable);
84
+ if (result.status !== "not-found")
85
+ return result;
86
+ const split = splitProviderPrefix(text, pool);
87
+ const anchor = constraint ? pool[0] : pool.find((model) => model.provider === split?.provider);
88
+ if (!anchor)
89
+ return result;
90
+ const modelText = split?.modelText ?? text;
91
+ const suffix = request.thinkingSuffix === "none" ? undefined : splitThinkingSuffix(modelText);
92
+ return {
93
+ status: "not-found",
94
+ target: {
95
+ provider: anchor.provider,
96
+ providerModels: [anchor, ...pool.filter((model) => model.provider === anchor.provider && model !== anchor)],
97
+ modelText,
98
+ modelId: suffix?.base ?? modelText,
99
+ thinkingLevel: suffix?.thinkingLevel,
100
+ },
101
+ };
102
+ }
103
+ /** Exact `provider/id` or bare id lookup without thinking suffixes or fuzzy matching. */
104
+ export function findExactModelReferenceMatch(modelReference, models) {
105
+ const result = resolveModelReference({ text: modelReference, thinkingSuffix: "none", fuzzy: false }, models, () => true);
106
+ return result.status === "resolved" ? result.model : undefined;
107
+ }
108
+ function resolveText(text, request, pool, usable) {
109
+ // An explicit provider makes its literal catalog IDs authoritative, even if they repeat the provider prefix.
110
+ const literal = request.provider ? pool.find((model) => model.id.toLowerCase() === text.toLowerCase()) : undefined;
111
+ if (literal)
112
+ return { status: "resolved", model: literal };
113
+ const reference = selectReference(text, pool, request.fuzzy, usable);
114
+ if (reference)
115
+ return reference;
116
+ if (request.fuzzy) {
117
+ const fuzzy = selectFuzzy(fuzzyMatches(text, pool), usable);
118
+ if (fuzzy)
119
+ return fuzzy;
120
+ }
121
+ if (request.thinkingSuffix === "none")
122
+ return { status: "not-found" };
123
+ const thinking = splitThinkingSuffix(text);
124
+ if (thinking) {
125
+ const inner = resolveText(thinking.base, request, pool, usable);
126
+ if (inner.status === "not-found")
127
+ return inner;
128
+ // Only use this thinking level if no warning from inner recursion
129
+ return { ...inner, thinkingLevel: inner.warning ? undefined : thinking.thinkingLevel };
130
+ }
131
+ // Keep an invalid suffix as part of the id and fail, rather than resolve a different model
132
+ if (request.thinkingSuffix === "strict")
133
+ return { status: "not-found" };
134
+ const colonIndex = text.lastIndexOf(":");
135
+ if (colonIndex === -1)
136
+ return { status: "not-found" };
137
+ const suffix = text.substring(colonIndex + 1);
138
+ const inner = resolveText(text.substring(0, colonIndex), request, pool, usable);
139
+ if (inner.status === "not-found")
140
+ return inner;
141
+ return {
142
+ ...inner,
143
+ thinkingLevel: undefined,
144
+ warning: `Invalid thinking level "${suffix}" in pattern "${text}". Using default instead.`,
145
+ };
146
+ }
147
+ /**
148
+ * `provider/rest` is only a hint: the whole text may also be a model id on another provider, such as
149
+ * gateway id `zai/glm-5` or commandcode id `xiaomi/mimo-v2.5-pro`. The named provider wins when usable,
150
+ * since that is what the syntax usually means; otherwise a sole usable raw match wins, since the named
151
+ * provider could not serve the request. An unusable named match is still preferred over unusable raw
152
+ * matches, so `--api-key` can set up the named provider.
153
+ */
154
+ function selectReference(text, pool, fuzzy, usable) {
155
+ const lowerText = text.toLowerCase();
156
+ const raw = pool.filter((model) => model.id.toLowerCase() === lowerText);
157
+ const split = splitProviderPrefix(text, pool);
158
+ let named;
159
+ if (split) {
160
+ const providerModels = pool.filter((model) => model.provider === split.provider);
161
+ const lowerModelText = split.modelText.toLowerCase();
162
+ // The provider's own literal id (OpenRouter's `openrouter/free`) beats its fuzzy matches
163
+ named =
164
+ providerModels.find((model) => model.id.toLowerCase() === lowerModelText) ??
165
+ raw.find((model) => model.provider === split.provider) ??
166
+ (fuzzy ? bestFuzzyMatch(fuzzyMatches(split.modelText, providerModels)) : undefined);
167
+ }
168
+ const others = raw.filter((model) => model !== named);
169
+ const candidates = named ? [named, ...others] : others;
170
+ if (candidates.length === 0)
116
171
  return undefined;
117
- }
118
- // Separate into aliases and dated versions
119
- const aliases = matches.filter((m) => isAlias(m.id));
120
- const datedVersions = matches.filter((m) => !isAlias(m.id));
121
- if (aliases.length > 0) {
122
- // Prefer alias - if multiple aliases, pick the one that sorts highest
123
- aliases.sort((a, b) => b.id.localeCompare(a.id));
124
- return aliases[0];
125
- }
126
- else {
127
- // No alias found, pick latest dated version
128
- datedVersions.sort((a, b) => b.id.localeCompare(a.id));
129
- return datedVersions[0];
130
- }
172
+ if (new Set(candidates.map((model) => model.provider)).size === 1)
173
+ return { status: "resolved", model: candidates[0] };
174
+ if (named && usable(named.provider))
175
+ return { status: "resolved", model: named };
176
+ const usableOthers = others.filter((model) => usable(model.provider));
177
+ if (usableOthers.length === 1)
178
+ return { status: "resolved", model: usableOthers[0] };
179
+ if (usableOthers.length === 0 && named)
180
+ return { status: "resolved", model: named };
181
+ return { status: "ambiguous", candidates, usableCount: usableOthers.length };
131
182
  }
132
- function buildFallbackModel(provider, modelId, availableModels) {
133
- const providerModels = availableModels.filter((m) => m.provider === provider);
134
- if (providerModels.length === 0)
183
+ function fuzzyMatches(text, models) {
184
+ const lowerText = text.toLowerCase();
185
+ return models.filter((model) => model.id.toLowerCase().includes(lowerText) || model.name?.toLowerCase().includes(lowerText));
186
+ }
187
+ function selectFuzzy(matches, usable) {
188
+ if (matches.length === 0)
189
+ return undefined;
190
+ const multipleProviders = new Set(matches.map((model) => model.provider)).size > 1;
191
+ const usableMatches = multipleProviders ? matches.filter((model) => usable(model.provider)) : [];
192
+ const pool = usableMatches.length > 0 ? usableMatches : matches;
193
+ const best = bestFuzzyMatch(pool);
194
+ if (!best)
135
195
  return undefined;
136
- const defaultId = defaultModelPerProvider[provider];
196
+ // The same id on several providers would otherwise be decided by catalog order
197
+ const tied = pool.filter((model) => model.id === best.id);
198
+ if (new Set(tied.map((model) => model.provider)).size === 1)
199
+ return { status: "resolved", model: best };
200
+ return {
201
+ status: "ambiguous",
202
+ candidates: tied,
203
+ usableCount: usableMatches.length > 0 ? tied.length : 0,
204
+ };
205
+ }
206
+ /** Prefer aliases (`claude-sonnet-4-5`) over dated versions (`claude-sonnet-4-5-20250929`), then the latest. */
207
+ function bestFuzzyMatch(matches) {
208
+ const aliases = matches.filter((model) => isAlias(model.id));
209
+ return [...(aliases.length > 0 ? aliases : matches)].sort((a, b) => b.id.localeCompare(a.id))[0];
210
+ }
211
+ function isAlias(id) {
212
+ return id.endsWith("-latest") || !/-\d{8}$/.test(id);
213
+ }
214
+ function buildFallbackModel(providerModels, modelId) {
215
+ const defaultId = defaultModelPerProvider[providerModels[0].provider];
137
216
  const baseModel = defaultId
138
217
  ? (providerModels.find((m) => m.id === defaultId) ?? providerModels[0])
139
218
  : providerModels[0];
@@ -144,129 +223,70 @@ function buildFallbackModel(provider, modelId, availableModels) {
144
223
  };
145
224
  }
146
225
  /**
147
- * Parse a pattern to extract model and thinking level.
148
- * Handles models with colons in their IDs (e.g., OpenRouter's :exacto suffix).
226
+ * Resolve scope patterns (`--models`, `enabledModels`) to models with optional thinking levels.
149
227
  *
150
- * Algorithm:
151
- * 1. Try to match full pattern as a model
152
- * 2. If found, return it with "off" thinking level
153
- * 3. If not found and has colons, split on last colon:
154
- * - If suffix is valid thinking level, use it and recurse on prefix
155
- * - If suffix is invalid, warn and recurse on prefix with "off"
156
- *
157
- * @internal Exported for testing
228
+ * Every model in `models` is usable, so credentials cannot choose between providers offering the same
229
+ * id. All of them are added, with a warning so the user can pick one with `provider/id`.
158
230
  */
159
- export function parseModelPattern(pattern, availableModels, options) {
160
- // Try exact match first
161
- const exactMatch = tryMatchModel(pattern, availableModels);
162
- if (exactMatch) {
163
- return { model: exactMatch, thinkingLevel: undefined, warning: undefined };
164
- }
165
- // No match - try splitting on last colon if present
166
- const lastColonIndex = pattern.lastIndexOf(":");
167
- if (lastColonIndex === -1) {
168
- // No colons, pattern simply doesn't match any model
169
- return { model: undefined, thinkingLevel: undefined, warning: undefined };
170
- }
171
- const prefix = pattern.substring(0, lastColonIndex);
172
- const suffix = pattern.substring(lastColonIndex + 1);
173
- if (isValidThinkingLevel(suffix)) {
174
- // Valid thinking level - recurse on prefix and use this level
175
- const result = parseModelPattern(prefix, availableModels, options);
176
- if (result.model) {
177
- // Only use this thinking level if no warning from inner recursion
178
- return {
179
- model: result.model,
180
- thinkingLevel: result.warning ? undefined : suffix,
181
- warning: result.warning,
182
- };
183
- }
184
- return result;
185
- }
186
- else {
187
- // Invalid suffix
188
- const allowFallback = options?.allowInvalidThinkingLevelFallback ?? true;
189
- if (!allowFallback) {
190
- // In strict mode (CLI --model parsing), treat it as part of the model id and fail.
191
- // This avoids accidentally resolving to a different model.
192
- return { model: undefined, thinkingLevel: undefined, warning: undefined };
193
- }
194
- // Scope mode: recurse on prefix and warn
195
- const result = parseModelPattern(prefix, availableModels, options);
196
- if (result.model) {
197
- return {
198
- model: result.model,
199
- thinkingLevel: undefined,
200
- warning: `Invalid thinking level "${suffix}" in pattern "${pattern}". Using default instead.`,
201
- };
202
- }
203
- return result;
204
- }
205
- }
206
231
  export function resolveModelScopeFromModels(patterns, models) {
207
- const availableModels = [...models];
208
232
  const scopedModels = [];
209
233
  const diagnostics = [];
234
+ const add = (model, thinkingLevel) => {
235
+ if (!scopedModels.some((scoped) => modelsAreEqual(scoped.model, model))) {
236
+ scopedModels.push({ model, thinkingLevel });
237
+ }
238
+ };
239
+ const noMatch = (pattern) => diagnostics.push({ type: "warning", code: "no-match", message: `No models match pattern "${pattern}"`, pattern });
240
+ const ambiguous = (pattern, candidates) => {
241
+ const providers = [...new Set(candidates.map((m) => m.provider))].sort((a, b) => a.localeCompare(b));
242
+ diagnostics.push({
243
+ type: "warning",
244
+ code: "ambiguous",
245
+ message: `Pattern "${pattern}" matches several providers: ${providers.join(", ")}. Use provider/id to choose one.`,
246
+ pattern,
247
+ });
248
+ };
210
249
  for (const pattern of patterns) {
211
250
  // Check if pattern contains glob characters
212
251
  if (pattern.includes("*") || pattern.includes("?") || pattern.includes("[")) {
213
252
  // Extract optional thinking level suffix (e.g., "provider/*:high")
214
- const colonIdx = pattern.lastIndexOf(":");
215
- let globPattern = pattern;
216
- let thinkingLevel;
217
- if (colonIdx !== -1) {
218
- const suffix = pattern.substring(colonIdx + 1);
219
- if (isValidThinkingLevel(suffix)) {
220
- thinkingLevel = suffix;
221
- globPattern = pattern.substring(0, colonIdx);
222
- }
223
- }
224
- const exactMatch = findExactModelReferenceMatch(globPattern, availableModels);
225
- if (exactMatch) {
226
- if (!scopedModels.find((sm) => modelsAreEqual(sm.model, exactMatch))) {
227
- scopedModels.push({ model: exactMatch, thinkingLevel });
228
- }
229
- continue;
253
+ const thinking = splitThinkingSuffix(pattern);
254
+ const globPattern = thinking?.base ?? pattern;
255
+ const thinkingLevel = thinking?.thinkingLevel;
256
+ // Ids such as `bracketed-model[1m]` are not globs
257
+ const exact = resolveModelReference({ text: globPattern, thinkingSuffix: "none", fuzzy: false }, models, () => true);
258
+ let matches = [];
259
+ if (exact.status === "resolved")
260
+ matches = [exact.model];
261
+ else if (exact.status === "ambiguous") {
262
+ matches = exact.candidates;
263
+ ambiguous(pattern, matches);
230
264
  }
231
- // Match against "provider/modelId" format OR just model ID
232
- // This allows "*sonnet*" to match without requiring "anthropic/*sonnet*"
233
- const matchingModels = availableModels.filter((m) => {
234
- const fullId = `${m.provider}/${m.id}`;
235
- return minimatch(fullId, globPattern, { nocase: true }) || minimatch(m.id, globPattern, { nocase: true });
236
- });
237
- if (matchingModels.length === 0) {
238
- diagnostics.push({
239
- type: "warning",
240
- code: "no-match",
241
- message: `No models match pattern "${pattern}"`,
242
- pattern,
243
- });
244
- continue;
245
- }
246
- for (const model of matchingModels) {
247
- if (!scopedModels.find((sm) => modelsAreEqual(sm.model, model))) {
248
- scopedModels.push({ model, thinkingLevel });
249
- }
265
+ else {
266
+ // Match against "provider/modelId" format OR just model ID
267
+ // This allows "*sonnet*" to match without requiring "anthropic/*sonnet*"
268
+ matches = models.filter((m) => minimatch(`${m.provider}/${m.id}`, globPattern, { nocase: true }) ||
269
+ minimatch(m.id, globPattern, { nocase: true }));
250
270
  }
271
+ if (matches.length === 0)
272
+ noMatch(pattern);
273
+ for (const model of matches)
274
+ add(model, thinkingLevel);
251
275
  continue;
252
276
  }
253
- const { model, thinkingLevel, warning } = parseModelPattern(pattern, availableModels);
254
- if (warning) {
255
- diagnostics.push({ type: "warning", code: "invalid-thinking-level", message: warning, pattern });
256
- }
257
- if (!model) {
258
- diagnostics.push({
259
- type: "warning",
260
- code: "no-match",
261
- message: `No models match pattern "${pattern}"`,
262
- pattern,
263
- });
277
+ const result = resolveModelReference({ text: pattern, thinkingSuffix: "lenient", fuzzy: true }, models, () => true);
278
+ if (result.status === "not-found") {
279
+ noMatch(pattern);
264
280
  continue;
265
281
  }
266
- // Avoid duplicates
267
- if (!scopedModels.find((sm) => modelsAreEqual(sm.model, model))) {
268
- scopedModels.push({ model, thinkingLevel });
282
+ if (result.warning) {
283
+ diagnostics.push({ type: "warning", code: "invalid-thinking-level", message: result.warning, pattern });
269
284
  }
285
+ if (result.status === "ambiguous")
286
+ ambiguous(pattern, result.candidates);
287
+ const matches = result.status === "resolved" ? [result.model] : result.candidates;
288
+ for (const model of matches)
289
+ add(model, result.thinkingLevel);
270
290
  }
271
291
  return { scopedModels, diagnostics };
272
292
  }
@@ -292,26 +312,23 @@ export async function resolveModelScope(patterns, modelRuntime, options) {
292
312
  * return a thinking level from "<pattern>:<thinking>" so the caller can apply it.
293
313
  */
294
314
  export function resolveCliModel(options) {
295
- const { cliProvider, cliModel, cliThinking, modelRuntime } = options;
315
+ const { cliProvider, cliModel, cliThinking, inlineApiKey, modelRuntime } = options;
296
316
  if (!cliModel) {
297
317
  return { model: undefined, warning: undefined, error: undefined };
298
318
  }
299
319
  // Important: use *all* models here, not just models with pre-configured auth.
300
320
  // This allows "--api-key" to be used for first-time setup.
301
- const availableModels = [...modelRuntime.getModels()];
302
- if (availableModels.length === 0) {
321
+ const models = [...modelRuntime.getModels()];
322
+ if (models.length === 0) {
303
323
  return {
304
324
  model: undefined,
305
325
  warning: undefined,
306
326
  error: "No models available. Check your installation or add models to models.json.",
307
327
  };
308
328
  }
309
- // Build canonical provider lookup (case-insensitive)
310
- const providerMap = new Map();
311
- for (const m of availableModels) {
312
- providerMap.set(m.provider.toLowerCase(), m.provider);
313
- }
314
- let provider = cliProvider ? providerMap.get(cliProvider.toLowerCase()) : undefined;
329
+ const provider = cliProvider
330
+ ? models.find((m) => m.provider.toLowerCase() === cliProvider.toLowerCase())?.provider
331
+ : undefined;
315
332
  if (cliProvider && !provider) {
316
333
  return {
317
334
  model: undefined,
@@ -319,183 +336,61 @@ export function resolveCliModel(options) {
319
336
  error: `Unknown provider "${cliProvider}". Use --list-models to see available providers/models.`,
320
337
  };
321
338
  }
322
- // If no explicit --provider, try to interpret "provider/model" format first.
323
- // When the prefix before the first slash matches a known provider, prefer that
324
- // interpretation over matching models whose IDs literally contain slashes
325
- // (e.g. "zai/glm-5" should resolve to provider=zai, model=glm-5, not to a
326
- // vercel-ai-gateway model with id "zai/glm-5").
327
- let pattern = cliModel;
328
- let inferredProvider = false;
329
- if (!provider) {
330
- const slashIndex = cliModel.indexOf("/");
331
- if (slashIndex !== -1) {
332
- const maybeProvider = cliModel.substring(0, slashIndex);
333
- const canonical = providerMap.get(maybeProvider.toLowerCase());
334
- if (canonical) {
335
- provider = canonical;
336
- pattern = cliModel.substring(slashIndex + 1);
337
- inferredProvider = true;
338
- }
339
- }
340
- }
341
- // If no provider was inferred from the slash, try exact matches without provider inference.
342
- // This handles models whose IDs naturally contain slashes (e.g. OpenRouter-style IDs).
343
- // Bare exact IDs can exist in multiple providers, so do not choose by catalog order.
344
- // Prefer the sole authenticated provider when there is one; otherwise require an
345
- // explicit provider to avoid silently selecting an unusable provider.
346
- if (!provider) {
347
- const lower = cliModel.toLowerCase();
348
- const exactMatches = availableModels.filter((m) => m.id.toLowerCase() === lower || `${m.provider}/${m.id}`.toLowerCase() === lower);
349
- if (exactMatches.length === 1) {
350
- return { model: exactMatches[0], warning: undefined, thinkingLevel: undefined, error: undefined };
351
- }
352
- if (exactMatches.length > 1) {
353
- const authenticatedExactMatches = exactMatches.filter((m) => modelRuntime.hasConfiguredAuth(m.provider));
354
- if (authenticatedExactMatches.length === 1) {
355
- return {
356
- model: authenticatedExactMatches[0],
357
- warning: undefined,
358
- thinkingLevel: undefined,
359
- error: undefined,
360
- };
361
- }
362
- const matches = exactMatches
363
- .map((m) => `${m.provider}/${m.id}`)
364
- .sort((a, b) => a.localeCompare(b))
365
- .join(", ");
366
- const authHint = authenticatedExactMatches.length === 0
339
+ const result = resolveModelReference({ text: cliModel, provider, thinkingSuffix: "strict", fuzzy: true }, models,
340
+ // An inline key goes to whichever provider is selected, so stored credentials must not choose it
341
+ inlineApiKey ? () => false : (providerId) => modelRuntime.hasConfiguredAuth(providerId));
342
+ if (result.status === "resolved") {
343
+ return { model: result.model, thinkingLevel: result.thinkingLevel, warning: result.warning, error: undefined };
344
+ }
345
+ if (result.status === "ambiguous") {
346
+ const matches = result.candidates
347
+ .map((m) => `${m.provider}/${m.id}`)
348
+ .sort((a, b) => a.localeCompare(b))
349
+ .join(", ");
350
+ const authHint = inlineApiKey
351
+ ? "--api-key does not choose a provider."
352
+ : result.usableCount === 0
367
353
  ? "No matching provider is authenticated."
368
354
  : "More than one matching provider is authenticated.";
369
- return {
370
- model: undefined,
371
- warning: undefined,
372
- thinkingLevel: undefined,
373
- error: `Model "${cliModel}" is ambiguous across providers: ${matches}. ${authHint} Use --provider or provider/model.`,
374
- };
375
- }
376
- }
377
- if (cliProvider && provider) {
378
- const exactModel = availableModels.find((model) => model.provider === provider && model.id.toLowerCase() === cliModel.toLowerCase());
379
- if (exactModel) {
380
- return { model: exactModel, warning: undefined, thinkingLevel: undefined, error: undefined };
381
- }
382
- // If both were provided, tolerate --model <provider>/<pattern> by stripping the provider prefix
383
- const prefix = `${provider}/`;
384
- if (cliModel.toLowerCase().startsWith(prefix.toLowerCase())) {
385
- pattern = cliModel.substring(prefix.length);
386
- }
387
- }
388
- const candidates = provider ? availableModels.filter((m) => m.provider === provider) : availableModels;
389
- const { model, thinkingLevel, warning } = parseModelPattern(pattern, candidates, {
390
- allowInvalidThinkingLevelFallback: false,
391
- });
392
- if (model) {
393
- // If provider inference matched an unauthenticated provider/model pair, prefer
394
- // one exact raw model-id match that is authenticated. This keeps
395
- // "provider/model" syntax preferred when usable, but handles models whose
396
- // literal id starts with a known provider name (for example
397
- // commandcode model id "xiaomi/mimo-v2.5-pro").
398
- if (inferredProvider) {
399
- const rawExactMatches = availableModels.filter((m) => m.id.toLowerCase() === cliModel.toLowerCase() && !modelsAreEqual(m, model));
400
- if (rawExactMatches.length > 0 && !modelRuntime.hasConfiguredAuth(model.provider)) {
401
- const authenticatedRawMatches = rawExactMatches.filter((m) => modelRuntime.hasConfiguredAuth(m.provider));
402
- if (authenticatedRawMatches.length === 1) {
403
- return {
404
- model: authenticatedRawMatches[0],
405
- thinkingLevel: undefined,
406
- warning: undefined,
407
- error: undefined,
408
- };
409
- }
410
- }
411
- }
412
- return { model, thinkingLevel, warning, error: undefined };
413
- }
414
- // If we inferred a provider from the slash but found no match within that provider,
415
- // fall back to matching the full input as a raw model id across all models.
416
- // This handles OpenRouter-style IDs like "openai/gpt-4o:extended" where "openai"
417
- // looks like a provider but the full string is actually a model id on openrouter.
418
- if (inferredProvider) {
419
- const lower = cliModel.toLowerCase();
420
- const exact = availableModels.find((m) => m.id.toLowerCase() === lower || `${m.provider}/${m.id}`.toLowerCase() === lower);
421
- if (exact) {
422
- return { model: exact, warning: undefined, thinkingLevel: undefined, error: undefined };
423
- }
424
- // Also try parseModelPattern on the full input against all models
425
- const fallback = parseModelPattern(cliModel, availableModels, {
426
- allowInvalidThinkingLevelFallback: false,
427
- });
428
- if (fallback.model) {
429
- return {
430
- model: fallback.model,
431
- thinkingLevel: fallback.thinkingLevel,
432
- warning: fallback.warning,
433
- error: undefined,
434
- };
435
- }
355
+ return {
356
+ model: undefined,
357
+ warning: undefined,
358
+ error: `Model "${cliModel}" is ambiguous across providers: ${matches}. ${authHint} Use --provider or provider/model.`,
359
+ };
436
360
  }
437
- if (provider) {
438
- // Parse thinking level suffix from the pattern before building the fallback model,
439
- // but only when --thinking is not explicitly provided.
440
- // e.g. "zai-org/GLM-5.1-FP8:high" → modelId="zai-org/GLM-5.1-FP8", fallbackThinking="high"
441
- let fallbackPattern = pattern;
442
- let fallbackThinking;
443
- if (!cliThinking) {
444
- const lastColon = pattern.lastIndexOf(":");
445
- if (lastColon !== -1) {
446
- const suffix = pattern.substring(lastColon + 1);
447
- if (isValidThinkingLevel(suffix)) {
448
- fallbackPattern = pattern.substring(0, lastColon);
449
- fallbackThinking = suffix;
450
- }
451
- }
452
- }
453
- const fallbackModel = buildFallbackModel(provider, fallbackPattern, availableModels);
454
- if (fallbackModel) {
455
- const requestedThinking = cliThinking ?? fallbackThinking;
456
- const model = requestedThinking && requestedThinking !== "off" ? { ...fallbackModel, reasoning: true } : fallbackModel;
457
- const fallbackWarning = warning
458
- ? `${warning} Model "${fallbackPattern}" not found for provider "${provider}". Using custom model id.`
459
- : `Model "${fallbackPattern}" not found for provider "${provider}". Using custom model id.`;
460
- return { model, thinkingLevel: fallbackThinking, warning: fallbackWarning, error: undefined };
461
- }
361
+ const { target } = result;
362
+ if (!target) {
363
+ return {
364
+ model: undefined,
365
+ warning: undefined,
366
+ error: `Model "${cliModel}" not found. Use --list-models to see available models.`,
367
+ };
462
368
  }
463
- const display = provider ? `${provider}/${pattern}` : cliModel;
369
+ // Use the thinking level suffix only when --thinking is not explicitly provided; otherwise it
370
+ // stays part of the custom model id.
371
+ // e.g. "zai-org/GLM-5.1-FP8:high" → modelId="zai-org/GLM-5.1-FP8", fallbackThinking="high"
372
+ const modelId = cliThinking ? target.modelText : target.modelId;
373
+ const fallbackThinking = cliThinking ? undefined : target.thinkingLevel;
374
+ const fallbackModel = buildFallbackModel(target.providerModels, modelId);
375
+ const requestedThinking = cliThinking ?? fallbackThinking;
464
376
  return {
465
- model: undefined,
466
- thinkingLevel: undefined,
467
- warning,
468
- error: `Model "${display}" not found. Use --list-models to see available models.`,
377
+ model: requestedThinking && requestedThinking !== "off" ? { ...fallbackModel, reasoning: true } : fallbackModel,
378
+ thinkingLevel: fallbackThinking,
379
+ warning: `Model "${modelId}" not found for provider "${target.provider}". Using custom model id.`,
380
+ error: undefined,
469
381
  };
470
382
  }
471
383
  /**
472
384
  * Find the initial model to use based on priority:
473
- * 1. CLI args (provider + model)
474
- * 2. First model from scoped models (if not continuing/resuming)
475
- * 3. Restored from session (if continuing/resuming)
476
- * 4. Saved default from settings
477
- * 5. First available model with valid API key
385
+ * 1. First model from scoped models (if not continuing/resuming)
386
+ * 2. Saved default from settings
387
+ * 3. First available model with valid API key
478
388
  */
479
389
  export async function findInitialModel(options) {
480
- const { cliProvider, cliModel, scopedModels, isContinuing, defaultProvider, defaultModelId, defaultThinkingLevel, modelThinkingLevels, modelRuntime, } = options;
390
+ const { scopedModels, isContinuing, defaultProvider, defaultModelId, defaultThinkingLevel, modelThinkingLevels, modelRuntime, } = options;
481
391
  let model;
482
392
  let thinkingLevel = DEFAULT_THINKING_LEVEL;
483
- // 1. CLI args take priority
484
- if (cliProvider && cliModel) {
485
- const resolved = resolveCliModel({
486
- cliProvider,
487
- cliModel,
488
- modelRuntime,
489
- });
490
- if (resolved.error) {
491
- console.error(chalk.red(resolved.error));
492
- process.exit(1);
493
- }
494
- if (resolved.model) {
495
- return { model: resolved.model, thinkingLevel: DEFAULT_THINKING_LEVEL, fallbackMessage: undefined };
496
- }
497
- }
498
- // 2. Use first model from scoped models (skip if continuing/resuming)
393
+ // 1. Use first model from scoped models (skip if continuing/resuming)
499
394
  if (scopedModels.length > 0 && !isContinuing) {
500
395
  const scopedModel = scopedModels[0];
501
396
  const perModel = modelThinkingLevels?.[`${scopedModel.model.provider}/${scopedModel.model.id}`];
@@ -505,7 +400,7 @@ export async function findInitialModel(options) {
505
400
  fallbackMessage: undefined,
506
401
  };
507
402
  }
508
- // 3. Try saved default from settings if auth is configured.
403
+ // 2. Try saved default from settings if auth is configured.
509
404
  if (defaultProvider && defaultModelId) {
510
405
  const found = modelRuntime.getModel(defaultProvider, defaultModelId);
511
406
  if (found && modelRuntime.hasConfiguredAuth(found.provider)) {
@@ -520,7 +415,7 @@ export async function findInitialModel(options) {
520
415
  return { model, thinkingLevel, fallbackMessage: undefined };
521
416
  }
522
417
  }
523
- // 4. Try first available model with valid API key
418
+ // 3. Try first available model with valid API key
524
419
  const availableModels = [...modelRuntime.getAvailableSnapshot()];
525
420
  if (availableModels.length > 0) {
526
421
  // Try to find a default model from known providers
@@ -534,7 +429,7 @@ export async function findInitialModel(options) {
534
429
  // If no default found, use first available
535
430
  return { model: availableModels[0], thinkingLevel: DEFAULT_THINKING_LEVEL, fallbackMessage: undefined };
536
431
  }
537
- // 5. No model found
432
+ // 4. No model found
538
433
  return { model: undefined, thinkingLevel: DEFAULT_THINKING_LEVEL, fallbackMessage: undefined };
539
434
  }
540
435
  /**