@humain/humain-code 0.4.6 → 0.4.8
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 +21 -0
- package/dist/bun/sandbox-env-setup.js +8 -0
- package/dist/bun/sandbox-env-setup.js.map +1 -1
- package/dist/bundle/agent-monitor.js +1 -1
- package/dist/bundle/chunks/{anthropic-messages-OHNAMPAM.js → anthropic-messages-YMPB2HJ7.js} +14 -13
- package/dist/bundle/chunks/{azure-openai-responses-FREWTLSS.js → azure-openai-responses-PDHOT7UC.js} +2 -2
- package/dist/bundle/chunks/bedrock-converse-stream.js +35 -35
- package/dist/bundle/chunks/{chunk-UTMYL2YO.js → chunk-2W5PWUPO.js} +10 -10
- package/dist/bundle/chunks/{chunk-DUZY4PDA.js → chunk-3E4SMILM.js} +33 -29
- package/dist/bundle/chunks/{chunk-JQZ7BIAI.js → chunk-F7UMX5BV.js} +25 -22
- package/dist/bundle/chunks/{chunk-FP2SXW5M.js → chunk-GNOKILVU.js} +472 -458
- package/dist/bundle/chunks/{chunk-E7WGCXWK.js → chunk-GUUAEK6G.js} +1 -1
- package/dist/bundle/chunks/{chunk-4X774RBJ.js → chunk-GVVRXZHN.js} +4 -4
- package/dist/bundle/chunks/{chunk-UU4WS4BQ.js → chunk-ILRBME2Y.js} +611 -563
- package/dist/bundle/chunks/{chunk-H5CZL7M5.js → chunk-KRMTBTWU.js} +1 -1
- package/dist/bundle/chunks/{chunk-ICLZNV4V.js → chunk-LQ4S7CRR.js} +79 -67
- package/dist/bundle/chunks/{chunk-KLIRQQH5.js → chunk-OTXURGIO.js} +1 -1
- package/dist/bundle/chunks/{chunk-OXJXKCLB.js → chunk-PMISFIBM.js} +1 -1
- package/dist/bundle/chunks/{chunk-BBBBZ5HY.js → chunk-PYU5BR3Z.js} +3 -3
- package/dist/bundle/chunks/{chunk-LFXFQLII.js → chunk-ROSZII6E.js} +1 -1
- package/dist/bundle/chunks/{chunk-E22S6D55.js → chunk-SWRU4BOC.js} +1 -1
- package/dist/bundle/chunks/{chunk-VQTXF23B.js → chunk-TIAXGIMN.js} +1 -1
- package/dist/bundle/chunks/{chunk-3ZI2TEVB.js → chunk-UZ5FVVCP.js} +1 -1
- package/dist/bundle/chunks/{chunk-2NX3BVH6.js → chunk-Z5LYSSTY.js} +2 -2
- package/dist/bundle/chunks/{cli-5YRA5PFB.js → cli-ZKT34WPW.js} +2 -2
- package/dist/bundle/chunks/{compat-LJ4ZIVJZ.js → compat-J5FTRJ6S.js} +8 -8
- package/dist/bundle/chunks/{dist-UAQRGPZO.js → dist-6FQCCUSC.js} +308 -287
- package/dist/bundle/chunks/{dist-QHFJK4TH.js → dist-N7XDUAAO.js} +4 -4
- package/dist/bundle/chunks/{easter-egg-3d-ARXMB2RN.js → easter-egg-3d-5KKDWEIA.js} +1 -1
- package/dist/bundle/chunks/{execute-MFIDTEMB.js → execute-OSBDNQU5.js} +1 -1
- package/dist/bundle/chunks/{extract-EWN2GRAC.js → extract-56PXVZVW.js} +2 -2
- package/dist/bundle/chunks/{host-3OGMFGBY.js → host-2ARI7PQ5.js} +1 -1
- package/dist/bundle/chunks/mistral-conversations-XA2ZGSAH.js +43 -0
- package/dist/bundle/chunks/{openai-codex-responses-5AJAJHTK.js → openai-codex-responses-Y6NRWMOI.js} +2 -2
- package/dist/bundle/chunks/{openai-completions-65RRYKEQ.js → openai-completions-FY77MIZH.js} +6 -6
- package/dist/bundle/chunks/{openai-responses-72W3PGZ7.js → openai-responses-LNSCERKH.js} +2 -2
- package/dist/bundle/chunks/{pi-messages-RLLYRBDT.js → pi-messages-LYJZPRST.js} +7 -6
- package/dist/bundle/chunks/{runtime-HBWXEJT3.js → runtime-JFLZUNYP.js} +1 -1
- package/dist/bundle/chunks/{virtual-modules-LWYOTTHQ.js → virtual-modules-TT2VTOSY.js} +2 -2
- package/dist/bundle/cli-runtime.js +2 -2
- package/dist/bundle/flow/package.json +1 -1
- package/dist/bundle/index.js +5 -5
- package/dist/bundle/rpc-entry.js +2 -2
- package/dist/core/tools/renderers/write.d.ts +2 -2
- package/dist/core/tools/renderers/write.d.ts.map +1 -1
- package/dist/core/tools/renderers/write.js +120 -15
- package/dist/core/tools/renderers/write.js.map +1 -1
- package/dist/humain/bedrock-provider/vendor/index.bundle.mjs +27 -28
- package/dist/humain/flow-loader.d.ts.map +1 -1
- package/dist/humain/flow-loader.js +30 -2
- package/dist/humain/flow-loader.js.map +1 -1
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/assistant-message.js +2 -0
- package/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/dist/modes/interactive/components/mermaid.d.ts.map +1 -1
- package/dist/modes/interactive/components/mermaid.js +4 -0
- package/dist/modes/interactive/components/mermaid.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +4 -0
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +5 -0
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/utils/child-process.d.ts +8 -0
- package/dist/utils/child-process.d.ts.map +1 -1
- package/dist/utils/child-process.js +65 -4
- package/dist/utils/child-process.js.map +1 -1
- package/dist/utils/windows-path.d.ts +9 -0
- package/dist/utils/windows-path.d.ts.map +1 -0
- package/dist/utils/windows-path.js +31 -0
- package/dist/utils/windows-path.js.map +1 -0
- package/docs/flow.md +2 -0
- package/docs/tui.md +1 -1
- package/npm-shrinkwrap.json +6 -6
- package/package.json +2 -2
- package/dist/bundle/chunks/mistral-conversations-5HCMHK6E.js +0 -43
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// Derived from Pi-Bolt (MIT, Copyright (c) 2026 OpenSec (Pi-Bolt)), commit 36a2080f; modified for HUMAIN Code CLI.
|
|
1
2
|
/**
|
|
2
3
|
* Presentation for the write tool.
|
|
3
4
|
*
|
|
@@ -14,8 +15,15 @@ class WriteCallRenderComponent extends Text {
|
|
|
14
15
|
constructor() {
|
|
15
16
|
super("", 0, 0);
|
|
16
17
|
}
|
|
18
|
+
invalidate() {
|
|
19
|
+
super.invalidate();
|
|
20
|
+
// Theme changes invalidate the highlighted prefix as well as the rendered text.
|
|
21
|
+
this.cache = undefined;
|
|
22
|
+
}
|
|
17
23
|
}
|
|
18
24
|
const WRITE_PARTIAL_FULL_HIGHLIGHT_LINES = 50;
|
|
25
|
+
/** The lines of a collapsed call that are shown. */
|
|
26
|
+
const WRITE_COLLAPSED_LINES = 10;
|
|
19
27
|
function highlightSingleLine(line, lang) {
|
|
20
28
|
const highlighted = highlightCode(line, lang);
|
|
21
29
|
return highlighted[0] ?? "";
|
|
@@ -25,6 +33,9 @@ function refreshWriteHighlightPrefix(cache) {
|
|
|
25
33
|
if (prefixCount === 0)
|
|
26
34
|
return;
|
|
27
35
|
const prefixSource = cache.normalizedLines.slice(0, prefixCount).join("\n");
|
|
36
|
+
if (cache.prefixSource === prefixSource)
|
|
37
|
+
return;
|
|
38
|
+
cache.prefixSource = prefixSource;
|
|
28
39
|
const prefixHighlighted = highlightCode(prefixSource, cache.lang);
|
|
29
40
|
for (let i = 0; i < prefixCount; i++) {
|
|
30
41
|
cache.highlightedLines[i] =
|
|
@@ -43,20 +54,70 @@ function rebuildWriteHighlightCacheFull(rawPath, fileContent) {
|
|
|
43
54
|
rawContent: fileContent,
|
|
44
55
|
normalizedLines: normalized.split("\n"),
|
|
45
56
|
highlightedLines: highlightCode(normalized, lang),
|
|
57
|
+
all: true,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/** The cache for a call shown collapsed: the first lines highlighted, as they are while the file streams in. */
|
|
61
|
+
function rebuildWriteHighlightCacheCollapsed(rawPath, fileContent) {
|
|
62
|
+
const lang = rawPath ? getLanguageFromPath(rawPath) : undefined;
|
|
63
|
+
if (!lang)
|
|
64
|
+
return undefined;
|
|
65
|
+
const cache = {
|
|
66
|
+
rawPath,
|
|
67
|
+
lang,
|
|
68
|
+
rawContent: fileContent,
|
|
69
|
+
normalizedLines: replaceTabs(normalizeDisplayText(fileContent)).split("\n"),
|
|
70
|
+
highlightedLines: [],
|
|
71
|
+
all: false,
|
|
46
72
|
};
|
|
73
|
+
refreshWriteHighlightPrefix(cache);
|
|
74
|
+
cache.all = cache.normalizedLines.length <= WRITE_PARTIAL_FULL_HIGHLIGHT_LINES;
|
|
75
|
+
return cache;
|
|
47
76
|
}
|
|
48
|
-
|
|
77
|
+
/** Highlights, each on its own, the lines after the first ones that a collapsed call left unhighlighted. */
|
|
78
|
+
function highlightRemainingLines(cache) {
|
|
79
|
+
if (cache.all)
|
|
80
|
+
return;
|
|
81
|
+
for (let i = Math.min(WRITE_PARTIAL_FULL_HIGHLIGHT_LINES, cache.normalizedLines.length); i < cache.normalizedLines.length; i++) {
|
|
82
|
+
cache.highlightedLines[i] = highlightSingleLine(cache.normalizedLines[i], cache.lang);
|
|
83
|
+
}
|
|
84
|
+
cache.all = true;
|
|
85
|
+
}
|
|
86
|
+
function updateWriteHighlightCacheIncremental(cache, rawPath, fileContent, expanded) {
|
|
49
87
|
const lang = rawPath ? getLanguageFromPath(rawPath) : undefined;
|
|
50
88
|
if (!lang)
|
|
51
89
|
return undefined;
|
|
90
|
+
const rebuild = expanded ? rebuildWriteHighlightCacheFull : rebuildWriteHighlightCacheCollapsed;
|
|
52
91
|
if (!cache)
|
|
53
|
-
return
|
|
92
|
+
return rebuild(rawPath, fileContent);
|
|
54
93
|
if (cache.lang !== lang || cache.rawPath !== rawPath)
|
|
55
|
-
return
|
|
94
|
+
return rebuild(rawPath, fileContent);
|
|
56
95
|
if (!fileContent.startsWith(cache.rawContent))
|
|
57
|
-
return
|
|
96
|
+
return rebuild(rawPath, fileContent);
|
|
97
|
+
if (cache.lineCount !== undefined && (expanded || fileContent.length !== cache.rawContent.length)) {
|
|
98
|
+
return rebuild(rawPath, fileContent);
|
|
99
|
+
}
|
|
100
|
+
if (expanded)
|
|
101
|
+
highlightRemainingLines(cache);
|
|
58
102
|
if (fileContent.length === cache.rawContent.length)
|
|
59
103
|
return cache;
|
|
104
|
+
if (!expanded) {
|
|
105
|
+
// Collapsed: the lines are kept, and the first of them highlighted.
|
|
106
|
+
const added = replaceTabs(normalizeDisplayText(fileContent.slice(cache.rawContent.length))).split("\n");
|
|
107
|
+
cache.rawContent = fileContent;
|
|
108
|
+
cache.all = false;
|
|
109
|
+
cache.complete = false;
|
|
110
|
+
if (cache.normalizedLines.length === 0)
|
|
111
|
+
cache.normalizedLines.push("");
|
|
112
|
+
const lastLine = cache.normalizedLines.length - 1;
|
|
113
|
+
cache.normalizedLines[lastLine] += added[0];
|
|
114
|
+
for (let i = 1; i < added.length; i++)
|
|
115
|
+
cache.normalizedLines.push(added[i]);
|
|
116
|
+
refreshWriteHighlightPrefix(cache);
|
|
117
|
+
// (While the first lines are all the lines, every line is highlighted.)
|
|
118
|
+
cache.all = cache.normalizedLines.length <= WRITE_PARTIAL_FULL_HIGHLIGHT_LINES;
|
|
119
|
+
return cache;
|
|
120
|
+
}
|
|
60
121
|
const deltaRaw = fileContent.slice(cache.rawContent.length);
|
|
61
122
|
const deltaDisplay = normalizeDisplayText(deltaRaw);
|
|
62
123
|
const deltaNormalized = replaceTabs(deltaDisplay);
|
|
@@ -76,6 +137,19 @@ function updateWriteHighlightCacheIncremental(cache, rawPath, fileContent) {
|
|
|
76
137
|
refreshWriteHighlightPrefix(cache);
|
|
77
138
|
return cache;
|
|
78
139
|
}
|
|
140
|
+
/** The lines of a collapsed cache that are counted: without the empty lines at the end, as formatWriteCall() counts them. */
|
|
141
|
+
function countCollapsedLines(cache) {
|
|
142
|
+
if (cache.lineCount !== undefined)
|
|
143
|
+
return cache.lineCount;
|
|
144
|
+
let totalLines = cache.normalizedLines.length;
|
|
145
|
+
// Without the empty lines at the end, unless an empty line is not empty once highlighted (in a language without a
|
|
146
|
+
// highlighter, every line is colored).
|
|
147
|
+
if (highlightSingleLine("", cache.lang) === "") {
|
|
148
|
+
while (totalLines > 0 && cache.normalizedLines[totalLines - 1] === "")
|
|
149
|
+
totalLines--;
|
|
150
|
+
}
|
|
151
|
+
return totalLines;
|
|
152
|
+
}
|
|
79
153
|
function trimTrailingEmptyLines(lines) {
|
|
80
154
|
let end = lines.length;
|
|
81
155
|
while (end > 0 && lines[end - 1] === "") {
|
|
@@ -93,14 +167,24 @@ function formatWriteCall(args, options, theme, cache, cwd) {
|
|
|
93
167
|
}
|
|
94
168
|
else if (fileContent) {
|
|
95
169
|
const lang = rawPath ? getLanguageFromPath(rawPath) : undefined;
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
170
|
+
let totalLines;
|
|
171
|
+
let displayLines;
|
|
172
|
+
if (lang && cache && !cache.all && !options.expanded) {
|
|
173
|
+
// Collapsed, with only the first lines highlighted. The lines are counted as they are when all are
|
|
174
|
+
// highlighted.
|
|
175
|
+
totalLines = countCollapsedLines(cache);
|
|
176
|
+
displayLines = cache.highlightedLines.slice(0, Math.min(WRITE_COLLAPSED_LINES, totalLines));
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
const renderedLines = lang
|
|
180
|
+
? (cache?.highlightedLines ?? highlightCode(replaceTabs(normalizeDisplayText(fileContent)), lang))
|
|
181
|
+
: normalizeDisplayText(fileContent).split("\n");
|
|
182
|
+
const lines = trimTrailingEmptyLines(renderedLines);
|
|
183
|
+
totalLines = lines.length;
|
|
184
|
+
displayLines = lines.slice(0, options.expanded ? lines.length : WRITE_COLLAPSED_LINES);
|
|
185
|
+
}
|
|
186
|
+
const maxLines = options.expanded ? totalLines : WRITE_COLLAPSED_LINES;
|
|
187
|
+
const remaining = totalLines - maxLines;
|
|
104
188
|
text += `\n\n${displayLines.map((line) => (lang ? line : theme.fg("toolOutput", replaceTabs(line)))).join("\n")}`;
|
|
105
189
|
if (remaining > 0) {
|
|
106
190
|
text += `${theme.fg("muted", `\n... (${remaining} more lines, ${totalLines} total,`)} ${keyHint("app.tools.expand", "to expand")}${theme.fg("muted", ")")}`;
|
|
@@ -128,13 +212,34 @@ export const writeRenderers = {
|
|
|
128
212
|
const fileContent = str(renderArgs?.content);
|
|
129
213
|
const component = context.lastComponent ?? new WriteCallRenderComponent();
|
|
130
214
|
if (fileContent !== null) {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
215
|
+
// Expanded, the whole file is highlighted once it is complete. Collapsed, the first lines are, as they were
|
|
216
|
+
// while it streamed in.
|
|
217
|
+
if (!context.argsComplete) {
|
|
218
|
+
component.cache = updateWriteHighlightCacheIncremental(component.cache, rawPath, fileContent, context.expanded);
|
|
219
|
+
}
|
|
220
|
+
else if (context.expanded) {
|
|
221
|
+
component.cache = rebuildWriteHighlightCacheFull(rawPath, fileContent);
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
const cache = component.cache;
|
|
225
|
+
if (cache?.complete && !cache.all && cache.rawPath === rawPath && cache.rawContent === fileContent) {
|
|
226
|
+
refreshWriteHighlightPrefix(cache);
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
component.cache = rebuildWriteHighlightCacheCollapsed(rawPath, fileContent);
|
|
230
|
+
if (component.cache)
|
|
231
|
+
component.cache.complete = true;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
134
234
|
}
|
|
135
235
|
else {
|
|
136
236
|
component.cache = undefined;
|
|
137
237
|
}
|
|
238
|
+
const cache = component.cache;
|
|
239
|
+
if (cache && !cache.all && !context.expanded && !context.isPartial && cache.lineCount === undefined) {
|
|
240
|
+
cache.lineCount = countCollapsedLines(cache);
|
|
241
|
+
cache.normalizedLines = cache.normalizedLines.slice(0, WRITE_PARTIAL_FULL_HIGHLIGHT_LINES);
|
|
242
|
+
}
|
|
138
243
|
component.setText(formatWriteCall(renderArgs, { expanded: context.expanded, isPartial: context.isPartial }, theme, component.cache, context.cwd));
|
|
139
244
|
return component;
|
|
140
245
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"write.js","sourceRoot":"","sources":["../../../../src/core/tools/renderers/write.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,MAAM,2DAA2D,CAAC;AACpF,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAc,MAAM,2CAA2C,CAAC;AAE3G,OAAO,EAAE,oBAAoB,EAAE,cAAc,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAC;AAS5F,MAAM,wBAAyB,SAAQ,IAAI;IAC1C,KAAK,CAAuB;IAE5B;QACC,KAAK,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IACjB,CAAC;CACD;AACD,MAAM,kCAAkC,GAAG,EAAE,CAAC;AAC9C,SAAS,mBAAmB,CAAC,IAAY,EAAE,IAAY;IACtD,MAAM,WAAW,GAAG,aAAa,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC9C,OAAO,WAAW,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;AAC7B,CAAC;AACD,SAAS,2BAA2B,CAAC,KAA0B;IAC9D,MAAM,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,kCAAkC,EAAE,KAAK,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;IAC/F,IAAI,WAAW,KAAK,CAAC;QAAE,OAAO;IAC9B,MAAM,YAAY,GAAG,KAAK,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5E,MAAM,iBAAiB,GAAG,aAAa,CAAC,YAAY,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;IAClE,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,WAAW,E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AG,CACX,CACD,CAAC;QACF,OAAO,SAAS,CAAC;IAClB,CAAC;IACD,YAAY,CAAC,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO;QAC5C,MAAM,MAAM,GAAG,iBAAiB,CAAC,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,EAAE,KAAK,CAAC,CAAC;QACjF,IAAI,CAAC,MAAM,EAAE,CAAC;YACb,MAAM,SAAS,GAAI,OAAO,CAAC,aAAuC,IAAI,IAAI,SAAS,EAAE,CAAC;YACtF,SAAS,CAAC,KAAK,EAAE,CAAC;YAClB,OAAO,SAAS,CAAC;QAClB,CAAC;QACD,MAAM,IAAI,GAAI,OAAO,CAAC,aAAkC,IAAI,IAAI,IAAI,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QAC/E,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QACrB,OAAO,IAAI,CAAC;IACb,CAAC;CACD,CAAC","sourcesContent":["/**\n * Presentation for the write tool.\n *\n * Renderers live apart from the implementation so a process that only displays tool output does not\n * load the execution path or its typebox parameter schema. `write.ts` spreads these into its\n * definition, so the tool's public shape is unchanged.\n */\n\nimport { Container, Text } from \"@earendil-works/pi-tui\";\nimport { keyHint } from \"../../../modes/interactive/components/keybinding-hints.ts\";\nimport { getLanguageFromPath, highlightCode, type Theme } from \"../../../modes/interactive/theme/theme.ts\";\nimport type { ToolDefinition, ToolRenderResultOptions } from \"../../extensions/types.ts\";\nimport { normalizeDisplayText, renderToolPath, replaceTabs, str } from \"../render-utils.ts\";\n\ntype WriteHighlightCache = {\n\trawPath: string | null;\n\tlang: string;\n\trawContent: string;\n\tnormalizedLines: string[];\n\thighlightedLines: string[];\n};\nclass WriteCallRenderComponent extends Text {\n\tcache?: WriteHighlightCache;\n\n\tconstructor() {\n\t\tsuper(\"\", 0, 0);\n\t}\n}\nconst WRITE_PARTIAL_FULL_HIGHLIGHT_LINES = 50;\nfunction highlightSingleLine(line: string, lang: string): string {\n\tconst highlighted = highlightCode(line, lang);\n\treturn highlighted[0] ?? \"\";\n}\nfunction refreshWriteHighlightPrefix(cache: WriteHighlightCache): void {\n\tconst prefixCount = Math.min(WRITE_PARTIAL_FULL_HIGHLIGHT_LINES, cache.normalizedLines.length);\n\tif (prefixCount === 0) return;\n\tconst prefixSource = cache.normalizedLines.slice(0, prefixCount).join(\"\\n\");\n\tconst prefixHighlighted = highlightCode(prefixSource, cache.lang);\n\tfor (let i = 0; i < prefixCount; i++) {\n\t\tcache.highlightedLines[i] =\n\t\t\tprefixHighlighted[i] ?? highlightSingleLine(cache.normalizedLines[i] ?? \"\", cache.lang);\n\t}\n}\nfunction rebuildWriteHighlightCacheFull(rawPath: string | null, fileContent: string): WriteHighlightCache | undefined {\n\tconst lang = rawPath ? getLanguageFromPath(rawPath) : undefined;\n\tif (!lang) return undefined;\n\tconst displayContent = normalizeDisplayText(fileContent);\n\tconst normalized = replaceTabs(displayContent);\n\treturn {\n\t\trawPath,\n\t\tlang,\n\t\trawContent: fileContent,\n\t\tnormalizedLines: normalized.split(\"\\n\"),\n\t\thighlightedLines: highlightCode(normalized, lang),\n\t};\n}\nfunction updateWriteHighlightCacheIncremental(\n\tcache: WriteHighlightCache | undefined,\n\trawPath: string | null,\n\tfileContent: string,\n): WriteHighlightCache | undefined {\n\tconst lang = rawPath ? getLanguageFromPath(rawPath) : undefined;\n\tif (!lang) return undefined;\n\tif (!cache) return rebuildWriteHighlightCacheFull(rawPath, fileContent);\n\tif (cache.lang !== lang || cache.rawPath !== rawPath) return rebuildWriteHighlightCacheFull(rawPath, fileContent);\n\tif (!fileContent.startsWith(cache.rawContent)) return rebuildWriteHighlightCacheFull(rawPath, fileContent);\n\tif (fileContent.length === cache.rawContent.length) return cache;\n\n\tconst deltaRaw = fileContent.slice(cache.rawContent.length);\n\tconst deltaDisplay = normalizeDisplayText(deltaRaw);\n\tconst deltaNormalized = replaceTabs(deltaDisplay);\n\tcache.rawContent = fileContent;\n\tif (cache.normalizedLines.length === 0) {\n\t\tcache.normalizedLines.push(\"\");\n\t\tcache.highlightedLines.push(\"\");\n\t}\n\n\tconst segments = deltaNormalized.split(\"\\n\");\n\tconst lastIndex = cache.normalizedLines.length - 1;\n\tcache.normalizedLines[lastIndex] += segments[0];\n\tcache.highlightedLines[lastIndex] = highlightSingleLine(cache.normalizedLines[lastIndex], cache.lang);\n\tfor (let i = 1; i < segments.length; i++) {\n\t\tcache.normalizedLines.push(segments[i]);\n\t\tcache.highlightedLines.push(highlightSingleLine(segments[i], cache.lang));\n\t}\n\trefreshWriteHighlightPrefix(cache);\n\treturn cache;\n}\nfunction trimTrailingEmptyLines(lines: string[]): string[] {\n\tlet end = lines.length;\n\twhile (end > 0 && lines[end - 1] === \"\") {\n\t\tend--;\n\t}\n\treturn lines.slice(0, end);\n}\nfunction formatWriteCall(\n\targs: { path?: string; file_path?: string; content?: string } | undefined,\n\toptions: ToolRenderResultOptions,\n\ttheme: Theme,\n\tcache: WriteHighlightCache | undefined,\n\tcwd: string,\n): string {\n\tconst rawPath = str(args?.file_path ?? args?.path);\n\tconst fileContent = str(args?.content);\n\tconst pathDisplay = renderToolPath(rawPath, theme, cwd);\n\tlet text = `${theme.fg(\"toolTitle\", theme.bold(\"write\"))} ${pathDisplay}`;\n\n\tif (fileContent === null) {\n\t\ttext += `\\n\\n${theme.fg(\"error\", \"[invalid content arg - expected string]\")}`;\n\t} else if (fileContent) {\n\t\tconst lang = rawPath ? getLanguageFromPath(rawPath) : undefined;\n\t\tconst renderedLines = lang\n\t\t\t? (cache?.highlightedLines ?? highlightCode(replaceTabs(normalizeDisplayText(fileContent)), lang))\n\t\t\t: normalizeDisplayText(fileContent).split(\"\\n\");\n\t\tconst lines = trimTrailingEmptyLines(renderedLines);\n\t\tconst totalLines = lines.length;\n\t\tconst maxLines = options.expanded ? lines.length : 10;\n\t\tconst displayLines = lines.slice(0, maxLines);\n\t\tconst remaining = lines.length - maxLines;\n\t\ttext += `\\n\\n${displayLines.map((line) => (lang ? line : theme.fg(\"toolOutput\", replaceTabs(line)))).join(\"\\n\")}`;\n\t\tif (remaining > 0) {\n\t\t\ttext += `${theme.fg(\"muted\", `\\n... (${remaining} more lines, ${totalLines} total,`)} ${keyHint(\"app.tools.expand\", \"to expand\")}${theme.fg(\"muted\", \")\")}`;\n\t\t}\n\t}\n\n\treturn text;\n}\nfunction formatWriteResult(\n\tresult: { content: Array<{ type: string; text?: string; data?: string; mimeType?: string }>; isError?: boolean },\n\ttheme: Theme,\n): string | undefined {\n\tif (!result.isError) {\n\t\treturn undefined;\n\t}\n\tconst output = result.content\n\t\t.filter((c) => c.type === \"text\")\n\t\t.map((c) => c.text || \"\")\n\t\t.join(\"\\n\");\n\tif (!output) {\n\t\treturn undefined;\n\t}\n\treturn `\\n${theme.fg(\"error\", output)}`;\n}\n\nexport const writeRenderers: Pick<ToolDefinition<any, any>, \"renderCall\" | \"renderResult\"> = {\n\trenderCall(args, theme, context) {\n\t\tconst renderArgs = args as { path?: string; file_path?: string; content?: string } | undefined;\n\t\tconst rawPath = str(renderArgs?.file_path ?? renderArgs?.path);\n\t\tconst fileContent = str(renderArgs?.content);\n\t\tconst component =\n\t\t\t(context.lastComponent as WriteCallRenderComponent | undefined) ?? new WriteCallRenderComponent();\n\t\tif (fileContent !== null) {\n\t\t\tcomponent.cache = context.argsComplete\n\t\t\t\t? rebuildWriteHighlightCacheFull(rawPath, fileContent)\n\t\t\t\t: updateWriteHighlightCacheIncremental(component.cache, rawPath, fileContent);\n\t\t} else {\n\t\t\tcomponent.cache = undefined;\n\t\t}\n\t\tcomponent.setText(\n\t\t\tformatWriteCall(\n\t\t\t\trenderArgs,\n\t\t\t\t{ expanded: context.expanded, isPartial: context.isPartial },\n\t\t\t\ttheme,\n\t\t\t\tcomponent.cache,\n\t\t\t\tcontext.cwd,\n\t\t\t),\n\t\t);\n\t\treturn component;\n\t},\n\trenderResult(result, _options, theme, context) {\n\t\tconst output = formatWriteResult({ ...result, isError: context.isError }, theme);\n\t\tif (!output) {\n\t\t\tconst component = (context.lastComponent as Container | undefined) ?? new Container();\n\t\t\tcomponent.clear();\n\t\t\treturn component;\n\t\t}\n\t\tconst text = (context.lastComponent as Text | undefined) ?? new Text(\"\", 0, 0);\n\t\ttext.setText(output);\n\t\treturn text;\n\t},\n};\n"]}
|
|
1
|
+
{"version":3,"file":"write.js","sourceRoot":"","sources":["../../../../src/core/tools/renderers/write.ts"],"names":[],"mappings":"AAAA,mHAAmH;AACnH;;;;;;GAMG;AAEH,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,MAAM,2DAA2D,CAAC;AACpF,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAc,MAAM,2CAA2C,CAAC;AAE3G,OAAO,EAAE,oBAAoB,EAAE,cAAc,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAC;AAwB5F,MAAM,wBAAyB,SAAQ,IAAI;IAC1C,KAAK,CAAuB;IAE5B;QACC,KAAK,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IACjB,CAAC;IAEQ,UAAU;QAClB,KAAK,CAAC,UAAU,EAAE,CAAC;QACnB,gFAAgF;QAChF,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC;IACxB,CAAC;CACD;AACD,MAAM,kCAAkC,GAAG,EAAE,CAAC;AAC9C,oDAAoD;AACpD,MAAM,qBAAqB,GAAG,EAAE,CAAC;AACjC,SAAS,mBAAmB,CAAC,IAAY,EAAE,IAAY;IACtD,MAAM,WAAW,GAAG,aAAa,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC9C,OAAO,WAAW,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;AAC7B,CAAC;AACD,SAAS,2BAA2B,CAAC,KAA0B;IAC9D,MAAM,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,kCAAkC,EAAE,KAAK,C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E,OAAO,CAAC,OAAO,EAAE,EAAE,KAAK,CAAC,CAAC;QACjF,IAAI,CAAC,MAAM,EAAE,CAAC;YACb,MAAM,SAAS,GAAI,OAAO,CAAC,aAAuC,IAAI,IAAI,SAAS,EAAE,CAAC;YACtF,SAAS,CAAC,KAAK,EAAE,CAAC;YAClB,OAAO,SAAS,CAAC;QAClB,CAAC;QACD,MAAM,IAAI,GAAI,OAAO,CAAC,aAAkC,IAAI,IAAI,IAAI,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QAC/E,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QACrB,OAAO,IAAI,CAAC;IACb,CAAC;CACD,CAAC","sourcesContent":["// Derived from Pi-Bolt (MIT, Copyright (c) 2026 OpenSec (Pi-Bolt)), commit 36a2080f; modified for HUMAIN Code CLI.\n/**\n * Presentation for the write tool.\n *\n * Renderers live apart from the implementation so a process that only displays tool output does not\n * load the execution path or its typebox parameter schema. `write.ts` spreads these into its\n * definition, so the tool's public shape is unchanged.\n */\n\nimport { Container, Text } from \"@earendil-works/pi-tui\";\nimport { keyHint } from \"../../../modes/interactive/components/keybinding-hints.ts\";\nimport { getLanguageFromPath, highlightCode, type Theme } from \"../../../modes/interactive/theme/theme.ts\";\nimport type { ToolRenderers, ToolRenderResultOptions } from \"../../extensions/types.ts\";\nimport { normalizeDisplayText, renderToolPath, replaceTabs, str } from \"../render-utils.ts\";\n\ntype WriteHighlightCache = {\n\trawPath: string | null;\n\tlang: string;\n\trawContent: string;\n\tnormalizedLines: string[];\n\t/**\n\t * The lines highlighted. When the call is shown collapsed, only the first lines are: the lines after the ones that can\n\t * be shown are highlighted when the call is expanded (`all`), not as each one arrives and again when the file is\n\t * complete, which for a large file stops everything for as long as highlighting all of it takes.\n\t */\n\thighlightedLines: string[];\n\tall: boolean;\n\t/** Made from the complete file, not from the pieces it arrived in. */\n\tcomplete?: boolean;\n\t/**\n\t * Set once the call has its result and is shown collapsed: the count of lines shown when expanded, with\n\t * normalizedLines cut to the first lines. A collapsed call needs no more of them, and every write of a session stays in\n\t * the chat: keeping each file split into lines again holds more memory than the files themselves.\n\t */\n\tlineCount?: number;\n\tprefixSource?: string;\n};\nclass WriteCallRenderComponent extends Text {\n\tcache?: WriteHighlightCache;\n\n\tconstructor() {\n\t\tsuper(\"\", 0, 0);\n\t}\n\n\toverride invalidate(): void {\n\t\tsuper.invalidate();\n\t\t// Theme changes invalidate the highlighted prefix as well as the rendered text.\n\t\tthis.cache = undefined;\n\t}\n}\nconst WRITE_PARTIAL_FULL_HIGHLIGHT_LINES = 50;\n/** The lines of a collapsed call that are shown. */\nconst WRITE_COLLAPSED_LINES = 10;\nfunction highlightSingleLine(line: string, lang: string): string {\n\tconst highlighted = highlightCode(line, lang);\n\treturn highlighted[0] ?? \"\";\n}\nfunction refreshWriteHighlightPrefix(cache: WriteHighlightCache): void {\n\tconst prefixCount = Math.min(WRITE_PARTIAL_FULL_HIGHLIGHT_LINES, cache.normalizedLines.length);\n\tif (prefixCount === 0) return;\n\tconst prefixSource = cache.normalizedLines.slice(0, prefixCount).join(\"\\n\");\n\tif (cache.prefixSource === prefixSource) return;\n\tcache.prefixSource = prefixSource;\n\tconst prefixHighlighted = highlightCode(prefixSource, cache.lang);\n\tfor (let i = 0; i < prefixCount; i++) {\n\t\tcache.highlightedLines[i] =\n\t\t\tprefixHighlighted[i] ?? highlightSingleLine(cache.normalizedLines[i] ?? \"\", cache.lang);\n\t}\n}\nfunction rebuildWriteHighlightCacheFull(rawPath: string | null, fileContent: string): WriteHighlightCache | undefined {\n\tconst lang = rawPath ? getLanguageFromPath(rawPath) : undefined;\n\tif (!lang) return undefined;\n\tconst displayContent = normalizeDisplayText(fileContent);\n\tconst normalized = replaceTabs(displayContent);\n\treturn {\n\t\trawPath,\n\t\tlang,\n\t\trawContent: fileContent,\n\t\tnormalizedLines: normalized.split(\"\\n\"),\n\t\thighlightedLines: highlightCode(normalized, lang),\n\t\tall: true,\n\t};\n}\n/** The cache for a call shown collapsed: the first lines highlighted, as they are while the file streams in. */\nfunction rebuildWriteHighlightCacheCollapsed(\n\trawPath: string | null,\n\tfileContent: string,\n): WriteHighlightCache | undefined {\n\tconst lang = rawPath ? getLanguageFromPath(rawPath) : undefined;\n\tif (!lang) return undefined;\n\tconst cache: WriteHighlightCache = {\n\t\trawPath,\n\t\tlang,\n\t\trawContent: fileContent,\n\t\tnormalizedLines: replaceTabs(normalizeDisplayText(fileContent)).split(\"\\n\"),\n\t\thighlightedLines: [],\n\t\tall: false,\n\t};\n\trefreshWriteHighlightPrefix(cache);\n\tcache.all = cache.normalizedLines.length <= WRITE_PARTIAL_FULL_HIGHLIGHT_LINES;\n\treturn cache;\n}\n/** Highlights, each on its own, the lines after the first ones that a collapsed call left unhighlighted. */\nfunction highlightRemainingLines(cache: WriteHighlightCache): void {\n\tif (cache.all) return;\n\tfor (\n\t\tlet i = Math.min(WRITE_PARTIAL_FULL_HIGHLIGHT_LINES, cache.normalizedLines.length);\n\t\ti < cache.normalizedLines.length;\n\t\ti++\n\t) {\n\t\tcache.highlightedLines[i] = highlightSingleLine(cache.normalizedLines[i], cache.lang);\n\t}\n\tcache.all = true;\n}\nfunction updateWriteHighlightCacheIncremental(\n\tcache: WriteHighlightCache | undefined,\n\trawPath: string | null,\n\tfileContent: string,\n\texpanded: boolean,\n): WriteHighlightCache | undefined {\n\tconst lang = rawPath ? getLanguageFromPath(rawPath) : undefined;\n\tif (!lang) return undefined;\n\tconst rebuild = expanded ? rebuildWriteHighlightCacheFull : rebuildWriteHighlightCacheCollapsed;\n\tif (!cache) return rebuild(rawPath, fileContent);\n\tif (cache.lang !== lang || cache.rawPath !== rawPath) return rebuild(rawPath, fileContent);\n\tif (!fileContent.startsWith(cache.rawContent)) return rebuild(rawPath, fileContent);\n\tif (cache.lineCount !== undefined && (expanded || fileContent.length !== cache.rawContent.length)) {\n\t\treturn rebuild(rawPath, fileContent);\n\t}\n\tif (expanded) highlightRemainingLines(cache);\n\tif (fileContent.length === cache.rawContent.length) return cache;\n\tif (!expanded) {\n\t\t// Collapsed: the lines are kept, and the first of them highlighted.\n\t\tconst added = replaceTabs(normalizeDisplayText(fileContent.slice(cache.rawContent.length))).split(\"\\n\");\n\t\tcache.rawContent = fileContent;\n\t\tcache.all = false;\n\t\tcache.complete = false;\n\t\tif (cache.normalizedLines.length === 0) cache.normalizedLines.push(\"\");\n\t\tconst lastLine = cache.normalizedLines.length - 1;\n\t\tcache.normalizedLines[lastLine] += added[0];\n\t\tfor (let i = 1; i < added.length; i++) cache.normalizedLines.push(added[i]);\n\t\trefreshWriteHighlightPrefix(cache);\n\t\t// (While the first lines are all the lines, every line is highlighted.)\n\t\tcache.all = cache.normalizedLines.length <= WRITE_PARTIAL_FULL_HIGHLIGHT_LINES;\n\t\treturn cache;\n\t}\n\n\tconst deltaRaw = fileContent.slice(cache.rawContent.length);\n\tconst deltaDisplay = normalizeDisplayText(deltaRaw);\n\tconst deltaNormalized = replaceTabs(deltaDisplay);\n\tcache.rawContent = fileContent;\n\tif (cache.normalizedLines.length === 0) {\n\t\tcache.normalizedLines.push(\"\");\n\t\tcache.highlightedLines.push(\"\");\n\t}\n\n\tconst segments = deltaNormalized.split(\"\\n\");\n\tconst lastIndex = cache.normalizedLines.length - 1;\n\tcache.normalizedLines[lastIndex] += segments[0];\n\tcache.highlightedLines[lastIndex] = highlightSingleLine(cache.normalizedLines[lastIndex], cache.lang);\n\tfor (let i = 1; i < segments.length; i++) {\n\t\tcache.normalizedLines.push(segments[i]);\n\t\tcache.highlightedLines.push(highlightSingleLine(segments[i], cache.lang));\n\t}\n\trefreshWriteHighlightPrefix(cache);\n\treturn cache;\n}\n/** The lines of a collapsed cache that are counted: without the empty lines at the end, as formatWriteCall() counts them. */\nfunction countCollapsedLines(cache: WriteHighlightCache): number {\n\tif (cache.lineCount !== undefined) return cache.lineCount;\n\tlet totalLines = cache.normalizedLines.length;\n\t// Without the empty lines at the end, unless an empty line is not empty once highlighted (in a language without a\n\t// highlighter, every line is colored).\n\tif (highlightSingleLine(\"\", cache.lang) === \"\") {\n\t\twhile (totalLines > 0 && cache.normalizedLines[totalLines - 1] === \"\") totalLines--;\n\t}\n\treturn totalLines;\n}\nfunction trimTrailingEmptyLines(lines: string[]): string[] {\n\tlet end = lines.length;\n\twhile (end > 0 && lines[end - 1] === \"\") {\n\t\tend--;\n\t}\n\treturn lines.slice(0, end);\n}\nfunction formatWriteCall(\n\targs: { path?: string; file_path?: string; content?: string } | undefined,\n\toptions: ToolRenderResultOptions,\n\ttheme: Theme,\n\tcache: WriteHighlightCache | undefined,\n\tcwd: string,\n): string {\n\tconst rawPath = str(args?.file_path ?? args?.path);\n\tconst fileContent = str(args?.content);\n\tconst pathDisplay = renderToolPath(rawPath, theme, cwd);\n\tlet text = `${theme.fg(\"toolTitle\", theme.bold(\"write\"))} ${pathDisplay}`;\n\n\tif (fileContent === null) {\n\t\ttext += `\\n\\n${theme.fg(\"error\", \"[invalid content arg - expected string]\")}`;\n\t} else if (fileContent) {\n\t\tconst lang = rawPath ? getLanguageFromPath(rawPath) : undefined;\n\t\tlet totalLines: number;\n\t\tlet displayLines: string[];\n\t\tif (lang && cache && !cache.all && !options.expanded) {\n\t\t\t// Collapsed, with only the first lines highlighted. The lines are counted as they are when all are\n\t\t\t// highlighted.\n\t\t\ttotalLines = countCollapsedLines(cache);\n\t\t\tdisplayLines = cache.highlightedLines.slice(0, Math.min(WRITE_COLLAPSED_LINES, totalLines));\n\t\t} else {\n\t\t\tconst renderedLines = lang\n\t\t\t\t? (cache?.highlightedLines ?? highlightCode(replaceTabs(normalizeDisplayText(fileContent)), lang))\n\t\t\t\t: normalizeDisplayText(fileContent).split(\"\\n\");\n\t\t\tconst lines = trimTrailingEmptyLines(renderedLines);\n\t\t\ttotalLines = lines.length;\n\t\t\tdisplayLines = lines.slice(0, options.expanded ? lines.length : WRITE_COLLAPSED_LINES);\n\t\t}\n\t\tconst maxLines = options.expanded ? totalLines : WRITE_COLLAPSED_LINES;\n\t\tconst remaining = totalLines - maxLines;\n\t\ttext += `\\n\\n${displayLines.map((line) => (lang ? line : theme.fg(\"toolOutput\", replaceTabs(line)))).join(\"\\n\")}`;\n\t\tif (remaining > 0) {\n\t\t\ttext += `${theme.fg(\"muted\", `\\n... (${remaining} more lines, ${totalLines} total,`)} ${keyHint(\"app.tools.expand\", \"to expand\")}${theme.fg(\"muted\", \")\")}`;\n\t\t}\n\t}\n\n\treturn text;\n}\nfunction formatWriteResult(\n\tresult: { content: Array<{ type: string; text?: string; data?: string; mimeType?: string }>; isError?: boolean },\n\ttheme: Theme,\n): string | undefined {\n\tif (!result.isError) {\n\t\treturn undefined;\n\t}\n\tconst output = result.content\n\t\t.filter((c) => c.type === \"text\")\n\t\t.map((c) => c.text || \"\")\n\t\t.join(\"\\n\");\n\tif (!output) {\n\t\treturn undefined;\n\t}\n\treturn `\\n${theme.fg(\"error\", output)}`;\n}\n\nexport const writeRenderers: Pick<ToolRenderers, \"renderCall\" | \"renderResult\"> = {\n\trenderCall(args, theme, context) {\n\t\tconst renderArgs = args as { path?: string; file_path?: string; content?: string } | undefined;\n\t\tconst rawPath = str(renderArgs?.file_path ?? renderArgs?.path);\n\t\tconst fileContent = str(renderArgs?.content);\n\t\tconst component =\n\t\t\t(context.lastComponent as WriteCallRenderComponent | undefined) ?? new WriteCallRenderComponent();\n\t\tif (fileContent !== null) {\n\t\t\t// Expanded, the whole file is highlighted once it is complete. Collapsed, the first lines are, as they were\n\t\t\t// while it streamed in.\n\t\t\tif (!context.argsComplete) {\n\t\t\t\tcomponent.cache = updateWriteHighlightCacheIncremental(\n\t\t\t\t\tcomponent.cache,\n\t\t\t\t\trawPath,\n\t\t\t\t\tfileContent,\n\t\t\t\t\tcontext.expanded,\n\t\t\t\t);\n\t\t\t} else if (context.expanded) {\n\t\t\t\tcomponent.cache = rebuildWriteHighlightCacheFull(rawPath, fileContent);\n\t\t\t} else {\n\t\t\t\tconst cache = component.cache;\n\t\t\t\tif (cache?.complete && !cache.all && cache.rawPath === rawPath && cache.rawContent === fileContent) {\n\t\t\t\t\trefreshWriteHighlightPrefix(cache);\n\t\t\t\t} else {\n\t\t\t\t\tcomponent.cache = rebuildWriteHighlightCacheCollapsed(rawPath, fileContent);\n\t\t\t\t\tif (component.cache) component.cache.complete = true;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tcomponent.cache = undefined;\n\t\t}\n\t\tconst cache = component.cache;\n\t\tif (cache && !cache.all && !context.expanded && !context.isPartial && cache.lineCount === undefined) {\n\t\t\tcache.lineCount = countCollapsedLines(cache);\n\t\t\tcache.normalizedLines = cache.normalizedLines.slice(0, WRITE_PARTIAL_FULL_HIGHLIGHT_LINES);\n\t\t}\n\t\tcomponent.setText(\n\t\t\tformatWriteCall(\n\t\t\t\trenderArgs,\n\t\t\t\t{ expanded: context.expanded, isPartial: context.isPartial },\n\t\t\t\ttheme,\n\t\t\t\tcomponent.cache,\n\t\t\t\tcontext.cwd,\n\t\t\t),\n\t\t);\n\t\treturn component;\n\t},\n\trenderResult(result, _options, theme, context) {\n\t\tconst output = formatWriteResult({ ...result, isError: context.isError }, theme);\n\t\tif (!output) {\n\t\t\tconst component = (context.lastComponent as Container | undefined) ?? new Container();\n\t\t\tcomponent.clear();\n\t\t\treturn component;\n\t\t}\n\t\tconst text = (context.lastComponent as Text | undefined) ?? new Text(\"\", 0, 0);\n\t\ttext.setText(output);\n\t\treturn text;\n\t},\n};\n"]}
|
|
@@ -318,10 +318,6 @@ function providerHeadersToRecord(...headerSources) {
|
|
|
318
318
|
// packages/ai/src/utils/json-parse.ts
|
|
319
319
|
import { parse as partialParse } from "partial-json";
|
|
320
320
|
var VALID_JSON_ESCAPES = /* @__PURE__ */ new Set(['"', "\\", "/", "b", "f", "n", "r", "t", "u"]);
|
|
321
|
-
function isControlCharacter(char) {
|
|
322
|
-
const codePoint = char.codePointAt(0);
|
|
323
|
-
return codePoint !== void 0 && codePoint >= 0 && codePoint <= 31;
|
|
324
|
-
}
|
|
325
321
|
function escapeControlCharacter(char) {
|
|
326
322
|
switch (char) {
|
|
327
323
|
case "\b":
|
|
@@ -340,46 +336,36 @@ function escapeControlCharacter(char) {
|
|
|
340
336
|
}
|
|
341
337
|
function repairJson(json) {
|
|
342
338
|
let repaired = "";
|
|
339
|
+
let runStart = 0;
|
|
343
340
|
let inString = false;
|
|
344
341
|
for (let index = 0; index < json.length; index++) {
|
|
345
|
-
const
|
|
342
|
+
const code = json.charCodeAt(index);
|
|
346
343
|
if (!inString) {
|
|
347
|
-
|
|
348
|
-
if (char === '"') {
|
|
344
|
+
if (code === 34) {
|
|
349
345
|
inString = true;
|
|
350
346
|
}
|
|
351
347
|
continue;
|
|
352
348
|
}
|
|
353
|
-
if (
|
|
354
|
-
repaired += char;
|
|
349
|
+
if (code === 34) {
|
|
355
350
|
inString = false;
|
|
356
351
|
continue;
|
|
357
352
|
}
|
|
358
|
-
if (
|
|
353
|
+
if (code === 92) {
|
|
359
354
|
const nextChar = json[index + 1];
|
|
360
|
-
if (nextChar
|
|
361
|
-
repaired += "\\\\";
|
|
362
|
-
continue;
|
|
363
|
-
}
|
|
364
|
-
if (nextChar === "u") {
|
|
365
|
-
const unicodeDigits = json.slice(index + 2, index + 6);
|
|
366
|
-
if (/^[0-9a-fA-F]{4}$/.test(unicodeDigits)) {
|
|
367
|
-
repaired += `\\u${unicodeDigits}`;
|
|
368
|
-
index += 5;
|
|
369
|
-
continue;
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
if (VALID_JSON_ESCAPES.has(nextChar)) {
|
|
373
|
-
repaired += `\\${nextChar}`;
|
|
355
|
+
if (nextChar !== void 0 && VALID_JSON_ESCAPES.has(nextChar)) {
|
|
374
356
|
index += 1;
|
|
375
357
|
continue;
|
|
376
358
|
}
|
|
377
|
-
repaired +=
|
|
359
|
+
repaired += `${json.slice(runStart, index)}\\\\`;
|
|
360
|
+
runStart = index + 1;
|
|
378
361
|
continue;
|
|
379
362
|
}
|
|
380
|
-
|
|
363
|
+
if (code <= 31) {
|
|
364
|
+
repaired += json.slice(runStart, index) + escapeControlCharacter(json[index]);
|
|
365
|
+
runStart = index + 1;
|
|
366
|
+
}
|
|
381
367
|
}
|
|
382
|
-
return repaired;
|
|
368
|
+
return runStart === 0 ? json : repaired + json.slice(runStart);
|
|
383
369
|
}
|
|
384
370
|
function parseJsonWithRepair(json) {
|
|
385
371
|
try {
|
|
@@ -412,6 +398,16 @@ function parseStreamingJson(partialJson) {
|
|
|
412
398
|
}
|
|
413
399
|
}
|
|
414
400
|
}
|
|
401
|
+
var lengthsParsedWhileStreaming = /* @__PURE__ */ new WeakMap();
|
|
402
|
+
function parseStreamingJsonWhileStreaming(block, partialJson, current) {
|
|
403
|
+
const length = partialJson?.length ?? 0;
|
|
404
|
+
const parsed = lengthsParsedWhileStreaming.get(block);
|
|
405
|
+
if (current !== void 0 && parsed !== void 0 && length - parsed < (parsed < 1024 ? 1 : parsed >> 3)) {
|
|
406
|
+
return current;
|
|
407
|
+
}
|
|
408
|
+
lengthsParsedWhileStreaming.set(block, length);
|
|
409
|
+
return parseStreamingJson(partialJson);
|
|
410
|
+
}
|
|
415
411
|
|
|
416
412
|
// packages/ai/src/utils/provider-env.ts
|
|
417
413
|
var procEnvCache = null;
|
|
@@ -1449,7 +1445,7 @@ function handleContentBlockDelta(event, blocks, output, stream2) {
|
|
|
1449
1445
|
}
|
|
1450
1446
|
} else if (delta?.toolUse && block?.type === "toolCall") {
|
|
1451
1447
|
block.partialJson = (block.partialJson || "") + (delta.toolUse.input || "");
|
|
1452
|
-
block.arguments =
|
|
1448
|
+
block.arguments = parseStreamingJsonWhileStreaming(block, block.partialJson, block.arguments);
|
|
1453
1449
|
stream2.push({ type: "toolcall_delta", contentIndex: index, delta: delta.toolUse.input || "", partial: output });
|
|
1454
1450
|
} else if (delta?.reasoningContent) {
|
|
1455
1451
|
let thinkingBlock = block;
|
|
@@ -1499,6 +1495,9 @@ function flushRedactedContent(block) {
|
|
|
1499
1495
|
}
|
|
1500
1496
|
function finalizeStreamingBlock(block) {
|
|
1501
1497
|
delete block.index;
|
|
1498
|
+
if (block.type === "toolCall" && block.partialJson !== void 0) {
|
|
1499
|
+
block.arguments = parseStreamingJson(block.partialJson);
|
|
1500
|
+
}
|
|
1502
1501
|
delete block.partialJson;
|
|
1503
1502
|
flushRedactedContent(block);
|
|
1504
1503
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flow-loader.d.ts","sourceRoot":"","sources":["../../src/humain/flow-loader.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"flow-loader.d.ts","sourceRoot":"","sources":["../../src/humain/flow-loader.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,4CAA4C,CAAC;AAEhH,OAAO,KAAK,EAEX,uBAAuB,EACvB,gBAAgB,EAEhB,MAAM,6BAA6B,CAAC;AAIrC;;;;;GAKG;AAEH,eAAO,MAAM,wBAAwB,kCAAkC,CAAC;AACxE,eAAO,MAAM,2BAA2B,qCAAqC,CAAC;AAE9E,8FAA8F;AAC9F,MAAM,WAAW,cAAc;IAC9B,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC;QAAE,OAAO,EAAE,aAAa,CAAC;QAAC,MAAM,CAAC,EAAE,YAAY,CAAA;KAAE,CAAC,CAAC;IACnF,WAAW,IAAI,MAAM,GAAG,SAAS,CAAC;CAClC;AAED,MAAM,WAAW,UAAU;IAC1B,aAAa,EAAE,gBAAgB,CAAC;IAChC,kHAAkH;IAClH,oBAAoB,CAAC,CAAC,OAAO,EAAE;QAC9B,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,gBAAgB,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;QAC/D,UAAU,CAAC,EAAE,MAAM,OAAO,CAAC;QAC3B,wFAAwF;QACxF,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,MA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CAAC,OAAO,GAAE,uBAA4B,GAAG,gBAAgB,CAkI9G"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createHash, randomBytes } from "node:crypto";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import { dirname, isAbsolute, join, resolve } from "node:path";
|
|
4
|
+
import { getAgentDir, getBundledFlowPackageDir, getBundledFlowProfilesDir, PACKAGE_NAME, VERSION } from "../config.js";
|
|
4
5
|
import { createTraceRedactor } from "../core/trace/redaction.js";
|
|
5
6
|
import { sanitizeForTerminal } from "../core/trace-client/sanitize.js";
|
|
6
7
|
/**
|
|
@@ -248,6 +249,30 @@ async function runFlowExtension(pi, flowExtension, lastSessionStart) {
|
|
|
248
249
|
live = true;
|
|
249
250
|
return captured;
|
|
250
251
|
}
|
|
252
|
+
function isSameCliReleaseFlowDir(dir) {
|
|
253
|
+
if (!isAbsolute(dir) || VERSION === "0.0.0")
|
|
254
|
+
return false;
|
|
255
|
+
try {
|
|
256
|
+
const manifest = JSON.parse(readFileSync(join(dir, "package.json"), "utf8"));
|
|
257
|
+
if (!isRecord(manifest) || manifest.name !== "@humain/flow")
|
|
258
|
+
return false;
|
|
259
|
+
}
|
|
260
|
+
catch {
|
|
261
|
+
return false;
|
|
262
|
+
}
|
|
263
|
+
// Bun ships flow/ beside package.json; bundled Node ships dist/bundle/flow/.
|
|
264
|
+
for (const root of [dirname(dir), resolve(dir, "../../..")]) {
|
|
265
|
+
try {
|
|
266
|
+
const manifest = JSON.parse(readFileSync(join(root, "package.json"), "utf8"));
|
|
267
|
+
if (isRecord(manifest) && manifest.name === PACKAGE_NAME)
|
|
268
|
+
return manifest.version === VERSION;
|
|
269
|
+
}
|
|
270
|
+
catch {
|
|
271
|
+
// Missing or unreadable release metadata cannot validate an override.
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
return false;
|
|
275
|
+
}
|
|
251
276
|
export function createHumainFlowLoaderExtensionFactory(options = {}) {
|
|
252
277
|
const env = options.env ?? process.env;
|
|
253
278
|
// This is the single sanctioned lazy-load boundary for @humain/flow (see AGENTS.md "No inline imports" exception).
|
|
@@ -265,6 +290,9 @@ export function createHumainFlowLoaderExtensionFactory(options = {}) {
|
|
|
265
290
|
pi.registerFlag("profile", { description: "Flow profile id", type: "string" });
|
|
266
291
|
pi.registerFlag("flow-admission", { description: "Flow run admission file (JSON)", type: "string" });
|
|
267
292
|
const loadModule = async () => {
|
|
293
|
+
const override = env[HUMAIN_FLOW_PACKAGE_DIR_ENV];
|
|
294
|
+
if (override && !isSameCliReleaseFlowDir(override))
|
|
295
|
+
delete env[HUMAIN_FLOW_PACKAGE_DIR_ENV];
|
|
268
296
|
if (flowPackageDir && !env[HUMAIN_FLOW_PACKAGE_DIR_ENV])
|
|
269
297
|
env[HUMAIN_FLOW_PACKAGE_DIR_ENV] = flowPackageDir;
|
|
270
298
|
flowModule ??= importFlow().then((module) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flow-loader.js","sourceRoot":"","sources":["../../src/humain/flow-loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAGjC,OAAO,EAAE,WAAW,EAAE,wBAAwB,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAC;AAOhG,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAEvE;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,wBAAwB,GAAG,+BAA+B,CAAC;AACxE,MAAM,CAAC,MAAM,2BAA2B,GAAG,kCAAkC,CAAC;AAkC9E,IAAI,UAAsC,CAAC;AAC3C,IAAI,aAA0C,CAAC;AAC/C,IAAI,SAA0E,CAAC;AAC/E,IAAI,SAAkE,CAAC;AACvE,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oBACD,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;gBAC/B,CAAC;aACD,CAAC,CAAC;QACJ,CAAC;IACF,CAAC,CAAC;AACH,CAAC","sourcesContent":["import { createHash, randomBytes } from \"node:crypto\";\nimport { join } from \"node:path\";\nimport type { FlowFailureClass } from \"@humain/humain-code-contracts/flow-common\";\nimport type { FlowEventFrameV1, FlowReceiptV1, FlowStatusV1 } from \"@humain/humain-code-contracts/flow-control\";\nimport { getAgentDir, getBundledFlowPackageDir, getBundledFlowProfilesDir } from \"../config.ts\";\nimport type {\n\tExtensionAPI,\n\tExtensionCommandContext,\n\tExtensionFactory,\n\tRegisteredCommand,\n} from \"../core/extensions/types.ts\";\nimport { createTraceRedactor } from \"../core/trace/redaction.ts\";\nimport { sanitizeForTerminal } from \"../core/trace-client/sanitize.ts\";\n\n/**\n * Lazy loader for the private @humain/flow package.\n *\n * The CLI entry graph must not statically reach Flow: this module registers cheap stub commands and a flag, and\n * only loads Flow (one memoized dynamic import) the first time a stub runs. Flow is bundled as its own chunk.\n */\n\nexport const HUMAIN_FLOW_DISABLED_ENV = \"HUMAIN_TERMINAL_FLOW_DISABLED\";\nexport const HUMAIN_FLOW_PACKAGE_DIR_ENV = \"HUMAIN_TERMINAL_FLOW_PACKAGE_DIR\";\n\n/** Run-control surface Flow exposes to rpc mode (flow_status/pause/resume/cancel/message). */\nexport interface FlowRpcControl {\n\thandle(input: unknown): Promise<{ receipt: FlowReceiptV1; status?: FlowStatusV1 }>;\n\tactiveRunId(): string | undefined;\n}\n\nexport interface FlowModule {\n\tflowExtension: ExtensionFactory;\n\t/** Documented rpc hook: called once when Flow loads; `writeFrame` carries `flow_event` frames to the rpc host. */\n\tcreateFlowRpcControl?(options: {\n\t\twriteFrame?: (frame: FlowEventFrameV1) => void | Promise<void>;\n\t\tisDisabled?: () => boolean;\n\t\t/** Queues text on the host session as a follow-up (flow_message with no active run). */\n\t\tsendFollowUp?: (text: string) => Promise<void>;\n\t}): FlowRpcControl;\n\t/** B1 profile command; optional so test fakes need not provide it. Methods stay bivariant for the real signatures. */\n\trunFlowProfileCommand?(args: string, ctx: ExtensionCommandContext, deps: { store: unknown }): Promise<unknown>;\n\tcreateProfileStore?(options: { flowDir: string; builtInDir?: string }): unknown;\n}\n\nexport interface HumainFlowLoaderOptions {\n\t/** Test seam. Defaults to the single sanctioned dynamic import of @humain/flow. */\n\timportFlow?: () => Promise<FlowModule>;\n\tenv?: NodeJS.ProcessEnv;\n\t/** Directory holding Flow's agents/assets/package.json. Defaults to the bundled layout's flow/ dir. */\n\tflowPackageDir?: string;\n\t/** Built-in Flow profiles dir. Defaults to the bundled layout's assets/profiles; undefined lets Flow find its own. */\n\tbuiltInProfilesDir?: string;\n\t/** Flow profile store directory. Defaults to `<agentDir>/flow`. */\n\tflowDir?: string;\n}\n\nlet rpcControl: FlowRpcControl | undefined;\nlet disabledProbe: (() => boolean) | undefined;\nlet rpcOutput: ((frame: FlowEventFrameV1) => void | Promise<void>) | undefined;\nlet rpcLoader: (() => Promise<FlowRpcControl | undefined>) | undefined;\nlet rpcFollowUp: ((text: string) => Promise<void>) | undefined;\n\n/** The documented rpc hook: rpc mode reads Flow's run control here and never imports Flow itself. */\nexport function getFlowRpcControl(): FlowRpcControl | undefined {\n\treturn rpcControl;\n}\n\n/**\n * The documented rpc hook: loads Flow through the same lazy-load path the stub commands use and returns its run control.\n * Undefined when Flow is disabled (never loaded then), not wired, or fails to load.\n */\nexport async function loadFlowRpcControl(): Promise<FlowRpcControl | undefined> {\n\tif (rpcControl) return rpcControl;\n\tif (isFlowDisabled()) return undefined;\n\treturn rpcLoader?.();\n}\n\n/** True while Flow is switched off (flow.enabled=false or the env kill switch); rpc mode refuses flow_resume then. */\nexport function isFlowDisabled(): boolean {\n\treturn disabledProbe?.() ?? false;\n}\n\n/** The documented rpc hook: rpc mode registers where Flow's `flow_event` frames are written. */\nexport function setFlowRpcOutput(writer: ((frame: FlowEventFrameV1) => void | Promise<void>) | undefined): void {\n\trpcOutput = writer;\n}\n\n/** The documented rpc hook: rpc mode registers how direct-mode flow_message text is queued as a host follow-up. */\nexport function setFlowRpcFollowUp(queue: ((text: string) => Promise<void>) | undefined): void {\n\trpcFollowUp = queue;\n}\n\ntype CommandOptions = Omit<RegisteredCommand, \"name\" | \"sourceInfo\">;\ntype EventHandler = (...args: unknown[]) => unknown;\n\n/**\n * ExtensionAPI members that only record registrations (see core/extensions/loader.ts). They are staged while Flow's\n * factory runs and applied to the real pi only after the factory and the session_start replay succeed. Reads and\n * actions (getFlag, getSettings, exec, sendMessage, ...) and `events` stay live: they have no registration to undo\n * or are needed by the factory itself. Flow uses none of the live ones that subscribe (`events.on`).\n */\nconst STAGED_MEMBERS = new Set([\n\t\"on\",\n\t\"registerTool\",\n\t\"registerCommand\",\n\t\"registerShortcut\",\n\t\"registerFlag\",\n\t\"registerMessageRenderer\",\n\t\"registerMarkdownTransformer\",\n\t\"registerEntryRenderer\",\n\t\"registerProvider\",\n\t\"unregisterProvider\",\n\t\"registerMcpServer\",\n\t\"unregisterMcpServer\",\n\t\"registerVirtualModel\",\n\t\"unregisterVirtualModel\",\n]);\n\ninterface StagedCall {\n\tmember: string;\n\targs: unknown[];\n\tcancelled: boolean;\n\tunsubscribe?: () => void;\n}\n\n// Descriptions match the real Flow commands (packages/flow/src). flow-profile is served here through Flow's\n// runFlowProfileCommand.\nconst STUB_COMMANDS: Record<string, string> = {\n\tflow:\n\t\t\"Plan and dispatch a hierarchical agent run. \" +\n\t\t\"Args: <goal> [--task-class T] [--complexity N] [--risk low|medium|high|critical] \" +\n\t\t\"[--profile NAME] [--lead-size small|standard|large] [--cheap ALIAS] [--mid ALIAS] [--premium ALIAS] [--frontier ALIAS] [--model <capability>=ALIAS] [--effort LEVEL] \" +\n\t\t\"[--quality-floor F] [--cost-aggressiveness C] [--max-retries R] [--flow-admission FILE] \" +\n\t\t\"[--context FILE ...] [--with-last-reply] [--force]\\n\\n\" +\n\t\t\"With no triage flags, an LLM triage call (cheapest configured model) \" +\n\t\t\"auto-fills task_class, complexity, and risk from the goal text. \" +\n\t\t\"Models: flags > profile (orchestrator-profiles.json) > cost-tier resolver. See /flow-models.\",\n\t\"flow-continue\":\n\t\t\"Preview and explicitly confirm recovery in the original checkout. Args: [run-id] (no --yes or --force).\",\n\t\"flow-status\": \"Open the full live orchestration board (↑↓ PgUp/PgDn scroll, Esc closes without cancelling).\",\n\t\"flow-cancel\": \"Cancel the currently running /flow run, if any.\",\n\t\"flow-pause\": \"Pause the currently running /flow run, if any.\",\n\t\"flow-resume\": \"Resume a paused /flow run.\",\n\t\"flow-title\": \"Rename the active flow and display its title on the widget border.\",\n\t\"flow-models\":\n\t\t\"Manage which models /flow uses. Subcommands: show|list|validate [--live]|check|set|effort|use|new|pick|workflow. \" +\n\t\t\"Aliases like fable-5-1, opus-5-5, sonnet-5, gpt-6-sol, gpt-6-luna, astra resolve against your configured models.\",\n\t\"flow-profile\": \"List, show, select, import or edit Flow profiles. Args: [list|show|use|export|import|validate ...]\",\n\tomsg:\n\t\t\"Send a message to the running orchestration (queued, delivered to the next dispatched task). \" +\n\t\t\"Usage: /omsg <text> — the lead will see and respond to it. Use '\\\\n' for newlines if needed.\",\n};\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 stub is refused when disabled.\n */\nconst LOADED_RUN_COMMANDS = new Set([\"flow-cancel\", \"flow-status\", \"flow-pause\", \"flow-resume\"]);\n/** Kill switch: resume would restart dispatch, so it is refused while Flow is disabled (cancel, status and pause are not). */\nconst AVAILABLE_WHEN_DISABLED = new Set([\"flow-cancel\", \"flow-status\", \"flow-pause\"]);\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null;\n}\n\n/**\n * Print/json mode has no UI: core makes ctx.ui.notify a no-op, so headless notices go to stderr as bare text.\n * Notice text can echo user args or env values, so it is redacted, stripped of terminal escapes, then redacted again\n * with the same redactor: the first pass catches secrets that stripping could otherwise mangle, the second catches\n * secrets that were split by escapes and are rejoined by stripping. Fails closed to a fixed line on any failure.\n * Replacing `ui` snapshots ui (descriptors preserve other ctx getters, so lazy getters on ctx stay live; same approach\n * as the runner's createCommandContext).\n */\nconst NOTICE_WITHHELD = \"[notice withheld: redaction unavailable]\";\n\nfunction safeNotice(message: string): string {\n\ttry {\n\t\tconst redactor = createTraceRedactor({ env: process.env });\n\t\treturn redactor.redactText(sanitizeForTerminal(redactor.redactText(message).text)).text;\n\t} catch {\n\t\treturn NOTICE_WITHHELD;\n\t}\n}\n\nfunction withHeadlessNotices(ctx: ExtensionCommandContext): ExtensionCommandContext {\n\tif (ctx.mode !== \"print\" && ctx.mode !== \"json\") return ctx;\n\tconst ui = Object.defineProperties({}, Object.getOwnPropertyDescriptors(ctx.ui)) as ExtensionCommandContext[\"ui\"];\n\tui.notify = (message: string) => {\n\t\tprocess.stderr.write(`${safeNotice(message)}\\n`);\n\t};\n\tconst wrapped = Object.defineProperties({}, Object.getOwnPropertyDescriptors(ctx)) as ExtensionCommandContext;\n\tObject.defineProperty(wrapped, \"ui\", { value: ui, enumerable: true, configurable: true });\n\treturn wrapped;\n}\n\n/**\n * Mirrors packages/flow emitRefusalSettled: an rpc /flow start 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\tname: string,\n\tctx: ExtensionCommandContext,\n\tfailureClass: FlowFailureClass,\n): Promise<void> {\n\tif ((name === \"flow\" || name === \"flow-continue\") && (ctx.mode === \"print\" || ctx.mode === \"json\"))\n\t\tprocess.exitCode = 1;\n\tif (ctx.mode !== \"rpc\" || !rpcOutput || (name !== \"flow\" && name !== \"flow-continue\")) return;\n\ttry {\n\t\tconst runId = `flow-refused-${randomBytes(8).toString(\"hex\")}`;\n\t\tconst frame: FlowEventFrameV1 = {\n\t\t\ttype: \"flow_event\",\n\t\t\tevent: {\n\t\t\t\tschema: \"humain-flow-event\",\n\t\t\t\tschemaVersion: 1,\n\t\t\t\teventId: `${runId}.refused`,\n\t\t\t\trunId,\n\t\t\t\tseq: 1,\n\t\t\t\tts: new Date().toISOString(),\n\t\t\t\tprofile: {\n\t\t\t\t\tid: \"unknown\",\n\t\t\t\t\tversion: 1,\n\t\t\t\t\tdigest: createHash(\"sha256\").update(\"unknown\", \"utf8\").digest(\"hex\"),\n\t\t\t\t},\n\t\t\t\tcauses: [],\n\t\t\t\tkind: \"run_settled\",\n\t\t\t\tpayload: { outcome: \"failed\", failureClass, settledCleanly: true, retryOffer: [\"direct\"], totals: {} },\n\t\t\t},\n\t\t};\n\t\tawait rpcOutput(frame);\n\t} catch {\n\t\t// Refusal must still notify; a dead transport is not the command's problem.\n\t}\n}\n\nfunction disabledReason(pi: ExtensionAPI, env: NodeJS.ProcessEnv): string | undefined {\n\tconst raw = env[HUMAIN_FLOW_DISABLED_ENV]?.trim().toLowerCase();\n\tif (raw === \"1\" || raw === \"true\") return `${HUMAIN_FLOW_DISABLED_ENV}=${raw}`;\n\ttry {\n\t\t// `flow` is not a typed Settings key: settings.json keeps unknown keys, so read it raw.\n\t\tconst flow = (pi.getSettings() as Record<string, unknown>).flow;\n\t\tif (isRecord(flow) && flow.enabled === false) return \"setting flow.enabled=false\";\n\t} catch {\n\t\t// Runtime not bound yet: treat as enabled.\n\t}\n\treturn undefined;\n}\n\n/**\n * Run flowExtension against a staging proxy. Stub commands are captured (so names never double-register); every other\n * registration is recorded and applied to the real pi only after the factory and the session_start replay succeed, so\n * a failed attempt leaves nothing behind and a retry starts from scratch. Late registration is supported by the\n * extension loader (handlers, tools, commands and flags are written to the live extension object), but\n * `session_start` has already fired by the time Flow loads, so the last session_start event is replayed to Flow's\n * staged session_start handlers.\n *\n * Commit is not transactional for non-handler members: if one throws midway, committed handlers are unsubscribed, and\n * tools/commands/flags/shortcuts/renderers (keyed maps in the extension loader) are simply overwritten on retry.\n */\nasync function runFlowExtension(\n\tpi: ExtensionAPI,\n\tflowExtension: ExtensionFactory,\n\tlastSessionStart: () => unknown[] | undefined,\n): Promise<Map<string, CommandOptions>> {\n\tconst captured = new Map<string, CommandOptions>();\n\tconst staged: StagedCall[] = [];\n\t// After a successful commit the proxy forwards live, so registrations made later (from handlers) reach the real pi.\n\tlet live = false;\n\tconst proxy = new Proxy(pi, {\n\t\tget(target, prop) {\n\t\t\tif (!live && typeof prop === \"string\" && STAGED_MEMBERS.has(prop)) {\n\t\t\t\treturn (...args: unknown[]) => {\n\t\t\t\t\tif (prop === \"registerCommand\" && typeof args[0] === \"string\" && args[0] in STUB_COMMANDS) {\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\nexport function createHumainFlowLoaderExtensionFactory(options: HumainFlowLoaderOptions = {}): ExtensionFactory {\n\tconst env = options.env ?? process.env;\n\t// This is the single sanctioned lazy-load boundary for @humain/flow (see AGENTS.md \"No inline imports\" exception).\n\tconst importFlow = options.importFlow ?? (() => import(\"@humain/flow\"));\n\tconst flowPackageDir = options.flowPackageDir ?? getBundledFlowPackageDir();\n\tconst builtInProfilesDir = options.builtInProfilesDir ?? getBundledFlowProfilesDir();\n\tlet flowModule: Promise<FlowModule> | undefined;\n\n\treturn (pi) => {\n\t\tdisabledProbe = () => disabledReason(pi, env) !== undefined;\n\t\tlet lastStart: unknown[] | undefined;\n\t\tlet loaded: Promise<Map<string, CommandOptions>> | undefined;\n\n\t\tpi.on(\"session_start\", (event, ctx) => {\n\t\t\tlastStart = [event, ctx];\n\t\t});\n\t\tpi.registerFlag(\"profile\", { description: \"Flow profile id\", type: \"string\" });\n\t\tpi.registerFlag(\"flow-admission\", { description: \"Flow run admission file (JSON)\", type: \"string\" });\n\n\t\tconst loadModule = async (): Promise<FlowModule> => {\n\t\t\tif (flowPackageDir && !env[HUMAIN_FLOW_PACKAGE_DIR_ENV]) env[HUMAIN_FLOW_PACKAGE_DIR_ENV] = flowPackageDir;\n\t\t\tflowModule ??= importFlow().then((module) => {\n\t\t\t\trpcControl = module.createFlowRpcControl?.({\n\t\t\t\t\twriteFrame: (frame) => rpcOutput?.(frame),\n\t\t\t\t\tisDisabled: isFlowDisabled,\n\t\t\t\t\tsendFollowUp: (text) =>\n\t\t\t\t\t\trpcFollowUp ? rpcFollowUp(text) : Promise.reject(new Error(\"host unavailable\")),\n\t\t\t\t});\n\t\t\t\treturn module;\n\t\t\t});\n\t\t\ttry {\n\t\t\t\treturn await flowModule;\n\t\t\t} catch (error) {\n\t\t\t\tflowModule = undefined;\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t};\n\n\t\trpcLoader = async () => {\n\t\t\ttry {\n\t\t\t\tawait loadModule();\n\t\t\t} catch {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\treturn rpcControl;\n\t\t};\n\n\t\tconst load = (): Promise<Map<string, CommandOptions>> => {\n\t\t\tif (!loaded) {\n\t\t\t\tconst attempt = (async () => {\n\t\t\t\t\tconst module = await loadModule();\n\t\t\t\t\treturn runFlowExtension(pi, module.flowExtension, () => lastStart);\n\t\t\t\t})();\n\t\t\t\tloaded = attempt;\n\t\t\t\t// A failed load must be retryable on the next invocation.\n\t\t\t\tattempt.catch(() => {\n\t\t\t\t\tif (loaded === attempt) loaded = undefined;\n\t\t\t\t});\n\t\t\t}\n\t\t\treturn loaded;\n\t\t};\n\n\t\tfor (const [name, description] of Object.entries(STUB_COMMANDS)) {\n\t\t\tpi.registerCommand(name, {\n\t\t\t\tdescription,\n\t\t\t\thandler: async (args: string, rawCtx: ExtensionCommandContext) => {\n\t\t\t\t\tconst ctx = withHeadlessNotices(rawCtx);\n\t\t\t\t\tconst reason = AVAILABLE_WHEN_DISABLED.has(name) ? undefined : disabledReason(pi, env);\n\t\t\t\t\tif (reason) {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tctx.ui.notify(`Flow disabled (${reason}). /${name} is unavailable.`, \"warning\");\n\t\t\t\t\t\t} finally {\n\t\t\t\t\t\t\tawait settleRefusal(name, ctx, \"config_invalid\");\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tif (name === \"flow-profile\") {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tconst module = await loadModule();\n\t\t\t\t\t\t\tif (!module.runFlowProfileCommand || !module.createProfileStore) {\n\t\t\t\t\t\t\t\tctx.ui.notify(\"/flow-profile is not available in this Flow build\", \"error\");\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tconst store = module.createProfileStore({\n\t\t\t\t\t\t\t\tflowDir: options.flowDir ?? join(getAgentDir(), \"flow\"),\n\t\t\t\t\t\t\t\t...(builtInProfilesDir !== undefined ? { builtInDir: builtInProfilesDir } : {}),\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\tawait module.runFlowProfileCommand(args, ctx, { store });\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\tctx.ui.notify(\n\t\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\t\"error\",\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tif (LOADED_RUN_COMMANDS.has(name) && !loaded) {\n\t\t\t\t\t\tctx.ui.notify(\"no active run\", \"info\");\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tlet commands: Map<string, CommandOptions>;\n\t\t\t\t\ttry {\n\t\t\t\t\t\tcommands = await load();\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tctx.ui.notify(\n\t\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\t\"error\",\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} finally {\n\t\t\t\t\t\t\tawait settleRefusal(name, ctx, \"internal\");\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tconst real = commands.get(name);\n\t\t\t\t\tif (!real) {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tctx.ui.notify(`/${name} is not available yet`, \"error\");\n\t\t\t\t\t\t} finally {\n\t\t\t\t\t\t\tawait settleRefusal(name, ctx, \"internal\");\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tawait real.handler(args, ctx);\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"flow-loader.js","sourceRoot":"","sources":["../../src/humain/flow-loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAG/D,OAAO,EAAE,WAAW,EAAE,wBAAwB,EAAE,yBAAyB,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAOvH,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAEvE;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,wBAAwB,GAAG,+BAA+B,CAAC;AACxE,MAAM,CAAC,MAAM,2BAA2B,GAAG,kCAAkC,CAAC;AAkC9E,IAAI,UAAsC,CAAC;AAC3C,IAAI,aAA0C,CAAC;AAC/C,IAAI,SAA0E,CAAC;AAC/E,IAAI,SAAkE,CAAC;AACvE,IAAI,WAA0D,CAAC;AAE/D,qGAAqG;AACrG,MAAM,UAAU,iBAAiB;IAChC,OAAO,UAAU,CAAC;AACnB,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB;IACvC,IAAI,UAAU;QAAE,OAAO,UAAU,CAAC;IAClC,IAAI,cAAc,EAAE;QAAE,OAAO,SAAS,CAAC;IACvC,OAAO,SAAS,EAAE,EAAE,CAAC;AACtB,CAAC;AAED,sHAAsH;AACtH,MAAM,UAAU,cAAc;IAC7B,OAAO,aAAa,EAAE,EA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AAC;wBACJ,QAAQ,GAAG,MAAM,IAAI,EAAE,CAAC;oBACzB,CAAC;oBAAC,OAAO,KAAK,EAAE,CAAC;wBAChB,IAAI,CAAC;4BACJ,GAAG,CAAC,EAAE,CAAC,MAAM,CACZ,wBAAwB,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,EAChF,OAAO,CACP,CAAC;wBACH,CAAC;gCAAS,CAAC;4BACV,MAAM,aAAa,CAAC,IAAI,EAAE,GAAG,EAAE,UAAU,CAAC,CAAC;wBAC5C,CAAC;wBACD,OAAO;oBACR,CAAC;oBACD,MAAM,IAAI,GAAG,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;oBAChC,IAAI,CAAC,IAAI,EAAE,CAAC;wBACX,IAAI,CAAC;4BACJ,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,IAAI,uBAAuB,EAAE,OAAO,CAAC,CAAC;wBACzD,CAAC;gCAAS,CAAC;4BACV,MAAM,aAAa,CAAC,IAAI,EAAE,GAAG,EAAE,UAAU,CAAC,CAAC;wBAC5C,CAAC;wBACD,OAAO;oBACR,CAAC;oBACD,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;gBAC/B,CAAC;aACD,CAAC,CAAC;QACJ,CAAC;IACF,CAAC,CAAC;AACH,CAAC","sourcesContent":["import { createHash, randomBytes } from \"node:crypto\";\nimport { readFileSync } from \"node:fs\";\nimport { dirname, isAbsolute, join, resolve } from \"node:path\";\nimport type { FlowFailureClass } from \"@humain/humain-code-contracts/flow-common\";\nimport type { FlowEventFrameV1, FlowReceiptV1, FlowStatusV1 } from \"@humain/humain-code-contracts/flow-control\";\nimport { getAgentDir, getBundledFlowPackageDir, getBundledFlowProfilesDir, PACKAGE_NAME, VERSION } from \"../config.ts\";\nimport type {\n\tExtensionAPI,\n\tExtensionCommandContext,\n\tExtensionFactory,\n\tRegisteredCommand,\n} from \"../core/extensions/types.ts\";\nimport { createTraceRedactor } from \"../core/trace/redaction.ts\";\nimport { sanitizeForTerminal } from \"../core/trace-client/sanitize.ts\";\n\n/**\n * Lazy loader for the private @humain/flow package.\n *\n * The CLI entry graph must not statically reach Flow: this module registers cheap stub commands and a flag, and\n * only loads Flow (one memoized dynamic import) the first time a stub runs. Flow is bundled as its own chunk.\n */\n\nexport const HUMAIN_FLOW_DISABLED_ENV = \"HUMAIN_TERMINAL_FLOW_DISABLED\";\nexport const HUMAIN_FLOW_PACKAGE_DIR_ENV = \"HUMAIN_TERMINAL_FLOW_PACKAGE_DIR\";\n\n/** Run-control surface Flow exposes to rpc mode (flow_status/pause/resume/cancel/message). */\nexport interface FlowRpcControl {\n\thandle(input: unknown): Promise<{ receipt: FlowReceiptV1; status?: FlowStatusV1 }>;\n\tactiveRunId(): string | undefined;\n}\n\nexport interface FlowModule {\n\tflowExtension: ExtensionFactory;\n\t/** Documented rpc hook: called once when Flow loads; `writeFrame` carries `flow_event` frames to the rpc host. */\n\tcreateFlowRpcControl?(options: {\n\t\twriteFrame?: (frame: FlowEventFrameV1) => void | Promise<void>;\n\t\tisDisabled?: () => boolean;\n\t\t/** Queues text on the host session as a follow-up (flow_message with no active run). */\n\t\tsendFollowUp?: (text: string) => Promise<void>;\n\t}): FlowRpcControl;\n\t/** B1 profile command; optional so test fakes need not provide it. Methods stay bivariant for the real signatures. */\n\trunFlowProfileCommand?(args: string, ctx: ExtensionCommandContext, deps: { store: unknown }): Promise<unknown>;\n\tcreateProfileStore?(options: { flowDir: string; builtInDir?: string }): unknown;\n}\n\nexport interface HumainFlowLoaderOptions {\n\t/** Test seam. Defaults to the single sanctioned dynamic import of @humain/flow. */\n\timportFlow?: () => Promise<FlowModule>;\n\tenv?: NodeJS.ProcessEnv;\n\t/** Directory holding Flow's agents/assets/package.json. Defaults to the bundled layout's flow/ dir. */\n\tflowPackageDir?: string;\n\t/** Built-in Flow profiles dir. Defaults to the bundled layout's assets/profiles; undefined lets Flow find its own. */\n\tbuiltInProfilesDir?: string;\n\t/** Flow profile store directory. Defaults to `<agentDir>/flow`. */\n\tflowDir?: string;\n}\n\nlet rpcControl: FlowRpcControl | undefined;\nlet disabledProbe: (() => boolean) | undefined;\nlet rpcOutput: ((frame: FlowEventFrameV1) => void | Promise<void>) | undefined;\nlet rpcLoader: (() => Promise<FlowRpcControl | undefined>) | undefined;\nlet rpcFollowUp: ((text: string) => Promise<void>) | undefined;\n\n/** The documented rpc hook: rpc mode reads Flow's run control here and never imports Flow itself. */\nexport function getFlowRpcControl(): FlowRpcControl | undefined {\n\treturn rpcControl;\n}\n\n/**\n * The documented rpc hook: loads Flow through the same lazy-load path the stub commands use and returns its run control.\n * Undefined when Flow is disabled (never loaded then), not wired, or fails to load.\n */\nexport async function loadFlowRpcControl(): Promise<FlowRpcControl | undefined> {\n\tif (rpcControl) return rpcControl;\n\tif (isFlowDisabled()) return undefined;\n\treturn rpcLoader?.();\n}\n\n/** True while Flow is switched off (flow.enabled=false or the env kill switch); rpc mode refuses flow_resume then. */\nexport function isFlowDisabled(): boolean {\n\treturn disabledProbe?.() ?? false;\n}\n\n/** The documented rpc hook: rpc mode registers where Flow's `flow_event` frames are written. */\nexport function setFlowRpcOutput(writer: ((frame: FlowEventFrameV1) => void | Promise<void>) | undefined): void {\n\trpcOutput = writer;\n}\n\n/** The documented rpc hook: rpc mode registers how direct-mode flow_message text is queued as a host follow-up. */\nexport function setFlowRpcFollowUp(queue: ((text: string) => Promise<void>) | undefined): void {\n\trpcFollowUp = queue;\n}\n\ntype CommandOptions = Omit<RegisteredCommand, \"name\" | \"sourceInfo\">;\ntype EventHandler = (...args: unknown[]) => unknown;\n\n/**\n * ExtensionAPI members that only record registrations (see core/extensions/loader.ts). They are staged while Flow's\n * factory runs and applied to the real pi only after the factory and the session_start replay succeed. Reads and\n * actions (getFlag, getSettings, exec, sendMessage, ...) and `events` stay live: they have no registration to undo\n * or are needed by the factory itself. Flow uses none of the live ones that subscribe (`events.on`).\n */\nconst STAGED_MEMBERS = new Set([\n\t\"on\",\n\t\"registerTool\",\n\t\"registerCommand\",\n\t\"registerShortcut\",\n\t\"registerFlag\",\n\t\"registerMessageRenderer\",\n\t\"registerMarkdownTransformer\",\n\t\"registerEntryRenderer\",\n\t\"registerProvider\",\n\t\"unregisterProvider\",\n\t\"registerMcpServer\",\n\t\"unregisterMcpServer\",\n\t\"registerVirtualModel\",\n\t\"unregisterVirtualModel\",\n]);\n\ninterface StagedCall {\n\tmember: string;\n\targs: unknown[];\n\tcancelled: boolean;\n\tunsubscribe?: () => void;\n}\n\n// Descriptions match the real Flow commands (packages/flow/src). flow-profile is served here through Flow's\n// runFlowProfileCommand.\nconst STUB_COMMANDS: Record<string, string> = {\n\tflow:\n\t\t\"Plan and dispatch a hierarchical agent run. \" +\n\t\t\"Args: <goal> [--task-class T] [--complexity N] [--risk low|medium|high|critical] \" +\n\t\t\"[--profile NAME] [--lead-size small|standard|large] [--cheap ALIAS] [--mid ALIAS] [--premium ALIAS] [--frontier ALIAS] [--model <capability>=ALIAS] [--effort LEVEL] \" +\n\t\t\"[--quality-floor F] [--cost-aggressiveness C] [--max-retries R] [--flow-admission FILE] \" +\n\t\t\"[--context FILE ...] [--with-last-reply] [--force]\\n\\n\" +\n\t\t\"With no triage flags, an LLM triage call (cheapest configured model) \" +\n\t\t\"auto-fills task_class, complexity, and risk from the goal text. \" +\n\t\t\"Models: flags > profile (orchestrator-profiles.json) > cost-tier resolver. See /flow-models.\",\n\t\"flow-continue\":\n\t\t\"Preview and explicitly confirm recovery in the original checkout. Args: [run-id] (no --yes or --force).\",\n\t\"flow-status\": \"Open the full live orchestration board (↑↓ PgUp/PgDn scroll, Esc closes without cancelling).\",\n\t\"flow-cancel\": \"Cancel the currently running /flow run, if any.\",\n\t\"flow-pause\": \"Pause the currently running /flow run, if any.\",\n\t\"flow-resume\": \"Resume a paused /flow run.\",\n\t\"flow-title\": \"Rename the active flow and display its title on the widget border.\",\n\t\"flow-models\":\n\t\t\"Manage which models /flow uses. Subcommands: show|list|validate [--live]|check|set|effort|use|new|pick|workflow. \" +\n\t\t\"Aliases like fable-5-1, opus-5-5, sonnet-5, gpt-6-sol, gpt-6-luna, astra resolve against your configured models.\",\n\t\"flow-profile\": \"List, show, select, import or edit Flow profiles. Args: [list|show|use|export|import|validate ...]\",\n\tomsg:\n\t\t\"Send a message to the running orchestration (queued, delivered to the next dispatched task). \" +\n\t\t\"Usage: /omsg <text> — the lead will see and respond to it. Use '\\\\n' for newlines if needed.\",\n};\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 stub is refused when disabled.\n */\nconst LOADED_RUN_COMMANDS = new Set([\"flow-cancel\", \"flow-status\", \"flow-pause\", \"flow-resume\"]);\n/** Kill switch: resume would restart dispatch, so it is refused while Flow is disabled (cancel, status and pause are not). */\nconst AVAILABLE_WHEN_DISABLED = new Set([\"flow-cancel\", \"flow-status\", \"flow-pause\"]);\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null;\n}\n\n/**\n * Print/json mode has no UI: core makes ctx.ui.notify a no-op, so headless notices go to stderr as bare text.\n * Notice text can echo user args or env values, so it is redacted, stripped of terminal escapes, then redacted again\n * with the same redactor: the first pass catches secrets that stripping could otherwise mangle, the second catches\n * secrets that were split by escapes and are rejoined by stripping. Fails closed to a fixed line on any failure.\n * Replacing `ui` snapshots ui (descriptors preserve other ctx getters, so lazy getters on ctx stay live; same approach\n * as the runner's createCommandContext).\n */\nconst NOTICE_WITHHELD = \"[notice withheld: redaction unavailable]\";\n\nfunction safeNotice(message: string): string {\n\ttry {\n\t\tconst redactor = createTraceRedactor({ env: process.env });\n\t\treturn redactor.redactText(sanitizeForTerminal(redactor.redactText(message).text)).text;\n\t} catch {\n\t\treturn NOTICE_WITHHELD;\n\t}\n}\n\nfunction withHeadlessNotices(ctx: ExtensionCommandContext): ExtensionCommandContext {\n\tif (ctx.mode !== \"print\" && ctx.mode !== \"json\") return ctx;\n\tconst ui = Object.defineProperties({}, Object.getOwnPropertyDescriptors(ctx.ui)) as ExtensionCommandContext[\"ui\"];\n\tui.notify = (message: string) => {\n\t\tprocess.stderr.write(`${safeNotice(message)}\\n`);\n\t};\n\tconst wrapped = Object.defineProperties({}, Object.getOwnPropertyDescriptors(ctx)) as ExtensionCommandContext;\n\tObject.defineProperty(wrapped, \"ui\", { value: ui, enumerable: true, configurable: true });\n\treturn wrapped;\n}\n\n/**\n * Mirrors packages/flow emitRefusalSettled: an rpc /flow start 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\tname: string,\n\tctx: ExtensionCommandContext,\n\tfailureClass: FlowFailureClass,\n): Promise<void> {\n\tif ((name === \"flow\" || name === \"flow-continue\") && (ctx.mode === \"print\" || ctx.mode === \"json\"))\n\t\tprocess.exitCode = 1;\n\tif (ctx.mode !== \"rpc\" || !rpcOutput || (name !== \"flow\" && name !== \"flow-continue\")) return;\n\ttry {\n\t\tconst runId = `flow-refused-${randomBytes(8).toString(\"hex\")}`;\n\t\tconst frame: FlowEventFrameV1 = {\n\t\t\ttype: \"flow_event\",\n\t\t\tevent: {\n\t\t\t\tschema: \"humain-flow-event\",\n\t\t\t\tschemaVersion: 1,\n\t\t\t\teventId: `${runId}.refused`,\n\t\t\t\trunId,\n\t\t\t\tseq: 1,\n\t\t\t\tts: new Date().toISOString(),\n\t\t\t\tprofile: {\n\t\t\t\t\tid: \"unknown\",\n\t\t\t\t\tversion: 1,\n\t\t\t\t\tdigest: createHash(\"sha256\").update(\"unknown\", \"utf8\").digest(\"hex\"),\n\t\t\t\t},\n\t\t\t\tcauses: [],\n\t\t\t\tkind: \"run_settled\",\n\t\t\t\tpayload: { outcome: \"failed\", failureClass, settledCleanly: true, retryOffer: [\"direct\"], totals: {} },\n\t\t\t},\n\t\t};\n\t\tawait rpcOutput(frame);\n\t} catch {\n\t\t// Refusal must still notify; a dead transport is not the command's problem.\n\t}\n}\n\nfunction disabledReason(pi: ExtensionAPI, env: NodeJS.ProcessEnv): string | undefined {\n\tconst raw = env[HUMAIN_FLOW_DISABLED_ENV]?.trim().toLowerCase();\n\tif (raw === \"1\" || raw === \"true\") return `${HUMAIN_FLOW_DISABLED_ENV}=${raw}`;\n\ttry {\n\t\t// `flow` is not a typed Settings key: settings.json keeps unknown keys, so read it raw.\n\t\tconst flow = (pi.getSettings() as Record<string, unknown>).flow;\n\t\tif (isRecord(flow) && flow.enabled === false) return \"setting flow.enabled=false\";\n\t} catch {\n\t\t// Runtime not bound yet: treat as enabled.\n\t}\n\treturn undefined;\n}\n\n/**\n * Run flowExtension against a staging proxy. Stub commands are captured (so names never double-register); every other\n * registration is recorded and applied to the real pi only after the factory and the session_start replay succeed, so\n * a failed attempt leaves nothing behind and a retry starts from scratch. Late registration is supported by the\n * extension loader (handlers, tools, commands and flags are written to the live extension object), but\n * `session_start` has already fired by the time Flow loads, so the last session_start event is replayed to Flow's\n * staged session_start handlers.\n *\n * Commit is not transactional for non-handler members: if one throws midway, committed handlers are unsubscribed, and\n * tools/commands/flags/shortcuts/renderers (keyed maps in the extension loader) are simply overwritten on retry.\n */\nasync function runFlowExtension(\n\tpi: ExtensionAPI,\n\tflowExtension: ExtensionFactory,\n\tlastSessionStart: () => unknown[] | undefined,\n): Promise<Map<string, CommandOptions>> {\n\tconst captured = new Map<string, CommandOptions>();\n\tconst staged: StagedCall[] = [];\n\t// After a successful commit the proxy forwards live, so registrations made later (from handlers) reach the real pi.\n\tlet live = false;\n\tconst proxy = new Proxy(pi, {\n\t\tget(target, prop) {\n\t\t\tif (!live && typeof prop === \"string\" && STAGED_MEMBERS.has(prop)) {\n\t\t\t\treturn (...args: unknown[]) => {\n\t\t\t\t\tif (prop === \"registerCommand\" && typeof args[0] === \"string\" && args[0] in STUB_COMMANDS) {\n\t\t\t\t\t\tcaptured.set(args[0], args[1] as CommandOptions);\n\t\t\t\t\t\treturn undefined;\n\t\t\t\t\t}\n\t\t\t\t\tconst call: StagedCall = { member: prop, args, cancelled: false };\n\t\t\t\t\tstaged.push(call);\n\t\t\t\t\tif (prop !== \"on\") return undefined;\n\t\t\t\t\treturn () => {\n\t\t\t\t\t\tcall.cancelled = true;\n\t\t\t\t\t\tcall.unsubscribe?.();\n\t\t\t\t\t};\n\t\t\t\t};\n\t\t\t}\n\t\t\tconst value: unknown = Reflect.get(target, prop, target);\n\t\t\treturn typeof value === \"function\" ? value.bind(target) : value;\n\t\t},\n\t});\n\tawait flowExtension(proxy);\n\n\tlet replayed: unknown[] | undefined;\n\tfor (let start = lastSessionStart(); start && start !== replayed; start = lastSessionStart()) {\n\t\treplayed = start;\n\t\tfor (const call of staged) {\n\t\t\tif (call.member === \"on\" && call.args[0] === \"session_start\" && !call.cancelled) {\n\t\t\t\tawait (call.args[1] as EventHandler)(...start);\n\t\t\t}\n\t\t}\n\t}\n\n\t// Synchronous from the last replay check: no session_start can slip between replay and commit.\n\tconst committed: Array<() => void> = [];\n\ttry {\n\t\tfor (const call of staged) {\n\t\t\tif (call.cancelled) continue;\n\t\t\tconst result = (Reflect.get(pi, call.member) as (...args: unknown[]) => unknown).apply(pi, call.args);\n\t\t\tif (call.member === \"on\") {\n\t\t\t\tcall.unsubscribe = result as () => void;\n\t\t\t\tcommitted.push(call.unsubscribe);\n\t\t\t}\n\t\t}\n\t} catch (error) {\n\t\tfor (const unsubscribe of committed) unsubscribe();\n\t\tthrow error;\n\t}\n\tlive = true;\n\treturn captured;\n}\n\nfunction isSameCliReleaseFlowDir(dir: string): boolean {\n\tif (!isAbsolute(dir) || VERSION === \"0.0.0\") return false;\n\ttry {\n\t\tconst manifest: unknown = JSON.parse(readFileSync(join(dir, \"package.json\"), \"utf8\"));\n\t\tif (!isRecord(manifest) || manifest.name !== \"@humain/flow\") return false;\n\t} catch {\n\t\treturn false;\n\t}\n\t// Bun ships flow/ beside package.json; bundled Node ships dist/bundle/flow/.\n\tfor (const root of [dirname(dir), resolve(dir, \"../../..\")]) {\n\t\ttry {\n\t\t\tconst manifest: unknown = JSON.parse(readFileSync(join(root, \"package.json\"), \"utf8\"));\n\t\t\tif (isRecord(manifest) && manifest.name === PACKAGE_NAME) return manifest.version === VERSION;\n\t\t} catch {\n\t\t\t// Missing or unreadable release metadata cannot validate an override.\n\t\t}\n\t}\n\treturn false;\n}\n\nexport function createHumainFlowLoaderExtensionFactory(options: HumainFlowLoaderOptions = {}): ExtensionFactory {\n\tconst env = options.env ?? process.env;\n\t// This is the single sanctioned lazy-load boundary for @humain/flow (see AGENTS.md \"No inline imports\" exception).\n\tconst importFlow = options.importFlow ?? (() => import(\"@humain/flow\"));\n\tconst flowPackageDir = options.flowPackageDir ?? getBundledFlowPackageDir();\n\tconst builtInProfilesDir = options.builtInProfilesDir ?? getBundledFlowProfilesDir();\n\tlet flowModule: Promise<FlowModule> | undefined;\n\n\treturn (pi) => {\n\t\tdisabledProbe = () => disabledReason(pi, env) !== undefined;\n\t\tlet lastStart: unknown[] | undefined;\n\t\tlet loaded: Promise<Map<string, CommandOptions>> | undefined;\n\n\t\tpi.on(\"session_start\", (event, ctx) => {\n\t\t\tlastStart = [event, ctx];\n\t\t});\n\t\tpi.registerFlag(\"profile\", { description: \"Flow profile id\", type: \"string\" });\n\t\tpi.registerFlag(\"flow-admission\", { description: \"Flow run admission file (JSON)\", type: \"string\" });\n\n\t\tconst loadModule = async (): Promise<FlowModule> => {\n\t\t\tconst override = env[HUMAIN_FLOW_PACKAGE_DIR_ENV];\n\t\t\tif (override && !isSameCliReleaseFlowDir(override)) delete env[HUMAIN_FLOW_PACKAGE_DIR_ENV];\n\t\t\tif (flowPackageDir && !env[HUMAIN_FLOW_PACKAGE_DIR_ENV]) env[HUMAIN_FLOW_PACKAGE_DIR_ENV] = flowPackageDir;\n\t\t\tflowModule ??= importFlow().then((module) => {\n\t\t\t\trpcControl = module.createFlowRpcControl?.({\n\t\t\t\t\twriteFrame: (frame) => rpcOutput?.(frame),\n\t\t\t\t\tisDisabled: isFlowDisabled,\n\t\t\t\t\tsendFollowUp: (text) =>\n\t\t\t\t\t\trpcFollowUp ? rpcFollowUp(text) : Promise.reject(new Error(\"host unavailable\")),\n\t\t\t\t});\n\t\t\t\treturn module;\n\t\t\t});\n\t\t\ttry {\n\t\t\t\treturn await flowModule;\n\t\t\t} catch (error) {\n\t\t\t\tflowModule = undefined;\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t};\n\n\t\trpcLoader = async () => {\n\t\t\ttry {\n\t\t\t\tawait loadModule();\n\t\t\t} catch {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\treturn rpcControl;\n\t\t};\n\n\t\tconst load = (): Promise<Map<string, CommandOptions>> => {\n\t\t\tif (!loaded) {\n\t\t\t\tconst attempt = (async () => {\n\t\t\t\t\tconst module = await loadModule();\n\t\t\t\t\treturn runFlowExtension(pi, module.flowExtension, () => lastStart);\n\t\t\t\t})();\n\t\t\t\tloaded = attempt;\n\t\t\t\t// A failed load must be retryable on the next invocation.\n\t\t\t\tattempt.catch(() => {\n\t\t\t\t\tif (loaded === attempt) loaded = undefined;\n\t\t\t\t});\n\t\t\t}\n\t\t\treturn loaded;\n\t\t};\n\n\t\tfor (const [name, description] of Object.entries(STUB_COMMANDS)) {\n\t\t\tpi.registerCommand(name, {\n\t\t\t\tdescription,\n\t\t\t\thandler: async (args: string, rawCtx: ExtensionCommandContext) => {\n\t\t\t\t\tconst ctx = withHeadlessNotices(rawCtx);\n\t\t\t\t\tconst reason = AVAILABLE_WHEN_DISABLED.has(name) ? undefined : disabledReason(pi, env);\n\t\t\t\t\tif (reason) {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tctx.ui.notify(`Flow disabled (${reason}). /${name} is unavailable.`, \"warning\");\n\t\t\t\t\t\t} finally {\n\t\t\t\t\t\t\tawait settleRefusal(name, ctx, \"config_invalid\");\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tif (name === \"flow-profile\") {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tconst module = await loadModule();\n\t\t\t\t\t\t\tif (!module.runFlowProfileCommand || !module.createProfileStore) {\n\t\t\t\t\t\t\t\tctx.ui.notify(\"/flow-profile is not available in this Flow build\", \"error\");\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tconst store = module.createProfileStore({\n\t\t\t\t\t\t\t\tflowDir: options.flowDir ?? join(getAgentDir(), \"flow\"),\n\t\t\t\t\t\t\t\t...(builtInProfilesDir !== undefined ? { builtInDir: builtInProfilesDir } : {}),\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\tawait module.runFlowProfileCommand(args, ctx, { store });\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\tctx.ui.notify(\n\t\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\t\"error\",\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tif (LOADED_RUN_COMMANDS.has(name) && !loaded) {\n\t\t\t\t\t\tctx.ui.notify(\"no active run\", \"info\");\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tlet commands: Map<string, CommandOptions>;\n\t\t\t\t\ttry {\n\t\t\t\t\t\tcommands = await load();\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tctx.ui.notify(\n\t\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\t\"error\",\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} finally {\n\t\t\t\t\t\t\tawait settleRefusal(name, ctx, \"internal\");\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tconst real = commands.get(name);\n\t\t\t\t\tif (!real) {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tctx.ui.notify(`/${name} is not available yet`, \"error\");\n\t\t\t\t\t\t} finally {\n\t\t\t\t\t\t\tawait settleRefusal(name, ctx, \"internal\");\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tawait real.handler(args, ctx);\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\t};\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assistant-message.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/assistant-message.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"assistant-message.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/assistant-message.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAY,KAAK,aAAa,EAA6B,MAAM,wBAAwB,CAAC;AAC5G,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AAQ7E;;GAEG;AACH,qBAAa,yBAA0B,SAAQ,SAAS;IACvD,OAAO,CAAC,gBAAgB,CAAY;IACpC,OAAO,CAAC,iBAAiB,CAAU;IACnC,OAAO,CAAC,aAAa,CAAgB;IACrC,OAAO,CAAC,mBAAmB,CAAS;IACpC,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,oBAAoB,CAAiC;IAC7D,OAAO,CAAC,WAAW,CAAC,CAAmB;IACvC,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,2BAA2B,CAA8B;IAEjE,YACC,OAAO,CAAC,EAAE,gBAAgB,EAC1B,iBAAiB,UAAQ,EACzB,aAAa,GAAE,aAAkC,EACjD,mBAAmB,SAAgB,EACnC,SAAS,SAAI,EACb,oBAAoB,GAAE,SAAS,mBAAmB,EAAO,EAiBzD;IAEQ,UAAU,IAAI,IAAI,CAK1B;IAED,oBAAoB,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,CAMxC;IAED,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAK1C;IAED,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAKlC;IAEQ,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CASvC;IAED,aAAa,CAAC,OAAO,EAAE,gBAAgB,EAAE,WAAW,UAAmB,GAAG,IAAI,CAgH7E;CACD"}
|