@maheidem/pi-delegate 0.3.0 → 0.3.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maheidem/pi-delegate",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "type": "module",
5
5
  "description": "Foreground isolated delegation and strict coordinator mode for the Pi coding agent.",
6
6
  "license": "MIT",
package/rpc-jsonl.ts CHANGED
@@ -175,7 +175,21 @@ export function classifyRpcRecord(record: RpcRecord): RpcRecordClassification {
175
175
  id: typeof obj.toolCallId === "string" ? obj.toolCallId : undefined,
176
176
  toolName: typeof obj.toolName === "string" ? obj.toolName : undefined,
177
177
  ...(result && typeof result === "object"
178
- ? { result: { details: result.details, isError: result.isError === true, ...(textHead ? { textHead } : {}) } }
178
+ ? {
179
+ result: {
180
+ details: result.details,
181
+ // Authoritative flags only. Pi emits `isError` at the TOP level of
182
+ // the event (verified against captured transcripts); `result.isError`
183
+ // is unset there. Reading only `result.isError` silently marked every
184
+ // genuine tool failure as success. Content is NEVER a failure signal.
185
+ isError:
186
+ obj.isError === true ||
187
+ obj.is_error === true ||
188
+ result.isError === true ||
189
+ result.is_error === true,
190
+ ...(textHead ? { textHead } : {}),
191
+ },
192
+ }
179
193
  : {}),
180
194
  };
181
195
  }
@@ -100,7 +100,15 @@ interface ParsedRecord {
100
100
  toolCallId?: string;
101
101
  toolName?: string;
102
102
  args?: unknown;
103
- result?: { content?: Array<{ type?: string; text?: string }>; isError?: boolean; details?: { delegateHandoff?: { outcome?: string } } };
103
+ /** Authoritative failure flag — Pi carries it at the TOP level. */
104
+ isError?: boolean;
105
+ is_error?: boolean;
106
+ result?: {
107
+ content?: Array<{ type?: string; text?: string }>;
108
+ isError?: boolean;
109
+ is_error?: boolean;
110
+ details?: { delegateHandoff?: { outcome?: string } };
111
+ };
104
112
  message?: {
105
113
  role?: string;
106
114
  stopReason?: string;
@@ -125,6 +133,26 @@ function parseEnvelope(line: string): { atMs: number; rec: ParsedRecord | null }
125
133
  }
126
134
  }
127
135
 
136
+ /**
137
+ * Authoritative failure flags ONLY. Pi's `tool_execution_end` records carry
138
+ * `isError` at the TOP level of the record (`result.isError` is unset in
139
+ * captured transcripts), so both positions are read; snake_case `is_error` is
140
+ * tolerated for other RPC producers.
141
+ *
142
+ * NEVER infer failure from result *content*: a successful `read` of a source
143
+ * file whose text contains `throw new Error("…")` is a SUCCESS, and a red
144
+ * `✗ read …` in the live feed is indistinguishable from a real failure to
145
+ * the user (cautionary instance: run del_20260908T113930Z_72cc3f31).
146
+ */
147
+ function toolFailed(rec: ParsedRecord): boolean {
148
+ return (
149
+ rec.isError === true ||
150
+ rec.is_error === true ||
151
+ rec.result?.isError === true ||
152
+ rec.result?.is_error === true
153
+ );
154
+ }
155
+
128
156
  function resultTextHead(result: ParsedRecord["result"]): string {
129
157
  const blocks = result?.content ?? [];
130
158
  for (const b of blocks) {
@@ -184,7 +212,8 @@ export function feedEventsFromTranscript(
184
212
  kind: "tool_end",
185
213
  tool: name,
186
214
  detail,
187
- isError: rec.result?.isError === true || /\berror\b/i.test(head.slice(0, 40)),
215
+ // Status flags only — `head` is untrusted content (see toolFailed).
216
+ isError: toolFailed(rec),
188
217
  ...(open ? { durationMs: atMs - open.atMs } : {}),
189
218
  });
190
219
  break;
@@ -123,11 +123,17 @@ export class RunningView implements Component {
123
123
 
124
124
  const footer = this.cancelArmed ? fg("error", "ESC again: CONFIRM cancel") : "esc/q cancel (press twice)";
125
125
 
126
+ // In-flight tools are the NORMAL state of a running child, not a
127
+ // problem: amber ("warning") is read by humans as trouble, so this row
128
+ // stays neutral/dim. Reserve "warning" for degraded and "error" for
129
+ // failed (see skills/pi-extension-builder OPERATIONAL-EXTENSIONS.md).
130
+ const inFlightColor: ThemeColor | undefined = openTools.length > 0 ? "dim" : undefined;
131
+
126
132
  // Assemble a fixed-height body: header, progress, in-flight, feed block, footer.
127
133
  const body: Array<[string, ThemeColor?]> = [
128
134
  [head],
129
135
  [progress, "accent"],
130
- [inFlight, inFlight ? "warning" : undefined],
136
+ [inFlight, inFlightColor],
131
137
  ...feedRows.map((l): [string, ThemeColor?] => [l, l ? "text" : undefined]),
132
138
  [footer, this.cancelArmed ? "error" : "dim"],
133
139
  ];