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.
@@ -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 child = spawn("pi", args, { cwd, stdio: ["ignore", "pipe", "pipe"], env: spawnEnv });
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
- if (step.model) args.push("--model", step.model);
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
- extensionPaths.push(tool);
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
- for (const extPath of extensionPaths) args.push("--extension", extPath);
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: true,
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 = "/tmp/pi-async-subagent-results";
241
- export const ASYNC_DIR = "/tmp/pi-async-subagent-runs";
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;