@arhen/pi-core-subagent 1.3.41 → 1.3.42

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arhen/pi-core-subagent",
3
- "version": "1.3.41",
3
+ "version": "1.3.42",
4
4
  "type": "module",
5
5
  "description": "pi extension: fast in-process subagents with a dependency-graph scheduler (needs edges gate tasks and carry upstream output into dependent prompts), plus background runs, intercom and agent-to-agent mailbox. Leader defines agents inline.",
6
6
  "license": "MIT",
package/src/format.ts CHANGED
@@ -250,6 +250,11 @@ export function makeSummary(run: RunSnapshot): string {
250
250
  return truncateText(lines.join("\n"));
251
251
  }
252
252
  /** Per-task notice: one task's outcome, small. Full output stays out of parent context. */
253
+ /** Dead on arrival: failed without ever producing assistant text — model/plan/auth/agent-file
254
+ * level, so every respawn with the same config fails identically. */
255
+ export function isStartupFailure(task: TaskSnapshot, kind: string): boolean {
256
+ return kind === "failed" && !task.finalText?.trim();
257
+ }
253
258
  export function makeTaskNotice(run: RunSnapshot, task: TaskSnapshot, kind: string): string {
254
259
  const goal = truncateText(task.task, 120);
255
260
  const detail = task.error ? task.error : truncateText(task.finalText || "(no output)", 200);
@@ -263,7 +268,9 @@ export function makeTaskNotice(run: RunSnapshot, task: TaskSnapshot, kind: strin
263
268
  return [
264
269
  `Task ${task.agent} (${task.id}) ${kind} in run ${run.id}: ${detail}${wt}`,
265
270
  `Goal: ${goal}${src}`,
266
- `Use subagent_result(runId: "${run.id}", taskId: "${task.id}") for full output.`,
271
+ isStartupFailure(task, kind)
272
+ ? "Never started — stop and diagnose before spawning anything else: a config-level error (model, plan, auth, agent file) fails identically on every respawn."
273
+ : `Use subagent_result(runId: "${run.id}", taskId: "${task.id}") for full output.`,
267
274
  ].join("\n");
268
275
  }
269
276
  /** Notification: 3 lines max. Full output stays out of parent context. */
package/src/index.ts CHANGED
@@ -157,7 +157,7 @@ export default function (pi: ExtensionAPI) {
157
157
  // ponytail: this string is billed on every request. No example block — an example
158
158
  // biases the model toward one shape; guidelines + JSON schema describe all of them.
159
159
  description:
160
- "Run isolated subagents (own context, own session). You invent each agent: name, optional system prompt, toolset (read-only default, write:true to edit). Use `agent`+`task` for one, `tasks` for many. `needs` declares dependency edges: a task waits for its needs and receives their outputs prepended to its prompt. If a user agent file in `.agents/agents`, `.claude/agents`, or `.pi/agents` (project dirs, then home) has a `description` matching the spawn goal (name + task), that file is authoritative: body = system prompt, frontmatter `model`/`tools` apply, inline prompt/model/tools ignored. No match → the inline definition stands. Write agents run in an isolated git worktree: on completion the result reports the branch + changed files — review, then merge with `git merge --no-ff <branch>` (merged branches are cleaned automatically). Every run is background: the call returns a runId immediately and completion notifies you. Set autoAwait:true when you need the result before your next step — the call parks until the run finishes and returns runId + final result in one response. allowIntercom:true lets children talk to you and each other.",
160
+ "Run isolated subagents (own context, own session). You invent each agent: name, optional system prompt, toolset (read-only default, write:true to edit). Use `agent`+`task` for one, `tasks` for many. `needs` declares dependency edges: a task waits for its needs and receives their outputs prepended to its prompt. If a user agent file in `.agents/agents`, `.claude/agents`, or `.pi/agents` (project dirs, then home) has a `description` matching the spawn goal (name + task), that file is authoritative: body = system prompt, frontmatter `model`/`tools` apply, inline prompt/model/tools ignored. No match → the inline definition stands. Write agents run in an isolated git worktree: on completion the result reports the branch + changed files — review, then merge with `git merge --no-ff <branch>` (merged branches are cleaned automatically). Every run is background: the call returns a runId immediately and completion notifies you — do NOT park waiting on it. If you have no other work, end your turn; the completion notice wakes you with the results. Set autoAwait:true only when the very next step in the SAME turn consumes the result. allowIntercom:true lets children talk to you and each other.",
161
161
  promptSnippet: "Define and delegate work to specialized subagents.",
162
162
  promptGuidelines: [
163
163
  "Use subagent when independent review, testing, research, or parallel analysis improves quality.",
@@ -167,8 +167,11 @@ export default function (pi: ExtensionAPI) {
167
167
  "End each task with a runnable check, e.g. 'Verify: npx tsc --noEmit && bun test'. A subagent's claim of success is not evidence.",
168
168
  "For write agents (write:true) in a git repo, the child works in an isolated worktree and its changes are committed to a branch — the result reports branch + changed files. Review the diff, then merge with `git merge --no-ff <branch>`; merged branches are cleaned up automatically. Never leave a worktree branch unmerged at the end of the task.",
169
169
  "Define each agent yourself: invented name, focused system prompt, and read-only (default) or write:true. Prefer read-only. A user agent file (`.agents/agents`, `.claude/agents`, `.pi/agents` — project first, then home) whose `description` matches the spawn goal (name + task) takes over: its body is the system prompt, frontmatter `model`/`tools` apply and are validated against the model registry. Matching is by description, not name — name the agent whatever fits the goal.",
170
- "When you need a run's result before your next step, spawn with autoAwait:true — the call returns runId + final result in one response. Otherwise spawn background and settle results (await_subagent / subagent_result) before continuing dependent work.",
171
- "For long multi-task runs, don't autoAwait the whole run: spawn background, then loop await_subagent with short timeoutMs slices (e.g. 20s), processing whichever tasks completed in each slice while the rest keep running. You get incremental results instead of one big wait.",
170
+ "Right after a background spawn, call subagent_status(runId) ONCE before any other work — confirm each task is running (or already progressing), not stuck queued or failed at startup. A child that dies on spawn otherwise stays invisible until far later.",
171
+ "If that first status shows a task failed or never started, fix or respawn immediately; do not move on assuming it runs.",
172
+ "Never block with nothing to do: if you have no work left after spawning, end your turn. Task completion notifies you and wakes a fresh turn with the results — await_subagent/autoAwait in that situation only burns time and tokens.",
173
+ "autoAwait:true only when the same turn must consume the result immediately (e.g. you spawn a reviewer and then must act on its verdict before replying). Otherwise spawn background and read results from the completion notice, or subagent_result when you come back.",
174
+ "await_subagent is for the rare case where you have parallel work of your own and need to sync at a specific point — not the default follow-up to a spawn.",
172
175
  "allowIntercom:true only when a child may need to ask you something.",
173
176
  ],
174
177
  parameters: SubagentParams,
@@ -218,7 +221,7 @@ export default function (pi: ExtensionAPI) {
218
221
  content: [
219
222
  {
220
223
  type: "text",
221
- text: `Background run started: ${details.run.id} (${details.run.mode}, ${details.run.tasks.length} task${details.run.tasks.length > 1 ? "s" : ""}).\nUse subagent_status / subagent_result / await_subagent / reply_subagent / subagent_cancel to interact.`,
224
+ text: `Background run started: ${details.run.id} (${details.run.mode}, ${details.run.tasks.length} task${details.run.tasks.length > 1 ? "s" : ""}).\nNext: call subagent_status("${details.run.id}") now to confirm the tasks actually started before doing anything else.\nAfter that, completion will notify you — if you have no other work, end your turn instead of waiting.\nOther tools: subagent_result / reply_subagent / steer_subagent / subagent_cancel.`,
222
225
  },
223
226
  ],
224
227
  details,
@@ -300,8 +303,11 @@ export default function (pi: ExtensionAPI) {
300
303
  name: "subagent_status",
301
304
  label: "Subagent Status",
302
305
  description:
303
- "Live status of a subagent run (non-blocking): per-task state, plus each child's session file path (JSONL) so you can tail it from outside — e.g. in a terminal multiplexer pane.",
304
- promptSnippet: "Check progress of a subagent run.",
306
+ "Live status of a subagent run (non-blocking): per-task state, plus each child's session file path (JSONL) so you can tail it from outside — e.g. in a terminal multiplexer pane. Call this once right after spawning to verify the children actually started.",
307
+ promptSnippet: "Check progress of a subagent run; use right after spawn as a health check.",
308
+ promptGuidelines: [
309
+ "Health-check every background spawn with one subagent_status(runId) before continuing — catch dead-on-arrival children early instead of at completion time.",
310
+ ],
305
311
  parameters: RunIdParam,
306
312
  async execute(_id, params) {
307
313
  const { runId } = params as { runId: string };
@@ -348,7 +354,10 @@ export default function (pi: ExtensionAPI) {
348
354
  name: "await_subagent",
349
355
  label: "Await Subagent",
350
356
  description:
351
- "Block until a run finishes (or timeoutMs elapses). While parked, child→leader messages (asks, notifies, completions) wake the wait and arrive INSIDE the result — the await doubles as the run's intercom drain, no steering queue involved.",
357
+ "Block until a run finishes (or timeoutMs elapses). Use ONLY when you have work of your own to sync with; if you have nothing else to do, end your turn instead — completion notifies you and wakes a new turn with the results. While parked, child→leader messages (asks, notifies, completions) wake the wait and arrive INSIDE the result.",
358
+ promptGuidelines: [
359
+ "Do not call await_subagent right after spawning with no other work pending — end the turn and let the completion notice wake you.",
360
+ ],
352
361
  parameters: AwaitParam,
353
362
  async execute(_id, params) {
354
363
  const { runId, timeoutMs } = params as { runId: string; timeoutMs?: number };
package/src/manager.ts CHANGED
@@ -25,6 +25,7 @@ import {
25
25
  isTalking,
26
26
  makeNotice,
27
27
  makeTaskNotice,
28
+ isStartupFailure,
28
29
  SubagentsWidget,
29
30
  truncateText,
30
31
  } from "./format.ts";
@@ -462,7 +463,16 @@ export class SubagentManager {
462
463
  this.pi.events.emit(type, { type, timestamp: Date.now(), ...payload });
463
464
  }
464
465
 
465
- /** Per-task wake-up: queued follow-up so the parent can interleave responses. */
466
+ /** Only startup failures are forced: they're dead-on-arrival and the leader must
467
+ * notice before it respawns the same broken config. Completed/aborted and even
468
+ * mid-run failures wait for the turn's end (followUp) — they're not urgent and
469
+ * steering every one of them would interrupt the leader mid-tool-call.
470
+ * force = deliver immediately even while streaming (steer). */
471
+ private deliverMode(kind: string, task: TaskSnapshot): "steer" | "followUp" {
472
+ return isStartupFailure(task, kind) ? "steer" : "followUp";
473
+ }
474
+
475
+ /** Per-task wake-up: failures steer in immediately, the rest queue as follow-up. */
466
476
  private notifyTask(run: RunSnapshot, task: TaskSnapshot, kind: "completed" | "failed" | "aborted"): void {
467
477
  const body = makeTaskNotice(run, task, kind);
468
478
  // Parked leader (await_subagent) receives completions through the wait — no queue.
@@ -471,7 +481,7 @@ export class SubagentManager {
471
481
  return;
472
482
  }
473
483
  try {
474
- this.pi.sendUserMessage(body, { deliverAs: "followUp" });
484
+ this.pi.sendUserMessage(body, { deliverAs: this.deliverMode(kind, task) });
475
485
  } catch {
476
486
  /* parent mid-stream; consumers can poll subagent_status */
477
487
  }
@@ -479,8 +489,8 @@ export class SubagentManager {
479
489
  }
480
490
 
481
491
  /** Wake the parent with a 3-line notice. Full text stays out of context.
482
- * deliverAs followUp queues the message if the parent is mid-stream
483
- * (e.g. inside await_subagent) instead of throwing/aborting. */
492
+ * deliverAs queues the message if the parent is mid-stream (e.g. inside
493
+ * await_subagent) instead of throwing/aborting. */
484
494
  private notifyParent(
485
495
  run: RunSnapshot,
486
496
  kind: "completed" | "failed" | "aborted" | "asked",