@humain/humain-code 0.4.9 → 0.4.10

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 (112) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/bundle/agent-monitor.js +1 -1
  3. package/dist/bundle/chunks/bedrock-converse-stream.js +39 -45
  4. package/dist/bundle/chunks/{chunk-6FVNSW6B.js → chunk-2QTTNAD4.js} +3353 -3938
  5. package/dist/bundle/chunks/chunk-76X5KOIA.js +28 -0
  6. package/dist/bundle/chunks/{chunk-KRMTBTWU.js → chunk-77EWF2NW.js} +1 -1
  7. package/dist/bundle/chunks/{chunk-RBKDBF5G.js → chunk-AS2Y2MO6.js} +36 -36
  8. package/dist/bundle/chunks/{chunk-4LAKI5IL.js → chunk-AUFEF24K.js} +1 -1
  9. package/dist/bundle/chunks/{chunk-P4YMUUSK.js → chunk-BCF7KZ3R.js} +739 -730
  10. package/dist/bundle/chunks/{chunk-W2QRCQBX.js → chunk-FF26YENK.js} +3 -4
  11. package/dist/bundle/chunks/{chunk-UZ5FVVCP.js → chunk-HMWAH7ZY.js} +1 -1
  12. package/dist/bundle/chunks/{chunk-F7UMX5BV.js → chunk-HSDTSUZE.js} +13 -2
  13. package/dist/bundle/chunks/chunk-I2ZWZAIV.js +751 -0
  14. package/dist/bundle/chunks/{chunk-GUUAEK6G.js → chunk-LCOHFEZZ.js} +1 -1
  15. package/dist/bundle/chunks/{chunk-Z5LYSSTY.js → chunk-QSPDLT2R.js} +2 -2
  16. package/dist/bundle/chunks/{chunk-UBQSONVR.js → chunk-R5VIAWGA.js} +103 -145
  17. package/dist/bundle/chunks/{chunk-EMYNPLY5.js → chunk-V5ZF7Q7L.js} +1 -1
  18. package/dist/bundle/chunks/{chunk-LQ4S7CRR.js → chunk-VYIIPF57.js} +1 -1
  19. package/dist/bundle/chunks/chunk-WBJN6PEI.js +43 -0
  20. package/dist/bundle/chunks/{chunk-SWRU4BOC.js → chunk-XGO43DKL.js} +1 -1
  21. package/dist/bundle/chunks/{chunk-PMISFIBM.js → chunk-XMHLSV3I.js} +1 -1
  22. package/dist/bundle/chunks/{chunk-3E4SMILM.js → chunk-YJBE3IGR.js} +14 -14
  23. package/dist/bundle/chunks/{cli-ZKT34WPW.js → cli-5ACW3WND.js} +2 -2
  24. package/dist/bundle/chunks/{compat-HEUVP6UJ.js → compat-TQKA4I7M.js} +1 -1
  25. package/dist/bundle/chunks/{dist-NU2EIVT6.js → dist-WHC67QRM.js} +676 -550
  26. package/dist/bundle/chunks/dist-cjs-RL2OCAP2.js +179 -0
  27. package/dist/bundle/chunks/{easter-egg-3d-5KKDWEIA.js → easter-egg-3d-3L3IKAT6.js} +1 -1
  28. package/dist/bundle/chunks/{esm-NCUV2DF7.js → esm-763X2IA7.js} +1 -1
  29. package/dist/bundle/chunks/event-streams-R5OECII4.js +2 -0
  30. package/dist/bundle/chunks/{execute-OSBDNQU5.js → execute-4X6G65NZ.js} +1 -1
  31. package/dist/bundle/chunks/{extract-PYRMDATF.js → extract-DLZ425VI.js} +4 -4
  32. package/dist/bundle/chunks/github-copilot.js +32 -31
  33. package/dist/bundle/chunks/{google-generative-ai-H2F5Y5H2.js → google-generative-ai-JD2FVOIX.js} +1 -1
  34. package/dist/bundle/chunks/{google-vertex-LFWD2AOO.js → google-vertex-PFBMDCBW.js} +1 -1
  35. package/dist/bundle/chunks/{host-6ZA6LK4C.js → host-4J7H7KDS.js} +1 -1
  36. package/dist/bundle/chunks/{node-XGNY74WT.js → node-W47VUEGE.js} +1 -1
  37. package/dist/bundle/chunks/{runtime-JFLZUNYP.js → runtime-SI76JZNE.js} +1 -1
  38. package/dist/bundle/chunks/virtual-modules-ID2GA4GE.js +5 -0
  39. package/dist/bundle/cli-runtime.js +3 -3
  40. package/dist/bundle/flow/package.json +1 -1
  41. package/dist/bundle/index.js +17 -17
  42. package/dist/bundle/rpc-entry.js +3 -2
  43. package/dist/core/account-reporting.d.ts +109 -0
  44. package/dist/core/account-reporting.d.ts.map +1 -0
  45. package/dist/core/account-reporting.js +328 -0
  46. package/dist/core/account-reporting.js.map +1 -0
  47. package/dist/core/agent-session.d.ts +22 -2
  48. package/dist/core/agent-session.d.ts.map +1 -1
  49. package/dist/core/agent-session.js +131 -0
  50. package/dist/core/agent-session.js.map +1 -1
  51. package/dist/core/anthropic-account-reporting.d.ts +76 -0
  52. package/dist/core/anthropic-account-reporting.d.ts.map +1 -0
  53. package/dist/core/anthropic-account-reporting.js +380 -0
  54. package/dist/core/anthropic-account-reporting.js.map +1 -0
  55. package/dist/core/bedrock-account-reporting.d.ts +82 -0
  56. package/dist/core/bedrock-account-reporting.d.ts.map +1 -0
  57. package/dist/core/bedrock-account-reporting.js +402 -0
  58. package/dist/core/bedrock-account-reporting.js.map +1 -0
  59. package/dist/core/model-runtime.d.ts +17 -0
  60. package/dist/core/model-runtime.d.ts.map +1 -1
  61. package/dist/core/model-runtime.js +64 -10
  62. package/dist/core/model-runtime.js.map +1 -1
  63. package/dist/core/oauth-account-pool.d.ts +4 -0
  64. package/dist/core/oauth-account-pool.d.ts.map +1 -1
  65. package/dist/core/oauth-account-pool.js +10 -3
  66. package/dist/core/oauth-account-pool.js.map +1 -1
  67. package/dist/humain/flow-accounts-host.d.ts +120 -0
  68. package/dist/humain/flow-accounts-host.d.ts.map +1 -0
  69. package/dist/humain/flow-accounts-host.js +346 -0
  70. package/dist/humain/flow-accounts-host.js.map +1 -0
  71. package/dist/humain/flow-command.d.ts +28 -0
  72. package/dist/humain/flow-command.d.ts.map +1 -0
  73. package/dist/humain/flow-command.js +226 -0
  74. package/dist/humain/flow-command.js.map +1 -0
  75. package/dist/humain/flow-loader.d.ts +4 -2
  76. package/dist/humain/flow-loader.d.ts.map +1 -1
  77. package/dist/humain/flow-loader.js +120 -91
  78. package/dist/humain/flow-loader.js.map +1 -1
  79. package/dist/humain/node-account-failure.d.ts +18 -0
  80. package/dist/humain/node-account-failure.d.ts.map +1 -0
  81. package/dist/humain/node-account-failure.js +73 -0
  82. package/dist/humain/node-account-failure.js.map +1 -0
  83. package/dist/humain/node-account-fallback.d.ts +85 -0
  84. package/dist/humain/node-account-fallback.d.ts.map +1 -0
  85. package/dist/humain/node-account-fallback.js +175 -0
  86. package/dist/humain/node-account-fallback.js.map +1 -0
  87. package/dist/humain/node-http.d.ts.map +1 -1
  88. package/dist/humain/node-http.js +11 -0
  89. package/dist/humain/node-http.js.map +1 -1
  90. package/dist/humain/node-provider.d.ts +4 -0
  91. package/dist/humain/node-provider.d.ts.map +1 -1
  92. package/dist/humain/node-provider.js +11 -0
  93. package/dist/humain/node-provider.js.map +1 -1
  94. package/dist/index.d.ts +4 -0
  95. package/dist/index.d.ts.map +1 -1
  96. package/dist/index.js.map +1 -1
  97. package/dist/modes/interactive/components/login-dialog.d.ts +2 -0
  98. package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
  99. package/dist/modes/interactive/components/login-dialog.js +5 -0
  100. package/dist/modes/interactive/components/login-dialog.js.map +1 -1
  101. package/dist/modes/interactive/interactive-mode.d.ts +26 -0
  102. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  103. package/dist/modes/interactive/interactive-mode.js +242 -19
  104. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  105. package/docs/flow-profiles.md +57 -5
  106. package/docs/flow.md +119 -37
  107. package/docs/providers.md +37 -0
  108. package/npm-shrinkwrap.json +48 -6
  109. package/package.json +3 -2
  110. package/dist/bundle/chunks/chunk-JOKJ3CEL.js +0 -27
  111. package/dist/bundle/chunks/event-streams-CGCQQL5M.js +0 -2
  112. package/dist/bundle/chunks/virtual-modules-NPWQ6NBS.js +0 -5
