@arhen/pi-core-subagent 1.1.3 → 1.1.5

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.ts +12 -8
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arhen/pi-core-subagent",
3
- "version": "1.1.3",
3
+ "version": "1.1.5",
4
4
  "type": "module",
5
5
  "description": "pi extension: fast in-process subagents with single/parallel/chain, background runs, intercom and agent-to-agent mailbox. Leader defines agents inline.",
6
6
  "license": "MIT",
package/src/index.ts CHANGED
@@ -59,6 +59,7 @@ interface TaskInput {
59
59
  tools?: string[];
60
60
  model?: string;
61
61
  thinking?: string;
62
+ cwd?: string;
62
63
  maxRuntimeMs?: number;
63
64
  }
64
65
 
@@ -539,20 +540,20 @@ class SubagentManager {
539
540
  this.ensureWidget(ctx);
540
541
  this.widgetTui?.requestRender();
541
542
  }
542
- onUpdate?.({ content: [{ type: "text", text: targets.flatMap(compactLines).join("\n") }] });
543
+ onUpdate?.({ content: [{ type: "text", text: compactLines(run ?? targets[0]!).join("\n") }] });
543
544
  }, WIDGET_THROTTLE_MS);
544
545
  }
545
- private flushWidget(ctx?: ExtensionContext, onUpdate?: (partial: any) => void): void {
546
+ private flushWidget(run: RunSnapshot | undefined, ctx?: ExtensionContext, onUpdate?: (partial: any) => void): void {
546
547
  if (this.widgetTimer) {
547
548
  clearTimeout(this.widgetTimer);
548
549
  this.widgetTimer = undefined;
549
550
  }
550
- if (this.widgetRuns.length === 0) return;
551
+ if (!run || this.widgetRuns.length === 0) return;
551
552
  if (ctx?.hasUI) {
552
553
  this.ensureWidget(ctx);
553
554
  this.widgetTui?.requestRender();
554
555
  }
555
- onUpdate?.({ content: [{ type: "text", text: this.widgetRuns.flatMap(compactLines).join("\n") }] });
556
+ onUpdate?.({ content: [{ type: "text", text: compactLines(run).join("\n") }] });
556
557
  }
557
558
  private ensureWidget(ctx: ExtensionContext): void {
558
559
  if (this.widgetTui !== null || !ctx.hasUI) return;
@@ -814,7 +815,7 @@ class SubagentManager {
814
815
 
815
816
  const mode: RunMode = hasChain ? "chain" : hasTasks ? "parallel" : "single";
816
817
  const inputs: TaskInput[] = hasSingle
817
- ? [{ agent: params.agent as string, task: params.task as string, prompt: params.prompt, write: params.write, model: params.model, thinking: params.thinking, tools: params.tools, maxRuntimeMs: params.maxRuntimeMs }]
818
+ ? [{ agent: params.agent as string, task: params.task as string, prompt: params.prompt, write: params.write, model: params.model, thinking: params.thinking, cwd: params.cwd, tools: params.tools, maxRuntimeMs: params.maxRuntimeMs }]
818
819
  : hasTasks
819
820
  ? params.tasks!
820
821
  : params.chain!;
@@ -834,7 +835,7 @@ class SubagentManager {
834
835
  runId: "",
835
836
  agent: input.agent,
836
837
  task: input.task,
837
- cwd: ctx.cwd,
838
+ cwd: input.cwd ?? ctx.cwd,
838
839
  status: "queued" as TaskStatus,
839
840
  model: input.model,
840
841
  thinking: input.thinking,
@@ -898,7 +899,7 @@ class SubagentManager {
898
899
  const aborted = run.tasks.some((t) => t.status === "aborted") || Boolean(signal?.aborted);
899
900
  run.status = aborted ? "aborted" : failed ? "failed" : "completed";
900
901
  run.endedAt = Date.now();
901
- this.flushWidget(ctx, onUpdate);
902
+ this.flushWidget(run, ctx, onUpdate);
902
903
  // Run done: keep the widget only while another run is still live.
903
904
  const live = this.listRuns().find((r) => !TERMINAL.includes(r.status));
904
905
  if (live) {
@@ -1013,6 +1014,7 @@ const TaskItem = Type.Object({
1013
1014
  write: Type.Optional(Type.Boolean({ description: "true = write toolset (read, bash, edit, write); default false = read-only (read, grep, find, ls)" })),
1014
1015
  model: Type.Optional(Type.String({ description: "Model override (provider/model-id)" })),
1015
1016
  thinking: Type.Optional(StringEnum(THINKING_LEVELS, { description: "Thinking level override" })),
1017
+ cwd: Type.Optional(Type.String({ description: "Working directory for this task. Default: current project." })),
1016
1018
  tools: Type.Optional(Type.Array(Type.String(), { description: "Explicit tool allowlist (overrides the toolset)" })),
1017
1019
  maxRuntimeMs: Type.Optional(Type.Number({ description: "Per-task timeout (ms)" })),
1018
1020
  });
@@ -1026,6 +1028,7 @@ type SubagentParamsShape = {
1026
1028
  chain?: TaskInput[];
1027
1029
  model?: string;
1028
1030
  thinking?: string;
1031
+ cwd?: string;
1029
1032
  tools?: string[];
1030
1033
  concurrency?: number;
1031
1034
  maxRuntimeMs?: number;
@@ -1043,6 +1046,7 @@ const SubagentParams = Type.Object({
1043
1046
  chain: Type.Optional(Type.Array(TaskItem, { description: "Sequential tasks; {previous} = prior output" })),
1044
1047
  model: Type.Optional(Type.String({ description: "Model override (single mode)" })),
1045
1048
  thinking: Type.Optional(StringEnum(THINKING_LEVELS, { description: "Thinking level override (single mode)" })),
1049
+ cwd: Type.Optional(Type.String({ description: "Working directory (single mode). Default: current project." })),
1046
1050
  concurrency: Type.Optional(Type.Number({ description: `Parallel concurrency (default ${DEFAULT_CONCURRENCY}, max ${MAX_CONCURRENCY})` })),
1047
1051
  maxRuntimeMs: Type.Optional(Type.Number({ description: `Per-task timeout, ms (default ${DEFAULT_RUNTIME_MS / 60000} min)` })),
1048
1052
  background: Type.Optional(Type.Boolean({ description: "Fire-and-forget: return immediately with a runId; you'll be notified on completion" })),
@@ -1109,7 +1113,7 @@ export default function (pi: ExtensionAPI) {
1109
1113
  promptSnippet: "Define and delegate work to specialized subagents.",
1110
1114
  promptGuidelines: [
1111
1115
  "Use subagent when independent review, testing, research, or parallel analysis improves quality.",
1112
- "Decompose parallelizable work: if the request has 2+ independent sub-tasks (separate files, separate concerns, independent research/review), delegate each to its own subagent in one parallel call instead of handling them inline.",
1116
+ "Decompose parallelizable work: if the request has 2+ independent sub-tasks (separate files, separate concerns, independent research/review), delegate each to its own subagent in ONE call with tasks[] (single shot), not multiple parallel subagent calls.",
1113
1117
  "If independent sub-tasks are sequential (each builds on the previous one's output), use chain mode with {previous}.",
1114
1118
  "Define each subagent yourself: an invented name, a focused system prompt (prompt:), and a toolset — read-only (default) or write (write:true).",
1115
1119
  "Prefer read-only subagents unless the task explicitly needs edits.",