pi-better-subagents 0.2.0 → 0.4.0

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/tools.ts CHANGED
@@ -18,6 +18,7 @@ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
18
18
  import { readMeta, listMetas, effectiveStatus, isFinalResultStatus, type RunMeta, type RunStatus } from "./registry.ts";
19
19
  import { parseRun, tailLog, formatSubagentOutputBody } from "./parse.ts";
20
20
  import { buildSubagentResultText } from "./finalization.ts";
21
+ import { failureSummary, prependFailureSummary } from "./failures.ts";
21
22
  import { formatOrphanedResult } from "./lifecycle.ts";
22
23
  import { stopRun } from "./stop.ts";
23
24
  import { fmtElapsed, fmtSpend } from "./widget.ts";
@@ -258,6 +259,10 @@ export function subagentListTool(Type: TypeModule): ToolDefinition {
258
259
  statusOf: effectiveStatus,
259
260
  usageById: (id: string) => parseRun(id).usage,
260
261
  healthById,
262
+ failureById: (id: string) => {
263
+ const meta = metas.find((m) => m.id === id);
264
+ return meta ? failureSummary(id, meta.cwd, meta.status !== "running" && meta.status !== "orphaned") : "";
265
+ },
261
266
  }));
262
267
  },
263
268
  } as ToolDefinition;
@@ -300,7 +305,7 @@ export function subagentOutputTool(Type: TypeModule): ToolDefinition {
300
305
  // Health diagnostics for orphaned/lost/degraded only (#67). Healthy/quiet
301
306
  // stays on today's body. Independent of meta.callback.
302
307
  const healthLine = formatHealthDiagnosticLine(observeMetaHealth(meta));
303
- return text(appendHealthDiagnostic(body, healthLine));
308
+ return text(prependFailureSummary(appendHealthDiagnostic(body, healthLine), failureSummary(p.id, meta.cwd, st !== "running" && st !== "orphaned")));
304
309
  },
305
310
  } as ToolDefinition;
306
311
  }
@@ -342,9 +347,9 @@ export function subagentResultTool(Type: TypeModule): ToolDefinition {
342
347
  const rawTail = tailLog(p.id, 40);
343
348
  const body = `${head}\n${formatOrphanedResult(r, rawTail)}`;
344
349
  const healthLine = formatHealthDiagnosticLine(observeMetaHealth(meta));
345
- return subagentResultText(appendHealthDiagnostic(body, healthLine));
350
+ return subagentResultText(prependFailureSummary(appendHealthDiagnostic(body, healthLine), failureSummary(p.id, meta.cwd)));
346
351
  }
347
- return subagentResultText(`Run ${p.id} is still running — no result yet. You'll be notified when it finishes; don't poll.`);
352
+ return subagentResultText(prependFailureSummary(`Run ${p.id} is still running — no result yet. You'll be notified when it finishes; don't poll.`, failureSummary(p.id, meta.cwd)));
348
353
  }
349
354
  // Lifecycle-aware body (complete-stream authority + diagnostics).
350
355
  // Lost runs go through formatLostResult inside formatSubagentResult (#65).
@@ -356,7 +361,7 @@ export function subagentResultTool(Type: TypeModule): ToolDefinition {
356
361
  // Append degraded/lost health facts when present; completed/failed
357
362
  // happy paths stay quiet when observation is non-actionable.
358
363
  const healthLine = formatHealthDiagnosticLine(observeMetaHealth(meta));
359
- return subagentResultText(appendHealthDiagnostic(body, healthLine));
364
+ return subagentResultText(prependFailureSummary(appendHealthDiagnostic(body, healthLine), failureSummary(p.id, meta.cwd, true)));
360
365
  },
361
366
  } as ToolDefinition;
362
367
  }