@caupulican/pi-adaptative 0.91.3 → 0.92.0
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 +30 -0
- package/dist/bundled-resources/skills/worker-profile-writer/SKILL.md +19 -9
- package/dist/cli.js +6 -1
- package/dist/cli.js.map +1 -1
- package/dist/core/agent-session.d.ts +1 -0
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +20 -33
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/autonomy/lane-tool-surface.d.ts.map +1 -1
- package/dist/core/autonomy/lane-tool-surface.js +7 -1
- package/dist/core/autonomy/lane-tool-surface.js.map +1 -1
- package/dist/core/bash-execution-controller.d.ts.map +1 -1
- package/dist/core/bash-execution-controller.js +1 -0
- package/dist/core/bash-execution-controller.js.map +1 -1
- package/dist/core/bash-executor.d.ts +2 -0
- package/dist/core/bash-executor.d.ts.map +1 -1
- package/dist/core/bash-executor.js +13 -4
- package/dist/core/bash-executor.js.map +1 -1
- package/dist/core/goals/goal-session-controller.d.ts +18 -1
- package/dist/core/goals/goal-session-controller.d.ts.map +1 -1
- package/dist/core/goals/goal-session-controller.js +46 -5
- package/dist/core/goals/goal-session-controller.js.map +1 -1
- package/dist/core/goals/natural-language-goal.d.ts +6 -5
- package/dist/core/goals/natural-language-goal.d.ts.map +1 -1
- package/dist/core/goals/natural-language-goal.js +109 -2
- package/dist/core/goals/natural-language-goal.js.map +1 -1
- package/dist/core/tools/bash.d.ts +2 -0
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +115 -13
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/delegate.d.ts.map +1 -1
- package/dist/core/tools/delegate.js +12 -2
- package/dist/core/tools/delegate.js.map +1 -1
- package/dist/core/tools/early-powershell-session.d.ts +21 -0
- package/dist/core/tools/early-powershell-session.d.ts.map +1 -0
- package/dist/core/tools/early-powershell-session.js +137 -0
- package/dist/core/tools/early-powershell-session.js.map +1 -0
- package/dist/core/tools/output-accumulator.d.ts +2 -0
- package/dist/core/tools/output-accumulator.d.ts.map +1 -1
- package/dist/core/tools/output-accumulator.js +2 -1
- package/dist/core/tools/output-accumulator.js.map +1 -1
- package/dist/core/tools/persistent-process-coordinator.d.ts.map +1 -1
- package/dist/core/tools/persistent-process-coordinator.js +2 -11
- package/dist/core/tools/persistent-process-coordinator.js.map +1 -1
- package/dist/core/tools/profile-writer.d.ts +1 -0
- package/dist/core/tools/profile-writer.d.ts.map +1 -1
- package/dist/core/tools/profile-writer.js +5 -1
- package/dist/core/tools/profile-writer.js.map +1 -1
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js +13 -1
- package/dist/core/tools/read.js.map +1 -1
- package/dist/core/tools/session-transcript-read.d.ts +4 -0
- package/dist/core/tools/session-transcript-read.d.ts.map +1 -0
- package/dist/core/tools/session-transcript-read.js +98 -0
- package/dist/core/tools/session-transcript-read.js.map +1 -0
- package/dist/core/tools/shell-output-decoder.d.ts +7 -0
- package/dist/core/tools/shell-output-decoder.d.ts.map +1 -0
- package/dist/core/tools/shell-output-decoder.js +135 -0
- package/dist/core/tools/shell-output-decoder.js.map +1 -0
- package/dist/core/tools/shell-session.d.ts +23 -6
- package/dist/core/tools/shell-session.d.ts.map +1 -1
- package/dist/core/tools/shell-session.js +275 -88
- package/dist/core/tools/shell-session.js.map +1 -1
- package/dist/utils/child-process-ref.d.ts +4 -0
- package/dist/utils/child-process-ref.d.ts.map +1 -0
- package/dist/utils/child-process-ref.js +15 -0
- package/dist/utils/child-process-ref.js.map +1 -0
- package/dist/utils/powershell-session-protocol.d.ts +16 -0
- package/dist/utils/powershell-session-protocol.d.ts.map +1 -0
- package/dist/utils/powershell-session-protocol.js +63 -0
- package/dist/utils/powershell-session-protocol.js.map +1 -0
- package/dist/utils/shell.d.ts +7 -4
- package/dist/utils/shell.d.ts.map +1 -1
- package/dist/utils/shell.js +38 -23
- package/dist/utils/shell.js.map +1 -1
- package/docs/sessions.md +12 -4
- package/docs/settings.md +2 -2
- package/docs/windows.md +9 -8
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/npm-shrinkwrap.json +12 -12
- package/package.json +4 -4
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type ChildProcess, type SpawnOptions } from "node:child_process";
|
|
2
|
+
export interface CliPowerShellWarmStartOptions {
|
|
3
|
+
platform?: NodeJS.Platform;
|
|
4
|
+
cwd: string;
|
|
5
|
+
env: NodeJS.ProcessEnv;
|
|
6
|
+
candidates?: readonly string[];
|
|
7
|
+
spawn?: (command: string, args: string[], options: SpawnOptions) => ChildProcess;
|
|
8
|
+
startupTimeoutMs?: number;
|
|
9
|
+
}
|
|
10
|
+
export interface ReadyCliPowerShellSession {
|
|
11
|
+
child: ChildProcess;
|
|
12
|
+
cwd: string;
|
|
13
|
+
env: NodeJS.ProcessEnv;
|
|
14
|
+
releaseStartupListeners(): void;
|
|
15
|
+
}
|
|
16
|
+
/** Begin one unclaimed native PowerShell session while the CLI imports its main runtime graph. */
|
|
17
|
+
export declare function startCliPowerShellWarmStart(options: CliPowerShellWarmStartOptions): void;
|
|
18
|
+
/** Claim the CLI warm start exactly once; callers attach ownership before releasing its listeners. */
|
|
19
|
+
export declare function claimCliPowerShellWarmStart(): Promise<ReadyCliPowerShellSession | null>;
|
|
20
|
+
export declare function resetCliPowerShellWarmStartForTests(): Promise<void>;
|
|
21
|
+
//# sourceMappingURL=early-powershell-session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"early-powershell-session.d.ts","sourceRoot":"","sources":["../../../src/core/tools/early-powershell-session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,YAAY,EAAS,MAAM,oBAAoB,CAAC;AAgBjF,MAAM,WAAW,6BAA6B;IAC7C,QAAQ,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAC;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC,UAAU,CAAC;IACvB,UAAU,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC/B,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,YAAY,KAAK,YAAY,CAAC;IACjF,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,yBAAyB;IACzC,KAAK,EAAE,YAAY,CAAC;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC,UAAU,CAAC;IACvB,uBAAuB,IAAI,IAAI,CAAC;CAChC;AAmGD,kGAAkG;AAClG,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,6BAA6B,GAAG,IAAI,CAUxF;AAED,sGAAsG;AACtG,wBAAsB,2BAA2B,IAAI,OAAO,CAAC,yBAAyB,GAAG,IAAI,CAAC,CAY7F;AAED,wBAAsB,mCAAmC,IAAI,OAAO,CAAC,IAAI,CAAC,CASzE"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { setChildProcessLoopRef } from "../../utils/child-process-ref.js";
|
|
3
|
+
import { createPowerShellHostEnvironment, POWERSHELL_ARGS, POWERSHELL_BOOTSTRAP, POWERSHELL_SESSION_READY_MARKER, POWERSHELL_SESSION_STDERR_READY_MARKER, POWERSHELL_STARTUP_PROBE_TIMEOUT_MS, } from "../../utils/powershell-session-protocol.js";
|
|
4
|
+
const MAX_STARTUP_DIAGNOSTIC_BYTES = 16 * 1024;
|
|
5
|
+
const READY_BYTES = Buffer.from(POWERSHELL_SESSION_READY_MARKER, "latin1");
|
|
6
|
+
const STDERR_READY_BYTES = Buffer.from(POWERSHELL_SESSION_STDERR_READY_MARKER, "latin1");
|
|
7
|
+
const DEFAULT_CANDIDATES = ["pwsh.exe"];
|
|
8
|
+
let warmStart = null;
|
|
9
|
+
let warmStartClaimed = false;
|
|
10
|
+
function waitForReady(child, cwd, env, startupTimeoutMs) {
|
|
11
|
+
return new Promise((resolve, reject) => {
|
|
12
|
+
let settled = false;
|
|
13
|
+
let stdout = Buffer.alloc(0);
|
|
14
|
+
let stderr = Buffer.alloc(0);
|
|
15
|
+
let stdoutReady = false;
|
|
16
|
+
let stderrReady = false;
|
|
17
|
+
let timeoutTimer;
|
|
18
|
+
const diagnostic = () => {
|
|
19
|
+
const text = Buffer.concat([stdout, stderr]).toString("utf8").trim();
|
|
20
|
+
return text ? `: ${text}` : "";
|
|
21
|
+
};
|
|
22
|
+
const releaseStartupListeners = () => {
|
|
23
|
+
child.stdout?.off("data", onStdout);
|
|
24
|
+
child.stderr?.off("data", onStderr);
|
|
25
|
+
child.off("error", onError);
|
|
26
|
+
child.off("exit", onExit);
|
|
27
|
+
};
|
|
28
|
+
const fail = (error) => {
|
|
29
|
+
if (settled)
|
|
30
|
+
return;
|
|
31
|
+
settled = true;
|
|
32
|
+
if (timeoutTimer)
|
|
33
|
+
clearTimeout(timeoutTimer);
|
|
34
|
+
releaseStartupListeners();
|
|
35
|
+
child.kill();
|
|
36
|
+
reject(error);
|
|
37
|
+
};
|
|
38
|
+
const resolveWhenReady = () => {
|
|
39
|
+
if (settled || !stdoutReady || !stderrReady)
|
|
40
|
+
return;
|
|
41
|
+
settled = true;
|
|
42
|
+
if (timeoutTimer)
|
|
43
|
+
clearTimeout(timeoutTimer);
|
|
44
|
+
resolve({ child, cwd, env, releaseStartupListeners });
|
|
45
|
+
};
|
|
46
|
+
const onStdout = (data) => {
|
|
47
|
+
if (settled)
|
|
48
|
+
return;
|
|
49
|
+
stdout = stdout.length === 0 ? data : Buffer.concat([stdout, data]).subarray(-MAX_STARTUP_DIAGNOSTIC_BYTES);
|
|
50
|
+
stdoutReady ||= stdout.indexOf(READY_BYTES) !== -1;
|
|
51
|
+
resolveWhenReady();
|
|
52
|
+
};
|
|
53
|
+
const onStderr = (data) => {
|
|
54
|
+
if (settled)
|
|
55
|
+
return;
|
|
56
|
+
stderr = stderr.length === 0 ? data : Buffer.concat([stderr, data]).subarray(-MAX_STARTUP_DIAGNOSTIC_BYTES);
|
|
57
|
+
stderrReady ||= stderr.indexOf(STDERR_READY_BYTES) !== -1;
|
|
58
|
+
resolveWhenReady();
|
|
59
|
+
};
|
|
60
|
+
const onError = (error) => fail(new Error(`${error.message}${diagnostic()}`));
|
|
61
|
+
const onExit = (code) => fail(new Error(`exited with code ${code ?? "null"} before readiness${diagnostic()}`));
|
|
62
|
+
child.stdout?.on("data", onStdout);
|
|
63
|
+
child.stderr?.on("data", onStderr);
|
|
64
|
+
child.on("error", onError);
|
|
65
|
+
child.on("exit", onExit);
|
|
66
|
+
timeoutTimer = setTimeout(() => fail(new Error(`startup timed out after ${startupTimeoutMs}ms${diagnostic()}`)), startupTimeoutMs);
|
|
67
|
+
timeoutTimer.unref();
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
async function startFirstUsableSession(options) {
|
|
71
|
+
for (const candidate of options.candidates) {
|
|
72
|
+
let child;
|
|
73
|
+
try {
|
|
74
|
+
child = options.spawnProcess(candidate, [...POWERSHELL_ARGS, POWERSHELL_BOOTSTRAP], {
|
|
75
|
+
cwd: options.cwd,
|
|
76
|
+
env: options.env,
|
|
77
|
+
detached: process.platform !== "win32",
|
|
78
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
79
|
+
windowsHide: true,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
setChildProcessLoopRef(child, false);
|
|
86
|
+
try {
|
|
87
|
+
return await waitForReady(child, options.cwd, options.env, options.startupTimeoutMs);
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
// Try the next host. The regular resolver retains the complete diagnostic fallback.
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
/** Begin one unclaimed native PowerShell session while the CLI imports its main runtime graph. */
|
|
96
|
+
export function startCliPowerShellWarmStart(options) {
|
|
97
|
+
if ((options.platform ?? process.platform) !== "win32" || warmStart)
|
|
98
|
+
return;
|
|
99
|
+
warmStartClaimed = false;
|
|
100
|
+
warmStart = startFirstUsableSession({
|
|
101
|
+
cwd: options.cwd,
|
|
102
|
+
env: createPowerShellHostEnvironment(options.env),
|
|
103
|
+
candidates: options.candidates ?? DEFAULT_CANDIDATES,
|
|
104
|
+
startupTimeoutMs: options.startupTimeoutMs ?? POWERSHELL_STARTUP_PROBE_TIMEOUT_MS,
|
|
105
|
+
spawnProcess: options.spawn ?? spawn,
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
/** Claim the CLI warm start exactly once; callers attach ownership before releasing its listeners. */
|
|
109
|
+
export async function claimCliPowerShellWarmStart() {
|
|
110
|
+
if (!warmStart || warmStartClaimed)
|
|
111
|
+
return null;
|
|
112
|
+
warmStartClaimed = true;
|
|
113
|
+
const pending = warmStart;
|
|
114
|
+
const ready = await pending;
|
|
115
|
+
if (warmStart === pending)
|
|
116
|
+
warmStart = null;
|
|
117
|
+
if (!ready)
|
|
118
|
+
return null;
|
|
119
|
+
if (ready.child.exitCode !== null || ready.child.signalCode !== null || ready.child.killed) {
|
|
120
|
+
ready.releaseStartupListeners();
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
return ready;
|
|
124
|
+
}
|
|
125
|
+
export async function resetCliPowerShellWarmStartForTests() {
|
|
126
|
+
const pending = warmStart;
|
|
127
|
+
warmStart = null;
|
|
128
|
+
warmStartClaimed = false;
|
|
129
|
+
if (!pending)
|
|
130
|
+
return;
|
|
131
|
+
const ready = await pending;
|
|
132
|
+
if (!ready)
|
|
133
|
+
return;
|
|
134
|
+
ready.releaseStartupListeners();
|
|
135
|
+
ready.child.kill();
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=early-powershell-session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"early-powershell-session.js","sourceRoot":"","sources":["../../../src/core/tools/early-powershell-session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwC,KAAK,EAAE,MAAM,oBAAoB,CAAC;AACjF,OAAO,EAAE,sBAAsB,EAAE,MAAM,kCAAkC,CAAC;AAC1E,OAAO,EACN,+BAA+B,EAC/B,eAAe,EACf,oBAAoB,EACpB,+BAA+B,EAC/B,sCAAsC,EACtC,mCAAmC,GACnC,MAAM,4CAA4C,CAAC;AAEpD,MAAM,4BAA4B,GAAG,EAAE,GAAG,IAAI,CAAC;AAC/C,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,+BAA+B,EAAE,QAAQ,CAAC,CAAC;AAC3E,MAAM,kBAAkB,GAAG,MAAM,CAAC,IAAI,CAAC,sCAAsC,EAAE,QAAQ,CAAC,CAAC;AACzF,MAAM,kBAAkB,GAAG,CAAC,UAAU,CAAC,CAAC;AAkBxC,IAAI,SAAS,GAAqD,IAAI,CAAC;AACvE,IAAI,gBAAgB,GAAG,KAAK,CAAC;AAE7B,SAAS,YAAY,CACpB,KAAmB,EACnB,GAAW,EACX,GAAsB,EACtB,gBAAwB;IAExB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACtC,IAAI,OAAO,GAAG,KAAK,CAAC;QACpB,IAAI,MAAM,GAAW,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACrC,IAAI,MAAM,GAAW,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACrC,IAAI,WAAW,GAAG,KAAK,CAAC;QACxB,IAAI,WAAW,GAAG,K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AAK,GAAG,MAAM,OAAO,CAAC;IAC5B,IAAI,CAAC,KAAK;QAAE,OAAO;IACnB,KAAK,CAAC,uBAAuB,EAAE,CAAC;IAChC,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;AACpB,CAAC","sourcesContent":["import { type ChildProcess, type SpawnOptions, spawn } from \"node:child_process\";\nimport { setChildProcessLoopRef } from \"../../utils/child-process-ref.ts\";\nimport {\n\tcreatePowerShellHostEnvironment,\n\tPOWERSHELL_ARGS,\n\tPOWERSHELL_BOOTSTRAP,\n\tPOWERSHELL_SESSION_READY_MARKER,\n\tPOWERSHELL_SESSION_STDERR_READY_MARKER,\n\tPOWERSHELL_STARTUP_PROBE_TIMEOUT_MS,\n} from \"../../utils/powershell-session-protocol.ts\";\n\nconst MAX_STARTUP_DIAGNOSTIC_BYTES = 16 * 1024;\nconst READY_BYTES = Buffer.from(POWERSHELL_SESSION_READY_MARKER, \"latin1\");\nconst STDERR_READY_BYTES = Buffer.from(POWERSHELL_SESSION_STDERR_READY_MARKER, \"latin1\");\nconst DEFAULT_CANDIDATES = [\"pwsh.exe\"];\n\nexport interface CliPowerShellWarmStartOptions {\n\tplatform?: NodeJS.Platform;\n\tcwd: string;\n\tenv: NodeJS.ProcessEnv;\n\tcandidates?: readonly string[];\n\tspawn?: (command: string, args: string[], options: SpawnOptions) => ChildProcess;\n\tstartupTimeoutMs?: number;\n}\n\nexport interface ReadyCliPowerShellSession {\n\tchild: ChildProcess;\n\tcwd: string;\n\tenv: NodeJS.ProcessEnv;\n\treleaseStartupListeners(): void;\n}\n\nlet warmStart: Promise<ReadyCliPowerShellSession | null> | null = null;\nlet warmStartClaimed = false;\n\nfunction waitForReady(\n\tchild: ChildProcess,\n\tcwd: string,\n\tenv: NodeJS.ProcessEnv,\n\tstartupTimeoutMs: number,\n): Promise<ReadyCliPowerShellSession> {\n\treturn new Promise((resolve, reject) => {\n\t\tlet settled = false;\n\t\tlet stdout: Buffer = Buffer.alloc(0);\n\t\tlet stderr: Buffer = Buffer.alloc(0);\n\t\tlet stdoutReady = false;\n\t\tlet stderrReady = false;\n\t\tlet timeoutTimer: NodeJS.Timeout | undefined;\n\n\t\tconst diagnostic = (): string => {\n\t\t\tconst text = Buffer.concat([stdout, stderr]).toString(\"utf8\").trim();\n\t\t\treturn text ? `: ${text}` : \"\";\n\t\t};\n\t\tconst releaseStartupListeners = (): void => {\n\t\t\tchild.stdout?.off(\"data\", onStdout);\n\t\t\tchild.stderr?.off(\"data\", onStderr);\n\t\t\tchild.off(\"error\", onError);\n\t\t\tchild.off(\"exit\", onExit);\n\t\t};\n\t\tconst fail = (error: Error): void => {\n\t\t\tif (settled) return;\n\t\t\tsettled = true;\n\t\t\tif (timeoutTimer) clearTimeout(timeoutTimer);\n\t\t\treleaseStartupListeners();\n\t\t\tchild.kill();\n\t\t\treject(error);\n\t\t};\n\t\tconst resolveWhenReady = (): void => {\n\t\t\tif (settled || !stdoutReady || !stderrReady) return;\n\t\t\tsettled = true;\n\t\t\tif (timeoutTimer) clearTimeout(timeoutTimer);\n\t\t\tresolve({ child, cwd, env, releaseStartupListeners });\n\t\t};\n\t\tconst onStdout = (data: Buffer): void => {\n\t\t\tif (settled) return;\n\t\t\tstdout = stdout.length === 0 ? data : Buffer.concat([stdout, data]).subarray(-MAX_STARTUP_DIAGNOSTIC_BYTES);\n\t\t\tstdoutReady ||= stdout.indexOf(READY_BYTES) !== -1;\n\t\t\tresolveWhenReady();\n\t\t};\n\t\tconst onStderr = (data: Buffer): void => {\n\t\t\tif (settled) return;\n\t\t\tstderr = stderr.length === 0 ? data : Buffer.concat([stderr, data]).subarray(-MAX_STARTUP_DIAGNOSTIC_BYTES);\n\t\t\tstderrReady ||= stderr.indexOf(STDERR_READY_BYTES) !== -1;\n\t\t\tresolveWhenReady();\n\t\t};\n\t\tconst onError = (error: Error): void => fail(new Error(`${error.message}${diagnostic()}`));\n\t\tconst onExit = (code: number | null): void =>\n\t\t\tfail(new Error(`exited with code ${code ?? \"null\"} before readiness${diagnostic()}`));\n\n\t\tchild.stdout?.on(\"data\", onStdout);\n\t\tchild.stderr?.on(\"data\", onStderr);\n\t\tchild.on(\"error\", onError);\n\t\tchild.on(\"exit\", onExit);\n\t\ttimeoutTimer = setTimeout(\n\t\t\t() => fail(new Error(`startup timed out after ${startupTimeoutMs}ms${diagnostic()}`)),\n\t\t\tstartupTimeoutMs,\n\t\t);\n\t\ttimeoutTimer.unref();\n\t});\n}\n\nasync function startFirstUsableSession(\n\toptions: Required<Pick<CliPowerShellWarmStartOptions, \"cwd\" | \"env\" | \"candidates\" | \"startupTimeoutMs\">> & {\n\t\tspawnProcess: (command: string, args: string[], options: SpawnOptions) => ChildProcess;\n\t},\n): Promise<ReadyCliPowerShellSession | null> {\n\tfor (const candidate of options.candidates) {\n\t\tlet child: ChildProcess;\n\t\ttry {\n\t\t\tchild = options.spawnProcess(candidate, [...POWERSHELL_ARGS, POWERSHELL_BOOTSTRAP], {\n\t\t\t\tcwd: options.cwd,\n\t\t\t\tenv: options.env,\n\t\t\t\tdetached: process.platform !== \"win32\",\n\t\t\t\tstdio: [\"pipe\", \"pipe\", \"pipe\"],\n\t\t\t\twindowsHide: true,\n\t\t\t});\n\t\t} catch {\n\t\t\tcontinue;\n\t\t}\n\t\tsetChildProcessLoopRef(child, false);\n\t\ttry {\n\t\t\treturn await waitForReady(child, options.cwd, options.env, options.startupTimeoutMs);\n\t\t} catch {\n\t\t\t// Try the next host. The regular resolver retains the complete diagnostic fallback.\n\t\t}\n\t}\n\treturn null;\n}\n\n/** Begin one unclaimed native PowerShell session while the CLI imports its main runtime graph. */\nexport function startCliPowerShellWarmStart(options: CliPowerShellWarmStartOptions): void {\n\tif ((options.platform ?? process.platform) !== \"win32\" || warmStart) return;\n\twarmStartClaimed = false;\n\twarmStart = startFirstUsableSession({\n\t\tcwd: options.cwd,\n\t\tenv: createPowerShellHostEnvironment(options.env),\n\t\tcandidates: options.candidates ?? DEFAULT_CANDIDATES,\n\t\tstartupTimeoutMs: options.startupTimeoutMs ?? POWERSHELL_STARTUP_PROBE_TIMEOUT_MS,\n\t\tspawnProcess: options.spawn ?? spawn,\n\t});\n}\n\n/** Claim the CLI warm start exactly once; callers attach ownership before releasing its listeners. */\nexport async function claimCliPowerShellWarmStart(): Promise<ReadyCliPowerShellSession | null> {\n\tif (!warmStart || warmStartClaimed) return null;\n\twarmStartClaimed = true;\n\tconst pending = warmStart;\n\tconst ready = await pending;\n\tif (warmStart === pending) warmStart = null;\n\tif (!ready) return null;\n\tif (ready.child.exitCode !== null || ready.child.signalCode !== null || ready.child.killed) {\n\t\tready.releaseStartupListeners();\n\t\treturn null;\n\t}\n\treturn ready;\n}\n\nexport async function resetCliPowerShellWarmStartForTests(): Promise<void> {\n\tconst pending = warmStart;\n\twarmStart = null;\n\twarmStartClaimed = false;\n\tif (!pending) return;\n\tconst ready = await pending;\n\tif (!ready) return;\n\tready.releaseStartupListeners();\n\tready.child.kill();\n}\n"]}
|
|
@@ -8,6 +8,8 @@ export interface OutputAccumulatorOptions {
|
|
|
8
8
|
persistAllOutput?: boolean;
|
|
9
9
|
/** Maximum raw bytes persisted to the managed output file. Defaults to no additional cap. */
|
|
10
10
|
maxPersistedBytes?: number;
|
|
11
|
+
/** Decode valid UTF-8 plus isolated Windows-1252 bytes from native Windows programs. */
|
|
12
|
+
windowsCompatibleEncoding?: boolean;
|
|
11
13
|
}
|
|
12
14
|
export interface OutputSnapshot {
|
|
13
15
|
content: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"output-accumulator.d.ts","sourceRoot":"","sources":["../../../src/core/tools/output-accumulator.ts"],"names":[],"mappings":"AAGA,OAAO,EAGN,KAAK,gBAAgB,EAErB,MAAM,oCAAoC,CAAC;
|
|
1
|
+
{"version":3,"file":"output-accumulator.d.ts","sourceRoot":"","sources":["../../../src/core/tools/output-accumulator.ts"],"names":[],"mappings":"AAGA,OAAO,EAGN,KAAK,gBAAgB,EAErB,MAAM,oCAAoC,CAAC;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AAC,cAAc;IAQtB,OAAO,CAAC,cAAc;IActB,OAAO,CAAC,sBAAsB;IAI9B,OAAO,CAAC,iBAAiB;IAMzB,OAAO,CAAC,kBAAkB;IAoB1B,OAAO,CAAC,aAAa;IA4ErB,OAAO,CAAC,iBAAiB;IASzB,OAAO,CAAC,cAAc;IAItB,OAAO,CAAC,iBAAiB;IAqBzB,OAAO,CAAC,cAAc;IAkBtB,OAAO,CAAC,mBAAmB;CAY3B"}
|
|
@@ -4,6 +4,7 @@ import { join } from "node:path";
|
|
|
4
4
|
import { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, truncateKnownHeadTail, } from "@caupulican/pi-agent-core/truncate";
|
|
5
5
|
import { getAgentDir } from "../../config.js";
|
|
6
6
|
import { getProcessWorkRun } from "../../utils/work-directory.js";
|
|
7
|
+
import { createShellOutputDecoder } from "./shell-output-decoder.js";
|
|
7
8
|
function defaultTempFilePath(directory, prefix) {
|
|
8
9
|
const id = randomBytes(8).toString("hex");
|
|
9
10
|
return join(directory, `${prefix}-${id}.log`);
|
|
@@ -44,7 +45,6 @@ function tailUtf8String(text, maxBytes) {
|
|
|
44
45
|
*/
|
|
45
46
|
export class OutputAccumulator {
|
|
46
47
|
constructor(options = {}) {
|
|
47
|
-
this.decoder = new TextDecoder();
|
|
48
48
|
this.rawChunks = [];
|
|
49
49
|
this.headLines = [];
|
|
50
50
|
this.headStoredBytes = 0;
|
|
@@ -71,6 +71,7 @@ export class OutputAccumulator {
|
|
|
71
71
|
this.tempDirectory = options.tempDirectory ?? getProcessWorkRun(getAgentDir(), "outputs", "tool-streams").path;
|
|
72
72
|
this.persistAllOutput = options.persistAllOutput ?? false;
|
|
73
73
|
this.maxPersistedBytes = options.maxPersistedBytes ?? Number.POSITIVE_INFINITY;
|
|
74
|
+
this.decoder = createShellOutputDecoder(options.windowsCompatibleEncoding);
|
|
74
75
|
}
|
|
75
76
|
append(data) {
|
|
76
77
|
if (this.finished) {
|
|
@@ -1 +1 @@
|
|
|
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I,CAAC;IACxE,CAAC;IAEO,mBAAmB,CAAC,KAAc;QACzC,IAAI,CAAC,aAAa,KAAK,aAAa,CAAC,KAAK,CAAC,CAAC;QAC5C,MAAM,EAAE,GAAG,IAAI,CAAC,UAAU,CAAC;QAC3B,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;QAC5B,IAAI,EAAE,KAAK,SAAS,EAAE,CAAC;YACtB,IAAI,CAAC;gBACJ,SAAS,CAAC,EAAE,CAAC,CAAC;YACf,CAAC;YAAC,OAAO,UAAU,EAAE,CAAC;gBACrB,IAAI,CAAC,aAAa,IAAI,mBAAmB,aAAa,CAAC,UAAU,CAAC,EAAE,CAAC;YACtE,CAAC;QACF,CAAC;IACF,CAAC;CACD","sourcesContent":["import { randomBytes } from \"node:crypto\";\nimport { closeSync, openSync, writeSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport {\n\tDEFAULT_MAX_BYTES,\n\tDEFAULT_MAX_LINES,\n\ttype TruncationResult,\n\ttruncateKnownHeadTail,\n} from \"@caupulican/pi-agent-core/truncate\";\nimport { getAgentDir } from \"../../config.ts\";\nimport { getProcessWorkRun } from \"../../utils/work-directory.ts\";\n\nexport interface OutputAccumulatorOptions {\n\tmaxLines?: number;\n\tmaxBytes?: number;\n\ttempFilePrefix?: string;\n\ttempDirectory?: string;\n\t/** Stream the complete output to disk even when the bounded in-memory view is not truncated. */\n\tpersistAllOutput?: boolean;\n\t/** Maximum raw bytes persisted to the managed output file. Defaults to no additional cap. */\n\tmaxPersistedBytes?: number;\n}\n\nexport interface OutputSnapshot {\n\tcontent: string;\n\ttruncation: TruncationResult;\n\tfullOutputPath?: string;\n\tfullOutputError?: string;\n\tpersistedOutputTruncated?: boolean;\n\tpersistedOutputBytes?: number;\n}\n\nexport interface OutputPreview {\n\tcontent: string;\n\tskippedLines: number;\n}\n\nfunction defaultTempFilePath(directory: string, prefix: string): string {\n\tconst id = randomBytes(8).toString(\"hex\");\n\treturn join(directory, `${prefix}-${id}.log`);\n}\n\nconst MAX_APPEND_CHUNK_BYTES = 64 * 1024;\n\nfunction byteLength(text: string): number {\n\treturn Buffer.byteLength(text, \"utf-8\");\n}\n\nfunction formatIoError(error: unknown): string {\n\tif (error instanceof Error) {\n\t\tconst code = (error as NodeJS.ErrnoException).code;\n\t\treturn code ? `${code}: ${error.message}` : error.message;\n\t}\n\treturn String(error);\n}\n\nfunction tailUtf8String(text: string, maxBytes: number): { text: string; bytes: number } {\n\tif (maxBytes <= 0 || text.length === 0) {\n\t\treturn { text: \"\", bytes: 0 };\n\t}\n\n\tconst buffer = Buffer.from(text, \"utf-8\");\n\tif (buffer.length <= maxBytes) {\n\t\treturn { text, bytes: buffer.length };\n\t}\n\n\tlet start = buffer.length - maxBytes;\n\twhile (start < buffer.length && (buffer[start] & 0xc0) === 0x80) {\n\t\tstart++;\n\t}\n\n\tconst result = buffer.subarray(start).toString(\"utf-8\");\n\treturn { text: result, bytes: byteLength(result) };\n}\n\n/**\n * Incrementally tracks streaming output with bounded memory.\n *\n * Appends decode chunks with a streaming UTF-8 decoder, keeps a bounded tail of\n * logical lines, and opens a temp file when the full output needs preserving.\n * Snapshot and preview work is bounded by configured output limits, never by\n * total command history.\n */\nexport class OutputAccumulator {\n\tprivate readonly maxLines: number;\n\tprivate readonly maxBytes: number;\n\tprivate readonly tempFilePrefix: string;\n\tprivate readonly tempDirectory: string;\n\tprivate readonly persistAllOutput: boolean;\n\tprivate readonly maxPersistedBytes: number;\n\tprivate readonly decoder = new TextDecoder();\n\n\tprivate rawChunks: Buffer[] = [];\n\tprivate headLines: string[] = [];\n\tprivate headStoredBytes = 0;\n\tprivate tailLines: string[] = [];\n\tprivate tailLineBytes: number[] = [];\n\tprivate tailLineStoredBytes: number[] = [];\n\tprivate tailStart = 0;\n\tprivate tailStoredBytes = 0;\n\tprivate currentLineText = \"\";\n\tprivate currentLineBytes = 0;\n\tprivate currentLineStoredBytes = 0;\n\tprivate lastCompletedLineBytes = 0;\n\tprivate totalRawBytes = 0;\n\tprivate totalDecodedBytes = 0;\n\tprivate completedLines = 0;\n\tprivate totalLines = 0;\n\tprivate hasOpenLine = false;\n\tprivate finished = false;\n\n\tprivate tempFilePath: string | undefined;\n\tprivate tempFileFd: number | undefined;\n\tprivate tempFileError: string | undefined;\n\tprivate persistedOutputBytes = 0;\n\tprivate persistedOutputTruncated = false;\n\n\tconstructor(options: OutputAccumulatorOptions = {}) {\n\t\tthis.maxLines = options.maxLines ?? DEFAULT_MAX_LINES;\n\t\tthis.maxBytes = options.maxBytes ?? DEFAULT_MAX_BYTES;\n\t\tthis.tempFilePrefix = options.tempFilePrefix ?? \"pi-output\";\n\t\tthis.tempDirectory = options.tempDirectory ?? getProcessWorkRun(getAgentDir(), \"outputs\", \"tool-streams\").path;\n\t\tthis.persistAllOutput = options.persistAllOutput ?? false;\n\t\tthis.maxPersistedBytes = options.maxPersistedBytes ?? Number.POSITIVE_INFINITY;\n\t}\n\n\tappend(data: Buffer): void {\n\t\tif (this.finished) {\n\t\t\tthrow new Error(\"Cannot append to a finished output accumulator\");\n\t\t}\n\n\t\tfor (let offset = 0; offset < data.length; offset += MAX_APPEND_CHUNK_BYTES) {\n\t\t\tthis.appendBlock(data.subarray(offset, offset + MAX_APPEND_CHUNK_BYTES));\n\t\t}\n\t}\n\n\tfinish(): void {\n\t\tif (this.finished) {\n\t\t\treturn;\n\t\t}\n\t\tthis.finished = true;\n\t\tthis.appendDecodedText(this.decoder.decode());\n\t\tif (this.shouldUseTempFile()) {\n\t\t\tthis.tryEnsureTempFile();\n\t\t}\n\t}\n\n\tsnapshot(options: { persistIfTruncated?: boolean; persistAlways?: boolean } = {}): OutputSnapshot {\n\t\tconst snapshot = this.buildModelSnapshot(this.maxLines, this.maxBytes);\n\n\t\tif (options.persistAlways || (options.persistIfTruncated && snapshot.truncation.truncated)) {\n\t\t\tthis.tryEnsureTempFile();\n\t\t}\n\n\t\treturn this.withPersistenceState(snapshot);\n\t}\n\n\tpreview(maxLines: number, maxBytes = this.maxBytes): OutputPreview {\n\t\tconst snapshot = this.previewSnapshot(maxLines, maxBytes);\n\t\treturn {\n\t\t\tcontent: snapshot.content,\n\t\t\tskippedLines: Math.max(0, this.totalLines - snapshot.truncation.outputLines),\n\t\t};\n\t}\n\n\tpreviewSnapshot(\n\t\tmaxLines: number,\n\t\tmaxBytes = this.maxBytes,\n\t\toptions: { persistIfFullTruncated?: boolean } = {},\n\t): OutputSnapshot {\n\t\tconst snapshot = this.buildSnapshot(maxLines, maxBytes);\n\t\tif (options.persistIfFullTruncated && this.shouldUseTempFile()) {\n\t\t\tthis.tryEnsureTempFile();\n\t\t}\n\t\treturn this.withPersistenceState(snapshot);\n\t}\n\n\tprivate withPersistenceState(snapshot: OutputSnapshot): OutputSnapshot {\n\t\treturn {\n\t\t\t...snapshot,\n\t\t\tfullOutputPath: this.fullOutputPath(),\n\t\t\tfullOutputError: this.tempFileError,\n\t\t\tpersistedOutputTruncated: this.persistedOutputTruncated || undefined,\n\t\t\tpersistedOutputBytes: this.persistedOutputTruncated ? this.persistedOutputBytes : undefined,\n\t\t};\n\t}\n\n\tasync closeTempFile(): Promise<void> {\n\t\tconst fd = this.tempFileFd;\n\t\tif (fd === undefined) {\n\t\t\treturn;\n\t\t}\n\t\tthis.tempFileFd = undefined;\n\t\ttry {\n\t\t\tcloseSync(fd);\n\t\t} catch (error) {\n\t\t\tthis.tempFileError ??= formatIoError(error);\n\t\t}\n\t}\n\n\tgetLastLineBytes(): number {\n\t\treturn this.hasOpenLine ? this.currentLineBytes : this.lastCompletedLineBytes;\n\t}\n\n\tprivate appendBlock(data: Buffer): void {\n\t\tthis.totalRawBytes += data.length;\n\t\tthis.appendDecodedText(this.decoder.decode(data, { stream: true }));\n\n\t\tif (this.tempFileFd !== undefined || this.shouldUseTempFile()) {\n\t\t\tif (this.tryEnsureTempFile() && this.tempFileFd !== undefined) {\n\t\t\t\ttry {\n\t\t\t\t\tthis.writePersisted(data);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tthis.recordTempFileError(error);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (data.length > 0) {\n\t\t\t// Copy retained chunks: Buffer.subarray would pin a large caller buffer in memory.\n\t\t\tthis.rawChunks.push(Buffer.from(data));\n\t\t}\n\t}\n\n\tprivate appendDecodedText(text: string): void {\n\t\tif (text.length === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.totalDecodedBytes += byteLength(text);\n\n\t\tlet segmentStart = 0;\n\t\tfor (\n\t\t\tlet newlineIndex = text.indexOf(\"\\n\");\n\t\t\tnewlineIndex !== -1;\n\t\t\tnewlineIndex = text.indexOf(\"\\n\", segmentStart)\n\t\t) {\n\t\t\tthis.appendToCurrentLine(text.slice(segmentStart, newlineIndex));\n\t\t\tthis.pushCompletedCurrentLine();\n\t\t\tsegmentStart = newlineIndex + 1;\n\t\t}\n\n\t\tif (segmentStart < text.length) {\n\t\t\tthis.appendToCurrentLine(text.slice(segmentStart));\n\t\t}\n\n\t\tthis.totalLines = this.completedLines + (this.hasOpenLine ? 1 : 0);\n\t}\n\n\tprivate appendToCurrentLine(segment: string): void {\n\t\tif (segment.length === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst segmentBytes = byteLength(segment);\n\t\tthis.currentLineBytes += segmentBytes;\n\t\tthis.hasOpenLine = true;\n\n\t\tif (segmentBytes >= this.maxBytes) {\n\t\t\tconst tail = tailUtf8String(segment, this.maxBytes);\n\t\t\tthis.currentLineText = tail.text;\n\t\t\tthis.currentLineStoredBytes = tail.bytes;\n\t\t\treturn;\n\t\t}\n\n\t\tthis.currentLineText += segment;\n\t\tthis.currentLineStoredBytes += segmentBytes;\n\t\tif (this.currentLineStoredBytes > this.maxBytes) {\n\t\t\tconst tail = tailUtf8String(this.currentLineText, this.maxBytes);\n\t\t\tthis.currentLineText = tail.text;\n\t\t\tthis.currentLineStoredBytes = tail.bytes;\n\t\t}\n\t}\n\n\tprivate pushCompletedCurrentLine(): void {\n\t\tthis.completedLines++;\n\t\tthis.lastCompletedLineBytes = this.currentLineBytes;\n\t\tthis.recordHeadLine(this.currentLineText, this.currentLineStoredBytes);\n\t\tthis.tailLines.push(this.currentLineText);\n\t\tthis.tailLineBytes.push(this.currentLineBytes);\n\t\tthis.tailLineStoredBytes.push(this.currentLineStoredBytes);\n\t\tthis.tailStoredBytes += this.currentLineStoredBytes;\n\t\tthis.currentLineText = \"\";\n\t\tthis.currentLineBytes = 0;\n\t\tthis.currentLineStoredBytes = 0;\n\t\tthis.hasOpenLine = false;\n\t\tthis.trimStoredTail();\n\t}\n\n\tprivate recordHeadLine(text: string, storedBytes: number): void {\n\t\tif (this.headLines.length >= this.maxLines) return;\n\t\tconst separatorBytes = this.headLines.length > 0 ? 1 : 0;\n\t\tif (this.headStoredBytes + storedBytes + separatorBytes > this.maxBytes) return;\n\t\tthis.headLines.push(text);\n\t\tthis.headStoredBytes += storedBytes + separatorBytes;\n\t}\n\n\tprivate trimStoredTail(): void {\n\t\twhile (this.completedTailLineCount() > this.maxLines || this.tailStoredBytes > this.maxBytes) {\n\t\t\tthis.tailStoredBytes -= this.tailLineStoredBytes[this.tailStart] ?? 0;\n\t\t\tthis.tailStart++;\n\t\t}\n\n\t\tif (this.tailStart > 1024 && this.tailStart * 2 > this.tailLines.length) {\n\t\t\tthis.tailLines = this.tailLines.slice(this.tailStart);\n\t\t\tthis.tailLineBytes = this.tailLineBytes.slice(this.tailStart);\n\t\t\tthis.tailLineStoredBytes = this.tailLineStoredBytes.slice(this.tailStart);\n\t\t\tthis.tailStart = 0;\n\t\t}\n\t}\n\n\tprivate completedTailLineCount(): number {\n\t\treturn this.tailLines.length - this.tailStart;\n\t}\n\n\tprivate retainedTailLines(): string[] {\n\t\tconst lines = this.tailLines.slice(this.tailStart);\n\t\tif (this.hasOpenLine) lines.push(this.currentLineText);\n\t\treturn lines;\n\t}\n\n\tprivate buildModelSnapshot(maxLines: number, maxBytes: number): OutputSnapshot {\n\t\tconst tailSnapshot = this.buildSnapshot(maxLines, maxBytes);\n\t\tif (!tailSnapshot.truncation.truncated || this.headLines.length === 0) {\n\t\t\treturn tailSnapshot;\n\t\t}\n\n\t\tconst truncation = truncateKnownHeadTail(\n\t\t\tthis.headLines,\n\t\t\tthis.retainedTailLines(),\n\t\t\t{ totalLines: this.totalLines, totalBytes: this.totalDecodedBytes },\n\t\t\t{ maxLines, maxBytes },\n\t\t);\n\t\treturn {\n\t\t\tcontent: truncation.content,\n\t\t\ttruncation,\n\t\t\tfullOutputPath: this.fullOutputPath(),\n\t\t\tfullOutputError: this.tempFileError,\n\t\t};\n\t}\n\n\tprivate buildSnapshot(maxLines: number, maxBytes: number): OutputSnapshot {\n\t\tconst truncated = this.totalLines > maxLines || this.totalDecodedBytes > maxBytes;\n\t\tconst outputLines: string[] = [];\n\t\tlet outputBytes = 0;\n\t\tlet outputLineCount = 0;\n\t\tlet truncatedBy: \"lines\" | \"bytes\" = this.totalLines > maxLines ? \"lines\" : \"bytes\";\n\t\tlet lastLinePartial = false;\n\t\tlet readCurrent = this.hasOpenLine;\n\t\tlet completedIndex = this.tailLines.length - 1;\n\n\t\twhile (outputLineCount < maxLines) {\n\t\t\tlet line: string;\n\t\t\tlet lineBytes: number;\n\t\t\tlet storedBytes: number;\n\t\t\tif (readCurrent) {\n\t\t\t\tline = this.currentLineText;\n\t\t\t\tlineBytes = this.currentLineBytes;\n\t\t\t\tstoredBytes = this.currentLineStoredBytes;\n\t\t\t\treadCurrent = false;\n\t\t\t} else {\n\t\t\t\tif (completedIndex < this.tailStart) break;\n\t\t\t\tline = this.tailLines[completedIndex] ?? \"\";\n\t\t\t\tlineBytes = this.tailLineBytes[completedIndex] ?? 0;\n\t\t\t\tstoredBytes = this.tailLineStoredBytes[completedIndex] ?? 0;\n\t\t\t\tcompletedIndex--;\n\t\t\t}\n\n\t\t\tconst separatorBytes = outputLineCount > 0 ? 1 : 0;\n\t\t\tconst fullLineBytes = lineBytes + separatorBytes;\n\t\t\tif (outputBytes + fullLineBytes > maxBytes) {\n\t\t\t\ttruncatedBy = \"bytes\";\n\t\t\t\tif (outputLineCount === 0) {\n\t\t\t\t\tconst partial =\n\t\t\t\t\t\tlineBytes > maxBytes ? tailUtf8String(line, maxBytes) : { text: line, bytes: storedBytes };\n\t\t\t\t\toutputLines.unshift(partial.text);\n\t\t\t\t\toutputBytes = partial.bytes;\n\t\t\t\t\toutputLineCount = 1;\n\t\t\t\t\tlastLinePartial = lineBytes > partial.bytes;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\toutputLines.unshift(line);\n\t\t\toutputBytes += storedBytes + separatorBytes;\n\t\t\toutputLineCount++;\n\t\t}\n\n\t\tlet content = outputLines.join(\"\\n\");\n\t\tif (!truncated && !this.hasOpenLine && this.totalLines > 0) {\n\t\t\tcontent += \"\\n\";\n\t\t\toutputBytes += 1;\n\t\t}\n\n\t\tconst effectiveTruncatedBy = truncated ? truncatedBy : null;\n\t\tconst truncation: TruncationResult = {\n\t\t\tcontent,\n\t\t\ttruncated,\n\t\t\ttruncatedBy: effectiveTruncatedBy,\n\t\t\ttotalLines: this.totalLines,\n\t\t\ttotalBytes: this.totalDecodedBytes,\n\t\t\toutputLines: outputLineCount,\n\t\t\toutputBytes,\n\t\t\tlastLinePartial,\n\t\t\tfirstLineExceedsLimit: false,\n\t\t\tmaxLines,\n\t\t\tmaxBytes,\n\t\t};\n\n\t\treturn {\n\t\t\tcontent,\n\t\t\ttruncation,\n\t\t\tfullOutputPath: this.fullOutputPath(),\n\t\t\tfullOutputError: this.tempFileError,\n\t\t};\n\t}\n\n\tprivate shouldUseTempFile(): boolean {\n\t\treturn (\n\t\t\tthis.persistAllOutput ||\n\t\t\tthis.totalRawBytes > this.maxBytes ||\n\t\t\tthis.totalDecodedBytes > this.maxBytes ||\n\t\t\tthis.totalLines > this.maxLines\n\t\t);\n\t}\n\n\tprivate fullOutputPath(): string | undefined {\n\t\treturn this.tempFileError === undefined ? this.tempFilePath : undefined;\n\t}\n\n\tprivate tryEnsureTempFile(): boolean {\n\t\tif (this.tempFileError !== undefined) {\n\t\t\treturn false;\n\t\t}\n\t\tif (this.tempFileFd !== undefined) {\n\t\t\treturn true;\n\t\t}\n\t\ttry {\n\t\t\tthis.tempFilePath ??= defaultTempFilePath(this.tempDirectory, this.tempFilePrefix);\n\t\t\tthis.tempFileFd = openSync(this.tempFilePath, \"w\");\n\t\t\tfor (const chunk of this.rawChunks) {\n\t\t\t\tthis.writePersisted(chunk);\n\t\t\t}\n\t\t\tthis.rawChunks = [];\n\t\t\treturn true;\n\t\t} catch (error) {\n\t\t\tthis.recordTempFileError(error);\n\t\t\treturn false;\n\t\t}\n\t}\n\n\tprivate writePersisted(data: Buffer): void {\n\t\tif (this.tempFileFd === undefined || data.length === 0) return;\n\t\tconst remaining = Math.max(0, this.maxPersistedBytes - this.persistedOutputBytes);\n\t\tif (remaining === 0) {\n\t\t\tthis.persistedOutputTruncated = true;\n\t\t\treturn;\n\t\t}\n\t\tconst bounded = data.length > remaining ? data.subarray(0, remaining) : data;\n\t\tlet offset = 0;\n\t\twhile (offset < bounded.length) {\n\t\t\tconst written = writeSync(this.tempFileFd, bounded, offset, bounded.length - offset);\n\t\t\tif (written <= 0) throw new Error(\"Managed output write made no progress\");\n\t\t\toffset += written;\n\t\t\tthis.persistedOutputBytes += written;\n\t\t}\n\t\tif (bounded.length < data.length) this.persistedOutputTruncated = true;\n\t}\n\n\tprivate recordTempFileError(error: unknown): void {\n\t\tthis.tempFileError ??= formatIoError(error);\n\t\tconst fd = this.tempFileFd;\n\t\tthis.tempFileFd = undefined;\n\t\tif (fd !== undefined) {\n\t\t\ttry {\n\t\t\t\tcloseSync(fd);\n\t\t\t} catch (closeError) {\n\t\t\t\tthis.tempFileError += `; close failed: ${formatIoError(closeError)}`;\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"output-accumulator.js","sourceRoot":"","sources":["../../../src/core/tools/output-accumulator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAA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CAAC;IAEO,mBAAmB,CAAC,KAAc;QACzC,IAAI,CAAC,aAAa,KAAK,aAAa,CAAC,KAAK,CAAC,CAAC;QAC5C,MAAM,EAAE,GAAG,IAAI,CAAC,UAAU,CAAC;QAC3B,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;QAC5B,IAAI,EAAE,KAAK,SAAS,EAAE,CAAC;YACtB,IAAI,CAAC;gBACJ,SAAS,CAAC,EAAE,CAAC,CAAC;YACf,CAAC;YAAC,OAAO,UAAU,EAAE,CAAC;gBACrB,IAAI,CAAC,aAAa,IAAI,mBAAmB,aAAa,CAAC,UAAU,CAAC,EAAE,CAAC;YACtE,CAAC;QACF,CAAC;IACF,CAAC;CACD","sourcesContent":["import { randomBytes } from \"node:crypto\";\nimport { closeSync, openSync, writeSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport {\n\tDEFAULT_MAX_BYTES,\n\tDEFAULT_MAX_LINES,\n\ttype TruncationResult,\n\ttruncateKnownHeadTail,\n} from \"@caupulican/pi-agent-core/truncate\";\nimport { getAgentDir } from \"../../config.ts\";\nimport { getProcessWorkRun } from \"../../utils/work-directory.ts\";\nimport { createShellOutputDecoder, type ShellOutputDecoder } from \"./shell-output-decoder.ts\";\n\nexport interface OutputAccumulatorOptions {\n\tmaxLines?: number;\n\tmaxBytes?: number;\n\ttempFilePrefix?: string;\n\ttempDirectory?: string;\n\t/** Stream the complete output to disk even when the bounded in-memory view is not truncated. */\n\tpersistAllOutput?: boolean;\n\t/** Maximum raw bytes persisted to the managed output file. Defaults to no additional cap. */\n\tmaxPersistedBytes?: number;\n\t/** Decode valid UTF-8 plus isolated Windows-1252 bytes from native Windows programs. */\n\twindowsCompatibleEncoding?: boolean;\n}\n\nexport interface OutputSnapshot {\n\tcontent: string;\n\ttruncation: TruncationResult;\n\tfullOutputPath?: string;\n\tfullOutputError?: string;\n\tpersistedOutputTruncated?: boolean;\n\tpersistedOutputBytes?: number;\n}\n\nexport interface OutputPreview {\n\tcontent: string;\n\tskippedLines: number;\n}\n\nfunction defaultTempFilePath(directory: string, prefix: string): string {\n\tconst id = randomBytes(8).toString(\"hex\");\n\treturn join(directory, `${prefix}-${id}.log`);\n}\n\nconst MAX_APPEND_CHUNK_BYTES = 64 * 1024;\n\nfunction byteLength(text: string): number {\n\treturn Buffer.byteLength(text, \"utf-8\");\n}\n\nfunction formatIoError(error: unknown): string {\n\tif (error instanceof Error) {\n\t\tconst code = (error as NodeJS.ErrnoException).code;\n\t\treturn code ? `${code}: ${error.message}` : error.message;\n\t}\n\treturn String(error);\n}\n\nfunction tailUtf8String(text: string, maxBytes: number): { text: string; bytes: number } {\n\tif (maxBytes <= 0 || text.length === 0) {\n\t\treturn { text: \"\", bytes: 0 };\n\t}\n\n\tconst buffer = Buffer.from(text, \"utf-8\");\n\tif (buffer.length <= maxBytes) {\n\t\treturn { text, bytes: buffer.length };\n\t}\n\n\tlet start = buffer.length - maxBytes;\n\twhile (start < buffer.length && (buffer[start] & 0xc0) === 0x80) {\n\t\tstart++;\n\t}\n\n\tconst result = buffer.subarray(start).toString(\"utf-8\");\n\treturn { text: result, bytes: byteLength(result) };\n}\n\n/**\n * Incrementally tracks streaming output with bounded memory.\n *\n * Appends decode chunks with a streaming UTF-8 decoder, keeps a bounded tail of\n * logical lines, and opens a temp file when the full output needs preserving.\n * Snapshot and preview work is bounded by configured output limits, never by\n * total command history.\n */\nexport class OutputAccumulator {\n\tprivate readonly maxLines: number;\n\tprivate readonly maxBytes: number;\n\tprivate readonly tempFilePrefix: string;\n\tprivate readonly tempDirectory: string;\n\tprivate readonly persistAllOutput: boolean;\n\tprivate readonly maxPersistedBytes: number;\n\tprivate readonly decoder: ShellOutputDecoder;\n\n\tprivate rawChunks: Buffer[] = [];\n\tprivate headLines: string[] = [];\n\tprivate headStoredBytes = 0;\n\tprivate tailLines: string[] = [];\n\tprivate tailLineBytes: number[] = [];\n\tprivate tailLineStoredBytes: number[] = [];\n\tprivate tailStart = 0;\n\tprivate tailStoredBytes = 0;\n\tprivate currentLineText = \"\";\n\tprivate currentLineBytes = 0;\n\tprivate currentLineStoredBytes = 0;\n\tprivate lastCompletedLineBytes = 0;\n\tprivate totalRawBytes = 0;\n\tprivate totalDecodedBytes = 0;\n\tprivate completedLines = 0;\n\tprivate totalLines = 0;\n\tprivate hasOpenLine = false;\n\tprivate finished = false;\n\n\tprivate tempFilePath: string | undefined;\n\tprivate tempFileFd: number | undefined;\n\tprivate tempFileError: string | undefined;\n\tprivate persistedOutputBytes = 0;\n\tprivate persistedOutputTruncated = false;\n\n\tconstructor(options: OutputAccumulatorOptions = {}) {\n\t\tthis.maxLines = options.maxLines ?? DEFAULT_MAX_LINES;\n\t\tthis.maxBytes = options.maxBytes ?? DEFAULT_MAX_BYTES;\n\t\tthis.tempFilePrefix = options.tempFilePrefix ?? \"pi-output\";\n\t\tthis.tempDirectory = options.tempDirectory ?? getProcessWorkRun(getAgentDir(), \"outputs\", \"tool-streams\").path;\n\t\tthis.persistAllOutput = options.persistAllOutput ?? false;\n\t\tthis.maxPersistedBytes = options.maxPersistedBytes ?? Number.POSITIVE_INFINITY;\n\t\tthis.decoder = createShellOutputDecoder(options.windowsCompatibleEncoding);\n\t}\n\n\tappend(data: Buffer): void {\n\t\tif (this.finished) {\n\t\t\tthrow new Error(\"Cannot append to a finished output accumulator\");\n\t\t}\n\n\t\tfor (let offset = 0; offset < data.length; offset += MAX_APPEND_CHUNK_BYTES) {\n\t\t\tthis.appendBlock(data.subarray(offset, offset + MAX_APPEND_CHUNK_BYTES));\n\t\t}\n\t}\n\n\tfinish(): void {\n\t\tif (this.finished) {\n\t\t\treturn;\n\t\t}\n\t\tthis.finished = true;\n\t\tthis.appendDecodedText(this.decoder.decode());\n\t\tif (this.shouldUseTempFile()) {\n\t\t\tthis.tryEnsureTempFile();\n\t\t}\n\t}\n\n\tsnapshot(options: { persistIfTruncated?: boolean; persistAlways?: boolean } = {}): OutputSnapshot {\n\t\tconst snapshot = this.buildModelSnapshot(this.maxLines, this.maxBytes);\n\n\t\tif (options.persistAlways || (options.persistIfTruncated && snapshot.truncation.truncated)) {\n\t\t\tthis.tryEnsureTempFile();\n\t\t}\n\n\t\treturn this.withPersistenceState(snapshot);\n\t}\n\n\tpreview(maxLines: number, maxBytes = this.maxBytes): OutputPreview {\n\t\tconst snapshot = this.previewSnapshot(maxLines, maxBytes);\n\t\treturn {\n\t\t\tcontent: snapshot.content,\n\t\t\tskippedLines: Math.max(0, this.totalLines - snapshot.truncation.outputLines),\n\t\t};\n\t}\n\n\tpreviewSnapshot(\n\t\tmaxLines: number,\n\t\tmaxBytes = this.maxBytes,\n\t\toptions: { persistIfFullTruncated?: boolean } = {},\n\t): OutputSnapshot {\n\t\tconst snapshot = this.buildSnapshot(maxLines, maxBytes);\n\t\tif (options.persistIfFullTruncated && this.shouldUseTempFile()) {\n\t\t\tthis.tryEnsureTempFile();\n\t\t}\n\t\treturn this.withPersistenceState(snapshot);\n\t}\n\n\tprivate withPersistenceState(snapshot: OutputSnapshot): OutputSnapshot {\n\t\treturn {\n\t\t\t...snapshot,\n\t\t\tfullOutputPath: this.fullOutputPath(),\n\t\t\tfullOutputError: this.tempFileError,\n\t\t\tpersistedOutputTruncated: this.persistedOutputTruncated || undefined,\n\t\t\tpersistedOutputBytes: this.persistedOutputTruncated ? this.persistedOutputBytes : undefined,\n\t\t};\n\t}\n\n\tasync closeTempFile(): Promise<void> {\n\t\tconst fd = this.tempFileFd;\n\t\tif (fd === undefined) {\n\t\t\treturn;\n\t\t}\n\t\tthis.tempFileFd = undefined;\n\t\ttry {\n\t\t\tcloseSync(fd);\n\t\t} catch (error) {\n\t\t\tthis.tempFileError ??= formatIoError(error);\n\t\t}\n\t}\n\n\tgetLastLineBytes(): number {\n\t\treturn this.hasOpenLine ? this.currentLineBytes : this.lastCompletedLineBytes;\n\t}\n\n\tprivate appendBlock(data: Buffer): void {\n\t\tthis.totalRawBytes += data.length;\n\t\tthis.appendDecodedText(this.decoder.decode(data, { stream: true }));\n\n\t\tif (this.tempFileFd !== undefined || this.shouldUseTempFile()) {\n\t\t\tif (this.tryEnsureTempFile() && this.tempFileFd !== undefined) {\n\t\t\t\ttry {\n\t\t\t\t\tthis.writePersisted(data);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tthis.recordTempFileError(error);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (data.length > 0) {\n\t\t\t// Copy retained chunks: Buffer.subarray would pin a large caller buffer in memory.\n\t\t\tthis.rawChunks.push(Buffer.from(data));\n\t\t}\n\t}\n\n\tprivate appendDecodedText(text: string): void {\n\t\tif (text.length === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.totalDecodedBytes += byteLength(text);\n\n\t\tlet segmentStart = 0;\n\t\tfor (\n\t\t\tlet newlineIndex = text.indexOf(\"\\n\");\n\t\t\tnewlineIndex !== -1;\n\t\t\tnewlineIndex = text.indexOf(\"\\n\", segmentStart)\n\t\t) {\n\t\t\tthis.appendToCurrentLine(text.slice(segmentStart, newlineIndex));\n\t\t\tthis.pushCompletedCurrentLine();\n\t\t\tsegmentStart = newlineIndex + 1;\n\t\t}\n\n\t\tif (segmentStart < text.length) {\n\t\t\tthis.appendToCurrentLine(text.slice(segmentStart));\n\t\t}\n\n\t\tthis.totalLines = this.completedLines + (this.hasOpenLine ? 1 : 0);\n\t}\n\n\tprivate appendToCurrentLine(segment: string): void {\n\t\tif (segment.length === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst segmentBytes = byteLength(segment);\n\t\tthis.currentLineBytes += segmentBytes;\n\t\tthis.hasOpenLine = true;\n\n\t\tif (segmentBytes >= this.maxBytes) {\n\t\t\tconst tail = tailUtf8String(segment, this.maxBytes);\n\t\t\tthis.currentLineText = tail.text;\n\t\t\tthis.currentLineStoredBytes = tail.bytes;\n\t\t\treturn;\n\t\t}\n\n\t\tthis.currentLineText += segment;\n\t\tthis.currentLineStoredBytes += segmentBytes;\n\t\tif (this.currentLineStoredBytes > this.maxBytes) {\n\t\t\tconst tail = tailUtf8String(this.currentLineText, this.maxBytes);\n\t\t\tthis.currentLineText = tail.text;\n\t\t\tthis.currentLineStoredBytes = tail.bytes;\n\t\t}\n\t}\n\n\tprivate pushCompletedCurrentLine(): void {\n\t\tthis.completedLines++;\n\t\tthis.lastCompletedLineBytes = this.currentLineBytes;\n\t\tthis.recordHeadLine(this.currentLineText, this.currentLineStoredBytes);\n\t\tthis.tailLines.push(this.currentLineText);\n\t\tthis.tailLineBytes.push(this.currentLineBytes);\n\t\tthis.tailLineStoredBytes.push(this.currentLineStoredBytes);\n\t\tthis.tailStoredBytes += this.currentLineStoredBytes;\n\t\tthis.currentLineText = \"\";\n\t\tthis.currentLineBytes = 0;\n\t\tthis.currentLineStoredBytes = 0;\n\t\tthis.hasOpenLine = false;\n\t\tthis.trimStoredTail();\n\t}\n\n\tprivate recordHeadLine(text: string, storedBytes: number): void {\n\t\tif (this.headLines.length >= this.maxLines) return;\n\t\tconst separatorBytes = this.headLines.length > 0 ? 1 : 0;\n\t\tif (this.headStoredBytes + storedBytes + separatorBytes > this.maxBytes) return;\n\t\tthis.headLines.push(text);\n\t\tthis.headStoredBytes += storedBytes + separatorBytes;\n\t}\n\n\tprivate trimStoredTail(): void {\n\t\twhile (this.completedTailLineCount() > this.maxLines || this.tailStoredBytes > this.maxBytes) {\n\t\t\tthis.tailStoredBytes -= this.tailLineStoredBytes[this.tailStart] ?? 0;\n\t\t\tthis.tailStart++;\n\t\t}\n\n\t\tif (this.tailStart > 1024 && this.tailStart * 2 > this.tailLines.length) {\n\t\t\tthis.tailLines = this.tailLines.slice(this.tailStart);\n\t\t\tthis.tailLineBytes = this.tailLineBytes.slice(this.tailStart);\n\t\t\tthis.tailLineStoredBytes = this.tailLineStoredBytes.slice(this.tailStart);\n\t\t\tthis.tailStart = 0;\n\t\t}\n\t}\n\n\tprivate completedTailLineCount(): number {\n\t\treturn this.tailLines.length - this.tailStart;\n\t}\n\n\tprivate retainedTailLines(): string[] {\n\t\tconst lines = this.tailLines.slice(this.tailStart);\n\t\tif (this.hasOpenLine) lines.push(this.currentLineText);\n\t\treturn lines;\n\t}\n\n\tprivate buildModelSnapshot(maxLines: number, maxBytes: number): OutputSnapshot {\n\t\tconst tailSnapshot = this.buildSnapshot(maxLines, maxBytes);\n\t\tif (!tailSnapshot.truncation.truncated || this.headLines.length === 0) {\n\t\t\treturn tailSnapshot;\n\t\t}\n\n\t\tconst truncation = truncateKnownHeadTail(\n\t\t\tthis.headLines,\n\t\t\tthis.retainedTailLines(),\n\t\t\t{ totalLines: this.totalLines, totalBytes: this.totalDecodedBytes },\n\t\t\t{ maxLines, maxBytes },\n\t\t);\n\t\treturn {\n\t\t\tcontent: truncation.content,\n\t\t\ttruncation,\n\t\t\tfullOutputPath: this.fullOutputPath(),\n\t\t\tfullOutputError: this.tempFileError,\n\t\t};\n\t}\n\n\tprivate buildSnapshot(maxLines: number, maxBytes: number): OutputSnapshot {\n\t\tconst truncated = this.totalLines > maxLines || this.totalDecodedBytes > maxBytes;\n\t\tconst outputLines: string[] = [];\n\t\tlet outputBytes = 0;\n\t\tlet outputLineCount = 0;\n\t\tlet truncatedBy: \"lines\" | \"bytes\" = this.totalLines > maxLines ? \"lines\" : \"bytes\";\n\t\tlet lastLinePartial = false;\n\t\tlet readCurrent = this.hasOpenLine;\n\t\tlet completedIndex = this.tailLines.length - 1;\n\n\t\twhile (outputLineCount < maxLines) {\n\t\t\tlet line: string;\n\t\t\tlet lineBytes: number;\n\t\t\tlet storedBytes: number;\n\t\t\tif (readCurrent) {\n\t\t\t\tline = this.currentLineText;\n\t\t\t\tlineBytes = this.currentLineBytes;\n\t\t\t\tstoredBytes = this.currentLineStoredBytes;\n\t\t\t\treadCurrent = false;\n\t\t\t} else {\n\t\t\t\tif (completedIndex < this.tailStart) break;\n\t\t\t\tline = this.tailLines[completedIndex] ?? \"\";\n\t\t\t\tlineBytes = this.tailLineBytes[completedIndex] ?? 0;\n\t\t\t\tstoredBytes = this.tailLineStoredBytes[completedIndex] ?? 0;\n\t\t\t\tcompletedIndex--;\n\t\t\t}\n\n\t\t\tconst separatorBytes = outputLineCount > 0 ? 1 : 0;\n\t\t\tconst fullLineBytes = lineBytes + separatorBytes;\n\t\t\tif (outputBytes + fullLineBytes > maxBytes) {\n\t\t\t\ttruncatedBy = \"bytes\";\n\t\t\t\tif (outputLineCount === 0) {\n\t\t\t\t\tconst partial =\n\t\t\t\t\t\tlineBytes > maxBytes ? tailUtf8String(line, maxBytes) : { text: line, bytes: storedBytes };\n\t\t\t\t\toutputLines.unshift(partial.text);\n\t\t\t\t\toutputBytes = partial.bytes;\n\t\t\t\t\toutputLineCount = 1;\n\t\t\t\t\tlastLinePartial = lineBytes > partial.bytes;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\toutputLines.unshift(line);\n\t\t\toutputBytes += storedBytes + separatorBytes;\n\t\t\toutputLineCount++;\n\t\t}\n\n\t\tlet content = outputLines.join(\"\\n\");\n\t\tif (!truncated && !this.hasOpenLine && this.totalLines > 0) {\n\t\t\tcontent += \"\\n\";\n\t\t\toutputBytes += 1;\n\t\t}\n\n\t\tconst effectiveTruncatedBy = truncated ? truncatedBy : null;\n\t\tconst truncation: TruncationResult = {\n\t\t\tcontent,\n\t\t\ttruncated,\n\t\t\ttruncatedBy: effectiveTruncatedBy,\n\t\t\ttotalLines: this.totalLines,\n\t\t\ttotalBytes: this.totalDecodedBytes,\n\t\t\toutputLines: outputLineCount,\n\t\t\toutputBytes,\n\t\t\tlastLinePartial,\n\t\t\tfirstLineExceedsLimit: false,\n\t\t\tmaxLines,\n\t\t\tmaxBytes,\n\t\t};\n\n\t\treturn {\n\t\t\tcontent,\n\t\t\ttruncation,\n\t\t\tfullOutputPath: this.fullOutputPath(),\n\t\t\tfullOutputError: this.tempFileError,\n\t\t};\n\t}\n\n\tprivate shouldUseTempFile(): boolean {\n\t\treturn (\n\t\t\tthis.persistAllOutput ||\n\t\t\tthis.totalRawBytes > this.maxBytes ||\n\t\t\tthis.totalDecodedBytes > this.maxBytes ||\n\t\t\tthis.totalLines > this.maxLines\n\t\t);\n\t}\n\n\tprivate fullOutputPath(): string | undefined {\n\t\treturn this.tempFileError === undefined ? this.tempFilePath : undefined;\n\t}\n\n\tprivate tryEnsureTempFile(): boolean {\n\t\tif (this.tempFileError !== undefined) {\n\t\t\treturn false;\n\t\t}\n\t\tif (this.tempFileFd !== undefined) {\n\t\t\treturn true;\n\t\t}\n\t\ttry {\n\t\t\tthis.tempFilePath ??= defaultTempFilePath(this.tempDirectory, this.tempFilePrefix);\n\t\t\tthis.tempFileFd = openSync(this.tempFilePath, \"w\");\n\t\t\tfor (const chunk of this.rawChunks) {\n\t\t\t\tthis.writePersisted(chunk);\n\t\t\t}\n\t\t\tthis.rawChunks = [];\n\t\t\treturn true;\n\t\t} catch (error) {\n\t\t\tthis.recordTempFileError(error);\n\t\t\treturn false;\n\t\t}\n\t}\n\n\tprivate writePersisted(data: Buffer): void {\n\t\tif (this.tempFileFd === undefined || data.length === 0) return;\n\t\tconst remaining = Math.max(0, this.maxPersistedBytes - this.persistedOutputBytes);\n\t\tif (remaining === 0) {\n\t\t\tthis.persistedOutputTruncated = true;\n\t\t\treturn;\n\t\t}\n\t\tconst bounded = data.length > remaining ? data.subarray(0, remaining) : data;\n\t\tlet offset = 0;\n\t\twhile (offset < bounded.length) {\n\t\t\tconst written = writeSync(this.tempFileFd, bounded, offset, bounded.length - offset);\n\t\t\tif (written <= 0) throw new Error(\"Managed output write made no progress\");\n\t\t\toffset += written;\n\t\t\tthis.persistedOutputBytes += written;\n\t\t}\n\t\tif (bounded.length < data.length) this.persistedOutputTruncated = true;\n\t}\n\n\tprivate recordTempFileError(error: unknown): void {\n\t\tthis.tempFileError ??= formatIoError(error);\n\t\tconst fd = this.tempFileFd;\n\t\tthis.tempFileFd = undefined;\n\t\tif (fd !== undefined) {\n\t\t\ttry {\n\t\t\t\tcloseSync(fd);\n\t\t\t} catch (closeError) {\n\t\t\t\tthis.tempFileError += `; close failed: ${formatIoError(closeError)}`;\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"persistent-process-coordinator.d.ts","sourceRoot":"","sources":["../../../src/core/tools/persistent-process-coordinator.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"persistent-process-coordinator.d.ts","sourceRoot":"","sources":["../../../src/core/tools/persistent-process-coordinator.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAIvD,MAAM,WAAW,uBAAuB;IACvC,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,OAAO,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IAC5B,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAAC;CACnC;AAaD,qBAAa,4BAA4B;IACxC,OAAO,CAAC,YAAY,CAA6B;IACjD,OAAO,CAAC,KAAK,CAAoC;IACjD,OAAO,CAAC,QAAQ,CAAS;IAEzB,cAGC;IAED,IAAI,KAAK,IAAI,YAAY,GAAG,IAAI,CAE/B;IAED,aAAa,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAOnD;IAED,MAAM,CAAC,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,uBAAuB,GAAG,IAAI,CAiCnE;IAED,IAAI,IAAI,IAAI,CAKX;IAED,OAAO,IAAI,IAAI,CAKd;IAED,mEAAmE;IACnE,kBAAkB,IAAI,IAAI,CAEzB;IAED,uFAAuF;IACvF,UAAU,CAAC,MAAM,EAAE,OAAO,GAAG,IAAI,CAIhC;IAED,OAAO,CAAC,KAAK;CAMb"}
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* This boundary owns only the invariant OS mechanics: one active task, one tracked child, stale
|
|
6
6
|
* event rejection, exit/close arbitration, whole-tree kill, loop references, and parent exit.
|
|
7
7
|
*/
|
|
8
|
+
import { setChildProcessLoopRef } from "../../utils/child-process-ref.js";
|
|
8
9
|
import { killProcessTree, trackDetachedChildPid, untrackDetachedChildPid } from "../../utils/shell.js";
|
|
9
10
|
const liveCoordinators = new Set();
|
|
10
11
|
let exitHookInstalled = false;
|
|
@@ -99,17 +100,7 @@ export class PersistentProcessCoordinator {
|
|
|
99
100
|
const child = this.currentChild;
|
|
100
101
|
if (!child)
|
|
101
102
|
return;
|
|
102
|
-
|
|
103
|
-
if (active) {
|
|
104
|
-
child.ref();
|
|
105
|
-
for (const stream of streams)
|
|
106
|
-
stream?.ref?.();
|
|
107
|
-
}
|
|
108
|
-
else {
|
|
109
|
-
child.unref();
|
|
110
|
-
for (const stream of streams)
|
|
111
|
-
stream?.unref?.();
|
|
112
|
-
}
|
|
103
|
+
setChildProcessLoopRef(child, active);
|
|
113
104
|
}
|
|
114
105
|
clear(child) {
|
|
115
106
|
if (this.currentChild !== child)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"persistent-process-coordinator.js","sourceRoot":"","sources":["../../../src/core/tools/persistent-process-coordinator.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AASvG,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAAgC,CAAC;AACjE,IAAI,iBAAiB,GAAG,KAAK,CAAC;AAE9B,SAAS,eAAe;IACvB,IAAI,iBAAiB;QAAE,OAAO;IAC9B,iBAAiB,GAAG,IAAI,CAAC;IACzB,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE;QACvB,KAAK,MA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AAO;QACnB,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAClB,IAAI,KAAK,CAAC,GAAG;YAAE,eAAe,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC3C,CAAC;IAED,OAAO;QACN,IAAI,IAAI,CAAC,QAAQ;YAAE,OAAO;QAC1B,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACrB,gBAAgB,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC9B,IAAI,CAAC,IAAI,EAAE,CAAC;IACb,CAAC;IAED,mEAAmE;IACnE,kBAAkB;QACjB,IAAI,CAAC,IAAI,EAAE,CAAC;IACb,CAAC;IAED,uFAAuF;IACvF,UAAU,CAAC,MAAe;QACzB,MAAM,KAAK,GAAG,IAAI,CAAC,YAAY,CAAC;QAChC,IAAI,CAAC,KAAK;YAAE,OAAO;QACnB,
|
|
1
|
+
{"version":3,"file":"persistent-process-coordinator.js","sourceRoot":"","sources":["../../../src/core/tools/persistent-process-coordinator.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,sBAAsB,EAAE,MAAM,kCAAkC,CAAC;AAC1E,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AASvG,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAAgC,CAAC;AACjE,IAAI,iBAAiB,GAAG,KAAK,CAAC;AAE9B,SAAS,eAAe;IACvB,IAAI,iBAAiB;QAAE,OAAO;IAC9B,iBAAiB,GAAG,IAAI,CAAC;IACzB,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE;QACvB,KAAK,MAAM,WAAW,IAAI,gBAAgB;YAAE,WAAW,CAAC,kBAAkB,EAAE,CAAC;IAC9E,CAAC,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,OAAO,4BAA4B;IAKxC;QAJQ,iBAAY,GAAwB,IAAI,CAAC;QACzC,UAAK,GAAkB,OAAO,CA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AO;QAC1B,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACrB,gBAAgB,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC9B,IAAI,CAAC,IAAI,EAAE,CAAC;IACb,CAAC;IAED,mEAAmE;IACnE,kBAAkB;QACjB,IAAI,CAAC,IAAI,EAAE,CAAC;IACb,CAAC;IAED,uFAAuF;IACvF,UAAU,CAAC,MAAe;QACzB,MAAM,KAAK,GAAG,IAAI,CAAC,YAAY,CAAC;QAChC,IAAI,CAAC,KAAK;YAAE,OAAO;QACnB,sBAAsB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IACvC,CAAC;IAEO,KAAK,CAAC,KAAmB;QAChC,IAAI,IAAI,CAAC,YAAY,KAAK,KAAK;YAAE,OAAO,KAAK,CAAC;QAC9C,IAAI,KAAK,CAAC,GAAG;YAAE,uBAAuB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAClD,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;QACzB,OAAO,IAAI,CAAC;IACb,CAAC;CACD","sourcesContent":["/**\n * Shared lifecycle owner for one serialized, persistent child process.\n *\n * Wire protocols, state projection, and respawn policy stay with their concrete shell adapters.\n * This boundary owns only the invariant OS mechanics: one active task, one tracked child, stale\n * event rejection, exit/close arbitration, whole-tree kill, loop references, and parent exit.\n */\n\nimport type { ChildProcess } from \"node:child_process\";\nimport { setChildProcessLoopRef } from \"../../utils/child-process-ref.ts\";\nimport { killProcessTree, trackDetachedChildPid, untrackDetachedChildPid } from \"../../utils/shell.ts\";\n\nexport interface PersistentChildHandlers {\n\tonStdout(data: Buffer): void;\n\tonStderr(data: Buffer): void;\n\tonError(error: Error): void;\n\tonClose(code: number | null): void;\n}\n\nconst liveCoordinators = new Set<PersistentProcessCoordinator>();\nlet exitHookInstalled = false;\n\nfunction installExitHook(): void {\n\tif (exitHookInstalled) return;\n\texitHookInstalled = true;\n\tprocess.on(\"exit\", () => {\n\t\tfor (const coordinator of liveCoordinators) coordinator.killForProcessExit();\n\t});\n}\n\nexport class PersistentProcessCoordinator {\n\tprivate currentChild: ChildProcess | null = null;\n\tprivate queue: Promise<void> = Promise.resolve();\n\tprivate disposed = false;\n\n\tconstructor() {\n\t\tinstallExitHook();\n\t\tliveCoordinators.add(this);\n\t}\n\n\tget child(): ChildProcess | null {\n\t\treturn this.currentChild;\n\t}\n\n\trunSerialized<T>(task: () => Promise<T>): Promise<T> {\n\t\tconst run = this.queue.then(task);\n\t\tthis.queue = run.then(\n\t\t\t() => undefined,\n\t\t\t() => undefined,\n\t\t);\n\t\treturn run;\n\t}\n\n\tattach(child: ChildProcess, handlers: PersistentChildHandlers): void {\n\t\tif (this.disposed) {\n\t\t\tif (child.pid) killProcessTree(child.pid);\n\t\t\tthrow new Error(\"Persistent process coordinator is disposed\");\n\t\t}\n\t\tif (this.currentChild) throw new Error(\"Persistent process coordinator already owns a child\");\n\t\tthis.currentChild = child;\n\t\tif (child.pid) trackDetachedChildPid(child.pid);\n\n\t\tchild.stdout?.on(\"data\", (data: Buffer) => {\n\t\t\tif (this.currentChild === child) handlers.onStdout(data);\n\t\t});\n\t\tchild.stderr?.on(\"data\", (data: Buffer) => {\n\t\t\tif (this.currentChild === child) handlers.onStderr(data);\n\t\t});\n\t\tchild.on(\"error\", (error) => {\n\t\t\tif (!this.clear(child)) return;\n\t\t\thandlers.onError(error instanceof Error ? error : new Error(String(error)));\n\t\t});\n\t\t// Process death is authoritative. Defer one check phase so stream data already delivered\n\t\t// by the kernel reaches the active protocol handler before the terminal callback.\n\t\tchild.on(\"exit\", (code) => {\n\t\t\tif (this.currentChild !== child) return;\n\t\t\tsetImmediate(() => {\n\t\t\t\tif (!this.clear(child)) return;\n\t\t\t\thandlers.onClose(code);\n\t\t\t});\n\t\t});\n\t\t// A genuine close may arrive first; `clear` makes exit/close settlement idempotent.\n\t\tchild.on(\"close\", (code) => {\n\t\t\tif (!this.clear(child)) return;\n\t\t\thandlers.onClose(code);\n\t\t});\n\t}\n\n\tkill(): void {\n\t\tconst child = this.currentChild;\n\t\tif (!child) return;\n\t\tthis.clear(child);\n\t\tif (child.pid) killProcessTree(child.pid);\n\t}\n\n\tdispose(): void {\n\t\tif (this.disposed) return;\n\t\tthis.disposed = true;\n\t\tliveCoordinators.delete(this);\n\t\tthis.kill();\n\t}\n\n\t/** Synchronous best-effort tree kill for the process exit hook. */\n\tkillForProcessExit(): void {\n\t\tthis.kill();\n\t}\n\n\t/** Idle coordinators must not keep one-shot Node modes alive; active commands must. */\n\tsetLoopRef(active: boolean): void {\n\t\tconst child = this.currentChild;\n\t\tif (!child) return;\n\t\tsetChildProcessLoopRef(child, active);\n\t}\n\n\tprivate clear(child: ChildProcess): boolean {\n\t\tif (this.currentChild !== child) return false;\n\t\tif (child.pid) untrackDetachedChildPid(child.pid);\n\t\tthis.currentChild = null;\n\t\treturn true;\n\t}\n}\n"]}
|
|
@@ -37,6 +37,7 @@ export declare function createDelegateProfileParameterSchemas(): {
|
|
|
37
37
|
}>>;
|
|
38
38
|
};
|
|
39
39
|
export declare function delegateProfilePanelModel(details: DelegateProfileToolDetails): OrchestrationPanelModel;
|
|
40
|
+
export declare function formatTaskProfileInspection(inspection: TaskProfileInspection): string;
|
|
40
41
|
export declare function executeDelegateProfileAction(action: DelegateProfileAction, input: DelegateProfileInput, writer: TaskProfileWriterPort): {
|
|
41
42
|
content: Array<{
|
|
42
43
|
type: "text";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"profile-writer.d.ts","sourceRoot":"","sources":["../../../src/core/tools/profile-writer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAS/B,OAAO,KAAK,EACX,sBAAsB,EACtB,uBAAuB,EACvB,qBAAqB,EACrB,qBAAqB,EACrB,MAAM,yCAAyC,CAAC;AACjD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AAExE,eAAO,MAAM,wBAAwB,YAAI,iBAA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AAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAAC,OAAO,EAAE,0BAA0B,CAAA;CAAE,CA8CzF"}
|
|
@@ -51,6 +51,10 @@ export function delegateProfilePanelModel(details) {
|
|
|
51
51
|
emptyText: details.reason,
|
|
52
52
|
};
|
|
53
53
|
}
|
|
54
|
+
export function formatTaskProfileInspection(inspection) {
|
|
55
|
+
const bases = inspection.baseProfiles.map((profile) => profile.profileId).join(", ") || "none";
|
|
56
|
+
return `Reusable owner-authored bases for profile_create: ${bases}. Native delegate start does not need a base; omit profileId and set authority.role to explorer or implementer. profile_create requires an owner-authored explorer or implementer base. Available configured models: ${inspection.models.length}.`;
|
|
57
|
+
}
|
|
54
58
|
export function executeDelegateProfileAction(action, input, writer) {
|
|
55
59
|
if (action === "profile_inspect") {
|
|
56
60
|
const inspection = writer.inspectTaskProfileOptions();
|
|
@@ -58,7 +62,7 @@ export function executeDelegateProfileAction(action, input, writer) {
|
|
|
58
62
|
content: [
|
|
59
63
|
{
|
|
60
64
|
type: "text",
|
|
61
|
-
text:
|
|
65
|
+
text: formatTaskProfileInspection(inspection),
|
|
62
66
|
},
|
|
63
67
|
],
|
|
64
68
|
details: { started: true, action, kind: "profile", created: false, inspection },
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"profile-writer.js","sourceRoot":"","sources":["../../../src/core/tools/profile-writer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC/B,OAAO,EACN,mCAAmC,EACnC,mCAAmC,EACnC,iCAAiC,EACjC,uCAAuC,EACvC,6BAA6B,GAC7B,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AASzE,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,iBAAiB,EAAE,gBAAgB,CAAU,CAAC;AAoBvF,MAAM,UAAU,qCAAqC;IACpD,OAAO;QACN,IAAI,EAAE,IAAI,CAAC,QAA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L_PROVIDER_LENGTH,\n\tORCHESTRATION_THINKING_LEVELS,\n} from \"../orchestration/contracts.ts\";\nimport { createRiskBudgetSchema } from \"../orchestration/risk-budget.ts\";\nimport type {\n\tTaskProfileCreateInput,\n\tTaskProfileCreateResult,\n\tTaskProfileInspection,\n\tTaskProfileWriterPort,\n} from \"../orchestration/task-profile-writer.ts\";\nimport type { OrchestrationPanelModel } from \"./orchestration-panel.ts\";\n\nexport const DELEGATE_PROFILE_ACTIONS = [\"profile_inspect\", \"profile_create\"] as const;\n\nexport type DelegateProfileAction = (typeof DELEGATE_PROFILE_ACTIONS)[number];\n\nexport interface DelegateProfileInput {\n\ttask?: string;\n\tbaseProfileId?: string;\n\tmodel?: TaskProfileCreateInput[\"model\"];\n\ttoolNames?: readonly string[];\n\tresourceProfileNames?: readonly string[];\n\tbudget?: TaskProfileCreateInput[\"budget\"];\n}\n\nexport interface DelegateProfileToolDetails extends TaskProfileCreateResult {\n\tstarted: boolean;\n\taction: DelegateProfileAction;\n\tkind: \"profile\";\n\tinspection?: TaskProfileInspection;\n}\n\nexport function createDelegateProfileParameterSchemas() {\n\treturn {\n\t\ttask: Type.Optional(Type.String({ minLength: 1, maxLength: 3_500 })),\n\t\tbaseProfileId: Type.Optional(Type.String({ minLength: 1, maxLength: MAX_ORCHESTRATION_IDENTIFIER_LENGTH })),\n\t\tmodel: Type.Optional(\n\t\t\tType.Object(\n\t\t\t\t{\n\t\t\t\t\tprovider: Type.String({\n\t\t\t\t\t\tminLength: 1,\n\t\t\t\t\t\tmaxLength: MAX_ORCHESTRATION_MODEL_PROVIDER_LENGTH,\n\t\t\t\t\t}),\n\t\t\t\t\tmodelId: Type.String({ minLength: 1, maxLength: MAX_ORCHESTRATION_MODEL_ID_LENGTH }),\n\t\t\t\t\tthinkingLevel: Type.Union(ORCHESTRATION_THINKING_LEVELS.map((level) => Type.Literal(level))),\n\t\t\t\t},\n\t\t\t\t{ additionalProperties: false },\n\t\t\t),\n\t\t),\n\t\ttoolNames: Type.Optional(\n\t\t\tType.Array(Type.String({ minLength: 1, maxLength: MAX_ORCHESTRATION_IDENTIFIER_LENGTH }), {\n\t\t\t\tmaxItems: MAX_ORCHESTRATION_COLLECTION_LENGTH,\n\t\t\t}),\n\t\t),\n\t\tresourceProfileNames: Type.Optional(\n\t\t\tType.Array(Type.String({ minLength: 1, maxLength: MAX_ORCHESTRATION_IDENTIFIER_LENGTH }), {\n\t\t\t\tmaxItems: MAX_ORCHESTRATION_COLLECTION_LENGTH,\n\t\t\t}),\n\t\t),\n\t\tbudget: Type.Optional(createRiskBudgetSchema()),\n\t};\n}\n\nexport function delegateProfilePanelModel(details: DelegateProfileToolDetails): OrchestrationPanelModel {\n\tif (details.action === \"profile_inspect\") {\n\t\treturn {\n\t\t\tlabel: \"worker profiles\",\n\t\t\taction: \"inspected\",\n\t\t\tstatus: \"success\",\n\t\t\tsummary: [\n\t\t\t\t`${details.inspection?.baseProfiles.length ?? 0} bases`,\n\t\t\t\t`${details.inspection?.models.length ?? 0} models`,\n\t\t\t],\n\t\t};\n\t}\n\treturn {\n\t\tlabel: \"worker profiles\",\n\t\taction: details.created ? \"created\" : \"rejected\",\n\t\tstatus: details.created ? \"success\" : \"warning\",\n\t\trows: details.profileId\n\t\t\t? [\n\t\t\t\t\t{\n\t\t\t\t\t\tstatus: \"succeeded\",\n\t\t\t\t\t\tlabel: details.profileId,\n\t\t\t\t\t\tmeta: details.baseProfileId ? [`base ${details.baseProfileId}`] : undefined,\n\t\t\t\t\t},\n\t\t\t\t]\n\t\t\t: undefined,\n\t\temptyText: details.reason,\n\t};\n}\n\nexport function formatTaskProfileInspection(inspection: TaskProfileInspection): string {\n\tconst bases = inspection.baseProfiles.map((profile) => profile.profileId).join(\", \") || \"none\";\n\treturn `Reusable owner-authored bases for profile_create: ${bases}. Native delegate start does not need a base; omit profileId and set authority.role to explorer or implementer. profile_create requires an owner-authored explorer or implementer base. Available configured models: ${inspection.models.length}.`;\n}\n\nexport function executeDelegateProfileAction(\n\taction: DelegateProfileAction,\n\tinput: DelegateProfileInput,\n\twriter: TaskProfileWriterPort,\n): { content: Array<{ type: \"text\"; text: string }>; details: DelegateProfileToolDetails } {\n\tif (action === \"profile_inspect\") {\n\t\tconst inspection = writer.inspectTaskProfileOptions();\n\t\treturn {\n\t\t\tcontent: [\n\t\t\t\t{\n\t\t\t\t\ttype: \"text\",\n\t\t\t\t\ttext: formatTaskProfileInspection(inspection),\n\t\t\t\t},\n\t\t\t],\n\t\t\tdetails: { started: true, action, kind: \"profile\", created: false, inspection },\n\t\t};\n\t}\n\n\tif (input.task === undefined) {\n\t\treturn {\n\t\t\tcontent: [{ type: \"text\", text: \"delegate profile_create requires task\" }],\n\t\t\tdetails: {\n\t\t\t\tstarted: false,\n\t\t\t\taction,\n\t\t\t\tkind: \"profile\",\n\t\t\t\tcreated: false,\n\t\t\t\treason: \"missing_profile_task\",\n\t\t\t},\n\t\t};\n\t}\n\tconst request: TaskProfileCreateInput = {\n\t\ttask: input.task,\n\t\t...(input.baseProfileId !== undefined ? { baseProfileId: input.baseProfileId } : {}),\n\t\t...(input.model !== undefined ? { model: input.model } : {}),\n\t\t...(input.toolNames !== undefined ? { toolNames: input.toolNames } : {}),\n\t\t...(input.resourceProfileNames !== undefined ? { resourceProfileNames: input.resourceProfileNames } : {}),\n\t\t...(input.budget !== undefined ? { budget: input.budget } : {}),\n\t};\n\tconst result = writer.createTaskProfile(request);\n\treturn {\n\t\tcontent: [\n\t\t\t{\n\t\t\t\ttype: \"text\",\n\t\t\t\ttext: result.created\n\t\t\t\t\t? `Created immutable session task profile ${result.profileId} from ${result.baseProfileId}.`\n\t\t\t\t\t: `delegate profile_create rejected the request: ${result.reason}.`,\n\t\t\t},\n\t\t],\n\t\tdetails: { started: result.created, action, kind: \"profile\", ...result },\n\t};\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"read.d.ts","sourceRoot":"","sources":["../../../src/core/tools/read.ts"],"names":[],"mappings":"AAE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O,UAAU,CAAC,CAEnG"}
|
package/dist/core/tools/read.js
CHANGED
|
@@ -16,6 +16,7 @@ import { getProcessWorkRun } from "../../utils/work-directory.js";
|
|
|
16
16
|
import { FILE_CURRENT_TEXT_RECOVERY_TARGET_KIND, FILE_EXISTS_RECOVERY_TARGET_KIND, fileRecoveryTarget, selectFileFailureRecoveryAuthority, } from "./file-failure-recovery.js";
|
|
17
17
|
import { resolveReadPathAsync, resolveToCwd } from "./path-utils.js";
|
|
18
18
|
import { getTextOutput, renderToolPath, replaceTabs, str } from "./render-utils.js";
|
|
19
|
+
import { isPiSessionJsonlPath, projectPiSessionJsonlLine } from "./session-transcript-read.js";
|
|
19
20
|
import { wrapToolDefinition } from "./tool-definition-wrapper.js";
|
|
20
21
|
const readSchema = Type.Object({
|
|
21
22
|
path: Type.String({ description: "Path to the file to read (relative or absolute)" }),
|
|
@@ -226,6 +227,7 @@ export function createReadToolDefinition(cwd, options) {
|
|
|
226
227
|
const failureRecoveryAuthority = selectFileFailureRecoveryAuthority(options?.operations !== undefined, options?.failureRecoveryAuthority);
|
|
227
228
|
const maxTextReadBytes = options?.maxTextReadBytes ?? DEFAULT_MAX_TEXT_READ_BYTES;
|
|
228
229
|
const maxImageReadBytes = options?.maxImageReadBytes ?? DEFAULT_MAX_IMAGE_READ_BYTES;
|
|
230
|
+
const configuredSessionDirectory = join(getAgentDir(), "sessions");
|
|
229
231
|
return {
|
|
230
232
|
name: "read",
|
|
231
233
|
label: "read",
|
|
@@ -391,9 +393,16 @@ export function createReadToolDefinition(cwd, options) {
|
|
|
391
393
|
userLimitedLines !== undefined && startLine + userLimitedLines < allLines.length;
|
|
392
394
|
}
|
|
393
395
|
const startLineDisplay = startLine + 1;
|
|
396
|
+
const projectSessionTranscript = isPiSessionJsonlPath(absolutePath, configuredSessionDirectory);
|
|
397
|
+
if (projectSessionTranscript) {
|
|
398
|
+
slicedLines = slicedLines.map((item) => ({
|
|
399
|
+
text: projectPiSessionJsonlLine(item.text),
|
|
400
|
+
originalIndex: item.originalIndex,
|
|
401
|
+
}));
|
|
402
|
+
}
|
|
394
403
|
const firstSelectedLineText = slicedLines[0]?.text ?? "";
|
|
395
404
|
// Safe text filtering
|
|
396
|
-
let canFilter =
|
|
405
|
+
let canFilter = !projectSessionTranscript;
|
|
397
406
|
if (mimeType) {
|
|
398
407
|
canFilter = false;
|
|
399
408
|
}
|
|
@@ -505,6 +514,9 @@ export function createReadToolDefinition(cwd, options) {
|
|
|
505
514
|
// No truncation and no remaining content.
|
|
506
515
|
outputText = truncation.content;
|
|
507
516
|
}
|
|
517
|
+
if (projectSessionTranscript) {
|
|
518
|
+
outputText = `Pi session transcript (user/assistant/summary/tool labels only; thinking and payloads omitted).\n${outputText}`;
|
|
519
|
+
}
|
|
508
520
|
content = [{ type: "text", text: outputText }];
|
|
509
521
|
}
|
|
510
522
|
if (aborted)
|