@juanbenjumea/pi-agy 0.5.2 → 0.5.4

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 CHANGED
@@ -1,5 +1,18 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.5.4
4
+
5
+ - 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.
6
+ - 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.
7
+ - Raise the raw stdout capture bound from 64 KB to 1 MB so plain-text fallbacks rarely truncate.
8
+ - Split rename/copy porcelain paths at the last ` -> ` (paths may themselves contain arrows), preserving git quoting verbatim so entries match `diff --name-only`.
9
+ - Extract `parsePorcelainStatus` as a testable unit; move fake-agy payloads from argv to a file so tests can exceed the ~128 KB argv cap.
10
+
11
+ ## 0.5.3
12
+
13
+ - 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.
14
+ - Extend the fake-agy test harness with a hang-after-output mode to reproduce hangs that start after a conversation id was emitted.
15
+
3
16
  ## 0.5.2
4
17
 
5
18
  - Deliver large streamed result records intact: the per-record bound now fits a maximum-size response (1M chars with worst-case JSON escaping) instead of discarding records over 256 KB mid-stream.
@@ -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 used as the non-streaming fallback — the
87
- // stream-json path accumulates results incrementally and is not capped by it.
88
- const MAX_CAPTURE_BYTES = 64 * 1024;
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;
@@ -237,7 +237,16 @@ export async function executeAgyTask(
237
237
  const conversationId = getAgyConversationId(error);
238
238
  if (conversationId) {
239
239
  try {
240
- await saveSession(options.dir, conversationId, effectiveModel, abortSignal);
240
+ // The composed signal is aborted in exactly the cases this save
241
+ // exists for (timeout, cancellation), and every store guard refuses
242
+ // an aborted signal — so persist under a fresh bounded deadline to
243
+ // keep the conversation resumable after the failure.
244
+ await saveSession(
245
+ options.dir,
246
+ conversationId,
247
+ effectiveModel,
248
+ AbortSignal.timeout(10_000),
249
+ );
241
250
  } catch {
242
251
  // Preserve the original agy failure; session persistence is best effort.
243
252
  }
@@ -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
- const dirtyFiles = new Set<string>();
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 };
@@ -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.2",
3
+ "version": "0.5.4",
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",