@juanbenjumea/pi-agy 0.5.3 → 0.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/extensions/lib/cli.ts +12 -3
- package/extensions/lib/execute.ts +21 -8
- package/extensions/lib/postflight.ts +31 -23
- package/extensions/lib/stream.ts +28 -4
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.5.5
|
|
4
|
+
|
|
5
|
+
- Preserve completed responses past the deadline: a result that fully arrived before cancellation or timeout is returned with an explanatory note instead of being discarded — previously a kill landing between delivery and process exit threw the finished response away.
|
|
6
|
+
- Post-run steps cut short by the deadline (diff summary) are skipped with a note instead of failing the whole run after agy already finished.
|
|
7
|
+
- Persist the conversation under a fresh bounded signal on the success path too, so a save racing the deadline still records the resumable id.
|
|
8
|
+
|
|
9
|
+
## 0.5.4
|
|
10
|
+
|
|
11
|
+
- Fix pre-existing unstaged modifications being misattributed to agy: porcelain paths are now parsed by fixed column — `line.trim()` before `slice(3)` ate the path's first character for ` M` lines, so unstaged dirt never matched `diff --name-only` and always looked newly-dirty. Found by the agy plan-mode cross-review.
|
|
12
|
+
- Honor top-level `--output-format json` envelope fields in-stream so non-streaming responses of any size accumulate fully instead of relying on the bounded raw capture.
|
|
13
|
+
- Raise the raw stdout capture bound from 64 KB to 1 MB so plain-text fallbacks rarely truncate.
|
|
14
|
+
- Split rename/copy porcelain paths at the last ` -> ` (paths may themselves contain arrows), preserving git quoting verbatim so entries match `diff --name-only`.
|
|
15
|
+
- Extract `parsePorcelainStatus` as a testable unit; move fake-agy payloads from argv to a file so tests can exceed the ~128 KB argv cap.
|
|
16
|
+
|
|
3
17
|
## 0.5.3
|
|
4
18
|
|
|
5
19
|
- Persist timed-out or cancelled conversations so they stay resumable: the failure-path session save passed the already-aborted signal to the session store, whose lock guards reject it, making conversation continuity on timeout/cancel silently dead code. Found by dogfooding a real agy run.
|
package/extensions/lib/cli.ts
CHANGED
|
@@ -83,9 +83,10 @@ export interface AgyOptions {
|
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
const PREFLIGHT_TIMEOUT_MS = 10_000;
|
|
86
|
-
// Raw stdout capture bound; only
|
|
87
|
-
// stream-json path accumulates results incrementally and is not capped by
|
|
88
|
-
|
|
86
|
+
// Raw stdout capture bound; only the non-streaming/parse-failure fallback —
|
|
87
|
+
// the stream-json path accumulates results incrementally and is not capped by
|
|
88
|
+
// it. Large enough that plain-text fallbacks rarely truncate.
|
|
89
|
+
const MAX_CAPTURE_BYTES = 1024 * 1024;
|
|
89
90
|
// Preview/experimental model ids must never win catalog resolution implicitly.
|
|
90
91
|
const UNSTABLE_MODEL_PATTERN =
|
|
91
92
|
/(?:^|[-_.])(?:preview|experimental|beta|alpha|rc\d*|snapshot|next)(?:$|[-_.])/i;
|
|
@@ -1008,6 +1009,14 @@ function spawnAgyInternal(
|
|
|
1008
1009
|
runResult = processStreamLine(lineBuffer, runResult, onProgress);
|
|
1009
1010
|
}
|
|
1010
1011
|
|
|
1012
|
+
// A fully delivered result outranks the kill: when cancellation or
|
|
1013
|
+
// timeout lands after the response arrived, the work is done and the
|
|
1014
|
+
// response must not be discarded.
|
|
1015
|
+
if (runResult.response_complete) {
|
|
1016
|
+
resolve(finalizeRunResult(out, runResult));
|
|
1017
|
+
return;
|
|
1018
|
+
}
|
|
1019
|
+
|
|
1011
1020
|
if (sig === "SIGTERM" || sig === "SIGKILL" || code === null) {
|
|
1012
1021
|
reject(
|
|
1013
1022
|
withConversationId(
|
|
@@ -185,13 +185,19 @@ export async function executeAgyTask(
|
|
|
185
185
|
|
|
186
186
|
if (run.conversation_id) {
|
|
187
187
|
try {
|
|
188
|
-
|
|
188
|
+
// Fresh bounded signal: the composed one may already be aborted
|
|
189
|
+
// when the run finished at the deadline edge (see below).
|
|
190
|
+
await saveSession(
|
|
191
|
+
options.dir,
|
|
192
|
+
run.conversation_id,
|
|
193
|
+
effectiveModel,
|
|
194
|
+
AbortSignal.timeout(10_000),
|
|
195
|
+
);
|
|
189
196
|
} catch (error) {
|
|
190
197
|
const reason = error instanceof Error ? error.message : String(error);
|
|
191
198
|
onProgress?.(`agy: warning — could not persist session: ${reason}`);
|
|
192
199
|
}
|
|
193
200
|
}
|
|
194
|
-
remainingBudget(startedAt, options.timeout_ms);
|
|
195
201
|
|
|
196
202
|
let text = run.response;
|
|
197
203
|
const quotaSummary = quota?.models.length
|
|
@@ -200,16 +206,23 @@ export async function executeAgyTask(
|
|
|
200
206
|
if (quotaSummary) text = `${text}\n\n## agy quota snapshot\n${quotaSummary}`;
|
|
201
207
|
let changedFiles: string[] | undefined;
|
|
202
208
|
let preexistingFiles: string[] | undefined;
|
|
209
|
+
// The agy run itself is complete; from here, an expiring budget or a
|
|
210
|
+
// racing cancellation must never discard its response. Skip the
|
|
211
|
+
// post-run steps with a note instead of throwing the result away.
|
|
203
212
|
if (options.mode === "accept-edits") {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
213
|
+
try {
|
|
214
|
+
const diff = await summarizeGitDiffSince(baseline, options.dir, abortSignal);
|
|
215
|
+
if (diff.summary) text = `${text}\n\n${diff.summary}`;
|
|
216
|
+
changedFiles = diff.newFiles;
|
|
217
|
+
preexistingFiles = diff.preexistingFiles;
|
|
218
|
+
} catch (error) {
|
|
219
|
+
if (!abortSignal.aborted) throw error;
|
|
220
|
+
text += "\n\n(diff summary skipped: the run reached its deadline as agy finished)";
|
|
221
|
+
}
|
|
208
222
|
}
|
|
209
223
|
if (abortSignal.aborted) {
|
|
210
|
-
|
|
224
|
+
text += `\n\nagy finished as the run was ${signal?.aborted ? "cancelled" : "timing out"}; the completed result is preserved.`;
|
|
211
225
|
}
|
|
212
|
-
remainingBudget(startedAt, options.timeout_ms);
|
|
213
226
|
|
|
214
227
|
return {
|
|
215
228
|
text,
|
|
@@ -12,6 +12,36 @@ export interface GitBaseline {
|
|
|
12
12
|
unavailable: boolean;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
/** Parse `git status --porcelain` v1 output into the set of dirty paths. */
|
|
16
|
+
export function parsePorcelainStatus(stdout: string): Set<string> {
|
|
17
|
+
const dirtyFiles = new Set<string>();
|
|
18
|
+
for (const line of stdout.split("\n")) {
|
|
19
|
+
if (!line.trim()) continue;
|
|
20
|
+
// Porcelain v1: `XY <path>` — two fixed status columns, one space, path.
|
|
21
|
+
// Never trim before slicing: unstaged statuses (` M`) carry meaning in
|
|
22
|
+
// the leading space, and trim-then-slice(3) eats the path's first char.
|
|
23
|
+
const status = line.slice(0, 2);
|
|
24
|
+
const file = line.slice(3).trim();
|
|
25
|
+
if (!file) continue;
|
|
26
|
+
// Rename/copy entries print `ORIG -> NEW` while `diff --name-only`
|
|
27
|
+
// reports only NEW, so record both sides — otherwise a pre-existing
|
|
28
|
+
// rename looks newly-dirty after the run and is misattributed to agy.
|
|
29
|
+
// Split at the LAST arrow (paths may contain " -> ") and keep git's
|
|
30
|
+
// C-quoting verbatim so entries match `diff --name-only` output.
|
|
31
|
+
const isRenameOrCopy = status.includes("R") || status.includes("C");
|
|
32
|
+
const arrow = isRenameOrCopy ? file.lastIndexOf(" -> ") : -1;
|
|
33
|
+
if (arrow !== -1) {
|
|
34
|
+
const orig = file.slice(0, arrow).trim();
|
|
35
|
+
const renamed = file.slice(arrow + " -> ".length).trim();
|
|
36
|
+
if (orig) dirtyFiles.add(orig);
|
|
37
|
+
if (renamed) dirtyFiles.add(renamed);
|
|
38
|
+
} else {
|
|
39
|
+
dirtyFiles.add(file);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return dirtyFiles;
|
|
43
|
+
}
|
|
44
|
+
|
|
15
45
|
/** Capture dirty state before accept-edits so the summary can attribute only new changes to agy. */
|
|
16
46
|
export async function captureGitBaseline(cwd: string, signal?: AbortSignal): Promise<GitBaseline> {
|
|
17
47
|
try {
|
|
@@ -21,29 +51,7 @@ export async function captureGitBaseline(cwd: string, signal?: AbortSignal): Pro
|
|
|
21
51
|
signal,
|
|
22
52
|
timeout: 10_000,
|
|
23
53
|
});
|
|
24
|
-
|
|
25
|
-
for (const line of stdout.split("\n")) {
|
|
26
|
-
const trimmed = line.trim();
|
|
27
|
-
if (!trimmed) continue;
|
|
28
|
-
// Porcelain v1: XY <path>[ -> <orig>]. Rename/copy entries print
|
|
29
|
-
// `ORIG -> NEW` while `diff --name-only` reports only NEW, so record
|
|
30
|
-
// both sides — otherwise a pre-existing rename looks newly-dirty
|
|
31
|
-
// after the run and is misattributed to agy.
|
|
32
|
-
const status = trimmed.slice(0, 2);
|
|
33
|
-
const file = trimmed.slice(3).trim();
|
|
34
|
-
if (!file) continue;
|
|
35
|
-
const isRenameOrCopy = status.includes("R") || status.includes("C");
|
|
36
|
-
const arrow = file.indexOf(" -> ");
|
|
37
|
-
if (isRenameOrCopy && arrow !== -1) {
|
|
38
|
-
const orig = file.slice(0, arrow).trim();
|
|
39
|
-
const renamed = file.slice(arrow + " -> ".length).trim();
|
|
40
|
-
if (orig) dirtyFiles.add(orig);
|
|
41
|
-
if (renamed) dirtyFiles.add(renamed);
|
|
42
|
-
} else {
|
|
43
|
-
dirtyFiles.add(file);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return { dirtyFiles, unavailable: false };
|
|
54
|
+
return { dirtyFiles: parsePorcelainStatus(stdout), unavailable: false };
|
|
47
55
|
} catch {
|
|
48
56
|
if (signal?.aborted) throw new Error("agy was cancelled");
|
|
49
57
|
return { dirtyFiles: new Set(), unavailable: true };
|
package/extensions/lib/stream.ts
CHANGED
|
@@ -24,6 +24,13 @@ export interface AgyStepUpdate {
|
|
|
24
24
|
export interface AgyStreamLine {
|
|
25
25
|
event?: string;
|
|
26
26
|
conversation_id?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Top-level `--output-format json` envelope fields — that mode emits one
|
|
29
|
+
* record without a result event, so the fields are honored directly.
|
|
30
|
+
*/
|
|
31
|
+
response?: string;
|
|
32
|
+
duration_seconds?: number;
|
|
33
|
+
usage?: AgyUsage;
|
|
27
34
|
init?: { model?: string; cwd?: string };
|
|
28
35
|
step_update?: AgyStepUpdate;
|
|
29
36
|
result?: {
|
|
@@ -146,11 +153,31 @@ export function appendStreamChunk(
|
|
|
146
153
|
return { lines, lineBuffer: remainder };
|
|
147
154
|
}
|
|
148
155
|
|
|
156
|
+
function capResponse(response: string): string {
|
|
157
|
+
return response.length > MAX_RESPONSE_CHARS
|
|
158
|
+
? response.slice(0, MAX_RESPONSE_CHARS) + "\n\n(response truncated)"
|
|
159
|
+
: response;
|
|
160
|
+
}
|
|
161
|
+
|
|
149
162
|
export function accumulateRunResult(parsed: AgyStreamLine, current: AgyRunResult): AgyRunResult {
|
|
150
163
|
const next = { ...current };
|
|
151
164
|
|
|
152
165
|
if (typeof parsed.conversation_id === "string") next.conversation_id = parsed.conversation_id;
|
|
153
166
|
|
|
167
|
+
// `--output-format json` produces one record with top-level envelope
|
|
168
|
+
// fields; honor them so non-streaming payloads of any size accumulate
|
|
169
|
+
// in-stream instead of falling back to the bounded raw capture.
|
|
170
|
+
if (typeof parsed.response === "string") {
|
|
171
|
+
next.response = capResponse(parsed.response);
|
|
172
|
+
next.response_complete = true;
|
|
173
|
+
}
|
|
174
|
+
if (typeof parsed.duration_seconds === "number" && Number.isFinite(parsed.duration_seconds)) {
|
|
175
|
+
next.duration_seconds = parsed.duration_seconds;
|
|
176
|
+
}
|
|
177
|
+
if (typeof parsed.usage === "object" && parsed.usage !== null) {
|
|
178
|
+
next.usage = parsed.usage;
|
|
179
|
+
}
|
|
180
|
+
|
|
154
181
|
const step = parsed.step_update;
|
|
155
182
|
if (typeof step?.conversation_id === "string") next.conversation_id = step.conversation_id;
|
|
156
183
|
|
|
@@ -159,10 +186,7 @@ export function accumulateRunResult(parsed: AgyStreamLine, current: AgyRunResult
|
|
|
159
186
|
next.conversation_id = parsed.result.conversation_id;
|
|
160
187
|
}
|
|
161
188
|
if (typeof parsed.result.response === "string") {
|
|
162
|
-
next.response =
|
|
163
|
-
parsed.result.response.length > MAX_RESPONSE_CHARS
|
|
164
|
-
? parsed.result.response.slice(0, MAX_RESPONSE_CHARS) + "\n\n(response truncated)"
|
|
165
|
-
: parsed.result.response;
|
|
189
|
+
next.response = capResponse(parsed.result.response);
|
|
166
190
|
next.response_complete = true;
|
|
167
191
|
}
|
|
168
192
|
if (typeof parsed.result.usage === "object" && parsed.result.usage !== null) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@juanbenjumea/pi-agy",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.5",
|
|
4
4
|
"description": "Enhanced Antigravity CLI (agy) bridge for Pi — streaming progress, conversation continuity, repo-aware verify, and diff summaries.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|