@juanbenjumea/pi-agy 0.6.9 → 0.6.11

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.6.11
4
+
5
+ - Parse agy 1.1.27+ `denied_actions` from nested stream results and top-level JSON envelopes, sanitizing, deduplicating, and bounding the untrusted action metadata.
6
+ - Reject `SUCCESS` envelopes that contain denied actions but no response instead of reporting a silent empty success; preserve the conversation id so the interrupted delegation remains resumable.
7
+ - Preserve explanatory responses that accompany denied actions while adding a visible model-facing warning, structured details, and non-duplicated native tool/receipt rendering.
8
+ - Document headless permission-denial behavior and add parser, execution, bounds, sanitization, and rendering regressions. Independent review found zero blockers; the full 204-test gate passes.
9
+
10
+ ## 0.6.10
11
+
12
+ - Validate terminal status only after finalizing the complete captured result, so pretty-printed top-level JSON errors cannot bypass 0.6.9's fail-closed status handling.
13
+ - Recover one bounded trailing root JSON envelope after earlier lifecycle or diagnostic records, preserving terminal status, error, and conversation identity before cancellation, exit-code, or completed-response precedence is decided.
14
+ - Add compact and multiline top-level error regression coverage; independent review found zero blockers and the full 201-test gate passes.
15
+
3
16
  ## 0.6.9
4
17
 
5
18
  - 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.
