@maheidem/pi-delegate 0.3.0 → 0.3.2

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/application.ts CHANGED
@@ -289,10 +289,12 @@ export class DelegateApplicationImpl implements DelegateApplication {
289
289
  // Strip the overlay's diagnostic keys so only real config fields
290
290
  // reach the runner (a spurious key would survive into metadata).
291
291
  const overlay = applyProjectOverlay(this.liveConfig, request.projectRoot);
292
- const { projectOverrides, projectCorrupt, ...rest } = overlay as unknown as DelegateConfigV1 & {
292
+ const { projectOverrides, projectSetKeys, projectCorrupt, ...rest } = overlay as unknown as DelegateConfigV1 & {
293
293
  projectOverrides: string[];
294
+ projectSetKeys: string[];
294
295
  projectCorrupt?: string;
295
296
  };
297
+ void projectSetKeys; // display-only; run resolution uses projectOverrides
296
298
  projectSetsHard = projectOverrides.includes("hardTimeoutMs");
297
299
  baseCfg = { ...(rest as unknown as DelegateConfigV1) } as DelegateConfigV1;
298
300
  }
@@ -529,20 +531,27 @@ export class DelegateApplicationImpl implements DelegateApplication {
529
531
  if (projectRoot) {
530
532
  const overlay = applyProjectOverlay(cfg, projectRoot) as unknown as DelegateConfigV1 & {
531
533
  projectOverrides: string[];
534
+ projectSetKeys: string[];
532
535
  projectCorrupt?: string;
533
536
  };
534
- const { projectOverrides, projectCorrupt, ...rest } = overlay;
537
+ const { projectOverrides, projectSetKeys, projectCorrupt, ...rest } = overlay;
535
538
  const eff = rest as unknown as DelegateConfigV1;
539
+ // Provenance (source) keeps the override semantics: the effective value
540
+ // only comes "from the project" when it differs. Reporting does not:
541
+ // projectHardMs is present whenever the key is in the project FILE, so a
542
+ // project value equal to the user value is still visible to the panel.
536
543
  const projectSetsHard = projectOverrides.includes("hardTimeoutMs");
544
+ const hardFromFile = projectSetKeys.includes("hardTimeoutMs");
537
545
  timeouts = {
538
546
  hardMs: eff.hardTimeoutMs,
539
547
  inactivityMs: eff.inactivityTimeoutMs,
540
548
  source: projectSetsHard ? "project" : "user",
541
549
  userHardMs: cfg.hardTimeoutMs,
542
550
  userInactivityMs: cfg.inactivityTimeoutMs,
543
- ...(projectSetsHard ? { projectHardMs: eff.hardTimeoutMs } : {}),
551
+ ...(hardFromFile ? { projectHardMs: eff.hardTimeoutMs } : {}),
544
552
  projectPath: projectConfigPath(projectRoot),
545
553
  projectOverrides,
554
+ projectSetKeys,
546
555
  ...(projectCorrupt ? { projectCorrupt } : {}),
547
556
  };
548
557
  }
package/config.ts CHANGED
@@ -327,15 +327,24 @@ export function projectConfigPath(projectRoot: string): string {
327
327
  * (a broken project file must never break delegations);
328
328
  * - only keys PRESENT in the project file override (no default backfill);
329
329
  * - values are clamped by the same min/max bounds as the user config.
330
+ * Two diagnostic arrays, deliberately different:
331
+ * - `projectOverrides`: keys that CHANGE the effective value (equality vs
332
+ * base). Resolution/provenance logic depends on this — do not widen.
333
+ * - `projectSetKeys`: every known key explicitly PRESENT in the file,
334
+ * regardless of equality with the base. Display code must use this, so a
335
+ * project value that happens to equal the user value never renders as
336
+ * "not set". A key whose value is invalid is still reported as set (it
337
+ * is in the file); its effective value then equals the base value.
330
338
  * Returns a NEW config object; the base is never mutated.
331
339
  */
332
340
  export function applyProjectOverlay(
333
341
  base: DelegateConfigV1,
334
342
  projectRoot: string,
335
- ): DelegateConfigV1 & { projectOverrides: string[]; projectCorrupt?: string } {
336
- const result: DelegateConfigV1 & { projectOverrides: string[]; projectCorrupt?: string } = {
343
+ ): DelegateConfigV1 & { projectOverrides: string[]; projectSetKeys: string[]; projectCorrupt?: string } {
344
+ const result: DelegateConfigV1 & { projectOverrides: string[]; projectSetKeys: string[]; projectCorrupt?: string } = {
337
345
  ...base,
338
346
  projectOverrides: [],
347
+ projectSetKeys: [],
339
348
  };
340
349
  const pPath = projectConfigPath(projectRoot);
341
350
  let raw: unknown;
@@ -351,9 +360,13 @@ export function applyProjectOverlay(
351
360
  const record = raw as Record<string, unknown>;
352
361
  const known = new Set<string>(Object.keys(DEFAULT_DELEGATE_CONFIG));
353
362
  const overrides: string[] = [];
363
+ const setKeys: string[] = [];
354
364
  for (const key of Object.keys(record)) {
355
365
  if (key === "schemaVersion") continue;
356
366
  if (!knownKey(key)) continue; // unknown keys in project overlay ignored
367
+ // File truth: present in the project file counts as set even when the
368
+ // normalized value equals the base value (the override list would omit it).
369
+ setKeys.push(key);
357
370
  try {
358
371
  const probe: DelegateConfigV1 = { ...DEFAULT_DELEGATE_CONFIG };
359
372
  applyKnownField(probe, key, record[key]);
@@ -367,6 +380,7 @@ export function applyProjectOverlay(
367
380
  }
368
381
  }
369
382
  result.projectOverrides = overrides;
383
+ result.projectSetKeys = setKeys;
370
384
  return result;
371
385
  }
372
386
 
@@ -382,14 +396,15 @@ export function loadConfigCascade(
382
396
  agentDir: string,
383
397
  projectRoot?: string,
384
398
  configPath?: string,
385
- ): ConfigLoadResult & { projectOverrides: string[]; projectCorrupt?: string } {
399
+ ): ConfigLoadResult & { projectOverrides: string[]; projectSetKeys: string[]; projectCorrupt?: string } {
386
400
  const base = loadConfig(agentDir, configPath);
387
401
  if (!projectRoot) {
388
- return { ...base, projectOverrides: [] };
402
+ return { ...base, projectOverrides: [], projectSetKeys: [] };
389
403
  }
390
404
  const overlay = applyProjectOverlay(base.config, projectRoot);
391
- const { projectOverrides, projectCorrupt, ...rest } = overlay as unknown as DelegateConfigV1 & {
405
+ const { projectOverrides, projectSetKeys, projectCorrupt, ...rest } = overlay as unknown as DelegateConfigV1 & {
392
406
  projectOverrides: string[];
407
+ projectSetKeys: string[];
393
408
  projectCorrupt?: string;
394
409
  };
395
410
  const config: DelegateConfigV1 = { ...(rest as unknown as DelegateConfigV1) };
@@ -397,6 +412,7 @@ export function loadConfigCascade(
397
412
  ...base,
398
413
  config,
399
414
  projectOverrides: overlay.projectOverrides,
415
+ projectSetKeys: overlay.projectSetKeys,
400
416
  projectCorrupt: overlay.projectCorrupt,
401
417
  };
402
418
  }
package/index.ts CHANGED
@@ -39,7 +39,7 @@ import type {
39
39
  SessionEntryLike,
40
40
  } from "./types.ts";
41
41
  import { SettingsPanel, type PanelSnapshot, type PanelActionResult, type PanelSection, type PanelRow } from "./ui/settings-panel.ts";
42
- import { shortModel, formatTokens, formatCost, stateGlyph, progressBar } from "./ui/format.ts";
42
+ import { shortModel, formatTokens, formatCost, stateGlyph, progressBar, projectValueCell } from "./ui/format.ts";
43
43
  import { RunningView, type RunningViewState } from "./ui/running-view.ts";
44
44
  import { PeekView } from "./ui/peek-view.ts";
45
45
  import { FeedRing, feedEventsFromTranscript, renderFeedEvents } from "./transcript-feed.ts";
@@ -949,7 +949,7 @@ export default function delegateExtension(pi: ExtensionAPI) {
949
949
  rows: [
950
950
  { key: "cfg:user:hardTimeoutMs", label: "Hard · user-wide", value: formatDuration(t.userHardMs), rawValue: String(t.userHardMs), kind: "input", inputHint: "e.g. 30m / 2h / 1d — user config" },
951
951
  { key: "cfg:user:inactivityTimeoutMs", label: "Idle · user-wide", value: formatDuration(t.userInactivityMs), rawValue: String(t.userInactivityMs), kind: "input", inputHint: "no-output watchdog; capped at ½ hard" },
952
- { key: "cfg:project:hardTimeoutMs", label: "Hard · project", value: t.projectHardMs !== undefined ? formatDuration(t.projectHardMs) : "not set", rawValue: t.projectHardMs !== undefined ? String(t.projectHardMs) : "", kind: "input", inputHint: `merges into ${t.projectPath ?? ".pi/delegate/config.json"}` },
952
+ { key: "cfg:project:hardTimeoutMs", label: "Hard · project", value: projectValueCell(t.projectHardMs, t.userHardMs), rawValue: t.projectHardMs !== undefined ? String(t.projectHardMs) : "", kind: "input", inputHint: `merges into ${t.projectPath ?? ".pi/delegate/config.json"}` },
953
953
  ...(t.projectCorrupt
954
954
  ? [{ key: "project-corrupt", label: "Project config", value: "corrupt — user values used", kind: "info" as const, valueStyle: "warning" as const }]
955
955
  : []),
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.2",
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;
package/types.ts CHANGED
@@ -346,11 +346,13 @@ export interface DelegateStatus {
346
346
  source: "user" | "project";
347
347
  userHardMs: number;
348
348
  userInactivityMs: number;
349
- /** Present when the project file overrides the hard timeout. */
349
+ /** Present when the project file sets the hard timeout (file truth, even when equal to user). */
350
350
  projectHardMs?: number;
351
351
  projectPath?: string;
352
- /** Config keys overridden by the project file. */
352
+ /** Config keys that CHANGE the effective value (equality vs the user layer). */
353
353
  projectOverrides?: string[];
354
+ /** Config keys PRESENT in the project file, whether or not they differ from user. */
355
+ projectSetKeys?: string[];
354
356
  /** Set when a corrupt project file was ignored (user values used). */
355
357
  projectCorrupt?: string;
356
358
  };
package/ui/format.ts CHANGED
@@ -20,6 +20,19 @@ export function formatTokens(n: number | undefined): string {
20
20
  return `${Math.round(n / 100_000) / 10}M`;
21
21
  }
22
22
 
23
+ /**
24
+ * Project-layer config cell for dashboard rows. The project FILE is the
25
+ * source of truth for presence: a value equal to the user layer renders as
26
+ * `2h (= user)` instead of reading as unset, and "not set" appears ONLY when
27
+ * the key is absent from the file. `undefined` means absent.
28
+ */
29
+ export function projectValueCell(value: number | undefined, userValue: number | undefined): string {
30
+ if (value === undefined || !Number.isFinite(value)) return "not set";
31
+ const text = formatDuration(value);
32
+ if (userValue !== undefined && Number.isFinite(userValue) && value === userValue) return `${text} (= user)`;
33
+ return text;
34
+ }
35
+
23
36
  /** Cost as `$X.YZ` (2 dp) or `$0.00`. Never emoji. */
24
37
  export function formatCost(cost: number | undefined): string {
25
38
  return `$${(cost ?? 0).toFixed(2)}`;
@@ -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
  ];