@juanbenjumea/pi-agy 0.6.8 → 0.6.9
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 +7 -0
- package/README.md +3 -1
- package/extensions/lib/cli.ts +30 -3
- package/extensions/lib/stream.ts +33 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.6.9
|
|
4
|
+
|
|
5
|
+
- Fail closed on agy terminal result statuses: only `SUCCESS` and `OK` are accepted when a status is present. `ERROR`, `FAILURE`, `CANCELLED`, `TIMEOUT`, empty, malformed, and unknown statuses now reject even when agy includes `response: ""` and exits with code 0.
|
|
6
|
+
- Preserve terminal status/error metadata from both stream-json result events and top-level JSON envelopes. Failed status takes precedence over response completeness and delivered-result cancellation handling, while status-absent legacy output remains compatible.
|
|
7
|
+
- Keep terminal diagnostics bounded and control-safe, append bounded stderr so canonical `AGY_ERROR` retryability remains available, and retain conversation IDs on failure for resumable recovery.
|
|
8
|
+
- Add nested/top-level, `SUCCESS`/`OK`, failed/unknown/empty/malformed, exit-zero, and conversation-continuity regression coverage.
|
|
9
|
+
|
|
3
10
|
## 0.6.8
|
|
4
11
|
|
|
5
12
|
- Keep agy's internal `--print-timeout` five seconds behind Pi's hard parent deadline. agy 1.1.28+ returns partial output with exit code 0 when its own timeout fires, so Pi must win the race to classify the run as timed out and preserve resumable-conversation guidance.
|
package/README.md
CHANGED
|
@@ -44,7 +44,9 @@ waits, preflight probes, and post-run summaries all count against it. When
|
|
|
44
44
|
it fires, the full agy process group is killed so nested tools cannot
|
|
45
45
|
outlive the run. agy's own `--print-timeout` is set five seconds later because
|
|
46
46
|
agy 1.1.28+ returns partial output with exit code 0 when that internal timer
|
|
47
|
-
fires; Pi therefore remains the authoritative timeout owner.
|
|
47
|
+
fires; Pi therefore remains the authoritative timeout owner. Terminal result
|
|
48
|
+
envelopes also fail closed: when agy supplies a status, only `SUCCESS` and `OK`
|
|
49
|
+
are accepted, even if a failed result carries an empty response and exits 0.
|
|
48
50
|
|
|
49
51
|
Active tool updates show bounded intent (for example a tool action or async
|
|
50
52
|
threshold) but never echo full command lines, which may contain secrets.
|
package/extensions/lib/cli.ts
CHANGED
|
@@ -1164,9 +1164,18 @@ function spawnAgyInternal(
|
|
|
1164
1164
|
runResult = processStreamLine(lineBuffer, runResult, onProgress);
|
|
1165
1165
|
}
|
|
1166
1166
|
|
|
1167
|
-
//
|
|
1168
|
-
//
|
|
1169
|
-
//
|
|
1167
|
+
// Terminal status is authoritative when present. agy can emit an
|
|
1168
|
+
// ERROR envelope with response: "" and even exit 0; response
|
|
1169
|
+
// completeness must never turn that failed turn into success.
|
|
1170
|
+
const terminalFailure = terminalFailureMessage(runResult, err);
|
|
1171
|
+
if (terminalFailure) {
|
|
1172
|
+
reject(withConversationId(terminalFailure, runResult));
|
|
1173
|
+
return;
|
|
1174
|
+
}
|
|
1175
|
+
|
|
1176
|
+
// A fully delivered successful result outranks the kill: when
|
|
1177
|
+
// cancellation or timeout lands after the response arrived, the work
|
|
1178
|
+
// is done and the response must not be discarded.
|
|
1170
1179
|
if (runResult.response_complete) {
|
|
1171
1180
|
resolve(finalizeRunResult(out, runResult));
|
|
1172
1181
|
return;
|
|
@@ -1202,6 +1211,24 @@ function spawnAgyInternal(
|
|
|
1202
1211
|
});
|
|
1203
1212
|
}
|
|
1204
1213
|
|
|
1214
|
+
const SUCCESSFUL_TERMINAL_STATUSES = new Set(["SUCCESS", "OK"]);
|
|
1215
|
+
|
|
1216
|
+
function terminalFailureMessage(runResult: AgyRunResult, stderr: string): string | undefined {
|
|
1217
|
+
if (runResult.terminal_status === undefined) return undefined;
|
|
1218
|
+
const status = runResult.terminal_status
|
|
1219
|
+
.trim()
|
|
1220
|
+
.replace(/[\u0000-\u001f\u007f-\u009f]/g, "")
|
|
1221
|
+
.slice(0, 64);
|
|
1222
|
+
if (SUCCESSFUL_TERMINAL_STATUSES.has(status.toUpperCase())) return undefined;
|
|
1223
|
+
|
|
1224
|
+
const detail = runResult.terminal_error?.trim();
|
|
1225
|
+
let message = `agy reported terminal status ${status || "(empty)"}`;
|
|
1226
|
+
if (detail) message += `: ${detail}`;
|
|
1227
|
+
const stderrDetail = stderr.trim().slice(0, 2_000);
|
|
1228
|
+
if (stderrDetail && !message.includes(stderrDetail)) message += `\n${stderrDetail}`;
|
|
1229
|
+
return message;
|
|
1230
|
+
}
|
|
1231
|
+
|
|
1205
1232
|
function withConversationId(message: string, runResult: AgyRunResult): Error {
|
|
1206
1233
|
const error = new Error(message) as Error & { conversation_id?: string };
|
|
1207
1234
|
if (runResult.conversation_id) error.conversation_id = runResult.conversation_id;
|
package/extensions/lib/stream.ts
CHANGED
|
@@ -39,7 +39,9 @@ export interface AgyStreamLine {
|
|
|
39
39
|
* Top-level `--output-format json` envelope fields — that mode emits one
|
|
40
40
|
* record without a result event, so the fields are honored directly.
|
|
41
41
|
*/
|
|
42
|
+
status?: string;
|
|
42
43
|
response?: string;
|
|
44
|
+
error?: string;
|
|
43
45
|
duration_seconds?: number;
|
|
44
46
|
usage?: AgyUsage;
|
|
45
47
|
init?: { model?: string; cwd?: string };
|
|
@@ -48,6 +50,7 @@ export interface AgyStreamLine {
|
|
|
48
50
|
conversation_id?: string;
|
|
49
51
|
status?: string;
|
|
50
52
|
response?: string;
|
|
53
|
+
error?: string;
|
|
51
54
|
duration_seconds?: number;
|
|
52
55
|
usage?: AgyUsage;
|
|
53
56
|
};
|
|
@@ -57,6 +60,10 @@ export interface AgyRunResult {
|
|
|
57
60
|
response: string;
|
|
58
61
|
/** Internal marker distinguishing a valid empty response from no response. */
|
|
59
62
|
response_complete?: boolean;
|
|
63
|
+
/** Authoritative terminal status when agy supplied one. */
|
|
64
|
+
terminal_status?: string;
|
|
65
|
+
/** Bounded terminal error detail from the result envelope. */
|
|
66
|
+
terminal_error?: string;
|
|
60
67
|
conversation_id?: string;
|
|
61
68
|
usage?: AgyUsage;
|
|
62
69
|
duration_seconds?: number;
|
|
@@ -209,6 +216,12 @@ function capResponse(response: string): string {
|
|
|
209
216
|
: response;
|
|
210
217
|
}
|
|
211
218
|
|
|
219
|
+
function capTerminalError(error: string): string {
|
|
220
|
+
return stripTerminalSequences(error)
|
|
221
|
+
.replace(/[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f-\u009f]/g, " ")
|
|
222
|
+
.slice(0, 2_000);
|
|
223
|
+
}
|
|
224
|
+
|
|
212
225
|
export function accumulateRunResult(parsed: AgyStreamLine, current: AgyRunResult): AgyRunResult {
|
|
213
226
|
const next = { ...current };
|
|
214
227
|
|
|
@@ -217,10 +230,14 @@ export function accumulateRunResult(parsed: AgyStreamLine, current: AgyRunResult
|
|
|
217
230
|
// `--output-format json` produces one record with top-level envelope
|
|
218
231
|
// fields; honor them so non-streaming payloads of any size accumulate
|
|
219
232
|
// in-stream instead of falling back to the bounded raw capture.
|
|
233
|
+
if (Object.hasOwn(parsed, "status")) {
|
|
234
|
+
next.terminal_status = typeof parsed.status === "string" ? parsed.status : "(invalid)";
|
|
235
|
+
}
|
|
220
236
|
if (typeof parsed.response === "string") {
|
|
221
237
|
next.response = capResponse(parsed.response);
|
|
222
238
|
next.response_complete = true;
|
|
223
239
|
}
|
|
240
|
+
if (typeof parsed.error === "string") next.terminal_error = capTerminalError(parsed.error);
|
|
224
241
|
if (typeof parsed.duration_seconds === "number" && Number.isFinite(parsed.duration_seconds)) {
|
|
225
242
|
next.duration_seconds = parsed.duration_seconds;
|
|
226
243
|
}
|
|
@@ -236,10 +253,17 @@ export function accumulateRunResult(parsed: AgyStreamLine, current: AgyRunResult
|
|
|
236
253
|
if (typeof parsed.result.conversation_id === "string") {
|
|
237
254
|
next.conversation_id = parsed.result.conversation_id;
|
|
238
255
|
}
|
|
256
|
+
if (Object.hasOwn(parsed.result, "status")) {
|
|
257
|
+
next.terminal_status =
|
|
258
|
+
typeof parsed.result.status === "string" ? parsed.result.status : "(invalid)";
|
|
259
|
+
}
|
|
239
260
|
if (typeof parsed.result.response === "string") {
|
|
240
261
|
next.response = capResponse(parsed.result.response);
|
|
241
262
|
next.response_complete = true;
|
|
242
263
|
}
|
|
264
|
+
if (typeof parsed.result.error === "string") {
|
|
265
|
+
next.terminal_error = capTerminalError(parsed.result.error);
|
|
266
|
+
}
|
|
243
267
|
if (typeof parsed.result.usage === "object" && parsed.result.usage !== null) {
|
|
244
268
|
next.usage = parsed.result.usage;
|
|
245
269
|
}
|
|
@@ -287,11 +311,19 @@ function mergeJsonEnvelope(parsed: unknown, current: AgyRunResult): AgyRunResult
|
|
|
287
311
|
next.conversation_id = record.conversation_id;
|
|
288
312
|
found = true;
|
|
289
313
|
}
|
|
314
|
+
if (Object.hasOwn(record, "status")) {
|
|
315
|
+
next.terminal_status = typeof record.status === "string" ? record.status : "(invalid)";
|
|
316
|
+
found = true;
|
|
317
|
+
}
|
|
290
318
|
if (typeof record.response === "string") {
|
|
291
|
-
next.response = record.response;
|
|
319
|
+
next.response = capResponse(record.response);
|
|
292
320
|
next.response_complete = true;
|
|
293
321
|
found = true;
|
|
294
322
|
}
|
|
323
|
+
if (typeof record.error === "string") {
|
|
324
|
+
next.terminal_error = capTerminalError(record.error);
|
|
325
|
+
found = true;
|
|
326
|
+
}
|
|
295
327
|
if (typeof record.duration_seconds === "number") {
|
|
296
328
|
next.duration_seconds = record.duration_seconds;
|
|
297
329
|
found = true;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@juanbenjumea/pi-agy",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.9",
|
|
4
4
|
"description": "Reliable Antigravity delegation for Pi — quota-aware runs, resumable tasks, repo verification, cancellation, and trustworthy diff summaries.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|