@deathbeam/pi-delegate 0.0.39 → 0.0.40

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/child.ts CHANGED
@@ -170,7 +170,8 @@ export function runChild(
170
170
  return;
171
171
  }
172
172
  case "agent_settled":
173
- finish(0);
173
+ // A run the child aborted itself (an extension's abort or compaction) is not the task's answer.
174
+ finish(0, event.aborted ? new Error("Delegate run was aborted before it finished") : undefined);
174
175
  return;
175
176
  case "extension_ui_request":
176
177
  if (["select", "confirm", "input", "editor"].includes(event.method)) {
package/format.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { getMarkdownTheme, keyHint, type Theme } from "@earendil-works/pi-coding-agent";
1
+ import { getMarkdownTheme, type KeybindingHints, type Theme } from "@earendil-works/pi-coding-agent";
2
2
  import {
3
3
  type Component,
4
4
  Container,
@@ -301,14 +301,20 @@ export function resultFallback(body: string, theme: Theme, isError: boolean): Te
301
301
  return new Text(`\n${mark} ${theme.fg(isError ? "error" : "toolOutput", body || "(no output)")}`, 0, 0);
302
302
  }
303
303
 
304
- export function moreLines(theme: Theme, hidden: number): string {
304
+ export function moreLines(theme: Theme, hidden: number, keyHint: KeybindingHints["keyHint"]): string {
305
305
  return theme.fg("muted", `… ${hidden} more lines, `) + keyHint("app.tools.expand", "to expand");
306
306
  }
307
307
 
308
- export function appendOutput(container: Container, body: string, expanded: boolean, theme: Theme): void {
308
+ export function appendOutput(
309
+ container: Container,
310
+ body: string,
311
+ expanded: boolean,
312
+ theme: Theme,
313
+ keyHint: KeybindingHints["keyHint"],
314
+ ): void {
309
315
  const { shown, hidden } = outputPreview(body, expanded ? Infinity : COLLAPSED_OUTPUT_LINES);
310
316
  container.addChild(new Markdown(shown.join("\n"), 0, 0, getMarkdownTheme()));
311
- if (hidden > 0) container.addChild(new Text(moreLines(theme, hidden), 0, 0));
317
+ if (hidden > 0) container.addChild(new Text(moreLines(theme, hidden, keyHint), 0, 0));
312
318
  }
313
319
 
314
320
  export function toolLayout(
@@ -317,6 +323,7 @@ export function toolLayout(
317
323
  payload: string,
318
324
  theme: Theme,
319
325
  expanded: boolean,
326
+ keyHint: KeybindingHints["keyHint"],
320
327
  ): Component {
321
328
  const container = new Container();
322
329
  if (toolName)
@@ -337,7 +344,7 @@ export function toolLayout(
337
344
  render: (width) => {
338
345
  // Wrapping turns one long line into many, so the cap counts rendered rows, not source lines.
339
346
  const { shown, hidden } = capLines(body.render(width), expanded ? Infinity : COLLAPSED_OUTPUT_LINES);
340
- return hidden ? [...shown, truncateToWidth(moreLines(theme, hidden), width)] : shown;
347
+ return hidden ? [...shown, truncateToWidth(moreLines(theme, hidden, keyHint), width)] : shown;
341
348
  },
342
349
  invalidate: () => body.invalidate(),
343
350
  });
@@ -368,6 +375,7 @@ export function launchResult(
368
375
  status: string,
369
376
  expanded: boolean,
370
377
  theme: Theme,
378
+ keyHint: KeybindingHints["keyHint"],
371
379
  ): Component {
372
380
  const container = new Container();
373
381
  // The mark is the call's outcome (launch succeeded); job progress stays in the widget and report.
@@ -378,6 +386,6 @@ export function launchResult(
378
386
  new Text(theme.fg("muted", launchDetails({ model: details.model, tools: details.tools }).join("\n")), 0, 0),
379
387
  );
380
388
  // Background results arrive as their own message; headless runs still show the output here.
381
- if (!details.background && body) appendOutput(container, body, expanded, theme);
389
+ if (!details.background && body) appendOutput(container, body, expanded, theme, keyHint);
382
390
  return container;
383
391
  }
package/index.ts CHANGED
@@ -383,7 +383,8 @@ export default function (pi: ExtensionAPI) {
383
383
  pi.on("session_start", (_event, ctx) => restoreSession(ctx));
384
384
  pi.on("session_tree", (_event, ctx) => restoreSession(ctx));
385
385
 
386
- pi.on("before_agent_start", () => {
386
+ pi.on("before_agent_start", (event) => {
387
+ if (event.messageType !== "user") return;
387
388
  directCalls = 0;
388
389
  nextReminder = FIRST_REMINDER_AT;
389
390
  });
@@ -410,7 +411,7 @@ export default function (pi: ExtensionAPI) {
410
411
  );
411
412
  });
412
413
 
413
- pi.registerMessageRenderer(RESULT_MESSAGE, (message, { expanded }, theme) => {
414
+ pi.registerMessageRenderer(RESULT_MESSAGE, (message, { expanded, keyHint }, theme) => {
414
415
  const report = message.details as DelegateReport | undefined;
415
416
  if (!report?.agent) return undefined;
416
417
  const container = new Container();
@@ -420,7 +421,7 @@ export default function (pi: ExtensionAPI) {
420
421
  if (report.error) container.addChild(new Text(theme.fg("error", report.error), 0, 0));
421
422
  else if (report.output) {
422
423
  container.addChild(new Spacer(1));
423
- appendOutput(container, report.output, expanded, theme);
424
+ appendOutput(container, report.output, expanded, theme, keyHint);
424
425
  }
425
426
  return container;
426
427
  });
@@ -507,6 +508,7 @@ export default function (pi: ExtensionAPI) {
507
508
  argText(args?.task),
508
509
  theme,
509
510
  context.expanded,
511
+ context.keyHint,
510
512
  );
511
513
  },
512
514
 
@@ -520,6 +522,7 @@ export default function (pi: ExtensionAPI) {
520
522
  details.background ? "started in background" : "completed",
521
523
  expanded,
522
524
  theme,
525
+ context.keyHint,
523
526
  );
524
527
  },
525
528
  });
@@ -611,6 +614,7 @@ export default function (pi: ExtensionAPI) {
611
614
  argText(args?.message),
612
615
  theme,
613
616
  context.expanded,
617
+ context.keyHint,
614
618
  );
615
619
  },
616
620
 
@@ -625,6 +629,7 @@ export default function (pi: ExtensionAPI) {
625
629
  details.background ? "revived in background" : "revived",
626
630
  expanded,
627
631
  theme,
632
+ context.keyHint,
628
633
  );
629
634
  },
630
635
  });
