@humain/humain-code 0.4.14 → 0.4.17

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 (315) hide show
  1. package/CHANGELOG.md +93 -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-HDA2IGKA.js → chunk-4NFYTS4C.js} +8 -8
  8. package/dist/bundle/chunks/{chunk-MF2NEHP4.js → chunk-4XU7TDAL.js} +939 -560
  9. package/dist/bundle/chunks/{chunk-LUL775V7.js → chunk-5K5RFXXO.js} +4 -4
  10. package/dist/bundle/chunks/chunk-65U7MPF4.js +1790 -0
  11. package/dist/bundle/chunks/{chunk-AIXI6RIE.js → chunk-7PRU6YW3.js} +114 -82
  12. package/dist/bundle/chunks/{chunk-KA7K6ECX.js → chunk-AOL6QG6L.js} +2254 -2416
  13. package/dist/bundle/chunks/chunk-AWCJWXGD.js +212 -0
  14. package/dist/bundle/chunks/{chunk-NNKA2PAP.js → chunk-FHVNUUBF.js} +1 -1
  15. package/dist/bundle/chunks/chunk-FZUJXM6D.js +816 -0
  16. package/dist/bundle/chunks/chunk-IJYVMOB4.js +6 -0
  17. package/dist/bundle/chunks/chunk-LG2PJ6JN.js +131 -0
  18. package/dist/bundle/chunks/chunk-NCQ6WAQK.js +125 -0
  19. package/dist/bundle/chunks/{chunk-Z74ZYQPX.js → chunk-OKALNPTJ.js} +80 -210
  20. package/dist/bundle/chunks/{chunk-OX2IBCCA.js → chunk-PTP2ZHFQ.js} +88 -82
  21. package/dist/bundle/chunks/chunk-PY7SOXCA.js +10 -0
  22. package/dist/bundle/chunks/chunk-Q7VXYXY3.js +7 -0
  23. package/dist/bundle/chunks/{chunk-COF5P635.js → chunk-QEF72EIZ.js} +13 -13
  24. package/dist/bundle/chunks/{chunk-EYIYBQAR.js → chunk-RXOCQRBG.js} +1 -1
  25. package/dist/bundle/chunks/{chunk-BVHXWQLD.js → chunk-SCBU5WOP.js} +1 -1
  26. package/dist/bundle/chunks/{chunk-UDVC7A5S.js → chunk-TIFFHHW6.js} +16 -14
  27. package/dist/bundle/chunks/{chunk-L3J4P5JR.js → chunk-UGJAAWNC.js} +1 -1
  28. package/dist/bundle/chunks/chunk-V76YPIMT.js +48 -0
  29. package/dist/bundle/chunks/{chunk-Y3RFGBG2.js → chunk-X3O5MCKJ.js} +1 -1
  30. package/dist/bundle/chunks/{chunk-KK3KUUMM.js → chunk-X6OTEVGA.js} +71 -66
  31. package/dist/bundle/chunks/chunk-Y26OS23T.js +80 -0
  32. package/dist/bundle/chunks/chunk-YDBNMIA3.js +34 -0
  33. package/dist/bundle/chunks/{chunk-UHLW4KJ7.js → chunk-ZRGFX6T6.js} +92 -89
  34. package/dist/bundle/chunks/{cloudflare-workers-ai-system-one-JGN7NZCV.js → cloudflare-workers-ai-system-one-MUJQ6LT2.js} +1 -1
  35. package/dist/bundle/chunks/{compat-OQMUE3QD.js → compat-ARQPWKBQ.js} +8 -8
  36. package/dist/bundle/chunks/{dist-65YQEF26.js → dist-D7M52E3X.js} +1733 -1053
  37. package/dist/bundle/chunks/dist-LKDZAEUQ.js +7 -0
  38. package/dist/bundle/chunks/{dist-JXEXN6S2.js → dist-XVXV2CL4.js} +1 -1
  39. package/dist/bundle/chunks/dist-cjs-AXBW3N4F.js +182 -0
  40. package/dist/bundle/chunks/{easter-egg-3d-ZJ2JUFOA.js → easter-egg-3d-4SUPLBUF.js} +1 -1
  41. package/dist/bundle/chunks/{execute-LRTXH4YJ.js → execute-NTO3U76E.js} +10 -9
  42. package/dist/bundle/chunks/{extract-OZW5JHG6.js → extract-BKBHK4AK.js} +14 -13
  43. package/dist/bundle/chunks/github-copilot.js +34 -47
  44. package/dist/bundle/chunks/{google-generative-ai-YXXFSTX7.js → google-generative-ai-SJ4JO2MY.js} +2 -2
  45. package/dist/bundle/chunks/{google-vertex-3IVWLYJ5.js → google-vertex-KNLNNDET.js} +2 -2
  46. package/dist/bundle/chunks/host-63SNKK5Y.js +2 -0
  47. package/dist/bundle/chunks/jiti-static-loader-7OZNBOCI.js +2 -0
  48. package/dist/bundle/chunks/{mistral-conversations-Y7GWO3QB.js → mistral-conversations-G3GN6CMT.js} +20 -20
  49. package/dist/bundle/chunks/{node-SPBTZUUS.js → node-DZCAT4Q6.js} +1 -1
  50. package/dist/bundle/chunks/{openai-codex-responses-NSXWHIDT.js → openai-codex-responses-FJFDAWHI.js} +17 -17
  51. package/dist/bundle/chunks/openai-completions-IC7WRLTI.js +82 -0
  52. package/dist/bundle/chunks/{openai-decisions-QWEISDVO.js → openai-decisions-HESOHYZB.js} +1 -1
  53. package/dist/bundle/chunks/openai-responses-XXCYDFSM.js +24 -0
  54. package/dist/bundle/chunks/{openrouter-images-BMVMAROU.js → openrouter-images-DT2HMZNO.js} +1 -1
  55. package/dist/bundle/chunks/pdfjs-EK6K7CXX.js +3593 -0
  56. package/dist/bundle/chunks/{pi-messages-XNEG23NU.js → pi-messages-SAOV3JNW.js} +1 -1
  57. package/dist/bundle/chunks/{typesafe-system-one-62YHYXZV.js → typesafe-system-one-HCMGHK6A.js} +1 -1
  58. package/dist/bundle/chunks/{undici-7EW63V4X.js → undici-N4LWJ3S3.js} +1 -1
  59. package/dist/bundle/chunks/virtual-modules-LP2ULVLW.js +5 -0
  60. package/dist/bundle/cli-runtime.js +3 -3
  61. package/dist/bundle/cli.js +2 -2
  62. package/dist/bundle/flow/package.json +6 -5
  63. package/dist/bundle/index.js +8 -8
  64. package/dist/bundle/rpc-entry.js +3 -3
  65. package/dist/cli/credential-print.d.ts.map +1 -1
  66. package/dist/cli/credential-print.js +4 -4
  67. package/dist/cli/credential-print.js.map +1 -1
  68. package/dist/coordination/adapter/index.d.ts.map +1 -1
  69. package/dist/coordination/adapter/index.js +1 -1
  70. package/dist/coordination/adapter/index.js.map +1 -1
  71. package/dist/coordination/adapter/integration-notices.d.ts +1 -1
  72. package/dist/coordination/adapter/integration-notices.d.ts.map +1 -1
  73. package/dist/coordination/adapter/integration-notices.js +5 -2
  74. package/dist/coordination/adapter/integration-notices.js.map +1 -1
  75. package/dist/coordination/broker/extension-state.js +3 -3
  76. package/dist/coordination/broker/extension-state.js.map +1 -1
  77. package/dist/coordination/transport/framing.d.ts.map +1 -1
  78. package/dist/coordination/transport/framing.js +2 -1
  79. package/dist/coordination/transport/framing.js.map +1 -1
  80. package/dist/core/account-reporting.d.ts +3 -1
  81. package/dist/core/account-reporting.d.ts.map +1 -1
  82. package/dist/core/account-reporting.js +12 -2
  83. package/dist/core/account-reporting.js.map +1 -1
  84. package/dist/core/agent-session-services.d.ts.map +1 -1
  85. package/dist/core/agent-session-services.js +39 -36
  86. package/dist/core/agent-session-services.js.map +1 -1
  87. package/dist/core/agent-session.d.ts +4 -2
  88. package/dist/core/agent-session.d.ts.map +1 -1
  89. package/dist/core/agent-session.js +5 -4
  90. package/dist/core/agent-session.js.map +1 -1
  91. package/dist/core/codex-usage.d.ts +11 -2
  92. package/dist/core/codex-usage.d.ts.map +1 -1
  93. package/dist/core/codex-usage.js +74 -2
  94. package/dist/core/codex-usage.js.map +1 -1
  95. package/dist/core/export-html/template.js +21 -16
  96. package/dist/core/model-config.d.ts +33 -8
  97. package/dist/core/model-config.d.ts.map +1 -1
  98. package/dist/core/model-config.js +22 -4
  99. package/dist/core/model-config.js.map +1 -1
  100. package/dist/core/model-resolver.d.ts +56 -43
  101. package/dist/core/model-resolver.d.ts.map +1 -1
  102. package/dist/core/model-resolver.js +256 -361
  103. package/dist/core/model-resolver.js.map +1 -1
  104. package/dist/core/model-runtime.d.ts +6 -3
  105. package/dist/core/model-runtime.d.ts.map +1 -1
  106. package/dist/core/model-runtime.js +19 -5
  107. package/dist/core/model-runtime.js.map +1 -1
  108. package/dist/core/models-store.d.ts.map +1 -1
  109. package/dist/core/models-store.js +7 -2
  110. package/dist/core/models-store.js.map +1 -1
  111. package/dist/core/oauth-account-pool.d.ts +9 -1
  112. package/dist/core/oauth-account-pool.d.ts.map +1 -1
  113. package/dist/core/oauth-account-pool.js +63 -12
  114. package/dist/core/oauth-account-pool.js.map +1 -1
  115. package/dist/core/prompt-templates.d.ts.map +1 -1
  116. package/dist/core/prompt-templates.js +7 -2
  117. package/dist/core/prompt-templates.js.map +1 -1
  118. package/dist/core/settings-defaults.d.ts +2 -0
  119. package/dist/core/settings-defaults.d.ts.map +1 -1
  120. package/dist/core/settings-defaults.js +2 -0
  121. package/dist/core/settings-defaults.js.map +1 -1
  122. package/dist/core/settings-manager.d.ts +4 -2
  123. package/dist/core/settings-manager.d.ts.map +1 -1
  124. package/dist/core/settings-manager.js +11 -0
  125. package/dist/core/settings-manager.js.map +1 -1
  126. package/dist/core/settings-schema.d.ts +4 -0
  127. package/dist/core/settings-schema.d.ts.map +1 -1
  128. package/dist/core/settings-schema.js +8 -0
  129. package/dist/core/settings-schema.js.map +1 -1
  130. package/dist/core/slash-commands.js +1 -1
  131. package/dist/core/slash-commands.js.map +1 -1
  132. package/dist/core/tools/render-utils.d.ts +2 -0
  133. package/dist/core/tools/render-utils.d.ts.map +1 -1
  134. package/dist/core/tools/render-utils.js +21 -0
  135. package/dist/core/tools/render-utils.js.map +1 -1
  136. package/dist/core/tools/renderers/read.d.ts.map +1 -1
  137. package/dist/core/tools/renderers/read.js +7 -10
  138. package/dist/core/tools/renderers/read.js.map +1 -1
  139. package/dist/core/tools/subagent.d.ts.map +1 -1
  140. package/dist/core/tools/subagent.js +4 -7
  141. package/dist/core/tools/subagent.js.map +1 -1
  142. package/dist/core/trace/redaction.d.ts.map +1 -1
  143. package/dist/core/trace/redaction.js +3 -1
  144. package/dist/core/trace/redaction.js.map +1 -1
  145. package/dist/extensions/codemode/execute.d.ts.map +1 -1
  146. package/dist/extensions/codemode/execute.js +12 -0
  147. package/dist/extensions/codemode/execute.js.map +1 -1
  148. package/dist/extensions/codemode/index.d.ts.map +1 -1
  149. package/dist/extensions/codemode/index.js +5 -0
  150. package/dist/extensions/codemode/index.js.map +1 -1
  151. package/dist/humain/bedrock-provider/vendor/index.bundle.mjs +74 -20
  152. package/dist/humain/flow-accounts-host.d.ts.map +1 -1
  153. package/dist/humain/flow-accounts-host.js +3 -0
  154. package/dist/humain/flow-accounts-host.js.map +1 -1
  155. package/dist/humain/flow-command.d.ts +1 -1
  156. package/dist/humain/flow-command.d.ts.map +1 -1
  157. package/dist/humain/flow-command.js +8 -1
  158. package/dist/humain/flow-command.js.map +1 -1
  159. package/dist/humain/flow-loader.js +1 -1
  160. package/dist/humain/flow-loader.js.map +1 -1
  161. package/dist/humain/node-provider.d.ts.map +1 -1
  162. package/dist/humain/node-provider.js +2 -0
  163. package/dist/humain/node-provider.js.map +1 -1
  164. package/dist/humain/trace-capture/index.js +3 -3
  165. package/dist/humain/trace-capture/index.js.map +1 -1
  166. package/dist/humain/web-access/vendor/credential-source.d.ts +2 -0
  167. package/dist/humain/web-access/vendor/credential-source.d.ts.map +1 -1
  168. package/dist/humain/web-access/vendor/credential-source.js +50 -4
  169. package/dist/humain/web-access/vendor/credential-source.js.map +1 -1
  170. package/dist/humain/web-access/vendor/curator-page.d.ts.map +1 -1
  171. package/dist/humain/web-access/vendor/curator-page.js +3 -1
  172. package/dist/humain/web-access/vendor/curator-page.js.map +1 -1
  173. package/dist/humain/web-access/vendor/curator-server.d.ts.map +1 -1
  174. package/dist/humain/web-access/vendor/curator-server.js +2 -0
  175. package/dist/humain/web-access/vendor/curator-server.js.map +1 -1
  176. package/dist/humain/web-access/vendor/deepseek.d.ts +4 -0
  177. package/dist/humain/web-access/vendor/deepseek.d.ts.map +1 -0
  178. package/dist/humain/web-access/vendor/deepseek.js +201 -0
  179. package/dist/humain/web-access/vendor/deepseek.js.map +1 -0
  180. package/dist/humain/web-access/vendor/extract.d.ts.map +1 -1
  181. package/dist/humain/web-access/vendor/extract.js +4 -2
  182. package/dist/humain/web-access/vendor/extract.js.map +1 -1
  183. package/dist/humain/web-access/vendor/gemini-adc.d.ts.map +1 -1
  184. package/dist/humain/web-access/vendor/gemini-adc.js +49 -5
  185. package/dist/humain/web-access/vendor/gemini-adc.js.map +1 -1
  186. package/dist/humain/web-access/vendor/gemini-search.d.ts +3 -3
  187. package/dist/humain/web-access/vendor/gemini-search.d.ts.map +1 -1
  188. package/dist/humain/web-access/vendor/gemini-search.js +11 -4
  189. package/dist/humain/web-access/vendor/gemini-search.js.map +1 -1
  190. package/dist/humain/web-access/vendor/index.d.ts.map +1 -1
  191. package/dist/humain/web-access/vendor/index.js +16 -1
  192. package/dist/humain/web-access/vendor/index.js.map +1 -1
  193. package/dist/humain/web-access/vendor/page-query.d.ts.map +1 -1
  194. package/dist/humain/web-access/vendor/page-query.js +12 -6
  195. package/dist/humain/web-access/vendor/page-query.js.map +1 -1
  196. package/dist/humain/web-access/vendor/query-rewrite.d.ts.map +1 -1
  197. package/dist/humain/web-access/vendor/query-rewrite.js +11 -4
  198. package/dist/humain/web-access/vendor/query-rewrite.js.map +1 -1
  199. package/dist/humain/web-access/vendor/searxng.d.ts.map +1 -1
  200. package/dist/humain/web-access/vendor/searxng.js +2 -1
  201. package/dist/humain/web-access/vendor/searxng.js.map +1 -1
  202. package/dist/humain/web-access/vendor/ssrf-protection.d.ts +1 -0
  203. package/dist/humain/web-access/vendor/ssrf-protection.d.ts.map +1 -1
  204. package/dist/humain/web-access/vendor/ssrf-protection.js +10 -0
  205. package/dist/humain/web-access/vendor/ssrf-protection.js.map +1 -1
  206. package/dist/humain/web-access/vendor/summary-review.d.ts.map +1 -1
  207. package/dist/humain/web-access/vendor/summary-review.js +17 -6
  208. package/dist/humain/web-access/vendor/summary-review.js.map +1 -1
  209. package/dist/humain/web-access/vendor/utils.d.ts +2 -0
  210. package/dist/humain/web-access/vendor/utils.d.ts.map +1 -1
  211. package/dist/humain/web-access/vendor/utils.js +18 -0
  212. package/dist/humain/web-access/vendor/utils.js.map +1 -1
  213. package/dist/humain/web-access/vendor/web-tool-core.d.ts +2 -0
  214. package/dist/humain/web-access/vendor/web-tool-core.d.ts.map +1 -1
  215. package/dist/humain/web-access/vendor/web-tool-core.js.map +1 -1
  216. package/dist/index.d.ts +1 -0
  217. package/dist/index.d.ts.map +1 -1
  218. package/dist/index.js.map +1 -1
  219. package/dist/main.d.ts.map +1 -1
  220. package/dist/main.js +1 -0
  221. package/dist/main.js.map +1 -1
  222. package/dist/modes/interactive/components/settings-selector.d.ts +3 -1
  223. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  224. package/dist/modes/interactive/components/settings-selector.js +10 -0
  225. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  226. package/dist/modes/interactive/components/status-indicator.d.ts +5 -0
  227. package/dist/modes/interactive/components/status-indicator.d.ts.map +1 -1
  228. package/dist/modes/interactive/components/status-indicator.js +27 -2
  229. package/dist/modes/interactive/components/status-indicator.js.map +1 -1
  230. package/dist/modes/interactive/components/tool-execution.d.ts +2 -1
  231. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  232. package/dist/modes/interactive/components/tool-execution.js +4 -2
  233. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  234. package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
  235. package/dist/modes/interactive/components/tree-selector.js +2 -9
  236. package/dist/modes/interactive/components/tree-selector.js.map +1 -1
  237. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  238. package/dist/modes/interactive/interactive-mode.js +28 -14
  239. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  240. package/dist/modes/interactive/oauth-account-format.d.ts +4 -4
  241. package/dist/modes/interactive/oauth-account-format.d.ts.map +1 -1
  242. package/dist/modes/interactive/oauth-account-format.js +5 -2
  243. package/dist/modes/interactive/oauth-account-format.js.map +1 -1
  244. package/dist/modes/interactive/session-share.d.ts.map +1 -1
  245. package/dist/modes/interactive/session-share.js +9 -2
  246. package/dist/modes/interactive/session-share.js.map +1 -1
  247. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  248. package/dist/modes/rpc/rpc-mode.js +16 -4
  249. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  250. package/dist/utils/tools-manager.d.ts.map +1 -1
  251. package/dist/utils/tools-manager.js +2 -1
  252. package/dist/utils/tools-manager.js.map +1 -1
  253. package/docs/cli.md +3 -3
  254. package/docs/codemode.md +3 -1
  255. package/docs/coordination.md +6 -0
  256. package/docs/docs.json +4 -0
  257. package/docs/environment-variables.md +4 -0
  258. package/docs/flow.md +20 -2
  259. package/docs/humain-code-forge-flow-walkthrough.md +1 -1
  260. package/docs/humain-code.md +2 -4
  261. package/docs/json.md +2 -2
  262. package/docs/llama-cpp.md +1 -1
  263. package/docs/nvidia-rtx-llama-cpp.md +96 -0
  264. package/docs/rpc-commands.md +1 -1
  265. package/docs/rpc.md +9 -1
  266. package/docs/sessions.md +1 -1
  267. package/docs/settings.md +2 -0
  268. package/docs/trace.md +4 -0
  269. package/docs/usage.md +1 -1
  270. package/examples/extensions/custom-provider-anthropic/package-lock.json +16 -6
  271. package/examples/extensions/custom-provider-anthropic/package.json +2 -2
  272. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  273. package/examples/extensions/gondolin/package-lock.json +16 -16
  274. package/examples/extensions/gondolin/package.json +1 -1
  275. package/examples/extensions/minimal-mode.ts +4 -4
  276. package/examples/extensions/sandbox/package-lock.json +6 -6
  277. package/examples/extensions/sandbox/package.json +2 -2
  278. package/examples/extensions/with-deps/package-lock.json +2 -2
  279. package/examples/extensions/with-deps/package.json +1 -1
  280. package/examples/plugins/pi-example-plugin/package.json +2 -2
  281. package/examples/rpc-subagent-progress-host.ts +6 -2
  282. package/npm-shrinkwrap.json +129 -171
  283. package/package.json +19 -19
  284. package/schemas/models.schema.json +9 -5
  285. package/schemas/settings.schema.json +32 -0
  286. package/src/coordination/UPSTREAM.md +31 -1
  287. package/src/coordination/upstream.json +3 -3
  288. package/src/humain/adhd/UPSTREAM.md +8 -0
  289. package/src/humain/caveman/UPSTREAM.md +19 -3
  290. package/src/humain/caveman/upstream.json +2 -2
  291. package/src/humain/ponytail/UPSTREAM.md +23 -2
  292. package/src/humain/ponytail/upstream.json +8 -8
  293. package/src/humain/ponytail/vendor/skills/ponytail/SKILL.md +1 -1
  294. package/src/humain/ponytail/vendor/skills/ponytail-debt/SKILL.md +1 -2
  295. package/src/humain/ponytail/vendor/skills/ponytail-gain/SKILL.md +0 -1
  296. package/src/humain/web-access/UPSTREAM.md +45 -1
  297. package/src/humain/web-access/upstream.json +4 -4
  298. package/dist/bundle/chunks/anthropic-messages-YSAHA7QM.js +0 -67
  299. package/dist/bundle/chunks/azure-openai-responses-Z5XYDPHS.js +0 -15
  300. package/dist/bundle/chunks/chunk-2TTB6GIB.js +0 -47
  301. package/dist/bundle/chunks/chunk-4DXXZHY2.js +0 -540
  302. package/dist/bundle/chunks/chunk-A7QKOI62.js +0 -572
  303. package/dist/bundle/chunks/chunk-FRUFMISJ.js +0 -505
  304. package/dist/bundle/chunks/chunk-IUKCPYKD.js +0 -1786
  305. package/dist/bundle/chunks/chunk-MG5PX4KU.js +0 -31
  306. package/dist/bundle/chunks/chunk-RYC5BYVE.js +0 -5
  307. package/dist/bundle/chunks/chunk-YJ3NQWES.js +0 -9
  308. package/dist/bundle/chunks/dist-MNSGVI4C.js +0 -7
  309. package/dist/bundle/chunks/dist-cjs-4BMVQ74V.js +0 -179
  310. package/dist/bundle/chunks/host-2RMBOGA7.js +0 -2
  311. package/dist/bundle/chunks/jiti-static-loader-2RCDI6B4.js +0 -2
  312. package/dist/bundle/chunks/openai-completions-WGBQHTYA.js +0 -79
  313. package/dist/bundle/chunks/openai-responses-OKGCSIEY.js +0 -23
  314. package/dist/bundle/chunks/pdfjs-6UVU6XFX.js +0 -3564
  315. package/dist/bundle/chunks/virtual-modules-5KW36RPG.js +0 -5
