@deathbeam/pi-delegate 0.0.33 → 0.0.35

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
@@ -15,12 +15,10 @@ export type ChildActivity = {
15
15
  kind: "tool" | "result" | "assistant" | "user" | "status";
16
16
  text: string;
17
17
  detail?: string;
18
+ isError?: boolean;
18
19
  };
19
20
  export type ChildUpdate = {
20
21
  toolCalls?: number;
21
- lastTool?: string;
22
- lastDetail?: string;
23
- lastResult?: string;
24
22
  contextTokens?: number;
25
23
  activity?: ChildActivity;
26
24
  };
@@ -132,9 +130,6 @@ export function runChild(
132
130
  const detail = toolCallDetail(event.toolName, event.args);
133
131
  onUpdate?.({
134
132
  toolCalls,
135
- lastTool: event.toolName,
136
- lastDetail: detail,
137
- lastResult: "",
138
133
  activity: { kind: "tool", text: event.toolName, detail },
139
134
  });
140
135
  return;
@@ -142,10 +137,10 @@ export function runChild(
142
137
  case "tool_execution_end": {
143
138
  const preview = resultPreview(event.result);
144
139
  onUpdate?.({
145
- lastResult: preview,
146
140
  activity: {
147
141
  kind: "result",
148
- text: `↳ ${event.toolName}${event.isError ? " ✗" : ""}: ${preview ?? "(no text output)"}`,
142
+ text: preview ?? "",
143
+ ...(event.isError ? { isError: true } : {}),
149
144
  },
150
145
  });
151
146
  return;
@@ -357,7 +352,7 @@ export function priorActivity(sessionDir: string, id: string): ChildActivity[] {
357
352
  ? (entry.message as {
358
353
  role?: "assistant" | "user" | "toolResult";
359
354
  content?: unknown;
360
- toolName?: string;
355
+ isError?: boolean;
361
356
  })
362
357
  : undefined;
363
358
  if (!message?.role) continue;
@@ -365,7 +360,8 @@ export function priorActivity(sessionDir: string, id: string): ChildActivity[] {
365
360
  const preview = resultPreview({ content: message.content });
366
361
  activity.push({
367
362
  kind: "result",
368
- text: normalize(`↳ ${message.toolName ?? "tool"}: ${preview ?? "(no text output)"}`),
363
+ text: normalize(preview ?? ""),
364
+ ...(message.isError ? { isError: true } : {}),
369
365
  });
370
366
  continue;
371
367
  }
package/index.ts CHANGED
@@ -30,7 +30,7 @@ import {
30
30
  widgetJobs,
31
31
  } from "./format.ts";
32
32
  import { priorActivity, runChild } from "./child.ts";
33
- import { createJobStore, type DelegateJob, type InspectJob } from "./store.ts";
33
+ import { createJobStore, type DelegateJob, lastToolCall, type InspectJob } from "./store.ts";
34
34
  import {
35
35
  applyClone,
36
36
  cloneCwd,
@@ -162,11 +162,15 @@ export default function (pi: ExtensionAPI) {
162
162
  `${statusText(theme, "running", now)} ${jobIdentity(theme, job)} ${theme.fg("muted", jobLine(job, elapsedMs(job, now)))}`,
163
163
  );
164
164
  if (!detail) continue;
165
- if (job.lastTool)
165
+ const { tool, result } = lastToolCall(job);
166
+ if (tool)
166
167
  lines.push(
167
- ` ${theme.fg("toolTitle", theme.bold(job.lastTool))}${job.lastDetail ? ` ${theme.fg("accent", job.lastDetail)}` : ""}`,
168
+ ` ${theme.fg("toolTitle", theme.bold(tool.text))}${tool.detail ? ` ${theme.fg("accent", tool.detail)}` : ""}`,
169
+ );
170
+ if (result?.text)
171
+ lines.push(
172
+ ` ${theme.fg("muted", "↳")} ${theme.fg(result.isError ? "error" : "toolOutput", result.text)}`,
168
173
  );
169
- if (job.lastResult) lines.push(` ${theme.fg("muted", "↳")} ${theme.fg("toolOutput", job.lastResult)}`);
170
174
  }
171
175
  if (hidden) lines.push(` ${theme.fg("muted", `… ${hidden} more running`)}`);
172
176
  ctx.ui.setWidget(WIDGET_KEY, lines);
@@ -271,19 +275,20 @@ export default function (pi: ExtensionAPI) {
271
275
  const entrypoint = process.argv[1];
272
276
  if (!entrypoint) throw new Error("Pi CLI entrypoint missing; start Pi from its CLI to delegate.");
273
277
  const cwd = isolation ? cloneCwd(isolation, ctx.cwd) : ctx.cwd;
278
+ if (isolation)
279
+ args.push(
280
+ "--append-system-prompt",
281
+ `You are working in an isolated git clone at ${isolation.clone}. Your working directory is ${cwd}; run every command from it with relative paths. Any path under ${ctx.cwd} means the same file under ${cwd}. Your edits and commits stay in this clone until the orchestrator applies them.${tools.includes("bash") ? " `git diff main-snapshot` shows every change made in this clone." : ""}`,
282
+ );
274
283
  const child = spawn(process.execPath, [entrypoint, "--mode", "rpc", ...args], {
275
284
  cwd,
276
285
  shell: false,
277
286
  stdio: "pipe",
278
287
  });
279
288
  store.launch(job);
280
- // The brief was written against the main tree, so its absolute paths need mapping to the clone.
281
- const isolatedPrompt = isolation
282
- ? `You are working in an isolated git clone at ${isolation.clone}. Your working directory ${cwd} is already inside it, so use relative paths and do not cd into it. Paths under ${ctx.cwd} in the task refer to the same files under ${cwd}. The main working tree is untouched; any edits or commits you make stay in this clone until the orchestrator applies them.${tools.includes("bash") ? " `git diff main-snapshot` shows all changes made in this clone." : ""}`
283
- : "";
284
289
  const run = runChild(
285
290
  child,
286
- isolatedPrompt ? `${isolatedPrompt}\n\n${prompt}` : prompt,
291
+ prompt,
287
292
  // Foreground runs also stop on the tool's own abort (Esc); delegate_cancel and shutdown use the controller.
288
293
  details.background || !signal ? job.controller.signal : AbortSignal.any([signal, job.controller.signal]),
289
294
  (update) => store.record(job, update),
@@ -769,10 +774,8 @@ export default function (pi: ExtensionAPI) {
769
774
  if (!jobs.length) return { content: [{ type: "text", text: "No delegates yet." }], details: undefined };
770
775
  const running = jobs.filter((job) => job.status === "running").length;
771
776
  const lastActivity = (job: InspectJob) => {
772
- const { lastTool, lastDetail } = job as DelegateJob;
773
- return job.status === "running" && lastTool
774
- ? ` · ${lastTool}${lastDetail ? ` ${lastDetail}` : ""}`
775
- : "";
777
+ const { tool } = lastToolCall(job);
778
+ return job.status === "running" && tool ? ` · ${tool.text}${tool.detail ? ` ${tool.detail}` : ""}` : "";
776
779
  };
777
780
  const lines = jobs.map((job) => {
778
781
  const tag = isolationWords(job);
package/inspector.ts CHANGED
@@ -72,12 +72,18 @@ export function registerInspector(pi: ExtensionAPI, store: JobStore) {
72
72
  if (entry.kind === "tool")
73
73
  return [
74
74
  truncateToWidth(
75
- theme.fg("toolTitle", entry.text) +
75
+ theme.fg("toolTitle", theme.bold(entry.text)) +
76
76
  (entry.detail ? ` ${theme.fg("accent", entry.detail)}` : ""),
77
77
  width,
78
78
  ),
79
79
  ];
80
- if (entry.kind === "result") return [truncateToWidth(theme.fg("text", entry.text), width)];
80
+ if (entry.kind === "result")
81
+ return [
82
+ truncateToWidth(
83
+ ` ${theme.fg("muted", "↳")} ${theme.fg(entry.isError ? "error" : "toolOutput", entry.text || "(no text output)")}`,
84
+ width,
85
+ ),
86
+ ];
81
87
  // Only failure detail still says anything; the header icon carries the status.
82
88
  if (!entry.text) return [];
83
89
  return [truncateToWidth(theme.fg(STATUS_COLORS.failed, entry.text), width)];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deathbeam/pi-delegate",
3
- "version": "0.0.33",
3
+ "version": "0.0.35",
4
4
  "description": "Minimal extension for delegating tasks to subagents.",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/store.ts CHANGED
@@ -21,10 +21,14 @@ export type InspectJob = {
21
21
  cloneClosed?: boolean;
22
22
  };
23
23
 
24
+ /** The job's latest tool call and its result, once the result arrives. */
25
+ export function lastToolCall(job: InspectJob): { tool?: ChildActivity; result?: ChildActivity } {
26
+ const at = job.activity.findLastIndex((entry) => entry.kind === "tool");
27
+ if (at < 0) return {};
28
+ return { tool: job.activity[at], result: job.activity.slice(at + 1).find((entry) => entry.kind === "result") };
29
+ }
30
+
24
31
  export type DelegateJob = InspectJob & {
25
- lastTool?: string;
26
- lastDetail?: string;
27
- lastResult?: string;
28
32
  controller: AbortController;
29
33
  steer?: (message: string) => Promise<void>;
30
34
  swapModel?: (provider: string, modelId: string, level?: string, onModelSet?: () => void) => Promise<void>;
@@ -61,10 +65,9 @@ export function createJobStore(append: (customType: string, data: InspectJob) =>
61
65
  if (stale >= 0) history.splice(stale, 1);
62
66
  };
63
67
  const find = (id: string) => running.get(id) ?? history.find((item) => item.id === id);
64
- /** The serializable form of a job: runtime handles and the latest tool detail stay out. */
68
+ /** The serializable form of a job: runtime handles stay out. */
65
69
  const snapshot = (job: InspectJob): InspectJob => {
66
- const { controller, steer, swapModel, lastTool, lastDetail, lastResult, ...plain } = job as InspectJob &
67
- Partial<DelegateJob>;
70
+ const { controller, steer, swapModel, ...plain } = job as InspectJob & Partial<DelegateJob>;
68
71
  // Copy activity: the live job keeps appending to its own array after the launch snapshot.
69
72
  return { ...plain, activity: [...plain.activity] };
70
73
  };
@@ -104,9 +107,6 @@ export function createJobStore(append: (customType: string, data: InspectJob) =>
104
107
  record: (job: DelegateJob, update: ChildUpdate) => {
105
108
  if (job.status !== "running") return;
106
109
  if (update.toolCalls !== undefined) job.toolCalls = update.toolCalls;
107
- if (update.lastTool !== undefined) job.lastTool = update.lastTool;
108
- if (update.lastDetail !== undefined) job.lastDetail = update.lastDetail;
109
- if (update.lastResult !== undefined) job.lastResult = update.lastResult;
110
110
  if (update.contextTokens !== undefined) job.contextTokens = update.contextTokens;
111
111
  if (update.activity) addActivity(job, update.activity);
112
112
  },