@deathbeam/pi-delegate 0.0.8 → 0.0.10

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.
Files changed (3) hide show
  1. package/child.ts +21 -13
  2. package/index.ts +5 -5
  3. package/package.json +1 -1
package/child.ts CHANGED
@@ -9,7 +9,11 @@ function usageTokens(usage: any): number | undefined {
9
9
  return tokens > 0 ? tokens : undefined;
10
10
  }
11
11
 
12
- export type ChildActivity = { kind: "tool" | "result" | "assistant" | "status"; text: string; detail?: string };
12
+ export type ChildActivity = {
13
+ kind: "tool" | "result" | "assistant" | "user" | "status";
14
+ text: string;
15
+ detail?: string;
16
+ };
13
17
  export type ChildUpdate = {
14
18
  toolCalls?: number;
15
19
  lastTool?: string;
@@ -138,30 +142,34 @@ export function runChild(
138
142
  return;
139
143
  }
140
144
  case "message_update": {
141
- const contextTokens = usageTokens(event.usage);
142
145
  const delta =
143
146
  event.assistantMessageEvent?.type === "text_delta"
144
147
  ? (event.assistantMessageEvent.delta ?? "")
145
148
  : "";
146
149
  if (delta) liveText += delta;
147
- if (contextTokens !== undefined) onUpdate?.({ contextTokens });
150
+ onUpdate?.({ contextTokens: usageTokens(event.usage) });
148
151
  return;
149
152
  }
150
153
  case "message_end": {
151
- if (event.message?.role !== "assistant") return;
152
- childError = event.message.errorMessage;
154
+ const role = event.message?.role;
155
+ if (role !== "assistant" && role !== "user") return;
156
+ const content = event.message.content;
153
157
  const text =
154
- event.message.content
155
- ?.filter((part: any) => part.type === "text")
156
- .map((part: any) => part.text ?? "")
157
- .join("") ?? "";
158
- if (text) {
159
- liveText = text;
158
+ typeof content === "string"
159
+ ? content
160
+ : (content
161
+ ?.filter((part: any) => part.type === "text")
162
+ .map((part: any) => part.text ?? "")
163
+ .join("") ?? "");
164
+ if (role === "assistant") {
165
+ childError = event.message.errorMessage;
166
+ if (text) liveText = text;
167
+ }
168
+ if (text)
160
169
  onUpdate?.({
161
170
  contextTokens: usageTokens(event.message.usage),
162
- activity: { kind: "assistant", text },
171
+ activity: { kind: role, text },
163
172
  });
164
- }
165
173
  return;
166
174
  }
167
175
  case "agent_settled":
package/index.ts CHANGED
@@ -191,7 +191,7 @@ export default function (pi: ExtensionAPI) {
191
191
  const addActivity = (job: DelegateJob, activity: ChildActivity) => {
192
192
  const normalize = (text: string) => text.replace(/\s+/g, " ").trim();
193
193
  job.activity.push(
194
- activity.kind === "assistant"
194
+ activity.kind === "assistant" || activity.kind === "user"
195
195
  ? activity
196
196
  : {
197
197
  ...activity,
@@ -376,13 +376,13 @@ export default function (pi: ExtensionAPI) {
376
376
  ].slice(0, bodyHeight());
377
377
  };
378
378
  const renderEntry = (entry: ChildActivity, width: number): string[] => {
379
- if (entry.kind === "assistant") {
379
+ if (entry.kind === "assistant" || entry.kind === "user") {
380
380
  let md = markdown.get(entry);
381
381
  if (!md) {
382
382
  md = new Markdown(entry.text, 0, 0, getMarkdownTheme());
383
383
  markdown.set(entry, md);
384
384
  }
385
- return [theme.fg("accent", "assistant"), ...md.render(width), ""];
385
+ return [theme.fg("accent", entry.kind), ...md.render(width), ""];
386
386
  }
387
387
  if (entry.kind === "tool")
388
388
  return [
@@ -546,7 +546,7 @@ export default function (pi: ExtensionAPI) {
546
546
  promptSnippet: "Delegate a focused task to a background agent; the result arrives later as a follow-up message",
547
547
  promptGuidelines: [
548
548
  "While delegates run, stay outside their scopes; delegate any new context-heavy investigation before tracing it yourself. When a report is the next dependency, end your turn with a brief waiting status. Completion will wake you.",
549
- "Read every required delegate report before claiming the task is done. Never sleep or poll for a report. Use delegate_list only for a one-time status check.",
549
+ "Read every required delegate report before claiming the task is done. Never sleep, poll, or call any tool solely to wait (including `bash` with `true`, `echo`, or `sleep 0`). Use delegate_list only for a one-time status check.",
550
550
  ],
551
551
  parameters: Type.Object({
552
552
  agent: Type.String({ description: "Agent name, one of the agents listed in the <agents> prompt section." }),
@@ -636,7 +636,7 @@ export default function (pi: ExtensionAPI) {
636
636
  content: [
637
637
  {
638
638
  type: "text",
639
- text: `Started agent "${job.agent}" in the background (job ${job.id}). Steer it with delegate_steer or stop it with delegate_cancel. Do not sleep or poll: its report arrives automatically unless cancelled.`,
639
+ text: `Started agent "${job.agent}" in the background (job ${job.id}). Steer it with delegate_steer or stop it with delegate_cancel. Do not call tools solely to wait, even no-op bash commands; when its report is your next dependency, end your turn and it will arrive automatically unless cancelled.`,
640
640
  },
641
641
  ],
642
642
  details,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deathbeam/pi-delegate",
3
- "version": "0.0.8",
3
+ "version": "0.0.10",
4
4
  "description": "Run focused Pi subagents as background tasks",
5
5
  "type": "module",
6
6
  "license": "MIT",