@@ -1 +1 @@
1
- {"version":3,"file":"flow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} from \"@earendil-works/pi-ai\";\nimport {\n\tAccountReporter,\n\ttype AccountReportTarget,\n\ttype AccountUsageReport,\n\tcreateCodexUsageCollector,\n} from \"../core/account-reporting.ts\";\nimport {\n\tANTHROPIC_PROVIDER_ID,\n\ttype AnthropicReportingCredentialProvider,\n\tanthropicOrganizationTarget,\n\tcreateAnthropicReportCollector,\n} from \"../core/anthropic-account-reporting.ts\";\nimport {\n\tBEDROCK_AWS_CREDENTIALS_SOURCE,\n\tBEDROCK_PROVIDER_ID,\n\ttype BedrockReportCollectorDeps,\n\tbedrockReportingCredentials,\n\tcreateBedrockReportCollector,\n\topenCloudWatchMetricsSession,\n} from \"../core/bedrock-account-reporting.ts\";\nimport { CODEX_USAGE_PROVIDER_ID } from \"../core/codex-usage.ts\";\nimport type { ExtensionContext } from \"../core/extensions/types.ts\";\nimport type { ModelRegistry } from \"../core/model-registry.ts\";\nimport type { AccountInfo, AccountSource, ModelRuntime } from \"../core/model-runtime.ts\";\nimport {\n\tassessNodeFallback,\n\tisSafeNodeText,\n\tMAX_NODE_FALLBACK_KEYS,\n\tMAX_NODE_LABEL_LENGTH,\n\ttype NodeAccountFallbackPolicy,\n\ttype NodeAccountLabels,\n\ttype NodeAccountView,\n\ttype NodeFallbackAssessment,\n} from \"./node-account-fallback.ts\";\nimport { describeHumainNodeEndpoint, HUMAIN_NODE_BASE_URL_ENV, HUMAIN_NODE_PROVIDER } from \"./node-provider.ts\";\n\n/**\n * Session-bound bridge that lets Flow drive host-owned account dialogs and catalog readiness.\n * Credentials never cross it: every value is non-secret metadata or a model catalog.\n */\nexport type FlowCatalogState =\n\t| { state: \"ready\"; models: readonly Model<Api>[] }\n\t| { state: \"unavailable\"; reason: string };\n\nexport interface FlowAccountsHost {\n\t/**\n\t * Resolves after the user finishes or cancels the account interaction. Cancelling through the signal ends the\n\t * dialog; sign-ins, account switches and removals already completed stay in effect.\n\t */\n\topenAccounts(signal: AbortSignal): Promise<void>;\n\t/** Explicit action: refresh the provider's catalog for the selected account, allowing network access. */\n\trefreshCatalog(providerId: string, signal: AbortSignal): Promise<FlowCatalogState>;\n\t/**\n\t * Explicit \"Refresh usage\" action. The only path that reaches a reporting transport; listing accounts and opening\n\t * Advanced never call it. Resolves to a labelled report and never throws for unavailable data.\n\t */\n\trefreshAccountUsage(target: AccountReportTarget, signal: AbortSignal): Promise<AccountUsageReport>;\n\t/** Opt-in HUMAIN Node key fallback: current policy, aliases, labels and setup warnings. No network. */\n\tgetNodeFallback(signal: AbortSignal): Promise<FlowNodeFallbackState>;\n\t/** Validate and persist policy and labels outside the credential store, then return the new state. */\n\tupdateNodeFallback(update: FlowNodeFallbackUpdate, signal: AbortSignal): Promise<FlowNodeFallbackState>;\n\t/** Whether `text` contains a stored HUMAIN Node key. Only the answer crosses the bridge, never a key. */\n\tlabelContainsStoredKey(text: string, signal: AbortSignal): Promise<boolean>;\n}\n\nexport const FLOW_ACCOUNTS_UNAVAILABLE = \"Account interaction unavailable\";\n\ninterface FlowAccountsBinding {\n\thandle: FlowAccountsHost;\n\trelease: () => void;\n}\n\nconst bindings = new WeakMap<ModelRegistry, FlowAccountsBinding>();\n\n/** Bind a host to the registry of the current session. Rebinding supersedes the previous generation. */\nexport function bindFlowAccountsHost(registry: ModelRegistry, host: FlowAccountsHost): () => void {\n\tbindings.get(registry)?.release();\n\tconst generation = new AbortController();\n\tconst run = async <T>(signal: AbortSignal, operation: (signal: AbortSignal) => Promise<T>): Promise<T> => {\n\t\tif (generation.signal.aborted) throw new Error(FLOW_ACCOUNTS_UNAVAILABLE);\n\t\ttry {\n\t\t\tconst result = await operation(AbortSignal.any([signal, generation.signal]));\n\t\t\tif (generation.signal.aborted) throw new Error(FLOW_ACCOUNTS_UNAVAILABLE);\n\t\t\treturn result;\n\t\t} catch (error) {\n\t\t\tif (generation.signal.aborted) throw new Error(FLOW_ACCOUNTS_UNAVAILABLE);\n\t\t\tthrow error;\n\t\t}\n\t};\n\tconst binding: FlowAccountsBinding = {\n\t\thandle: {\n\t\t\topenAccounts: (signal) => run(signal, (combined) => host.openAccounts(combined)),\n\t\t\trefreshCatalog: (providerId, signal) => run(signal, (combined) => host.refreshCatalog(providerId, combined)),\n\t\t\trefreshAccountUsage: (target, signal) => run(signal, (combined) => host.refreshAccountUsage(target, combined)),\n\t\t\tgetNodeFallback: (signal) => run(signal, (combined) => host.getNodeFallback(combined)),\n\t\t\tupdateNodeFallback: (update, signal) => run(signal, (combined) => host.updateNodeFallback(update, combined)),\n\t\t\tlabelContainsStoredKey: (text, signal) =>\n\t\t\t\trun(signal, (combined) => host.labelContainsStoredKey(text, combined)),\n\t\t},\n\t\trelease: () => {\n\t\t\tgeneration.abort();\n\t\t\tif (bindings.get(registry) === binding) bindings.delete(registry);\n\t\t},\n\t};\n\tbindings.set(registry, binding);\n\treturn binding.release;\n}\n\n/** Look up the host by actual registry identity. Only the terminal UI owns secure dialogs. */\nexport function getFlowAccountsHost(\n\tctx: Pick<ExtensionContext, \"modelRegistry\" | \"mode\">,\n): FlowAccountsHost | undefined {\n\treturn ctx.mode === \"tui\" ? bindings.get(ctx.modelRegistry)?.handle : undefined;\n}\n\n/** Secret-free account metadata. `endpoint` is the HUMAIN Node base URL; `region` the stored Bedrock region. */\nexport interface FlowAccountMetadata extends AccountInfo {\n\tendpoint?: string;\n\tregion?: string;\n}\n\nexport interface FlowAccountSourceMetadata extends AccountSource {\n\tendpoint?: string;\n\t/** Stored Bedrock region of the auth.json provider configuration. */\n\tregion?: string;\n}\n\nexport interface FlowProviderAccountMetadata {\n\tproviderId: string;\n\taccounts: FlowAccountMetadata[];\n\tsources: FlowAccountSourceMetadata[];\n}\n\nfunction envString(env: Record<string, unknown> | undefined, name: string): string | undefined {\n\tconst value = env?.[name];\n\treturn typeof value === \"string\" ? value : undefined;\n}\n\n/**\n * Enumerate accounts and sources from stored metadata only. This never resolves credentials, refreshes OAuth,\n * runs credential commands, or touches the network; `accounts.list/sources` are side-effect-free by contract.\n */\nexport async function listFlowAccountMetadata(\n\truntime: ModelRuntime,\n\tproviderId: string,\n\tsignal: AbortSignal,\n\tambientEnv: NodeJS.ProcessEnv = process.env,\n): Promise<FlowProviderAccountMetadata> {\n\tconst options = { signal };\n\tconst accounts = await runtime.accounts.list(providerId, options);\n\tconst sources = await runtime.accounts.sources(providerId, options);\n\tconst stored = await runtime.oauthAccounts.listAccounts(providerId, options);\n\tconst ambientEndpoint = envString(ambientEnv, HUMAIN_NODE_BASE_URL_ENV);\n\tconst isNode = providerId === HUMAIN_NODE_PROVIDER;\n\t// Bedrock AWS-credentials logins have no key, so they are an auth.json source: read its region without resolving it.\n\tconst storedConfiguration =\n\t\tproviderId === BEDROCK_PROVIDER_ID ? await runtime.readStoredCredential(providerId, options) : undefined;\n\tconst sourceRegion =\n\t\tstoredConfiguration?.type === \"api_key\" ? envString(storedConfiguration.env, \"AWS_REGION\") : undefined;\n\treturn {\n\t\tproviderId,\n\t\taccounts: accounts.map((account) => {\n\t\t\tconst credential = stored.find((entry) => entry.key === account.key)?.credential;\n\t\t\tconst env = credential?.type === \"api_key\" ? credential.env : undefined;\n\t\t\tconst endpoint = isNode\n\t\t\t\t? describeHumainNodeEndpoint(envString(env, HUMAIN_NODE_BASE_URL_ENV), ambientEndpoint)\n\t\t\t\t: undefined;\n\t\t\tconst region = providerId === \"amazon-bedrock\" ? envString(env, \"AWS_REGION\") : undefined;\n\t\t\treturn { ...account, ...(endpoint ? { endpoint } : {}), ...(region ? { region } : {}) };\n\t\t}),\n\t\tsources: sources.map((source) => {\n\t\t\t// Only the environment source is defined by the ambient base URL; other sources carry no non-secret endpoint.\n\t\t\tconst endpoint =\n\t\t\t\tisNode && source.source === \"environment\"\n\t\t\t\t\t? describeHumainNodeEndpoint(undefined, ambientEndpoint)\n\t\t\t\t\t: undefined;\n\t\t\tif (sourceRegion && source.source === \"auth_json\") return { ...source, region: sourceRegion };\n\t\t\treturn endpoint ? { ...source, endpoint } : source;\n\t\t}),\n\t};\n}\n\nexport const NODE_USAGE_UNSUPPORTED = \"Usage reporting is not yet supported for HUMAIN Node.\";\nexport const BEDROCK_USAGE_NOTE =\n\t\"Usage reporting reads Amazon CloudWatch metrics and needs AWS credentials saved through Connect, with a region. A Bedrock API key cannot report usage.\";\nexport const FLOW_ACCOUNT_PERSISTENCE_NOTICE =\n\t\"Sign-in and account changes take effect immediately and are not undone by cancelling setup.\";\n\n/** Advanced details for the selected provider. Configured and effective never mean verified. */\nexport function formatFlowAccountAdvanced(\n\tproviderId: string,\n\tproviderName: string,\n\tmetadata: FlowProviderAccountMetadata,\n): string[] {\n\tconst lines: string[] = [];\n\tif (metadata.accounts.length === 0 && metadata.sources.length === 0) {\n\t\tlines.push(`No ${providerName} account is configured.`);\n\t}\n\tfor (const account of metadata.accounts) {\n\t\tconst parts = [account.type === \"oauth\" ? \"OAuth\" : \"API key\"];\n\t\tif (account.active) parts.push(\"selected\");\n\t\tconst state = account.effective\n\t\t\t? \"Effective for future requests.\"\n\t\t\t: account.active\n\t\t\t\t? \"An external source still controls requests.\"\n\t\t\t\t: \"Not selected.\";\n\t\tconst place = [\n\t\t\taccount.endpoint ? `Endpoint ${account.endpoint}.` : undefined,\n\t\t\taccount.region ? `Region ${account.region}.` : undefined,\n\t\t].filter(Boolean);\n\t\tlines.push(\n\t\t\t`${account.label} [${account.key}]: ${parts.join(\", \")}. ${state} Configured — not verified. ${place.join(\" \")}`.trim(),\n\t\t);\n\t}\n\tfor (const source of metadata.sources) {\n\t\tconst state = source.effective ? \"Effective for future requests.\" : \"Shadowed by a higher-precedence source.\";\n\t\tlines.push(\n\t\t\t`${source.label} [read-only]: ${state} Configured — not verified.${source.endpoint ? ` Endpoint ${source.endpoint}.` : \"\"}${source.region ? ` Region ${source.region}.` : \"\"}`,\n\t\t);\n\t}\n\tif (providerId === HUMAIN_NODE_PROVIDER) lines.push(NODE_USAGE_UNSUPPORTED);\n\tif (providerId === BEDROCK_PROVIDER_ID) lines.push(BEDROCK_USAGE_NOTE);\n\treturn lines;\n}\n\nconst RETRY_OTHERS = \"Retry, or continue with other providers.\";\n\nconst unavailable = (reason: string): FlowCatalogState => ({ state: \"unavailable\", reason });\n\nfunction nodeFailureReason(error: Error): string {\n\tconst text = `${error.name} ${error.message}`;\n\tif (/\\b(401|403)\\b|invalid_api_key|unauthori|revoked|inactive/iu.test(text)) {\n\t\treturn \"HUMAIN Node rejected the selected key. Check the key, then retry.\";\n\t}\n\tif (/TypeError|TimeoutError|fetch failed|network|ECONN|ENOTFOUND|EAI_AGAIN|timed out/iu.test(text)) {\n\t\treturn \"HUMAIN Node is unreachable. Check the connection, then retry.\";\n\t}\n\t// Raw provider text can carry request details; show only the category.\n\treturn `HUMAIN Node model discovery failed. ${RETRY_OTHERS}`;\n}\n\nasync function selectedKeyFingerprint(runtime: ModelRuntime, providerId: string, signal: AbortSignal): Promise<string> {\n\tconst metadata = await listFlowAccountMetadata(runtime, providerId, signal);\n\tconst selected = metadata.accounts.find((account) => account.active);\n\treturn JSON.stringify([\n\t\tselected?.key,\n\t\tselected?.endpoint,\n\t\tmetadata.sources.filter((source) => source.effective).map((source) => source.label),\n\t]);\n}\n\n/**\n * Wait for the selected key's catalog. HUMAIN Node discovery uses the network, so call this only after an explicit\n * account or catalog action. Anything short of a fresh, non-empty catalog for the same selected key is unavailable;\n * models are never invented or carried over from another key.\n */\nexport async function refreshFlowCatalog(\n\truntime: ModelRuntime,\n\tproviderId: string,\n\tsignal: AbortSignal,\n): Promise<FlowCatalogState> {\n\tconst cancelled = unavailable(\"Model discovery was cancelled. Retry when ready.\");\n\tif (signal.aborted) return cancelled;\n\tconst models = () => runtime.getAvailableSnapshot().filter((model) => model.provider === providerId);\n\tif (providerId !== HUMAIN_NODE_PROVIDER) {\n\t\tconst local = models();\n\t\treturn local.length > 0\n\t\t\t? { state: \"ready\", models: local }\n\t\t\t: unavailable(`No models are available for ${providerId}. Connect the provider, then retry.`);\n\t}\n\ttry {\n\t\tconst before = await selectedKeyFingerprint(runtime, providerId, signal);\n\t\tconst result = await runtime.refresh({ providers: [providerId], allowNetwork: true, force: true, signal });\n\t\tif (signal.aborted || result.aborted) return cancelled;\n\t\t// Check the key first: a late failure from the old key must not be blamed on the newly selected one.\n\t\tif ((await selectedKeyFingerprint(runtime, providerId, signal)) !== before) {\n\t\t\treturn unavailable(\n\t\t\t\t\"The selected HUMAIN Node key changed during discovery. Retry with the key you want to use.\",\n\t\t\t);\n\t\t}\n\t\tconst error = result.errors.get(providerId);\n\t\tif (error) return unavailable(nodeFailureReason(error));\n\t\tif (!runtime.hasConfiguredAuth(providerId)) {\n\t\t\treturn unavailable(\"No HUMAIN Node key is configured. Connect one, then retry.\");\n\t\t}\n\t\tconst discovered = models();\n\t\treturn discovered.length > 0\n\t\t\t? { state: \"ready\", models: discovered }\n\t\t\t: unavailable(`HUMAIN Node returned no models for the selected key. ${RETRY_OTHERS}`);\n\t} catch {\n\t\treturn signal.aborted ? cancelled : unavailable(`HUMAIN Node model discovery failed. ${RETRY_OTHERS}`);\n\t}\n}\n\n/** Secret-free state for the Node fallback setup step. `accounts` lists stored Node API-key accounts in pool order. */\nexport interface FlowNodeFallbackState extends NodeFallbackAssessment {\n\tpolicy: Required<NodeAccountFallbackPolicy>;\n\taccounts: NodeAccountView[];\n}\n\nexport interface FlowNodeFallbackUpdate {\n\tpolicy?: Partial<NodeAccountFallbackPolicy>;\n\t/** Per account key. `null` clears a label. */\n\tlabels?: Record<string, { nodeUser?: string | null; environment?: string | null }>;\n}\n\n/** Read the policy and labels. Uses stored metadata only: no credential resolution, refresh or network access. */\nexport async function readFlowNodeFallbackState(\n\truntime: ModelRuntime,\n\tsignal: AbortSignal,\n\tambientEnv: NodeJS.ProcessEnv = process.env,\n): Promise<FlowNodeFallbackState> {\n\tconst metadata = await listFlowAccountMetadata(runtime, HUMAIN_NODE_PROVIDER, signal, ambientEnv);\n\tconst stored = runtime.nodeAccountMetadata.read();\n\tconst accounts = metadata.accounts\n\t\t.filter((account) => account.type === \"api_key\")\n\t\t.map((account): NodeAccountView => {\n\t\t\tconst labels = Object.hasOwn(stored.accounts, account.key) ? stored.accounts[account.key] : undefined;\n\t\t\treturn {\n\t\t\t\tkey: account.key,\n\t\t\t\talias: account.label,\n\t\t\t\t...(account.endpoint ? { endpoint: account.endpoint } : {}),\n\t\t\t\t...(labels?.nodeUser ? { nodeUser: labels.nodeUser } : {}),\n\t\t\t\t...(labels?.environment ? { environment: labels.environment } : {}),\n\t\t\t\tactive: account.active,\n\t\t\t\tinFallback: stored.policy.accountKeys.includes(account.key),\n\t\t\t};\n\t\t});\n\treturn { policy: stored.policy, accounts, ...assessNodeFallback(accounts, stored.policy) };\n}\n\nconst containsKey = (apiKeys: readonly (string | undefined)[], text: string): boolean =>\n\tapiKeys.some((secret) => secret !== undefined && secret.length > 0 && text.includes(secret));\n\n/** True when `text` would embed a stored Node API key. Stored metadata only: no refresh, no network. */\nexport async function nodeLabelContainsStoredKey(\n\truntime: ModelRuntime,\n\ttext: string,\n\tsignal: AbortSignal,\n): Promise<boolean> {\n\tconst stored = await runtime.oauthAccounts.listAccounts(HUMAIN_NODE_PROVIDER, { signal });\n\treturn containsKey(\n\t\tstored.flatMap((account) => (account.credential.type === \"api_key\" ? [account.credential.key] : [])),\n\t\ttext.trim(),\n\t);\n}\n\nconst INVALID_NODE_LABEL = \"HUMAIN Node labels must be 1 to 80 printable characters and must not contain a key.\";\nconst INVALID_NODE_POLICY_FLAG = \"HUMAIN Node fallback policy flags must be true or false.\";\n\n/**\n * Persist the opt-in fallback policy and user labels. Keys are only referenced by their stored account key; unknown\n * or duplicate keys, oversized or key-bearing labels are rejected before anything is written.\n */\nexport async function updateFlowNodeFallback(\n\truntime: ModelRuntime,\n\tupdate: FlowNodeFallbackUpdate,\n\tsignal: AbortSignal,\n\tambientEnv: NodeJS.ProcessEnv = process.env,\n): Promise<FlowNodeFallbackState> {\n\tsignal.throwIfAborted();\n\tconst stored = await runtime.oauthAccounts.listAccounts(HUMAIN_NODE_PROVIDER, { signal });\n\tconst apiKeys = stored.flatMap((account) => (account.credential.type === \"api_key\" ? [account.credential.key] : []));\n\tconst known = new Set(\n\t\tstored.filter((account) => account.credential.type === \"api_key\").map((account) => account.key),\n\t);\n\tconst accountKeys = update.policy?.accountKeys;\n\tif (accountKeys !== undefined) {\n\t\tif (\n\t\t\t!Array.isArray(accountKeys) ||\n\t\t\taccountKeys.length > MAX_NODE_FALLBACK_KEYS ||\n\t\t\tnew Set(accountKeys).size !== accountKeys.length ||\n\t\t\t!accountKeys.every((key) => known.has(key))\n\t\t) {\n\t\t\tthrow new Error(\"The HUMAIN Node fallback list must name distinct stored Node keys.\");\n\t\t}\n\t}\n\tfor (const flag of [update.policy?.enabled, update.policy?.allowCrossEndpoint]) {\n\t\tif (flag !== undefined && typeof flag !== \"boolean\") throw new Error(INVALID_NODE_POLICY_FLAG);\n\t}\n\tconst labelChanges = Object.entries(update.labels ?? {});\n\tfor (const [key, labels] of labelChanges) {\n\t\tif (!known.has(key)) throw new Error(\"HUMAIN Node labels must name a stored Node key.\");\n\t\tfor (const value of [labels.nodeUser, labels.environment]) {\n\t\t\tif (value === undefined || value === null) continue;\n\t\t\tconst text = value.trim();\n\t\t\tif (!isSafeNodeText(text, MAX_NODE_LABEL_LENGTH) || containsKey(apiKeys, text)) {\n\t\t\t\tthrow new Error(INVALID_NODE_LABEL);\n\t\t\t}\n\t\t}\n\t}\n\tsignal.throwIfAborted();\n\truntime.nodeAccountMetadata.update((current) => {\n\t\tconst accounts = { ...current.accounts };\n\t\tfor (const [key, labels] of labelChanges) {\n\t\t\tconst next: NodeAccountLabels = { ...(Object.hasOwn(accounts, key) ? accounts[key] : {}) };\n\t\t\tfor (const field of [\"nodeUser\", \"environment\"] as const) {\n\t\t\t\tconst value = labels[field];\n\t\t\t\tif (value === null) delete next[field];\n\t\t\t\telse if (value !== undefined) next[field] = value.trim();\n\t\t\t}\n\t\t\taccounts[key] = next;\n\t\t}\n\t\treturn {\n\t\t\tpolicy: {\n\t\t\t\tenabled: update.policy?.enabled ?? current.policy.enabled,\n\t\t\t\taccountKeys: update.policy?.accountKeys ?? current.policy.accountKeys,\n\t\t\t\tallowCrossEndpoint: update.policy?.allowCrossEndpoint ?? current.policy.allowCrossEndpoint,\n\t\t\t},\n\t\t\taccounts,\n\t\t};\n\t});\n\treturn readFlowNodeFallbackState(runtime, signal, ambientEnv);\n}\n\n/** Providers whose Advanced view offers \"Refresh usage\". Node reports its own exact unsupported text instead. */\nexport const FLOW_USAGE_REPORTING_PROVIDERS: ReadonlySet<string> = new Set([\n\tANTHROPIC_PROVIDER_ID,\n\tBEDROCK_PROVIDER_ID,\n\tCODEX_USAGE_PROVIDER_ID,\n]);\n\nexport interface FlowAccountReporterOptions {\n\t/**\n\t * Explicitly provisioned Anthropic Admin API reporting credentials. The host has no supported secure provisioning\n\t * for them today, so this is normally absent and organization reporting reads \"reporting credentials not configured\".\n\t */\n\torganizationCredentials?: AnthropicReportingCredentialProvider;\n\tfetch?: typeof fetch;\n\tnow?: () => number;\n\t/** SDK client factory for Bedrock CloudWatch reporting. Defaults to the official AWS SDK client. */\n\topenBedrockClient?: BedrockReportCollectorDeps[\"openClient\"];\n}\n\n/** Build the session reporter. Nothing is fetched or resolved until `refreshAccountUsage` is called. */\nexport function createFlowAccountReporter(\n\truntime: ModelRuntime,\n\toptions: FlowAccountReporterOptions = {},\n): AccountReporter {\n\treturn new AccountReporter({\n\t\tnow: options.now,\n\t\tcollectors: {\n\t\t\t[CODEX_USAGE_PROVIDER_ID]: createCodexUsageCollector({\n\t\t\t\treadAccount: async (accountKey, signal) =>\n\t\t\t\t\t(await runtime.oauthAccounts.list(CODEX_USAGE_PROVIDER_ID, { signal })).find(\n\t\t\t\t\t\t(account) => account.key === accountKey,\n\t\t\t\t\t),\n\t\t\t\tfetch: options.fetch,\n\t\t\t\tnow: options.now,\n\t\t\t}),\n\t\t\t[ANTHROPIC_PROVIDER_ID]: createAnthropicReportCollector({\n\t\t\t\tstore: runtime.anthropicRateLimits,\n\t\t\t\taccountType: async (accountKey, signal) =>\n\t\t\t\t\t(await runtime.oauthAccounts.listAccounts(ANTHROPIC_PROVIDER_ID, { signal })).find(\n\t\t\t\t\t\t(account) => account.key === accountKey,\n\t\t\t\t\t)?.credential.type,\n\t\t\t\torganizationCredentials: options.organizationCredentials,\n\t\t\t\tfetch: options.fetch,\n\t\t\t\tnow: options.now,\n\t\t\t}),\n\t\t\t[BEDROCK_PROVIDER_ID]: createBedrockReportCollector({\n\t\t\t\tresolveCredentials: async (target, signal) => {\n\t\t\t\t\tconst credential =\n\t\t\t\t\t\ttarget.source === undefined\n\t\t\t\t\t\t\t? (await runtime.oauthAccounts.listAccounts(BEDROCK_PROVIDER_ID, { signal })).find(\n\t\t\t\t\t\t\t\t\t(entry) => entry.key === target.accountKey,\n\t\t\t\t\t\t\t\t)?.credential\n\t\t\t\t\t\t\t: await runtime.readStoredCredential(BEDROCK_PROVIDER_ID, { signal });\n\t\t\t\t\treturn credential ? bedrockReportingCredentials(credential) : undefined;\n\t\t\t\t},\n\t\t\t\topenClient: options.openBedrockClient ?? openCloudWatchMetricsSession,\n\t\t\t\tnow: options.now,\n\t\t\t}),\n\t\t},\n\t});\n}\n\n/** UTC calendar day containing `now`: the reporting period for window-based sources. */\nexport function utcDayPeriod(now: number): AccountReportTarget[\"period\"] {\n\tconst start = new Date(now);\n\tstart.setUTCHours(0, 0, 0, 0);\n\treturn { start: start.toISOString(), end: new Date(start.getTime() + 24 * 60 * 60 * 1000).toISOString() };\n}\n\n/**\n * Targets for \"Refresh usage\" from stored metadata: the selected account (Bedrock: with its stored region), plus\n * Anthropic organization reporting as its own source. `openai` API accounts and every other provider have none: their usage is never inferred.\n */\nexport function flowUsageTargets(\n\tproviderId: string,\n\tmetadata: FlowProviderAccountMetadata,\n\tnow: number,\n): AccountReportTarget[] {\n\tif (!FLOW_USAGE_REPORTING_PROVIDERS.has(providerId)) return [];\n\tconst period = utcDayPeriod(now);\n\tconst selected = metadata.accounts.find((account) => account.active);\n\t// Bedrock figures are regional: the target carries the stored region and nothing else is assumed.\n\tconst targets: AccountReportTarget[] = selected\n\t\t? [{ providerId, accountKey: selected.key, ...(selected.region ? { region: selected.region } : {}), period }]\n\t\t: [];\n\tif (providerId === BEDROCK_PROVIDER_ID) {\n\t\t// Any stored entry without keys, profile or bearer token resolves through the ambient AWS chain, the same as inference.\n\t\tconst stored = metadata.sources.find((source) => source.source === \"auth_json\");\n\t\tif (stored) {\n\t\t\ttargets.push({\n\t\t\t\tproviderId,\n\t\t\t\taccountKey: \"\",\n\t\t\t\tsource: BEDROCK_AWS_CREDENTIALS_SOURCE,\n\t\t\t\t...(stored.region ? { region: stored.region } : {}),\n\t\t\t\tperiod,\n\t\t\t});\n\t\t}\n\t}\n\tif (providerId === ANTHROPIC_PROVIDER_ID) targets.push(anthropicOrganizationTarget(period));\n\treturn targets;\n}\n"]}
1
+ {"version":3,"file":"flow-accounts-host.js","sourceRoot":"","sources":["../../src/humain/flow-accounts-host.ts"],"names":[],"mappings":"AACA,OAAO,EACN,eAAe,EAGf,yBAAyB,GACzB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACN,qBAAqB,EAErB,2BAA2B,EAC3B,8BAA8B,GAC9B,MAAM,wCAAwC,CAAC;AAChD,OAAO,EACN,8BAA8B,EAC9B,mBAAmB,EAEnB,2BAA2B,EAC3B,4BAA4B,EAC5B,4BAA4B,GAC5B,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAIjE,OAAO,EACN,kBAAkB,EAClB,cAAc,EACd,sBAAsB,EACtB,qBAAqB,GAKrB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,0BAA0B,EAAE,wBAAwB,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AA+BhH,MAAM,CAAC,MAAM,yBAAyB,GAAG,iCAAiC,CAAC;AAO3E,MAAM,QAAQ,GAAG,IAAI,OAAO,EAAsC,CAAC;AAEnE,wGAAwG;AACxG,MAAM,UAAU,oB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,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC;QAC7G,CAAC,CAAC,EAAE,CAAC;IACN,IAAI,UAAU,KAAK,mBAAmB,EAAE,CAAC;QACxC,wHAAwH;QACxH,MAAM,MAAM,GAAG,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,KAAK,WAAW,CAAC,CAAC;QAChF,IAAI,MAAM,EAAE,CAAC;YACZ,OAAO,CAAC,IAAI,CAAC;gBACZ,UAAU;gBACV,UAAU,EAAE,EAAE;gBACd,MAAM,EAAE,8BAA8B;gBACtC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBACnD,MAAM;aACN,CAAC,CAAC;QACJ,CAAC;IACF,CAAC;IACD,IAAI,UAAU,KAAK,qBAAqB;QAAE,OAAO,CAAC,IAAI,CAAC,2BAA2B,CAAC,MAAM,CAAC,CAAC,CAAC;IAC5F,OAAO,OAAO,CAAC;AAChB,CAAC","sourcesContent":["import type { Api, Model } from \"@earendil-works/pi-ai\";\nimport {\n\tAccountReporter,\n\ttype AccountReportTarget,\n\ttype AccountUsageReport,\n\tcreateCodexUsageCollector,\n} from \"../core/account-reporting.ts\";\nimport {\n\tANTHROPIC_PROVIDER_ID,\n\ttype AnthropicReportingCredentialProvider,\n\tanthropicOrganizationTarget,\n\tcreateAnthropicReportCollector,\n} from \"../core/anthropic-account-reporting.ts\";\nimport {\n\tBEDROCK_AWS_CREDENTIALS_SOURCE,\n\tBEDROCK_PROVIDER_ID,\n\ttype BedrockReportCollectorDeps,\n\tbedrockReportingCredentials,\n\tcreateBedrockReportCollector,\n\topenCloudWatchMetricsSession,\n} from \"../core/bedrock-account-reporting.ts\";\nimport { CODEX_USAGE_PROVIDER_ID } from \"../core/codex-usage.ts\";\nimport type { ExtensionContext } from \"../core/extensions/types.ts\";\nimport type { ModelRegistry } from \"../core/model-registry.ts\";\nimport type { AccountInfo, AccountSource, ModelRuntime } from \"../core/model-runtime.ts\";\nimport {\n\tassessNodeFallback,\n\tisSafeNodeText,\n\tMAX_NODE_FALLBACK_KEYS,\n\tMAX_NODE_LABEL_LENGTH,\n\ttype NodeAccountFallbackPolicy,\n\ttype NodeAccountLabels,\n\ttype NodeAccountView,\n\ttype NodeFallbackAssessment,\n} from \"./node-account-fallback.ts\";\nimport { describeHumainNodeEndpoint, HUMAIN_NODE_BASE_URL_ENV, HUMAIN_NODE_PROVIDER } from \"./node-provider.ts\";\n\n/**\n * Session-bound bridge that lets Flow drive host-owned account dialogs and catalog readiness.\n * Credentials never cross it: every value is non-secret metadata or a model catalog.\n */\nexport type FlowCatalogState =\n\t| { state: \"ready\"; models: readonly Model<Api>[] }\n\t| { state: \"unavailable\"; reason: string };\n\nexport interface FlowAccountsHost {\n\t/**\n\t * Resolves after the user finishes or cancels the account interaction. Cancelling through the signal ends the\n\t * dialog; sign-ins, account switches and removals already completed stay in effect.\n\t */\n\topenAccounts(signal: AbortSignal): Promise<void>;\n\t/** Explicit action: refresh the provider's catalog for the selected account, allowing network access. */\n\trefreshCatalog(providerId: string, signal: AbortSignal): Promise<FlowCatalogState>;\n\t/**\n\t * Explicit \"Refresh usage\" action. The only path that reaches a reporting transport; listing accounts and opening\n\t * Advanced never call it. Resolves to a labelled report and never throws for unavailable data.\n\t */\n\trefreshAccountUsage(target: AccountReportTarget, signal: AbortSignal): Promise<AccountUsageReport>;\n\t/** Opt-in HUMAIN Node key fallback: current policy, aliases, labels and setup warnings. No network. */\n\tgetNodeFallback(signal: AbortSignal): Promise<FlowNodeFallbackState>;\n\t/** Validate and persist policy and labels outside the credential store, then return the new state. */\n\tupdateNodeFallback(update: FlowNodeFallbackUpdate, signal: AbortSignal): Promise<FlowNodeFallbackState>;\n\t/** Whether `text` contains a stored HUMAIN Node key. Only the answer crosses the bridge, never a key. */\n\tlabelContainsStoredKey(text: string, signal: AbortSignal): Promise<boolean>;\n}\n\nexport const FLOW_ACCOUNTS_UNAVAILABLE = \"Account interaction unavailable\";\n\ninterface FlowAccountsBinding {\n\thandle: FlowAccountsHost;\n\trelease: () => void;\n}\n\nconst bindings = new WeakMap<ModelRegistry, FlowAccountsBinding>();\n\n/** Bind a host to the registry of the current session. Rebinding supersedes the previous generation. */\nexport function bindFlowAccountsHost(registry: ModelRegistry, host: FlowAccountsHost): () => void {\n\tbindings.get(registry)?.release();\n\tconst generation = new AbortController();\n\tconst run = async <T>(signal: AbortSignal, operation: (signal: AbortSignal) => Promise<T>): Promise<T> => {\n\t\tif (generation.signal.aborted) throw new Error(FLOW_ACCOUNTS_UNAVAILABLE);\n\t\ttry {\n\t\t\tconst result = await operation(AbortSignal.any([signal, generation.signal]));\n\t\t\tif (generation.signal.aborted) throw new Error(FLOW_ACCOUNTS_UNAVAILABLE);\n\t\t\treturn result;\n\t\t} catch (error) {\n\t\t\tif (generation.signal.aborted) throw new Error(FLOW_ACCOUNTS_UNAVAILABLE);\n\t\t\tthrow error;\n\t\t}\n\t};\n\tconst binding: FlowAccountsBinding = {\n\t\thandle: {\n\t\t\topenAccounts: (signal) => run(signal, (combined) => host.openAccounts(combined)),\n\t\t\trefreshCatalog: (providerId, signal) => run(signal, (combined) => host.refreshCatalog(providerId, combined)),\n\t\t\trefreshAccountUsage: (target, signal) => run(signal, (combined) => host.refreshAccountUsage(target, combined)),\n\t\t\tgetNodeFallback: (signal) => run(signal, (combined) => host.getNodeFallback(combined)),\n\t\t\tupdateNodeFallback: (update, signal) => run(signal, (combined) => host.updateNodeFallback(update, combined)),\n\t\t\tlabelContainsStoredKey: (text, signal) =>\n\t\t\t\trun(signal, (combined) => host.labelContainsStoredKey(text, combined)),\n\t\t},\n\t\trelease: () => {\n\t\t\tgeneration.abort();\n\t\t\tif (bindings.get(registry) === binding) bindings.delete(registry);\n\t\t},\n\t};\n\tbindings.set(registry, binding);\n\treturn binding.release;\n}\n\n/** Look up the host by actual registry identity. Only the terminal UI owns secure dialogs. */\nexport function getFlowAccountsHost(\n\tctx: Pick<ExtensionContext, \"modelRegistry\" | \"mode\">,\n): FlowAccountsHost | undefined {\n\treturn ctx.mode === \"tui\" ? bindings.get(ctx.modelRegistry)?.handle : undefined;\n}\n\n/** Secret-free account metadata. `endpoint` is the HUMAIN Node base URL; `region` the stored Bedrock region. */\nexport interface FlowAccountMetadata extends AccountInfo {\n\tendpoint?: string;\n\tregion?: string;\n}\n\nexport interface FlowAccountSourceMetadata extends AccountSource {\n\tendpoint?: string;\n\t/** Stored Bedrock region of the auth.json provider configuration. */\n\tregion?: string;\n}\n\nexport interface FlowProviderAccountMetadata {\n\tproviderId: string;\n\taccounts: FlowAccountMetadata[];\n\tsources: FlowAccountSourceMetadata[];\n}\n\nfunction envString(env: Record<string, unknown> | undefined, name: string): string | undefined {\n\tconst value = env?.[name];\n\treturn typeof value === \"string\" ? value : undefined;\n}\n\n/**\n * Enumerate accounts and sources from stored metadata only. This never resolves credentials, refreshes OAuth,\n * runs credential commands, or touches the network; `accounts.list/sources` are side-effect-free by contract.\n */\nexport async function listFlowAccountMetadata(\n\truntime: ModelRuntime,\n\tproviderId: string,\n\tsignal: AbortSignal,\n\tambientEnv: NodeJS.ProcessEnv = process.env,\n): Promise<FlowProviderAccountMetadata> {\n\tconst options = { signal };\n\tconst accounts = await runtime.accounts.list(providerId, options);\n\tconst sources = await runtime.accounts.sources(providerId, options);\n\tconst stored = await runtime.oauthAccounts.listAccounts(providerId, options);\n\tconst ambientEndpoint = envString(ambientEnv, HUMAIN_NODE_BASE_URL_ENV);\n\tconst isNode = providerId === HUMAIN_NODE_PROVIDER;\n\t// Bedrock AWS-credentials logins have no key, so they are an auth.json source: read its region without resolving it.\n\tconst storedConfiguration =\n\t\tproviderId === BEDROCK_PROVIDER_ID ? await runtime.readStoredCredential(providerId, options) : undefined;\n\tconst sourceRegion =\n\t\tstoredConfiguration?.type === \"api_key\" ? envString(storedConfiguration.env, \"AWS_REGION\") : undefined;\n\treturn {\n\t\tproviderId,\n\t\taccounts: accounts.map((account) => {\n\t\t\tconst credential = stored.find((entry) => entry.key === account.key)?.credential;\n\t\t\tconst env = credential?.type === \"api_key\" ? credential.env : undefined;\n\t\t\tconst endpoint = isNode\n\t\t\t\t? describeHumainNodeEndpoint(envString(env, HUMAIN_NODE_BASE_URL_ENV), ambientEndpoint)\n\t\t\t\t: undefined;\n\t\t\tconst region = providerId === \"amazon-bedrock\" ? envString(env, \"AWS_REGION\") : undefined;\n\t\t\treturn { ...account, ...(endpoint ? { endpoint } : {}), ...(region ? { region } : {}) };\n\t\t}),\n\t\tsources: sources.map((source) => {\n\t\t\t// Only the environment source is defined by the ambient base URL; other sources carry no non-secret endpoint.\n\t\t\tconst endpoint =\n\t\t\t\tisNode && source.source === \"environment\"\n\t\t\t\t\t? describeHumainNodeEndpoint(undefined, ambientEndpoint)\n\t\t\t\t\t: undefined;\n\t\t\tif (sourceRegion && source.source === \"auth_json\") return { ...source, region: sourceRegion };\n\t\t\treturn endpoint ? { ...source, endpoint } : source;\n\t\t}),\n\t};\n}\n\nexport const NODE_USAGE_UNSUPPORTED = \"Usage reporting is not yet supported for HUMAIN Node.\";\nexport const BEDROCK_USAGE_NOTE =\n\t\"Usage reporting reads Amazon CloudWatch metrics and needs AWS credentials saved through Connect, with a region. A Bedrock API key cannot report usage.\";\nexport const FLOW_ACCOUNT_PERSISTENCE_NOTICE =\n\t\"Sign-in and account changes take effect immediately and are not undone by cancelling setup.\";\n\n/** Advanced details for the selected provider. Configured and effective never mean verified. */\nexport function formatFlowAccountAdvanced(\n\tproviderId: string,\n\tproviderName: string,\n\tmetadata: FlowProviderAccountMetadata,\n): string[] {\n\tconst lines: string[] = [];\n\tif (metadata.accounts.length === 0 && metadata.sources.length === 0) {\n\t\tlines.push(`No ${providerName} account is configured.`);\n\t}\n\tfor (const account of metadata.accounts) {\n\t\tconst parts = [account.type === \"oauth\" ? \"OAuth\" : \"API key\"];\n\t\tif (account.active) parts.push(\"selected\");\n\t\tconst state = account.effective\n\t\t\t? \"Effective for future requests.\"\n\t\t\t: account.active\n\t\t\t\t? \"An external source still controls requests.\"\n\t\t\t\t: \"Not selected.\";\n\t\tconst cooldown = new Date(account.exhaustedUntil ?? Number.NaN);\n\t\tconst place = [\n\t\t\tcooldown.getTime() > Date.now() ? `cached local cooldown until ${cooldown.toISOString()}.` : undefined,\n\t\t\taccount.endpoint ? `Endpoint ${account.endpoint}.` : undefined,\n\t\t\taccount.region ? `Region ${account.region}.` : undefined,\n\t\t].filter(Boolean);\n\t\tlines.push(\n\t\t\t`${account.label} [${account.key}]: ${parts.join(\", \")}. ${state} Configured — not verified. ${place.join(\" \")}`.trim(),\n\t\t);\n\t}\n\tfor (const source of metadata.sources) {\n\t\tconst state = source.effective ? \"Effective for future requests.\" : \"Shadowed by a higher-precedence source.\";\n\t\tlines.push(\n\t\t\t`${source.label} [read-only]: ${state} Configured — not verified.${source.endpoint ? ` Endpoint ${source.endpoint}.` : \"\"}${source.region ? ` Region ${source.region}.` : \"\"}`,\n\t\t);\n\t}\n\tif (providerId === HUMAIN_NODE_PROVIDER) lines.push(NODE_USAGE_UNSUPPORTED);\n\tif (providerId === BEDROCK_PROVIDER_ID) lines.push(BEDROCK_USAGE_NOTE);\n\treturn lines;\n}\n\nconst RETRY_OTHERS = \"Retry, or continue with other providers.\";\n\nconst unavailable = (reason: string): FlowCatalogState => ({ state: \"unavailable\", reason });\n\nfunction nodeFailureReason(error: Error): string {\n\tconst text = `${error.name} ${error.message}`;\n\tif (/\\b(401|403)\\b|invalid_api_key|unauthori|revoked|inactive/iu.test(text)) {\n\t\treturn \"HUMAIN Node rejected the selected key. Check the key, then retry.\";\n\t}\n\tif (/TypeError|TimeoutError|fetch failed|network|ECONN|ENOTFOUND|EAI_AGAIN|timed out/iu.test(text)) {\n\t\treturn \"HUMAIN Node is unreachable. Check the connection, then retry.\";\n\t}\n\t// Raw provider text can carry request details; show only the category.\n\treturn `HUMAIN Node model discovery failed. ${RETRY_OTHERS}`;\n}\n\nasync function selectedKeyFingerprint(runtime: ModelRuntime, providerId: string, signal: AbortSignal): Promise<string> {\n\tconst metadata = await listFlowAccountMetadata(runtime, providerId, signal);\n\tconst selected = metadata.accounts.find((account) => account.active);\n\treturn JSON.stringify([\n\t\tselected?.key,\n\t\tselected?.endpoint,\n\t\tmetadata.sources.filter((source) => source.effective).map((source) => source.label),\n\t]);\n}\n\n/**\n * Wait for the selected key's catalog. HUMAIN Node discovery uses the network, so call this only after an explicit\n * account or catalog action. Anything short of a fresh, non-empty catalog for the same selected key is unavailable;\n * models are never invented or carried over from another key.\n */\nexport async function refreshFlowCatalog(\n\truntime: ModelRuntime,\n\tproviderId: string,\n\tsignal: AbortSignal,\n): Promise<FlowCatalogState> {\n\tconst cancelled = unavailable(\"Model discovery was cancelled. Retry when ready.\");\n\tif (signal.aborted) return cancelled;\n\tconst models = () => runtime.getAvailableSnapshot().filter((model) => model.provider === providerId);\n\tif (providerId !== HUMAIN_NODE_PROVIDER) {\n\t\tconst local = models();\n\t\treturn local.length > 0\n\t\t\t? { state: \"ready\", models: local }\n\t\t\t: unavailable(`No models are available for ${providerId}. Connect the provider, then retry.`);\n\t}\n\ttry {\n\t\tconst before = await selectedKeyFingerprint(runtime, providerId, signal);\n\t\tconst result = await runtime.refresh({ providers: [providerId], allowNetwork: true, force: true, signal });\n\t\tif (signal.aborted || result.aborted) return cancelled;\n\t\t// Check the key first: a late failure from the old key must not be blamed on the newly selected one.\n\t\tif ((await selectedKeyFingerprint(runtime, providerId, signal)) !== before) {\n\t\t\treturn unavailable(\n\t\t\t\t\"The selected HUMAIN Node key changed during discovery. Retry with the key you want to use.\",\n\t\t\t);\n\t\t}\n\t\tconst error = result.errors.get(providerId);\n\t\tif (error) return unavailable(nodeFailureReason(error));\n\t\tif (!runtime.hasConfiguredAuth(providerId)) {\n\t\t\treturn unavailable(\"No HUMAIN Node key is configured. Connect one, then retry.\");\n\t\t}\n\t\tconst discovered = models();\n\t\treturn discovered.length > 0\n\t\t\t? { state: \"ready\", models: discovered }\n\t\t\t: unavailable(`HUMAIN Node returned no models for the selected key. ${RETRY_OTHERS}`);\n\t} catch {\n\t\treturn signal.aborted ? cancelled : unavailable(`HUMAIN Node model discovery failed. ${RETRY_OTHERS}`);\n\t}\n}\n\n/** Secret-free state for the Node fallback setup step. `accounts` lists stored Node API-key accounts in pool order. */\nexport interface FlowNodeFallbackState extends NodeFallbackAssessment {\n\tpolicy: Required<NodeAccountFallbackPolicy>;\n\taccounts: NodeAccountView[];\n}\n\nexport interface FlowNodeFallbackUpdate {\n\tpolicy?: Partial<NodeAccountFallbackPolicy>;\n\t/** Per account key. `null` clears a label. */\n\tlabels?: Record<string, { nodeUser?: string | null; environment?: string | null }>;\n}\n\n/** Read the policy and labels. Uses stored metadata only: no credential resolution, refresh or network access. */\nexport async function readFlowNodeFallbackState(\n\truntime: ModelRuntime,\n\tsignal: AbortSignal,\n\tambientEnv: NodeJS.ProcessEnv = process.env,\n): Promise<FlowNodeFallbackState> {\n\tconst metadata = await listFlowAccountMetadata(runtime, HUMAIN_NODE_PROVIDER, signal, ambientEnv);\n\tconst stored = runtime.nodeAccountMetadata.read();\n\tconst accounts = metadata.accounts\n\t\t.filter((account) => account.type === \"api_key\")\n\t\t.map((account): NodeAccountView => {\n\t\t\tconst labels = Object.hasOwn(stored.accounts, account.key) ? stored.accounts[account.key] : undefined;\n\t\t\treturn {\n\t\t\t\tkey: account.key,\n\t\t\t\talias: account.label,\n\t\t\t\t...(account.endpoint ? { endpoint: account.endpoint } : {}),\n\t\t\t\t...(labels?.nodeUser ? { nodeUser: labels.nodeUser } : {}),\n\t\t\t\t...(labels?.environment ? { environment: labels.environment } : {}),\n\t\t\t\tactive: account.active,\n\t\t\t\tinFallback: stored.policy.accountKeys.includes(account.key),\n\t\t\t};\n\t\t});\n\treturn { policy: stored.policy, accounts, ...assessNodeFallback(accounts, stored.policy) };\n}\n\nconst containsKey = (apiKeys: readonly (string | undefined)[], text: string): boolean =>\n\tapiKeys.some((secret) => secret !== undefined && secret.length > 0 && text.includes(secret));\n\n/** True when `text` would embed a stored Node API key. Stored metadata only: no refresh, no network. */\nexport async function nodeLabelContainsStoredKey(\n\truntime: ModelRuntime,\n\ttext: string,\n\tsignal: AbortSignal,\n): Promise<boolean> {\n\tconst stored = await runtime.oauthAccounts.listAccounts(HUMAIN_NODE_PROVIDER, { signal });\n\treturn containsKey(\n\t\tstored.flatMap((account) => (account.credential.type === \"api_key\" ? [account.credential.key] : [])),\n\t\ttext.trim(),\n\t);\n}\n\nconst INVALID_NODE_LABEL = \"HUMAIN Node labels must be 1 to 80 printable characters and must not contain a key.\";\nconst INVALID_NODE_POLICY_FLAG = \"HUMAIN Node fallback policy flags must be true or false.\";\n\n/**\n * Persist the opt-in fallback policy and user labels. Keys are only referenced by their stored account key; unknown\n * or duplicate keys, oversized or key-bearing labels are rejected before anything is written.\n */\nexport async function updateFlowNodeFallback(\n\truntime: ModelRuntime,\n\tupdate: FlowNodeFallbackUpdate,\n\tsignal: AbortSignal,\n\tambientEnv: NodeJS.ProcessEnv = process.env,\n): Promise<FlowNodeFallbackState> {\n\tsignal.throwIfAborted();\n\tconst stored = await runtime.oauthAccounts.listAccounts(HUMAIN_NODE_PROVIDER, { signal });\n\tconst apiKeys = stored.flatMap((account) => (account.credential.type === \"api_key\" ? [account.credential.key] : []));\n\tconst known = new Set(\n\t\tstored.filter((account) => account.credential.type === \"api_key\").map((account) => account.key),\n\t);\n\tconst accountKeys = update.policy?.accountKeys;\n\tif (accountKeys !== undefined) {\n\t\tif (\n\t\t\t!Array.isArray(accountKeys) ||\n\t\t\taccountKeys.length > MAX_NODE_FALLBACK_KEYS ||\n\t\t\tnew Set(accountKeys).size !== accountKeys.length ||\n\t\t\t!accountKeys.every((key) => known.has(key))\n\t\t) {\n\t\t\tthrow new Error(\"The HUMAIN Node fallback list must name distinct stored Node keys.\");\n\t\t}\n\t}\n\tfor (const flag of [update.policy?.enabled, update.policy?.allowCrossEndpoint]) {\n\t\tif (flag !== undefined && typeof flag !== \"boolean\") throw new Error(INVALID_NODE_POLICY_FLAG);\n\t}\n\tconst labelChanges = Object.entries(update.labels ?? {});\n\tfor (const [key, labels] of labelChanges) {\n\t\tif (!known.has(key)) throw new Error(\"HUMAIN Node labels must name a stored Node key.\");\n\t\tfor (const value of [labels.nodeUser, labels.environment]) {\n\t\t\tif (value === undefined || value === null) continue;\n\t\t\tconst text = value.trim();\n\t\t\tif (!isSafeNodeText(text, MAX_NODE_LABEL_LENGTH) || containsKey(apiKeys, text)) {\n\t\t\t\tthrow new Error(INVALID_NODE_LABEL);\n\t\t\t}\n\t\t}\n\t}\n\tsignal.throwIfAborted();\n\truntime.nodeAccountMetadata.update((current) => {\n\t\tconst accounts = { ...current.accounts };\n\t\tfor (const [key, labels] of labelChanges) {\n\t\t\tconst next: NodeAccountLabels = { ...(Object.hasOwn(accounts, key) ? accounts[key] : {}) };\n\t\t\tfor (const field of [\"nodeUser\", \"environment\"] as const) {\n\t\t\t\tconst value = labels[field];\n\t\t\t\tif (value === null) delete next[field];\n\t\t\t\telse if (value !== undefined) next[field] = value.trim();\n\t\t\t}\n\t\t\taccounts[key] = next;\n\t\t}\n\t\treturn {\n\t\t\tpolicy: {\n\t\t\t\tenabled: update.policy?.enabled ?? current.policy.enabled,\n\t\t\t\taccountKeys: update.policy?.accountKeys ?? current.policy.accountKeys,\n\t\t\t\tallowCrossEndpoint: update.policy?.allowCrossEndpoint ?? current.policy.allowCrossEndpoint,\n\t\t\t},\n\t\t\taccounts,\n\t\t};\n\t});\n\treturn readFlowNodeFallbackState(runtime, signal, ambientEnv);\n}\n\n/** Providers whose Advanced view offers \"Refresh usage\". Node reports its own exact unsupported text instead. */\nexport const FLOW_USAGE_REPORTING_PROVIDERS: ReadonlySet<string> = new Set([\n\tANTHROPIC_PROVIDER_ID,\n\tBEDROCK_PROVIDER_ID,\n\tCODEX_USAGE_PROVIDER_ID,\n]);\n\nexport interface FlowAccountReporterOptions {\n\t/**\n\t * Explicitly provisioned Anthropic Admin API reporting credentials. The host has no supported secure provisioning\n\t * for them today, so this is normally absent and organization reporting reads \"reporting credentials not configured\".\n\t */\n\torganizationCredentials?: AnthropicReportingCredentialProvider;\n\tfetch?: typeof fetch;\n\tnow?: () => number;\n\t/** SDK client factory for Bedrock CloudWatch reporting. Defaults to the official AWS SDK client. */\n\topenBedrockClient?: BedrockReportCollectorDeps[\"openClient\"];\n}\n\n/** Build the session reporter. Nothing is fetched or resolved until `refreshAccountUsage` is called. */\nexport function createFlowAccountReporter(\n\truntime: ModelRuntime,\n\toptions: FlowAccountReporterOptions = {},\n): AccountReporter {\n\treturn new AccountReporter({\n\t\tnow: options.now,\n\t\tcollectors: {\n\t\t\t[CODEX_USAGE_PROVIDER_ID]: createCodexUsageCollector({\n\t\t\t\treadAccount: async (accountKey, signal) =>\n\t\t\t\t\t(await runtime.oauthAccounts.list(CODEX_USAGE_PROVIDER_ID, { signal })).find(\n\t\t\t\t\t\t(account) => account.key === accountKey,\n\t\t\t\t\t),\n\t\t\t\tfetch: options.fetch,\n\t\t\t\taccountPool: runtime.oauthAccounts,\n\t\t\t\tnow: options.now,\n\t\t\t}),\n\t\t\t[ANTHROPIC_PROVIDER_ID]: createAnthropicReportCollector({\n\t\t\t\tstore: runtime.anthropicRateLimits,\n\t\t\t\taccountType: async (accountKey, signal) =>\n\t\t\t\t\t(await runtime.oauthAccounts.listAccounts(ANTHROPIC_PROVIDER_ID, { signal })).find(\n\t\t\t\t\t\t(account) => account.key === accountKey,\n\t\t\t\t\t)?.credential.type,\n\t\t\t\torganizationCredentials: options.organizationCredentials,\n\t\t\t\tfetch: options.fetch,\n\t\t\t\tnow: options.now,\n\t\t\t}),\n\t\t\t[BEDROCK_PROVIDER_ID]: createBedrockReportCollector({\n\t\t\t\tresolveCredentials: async (target, signal) => {\n\t\t\t\t\tconst credential =\n\t\t\t\t\t\ttarget.source === undefined\n\t\t\t\t\t\t\t? (await runtime.oauthAccounts.listAccounts(BEDROCK_PROVIDER_ID, { signal })).find(\n\t\t\t\t\t\t\t\t\t(entry) => entry.key === target.accountKey,\n\t\t\t\t\t\t\t\t)?.credential\n\t\t\t\t\t\t\t: await runtime.readStoredCredential(BEDROCK_PROVIDER_ID, { signal });\n\t\t\t\t\treturn credential ? bedrockReportingCredentials(credential) : undefined;\n\t\t\t\t},\n\t\t\t\topenClient: options.openBedrockClient ?? openCloudWatchMetricsSession,\n\t\t\t\tnow: options.now,\n\t\t\t}),\n\t\t},\n\t});\n}\n\n/** UTC calendar day containing `now`: the reporting period for window-based sources. */\nexport function utcDayPeriod(now: number): AccountReportTarget[\"period\"] {\n\tconst start = new Date(now);\n\tstart.setUTCHours(0, 0, 0, 0);\n\treturn { start: start.toISOString(), end: new Date(start.getTime() + 24 * 60 * 60 * 1000).toISOString() };\n}\n\n/**\n * Targets for \"Refresh usage\" from stored metadata: the selected account (Bedrock: with its stored region), plus\n * Anthropic organization reporting as its own source. `openai` API accounts and every other provider have none: their usage is never inferred.\n */\nexport function flowUsageTargets(\n\tproviderId: string,\n\tmetadata: FlowProviderAccountMetadata,\n\tnow: number,\n): AccountReportTarget[] {\n\tif (!FLOW_USAGE_REPORTING_PROVIDERS.has(providerId)) return [];\n\tconst period = utcDayPeriod(now);\n\tconst selected = metadata.accounts.find((account) => account.active);\n\t// Bedrock figures are regional: the target carries the stored region and nothing else is assumed.\n\tconst targets: AccountReportTarget[] = selected\n\t\t? [{ providerId, accountKey: selected.key, ...(selected.region ? { region: selected.region } : {}), period }]\n\t\t: [];\n\tif (providerId === BEDROCK_PROVIDER_ID) {\n\t\t// Any stored entry without keys, profile or bearer token resolves through the ambient AWS chain, the same as inference.\n\t\tconst stored = metadata.sources.find((source) => source.source === \"auth_json\");\n\t\tif (stored) {\n\t\t\ttargets.push({\n\t\t\t\tproviderId,\n\t\t\t\taccountKey: \"\",\n\t\t\t\tsource: BEDROCK_AWS_CREDENTIALS_SOURCE,\n\t\t\t\t...(stored.region ? { region: stored.region } : {}),\n\t\t\t\tperiod,\n\t\t\t});\n\t\t}\n\t}\n\tif (providerId === ANTHROPIC_PROVIDER_ID) targets.push(anthropicOrganizationTarget(period));\n\treturn targets;\n}\n"]}
@@ -3,7 +3,7 @@ import type { AutocompleteItem } from "@earendil-works/pi-tui";
3
3
  * Static vocabulary, parsing, help and completion for the single `/flow` command. Pure and dependency-light on
