@xzzpig/pi-subagents 0.16.0 → 0.18.0
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 +164 -1
- package/README.md +5 -3
- package/agents/claude-code-writer.md +1 -0
- package/agents/codex-exec-writer.md +1 -0
- package/agents/cursor-agent-writer.md +1 -0
- package/agents/reviewer.md +3 -2
- package/agents/worker.md +3 -2
- package/docs/agents.md +17 -10
- package/docs/configuration.md +21 -3
- package/docs/extension-api.md +70 -4
- package/docs/models.md +5 -3
- package/docs/observability.md +23 -13
- package/docs/standalone-background.md +4 -4
- package/docs/tool-reference.md +40 -19
- package/docs/watchdog.md +2 -0
- package/docs/workflows.md +57 -3
- package/inspector-runner.mjs +1 -1
- package/package.json +14 -8
- package/prompts/council.md +6 -3
- package/runner-peer-loader.mjs +4 -7
- package/runner-peer-preload.mjs +5 -7
- package/skills/pi-subagents/SKILL.md +1 -0
- package/skills/pi-subagents/references/constraints-and-recipes.md +5 -2
- package/skills/pi-subagents/references/execution-controls.md +6 -4
- package/skills/pi-subagents/references/management-authoring-rpc.md +3 -3
- package/skills/pi-subagents/references/multi-lane-orchestration.md +8 -0
- package/skills/pi-subagents/references/prompting-and-roles.md +16 -15
- package/src/agents/agent-eject.ts +3 -3
- package/src/agents/agent-management.ts +61 -52
- package/src/agents/agent-memory.ts +90 -3
- package/src/agents/agent-serializer.ts +4 -4
- package/src/agents/agents.ts +125 -51
- package/src/agents/global-npm-root.ts +58 -0
- package/src/agents/proactive-skills.ts +4 -1
- package/src/agents/runtime-agent-registry.ts +14 -11
- package/src/agents/skills.ts +42 -9
- package/src/api/delegation.ts +15 -0
- package/src/api/inspectors.ts +27 -0
- package/src/api/preflight.ts +60 -60
- package/src/extension/doctor.ts +9 -4
- package/src/extension/fanout-child.ts +8 -0
- package/src/extension/index.ts +101 -48
- package/src/extension/rpc.ts +10 -1
- package/src/extension/schemas.ts +12 -6
- package/src/extension/subagent-guide.ts +12 -4
- package/src/extension/tool-activation.ts +197 -0
- package/src/extension/tool-description.ts +1 -1
- package/src/inspectors/ghostty/plugin.ts +13 -1
- package/src/inspectors/plugins.ts +70 -3
- package/src/intercom/intercom-bridge.ts +2 -0
- package/src/intercom/native-supervisor-channel.ts +22 -15
- package/src/intercom/result-intercom.ts +4 -0
- package/src/runs/background/active-async-capacity.ts +3 -25
- package/src/runs/background/async-execution.ts +100 -140
- package/src/runs/background/async-job-tracker.ts +28 -34
- package/src/runs/background/async-resume.ts +16 -8
- package/src/runs/background/async-status.ts +2 -0
- package/src/runs/background/binary-bootstrap.ts +34 -6
- package/src/runs/background/fleet-view.ts +51 -7
- package/src/runs/background/notify.ts +93 -7
- package/src/runs/background/pid-namespace.ts +18 -0
- package/src/runs/background/process-terminal-candidate.ts +98 -0
- package/src/runs/background/process-terminal.ts +17 -96
- package/src/runs/background/result-watcher.ts +1 -1
- package/src/runs/background/retained-children.ts +3 -2
- package/src/runs/background/run-child-session.ts +16 -5
- package/src/runs/background/run-id-resolver.ts +10 -5
- package/src/runs/background/run-status.ts +10 -4
- package/src/runs/background/runner-aliases.ts +25 -15
- package/src/runs/background/runner-child-launch.ts +1 -2
- package/src/runs/background/runner-startup-failure.ts +56 -0
- package/src/runs/background/stale-run-reconciler.ts +19 -3
- package/src/runs/background/subagent-runner-bootstrap.ts +276 -0
- package/src/runs/background/subagent-runner.ts +96 -287
- package/src/runs/background/wait-tool.ts +2 -0
- package/src/runs/background/workflow-terminal-proof.ts +68 -0
- package/src/runs/foreground/execution.ts +217 -250
- package/src/runs/foreground/prompt-audit.ts +3 -9
- package/src/runs/foreground/subagent-executor.ts +377 -119
- package/src/runs/shared/acceptance.ts +167 -68
- package/src/runs/shared/capability-ceiling.ts +4 -1
- package/src/runs/shared/child-hooks.ts +1 -16
- package/src/runs/shared/child-launch.ts +22 -14
- package/src/runs/shared/child-runtime-config.ts +3 -0
- package/src/runs/shared/child-session.ts +52 -2
- package/src/runs/shared/child-tool-plan.ts +23 -113
- package/src/runs/shared/dynamic-fanout.ts +1 -1
- package/src/runs/shared/external-cli-runner.ts +3 -1
- package/src/runs/shared/external-job-bridge.ts +54 -0
- package/src/runs/shared/git-environment.ts +29 -0
- package/src/runs/shared/mcp-config-sources.ts +3 -0
- package/src/runs/shared/mcp-direct-tool-allowlist.ts +1 -1
- package/src/runs/shared/mcp-direct-tool-grant.ts +22 -6
- package/src/runs/shared/model-resolution.ts +6 -1
- package/src/runs/shared/nested-events.ts +67 -55
- package/src/runs/shared/orca-progress-tabs.ts +3 -2
- package/src/runs/shared/parallel-utils.ts +2 -1
- package/src/runs/shared/pi-spawn.ts +92 -6
- package/src/runs/shared/single-output.ts +11 -2
- package/src/runs/shared/structured-output.ts +227 -7
- package/src/runs/shared/subagent-control.ts +2 -16
- package/src/runs/shared/subagent-prompt-runtime.ts +27 -5
- package/src/runs/shared/tool-availability.ts +2 -2
- package/src/runs/shared/tool-budget.ts +21 -0
- package/src/runs/shared/usage-reconciliation.ts +73 -0
- package/src/runs/shared/worktree.ts +35 -8
- package/src/shared/child-session-name.ts +4 -2
- package/src/shared/fork-context.ts +11 -4
- package/src/shared/launch-contract.ts +1 -1
- package/src/shared/pruned-fork.ts +69 -56
- package/src/shared/types.ts +52 -16
- package/src/slash/delegation-adapters.ts +25 -1
- package/src/slash/prompt-template-bridge.ts +16 -1
- package/src/slash/prompt-workflows.ts +12 -1
- package/src/slash/slash-commands.ts +7 -241
- package/src/slash/subagent-cost.ts +313 -0
- package/src/slash/subagents-admin.ts +28 -29
- package/src/tui/fleet-status.ts +24 -2
- package/src/tui/fleet.ts +7 -4
- package/src/tui/render.ts +53 -19
- package/src/watchdog/diff-tool.ts +24 -3
- package/src/watchdog/permission-arbiter.ts +13 -15
- package/src/watchdog/register-child.ts +10 -2
- package/src/watchdog/review.ts +14 -14
- package/src/watchdog/runtime.ts +2 -1
- package/src/watchdog/turn-delta.ts +11 -5
- package/src/workflows/scripted-workflow.ts +109 -23
- package/src/workflows/workflow-child-summary.ts +4 -2
- package/src/workflows/workflow-settlement.ts +4 -1
- package/src/runs/shared/completion-evidence.ts +0 -89
- package/src/runs/shared/completion-guard.ts +0 -255
- package/src/runs/shared/llm-intent-arbiter.ts +0 -321
- package/src/runs/shared/task-intent.ts +0 -244
|
@@ -20,7 +20,7 @@ import { applyThinkingSuffix, getHostBuiltinToolNames, projectLaunchResolvedChil
|
|
|
20
20
|
import { injectSingleOutputInstruction, normalizeSingleOutputOverride, resolveSingleOutputPath, validateFileOnlyOutputMode } from "../shared/single-output.ts";
|
|
21
21
|
import { applyWatchdogLaunchRules, sendRuleViolationWarning } from "../../watchdog/rules.ts";
|
|
22
22
|
import { buildChainInstructions, isDynamicParallelStep, isParallelStep, resolveExistingReadInstructionPaths, resolveExistingReadPaths, writeInitialProgressFile, type ChainStep, type SequentialStep, type StepOverrides } from "../../shared/settings.ts";
|
|
23
|
-
import type
|
|
23
|
+
import { isDynamicRunnerGroup, isParallelGroup, type RunnerStep } from "../shared/parallel-utils.ts";
|
|
24
24
|
import type { ContextMode } from "../shared/context-mode.ts";
|
|
25
25
|
import { PI_CODING_AGENT_PACKAGE, resolveBunPiExecutable, resolveInstalledPiPackageRoot, resolvePiPackageRoot } from "../shared/pi-spawn.ts";
|
|
26
26
|
import { JITI_ALIAS_ENV, resolveHostPeerAliases } from "./runner-aliases.ts";
|
|
@@ -40,7 +40,6 @@ import { ChainOutputValidationError, validateChainOutputBindings } from "../shar
|
|
|
40
40
|
import { createStructuredOutputRuntime } from "../shared/structured-output.ts";
|
|
41
41
|
import { resolveAcceptanceReportMode, resolveEffectiveAcceptance, validateAcceptanceInput, validateExecutionAcceptance } from "../shared/acceptance.ts";
|
|
42
42
|
import { createRunFanoutBudget, writeRunFanoutBudgetDescriptor } from "../shared/run-fanout-budget.ts";
|
|
43
|
-
import { validateImplementationToolContract } from "../shared/completion-guard.ts";
|
|
44
43
|
import {
|
|
45
44
|
type AcceptanceInput,
|
|
46
45
|
type AgentContract,
|
|
@@ -69,7 +68,7 @@ import {
|
|
|
69
68
|
resolveChildMaxSubagentDepth,
|
|
70
69
|
} from "../../shared/types.ts";
|
|
71
70
|
import { inheritedNestedParentAddressOf, inheritedNestedRouteOf, nestedResultsPath, nestedSummaryFromAsyncStatus, writeNestedEvent } from "../shared/nested-events.ts";
|
|
72
|
-
import type
|
|
71
|
+
import { SUBAGENT_PARENT_SESSION_ENV, type ChildRuntimeConfig } from "../shared/child-runtime-config.ts";
|
|
73
72
|
import { childSessionFactoryModule } from "../shared/child-session.ts";
|
|
74
73
|
import { inheritedChildRuntime } from "../shared/child-launch.ts";
|
|
75
74
|
import { resultFilePath } from "./result-files.ts";
|
|
@@ -79,13 +78,16 @@ import { usageBudgetState } from "../shared/usage-budget.ts";
|
|
|
79
78
|
import type { ImportedAsyncRoot } from "./chain-root-attachment.ts";
|
|
80
79
|
import type { SessionLeaseRequest } from "../shared/session-lease.ts";
|
|
81
80
|
import { finalizeProcessTerminal, initializeProcessTerminal, readProcessTerminal } from "./process-terminal.ts";
|
|
81
|
+
import { persistRunnerStartupFailure } from "./runner-startup-failure.ts";
|
|
82
82
|
import type { ActiveAsyncCapacityHandle } from "./active-async-capacity.ts";
|
|
83
83
|
import { statusStepDescription } from "./chain-append.ts";
|
|
84
|
+
import { currentPidNamespaceScope } from "./pid-namespace.ts";
|
|
84
85
|
import { SUBAGENT_PROCESS_TERMINAL_EVENT } from "../../shared/types.ts";
|
|
85
86
|
import { assertAgentAllowedByCapabilityCeiling, intersectSubagentCapabilityCeilings, resolveCurrentSubagentCapabilityCeiling, type ResolvedSubagentCapabilityCeiling } from "../shared/capability-ceiling.ts";
|
|
86
87
|
import { resolveLaunchBinding } from "../../shared/launch-contract.ts";
|
|
87
88
|
import { resolvePermissionRules, type PermissionConfig } from "../shared/permissions.ts";
|
|
88
89
|
import { normalizeExtensionBindings, omitExtensionBindingsEnv, omitInheritedProfileEnv, type ExtensionBindings } from "../shared/extension-bindings.ts";
|
|
90
|
+
import { omitGitRoutingEnv } from "../shared/git-environment.ts";
|
|
89
91
|
import { assertWorkflowLaneKey, normalizeWorkflowLaneMetadata } from "../shared/lane-metadata.ts";
|
|
90
92
|
import { resolveRequiredChildExtensions, type RequiredChildExtensionSnapshot } from "../../shared/required-child-extensions.ts";
|
|
91
93
|
|
|
@@ -110,14 +112,14 @@ function resolveAsyncPiPackageRoot(env: NodeJS.ProcessEnv = process.env): string
|
|
|
110
112
|
function resolveJitiCliFromPackageJson(packageJsonPath: string): string | undefined {
|
|
111
113
|
if (!fs.existsSync(packageJsonPath)) return undefined;
|
|
112
114
|
const packageRoot = path.dirname(packageJsonPath);
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
115
|
+
let parsed: unknown;
|
|
116
|
+
try {
|
|
117
|
+
parsed = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
|
|
118
|
+
} catch {
|
|
119
|
+
return undefined;
|
|
120
|
+
}
|
|
121
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return undefined;
|
|
122
|
+
const pkg = parsed as { bin?: string | Record<string, string> };
|
|
121
123
|
const binField = pkg.bin;
|
|
122
124
|
const binPath = typeof binField === "string"
|
|
123
125
|
? binField
|
|
@@ -159,7 +161,7 @@ function resolveJitiCliPath(): string | undefined {
|
|
|
159
161
|
const jitiCliPath = resolveJitiCliPath();
|
|
160
162
|
const asyncRunnerSourcePath = path.join(
|
|
161
163
|
path.dirname(fileURLToPath(import.meta.url)),
|
|
162
|
-
`subagent-runner${path.extname(fileURLToPath(import.meta.url))}`,
|
|
164
|
+
`subagent-runner-bootstrap${path.extname(fileURLToPath(import.meta.url))}`,
|
|
163
165
|
);
|
|
164
166
|
const sourceUnderNodeModules = asyncRunnerSourcePath.split(path.sep).some((segment) => segment.toLowerCase() === "node_modules");
|
|
165
167
|
function supportsNativeRunner(nodeExecutable: string): boolean {
|
|
@@ -185,7 +187,7 @@ interface AsyncExecutionContext {
|
|
|
185
187
|
projectTrusted?: boolean;
|
|
186
188
|
/** Exact trusted parent cwd; project config applies only when it matches the child cwd. */
|
|
187
189
|
trustedProjectCwd?: string;
|
|
188
|
-
modelResponseAliases?: Record<string, string[]>;
|
|
190
|
+
modelResponseAliases?: Record<string, string[]>;
|
|
189
191
|
/** Whether the parent session has an interactive UI. */
|
|
190
192
|
interactive?: boolean;
|
|
191
193
|
/** The executor's own child runtime when the launch comes from an in-process child. */
|
|
@@ -268,7 +270,7 @@ interface AsyncSingleParams {
|
|
|
268
270
|
recoveryAgentConfig?: AgentConfig;
|
|
269
271
|
/** Selected global sandbox profile carried across revival. */
|
|
270
272
|
sandbox?: string;
|
|
271
|
-
requiredExtensions?: RequiredChildExtensionSnapshot;
|
|
273
|
+
requiredExtensions?: RequiredChildExtensionSnapshot;
|
|
272
274
|
ctx: AsyncExecutionContext;
|
|
273
275
|
cwd?: string;
|
|
274
276
|
requestedCwd?: string;
|
|
@@ -427,8 +429,8 @@ export function isAsyncAvailable(): boolean {
|
|
|
427
429
|
}
|
|
428
430
|
|
|
429
431
|
export function resolveAsyncRunnerLogPaths(cfg: Record<string, unknown>): { stdoutPath: string; stderrPath: string } | undefined {
|
|
430
|
-
|
|
431
|
-
|
|
432
|
+
const asyncDir = typeof cfg.asyncDir === "string"
|
|
433
|
+
? cfg.asyncDir
|
|
432
434
|
: undefined;
|
|
433
435
|
if (!asyncDir) return undefined;
|
|
434
436
|
return {
|
|
@@ -563,6 +565,7 @@ async function terminateRunnerBeforeProceedAsync(proc: ChildProcess, processClos
|
|
|
563
565
|
async function completeRunnerStartupHandshake(
|
|
564
566
|
startupPath: string,
|
|
565
567
|
startupAckPath: string,
|
|
568
|
+
startupConfirmPath: string,
|
|
566
569
|
startupProceedPath: string,
|
|
567
570
|
proc: ChildProcess,
|
|
568
571
|
processClosed: Promise<{ exitCode: number | null; signal: NodeJS.Signals | null }>,
|
|
@@ -589,7 +592,7 @@ async function completeRunnerStartupHandshake(
|
|
|
589
592
|
const terminationObserved = await terminateRunnerBeforeProceedAsync(proc, processClosed);
|
|
590
593
|
return { pid: proc.pid, runnerProcessInstanceId, error: acknowledged.error, terminationObserved, startupDidNotProceed: true };
|
|
591
594
|
}
|
|
592
|
-
try { writeRunnerStartupControl(
|
|
595
|
+
try { writeRunnerStartupControl(startupConfirmPath, { action: "confirm", token: ready.token }); } catch (error) {
|
|
593
596
|
const message = `Failed to confirm async runner startup: ${error instanceof Error ? error.message : String(error)}`;
|
|
594
597
|
persistStartupFailure(message);
|
|
595
598
|
const terminationObserved = await terminateRunnerBeforeProceedAsync(proc, processClosed);
|
|
@@ -626,37 +629,8 @@ async function completeRunnerStartupHandshake(
|
|
|
626
629
|
}
|
|
627
630
|
|
|
628
631
|
function persistPreProceedStartupFailure(asyncDir: string, runId: string, runnerProcessInstanceId: string, sessionId: string | undefined, completionOwnerId: string | undefined, message: string): void {
|
|
629
|
-
const now = Date.now();
|
|
630
632
|
try {
|
|
631
|
-
|
|
632
|
-
let status: Partial<AsyncStatus> = {};
|
|
633
|
-
try {
|
|
634
|
-
status = JSON.parse(fs.readFileSync(statusPath, "utf-8")) as Partial<AsyncStatus>;
|
|
635
|
-
} catch {}
|
|
636
|
-
const existingProcessTerminal = status.processTerminal?.state === "observed" || status.processTerminal?.state === "unknown"
|
|
637
|
-
? status.processTerminal : undefined;
|
|
638
|
-
writePrivateAtomicJson(statusPath, {
|
|
639
|
-
...status,
|
|
640
|
-
runId,
|
|
641
|
-
...(sessionId ? { sessionId } : {}),
|
|
642
|
-
...(completionOwnerId ? { completionOwnerId } : {}),
|
|
643
|
-
state: "failed",
|
|
644
|
-
lastUpdate: now,
|
|
645
|
-
error: message,
|
|
646
|
-
processTerminal: existingProcessTerminal ?? {
|
|
647
|
-
version: 1,
|
|
648
|
-
state: "not-started",
|
|
649
|
-
runId,
|
|
650
|
-
runnerProcessInstanceId,
|
|
651
|
-
},
|
|
652
|
-
});
|
|
653
|
-
writePrivateAtomicJson(path.join(asyncDir, "process-terminal-candidate.json"), {
|
|
654
|
-
version: 1,
|
|
655
|
-
runId,
|
|
656
|
-
runnerProcessInstanceId,
|
|
657
|
-
writers: {},
|
|
658
|
-
expectedWriters: { 0: 0 },
|
|
659
|
-
});
|
|
633
|
+
persistRunnerStartupFailure({ asyncDir, runId, runnerProcessInstanceId, sessionId, completionOwnerId, message });
|
|
660
634
|
} catch {
|
|
661
635
|
// Startup failures must still return the original launch error.
|
|
662
636
|
}
|
|
@@ -683,19 +657,23 @@ export function emitProcessTerminalEvent(ctx: AsyncExecutionContext, proof: unkn
|
|
|
683
657
|
}
|
|
684
658
|
}
|
|
685
659
|
|
|
686
|
-
function spawnRunner(cfg: object, suffix: string, cwd: string, initialStatus: Omit<AsyncStatus, "pid" | "processTerminal">, initialStatusPath: string, onProcessTerminal?: (proof: unknown) => void, onBeforeProceed?: (runnerProcessInstanceId: string) => void, requestedCwd = cwd): SpawnRunnerResult | Promise<SpawnRunnerResult> {
|
|
660
|
+
function spawnRunner(cfg: object, suffix: string, cwd: string, initialStatus: Omit<AsyncStatus, "pid" | "processTerminal">, initialStatusPath: string, launchParentSessionId: string | undefined, onProcessTerminal?: (proof: unknown) => void, onBeforeProceed?: (runnerProcessInstanceId: string) => void, requestedCwd = cwd): SpawnRunnerResult | Promise<SpawnRunnerResult> {
|
|
687
661
|
const cwdError = preflightLaunchCwd(requestedCwd, cwd);
|
|
688
662
|
if (cwdError) return { error: cwdError };
|
|
663
|
+
if (launchParentSessionId !== undefined && (!launchParentSessionId || launchParentSessionId.trim() !== launchParentSessionId)) {
|
|
664
|
+
return { error: "Background runner parent session identity is invalid." };
|
|
665
|
+
}
|
|
666
|
+
const steps = (cfg as { steps?: unknown }).steps;
|
|
667
|
+
if (!Array.isArray(steps)) return { error: "Background runner launch is missing its steps." };
|
|
668
|
+
const inconsistentParent = (steps as RunnerStep[]).some((step) => isParallelGroup(step)
|
|
669
|
+
? step.parallel.some((child) => child.parentSessionId !== launchParentSessionId)
|
|
670
|
+
: (isDynamicRunnerGroup(step) ? step.parallel.parentSessionId : step.parentSessionId) !== launchParentSessionId);
|
|
671
|
+
if (inconsistentParent) return { error: "Background runner steps have inconsistent parent session identities." };
|
|
689
672
|
|
|
690
673
|
// The compiled host exposes its SDK only through Pi's extension loader.
|
|
691
674
|
const binaryHost = resolveBunPiExecutable();
|
|
692
675
|
const nodeExecutable = resolveNodeExecutable();
|
|
693
|
-
const
|
|
694
|
-
(step) => (step.extensions?.length ?? 0) > 0 || (step.subagentOnlyExtensions?.length ?? 0) > 0 || (step.requiredExtensions?.length ?? 0) > 0,
|
|
695
|
-
) ?? false;
|
|
696
|
-
// Keep provider/tool extensions in Jiti's host-alias boundary; the native preload
|
|
697
|
-
// only certifies the runner's imports, not a separately loaded extension graph.
|
|
698
|
-
const nativeRunnerSupported = supportsNativeRunner(nodeExecutable) && !configuredExtensions;
|
|
676
|
+
const nativeRunnerSupported = supportsNativeRunner(nodeExecutable);
|
|
699
677
|
const runner = asyncRunnerSourcePath;
|
|
700
678
|
const runnerIsJavaScript = path.extname(runner) === ".js";
|
|
701
679
|
const bootstrap = path.join(path.dirname(runner), `binary-bootstrap${path.extname(fileURLToPath(import.meta.url))}`);
|
|
@@ -730,11 +708,13 @@ function spawnRunner(cfg: object, suffix: string, cwd: string, initialStatus: Om
|
|
|
730
708
|
? path.join(launchAsyncDir, "runner-startup.json")
|
|
731
709
|
: undefined;
|
|
732
710
|
const startupAckPath = startupPath ? path.join(path.dirname(startupPath), "runner-startup-ack.json") : undefined;
|
|
711
|
+
const startupConfirmPath = startupPath ? path.join(path.dirname(startupPath), "runner-startup-confirm.json") : undefined;
|
|
733
712
|
const startupProceedPath = launchAsyncDir && (startupPath || launchBarrierToken)
|
|
734
713
|
? path.join(launchAsyncDir, "runner-startup-proceed.json")
|
|
735
714
|
: undefined;
|
|
736
715
|
if (startupPath) fs.rmSync(startupPath, { force: true });
|
|
737
716
|
if (startupAckPath) fs.rmSync(startupAckPath, { force: true });
|
|
717
|
+
if (startupConfirmPath) fs.rmSync(startupConfirmPath, { force: true });
|
|
738
718
|
if (startupProceedPath) fs.rmSync(startupProceedPath, { force: true });
|
|
739
719
|
|
|
740
720
|
const logPaths = resolveAsyncRunnerLogPaths(launchConfig);
|
|
@@ -746,6 +726,7 @@ function spawnRunner(cfg: object, suffix: string, cwd: string, initialStatus: Om
|
|
|
746
726
|
stdoutFd = fs.openSync(logPaths.stdoutPath, "a");
|
|
747
727
|
stderrFd = fs.openSync(logPaths.stderrPath, "a");
|
|
748
728
|
}
|
|
729
|
+
// Short-circuit native peer aliases so Pi's loader and generated factories preserve filesystem resolution semantics.
|
|
749
730
|
const preload = Object.keys(hostPeerAliases.aliases).length > 0
|
|
750
731
|
? ["--import", new URL("../../../runner-peer-preload.mjs", import.meta.url).href]
|
|
751
732
|
: [];
|
|
@@ -756,22 +737,24 @@ function spawnRunner(cfg: object, suffix: string, cwd: string, initialStatus: Om
|
|
|
756
737
|
: nativeRunnerSupported
|
|
757
738
|
? [...preload, "--experimental-strip-types", runner, cfgPath]
|
|
758
739
|
: [...preload, jitiCliPath!, runner, cfgPath];
|
|
740
|
+
const runnerEnv: NodeJS.ProcessEnv = {
|
|
741
|
+
// Fork: profile env inherited from the parent must not leak into children.
|
|
742
|
+
...omitGitRoutingEnv(omitInheritedProfileEnv(omitExtensionBindingsEnv(process.env))),
|
|
743
|
+
...childCacheRetentionEnv(),
|
|
744
|
+
[PI_CODING_AGENT_PACKAGE_ROOT_ENV]: binaryHost ? undefined : piPackageRoot,
|
|
745
|
+
// npm must override inherited bundled layouts (#2071); binaries retain release assets.
|
|
746
|
+
PI_PACKAGE_DIR: binaryHost ? process.env.PI_PACKAGE_DIR : piPackageRoot,
|
|
747
|
+
[JITI_ALIAS_ENV]: binaryHost ? undefined : JSON.stringify(hostPeerAliases.aliases),
|
|
748
|
+
PI_ASYNC_NATIVE_RUNNER: !binaryHost && (runnerIsJavaScript || nativeRunnerSupported) ? "1" : "0",
|
|
749
|
+
PI_SUBAGENT_RUNNER_CONFIG: binaryHost ? cfgPath : undefined,
|
|
750
|
+
};
|
|
751
|
+
if (launchParentSessionId === undefined) delete runnerEnv[SUBAGENT_PARENT_SESSION_ENV];
|
|
752
|
+
else runnerEnv[SUBAGENT_PARENT_SESSION_ENV] = launchParentSessionId;
|
|
759
753
|
const proc = spawn(command, args, {
|
|
760
754
|
cwd,
|
|
761
755
|
...backgroundProcessOptions(),
|
|
762
756
|
stdio: ["ignore", stdoutFd ?? "ignore", stderrFd ?? "ignore"],
|
|
763
|
-
env:
|
|
764
|
-
...omitInheritedProfileEnv(omitExtensionBindingsEnv(process.env)),
|
|
765
|
-
// Unset leaves the inherited parent value in place. See childCacheRetention.
|
|
766
|
-
...childCacheRetentionEnv(),
|
|
767
|
-
[PI_CODING_AGENT_PACKAGE_ROOT_ENV]: binaryHost ? undefined : piPackageRoot,
|
|
768
|
-
// npm must override inherited bundled layouts (#2071); binaries retain release assets.
|
|
769
|
-
PI_PACKAGE_DIR: binaryHost ? process.env.PI_PACKAGE_DIR : piPackageRoot,
|
|
770
|
-
[JITI_ALIAS_ENV]: binaryHost ? undefined : JSON.stringify(hostPeerAliases.aliases),
|
|
771
|
-
PI_ASYNC_NATIVE_RUNNER: !binaryHost && (runnerIsJavaScript || nativeRunnerSupported) ? "1" : "0",
|
|
772
|
-
PI_ASYNC_COMPILED_RUNNER: !binaryHost && runnerIsJavaScript ? "1" : "0",
|
|
773
|
-
PI_SUBAGENT_RUNNER_CONFIG: binaryHost ? cfgPath : undefined,
|
|
774
|
-
},
|
|
757
|
+
env: runnerEnv,
|
|
775
758
|
});
|
|
776
759
|
let observedProcessExit: { exitCode: number | null; signal: NodeJS.Signals | null } | undefined;
|
|
777
760
|
proc.once("exit", (exitCode, signal) => { observedProcessExit = { exitCode, signal }; });
|
|
@@ -847,6 +830,7 @@ function spawnRunner(cfg: object, suffix: string, cwd: string, initialStatus: Om
|
|
|
847
830
|
writePrivateAtomicJson(initialStatusPath, {
|
|
848
831
|
...initialStatus,
|
|
849
832
|
pid: proc.pid,
|
|
833
|
+
pidNamespaceScope: currentPidNamespaceScope(),
|
|
850
834
|
processTerminal: { version: 1, state: "pending", runId: initialStatus.runId, runnerProcessInstanceId },
|
|
851
835
|
});
|
|
852
836
|
// Aggregate waits must see the launch before the runner's first status update.
|
|
@@ -885,11 +869,11 @@ function spawnRunner(cfg: object, suffix: string, cwd: string, initialStatus: Om
|
|
|
885
869
|
}
|
|
886
870
|
}
|
|
887
871
|
proc.unref();
|
|
888
|
-
if (startupPath && startupAckPath && startupProceedPath) {
|
|
872
|
+
if (startupPath && startupAckPath && startupConfirmPath && startupProceedPath) {
|
|
889
873
|
const persistStartupFailure = (message: string) => {
|
|
890
874
|
if (launchAsyncDir) persistPreProceedStartupFailure(launchAsyncDir, launchRunId, runnerProcessInstanceId, launchSessionId, launchCompletionOwnerId, message);
|
|
891
875
|
};
|
|
892
|
-
return completeRunnerStartupHandshake(startupPath, startupAckPath, startupProceedPath, proc, processClosed, () => observedProcessExit ?? (proc.exitCode !== null || proc.signalCode !== null ? { exitCode: proc.exitCode, signal: proc.signalCode } : undefined), runnerProcessInstanceId, persistStartupFailure);
|
|
876
|
+
return completeRunnerStartupHandshake(startupPath, startupAckPath, startupConfirmPath, startupProceedPath, proc, processClosed, () => observedProcessExit ?? (proc.exitCode !== null || proc.signalCode !== null ? { exitCode: proc.exitCode, signal: proc.signalCode } : undefined), runnerProcessInstanceId, persistStartupFailure);
|
|
893
877
|
}
|
|
894
878
|
return { pid: proc.pid, runnerProcessInstanceId };
|
|
895
879
|
} catch (error) {
|
|
@@ -913,16 +897,16 @@ class UnavailableSubagentSkillError extends Error {}
|
|
|
913
897
|
class AsyncStartValidationError extends Error {}
|
|
914
898
|
|
|
915
899
|
function profileProjectTrustedForCwd(ctx: AsyncExecutionContext, cwd: string): boolean {
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
900
|
+
return ctx.projectTrusted === true
|
|
901
|
+
&& ctx.trustedProjectCwd !== undefined
|
|
902
|
+
&& path.resolve(ctx.trustedProjectCwd) === path.resolve(cwd);
|
|
919
903
|
}
|
|
920
904
|
|
|
921
905
|
function profileProjectTrustError(agent: AgentConfig, ctx: AsyncExecutionContext): string {
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
906
|
+
if (ctx.projectTrusted !== true) {
|
|
907
|
+
return `Agent '${agent.name}' selects sandbox profile '${agent.sandbox}' from project scope, but the project is not trusted. Trust the project and retry.`;
|
|
908
|
+
}
|
|
909
|
+
return `Agent '${agent.name}' selects sandbox profile '${agent.sandbox}' from project scope, but the child cwd is not an exact trusted project root. Launch from that trusted cwd and retry.`;
|
|
926
910
|
}
|
|
927
911
|
|
|
928
912
|
export function buildAsyncRunnerSteps(id: string, params: AsyncRunnerStepBuildParams): AsyncRunnerStepBuildResult {
|
|
@@ -938,6 +922,7 @@ export function buildAsyncRunnerSteps(id: string, params: AsyncRunnerStepBuildPa
|
|
|
938
922
|
worktreeProvider,
|
|
939
923
|
asyncDir,
|
|
940
924
|
} = params;
|
|
925
|
+
const launchParentSessionId = ctx.parentSessionId ?? ctx.currentSessionId;
|
|
941
926
|
const outputBaseDir = params.outputBaseDir;
|
|
942
927
|
const resultMode = params.resultMode ?? "chain";
|
|
943
928
|
const chainSkills = params.chainSkills ?? [];
|
|
@@ -1032,7 +1017,7 @@ export function buildAsyncRunnerSteps(id: string, params: AsyncRunnerStepBuildPa
|
|
|
1032
1017
|
if (effectiveBehavior.outputSchema !== undefined) unsupported.push("structured output");
|
|
1033
1018
|
if (s.acceptance !== undefined || params.agentContract !== undefined || s.agentContract !== undefined) unsupported.push("acceptance/agent contract");
|
|
1034
1019
|
if (s.toolBudget !== undefined || params.toolBudget !== undefined || a.toolBudget !== undefined || params.configToolBudget !== undefined) unsupported.push("tool budget");
|
|
1035
|
-
|
|
1020
|
+
if (a.sandbox !== undefined) unsupported.push("sandbox profile");
|
|
1036
1021
|
if ((s.fast ?? params.fast ?? a.fast) === true) unsupported.push("fast mode");
|
|
1037
1022
|
if (params.contextForAgent?.(s.agent) === "fork") unsupported.push("fork context");
|
|
1038
1023
|
if (unsupported.length > 0) throw new AsyncStartValidationError(`Agent '${a.name}' uses runner.type='${externalRunnerType}' and does not support: ${unsupported.join(", ")}.`);
|
|
@@ -1068,10 +1053,10 @@ export function buildAsyncRunnerSteps(id: string, params: AsyncRunnerStepBuildPa
|
|
|
1068
1053
|
resolvedBehavior: effectiveBehavior,
|
|
1069
1054
|
});
|
|
1070
1055
|
const { stepCwd, instructionCwd, readExistenceCwd, behavior, namespaceOutputPath, outputPath, skillNames } = launchPlan;
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1056
|
+
const profileChildCwd = behaviorCwd ?? stepCwd;
|
|
1057
|
+
if (a.sandbox && (a.source === "project" || a.override?.scope === "project") && !profileProjectTrustedForCwd(ctx, profileChildCwd)) {
|
|
1058
|
+
throw new AsyncStartValidationError(profileProjectTrustError(a, ctx));
|
|
1059
|
+
}
|
|
1075
1060
|
const { resolved: resolvedSkills, missing: missingSkills } = resolveSkillsWithFallback(
|
|
1076
1061
|
skillNames,
|
|
1077
1062
|
stepCwd,
|
|
@@ -1144,8 +1129,8 @@ export function buildAsyncRunnerSteps(id: string, params: AsyncRunnerStepBuildPa
|
|
|
1144
1129
|
const launchRuleError = applyWatchdogLaunchRules({ cwd: machine ? runnerCwd : stepCwd, agent: a.name, model: selectedModel, warn: (violation) => sendRuleViolationWarning(ctx.pi, violation) });
|
|
1145
1130
|
if (launchRuleError) throw new AsyncStartValidationError(launchRuleError);
|
|
1146
1131
|
const fast = s.fast ?? params.fast ?? a.fast;
|
|
1147
|
-
const hostAvailableBuiltins = getHostBuiltinToolNames(ctx.pi);
|
|
1148
1132
|
const requiredExtensions = externalRunner ? [] : ctx.childRuntime?.requiredExtensions ?? resolveRequiredChildExtensions(ctx.parentSessionId ?? ctx.currentSessionId ?? undefined);
|
|
1133
|
+
const hostAvailableBuiltins = getHostBuiltinToolNames(ctx.pi);
|
|
1149
1134
|
const toolPlan = resolvePiLaunchToolPlan({
|
|
1150
1135
|
tools: a.tools,
|
|
1151
1136
|
excludeTools: a.excludeTools,
|
|
@@ -1164,32 +1149,18 @@ export function buildAsyncRunnerSteps(id: string, params: AsyncRunnerStepBuildPa
|
|
|
1164
1149
|
agentName: a.name,
|
|
1165
1150
|
permissionRules,
|
|
1166
1151
|
runtimeSnapshotHost: ctx.pi,
|
|
1167
|
-
|
|
1168
|
-
|
|
1152
|
+
sandbox: a.sandbox,
|
|
1153
|
+
hostAvailableBuiltins,
|
|
1169
1154
|
});
|
|
1170
1155
|
const launchResolvedExtensions = externalRunner ? undefined : projectLaunchResolvedChildExtensions(toolPlan);
|
|
1171
1156
|
if (externalRunner && permissionRules) {
|
|
1172
1157
|
throw new AsyncStartValidationError(`Agent '${a.name}' uses runner.type='${externalRunnerType}', which cannot enforce native Pi child permission rules.`);
|
|
1173
1158
|
}
|
|
1174
|
-
if (!externalRunner) {
|
|
1175
|
-
const contractTools = toolPlan.explicitToolAllowlist ? toolPlan.effectiveToolAllowlist : undefined;
|
|
1176
|
-
const contractError = validateImplementationToolContract({
|
|
1177
|
-
agent: a.name,
|
|
1178
|
-
task,
|
|
1179
|
-
tools: contractTools,
|
|
1180
|
-
mcpDirectTools: toolPlan.effectiveMcpTools,
|
|
1181
|
-
configuredExtensions: toolPlan.configuredExtensions,
|
|
1182
|
-
requestedTools: toolPlan.requestedBuiltinTools,
|
|
1183
|
-
acceptanceRole: a.acceptanceRole,
|
|
1184
|
-
completionGuard: a.completionGuard,
|
|
1185
|
-
});
|
|
1186
|
-
if (contractError) throw new AsyncStartValidationError(contractError);
|
|
1187
|
-
}
|
|
1188
1159
|
return {
|
|
1189
|
-
parentSessionId:
|
|
1160
|
+
parentSessionId: launchParentSessionId,
|
|
1190
1161
|
permissionRules,
|
|
1191
|
-
|
|
1192
|
-
|
|
1162
|
+
...(ctx.projectTrusted !== undefined ? { projectTrusted: ctx.projectTrusted } : {}),
|
|
1163
|
+
...(ctx.trustedProjectCwd ? { trustedProjectCwd: ctx.trustedProjectCwd } : {}),
|
|
1193
1164
|
...(params.capabilityCeiling ? { capabilityCeiling: params.capabilityCeiling } : {}),
|
|
1194
1165
|
...(runFanoutPath ? { runFanoutPath } : {}),
|
|
1195
1166
|
agent: s.agent,
|
|
@@ -1218,13 +1189,13 @@ export function buildAsyncRunnerSteps(id: string, params: AsyncRunnerStepBuildPa
|
|
|
1218
1189
|
tools: a.tools,
|
|
1219
1190
|
excludeTools: a.excludeTools,
|
|
1220
1191
|
allowNestedSubagents: a.allowNestedSubagents,
|
|
1192
|
+
allowedAgents: a.allowedAgents,
|
|
1221
1193
|
extensions: a.extensions,
|
|
1222
1194
|
subagentOnlyExtensions: a.subagentOnlyExtensions,
|
|
1223
1195
|
...(!externalRunner ? { requiredExtensions } : {}),
|
|
1224
1196
|
mcpDirectTools: a.mcpDirectTools,
|
|
1225
1197
|
mutationTools: a.mutationTools,
|
|
1226
|
-
|
|
1227
|
-
...(a.sandbox ? { sandbox: a.sandbox } : {}),
|
|
1198
|
+
...(a.sandbox ? { sandbox: a.sandbox } : {}),
|
|
1228
1199
|
systemPrompt,
|
|
1229
1200
|
systemPromptMode: a.systemPromptMode,
|
|
1230
1201
|
inheritProjectContext: a.inheritProjectContext,
|
|
@@ -1359,6 +1330,7 @@ export function buildAsyncRunnerSteps(id: string, params: AsyncRunnerStepBuildPa
|
|
|
1359
1330
|
});
|
|
1360
1331
|
const steps = params.attachRoot
|
|
1361
1332
|
? [{
|
|
1333
|
+
parentSessionId: launchParentSessionId,
|
|
1362
1334
|
agent: params.attachRoot.agent,
|
|
1363
1335
|
task: "",
|
|
1364
1336
|
label: params.attachRoot.label ?? `Attached root ${params.attachRoot.runId}`,
|
|
@@ -1529,6 +1501,7 @@ export function executeAsyncChain(
|
|
|
1529
1501
|
}
|
|
1530
1502
|
const initialStatusAt = Date.now();
|
|
1531
1503
|
const initialCompletionOwnerId = ctx.completionOwnerId ?? currentCompletionOwnerId();
|
|
1504
|
+
const launchParentSessionId = ctx.parentSessionId ?? ctx.currentSessionId;
|
|
1532
1505
|
|
|
1533
1506
|
let spawnResult: SpawnRunnerResult = {};
|
|
1534
1507
|
try {
|
|
@@ -1568,7 +1541,6 @@ export function executeAsyncChain(
|
|
|
1568
1541
|
deadlineAt,
|
|
1569
1542
|
globalConcurrencyLimit: params.globalConcurrencyLimit,
|
|
1570
1543
|
runFanoutBudget,
|
|
1571
|
-
hostAvailableBuiltins: getHostBuiltinToolNames(ctx.pi),
|
|
1572
1544
|
workflowGraph,
|
|
1573
1545
|
...(params.parentWorkflowRunId ? { parentWorkflowRunId: params.parentWorkflowRunId } : {}),
|
|
1574
1546
|
...(params.workflowKey ? { workflowKey: params.workflowKey } : {}),
|
|
@@ -1597,6 +1569,7 @@ export function executeAsyncChain(
|
|
|
1597
1569
|
steps: initialStatusSteps,
|
|
1598
1570
|
},
|
|
1599
1571
|
path.join(asyncDir, "status.json"),
|
|
1572
|
+
launchParentSessionId,
|
|
1600
1573
|
(proof) => emitProcessTerminalEvent(ctx, proof),
|
|
1601
1574
|
(runnerProcessInstanceId) => params.activeAsyncCapacity?.markStarted(runnerProcessInstanceId),
|
|
1602
1575
|
) as SpawnRunnerResult;
|
|
@@ -1782,7 +1755,7 @@ export function executeAsyncSingle(
|
|
|
1782
1755
|
const externalRunner = agentConfig.runner?.type === "external-cli" || agentConfig.runner?.type === "external-job";
|
|
1783
1756
|
const externalRunnerType = agentConfig.runner?.type;
|
|
1784
1757
|
const permissionRules = resolvePermissionRules(ctx.permissions, agentConfig.permissions);
|
|
1785
|
-
|
|
1758
|
+
const sandbox = params.sandbox ?? agentConfig.sandbox;
|
|
1786
1759
|
if (externalRunner) {
|
|
1787
1760
|
const unsupported: string[] = [];
|
|
1788
1761
|
if (params.modelOverride !== undefined) unsupported.push("model override");
|
|
@@ -1791,7 +1764,7 @@ export function executeAsyncSingle(
|
|
|
1791
1764
|
if (params.structuredOutputSchema !== undefined) unsupported.push("structured output");
|
|
1792
1765
|
if (params.acceptance !== undefined || params.agentContract !== undefined) unsupported.push("acceptance/agent contract");
|
|
1793
1766
|
if (params.toolBudget !== undefined || agentConfig.toolBudget !== undefined || params.configToolBudget !== undefined) unsupported.push("tool budget");
|
|
1794
|
-
|
|
1767
|
+
if (sandbox !== undefined) unsupported.push("sandbox profile");
|
|
1795
1768
|
if (params.context === "fork") unsupported.push("fork context");
|
|
1796
1769
|
if ((params.skills?.length ?? 0) > 0) unsupported.push("skills");
|
|
1797
1770
|
if (permissionRules) unsupported.push("native Pi child permissions");
|
|
@@ -1833,9 +1806,9 @@ export function executeAsyncSingle(
|
|
|
1833
1806
|
: params.worktree === true && managedWorktreeProvider === "native"
|
|
1834
1807
|
? resolveExpectedWorktreeAgentCwd(runnerCwd, `${id}-s0`, 0, worktreeBaseDir)
|
|
1835
1808
|
: machine?.cwd ?? runnerCwd;
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1809
|
+
if (sandbox && (agentConfig.source === "project" || agentConfig.override?.scope === "project") && !profileProjectTrustedForCwd(ctx, instructionCwd)) {
|
|
1810
|
+
return formatAsyncStartError("single", profileProjectTrustError(agentConfig, ctx));
|
|
1811
|
+
}
|
|
1839
1812
|
const readExistenceCwd = params.worktree === true ? runnerCwd : instructionCwd;
|
|
1840
1813
|
const skillNames = params.skills ?? agentConfig.skills ?? [];
|
|
1841
1814
|
const availableModels = params.availableModels;
|
|
@@ -1964,8 +1937,8 @@ export function executeAsyncSingle(
|
|
|
1964
1937
|
return formatAsyncStartError("single", error instanceof Error ? error.message : String(error));
|
|
1965
1938
|
}
|
|
1966
1939
|
}
|
|
1967
|
-
const hostAvailableBuiltins = getHostBuiltinToolNames(ctx.pi);
|
|
1968
1940
|
const requiredExtensions = externalRunner ? [] : params.requiredExtensions ?? ctx.childRuntime?.requiredExtensions ?? resolveRequiredChildExtensions(ctx.parentSessionId ?? ctx.currentSessionId ?? undefined);
|
|
1941
|
+
const hostAvailableBuiltins = getHostBuiltinToolNames(ctx.pi);
|
|
1969
1942
|
const toolPlan = resolvePiLaunchToolPlan({
|
|
1970
1943
|
tools: agentConfig.tools,
|
|
1971
1944
|
excludeTools: agentConfig.excludeTools,
|
|
@@ -1984,24 +1957,10 @@ export function executeAsyncSingle(
|
|
|
1984
1957
|
agentName: agentConfig.name,
|
|
1985
1958
|
permissionRules: resolvePermissionRules(ctx.permissions, agentConfig.permissions),
|
|
1986
1959
|
runtimeSnapshotHost: ctx.pi,
|
|
1987
|
-
|
|
1988
|
-
|
|
1960
|
+
sandbox,
|
|
1961
|
+
hostAvailableBuiltins,
|
|
1989
1962
|
});
|
|
1990
1963
|
const launchResolvedExtensions = externalRunner ? undefined : projectLaunchResolvedChildExtensions(toolPlan);
|
|
1991
|
-
if (!externalRunner) {
|
|
1992
|
-
const contractTools = toolPlan.explicitToolAllowlist ? toolPlan.effectiveToolAllowlist : undefined;
|
|
1993
|
-
const contractError = validateImplementationToolContract({
|
|
1994
|
-
agent: agentConfig.name,
|
|
1995
|
-
task: taskText,
|
|
1996
|
-
tools: contractTools,
|
|
1997
|
-
mcpDirectTools: toolPlan.effectiveMcpTools,
|
|
1998
|
-
configuredExtensions: toolPlan.configuredExtensions,
|
|
1999
|
-
requestedTools: toolPlan.requestedBuiltinTools,
|
|
2000
|
-
acceptanceRole: agentConfig.acceptanceRole,
|
|
2001
|
-
completionGuard: agentConfig.completionGuard,
|
|
2002
|
-
});
|
|
2003
|
-
if (contractError) return formatAsyncStartError("single", contractError);
|
|
2004
|
-
}
|
|
2005
1964
|
const fast = params.fast ?? agentConfig.fast;
|
|
2006
1965
|
const launchThinking = resolveEffectiveThinking(selectedModel, effectiveThinking);
|
|
2007
1966
|
const { definitionDigest, launchContractDigest } = resolveLaunchBinding({
|
|
@@ -2011,11 +1970,11 @@ export function executeAsyncSingle(
|
|
|
2011
1970
|
...(fast !== undefined ? { fast } : {}),
|
|
2012
1971
|
...(launchThinking ? { thinking: launchThinking } : {}),
|
|
2013
1972
|
systemPrompt,
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
1973
|
+
systemPromptMode: agentConfig.systemPromptMode,
|
|
1974
|
+
inheritProjectContext: agentConfig.inheritProjectContext,
|
|
1975
|
+
inheritGlobalContext: agentConfig.inheritGlobalContext,
|
|
1976
|
+
inheritSkills: agentConfig.inheritSkills,
|
|
1977
|
+
sandbox,
|
|
2019
1978
|
skills: resolvedSkills.map((skill) => skill.name),
|
|
2020
1979
|
toolPlan,
|
|
2021
1980
|
...(outputPath ? { outputPath } : {}),
|
|
@@ -2044,7 +2003,7 @@ export function executeAsyncSingle(
|
|
|
2044
2003
|
sourceRunId: id,
|
|
2045
2004
|
...(params.agentContract ? { agentContract: params.agentContract } : {}),
|
|
2046
2005
|
agent,
|
|
2047
|
-
|
|
2006
|
+
...(sandbox ? { sandbox } : {}),
|
|
2048
2007
|
launchResolvedExtensions,
|
|
2049
2008
|
...(sessionFile ? { sessionFile } : {}),
|
|
2050
2009
|
cwd: runnerCwd,
|
|
@@ -2058,6 +2017,7 @@ export function executeAsyncSingle(
|
|
|
2058
2017
|
...(recoveryAgentConfig.tools ? { tools: [...recoveryAgentConfig.tools] } : {}),
|
|
2059
2018
|
...(recoveryAgentConfig.excludeTools ? { excludeTools: [...recoveryAgentConfig.excludeTools] } : {}),
|
|
2060
2019
|
...(recoveryAgentConfig.allowNestedSubagents !== undefined ? { allowNestedSubagents: recoveryAgentConfig.allowNestedSubagents } : {}),
|
|
2020
|
+
...(recoveryAgentConfig.allowedAgents !== undefined ? { allowedAgents: [...recoveryAgentConfig.allowedAgents] } : {}),
|
|
2061
2021
|
...(recoveryAgentConfig.extensions ? { extensions: [...recoveryAgentConfig.extensions] } : {}),
|
|
2062
2022
|
...(recoveryAgentConfig.subagentOnlyExtensions ? { subagentOnlyExtensions: [...recoveryAgentConfig.subagentOnlyExtensions] } : {}),
|
|
2063
2023
|
...(recoveryAgentConfig.mcpDirectTools ? { mcpDirectTools: [...recoveryAgentConfig.mcpDirectTools] } : {}),
|
|
@@ -2070,7 +2030,6 @@ export function executeAsyncSingle(
|
|
|
2070
2030
|
...(resolvedSkills.length ? { skills: resolvedSkills.map((skill) => skill.name) } : {}),
|
|
2071
2031
|
...(recoveryAgentConfig.skillPath ? { skillPath: [...recoveryAgentConfig.skillPath] } : {}),
|
|
2072
2032
|
...(recoveryAgentConfig.filePath ? { agentFilePath: recoveryAgentConfig.filePath } : {}),
|
|
2073
|
-
...(recoveryAgentConfig.completionGuard !== undefined ? { completionGuard: recoveryAgentConfig.completionGuard } : {}),
|
|
2074
2033
|
...(recoveryAgentConfig.memory ? { memory: { ...recoveryAgentConfig.memory } } : {}),
|
|
2075
2034
|
...(outputPath ? { outputPath } : {}),
|
|
2076
2035
|
outputMode,
|
|
@@ -2100,16 +2059,17 @@ export function executeAsyncSingle(
|
|
|
2100
2059
|
let spawnResultOrPromise: SpawnRunnerResult | Promise<SpawnRunnerResult> = {};
|
|
2101
2060
|
const initialStatusAt = Date.now();
|
|
2102
2061
|
const initialCompletionOwnerId = ctx.completionOwnerId ?? currentCompletionOwnerId();
|
|
2062
|
+
const launchParentSessionId = ctx.parentSessionId ?? ctx.currentSessionId;
|
|
2103
2063
|
try {
|
|
2104
2064
|
spawnResultOrPromise = spawnRunner(
|
|
2105
2065
|
{
|
|
2106
2066
|
id,
|
|
2107
2067
|
steps: [
|
|
2108
2068
|
{
|
|
2109
|
-
parentSessionId:
|
|
2069
|
+
parentSessionId: launchParentSessionId,
|
|
2110
2070
|
permissionRules,
|
|
2111
|
-
|
|
2112
|
-
|
|
2071
|
+
...(ctx.projectTrusted !== undefined ? { projectTrusted: ctx.projectTrusted } : {}),
|
|
2072
|
+
...(ctx.trustedProjectCwd ? { trustedProjectCwd: ctx.trustedProjectCwd } : {}),
|
|
2113
2073
|
...(capabilityCeiling ? { capabilityCeiling } : {}),
|
|
2114
2074
|
agent,
|
|
2115
2075
|
task: taskText,
|
|
@@ -2133,13 +2093,13 @@ export function executeAsyncSingle(
|
|
|
2133
2093
|
tools: agentConfig.tools,
|
|
2134
2094
|
excludeTools: agentConfig.excludeTools,
|
|
2135
2095
|
allowNestedSubagents: agentConfig.allowNestedSubagents,
|
|
2096
|
+
allowedAgents: agentConfig.allowedAgents,
|
|
2136
2097
|
extensions: agentConfig.extensions,
|
|
2137
2098
|
subagentOnlyExtensions: agentConfig.subagentOnlyExtensions,
|
|
2138
2099
|
...(!externalRunner ? { requiredExtensions } : {}),
|
|
2139
2100
|
mcpDirectTools: agentConfig.mcpDirectTools,
|
|
2140
2101
|
mutationTools: agentConfig.mutationTools,
|
|
2141
|
-
|
|
2142
|
-
...(sandbox ? { sandbox } : {}),
|
|
2102
|
+
...(sandbox ? { sandbox } : {}),
|
|
2143
2103
|
systemPrompt,
|
|
2144
2104
|
systemPromptMode: agentConfig.systemPromptMode,
|
|
2145
2105
|
inheritProjectContext: agentConfig.inheritProjectContext,
|
|
@@ -2204,7 +2164,6 @@ export function executeAsyncSingle(
|
|
|
2204
2164
|
launchContractDigest,
|
|
2205
2165
|
launchResolvedExtensions,
|
|
2206
2166
|
runFanoutBudget,
|
|
2207
|
-
hostAvailableBuiltins,
|
|
2208
2167
|
...(params.parentWorkflowRunId ? { parentWorkflowRunId: params.parentWorkflowRunId } : {}),
|
|
2209
2168
|
...(params.workflowKey ? { workflowKey: params.workflowKey } : {}),
|
|
2210
2169
|
...(lane ? { lane } : {}),
|
|
@@ -2234,6 +2193,7 @@ export function executeAsyncSingle(
|
|
|
2234
2193
|
steps: [{ agent, status: "pending", ...(lane ? { lane } : {}), ...(model ? { model } : {}), ...(contextLimit !== undefined ? { contextLimit } : {}) }],
|
|
2235
2194
|
},
|
|
2236
2195
|
path.join(asyncDir, "status.json"),
|
|
2196
|
+
launchParentSessionId,
|
|
2237
2197
|
(proof) => emitProcessTerminalEvent(ctx, proof),
|
|
2238
2198
|
(runnerProcessInstanceId) => params.activeAsyncCapacity?.markStarted(runnerProcessInstanceId),
|
|
2239
2199
|
params.requestedCwd ?? runnerCwd,
|
|
@@ -2280,7 +2240,7 @@ export function executeAsyncSingle(
|
|
|
2280
2240
|
mode: "single",
|
|
2281
2241
|
state: "running",
|
|
2282
2242
|
agent,
|
|
2283
|
-
|
|
2243
|
+
...(sandbox ? { sandbox } : {}),
|
|
2284
2244
|
agents: [agent],
|
|
2285
2245
|
chainStepCount: 1,
|
|
2286
2246
|
...(timeoutMs !== undefined ? { timeoutMs, deadlineAt } : {}),
|
|
@@ -2301,7 +2261,7 @@ export function executeAsyncSingle(
|
|
|
2301
2261
|
completionOwnerId: ctx.completionOwnerId ?? currentCompletionOwnerId(),
|
|
2302
2262
|
mode: "single",
|
|
2303
2263
|
agent,
|
|
2304
|
-
|
|
2264
|
+
...(sandbox ? { sandbox } : {}),
|
|
2305
2265
|
task: task?.trim() ? PROMPT_REDACTED : undefined,
|
|
2306
2266
|
goal: (params.goal ?? task).trim() ? PROMPT_REDACTED : undefined,
|
|
2307
2267
|
cwd: runnerCwd,
|