@humain/humain-code 0.8.4 → 0.8.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/bundle/chunks/{chunk-4BNDLR6C.js → chunk-2RXTZK2V.js} +1 -1
- package/dist/bundle/chunks/{chunk-CIAXW64K.js → chunk-3OOOEJV4.js} +5 -5
- package/dist/bundle/chunks/{chunk-J5YFXMTM.js → chunk-53DWQSBC.js} +1 -1
- package/dist/bundle/chunks/{chunk-73YX5XGR.js → chunk-7XRMMCKG.js} +267 -251
- package/dist/bundle/chunks/{chunk-HWXQCJDP.js → chunk-BDNX23GT.js} +76 -71
- package/dist/bundle/chunks/{chunk-52642TYH.js → chunk-COZTJAOY.js} +54 -51
- package/dist/bundle/chunks/{chunk-SOE25WIS.js → chunk-EWPEY4F4.js} +789 -790
- package/dist/bundle/chunks/{chunk-ARTF7ZMQ.js → chunk-FHP5BULR.js} +1 -1
- package/dist/bundle/chunks/{chunk-XGSJX23G.js → chunk-N3W4ALAM.js} +1 -1
- package/dist/bundle/chunks/{chunk-OTVHRZ67.js → chunk-SASR4VNV.js} +1 -1
- package/dist/bundle/chunks/{chunk-EVDQRT3I.js → chunk-VWUEKLRH.js} +8 -8
- package/dist/bundle/chunks/{compat-7UJJAO4E.js → compat-2RC4CJNV.js} +1 -1
- package/dist/bundle/chunks/{dist-7PCCEUQF.js → dist-3DAGUOYC.js} +1 -1
- package/dist/bundle/chunks/{dist-I53JI67E.js → dist-K4QIXV5O.js} +5 -5
- package/dist/bundle/chunks/{doctor-KJVAYG3F.js → doctor-EH7X36SK.js} +2 -2
- package/dist/bundle/chunks/{flow-implementer-GE2ARQKR.js → flow-implementer-J6QTLBTH.js} +2 -2
- package/dist/bundle/chunks/{inprocess-MGMVI6HN.js → inprocess-OHNEKTFB.js} +3 -3
- package/dist/bundle/chunks/{interactive-mode-HHWOE4FD.js → interactive-mode-ZREVRX7W.js} +2 -2
- package/dist/bundle/chunks/{virtual-modules-UXSSFNV5.js → virtual-modules-6FVRJTM3.js} +3 -3
- package/dist/bundle/cli-runtime.js +2 -2
- package/dist/bundle/index.js +6 -6
- package/dist/bundle/rpc-entry.js +2 -2
- package/dist/core/bug-report.d.ts +24 -1
- package/dist/core/bug-report.d.ts.map +1 -1
- package/dist/core/bug-report.js +216 -19
- package/dist/core/bug-report.js.map +1 -1
- package/dist/core/extensions/containment.d.ts +26 -0
- package/dist/core/extensions/containment.d.ts.map +1 -0
- package/dist/core/extensions/containment.js +66 -0
- package/dist/core/extensions/containment.js.map +1 -0
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +65 -7
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +2 -1
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +55 -10
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/types.d.ts +5 -2
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/extensions/wrapper.d.ts.map +1 -1
- package/dist/core/extensions/wrapper.js +4 -1
- package/dist/core/extensions/wrapper.js.map +1 -1
- package/dist/humain/checklist/vendor/commands.d.ts.map +1 -1
- package/dist/humain/checklist/vendor/commands.js +20 -8
- package/dist/humain/checklist/vendor/commands.js.map +1 -1
- package/dist/humain/flow-loader.d.ts.map +1 -1
- package/dist/humain/flow-loader.js +31 -5
- package/dist/humain/flow-loader.js.map +1 -1
- package/dist/humain/web-access/vendor/index.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/index.js +11 -1
- package/dist/humain/web-access/vendor/index.js.map +1 -1
- package/dist/modes/interactive/bug-report.d.ts.map +1 -1
- package/dist/modes/interactive/bug-report.js +48 -12
- package/dist/modes/interactive/bug-report.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +3 -3
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +28 -46
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/docs/extensions.md +2 -0
- package/docs/flow.md +2 -0
- package/docs/humain-code.md +1 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/src/humain/web-access/UPSTREAM.md +8 -0
|
@@ -29,7 +29,7 @@ export function parseChecklistArgs(raw) {
|
|
|
29
29
|
}
|
|
30
30
|
const CHECKLIST_USAGE = "Usage: /checklist [show|hide|clear|add [text]|settings]";
|
|
31
31
|
/** Open the checklist in a centered TUI popup dialog (overlay modal). */
|
|
32
|
-
async function openChecklistDialog(ctx, deps) {
|
|
32
|
+
async function openChecklistDialog(ctx, deps, signal) {
|
|
33
33
|
if (ctx.mode !== "tui" || !ctx.hasUI) {
|
|
34
34
|
// No popup surface in print mode — fall back to a text summary.
|
|
35
35
|
const checklist = deps.getChecklist();
|
|
@@ -65,7 +65,7 @@ async function openChecklistDialog(ctx, deps) {
|
|
|
65
65
|
getMaxRows: () => dialogMaxRows(tui.terminal.rows),
|
|
66
66
|
}, opts, deps.getMetaEnabled());
|
|
67
67
|
}, { overlay: true, overlayOptions: { width: "70%", maxHeight: `${DIALOG_MAX_HEIGHT_PERCENT}%`, anchor: "center" } });
|
|
68
|
-
if (goSettings) {
|
|
68
|
+
if (goSettings && !signal.aborted) {
|
|
69
69
|
openSettingsScreen(ctx);
|
|
70
70
|
}
|
|
71
71
|
}
|
|
@@ -81,7 +81,7 @@ function describeAddErrors(errors) {
|
|
|
81
81
|
.join("; ");
|
|
82
82
|
}
|
|
83
83
|
/** `/checklist add [text]`: dialog in the TUI, direct add (auto id) when there is no dialog surface. */
|
|
84
|
-
async function runAddTask(ctx, deps, title) {
|
|
84
|
+
async function runAddTask(ctx, deps, title, signal) {
|
|
85
85
|
const checklist = deps.getChecklist();
|
|
86
86
|
const count = checklist?.tasks.length ?? 0;
|
|
87
87
|
if (count >= MAX_CHECKLIST_TASKS) {
|
|
@@ -102,6 +102,8 @@ async function runAddTask(ctx, deps, title) {
|
|
|
102
102
|
let added;
|
|
103
103
|
await ctx.ui.custom((tui, theme, _kb, done) => new AddTaskDialog(checklist, { title }, theme, {
|
|
104
104
|
onSubmit: (draft) => {
|
|
105
|
+
if (signal.aborted)
|
|
106
|
+
return { ok: false, errors: { form: "This session has closed." } };
|
|
105
107
|
const result = deps.addTask({ ...draft, id: suggestTaskId(deps.getChecklist()) }, ctx);
|
|
106
108
|
if (result.ok)
|
|
107
109
|
added = result.task;
|
|
@@ -122,7 +124,7 @@ async function runAddTask(ctx, deps, title) {
|
|
|
122
124
|
requestRender: () => tui.requestRender(),
|
|
123
125
|
getMaxRows: () => dialogMaxRows(tui.terminal.rows),
|
|
124
126
|
}, opts), { overlay: true, overlayOptions: { width: "70%", maxHeight: `${DIALOG_MAX_HEIGHT_PERCENT}%`, anchor: "center" } });
|
|
125
|
-
if (added)
|
|
127
|
+
if (added && !signal.aborted)
|
|
126
128
|
ctx.ui.notify(describe(added), "info");
|
|
127
129
|
}
|
|
128
130
|
/** Prepare the native settings command without sending a prompt to the model. */
|
|
@@ -135,6 +137,10 @@ function openSettingsScreen(ctx) {
|
|
|
135
137
|
ctx.ui.notify("Use /settings in interactive mode to configure the checklist.", "info");
|
|
136
138
|
}
|
|
137
139
|
export function registerChecklistCommand(pi, deps) {
|
|
140
|
+
// A dialog may settle after replacement/reload invalidates its command context.
|
|
141
|
+
// Its answer belongs to the old session and must not mutate the replacement.
|
|
142
|
+
const lifetime = new AbortController();
|
|
143
|
+
pi.on("session_shutdown", () => lifetime.abort());
|
|
138
144
|
const options = {
|
|
139
145
|
description: "Show the session task checklist in a popup dialog (args: show | hide | clear | add [text] | settings)",
|
|
140
146
|
getArgumentCompletions: (prefix) => {
|
|
@@ -144,6 +150,8 @@ export function registerChecklistCommand(pi, deps) {
|
|
|
144
150
|
return filtered.length > 0 ? filtered.map((value) => ({ value, label: value })) : null;
|
|
145
151
|
},
|
|
146
152
|
handler: async (args, ctx) => {
|
|
153
|
+
if (lifetime.signal.aborted)
|
|
154
|
+
return;
|
|
147
155
|
const action = parseChecklistArgs(args);
|
|
148
156
|
if (action.name === "sidebar") {
|
|
149
157
|
deps.toggleSidebar(action.value, ctx);
|
|
@@ -151,6 +159,8 @@ export function registerChecklistCommand(pi, deps) {
|
|
|
151
159
|
}
|
|
152
160
|
if (action.name === "hide") {
|
|
153
161
|
await deps.setDisplayMode("hidden", ctx);
|
|
162
|
+
if (lifetime.signal.aborted)
|
|
163
|
+
return;
|
|
154
164
|
ctx.ui.notify("checklist hidden (/checklist show to restore)", "info");
|
|
155
165
|
return;
|
|
156
166
|
}
|
|
@@ -158,22 +168,24 @@ export function registerChecklistCommand(pi, deps) {
|
|
|
158
168
|
// "show" pops the checklist dialog; also restore the widget if hidden.
|
|
159
169
|
if (deps.getDisplayMode() === "hidden") {
|
|
160
170
|
await deps.setDisplayMode("statusbar", ctx);
|
|
171
|
+
if (lifetime.signal.aborted)
|
|
172
|
+
return;
|
|
161
173
|
}
|
|
162
|
-
await openChecklistDialog(ctx, deps);
|
|
174
|
+
await openChecklistDialog(ctx, deps, lifetime.signal);
|
|
163
175
|
return;
|
|
164
176
|
}
|
|
165
177
|
if (action.name === "clear") {
|
|
166
178
|
const ok = ctx.hasUI
|
|
167
179
|
? await ctx.ui.confirm("Clear checklist?", "Remove all tasks from this session's checklist?")
|
|
168
180
|
: true;
|
|
169
|
-
if (!ok)
|
|
181
|
+
if (!ok || lifetime.signal.aborted)
|
|
170
182
|
return;
|
|
171
183
|
deps.clear(ctx);
|
|
172
184
|
ctx.ui.notify("checklist cleared", "info");
|
|
173
185
|
return;
|
|
174
186
|
}
|
|
175
187
|
if (action.name === "add") {
|
|
176
|
-
await runAddTask(ctx, deps, action.title);
|
|
188
|
+
await runAddTask(ctx, deps, action.title, lifetime.signal);
|
|
177
189
|
return;
|
|
178
190
|
}
|
|
179
191
|
if (action.name === "settings") {
|
|
@@ -185,7 +197,7 @@ export function registerChecklistCommand(pi, deps) {
|
|
|
185
197
|
return;
|
|
186
198
|
}
|
|
187
199
|
// open popup dialog (bare /checklist and /checklist show)
|
|
188
|
-
await openChecklistDialog(ctx, deps);
|
|
200
|
+
await openChecklistDialog(ctx, deps, lifetime.signal);
|
|
189
201
|
},
|
|
190
202
|
};
|
|
191
203
|
pi.registerCommand("checklist", options);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commands.js","sourceRoot":"","sources":["../../../../src/humain/checklist/vendor/commands.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EACN,gBAAgB,EAChB,yBAAyB,EACzB,gBAAgB,EAChB,aAAa,GAEb,MAAM,aAAa,CAAC;AACrB,OAAO,EAGN,QAAQ,EACR,mBAAmB,EACnB,SAAS,EACT,aAAa,EACb,OAAO,GACP,MAAM,YAAY,CAAC;AAapB,MAAM,UAAU,kBAAkB,CAAC,GAAW;IAC7C,MAAM,KAAK,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACpE,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IAC5B,IAAI,IAAI,KAAK,EAAE;QAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;IACzC,IAAI,IAAI,KAAK,SAAS,IAAI,KAAK,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,IAAI,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC;QACpG,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,K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CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;gBAC5B,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,eAAe,EAAE,SAAS,CAAC,CAAC;gBAC1C,OAAO;YACR,CAAC;YACD,0DAA0D;YAC1D,MAAM,mBAAmB,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QACtC,CAAC;KACD,CAAC;IACF,EAAE,CAAC,eAAe,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;AAC1C,CAAC","sourcesContent":["/** /checklist command: overlay + settings (display / style / icons / usage) + show/hide/clear. */\nimport type { ExtensionAPI, ExtensionCommandContext } from \"../../../core/extensions/types.ts\";\n\nimport { AddTaskDialog } from \"./add-task-dialog.ts\";\nimport {\n\tChecklistOverlay,\n\tDIALOG_MAX_HEIGHT_PERCENT,\n\tdependencyTitles,\n\tdialogMaxRows,\n\ttype RenderOpts,\n} from \"./render.ts\";\nimport {\n\ttype AddTaskDraft,\n\ttype AddTaskResult,\n\tcountsOf,\n\tMAX_CHECKLIST_TASKS,\n\tsortViews,\n\tsuggestTaskId,\n\tviewsOf,\n} from \"./store.ts\";\nimport type { Checklist, DisplayMode } from \"./types.ts\";\n\nexport type ChecklistAction =\n\t| { name: \"sidebar\"; value: \"toggle\" | \"on\" | \"off\" }\n\t| { name: \"open\" }\n\t| { name: \"show\" }\n\t| { name: \"hide\" }\n\t| { name: \"clear\" }\n\t| { name: \"add\"; title?: string }\n\t| { name: \"settings\" }\n\t| { name: \"help\" };\n\nexport function parseChecklistArgs(raw: string): ChecklistAction {\n\tconst parts = raw.trim().toLowerCase().split(/\\s+/).filter(Boolean);\n\tconst head = parts[0] ?? \"\";\n\tif (head === \"\") return { name: \"open\" };\n\tif (head === \"sidebar\" && parts.length <= 2 && (!parts[1] || parts[1] === \"on\" || parts[1] === \"off\"))\n\t\treturn { name: \"sidebar\", value: parts[1] === \"on\" ? \"on\" : parts[1] === \"off\" ? \"off\" : \"toggle\" };\n\tif (head === \"show\") return { name: \"show\" };\n\tif (head === \"hide\") return { name: \"hide\" };\n\tif (head === \"clear\") return { name: \"clear\" };\n\tif (head === \"add\") {\n\t\t// Anything after `add` prefills the task text (original casing kept).\n\t\tconst title = raw\n\t\t\t.trim()\n\t\t\t.replace(/^add\\s*/i, \"\")\n\t\t\t.trim();\n\t\treturn title === \"\" ? { name: \"add\" } : { name: \"add\", title };\n\t}\n\tif (head === \"settings\" || head === \"setting\" || head === \"mode\") {\n\t\treturn { name: \"settings\" };\n\t}\n\treturn { name: \"help\" };\n}\n\nconst CHECKLIST_USAGE = \"Usage: /checklist [show|hide|clear|add [text]|settings]\";\n\n/** Open the checklist in a centered TUI popup dialog (overlay modal). */\nasync function openChecklistDialog(ctx: ExtensionCommandContext, deps: ChecklistCommandDeps): Promise<void> {\n\tif (ctx.mode !== \"tui\" || !ctx.hasUI) {\n\t\t// No popup surface in print mode — fall back to a text summary.\n\t\tconst checklist = deps.getChecklist();\n\t\tif (!checklist || checklist.tasks.length === 0) {\n\t\t\tctx.ui.notify(\"checklist is empty\", \"info\");\n\t\t\treturn;\n\t\t}\n\t\tconst c = countsOf(checklist);\n\t\tconst rows = sortViews(viewsOf(checklist))\n\t\t\t.map(\n\t\t\t\t(v) =>\n\t\t\t\t\t` ${v.status === \"done\" ? \"✓\" : v.status === \"ongoing\" ? \"●\" : v.status === \"cancelled\" ? \"✕\" : \"○\"} [${v.status}] \"${v.title}\"`,\n\t\t\t)\n\t\t\t.join(\"\\n\");\n\t\tctx.ui.notify(`checklist ${c.done}/${c.total} done\\n${rows}`, \"info\");\n\t\treturn;\n\t}\n\tconst checklist = deps.getChecklist();\n\tconst opts = deps.getRenderOpts();\n\t// `s` jumps to settings: close this dialog first, then open the settings\n\t// screen once the overlay promise settles (avoids nested overlays).\n\tlet goSettings = false;\n\t// ctx.ui.custom with overlay:true renders as a floating TUI dialog box\n\t// on top of the session (see tui.md \"Overlays\"). The ChecklistOverlay\n\t// component handles j/k + arrows to scroll, s for settings, Esc/q to close.\n\tawait ctx.ui.custom<void>(\n\t\t(tui, theme, _kb, done) => {\n\t\t\treturn new ChecklistOverlay(\n\t\t\t\tchecklist,\n\t\t\t\ttheme,\n\t\t\t\t{\n\t\t\t\t\tonClose: () => done(),\n\t\t\t\t\tonSettings: () => {\n\t\t\t\t\t\tgoSettings = true;\n\t\t\t\t\t\tdone();\n\t\t\t\t\t},\n\t\t\t\t\trequestRender: () => tui.requestRender(),\n\t\t\t\t\t// pi-tui slices overlay lines to maxHeight with no scrolling, so the\n\t\t\t\t\t// dialog windows its own rows against the live terminal height.\n\t\t\t\t\tgetMaxRows: () => dialogMaxRows(tui.terminal.rows),\n\t\t\t\t},\n\t\t\t\topts,\n\t\t\t\tdeps.getMetaEnabled(),\n\t\t\t);\n\t\t},\n\t\t{ overlay: true, overlayOptions: { width: \"70%\", maxHeight: `${DIALOG_MAX_HEIGHT_PERCENT}%`, anchor: \"center\" } },\n\t);\n\tif (goSettings) {\n\t\topenSettingsScreen(ctx);\n\t}\n}\n\nexport interface ChecklistCommandDeps {\n\t/** Validate against the live checklist and, when fine, append + persist + refresh the UI. */\n\taddTask: (draft: AddTaskDraft, ctx: ExtensionCommandContext) => AddTaskResult;\n\tgetDisplayMode: () => DisplayMode;\n\tsetDisplayMode: (mode: DisplayMode, ctx: ExtensionCommandContext) => void | Promise<void>;\n\tgetMetaEnabled: () => boolean;\n\tgetRenderOpts: () => RenderOpts;\n\tclear: (ctx: ExtensionCommandContext) => void;\n\tgetChecklist: () => Checklist | null;\n\ttoggleSidebar: (value: \"toggle\" | \"on\" | \"off\", ctx: ExtensionCommandContext) => void;\n}\n\n/** Human-readable summary of a failed add without machine task references. */\nfunction describeAddErrors(errors: Extract<AddTaskResult, { ok: false }>[\"errors\"]): string {\n\treturn [\n\t\terrors.form ? \"Unable to add task; retry with the current checklist.\" : undefined,\n\t\terrors.id ? \"Unable to allocate a task reference; please retry.\" : undefined,\n\t\terrors.title,\n\t\terrors.dependsOn ? \"A selected dependency is no longer available; reopen the dialog.\" : undefined,\n\t]\n\t\t.filter(Boolean)\n\t\t.join(\"; \");\n}\n\n/** `/checklist add [text]`: dialog in the TUI, direct add (auto id) when there is no dialog surface. */\nasync function runAddTask(\n\tctx: ExtensionCommandContext,\n\tdeps: ChecklistCommandDeps,\n\ttitle: string | undefined,\n): Promise<void> {\n\tconst checklist = deps.getChecklist();\n\tconst count = checklist?.tasks.length ?? 0;\n\tif (count >= MAX_CHECKLIST_TASKS) {\n\t\tctx.ui.notify(`checklist is full (${count}/${MAX_CHECKLIST_TASKS} tasks): can't add another`, \"warning\");\n\t\treturn;\n\t}\n\tconst describe = (task: { id: string; title: string; dependsOn: string[] }) =>\n\t\t`checklist: added \"${task.title}\"${task.dependsOn.length > 0 ? ` (depends on ${dependencyTitles(task.dependsOn, deps.getChecklist()!)})` : \"\"}`;\n\n\tif (ctx.mode !== \"tui\" || !ctx.hasUI) {\n\t\tif (!title) {\n\t\t\tctx.ui.notify(\n\t\t\t\t\"/checklist add opens a dialog in the TUI; here pass the task text: /checklist add <text>\",\n\t\t\t\t\"warning\",\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\t\tconst result = deps.addTask({ id: suggestTaskId(checklist), title, dependsOn: [] }, ctx);\n\t\tctx.ui.notify(\n\t\t\tresult.ok ? describe(result.task) : `checklist: not added: ${describeAddErrors(result.errors)}`,\n\t\t\tresult.ok ? \"info\" : \"warning\",\n\t\t);\n\t\treturn;\n\t}\n\n\tconst opts = deps.getRenderOpts();\n\tlet added: { id: string; title: string; dependsOn: string[] } | undefined;\n\tawait ctx.ui.custom<void>(\n\t\t(tui, theme, _kb, done) =>\n\t\t\tnew AddTaskDialog(\n\t\t\t\tchecklist,\n\t\t\t\t{ title },\n\t\t\t\ttheme,\n\t\t\t\t{\n\t\t\t\t\tonSubmit: (draft) => {\n\t\t\t\t\t\tconst result = deps.addTask({ ...draft, id: suggestTaskId(deps.getChecklist()) }, ctx);\n\t\t\t\t\t\tif (result.ok) added = result.task;\n\t\t\t\t\t\tif (result.ok) return result;\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tok: false,\n\t\t\t\t\t\t\terrors: {\n\t\t\t\t\t\t\t\ttitle: result.errors.title,\n\t\t\t\t\t\t\t\tdependsOn: result.errors.dependsOn\n\t\t\t\t\t\t\t\t\t? \"A selected dependency is no longer available; reopen the dialog.\"\n\t\t\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\t\t\t\tform: describeAddErrors({ form: result.errors.form, id: result.errors.id }) || undefined,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t};\n\t\t\t\t\t},\n\t\t\t\t\tonClose: () => done(),\n\t\t\t\t\trequestRender: () => tui.requestRender(),\n\t\t\t\t\tgetMaxRows: () => dialogMaxRows(tui.terminal.rows),\n\t\t\t\t},\n\t\t\t\topts,\n\t\t\t),\n\t\t{ overlay: true, overlayOptions: { width: \"70%\", maxHeight: `${DIALOG_MAX_HEIGHT_PERCENT}%`, anchor: \"center\" } },\n\t);\n\tif (added) ctx.ui.notify(describe(added), \"info\");\n}\n\n/** Prepare the native settings command without sending a prompt to the model. */\nfunction openSettingsScreen(ctx: ExtensionCommandContext): void {\n\tif (ctx.mode === \"tui\" && ctx.hasUI) {\n\t\tctx.ui.setEditorText(\"/settings\");\n\t\tctx.ui.notify(\"Press Enter to open native checklist settings.\", \"info\");\n\t} else ctx.ui.notify(\"Use /settings in interactive mode to configure the checklist.\", \"info\");\n}\n\nexport function registerChecklistCommand(pi: ExtensionAPI, deps: ChecklistCommandDeps): void {\n\tconst options = {\n\t\tdescription:\n\t\t\t\"Show the session task checklist in a popup dialog (args: show | hide | clear | add [text] | settings)\",\n\t\tgetArgumentCompletions: (prefix: string) => {\n\t\t\tconst lower = prefix.toLowerCase();\n\t\t\tconst opts = [\"show\", \"hide\", \"clear\", \"add\", \"settings\", \"sidebar\"];\n\t\t\tconst filtered = opts.filter((o) => o.startsWith(lower));\n\t\t\treturn filtered.length > 0 ? filtered.map((value) => ({ value, label: value })) : null;\n\t\t},\n\t\thandler: async (args: string, ctx: ExtensionCommandContext) => {\n\t\t\tconst action = parseChecklistArgs(args);\n\t\t\tif (action.name === \"sidebar\") {\n\t\t\t\tdeps.toggleSidebar(action.value, ctx);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (action.name === \"hide\") {\n\t\t\t\tawait deps.setDisplayMode(\"hidden\", ctx);\n\t\t\t\tctx.ui.notify(\"checklist hidden (/checklist show to restore)\", \"info\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (action.name === \"show\") {\n\t\t\t\t// \"show\" pops the checklist dialog; also restore the widget if hidden.\n\t\t\t\tif (deps.getDisplayMode() === \"hidden\") {\n\t\t\t\t\tawait deps.setDisplayMode(\"statusbar\", ctx);\n\t\t\t\t}\n\t\t\t\tawait openChecklistDialog(ctx, deps);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (action.name === \"clear\") {\n\t\t\t\tconst ok = ctx.hasUI\n\t\t\t\t\t? await ctx.ui.confirm(\"Clear checklist?\", \"Remove all tasks from this session's checklist?\")\n\t\t\t\t\t: true;\n\t\t\t\tif (!ok) return;\n\t\t\t\tdeps.clear(ctx);\n\t\t\t\tctx.ui.notify(\"checklist cleared\", \"info\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (action.name === \"add\") {\n\t\t\t\tawait runAddTask(ctx, deps, action.title);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (action.name === \"settings\") {\n\t\t\t\topenSettingsScreen(ctx);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (action.name === \"help\") {\n\t\t\t\tctx.ui.notify(CHECKLIST_USAGE, \"warning\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// open popup dialog (bare /checklist and /checklist show)\n\t\t\tawait openChecklistDialog(ctx, deps);\n\t\t},\n\t};\n\tpi.registerCommand(\"checklist\", options);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"commands.js","sourceRoot":"","sources":["../../../../src/humain/checklist/vendor/commands.ts"],"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CAAC;gBAC3C,OAAO;YACR,CAAC;YACD,IAAI,MAAM,CAAC,IAAI,KAAK,KAAK,EAAE,CAAC;gBAC3B,MAAM,UAAU,CAAC,GAAG,EAAE,IAAI,EAAE,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;gBAC3D,OAAO;YACR,CAAC;YACD,IAAI,MAAM,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;gBAChC,kBAAkB,CAAC,GAAG,CAAC,CAAC;gBACxB,OAAO;YACR,CAAC;YACD,IAAI,MAAM,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;gBAC5B,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,eAAe,EAAE,SAAS,CAAC,CAAC;gBAC1C,OAAO;YACR,CAAC;YACD,0DAA0D;YAC1D,MAAM,mBAAmB,CAAC,GAAG,EAAE,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;QACvD,CAAC;KACD,CAAC;IACF,EAAE,CAAC,eAAe,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;AAC1C,CAAC","sourcesContent":["/** /checklist command: overlay + settings (display / style / icons / usage) + show/hide/clear. */\nimport type { ExtensionAPI, ExtensionCommandContext } from \"../../../core/extensions/types.ts\";\n\nimport { AddTaskDialog } from \"./add-task-dialog.ts\";\nimport {\n\tChecklistOverlay,\n\tDIALOG_MAX_HEIGHT_PERCENT,\n\tdependencyTitles,\n\tdialogMaxRows,\n\ttype RenderOpts,\n} from \"./render.ts\";\nimport {\n\ttype AddTaskDraft,\n\ttype AddTaskResult,\n\tcountsOf,\n\tMAX_CHECKLIST_TASKS,\n\tsortViews,\n\tsuggestTaskId,\n\tviewsOf,\n} from \"./store.ts\";\nimport type { Checklist, DisplayMode } from \"./types.ts\";\n\nexport type ChecklistAction =\n\t| { name: \"sidebar\"; value: \"toggle\" | \"on\" | \"off\" }\n\t| { name: \"open\" }\n\t| { name: \"show\" }\n\t| { name: \"hide\" }\n\t| { name: \"clear\" }\n\t| { name: \"add\"; title?: string }\n\t| { name: \"settings\" }\n\t| { name: \"help\" };\n\nexport function parseChecklistArgs(raw: string): ChecklistAction {\n\tconst parts = raw.trim().toLowerCase().split(/\\s+/).filter(Boolean);\n\tconst head = parts[0] ?? \"\";\n\tif (head === \"\") return { name: \"open\" };\n\tif (head === \"sidebar\" && parts.length <= 2 && (!parts[1] || parts[1] === \"on\" || parts[1] === \"off\"))\n\t\treturn { name: \"sidebar\", value: parts[1] === \"on\" ? \"on\" : parts[1] === \"off\" ? \"off\" : \"toggle\" };\n\tif (head === \"show\") return { name: \"show\" };\n\tif (head === \"hide\") return { name: \"hide\" };\n\tif (head === \"clear\") return { name: \"clear\" };\n\tif (head === \"add\") {\n\t\t// Anything after `add` prefills the task text (original casing kept).\n\t\tconst title = raw\n\t\t\t.trim()\n\t\t\t.replace(/^add\\s*/i, \"\")\n\t\t\t.trim();\n\t\treturn title === \"\" ? { name: \"add\" } : { name: \"add\", title };\n\t}\n\tif (head === \"settings\" || head === \"setting\" || head === \"mode\") {\n\t\treturn { name: \"settings\" };\n\t}\n\treturn { name: \"help\" };\n}\n\nconst CHECKLIST_USAGE = \"Usage: /checklist [show|hide|clear|add [text]|settings]\";\n\n/** Open the checklist in a centered TUI popup dialog (overlay modal). */\nasync function openChecklistDialog(\n\tctx: ExtensionCommandContext,\n\tdeps: ChecklistCommandDeps,\n\tsignal: AbortSignal,\n): Promise<void> {\n\tif (ctx.mode !== \"tui\" || !ctx.hasUI) {\n\t\t// No popup surface in print mode — fall back to a text summary.\n\t\tconst checklist = deps.getChecklist();\n\t\tif (!checklist || checklist.tasks.length === 0) {\n\t\t\tctx.ui.notify(\"checklist is empty\", \"info\");\n\t\t\treturn;\n\t\t}\n\t\tconst c = countsOf(checklist);\n\t\tconst rows = sortViews(viewsOf(checklist))\n\t\t\t.map(\n\t\t\t\t(v) =>\n\t\t\t\t\t` ${v.status === \"done\" ? \"✓\" : v.status === \"ongoing\" ? \"●\" : v.status === \"cancelled\" ? \"✕\" : \"○\"} [${v.status}] \"${v.title}\"`,\n\t\t\t)\n\t\t\t.join(\"\\n\");\n\t\tctx.ui.notify(`checklist ${c.done}/${c.total} done\\n${rows}`, \"info\");\n\t\treturn;\n\t}\n\tconst checklist = deps.getChecklist();\n\tconst opts = deps.getRenderOpts();\n\t// `s` jumps to settings: close this dialog first, then open the settings\n\t// screen once the overlay promise settles (avoids nested overlays).\n\tlet goSettings = false;\n\t// ctx.ui.custom with overlay:true renders as a floating TUI dialog box\n\t// on top of the session (see tui.md \"Overlays\"). The ChecklistOverlay\n\t// component handles j/k + arrows to scroll, s for settings, Esc/q to close.\n\tawait ctx.ui.custom<void>(\n\t\t(tui, theme, _kb, done) => {\n\t\t\treturn new ChecklistOverlay(\n\t\t\t\tchecklist,\n\t\t\t\ttheme,\n\t\t\t\t{\n\t\t\t\t\tonClose: () => done(),\n\t\t\t\t\tonSettings: () => {\n\t\t\t\t\t\tgoSettings = true;\n\t\t\t\t\t\tdone();\n\t\t\t\t\t},\n\t\t\t\t\trequestRender: () => tui.requestRender(),\n\t\t\t\t\t// pi-tui slices overlay lines to maxHeight with no scrolling, so the\n\t\t\t\t\t// dialog windows its own rows against the live terminal height.\n\t\t\t\t\tgetMaxRows: () => dialogMaxRows(tui.terminal.rows),\n\t\t\t\t},\n\t\t\t\topts,\n\t\t\t\tdeps.getMetaEnabled(),\n\t\t\t);\n\t\t},\n\t\t{ overlay: true, overlayOptions: { width: \"70%\", maxHeight: `${DIALOG_MAX_HEIGHT_PERCENT}%`, anchor: \"center\" } },\n\t);\n\tif (goSettings && !signal.aborted) {\n\t\topenSettingsScreen(ctx);\n\t}\n}\n\nexport interface ChecklistCommandDeps {\n\t/** Validate against the live checklist and, when fine, append + persist + refresh the UI. */\n\taddTask: (draft: AddTaskDraft, ctx: ExtensionCommandContext) => AddTaskResult;\n\tgetDisplayMode: () => DisplayMode;\n\tsetDisplayMode: (mode: DisplayMode, ctx: ExtensionCommandContext) => void | Promise<void>;\n\tgetMetaEnabled: () => boolean;\n\tgetRenderOpts: () => RenderOpts;\n\tclear: (ctx: ExtensionCommandContext) => void;\n\tgetChecklist: () => Checklist | null;\n\ttoggleSidebar: (value: \"toggle\" | \"on\" | \"off\", ctx: ExtensionCommandContext) => void;\n}\n\n/** Human-readable summary of a failed add without machine task references. */\nfunction describeAddErrors(errors: Extract<AddTaskResult, { ok: false }>[\"errors\"]): string {\n\treturn [\n\t\terrors.form ? \"Unable to add task; retry with the current checklist.\" : undefined,\n\t\terrors.id ? \"Unable to allocate a task reference; please retry.\" : undefined,\n\t\terrors.title,\n\t\terrors.dependsOn ? \"A selected dependency is no longer available; reopen the dialog.\" : undefined,\n\t]\n\t\t.filter(Boolean)\n\t\t.join(\"; \");\n}\n\n/** `/checklist add [text]`: dialog in the TUI, direct add (auto id) when there is no dialog surface. */\nasync function runAddTask(\n\tctx: ExtensionCommandContext,\n\tdeps: ChecklistCommandDeps,\n\ttitle: string | undefined,\n\tsignal: AbortSignal,\n): Promise<void> {\n\tconst checklist = deps.getChecklist();\n\tconst count = checklist?.tasks.length ?? 0;\n\tif (count >= MAX_CHECKLIST_TASKS) {\n\t\tctx.ui.notify(`checklist is full (${count}/${MAX_CHECKLIST_TASKS} tasks): can't add another`, \"warning\");\n\t\treturn;\n\t}\n\tconst describe = (task: { id: string; title: string; dependsOn: string[] }) =>\n\t\t`checklist: added \"${task.title}\"${task.dependsOn.length > 0 ? ` (depends on ${dependencyTitles(task.dependsOn, deps.getChecklist()!)})` : \"\"}`;\n\n\tif (ctx.mode !== \"tui\" || !ctx.hasUI) {\n\t\tif (!title) {\n\t\t\tctx.ui.notify(\n\t\t\t\t\"/checklist add opens a dialog in the TUI; here pass the task text: /checklist add <text>\",\n\t\t\t\t\"warning\",\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\t\tconst result = deps.addTask({ id: suggestTaskId(checklist), title, dependsOn: [] }, ctx);\n\t\tctx.ui.notify(\n\t\t\tresult.ok ? describe(result.task) : `checklist: not added: ${describeAddErrors(result.errors)}`,\n\t\t\tresult.ok ? \"info\" : \"warning\",\n\t\t);\n\t\treturn;\n\t}\n\n\tconst opts = deps.getRenderOpts();\n\tlet added: { id: string; title: string; dependsOn: string[] } | undefined;\n\tawait ctx.ui.custom<void>(\n\t\t(tui, theme, _kb, done) =>\n\t\t\tnew AddTaskDialog(\n\t\t\t\tchecklist,\n\t\t\t\t{ title },\n\t\t\t\ttheme,\n\t\t\t\t{\n\t\t\t\t\tonSubmit: (draft) => {\n\t\t\t\t\t\tif (signal.aborted) return { ok: false, errors: { form: \"This session has closed.\" } };\n\t\t\t\t\t\tconst result = deps.addTask({ ...draft, id: suggestTaskId(deps.getChecklist()) }, ctx);\n\t\t\t\t\t\tif (result.ok) added = result.task;\n\t\t\t\t\t\tif (result.ok) return result;\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tok: false,\n\t\t\t\t\t\t\terrors: {\n\t\t\t\t\t\t\t\ttitle: result.errors.title,\n\t\t\t\t\t\t\t\tdependsOn: result.errors.dependsOn\n\t\t\t\t\t\t\t\t\t? \"A selected dependency is no longer available; reopen the dialog.\"\n\t\t\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\t\t\t\tform: describeAddErrors({ form: result.errors.form, id: result.errors.id }) || undefined,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t};\n\t\t\t\t\t},\n\t\t\t\t\tonClose: () => done(),\n\t\t\t\t\trequestRender: () => tui.requestRender(),\n\t\t\t\t\tgetMaxRows: () => dialogMaxRows(tui.terminal.rows),\n\t\t\t\t},\n\t\t\t\topts,\n\t\t\t),\n\t\t{ overlay: true, overlayOptions: { width: \"70%\", maxHeight: `${DIALOG_MAX_HEIGHT_PERCENT}%`, anchor: \"center\" } },\n\t);\n\tif (added && !signal.aborted) ctx.ui.notify(describe(added), \"info\");\n}\n\n/** Prepare the native settings command without sending a prompt to the model. */\nfunction openSettingsScreen(ctx: ExtensionCommandContext): void {\n\tif (ctx.mode === \"tui\" && ctx.hasUI) {\n\t\tctx.ui.setEditorText(\"/settings\");\n\t\tctx.ui.notify(\"Press Enter to open native checklist settings.\", \"info\");\n\t} else ctx.ui.notify(\"Use /settings in interactive mode to configure the checklist.\", \"info\");\n}\n\nexport function registerChecklistCommand(pi: ExtensionAPI, deps: ChecklistCommandDeps): void {\n\t// A dialog may settle after replacement/reload invalidates its command context.\n\t// Its answer belongs to the old session and must not mutate the replacement.\n\tconst lifetime = new AbortController();\n\tpi.on(\"session_shutdown\", () => lifetime.abort());\n\tconst options = {\n\t\tdescription:\n\t\t\t\"Show the session task checklist in a popup dialog (args: show | hide | clear | add [text] | settings)\",\n\t\tgetArgumentCompletions: (prefix: string) => {\n\t\t\tconst lower = prefix.toLowerCase();\n\t\t\tconst opts = [\"show\", \"hide\", \"clear\", \"add\", \"settings\", \"sidebar\"];\n\t\t\tconst filtered = opts.filter((o) => o.startsWith(lower));\n\t\t\treturn filtered.length > 0 ? filtered.map((value) => ({ value, label: value })) : null;\n\t\t},\n\t\thandler: async (args: string, ctx: ExtensionCommandContext) => {\n\t\t\tif (lifetime.signal.aborted) return;\n\t\t\tconst action = parseChecklistArgs(args);\n\t\t\tif (action.name === \"sidebar\") {\n\t\t\t\tdeps.toggleSidebar(action.value, ctx);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (action.name === \"hide\") {\n\t\t\t\tawait deps.setDisplayMode(\"hidden\", ctx);\n\t\t\t\tif (lifetime.signal.aborted) return;\n\t\t\t\tctx.ui.notify(\"checklist hidden (/checklist show to restore)\", \"info\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (action.name === \"show\") {\n\t\t\t\t// \"show\" pops the checklist dialog; also restore the widget if hidden.\n\t\t\t\tif (deps.getDisplayMode() === \"hidden\") {\n\t\t\t\t\tawait deps.setDisplayMode(\"statusbar\", ctx);\n\t\t\t\t\tif (lifetime.signal.aborted) return;\n\t\t\t\t}\n\t\t\t\tawait openChecklistDialog(ctx, deps, lifetime.signal);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (action.name === \"clear\") {\n\t\t\t\tconst ok = ctx.hasUI\n\t\t\t\t\t? await ctx.ui.confirm(\"Clear checklist?\", \"Remove all tasks from this session's checklist?\")\n\t\t\t\t\t: true;\n\t\t\t\tif (!ok || lifetime.signal.aborted) return;\n\t\t\t\tdeps.clear(ctx);\n\t\t\t\tctx.ui.notify(\"checklist cleared\", \"info\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (action.name === \"add\") {\n\t\t\t\tawait runAddTask(ctx, deps, action.title, lifetime.signal);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (action.name === \"settings\") {\n\t\t\t\topenSettingsScreen(ctx);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (action.name === \"help\") {\n\t\t\t\tctx.ui.notify(CHECKLIST_USAGE, \"warning\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// open popup dialog (bare /checklist and /checklist show)\n\t\t\tawait openChecklistDialog(ctx, deps, lifetime.signal);\n\t\t},\n\t};\n\tpi.registerCommand(\"checklist\", options);\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flow-loader.d.ts","sourceRoot":"","sources":["../../src/humain/flow-loader.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAE1D,OAAO,KAAK,EAAE,gBAAgB,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,4CAA4C,CAAC;AAGhH,OAAO,KAAK,EACX,YAAY,EACZ,uBAAuB,EACvB,gBAAgB,EAEhB,MAAM,6BAA6B,CAAC;AACrC,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,6BAA6B,CAAC;AAa/E;;;;;;;;GAQG;AAEH,eAAO,MAAM,wBAAwB,kCAAkC,CAAC;AACxE,eAAO,MAAM,2BAA2B,qCAAqC,CAAC;AAE9E,8FAA8F;AAC9F,MAAM,WAAW,cAAc;IAC9B,MAA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QAAQ,EAAE,qBAAqB,GAAG,gBAAgB,CAAC;CAC9E;AAED,MAAM,WAAW,uBAAuB;IACvC,mFAAmF;IACnF,UAAU,CAAC,EAAE,MAAM,OAAO,CAAC,UAAU,CAAC,CAAC;IACvC,gFAAgF;IAChF,iBAAiB,CAAC,EAAE,MAAM,OAAO,CAAC,iBAAiB,CAAC,CAAC;IACrD,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;IACxB,uGAAuG;IACvG,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,sHAAsH;IACtH,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,mEAAmE;IACnE,OAAO,CAAC,EAAE,MAAM,CAAC;CACjB;AAQD,qGAAqG;AACrG,wBAAgB,iBAAiB,IAAI,cAAc,GAAG,SAAS,CAE9D;AAED;;;GAGG;AACH,wBAAsB,kBAAkB,IAAI,OAAO,CAAC,cAAc,GAAG,SAAS,CAAC,CAI9E;AAED,sHAAsH;AACtH,wBAAgB,cAAc,IAAI,OAAO,CAExC;AAED,gGAAgG;AAChG,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,CAAC,CAAC,KAAK,EAAE,gBAAgB,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,SAAS,GAAG,IAAI,CAE9G;AAED,mHAAmH;AACnH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,CAAC,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,SAAS,GAAG,IAAI,CAE7F;AA0QD,wBAAgB,sCAAsC,CAAC,OAAO,GAAE,uBAA4B,GAAG,gBAAgB,CAgO9G"}
|
|
@@ -214,7 +214,7 @@ function disabledReason(pi, env) {
|
|
|
214
214
|
* Commit is not transactional for non-handler members: if one throws midway, committed handlers are unsubscribed, and
|
|
215
215
|
* tools/commands/flags/shortcuts/renderers (keyed maps in the extension loader) are simply overwritten on retry.
|
|
216
216
|
*/
|
|
217
|
-
async function runFlowExtension(pi, flowExtension, lastSessionStart, capturedCommand = "flow") {
|
|
217
|
+
async function runFlowExtension(pi, flowExtension, lastSessionStart, signal, capturedCommand = "flow") {
|
|
218
218
|
const captured = new Map();
|
|
219
219
|
const staged = [];
|
|
220
220
|
// After a successful commit the proxy forwards live, so registrations made later (from handlers) reach the real pi.
|
|
@@ -242,12 +242,16 @@ async function runFlowExtension(pi, flowExtension, lastSessionStart, capturedCom
|
|
|
242
242
|
},
|
|
243
243
|
});
|
|
244
244
|
await flowExtension(proxy);
|
|
245
|
+
if (signal.aborted)
|
|
246
|
+
return new Map();
|
|
245
247
|
let replayed;
|
|
246
248
|
for (let start = lastSessionStart(); start && start !== replayed; start = lastSessionStart()) {
|
|
247
249
|
replayed = start;
|
|
248
250
|
for (const call of staged) {
|
|
249
251
|
if (call.member === "on" && call.args[0] === "session_start" && !call.cancelled) {
|
|
250
252
|
await call.args[1](...start);
|
|
253
|
+
if (signal.aborted)
|
|
254
|
+
return new Map();
|
|
251
255
|
}
|
|
252
256
|
}
|
|
253
257
|
}
|
|
@@ -307,7 +311,13 @@ export function createHumainFlowLoaderExtensionFactory(options = {}) {
|
|
|
307
311
|
let flowModule;
|
|
308
312
|
return (pi) => {
|
|
309
313
|
disabledProbe = () => disabledReason(pi, env) !== undefined;
|
|
314
|
+
// Lazy imports and staged startup replays must not revive a replaced session.
|
|
315
|
+
const lifetime = new AbortController();
|
|
310
316
|
let lastStart;
|
|
317
|
+
pi.on("session_shutdown", () => {
|
|
318
|
+
lifetime.abort();
|
|
319
|
+
lastStart = undefined;
|
|
320
|
+
});
|
|
311
321
|
let loaded;
|
|
312
322
|
let hierarchy;
|
|
313
323
|
let orchestrateLoaded;
|
|
@@ -347,19 +357,23 @@ export function createHumainFlowLoaderExtensionFactory(options = {}) {
|
|
|
347
357
|
catch {
|
|
348
358
|
return undefined;
|
|
349
359
|
}
|
|
350
|
-
return rpcControl;
|
|
360
|
+
return lifetime.signal.aborted ? undefined : rpcControl;
|
|
351
361
|
};
|
|
352
362
|
const load = () => {
|
|
353
363
|
if (!loaded) {
|
|
354
364
|
const attempt = (async () => {
|
|
355
365
|
const module = await loadModule();
|
|
366
|
+
if (lifetime.signal.aborted)
|
|
367
|
+
return new Map();
|
|
356
368
|
let published;
|
|
357
369
|
const commands = await runFlowExtension(pi, (api) => module.flowExtension(api, (value) => {
|
|
358
370
|
published = value;
|
|
359
371
|
}, {
|
|
360
372
|
// Sanctioned opt-in runtime boundary: never load SDK session code for ordinary Flow children.
|
|
361
373
|
startImplementerSession: async (input) => (await import("../core/flow-implementer.js")).startFlowImplementerSession(input),
|
|
362
|
-
}), () => lastStart);
|
|
374
|
+
}), () => lastStart, lifetime.signal);
|
|
375
|
+
if (lifetime.signal.aborted)
|
|
376
|
+
return commands;
|
|
363
377
|
// Publish only after staging and session replay succeed; failed attempts cannot leak their command.
|
|
364
378
|
hierarchy = published;
|
|
365
379
|
hierarchy?.hierarchyExecutor.setLoader(async () => {
|
|
@@ -382,10 +396,12 @@ export function createHumainFlowLoaderExtensionFactory(options = {}) {
|
|
|
382
396
|
if (!orchestrateLoaded) {
|
|
383
397
|
const attempt = (async () => {
|
|
384
398
|
await load();
|
|
385
|
-
if (!hierarchy)
|
|
399
|
+
if (lifetime.signal.aborted || !hierarchy)
|
|
386
400
|
return new Map();
|
|
387
401
|
const module = await importOrchestrate();
|
|
388
|
-
|
|
402
|
+
if (lifetime.signal.aborted)
|
|
403
|
+
return new Map();
|
|
404
|
+
return runFlowExtension(pi, module.createOrchestrateExtension(hierarchy), () => lastStart, lifetime.signal, "orchestrate");
|
|
389
405
|
})();
|
|
390
406
|
orchestrateLoaded = attempt;
|
|
391
407
|
attempt.catch(() => {
|
|
@@ -399,6 +415,8 @@ export function createHumainFlowLoaderExtensionFactory(options = {}) {
|
|
|
399
415
|
description: FLOW_DESCRIPTION,
|
|
400
416
|
getArgumentCompletions: completeFlowArguments,
|
|
401
417
|
handler: async (args, rawCtx) => {
|
|
418
|
+
if (lifetime.signal.aborted)
|
|
419
|
+
return;
|
|
402
420
|
const ctx = withHeadlessNotices(rawCtx);
|
|
403
421
|
const refuse = (message, level) => {
|
|
404
422
|
if (ctx.mode === "print" || ctx.mode === "json")
|
|
@@ -439,6 +457,8 @@ export function createHumainFlowLoaderExtensionFactory(options = {}) {
|
|
|
439
457
|
if (command === "profile") {
|
|
440
458
|
try {
|
|
441
459
|
const module = await loadModule();
|
|
460
|
+
if (lifetime.signal.aborted)
|
|
461
|
+
return;
|
|
442
462
|
if (!module.runFlowProfileCommand || !module.createProfileStore) {
|
|
443
463
|
ctx.ui.notify(flowBuildUnavailable(command), "error");
|
|
444
464
|
return;
|
|
@@ -450,6 +470,8 @@ export function createHumainFlowLoaderExtensionFactory(options = {}) {
|
|
|
450
470
|
await module.runFlowProfileCommand(payload, ctx, { store });
|
|
451
471
|
}
|
|
452
472
|
catch (error) {
|
|
473
|
+
if (lifetime.signal.aborted)
|
|
474
|
+
return;
|
|
453
475
|
ctx.ui.notify(`/flow profile failed: ${error instanceof Error ? error.message : String(error)}`, "error");
|
|
454
476
|
}
|
|
455
477
|
return;
|
|
@@ -461,8 +483,12 @@ export function createHumainFlowLoaderExtensionFactory(options = {}) {
|
|
|
461
483
|
let commands;
|
|
462
484
|
try {
|
|
463
485
|
commands = await (command === "orchestrate" ? loadOrchestrate() : load());
|
|
486
|
+
if (lifetime.signal.aborted)
|
|
487
|
+
return;
|
|
464
488
|
}
|
|
465
489
|
catch (error) {
|
|
490
|
+
if (lifetime.signal.aborted)
|
|
491
|
+
return;
|
|
466
492
|
try {
|
|
467
493
|
ctx.ui.notify(`Failed to load Flow: ${error instanceof Error ? error.message : String(error)}`, "error");
|
|
468
494
|
}
|
|
@@ -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,EAA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AAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,EAChF,OAAO,CACP,CAAC;oBACH,CAAC;4BAAS,CAAC;wBACV,MAAM,aAAa,CAAC,EAAE,EAAE,OAAO,EAAE,GAAG,EAAE,UAAU,CAAC,CAAC;oBACnD,CAAC;oBACD,OAAO;gBACR,CAAC;gBACD,MAAM,IAAI,GAAG,QAAQ,CAAC,GAAG,CAAC,OAAO,KAAK,aAAa,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;gBAC9E,IAAI,CAAC,IAAI,EAAE,CAAC;oBACX,IAAI,CAAC;wBACJ,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,oBAAoB,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,CAAC;oBACvD,CAAC;4BAAS,CAAC;wBACV,MAAM,aAAa,CAAC,EAAE,EAAE,OAAO,EAAE,GAAG,EAAE,UAAU,CAAC,CAAC;oBACnD,CAAC;oBACD,OAAO;gBACR,CAAC;gBACD,wGAAwG;gBACxG,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,KAAK,aAAa,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;YACrE,CAAC;SACD,CAAC;QACF,EAAE,CAAC,eAAe,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QACjC,oEAAoE;QACpE,EAAE,CAAC,eAAe,CAAC,aAAa,EAAE;YACjC,WAAW,EAAE,gEAAgE;YAC7E,OAAO,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,eAAe,IAAI,EAAE,EAAE,GAAG,CAAC;SAChE,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 { FlowHierarchyCommands } from \"@humain/flow\";\nimport { FLOW_ID_PATTERN, 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 { readJsonFile } from \"../coordination/broker/atomic-file.ts\";\nimport type {\n\tExtensionAPI,\n\tExtensionCommandContext,\n\tExtensionFactory,\n\tRegisteredCommand,\n} from \"../core/extensions/types.ts\";\nimport type { startFlowImplementerSession } from \"../core/flow-implementer.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\tFLOW_SUBCOMMANDS,\n\ttype FlowSubcommand,\n\tflowBuildUnavailable,\n\tparseFlowCommand,\n\trenderFlowHelp,\n} from \"./flow-command.ts\";\n\n/**\n * Lazy loader for the private @humain/flow and @humain/orchestrate packages.\n *\n * The CLI entry graph must not statically reach Flow: this module registers one cheap `/flow` stub (plus `/orchestrate`,\n * which forwards to it) and two flags, and\n * loads Flow the first time a subcommand needs it. Hierarchy commands additionally load Orchestrate through a second\n * memoized dynamic import, using the initialized Flow instance. Help, completion, unknown commands and not-yet-available\n * commands are answered statically and never import either package. Both packages are bundled as lazy chunks.\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(\n\t\tpi: ExtensionAPI,\n\t\tpublishHierarchy?: (commands: FlowHierarchyCommands) => void,\n\t\thostServices?: { startImplementerSession: typeof startFlowImplementerSession },\n\t): void | Promise<void>;\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 OrchestrateModule {\n\tcreateOrchestrateExtension(commands: FlowHierarchyCommands): ExtensionFactory;\n}\n\nexport interface HumainFlowLoaderOptions {\n\t/** Test seam. Defaults to the single sanctioned dynamic import of @humain/flow. */\n\timportFlow?: () => Promise<FlowModule>;\n\t/** Test seam for the separate sanctioned lazy import of @humain/orchestrate. */\n\timportOrchestrate?: () => Promise<OrchestrateModule>;\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: \" +\n\t`${FLOW_SUBCOMMANDS.filter((name) => name !== \"help\").join(\", \")}. 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\", \"orchestrate\", \"continue\", \"fix\"]);\nconst FLOW_ID = new RegExp(FLOW_ID_PATTERN);\n// Match Flow's admission size limit without loading Flow on this refusal path.\nconst MAX_ADMISSION_FILE_BYTES = 1024 * 1024;\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\nfunction readRefusalRunId(pi: ExtensionAPI, cwd: string): string | undefined {\n\ttry {\n\t\tconst file = pi.getFlag(\"flow-admission\");\n\t\tif (typeof file !== \"string\" || !file) return undefined;\n\t\tconst admission = readJsonFile(resolve(cwd, file), MAX_ADMISSION_FILE_BYTES);\n\t\t// As in Flow's refusal path, validate just the identity needed for correlation, not the entire admission.\n\t\tconst runId = isRecord(admission) ? admission.runId : undefined;\n\t\treturn typeof runId === \"string\" && !/[\\r\\n]/.test(runId) && FLOW_ID.test(runId) ? runId : undefined;\n\t} catch {\n\t\treturn undefined;\n\t}\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\tpi: ExtensionAPI,\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 = readRefusalRunId(pi, ctx.cwd) ?? `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.slice(0, 120)}.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 an executor extension against a staging proxy. The selected 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\tcapturedCommand = \"flow\",\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] === capturedCommand) {\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\t// Separate sanctioned lazy boundary: lean Flow commands must never import the hierarchy package.\n\tconst importOrchestrate = options.importOrchestrate ?? (() => import(\"@humain/orchestrate\"));\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\t\tlet hierarchy: FlowHierarchyCommands | undefined;\n\t\tlet orchestrateLoaded: 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\tif (flowPackageDir) env.HUMAIN_TERMINAL_ORCHESTRATE_PACKAGE_DIR = join(dirname(flowPackageDir), \"orchestrate\");\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\tlet published: FlowHierarchyCommands | undefined;\n\t\t\t\t\tconst commands = await runFlowExtension(\n\t\t\t\t\t\tpi,\n\t\t\t\t\t\t(api) =>\n\t\t\t\t\t\t\tmodule.flowExtension(\n\t\t\t\t\t\t\t\tapi,\n\t\t\t\t\t\t\t\t(value) => {\n\t\t\t\t\t\t\t\t\tpublished = value;\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t// Sanctioned opt-in runtime boundary: never load SDK session code for ordinary Flow children.\n\t\t\t\t\t\t\t\t\tstartImplementerSession: async (input) =>\n\t\t\t\t\t\t\t\t\t\t(await import(\"../core/flow-implementer.ts\")).startFlowImplementerSession(input),\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t() => lastStart,\n\t\t\t\t\t);\n\t\t\t\t\t// Publish only after staging and session replay succeed; failed attempts cannot leak their command.\n\t\t\t\t\thierarchy = published;\n\t\t\t\t\thierarchy?.hierarchyExecutor.setLoader(async () => {\n\t\t\t\t\t\tif (disabledReason(pi, env)) return;\n\t\t\t\t\t\tawait loadOrchestrate();\n\t\t\t\t\t});\n\t\t\t\t\treturn commands;\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\tconst loadOrchestrate = (): Promise<Map<string, CommandOptions>> => {\n\t\t\tif (!orchestrateLoaded) {\n\t\t\t\tconst attempt = (async () => {\n\t\t\t\t\tawait load();\n\t\t\t\t\tif (!hierarchy) return new Map<string, CommandOptions>();\n\t\t\t\t\tconst module = await importOrchestrate();\n\t\t\t\t\treturn runFlowExtension(\n\t\t\t\t\t\tpi,\n\t\t\t\t\t\tmodule.createOrchestrateExtension(hierarchy),\n\t\t\t\t\t\t() => lastStart,\n\t\t\t\t\t\t\"orchestrate\",\n\t\t\t\t\t);\n\t\t\t\t})();\n\t\t\t\torchestrateLoaded = attempt;\n\t\t\t\tattempt.catch(() => {\n\t\t\t\t\tif (orchestrateLoaded === attempt) orchestrateLoaded = undefined;\n\t\t\t\t});\n\t\t\t}\n\t\t\treturn orchestrateLoaded;\n\t\t};\n\n\t\tconst flow: CommandOptions = {\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(pi, 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(pi, 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 (command === \"orchestrate\" ? loadOrchestrate() : 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(pi, 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(command === \"orchestrate\" ? \"orchestrate\" : \"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(pi, 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 re-parses its original arguments; Orchestrate receives the same byte-preserved payload directly.\n\t\t\t\tawait real.handler(command === \"orchestrate\" ? payload : args, ctx);\n\t\t\t},\n\t\t};\n\t\tpi.registerCommand(\"flow\", flow);\n\t\t// Same load, gating and refusal path as `/flow orchestrate <goal>`.\n\t\tpi.registerCommand(\"orchestrate\", {\n\t\t\tdescription: \"Plan and run a multi-agent Flow topology. Args: <goal> [flags]\",\n\t\t\thandler: (args, ctx) => flow.handler(`orchestrate ${args}`, ctx),\n\t\t});\n\t};\n}\n"]}
|
|
1
|
+
{"version":3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AO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,EAChF,OAAO,CACP,CAAC;oBACH,CAAC;4BAAS,CAAC;wBACV,MAAM,aAAa,CAAC,EAAE,EAAE,OAAO,EAAE,GAAG,EAAE,UAAU,CAAC,CAAC;oBACnD,CAAC;oBACD,OAAO;gBACR,CAAC;gBACD,MAAM,IAAI,GAAG,QAAQ,CAAC,GAAG,CAAC,OAAO,KAAK,aAAa,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;gBAC9E,IAAI,CAAC,IAAI,EAAE,CAAC;oBACX,IAAI,CAAC;wBACJ,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,oBAAoB,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,CAAC;oBACvD,CAAC;4BAAS,CAAC;wBACV,MAAM,aAAa,CAAC,EAAE,EAAE,OAAO,EAAE,GAAG,EAAE,UAAU,CAAC,CAAC;oBACnD,CAAC;oBACD,OAAO;gBACR,CAAC;gBACD,wGAAwG;gBACxG,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,KAAK,aAAa,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;YACrE,CAAC;SACD,CAAC;QACF,EAAE,CAAC,eAAe,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QACjC,oEAAoE;QACpE,EAAE,CAAC,eAAe,CAAC,aAAa,EAAE;YACjC,WAAW,EAAE,gEAAgE;YAC7E,OAAO,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,eAAe,IAAI,EAAE,EAAE,GAAG,CAAC;SAChE,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 { FlowHierarchyCommands } from \"@humain/flow\";\nimport { FLOW_ID_PATTERN, 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 { readJsonFile } from \"../coordination/broker/atomic-file.ts\";\nimport type {\n\tExtensionAPI,\n\tExtensionCommandContext,\n\tExtensionFactory,\n\tRegisteredCommand,\n} from \"../core/extensions/types.ts\";\nimport type { startFlowImplementerSession } from \"../core/flow-implementer.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\tFLOW_SUBCOMMANDS,\n\ttype FlowSubcommand,\n\tflowBuildUnavailable,\n\tparseFlowCommand,\n\trenderFlowHelp,\n} from \"./flow-command.ts\";\n\n/**\n * Lazy loader for the private @humain/flow and @humain/orchestrate packages.\n *\n * The CLI entry graph must not statically reach Flow: this module registers one cheap `/flow` stub (plus `/orchestrate`,\n * which forwards to it) and two flags, and\n * loads Flow the first time a subcommand needs it. Hierarchy commands additionally load Orchestrate through a second\n * memoized dynamic import, using the initialized Flow instance. Help, completion, unknown commands and not-yet-available\n * commands are answered statically and never import either package. Both packages are bundled as lazy chunks.\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(\n\t\tpi: ExtensionAPI,\n\t\tpublishHierarchy?: (commands: FlowHierarchyCommands) => void,\n\t\thostServices?: { startImplementerSession: typeof startFlowImplementerSession },\n\t): void | Promise<void>;\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 OrchestrateModule {\n\tcreateOrchestrateExtension(commands: FlowHierarchyCommands): ExtensionFactory;\n}\n\nexport interface HumainFlowLoaderOptions {\n\t/** Test seam. Defaults to the single sanctioned dynamic import of @humain/flow. */\n\timportFlow?: () => Promise<FlowModule>;\n\t/** Test seam for the separate sanctioned lazy import of @humain/orchestrate. */\n\timportOrchestrate?: () => Promise<OrchestrateModule>;\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: \" +\n\t`${FLOW_SUBCOMMANDS.filter((name) => name !== \"help\").join(\", \")}. 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\", \"orchestrate\", \"continue\", \"fix\"]);\nconst FLOW_ID = new RegExp(FLOW_ID_PATTERN);\n// Match Flow's admission size limit without loading Flow on this refusal path.\nconst MAX_ADMISSION_FILE_BYTES = 1024 * 1024;\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\nfunction readRefusalRunId(pi: ExtensionAPI, cwd: string): string | undefined {\n\ttry {\n\t\tconst file = pi.getFlag(\"flow-admission\");\n\t\tif (typeof file !== \"string\" || !file) return undefined;\n\t\tconst admission = readJsonFile(resolve(cwd, file), MAX_ADMISSION_FILE_BYTES);\n\t\t// As in Flow's refusal path, validate just the identity needed for correlation, not the entire admission.\n\t\tconst runId = isRecord(admission) ? admission.runId : undefined;\n\t\treturn typeof runId === \"string\" && !/[\\r\\n]/.test(runId) && FLOW_ID.test(runId) ? runId : undefined;\n\t} catch {\n\t\treturn undefined;\n\t}\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\tpi: ExtensionAPI,\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 = readRefusalRunId(pi, ctx.cwd) ?? `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.slice(0, 120)}.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 an executor extension against a staging proxy. The selected 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\tsignal: AbortSignal,\n\tcapturedCommand = \"flow\",\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] === capturedCommand) {\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\tif (signal.aborted) return new Map();\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\tif (signal.aborted) return new Map();\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\t// Separate sanctioned lazy boundary: lean Flow commands must never import the hierarchy package.\n\tconst importOrchestrate = options.importOrchestrate ?? (() => import(\"@humain/orchestrate\"));\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\t// Lazy imports and staged startup replays must not revive a replaced session.\n\t\tconst lifetime = new AbortController();\n\t\tlet lastStart: unknown[] | undefined;\n\t\tpi.on(\"session_shutdown\", () => {\n\t\t\tlifetime.abort();\n\t\t\tlastStart = undefined;\n\t\t});\n\t\tlet loaded: Promise<Map<string, CommandOptions>> | undefined;\n\t\tlet hierarchy: FlowHierarchyCommands | undefined;\n\t\tlet orchestrateLoaded: 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\tif (flowPackageDir) env.HUMAIN_TERMINAL_ORCHESTRATE_PACKAGE_DIR = join(dirname(flowPackageDir), \"orchestrate\");\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 lifetime.signal.aborted ? undefined : 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\tif (lifetime.signal.aborted) return new Map<string, CommandOptions>();\n\t\t\t\t\tlet published: FlowHierarchyCommands | undefined;\n\t\t\t\t\tconst commands = await runFlowExtension(\n\t\t\t\t\t\tpi,\n\t\t\t\t\t\t(api) =>\n\t\t\t\t\t\t\tmodule.flowExtension(\n\t\t\t\t\t\t\t\tapi,\n\t\t\t\t\t\t\t\t(value) => {\n\t\t\t\t\t\t\t\t\tpublished = value;\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t// Sanctioned opt-in runtime boundary: never load SDK session code for ordinary Flow children.\n\t\t\t\t\t\t\t\t\tstartImplementerSession: async (input) =>\n\t\t\t\t\t\t\t\t\t\t(await import(\"../core/flow-implementer.ts\")).startFlowImplementerSession(input),\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t() => lastStart,\n\t\t\t\t\t\tlifetime.signal,\n\t\t\t\t\t);\n\t\t\t\t\tif (lifetime.signal.aborted) return commands;\n\t\t\t\t\t// Publish only after staging and session replay succeed; failed attempts cannot leak their command.\n\t\t\t\t\thierarchy = published;\n\t\t\t\t\thierarchy?.hierarchyExecutor.setLoader(async () => {\n\t\t\t\t\t\tif (disabledReason(pi, env)) return;\n\t\t\t\t\t\tawait loadOrchestrate();\n\t\t\t\t\t});\n\t\t\t\t\treturn commands;\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\tconst loadOrchestrate = (): Promise<Map<string, CommandOptions>> => {\n\t\t\tif (!orchestrateLoaded) {\n\t\t\t\tconst attempt = (async () => {\n\t\t\t\t\tawait load();\n\t\t\t\t\tif (lifetime.signal.aborted || !hierarchy) return new Map<string, CommandOptions>();\n\t\t\t\t\tconst module = await importOrchestrate();\n\t\t\t\t\tif (lifetime.signal.aborted) return new Map<string, CommandOptions>();\n\t\t\t\t\treturn runFlowExtension(\n\t\t\t\t\t\tpi,\n\t\t\t\t\t\tmodule.createOrchestrateExtension(hierarchy),\n\t\t\t\t\t\t() => lastStart,\n\t\t\t\t\t\tlifetime.signal,\n\t\t\t\t\t\t\"orchestrate\",\n\t\t\t\t\t);\n\t\t\t\t})();\n\t\t\t\torchestrateLoaded = attempt;\n\t\t\t\tattempt.catch(() => {\n\t\t\t\t\tif (orchestrateLoaded === attempt) orchestrateLoaded = undefined;\n\t\t\t\t});\n\t\t\t}\n\t\t\treturn orchestrateLoaded;\n\t\t};\n\n\t\tconst flow: CommandOptions = {\n\t\t\tdescription: FLOW_DESCRIPTION,\n\t\t\tgetArgumentCompletions: completeFlowArguments,\n\t\t\thandler: async (args: string, rawCtx: ExtensionCommandContext) => {\n\t\t\t\tif (lifetime.signal.aborted) return;\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(pi, 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(pi, 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 (lifetime.signal.aborted) return;\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\tif (lifetime.signal.aborted) return;\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 (command === \"orchestrate\" ? loadOrchestrate() : load());\n\t\t\t\t\tif (lifetime.signal.aborted) return;\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (lifetime.signal.aborted) return;\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(pi, 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(command === \"orchestrate\" ? \"orchestrate\" : \"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(pi, 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 re-parses its original arguments; Orchestrate receives the same byte-preserved payload directly.\n\t\t\t\tawait real.handler(command === \"orchestrate\" ? payload : args, ctx);\n\t\t\t},\n\t\t};\n\t\tpi.registerCommand(\"flow\", flow);\n\t\t// Same load, gating and refusal path as `/flow orchestrate <goal>`.\n\t\tpi.registerCommand(\"orchestrate\", {\n\t\t\tdescription: \"Plan and run a multi-agent Flow topology. Args: <goal> [flags]\",\n\t\t\thandler: (args, ctx) => flow.handler(`orchestrate ${args}`, ctx),\n\t\t});\n\t};\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/humain/web-access/vendor/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAoB,MAAM,YAAY,CAAC;AAGlF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAKrD,OAAO,EAAwK,KAAK,oBAAoB,EAAE,KAAK,cAAc,EAAE,KAAK,uBAAuB,EAA+B,MAAM,oBAAoB,CAAC;AACrT,YAAY,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAE/D,OAAO,EAQN,KAAK,eAAe,EAEpB,MAAM,cAAc,CAAC;AAGtB,OAAO,EAIN,KAAK,wBAAwB,EAE7B,MAAM,qBAAqB,CAAC;AAa7B,OAAO,EAA+D,iCAAiC,EAAE,MAAM,oBAAoB,CAAC;AA0JpI,KAAK,eAAe,GAAG,gBAAgB,CAAC;AACxC,MAAM,MAAM,eAAe,GAAG,cAAc,CAAC;AA0G7C,wBAAgB,8BAA8B,IAAI,MAAM,CAMvD;AAED,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,GAAG,IAAI,CAAC;IACnC,cAAc,EAAE,MAAM,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE;QAAE,OAAO,EAAE,KAAK,CAAC;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,IAAI,EAAE,MAAM,CAAA;SAAE,CAAC,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;IAChI,MAAM,EAAE,WAAW,GAAG,SAAS,CAAC;IAChC,aAAa,EAAE,MAAM,IAAI,CAAC;IAC1B,MAAM,EAAE,CAAC,KAAK,EAAE,eAAe,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,KAAK,IAAI,CAAC;IAClE,MAAM,EAAE,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,KAAK,IAAI,CAAC;IAC5C,cAAc,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/B,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC1B;AA0PD,MAAM,CAAC,OAAO,WAAW,EAAE,EAAE,YAAY,QAi8DxC"}
|
|
@@ -710,6 +710,7 @@ export default function (pi) {
|
|
|
710
710
|
const instance = {};
|
|
711
711
|
const pendingFetches = new Map();
|
|
712
712
|
let sessionActive = false;
|
|
713
|
+
let sessionLifetime = new AbortController();
|
|
713
714
|
/** Ids of the results this instance's session holds in memory. */
|
|
714
715
|
const ownedResults = new Set();
|
|
715
716
|
function abortPendingFetches() {
|
|
@@ -729,6 +730,7 @@ export default function (pi) {
|
|
|
729
730
|
pi.appendEntry("web-search-results", data);
|
|
730
731
|
}
|
|
731
732
|
function endSession() {
|
|
733
|
+
sessionLifetime.abort();
|
|
732
734
|
sessionActive = false;
|
|
733
735
|
abortPendingFetches();
|
|
734
736
|
releaseResults(ownedResults);
|
|
@@ -741,6 +743,7 @@ export default function (pi) {
|
|
|
741
743
|
}
|
|
742
744
|
function startSession(ctx) {
|
|
743
745
|
endSession();
|
|
746
|
+
sessionLifetime = new AbortController();
|
|
744
747
|
liveInstances.set(instance, Date.now());
|
|
745
748
|
sessionActive = true;
|
|
746
749
|
const restored = loadSessionResults(ctx);
|
|
@@ -2418,6 +2421,11 @@ export default function (pi) {
|
|
|
2418
2421
|
pi.registerCommand("search", {
|
|
2419
2422
|
description: "Browse stored web search results",
|
|
2420
2423
|
handler: async (_args, ctx) => {
|
|
2424
|
+
// Selector answers belong to the session that opened them, even if a new
|
|
2425
|
+
// session now holds the same result id. Never release that session's hold.
|
|
2426
|
+
const signal = sessionLifetime.signal;
|
|
2427
|
+
if (signal.aborted)
|
|
2428
|
+
return;
|
|
2421
2429
|
const results = getAllResults().filter((r) => ownedResults.has(r.id));
|
|
2422
2430
|
if (results.length === 0) {
|
|
2423
2431
|
ctx.ui.notify("No stored search results", "info");
|
|
@@ -2436,7 +2444,7 @@ export default function (pi) {
|
|
|
2436
2444
|
return `[${r.id.slice(0, 6)}] ${r.type} - ${ageStr}`;
|
|
2437
2445
|
});
|
|
2438
2446
|
const choice = await ctx.ui.select("Stored Search Results", options);
|
|
2439
|
-
if (!choice)
|
|
2447
|
+
if (!choice || signal.aborted)
|
|
2440
2448
|
return;
|
|
2441
2449
|
const match = choice.match(/^\[([a-z0-9]+)\]/);
|
|
2442
2450
|
if (!match)
|
|
@@ -2446,6 +2454,8 @@ export default function (pi) {
|
|
|
2446
2454
|
return;
|
|
2447
2455
|
const actions = ["View details", "Delete"];
|
|
2448
2456
|
const action = await ctx.ui.select(`Result ${selected.id.slice(0, 6)}`, actions);
|
|
2457
|
+
if (signal.aborted)
|
|
2458
|
+
return;
|
|
2449
2459
|
if (action === "Delete") {
|
|
2450
2460
|
deleteHeldResult(selected.id);
|
|
2451
2461
|
ownedResults.delete(selected.id);
|