4
4
  * purpose: the lazy loader uses it before (and without) importing Flow, so help works when Flow is disabled.
5
5
  */
6
- export declare const FLOW_SUBCOMMANDS: readonly ["help", "run", "continue", "list", "status", "cancel", "pause", "resume", "title", "message", "hide", "show", "models", "profile", "setup"];
6
+ export declare const FLOW_SUBCOMMANDS: readonly ["help", "run", "continue", "fix", "list", "status", "cancel", "pause", "resume", "title", "message", "hide", "show", "models", "profile", "setup"];
7
7
  export type FlowSubcommand = (typeof FLOW_SUBCOMMANDS)[number];
8
8
  /** Refusal for `/flow setup` outside the terminal UI: secure account dialogs exist only there. */
9
9
  export declare const FLOW_SETUP_TERMINAL_ONLY = "/flow setup needs the interactive terminal. Use /flow models and /flow profile for changes from other modes.";
@@ -1 +1 @@
1
- {"version":3,"file":"flow-command.d.ts","sourceRoot":"","sources":["../../src/humain/flow-command.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAG/D;;;GAGG;AAEH,eAAO,MAAM,gBAAgB,YAC5B,MAAM,EACN,KAAK,EACL,UAAU,EACV,MAAM,EACN,QAAQ,EACR,QAAQ,EACR,OAAO,EACP,QAAQ,EACR,OAAO,EACP,SAAS,EACT,MAAM,EACN,MAAM,EACN,QAAQ,EACR,SAAS,EACT,OAAO,CACE,CAAC;AAEX,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,CAAC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cAAc,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,cAAc,CAAA;CAAE,CA8B5F;AAyFD,mHAAmH;AACnH,wBAAgB,cAAc,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAOrD;AAED,8GAA8G;AAC9G,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,gBAAgB,EAAE,GAAG,IAAI,CAyB/E"}
@@ -7,6 +7,7 @@ export const FLOW_SUBCOMMANDS = [
7
7
  "help",
8
8
  "run",
9
9
  "continue",
10
+ "fix",
10
11
  "list",
11
12
  "status",
12
13
  "cancel",
@@ -37,6 +38,7 @@ const SUMMARIES = {
37
38
  help: "Show usage and examples",
38
39
  run: "Start work",
39
40
  continue: "Recover an interrupted run",
41
+ fix: "Fix failing checks of a verified-after run",
40
42
  list: "Find recent runs and run IDs",
41
43
  status: "View progress",
42
44
  cancel: "Stop the active run",
@@ -98,6 +100,9 @@ export function parseFlowCommand(args) {
98
100
  if (NO_ARGUMENT_SUBCOMMANDS.has(name) && trimmed) {
99
101
  return { error: `/flow ${name} does not accept arguments. Usage: /flow ${name}` };
100
102
  }
103
+ if (name === "fix" && /\s/.test(trimmed)) {
104
+ return { error: "/flow fix accepts at most one run ID. Usage: /flow fix [run-id]", command: name };
105
+ }
101
106
  if (name === "continue" && /\s/.test(trimmed)) {
102
107
  // `command` lets the loader settle the refused start over rpc.
103
108
  return { error: "/flow continue accepts at most one run ID. Usage: /flow continue [run-id]", command: name };
@@ -118,6 +123,7 @@ const GENERAL_HELP = [
118
123
  helpRow("/flow pause", "pause"),
119
124
  helpRow("/flow resume", "resume"),
120
125
  helpRow("/flow continue [run-id]", "continue"),
126
+ helpRow("/flow fix [run-id]", "fix"),
121
127
  helpRow("/flow title <title>", "title"),
122
128
  helpRow("/flow message <text>", "message"),
123
129
  helpRow("/flow hide", "hide"),
@@ -140,7 +146,7 @@ const RUN_FLAGS = [
140
146
  " --profile ID --lead-size small|standard|large --workflow direct|checked|led|full --effort LEVEL",
141
147
  " --cheap ALIAS --mid ALIAS --premium ALIAS --frontier ALIAS --model <capability>=ALIAS",
142
148
  " --quality-floor F --cost-aggressiveness C --max-retries R --fan-out",
143
- " --context FILE ... --with-last-reply --force --route-only --candidate PATH",
149
+ " --context FILE ... --with-last-reply --force --route-only --candidate PATH --verify-after",
144
150
  " --live-qa --no-live-qa --live-qa-adapter ID --live-qa-scope SCOPE --live-qa-acceptance FILE",
145
151
  ].join("\n");
146
152
  const TOPIC_HELP = {
@@ -159,6 +165,7 @@ const TOPIC_HELP = {
159
165
  "",
160
166
  RUN_FLAGS,
161
167
  ].join("\n"),
168
+ fix: "Fix the failing checks of a run started with --verify-after\n\nUsage:\n /flow fix [run-id]\n\nStarts a new run from that run's local failing-check report. Default: the last such run in this session.",
162
169
  continue: "Recover an interrupted run\n\nUsage:\n /flow continue [run-id]\n\nRecovery requires a safety check and your confirmation.",
163
170
  list: [
164
171
  "Find recent runs and run IDs",
@@ -1 +1 @@
1
- {"version":3,"file":"flow-command.js","sourceRoot":"","sources":["../../src/humain/flow-command.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAEvE;;;GAGG;AAEH,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC/B,MAAM;IACN,KAAK;IACL,UAAU;IACV,MAAM;IACN,QAAQ;IACR,QAAQ;IACR,OAAO;IACP,QAAQ;IACR,OAAO;IACP,SAAS;IACT,MAAM;IACN,MAAM;IACN,QAAQ;IACR,SAAS;IACT,OAAO;CACE,CAAC;AAIX,kGAAkG;AAClG,MAAM,CAAC,MAAM,wBAAwB,GACpC,8GAA8G,CAAC;AAEhH,uCAAuC;AACvC,MAAM,uBAAuB,GAAgC,IAAI,GAAG,CAAC;IACpE,MAAM;IACN,QAAQ;IACR,QAAQ;IACR,OAAO;IACP,QAAQ;IACR,MA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E,IAAI,EAAE,CAAC,CAAC;QAC3F,CAAC;IACF,CAAC;IACD,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;AACxC,CAAC","sourcesContent":["import type { AutocompleteItem } from \"@earendil-works/pi-tui\";\nimport { sanitizeForTerminal } from \"../core/trace-client/sanitize.ts\";\n\n/**\n * Static vocabulary, parsing, help and completion for the single `/flow` command. Pure and dependency-light on\n * purpose: the lazy loader uses it before (and without) importing Flow, so help works when Flow is disabled.\n */\n\nexport const FLOW_SUBCOMMANDS = [\n\t\"help\",\n\t\"run\",\n\t\"continue\",\n\t\"list\",\n\t\"status\",\n\t\"cancel\",\n\t\"pause\",\n\t\"resume\",\n\t\"title\",\n\t\"message\",\n\t\"hide\",\n\t\"show\",\n\t\"models\",\n\t\"profile\",\n\t\"setup\",\n] as const;\n\nexport type FlowSubcommand = (typeof FLOW_SUBCOMMANDS)[number];\n\n/** Refusal for `/flow setup` outside the terminal UI: secure account dialogs exist only there. */\nexport const FLOW_SETUP_TERMINAL_ONLY =\n\t\"/flow setup needs the interactive terminal. Use /flow models and /flow profile for changes from other modes.\";\n\n/** Commands that take no arguments. */\nconst NO_ARGUMENT_SUBCOMMANDS: ReadonlySet<FlowSubcommand> = new Set([\n\t\"list\",\n\t\"status\",\n\t\"cancel\",\n\t\"pause\",\n\t\"resume\",\n\t\"hide\",\n\t\"show\",\n\t\"setup\",\n]);\n\nconst SUMMARIES: Record<FlowSubcommand, string> = {\n\thelp: \"Show usage and examples\",\n\trun: \"Start work\",\n\tcontinue: \"Recover an interrupted run\",\n\tlist: \"Find recent runs and run IDs\",\n\tstatus: \"View progress\",\n\tcancel: \"Stop the active run\",\n\tpause: \"Pause new work\",\n\tresume: \"Resume paused work\",\n\ttitle: \"Rename the active run\",\n\tmessage: \"Send guidance\",\n\thide: \"Hide the widget; work continues\",\n\tshow: \"Show the active run's widget\",\n\tmodels: \"Manage model choices\",\n\tprofile: \"Manage run profiles\",\n\tsetup: \"Connect providers and configure Flow\",\n};\n\nconst MODELS_SUBCOMMANDS = [\n\t\"show\",\n\t\"list\",\n\t\"validate\",\n\t\"check\",\n\t\"set\",\n\t\"effort\",\n\t\"use\",\n\t\"new\",\n\t\"pick\",\n\t\"convert\",\n\t\"workflow\",\n];\nconst PROFILE_SUBCOMMANDS = [\"list\", \"show\", \"use\", \"export\", \"import\", \"validate\"];\n\nconst isSubcommand = (value: string): value is FlowSubcommand =>\n\t(FLOW_SUBCOMMANDS as readonly string[]).includes(value);\n\n/** Copy for a recognized subcommand this build does not implement yet. */\nexport function flowBuildUnavailable(command: string): string {\n\treturn `/flow ${sanitizeForTerminal(command)} is not available in this build. Use /flow help to see supported commands.`;\n}\n\n/**\n * Splits `/flow` arguments into subcommand and payload. Consumes the subcommand and exactly one separating\n * whitespace character; the rest of the payload is returned byte-for-byte so goal, message and title text is\n * never split or rejoined. Bare or whitespace-only input means help.\n */\nexport function parseFlowCommand(\n\targs: string,\n): { command: FlowSubcommand; payload: string } | { error: string; command?: FlowSubcommand } {\n\tconst match = /^\\s*(\\S+)([\\s\\S]*)$/.exec(args);\n\tif (!match) return { command: \"help\", payload: \"\" };\n\tconst [, name, rest] = match;\n\tif (!isSubcommand(name)) {\n\t\treturn {\n\t\t\terror: `Unknown Flow command: ${sanitizeForTerminal(name).slice(0, 80)}. Use /flow help to see available commands. To start work: /flow run <goal>`,\n\t\t};\n\t}\n\tconst payload = /^\\s/.test(rest) ? rest.slice(1) : rest;\n\tconst trimmed = payload.trim();\n\tif (name === \"help\" && trimmed) {\n\t\tif (/\\s/.test(trimmed)) return { error: \"/flow help accepts at most one topic. Usage: /flow help [topic]\" };\n\t\tif (!isSubcommand(trimmed)) {\n\t\t\treturn {\n\t\t\t\terror: `No help topic named “${sanitizeForTerminal(trimmed).slice(0, 80)}”. Use /flow help to see available commands.`,\n\t\t\t};\n\t\t}\n\t}\n\tif (NO_ARGUMENT_SUBCOMMANDS.has(name) && trimmed) {\n\t\treturn { error: `/flow ${name} does not accept arguments. Usage: /flow ${name}` };\n\t}\n\tif (name === \"continue\" && /\\s/.test(trimmed)) {\n\t\t// `command` lets the loader settle the refused start over rpc.\n\t\treturn { error: \"/flow continue accepts at most one run ID. Usage: /flow continue [run-id]\", command: name };\n\t}\n\treturn { command: name, payload };\n}\n\nconst helpRow = (usage: string, command: FlowSubcommand) => `${` ${usage}`.padEnd(27)}${SUMMARIES[command]}`;\n\nconst GENERAL_HELP = [\n\t\"Flow — plan, run, and verify work with agents.\",\n\t\"\",\n\t\"Start work\",\n\t\" /flow run <goal> [flags]\",\n\t\"\",\n\t\"Manage a run\",\n\thelpRow(\"/flow list\", \"list\"),\n\thelpRow(\"/flow status\", \"status\"),\n\thelpRow(\"/flow cancel\", \"cancel\"),\n\thelpRow(\"/flow pause\", \"pause\"),\n\thelpRow(\"/flow resume\", \"resume\"),\n\thelpRow(\"/flow continue [run-id]\", \"continue\"),\n\thelpRow(\"/flow title <title>\", \"title\"),\n\thelpRow(\"/flow message <text>\", \"message\"),\n\thelpRow(\"/flow hide\", \"hide\"),\n\thelpRow(\"/flow show\", \"show\"),\n\t\"\",\n\t\"Configure\",\n\thelpRow(\"/flow setup\", \"setup\"),\n\thelpRow(\"/flow models <command>\", \"models\"),\n\thelpRow(\"/flow profile <command>\", \"profile\"),\n\t\"\",\n\t\"Learn more\",\n\t\" /flow help <command> Show usage and examples\",\n\t\"\",\n\t\"Example\",\n\t\" /flow run Fix the login timeout --risk medium\",\n].join(\"\\n\");\n\nconst RUN_FLAGS = [\n\t\"Flags:\",\n\t\" --task-class T --complexity N --risk low|medium|high|critical\",\n\t\" --profile ID --lead-size small|standard|large --workflow direct|checked|led|full --effort LEVEL\",\n\t\" --cheap ALIAS --mid ALIAS --premium ALIAS --frontier ALIAS --model <capability>=ALIAS\",\n\t\" --quality-floor F --cost-aggressiveness C --max-retries R --fan-out\",\n\t\" --context FILE ... --with-last-reply --force --route-only --candidate PATH\",\n\t\" --live-qa --no-live-qa --live-qa-adapter ID --live-qa-scope SCOPE --live-qa-acceptance FILE\",\n].join(\"\\n\");\n\nconst TOPIC_HELP: Record<FlowSubcommand, string> = {\n\thelp: \"Show help\\n\\nUsage:\\n /flow help [command]\",\n\trun: [\n\t\t\"Start a Flow run\",\n\t\t\"\",\n\t\t\"Usage:\",\n\t\t\" /flow run <goal> [flags]\",\n\t\t\"\",\n\t\t\"Example:\",\n\t\t\" /flow run Fix the login timeout --risk medium\",\n\t\t\"\",\n\t\t\"Describe the outcome you want. Flow plans the work,\",\n\t\t\"dispatches agents, and verifies the result.\",\n\t\t\"\",\n\t\tRUN_FLAGS,\n\t].join(\"\\n\"),\n\tcontinue:\n\t\t\"Recover an interrupted run\\n\\nUsage:\\n /flow continue [run-id]\\n\\nRecovery requires a safety check and your confirmation.\",\n\tlist: [\n\t\t\"Find recent runs and run IDs\",\n\t\t\"\",\n\t\t\"Usage:\",\n\t\t\" /flow list\",\n\t\t\"\",\n\t\t\"History examines up to 200 runs by creation time.\",\n\t\t\"Runs without readable execution snapshots are omitted.\",\n\t\t\"Listing does not recover a run or claim ownership.\",\n\t].join(\"\\n\"),\n\tstatus: \"View progress of the active run\\n\\nUsage:\\n /flow status\",\n\tcancel: \"Stop the active run\\n\\nUsage:\\n /flow cancel\",\n\tpause: \"Pause new work. Running agents finish their current turn. No new agents will start.\\n\\nUsage:\\n /flow pause\",\n\tresume: \"Resume paused work\\n\\nUsage:\\n /flow resume\",\n\ttitle: \"Rename the active run\\n\\nUsage:\\n /flow title <title>\",\n\tmessage:\n\t\t\"Send guidance to the running lead. It is held until the lead starts if none is running yet, and sent to the host as a follow-up when no Flow is running.\\n\\nUsage:\\n /flow message <text>\\n\\nUse \\\\n for newlines.\",\n\thide: \"Hide the widget; work continues. Only the current widget is hidden; a new run shows it again. Bring it back with /flow show.\\n\\nUsage:\\n /flow hide\",\n\tshow: \"Show the active run's widget, or the retained final result of the last run until a new run starts.\\n\\nUsage:\\n /flow show\",\n\tmodels: `Flow models\\n\\nView or change the models Flow uses.\\nChanges apply to future runs. Runs already started keep their settings.\\nFlow switches models after a failure only to fallbacks you list.\\nWith no fallbacks configured, Flow will not switch models automatically.\\n\\nUsage:\\n /flow models [${MODELS_SUBCOMMANDS.join(\"|\")}]\\n\\nView current choices:\\n /flow models show`,\n\tprofile: `Flow profiles\\n\\nView and manage saved run settings.\\nChanges apply to future runs. Runs already started keep their settings.\\n\\nUsage:\\n /flow profile [${PROFILE_SUBCOMMANDS.join(\"|\")}]\\n\\nList profiles:\\n /flow profile list`,\n\t// The account sentence must equal FLOW_ACCOUNT_PERSISTENCE_NOTICE; humain-flow-command.test.ts enforces it.\n\tsetup: `Connect providers and configure Flow\\n\\nTerminal only. Use /flow models and /flow profile from other modes.\\nProfile edits remain unsaved until Save. Sign-in and account changes take effect immediately and are not undone by cancelling setup.\\n\\nUsage:\\n /flow setup`,\n};\n\n/** Static help text. An unrecognized topic yields the unknown-topic copy; the parser rejects those before this. */\nexport function renderFlowHelp(topic?: string): string {\n\tconst name = topic?.trim();\n\tif (!name) return GENERAL_HELP;\n\tif (!isSubcommand(name)) {\n\t\treturn `No help topic named “${sanitizeForTerminal(name).slice(0, 80)}”. Use /flow help to see available commands.`;\n\t}\n\treturn TOPIC_HELP[name];\n}\n\n/** Static completion for the argument text after `/flow `: subcommands, then help topics and nested names. */\nexport function completeFlowArguments(prefix: string): AutocompleteItem[] | null {\n\tconst words = prefix.trimStart().split(/\\s+/);\n\tconst [first = \"\", second] = words;\n\tconst items: AutocompleteItem[] = [];\n\tif (words.length === 1) {\n\t\tfor (const command of FLOW_SUBCOMMANDS) {\n\t\t\tif (command.startsWith(first)) {\n\t\t\t\titems.push({\n\t\t\t\t\tvalue: command,\n\t\t\t\t\tlabel: command,\n\t\t\t\t\tdescription: SUMMARIES[command],\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t} else if (words.length === 2 && first === \"help\") {\n\t\tfor (const command of FLOW_SUBCOMMANDS) {\n\t\t\tif (command.startsWith(second ?? \"\"))\n\t\t\t\titems.push({ value: `help ${command}`, label: command, description: SUMMARIES[command] });\n\t\t}\n\t} else if (words.length === 2 && (first === \"models\" || first === \"profile\")) {\n\t\tfor (const name of first === \"models\" ? MODELS_SUBCOMMANDS : PROFILE_SUBCOMMANDS) {\n\t\t\tif (name.startsWith(second ?? \"\")) items.push({ value: `${first} ${name}`, label: name });\n\t\t}\n\t}\n\treturn items.length > 0 ? items : null;\n}\n"]}
1
+ {"version":3,"file":"flow-command.js","sourceRoot":"","sources":["../../src/humain/flow-command.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAEvE;;;GAGG;AAEH,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC/B,MAAM;IACN,KAAK;IACL,UAAU;IACV,KAAK;IACL,MAAM;IACN,QAAQ;IACR,QAAQ;IACR,OAAO;IACP,QAAQ;IACR,OAAO;IACP,SAAS;IACT,MAAM;IACN,MAAM;IACN,QAAQ;IACR,SAAS;IACT,OAAO;CACE,CAAC;AAIX,kGAAkG;AAClG,MAAM,CAAC,MAAM,wBAAwB,GACpC,8GAA8G,CAAC;AAEhH,uCAAuC;AACvC,MAAM,uBAAuB,GAAgC,IAAI,GAAG,CAAC;IACpE,MAAM;IACN,QAAQ;IACR,QAAQ;IACR,OAAO;IACP,QAAQ;IACR,MAAM;IACN,MAAM;IACN,OAAO;CACP,CAAC,CAAC;AAEH,MAAM,SAAS,GAAmC;IACjD,IAAI,EAAE,yBAAyB;IAC/B,GAAG,EAAE,YAAY;IACjB,QAAQ,EAAE,4BAA4B;IACtC,GAAG,EAAE,4CAA4C;IACjD,IAAI,EAAE,8BAA8B;IACpC,MAAM,EAAE,eAAe;IACvB,MAAM,EAAE,qBAAqB;IAC7B,KAAK,EAAE,gBAAgB;IACvB,MAAM,EAAE,oBAAoB;IAC5B,KAAK,EAAE,uBAAuB;IAC9B,OAAO,EAAE,eAAe;IACxB,IAA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CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;AACxC,CAAC","sourcesContent":["import type { AutocompleteItem } from \"@earendil-works/pi-tui\";\nimport { sanitizeForTerminal } from \"../core/trace-client/sanitize.ts\";\n\n/**\n * Static vocabulary, parsing, help and completion for the single `/flow` command. Pure and dependency-light on\n * purpose: the lazy loader uses it before (and without) importing Flow, so help works when Flow is disabled.\n */\n\nexport const FLOW_SUBCOMMANDS = [\n\t\"help\",\n\t\"run\",\n\t\"continue\",\n\t\"fix\",\n\t\"list\",\n\t\"status\",\n\t\"cancel\",\n\t\"pause\",\n\t\"resume\",\n\t\"title\",\n\t\"message\",\n\t\"hide\",\n\t\"show\",\n\t\"models\",\n\t\"profile\",\n\t\"setup\",\n] as const;\n\nexport type FlowSubcommand = (typeof FLOW_SUBCOMMANDS)[number];\n\n/** Refusal for `/flow setup` outside the terminal UI: secure account dialogs exist only there. */\nexport const FLOW_SETUP_TERMINAL_ONLY =\n\t\"/flow setup needs the interactive terminal. Use /flow models and /flow profile for changes from other modes.\";\n\n/** Commands that take no arguments. */\nconst NO_ARGUMENT_SUBCOMMANDS: ReadonlySet<FlowSubcommand> = new Set([\n\t\"list\",\n\t\"status\",\n\t\"cancel\",\n\t\"pause\",\n\t\"resume\",\n\t\"hide\",\n\t\"show\",\n\t\"setup\",\n]);\n\nconst SUMMARIES: Record<FlowSubcommand, string> = {\n\thelp: \"Show usage and examples\",\n\trun: \"Start work\",\n\tcontinue: \"Recover an interrupted run\",\n\tfix: \"Fix failing checks of a verified-after run\",\n\tlist: \"Find recent runs and run IDs\",\n\tstatus: \"View progress\",\n\tcancel: \"Stop the active run\",\n\tpause: \"Pause new work\",\n\tresume: \"Resume paused work\",\n\ttitle: \"Rename the active run\",\n\tmessage: \"Send guidance\",\n\thide: \"Hide the widget; work continues\",\n\tshow: \"Show the active run's widget\",\n\tmodels: \"Manage model choices\",\n\tprofile: \"Manage run profiles\",\n\tsetup: \"Connect providers and configure Flow\",\n};\n\nconst MODELS_SUBCOMMANDS = [\n\t\"show\",\n\t\"list\",\n\t\"validate\",\n\t\"check\",\n\t\"set\",\n\t\"effort\",\n\t\"use\",\n\t\"new\",\n\t\"pick\",\n\t\"convert\",\n\t\"workflow\",\n];\nconst PROFILE_SUBCOMMANDS = [\"list\", \"show\", \"use\", \"export\", \"import\", \"validate\"];\n\nconst isSubcommand = (value: string): value is FlowSubcommand =>\n\t(FLOW_SUBCOMMANDS as readonly string[]).includes(value);\n\n/** Copy for a recognized subcommand this build does not implement yet. */\nexport function flowBuildUnavailable(command: string): string {\n\treturn `/flow ${sanitizeForTerminal(command)} is not available in this build. Use /flow help to see supported commands.`;\n}\n\n/**\n * Splits `/flow` arguments into subcommand and payload. Consumes the subcommand and exactly one separating\n * whitespace character; the rest of the payload is returned byte-for-byte so goal, message and title text is\n * never split or rejoined. Bare or whitespace-only input means help.\n */\nexport function parseFlowCommand(\n\targs: string,\n): { command: FlowSubcommand; payload: string } | { error: string; command?: FlowSubcommand } {\n\tconst match = /^\\s*(\\S+)([\\s\\S]*)$/.exec(args);\n\tif (!match) return { command: \"help\", payload: \"\" };\n\tconst [, name, rest] = match;\n\tif (!isSubcommand(name)) {\n\t\treturn {\n\t\t\terror: `Unknown Flow command: ${sanitizeForTerminal(name).slice(0, 80)}. Use /flow help to see available commands. To start work: /flow run <goal>`,\n\t\t};\n\t}\n\tconst payload = /^\\s/.test(rest) ? rest.slice(1) : rest;\n\tconst trimmed = payload.trim();\n\tif (name === \"help\" && trimmed) {\n\t\tif (/\\s/.test(trimmed)) return { error: \"/flow help accepts at most one topic. Usage: /flow help [topic]\" };\n\t\tif (!isSubcommand(trimmed)) {\n\t\t\treturn {\n\t\t\t\terror: `No help topic named “${sanitizeForTerminal(trimmed).slice(0, 80)}”. Use /flow help to see available commands.`,\n\t\t\t};\n\t\t}\n\t}\n\tif (NO_ARGUMENT_SUBCOMMANDS.has(name) && trimmed) {\n\t\treturn { error: `/flow ${name} does not accept arguments. Usage: /flow ${name}` };\n\t}\n\tif (name === \"fix\" && /\\s/.test(trimmed)) {\n\t\treturn { error: \"/flow fix accepts at most one run ID. Usage: /flow fix [run-id]\", command: name };\n\t}\n\tif (name === \"continue\" && /\\s/.test(trimmed)) {\n\t\t// `command` lets the loader settle the refused start over rpc.\n\t\treturn { error: \"/flow continue accepts at most one run ID. Usage: /flow continue [run-id]\", command: name };\n\t}\n\treturn { command: name, payload };\n}\n\nconst helpRow = (usage: string, command: FlowSubcommand) => `${` ${usage}`.padEnd(27)}${SUMMARIES[command]}`;\n\nconst GENERAL_HELP = [\n\t\"Flow — plan, run, and verify work with agents.\",\n\t\"\",\n\t\"Start work\",\n\t\" /flow run <goal> [flags]\",\n\t\"\",\n\t\"Manage a run\",\n\thelpRow(\"/flow list\", \"list\"),\n\thelpRow(\"/flow status\", \"status\"),\n\thelpRow(\"/flow cancel\", \"cancel\"),\n\thelpRow(\"/flow pause\", \"pause\"),\n\thelpRow(\"/flow resume\", \"resume\"),\n\thelpRow(\"/flow continue [run-id]\", \"continue\"),\n\thelpRow(\"/flow fix [run-id]\", \"fix\"),\n\thelpRow(\"/flow title <title>\", \"title\"),\n\thelpRow(\"/flow message <text>\", \"message\"),\n\thelpRow(\"/flow hide\", \"hide\"),\n\thelpRow(\"/flow show\", \"show\"),\n\t\"\",\n\t\"Configure\",\n\thelpRow(\"/flow setup\", \"setup\"),\n\thelpRow(\"/flow models <command>\", \"models\"),\n\thelpRow(\"/flow profile <command>\", \"profile\"),\n\t\"\",\n\t\"Learn more\",\n\t\" /flow help <command> Show usage and examples\",\n\t\"\",\n\t\"Example\",\n\t\" /flow run Fix the login timeout --risk medium\",\n].join(\"\\n\");\n\nconst RUN_FLAGS = [\n\t\"Flags:\",\n\t\" --task-class T --complexity N --risk low|medium|high|critical\",\n\t\" --profile ID --lead-size small|standard|large --workflow direct|checked|led|full --effort LEVEL\",\n\t\" --cheap ALIAS --mid ALIAS --premium ALIAS --frontier ALIAS --model <capability>=ALIAS\",\n\t\" --quality-floor F --cost-aggressiveness C --max-retries R --fan-out\",\n\t\" --context FILE ... --with-last-reply --force --route-only --candidate PATH --verify-after\",\n\t\" --live-qa --no-live-qa --live-qa-adapter ID --live-qa-scope SCOPE --live-qa-acceptance FILE\",\n].join(\"\\n\");\n\nconst TOPIC_HELP: Record<FlowSubcommand, string> = {\n\thelp: \"Show help\\n\\nUsage:\\n /flow help [command]\",\n\trun: [\n\t\t\"Start a Flow run\",\n\t\t\"\",\n\t\t\"Usage:\",\n\t\t\" /flow run <goal> [flags]\",\n\t\t\"\",\n\t\t\"Example:\",\n\t\t\" /flow run Fix the login timeout --risk medium\",\n\t\t\"\",\n\t\t\"Describe the outcome you want. Flow plans the work,\",\n\t\t\"dispatches agents, and verifies the result.\",\n\t\t\"\",\n\t\tRUN_FLAGS,\n\t].join(\"\\n\"),\n\tfix: \"Fix the failing checks of a run started with --verify-after\\n\\nUsage:\\n /flow fix [run-id]\\n\\nStarts a new run from that run's local failing-check report. Default: the last such run in this session.\",\n\tcontinue:\n\t\t\"Recover an interrupted run\\n\\nUsage:\\n /flow continue [run-id]\\n\\nRecovery requires a safety check and your confirmation.\",\n\tlist: [\n\t\t\"Find recent runs and run IDs\",\n\t\t\"\",\n\t\t\"Usage:\",\n\t\t\" /flow list\",\n\t\t\"\",\n\t\t\"History examines up to 200 runs by creation time.\",\n\t\t\"Runs without readable execution snapshots are omitted.\",\n\t\t\"Listing does not recover a run or claim ownership.\",\n\t].join(\"\\n\"),\n\tstatus: \"View progress of the active run\\n\\nUsage:\\n /flow status\",\n\tcancel: \"Stop the active run\\n\\nUsage:\\n /flow cancel\",\n\tpause: \"Pause new work. Running agents finish their current turn. No new agents will start.\\n\\nUsage:\\n /flow pause\",\n\tresume: \"Resume paused work\\n\\nUsage:\\n /flow resume\",\n\ttitle: \"Rename the active run\\n\\nUsage:\\n /flow title <title>\",\n\tmessage:\n\t\t\"Send guidance to the running lead. It is held until the lead starts if none is running yet, and sent to the host as a follow-up when no Flow is running.\\n\\nUsage:\\n /flow message <text>\\n\\nUse \\\\n for newlines.\",\n\thide: \"Hide the widget; work continues. Only the current widget is hidden; a new run shows it again. Bring it back with /flow show.\\n\\nUsage:\\n /flow hide\",\n\tshow: \"Show the active run's widget, or the retained final result of the last run until a new run starts.\\n\\nUsage:\\n /flow show\",\n\tmodels: `Flow models\\n\\nView or change the models Flow uses.\\nChanges apply to future runs. Runs already started keep their settings.\\nFlow switches models after a failure only to fallbacks you list.\\nWith no fallbacks configured, Flow will not switch models automatically.\\n\\nUsage:\\n /flow models [${MODELS_SUBCOMMANDS.join(\"|\")}]\\n\\nView current choices:\\n /flow models show`,\n\tprofile: `Flow profiles\\n\\nView and manage saved run settings.\\nChanges apply to future runs. Runs already started keep their settings.\\n\\nUsage:\\n /flow profile [${PROFILE_SUBCOMMANDS.join(\"|\")}]\\n\\nList profiles:\\n /flow profile list`,\n\t// The account sentence must equal FLOW_ACCOUNT_PERSISTENCE_NOTICE; humain-flow-command.test.ts enforces it.\n\tsetup: `Connect providers and configure Flow\\n\\nTerminal only. Use /flow models and /flow profile from other modes.\\nProfile edits remain unsaved until Save. Sign-in and account changes take effect immediately and are not undone by cancelling setup.\\n\\nUsage:\\n /flow setup`,\n};\n\n/** Static help text. An unrecognized topic yields the unknown-topic copy; the parser rejects those before this. */\nexport function renderFlowHelp(topic?: string): string {\n\tconst name = topic?.trim();\n\tif (!name) return GENERAL_HELP;\n\tif (!isSubcommand(name)) {\n\t\treturn `No help topic named “${sanitizeForTerminal(name).slice(0, 80)}”. Use /flow help to see available commands.`;\n\t}\n\treturn TOPIC_HELP[name];\n}\n\n/** Static completion for the argument text after `/flow `: subcommands, then help topics and nested names. */\nexport function completeFlowArguments(prefix: string): AutocompleteItem[] | null {\n\tconst words = prefix.trimStart().split(/\\s+/);\n\tconst [first = \"\", second] = words;\n\tconst items: AutocompleteItem[] = [];\n\tif (words.length === 1) {\n\t\tfor (const command of FLOW_SUBCOMMANDS) {\n\t\t\tif (command.startsWith(first)) {\n\t\t\t\titems.push({\n\t\t\t\t\tvalue: command,\n\t\t\t\t\tlabel: command,\n\t\t\t\t\tdescription: SUMMARIES[command],\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t} else if (words.length === 2 && first === \"help\") {\n\t\tfor (const command of FLOW_SUBCOMMANDS) {\n\t\t\tif (command.startsWith(second ?? \"\"))\n\t\t\t\titems.push({ value: `help ${command}`, label: command, description: SUMMARIES[command] });\n\t\t}\n\t} else if (words.length === 2 && (first === \"models\" || first === \"profile\")) {\n\t\tfor (const name of first === \"models\" ? MODELS_SUBCOMMANDS : PROFILE_SUBCOMMANDS) {\n\t\t\tif (name.startsWith(second ?? \"\")) items.push({ value: `${first} ${name}`, label: name });\n\t\t}\n\t}\n\treturn items.length > 0 ? items : null;\n}\n"]}
@@ -96,7 +96,7 @@ const NO_LOADED_RUN_COPY = {
96
96
  show: "No current Flow widget to show.",
97
97
  };
98
98
  /** Only these start (or recover) work, so only their refusals settle an rpc run. */
99
- const START_COMMANDS = new Set(["run", "continue"]);
99
+ const START_COMMANDS = new Set(["run", "continue", "fix"]);
100
100
  function isRecord(value) {
101
101
  return typeof value === "object" && value !== null;
102
102
  }
@@ -1 +1 @@
1
- {"version":3,"file":"flow-loader.js","sourceRoot":"","sources":["../../src/humain/flow-loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAG/D,OAAO,EAAE,WAAW,EAAE,wBAAwB,EAAE,yBAAyB,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAOvH,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AACvE,OAAO,E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AC,CAAC;AACH,CAAC","sourcesContent":["import { createHash, randomBytes } from \"node:crypto\";\nimport { readFileSync } from \"node:fs\";\nimport { dirname, isAbsolute, join, resolve } from \"node:path\";\nimport type { FlowFailureClass } from \"@humain/humain-code-contracts/flow-common\";\nimport type { FlowEventFrameV1, FlowReceiptV1, FlowStatusV1 } from \"@humain/humain-code-contracts/flow-control\";\nimport { getAgentDir, getBundledFlowPackageDir, getBundledFlowProfilesDir, PACKAGE_NAME, VERSION } from \"../config.ts\";\nimport type {\n\tExtensionAPI,\n\tExtensionCommandContext,\n\tExtensionFactory,\n\tRegisteredCommand,\n} from \"../core/extensions/types.ts\";\nimport { createTraceRedactor } from \"../core/trace/redaction.ts\";\nimport { sanitizeForTerminal } from \"../core/trace-client/sanitize.ts\";\nimport {\n\tcompleteFlowArguments,\n\tFLOW_SETUP_TERMINAL_ONLY,\n\ttype FlowSubcommand,\n\tflowBuildUnavailable,\n\tparseFlowCommand,\n\trenderFlowHelp,\n} from \"./flow-command.ts\";\n\n/**\n * Lazy loader for the private @humain/flow package.\n *\n * The CLI entry graph must not statically reach Flow: this module registers one cheap `/flow` stub and two flags, and\n * only loads Flow (one memoized dynamic import) the first time a subcommand needs it. Help, completion, unknown\n * commands and not-yet-available commands are answered statically and never import Flow. Flow is bundled as its own\n * chunk.\n */\n\nexport const HUMAIN_FLOW_DISABLED_ENV = \"HUMAIN_TERMINAL_FLOW_DISABLED\";\nexport const HUMAIN_FLOW_PACKAGE_DIR_ENV = \"HUMAIN_TERMINAL_FLOW_PACKAGE_DIR\";\n\n/** Run-control surface Flow exposes to rpc mode (flow_status/pause/resume/cancel/message). */\nexport interface FlowRpcControl {\n\thandle(input: unknown): Promise<{ receipt: FlowReceiptV1; status?: FlowStatusV1 }>;\n\tactiveRunId(): string | undefined;\n}\n\nexport interface FlowModule {\n\tflowExtension: ExtensionFactory;\n\t/** Documented rpc hook: called once when Flow loads; `writeFrame` carries `flow_event` frames to the rpc host. */\n\tcreateFlowRpcControl?(options: {\n\t\twriteFrame?: (frame: FlowEventFrameV1) => void | Promise<void>;\n\t\tisDisabled?: () => boolean;\n\t\t/** Queues text on the host session as a follow-up (flow_message with no active run). */\n\t\tsendFollowUp?: (text: string) => Promise<void>;\n\t}): FlowRpcControl;\n\t/** B1 profile command; optional so test fakes need not provide it. Methods stay bivariant for the real signatures. */\n\trunFlowProfileCommand?(args: string, ctx: ExtensionCommandContext, deps: { store: unknown }): Promise<unknown>;\n\tcreateProfileStore?(options: { flowDir: string; builtInDir?: string }): unknown;\n}\n\nexport interface HumainFlowLoaderOptions {\n\t/** Test seam. Defaults to the single sanctioned dynamic import of @humain/flow. */\n\timportFlow?: () => Promise<FlowModule>;\n\tenv?: NodeJS.ProcessEnv;\n\t/** Directory holding Flow's agents/assets/package.json. Defaults to the bundled layout's flow/ dir. */\n\tflowPackageDir?: string;\n\t/** Built-in Flow profiles dir. Defaults to the bundled layout's assets/profiles; undefined lets Flow find its own. */\n\tbuiltInProfilesDir?: string;\n\t/** Flow profile store directory. Defaults to `<agentDir>/flow`. */\n\tflowDir?: string;\n}\n\nlet rpcControl: FlowRpcControl | undefined;\nlet disabledProbe: (() => boolean) | undefined;\nlet rpcOutput: ((frame: FlowEventFrameV1) => void | Promise<void>) | undefined;\nlet rpcLoader: (() => Promise<FlowRpcControl | undefined>) | undefined;\nlet rpcFollowUp: ((text: string) => Promise<void>) | undefined;\n\n/** The documented rpc hook: rpc mode reads Flow's run control here and never imports Flow itself. */\nexport function getFlowRpcControl(): FlowRpcControl | undefined {\n\treturn rpcControl;\n}\n\n/**\n * The documented rpc hook: loads Flow through the same lazy-load path the stub commands use and returns its run control.\n * Undefined when Flow is disabled (never loaded then), not wired, or fails to load.\n */\nexport async function loadFlowRpcControl(): Promise<FlowRpcControl | undefined> {\n\tif (rpcControl) return rpcControl;\n\tif (isFlowDisabled()) return undefined;\n\treturn rpcLoader?.();\n}\n\n/** True while Flow is switched off (flow.enabled=false or the env kill switch); rpc mode refuses flow_resume then. */\nexport function isFlowDisabled(): boolean {\n\treturn disabledProbe?.() ?? false;\n}\n\n/** The documented rpc hook: rpc mode registers where Flow's `flow_event` frames are written. */\nexport function setFlowRpcOutput(writer: ((frame: FlowEventFrameV1) => void | Promise<void>) | undefined): void {\n\trpcOutput = writer;\n}\n\n/** The documented rpc hook: rpc mode registers how direct-mode flow_message text is queued as a host follow-up. */\nexport function setFlowRpcFollowUp(queue: ((text: string) => Promise<void>) | undefined): void {\n\trpcFollowUp = queue;\n}\n\ntype CommandOptions = Omit<RegisteredCommand, \"name\" | \"sourceInfo\">;\ntype EventHandler = (...args: unknown[]) => unknown;\n\n/**\n * ExtensionAPI members that only record registrations (see core/extensions/loader.ts). They are staged while Flow's\n * factory runs and applied to the real pi only after the factory and the session_start replay succeed. Reads and\n * actions (getFlag, getSettings, exec, sendMessage, ...) and `events` stay live: they have no registration to undo\n * or are needed by the factory itself. Flow uses none of the live ones that subscribe (`events.on`).\n */\nconst STAGED_MEMBERS = new Set([\n\t\"on\",\n\t\"registerTool\",\n\t\"registerCommand\",\n\t\"registerShortcut\",\n\t\"registerFlag\",\n\t\"registerMessageRenderer\",\n\t\"registerMarkdownTransformer\",\n\t\"registerEntryRenderer\",\n\t\"registerProvider\",\n\t\"unregisterProvider\",\n\t\"registerMcpServer\",\n\t\"unregisterMcpServer\",\n\t\"registerVirtualModel\",\n\t\"unregisterVirtualModel\",\n]);\n\ninterface StagedCall {\n\tmember: string;\n\targs: unknown[];\n\tcancelled: boolean;\n\tunsubscribe?: () => void;\n}\n\nconst FLOW_DESCRIPTION =\n\t\"Plan, run, and verify work with agents. Subcommands: run, continue, list, status, cancel, pause, resume, \" +\n\t\"title, message, hide, show, models, profile, setup. Use /flow help for usage.\";\n\n/**\n * Act on an already loaded run only; with Flow not loaded there is no run, so Flow is never imported for them. They\n * stay reachable when Flow is disabled so a live run can still be stopped. Every other subcommand is refused when\n * disabled.\n */\nconst LOADED_RUN_COMMANDS: ReadonlySet<FlowSubcommand> = new Set([\n\t\"cancel\",\n\t\"status\",\n\t\"pause\",\n\t\"resume\",\n\t\"hide\",\n\t\"show\",\n]);\n/** Kill switch: resume would restart dispatch, so it is refused while Flow is disabled (the others are not). */\nconst AVAILABLE_WHEN_DISABLED: ReadonlySet<FlowSubcommand> = new Set([\"cancel\", \"status\", \"pause\", \"hide\", \"show\"]);\n/** Copy when a loaded-run command finds no Flow loaded, so there is nothing to act on. */\nconst NO_LOADED_RUN_COPY: Partial<Record<FlowSubcommand, string>> = {\n\tcancel: \"No active Flow run to stop.\",\n\tstatus: \"No active Flow run. Start one with /flow run <goal>.\",\n\tpause: \"No active Flow run to pause.\",\n\tresume: \"No paused Flow run to resume.\",\n\thide: \"No current Flow widget to hide.\",\n\tshow: \"No current Flow widget to show.\",\n};\n/** Only these start (or recover) work, so only their refusals settle an rpc run. */\nconst START_COMMANDS: ReadonlySet<FlowSubcommand> = new Set([\"run\", \"continue\"]);\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null;\n}\n\n/**\n * Print/json mode has no UI: core makes ctx.ui.notify a no-op, so headless notices go to stderr as bare text.\n * Notice text can echo user args or env values, so it is redacted, stripped of terminal escapes, then redacted again\n * with the same redactor: the first pass catches secrets that stripping could otherwise mangle, the second catches\n * secrets that were split by escapes and are rejoined by stripping. Fails closed to a fixed line on any failure.\n * Replacing `ui` snapshots ui (descriptors preserve other ctx getters, so lazy getters on ctx stay live; same approach\n * as the runner's createCommandContext).\n */\nconst NOTICE_WITHHELD = \"[notice withheld: redaction unavailable]\";\n\nfunction safeNotice(message: string): string {\n\ttry {\n\t\tconst redactor = createTraceRedactor({ env: process.env });\n\t\treturn redactor.redactText(sanitizeForTerminal(redactor.redactText(message).text)).text;\n\t} catch {\n\t\treturn NOTICE_WITHHELD;\n\t}\n}\n\nfunction withHeadlessNotices(ctx: ExtensionCommandContext): ExtensionCommandContext {\n\tif (ctx.mode !== \"print\" && ctx.mode !== \"json\") return ctx;\n\tconst ui = Object.defineProperties({}, Object.getOwnPropertyDescriptors(ctx.ui)) as ExtensionCommandContext[\"ui\"];\n\tui.notify = (message: string) => {\n\t\tprocess.stderr.write(`${safeNotice(message)}\\n`);\n\t};\n\tconst wrapped = Object.defineProperties({}, Object.getOwnPropertyDescriptors(ctx)) as ExtensionCommandContext;\n\tObject.defineProperty(wrapped, \"ui\", { value: ui, enumerable: true, configurable: true });\n\treturn wrapped;\n}\n\n/**\n * Mirrors packages/flow emitRefusalSettled: an rpc `/flow run` or `/flow continue` that dispatches nothing still emits one terminal\n * `run_settled` frame so the host stops waiting. Built here because the entry graph must not reach @humain/flow.\n * Print/json refusals exit non-zero (mirrors flow's markHeadlessFailure). Never throws; no-op otherwise.\n */\nasync function settleRefusal(\n\tcommand: FlowSubcommand,\n\tctx: ExtensionCommandContext,\n\tfailureClass: FlowFailureClass,\n): Promise<void> {\n\tif (!START_COMMANDS.has(command)) return;\n\tif (ctx.mode === \"print\" || ctx.mode === \"json\") process.exitCode = 1;\n\tif (ctx.mode !== \"rpc\" || !rpcOutput) return;\n\ttry {\n\t\tconst runId = `flow-refused-${randomBytes(8).toString(\"hex\")}`;\n\t\tconst frame: FlowEventFrameV1 = {\n\t\t\ttype: \"flow_event\",\n\t\t\tevent: {\n\t\t\t\tschema: \"humain-flow-event\",\n\t\t\t\tschemaVersion: 1,\n\t\t\t\teventId: `${runId}.refused`,\n\t\t\t\trunId,\n\t\t\t\tseq: 1,\n\t\t\t\tts: new Date().toISOString(),\n\t\t\t\tprofile: {\n\t\t\t\t\tid: \"unknown\",\n\t\t\t\t\tversion: 1,\n\t\t\t\t\tdigest: createHash(\"sha256\").update(\"unknown\", \"utf8\").digest(\"hex\"),\n\t\t\t\t},\n\t\t\t\tcauses: [],\n\t\t\t\tkind: \"run_settled\",\n\t\t\t\tpayload: { outcome: \"failed\", failureClass, settledCleanly: true, retryOffer: [\"direct\"], totals: {} },\n\t\t\t},\n\t\t};\n\t\tawait rpcOutput(frame);\n\t} catch {\n\t\t// Refusal must still notify; a dead transport is not the command's problem.\n\t}\n}\n\nfunction disabledReason(pi: ExtensionAPI, env: NodeJS.ProcessEnv): string | undefined {\n\tconst raw = env[HUMAIN_FLOW_DISABLED_ENV]?.trim().toLowerCase();\n\tif (raw === \"1\" || raw === \"true\") return `${HUMAIN_FLOW_DISABLED_ENV}=${raw}`;\n\ttry {\n\t\t// `flow` is not a typed Settings key: settings.json keeps unknown keys, so read it raw.\n\t\tconst flow = (pi.getSettings() as Record<string, unknown>).flow;\n\t\tif (isRecord(flow) && flow.enabled === false) return \"setting flow.enabled=false\";\n\t} catch {\n\t\t// Runtime not bound yet: treat as enabled.\n\t}\n\treturn undefined;\n}\n\n/**\n * Run flowExtension against a staging proxy. The `/flow` command is captured (so names never double-register); every other\n * registration is recorded and applied to the real pi only after the factory and the session_start replay succeed, so\n * a failed attempt leaves nothing behind and a retry starts from scratch. Late registration is supported by the\n * extension loader (handlers, tools, commands and flags are written to the live extension object), but\n * `session_start` has already fired by the time Flow loads, so the last session_start event is replayed to Flow's\n * staged session_start handlers.\n *\n * Commit is not transactional for non-handler members: if one throws midway, committed handlers are unsubscribed, and\n * tools/commands/flags/shortcuts/renderers (keyed maps in the extension loader) are simply overwritten on retry.\n */\nasync function runFlowExtension(\n\tpi: ExtensionAPI,\n\tflowExtension: ExtensionFactory,\n\tlastSessionStart: () => unknown[] | undefined,\n): Promise<Map<string, CommandOptions>> {\n\tconst captured = new Map<string, CommandOptions>();\n\tconst staged: StagedCall[] = [];\n\t// After a successful commit the proxy forwards live, so registrations made later (from handlers) reach the real pi.\n\tlet live = false;\n\tconst proxy = new Proxy(pi, {\n\t\tget(target, prop) {\n\t\t\tif (!live && typeof prop === \"string\" && STAGED_MEMBERS.has(prop)) {\n\t\t\t\treturn (...args: unknown[]) => {\n\t\t\t\t\tif (prop === \"registerCommand\" && args[0] === \"flow\") {\n\t\t\t\t\t\tcaptured.set(args[0], args[1] as CommandOptions);\n\t\t\t\t\t\treturn undefined;\n\t\t\t\t\t}\n\t\t\t\t\tconst call: StagedCall = { member: prop, args, cancelled: false };\n\t\t\t\t\tstaged.push(call);\n\t\t\t\t\tif (prop !== \"on\") return undefined;\n\t\t\t\t\treturn () => {\n\t\t\t\t\t\tcall.cancelled = true;\n\t\t\t\t\t\tcall.unsubscribe?.();\n\t\t\t\t\t};\n\t\t\t\t};\n\t\t\t}\n\t\t\tconst value: unknown = Reflect.get(target, prop, target);\n\t\t\treturn typeof value === \"function\" ? value.bind(target) : value;\n\t\t},\n\t});\n\tawait flowExtension(proxy);\n\n\tlet replayed: unknown[] | undefined;\n\tfor (let start = lastSessionStart(); start && start !== replayed; start = lastSessionStart()) {\n\t\treplayed = start;\n\t\tfor (const call of staged) {\n\t\t\tif (call.member === \"on\" && call.args[0] === \"session_start\" && !call.cancelled) {\n\t\t\t\tawait (call.args[1] as EventHandler)(...start);\n\t\t\t}\n\t\t}\n\t}\n\n\t// Synchronous from the last replay check: no session_start can slip between replay and commit.\n\tconst committed: Array<() => void> = [];\n\ttry {\n\t\tfor (const call of staged) {\n\t\t\tif (call.cancelled) continue;\n\t\t\tconst result = (Reflect.get(pi, call.member) as (...args: unknown[]) => unknown).apply(pi, call.args);\n\t\t\tif (call.member === \"on\") {\n\t\t\t\tcall.unsubscribe = result as () => void;\n\t\t\t\tcommitted.push(call.unsubscribe);\n\t\t\t}\n\t\t}\n\t} catch (error) {\n\t\tfor (const unsubscribe of committed) unsubscribe();\n\t\tthrow error;\n\t}\n\tlive = true;\n\treturn captured;\n}\n\nfunction isSameCliReleaseFlowDir(dir: string): boolean {\n\tif (!isAbsolute(dir) || VERSION === \"0.0.0\") return false;\n\ttry {\n\t\tconst manifest: unknown = JSON.parse(readFileSync(join(dir, \"package.json\"), \"utf8\"));\n\t\tif (!isRecord(manifest) || manifest.name !== \"@humain/flow\") return false;\n\t} catch {\n\t\treturn false;\n\t}\n\t// Bun ships flow/ beside package.json; bundled Node ships dist/bundle/flow/.\n\tfor (const root of [dirname(dir), resolve(dir, \"../../..\")]) {\n\t\ttry {\n\t\t\tconst manifest: unknown = JSON.parse(readFileSync(join(root, \"package.json\"), \"utf8\"));\n\t\t\tif (isRecord(manifest) && manifest.name === PACKAGE_NAME) return manifest.version === VERSION;\n\t\t} catch {\n\t\t\t// Missing or unreadable release metadata cannot validate an override.\n\t\t}\n\t}\n\treturn false;\n}\n\nexport function createHumainFlowLoaderExtensionFactory(options: HumainFlowLoaderOptions = {}): ExtensionFactory {\n\tconst env = options.env ?? process.env;\n\t// This is the single sanctioned lazy-load boundary for @humain/flow (see AGENTS.md \"No inline imports\" exception).\n\tconst importFlow = options.importFlow ?? (() => import(\"@humain/flow\"));\n\tconst flowPackageDir = options.flowPackageDir ?? getBundledFlowPackageDir();\n\tconst builtInProfilesDir = options.builtInProfilesDir ?? getBundledFlowProfilesDir();\n\tlet flowModule: Promise<FlowModule> | undefined;\n\n\treturn (pi) => {\n\t\tdisabledProbe = () => disabledReason(pi, env) !== undefined;\n\t\tlet lastStart: unknown[] | undefined;\n\t\tlet loaded: Promise<Map<string, CommandOptions>> | undefined;\n\n\t\tpi.on(\"session_start\", (event, ctx) => {\n\t\t\tlastStart = [event, ctx];\n\t\t});\n\t\tpi.registerFlag(\"profile\", { description: \"Flow profile id\", type: \"string\" });\n\t\tpi.registerFlag(\"flow-admission\", { description: \"Flow run admission file (JSON)\", type: \"string\" });\n\n\t\tconst loadModule = async (): Promise<FlowModule> => {\n\t\t\tconst override = env[HUMAIN_FLOW_PACKAGE_DIR_ENV];\n\t\t\tif (override && !isSameCliReleaseFlowDir(override)) delete env[HUMAIN_FLOW_PACKAGE_DIR_ENV];\n\t\t\tif (flowPackageDir && !env[HUMAIN_FLOW_PACKAGE_DIR_ENV]) env[HUMAIN_FLOW_PACKAGE_DIR_ENV] = flowPackageDir;\n\t\t\tflowModule ??= importFlow().then((module) => {\n\t\t\t\trpcControl = module.createFlowRpcControl?.({\n\t\t\t\t\twriteFrame: (frame) => rpcOutput?.(frame),\n\t\t\t\t\tisDisabled: isFlowDisabled,\n\t\t\t\t\tsendFollowUp: (text) =>\n\t\t\t\t\t\trpcFollowUp ? rpcFollowUp(text) : Promise.reject(new Error(\"host unavailable\")),\n\t\t\t\t});\n\t\t\t\treturn module;\n\t\t\t});\n\t\t\ttry {\n\t\t\t\treturn await flowModule;\n\t\t\t} catch (error) {\n\t\t\t\tflowModule = undefined;\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t};\n\n\t\trpcLoader = async () => {\n\t\t\ttry {\n\t\t\t\tawait loadModule();\n\t\t\t} catch {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\treturn rpcControl;\n\t\t};\n\n\t\tconst load = (): Promise<Map<string, CommandOptions>> => {\n\t\t\tif (!loaded) {\n\t\t\t\tconst attempt = (async () => {\n\t\t\t\t\tconst module = await loadModule();\n\t\t\t\t\treturn runFlowExtension(pi, module.flowExtension, () => lastStart);\n\t\t\t\t})();\n\t\t\t\tloaded = attempt;\n\t\t\t\t// A failed load must be retryable on the next invocation.\n\t\t\t\tattempt.catch(() => {\n\t\t\t\t\tif (loaded === attempt) loaded = undefined;\n\t\t\t\t});\n\t\t\t}\n\t\t\treturn loaded;\n\t\t};\n\n\t\tpi.registerCommand(\"flow\", {\n\t\t\tdescription: FLOW_DESCRIPTION,\n\t\t\tgetArgumentCompletions: completeFlowArguments,\n\t\t\thandler: async (args: string, rawCtx: ExtensionCommandContext) => {\n\t\t\t\tconst ctx = withHeadlessNotices(rawCtx);\n\t\t\t\tconst refuse = (message: string, level: \"warning\" | \"error\") => {\n\t\t\t\t\tif (ctx.mode === \"print\" || ctx.mode === \"json\") process.exitCode = 1;\n\t\t\t\t\tctx.ui.notify(message, level);\n\t\t\t\t};\n\t\t\t\tconst parsed = parseFlowCommand(args);\n\t\t\t\tif (\"error\" in parsed) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\trefuse(parsed.error, \"error\");\n\t\t\t\t\t} finally {\n\t\t\t\t\t\tif (parsed.command) await settleRefusal(parsed.command, ctx, \"config_invalid\");\n\t\t\t\t\t}\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst { command, payload } = parsed;\n\t\t\t\tif (command === \"help\") {\n\t\t\t\t\tctx.ui.notify(renderFlowHelp(payload.trim() || undefined), \"info\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\t// Secure account dialogs exist only in the terminal UI: refuse elsewhere before loading Flow.\n\t\t\t\tif (command === \"setup\" && ctx.mode !== \"tui\") {\n\t\t\t\t\trefuse(FLOW_SETUP_TERMINAL_ONLY, \"error\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst reason = AVAILABLE_WHEN_DISABLED.has(command) ? undefined : disabledReason(pi, env);\n\t\t\t\tif (reason) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tctx.ui.notify(`Flow disabled (${reason}). /flow ${command} is unavailable.`, \"warning\");\n\t\t\t\t\t} finally {\n\t\t\t\t\t\tawait settleRefusal(command, ctx, \"config_invalid\");\n\t\t\t\t\t}\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (command === \"profile\") {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst module = await loadModule();\n\t\t\t\t\t\tif (!module.runFlowProfileCommand || !module.createProfileStore) {\n\t\t\t\t\t\t\tctx.ui.notify(flowBuildUnavailable(command), \"error\");\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst store = module.createProfileStore({\n\t\t\t\t\t\t\tflowDir: options.flowDir ?? join(getAgentDir(), \"flow\"),\n\t\t\t\t\t\t\t...(builtInProfilesDir !== undefined ? { builtInDir: builtInProfilesDir } : {}),\n\t\t\t\t\t\t});\n\t\t\t\t\t\tawait module.runFlowProfileCommand(payload, ctx, { store });\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tctx.ui.notify(\n\t\t\t\t\t\t\t`/flow profile failed: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t\t\t\t\t\"error\",\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (LOADED_RUN_COMMANDS.has(command) && !loaded) {\n\t\t\t\t\tctx.ui.notify(NO_LOADED_RUN_COPY[command] ?? \"No active Flow run.\", \"info\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tlet commands: Map<string, CommandOptions>;\n\t\t\t\ttry {\n\t\t\t\t\tcommands = await load();\n\t\t\t\t} catch (error) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tctx.ui.notify(\n\t\t\t\t\t\t\t`Failed to load Flow: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t\t\t\t\t\"error\",\n\t\t\t\t\t\t);\n\t\t\t\t\t} finally {\n\t\t\t\t\t\tawait settleRefusal(command, ctx, \"internal\");\n\t\t\t\t\t}\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst real = commands.get(\"flow\");\n\t\t\t\tif (!real) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tctx.ui.notify(flowBuildUnavailable(command), \"error\");\n\t\t\t\t\t} finally {\n\t\t\t\t\t\tawait settleRefusal(command, ctx, \"internal\");\n\t\t\t\t\t}\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\t// Flow's own dispatcher re-parses the original arguments and slices the payload itself.\n\t\t\t\tawait real.handler(args, ctx);\n\t\t\t},\n\t\t});\n\t};\n}\n"]}
1
+ {"version":3,"file":"flow-loader.js","sourceRoot":"","sources":["../../src/humain/flow-loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAG/D,OAAO,EAAE,WAAW,EAAE,wBAAwB,EAAE,yBAAyB,EAAE,YAAY,EA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CAAC;oBAC/C,CAAC;oBACD,OAAO;gBACR,CAAC;gBACD,wFAAwF;gBACxF,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;YAC/B,CAAC;SACD,CAAC,CAAC;IACJ,CAAC,CAAC;AACH,CAAC","sourcesContent":["import { createHash, randomBytes } from \"node:crypto\";\nimport { readFileSync } from \"node:fs\";\nimport { dirname, isAbsolute, join, resolve } from \"node:path\";\nimport type { FlowFailureClass } from \"@humain/humain-code-contracts/flow-common\";\nimport type { FlowEventFrameV1, FlowReceiptV1, FlowStatusV1 } from \"@humain/humain-code-contracts/flow-control\";\nimport { getAgentDir, getBundledFlowPackageDir, getBundledFlowProfilesDir, PACKAGE_NAME, VERSION } from \"../config.ts\";\nimport type {\n\tExtensionAPI,\n\tExtensionCommandContext,\n\tExtensionFactory,\n\tRegisteredCommand,\n} from \"../core/extensions/types.ts\";\nimport { createTraceRedactor } from \"../core/trace/redaction.ts\";\nimport { sanitizeForTerminal } from \"../core/trace-client/sanitize.ts\";\nimport {\n\tcompleteFlowArguments,\n\tFLOW_SETUP_TERMINAL_ONLY,\n\ttype FlowSubcommand,\n\tflowBuildUnavailable,\n\tparseFlowCommand,\n\trenderFlowHelp,\n} from \"./flow-command.ts\";\n\n/**\n * Lazy loader for the private @humain/flow package.\n *\n * The CLI entry graph must not statically reach Flow: this module registers one cheap `/flow` stub and two flags, and\n * only loads Flow (one memoized dynamic import) the first time a subcommand needs it. Help, completion, unknown\n * commands and not-yet-available commands are answered statically and never import Flow. Flow is bundled as its own\n * chunk.\n */\n\nexport const HUMAIN_FLOW_DISABLED_ENV = \"HUMAIN_TERMINAL_FLOW_DISABLED\";\nexport const HUMAIN_FLOW_PACKAGE_DIR_ENV = \"HUMAIN_TERMINAL_FLOW_PACKAGE_DIR\";\n\n/** Run-control surface Flow exposes to rpc mode (flow_status/pause/resume/cancel/message). */\nexport interface FlowRpcControl {\n\thandle(input: unknown): Promise<{ receipt: FlowReceiptV1; status?: FlowStatusV1 }>;\n\tactiveRunId(): string | undefined;\n}\n\nexport interface FlowModule {\n\tflowExtension: ExtensionFactory;\n\t/** Documented rpc hook: called once when Flow loads; `writeFrame` carries `flow_event` frames to the rpc host. */\n\tcreateFlowRpcControl?(options: {\n\t\twriteFrame?: (frame: FlowEventFrameV1) => void | Promise<void>;\n\t\tisDisabled?: () => boolean;\n\t\t/** Queues text on the host session as a follow-up (flow_message with no active run). */\n\t\tsendFollowUp?: (text: string) => Promise<void>;\n\t}): FlowRpcControl;\n\t/** B1 profile command; optional so test fakes need not provide it. Methods stay bivariant for the real signatures. */\n\trunFlowProfileCommand?(args: string, ctx: ExtensionCommandContext, deps: { store: unknown }): Promise<unknown>;\n\tcreateProfileStore?(options: { flowDir: string; builtInDir?: string }): unknown;\n}\n\nexport interface HumainFlowLoaderOptions {\n\t/** Test seam. Defaults to the single sanctioned dynamic import of @humain/flow. */\n\timportFlow?: () => Promise<FlowModule>;\n\tenv?: NodeJS.ProcessEnv;\n\t/** Directory holding Flow's agents/assets/package.json. Defaults to the bundled layout's flow/ dir. */\n\tflowPackageDir?: string;\n\t/** Built-in Flow profiles dir. Defaults to the bundled layout's assets/profiles; undefined lets Flow find its own. */\n\tbuiltInProfilesDir?: string;\n\t/** Flow profile store directory. Defaults to `<agentDir>/flow`. */\n\tflowDir?: string;\n}\n\nlet rpcControl: FlowRpcControl | undefined;\nlet disabledProbe: (() => boolean) | undefined;\nlet rpcOutput: ((frame: FlowEventFrameV1) => void | Promise<void>) | undefined;\nlet rpcLoader: (() => Promise<FlowRpcControl | undefined>) | undefined;\nlet rpcFollowUp: ((text: string) => Promise<void>) | undefined;\n\n/** The documented rpc hook: rpc mode reads Flow's run control here and never imports Flow itself. */\nexport function getFlowRpcControl(): FlowRpcControl | undefined {\n\treturn rpcControl;\n}\n\n/**\n * The documented rpc hook: loads Flow through the same lazy-load path the stub commands use and returns its run control.\n * Undefined when Flow is disabled (never loaded then), not wired, or fails to load.\n */\nexport async function loadFlowRpcControl(): Promise<FlowRpcControl | undefined> {\n\tif (rpcControl) return rpcControl;\n\tif (isFlowDisabled()) return undefined;\n\treturn rpcLoader?.();\n}\n\n/** True while Flow is switched off (flow.enabled=false or the env kill switch); rpc mode refuses flow_resume then. */\nexport function isFlowDisabled(): boolean {\n\treturn disabledProbe?.() ?? false;\n}\n\n/** The documented rpc hook: rpc mode registers where Flow's `flow_event` frames are written. */\nexport function setFlowRpcOutput(writer: ((frame: FlowEventFrameV1) => void | Promise<void>) | undefined): void {\n\trpcOutput = writer;\n}\n\n/** The documented rpc hook: rpc mode registers how direct-mode flow_message text is queued as a host follow-up. */\nexport function setFlowRpcFollowUp(queue: ((text: string) => Promise<void>) | undefined): void {\n\trpcFollowUp = queue;\n}\n\ntype CommandOptions = Omit<RegisteredCommand, \"name\" | \"sourceInfo\">;\ntype EventHandler = (...args: unknown[]) => unknown;\n\n/**\n * ExtensionAPI members that only record registrations (see core/extensions/loader.ts). They are staged while Flow's\n * factory runs and applied to the real pi only after the factory and the session_start replay succeed. Reads and\n * actions (getFlag, getSettings, exec, sendMessage, ...) and `events` stay live: they have no registration to undo\n * or are needed by the factory itself. Flow uses none of the live ones that subscribe (`events.on`).\n */\nconst STAGED_MEMBERS = new Set([\n\t\"on\",\n\t\"registerTool\",\n\t\"registerCommand\",\n\t\"registerShortcut\",\n\t\"registerFlag\",\n\t\"registerMessageRenderer\",\n\t\"registerMarkdownTransformer\",\n\t\"registerEntryRenderer\",\n\t\"registerProvider\",\n\t\"unregisterProvider\",\n\t\"registerMcpServer\",\n\t\"unregisterMcpServer\",\n\t\"registerVirtualModel\",\n\t\"unregisterVirtualModel\",\n]);\n\ninterface StagedCall {\n\tmember: string;\n\targs: unknown[];\n\tcancelled: boolean;\n\tunsubscribe?: () => void;\n}\n\nconst FLOW_DESCRIPTION =\n\t\"Plan, run, and verify work with agents. Subcommands: run, continue, list, status, cancel, pause, resume, \" +\n\t\"title, message, hide, show, models, profile, setup. Use /flow help for usage.\";\n\n/**\n * Act on an already loaded run only; with Flow not loaded there is no run, so Flow is never imported for them. They\n * stay reachable when Flow is disabled so a live run can still be stopped. Every other subcommand is refused when\n * disabled.\n */\nconst LOADED_RUN_COMMANDS: ReadonlySet<FlowSubcommand> = new Set([\n\t\"cancel\",\n\t\"status\",\n\t\"pause\",\n\t\"resume\",\n\t\"hide\",\n\t\"show\",\n]);\n/** Kill switch: resume would restart dispatch, so it is refused while Flow is disabled (the others are not). */\nconst AVAILABLE_WHEN_DISABLED: ReadonlySet<FlowSubcommand> = new Set([\"cancel\", \"status\", \"pause\", \"hide\", \"show\"]);\n/** Copy when a loaded-run command finds no Flow loaded, so there is nothing to act on. */\nconst NO_LOADED_RUN_COPY: Partial<Record<FlowSubcommand, string>> = {\n\tcancel: \"No active Flow run to stop.\",\n\tstatus: \"No active Flow run. Start one with /flow run <goal>.\",\n\tpause: \"No active Flow run to pause.\",\n\tresume: \"No paused Flow run to resume.\",\n\thide: \"No current Flow widget to hide.\",\n\tshow: \"No current Flow widget to show.\",\n};\n/** Only these start (or recover) work, so only their refusals settle an rpc run. */\nconst START_COMMANDS: ReadonlySet<FlowSubcommand> = new Set([\"run\", \"continue\", \"fix\"]);\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null;\n}\n\n/**\n * Print/json mode has no UI: core makes ctx.ui.notify a no-op, so headless notices go to stderr as bare text.\n * Notice text can echo user args or env values, so it is redacted, stripped of terminal escapes, then redacted again\n * with the same redactor: the first pass catches secrets that stripping could otherwise mangle, the second catches\n * secrets that were split by escapes and are rejoined by stripping. Fails closed to a fixed line on any failure.\n * Replacing `ui` snapshots ui (descriptors preserve other ctx getters, so lazy getters on ctx stay live; same approach\n * as the runner's createCommandContext).\n */\nconst NOTICE_WITHHELD = \"[notice withheld: redaction unavailable]\";\n\nfunction safeNotice(message: string): string {\n\ttry {\n\t\tconst redactor = createTraceRedactor({ env: process.env });\n\t\treturn redactor.redactText(sanitizeForTerminal(redactor.redactText(message).text)).text;\n\t} catch {\n\t\treturn NOTICE_WITHHELD;\n\t}\n}\n\nfunction withHeadlessNotices(ctx: ExtensionCommandContext): ExtensionCommandContext {\n\tif (ctx.mode !== \"print\" && ctx.mode !== \"json\") return ctx;\n\tconst ui = Object.defineProperties({}, Object.getOwnPropertyDescriptors(ctx.ui)) as ExtensionCommandContext[\"ui\"];\n\tui.notify = (message: string) => {\n\t\tprocess.stderr.write(`${safeNotice(message)}\\n`);\n\t};\n\tconst wrapped = Object.defineProperties({}, Object.getOwnPropertyDescriptors(ctx)) as ExtensionCommandContext;\n\tObject.defineProperty(wrapped, \"ui\", { value: ui, enumerable: true, configurable: true });\n\treturn wrapped;\n}\n\n/**\n * Mirrors packages/flow emitRefusalSettled: an rpc `/flow run` or `/flow continue` that dispatches nothing still emits one terminal\n * `run_settled` frame so the host stops waiting. Built here because the entry graph must not reach @humain/flow.\n * Print/json refusals exit non-zero (mirrors flow's markHeadlessFailure). Never throws; no-op otherwise.\n */\nasync function settleRefusal(\n\tcommand: FlowSubcommand,\n\tctx: ExtensionCommandContext,\n\tfailureClass: FlowFailureClass,\n): Promise<void> {\n\tif (!START_COMMANDS.has(command)) return;\n\tif (ctx.mode === \"print\" || ctx.mode === \"json\") process.exitCode = 1;\n\tif (ctx.mode !== \"rpc\" || !rpcOutput) return;\n\ttry {\n\t\tconst runId = `flow-refused-${randomBytes(8).toString(\"hex\")}`;\n\t\tconst frame: FlowEventFrameV1 = {\n\t\t\ttype: \"flow_event\",\n\t\t\tevent: {\n\t\t\t\tschema: \"humain-flow-event\",\n\t\t\t\tschemaVersion: 1,\n\t\t\t\teventId: `${runId}.refused`,\n\t\t\t\trunId,\n\t\t\t\tseq: 1,\n\t\t\t\tts: new Date().toISOString(),\n\t\t\t\tprofile: {\n\t\t\t\t\tid: \"unknown\",\n\t\t\t\t\tversion: 1,\n\t\t\t\t\tdigest: createHash(\"sha256\").update(\"unknown\", \"utf8\").digest(\"hex\"),\n\t\t\t\t},\n\t\t\t\tcauses: [],\n\t\t\t\tkind: \"run_settled\",\n\t\t\t\tpayload: { outcome: \"failed\", failureClass, settledCleanly: true, retryOffer: [\"direct\"], totals: {} },\n\t\t\t},\n\t\t};\n\t\tawait rpcOutput(frame);\n\t} catch {\n\t\t// Refusal must still notify; a dead transport is not the command's problem.\n\t}\n}\n\nfunction disabledReason(pi: ExtensionAPI, env: NodeJS.ProcessEnv): string | undefined {\n\tconst raw = env[HUMAIN_FLOW_DISABLED_ENV]?.trim().toLowerCase();\n\tif (raw === \"1\" || raw === \"true\") return `${HUMAIN_FLOW_DISABLED_ENV}=${raw}`;\n\ttry {\n\t\t// `flow` is not a typed Settings key: settings.json keeps unknown keys, so read it raw.\n\t\tconst flow = (pi.getSettings() as Record<string, unknown>).flow;\n\t\tif (isRecord(flow) && flow.enabled === false) return \"setting flow.enabled=false\";\n\t} catch {\n\t\t// Runtime not bound yet: treat as enabled.\n\t}\n\treturn undefined;\n}\n\n/**\n * Run flowExtension against a staging proxy. The `/flow` command is captured (so names never double-register); every other\n * registration is recorded and applied to the real pi only after the factory and the session_start replay succeed, so\n * a failed attempt leaves nothing behind and a retry starts from scratch. Late registration is supported by the\n * extension loader (handlers, tools, commands and flags are written to the live extension object), but\n * `session_start` has already fired by the time Flow loads, so the last session_start event is replayed to Flow's\n * staged session_start handlers.\n *\n * Commit is not transactional for non-handler members: if one throws midway, committed handlers are unsubscribed, and\n * tools/commands/flags/shortcuts/renderers (keyed maps in the extension loader) are simply overwritten on retry.\n */\nasync function runFlowExtension(\n\tpi: ExtensionAPI,\n\tflowExtension: ExtensionFactory,\n\tlastSessionStart: () => unknown[] | undefined,\n): Promise<Map<string, CommandOptions>> {\n\tconst captured = new Map<string, CommandOptions>();\n\tconst staged: StagedCall[] = [];\n\t// After a successful commit the proxy forwards live, so registrations made later (from handlers) reach the real pi.\n\tlet live = false;\n\tconst proxy = new Proxy(pi, {\n\t\tget(target, prop) {\n\t\t\tif (!live && typeof prop === \"string\" && STAGED_MEMBERS.has(prop)) {\n\t\t\t\treturn (...args: unknown[]) => {\n\t\t\t\t\tif (prop === \"registerCommand\" && args[0] === \"flow\") {\n\t\t\t\t\t\tcaptured.set(args[0], args[1] as CommandOptions);\n\t\t\t\t\t\treturn undefined;\n\t\t\t\t\t}\n\t\t\t\t\tconst call: StagedCall = { member: prop, args, cancelled: false };\n\t\t\t\t\tstaged.push(call);\n\t\t\t\t\tif (prop !== \"on\") return undefined;\n\t\t\t\t\treturn () => {\n\t\t\t\t\t\tcall.cancelled = true;\n\t\t\t\t\t\tcall.unsubscribe?.();\n\t\t\t\t\t};\n\t\t\t\t};\n\t\t\t}\n\t\t\tconst value: unknown = Reflect.get(target, prop, target);\n\t\t\treturn typeof value === \"function\" ? value.bind(target) : value;\n\t\t},\n\t});\n\tawait flowExtension(proxy);\n\n\tlet replayed: unknown[] | undefined;\n\tfor (let start = lastSessionStart(); start && start !== replayed; start = lastSessionStart()) {\n\t\treplayed = start;\n\t\tfor (const call of staged) {\n\t\t\tif (call.member === \"on\" && call.args[0] === \"session_start\" && !call.cancelled) {\n\t\t\t\tawait (call.args[1] as EventHandler)(...start);\n\t\t\t}\n\t\t}\n\t}\n\n\t// Synchronous from the last replay check: no session_start can slip between replay and commit.\n\tconst committed: Array<() => void> = [];\n\ttry {\n\t\tfor (const call of staged) {\n\t\t\tif (call.cancelled) continue;\n\t\t\tconst result = (Reflect.get(pi, call.member) as (...args: unknown[]) => unknown).apply(pi, call.args);\n\t\t\tif (call.member === \"on\") {\n\t\t\t\tcall.unsubscribe = result as () => void;\n\t\t\t\tcommitted.push(call.unsubscribe);\n\t\t\t}\n\t\t}\n\t} catch (error) {\n\t\tfor (const unsubscribe of committed) unsubscribe();\n\t\tthrow error;\n\t}\n\tlive = true;\n\treturn captured;\n}\n\nfunction isSameCliReleaseFlowDir(dir: string): boolean {\n\tif (!isAbsolute(dir) || VERSION === \"0.0.0\") return false;\n\ttry {\n\t\tconst manifest: unknown = JSON.parse(readFileSync(join(dir, \"package.json\"), \"utf8\"));\n\t\tif (!isRecord(manifest) || manifest.name !== \"@humain/flow\") return false;\n\t} catch {\n\t\treturn false;\n\t}\n\t// Bun ships flow/ beside package.json; bundled Node ships dist/bundle/flow/.\n\tfor (const root of [dirname(dir), resolve(dir, \"../../..\")]) {\n\t\ttry {\n\t\t\tconst manifest: unknown = JSON.parse(readFileSync(join(root, \"package.json\"), \"utf8\"));\n\t\t\tif (isRecord(manifest) && manifest.name === PACKAGE_NAME) return manifest.version === VERSION;\n\t\t} catch {\n\t\t\t// Missing or unreadable release metadata cannot validate an override.\n\t\t}\n\t}\n\treturn false;\n}\n\nexport function createHumainFlowLoaderExtensionFactory(options: HumainFlowLoaderOptions = {}): ExtensionFactory {\n\tconst env = options.env ?? process.env;\n\t// This is the single sanctioned lazy-load boundary for @humain/flow (see AGENTS.md \"No inline imports\" exception).\n\tconst importFlow = options.importFlow ?? (() => import(\"@humain/flow\"));\n\tconst flowPackageDir = options.flowPackageDir ?? getBundledFlowPackageDir();\n\tconst builtInProfilesDir = options.builtInProfilesDir ?? getBundledFlowProfilesDir();\n\tlet flowModule: Promise<FlowModule> | undefined;\n\n\treturn (pi) => {\n\t\tdisabledProbe = () => disabledReason(pi, env) !== undefined;\n\t\tlet lastStart: unknown[] | undefined;\n\t\tlet loaded: Promise<Map<string, CommandOptions>> | undefined;\n\n\t\tpi.on(\"session_start\", (event, ctx) => {\n\t\t\tlastStart = [event, ctx];\n\t\t});\n\t\tpi.registerFlag(\"profile\", { description: \"Flow profile id\", type: \"string\" });\n\t\tpi.registerFlag(\"flow-admission\", { description: \"Flow run admission file (JSON)\", type: \"string\" });\n\n\t\tconst loadModule = async (): Promise<FlowModule> => {\n\t\t\tconst override = env[HUMAIN_FLOW_PACKAGE_DIR_ENV];\n\t\t\tif (override && !isSameCliReleaseFlowDir(override)) delete env[HUMAIN_FLOW_PACKAGE_DIR_ENV];\n\t\t\tif (flowPackageDir && !env[HUMAIN_FLOW_PACKAGE_DIR_ENV]) env[HUMAIN_FLOW_PACKAGE_DIR_ENV] = flowPackageDir;\n\t\t\tflowModule ??= importFlow().then((module) => {\n\t\t\t\trpcControl = module.createFlowRpcControl?.({\n\t\t\t\t\twriteFrame: (frame) => rpcOutput?.(frame),\n\t\t\t\t\tisDisabled: isFlowDisabled,\n\t\t\t\t\tsendFollowUp: (text) =>\n\t\t\t\t\t\trpcFollowUp ? rpcFollowUp(text) : Promise.reject(new Error(\"host unavailable\")),\n\t\t\t\t});\n\t\t\t\treturn module;\n\t\t\t});\n\t\t\ttry {\n\t\t\t\treturn await flowModule;\n\t\t\t} catch (error) {\n\t\t\t\tflowModule = undefined;\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t};\n\n\t\trpcLoader = async () => {\n\t\t\ttry {\n\t\t\t\tawait loadModule();\n\t\t\t} catch {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\treturn rpcControl;\n\t\t};\n\n\t\tconst load = (): Promise<Map<string, CommandOptions>> => {\n\t\t\tif (!loaded) {\n\t\t\t\tconst attempt = (async () => {\n\t\t\t\t\tconst module = await loadModule();\n\t\t\t\t\treturn runFlowExtension(pi, module.flowExtension, () => lastStart);\n\t\t\t\t})();\n\t\t\t\tloaded = attempt;\n\t\t\t\t// A failed load must be retryable on the next invocation.\n\t\t\t\tattempt.catch(() => {\n\t\t\t\t\tif (loaded === attempt) loaded = undefined;\n\t\t\t\t});\n\t\t\t}\n\t\t\treturn loaded;\n\t\t};\n\n\t\tpi.registerCommand(\"flow\", {\n\t\t\tdescription: FLOW_DESCRIPTION,\n\t\t\tgetArgumentCompletions: completeFlowArguments,\n\t\t\thandler: async (args: string, rawCtx: ExtensionCommandContext) => {\n\t\t\t\tconst ctx = withHeadlessNotices(rawCtx);\n\t\t\t\tconst refuse = (message: string, level: \"warning\" | \"error\") => {\n\t\t\t\t\tif (ctx.mode === \"print\" || ctx.mode === \"json\") process.exitCode = 1;\n\t\t\t\t\tctx.ui.notify(message, level);\n\t\t\t\t};\n\t\t\t\tconst parsed = parseFlowCommand(args);\n\t\t\t\tif (\"error\" in parsed) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\trefuse(parsed.error, \"error\");\n\t\t\t\t\t} finally {\n\t\t\t\t\t\tif (parsed.command) await settleRefusal(parsed.command, ctx, \"config_invalid\");\n\t\t\t\t\t}\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst { command, payload } = parsed;\n\t\t\t\tif (command === \"help\") {\n\t\t\t\t\tctx.ui.notify(renderFlowHelp(payload.trim() || undefined), \"info\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\t// Secure account dialogs exist only in the terminal UI: refuse elsewhere before loading Flow.\n\t\t\t\tif (command === \"setup\" && ctx.mode !== \"tui\") {\n\t\t\t\t\trefuse(FLOW_SETUP_TERMINAL_ONLY, \"error\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst reason = AVAILABLE_WHEN_DISABLED.has(command) ? undefined : disabledReason(pi, env);\n\t\t\t\tif (reason) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tctx.ui.notify(`Flow disabled (${reason}). /flow ${command} is unavailable.`, \"warning\");\n\t\t\t\t\t} finally {\n\t\t\t\t\t\tawait settleRefusal(command, ctx, \"config_invalid\");\n\t\t\t\t\t}\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (command === \"profile\") {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst module = await loadModule();\n\t\t\t\t\t\tif (!module.runFlowProfileCommand || !module.createProfileStore) {\n\t\t\t\t\t\t\tctx.ui.notify(flowBuildUnavailable(command), \"error\");\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst store = module.createProfileStore({\n\t\t\t\t\t\t\tflowDir: options.flowDir ?? join(getAgentDir(), \"flow\"),\n\t\t\t\t\t\t\t...(builtInProfilesDir !== undefined ? { builtInDir: builtInProfilesDir } : {}),\n\t\t\t\t\t\t});\n\t\t\t\t\t\tawait module.runFlowProfileCommand(payload, ctx, { store });\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tctx.ui.notify(\n\t\t\t\t\t\t\t`/flow profile failed: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t\t\t\t\t\"error\",\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (LOADED_RUN_COMMANDS.has(command) && !loaded) {\n\t\t\t\t\tctx.ui.notify(NO_LOADED_RUN_COPY[command] ?? \"No active Flow run.\", \"info\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tlet commands: Map<string, CommandOptions>;\n\t\t\t\ttry {\n\t\t\t\t\tcommands = await load();\n\t\t\t\t} catch (error) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tctx.ui.notify(\n\t\t\t\t\t\t\t`Failed to load Flow: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t\t\t\t\t\"error\",\n\t\t\t\t\t\t);\n\t\t\t\t\t} finally {\n\t\t\t\t\t\tawait settleRefusal(command, ctx, \"internal\");\n\t\t\t\t\t}\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst real = commands.get(\"flow\");\n\t\t\t\tif (!real) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tctx.ui.notify(flowBuildUnavailable(command), \"error\");\n\t\t\t\t\t} finally {\n\t\t\t\t\t\tawait settleRefusal(command, ctx, \"internal\");\n\t\t\t\t\t}\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\t// Flow's own dispatcher re-parses the original arguments and slices the payload itself.\n\t\t\t\tawait real.handler(args, ctx);\n\t\t\t},\n\t\t});\n\t};\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"node-provider.d.ts","sourceRoot":"","sources":["../../src/humain/node-provider.ts"],"names":[],"mappings":"AACA,OAAO,EAQN,KAAK,QAAQ,EAEb,MAAM,uBAAuB,CAAC;AAM/B,OAAO,EACN,0BAA0B,EAC1B,KAAK,kBAAkB,EACvB,KAAK,wBAAwB,GAC7B,MAAM,2BAA2B,CAAC;AAEnC,eAAO,MAAM,oBAAoB,gBAAgB,CAAC;AAuDlD,2HAA2H;AAC3H,wBAAgB,0BAA0B,CACzC,aAAa,EAAE,MAAM,GAAG,SAAS,EACjC,cAAc,EAAE,MAAM,GAAG,SAAS,GAChC,MAAM,GAAG,SAAS,CAMpB;AAED,eAAO,MAAM,wBAAwB,yBAAe,CAAC;AAuRrD,wBAAgB,wBAAwB,CAAC,GAAG,GAAE,MAAM,CAAC,UAAwB,GAAG,QAAQ,CAgGvF"}
1
+ {"version":3,"file":"node-provider.d.ts","sourceRoot":"","sources":["../../src/humain/node-provider.ts"],"names":[],"mappings":"AACA,OAAO,EAQN,KAAK,QAAQ,EAEb,MAAM,uBAAuB,CAAC;AAM/B,OAAO,EACN,0BAA0B,EAC1B,KAAK,kBAAkB,EACvB,KAAK,wBAAwB,GAC7B,MAAM,2BAA2B,CAAC;AAEnC,eAAO,MAAM,oBAAoB,gBAAgB,CAAC;AAuDlD,2HAA2H;AAC3H,wBAAgB,0BAA0B,CACzC,aAAa,EAAE,MAAM,GAAG,SAAS,EACjC,cAAc,EAAE,MAAM,GAAG,SAAS,GAChC,MAAM,GAAG,SAAS,CAMpB;AAED,eAAO,MAAM,wBAAwB,yBAAe,CAAC;AAyRrD,wBAAgB,wBAAwB,CAAC,GAAG,GAAE,MAAM,CAAC,UAAwB,GAAG,QAAQ,CAgGvF"}
@@ -215,6 +215,8 @@ function toModel(value, baseUrl) {
215
215
  supportsStrictMode: false,
216
216
  supportsLongCacheRetention: false,
217
217
  maxTokensField: maxTokensField(id),
218
+ // MiniMax returns reasoning inline as a leading <think>...</think> in content.
219
+ ...(/minimax/i.test(id) ? { inlineThinkTags: true } : {}),
218
220
  },
219
221
  }
220
222
  : {}),