@pi-archimedes/subagent 1.9.0 → 2.0.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Daniel Cherubini and contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -5,10 +5,11 @@ Subagent dispatch with live TUI streaming and cost tracking for the [Pi coding a
5
5
  ## Features
6
6
 
7
7
  - **Single & parallel execution** — dispatch one task or fan out multiple tasks across different agents simultaneously
8
- - **Live TUI streaming** — watch subagent progress in real-time with tool calls, token counts, and cost updates
8
+ - **Live TUI streaming** — watch subagent progress in real-time with color-coded tool calls (grey while running, green/red on completion), readable argument previews, token counts, and cost updates
9
9
  - **Agent discovery** — auto-discovers agents from `.pi/agents/*.md` files at project, user, and global scope
10
10
  - **Per-agent model override** — each subagent can use its own model, falling back to the parent's selection
11
11
  - **Cost tracking** — detailed token usage (input, output, cache read/write) and cost per subagent, emitted through the core bus for the footer to consume
12
+ - **Trace correlation** — results expose the ephemeral child's logical Pi session UUID as optional `childSessionId` when Pi emits a valid session event
12
13
  - **`/agents` command** — full CRUD TUI for managing agent definitions with model picker, tool picker, and cross-scope collision warnings (available via the meta package)
13
14
 
14
15
  ## Screenshots
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-archimedes/subagent",
3
- "version": "1.9.0",
3
+ "version": "2.0.1",
4
4
  "type": "module",
5
5
  "keywords": [
6
6
  "pi-package"
@@ -11,7 +11,7 @@
11
11
  ],
12
12
  "main": "./src/index.ts",
13
13
  "dependencies": {
14
- "@pi-archimedes/core": "1.9.0"
14
+ "@pi-archimedes/core": "2.0.1"
15
15
  },
16
16
  "peerDependencies": {
17
17
  "@earendil-works/pi-ai": ">=0.1.0",
package/src/index.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import type { ExtensionAPI, ExtensionCommandContext, ExtensionContext, Theme } from "@earendil-works/pi-coding-agent";
2
2
  import { Text, TUI } from "@earendil-works/pi-tui";
3
3
  import { Type } from "typebox";
4
- // execute.js + agent-manager.js lazy-loaded below to keep subagent tool registration fast
4
+ import { executeSubagent, executeParallel } from "./execute.js";
5
+ // agent-manager.js lazy-loaded below to keep subagent tool registration fast
5
6
  import { renderSubagentResult } from "./render.js";
6
7
  import { discoverAgents, discoverAgentsAll, findAgent, formatAgentList } from "./agents.js";
7
8
  import { validateModel, firstError } from "./model-validation.js";
@@ -75,8 +76,6 @@ export function registerSubagent(pi: ExtensionAPI): void {
75
76
  onUpdate: ((update: SubagentToolResult) => void) | undefined,
76
77
  ctx: ExtensionContext,
77
78
  ): Promise<SubagentToolResult> {
78
- // Lazy-load executor (spawn/stream/cost) — only when tool is actually invoked
79
- const { executeSubagent, executeParallel } = await import("./execute.js");
80
79
  const agents = discoverAgents(ctx.cwd);
81
80
 
82
81
  // Parallel mode
@@ -0,0 +1,47 @@
1
+ import { EventEmitter } from "node:events";
2
+ import { PassThrough } from "node:stream";
3
+ import type { ChildProcess } from "node:child_process";
4
+ import { describe, expect, it } from "vitest";
5
+ import { streamEvents } from "./stream.js";
6
+
7
+ type FakeChild = ChildProcess & { stdout: PassThrough; stderr: PassThrough };
8
+
9
+ function fakeChild(): FakeChild {
10
+ const child = new EventEmitter() as FakeChild;
11
+ Object.assign(child, {
12
+ stdout: new PassThrough(),
13
+ stderr: new PassThrough(),
14
+ kill: () => true,
15
+ });
16
+ return child;
17
+ }
18
+
19
+ async function finishWith(events: Array<Record<string, unknown>>) {
20
+ const child = fakeChild();
21
+ const result = streamEvents(child);
22
+ for (const event of events) {
23
+ child.stdout.write(`${JSON.stringify(event)}\n`);
24
+ }
25
+ child.emit("close", 0);
26
+ return result;
27
+ }
28
+
29
+ describe("streamEvents session identity", () => {
30
+ it("returns the logical child Pi session ID", async () => {
31
+ const result = await finishWith([{
32
+ type: "session",
33
+ id: "00000000-0000-7000-8000-000000000003",
34
+ }]);
35
+
36
+ expect(result.childSessionId).toBe("00000000-0000-7000-8000-000000000003");
37
+ });
38
+
39
+ it("omits the child session ID when no valid session event arrives", async () => {
40
+ const result = await finishWith([
41
+ { type: "session" },
42
+ { type: "session", id: 42 },
43
+ ]);
44
+
45
+ expect(result.childSessionId).toBeUndefined();
46
+ });
47
+ });
package/src/stream.ts CHANGED
@@ -127,6 +127,12 @@ export function streamEvents(
127
127
  clearStartupTimer();
128
128
 
129
129
  switch (event.type) {
130
+ case "session": {
131
+ if (typeof event.id === "string" && event.id) {
132
+ state.childSessionId = event.id;
133
+ }
134
+ break;
135
+ }
130
136
  case "tool_execution_start": {
131
137
  handleToolStart(state, event);
132
138
  emitProgress();
@@ -163,7 +169,7 @@ export function streamEvents(
163
169
  handleAgentEnd(state, event);
164
170
  break;
165
171
  }
166
- // Ignore: session, agent_start, message_start, message_update, turn_end, tool_execution_update
172
+ // Ignore: agent_start, message_start, message_update, turn_end, tool_execution_update
167
173
  }
168
174
  });
169
175
 
@@ -183,6 +189,7 @@ export function streamEvents(
183
189
  const result: SubagentResult = {
184
190
  agent: callbacks.agent ?? "subagent",
185
191
  task: callbacks.task ?? "",
192
+ ...(state.childSessionId ? { childSessionId: state.childSessionId } : {}),
186
193
  exitCode,
187
194
  model: state.model,
188
195
  usage: {
package/src/types.ts CHANGED
@@ -40,6 +40,8 @@ export interface SubagentProgress {
40
40
  export interface SubagentResult {
41
41
  agent: string;
42
42
  task: string;
43
+ /** Logical Pi session UUID for this spawned subagent process. */
44
+ childSessionId?: string;
43
45
  exitCode: number;
44
46
  usage: SubagentUsage;
45
47
  model: string | undefined;
@@ -63,6 +65,7 @@ export interface SubagentDetails {
63
65
 
64
66
  /** Mutable state during streaming — shared between stream.ts and handlers.ts */
65
67
  export interface StreamState {
68
+ childSessionId?: string;
66
69
  toolCount: number;
67
70
  turnCount: number;
68
71
  totalInput: number;