@maheidem/pi-delegate 0.6.2 → 0.6.4

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/background.ts CHANGED
@@ -150,11 +150,9 @@ export function formatBackgroundResultEnvelope(
150
150
  runText: string,
151
151
  ): string {
152
152
  return (
153
- `[delegate background ${runId} · ${role} · ${description}: ${backgroundStateWord(state)}]\n` +
153
+ `### [delegate background ${runId} · ${role} · ${description}: ${backgroundStateWord(state)}]\n` +
154
154
  "\n" +
155
- "This is the terminal report of a background delegation. The run has finished and\n" +
156
- "cannot receive steering. Treat it as an internal work event: write user-visible\n" +
157
- "text only if material, and do not re-narrate the handoff.\n" +
155
+ "<!-- This is the terminal report of a background delegation. The run has finished and cannot receive steering. Treat it as an internal work event: write user-visible text only if material, and do not re-narrate the handoff. -->\n" +
158
156
  "\n" +
159
157
  runText
160
158
  );
@@ -173,13 +171,9 @@ export function formatBackgroundStartedText(runId: string, role: RoleName, descr
173
171
  /** R17: the question envelope (SPEC §5, byte-exact; wakes the parent). */
174
172
  export function formatChildQuestionEnvelope(runId: string, role: RoleName, description: string, topic: string, question: string): string {
175
173
  return (
176
- `[delegate background ${runId} · ${role} · ${description}: asks]\n` +
174
+ `### [delegate background ${runId} · ${role} · ${description}: asks]\n` +
177
175
  "\n" +
178
- `A delegated child is blocked waiting for your answer (topic: ${topic}). Answer\n` +
179
- `with the delegate_answer tool: delegate_answer({ runId: "${runId}", answer: "…" }).\n` +
180
- "Be terse and directive; the child resumes the moment your answer lands. Do not\n" +
181
- "narrate this exchange to the user unless it is material. If you cannot answer,\n" +
182
- "say so — the child proceeds with its best judgment after the ask budget expires.\n" +
176
+ `<!-- A delegated child is blocked waiting for your answer (topic: ${topic}). Answer with the delegate_answer tool: delegate_answer({ runId: "${runId}", answer: "…" }). Be terse and directive; the child resumes the moment your answer lands. Do not narrate this exchange to the user unless it is material. If you cannot answer, say so — the child proceeds with its best judgment after the ask budget expires. -->\n` +
183
177
  "\n" +
184
178
  question
185
179
  );
@@ -188,10 +182,9 @@ export function formatChildQuestionEnvelope(runId: string, role: RoleName, descr
188
182
  /** R18: the note envelope (SPEC §5, byte-exact; NEVER wakes the parent). */
189
183
  export function formatChildNoteEnvelope(runId: string, role: RoleName, description: string, topic: string, note: string): string {
190
184
  return (
191
- `[delegate background ${runId} · ${role} · ${description}: note]\n` +
185
+ `### [delegate background ${runId} · ${role} · ${description}: note]\n` +
192
186
  "\n" +
193
- `A delegated child filed a non-blocking note (topic: ${topic}). No answer is\n` +
194
- "expected or possible. Treat it as an internal work event.\n" +
187
+ `<!-- A delegated child filed a non-blocking note (topic: ${topic}). No answer is expected or possible. Treat it as an internal work event. -->\n` +
195
188
  "\n" +
196
189
  note
197
190
  );
@@ -760,7 +753,7 @@ export function backgroundResultDisplay(content: string, details: { runId?: stri
760
753
  const state = (details.state ?? "?") as RunTerminalState;
761
754
  const word = backgroundStateWord(state);
762
755
  const glyph = state === "succeeded" ? "✓" : state === "cancelled" ? "⊘" : state.startsWith("timed_out") ? "⏱" : "⚠";
763
- const runId = details.runId ?? "?";
756
+ const runId = (details.runId ?? "?").slice(-12);
764
757
  const desc = details.description ? ` · ${details.description}` : "";
765
758
  const bodyLines = body.split("\n");
766
759
  const head = bodyLines[0] ?? "";
package/index.ts CHANGED
@@ -572,7 +572,20 @@ export default function delegateExtension(pi: ExtensionAPI) {
572
572
  },
573
573
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
574
574
  renderResult(result: any, options: any, theme: any) {
575
- const d = result.details as DelegateDetails | undefined;
575
+ const d = result.details as (DelegateDetails & { background?: boolean; description?: string }) | undefined;
576
+ // Background spawn: start details {runId, role, background, description}
577
+ // carry no state/duration/usage — the full-card path below would render
578
+ // ✗ unknown NaNs ↑0 ↓0. Neutral spawned card instead; runId guard keeps
579
+ // the slot/busy error details {background, busy} on the plain path.
580
+ if (d?.runId && d.background === true) {
581
+ return renderToolResultCard(theme, {
582
+ header: `→ ${String(d.runId).slice(-16)}`,
583
+ lead: d.role,
584
+ state: "spawned",
585
+ stateBits: d.description ? [d.description] : [],
586
+ detailLines: [{ text: " report arrives as a message · poll delegate_status" }],
587
+ });
588
+ }
576
589
  if (!d?.runId) {
577
590
  const text = (result.content ?? []).map((c: { text?: string }) => c.text ?? "").filter(Boolean).join("\n");
578
591
  return renderToolPlainCard(text);
@@ -823,7 +836,7 @@ export default function delegateExtension(pi: ExtensionAPI) {
823
836
  : "";
824
837
  const parts = text.split("\n\n");
825
838
  const body = parts.length > 2 ? parts.slice(2).join("\n\n") : text;
826
- return new Text(`? background ${d.runId ?? "?"}${d.description ? ` · ${d.description}` : ""}: asks (${d.topic ?? "?"})\n\n${body}`, 0, 0);
839
+ return new Text(`? background ${(d.runId ?? "?").slice(-12)}${d.description ? ` · ${d.description}` : ""}: asks (${d.topic ?? "?"})\n\n${body}`, 0, 0);
827
840
  });
828
841
 
829
842
  pi.registerMessageRenderer(CHILD_NOTE_TYPE, (message: { content?: string | unknown[]; details?: unknown }) => {
@@ -835,7 +848,7 @@ export default function delegateExtension(pi: ExtensionAPI) {
835
848
  : "";
836
849
  const parts = text.split("\n\n");
837
850
  const body = parts.length > 2 ? parts.slice(2).join("\n\n") : text;
838
- return new Text(`ℹ background ${d.runId ?? "?"}${d.description ? ` · ${d.description}` : ""}: note (${d.topic ?? "?"})\n\n${body}`, 0, 0);
851
+ return new Text(`ℹ background ${(d.runId ?? "?").slice(-12)}${d.description ? ` · ${d.description}` : ""}: note (${d.topic ?? "?"})\n\n${body}`, 0, 0);
839
852
  });
840
853
 
841
854
  // ── Handoff custom message renderer (§6.4) ─────────────────────────────
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maheidem/pi-delegate",
3
- "version": "0.6.2",
3
+ "version": "0.6.4",
4
4
  "type": "module",
5
5
  "description": "Foreground isolated delegation and strict coordinator mode for the Pi coding agent.",
6
6
  "license": "MIT",
package/ui/format.ts CHANGED
@@ -103,6 +103,8 @@ export function stateGlyph(state: string): { glyph: string; word: string; color:
103
103
  return { glyph: "⏱", word: "timeout · hard", color: "warning" };
104
104
  case "queued":
105
105
  return { glyph: "○", word: "queued", color: "muted" };
106
+ case "spawned":
107
+ return { glyph: "↗", word: "spawned", color: "muted" };
106
108
  default:
107
109
  return { glyph: "✗", word: state || "unknown", color: "error" };
108
110
  }