Thread the load-time child environment into the runner

This commit is contained in:
alex committed 2026-12-01 11:56:55 +00:00
1 parent e623dae30c
commit dcc66a4b26
4 files changed
+12 -16

No files matched your search

+6 -9
View File
@@ -117,7 +117,7 @@ export function readUltraGuideline(value: string | undefined): { value: UltraGui
};
}
/** Every load-time setting, read from the process environment exactly once. */
/** Every load-time setting and the child environment, read from the process environment exactly once. */
export function readEnvironmentConfig(env: NodeJS.ProcessEnv = process.env) {
return {
maxWorkers: readMaxWorkers(env.PI_SUBAGENT_MAX_WORKERS),
@@ -127,13 +127,10 @@ export function readEnvironmentConfig(env: NodeJS.ProcessEnv = process.env) {
ultraMode: readUltraMode(env.PI_SUBAGENT_ULTRACODE),
ultraGuideline: readUltraGuideline(env.PI_SUBAGENT_ULTRA_GUIDELINE),
ultraKeyword: readUltraKeyword(env.PI_SUBAGENT_ULTRA_KEYWORD),
/**
* The environment a child process inherits, captured with the settings
* so execution modules never read `process.env` themselves.
*/
childEnvironment: env,
};
}
/**
* The parent environment a child process inherits when the caller does not
* override it. Kept here so no execution module reads `process.env` itself.
*/
export function inheritedEnvironment(): NodeJS.ProcessEnv {
return process.env;
}
+1 -1
View File
@@ -148,7 +148,7 @@ export default function (pi: ExtensionAPI, taskRunner?: TaskRunner) {
ctx.ui.setStatus("subagents", active > 0 ? `subagents: ${active} active` : undefined);
};
const manager = new SubagentManager(taskRunner ?? new ProcessRunner(), {
const manager = new SubagentManager(taskRunner ?? new ProcessRunner({ env: environment.childEnvironment }), {
maxWorkers: workerConfig.value,
onJobEvent: (event) => {
updateStatus();
+4 -5
View File
@@ -11,7 +11,6 @@ import * as os from "node:os";
import * as path from "node:path";
import { StringDecoder } from "node:string_decoder";
import type { Message } from "@earendil-works/pi-ai";
import { inheritedEnvironment } from "./config.ts";
import { emptyRunResult } from "./job-state.ts";
import type {
DispatchDefaults,
@@ -48,8 +47,8 @@ export interface ProcessRunnerOptions {
stderrLimitBytes?: number;
/** Override platform detection, primarily for tests. */
platform?: NodeJS.Platform;
/** Environment for the child (defaults to the current process environment). */
env?: NodeJS.ProcessEnv;
/** Environment for the child, threaded from the load-time configuration. */
env: NodeJS.ProcessEnv;
}
/** Keep the last `limit` bytes without starting inside a UTF-8 code point. */
@@ -224,12 +223,12 @@ export class ProcessRunner implements TaskRunner {
private readonly platform: NodeJS.Platform;
private readonly env: NodeJS.ProcessEnv;
constructor(options: ProcessRunnerOptions = {}) {
constructor(options: ProcessRunnerOptions) {
this.invocation = options.invocation ?? getPiInvocation;
this.killGraceMs = Math.max(0, options.killGraceMs ?? DEFAULT_KILL_GRACE_MS);
this.stderrLimitBytes = Math.max(0, Math.floor(options.stderrLimitBytes ?? DEFAULT_STDERR_LIMIT_BYTES));
this.platform = options.platform ?? process.platform;
this.env = options.env ?? inheritedEnvironment();
this.env = options.env;
}
async run(task: PreparedTask, defaults: DispatchDefaults, options: RunOptions): Promise<RunResult> {
+1 -1
View File
@@ -32,7 +32,7 @@ function makeTask(overrides: Partial<PreparedTask> = {}): PreparedTask {
};
}
function makeRunner(env: NodeJS.ProcessEnv = {}, options: ProcessRunnerOptions = {}): ProcessRunner {
function makeRunner(env: NodeJS.ProcessEnv = {}, options: Omit<ProcessRunnerOptions, "env"> = {}): ProcessRunner {
return new ProcessRunner({
invocation: (args) => ({ command: process.execPath, args: [fixturePath, ...args] }),
killGraceMs: 150,