@nubl/maestro 0.1.1 → 0.1.2
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/dist/maestro/adapters/pi/exit-output.d.ts +30 -0
- package/dist/maestro/adapters/pi/exit-output.d.ts.map +1 -0
- package/dist/maestro/adapters/pi/exit-output.js +186 -0
- package/dist/maestro/adapters/pi/exit-output.js.map +1 -0
- package/dist/maestro/adapters/pi/pi-harness-adapter.d.ts +5 -0
- package/dist/maestro/adapters/pi/pi-harness-adapter.d.ts.map +1 -1
- package/dist/maestro/adapters/pi/pi-harness-adapter.js +26 -3
- package/dist/maestro/adapters/pi/pi-harness-adapter.js.map +1 -1
- package/dist/maestro/core/config/model-config.d.ts +5 -1
- package/dist/maestro/core/config/model-config.d.ts.map +1 -1
- package/dist/maestro/core/config/model-config.js +8 -2
- package/dist/maestro/core/config/model-config.js.map +1 -1
- package/dist/maestro/core/status.d.ts.map +1 -1
- package/dist/maestro/core/status.js +7 -1
- package/dist/maestro/core/status.js.map +1 -1
- package/dist/maestro/core/types.d.ts +5 -0
- package/dist/maestro/core/types.d.ts.map +1 -1
- package/dist/maestro/core/types.js.map +1 -1
- package/dist/maestro/runtime/pi-run-session.js +1 -1
- package/dist/maestro/runtime/pi-run-session.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The last lines a child Pi printed when it exited before its session started
|
|
3
|
+
* (#149). Pi writes a startup failure, such as an extension that fails to
|
|
4
|
+
* load, to stderr, which is the child's terminal; the host reads that terminal
|
|
5
|
+
* once and relays a bounded, redacted tail so a failure carries its reason.
|
|
6
|
+
*/
|
|
7
|
+
/** Terminal lines read once after an early exit. */
|
|
8
|
+
export declare const EXIT_OUTPUT_SCREEN_LINES = 40;
|
|
9
|
+
/** Most lines relayed. */
|
|
10
|
+
export declare const EXIT_OUTPUT_MAX_LINES = 12;
|
|
11
|
+
/** Most characters per relayed line. */
|
|
12
|
+
export declare const EXIT_OUTPUT_LINE_CHARS = 300;
|
|
13
|
+
/** Most characters relayed in total. */
|
|
14
|
+
export declare const EXIT_OUTPUT_MAX_CHARS = 2000;
|
|
15
|
+
/** Longest wait for that read. The host's own readers time out later (5-10s). */
|
|
16
|
+
export declare const EXIT_OUTPUT_READ_TIMEOUT_MS = 3000;
|
|
17
|
+
/** Mask credential-shaped substrings of one or more lines. */
|
|
18
|
+
export declare function redactSecrets(text: string): string;
|
|
19
|
+
/**
|
|
20
|
+
* A terminal read bounded by `ms`: undefined when it fails or does not settle
|
|
21
|
+
* in time, so a stuck read never holds back the failure it would explain.
|
|
22
|
+
*/
|
|
23
|
+
export declare function readWithin(read: () => string | Promise<string>, ms: number): Promise<string | undefined>;
|
|
24
|
+
/**
|
|
25
|
+
* The child's output from a terminal tail: the lines after the launch line
|
|
26
|
+
* (the last line naming `launchScriptFile`, when present) and before the exit
|
|
27
|
+
* marker, cleaned, redacted and bounded. Undefined when nothing is left.
|
|
28
|
+
*/
|
|
29
|
+
export declare function extractExitOutput(screen: string, launchScriptFile?: string): string | undefined;
|
|
30
|
+
//# sourceMappingURL=exit-output.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exit-output.d.ts","sourceRoot":"","sources":["../../../../maestro/adapters/pi/exit-output.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,oDAAoD;AACpD,eAAO,MAAM,wBAAwB,KAAK,CAAC;AAC3C,0BAA0B;AAC1B,eAAO,MAAM,qBAAqB,KAAK,CAAC;AACxC,wCAAwC;AACxC,eAAO,MAAM,sBAAsB,MAAM,CAAC;AAC1C,wCAAwC;AACxC,eAAO,MAAM,qBAAqB,OAAQ,CAAC;AAC3C,iFAAiF;AACjF,eAAO,MAAM,2BAA2B,OAAQ,CAAC;AA4HjD,8DAA8D;AAC9D,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAElD;AAED;;;GAGG;AACH,wBAAsB,UAAU,CAC/B,IAAI,EAAE,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,EACpC,EAAE,EAAE,MAAM,GACR,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAc7B;AAMD;;;;GAIG;AACH,wBAAgB,iBAAiB,CAChC,MAAM,EAAE,MAAM,EACd,gBAAgB,CAAC,EAAE,MAAM,GACvB,MAAM,GAAG,SAAS,CA2BpB"}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The last lines a child Pi printed when it exited before its session started
|
|
3
|
+
* (#149). Pi writes a startup failure, such as an extension that fails to
|
|
4
|
+
* load, to stderr, which is the child's terminal; the host reads that terminal
|
|
5
|
+
* once and relays a bounded, redacted tail so a failure carries its reason.
|
|
6
|
+
*/
|
|
7
|
+
/** Terminal lines read once after an early exit. */
|
|
8
|
+
export const EXIT_OUTPUT_SCREEN_LINES = 40;
|
|
9
|
+
/** Most lines relayed. */
|
|
10
|
+
export const EXIT_OUTPUT_MAX_LINES = 12;
|
|
11
|
+
/** Most characters per relayed line. */
|
|
12
|
+
export const EXIT_OUTPUT_LINE_CHARS = 300;
|
|
13
|
+
/** Most characters relayed in total. */
|
|
14
|
+
export const EXIT_OUTPUT_MAX_CHARS = 2_000;
|
|
15
|
+
/** Longest wait for that read. The host's own readers time out later (5-10s). */
|
|
16
|
+
export const EXIT_OUTPUT_READ_TIMEOUT_MS = 3_000;
|
|
17
|
+
const TERMINAL_SENTINEL = /__SUBAGENT_DONE_\d+__/;
|
|
18
|
+
// CSI and OSC escape sequences; then, per line, any remaining control.
|
|
19
|
+
const ANSI_ESCAPE =
|
|
20
|
+
// oxlint-disable-next-line no-control-regex -- terminal escapes start with ESC.
|
|
21
|
+
/\u001b\[[0-?]*[ -/]*[@-~]|\u001b\][^\u0007\u001b]*(?:\u0007|\u001b\\)|\u001b[@-_]/g;
|
|
22
|
+
const CONTROL = /\p{Cc}/gu;
|
|
23
|
+
const REDACTED = "[redacted]";
|
|
24
|
+
// AWS access key IDs by their documented unique-ID prefixes: AKIA long-term,
|
|
25
|
+
// ASIA temporary (STS), and the other IAM resource prefixes.
|
|
26
|
+
const AWS_KEY_ID = /\b(?:A3T[A-Z0-9]|AKIA|ASIA|ABIA|ACCA|AGPA|AIDA|AIPA|ANPA|ANVA|APKA|AROA|ASCA)[A-Z0-9]{16}\b/g;
|
|
27
|
+
const SECRET_RULES = [
|
|
28
|
+
// user:password@ in a URL
|
|
29
|
+
{ pattern: /\b[a-z][a-z0-9+.-]*:\/\/([^\s/@:]+:[^\s/@]+)(?=@)/gi },
|
|
30
|
+
// key, token, signature or password query parameters
|
|
31
|
+
{
|
|
32
|
+
pattern: /[?&][^\s=&#]*(?:key|token|sig|signature|secret|password|auth)[^\s=&#]*=([^\s&#"']+)/gi,
|
|
33
|
+
},
|
|
34
|
+
// Authorization: <scheme> <credential>, in any case
|
|
35
|
+
{
|
|
36
|
+
pattern: /\bauthorization["']?\s*[:=]\s*["']?(?:(?:bearer|basic|digest|token|negotiate)\s+)?([^\s"',;]+)/gi,
|
|
37
|
+
},
|
|
38
|
+
// Bearer/Basic <credential>
|
|
39
|
+
{ pattern: /\b(?:[Bb]earer|BEARER|Basic)\s+([A-Za-z0-9._~+/=-]{8,})/g },
|
|
40
|
+
// NAME=value, "name": "value" and name: value for credential-like names
|
|
41
|
+
{
|
|
42
|
+
pattern: /\b[A-Za-z0-9_.-]*(?:api[_-]?key|apikey|token|secret|passw(?:or)?d|credential)[A-Za-z0-9_.-]*["']?\s*[:=]\s*["']?([^\s"',;]+)/gi,
|
|
43
|
+
},
|
|
44
|
+
// Well-known credential prefixes
|
|
45
|
+
{
|
|
46
|
+
pattern: /\b(?:sk|pk|rk)-[A-Za-z0-9_-]{16,}|\b(?:gh[pousr]_|github_pat_)[A-Za-z0-9_]{20,}|\bglpat-[A-Za-z0-9_-]{20,}|\bxox[abprs]-[A-Za-z0-9-]{10,}|\bAIza[0-9A-Za-z_-]{35}\b/g,
|
|
47
|
+
},
|
|
48
|
+
{ pattern: AWS_KEY_ID },
|
|
49
|
+
// A JWT (or JWE) of any length: base64url JSON ("eyJ") and its segments.
|
|
50
|
+
{ pattern: /\beyJ[A-Za-z0-9_-]{4,}(?:\.[A-Za-z0-9_-]*)*/g },
|
|
51
|
+
// An AWS secret access key: exactly 40 base64 characters, mixed case with a
|
|
52
|
+
// digit or "+". A path is rarely exactly 40 such characters and never
|
|
53
|
+
// starts the run with "/"; when one does match, it is masked.
|
|
54
|
+
{
|
|
55
|
+
pattern: /(?<![A-Za-z0-9/+])[A-Za-z0-9/+]{40}(?![A-Za-z0-9/+])/g,
|
|
56
|
+
keep: (run) => !run.startsWith("/") &&
|
|
57
|
+
/[A-Z]/.test(run) &&
|
|
58
|
+
/[a-z]/.test(run) &&
|
|
59
|
+
/[0-9+]/.test(run),
|
|
60
|
+
},
|
|
61
|
+
// A long opaque run with both letters and digits: likely a key or token.
|
|
62
|
+
{
|
|
63
|
+
pattern: /[A-Za-z0-9+_=-]{40,}/g,
|
|
64
|
+
keep: (run) => /\d/.test(run) && /[A-Za-z]/.test(run),
|
|
65
|
+
},
|
|
66
|
+
];
|
|
67
|
+
/** [start, end) ranges of credential-shaped text. */
|
|
68
|
+
function secretRanges(text) {
|
|
69
|
+
const ranges = [];
|
|
70
|
+
for (const { pattern, keep } of SECRET_RULES)
|
|
71
|
+
for (const match of text.matchAll(pattern)) {
|
|
72
|
+
if (keep && !keep(match[0]))
|
|
73
|
+
continue;
|
|
74
|
+
const end = match.index + match[0].length;
|
|
75
|
+
const secret = match[1] ?? match[0];
|
|
76
|
+
if (secret.length > 0)
|
|
77
|
+
ranges.push([end - secret.length, end]);
|
|
78
|
+
}
|
|
79
|
+
return ranges;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Mask credential-shaped text in terminal rows. Best effort: it errs toward
|
|
83
|
+
* masking. Each row is masked on its own; then rows a terminal wrapped are
|
|
84
|
+
* rejoined and masked again, so a credential split across rows is masked on
|
|
85
|
+
* every row it reaches. A row as wide as the widest row is taken to wrap into
|
|
86
|
+
* the next; a row one character narrower, to wrap on a space the read trimmed.
|
|
87
|
+
*/
|
|
88
|
+
function redactLines(lines) {
|
|
89
|
+
const masks = lines.map((line) => new Uint8Array(line.length));
|
|
90
|
+
lines.forEach((line, row) => {
|
|
91
|
+
for (const [start, end] of secretRanges(line))
|
|
92
|
+
masks[row].fill(1, start, end);
|
|
93
|
+
});
|
|
94
|
+
const width = Math.max(0, ...lines.map((line) => line.length));
|
|
95
|
+
for (let first = 0, last = 0; first < lines.length; first = ++last) {
|
|
96
|
+
let joined = lines[first];
|
|
97
|
+
const offsets = [0];
|
|
98
|
+
while (last + 1 < lines.length && lines[last].length >= width - 1) {
|
|
99
|
+
joined += lines[last].length === width ? "" : " ";
|
|
100
|
+
offsets.push(joined.length);
|
|
101
|
+
joined += lines[++last];
|
|
102
|
+
}
|
|
103
|
+
if (last === first)
|
|
104
|
+
continue;
|
|
105
|
+
for (const [start, end] of secretRanges(joined))
|
|
106
|
+
for (let row = first; row <= last; row++) {
|
|
107
|
+
const offset = offsets[row - first];
|
|
108
|
+
const from = Math.max(start - offset, 0);
|
|
109
|
+
const to = Math.min(end - offset, lines[row].length);
|
|
110
|
+
if (from < to)
|
|
111
|
+
masks[row].fill(1, from, to);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return lines.map((line, row) => {
|
|
115
|
+
let masked = "";
|
|
116
|
+
for (let at = 0; at < line.length; at++)
|
|
117
|
+
if (!masks[row][at])
|
|
118
|
+
masked += line[at];
|
|
119
|
+
else if (at === 0 || !masks[row][at - 1])
|
|
120
|
+
masked += REDACTED;
|
|
121
|
+
return masked;
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
/** Mask credential-shaped substrings of one or more lines. */
|
|
125
|
+
export function redactSecrets(text) {
|
|
126
|
+
return redactLines(text.split("\n")).join("\n");
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* A terminal read bounded by `ms`: undefined when it fails or does not settle
|
|
130
|
+
* in time, so a stuck read never holds back the failure it would explain.
|
|
131
|
+
*/
|
|
132
|
+
export async function readWithin(read, ms) {
|
|
133
|
+
let timer;
|
|
134
|
+
try {
|
|
135
|
+
return await Promise.race([
|
|
136
|
+
Promise.resolve().then(read),
|
|
137
|
+
new Promise((resolve) => {
|
|
138
|
+
timer = setTimeout(() => resolve(undefined), ms);
|
|
139
|
+
}),
|
|
140
|
+
]);
|
|
141
|
+
}
|
|
142
|
+
catch {
|
|
143
|
+
return undefined;
|
|
144
|
+
}
|
|
145
|
+
finally {
|
|
146
|
+
clearTimeout(timer);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
function clip(line, max) {
|
|
150
|
+
return line.length <= max ? line : `${line.slice(0, max - 1)}…`;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* The child's output from a terminal tail: the lines after the launch line
|
|
154
|
+
* (the last line naming `launchScriptFile`, when present) and before the exit
|
|
155
|
+
* marker, cleaned, redacted and bounded. Undefined when nothing is left.
|
|
156
|
+
*/
|
|
157
|
+
export function extractExitOutput(screen, launchScriptFile) {
|
|
158
|
+
let lines = screen
|
|
159
|
+
.replace(ANSI_ESCAPE, "")
|
|
160
|
+
.split(/\r?\n|\r/)
|
|
161
|
+
.map((line) => line.replace(/\t/g, " ").replace(CONTROL, "").trimEnd());
|
|
162
|
+
const marker = lines.findLastIndex((line) => TERMINAL_SENTINEL.test(line));
|
|
163
|
+
if (marker !== -1)
|
|
164
|
+
lines = lines.slice(0, marker);
|
|
165
|
+
const launchName = launchScriptFile?.split(/[\\/]/).pop();
|
|
166
|
+
if (launchName) {
|
|
167
|
+
const launch = lines.findLastIndex((line) => line.includes(launchName));
|
|
168
|
+
if (launch !== -1)
|
|
169
|
+
lines = lines.slice(launch + 1);
|
|
170
|
+
}
|
|
171
|
+
// Mask the whole read before taking the tail, so a credential that started
|
|
172
|
+
// on a row above the tail is still recognised.
|
|
173
|
+
const tail = redactLines(lines.filter((line) => line.trim() !== "")).slice(-EXIT_OUTPUT_MAX_LINES);
|
|
174
|
+
const kept = [];
|
|
175
|
+
let chars = 0;
|
|
176
|
+
// Newest lines first, so the character bound drops the oldest.
|
|
177
|
+
for (let index = tail.length - 1; index >= 0; index--) {
|
|
178
|
+
const relayed = clip(tail[index], EXIT_OUTPUT_LINE_CHARS);
|
|
179
|
+
if (chars + relayed.length > EXIT_OUTPUT_MAX_CHARS)
|
|
180
|
+
break;
|
|
181
|
+
chars += relayed.length + 1;
|
|
182
|
+
kept.unshift(relayed);
|
|
183
|
+
}
|
|
184
|
+
return kept.length > 0 ? kept.join("\n") : undefined;
|
|
185
|
+
}
|
|
186
|
+
//# sourceMappingURL=exit-output.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exit-output.js","sourceRoot":"","sources":["../../../../maestro/adapters/pi/exit-output.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,oDAAoD;AACpD,MAAM,CAAC,MAAM,wBAAwB,GAAG,EAAE,CAAC;AAC3C,0BAA0B;AAC1B,MAAM,CAAC,MAAM,qBAAqB,GAAG,EAAE,CAAC;AACxC,wCAAwC;AACxC,MAAM,CAAC,MAAM,sBAAsB,GAAG,GAAG,CAAC;AAC1C,wCAAwC;AACxC,MAAM,CAAC,MAAM,qBAAqB,GAAG,KAAK,CAAC;AAC3C,iFAAiF;AACjF,MAAM,CAAC,MAAM,2BAA2B,GAAG,KAAK,CAAC;AAEjD,MAAM,iBAAiB,GAAG,uBAAuB,CAAC;AAClD,uEAAuE;AACvE,MAAM,WAAW;AAChB,gFAAgF;AAChF,oFAAoF,CAAC;AACtF,MAAM,OAAO,GAAG,UAAU,CAAC;AAE3B,MAAM,QAAQ,GAAG,YAAY,CAAC;AAY9B,6EAA6E;AAC7E,6DAA6D;AAC7D,MAAM,UAAU,GACf,8FAA8F,CAAC;AAChG,MAAM,YAAY,GAAiB;IAClC,0BAA0B;IAC1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AAC;QACvD,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,sBAAsB,CAAC,CAAC;QAC1D,IAAI,KAAK,GAAG,OAAO,CAAC,MAAM,GAAG,qBAAqB;YAAE,MAAM;QAC1D,KAAK,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC;QAC5B,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IACvB,CAAC;IACD,OAAO,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AACtD,CAAC","sourcesContent":["/**\n * The last lines a child Pi printed when it exited before its session started\n * (#149). Pi writes a startup failure, such as an extension that fails to\n * load, to stderr, which is the child's terminal; the host reads that terminal\n * once and relays a bounded, redacted tail so a failure carries its reason.\n */\n\n/** Terminal lines read once after an early exit. */\nexport const EXIT_OUTPUT_SCREEN_LINES = 40;\n/** Most lines relayed. */\nexport const EXIT_OUTPUT_MAX_LINES = 12;\n/** Most characters per relayed line. */\nexport const EXIT_OUTPUT_LINE_CHARS = 300;\n/** Most characters relayed in total. */\nexport const EXIT_OUTPUT_MAX_CHARS = 2_000;\n/** Longest wait for that read. The host's own readers time out later (5-10s). */\nexport const EXIT_OUTPUT_READ_TIMEOUT_MS = 3_000;\n\nconst TERMINAL_SENTINEL = /__SUBAGENT_DONE_\\d+__/;\n// CSI and OSC escape sequences; then, per line, any remaining control.\nconst ANSI_ESCAPE =\n\t// oxlint-disable-next-line no-control-regex -- terminal escapes start with ESC.\n\t/\\u001b\\[[0-?]*[ -/]*[@-~]|\\u001b\\][^\\u0007\\u001b]*(?:\\u0007|\\u001b\\\\)|\\u001b[@-_]/g;\nconst CONTROL = /\\p{Cc}/gu;\n\nconst REDACTED = \"[redacted]\";\n\n/**\n * A credential shape. The secret is the whole match, or capture group 1 when\n * the pattern has one; a group always ends the match, so a label before it\n * (\"Bearer \", \"key=\") stays readable. `keep` rejects a match that only looks\n * like a credential.\n */\ninterface SecretRule {\n\tpattern: RegExp;\n\tkeep?: (match: string) => boolean;\n}\n// AWS access key IDs by their documented unique-ID prefixes: AKIA long-term,\n// ASIA temporary (STS), and the other IAM resource prefixes.\nconst AWS_KEY_ID =\n\t/\\b(?:A3T[A-Z0-9]|AKIA|ASIA|ABIA|ACCA|AGPA|AIDA|AIPA|ANPA|ANVA|APKA|AROA|ASCA)[A-Z0-9]{16}\\b/g;\nconst SECRET_RULES: SecretRule[] = [\n\t// user:password@ in a URL\n\t{ pattern: /\\b[a-z][a-z0-9+.-]*:\\/\\/([^\\s/@:]+:[^\\s/@]+)(?=@)/gi },\n\t// key, token, signature or password query parameters\n\t{\n\t\tpattern:\n\t\t\t/[?&][^\\s=&#]*(?:key|token|sig|signature|secret|password|auth)[^\\s=&#]*=([^\\s&#\"']+)/gi,\n\t},\n\t// Authorization: <scheme> <credential>, in any case\n\t{\n\t\tpattern:\n\t\t\t/\\bauthorization[\"']?\\s*[:=]\\s*[\"']?(?:(?:bearer|basic|digest|token|negotiate)\\s+)?([^\\s\"',;]+)/gi,\n\t},\n\t// Bearer/Basic <credential>\n\t{ pattern: /\\b(?:[Bb]earer|BEARER|Basic)\\s+([A-Za-z0-9._~+/=-]{8,})/g },\n\t// NAME=value, \"name\": \"value\" and name: value for credential-like names\n\t{\n\t\tpattern:\n\t\t\t/\\b[A-Za-z0-9_.-]*(?:api[_-]?key|apikey|token|secret|passw(?:or)?d|credential)[A-Za-z0-9_.-]*[\"']?\\s*[:=]\\s*[\"']?([^\\s\"',;]+)/gi,\n\t},\n\t// Well-known credential prefixes\n\t{\n\t\tpattern:\n\t\t\t/\\b(?:sk|pk|rk)-[A-Za-z0-9_-]{16,}|\\b(?:gh[pousr]_|github_pat_)[A-Za-z0-9_]{20,}|\\bglpat-[A-Za-z0-9_-]{20,}|\\bxox[abprs]-[A-Za-z0-9-]{10,}|\\bAIza[0-9A-Za-z_-]{35}\\b/g,\n\t},\n\t{ pattern: AWS_KEY_ID },\n\t// A JWT (or JWE) of any length: base64url JSON (\"eyJ\") and its segments.\n\t{ pattern: /\\beyJ[A-Za-z0-9_-]{4,}(?:\\.[A-Za-z0-9_-]*)*/g },\n\t// An AWS secret access key: exactly 40 base64 characters, mixed case with a\n\t// digit or \"+\". A path is rarely exactly 40 such characters and never\n\t// starts the run with \"/\"; when one does match, it is masked.\n\t{\n\t\tpattern: /(?<![A-Za-z0-9/+])[A-Za-z0-9/+]{40}(?![A-Za-z0-9/+])/g,\n\t\tkeep: (run) =>\n\t\t\t!run.startsWith(\"/\") &&\n\t\t\t/[A-Z]/.test(run) &&\n\t\t\t/[a-z]/.test(run) &&\n\t\t\t/[0-9+]/.test(run),\n\t},\n\t// A long opaque run with both letters and digits: likely a key or token.\n\t{\n\t\tpattern: /[A-Za-z0-9+_=-]{40,}/g,\n\t\tkeep: (run) => /\\d/.test(run) && /[A-Za-z]/.test(run),\n\t},\n];\n\n/** [start, end) ranges of credential-shaped text. */\nfunction secretRanges(text: string): [number, number][] {\n\tconst ranges: [number, number][] = [];\n\tfor (const { pattern, keep } of SECRET_RULES)\n\t\tfor (const match of text.matchAll(pattern)) {\n\t\t\tif (keep && !keep(match[0])) continue;\n\t\t\tconst end = match.index + match[0].length;\n\t\t\tconst secret = match[1] ?? match[0];\n\t\t\tif (secret.length > 0) ranges.push([end - secret.length, end]);\n\t\t}\n\treturn ranges;\n}\n\n/**\n * Mask credential-shaped text in terminal rows. Best effort: it errs toward\n * masking. Each row is masked on its own; then rows a terminal wrapped are\n * rejoined and masked again, so a credential split across rows is masked on\n * every row it reaches. A row as wide as the widest row is taken to wrap into\n * the next; a row one character narrower, to wrap on a space the read trimmed.\n */\nfunction redactLines(lines: readonly string[]): string[] {\n\tconst masks = lines.map((line) => new Uint8Array(line.length));\n\tlines.forEach((line, row) => {\n\t\tfor (const [start, end] of secretRanges(line))\n\t\t\tmasks[row].fill(1, start, end);\n\t});\n\tconst width = Math.max(0, ...lines.map((line) => line.length));\n\tfor (let first = 0, last = 0; first < lines.length; first = ++last) {\n\t\tlet joined = lines[first];\n\t\tconst offsets = [0];\n\t\twhile (last + 1 < lines.length && lines[last].length >= width - 1) {\n\t\t\tjoined += lines[last].length === width ? \"\" : \" \";\n\t\t\toffsets.push(joined.length);\n\t\t\tjoined += lines[++last];\n\t\t}\n\t\tif (last === first) continue;\n\t\tfor (const [start, end] of secretRanges(joined))\n\t\t\tfor (let row = first; row <= last; row++) {\n\t\t\t\tconst offset = offsets[row - first];\n\t\t\t\tconst from = Math.max(start - offset, 0);\n\t\t\t\tconst to = Math.min(end - offset, lines[row].length);\n\t\t\t\tif (from < to) masks[row].fill(1, from, to);\n\t\t\t}\n\t}\n\treturn lines.map((line, row) => {\n\t\tlet masked = \"\";\n\t\tfor (let at = 0; at < line.length; at++)\n\t\t\tif (!masks[row][at]) masked += line[at];\n\t\t\telse if (at === 0 || !masks[row][at - 1]) masked += REDACTED;\n\t\treturn masked;\n\t});\n}\n\n/** Mask credential-shaped substrings of one or more lines. */\nexport function redactSecrets(text: string): string {\n\treturn redactLines(text.split(\"\\n\")).join(\"\\n\");\n}\n\n/**\n * A terminal read bounded by `ms`: undefined when it fails or does not settle\n * in time, so a stuck read never holds back the failure it would explain.\n */\nexport async function readWithin(\n\tread: () => string | Promise<string>,\n\tms: number,\n): Promise<string | undefined> {\n\tlet timer: ReturnType<typeof setTimeout> | undefined;\n\ttry {\n\t\treturn await Promise.race([\n\t\t\tPromise.resolve().then(read),\n\t\t\tnew Promise<undefined>((resolve) => {\n\t\t\t\ttimer = setTimeout(() => resolve(undefined), ms);\n\t\t\t}),\n\t\t]);\n\t} catch {\n\t\treturn undefined;\n\t} finally {\n\t\tclearTimeout(timer);\n\t}\n}\n\nfunction clip(line: string, max: number): string {\n\treturn line.length <= max ? line : `${line.slice(0, max - 1)}…`;\n}\n\n/**\n * The child's output from a terminal tail: the lines after the launch line\n * (the last line naming `launchScriptFile`, when present) and before the exit\n * marker, cleaned, redacted and bounded. Undefined when nothing is left.\n */\nexport function extractExitOutput(\n\tscreen: string,\n\tlaunchScriptFile?: string,\n): string | undefined {\n\tlet lines = screen\n\t\t.replace(ANSI_ESCAPE, \"\")\n\t\t.split(/\\r?\\n|\\r/)\n\t\t.map((line) => line.replace(/\\t/g, \" \").replace(CONTROL, \"\").trimEnd());\n\tconst marker = lines.findLastIndex((line) => TERMINAL_SENTINEL.test(line));\n\tif (marker !== -1) lines = lines.slice(0, marker);\n\tconst launchName = launchScriptFile?.split(/[\\\\/]/).pop();\n\tif (launchName) {\n\t\tconst launch = lines.findLastIndex((line) => line.includes(launchName));\n\t\tif (launch !== -1) lines = lines.slice(launch + 1);\n\t}\n\t// Mask the whole read before taking the tail, so a credential that started\n\t// on a row above the tail is still recognised.\n\tconst tail = redactLines(lines.filter((line) => line.trim() !== \"\")).slice(\n\t\t-EXIT_OUTPUT_MAX_LINES,\n\t);\n\tconst kept: string[] = [];\n\tlet chars = 0;\n\t// Newest lines first, so the character bound drops the oldest.\n\tfor (let index = tail.length - 1; index >= 0; index--) {\n\t\tconst relayed = clip(tail[index], EXIT_OUTPUT_LINE_CHARS);\n\t\tif (chars + relayed.length > EXIT_OUTPUT_MAX_CHARS) break;\n\t\tchars += relayed.length + 1;\n\t\tkept.unshift(relayed);\n\t}\n\treturn kept.length > 0 ? kept.join(\"\\n\") : undefined;\n}\n"]}
|
|
@@ -86,6 +86,11 @@ export declare class PiHarnessAdapter implements HarnessAdapter {
|
|
|
86
86
|
exitCode(handle: AgentHandle): number | undefined;
|
|
87
87
|
sendInput(handle: AgentHandle, text: string): Promise<void>;
|
|
88
88
|
awaitCompletion(handle: AgentHandle, signal: AbortSignal): Promise<CompletionEvidence>;
|
|
89
|
+
/**
|
|
90
|
+
* A child that failed before its session started has no transcript to
|
|
91
|
+
* explain it; relay the terminal's last lines instead (#149).
|
|
92
|
+
*/
|
|
93
|
+
private readExitOutput;
|
|
89
94
|
private joinWait;
|
|
90
95
|
private runKey;
|
|
91
96
|
private track;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pi-harness-adapter.d.ts","sourceRoot":"","sources":["../../../../maestro/adapters/pi/pi-harness-adapter.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACX,cAAc,EACd,aAAa,EACb,YAAY,EACZ,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EACX,WAAW,EACX,UAAU,EACV,kBAAkB,EAClB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAQtE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAIN,KAAK,oBAAoB,EACzB,KAAK,aAAa,EAClB,KAAK,mBAAmB,EACxB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AACxE,OAAO,EAKN,KAAK,oBAAoB,EAEzB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAGN,KAAK,kBAAkB,EACvB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAKN,KAAK,oBAAoB,EACzB,KAAK,cAAc,EACnB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"pi-harness-adapter.d.ts","sourceRoot":"","sources":["../../../../maestro/adapters/pi/pi-harness-adapter.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACX,cAAc,EACd,aAAa,EACb,YAAY,EACZ,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EACX,WAAW,EACX,UAAU,EACV,kBAAkB,EAClB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAQtE,OAAO,KAAK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M,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAqB9C;;;;;;;;;;OAUG;YACW,cAAc;IAgFtB,UAAU,CAAC,MAAM,EAAE,WAAW,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAMtE,QAAQ,CAAC,MAAM,EAAE,WAAW,GAAG,MAAM,GAAG,SAAS;IAG3C,SAAS,CAAC,MAAM,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAsC3D,eAAe,CACpB,MAAM,EAAE,WAAW,EACnB,MAAM,EAAE,WAAW,GACjB,OAAO,CAAC,kBAAkB,CAAC;IA4H9B;;;OAGG;YACW,cAAc;IAyB5B,OAAO,CAAC,QAAQ;IAmBhB,OAAO,CAAC,MAAM;IAId,OAAO,CAAC,KAAK;IA2Bb,OAAO,CAAC,aAAa;IA2BrB,OAAO,CAAC,iBAAiB;CAMzB"}
|
|
@@ -10,6 +10,7 @@ import { launchPiSubagent, AcquiredPiLaunchError, startProcessIdentityCapture, }
|
|
|
10
10
|
import { shellExitFileFor, waitForCompletion } from "./completion.js";
|
|
11
11
|
import { acceptLaunchRefusal } from "../../core/accept.js";
|
|
12
12
|
import { notifyLaunchRefusal } from "../../core/specialist-notice.js";
|
|
13
|
+
import { EXIT_OUTPUT_READ_TIMEOUT_MS, EXIT_OUTPUT_SCREEN_LINES, extractExitOutput, readWithin, } from "./exit-output.js";
|
|
13
14
|
import { appendPersistentDeliveryLedger, findObservedSessionRuntime, getNewEntries, inspectFinalAssistantMessage, readPersistentTaskEvents, writePersistentTaskInbox, } from "./session.js";
|
|
14
15
|
/** Pi's existing launch and child-sidecar protocol behind the harness seam. */
|
|
15
16
|
export class PiHarnessAdapter {
|
|
@@ -423,7 +424,7 @@ export class PiHarnessAdapter {
|
|
|
423
424
|
},
|
|
424
425
|
});
|
|
425
426
|
})()
|
|
426
|
-
.then((result) => {
|
|
427
|
+
.then(async (result) => {
|
|
427
428
|
if (child.launchFailure)
|
|
428
429
|
result = {
|
|
429
430
|
...result,
|
|
@@ -432,13 +433,19 @@ export class PiHarnessAdapter {
|
|
|
432
433
|
errorMessage: child.launchFailure,
|
|
433
434
|
errorSource: "host",
|
|
434
435
|
};
|
|
435
|
-
const
|
|
436
|
-
?
|
|
436
|
+
const entries = existsSync(child.sessionFile)
|
|
437
|
+
? getNewEntries(child.sessionFile, 0)
|
|
438
|
+
: undefined;
|
|
439
|
+
const final = entries
|
|
440
|
+
? inspectFinalAssistantMessage(entries)
|
|
437
441
|
: undefined;
|
|
438
442
|
const evidence = {
|
|
439
443
|
...result,
|
|
440
444
|
sessionRef: child.sessionFile,
|
|
441
445
|
};
|
|
446
|
+
const exitOutput = await this.readExitOutput(child, result, entries);
|
|
447
|
+
if (exitOutput)
|
|
448
|
+
evidence.exitOutput = exitOutput;
|
|
442
449
|
if (final && (final.text != null || final.stopReason)) {
|
|
443
450
|
evidence.finalMessage = {
|
|
444
451
|
text: final.text ?? "",
|
|
@@ -464,6 +471,22 @@ export class PiHarnessAdapter {
|
|
|
464
471
|
}
|
|
465
472
|
return this.joinWait(wait, signal);
|
|
466
473
|
}
|
|
474
|
+
/**
|
|
475
|
+
* A child that failed before its session started has no transcript to
|
|
476
|
+
* explain it; relay the terminal's last lines instead (#149).
|
|
477
|
+
*/
|
|
478
|
+
async readExitOutput(child, result, entries) {
|
|
479
|
+
if (result.exitCode === 0 ||
|
|
480
|
+
result.errorMessage ||
|
|
481
|
+
entries?.some((entry) => entry.type === "message"))
|
|
482
|
+
return undefined;
|
|
483
|
+
// The output only explains the failure; a terminal that cannot be read
|
|
484
|
+
// in time leaves the exit code as the result.
|
|
485
|
+
const screen = await readWithin(() => this.options.surface.readScreen(child.surface, EXIT_OUTPUT_SCREEN_LINES), EXIT_OUTPUT_READ_TIMEOUT_MS);
|
|
486
|
+
return screen === undefined
|
|
487
|
+
? undefined
|
|
488
|
+
: extractExitOutput(screen, child.launchScriptFile);
|
|
489
|
+
}
|
|
467
490
|
joinWait(wait, signal) {
|
|
468
491
|
wait.waiters++;
|
|
469
492
|
const abort = () => rejectWait(new Error("Aborted while waiting for subagent to finish"));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pi-harness-adapter.js","sourceRoot":"","sources":["../../../../maestro/adapters/pi/pi-harness-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACtE,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAY5C,OAAO,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EACN,sBAAsB,EACtB,sBAAsB,EACtB,eAAe,EACf,qBAAqB,GACrB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EACN,eAAe,EACf,kBAAkB,EAClB,kBAAkB,GAIlB,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EACN,oBAAoB,EACpB,iBAAiB,EACjB,wBAAwB,GAIxB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACN,2BAA2B,EAC3B,YAAY,GAEZ,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACN,gBAAgB,EAChB,qBAAqB,EAErB,2BAA2B,GAG3B,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACtE,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AACtE,OAAO,EACN,8BAA8B,EAC9B,0BAA0B,EAC1B,aAAa,EACb,4BAA4B,EAC5B,wBAAwB,EACxB,wBAAwB,GACxB,MAAM,cAAc,CAAC;AA0DtB,+EAA+E;AAC/E,MAAM,OAAO,gBAAgB;IACn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AC,QAAQ,EAAE,KAAK,IAAI,EAAE,CACtD,CAAC;QACF,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,EAAE,QAAQ,IAAI,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,QAAQ,CAAC;QACxE,IAAI,KAAK,IAAI,QAAQ;YAAE,OAAO,EAAE,GAAG,KAAK,EAAE,QAAQ,EAAE,CAAC;QACrD,MAAM,IAAI,KAAK,CACd,6EAA6E,CAC7E,CAAC;IACH,CAAC;IACO,iBAAiB,CAAC,GAAuC;QAChE,IAAI,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM;YACjC,MAAM,IAAI,KAAK,CACd,kFAAkF,CAClF,CAAC;IACJ,CAAC;CACD;AAED,SAAS,SAAS,CAAC,KAAc;IAChC,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC/D,CAAC;AAED,SAAS,qBAAqB,CAC7B,QAA2B,EAC3B,KAA2B,EAC3B,SAAkB,EAClB,SAAiB;IAEjB,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS;QAC3B,OAAO,GAAG,KAAK,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,iBAAiB,EAAE,CAAC;IAC7E,OAAO,WAAW,QAAQ,CAAC,GAAG,gBAAgB,QAAQ,CAAC,SAAS,cAAc,KAAK,CAAC,IAAI,IAAI,SAAS,kBAAkB,CAAC;AACzH,CAAC","sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport { accessSync, constants, existsSync, statSync } from \"node:fs\";\nimport { delimiter, join } from \"node:path\";\nimport type {\n\tHarnessAdapter,\n\tResumeOptions,\n\tSpawnOptions,\n} from \"../../core/harness-adapter.ts\";\nimport type {\n\tAgentHandle,\n\tAgentState,\n\tCompletionEvidence,\n} from \"../../core/types.ts\";\nimport type { SurfaceProvider } from \"../../core/surface-provider.ts\";\nimport { readSubagentActivityFile } from \"./activity-file.ts\";\nimport {\n\tmarkCompletionDetected,\n\tmarkInterruptRequested,\n\tobserveActivity,\n\tobservePaneInspection,\n} from \"../../core/lifecycle.ts\";\nimport type { PaneConfig } from \"../../core/config/pane-config.ts\";\nimport {\n\tisThinkingLevel,\n\tparseExactModelRef,\n\tresolveRuntimePlan,\n\ttype ModelRegistryAdapter,\n\ttype ParentRuntime,\n\ttype ResolvedRuntimePlan,\n} from \"../../core/routing.ts\";\nimport type { FileWakeRegistry } from \"../../core/wake.ts\";\nimport type { SupervisionCoordinator } from \"../../core/supervision.ts\";\nimport {\n\tjudgeProcessIdentity,\n\tlinuxProcessProbe,\n\tterminateProcessIdentity,\n\ttype PiProcessIdentity,\n\ttype ProcessIdentityProbe,\n\ttype ProcessIdentityState,\n} from \"./process-identity.ts\";\nimport {\n\tlaunchOperationsFromSurface,\n\tsettleBefore,\n\ttype PiLaunchOperations,\n} from \"./launch-operations.ts\";\nimport {\n\tlaunchPiSubagent,\n\tAcquiredPiLaunchError,\n\ttype PiLaunchRequest,\n\tstartProcessIdentityCapture,\n\ttype FreshPiLaunchRequest,\n\ttype PiRunningChild,\n} from \"./launch.ts\";\nimport type { WorktreeOperations } from \"../../core/worktree.ts\";\nimport { shellExitFileFor, waitForCompletion } from \"./completion.ts\";\nimport { acceptLaunchRefusal } from \"../../core/accept.ts\";\nimport { notifyLaunchRefusal } from \"../../core/specialist-notice.ts\";\nimport {\n\tappendPersistentDeliveryLedger,\n\tfindObservedSessionRuntime,\n\tgetNewEntries,\n\tinspectFinalAssistantMessage,\n\treadPersistentTaskEvents,\n\twritePersistentTaskInbox,\n} from \"./session.ts\";\n\nexport interface PiSpawnOptions extends SpawnOptions {\n\t/** Pi host normalization: retain validation/provenance and raw cwd/config origins.\n\t * Presence selects this snapshot, including intentionally omitted agent/tools/cwd.\n\t * Generic callers continue to resolve their role/runtime through the adapter.\n\t */\n\tresolvedLaunch?: {\n\t\truntimePlan: ResolvedRuntimePlan;\n\t\tagent?: string;\n\t\tcwd?: string;\n\t\troleCwd?: string;\n\t\ttools?: string;\n\t};\n\t/** Preserve opaque host identities during the staged migration. Not the core task/session ID. */\n\tlaunchIdentity?: {\n\t\tid?: string;\n\t\tlogicalId?: string;\n\t\tgenerationId?: string;\n\t\ttaskId?: string;\n\t};\n}\nexport interface PiHarnessAdapterOptions {\n\tchildEntryPath?: string;\n\tsurface: SurfaceProvider;\n\tpaneConfig: PaneConfig;\n\tmodelRegistry: ModelRegistryAdapter;\n\tparent: FreshPiLaunchRequest[\"parent\"];\n\t/** Compatibility only; supervision owns its wake registry and registrations. */\n\twake?: FileWakeRegistry;\n\tsupervision: SupervisionCoordinator;\n\t/** The active parent's registry runtime can precede persisted model-change entries. */\n\tparentRuntime?: ParentRuntime;\n\t/** Optional launch-operation injection, keeping the real Pi protocol in unit tests. */\n\toperations?: PiLaunchOperations;\n\tworktreeOperations?: WorktreeOperations;\n\t/** Kernel process facts for a retained worktree child's identity; tests inject it. */\n\tprocessProbe?: ProcessIdentityProbe;\n\t/** Bound for confirming a retained worktree child's exit. Default: 5000ms. */\n\tkillTimeoutMs?: number;\n\t/** Explicit local evidence/lifecycle bridge. The host still owns delivery and deduplication. */\n\tonObservation?(\n\t\tchild: PiRunningChild,\n\t\tkind:\n\t\t\t| \"local-evidence\"\n\t\t\t| \"pane\"\n\t\t\t| \"tick\"\n\t\t\t| \"completion\"\n\t\t\t| \"state\"\n\t\t\t| \"interrupt\",\n\t): void;\n}\ninterface CompletionWait {\n\tcontroller: AbortController;\n\tpromise: Promise<CompletionEvidence>;\n\twaiters: number;\n}\n\n/** Pi's existing launch and child-sidecar protocol behind the harness seam. */\nexport class PiHarnessAdapter implements HarnessAdapter {\n\treadonly name = \"pi\";\n\tprivate readonly options: PiHarnessAdapterOptions;\n\tprivate readonly operations: PiLaunchOperations;\n\tprivate readonly children = new Map<string, PiRunningChild>();\n\tprivate readonly evidence = new Map<string, CompletionEvidence>();\n\tprivate readonly waits = new Map<string, CompletionWait>();\n\tconstructor(options: PiHarnessAdapterOptions) {\n\t\tthis.options = options;\n\t\tthis.operations =\n\t\t\toptions.operations ??\n\t\t\tlaunchOperationsFromSurface(\n\t\t\t\toptions.surface,\n\t\t\t\toptions.paneConfig,\n\t\t\t\toptions.worktreeOperations,\n\t\t\t);\n\t\tif (this.operations.nativeExecution !== options.surface.nativeExecution)\n\t\t\tthrow new Error(\n\t\t\t\t\"Pi owning provider and launch operations must use the same native execution binding\",\n\t\t\t);\n\t}\n\tisAvailable(): boolean {\n\t\treturn (process.env.PATH ?? \"\").split(delimiter).some((directory) => {\n\t\t\ttry {\n\t\t\t\tconst path = join(directory, \"pi\");\n\t\t\t\taccessSync(path, constants.X_OK);\n\t\t\t\treturn statSync(path).isFile();\n\t\t\t} catch {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t});\n\t}\n\tasync spawn(opts: PiSpawnOptions): Promise<AgentHandle> {\n\t\tthis.rejectEnvironment(opts.env);\n\t\tif (opts.worktree && !opts.worktreeRequest)\n\t\t\tthrow new Error(\n\t\t\t\t\"Pi requires an unprovisioned worktreeRequest; it owns worktree acquisition\",\n\t\t\t);\n\t\t// One ordinary attempt per spawn; the run session owns retries and their evidence.\n\t\tif (opts.worktreeRequest && opts.runtime?.fallbacks?.length)\n\t\t\tthrow new Error(\n\t\t\t\t\"Model fallbacks are not supported for worktree subagents.\",\n\t\t\t);\n\t\tif (\n\t\t\topts.session?.parentSessionId &&\n\t\t\topts.session.parentSessionId !== this.options.parent.sessionId\n\t\t)\n\t\t\tthrow new Error(\n\t\t\t\t\"Pi session parent identity does not match the launch parent\",\n\t\t\t);\n\t\tconst defaults = opts.role.defaults;\n\t\tconst persistent =\n\t\t\topts.behavior?.persistent ?? defaults?.persistent ?? false;\n\t\tconst autoExit = persistent\n\t\t\t? false\n\t\t\t: (opts.behavior?.autoExit ?? defaults?.autoExit ?? false);\n\t\tconst interactive =\n\t\t\topts.behavior?.interactive ??\n\t\t\topts.interactive ??\n\t\t\t(persistent ? false : (defaults?.interactive ?? !autoExit));\n\t\tconst acceptRefusal =\n\t\t\topts.accept && acceptLaunchRefusal({ persistent, autoExit });\n\t\tif (acceptRefusal) throw new Error(acceptRefusal);\n\t\tconst notify = opts.behavior?.notify === true;\n\t\tconst notifyRefusal = notifyLaunchRefusal({ persistent, notify });\n\t\tif (notifyRefusal) throw new Error(notifyRefusal);\n\t\tconst denied = new Set([\n\t\t\t...(defaults?.denyTools ?? []),\n\t\t\t...(opts.behavior?.denyTools ?? []),\n\t\t]);\n\t\tif (defaults?.spawning === false)\n\t\t\tfor (const name of [\n\t\t\t\t\"subagent\",\n\t\t\t\t\"subagent_interrupt\",\n\t\t\t\t\"subagent_cancel\",\n\t\t\t\t\"subagent_send\",\n\t\t\t\t\"subagent_stop\",\n\t\t\t\t\"subagents_list\",\n\t\t\t\t\"subagent_resume\",\n\t\t\t])\n\t\t\t\tdenied.add(name);\n\t\tconst resolved = opts.resolvedLaunch;\n\t\tconst cwd = resolved ? resolved.cwd : opts.cwd;\n\t\tconst roleCwd = resolved ? resolved.roleCwd : defaults?.cwd;\n\t\tconst id = opts.launchIdentity?.id ?? randomUUID();\n\t\tconst taskId = opts.launchIdentity?.taskId ?? randomUUID();\n\t\tconst child = await this.acquireChild({\n\t\t\tkind: \"fresh\",\n\t\t\tchildEntryPath: this.options.childEntryPath,\n\t\t\tacquisitionSignal: opts.acquisitionSignal,\n\t\t\tid,\n\t\t\tname: opts.name,\n\t\t\ttask: opts.task,\n\t\t\tagent: resolved ? resolved.agent : opts.role.name,\n\t\t\tcwd,\n\t\t\tworktree: opts.worktreeRequest,\n\t\t\taccept: opts.accept,\n\t\t\t// An omitted override must not force lineage-only/default fork to standalone.\n\t\t\tfork: opts.session\n\t\t\t\t? opts.session.mode === \"fork\"\n\t\t\t\t\t? true\n\t\t\t\t\t: opts.session.mode === \"standalone\"\n\t\t\t\t\t\t? false\n\t\t\t\t\t\t: undefined\n\t\t\t\t: undefined,\n\t\t\tsurface: opts.surface?.id,\n\t\t\tparent: this.options.parent,\n\t\t\truntimePlan:\n\t\t\t\tresolved?.runtimePlan ??\n\t\t\t\tresolveRuntimePlan(\n\t\t\t\t\topts.runtime ?? {},\n\t\t\t\t\tdefaults ?? {},\n\t\t\t\t\tthis.parentRuntime(opts),\n\t\t\t\t\tthis.options.modelRegistry,\n\t\t\t\t),\n\t\t\tmodelScope: this.options.modelRegistry.scope,\n\t\t\tbehavior: {\n\t\t\t\ttools: resolved\n\t\t\t\t\t? resolved.tools\n\t\t\t\t\t: (opts.tools ?? opts.role.allowedTools).join(\",\"),\n\t\t\t\tcwd: roleCwd,\n\t\t\t\tskills: (opts.behavior?.skills ?? defaults?.skills)?.join(\",\"),\n\t\t\t\tdeniedTools: [...denied],\n\t\t\t\t// `spawning: false` removes the spawning tools, so it always wins.\n\t\t\t\tselfSpawn: defaults?.selfSpawn === true && defaults.spawning !== false,\n\t\t\t\tautoExit,\n\t\t\t\tinteractive,\n\t\t\t\tpersistent,\n\t\t\t\tnotify,\n\t\t\t\tlogicalId: opts.launchIdentity?.logicalId ?? id,\n\t\t\t\tgenerationId: opts.launchIdentity?.generationId ?? randomUUID(),\n\t\t\t\ttaskId,\n\t\t\t\tidentity: opts.systemPrompt ?? opts.role.systemPrompt,\n\t\t\t\tsystemPromptMode:\n\t\t\t\t\topts.behavior?.systemPromptMode ?? defaults?.systemPromptMode,\n\t\t\t\tsessionMode:\n\t\t\t\t\topts.session?.mode ?? defaults?.sessionMode ?? \"standalone\",\n\t\t\t},\n\t\t});\n\t\t// Launch returns a fully initialized owner; no fallible I/O may separate\n\t\t// command dispatch from tracking (a rejection could start a fallback).\n\t\treturn this.track(child);\n\t}\n\tasync resume(opts: ResumeOptions): Promise<AgentHandle> {\n\t\tthis.rejectEnvironment(opts.env);\n\t\tif (opts.surface)\n\t\t\tthrow new Error(\"Pi public resume owns its new ordinary pane\");\n\t\tif (opts.tools)\n\t\t\tthrow new Error(\n\t\t\t\t\"Pi resume restores saved tools; tool overrides are not supported\",\n\t\t\t);\n\t\tconst child = await this.acquireChild({\n\t\t\tkind: \"resume\",\n\t\t\tchildEntryPath: this.options.childEntryPath,\n\t\t\tacquisitionSignal: opts.acquisitionSignal,\n\t\t\tname: opts.name,\n\t\t\tsessionFile: opts.sessionId,\n\t\t\tmessage: opts.message,\n\t\t\tparent: this.options.parent,\n\t\t\tmodelScope: this.options.modelRegistry.scope,\n\t\t\tbehavior: { autoExit: opts.autoExit },\n\t\t});\n\t\treturn this.track(child);\n\t}\n\tprivate async acquireChild(\n\t\trequest: PiLaunchRequest,\n\t): Promise<PiRunningChild> {\n\t\ttry {\n\t\t\treturn await launchPiSubagent(request, this.operations);\n\t\t} catch (error) {\n\t\t\t// The transaction transfers its fully initialized owner, not a made-up handle.\n\t\t\tif (error instanceof AcquiredPiLaunchError) return error.child;\n\t\t\tthrow error;\n\t\t}\n\t}\n\t/** Temporary Pi-specific bridge for runtime migration; never infer task delivery from coarse state. */\n\tgetRunningChild(handle: AgentHandle): PiRunningChild {\n\t\tconst child = this.children.get(handle.id);\n\t\tif (\n\t\t\t!child ||\n\t\t\thandle.harness !== this.name ||\n\t\t\thandle.sessionId !== child.sessionFile\n\t\t)\n\t\t\tthrow new Error(`Unknown Pi child ${handle.id}`);\n\t\treturn child;\n\t}\n\treadPersistentEvents(handle: AgentHandle) {\n\t\tconst child = this.getRunningChild(handle);\n\t\treturn readPersistentTaskEvents(child.sessionFile).filter(\n\t\t\t(event) => event.generation === child.generationId,\n\t\t);\n\t}\n\tasync getState(handle: AgentHandle): Promise<AgentState> {\n\t\ttry {\n\t\t\tif (handle.harness !== this.name) return \"unknown\";\n\t\t\tif (this.evidence.has(this.runKey(handle))) return \"done\";\n\t\t\tconst child = this.getRunningChild(handle);\n\t\t\tconst read = readSubagentActivityFile(child.activityFile, child.id);\n\t\t\tlet pane;\n\t\t\ttry {\n\t\t\t\tpane = await this.options.surface.inspectSurface(child.surface);\n\t\t\t} catch {\n\t\t\t\tpane = { kind: \"unavailable\" as const };\n\t\t\t}\n\t\t\tchild.lifecycle = observeActivity(\n\t\t\t\tobservePaneInspection(child.lifecycle, pane, Date.now()),\n\t\t\t\tread,\n\t\t\t\tDate.now(),\n\t\t\t);\n\t\t\tthis.options.onObservation?.(child, \"state\");\n\t\t\tif (pane.kind !== \"present\") return \"unknown\";\n\t\t\tswitch (child.lifecycle.turn.kind) {\n\t\t\t\tcase \"active\":\n\t\t\t\t\treturn \"working\";\n\t\t\t\tcase \"blocked\":\n\t\t\t\tcase \"waiting\":\n\t\t\t\t\treturn \"blocked\";\n\t\t\t\tcase \"starting\":\n\t\t\t\t\treturn \"idle\";\n\t\t\t\tdefault:\n\t\t\t\t\treturn \"unknown\";\n\t\t\t}\n\t\t} catch {\n\t\t\treturn \"unknown\";\n\t\t}\n\t}\n\tasync interrupt(handle: AgentHandle): Promise<void> {\n\t\tconst child = this.getRunningChild(handle);\n\t\tawait this.options.surface.sendKeys(child.surface, \"Escape\");\n\t\tchild.lifecycle = markInterruptRequested(child.lifecycle, Date.now());\n\t\tthis.options.onObservation?.(child, \"interrupt\");\n\t}\n\t/** Resolves only with termination evidence; otherwise rejects (unconfirmed). */\n\tasync kill(handle: AgentHandle): Promise<void> {\n\t\tconst child = this.getRunningChild(handle);\n\t\tif (this.options.surface.nativeExecution)\n\t\t\treturn this.options.surface.nativeExecution.terminate(child.surface);\n\t\t// A worktree root pane is the retained review workspace (Herdr refuses to\n\t\t// close it): stop only the owned Pi process and keep pane and checkout.\n\t\tif (child.worktree || !child.ownsSurface) return this.stopRetainedPi(child);\n\t\tlet closeError: unknown;\n\t\ttry {\n\t\t\tawait this.options.surface.closeSurface(child.surface);\n\t\t} catch (error) {\n\t\t\t// Absence is still checked: a pane that is already gone is terminated.\n\t\t\tcloseError = error;\n\t\t}\n\t\ttry {\n\t\t\tawait this.options.surface.waitForSurfaceAbsence(child.surface);\n\t\t} catch (error) {\n\t\t\tif (closeError === undefined) throw error;\n\t\t\tthrow new Error(`${errorText(closeError)}; ${errorText(error)}`);\n\t\t}\n\t}\n\t/**\n\t * Exit evidence is only the launch-verified identity (PID + start time, on\n\t * this boot and PID namespace) no longer existing, or a gone pane while that\n\t * identity is not known alive. SIGTERM goes only to that identity,\n\t * re-verified first; without it nothing is signalled and the cancel stays\n\t * unconfirmed. A failed SIGTERM to a live identity stays unconfirmed unless\n\t * that identity then exits. Herdr's foreground list and argv text are never\n\t * evidence.\n\t * Every provider await is bounded by the deadline, and a late answer is\n\t * dropped, so an unconfirmed outcome is reported on time and never flipped.\n\t */\n\tprivate async stopRetainedPi(child: PiRunningChild): Promise<void> {\n\t\tconst probe = this.options.processProbe ?? linuxProcessProbe;\n\t\tconst retainedDescription = child.worktree\n\t\t\t? \"retained worktree pane\"\n\t\t\t: \"caller-provided pane\";\n\t\tconst timeoutMs = this.options.killTimeoutMs ?? 5_000;\n\t\tconst deadline = Date.now() + timeoutMs;\n\t\tconst paneGone = async () =>\n\t\t\t(\n\t\t\t\tawait settleBefore(\n\t\t\t\t\t// Providers may throw synchronously or reject; both mean \"unknown\".\n\t\t\t\t\tPromise.resolve()\n\t\t\t\t\t\t.then(() => this.options.surface.inspectSurface(child.surface))\n\t\t\t\t\t\t.catch(() => undefined),\n\t\t\t\t\tdeadline,\n\t\t\t\t)\n\t\t\t)?.kind === \"missing\";\n\t\tlet identity = child.processIdentity;\n\t\tif (!identity) {\n\t\t\t// An expired capture gets one fresh attempt within this cancel's budget.\n\t\t\tif (child.processIdentityError !== undefined)\n\t\t\t\tstartProcessIdentityCapture(child, this.operations, {\n\t\t\t\t\ttimeoutMs: Math.max(0, deadline - Date.now()),\n\t\t\t\t});\n\t\t\t// Inspect alongside the capture wait so absence evidence is not\n\t\t\t// starved by it; the identity is re-read after the inspection.\n\t\t\tconst absence = paneGone();\n\t\t\tconst captured = await settleBefore(\n\t\t\t\tchild.processIdentityCapture,\n\t\t\t\tdeadline,\n\t\t\t);\n\t\t\tconst gone = (child.processIdentity ?? captured) ? false : await absence;\n\t\t\tidentity = child.processIdentity ?? captured;\n\t\t\tif (!identity) {\n\t\t\t\tif (gone) return;\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Owned Pi process identity was not captured for ${retainedDescription} ${child.surface}; nothing was signalled: ${child.processIdentityError ?? (child.processIdentityCapture ? \"identity capture is still pending\" : \"no identity was recorded at launch\")}`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\tlet signalled = false;\n\t\tconst verified = identity;\n\t\tconst signal = (): ProcessIdentityState => {\n\t\t\tconst before = judgeProcessIdentity(verified, probe);\n\t\t\tif (before.kind !== \"alive\") return before;\n\t\t\tconst after = terminateProcessIdentity(verified, probe);\n\t\t\tif (after.kind === \"alive\") signalled = true;\n\t\t\tif (after.kind !== \"unknown\") return after;\n\t\t\t// The identity was just known alive and the signal failed: only its\n\t\t\t// own exit confirms; pane absence never does.\n\t\t\tif (judgeProcessIdentity(verified, probe).kind === \"exited\")\n\t\t\t\treturn { kind: \"exited\" };\n\t\t\tthrow new Error(\n\t\t\t\t`Owned Pi process exit unconfirmed in ${retainedDescription} ${child.surface}: ${after.reason}; process ${verified.pid} was alive when signalled`,\n\t\t\t);\n\t\t};\n\t\tlet state = signal();\n\t\tlet paneSeenGone = false;\n\t\tfor (;;) {\n\t\t\tif (state.kind === \"exited\") return;\n\t\t\t// Unknown is never signalled and waiting cannot make it evidence.\n\t\t\tif (state.kind === \"unknown\") {\n\t\t\t\tif (!paneSeenGone && !(await paneGone())) break;\n\t\t\t\tpaneSeenGone = true;\n\t\t\t\t// The inspection awaited: confirm only while still not known alive.\n\t\t\t\tstate = judgeProcessIdentity(identity, probe);\n\t\t\t\tif (state.kind === \"alive\" && !signalled) state = signal();\n\t\t\t\tif (state.kind !== \"alive\") return;\n\t\t\t}\n\t\t\tconst remaining = deadline - Date.now();\n\t\t\tif (remaining <= 0) break;\n\t\t\tawait new Promise((resolve) =>\n\t\t\t\tsetTimeout(resolve, Math.min(50, remaining)),\n\t\t\t);\n\t\t\tstate = judgeProcessIdentity(identity, probe);\n\t\t}\n\t\tthrow new Error(\n\t\t\t`Owned Pi process exit unconfirmed in ${retainedDescription} ${child.surface}: ${describeIdentityState(identity, state, signalled, timeoutMs)}`,\n\t\t);\n\t}\n\tasync readOutput(handle: AgentHandle, lines?: number): Promise<string> {\n\t\treturn this.options.surface.readScreen(\n\t\t\tthis.getRunningChild(handle).surface,\n\t\t\tlines,\n\t\t);\n\t}\n\texitCode(handle: AgentHandle): number | undefined {\n\t\treturn this.evidence.get(this.runKey(handle))?.exitCode;\n\t}\n\tasync sendInput(handle: AgentHandle, text: string): Promise<void> {\n\t\tconst child = this.getRunningChild(handle);\n\t\tif (!child.persistent)\n\t\t\tthrow new Error(\"child is not a persistent specialist\");\n\t\tconst task = randomUUID();\n\t\tconst facts = {\n\t\t\ttask,\n\t\t\tgeneration: child.generationId!,\n\t\t\tlogicalId: child.logicalId!,\n\t\t\tpolicyHash: child.policyHash!,\n\t\t};\n\t\tif (\n\t\t\tthis.evidence.has(this.runKey(handle)) ||\n\t\t\tchild.launchFailure ||\n\t\t\tchild.stopState ||\n\t\t\tchild.taskId != null ||\n\t\t\tchild.tasksCompleted == null\n\t\t) {\n\t\t\tappendPersistentDeliveryLedger(child.sessionFile, {\n\t\t\t\t...facts,\n\t\t\t\toutcome: \"rejected-busy\",\n\t\t\t});\n\t\t\tthrow new Error(\n\t\t\t\t`Persistent specialist \"${child.name}\" is busy or stopped; task ${task} was rejected-busy. Resend after the pending result.`,\n\t\t\t);\n\t\t}\n\t\twritePersistentTaskInbox(\n\t\t\tchild.sessionFile,\n\t\t\t(child.inboxSequence = (child.inboxSequence ?? 0) + 1),\n\t\t\t{ task, message: text },\n\t\t);\n\t\tchild.taskId = task;\n\t\t(child.issuedTaskIds ??= []).push(task);\n\t\tappendPersistentDeliveryLedger(child.sessionFile, {\n\t\t\t...facts,\n\t\t\toutcome: \"dispatched\",\n\t\t});\n\t}\n\tasync awaitCompletion(\n\t\thandle: AgentHandle,\n\t\tsignal: AbortSignal,\n\t): Promise<CompletionEvidence> {\n\t\tif (signal.aborted)\n\t\t\tthrow new Error(\"Aborted while waiting for subagent to finish\");\n\t\tconst key = this.runKey(handle);\n\t\tconst recorded = this.evidence.get(key);\n\t\tif (recorded) return recorded;\n\t\tconst child = this.getRunningChild(handle);\n\t\tlet wait = this.waits.get(key);\n\t\tif (!wait || wait.controller.signal.aborted) {\n\t\t\tconst controller = new AbortController();\n\t\t\tconst registration = this.options.supervision.register(\n\t\t\t\tchild.sessionFile,\n\t\t\t\tchild.surface,\n\t\t\t);\n\t\t\tconst next: CompletionWait = {\n\t\t\t\tcontroller,\n\t\t\t\twaiters: 0,\n\t\t\t\tpromise: (async () => {\n\t\t\t\t\tif (child.launchFailure && !this.options.surface.nativeExecution) {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tawait this.kill(handle);\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\treason: \"error\" as const,\n\t\t\t\t\t\t\t\texitCode: 1,\n\t\t\t\t\t\t\t\terrorMessage: child.launchFailure,\n\t\t\t\t\t\t\t\terrorSource: \"host\" as const,\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\t/* unconfirmed: keep the actual owner supervised and controllable */\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\treturn waitForCompletion(controller.signal, {\n\t\t\t\t\t\tintervalMs: 1000,\n\t\t\t\t\t\tinspectExecution: this.options.surface.nativeExecution\n\t\t\t\t\t\t\t? () =>\n\t\t\t\t\t\t\t\t\tthis.options.surface.nativeExecution!.inspect(child.surface)\n\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\t\tsessionFile: child.sessionFile,\n\t\t\t\t\t\trequireProcessExit: child.persistent || !!child.launchFailure,\n\t\t\t\t\t\tshellExitFile: child.persistent\n\t\t\t\t\t\t\t? shellExitFileFor(child.sessionFile)\n\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\t\tinspectProcess: () =>\n\t\t\t\t\t\t\tchild.processIdentity\n\t\t\t\t\t\t\t\t? judgeProcessIdentity(\n\t\t\t\t\t\t\t\t\t\tchild.processIdentity,\n\t\t\t\t\t\t\t\t\t\tthis.options.processProbe ?? linuxProcessProbe,\n\t\t\t\t\t\t\t\t\t).kind\n\t\t\t\t\t\t\t\t: \"unknown\",\n\t\t\t\t\t\twaitForNextCheck: registration.wait,\n\t\t\t\t\t\treadTerminalTail: async () =>\n\t\t\t\t\t\t\t// A caller-provided terminal can contain an earlier run's marker.\n\t\t\t\t\t\t\tchild.launchFailure && !child.ownsSurface && !child.worktree\n\t\t\t\t\t\t\t\t? \"\"\n\t\t\t\t\t\t\t\t: this.options.surface.readScreen(child.surface, 5),\n\t\t\t\t\t\tinspectPane: registration.inspectPane,\n\t\t\t\t\t\tonLocalEvidence: () =>\n\t\t\t\t\t\t\tthis.options.onObservation?.(child, \"local-evidence\"),\n\t\t\t\t\t\tonPaneInspection: (pane, at) => {\n\t\t\t\t\t\t\tchild.lifecycle = observePaneInspection(\n\t\t\t\t\t\t\t\tchild.lifecycle,\n\t\t\t\t\t\t\t\tpane,\n\t\t\t\t\t\t\t\tat,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tthis.options.onObservation?.(child, \"pane\");\n\t\t\t\t\t\t},\n\t\t\t\t\t\tonTick: () => {\n\t\t\t\t\t\t\tthis.options.onObservation?.(child, \"tick\");\n\t\t\t\t\t\t},\n\t\t\t\t\t});\n\t\t\t\t})()\n\t\t\t\t\t.then((result) => {\n\t\t\t\t\t\tif (child.launchFailure)\n\t\t\t\t\t\t\tresult = {\n\t\t\t\t\t\t\t\t...result,\n\t\t\t\t\t\t\t\treason: \"error\",\n\t\t\t\t\t\t\t\texitCode: 1,\n\t\t\t\t\t\t\t\terrorMessage: child.launchFailure,\n\t\t\t\t\t\t\t\terrorSource: \"host\",\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\tconst final = existsSync(child.sessionFile)\n\t\t\t\t\t\t\t? inspectFinalAssistantMessage(\n\t\t\t\t\t\t\t\t\tgetNewEntries(child.sessionFile, 0),\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t: undefined;\n\t\t\t\t\t\tconst evidence: CompletionEvidence = {\n\t\t\t\t\t\t\t...result,\n\t\t\t\t\t\t\tsessionRef: child.sessionFile,\n\t\t\t\t\t\t};\n\t\t\t\t\t\tif (final && (final.text != null || final.stopReason)) {\n\t\t\t\t\t\t\tevidence.finalMessage = {\n\t\t\t\t\t\t\t\ttext: final.text ?? \"\",\n\t\t\t\t\t\t\t\tstopReason: final.stopReason,\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\tif (final.stopReason === \"error\" && result.errorMessage)\n\t\t\t\t\t\t\t\tevidence.finalMessage.errorMessage = result.errorMessage;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// RunSession finalization is the single Git handoff capture owner.\n\t\t\t\t\t\tthis.evidence.set(key, evidence);\n\t\t\t\t\t\tchild.lifecycle = markCompletionDetected(\n\t\t\t\t\t\t\tchild.lifecycle,\n\t\t\t\t\t\t\tresult,\n\t\t\t\t\t\t\tDate.now(),\n\t\t\t\t\t\t);\n\t\t\t\t\t\tthis.options.onObservation?.(child, \"completion\");\n\t\t\t\t\t\treturn evidence;\n\t\t\t\t\t})\n\t\t\t\t\t.finally(() => {\n\t\t\t\t\t\tregistration.unregister();\n\t\t\t\t\t\tif (this.waits.get(key) === next) this.waits.delete(key);\n\t\t\t\t\t}),\n\t\t\t};\n\t\t\tthis.waits.set(key, next);\n\t\t\twait = next;\n\t\t}\n\t\treturn this.joinWait(wait, signal);\n\t}\n\tprivate joinWait(\n\t\twait: CompletionWait,\n\t\tsignal: AbortSignal,\n\t): Promise<CompletionEvidence> {\n\t\twait.waiters++;\n\t\tconst abort = () =>\n\t\t\trejectWait(new Error(\"Aborted while waiting for subagent to finish\"));\n\t\tlet rejectWait!: (error: Error) => void;\n\t\treturn new Promise<CompletionEvidence>((resolve, reject) => {\n\t\t\trejectWait = reject;\n\t\t\tsignal.addEventListener(\"abort\", abort, { once: true });\n\t\t\twait.promise.then(resolve, reject);\n\t\t}).finally(() => {\n\t\t\t// Each consumer owns only its cancellation, never another consumer's wait.\n\t\t\tsignal.removeEventListener(\"abort\", abort);\n\t\t\twait.waiters--;\n\t\t\tif (wait.waiters === 0) wait.controller.abort();\n\t\t});\n\t}\n\tprivate runKey(handle: Pick<AgentHandle, \"id\" | \"sessionId\">): string {\n\t\t// Legacy fallback retries reuse the opaque child ID, but create a new Pi session.\n\t\treturn JSON.stringify([handle.id, handle.sessionId]);\n\t}\n\tprivate track(child: PiRunningChild): AgentHandle {\n\t\tthis.children.set(child.id, child);\n\t\tconst handle: AgentHandle = {\n\t\t\tid: child.id,\n\t\t\tname: child.name,\n\t\t\trole: child.agent ?? \"\",\n\t\t\tharness: this.name,\n\t\t\tcwd: child.cwd!,\n\t\t\tstartedAt: child.startTime,\n\t\t\tsessionId: child.sessionFile,\n\t\t\tsurfaceId: child.surface,\n\t\t};\n\t\tif (child.launchFailure) handle.launchFailure = child.launchFailure;\n\t\tif (child.worktree)\n\t\t\thandle.worktree = {\n\t\t\t\tid: child.id,\n\t\t\t\towner: \"maestro\",\n\t\t\t\tbranch: child.worktree.branch,\n\t\t\t\tbaseRef: child.worktree.baseRef,\n\t\t\t\tbaseSha: child.worktree.baseSha,\n\t\t\t\tcreatedAt: child.startTime,\n\t\t\t\tpath: child.worktree.path,\n\t\t\t\tstate: child.launchFailure ? \"failed\" : \"running\",\n\t\t\t\tmanifestFile: child.worktree.manifestFile,\n\t\t\t};\n\t\treturn handle;\n\t}\n\tprivate parentRuntime(opts: SpawnOptions): ParentRuntime {\n\t\tif (this.options.parentRuntime) return this.options.parentRuntime;\n\t\tconst observed = existsSync(this.options.parent.sessionFile)\n\t\t\t? findObservedSessionRuntime(\n\t\t\t\t\tgetNewEntries(this.options.parent.sessionFile, 0),\n\t\t\t\t)\n\t\t\t: {};\n\t\tif (\n\t\t\tobserved.provider &&\n\t\t\tobserved.modelId &&\n\t\t\tobserved.thinking &&\n\t\t\tisThinkingLevel(observed.thinking)\n\t\t)\n\t\t\treturn {\n\t\t\t\tprovider: observed.provider,\n\t\t\t\tmodelId: observed.modelId,\n\t\t\t\tthinking: observed.thinking,\n\t\t\t};\n\t\tconst model = parseExactModelRef(\n\t\t\topts.runtime?.model ?? opts.role.defaults?.model ?? \"\",\n\t\t);\n\t\tconst thinking = opts.runtime?.thinking ?? opts.role.defaults?.thinking;\n\t\tif (model && thinking) return { ...model, thinking };\n\t\tthrow new Error(\n\t\t\t\"Pi launch requires the active parent runtime or explicit model and thinking\",\n\t\t);\n\t}\n\tprivate rejectEnvironment(env: Record<string, string> | undefined): void {\n\t\tif (env && Object.keys(env).length)\n\t\t\tthrow new Error(\n\t\t\t\t\"The existing Pi launch protocol does not support per-child environment overrides\",\n\t\t\t);\n\t}\n}\n\nfunction errorText(cause: unknown): string {\n\treturn cause instanceof Error ? cause.message : String(cause);\n}\n\nfunction describeIdentityState(\n\tidentity: PiProcessIdentity,\n\tstate: ProcessIdentityState,\n\tsignalled: boolean,\n\ttimeoutMs: number,\n): string {\n\tif (state.kind === \"unknown\")\n\t\treturn `${state.reason}${signalled ? \" after SIGTERM\" : \"; not signalled\"}`;\n\treturn `process ${identity.pid} (start time ${identity.startTime}) is still ${state.kind} ${timeoutMs}ms after SIGTERM`;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"pi-harness-adapter.js","sourceRoot":"","sources":["../../../../maestro/adapters/pi/pi-harness-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACtE,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAY5C,OAAO,EAAE,wBAAwB,EAAE,MAAM,oBAA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OAAO,GAAG,KAAK,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,iBAAiB,EAAE,CAAC;IAC7E,OAAO,WAAW,QAAQ,CAAC,GAAG,gBAAgB,QAAQ,CAAC,SAAS,cAAc,KAAK,CAAC,IAAI,IAAI,SAAS,kBAAkB,CAAC;AACzH,CAAC","sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport { accessSync, constants, existsSync, statSync } from \"node:fs\";\nimport { delimiter, join } from \"node:path\";\nimport type {\n\tHarnessAdapter,\n\tResumeOptions,\n\tSpawnOptions,\n} from \"../../core/harness-adapter.ts\";\nimport type {\n\tAgentHandle,\n\tAgentState,\n\tCompletionEvidence,\n} from \"../../core/types.ts\";\nimport type { SurfaceProvider } from \"../../core/surface-provider.ts\";\nimport { readSubagentActivityFile } from \"./activity-file.ts\";\nimport {\n\tmarkCompletionDetected,\n\tmarkInterruptRequested,\n\tobserveActivity,\n\tobservePaneInspection,\n} from \"../../core/lifecycle.ts\";\nimport type { PaneConfig } from \"../../core/config/pane-config.ts\";\nimport {\n\tisThinkingLevel,\n\tparseExactModelRef,\n\tresolveRuntimePlan,\n\ttype ModelRegistryAdapter,\n\ttype ParentRuntime,\n\ttype ResolvedRuntimePlan,\n} from \"../../core/routing.ts\";\nimport type { FileWakeRegistry } from \"../../core/wake.ts\";\nimport type { SupervisionCoordinator } from \"../../core/supervision.ts\";\nimport {\n\tjudgeProcessIdentity,\n\tlinuxProcessProbe,\n\tterminateProcessIdentity,\n\ttype PiProcessIdentity,\n\ttype ProcessIdentityProbe,\n\ttype ProcessIdentityState,\n} from \"./process-identity.ts\";\nimport {\n\tlaunchOperationsFromSurface,\n\tsettleBefore,\n\ttype PiLaunchOperations,\n} from \"./launch-operations.ts\";\nimport {\n\tlaunchPiSubagent,\n\tAcquiredPiLaunchError,\n\ttype PiLaunchRequest,\n\tstartProcessIdentityCapture,\n\ttype FreshPiLaunchRequest,\n\ttype PiRunningChild,\n} from \"./launch.ts\";\nimport type { WorktreeOperations } from \"../../core/worktree.ts\";\nimport { shellExitFileFor, waitForCompletion } from \"./completion.ts\";\nimport { acceptLaunchRefusal } from \"../../core/accept.ts\";\nimport { notifyLaunchRefusal } from \"../../core/specialist-notice.ts\";\nimport {\n\tEXIT_OUTPUT_READ_TIMEOUT_MS,\n\tEXIT_OUTPUT_SCREEN_LINES,\n\textractExitOutput,\n\treadWithin,\n} from \"./exit-output.ts\";\nimport {\n\tappendPersistentDeliveryLedger,\n\tfindObservedSessionRuntime,\n\tgetNewEntries,\n\tinspectFinalAssistantMessage,\n\treadPersistentTaskEvents,\n\twritePersistentTaskInbox,\n} from \"./session.ts\";\n\nexport interface PiSpawnOptions extends SpawnOptions {\n\t/** Pi host normalization: retain validation/provenance and raw cwd/config origins.\n\t * Presence selects this snapshot, including intentionally omitted agent/tools/cwd.\n\t * Generic callers continue to resolve their role/runtime through the adapter.\n\t */\n\tresolvedLaunch?: {\n\t\truntimePlan: ResolvedRuntimePlan;\n\t\tagent?: string;\n\t\tcwd?: string;\n\t\troleCwd?: string;\n\t\ttools?: string;\n\t};\n\t/** Preserve opaque host identities during the staged migration. Not the core task/session ID. */\n\tlaunchIdentity?: {\n\t\tid?: string;\n\t\tlogicalId?: string;\n\t\tgenerationId?: string;\n\t\ttaskId?: string;\n\t};\n}\nexport interface PiHarnessAdapterOptions {\n\tchildEntryPath?: string;\n\tsurface: SurfaceProvider;\n\tpaneConfig: PaneConfig;\n\tmodelRegistry: ModelRegistryAdapter;\n\tparent: FreshPiLaunchRequest[\"parent\"];\n\t/** Compatibility only; supervision owns its wake registry and registrations. */\n\twake?: FileWakeRegistry;\n\tsupervision: SupervisionCoordinator;\n\t/** The active parent's registry runtime can precede persisted model-change entries. */\n\tparentRuntime?: ParentRuntime;\n\t/** Optional launch-operation injection, keeping the real Pi protocol in unit tests. */\n\toperations?: PiLaunchOperations;\n\tworktreeOperations?: WorktreeOperations;\n\t/** Kernel process facts for a retained worktree child's identity; tests inject it. */\n\tprocessProbe?: ProcessIdentityProbe;\n\t/** Bound for confirming a retained worktree child's exit. Default: 5000ms. */\n\tkillTimeoutMs?: number;\n\t/** Explicit local evidence/lifecycle bridge. The host still owns delivery and deduplication. */\n\tonObservation?(\n\t\tchild: PiRunningChild,\n\t\tkind:\n\t\t\t| \"local-evidence\"\n\t\t\t| \"pane\"\n\t\t\t| \"tick\"\n\t\t\t| \"completion\"\n\t\t\t| \"state\"\n\t\t\t| \"interrupt\",\n\t): void;\n}\ninterface CompletionWait {\n\tcontroller: AbortController;\n\tpromise: Promise<CompletionEvidence>;\n\twaiters: number;\n}\n\n/** Pi's existing launch and child-sidecar protocol behind the harness seam. */\nexport class PiHarnessAdapter implements HarnessAdapter {\n\treadonly name = \"pi\";\n\tprivate readonly options: PiHarnessAdapterOptions;\n\tprivate readonly operations: PiLaunchOperations;\n\tprivate readonly children = new Map<string, PiRunningChild>();\n\tprivate readonly evidence = new Map<string, CompletionEvidence>();\n\tprivate readonly waits = new Map<string, CompletionWait>();\n\tconstructor(options: PiHarnessAdapterOptions) {\n\t\tthis.options = options;\n\t\tthis.operations =\n\t\t\toptions.operations ??\n\t\t\tlaunchOperationsFromSurface(\n\t\t\t\toptions.surface,\n\t\t\t\toptions.paneConfig,\n\t\t\t\toptions.worktreeOperations,\n\t\t\t);\n\t\tif (this.operations.nativeExecution !== options.surface.nativeExecution)\n\t\t\tthrow new Error(\n\t\t\t\t\"Pi owning provider and launch operations must use the same native execution binding\",\n\t\t\t);\n\t}\n\tisAvailable(): boolean {\n\t\treturn (process.env.PATH ?? \"\").split(delimiter).some((directory) => {\n\t\t\ttry {\n\t\t\t\tconst path = join(directory, \"pi\");\n\t\t\t\taccessSync(path, constants.X_OK);\n\t\t\t\treturn statSync(path).isFile();\n\t\t\t} catch {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t});\n\t}\n\tasync spawn(opts: PiSpawnOptions): Promise<AgentHandle> {\n\t\tthis.rejectEnvironment(opts.env);\n\t\tif (opts.worktree && !opts.worktreeRequest)\n\t\t\tthrow new Error(\n\t\t\t\t\"Pi requires an unprovisioned worktreeRequest; it owns worktree acquisition\",\n\t\t\t);\n\t\t// One ordinary attempt per spawn; the run session owns retries and their evidence.\n\t\tif (opts.worktreeRequest && opts.runtime?.fallbacks?.length)\n\t\t\tthrow new Error(\n\t\t\t\t\"Model fallbacks are not supported for worktree subagents.\",\n\t\t\t);\n\t\tif (\n\t\t\topts.session?.parentSessionId &&\n\t\t\topts.session.parentSessionId !== this.options.parent.sessionId\n\t\t)\n\t\t\tthrow new Error(\n\t\t\t\t\"Pi session parent identity does not match the launch parent\",\n\t\t\t);\n\t\tconst defaults = opts.role.defaults;\n\t\tconst persistent =\n\t\t\topts.behavior?.persistent ?? defaults?.persistent ?? false;\n\t\tconst autoExit = persistent\n\t\t\t? false\n\t\t\t: (opts.behavior?.autoExit ?? defaults?.autoExit ?? false);\n\t\tconst interactive =\n\t\t\topts.behavior?.interactive ??\n\t\t\topts.interactive ??\n\t\t\t(persistent ? false : (defaults?.interactive ?? !autoExit));\n\t\tconst acceptRefusal =\n\t\t\topts.accept && acceptLaunchRefusal({ persistent, autoExit });\n\t\tif (acceptRefusal) throw new Error(acceptRefusal);\n\t\tconst notify = opts.behavior?.notify === true;\n\t\tconst notifyRefusal = notifyLaunchRefusal({ persistent, notify });\n\t\tif (notifyRefusal) throw new Error(notifyRefusal);\n\t\tconst denied = new Set([\n\t\t\t...(defaults?.denyTools ?? []),\n\t\t\t...(opts.behavior?.denyTools ?? []),\n\t\t]);\n\t\tif (defaults?.spawning === false)\n\t\t\tfor (const name of [\n\t\t\t\t\"subagent\",\n\t\t\t\t\"subagent_interrupt\",\n\t\t\t\t\"subagent_cancel\",\n\t\t\t\t\"subagent_send\",\n\t\t\t\t\"subagent_stop\",\n\t\t\t\t\"subagents_list\",\n\t\t\t\t\"subagent_resume\",\n\t\t\t])\n\t\t\t\tdenied.add(name);\n\t\tconst resolved = opts.resolvedLaunch;\n\t\tconst cwd = resolved ? resolved.cwd : opts.cwd;\n\t\tconst roleCwd = resolved ? resolved.roleCwd : defaults?.cwd;\n\t\tconst id = opts.launchIdentity?.id ?? randomUUID();\n\t\tconst taskId = opts.launchIdentity?.taskId ?? randomUUID();\n\t\tconst child = await this.acquireChild({\n\t\t\tkind: \"fresh\",\n\t\t\tchildEntryPath: this.options.childEntryPath,\n\t\t\tacquisitionSignal: opts.acquisitionSignal,\n\t\t\tid,\n\t\t\tname: opts.name,\n\t\t\ttask: opts.task,\n\t\t\tagent: resolved ? resolved.agent : opts.role.name,\n\t\t\tcwd,\n\t\t\tworktree: opts.worktreeRequest,\n\t\t\taccept: opts.accept,\n\t\t\t// An omitted override must not force lineage-only/default fork to standalone.\n\t\t\tfork: opts.session\n\t\t\t\t? opts.session.mode === \"fork\"\n\t\t\t\t\t? true\n\t\t\t\t\t: opts.session.mode === \"standalone\"\n\t\t\t\t\t\t? false\n\t\t\t\t\t\t: undefined\n\t\t\t\t: undefined,\n\t\t\tsurface: opts.surface?.id,\n\t\t\tparent: this.options.parent,\n\t\t\truntimePlan:\n\t\t\t\tresolved?.runtimePlan ??\n\t\t\t\tresolveRuntimePlan(\n\t\t\t\t\topts.runtime ?? {},\n\t\t\t\t\tdefaults ?? {},\n\t\t\t\t\tthis.parentRuntime(opts),\n\t\t\t\t\tthis.options.modelRegistry,\n\t\t\t\t),\n\t\t\tmodelScope: this.options.modelRegistry.scope,\n\t\t\tbehavior: {\n\t\t\t\ttools: resolved\n\t\t\t\t\t? resolved.tools\n\t\t\t\t\t: (opts.tools ?? opts.role.allowedTools).join(\",\"),\n\t\t\t\tcwd: roleCwd,\n\t\t\t\tskills: (opts.behavior?.skills ?? defaults?.skills)?.join(\",\"),\n\t\t\t\tdeniedTools: [...denied],\n\t\t\t\t// `spawning: false` removes the spawning tools, so it always wins.\n\t\t\t\tselfSpawn: defaults?.selfSpawn === true && defaults.spawning !== false,\n\t\t\t\tautoExit,\n\t\t\t\tinteractive,\n\t\t\t\tpersistent,\n\t\t\t\tnotify,\n\t\t\t\tlogicalId: opts.launchIdentity?.logicalId ?? id,\n\t\t\t\tgenerationId: opts.launchIdentity?.generationId ?? randomUUID(),\n\t\t\t\ttaskId,\n\t\t\t\tidentity: opts.systemPrompt ?? opts.role.systemPrompt,\n\t\t\t\tsystemPromptMode:\n\t\t\t\t\topts.behavior?.systemPromptMode ?? defaults?.systemPromptMode,\n\t\t\t\tsessionMode:\n\t\t\t\t\topts.session?.mode ?? defaults?.sessionMode ?? \"standalone\",\n\t\t\t},\n\t\t});\n\t\t// Launch returns a fully initialized owner; no fallible I/O may separate\n\t\t// command dispatch from tracking (a rejection could start a fallback).\n\t\treturn this.track(child);\n\t}\n\tasync resume(opts: ResumeOptions): Promise<AgentHandle> {\n\t\tthis.rejectEnvironment(opts.env);\n\t\tif (opts.surface)\n\t\t\tthrow new Error(\"Pi public resume owns its new ordinary pane\");\n\t\tif (opts.tools)\n\t\t\tthrow new Error(\n\t\t\t\t\"Pi resume restores saved tools; tool overrides are not supported\",\n\t\t\t);\n\t\tconst child = await this.acquireChild({\n\t\t\tkind: \"resume\",\n\t\t\tchildEntryPath: this.options.childEntryPath,\n\t\t\tacquisitionSignal: opts.acquisitionSignal,\n\t\t\tname: opts.name,\n\t\t\tsessionFile: opts.sessionId,\n\t\t\tmessage: opts.message,\n\t\t\tparent: this.options.parent,\n\t\t\tmodelScope: this.options.modelRegistry.scope,\n\t\t\tbehavior: { autoExit: opts.autoExit },\n\t\t});\n\t\treturn this.track(child);\n\t}\n\tprivate async acquireChild(\n\t\trequest: PiLaunchRequest,\n\t): Promise<PiRunningChild> {\n\t\ttry {\n\t\t\treturn await launchPiSubagent(request, this.operations);\n\t\t} catch (error) {\n\t\t\t// The transaction transfers its fully initialized owner, not a made-up handle.\n\t\t\tif (error instanceof AcquiredPiLaunchError) return error.child;\n\t\t\tthrow error;\n\t\t}\n\t}\n\t/** Temporary Pi-specific bridge for runtime migration; never infer task delivery from coarse state. */\n\tgetRunningChild(handle: AgentHandle): PiRunningChild {\n\t\tconst child = this.children.get(handle.id);\n\t\tif (\n\t\t\t!child ||\n\t\t\thandle.harness !== this.name ||\n\t\t\thandle.sessionId !== child.sessionFile\n\t\t)\n\t\t\tthrow new Error(`Unknown Pi child ${handle.id}`);\n\t\treturn child;\n\t}\n\treadPersistentEvents(handle: AgentHandle) {\n\t\tconst child = this.getRunningChild(handle);\n\t\treturn readPersistentTaskEvents(child.sessionFile).filter(\n\t\t\t(event) => event.generation === child.generationId,\n\t\t);\n\t}\n\tasync getState(handle: AgentHandle): Promise<AgentState> {\n\t\ttry {\n\t\t\tif (handle.harness !== this.name) return \"unknown\";\n\t\t\tif (this.evidence.has(this.runKey(handle))) return \"done\";\n\t\t\tconst child = this.getRunningChild(handle);\n\t\t\tconst read = readSubagentActivityFile(child.activityFile, child.id);\n\t\t\tlet pane;\n\t\t\ttry {\n\t\t\t\tpane = await this.options.surface.inspectSurface(child.surface);\n\t\t\t} catch {\n\t\t\t\tpane = { kind: \"unavailable\" as const };\n\t\t\t}\n\t\t\tchild.lifecycle = observeActivity(\n\t\t\t\tobservePaneInspection(child.lifecycle, pane, Date.now()),\n\t\t\t\tread,\n\t\t\t\tDate.now(),\n\t\t\t);\n\t\t\tthis.options.onObservation?.(child, \"state\");\n\t\t\tif (pane.kind !== \"present\") return \"unknown\";\n\t\t\tswitch (child.lifecycle.turn.kind) {\n\t\t\t\tcase \"active\":\n\t\t\t\t\treturn \"working\";\n\t\t\t\tcase \"blocked\":\n\t\t\t\tcase \"waiting\":\n\t\t\t\t\treturn \"blocked\";\n\t\t\t\tcase \"starting\":\n\t\t\t\t\treturn \"idle\";\n\t\t\t\tdefault:\n\t\t\t\t\treturn \"unknown\";\n\t\t\t}\n\t\t} catch {\n\t\t\treturn \"unknown\";\n\t\t}\n\t}\n\tasync interrupt(handle: AgentHandle): Promise<void> {\n\t\tconst child = this.getRunningChild(handle);\n\t\tawait this.options.surface.sendKeys(child.surface, \"Escape\");\n\t\tchild.lifecycle = markInterruptRequested(child.lifecycle, Date.now());\n\t\tthis.options.onObservation?.(child, \"interrupt\");\n\t}\n\t/** Resolves only with termination evidence; otherwise rejects (unconfirmed). */\n\tasync kill(handle: AgentHandle): Promise<void> {\n\t\tconst child = this.getRunningChild(handle);\n\t\tif (this.options.surface.nativeExecution)\n\t\t\treturn this.options.surface.nativeExecution.terminate(child.surface);\n\t\t// A worktree root pane is the retained review workspace (Herdr refuses to\n\t\t// close it): stop only the owned Pi process and keep pane and checkout.\n\t\tif (child.worktree || !child.ownsSurface) return this.stopRetainedPi(child);\n\t\tlet closeError: unknown;\n\t\ttry {\n\t\t\tawait this.options.surface.closeSurface(child.surface);\n\t\t} catch (error) {\n\t\t\t// Absence is still checked: a pane that is already gone is terminated.\n\t\t\tcloseError = error;\n\t\t}\n\t\ttry {\n\t\t\tawait this.options.surface.waitForSurfaceAbsence(child.surface);\n\t\t} catch (error) {\n\t\t\tif (closeError === undefined) throw error;\n\t\t\tthrow new Error(`${errorText(closeError)}; ${errorText(error)}`);\n\t\t}\n\t}\n\t/**\n\t * Exit evidence is only the launch-verified identity (PID + start time, on\n\t * this boot and PID namespace) no longer existing, or a gone pane while that\n\t * identity is not known alive. SIGTERM goes only to that identity,\n\t * re-verified first; without it nothing is signalled and the cancel stays\n\t * unconfirmed. A failed SIGTERM to a live identity stays unconfirmed unless\n\t * that identity then exits. Herdr's foreground list and argv text are never\n\t * evidence.\n\t * Every provider await is bounded by the deadline, and a late answer is\n\t * dropped, so an unconfirmed outcome is reported on time and never flipped.\n\t */\n\tprivate async stopRetainedPi(child: PiRunningChild): Promise<void> {\n\t\tconst probe = this.options.processProbe ?? linuxProcessProbe;\n\t\tconst retainedDescription = child.worktree\n\t\t\t? \"retained worktree pane\"\n\t\t\t: \"caller-provided pane\";\n\t\tconst timeoutMs = this.options.killTimeoutMs ?? 5_000;\n\t\tconst deadline = Date.now() + timeoutMs;\n\t\tconst paneGone = async () =>\n\t\t\t(\n\t\t\t\tawait settleBefore(\n\t\t\t\t\t// Providers may throw synchronously or reject; both mean \"unknown\".\n\t\t\t\t\tPromise.resolve()\n\t\t\t\t\t\t.then(() => this.options.surface.inspectSurface(child.surface))\n\t\t\t\t\t\t.catch(() => undefined),\n\t\t\t\t\tdeadline,\n\t\t\t\t)\n\t\t\t)?.kind === \"missing\";\n\t\tlet identity = child.processIdentity;\n\t\tif (!identity) {\n\t\t\t// An expired capture gets one fresh attempt within this cancel's budget.\n\t\t\tif (child.processIdentityError !== undefined)\n\t\t\t\tstartProcessIdentityCapture(child, this.operations, {\n\t\t\t\t\ttimeoutMs: Math.max(0, deadline - Date.now()),\n\t\t\t\t});\n\t\t\t// Inspect alongside the capture wait so absence evidence is not\n\t\t\t// starved by it; the identity is re-read after the inspection.\n\t\t\tconst absence = paneGone();\n\t\t\tconst captured = await settleBefore(\n\t\t\t\tchild.processIdentityCapture,\n\t\t\t\tdeadline,\n\t\t\t);\n\t\t\tconst gone = (child.processIdentity ?? captured) ? false : await absence;\n\t\t\tidentity = child.processIdentity ?? captured;\n\t\t\tif (!identity) {\n\t\t\t\tif (gone) return;\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Owned Pi process identity was not captured for ${retainedDescription} ${child.surface}; nothing was signalled: ${child.processIdentityError ?? (child.processIdentityCapture ? \"identity capture is still pending\" : \"no identity was recorded at launch\")}`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\tlet signalled = false;\n\t\tconst verified = identity;\n\t\tconst signal = (): ProcessIdentityState => {\n\t\t\tconst before = judgeProcessIdentity(verified, probe);\n\t\t\tif (before.kind !== \"alive\") return before;\n\t\t\tconst after = terminateProcessIdentity(verified, probe);\n\t\t\tif (after.kind === \"alive\") signalled = true;\n\t\t\tif (after.kind !== \"unknown\") return after;\n\t\t\t// The identity was just known alive and the signal failed: only its\n\t\t\t// own exit confirms; pane absence never does.\n\t\t\tif (judgeProcessIdentity(verified, probe).kind === \"exited\")\n\t\t\t\treturn { kind: \"exited\" };\n\t\t\tthrow new Error(\n\t\t\t\t`Owned Pi process exit unconfirmed in ${retainedDescription} ${child.surface}: ${after.reason}; process ${verified.pid} was alive when signalled`,\n\t\t\t);\n\t\t};\n\t\tlet state = signal();\n\t\tlet paneSeenGone = false;\n\t\tfor (;;) {\n\t\t\tif (state.kind === \"exited\") return;\n\t\t\t// Unknown is never signalled and waiting cannot make it evidence.\n\t\t\tif (state.kind === \"unknown\") {\n\t\t\t\tif (!paneSeenGone && !(await paneGone())) break;\n\t\t\t\tpaneSeenGone = true;\n\t\t\t\t// The inspection awaited: confirm only while still not known alive.\n\t\t\t\tstate = judgeProcessIdentity(identity, probe);\n\t\t\t\tif (state.kind === \"alive\" && !signalled) state = signal();\n\t\t\t\tif (state.kind !== \"alive\") return;\n\t\t\t}\n\t\t\tconst remaining = deadline - Date.now();\n\t\t\tif (remaining <= 0) break;\n\t\t\tawait new Promise((resolve) =>\n\t\t\t\tsetTimeout(resolve, Math.min(50, remaining)),\n\t\t\t);\n\t\t\tstate = judgeProcessIdentity(identity, probe);\n\t\t}\n\t\tthrow new Error(\n\t\t\t`Owned Pi process exit unconfirmed in ${retainedDescription} ${child.surface}: ${describeIdentityState(identity, state, signalled, timeoutMs)}`,\n\t\t);\n\t}\n\tasync readOutput(handle: AgentHandle, lines?: number): Promise<string> {\n\t\treturn this.options.surface.readScreen(\n\t\t\tthis.getRunningChild(handle).surface,\n\t\t\tlines,\n\t\t);\n\t}\n\texitCode(handle: AgentHandle): number | undefined {\n\t\treturn this.evidence.get(this.runKey(handle))?.exitCode;\n\t}\n\tasync sendInput(handle: AgentHandle, text: string): Promise<void> {\n\t\tconst child = this.getRunningChild(handle);\n\t\tif (!child.persistent)\n\t\t\tthrow new Error(\"child is not a persistent specialist\");\n\t\tconst task = randomUUID();\n\t\tconst facts = {\n\t\t\ttask,\n\t\t\tgeneration: child.generationId!,\n\t\t\tlogicalId: child.logicalId!,\n\t\t\tpolicyHash: child.policyHash!,\n\t\t};\n\t\tif (\n\t\t\tthis.evidence.has(this.runKey(handle)) ||\n\t\t\tchild.launchFailure ||\n\t\t\tchild.stopState ||\n\t\t\tchild.taskId != null ||\n\t\t\tchild.tasksCompleted == null\n\t\t) {\n\t\t\tappendPersistentDeliveryLedger(child.sessionFile, {\n\t\t\t\t...facts,\n\t\t\t\toutcome: \"rejected-busy\",\n\t\t\t});\n\t\t\tthrow new Error(\n\t\t\t\t`Persistent specialist \"${child.name}\" is busy or stopped; task ${task} was rejected-busy. Resend after the pending result.`,\n\t\t\t);\n\t\t}\n\t\twritePersistentTaskInbox(\n\t\t\tchild.sessionFile,\n\t\t\t(child.inboxSequence = (child.inboxSequence ?? 0) + 1),\n\t\t\t{ task, message: text },\n\t\t);\n\t\tchild.taskId = task;\n\t\t(child.issuedTaskIds ??= []).push(task);\n\t\tappendPersistentDeliveryLedger(child.sessionFile, {\n\t\t\t...facts,\n\t\t\toutcome: \"dispatched\",\n\t\t});\n\t}\n\tasync awaitCompletion(\n\t\thandle: AgentHandle,\n\t\tsignal: AbortSignal,\n\t): Promise<CompletionEvidence> {\n\t\tif (signal.aborted)\n\t\t\tthrow new Error(\"Aborted while waiting for subagent to finish\");\n\t\tconst key = this.runKey(handle);\n\t\tconst recorded = this.evidence.get(key);\n\t\tif (recorded) return recorded;\n\t\tconst child = this.getRunningChild(handle);\n\t\tlet wait = this.waits.get(key);\n\t\tif (!wait || wait.controller.signal.aborted) {\n\t\t\tconst controller = new AbortController();\n\t\t\tconst registration = this.options.supervision.register(\n\t\t\t\tchild.sessionFile,\n\t\t\t\tchild.surface,\n\t\t\t);\n\t\t\tconst next: CompletionWait = {\n\t\t\t\tcontroller,\n\t\t\t\twaiters: 0,\n\t\t\t\tpromise: (async () => {\n\t\t\t\t\tif (child.launchFailure && !this.options.surface.nativeExecution) {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tawait this.kill(handle);\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\treason: \"error\" as const,\n\t\t\t\t\t\t\t\texitCode: 1,\n\t\t\t\t\t\t\t\terrorMessage: child.launchFailure,\n\t\t\t\t\t\t\t\terrorSource: \"host\" as const,\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\t/* unconfirmed: keep the actual owner supervised and controllable */\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\treturn waitForCompletion(controller.signal, {\n\t\t\t\t\t\tintervalMs: 1000,\n\t\t\t\t\t\tinspectExecution: this.options.surface.nativeExecution\n\t\t\t\t\t\t\t? () =>\n\t\t\t\t\t\t\t\t\tthis.options.surface.nativeExecution!.inspect(child.surface)\n\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\t\tsessionFile: child.sessionFile,\n\t\t\t\t\t\trequireProcessExit: child.persistent || !!child.launchFailure,\n\t\t\t\t\t\tshellExitFile: child.persistent\n\t\t\t\t\t\t\t? shellExitFileFor(child.sessionFile)\n\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\t\tinspectProcess: () =>\n\t\t\t\t\t\t\tchild.processIdentity\n\t\t\t\t\t\t\t\t? judgeProcessIdentity(\n\t\t\t\t\t\t\t\t\t\tchild.processIdentity,\n\t\t\t\t\t\t\t\t\t\tthis.options.processProbe ?? linuxProcessProbe,\n\t\t\t\t\t\t\t\t\t).kind\n\t\t\t\t\t\t\t\t: \"unknown\",\n\t\t\t\t\t\twaitForNextCheck: registration.wait,\n\t\t\t\t\t\treadTerminalTail: async () =>\n\t\t\t\t\t\t\t// A caller-provided terminal can contain an earlier run's marker.\n\t\t\t\t\t\t\tchild.launchFailure && !child.ownsSurface && !child.worktree\n\t\t\t\t\t\t\t\t? \"\"\n\t\t\t\t\t\t\t\t: this.options.surface.readScreen(child.surface, 5),\n\t\t\t\t\t\tinspectPane: registration.inspectPane,\n\t\t\t\t\t\tonLocalEvidence: () =>\n\t\t\t\t\t\t\tthis.options.onObservation?.(child, \"local-evidence\"),\n\t\t\t\t\t\tonPaneInspection: (pane, at) => {\n\t\t\t\t\t\t\tchild.lifecycle = observePaneInspection(\n\t\t\t\t\t\t\t\tchild.lifecycle,\n\t\t\t\t\t\t\t\tpane,\n\t\t\t\t\t\t\t\tat,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tthis.options.onObservation?.(child, \"pane\");\n\t\t\t\t\t\t},\n\t\t\t\t\t\tonTick: () => {\n\t\t\t\t\t\t\tthis.options.onObservation?.(child, \"tick\");\n\t\t\t\t\t\t},\n\t\t\t\t\t});\n\t\t\t\t})()\n\t\t\t\t\t.then(async (result) => {\n\t\t\t\t\t\tif (child.launchFailure)\n\t\t\t\t\t\t\tresult = {\n\t\t\t\t\t\t\t\t...result,\n\t\t\t\t\t\t\t\treason: \"error\",\n\t\t\t\t\t\t\t\texitCode: 1,\n\t\t\t\t\t\t\t\terrorMessage: child.launchFailure,\n\t\t\t\t\t\t\t\terrorSource: \"host\",\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\tconst entries = existsSync(child.sessionFile)\n\t\t\t\t\t\t\t? getNewEntries(child.sessionFile, 0)\n\t\t\t\t\t\t\t: undefined;\n\t\t\t\t\t\tconst final = entries\n\t\t\t\t\t\t\t? inspectFinalAssistantMessage(entries)\n\t\t\t\t\t\t\t: undefined;\n\t\t\t\t\t\tconst evidence: CompletionEvidence = {\n\t\t\t\t\t\t\t...result,\n\t\t\t\t\t\t\tsessionRef: child.sessionFile,\n\t\t\t\t\t\t};\n\t\t\t\t\t\tconst exitOutput = await this.readExitOutput(\n\t\t\t\t\t\t\tchild,\n\t\t\t\t\t\t\tresult,\n\t\t\t\t\t\t\tentries,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif (exitOutput) evidence.exitOutput = exitOutput;\n\t\t\t\t\t\tif (final && (final.text != null || final.stopReason)) {\n\t\t\t\t\t\t\tevidence.finalMessage = {\n\t\t\t\t\t\t\t\ttext: final.text ?? \"\",\n\t\t\t\t\t\t\t\tstopReason: final.stopReason,\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\tif (final.stopReason === \"error\" && result.errorMessage)\n\t\t\t\t\t\t\t\tevidence.finalMessage.errorMessage = result.errorMessage;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// RunSession finalization is the single Git handoff capture owner.\n\t\t\t\t\t\tthis.evidence.set(key, evidence);\n\t\t\t\t\t\tchild.lifecycle = markCompletionDetected(\n\t\t\t\t\t\t\tchild.lifecycle,\n\t\t\t\t\t\t\tresult,\n\t\t\t\t\t\t\tDate.now(),\n\t\t\t\t\t\t);\n\t\t\t\t\t\tthis.options.onObservation?.(child, \"completion\");\n\t\t\t\t\t\treturn evidence;\n\t\t\t\t\t})\n\t\t\t\t\t.finally(() => {\n\t\t\t\t\t\tregistration.unregister();\n\t\t\t\t\t\tif (this.waits.get(key) === next) this.waits.delete(key);\n\t\t\t\t\t}),\n\t\t\t};\n\t\t\tthis.waits.set(key, next);\n\t\t\twait = next;\n\t\t}\n\t\treturn this.joinWait(wait, signal);\n\t}\n\t/**\n\t * A child that failed before its session started has no transcript to\n\t * explain it; relay the terminal's last lines instead (#149).\n\t */\n\tprivate async readExitOutput(\n\t\tchild: PiRunningChild,\n\t\tresult: { exitCode: number; errorMessage?: string },\n\t\tentries: { type?: string }[] | undefined,\n\t): Promise<string | undefined> {\n\t\tif (\n\t\t\tresult.exitCode === 0 ||\n\t\t\tresult.errorMessage ||\n\t\t\tentries?.some((entry) => entry.type === \"message\")\n\t\t)\n\t\t\treturn undefined;\n\t\t// The output only explains the failure; a terminal that cannot be read\n\t\t// in time leaves the exit code as the result.\n\t\tconst screen = await readWithin(\n\t\t\t() =>\n\t\t\t\tthis.options.surface.readScreen(\n\t\t\t\t\tchild.surface,\n\t\t\t\t\tEXIT_OUTPUT_SCREEN_LINES,\n\t\t\t\t),\n\t\t\tEXIT_OUTPUT_READ_TIMEOUT_MS,\n\t\t);\n\t\treturn screen === undefined\n\t\t\t? undefined\n\t\t\t: extractExitOutput(screen, child.launchScriptFile);\n\t}\n\tprivate joinWait(\n\t\twait: CompletionWait,\n\t\tsignal: AbortSignal,\n\t): Promise<CompletionEvidence> {\n\t\twait.waiters++;\n\t\tconst abort = () =>\n\t\t\trejectWait(new Error(\"Aborted while waiting for subagent to finish\"));\n\t\tlet rejectWait!: (error: Error) => void;\n\t\treturn new Promise<CompletionEvidence>((resolve, reject) => {\n\t\t\trejectWait = reject;\n\t\t\tsignal.addEventListener(\"abort\", abort, { once: true });\n\t\t\twait.promise.then(resolve, reject);\n\t\t}).finally(() => {\n\t\t\t// Each consumer owns only its cancellation, never another consumer's wait.\n\t\t\tsignal.removeEventListener(\"abort\", abort);\n\t\t\twait.waiters--;\n\t\t\tif (wait.waiters === 0) wait.controller.abort();\n\t\t});\n\t}\n\tprivate runKey(handle: Pick<AgentHandle, \"id\" | \"sessionId\">): string {\n\t\t// Legacy fallback retries reuse the opaque child ID, but create a new Pi session.\n\t\treturn JSON.stringify([handle.id, handle.sessionId]);\n\t}\n\tprivate track(child: PiRunningChild): AgentHandle {\n\t\tthis.children.set(child.id, child);\n\t\tconst handle: AgentHandle = {\n\t\t\tid: child.id,\n\t\t\tname: child.name,\n\t\t\trole: child.agent ?? \"\",\n\t\t\tharness: this.name,\n\t\t\tcwd: child.cwd!,\n\t\t\tstartedAt: child.startTime,\n\t\t\tsessionId: child.sessionFile,\n\t\t\tsurfaceId: child.surface,\n\t\t};\n\t\tif (child.launchFailure) handle.launchFailure = child.launchFailure;\n\t\tif (child.worktree)\n\t\t\thandle.worktree = {\n\t\t\t\tid: child.id,\n\t\t\t\towner: \"maestro\",\n\t\t\t\tbranch: child.worktree.branch,\n\t\t\t\tbaseRef: child.worktree.baseRef,\n\t\t\t\tbaseSha: child.worktree.baseSha,\n\t\t\t\tcreatedAt: child.startTime,\n\t\t\t\tpath: child.worktree.path,\n\t\t\t\tstate: child.launchFailure ? \"failed\" : \"running\",\n\t\t\t\tmanifestFile: child.worktree.manifestFile,\n\t\t\t};\n\t\treturn handle;\n\t}\n\tprivate parentRuntime(opts: SpawnOptions): ParentRuntime {\n\t\tif (this.options.parentRuntime) return this.options.parentRuntime;\n\t\tconst observed = existsSync(this.options.parent.sessionFile)\n\t\t\t? findObservedSessionRuntime(\n\t\t\t\t\tgetNewEntries(this.options.parent.sessionFile, 0),\n\t\t\t\t)\n\t\t\t: {};\n\t\tif (\n\t\t\tobserved.provider &&\n\t\t\tobserved.modelId &&\n\t\t\tobserved.thinking &&\n\t\t\tisThinkingLevel(observed.thinking)\n\t\t)\n\t\t\treturn {\n\t\t\t\tprovider: observed.provider,\n\t\t\t\tmodelId: observed.modelId,\n\t\t\t\tthinking: observed.thinking,\n\t\t\t};\n\t\tconst model = parseExactModelRef(\n\t\t\topts.runtime?.model ?? opts.role.defaults?.model ?? \"\",\n\t\t);\n\t\tconst thinking = opts.runtime?.thinking ?? opts.role.defaults?.thinking;\n\t\tif (model && thinking) return { ...model, thinking };\n\t\tthrow new Error(\n\t\t\t\"Pi launch requires the active parent runtime or explicit model and thinking\",\n\t\t);\n\t}\n\tprivate rejectEnvironment(env: Record<string, string> | undefined): void {\n\t\tif (env && Object.keys(env).length)\n\t\t\tthrow new Error(\n\t\t\t\t\"The existing Pi launch protocol does not support per-child environment overrides\",\n\t\t\t);\n\t}\n}\n\nfunction errorText(cause: unknown): string {\n\treturn cause instanceof Error ? cause.message : String(cause);\n}\n\nfunction describeIdentityState(\n\tidentity: PiProcessIdentity,\n\tstate: ProcessIdentityState,\n\tsignalled: boolean,\n\ttimeoutMs: number,\n): string {\n\tif (state.kind === \"unknown\")\n\t\treturn `${state.reason}${signalled ? \" after SIGTERM\" : \"; not signalled\"}`;\n\treturn `process ${identity.pid} (start time ${identity.startTime}) is still ${state.kind} ${timeoutMs}ms after SIGTERM`;\n}\n"]}
|
|
@@ -78,7 +78,9 @@ export declare function describeTaskModelWriteFailure(approved: PreparedTaskMode
|
|
|
78
78
|
/**
|
|
79
79
|
* Atomically replace models.tasks, category thinking and models.tasksMeta in the durable user config.
|
|
80
80
|
* `_examplePath` is retained for positional compatibility only; missing files
|
|
81
|
-
* receive the minimal
|
|
81
|
+
* receive the minimal status setting and proposed models, never an example seed.
|
|
82
|
+
* Every other top-level key of an existing file is kept, and the published file
|
|
83
|
+
* is mode 0600.
|
|
82
84
|
*
|
|
83
85
|
* Cooperating calls use an exclusive sibling lock around snapshot validation
|
|
84
86
|
* and temporary-file publication. Non-cooperating processes can unlink it, so
|
|
@@ -87,6 +89,8 @@ export declare function describeTaskModelWriteFailure(approved: PreparedTaskMode
|
|
|
87
89
|
* fail closed without waiting or breaking another owner's lock.
|
|
88
90
|
*/
|
|
89
91
|
export declare function writeTaskModelConfig(configPath: string, _examplePath: string, tasks: TaskPreferences, tasksMeta: TaskPreferencesMeta, isAuthenticatedCandidate: (candidate: string) => boolean, options?: WriteTaskModelConfigOptions): SavedTaskModelConfig;
|
|
92
|
+
/** The published config file is owner read/write only (#149). */
|
|
93
|
+
export declare const CONFIG_FILE_MODE = 384;
|
|
90
94
|
/** Sibling advisory lock path shared by every cooperating config writer. */
|
|
91
95
|
export declare function getConfigWriteLockPath(configPath: string): string;
|
|
92
96
|
//# sourceMappingURL=model-config.d.ts.map
|