pi-subagents 0.83.1 → 0.85.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 +79 -0
- package/bundle/agents.js +3 -3
- package/bundle/child-tool-plan.js +2 -2
- package/bundle/{chunk-5YIITCPD.js → chunk-3UZ5FVVJ.js} +322 -110
- package/bundle/{chunk-F4ASL6OV.js → chunk-7MAE3DJV.js} +1 -1
- package/bundle/{chunk-YXFJVCOL.js → chunk-CS4O36CZ.js} +11 -156
- package/bundle/{chunk-AHIFYGR3.js → chunk-DV2NCNPR.js} +22 -11
- package/bundle/{chunk-G2Z6ZH26.js → chunk-GCSLVFCX.js} +1 -1
- package/bundle/{chunk-2S4K53MV.js → chunk-H2NLFTC5.js} +1 -1
- package/bundle/{chunk-MABL3FUM.js → chunk-HFTBF7SG.js} +2 -1
- package/bundle/chunk-HXRB42AF.js +108 -0
- package/bundle/{chunk-UFL7IYCW.js → chunk-IQIWF2VX.js} +190 -1177
- package/bundle/{chunk-NPIYWVOD.js → chunk-JNXT3MPI.js} +15 -6
- package/bundle/{chunk-C7JMPU5F.js → chunk-JO67XSKD.js} +59 -27
- package/bundle/{chunk-UUP372DR.js → chunk-JWYG26RE.js} +223 -93
- package/bundle/{chunk-C5P5CHYK.js → chunk-KDMFBYFM.js} +1 -1
- package/bundle/{chunk-V2BZYLEP.js → chunk-KEY3UQMQ.js} +7 -2
- package/bundle/{chunk-VLFZIN6D.js → chunk-KZ34KQQH.js} +9 -6
- package/bundle/{chunk-ZVOAMTUQ.js → chunk-L2ENOFVZ.js} +76 -58
- package/bundle/{chunk-RNIZLSEA.js → chunk-LGMILZNE.js} +323 -18
- package/bundle/{chunk-UYK5MZWE.js → chunk-LTPH2DXH.js} +247 -153
- package/bundle/{chunk-2D52JFLF.js → chunk-N7B2KD74.js} +41 -117
- package/bundle/{chunk-IPGZMQXV.js → chunk-O7CPL6H4.js} +183 -28
- package/bundle/{chunk-D3JAFGMO.js → chunk-PHZP3KHB.js} +1 -1
- package/bundle/{chunk-2DHZTCOL.js → chunk-PVIVCDG2.js} +2 -2
- package/bundle/{chunk-LFDBD4PW.js → chunk-QO75KJBT.js} +2 -2
- package/bundle/{chunk-SSG7IEP5.js → chunk-RQAUNAWG.js} +2 -2
- package/bundle/{chunk-QP5ZWNIS.js → chunk-RV5OGHLO.js} +6 -3
- package/bundle/chunk-T5V5BRCL.js +1067 -0
- package/bundle/{chunk-LNRJCP2Y.js → chunk-UX4SCV5N.js} +337 -207
- package/bundle/{chunk-F5DBXJ2G.js → chunk-WOVMHDES.js} +234 -182
- package/bundle/control-channel.js +2 -2
- package/bundle/index.js +1 -1
- package/bundle/intercom-bridge.js +2 -2
- package/bundle/preflight.js +8 -8
- package/bundle/project-panes.js +3 -3
- package/docs/agents.md +17 -2
- package/docs/configuration.md +2 -2
- package/docs/extension-api.md +16 -1
- package/docs/workflows.md +30 -2
- package/package.json +1 -1
- package/src/agents/agent-management.js +27 -11
- package/src/agents/agent-memory.d.ts +1 -4
- package/src/agents/agent-memory.js +1 -4
- package/src/agents/agents.d.ts +1 -3
- package/src/agents/agents.js +7 -6
- package/src/agents/frontmatter.js +1 -8
- package/src/agents/global-npm-root.d.ts +1 -0
- package/src/agents/global-npm-root.js +11 -3
- package/src/agents/skills.d.ts +0 -3
- package/src/agents/skills.js +0 -3
- package/src/extension/config.js +7 -1
- package/src/extension/herdr-pi-bridge.js +10 -2
- package/src/extension/index.d.ts +0 -13
- package/src/extension/index.js +43 -32
- package/src/extension/public-execution.d.ts +1 -0
- package/src/extension/public-execution.js +4 -0
- package/src/extension/reply-workflow-script.js +24 -4
- package/src/extension/schemas.d.ts +8 -3
- package/src/extension/schemas.js +5 -3
- package/src/extension/session-switch.d.ts +25 -0
- package/src/extension/session-switch.js +138 -0
- package/src/extension/subagent-guide.d.ts +1 -1
- package/src/extension/subagent-guide.js +1 -1
- package/src/extension/subagent-launch-tool.d.ts +25 -0
- package/src/extension/subagent-launch-tool.js +48 -0
- package/src/extension/tool-activation.js +25 -11
- package/src/extension/tool-description.js +6 -0
- package/src/inspectors/herdr/actions.d.ts +0 -1
- package/src/inspectors/herdr/actions.js +0 -1
- package/src/inspectors/session-roots-codec.d.ts +0 -1
- package/src/inspectors/session-roots-codec.js +0 -1
- package/src/inspectors/tmux/actions.d.ts +0 -1
- package/src/inspectors/tmux/actions.js +0 -1
- package/src/integrations/herdr-status.js +3 -8
- package/src/intercom/native-supervisor-channel.js +65 -9
- package/src/runs/background/async-execution.d.ts +8 -9
- package/src/runs/background/async-execution.js +77 -27
- package/src/runs/background/async-job-tracker.js +12 -0
- package/src/runs/background/async-resume.d.ts +2 -1
- package/src/runs/background/async-resume.js +112 -39
- package/src/runs/background/async-retention.d.ts +1 -0
- package/src/runs/background/async-retention.js +22 -11
- package/src/runs/background/auto-drain.js +2 -1
- package/src/runs/background/boot-id.d.ts +1 -3
- package/src/runs/background/boot-id.js +1 -3
- package/src/runs/background/completion-batcher.d.ts +3 -4
- package/src/runs/background/completion-batcher.js +2 -3
- package/src/runs/background/control-channel.d.ts +0 -6
- package/src/runs/background/control-channel.js +0 -6
- package/src/runs/background/fleet-view.js +2 -3
- package/src/runs/background/notify.d.ts +0 -2
- package/src/runs/background/notify.js +0 -2
- package/src/runs/background/result-watcher.d.ts +1 -0
- package/src/runs/background/result-watcher.js +59 -29
- package/src/runs/background/resume-guidance.js +4 -2
- package/src/runs/background/retained-children.js +2 -1
- package/src/runs/background/run-child-session.d.ts +2 -1
- package/src/runs/background/run-child-session.js +10 -2
- package/src/runs/background/run-status.js +4 -3
- package/src/runs/background/scheduled-runs.d.ts +3 -1
- package/src/runs/background/scheduled-runs.js +13 -16
- package/src/runs/background/subagent-runner.d.ts +2 -4
- package/src/runs/background/subagent-runner.js +10 -6
- package/src/runs/background/subagent-wait.js +12 -15
- package/src/runs/background/wait-config.d.ts +2 -0
- package/src/runs/background/wait-config.js +17 -3
- package/src/runs/background/wait-tool.js +4 -2
- package/src/runs/background/workflow-terminal-proof.d.ts +0 -1
- package/src/runs/background/workflow-terminal-proof.js +0 -1
- package/src/runs/foreground/execution.d.ts +0 -3
- package/src/runs/foreground/execution.js +17 -9
- package/src/runs/foreground/subagent-executor.d.ts +3 -2
- package/src/runs/foreground/subagent-executor.js +112 -26
- package/src/runs/shared/child-commands.js +15 -2
- package/src/runs/shared/child-hooks.d.ts +1 -7
- package/src/runs/shared/child-hooks.js +13 -5
- package/src/runs/shared/child-launch.js +6 -2
- package/src/runs/shared/child-runtime-config.d.ts +0 -1
- package/src/runs/shared/child-session.d.ts +3 -1
- package/src/runs/shared/child-session.js +22 -2
- package/src/runs/shared/child-tool-plan.d.ts +0 -1
- package/src/runs/shared/child-tool-plan.js +0 -1
- package/src/runs/shared/claude-code-adapter.js +11 -0
- package/src/runs/shared/external-cli-runner.js +26 -6
- package/src/runs/shared/herdr-connection.js +2 -1
- package/src/runs/shared/herdr-pane-host.d.ts +2 -2
- package/src/runs/shared/herdr-pane-host.js +17 -1
- package/src/runs/shared/herdr-placed-run.js +48 -22
- package/src/runs/shared/lane-metadata.d.ts +0 -1
- package/src/runs/shared/lane-metadata.js +0 -1
- package/src/runs/shared/mcp-direct-tool-grant.js +8 -1
- package/src/runs/shared/model-resolution-diagnostic.d.ts +11 -1
- package/src/runs/shared/model-resolution-diagnostic.js +25 -0
- package/src/runs/shared/model-resolution.d.ts +2 -2
- package/src/runs/shared/model-resolution.js +7 -1
- package/src/runs/shared/model-scope.d.ts +1 -5
- package/src/runs/shared/model-scope.js +1 -5
- package/src/runs/shared/mutation-evidence.d.ts +1 -1
- package/src/runs/shared/mutation-evidence.js +52 -7
- package/src/runs/shared/nested-events.d.ts +1 -0
- package/src/runs/shared/nested-events.js +1 -1
- package/src/runs/shared/parallel-utils.d.ts +2 -1
- package/src/runs/shared/permissions.js +5 -3
- package/src/runs/shared/placement-host.d.ts +5 -1
- package/src/runs/shared/rex-pane-host.d.ts +0 -1
- package/src/runs/shared/rex-pane-host.js +0 -2
- package/src/runs/shared/run-launch-folder.d.ts +12 -0
- package/src/runs/shared/run-launch-folder.js +21 -0
- package/src/runs/shared/runner-launcher.d.ts +12 -1
- package/src/runs/shared/runner-launcher.js +16 -0
- package/src/runs/shared/single-output.d.ts +3 -3
- package/src/runs/shared/single-output.js +5 -3
- package/src/runs/shared/structured-output.d.ts +8 -0
- package/src/runs/shared/structured-output.js +30 -2
- package/src/runs/shared/subagent-prompt-runtime.d.ts +0 -1
- package/src/runs/shared/subagent-prompt-runtime.js +4 -2
- package/src/runs/shared/tool-timeout.js +2 -1
- package/src/runs/shared/worktree-cleanup-plan.d.ts +0 -1
- package/src/runs/shared/worktree-cleanup-plan.js +0 -1
- package/src/runs/shared/worktree.d.ts +3 -0
- package/src/runs/shared/worktree.js +20 -0
- package/src/shared/capacity-resilient-json.d.ts +1 -1
- package/src/shared/child-cache-retention.d.ts +1 -2
- package/src/shared/child-cache-retention.js +1 -2
- package/src/shared/fleet-transcript-reader.d.ts +51 -0
- package/src/shared/fleet-transcript-reader.js +333 -0
- package/src/shared/formatters.d.ts +0 -18
- package/src/shared/formatters.js +0 -18
- package/src/shared/session-succession.d.ts +16 -1
- package/src/shared/session-succession.js +41 -2
- package/src/shared/session-warnings.d.ts +7 -0
- package/src/shared/session-warnings.js +26 -0
- package/src/shared/settings.d.ts +0 -23
- package/src/shared/settings.js +3 -35
- package/src/shared/types.d.ts +28 -11
- package/src/shared/types.js +0 -12
- package/src/shared/utils.d.ts +0 -14
- package/src/shared/utils.js +0 -22
- package/src/shared/wait-tool-name.d.ts +8 -0
- package/src/shared/wait-tool-name.js +13 -0
- package/src/slash/slash-commands.js +2 -1
- package/src/slash/subagent-cost.d.ts +3 -2
- package/src/slash/subagent-cost.js +22 -3
- package/src/slash/subagents-admin.js +0 -1
- package/src/tui/fleet-status.d.ts +0 -5
- package/src/tui/fleet-status.js +4 -24
- package/src/tui/fleet-transcript.d.ts +1 -44
- package/src/tui/fleet-transcript.js +1 -327
- package/src/tui/fleet.js +6 -4
- package/src/tui/render.d.ts +0 -9
- package/src/tui/render.js +81 -47
- package/src/tui/subagent-messages.js +3 -2
- package/src/watchdog/register-child.d.ts +2 -3
- package/src/watchdog/register-child.js +2 -3
- package/src/watchdog/turn-delta.js +2 -1
- package/src/workflows/scripted-workflow.js +243 -20
- package/src/workflows/workflow-launch-record.d.ts +15 -6
- package/src/workflows/workflow-launch-record.js +30 -12
- package/src/workflows/workflow-resume-claim.js +2 -2
- package/src/workflows/workflow-resume.d.ts +1 -1
- package/src/workflows/workflow-resume.js +11 -8
- package/src/workflows/workflow-script-worker.d.ts +13 -0
- package/src/workflows/workflow-script-worker.js +79 -0
- package/workflow-script-process.cjs +36 -0
- package/workflow-script-worker.cjs +453 -176
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Async execution logic for subagent tool
|
|
3
|
-
*/
|
|
4
1
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import type { ParentProviderRegistry } from "../shared/child-session.ts";
|
|
5
3
|
import { type AgentConfig, type UnknownAgentDiagnosticContext } from "../../agents/agents.ts";
|
|
6
4
|
import { type ClaudeCodeOverride } from "../shared/claude-code-adapter.ts";
|
|
7
5
|
import { type ChainStep } from "../../shared/settings.ts";
|
|
@@ -16,6 +14,7 @@ import { type ChildRuntimeConfig } from "../shared/child-runtime-config.ts";
|
|
|
16
14
|
import type { ImportedAsyncRoot } from "./chain-root-attachment.ts";
|
|
17
15
|
import type { SessionLeaseRequest } from "../shared/session-lease.ts";
|
|
18
16
|
import type { ActiveAsyncCapacityHandle } from "./active-async-capacity.ts";
|
|
17
|
+
import { type RequiredRunnerLauncher } from "../../shared/types.ts";
|
|
19
18
|
import { type ResolvedSubagentCapabilityCeiling } from "../shared/capability-ceiling.ts";
|
|
20
19
|
import { type PermissionConfig } from "../shared/permissions.ts";
|
|
21
20
|
import { type ExtensionBindings } from "../shared/extension-bindings.ts";
|
|
@@ -44,6 +43,8 @@ interface AsyncExecutionContext {
|
|
|
44
43
|
childRuntime?: ChildRuntimeConfig;
|
|
45
44
|
/** The launching session's project trust; undefined when the host has no trust concept. */
|
|
46
45
|
projectTrusted?: boolean;
|
|
46
|
+
/** The parent's model registry, read at launch to name a provider an extension registered there. */
|
|
47
|
+
parentProviderRegistry?: Pick<ParentProviderRegistry, "getRegisteredProviderIds">;
|
|
47
48
|
}
|
|
48
49
|
export declare const DEFAULT_ASYNC_TIMEOUT_MS: number;
|
|
49
50
|
interface AsyncChainParams {
|
|
@@ -131,6 +132,10 @@ interface AsyncSingleParams {
|
|
|
131
132
|
machine?: string;
|
|
132
133
|
/** Launch cwd as typed when a machine is set: a path on that machine, never resolved locally. */
|
|
133
134
|
machineCwd?: string;
|
|
135
|
+
/** The launcher and agent definition digest the call requires; checked here, on what this launch spawns. */
|
|
136
|
+
requireLauncher?: RequiredRunnerLauncher;
|
|
137
|
+
/** A revived run's inherited requirement: recorded for its own resumes, not checked here (resume already checked it). */
|
|
138
|
+
carriedRequiredLauncher?: RequiredRunnerLauncher;
|
|
134
139
|
maxOutput?: MaxOutputConfig;
|
|
135
140
|
artifactsDir?: string;
|
|
136
141
|
artifactConfig: ArtifactConfig;
|
|
@@ -285,13 +290,7 @@ export declare function resolveClaudeCodeThinking(source: string | false | undef
|
|
|
285
290
|
* owns the remote model registry, so the combination fails instead of losing both flags. */
|
|
286
291
|
export declare function assertClaudeCodeOverrideIsLocal(agent: string, machine: string | undefined, override: ClaudeCodeOverride | undefined): void;
|
|
287
292
|
export declare function buildAsyncRunnerSteps(id: string, params: AsyncRunnerStepBuildParams): AsyncRunnerStepBuildResult;
|
|
288
|
-
/**
|
|
289
|
-
* Execute a chain asynchronously
|
|
290
|
-
*/
|
|
291
293
|
export declare function executeAsyncChain(id: string, params: AsyncChainParams): AsyncExecutionResult | Promise<AsyncExecutionResult>;
|
|
292
|
-
/**
|
|
293
|
-
* Execute a single agent asynchronously
|
|
294
|
-
*/
|
|
295
294
|
export declare function workflowAwaitedAsyncResultPath(asyncDir: string): string;
|
|
296
295
|
export declare function executeAsyncSingle(id: string, params: AsyncSingleParams): AsyncExecutionResult | Promise<AsyncExecutionResult>;
|
|
297
296
|
export {};
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* Async execution logic for subagent tool
|
|
3
|
-
*/
|
|
4
|
-
import { spawn } from "node:child_process";
|
|
1
|
+
import { spawn, spawnSync } from "node:child_process";
|
|
5
2
|
import { randomUUID } from "node:crypto";
|
|
6
3
|
import * as fs from "node:fs";
|
|
7
4
|
import * as path from "node:path";
|
|
@@ -33,7 +30,7 @@ import { resolveToolTimeoutMs, toolTimeoutFromEnv } from "../shared/tool-timeout
|
|
|
33
30
|
import { resolveModelScopesForAgent } from "../shared/model-scope.js";
|
|
34
31
|
import { findModelInfo, resolveEffectiveThinking } from "../../shared/model-info.js";
|
|
35
32
|
import { assertThinkingWithinCeiling, intersectThinkingCeilings } from "../../shared/thinking-ceiling.js";
|
|
36
|
-
import { resolveExpectedWorktreeAgentCwd, resolveWorktreeProvider, shouldDeferWorktreeCwd, WORKTREE_AGENT_CWD_PLACEHOLDER } from "../shared/worktree.js";
|
|
33
|
+
import { buildWorktreeNaming, resolveExpectedWorktreeAgentCwd, resolveWorktreeProvider, shouldDeferWorktreeCwd, WORKTREE_AGENT_CWD_PLACEHOLDER } from "../shared/worktree.js";
|
|
37
34
|
import { buildWorkflowGraphSnapshot } from "../shared/workflow-graph.js";
|
|
38
35
|
import { ChainOutputValidationError, validateChainOutputBindings } from "../shared/chain-outputs.js";
|
|
39
36
|
import { createStructuredOutputRuntime } from "../shared/structured-output.js";
|
|
@@ -54,7 +51,7 @@ import { statusStepDescription } from "./chain-append.js";
|
|
|
54
51
|
import { currentBootId, currentRecordedPid } from "./boot-id.js";
|
|
55
52
|
import { currentPidNamespaceScope } from "./pid-namespace.js";
|
|
56
53
|
import { checkRecordedPidLiveness } from "./stale-run-reconciler.js";
|
|
57
|
-
import { lookupRunnerLauncher, resolveAgentRunnerLauncher, runnerLauncherPlacementError } from "../shared/runner-launcher.js";
|
|
54
|
+
import { checkRequiredRunnerLauncher, lookupRunnerLauncher, resolveAgentRunnerLauncher, runnerLauncherPlacementError } from "../shared/runner-launcher.js";
|
|
58
55
|
import { SUBAGENT_PROCESS_TERMINAL_EVENT } from "../../shared/types.js";
|
|
59
56
|
import { assertAgentAllowedByCapabilityCeiling, intersectSubagentCapabilityCeilings, resolveCurrentSubagentCapabilityCeiling } from "../shared/capability-ceiling.js";
|
|
60
57
|
import { resolveLaunchBinding } from "../../shared/launch-contract.js";
|
|
@@ -62,7 +59,9 @@ import { resolvePermissionRules } from "../shared/permissions.js";
|
|
|
62
59
|
import { normalizeExtensionBindings, omitExtensionBindingsEnv } from "../shared/extension-bindings.js";
|
|
63
60
|
import { omitGitRoutingEnv } from "../shared/git-environment.js";
|
|
64
61
|
import { assertWorkflowLaneKey, normalizeWorkflowLaneMetadata } from "../shared/lane-metadata.js";
|
|
62
|
+
import { recoveryDescriptorPath } from "../shared/run-launch-folder.js";
|
|
65
63
|
import { assertRequiredChildExtensionsAdmitted, resolveRequiredChildExtensions, writeRetainedRequiredChildExtensions } from "../../shared/required-child-extensions.js";
|
|
64
|
+
import { DEFAULT_WAIT_TOOL_NAME, waitToolName } from "../../shared/wait-tool-name.js";
|
|
66
65
|
const require = nodeModule.createRequire(import.meta.url);
|
|
67
66
|
// Cache failures as well as roots: management must remain loadable, and launches must not retry another SDK.
|
|
68
67
|
const piPackageSelection = (() => {
|
|
@@ -135,15 +134,26 @@ function supportsNativeRunner(nodeExecutable) {
|
|
|
135
134
|
&& nodeExecutable === process.execPath
|
|
136
135
|
&& !sourceUnderNodeModules();
|
|
137
136
|
}
|
|
137
|
+
/**
|
|
138
|
+
* A runner child without the ambient extensions does not load the parent extension that
|
|
139
|
+
* registered its model's provider, and still resolves the model when a built-in provider
|
|
140
|
+
* has the same id. Name that provider so a failed run can say so.
|
|
141
|
+
*/
|
|
142
|
+
function parentExtensionProviderForChild(ctx, disableAmbientExtensions, model, availableModels, preferredProvider) {
|
|
143
|
+
if (!disableAmbientExtensions || !ctx.parentProviderRegistry)
|
|
144
|
+
return undefined;
|
|
145
|
+
const provider = findModelInfo(model, availableModels, preferredProvider)?.provider;
|
|
146
|
+
return provider && ctx.parentProviderRegistry.getRegisteredProviderIds().includes(provider) ? provider : undefined;
|
|
147
|
+
}
|
|
138
148
|
export const DEFAULT_ASYNC_TIMEOUT_MS = 30 * 60 * 1000;
|
|
139
149
|
export function formatAsyncStartedMessage(headline, interactive) {
|
|
140
150
|
const guidance = interactive
|
|
141
151
|
? [
|
|
142
|
-
|
|
152
|
+
`Detached. Return control now: native completion wakes you, so do not sleep, poll, or call ${waitToolName()} for it.`,
|
|
143
153
|
"One-shot check: subagent({ action: \"status\", id: \"...\" }).",
|
|
144
154
|
]
|
|
145
155
|
: [
|
|
146
|
-
|
|
156
|
+
`Detached non-interactive run: Pi auto-drains current-session subagent work at agent_end. Do not run sleep timers or polling loops. Use ${waitToolName()} only for results this turn needs from work without native notification, and subagent({ action: \"status\", id: \"...\" }) for a one-shot check.`,
|
|
147
157
|
];
|
|
148
158
|
return [headline, "", ...guidance].join("\n");
|
|
149
159
|
}
|
|
@@ -172,9 +182,6 @@ function closeFd(fd) {
|
|
|
172
182
|
// Best-effort cleanup; child process already owns its duplicated stdio fd.
|
|
173
183
|
}
|
|
174
184
|
}
|
|
175
|
-
/**
|
|
176
|
-
* Spawn the async runner process
|
|
177
|
-
*/
|
|
178
185
|
const RUNNER_STARTUP_TIMEOUT_MS = 10_000;
|
|
179
186
|
function waitForStartupInterval(delayMs = 20) {
|
|
180
187
|
return new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
@@ -276,6 +283,33 @@ function terminateRunnerBeforeProceed(pid) {
|
|
|
276
283
|
}
|
|
277
284
|
return !runnerIsAlive(pid);
|
|
278
285
|
}
|
|
286
|
+
function parentPid(pid) {
|
|
287
|
+
let ppid;
|
|
288
|
+
if (process.platform === "linux") {
|
|
289
|
+
try {
|
|
290
|
+
const stat = fs.readFileSync(`/proc/${pid}/stat`, "utf-8");
|
|
291
|
+
ppid = Number(stat.slice(stat.lastIndexOf(")") + 1).trim().split(/\s+/)[1]);
|
|
292
|
+
}
|
|
293
|
+
catch {
|
|
294
|
+
return undefined;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
else {
|
|
298
|
+
const result = spawnSync("ps", ["-o", "ppid=", "-p", String(pid)], { encoding: "utf-8" });
|
|
299
|
+
if (result.error || result.status !== 0)
|
|
300
|
+
return undefined;
|
|
301
|
+
ppid = Number(result.stdout.trim());
|
|
302
|
+
}
|
|
303
|
+
return Number.isSafeInteger(ppid) && ppid > 0 ? ppid : undefined;
|
|
304
|
+
}
|
|
305
|
+
/** The runner reports its own pid, so behind a launcher only a pid inside the spawned launcher's tree may be signalled. */
|
|
306
|
+
function isInProcessTree(pid, rootPid) {
|
|
307
|
+
for (let current = pid; current !== undefined && current > 1; current = parentPid(current)) {
|
|
308
|
+
if (current === rootPid)
|
|
309
|
+
return true;
|
|
310
|
+
}
|
|
311
|
+
return false;
|
|
312
|
+
}
|
|
279
313
|
async function terminateRunnerBeforeProceedAsyncDefault(proc, processClosed) {
|
|
280
314
|
for (const signal of ["SIGTERM", "SIGKILL"]) {
|
|
281
315
|
if (proc.pid === undefined || !runnerIsAlive(proc.pid))
|
|
@@ -438,7 +472,7 @@ function spawnRunner(cfg, suffix, cwd, initialStatus, initialStatusPath, launchP
|
|
|
438
472
|
// its own identity before it is allowed to proceed.
|
|
439
473
|
const launcher = cfg.launcher;
|
|
440
474
|
const bootId = launcher ? undefined : currentBootId();
|
|
441
|
-
const launchConfig = { ...cfg, runnerProcessInstanceId, ...(launchBarrierToken ? { launchBarrierToken } : {}), ...(bootId ? { bootId } : {}) };
|
|
475
|
+
const launchConfig = { ...cfg, runnerProcessInstanceId, ...(launchBarrierToken ? { launchBarrierToken } : {}), ...(bootId ? { bootId } : {}), ...(waitToolName() !== DEFAULT_WAIT_TOOL_NAME ? { waitToolName: waitToolName() } : {}) };
|
|
442
476
|
writePrivateAtomicJson(cfgPath, launchConfig);
|
|
443
477
|
const command = binaryHost ?? nodeExecutable;
|
|
444
478
|
const launchForStartup = launchConfig;
|
|
@@ -466,10 +500,12 @@ function spawnRunner(cfg, suffix, cwd, initialStatus, initialStatusPath, launchP
|
|
|
466
500
|
if (identityPath)
|
|
467
501
|
fs.rmSync(identityPath, { force: true });
|
|
468
502
|
let runnerIdentity;
|
|
469
|
-
// Wrapper exit is not runner exit, so only a reported runner in this namespace may be signalled
|
|
503
|
+
// Wrapper exit is not runner exit, so only a reported runner in this namespace may be signalled, and only
|
|
504
|
+
// inside the spawned launcher's process tree. Otherwise the runner exits when proceed never arrives.
|
|
470
505
|
const terminateBeforeProceed = (pid) => !launcher
|
|
471
506
|
? terminateRunnerBeforeProceed(pid)
|
|
472
|
-
: runnerIdentity !== undefined && runnerIdentity.pidNamespaceScope === currentPidNamespaceScope()
|
|
507
|
+
: runnerIdentity !== undefined && runnerIdentity.pidNamespaceScope === currentPidNamespaceScope()
|
|
508
|
+
&& isInProcessTree(runnerIdentity.pid, pid) && terminateRunnerBeforeProceed(runnerIdentity.pid);
|
|
473
509
|
const adoptRunnerIdentity = (pid, pidNamespaceScope) => {
|
|
474
510
|
if (typeof pid !== "number" || !Number.isSafeInteger(pid) || pid < 1)
|
|
475
511
|
return `Async runner reported an invalid process identity in '${launchAsyncDir}'.`;
|
|
@@ -917,7 +953,7 @@ export function buildAsyncRunnerSteps(id, params) {
|
|
|
917
953
|
taskTemplate = taskTemplate.replace(/\{chain_dir\}/g, behaviorCwd ?? runnerCwd);
|
|
918
954
|
const taskText = `${readInstructions.prefix}${taskTemplate}${progressInstructions.suffix}`;
|
|
919
955
|
// A namespaced parallel output path is added to each child's task by the runner.
|
|
920
|
-
const task = namespaceOutputPath ? taskText : injectSingleOutputInstruction(taskText, outputPath, a);
|
|
956
|
+
const task = namespaceOutputPath ? taskText : injectSingleOutputInstruction(taskText, outputPath, a, machine);
|
|
921
957
|
const modelScopes = resolveModelScopesForAgent(ctx.modelScope, a.name, ctx.currentModel, ctx.scopedModelIds);
|
|
922
958
|
const modelOrigin = resolveModelOrigin({ explicitModel: s.model, agentModel: a.model, parentModel: ctx.currentModel });
|
|
923
959
|
const primaryModelFromParent = modelOrigin === "inherited";
|
|
@@ -976,7 +1012,8 @@ export function buildAsyncRunnerSteps(id, params) {
|
|
|
976
1012
|
if (launchRuleError)
|
|
977
1013
|
throw new AsyncStartValidationError(launchRuleError);
|
|
978
1014
|
const fast = s.fast ?? params.fast ?? a.fast;
|
|
979
|
-
|
|
1015
|
+
// Admission already refused mandatory entries for a placed child, which skips the rest.
|
|
1016
|
+
const requiredExtensions = externalRunner || machine ? [] : params.requiredExtensions ?? ctx.childRuntime?.requiredExtensions ?? registeredExtensions;
|
|
980
1017
|
const toolPlan = resolvePiLaunchToolPlan({
|
|
981
1018
|
tools: a.tools,
|
|
982
1019
|
excludeTools: a.excludeTools,
|
|
@@ -997,6 +1034,7 @@ export function buildAsyncRunnerSteps(id, params) {
|
|
|
997
1034
|
runtimeSnapshotHost: ctx.pi,
|
|
998
1035
|
});
|
|
999
1036
|
const launchResolvedExtensions = externalRunner ? undefined : projectLaunchResolvedChildExtensions(toolPlan);
|
|
1037
|
+
const parentExtensionProvider = externalRunner || machine ? undefined : parentExtensionProviderForChild(ctx, toolPlan.disableAmbientExtensions, selectedModel, availableModels, a.modelProvider ?? ctx.currentModelProvider);
|
|
1000
1038
|
if (externalRunner && permissionRules) {
|
|
1001
1039
|
throw new AsyncStartValidationError(`Agent '${a.name}' uses runner.type='${externalRunnerType}', which cannot enforce native Pi child permission rules.`);
|
|
1002
1040
|
}
|
|
@@ -1026,6 +1064,7 @@ export function buildAsyncRunnerSteps(id, params) {
|
|
|
1026
1064
|
thinking: resolveEffectiveThinking(selectedModel, effectiveThinking),
|
|
1027
1065
|
...(thinkingCeiling ? { thinkingCeiling } : {}),
|
|
1028
1066
|
launchResolvedExtensions,
|
|
1067
|
+
...(parentExtensionProvider ? { parentExtensionProvider } : {}),
|
|
1029
1068
|
...(requestedModel ? { requestedModel } : {}),
|
|
1030
1069
|
...(primaryModelFromParent ? { skipPrimaryModelVerification: true } : {}),
|
|
1031
1070
|
...(availableModels && availableModels.length > 0 ? { modelVerificationRegistry: availableModels } : {}),
|
|
@@ -1217,9 +1256,6 @@ export function buildAsyncRunnerSteps(id, params) {
|
|
|
1217
1256
|
throw error;
|
|
1218
1257
|
}
|
|
1219
1258
|
}
|
|
1220
|
-
/**
|
|
1221
|
-
* Execute a chain asynchronously
|
|
1222
|
-
*/
|
|
1223
1259
|
export function executeAsyncChain(id, params) {
|
|
1224
1260
|
const { chain, agents, ctx, cwd, maxOutput, artifactsDir, artifactConfig, shareEnabled, sessionRoot, sessionFilesByFlatIndex, thinkingOverridesByFlatIndex, maxSubagentDepth, worktreeSetupHook, worktreeSetupHookTimeoutMs, worktreeBaseDir, baseRef, worktreeProvider, worktreeBranchPrefix, controlConfig, controlIntercomTarget, childIntercomTarget, nestedRoute, } = params;
|
|
1225
1261
|
const resultMode = params.resultMode ?? "chain";
|
|
@@ -1542,14 +1578,12 @@ export function executeAsyncChain(id, params) {
|
|
|
1542
1578
|
};
|
|
1543
1579
|
return spawnResultOrPromise instanceof Promise ? spawnResultOrPromise.then(finishSpawnResult) : finishSpawnResult(spawnResultOrPromise);
|
|
1544
1580
|
}
|
|
1545
|
-
/**
|
|
1546
|
-
* Execute a single agent asynchronously
|
|
1547
|
-
*/
|
|
1548
1581
|
export function workflowAwaitedAsyncResultPath(asyncDir) {
|
|
1549
1582
|
return path.join(asyncDir, "workflow-result.json");
|
|
1550
1583
|
}
|
|
1551
1584
|
export function executeAsyncSingle(id, params) {
|
|
1552
|
-
const { agent,
|
|
1585
|
+
const { agent, ctx, cwd, maxOutput, artifactsDir, artifactConfig, shareEnabled, sessionRoot, sessionFile, maxSubagentDepth, worktreeSetupHook, worktreeSetupHookTimeoutMs, worktreeBaseDir, baseRef, worktreeProvider, worktreeBranchPrefix, controlConfig, controlIntercomTarget, childIntercomTarget, nestedRoute, } = params;
|
|
1586
|
+
let agentConfig = params.agentConfig;
|
|
1553
1587
|
let lane;
|
|
1554
1588
|
try {
|
|
1555
1589
|
lane = normalizeWorkflowLaneMetadata(params.lane, "lane");
|
|
@@ -1619,6 +1653,13 @@ export function executeAsyncSingle(id, params) {
|
|
|
1619
1653
|
if (resolvedLauncher.error)
|
|
1620
1654
|
return formatAsyncStartError("single", resolvedLauncher.error);
|
|
1621
1655
|
const launcher = resolvedLauncher.launcher;
|
|
1656
|
+
if (params.requireLauncher) {
|
|
1657
|
+
const required = checkRequiredRunnerLauncher(agentConfig, launcher?.name, params.requireLauncher);
|
|
1658
|
+
if (required.error !== undefined)
|
|
1659
|
+
return formatAsyncStartError("single", required.error);
|
|
1660
|
+
// The launch records the digest it checked, not a second hash of an agent file that may have changed since.
|
|
1661
|
+
agentConfig = { ...agentConfig, definitionDigest: required.definitionDigest };
|
|
1662
|
+
}
|
|
1622
1663
|
const registeredExtensions = resolveRequiredChildExtensions(ctx.parentSessionId ?? ctx.currentSessionId ?? undefined);
|
|
1623
1664
|
try {
|
|
1624
1665
|
assertRequiredChildExtensionsAdmitted([params.requiredExtensions, ctx.childRuntime?.requiredExtensions, registeredExtensions], { agent: agentConfig.name, runnerType: agentConfig.runner?.type, machine: requestedMachine });
|
|
@@ -1685,7 +1726,7 @@ export function executeAsyncSingle(id, params) {
|
|
|
1685
1726
|
const validationError = validateFileOnlyOutputMode(outputMode, outputPath, `Async single run (${agent})`);
|
|
1686
1727
|
if (validationError)
|
|
1687
1728
|
return formatAsyncStartError("single", validationError);
|
|
1688
|
-
const taskWithOutputInstruction = injectSingleOutputInstruction(task, outputPath, agentConfig);
|
|
1729
|
+
const taskWithOutputInstruction = injectSingleOutputInstruction(task, outputPath, agentConfig, machine);
|
|
1689
1730
|
// Reads: caller override > agent defaultReads > none. `~`/`~/` expand to home;
|
|
1690
1731
|
// absolute paths pass through; relative paths resolve against the child cwd.
|
|
1691
1732
|
const reads = params.reads !== undefined ? params.reads : agentConfig.defaultReads ?? false;
|
|
@@ -1790,7 +1831,8 @@ export function executeAsyncSingle(id, params) {
|
|
|
1790
1831
|
return formatAsyncStartError("single", error instanceof Error ? error.message : String(error));
|
|
1791
1832
|
}
|
|
1792
1833
|
}
|
|
1793
|
-
|
|
1834
|
+
// Admission already refused mandatory entries for a placed child, which skips the rest.
|
|
1835
|
+
const requiredExtensions = externalRunner || machine ? [] : params.requiredExtensions ?? ctx.childRuntime?.requiredExtensions ?? registeredExtensions;
|
|
1794
1836
|
const toolPlan = resolvePiLaunchToolPlan({
|
|
1795
1837
|
tools: agentConfig.tools,
|
|
1796
1838
|
excludeTools: agentConfig.excludeTools,
|
|
@@ -1811,6 +1853,7 @@ export function executeAsyncSingle(id, params) {
|
|
|
1811
1853
|
runtimeSnapshotHost: ctx.pi,
|
|
1812
1854
|
});
|
|
1813
1855
|
const launchResolvedExtensions = externalRunner ? undefined : projectLaunchResolvedChildExtensions(toolPlan);
|
|
1856
|
+
const parentExtensionProvider = externalRunner || machine ? undefined : parentExtensionProviderForChild(ctx, toolPlan.disableAmbientExtensions, selectedModel, availableModels, agentConfig.modelProvider ?? ctx.currentModelProvider);
|
|
1814
1857
|
const fast = params.fast ?? agentConfig.fast;
|
|
1815
1858
|
const launchThinking = resolveEffectiveThinking(selectedModel, effectiveThinking);
|
|
1816
1859
|
const { definitionDigest, launchContractDigest } = resolveLaunchBinding({
|
|
@@ -1837,6 +1880,7 @@ export function executeAsyncSingle(id, params) {
|
|
|
1837
1880
|
agentContract: params.agentContract,
|
|
1838
1881
|
});
|
|
1839
1882
|
const recoveryAgentConfig = params.recoveryAgentConfig ?? agentConfig;
|
|
1883
|
+
const requiredLauncher = params.requireLauncher ?? params.carriedRequiredLauncher;
|
|
1840
1884
|
const recoveryDescriptor = {
|
|
1841
1885
|
...(ctx.modelResponseAliases ? { modelResponseAliases: ctx.modelResponseAliases } : {}),
|
|
1842
1886
|
version: 1,
|
|
@@ -1846,6 +1890,10 @@ export function executeAsyncSingle(id, params) {
|
|
|
1846
1890
|
...(requiredExtensions.length > 0 ? { requiredExtensions } : {}),
|
|
1847
1891
|
runFanoutBudget,
|
|
1848
1892
|
sourceRunId: id,
|
|
1893
|
+
...(ctx.currentSessionId ? { sessionId: ctx.currentSessionId } : {}),
|
|
1894
|
+
// The worktree the runner will create, fixed here from launch inputs (the runner's own naming call).
|
|
1895
|
+
...(managedWorktreeProvider === "native" ? { managedWorktree: { provider: "native", cwd: instructionCwd } } : {}),
|
|
1896
|
+
...(managedWorktreeProvider === "worktrunk" ? { managedWorktree: { provider: "worktrunk", branch: buildWorktreeNaming({ runId: `${id}-s0`, index: 0, agent, label: lane?.key ?? params.workflowKey, task: taskText, branchPrefix: worktreeBranchPrefix }).requestedBranch } } : {}),
|
|
1849
1897
|
...(params.agentContract ? { agentContract: params.agentContract } : {}),
|
|
1850
1898
|
agent,
|
|
1851
1899
|
launchResolvedExtensions,
|
|
@@ -1883,7 +1931,8 @@ export function executeAsyncSingle(id, params) {
|
|
|
1883
1931
|
...(params.context ? { context: params.context } : {}),
|
|
1884
1932
|
...(params.intercomBridge !== undefined ? { intercomBridge: params.intercomBridge } : {}),
|
|
1885
1933
|
...(params.baseRef !== undefined ? { baseRef: params.baseRef } : {}),
|
|
1886
|
-
|
|
1934
|
+
launcher: launcher ? launcher.name : null,
|
|
1935
|
+
...(requiredLauncher ? { requiredLauncher } : {}),
|
|
1887
1936
|
...(deadlineAt !== undefined ? { absoluteDeadlineAt: deadlineAt } : {}),
|
|
1888
1937
|
...(resolvedToolBudget.budget ? { initialToolBudget: resolvedToolBudget.budget } : {}),
|
|
1889
1938
|
maxSubagentDepth: resolveChildMaxSubagentDepth(maxSubagentDepth, recoveryAgentConfig.maxSubagentDepth),
|
|
@@ -1896,7 +1945,7 @@ export function executeAsyncSingle(id, params) {
|
|
|
1896
1945
|
};
|
|
1897
1946
|
if (!externalRunner) {
|
|
1898
1947
|
try {
|
|
1899
|
-
writePrivateAtomicJson(path.
|
|
1948
|
+
writePrivateAtomicJson(recoveryDescriptorPath(path.dirname(asyncDir), id), recoveryDescriptor);
|
|
1900
1949
|
}
|
|
1901
1950
|
catch (error) {
|
|
1902
1951
|
return formatAsyncStartError("single", `Failed to persist async recovery descriptor for '${id}': ${error instanceof Error ? error.message : String(error)}`);
|
|
@@ -1933,6 +1982,7 @@ export function executeAsyncSingle(id, params) {
|
|
|
1933
1982
|
...(params.fast ?? agentConfig.fast ? { fast: params.fast ?? agentConfig.fast } : {}),
|
|
1934
1983
|
thinking: resolveEffectiveThinking(selectedModel, effectiveThinking),
|
|
1935
1984
|
...(thinkingCeiling ? { thinkingCeiling } : {}),
|
|
1985
|
+
...(parentExtensionProvider ? { parentExtensionProvider } : {}),
|
|
1936
1986
|
...(requestedModel ? { requestedModel } : {}),
|
|
1937
1987
|
...(modelOrigin === "inherited" ? { skipPrimaryModelVerification: true } : {}),
|
|
1938
1988
|
...(availableModels && availableModels.length > 0 ? { modelVerificationRegistry: availableModels } : {}),
|
|
@@ -16,6 +16,7 @@ import { validHostStepNodes } from "../shared/host-step-status.js";
|
|
|
16
16
|
import { readProcessTerminal } from "./process-terminal.js";
|
|
17
17
|
import { withCachedUiContext } from "../../shared/extension-context.js";
|
|
18
18
|
import { OWNING_SESSION_COMPLETION_OWNER } from "../../shared/completion-owner.js";
|
|
19
|
+
import { ownerSessionIds } from "../shared/run-ownership.js";
|
|
19
20
|
const CONTROL_EVENT_READ_CHUNK_BYTES = 64 * 1024;
|
|
20
21
|
const MAX_CONTROL_EVENT_LINE_BYTES = 1024 * 1024;
|
|
21
22
|
const CONTROL_EVENT_SCAN_WINDOW_BYTES = 2 * 1024 * 1024;
|
|
@@ -746,7 +747,18 @@ export function createAsyncJobTracker(pi, state, asyncDirRoot, options = {}) {
|
|
|
746
747
|
if (now >= nextLivenessAt) {
|
|
747
748
|
nextLivenessAt = now + livenessIntervalMs;
|
|
748
749
|
let widgetChanged = false;
|
|
750
|
+
// A session reopened in this process takes its runs back from the session that replaced it.
|
|
751
|
+
const owners = state.currentSessionId ? ownerSessionIds(state.currentSessionId) : undefined;
|
|
749
752
|
for (const job of state.asyncJobs.values()) {
|
|
753
|
+
if (owners && job.sessionId !== undefined && !owners.has(job.sessionId)) {
|
|
754
|
+
cancelCleanup(job.asyncId);
|
|
755
|
+
closeJobWatcher(job.asyncId);
|
|
756
|
+
state.asyncJobs.delete(job.asyncId);
|
|
757
|
+
state.fleetJobs?.delete(job.asyncId);
|
|
758
|
+
options.onJobCleanup?.(job.asyncId);
|
|
759
|
+
widgetChanged = true;
|
|
760
|
+
continue;
|
|
761
|
+
}
|
|
750
762
|
watchJob(job);
|
|
751
763
|
if (refreshJob(job))
|
|
752
764
|
widgetChanged = true;
|
|
@@ -51,8 +51,9 @@ export declare function findAsyncRunPrefixMatches(prefix: string, asyncDirRoot:
|
|
|
51
51
|
location: AsyncRunLocation;
|
|
52
52
|
}>;
|
|
53
53
|
export declare function resolveAsyncRunLocation(params: AsyncResumeParams, asyncDirRoot: string, resultsDir: string): AsyncRunLocation;
|
|
54
|
+
/** A workflow-mode target has a ceiling only when its parent-owned launch record exists (resolveAsyncResumeTarget). */
|
|
54
55
|
export declare function asyncReviveRequiresRecoveryDescriptor(target: Pick<AsyncResumeTarget, "recoveryDescriptor" | "mode" | "sessionFile" | "capabilityCeiling">): boolean;
|
|
55
|
-
export declare function readAsyncRecoveryDescriptor(
|
|
56
|
+
export declare function readAsyncRecoveryDescriptor(runsRoot: string, runId: string): SteeringRecoveryDescriptor | undefined;
|
|
56
57
|
export declare function resolveAsyncResumeTarget(params: AsyncResumeParams, deps?: AsyncResumeDeps, options?: AsyncResumeOptions): AsyncResumeTarget;
|
|
57
58
|
export declare function applySteeringRecoveryAgentConfig(agentConfig: AgentConfig, descriptor: SteeringRecoveryDescriptor): AgentConfig;
|
|
58
59
|
export declare function buildRevivedAsyncTask(target: AsyncResumeTarget, message: string): string;
|