package/README.md CHANGED
@@ -184,7 +184,9 @@ Optional `$PI_CODING_AGENT_DIR/agy-config.json` (default
184
184
  - `skipPermissions` (default `true`) — pass `--dangerously-skip-permissions`
185
185
  for `accept-edits` runs. Set `false` to leave agy's own permission checks in
186
186
  place; note print mode has no interactive approval path, so restricted
187
- operations may fail instead of prompting.
187
+ operations may be reported as `denied_actions` instead of prompting. The
188
+ extension rejects a denied run with no response and visibly warns when agy
189
+ returns an explanatory response alongside denied actions.
188
190
  - `defaultModel` — alias used when `agy_execute` omits `model`/`tier`.
189
191
  - `defaultModelCommand` — shell command whose stdout sets the default alias
190
192
  when `defaultModel` is unset (an explicit `defaultModel` always wins).
@@ -13,6 +13,7 @@ import {
13
13
  finalizeRunResult,
14
14
  formatStepProgress,
15
15
  parseStreamLine,
16
+ summarizeAgyDeniedActions,
16
17
  type AgyProgressHandler,
17
18
  type AgyRunResult,
18
19
  type AgyStreamLine,
@@ -1164,20 +1165,33 @@ function spawnAgyInternal(
1164
1165
  runResult = processStreamLine(lineBuffer, runResult, onProgress);
1165
1166
  }
1166
1167
 
1168
+ // Finalization also parses whole top-level JSON envelopes, including
1169
+ // pretty-printed output that cannot be consumed one line at a time.
1170
+ const finalized = finalizeRunResult(out, runResult);
1171
+
1167
1172
  // Terminal status is authoritative when present. agy can emit an
1168
1173
  // ERROR envelope with response: "" and even exit 0; response
1169
1174
  // completeness must never turn that failed turn into success.
1170
- const terminalFailure = terminalFailureMessage(runResult, err);
1175
+ const terminalFailure = terminalFailureMessage(finalized, err);
1171
1176
  if (terminalFailure) {
1172
- reject(withConversationId(terminalFailure, runResult));
1177
+ reject(withConversationId(terminalFailure, finalized));
1178
+ return;
1179
+ }
1180
+
1181
+ // Headless permission denials are intentionally nonfatal in agy and
1182
+ // can therefore arrive as SUCCESS with an empty response. Never turn
1183
+ // that incomplete delegation into a silent successful tool result.
1184
+ if (finalized.denied_actions?.length && !finalized.response.trim()) {
1185
+ const denied = summarizeAgyDeniedActions(finalized.denied_actions);
1186
+ reject(withConversationId(`agy denied tool actions: ${denied}`, finalized));
1173
1187
  return;
1174
1188
  }
1175
1189
 
1176
1190
  // A fully delivered successful result outranks the kill: when
1177
1191
  // cancellation or timeout lands after the response arrived, the work
1178
1192
  // is done and the response must not be discarded.
1179
- if (runResult.response_complete) {
1180
- resolve(finalizeRunResult(out, runResult));
1193
+ if (finalized.response_complete) {
1194
+ resolve(finalized);
1181
1195
  return;
1182
1196
  }
1183
1197
 
@@ -1185,7 +1199,7 @@ function spawnAgyInternal(
1185
1199
  reject(
1186
1200
  withConversationId(
1187
1201
  signal.aborted && !timedOut ? "agy was cancelled" : "agy timed out",
1188
- runResult,
1202
+ finalized,
1189
1203
  ),
1190
1204
  );
1191
1205
  return;
@@ -1193,13 +1207,12 @@ function spawnAgyInternal(
1193
1207
 
1194
1208
  if (code !== 0) {
1195
1209
  const detail = (err || out).slice(0, 2000).trim();
1196
- reject(withConversationId(`agy exited with code ${code}:\n${detail || "(no output)"}`, runResult));
1210
+ reject(withConversationId(`agy exited with code ${code}:\n${detail || "(no output)"}`, finalized));
1197
1211
  return;
1198
1212
  }
1199
1213
 
1200
1214
  // agy writes diagnostics to stderr even on successful runs. Keep it
1201
1215
  // out of the response so JSON/stream parsing remains deterministic.
1202
- const finalized = finalizeRunResult(out, runResult);
1203
1216
  // Only responses served verbatim from the bounded raw capture can be
1204
1217
  // incomplete; anything parsed from a record was delivered in full.
1205
1218
  if (stdoutTruncated && !finalized.response_complete) {
@@ -18,7 +18,11 @@ import {
18
18
  } from "./cli.js";
19
19
  import { loadAgyConfig, resolveDefaultModel } from "./config.js";
20
20
  import type { AgyContextMode } from "./context.js";
21
- import type { AgyUsage } from "./stream.js";
21
+ import {
22
+ summarizeAgyDeniedActions,
23
+ type AgyDeniedAction,
24
+ type AgyUsage,
25
+ } from "./stream.js";
22
26
  import {
23
27
  formatAgySubagentObservations,
24
28
  type AgyObservedSubagent,
@@ -66,6 +70,8 @@ export interface AgyExecutionDetails {
66
70
  duration_seconds?: number;
67
71
  /** Stream observations only; entries do not imply a live controllable process. */
68
72
  subagents?: AgyObservedSubagent[];
73
+ /** Bounded tool actions refused by agy's headless permission policy. */
74
+ denied_actions?: AgyDeniedAction[];
69
75
  changed_files?: string[];
70
76
  preexisting_files?: string[];
71
77
  context_mode?: AgyContextMode;
@@ -249,6 +255,9 @@ export async function executeAgyTask(
249
255
  }
250
256
 
251
257
  let text = run.response;
258
+ if (run.denied_actions?.length) {
259
+ text = `${text}\n\n## agy denied actions\n${summarizeAgyDeniedActions(run.denied_actions)}`;
260
+ }
252
261
  const subagentSummary = formatAgySubagentObservations(run.subagents);
253
262
  if (subagentSummary) text = `${text}\n\n## ${subagentSummary}`;
254
263
  const quotaSummary = quota?.models.length
@@ -290,6 +299,7 @@ export async function executeAgyTask(
290
299
  usage: run.usage,
291
300
  duration_seconds: run.duration_seconds,
292
301
  subagents: run.subagents,
302
+ denied_actions: run.denied_actions,
293
303
  changed_files: changedFiles,
294
304
  preexisting_files: preexistingFiles,
295
305
  context_mode: options.context ?? "none",
@@ -2,6 +2,10 @@ import { keyHint, type Theme } from "@earendil-works/pi-coding-agent";
2
2
  import { stripTerminalSequences, Text, truncateToWidth } from "@earendil-works/pi-tui";
3
3
 
4
4
  import type { AgyExecutionDetails } from "./execute.js";
5
+ import {
6
+ normalizeAgyDeniedActions,
7
+ summarizeAgyDeniedActions,
8
+ } from "./stream.js";
5
9
 
6
10
  export const AGY_RUN_ENTRY_TYPE = "agy-run-receipt";
7
11
 
@@ -47,6 +51,7 @@ function firstText(content: unknown): string {
47
51
 
48
52
  function stripSyntheticResultSections(value: string): string {
49
53
  const markers = [
54
+ "\n\n## agy denied actions",
50
55
  "\n\n## agy quota snapshot",
51
56
  "\n\n## agy subagents observed",
52
57
  "\n\n## git diff --stat",
@@ -140,6 +145,18 @@ function formatAgyResult(
140
145
  }
141
146
  if (metadata.length) lines.push(theme.fg("dim", metadata.join(" · ")));
142
147
 
148
+ const denied = normalizeAgyDeniedActions(details.denied_actions) ?? [];
149
+ if (denied.length) {
150
+ const count = `${denied.length} denied action${denied.length === 1 ? "" : "s"}`;
151
+ const summary = summarizeAgyDeniedActions(denied, 3);
152
+ lines.push(theme.fg("warning", `⚠ ${count}${summary ? ` · ${summary}` : ""}`));
153
+ if (expanded) {
154
+ for (const entry of denied) {
155
+ lines.push(theme.fg("toolOutput", `↳ denied ${summarizeAgyDeniedActions([entry], 1)}`));
156
+ }
157
+ }
158
+ }
159
+
143
160
  const subagents = Array.isArray(details.subagents) ? details.subagents.slice(0, 32) : [];
144
161
  if (subagents.length) {
145
162
  const done = subagents.filter((entry) => entry?.status === "done").length;
@@ -14,6 +14,11 @@ export interface AgyUsage {
14
14
  total_tokens?: number;
15
15
  }
16
16
 
17
+ export interface AgyDeniedAction {
18
+ action?: string;
19
+ display_name?: string;
20
+ }
21
+
17
22
  export interface AgyStepUpdate {
18
23
  conversation_id?: string;
19
24
  step_index?: number;
@@ -42,6 +47,7 @@ export interface AgyStreamLine {
42
47
  status?: string;
43
48
  response?: string;
44
49
  error?: string;
50
+ denied_actions?: unknown;
45
51
  duration_seconds?: number;
46
52
  usage?: AgyUsage;
47
53
  init?: { model?: string; cwd?: string };
@@ -51,6 +57,7 @@ export interface AgyStreamLine {
51
57
  status?: string;
52
58
  response?: string;
53
59
  error?: string;
60
+ denied_actions?: unknown;
54
61
  duration_seconds?: number;
55
62
  usage?: AgyUsage;
56
63
  };
@@ -64,6 +71,8 @@ export interface AgyRunResult {
64
71
  terminal_status?: string;
65
72
  /** Bounded terminal error detail from the result envelope. */
66
73
  terminal_error?: string;
74
+ /** Bounded permission refusals reported by headless agy. */
75
+ denied_actions?: AgyDeniedAction[];
67
76
  conversation_id?: string;
68
77
  usage?: AgyUsage;
69
78
  duration_seconds?: number;
@@ -222,6 +231,58 @@ function capTerminalError(error: string): string {
222
231
  .slice(0, 2_000);
223
232
  }
224
233
 
234
+ const MAX_DENIED_ACTIONS = 32;
235
+ const MAX_DENIED_ACTION_CHARS = 120;
236
+
237
+ function cleanDeniedActionField(value: unknown): string | undefined {
238
+ if (typeof value !== "string") return undefined;
239
+ const clean = stripTerminalSequences(value)
240
+ .replace(/[\u0000-\u001f\u007f-\u009f]/g, " ")
241
+ .replace(/\s+/g, " ")
242
+ .trim()
243
+ .slice(0, MAX_DENIED_ACTION_CHARS);
244
+ return clean || undefined;
245
+ }
246
+
247
+ export function normalizeAgyDeniedActions(value: unknown): AgyDeniedAction[] | undefined {
248
+ if (!Array.isArray(value)) return undefined;
249
+ const denied: AgyDeniedAction[] = [];
250
+ const seen = new Set<string>();
251
+ for (const item of value) {
252
+ let action: string | undefined;
253
+ let displayName: string | undefined;
254
+ if (typeof item === "string") {
255
+ action = cleanDeniedActionField(item);
256
+ } else if (typeof item === "object" && item !== null && !Array.isArray(item)) {
257
+ const record = item as Record<string, unknown>;
258
+ action = cleanDeniedActionField(record.action);
259
+ displayName = cleanDeniedActionField(record.display_name);
260
+ }
261
+ if (!action && !displayName) continue;
262
+ const key = `${action ?? ""}\u0000${displayName ?? ""}`;
263
+ if (seen.has(key)) continue;
264
+ seen.add(key);
265
+ denied.push({
266
+ ...(action ? { action } : {}),
267
+ ...(displayName ? { display_name: displayName } : {}),
268
+ });
269
+ if (denied.length >= MAX_DENIED_ACTIONS) break;
270
+ }
271
+ return denied.length ? denied : undefined;
272
+ }
273
+
274
+ export function summarizeAgyDeniedActions(value: unknown, max = 12): string {
275
+ const denied = normalizeAgyDeniedActions(value) ?? [];
276
+ const shown = denied.slice(0, Math.max(0, max));
277
+ const labels = shown.map(({ action, display_name: displayName }) =>
278
+ displayName && action && displayName !== action
279
+ ? `${displayName} (${action})`
280
+ : displayName ?? action ?? "unknown action",
281
+ );
282
+ if (denied.length > shown.length) labels.push(`… ${denied.length - shown.length} more`);
283
+ return labels.join(", ");
284
+ }
285
+
225
286
  export function accumulateRunResult(parsed: AgyStreamLine, current: AgyRunResult): AgyRunResult {
226
287
  const next = { ...current };
227
288
 
@@ -238,6 +299,8 @@ export function accumulateRunResult(parsed: AgyStreamLine, current: AgyRunResult
238
299
  next.response_complete = true;
239
300
  }
240
301
  if (typeof parsed.error === "string") next.terminal_error = capTerminalError(parsed.error);
302
+ const topLevelDenied = normalizeAgyDeniedActions(parsed.denied_actions);
303
+ if (topLevelDenied) next.denied_actions = topLevelDenied;
241
304
  if (typeof parsed.duration_seconds === "number" && Number.isFinite(parsed.duration_seconds)) {
242
305
  next.duration_seconds = parsed.duration_seconds;
243
306
  }
@@ -264,6 +327,8 @@ export function accumulateRunResult(parsed: AgyStreamLine, current: AgyRunResult
264
327
  if (typeof parsed.result.error === "string") {
265
328
  next.terminal_error = capTerminalError(parsed.result.error);
266
329
  }
330
+ const denied = normalizeAgyDeniedActions(parsed.result.denied_actions);
331
+ if (denied) next.denied_actions = denied;
267
332
  if (typeof parsed.result.usage === "object" && parsed.result.usage !== null) {
268
333
  next.usage = parsed.result.usage;
269
334
  }
@@ -289,15 +354,22 @@ export function finalizeRunResult(rawStdout: string, current: AgyRunResult): Agy
289
354
  }
290
355
  }
291
356
 
292
- try {
293
- const parsed: unknown = JSON.parse(rawStdout);
294
- const next = mergeJsonEnvelope(parsed, current);
295
- if (next) return next;
296
- } catch {
297
- // not json
357
+ const trimmed = rawStdout.trim();
358
+ const trailingRoot = trimmed.lastIndexOf("\n{");
359
+ const candidates = trailingRoot >= 0
360
+ ? [trimmed, trimmed.slice(trailingRoot + 1)]
361
+ : [trimmed];
362
+ for (const candidate of candidates) {
363
+ try {
364
+ const parsed: unknown = JSON.parse(candidate);
365
+ const next = mergeJsonEnvelope(parsed, current);
366
+ if (next) return next;
367
+ } catch {
368
+ // Try the bounded trailing root object after earlier stream records.
369
+ }
298
370
  }
299
371
 
300
- return { ...current, response: rawStdout.trim() || "(empty response)" };
372
+ return { ...current, response: trimmed || "(empty response)" };
301
373
  }
302
374
 
303
375
  /** Preserve metadata from agy's non-stream JSON envelope when available. */
@@ -324,6 +396,11 @@ function mergeJsonEnvelope(parsed: unknown, current: AgyRunResult): AgyRunResult
324
396
  next.terminal_error = capTerminalError(record.error);
325
397
  found = true;
326
398
  }
399
+ const denied = normalizeAgyDeniedActions(record.denied_actions);
400
+ if (denied) {
401
+ next.denied_actions = denied;
402
+ found = true;
403
+ }
327
404
  if (typeof record.duration_seconds === "number") {
328
405
  next.duration_seconds = record.duration_seconds;
329
406
  found = true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juanbenjumea/pi-agy",
3
- "version": "0.6.9",
3
+ "version": "0.6.11",
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",