@@ -654,7 +659,14 @@ export default function (pi: ExtensionAPI) {
654
659
  },
655
660
 
656
661
  renderCall(args, theme, context) {
657
- return toolLayout("delegate_cancel", jobTarget(args?.id, theme), "", theme, context.expanded);
662
+ return toolLayout(
663
+ "delegate_cancel",
664
+ jobTarget(args?.id, theme),
665
+ "",
666
+ theme,
667
+ context.expanded,
668
+ context.keyHint,
669
+ );
658
670
  },
659
671
 
660
672
  renderResult(result, _options, theme, context) {
@@ -708,7 +720,14 @@ export default function (pi: ExtensionAPI) {
708
720
  },
709
721
 
710
722
  renderCall(args, theme, context) {
711
- return toolLayout("delegate_apply", jobTarget(args?.id, theme), "", theme, context.expanded);
723
+ return toolLayout(
724
+ "delegate_apply",
725
+ jobTarget(args?.id, theme),
726
+ "",
727
+ theme,
728
+ context.expanded,
729
+ context.keyHint,
730
+ );
712
731
  },
713
732
 
714
733
  renderResult(result, { expanded }, theme, context) {
@@ -720,7 +739,7 @@ export default function (pi: ExtensionAPI) {
720
739
  if (!diff) return new Text(header, 0, 0);
721
740
  // Collapsed shows the head like the other delegate previews; expanded shows the full colored diff.
722
741
  const { shown, hidden } = capLines(diff.split("\n"), expanded ? Infinity : COLLAPSED_OUTPUT_LINES);
723
- if (hidden) shown.push(moreLines(theme, hidden));
742
+ if (hidden) shown.push(moreLines(theme, hidden, context.keyHint));
724
743
  const container = new Container();
725
744
  container.addChild(new Text(header, 0, 0));
726
745
  container.addChild(new Spacer(1));
@@ -756,7 +775,14 @@ export default function (pi: ExtensionAPI) {
756
775
  },
757
776
 
758
777
  renderCall(args, theme, context) {
759
- return toolLayout("delegate_discard", jobTarget(args?.id, theme), "", theme, context.expanded);
778
+ return toolLayout(
779
+ "delegate_discard",
780
+ jobTarget(args?.id, theme),
781
+ "",
782
+ theme,
783
+ context.expanded,
784
+ context.keyHint,
785
+ );
760
786
  },
761
787
 
762
788
  renderResult(result, _options, theme, context) {
package/inspector.ts CHANGED
@@ -1,5 +1,12 @@
1
- import { type ExtensionAPI, getMarkdownTheme, keyHint, rawKeyHint } from "@earendil-works/pi-coding-agent";
2
- import { HStack, Markdown, matchesKey, truncateToWidth, wrapTextWithAnsi } from "@earendil-works/pi-tui";
1
+ import { type ExtensionAPI, getMarkdownTheme, rawKeyHint } from "@earendil-works/pi-coding-agent";
2
+ import {
3
+ HStack,
4
+ type Keybinding,
5
+ Markdown,
6
+ matchesKey,
7
+ truncateToWidth,
8
+ wrapTextWithAnsi,
9
+ } from "@earendil-works/pi-tui";
3
10
  import type { ChildActivity } from "./child.ts";
4
11
  import { elapsedMs, formatTools, jobIdentity, STATUS_COLORS, statusText, tally, usageStats } from "./format.ts";
5
12
  import type { InspectJob, JobStore } from "./store.ts";
@@ -27,6 +34,9 @@ export function registerInspector(pi: ExtensionAPI, store: JobStore) {
27
34
  let historyWidth = 1;
28
35
  let markdown = new WeakMap<ChildActivity, Markdown>();
29
36
  const jobs = () => store.all();
37
+ // Format hints from the injected manager; an imported copy would not see the user's keybindings.
38
+ const hint = (id: Keybinding, description: string) =>
39
+ rawKeyHint(keys.getKeys(id).join("/"), description);
30
40
  // Fixed rows: title, top rule, bottom rule, footer.
31
41
  const bodyHeight = () => Math.max(0, tui.terminal.rows - 4);
32
42
  const toolsLines = (job: InspectJob, width: number) =>
@@ -146,7 +156,7 @@ export function registerInspector(pi: ExtensionAPI, store: JobStore) {
146
156
  const footer = truncateToWidth(
147
157
  theme.fg(
148
158
  "dim",
149
- `${keyHint("tui.select.up", "up")} · ${keyHint("tui.select.down", "down")} · ${rawKeyHint("←/→", "switch pane")} · ${keyHint("tui.select.cancel", "close")}`,
159
+ `${hint("tui.select.up", "up")} · ${hint("tui.select.down", "down")} · ${rawKeyHint("←/→", "switch pane")} · ${hint("tui.select.cancel", "close")}`,
150
160
  ),
151
161
  width,
152
162
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deathbeam/pi-delegate",
3
- "version": "0.0.39",
3
+ "version": "0.0.40",
4
4
  "description": "Minimal extension for delegating tasks to subagents.",
5
5
  "type": "module",
6
6
  "license": "MIT",