@@ -0,0 +1,226 @@
1
+ import { sanitizeForTerminal } from "../core/trace-client/sanitize.js";
2
+ /**
3
+ * Static vocabulary, parsing, help and completion for the single `/flow` command. Pure and dependency-light on
4
+ * purpose: the lazy loader uses it before (and without) importing Flow, so help works when Flow is disabled.
5
+ */
6
+ export const FLOW_SUBCOMMANDS = [
7
+ "help",
8
+ "run",
9
+ "continue",
10
+ "list",
11
+ "status",
12
+ "cancel",
13
+ "pause",
14
+ "resume",
15
+ "title",
16
+ "message",
17
+ "hide",
18
+ "show",
19
+ "models",
20
+ "profile",
21
+ "setup",
22
+ ];
23
+ /** Refusal for `/flow setup` outside the terminal UI: secure account dialogs exist only there. */
24
+ export const FLOW_SETUP_TERMINAL_ONLY = "/flow setup needs the interactive terminal. Use /flow models and /flow profile for changes from other modes.";
25
+ /** Commands that take no arguments. */
26
+ const NO_ARGUMENT_SUBCOMMANDS = new Set([
27
+ "list",
28
+ "status",
29
+ "cancel",
30
+ "pause",
31
+ "resume",
32
+ "hide",
33
+ "show",
34
+ "setup",
35
+ ]);
36
+ const SUMMARIES = {
37
+ help: "Show usage and examples",
38
+ run: "Start work",
39
+ continue: "Recover an interrupted run",
40
+ list: "Find recent runs and run IDs",
41
+ status: "View progress",
42
+ cancel: "Stop the active run",
43
+ pause: "Pause new work",
44
+ resume: "Resume paused work",
45
+ title: "Rename the active run",
46
+ message: "Send guidance",
47
+ hide: "Hide the widget; work continues",
48
+ show: "Show the active run's widget",
49
+ models: "Manage model choices",
50
+ profile: "Manage run profiles",
51
+ setup: "Connect providers and configure Flow",
52
+ };
53
+ const MODELS_SUBCOMMANDS = [
54
+ "show",
55
+ "list",
56
+ "validate",
57
+ "check",
58
+ "set",
59
+ "effort",
60
+ "use",
61
+ "new",
62
+ "pick",
63
+ "convert",
64
+ "workflow",
65
+ ];
66
+ const PROFILE_SUBCOMMANDS = ["list", "show", "use", "export", "import", "validate"];
67
+ const isSubcommand = (value) => FLOW_SUBCOMMANDS.includes(value);
68
+ /** Copy for a recognized subcommand this build does not implement yet. */
69
+ export function flowBuildUnavailable(command) {
70
+ return `/flow ${sanitizeForTerminal(command)} is not available in this build. Use /flow help to see supported commands.`;
71
+ }
72
+ /**
73
+ * Splits `/flow` arguments into subcommand and payload. Consumes the subcommand and exactly one separating
74
+ * whitespace character; the rest of the payload is returned byte-for-byte so goal, message and title text is
75
+ * never split or rejoined. Bare or whitespace-only input means help.
76
+ */
77
+ export function parseFlowCommand(args) {
78
+ const match = /^\s*(\S+)([\s\S]*)$/.exec(args);
79
+ if (!match)
80
+ return { command: "help", payload: "" };
81
+ const [, name, rest] = match;
82
+ if (!isSubcommand(name)) {
83
+ return {
84
+ error: `Unknown Flow command: ${sanitizeForTerminal(name).slice(0, 80)}. Use /flow help to see available commands. To start work: /flow run <goal>`,
85
+ };
86
+ }
87
+ const payload = /^\s/.test(rest) ? rest.slice(1) : rest;
88
+ const trimmed = payload.trim();
89
+ if (name === "help" && trimmed) {
90
+ if (/\s/.test(trimmed))
91
+ return { error: "/flow help accepts at most one topic. Usage: /flow help [topic]" };
92
+ if (!isSubcommand(trimmed)) {
93
+ return {
94
+ error: `No help topic named “${sanitizeForTerminal(trimmed).slice(0, 80)}”. Use /flow help to see available commands.`,
95
+ };
96
+ }
97
+ }
98
+ if (NO_ARGUMENT_SUBCOMMANDS.has(name) && trimmed) {
99
+ return { error: `/flow ${name} does not accept arguments. Usage: /flow ${name}` };
100
+ }
101
+ if (name === "continue" && /\s/.test(trimmed)) {
102
+ // `command` lets the loader settle the refused start over rpc.
103
+ return { error: "/flow continue accepts at most one run ID. Usage: /flow continue [run-id]", command: name };
104
+ }
105
+ return { command: name, payload };
106
+ }
107
+ const helpRow = (usage, command) => `${` ${usage}`.padEnd(27)}${SUMMARIES[command]}`;
108
+ const GENERAL_HELP = [
109
+ "Flow — plan, run, and verify work with agents.",
110
+ "",
111
+ "Start work",
112
+ " /flow run <goal> [flags]",
113
+ "",
114
+ "Manage a run",
115
+ helpRow("/flow list", "list"),
116
+ helpRow("/flow status", "status"),
117
+ helpRow("/flow cancel", "cancel"),
118
+ helpRow("/flow pause", "pause"),
119
+ helpRow("/flow resume", "resume"),
120
+ helpRow("/flow continue [run-id]", "continue"),
121
+ helpRow("/flow title <title>", "title"),
122
+ helpRow("/flow message <text>", "message"),
123
+ helpRow("/flow hide", "hide"),
124
+ helpRow("/flow show", "show"),
125
+ "",
126
+ "Configure",
127
+ helpRow("/flow setup", "setup"),
128
+ helpRow("/flow models <command>", "models"),
129
+ helpRow("/flow profile <command>", "profile"),
130
+ "",
131
+ "Learn more",
132
+ " /flow help <command> Show usage and examples",
133
+ "",
134
+ "Example",
135
+ " /flow run Fix the login timeout --risk medium",
136
+ ].join("\n");
137
+ const RUN_FLAGS = [
138
+ "Flags:",
139
+ " --task-class T --complexity N --risk low|medium|high|critical",
140
+ " --profile ID --lead-size small|standard|large --workflow direct|checked|led|full --effort LEVEL",
141
+ " --cheap ALIAS --mid ALIAS --premium ALIAS --frontier ALIAS --model <capability>=ALIAS",
142
+ " --quality-floor F --cost-aggressiveness C --max-retries R --fan-out",
143
+ " --context FILE ... --with-last-reply --force --route-only --candidate PATH",
144
+ " --live-qa --no-live-qa --live-qa-adapter ID --live-qa-scope SCOPE --live-qa-acceptance FILE",
145
+ ].join("\n");
146
+ const TOPIC_HELP = {
147
+ help: "Show help\n\nUsage:\n /flow help [command]",
148
+ run: [
149
+ "Start a Flow run",
150
+ "",
151
+ "Usage:",
152
+ " /flow run <goal> [flags]",
153
+ "",
154
+ "Example:",
155
+ " /flow run Fix the login timeout --risk medium",
156
+ "",
157
+ "Describe the outcome you want. Flow plans the work,",
158
+ "dispatches agents, and verifies the result.",
159
+ "",
160
+ RUN_FLAGS,
161
+ ].join("\n"),
162
+ continue: "Recover an interrupted run\n\nUsage:\n /flow continue [run-id]\n\nRecovery requires a safety check and your confirmation.",
163
+ list: [
164
+ "Find recent runs and run IDs",
165
+ "",
166
+ "Usage:",
167
+ " /flow list",
168
+ "",
169
+ "History examines up to 200 runs by creation time.",
170
+ "Runs without readable execution snapshots are omitted.",
171
+ "Listing does not recover a run or claim ownership.",
172
+ ].join("\n"),
173
+ status: "View progress of the active run\n\nUsage:\n /flow status",
174
+ cancel: "Stop the active run\n\nUsage:\n /flow cancel",
175
+ pause: "Pause new work. Running agents finish their current turn. No new agents will start.\n\nUsage:\n /flow pause",
176
+ resume: "Resume paused work\n\nUsage:\n /flow resume",
177
+ title: "Rename the active run\n\nUsage:\n /flow title <title>",
178
+ message: "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.",
179
+ hide: "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",
180
+ show: "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",
181
+ models: `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`,
182
+ profile: `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`,
183
+ // The account sentence must equal FLOW_ACCOUNT_PERSISTENCE_NOTICE; humain-flow-command.test.ts enforces it.
184
+ setup: `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`,
185
+ };
186
+ /** Static help text. An unrecognized topic yields the unknown-topic copy; the parser rejects those before this. */
187
+ export function renderFlowHelp(topic) {
188
+ const name = topic?.trim();
189
+ if (!name)
190
+ return GENERAL_HELP;
191
+ if (!isSubcommand(name)) {
192
+ return `No help topic named “${sanitizeForTerminal(name).slice(0, 80)}”. Use /flow help to see available commands.`;
193
+ }
194
+ return TOPIC_HELP[name];
195
+ }
196
+ /** Static completion for the argument text after `/flow `: subcommands, then help topics and nested names. */
197
+ export function completeFlowArguments(prefix) {
198
+ const words = prefix.trimStart().split(/\s+/);
199
+ const [first = "", second] = words;
200
+ const items = [];
201
+ if (words.length === 1) {
202
+ for (const command of FLOW_SUBCOMMANDS) {
203
+ if (command.startsWith(first)) {
204
+ items.push({
205
+ value: command,
206
+ label: command,
207
+ description: SUMMARIES[command],
208
+ });
209
+ }
210
+ }
211
+ }
212
+ else if (words.length === 2 && first === "help") {
213
+ for (const command of FLOW_SUBCOMMANDS) {
214
+ if (command.startsWith(second ?? ""))
215
+ items.push({ value: `help ${command}`, label: command, description: SUMMARIES[command] });
216
+ }
217
+ }
218
+ else if (words.length === 2 && (first === "models" || first === "profile")) {
219
+ for (const name of first === "models" ? MODELS_SUBCOMMANDS : PROFILE_SUBCOMMANDS) {
220
+ if (name.startsWith(second ?? ""))
221
+ items.push({ value: `${first} ${name}`, label: name });
222
+ }
223
+ }
224
+ return items.length > 0 ? items : null;
225
+ }
226
+ //# sourceMappingURL=flow-command.js.map
@@ -0,0 +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,MAAM;IACN,MAAM;IACN,OAAO;CACP,CAAC,CAAC;AAEH,MAAM,SAAS,GAAmC;IACjD,IAAI,EAAE,yBAAyB;IAC/B,GAAG,EAAE,YAAY;IACjB,QAAQ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AC,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"]}
@@ -3,8 +3,10 @@ import type { ExtensionCommandContext, ExtensionFactory } from "../core/extensio
3
3
  /**
4
4
  * Lazy loader for the private @humain/flow package.
5
5
  *
6
- * The CLI entry graph must not statically reach Flow: this module registers cheap stub commands and a flag, and
7
- * only loads Flow (one memoized dynamic import) the first time a stub runs. Flow is bundled as its own chunk.
6
+ * The CLI entry graph must not statically reach Flow: this module registers one cheap `/flow` stub and two flags, and
7
+ * only loads Flow (one memoized dynamic import) the first time a subcommand needs it. Help, completion, unknown
8
+ * commands and not-yet-available commands are answered statically and never import Flow. Flow is bundled as its own
9
+ * chunk.
8
10
  */
