pi-subagents 0.8.2 ā 0.8.4
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/CHANGELOG.md +30 -1
- package/README.md +43 -18
- package/agent-management.ts +7 -0
- package/agent-manager-detail.ts +4 -0
- package/agent-manager-edit.ts +4 -2
- package/agent-scope.ts +6 -0
- package/agent-selection.ts +20 -0
- package/agent-serializer.ts +6 -0
- package/agents.ts +13 -12
- package/artifacts.ts +23 -1
- package/async-execution.ts +8 -18
- package/chain-execution.ts +15 -7
- package/completion-dedupe.ts +63 -0
- package/execution.ts +36 -13
- package/file-coalescer.ts +40 -0
- package/index.ts +54 -24
- package/jsonl-writer.ts +81 -0
- package/notify.ts +4 -13
- package/package.json +2 -2
- package/pi-spawn.ts +77 -0
- package/render.ts +44 -18
- package/schemas.ts +5 -4
- package/settings.ts +18 -2
- package/single-output.ts +55 -0
- package/skills.ts +221 -80
- package/subagent-runner.ts +32 -6
- package/types.ts +5 -3
package/subagent-runner.ts
CHANGED
|
@@ -5,6 +5,8 @@ import * as os from "node:os";
|
|
|
5
5
|
import * as path from "node:path";
|
|
6
6
|
import { pathToFileURL } from "node:url";
|
|
7
7
|
import { appendJsonl, getArtifactPaths } from "./artifacts.js";
|
|
8
|
+
import { getPiSpawnCommand } from "./pi-spawn.js";
|
|
9
|
+
import { persistSingleOutput } from "./single-output.js";
|
|
8
10
|
import {
|
|
9
11
|
type ArtifactConfig,
|
|
10
12
|
type ArtifactPaths,
|
|
@@ -20,9 +22,11 @@ interface SubagentStep {
|
|
|
20
22
|
cwd?: string;
|
|
21
23
|
model?: string;
|
|
22
24
|
tools?: string[];
|
|
25
|
+
extensions?: string[];
|
|
23
26
|
mcpDirectTools?: string[];
|
|
24
27
|
systemPrompt?: string | null;
|
|
25
28
|
skills?: string[];
|
|
29
|
+
outputPath?: string;
|
|
26
30
|
}
|
|
27
31
|
|
|
28
32
|
interface SubagentRunConfig {
|
|
@@ -104,7 +108,8 @@ function runPiStreaming(
|
|
|
104
108
|
return new Promise((resolve) => {
|
|
105
109
|
const outputStream = fs.createWriteStream(outputFile, { flags: "w" });
|
|
106
110
|
const spawnEnv = { ...process.env, ...(env ?? {}), ...getSubagentDepthEnv() };
|
|
107
|
-
const
|
|
111
|
+
const spawnSpec = getPiSpawnCommand(args);
|
|
112
|
+
const child = spawn(spawnSpec.command, spawnSpec.args, { cwd, stdio: ["ignore", "pipe", "pipe"], env: spawnEnv });
|
|
108
113
|
let stdout = "";
|
|
109
114
|
|
|
110
115
|
child.stdout.on("data", (chunk: Buffer) => {
|
|
@@ -337,19 +342,27 @@ async function runSubagent(config: SubagentRunConfig): Promise<void> {
|
|
|
337
342
|
} catch {}
|
|
338
343
|
args.push("--session-dir", config.sessionDir);
|
|
339
344
|
}
|
|
340
|
-
|
|
345
|
+
// Use --models (not --model) because pi CLI silently ignores --model
|
|
346
|
+
// without a companion --provider flag. --models resolves the provider
|
|
347
|
+
// automatically via resolveModelScope. See: #8
|
|
348
|
+
if (step.model) args.push("--models", step.model);
|
|
349
|
+
const toolExtensionPaths: string[] = [];
|
|
341
350
|
if (step.tools?.length) {
|
|
342
351
|
const builtinTools: string[] = [];
|
|
343
|
-
const extensionPaths: string[] = [];
|
|
344
352
|
for (const tool of step.tools) {
|
|
345
353
|
if (tool.includes("/") || tool.endsWith(".ts") || tool.endsWith(".js")) {
|
|
346
|
-
|
|
354
|
+
toolExtensionPaths.push(tool);
|
|
347
355
|
} else {
|
|
348
356
|
builtinTools.push(tool);
|
|
349
357
|
}
|
|
350
358
|
}
|
|
351
359
|
if (builtinTools.length > 0) args.push("--tools", builtinTools.join(","));
|
|
352
|
-
|
|
360
|
+
}
|
|
361
|
+
if (step.extensions !== undefined) {
|
|
362
|
+
args.push("--no-extensions");
|
|
363
|
+
for (const extPath of step.extensions) args.push("--extension", extPath);
|
|
364
|
+
} else {
|
|
365
|
+
for (const extPath of toolExtensionPaths) args.push("--extension", extPath);
|
|
353
366
|
}
|
|
354
367
|
|
|
355
368
|
let tmpDir: string | null = null;
|
|
@@ -392,6 +405,19 @@ async function runSubagent(config: SubagentRunConfig): Promise<void> {
|
|
|
392
405
|
|
|
393
406
|
const output = (result.stdout || "").trim();
|
|
394
407
|
previousOutput = output;
|
|
408
|
+
let outputForSummary = output;
|
|
409
|
+
if (step.outputPath && result.exitCode === 0) {
|
|
410
|
+
const persisted = persistSingleOutput(step.outputPath, output);
|
|
411
|
+
if (persisted.savedPath) {
|
|
412
|
+
outputForSummary = output
|
|
413
|
+
? `${output}\n\nš Output saved to: ${persisted.savedPath}`
|
|
414
|
+
: `š Output saved to: ${persisted.savedPath}`;
|
|
415
|
+
} else if (persisted.error) {
|
|
416
|
+
outputForSummary = output
|
|
417
|
+
? `${output}\n\nā ļø Failed to save output to: ${step.outputPath}\n${persisted.error}`
|
|
418
|
+
: `ā ļø Failed to save output to: ${step.outputPath}\n${persisted.error}`;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
395
421
|
|
|
396
422
|
const cumulativeTokens = config.sessionDir ? parseSessionTokens(config.sessionDir) : null;
|
|
397
423
|
const stepTokens: TokenUsage | null = cumulativeTokens
|
|
@@ -407,7 +433,7 @@ async function runSubagent(config: SubagentRunConfig): Promise<void> {
|
|
|
407
433
|
|
|
408
434
|
const stepResult: StepResult = {
|
|
409
435
|
agent: step.agent,
|
|
410
|
-
output,
|
|
436
|
+
output: outputForSummary,
|
|
411
437
|
success: result.exitCode === 0,
|
|
412
438
|
artifactPaths,
|
|
413
439
|
};
|
package/types.ts
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
* Type definitions for the subagent extension
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
+
import * as os from "node:os";
|
|
6
|
+
import * as path from "node:path";
|
|
5
7
|
import type { Message } from "@mariozechner/pi-ai";
|
|
6
8
|
|
|
7
9
|
// ============================================================================
|
|
@@ -230,15 +232,15 @@ export const DEFAULT_ARTIFACT_CONFIG: ArtifactConfig = {
|
|
|
230
232
|
enabled: true,
|
|
231
233
|
includeInput: true,
|
|
232
234
|
includeOutput: true,
|
|
233
|
-
includeJsonl:
|
|
235
|
+
includeJsonl: false,
|
|
234
236
|
includeMetadata: true,
|
|
235
237
|
cleanupDays: 7,
|
|
236
238
|
};
|
|
237
239
|
|
|
238
240
|
export const MAX_PARALLEL = 8;
|
|
239
241
|
export const MAX_CONCURRENCY = 4;
|
|
240
|
-
export const RESULTS_DIR = "
|
|
241
|
-
export const ASYNC_DIR = "
|
|
242
|
+
export const RESULTS_DIR = path.join(os.tmpdir(), "pi-async-subagent-results");
|
|
243
|
+
export const ASYNC_DIR = path.join(os.tmpdir(), "pi-async-subagent-runs");
|
|
242
244
|
export const WIDGET_KEY = "subagent-async";
|
|
243
245
|
export const POLL_INTERVAL_MS = 250;
|
|
244
246
|
export const MAX_WIDGET_JOBS = 4;
|