9
11
  export declare const HUMAIN_FLOW_DISABLED_ENV = "HUMAIN_TERMINAL_FLOW_DISABLED";
10
12
  export declare const HUMAIN_FLOW_PACKAGE_DIR_ENV = "HUMAIN_TERMINAL_FLOW_PACKAGE_DIR";
@@ -1 +1 @@
1
- {"version":3,"file":"flow-loader.d.ts","sourceRoot":"","sources":["../../src/humain/flow-loader.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,4CAA4C,CAAC;AAEhH,OAAO,KAAK,EAEX,uBAAuB,EACvB,gBAAgB,EAEhB,MAAM,6BAA6B,CAAC;AAIrC;;;;;GAKG;AAEH,eAAO,MAAM,wBAAwB,kCAAkC,CAAC;AACxE,eAAO,MAAM,2BAA2B,qCAAqC,CAAC;AAE9E,8FAA8F;AAC9F,MAAM,WAAW,cAAc;IAC9B,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC;QAAE,OAAO,EAAE,aAAa,CAAC;QAAC,MAAM,CAAC,EAAE,YAAY,CAAA;KAAE,CAAC,CAA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AC,CAAC,GAAG,SAAS,GAAG,IAAI,CAE7F;AAqPD,wBAAgB,sCAAsC,CAAC,OAAO,GAAE,uBAA4B,GAAG,gBAAgB,CAyJ9G"}
@@ -4,11 +4,14 @@ import { dirname, isAbsolute, join, resolve } from "node:path";
4
4
  import { getAgentDir, getBundledFlowPackageDir, getBundledFlowProfilesDir, PACKAGE_NAME, VERSION } from "../config.js";
5
5
  import { createTraceRedactor } from "../core/trace/redaction.js";
6
6
  import { sanitizeForTerminal } from "../core/trace-client/sanitize.js";
7
+ import { completeFlowArguments, FLOW_SETUP_TERMINAL_ONLY, flowBuildUnavailable, parseFlowCommand, renderFlowHelp, } from "./flow-command.js";
7
8
  /**
8
9
  * Lazy loader for the private @humain/flow package.
9
10
  *
10
- * The CLI entry graph must not statically reach Flow: this module registers cheap stub commands and a flag, and
11
- * only loads Flow (one memoized dynamic import) the first time a stub runs. Flow is bundled as its own chunk.
11
+ * The CLI entry graph must not statically reach Flow: this module registers one cheap `/flow` stub and two flags, and
12
+ * only loads Flow (one memoized dynamic import) the first time a subcommand needs it. Help, completion, unknown
13
+ * commands and not-yet-available commands are answered statically and never import Flow. Flow is bundled as its own
14
+ * chunk.
12
15
  */
13
16
  export const HUMAIN_FLOW_DISABLED_ENV = "HUMAIN_TERMINAL_FLOW_DISABLED";
14
17
  export const HUMAIN_FLOW_PACKAGE_DIR_ENV = "HUMAIN_TERMINAL_FLOW_PACKAGE_DIR";
@@ -66,36 +69,34 @@ const STAGED_MEMBERS = new Set([
66
69
  "registerVirtualModel",
67
70
  "unregisterVirtualModel",
68
71
  ]);
69
- // Descriptions match the real Flow commands (packages/flow/src). flow-profile is served here through Flow's
70
- // runFlowProfileCommand.
71
- const STUB_COMMANDS = {
72
- flow: "Plan and dispatch a hierarchical agent run. " +
73
- "Args: <goal> [--task-class T] [--complexity N] [--risk low|medium|high|critical] " +
74
- "[--profile NAME] [--lead-size small|standard|large] [--cheap ALIAS] [--mid ALIAS] [--premium ALIAS] [--frontier ALIAS] [--model <capability>=ALIAS] [--effort LEVEL] " +
75
- "[--quality-floor F] [--cost-aggressiveness C] [--max-retries R] [--flow-admission FILE] " +
76
- "[--context FILE ...] [--with-last-reply] [--force]\n\n" +
77
- "With no triage flags, an LLM triage call (cheapest configured model) " +
78
- "auto-fills task_class, complexity, and risk from the goal text. " +
79
- "Models: flags > profile (orchestrator-profiles.json) > cost-tier resolver. See /flow-models.",
80
- "flow-continue": "Preview and explicitly confirm recovery in the original checkout. Args: [run-id] (no --yes or --force).",
81
- "flow-status": "Open the full live orchestration board (↑↓ PgUp/PgDn scroll, Esc closes without cancelling).",
82
- "flow-cancel": "Cancel the currently running /flow run, if any.",
83
- "flow-pause": "Pause the currently running /flow run, if any.",
84
- "flow-resume": "Resume a paused /flow run.",
85
- "flow-title": "Rename the active flow and display its title on the widget border.",
86
- "flow-models": "Manage which models /flow uses. Subcommands: show|list|validate [--live]|check|set|effort|use|new|pick|workflow. " +
87
- "Aliases like fable-5-1, opus-5-5, sonnet-5, gpt-6-sol, gpt-6-luna, astra resolve against your configured models.",
88
- "flow-profile": "List, show, select, import or edit Flow profiles. Args: [list|show|use|export|import|validate ...]",
89
- omsg: "Send a message to the running orchestration (queued, delivered to the next dispatched task). " +
90
- "Usage: /omsg <text> — the lead will see and respond to it. Use '\\n' for newlines if needed.",
91
- };
72
+ const FLOW_DESCRIPTION = "Plan, run, and verify work with agents. Subcommands: run, continue, list, status, cancel, pause, resume, " +
73
+ "title, message, hide, show, models, profile, setup. Use /flow help for usage.";
92
74
  /**
93
75
  * Act on an already loaded run only; with Flow not loaded there is no run, so Flow is never imported for them. They
94
- * stay reachable when Flow is disabled so a live run can still be stopped. Every other stub is refused when disabled.
76
+ * stay reachable when Flow is disabled so a live run can still be stopped. Every other subcommand is refused when
77
+ * disabled.
95
78
  */
96
- const LOADED_RUN_COMMANDS = new Set(["flow-cancel", "flow-status", "flow-pause", "flow-resume"]);
97
- /** Kill switch: resume would restart dispatch, so it is refused while Flow is disabled (cancel, status and pause are not). */
98
- const AVAILABLE_WHEN_DISABLED = new Set(["flow-cancel", "flow-status", "flow-pause"]);
79
+ const LOADED_RUN_COMMANDS = new Set([
80
+ "cancel",
81
+ "status",
82
+ "pause",
83
+ "resume",
84
+ "hide",
85
+ "show",
86
+ ]);
87
+ /** Kill switch: resume would restart dispatch, so it is refused while Flow is disabled (the others are not). */
88
+ const AVAILABLE_WHEN_DISABLED = new Set(["cancel", "status", "pause", "hide", "show"]);
89
+ /** Copy when a loaded-run command finds no Flow loaded, so there is nothing to act on. */
90
+ const NO_LOADED_RUN_COPY = {
91
+ cancel: "No active Flow run to stop.",
92
+ status: "No active Flow run. Start one with /flow run <goal>.",
93
+ pause: "No active Flow run to pause.",
94
+ resume: "No paused Flow run to resume.",
95
+ hide: "No current Flow widget to hide.",
96
+ show: "No current Flow widget to show.",
97
+ };
98
+ /** Only these start (or recover) work, so only their refusals settle an rpc run. */
99
+ const START_COMMANDS = new Set(["run", "continue"]);
99
100
  function isRecord(value) {
100
101
  return typeof value === "object" && value !== null;
101
102
  }
@@ -129,14 +130,16 @@ function withHeadlessNotices(ctx) {
129
130
  return wrapped;
130
131
  }
131
132
  /**
132
- * Mirrors packages/flow emitRefusalSettled: an rpc /flow start that dispatches nothing still emits one terminal
133
+ * Mirrors packages/flow emitRefusalSettled: an rpc `/flow run` or `/flow continue` that dispatches nothing still emits one terminal
133
134
  * `run_settled` frame so the host stops waiting. Built here because the entry graph must not reach @humain/flow.
134
135
  * Print/json refusals exit non-zero (mirrors flow's markHeadlessFailure). Never throws; no-op otherwise.
135
136
  */
136
- async function settleRefusal(name, ctx, failureClass) {
137
- if ((name === "flow" || name === "flow-continue") && (ctx.mode === "print" || ctx.mode === "json"))
137
+ async function settleRefusal(command, ctx, failureClass) {
138
+ if (!START_COMMANDS.has(command))
139
+ return;
140
+ if (ctx.mode === "print" || ctx.mode === "json")
138
141
  process.exitCode = 1;
139
- if (ctx.mode !== "rpc" || !rpcOutput || (name !== "flow" && name !== "flow-continue"))
142
+ if (ctx.mode !== "rpc" || !rpcOutput)
140
143
  return;
141
144
  try {
142
145
  const runId = `flow-refused-${randomBytes(8).toString("hex")}`;
@@ -181,7 +184,7 @@ function disabledReason(pi, env) {
181
184
  return undefined;
182
185
  }
183
186
  /**
184
- * Run flowExtension against a staging proxy. Stub commands are captured (so names never double-register); every other
187
+ * Run flowExtension against a staging proxy. The `/flow` command is captured (so names never double-register); every other
185
188
  * registration is recorded and applied to the real pi only after the factory and the session_start replay succeed, so
186
189
  * a failed attempt leaves nothing behind and a retry starts from scratch. Late registration is supported by the
187
190
  * extension loader (handlers, tools, commands and flags are written to the live extension object), but
@@ -200,7 +203,7 @@ async function runFlowExtension(pi, flowExtension, lastSessionStart) {
200
203
  get(target, prop) {
201
204
  if (!live && typeof prop === "string" && STAGED_MEMBERS.has(prop)) {
202
205
  return (...args) => {
203
- if (prop === "registerCommand" && typeof args[0] === "string" && args[0] in STUB_COMMANDS) {
206
+ if (prop === "registerCommand" && args[0] === "flow") {
204
207
  captured.set(args[0], args[1]);
205
208
  return undefined;
206
209
  }
@@ -335,70 +338,96 @@ export function createHumainFlowLoaderExtensionFactory(options = {}) {
335
338
  }
336
339
  return loaded;
337
340
  };
338
- for (const [name, description] of Object.entries(STUB_COMMANDS)) {
339
- pi.registerCommand(name, {
340
- description,
341
- handler: async (args, rawCtx) => {
342
- const ctx = withHeadlessNotices(rawCtx);
343
- const reason = AVAILABLE_WHEN_DISABLED.has(name) ? undefined : disabledReason(pi, env);
344
- if (reason) {
345
- try {
346
- ctx.ui.notify(`Flow disabled (${reason}). /${name} is unavailable.`, "warning");
347
- }
348
- finally {
349
- await settleRefusal(name, ctx, "config_invalid");
350
- }
351
- return;
341
+ pi.registerCommand("flow", {
342
+ description: FLOW_DESCRIPTION,
343
+ getArgumentCompletions: completeFlowArguments,
344
+ handler: async (args, rawCtx) => {
345
+ const ctx = withHeadlessNotices(rawCtx);
346
+ const refuse = (message, level) => {
347
+ if (ctx.mode === "print" || ctx.mode === "json")
348
+ process.exitCode = 1;
349
+ ctx.ui.notify(message, level);
350
+ };
351
+ const parsed = parseFlowCommand(args);
352
+ if ("error" in parsed) {
353
+ try {
354
+ refuse(parsed.error, "error");
352
355
  }
353
- if (name === "flow-profile") {
354
- try {
355
- const module = await loadModule();
356
- if (!module.runFlowProfileCommand || !module.createProfileStore) {
357
- ctx.ui.notify("/flow-profile is not available in this Flow build", "error");
358
- return;
359
- }
360
- const store = module.createProfileStore({
361
- flowDir: options.flowDir ?? join(getAgentDir(), "flow"),
362
- ...(builtInProfilesDir !== undefined ? { builtInDir: builtInProfilesDir } : {}),
363
- });
364
- await module.runFlowProfileCommand(args, ctx, { store });
365
- }
366
- catch (error) {
367
- ctx.ui.notify(`/flow-profile failed: ${error instanceof Error ? error.message : String(error)}`, "error");
368
- }
369
- return;
356
+ finally {
357
+ if (parsed.command)
358
+ await settleRefusal(parsed.command, ctx, "config_invalid");
370
359
  }
371
- if (LOADED_RUN_COMMANDS.has(name) && !loaded) {
372
- ctx.ui.notify("no active run", "info");
373
- return;
360
+ return;
361
+ }
362
+ const { command, payload } = parsed;
363
+ if (command === "help") {
364
+ ctx.ui.notify(renderFlowHelp(payload.trim() || undefined), "info");
365
+ return;
366
+ }
367
+ // Secure account dialogs exist only in the terminal UI: refuse elsewhere before loading Flow.
368
+ if (command === "setup" && ctx.mode !== "tui") {
369
+ refuse(FLOW_SETUP_TERMINAL_ONLY, "error");
370
+ return;
371
+ }
372
+ const reason = AVAILABLE_WHEN_DISABLED.has(command) ? undefined : disabledReason(pi, env);
373
+ if (reason) {
374
+ try {
375
+ ctx.ui.notify(`Flow disabled (${reason}). /flow ${command} is unavailable.`, "warning");
374
376
  }
375
- let commands;
377
+ finally {
378
+ await settleRefusal(command, ctx, "config_invalid");
379
+ }
380
+ return;
381
+ }
382
+ if (command === "profile") {
376
383
  try {
377
- commands = await load();
384
+ const module = await loadModule();
385
+ if (!module.runFlowProfileCommand || !module.createProfileStore) {
386
+ ctx.ui.notify(flowBuildUnavailable(command), "error");
387
+ return;
388
+ }
389
+ const store = module.createProfileStore({
390
+ flowDir: options.flowDir ?? join(getAgentDir(), "flow"),
391
+ ...(builtInProfilesDir !== undefined ? { builtInDir: builtInProfilesDir } : {}),
392
+ });
393
+ await module.runFlowProfileCommand(payload, ctx, { store });
378
394
  }
379
395
  catch (error) {
380
- try {
381
- ctx.ui.notify(`Failed to load Flow: ${error instanceof Error ? error.message : String(error)}`, "error");
382
- }
383
- finally {
384
- await settleRefusal(name, ctx, "internal");
385
- }
386
- return;
396
+ ctx.ui.notify(`/flow profile failed: ${error instanceof Error ? error.message : String(error)}`, "error");
387
397
  }
388
- const real = commands.get(name);
389
- if (!real) {
390
- try {
391
- ctx.ui.notify(`/${name} is not available yet`, "error");
392
- }
393
- finally {
394
- await settleRefusal(name, ctx, "internal");
395
- }
396
- return;
398
+ return;
399
+ }
400
+ if (LOADED_RUN_COMMANDS.has(command) && !loaded) {
401
+ ctx.ui.notify(NO_LOADED_RUN_COPY[command] ?? "No active Flow run.", "info");
402
+ return;
403
+ }
404
+ let commands;
405
+ try {
406
+ commands = await load();
407
+ }
408
+ catch (error) {
409
+ try {
410
+ ctx.ui.notify(`Failed to load Flow: ${error instanceof Error ? error.message : String(error)}`, "error");
397
411
  }
398
- await real.handler(args, ctx);
399
- },
400
- });
401
- }
412
+ finally {
413
+ await settleRefusal(command, ctx, "internal");
414
+ }
415
+ return;
416
+ }
417
+ const real = commands.get("flow");
418
+ if (!real) {
419
+ try {
420
+ ctx.ui.notify(flowBuildUnavailable(command), "error");
421
+ }
422
+ finally {
423
+ await settleRefusal(command, ctx, "internal");
424
+ }
425
+ return;
426
+ }
427
+ // Flow's own dispatcher re-parses the original arguments and slices the payload itself.
428
+ await real.handler(args, ctx);
429
+ },
430
+ });
402
431
  };
403
432
  }
404
433
  //# sourceMappingURL=flow-loader.js.map