@xzzpig/pi-subagents 0.14.0 → 0.15.1
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 +239 -0
- package/README.md +7 -6
- package/agents/evidence-auditor.md +34 -0
- package/agents/researcher.md +23 -13
- package/agents/reviewer.md +3 -2
- package/docs/agents.md +55 -136
- package/docs/configuration.md +92 -14
- package/docs/extension-api.md +132 -74
- package/docs/fork-extensions.md +184 -0
- package/docs/missions.md +10 -2
- package/docs/models.md +11 -22
- package/docs/observability.md +63 -11
- package/docs/standalone-background.md +59 -0
- package/docs/tool-reference.md +42 -23
- package/docs/watchdog.md +39 -10
- package/docs/workflows.md +58 -19
- package/index.ts +5 -2
- package/inspector-runner.mjs +2 -2
- package/node_modules/@xzzpig/pi-components/dist/src/transcript.d.ts +13 -3
- package/node_modules/@xzzpig/pi-components/dist/src/transcript.js +18 -6
- package/node_modules/@xzzpig/pi-components/src/transcript.ts +26 -6
- package/package.json +9 -4
- package/prompts/parallel-review.md +1 -1
- package/runner-peer-loader.mjs +24 -0
- package/runner-peer-preload.mjs +36 -0
- package/skills/pi-subagents/SKILL.md +34 -22
- package/skills/pi-subagents/references/constraints-and-recipes.md +3 -2
- package/skills/pi-subagents/references/execution-controls.md +27 -8
- package/skills/pi-subagents/references/management-authoring-rpc.md +2 -2
- package/skills/pi-subagents/references/multi-lane-orchestration.md +3 -1
- package/skills/pi-subagents/references/prompting-and-roles.md +17 -13
- package/skills/pi-subagents/references/review-and-validation.md +3 -3
- package/src/agents/advertised-agent-prompt.ts +94 -0
- package/src/agents/agent-eject.ts +339 -0
- package/src/agents/agent-management.ts +79 -387
- package/src/agents/agent-serializer.ts +6 -3
- package/src/agents/agents.ts +198 -72
- package/src/agents/builtin-names.ts +1 -0
- package/src/agents/chain-serializer.ts +5 -0
- package/src/agents/runtime-agent-registry.ts +7 -6
- package/src/api/agent-management.ts +2 -2
- package/src/api/delegation.ts +4 -0
- package/src/api/preflight.ts +131 -86
- package/src/api/required-child-extensions.ts +6 -0
- package/src/api/shared-types.ts +3 -1
- package/src/api/workflow-resources.ts +6 -0
- package/src/extension/config.ts +14 -37
- package/src/extension/fanout-child.ts +68 -5
- package/src/extension/herdr-pi-bridge.ts +164 -0
- package/src/extension/index.ts +141 -51
- package/src/extension/public-execution.ts +7 -6
- package/src/extension/rpc.ts +8 -21
- package/src/extension/schemas.ts +86 -84
- package/src/extension/tool-description.ts +32 -79
- package/src/inspectors/actions.ts +148 -0
- package/src/inspectors/ghostty/actions.ts +74 -0
- package/src/inspectors/ghostty/plugin.ts +17 -0
- package/src/inspectors/herdr/actions.ts +99 -179
- package/src/inspectors/herdr/plugin.ts +20 -0
- package/src/inspectors/herdr/project-panes.ts +4 -1
- package/src/inspectors/{herdr/inspector-runner.ts → inspector-runner.ts} +12 -12
- package/src/inspectors/plugins.ts +8 -0
- package/src/inspectors/{herdr/session-roots-codec.ts → session-roots-codec.ts} +3 -14
- package/src/inspectors/types.ts +51 -0
- package/src/integrations/pi-web-session-liveness.ts +73 -0
- package/src/intercom/intercom-bridge.ts +50 -8
- package/src/intercom/native-supervisor-channel.ts +142 -115
- package/src/intercom/supervisor-ui.ts +3 -2
- package/src/missions/workflow-state.ts +37 -16
- package/src/policy/authority.ts +4 -0
- package/src/profiles/profiles.ts +12 -6
- package/src/runs/background/active-async-capacity.ts +22 -18
- package/src/runs/background/active-run-index.ts +17 -1
- package/src/runs/background/async-execution.ts +359 -176
- package/src/runs/background/async-job-tracker.ts +41 -7
- package/src/runs/background/async-resume.ts +19 -12
- package/src/runs/background/async-retention.ts +20 -0
- package/src/runs/background/async-status-snapshot.ts +10 -12
- package/src/runs/background/async-status.ts +38 -35
- package/src/runs/background/auto-drain.ts +59 -35
- package/src/runs/background/binary-bootstrap.ts +38 -0
- package/src/runs/background/chain-append.ts +1 -1
- package/src/runs/background/chain-root-attachment.ts +22 -33
- package/src/runs/background/control-channel.ts +78 -44
- package/src/runs/background/fleet-view.ts +30 -2
- package/src/runs/background/notify.ts +193 -19
- package/src/runs/background/owned-process-tree.ts +35 -8
- package/src/runs/background/process-terminal.ts +23 -23
- package/src/runs/background/result-files.ts +8 -4
- package/src/runs/background/result-watcher.ts +19 -2
- package/src/runs/background/retained-nested-route-tracker.ts +96 -0
- package/src/runs/background/run-child-session.ts +118 -41
- package/src/runs/background/run-status.ts +78 -5
- package/src/runs/background/runner-aliases.ts +22 -5
- package/src/runs/background/runner-child-launch.ts +93 -0
- package/src/runs/background/runner-child-sessions.ts +5 -4
- package/src/runs/background/runner-http-dispatcher.ts +119 -0
- package/src/runs/background/scheduled-runs.ts +51 -18
- package/src/runs/background/stale-run-reconciler.ts +38 -12
- package/src/runs/background/steering.ts +20 -2
- package/src/runs/background/subagent-runner.ts +770 -444
- package/src/runs/background/subagent-wait.ts +179 -28
- package/src/runs/background/wait-completions.ts +79 -27
- package/src/runs/background/wait-subscriptions.ts +9 -3
- package/src/runs/background/wait-tool.ts +5 -3
- package/src/runs/foreground/async-steering-action.ts +37 -7
- package/src/runs/foreground/async-stop-action.ts +93 -3
- package/src/runs/foreground/execution.ts +174 -194
- package/src/runs/foreground/foreground-history.ts +5 -2
- package/src/runs/foreground/prompt-audit.ts +12 -6
- package/src/runs/foreground/subagent-executor.ts +915 -411
- package/src/runs/foreground/workflow-detach-reconcile.ts +10 -5
- package/src/runs/foreground/workflow-foreground-steering.ts +57 -2
- package/src/runs/shared/acceptance.ts +54 -14
- package/src/runs/shared/agent-contract.ts +1 -1
- package/src/runs/shared/async-status-projection.ts +172 -78
- package/src/runs/shared/capability-ceiling.ts +2 -0
- package/src/runs/shared/child-hooks.ts +167 -3
- package/src/runs/shared/child-launch-plan.ts +15 -3
- package/src/runs/shared/child-launch.ts +49 -85
- package/src/runs/shared/child-lifecycle.ts +6 -3
- package/src/runs/shared/child-runtime-config.ts +8 -1
- package/src/runs/shared/child-session.ts +130 -24
- package/src/runs/shared/child-tool-plan.ts +149 -112
- package/src/runs/shared/completion-evidence.ts +2 -2
- package/src/runs/shared/completion-guard.ts +6 -3
- package/src/runs/shared/dynamic-fanout.ts +2 -2
- package/src/runs/shared/effective-system-prompt.ts +33 -0
- package/src/runs/shared/external-cli-contract.ts +11 -1
- package/src/runs/shared/external-cli-preflight.ts +6 -2
- package/src/runs/shared/external-cli-runner.ts +9 -7
- package/src/runs/shared/herdr-connection.ts +134 -0
- package/src/runs/shared/herdr-external-adapters.ts +169 -0
- package/src/runs/shared/herdr-machine.ts +279 -0
- package/src/runs/shared/herdr-pi-protocol.ts +59 -0
- package/src/runs/shared/herdr-placed-run.ts +263 -0
- package/src/runs/shared/host-step-status.ts +11 -11
- package/src/runs/shared/llm-intent-arbiter.ts +40 -21
- package/src/runs/shared/model-resolution-diagnostic.ts +76 -0
- package/src/runs/shared/{model-fallback.ts → model-resolution.ts} +34 -218
- package/src/runs/shared/model-scope.ts +1 -1
- package/src/runs/shared/nested-events.ts +27 -34
- package/src/runs/shared/orca-progress-tabs.ts +7 -1
- package/src/runs/shared/parallel-handoff.ts +57 -12
- package/src/runs/shared/parallel-utils.ts +10 -4
- package/src/runs/shared/pi-spawn.ts +10 -0
- package/src/runs/shared/profile-extensions.ts +134 -0
- package/src/runs/shared/profile-launch-env.ts +113 -0
- package/src/runs/shared/readonly-drain-observation.ts +42 -0
- package/src/runs/shared/run-fanout-budget.ts +8 -8
- package/src/runs/shared/runtime-acknowledged-extensions.ts +3 -3
- package/src/runs/shared/sandbox-profile-guard.ts +34 -0
- package/src/runs/shared/subagent-prompt-runtime.ts +23 -5
- package/src/runs/shared/task-intent.ts +46 -13
- package/src/runs/shared/workflow-async-child-guidance.ts +18 -0
- package/src/runs/shared/worktree-cleanup-plan.ts +6 -3
- package/src/runs/shared/worktree-setup-command.ts +213 -0
- package/src/runs/shared/worktree.ts +437 -214
- package/src/shared/child-cache-retention.ts +43 -0
- package/src/shared/fork-context.ts +15 -72
- package/src/shared/launch-contract.ts +70 -8
- package/src/shared/model-response-aliases.ts +13 -0
- package/src/shared/opencode-session-headers.ts +30 -0
- package/src/shared/permission-profile.ts +14 -0
- package/src/shared/pruned-fork.ts +1 -1
- package/src/shared/required-child-extensions.ts +81 -0
- package/src/shared/sandbox-profile.ts +14 -0
- package/src/shared/settings.ts +5 -2
- package/src/shared/shortcuts.ts +0 -4
- package/src/shared/types.ts +163 -90
- package/src/shared/utils.ts +10 -2
- package/src/shared/watch-strategy.ts +2 -0
- package/src/shared/workflow-child-permit.ts +18 -13
- package/src/slash/delegation-adapters.ts +3 -1
- package/src/slash/delegation-request.ts +14 -0
- package/src/slash/slash-commands.ts +2 -7
- package/src/slash/subagents-admin.ts +31 -14
- package/src/tui/fleet-status.ts +165 -20
- package/src/tui/fleet.ts +30 -19
- package/src/tui/render.ts +210 -50
- package/src/watchdog/child-status.ts +28 -28
- package/src/watchdog/lsp-diagnostics.ts +1 -1
- package/src/watchdog/model-selection.ts +21 -1
- package/src/watchdog/permission-arbiter.ts +5 -2
- package/src/watchdog/register-child.ts +10 -2
- package/src/watchdog/register-main.ts +39 -35
- package/src/watchdog/render.ts +1 -1
- package/src/watchdog/review.ts +122 -74
- package/src/watchdog/rules.ts +1 -1
- package/src/watchdog/runtime.ts +100 -27
- package/src/watchdog/scope.ts +1 -1
- package/src/watchdog/settings.ts +3 -0
- package/src/watchdog/tool-actions.ts +13 -12
- package/src/watchdog/turn-delta.ts +23 -0
- package/src/watchdog/types.ts +5 -3
- package/src/watchdog/warning-format.ts +1 -1
- package/src/workflows/chat-progress.ts +3 -3
- package/src/workflows/scripted-workflow.ts +349 -26
- package/src/workflows/workflow-checklist.ts +17 -20
- package/src/workflows/workflow-child-summary.ts +57 -8
- package/src/workflows/workflow-preflight.ts +19 -19
- package/src/workflows/workflow-receipt.ts +24 -6
- package/src/workflows/workflow-resources.ts +108 -22
- package/src/workflows/workflow-settlement.ts +3 -0
- package/src/runs/shared/model-exclusions.ts +0 -373
- /package/src/inspectors/{herdr/shell-command.ts → shell-command.ts} +0 -0
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import
|
|
2
|
+
import { listBackgroundWorkProviders } from "../../api/background-work.ts";
|
|
3
|
+
import { ReadonlyDrainObservation } from "./readonly-drain-observation.ts";
|
|
4
|
+
import registerFanoutChildSubagentExtension, { createChildSafeState } from "../../extension/fanout-child.ts";
|
|
3
5
|
import registerSubagentFastModeExtension from "./fast-mode-extension.ts";
|
|
4
6
|
import registerSubagentPromptRuntime from "./subagent-prompt-runtime.ts";
|
|
5
7
|
import type { ChildRuntimeConfig } from "./child-runtime-config.ts";
|
|
8
|
+
import type { ChildToolDiagnostic } from "./tool-availability.ts";
|
|
9
|
+
import type { ChildSessionLaunch } from "./child-session.ts";
|
|
10
|
+
import type { ArbiterModelContext } from "./llm-intent-arbiter.ts";
|
|
11
|
+
import type { ChildTranscriptWriter } from "../../shared/child-transcript.ts";
|
|
12
|
+
import { projectRuntimeAcknowledgedExtensions } from "./runtime-acknowledged-extensions.ts";
|
|
6
13
|
|
|
7
14
|
/** Inline extension shape accepted by pi's resource loader (`extensionFactories`). */
|
|
8
15
|
export interface ChildHookExtension {
|
|
@@ -10,16 +17,173 @@ export interface ChildHookExtension {
|
|
|
10
17
|
factory: (pi: ExtensionAPI) => void;
|
|
11
18
|
}
|
|
12
19
|
|
|
20
|
+
type OwnedCapture = Required<Pick<ChildRuntimeConfig, "toolDiagnostic" | "runtimeAcknowledgements">>;
|
|
21
|
+
type PromptProof = { config: ChildRuntimeConfig; snapshot: string; factories?: ChildHookExtension["factory"][]; observeNext?: ReadonlyDrainObservation; observation?: ReadonlyDrainObservation; capture?: OwnedCapture; reporting?: { launch: ChildSessionLaunch; callback: ChildSessionLaunch["onExtensionError"] } };
|
|
22
|
+
const promptProofs = new WeakMap<ChildHookExtension["factory"], PromptProof>();
|
|
23
|
+
|
|
24
|
+
function ownedProof(hooks: ChildHookExtension[]): PromptProof | undefined {
|
|
25
|
+
const proof = hooks[0] && promptProofs.get(hooks[0].factory);
|
|
26
|
+
return proof?.factories?.length === hooks.length && proof.factories.every((factory, index) => hooks[index]?.factory === factory) ? proof : undefined;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** The host's mandatory transcript reporting, owned by the existing hook certificate. */
|
|
30
|
+
export function withChildSessionErrorReporting(session: Omit<ChildSessionLaunch, "onExtensionError">, transcriptWriter: ChildTranscriptWriter | undefined): ChildSessionLaunch {
|
|
31
|
+
const launch: ChildSessionLaunch = { ...session, onExtensionError: (error) => {
|
|
32
|
+
transcriptWriter?.writeStderrLine(`Extension error (${error.extensionPath}, ${error.event}): ${error.error instanceof Error ? error.error.message : String(error.error)}`);
|
|
33
|
+
} };
|
|
34
|
+
const proof = ownedProof(launch.hooks);
|
|
35
|
+
if (proof?.capture && proof.config === launch.runtime) proof.reporting = { launch, callback: launch.onExtensionError };
|
|
36
|
+
return launch;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function isReadonlyChildSessionReporting(launch: ChildSessionLaunch): boolean {
|
|
40
|
+
const proof = ownedProof(launch.hooks);
|
|
41
|
+
const descriptor = Object.getOwnPropertyDescriptor(launch, "onExtensionError");
|
|
42
|
+
if (descriptor && (!descriptor.enumerable || !("value" in descriptor))) return false;
|
|
43
|
+
return proof?.reporting ? proof.reporting.launch === launch && proof.reporting.callback === descriptor?.value : !descriptor && !("onExtensionError" in launch);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Admit only own enumerable data: inspecting descriptors must not invoke getters. */
|
|
47
|
+
function dataKeys(value: unknown): string[] | undefined {
|
|
48
|
+
if (!value || typeof value !== "object" || Object.getPrototypeOf(value) !== Object.prototype) return undefined;
|
|
49
|
+
const keys = Reflect.ownKeys(value);
|
|
50
|
+
for (const key of keys) {
|
|
51
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key)!;
|
|
52
|
+
if (typeof key !== "string" || !descriptor.enumerable || !("value" in descriptor)) return undefined;
|
|
53
|
+
}
|
|
54
|
+
return keys as string[];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Only reviewed data and the capture callbacks constructed below; no caller callback opt-in. */
|
|
58
|
+
function readonlyConfig(config: ChildRuntimeConfig, capture?: OwnedCapture): string | undefined {
|
|
59
|
+
const strings = ["runId", "agent", "sessionName", "forkCacheKey", "parentSessionId", "orchestratorSessionId"];
|
|
60
|
+
const numbers = ["childIndex", "depth", "maxDepth"];
|
|
61
|
+
const booleans = ["inheritProjectContext", "inheritGlobalContext", "inheritSkills"];
|
|
62
|
+
const keys = dataKeys(config);
|
|
63
|
+
if (!keys) return undefined;
|
|
64
|
+
if (capture && (config.toolDiagnostic !== capture.toolDiagnostic || config.runtimeAcknowledgements !== capture.runtimeAcknowledgements)) return undefined;
|
|
65
|
+
const waitKeys = dataKeys(config.waitTool);
|
|
66
|
+
if (!waitKeys || waitKeys.some((key) => key !== "enabled")) return undefined;
|
|
67
|
+
if (config.fast !== false || config.fanoutChild !== false || config.waitTool.enabled !== false) return undefined;
|
|
68
|
+
for (const key of keys) {
|
|
69
|
+
const value = Object.getOwnPropertyDescriptor(config, key)!.value;
|
|
70
|
+
if (["fast", "fanoutChild", "waitTool"].includes(key)) continue;
|
|
71
|
+
if (capture && (key === "toolDiagnostic" || key === "runtimeAcknowledgements")) continue;
|
|
72
|
+
if (capture && key === "requiredTools" && Array.isArray(value) && Object.getPrototypeOf(value) === Array.prototype) {
|
|
73
|
+
const descriptors = Object.getOwnPropertyDescriptors(value);
|
|
74
|
+
if (Reflect.ownKeys(descriptors).length !== value.length + 1) return undefined;
|
|
75
|
+
for (let i = 0; i < value.length; i++) {
|
|
76
|
+
const descriptor = descriptors[String(i)];
|
|
77
|
+
if (!descriptor?.enumerable || !("value" in descriptor) || !["read", "ls"].includes(descriptor.value)) return undefined;
|
|
78
|
+
}
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
if (strings.includes(key) && (value === undefined || typeof value === "string")) continue;
|
|
82
|
+
if (numbers.includes(key) && (value === undefined || (typeof value === "number" && Number.isInteger(value) && value >= 0))) continue;
|
|
83
|
+
if (booleans.includes(key) && (value === undefined || typeof value === "boolean")) continue;
|
|
84
|
+
return undefined;
|
|
85
|
+
}
|
|
86
|
+
return JSON.stringify(config);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function noBackgroundProviders(): boolean {
|
|
90
|
+
try {
|
|
91
|
+
return listBackgroundWorkProviders().length === 0;
|
|
92
|
+
} catch { return false; }
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** Internal proof of the captured closure/config, not its caller-controlled display name. */
|
|
96
|
+
export function isReadonlyChildHookProfile(hooks: ChildHookExtension[], config: ChildRuntimeConfig): boolean {
|
|
97
|
+
const proof = ownedProof(hooks);
|
|
98
|
+
if (!proof) return false;
|
|
99
|
+
const valid = proof.config === config && readonlyConfig(config, proof.capture) === proof.snapshot && noBackgroundProviders();
|
|
100
|
+
if (!valid) proof.observation?.deny();
|
|
101
|
+
return valid && (proof.observation?.check() ?? true);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** Arm just the next installation; ordinary installations retain the original API/handlers. */
|
|
105
|
+
export function observeReadonlyChildHookDrain(hooks: ChildHookExtension[], enabled: boolean, sessionFile: string): void {
|
|
106
|
+
const proof = ownedProof(hooks);
|
|
107
|
+
if (!proof) return;
|
|
108
|
+
if (enabled) {
|
|
109
|
+
proof.observation?.deny();
|
|
110
|
+
proof.observation = undefined;
|
|
111
|
+
}
|
|
112
|
+
proof.observeNext = enabled ? new ReadonlyDrainObservation(sessionFile, () => readonlyConfig(proof.config, proof.capture) === proof.snapshot && noBackgroundProviders()) : undefined;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export function captureReadonlyChildDrain(hooks: ChildHookExtension[]): (() => boolean) {
|
|
116
|
+
const proof = ownedProof(hooks);
|
|
117
|
+
const observation = proof?.observation;
|
|
118
|
+
return () => !!observation && proof?.observation === observation && observation.settled();
|
|
119
|
+
}
|
|
120
|
+
|
|
13
121
|
/**
|
|
14
122
|
* The child-side hooks pi-subagents installs in every child, keyed off the
|
|
15
123
|
* launch config. The registrations live in `subagent-prompt-runtime.ts`,
|
|
16
124
|
* `fast-mode-extension.ts`, and `fanout-child.ts`.
|
|
17
125
|
*/
|
|
18
126
|
export function createChildHooks(config: ChildRuntimeConfig): ChildHookExtension[] {
|
|
127
|
+
return childHooks(config);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** Launch-owned bookkeeping, paired with the same private hook certificate (no callback registration API). */
|
|
131
|
+
export function createCapturedChildHooks(config: ChildRuntimeConfig, runner = false) {
|
|
132
|
+
let diagnostic: ChildToolDiagnostic | undefined;
|
|
133
|
+
let acknowledgedIds: string[] | undefined;
|
|
134
|
+
let completionIntentContext: ArbiterModelContext | undefined;
|
|
135
|
+
let finalDrainHeld = false;
|
|
136
|
+
const capture: OwnedCapture = {
|
|
137
|
+
toolDiagnostic: (value) => { diagnostic = value; },
|
|
138
|
+
runtimeAcknowledgements: (ids) => { acknowledgedIds = ids; },
|
|
139
|
+
};
|
|
140
|
+
Object.assign(config, capture);
|
|
141
|
+
const hooks = childHooks(config, capture, (held) => { finalDrainHeld = held; });
|
|
142
|
+
if (runner) {
|
|
143
|
+
hooks.push({ name: "pi-subagents:completion-intent", factory: (pi) => pi.on("session_start", (_event, childCtx) => {
|
|
144
|
+
// Retain only attempt model services and the session id string, not the live child session.
|
|
145
|
+
completionIntentContext = {
|
|
146
|
+
model: childCtx.model,
|
|
147
|
+
modelRegistry: childCtx.modelRegistry,
|
|
148
|
+
sessionId: childCtx.sessionManager.getSessionId(),
|
|
149
|
+
};
|
|
150
|
+
}) });
|
|
151
|
+
const proof = promptProofs.get(hooks[0]!.factory);
|
|
152
|
+
if (proof) proof.factories = hooks.map((hook) => hook.factory);
|
|
153
|
+
}
|
|
154
|
+
return {
|
|
155
|
+
hooks,
|
|
156
|
+
completionIntentContext: () => completionIntentContext,
|
|
157
|
+
toolDiagnostic: () => diagnostic,
|
|
158
|
+
runtimeAcknowledgedExtensions: () => acknowledgedIds ? projectRuntimeAcknowledgedExtensions(acknowledgedIds) : undefined,
|
|
159
|
+
finalDrainHeld: () => finalDrainHeld,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function childHooks(config: ChildRuntimeConfig, capture?: OwnedCapture, holdFinalDrain?: (held: boolean) => void): ChildHookExtension[] {
|
|
164
|
+
const snapshot = readonlyConfig(config, capture);
|
|
165
|
+
const proof: PromptProof | undefined = snapshot === undefined ? undefined : { config, snapshot, capture };
|
|
166
|
+
const runtime = Object.create(config) as ChildRuntimeConfig;
|
|
167
|
+
const ownedState = Object.getOwnPropertyDescriptor(config, "runtimeState");
|
|
168
|
+
if (!ownedState || !("value" in ownedState) || ownedState.value == null) {
|
|
169
|
+
Object.defineProperty(runtime, "runtimeState", { configurable: true, enumerable: true, writable: true, value: createChildSafeState() });
|
|
170
|
+
}
|
|
171
|
+
if (holdFinalDrain) {
|
|
172
|
+
Object.defineProperty(runtime, "holdFinalDrain", { configurable: true, enumerable: true, writable: true, value: holdFinalDrain });
|
|
173
|
+
}
|
|
19
174
|
const hooks: ChildHookExtension[] = [
|
|
20
|
-
{ name: "pi-subagents:prompt-runtime", factory:
|
|
175
|
+
{ name: "pi-subagents:prompt-runtime", factory: function promptRuntime(pi) {
|
|
176
|
+
if (!proof?.observeNext) return registerSubagentPromptRuntime(pi, runtime);
|
|
177
|
+
proof.observation = proof.observeNext;
|
|
178
|
+
proof.observeNext = undefined;
|
|
179
|
+
registerSubagentPromptRuntime(pi, runtime, proof.observation);
|
|
180
|
+
} },
|
|
21
181
|
];
|
|
182
|
+
if (proof) {
|
|
183
|
+
proof.factories = hooks.map((hook) => hook.factory);
|
|
184
|
+
promptProofs.set(hooks[0]!.factory, proof);
|
|
185
|
+
}
|
|
22
186
|
if (config.fast) hooks.push({ name: "pi-subagents:fast-mode", factory: (pi) => registerSubagentFastModeExtension(pi) });
|
|
23
|
-
if (config.fanoutChild) hooks.push({ name: "pi-subagents:fanout-child", factory: (pi) => registerFanoutChildSubagentExtension(pi,
|
|
187
|
+
if (config.fanoutChild) hooks.push({ name: "pi-subagents:fanout-child", factory: (pi) => registerFanoutChildSubagentExtension(pi, runtime) });
|
|
24
188
|
return hooks;
|
|
25
189
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as path from "node:path";
|
|
2
2
|
import type { AgentConfig } from "../../agents/agents.ts";
|
|
3
3
|
import { resolveChildCwd } from "../../shared/utils.ts";
|
|
4
|
-
import type { OutputMode } from "../../shared/types.ts";
|
|
4
|
+
import type { JsonSchemaObject, OutputMode } from "../../shared/types.ts";
|
|
5
5
|
import { resolveSingleOutputPath } from "./single-output.ts";
|
|
6
6
|
|
|
7
7
|
export interface ResolvedStepBehavior {
|
|
@@ -12,6 +12,7 @@ export interface ResolvedStepBehavior {
|
|
|
12
12
|
skills: string[] | false;
|
|
13
13
|
model?: string;
|
|
14
14
|
fast?: boolean;
|
|
15
|
+
outputSchema?: JsonSchemaObject;
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
export type OutputOverrideInput = string | boolean;
|
|
@@ -24,6 +25,7 @@ export interface StepOverrides {
|
|
|
24
25
|
skills?: string[] | false;
|
|
25
26
|
model?: string;
|
|
26
27
|
fast?: boolean;
|
|
28
|
+
outputSchema?: JsonSchemaObject | false;
|
|
27
29
|
}
|
|
28
30
|
|
|
29
31
|
export interface ChildLaunchPlanInput {
|
|
@@ -35,6 +37,7 @@ export interface ChildLaunchPlanInput {
|
|
|
35
37
|
runtimeCwd: string;
|
|
36
38
|
stepCwdInput?: string;
|
|
37
39
|
behaviorCwd?: string;
|
|
40
|
+
machineCwd?: string;
|
|
38
41
|
chainSkills?: string[];
|
|
39
42
|
outputBaseDir?: string;
|
|
40
43
|
parallelOutputNamespace?: { stepIndex: number; taskIndex?: number };
|
|
@@ -58,6 +61,14 @@ export function normalizeOutputOverride(output: unknown): string | false | undef
|
|
|
58
61
|
return typeof output === "string" && output.length > 0 ? output : undefined;
|
|
59
62
|
}
|
|
60
63
|
|
|
64
|
+
export const resolveEffectiveOutputSchema = (agentConfig: AgentConfig, override?: JsonSchemaObject | false): JsonSchemaObject | undefined => override === false ? undefined : override !== undefined ? override : agentConfig.outputSchema;
|
|
65
|
+
|
|
66
|
+
type OutputSchemaStep = { agent: string; outputSchema?: JsonSchemaObject | false };
|
|
67
|
+
export function projectChainOutputSchemas<S extends OutputSchemaStep, R = S, G = { parallel: R[] | R }>(chain: readonly (S | { parallel: S[] | S })[], agents: AgentConfig[], projectStep?: (step: S, outputSchema: JsonSchemaObject | undefined) => R, projectGroup?: (step: { parallel: S[] | S }, parallel: R[] | R) => G): Array<R | G> {
|
|
68
|
+
const project = (step: S): R => { const agent = agents.find((candidate) => candidate.name === step.agent); if (!agent && !projectStep) return step as unknown as R; const outputSchema = agent && resolveEffectiveOutputSchema(agent, step.outputSchema); return projectStep ? projectStep(step, outputSchema) : { ...step, outputSchema } as unknown as R; };
|
|
69
|
+
return chain.map((step) => { if (!("parallel" in step)) return project(step as S); const parallel = Array.isArray(step.parallel) ? step.parallel.map(project) : project(step.parallel as S); return projectGroup ? projectGroup(step, parallel) : { ...step, parallel } as unknown as G; });
|
|
70
|
+
}
|
|
71
|
+
|
|
61
72
|
export function resolveStepBehavior(
|
|
62
73
|
agentConfig: AgentConfig,
|
|
63
74
|
stepOverrides: StepOverrides,
|
|
@@ -94,7 +105,8 @@ export function resolveStepBehavior(
|
|
|
94
105
|
const outputMode = stepOverrides.outputMode ?? agentConfig.outputMode ?? "inline";
|
|
95
106
|
const model = stepOverrides.model ?? agentConfig.model;
|
|
96
107
|
const fast = stepOverrides.fast ?? agentConfig.fast;
|
|
97
|
-
|
|
108
|
+
const outputSchema = resolveEffectiveOutputSchema(agentConfig, stepOverrides.outputSchema);
|
|
109
|
+
return { output, outputMode, reads, progress, skills, model, fast, ...(outputSchema !== undefined ? { outputSchema } : {}) };
|
|
98
110
|
}
|
|
99
111
|
|
|
100
112
|
export function resolveTaskTextForFileUpdatePolicy(task: string | undefined, originalTask?: string): string | undefined {
|
|
@@ -117,7 +129,7 @@ export function suppressProgressForReadOnlyTask(behavior: ResolvedStepBehavior,
|
|
|
117
129
|
}
|
|
118
130
|
|
|
119
131
|
export function planChildLaunch(input: ChildLaunchPlanInput): ChildLaunchPlan {
|
|
120
|
-
const stepCwd = resolveChildCwd(input.runnerCwd, input.stepCwdInput);
|
|
132
|
+
const stepCwd = input.machineCwd ?? resolveChildCwd(input.runnerCwd, input.stepCwdInput);
|
|
121
133
|
const instructionCwd = input.behaviorCwd ?? stepCwd;
|
|
122
134
|
const readExistenceCwd = input.behaviorCwd ? stepCwd : instructionCwd;
|
|
123
135
|
let behavior = suppressProgressForReadOnlyTask(
|
|
@@ -6,29 +6,25 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import * as fs from "node:fs";
|
|
8
8
|
import * as path from "node:path";
|
|
9
|
-
import { randomUUID } from "node:crypto";
|
|
10
9
|
import type { ChildWatchdogConfig, ChildWatchdogStatusEvent } from "../../watchdog/child-status.ts";
|
|
11
10
|
import type { ThinkingLevel } from "../../shared/model-info.ts";
|
|
12
11
|
import { intersectThinkingCeilings } from "../../shared/thinking-ceiling.ts";
|
|
13
12
|
import {
|
|
14
|
-
TEMP_ROOT_DIR,
|
|
15
13
|
resolveChildDepth,
|
|
16
|
-
type
|
|
14
|
+
type LaunchResolvedChildExtensions,
|
|
17
15
|
type ResolvedToolBudget,
|
|
18
16
|
type RunFanoutBudgetDescriptor,
|
|
17
|
+
type HerdrMachineReference,
|
|
19
18
|
} from "../../shared/types.ts";
|
|
20
|
-
import { SUBAGENT_SANDBOX_PROFILE_ENV, SUBAGENT_SANDBOX_PROJECT_TRUST_ENV } from "../../shared/sandbox-profile.ts";
|
|
21
|
-
import { SUBAGENT_PERMISSION_PROFILE_ENV, SUBAGENT_PERMISSION_PROFILE_PINNED_ENV } from "../../shared/permission-profile.ts";
|
|
22
19
|
import type { NestedPathEntry } from "./nested-path.ts";
|
|
23
20
|
import type { McpRuntimeSnapshotHost } from "./mcp-direct-tool-allowlist.ts";
|
|
24
21
|
import type { PermissionRules } from "./permissions.ts";
|
|
25
22
|
import type { StructuredOutputRuntime } from "./structured-output.ts";
|
|
26
23
|
import type { ChildToolDiagnostic } from "./tool-availability.ts";
|
|
27
|
-
import type {
|
|
28
|
-
import { projectRuntimeAcknowledgedExtensions } from "./runtime-acknowledged-extensions.ts";
|
|
24
|
+
import type { RuntimeAcknowledgedChildExtensions } from "../../shared/types.ts";
|
|
29
25
|
import { encodeExtensionBindings, PI_SUBAGENT_EXTENSION_BINDINGS_ENV, type ExtensionBindings } from "./extension-bindings.ts";
|
|
30
|
-
import { SANDBOX_DIAGNOSTICS_PATH_ENV } from "./sandbox-startup-diagnostics.ts";
|
|
31
26
|
import type { ResolvedSubagentCapabilityCeiling, SubagentCapabilityAudit } from "./capability-ceiling.ts";
|
|
27
|
+
import { buildProfileLaunchEnv } from "./profile-launch-env.ts";
|
|
32
28
|
import {
|
|
33
29
|
isSubagentRuntimeExtensionPath,
|
|
34
30
|
projectLaunchResolvedChildExtensions,
|
|
@@ -37,30 +33,21 @@ import {
|
|
|
37
33
|
type PiLaunchToolPlan,
|
|
38
34
|
} from "./child-tool-plan.ts";
|
|
39
35
|
import type { ChildRuntimeConfig } from "./child-runtime-config.ts";
|
|
40
|
-
import {
|
|
36
|
+
import { createCapturedChildHooks, withChildSessionErrorReporting } from "./child-hooks.ts";
|
|
37
|
+
import type { ChildTranscriptWriter } from "../../shared/child-transcript.ts";
|
|
41
38
|
import type { ChildSessionLaunch, ChildSessionStorage } from "./child-session.ts";
|
|
39
|
+
import type { ArbiterModelContext } from "./llm-intent-arbiter.ts";
|
|
40
|
+
import { resolveRequiredChildExtensions, type RequiredChildExtensionSnapshot } from "../../shared/required-child-extensions.ts";
|
|
42
41
|
|
|
43
42
|
/** Environment variable pi-mcp-adapter reads for the tools a child may expose. */
|
|
44
43
|
export const MCP_DIRECT_TOOLS_ENV = "MCP_DIRECT_TOOLS";
|
|
45
44
|
|
|
46
|
-
const SANDBOX_STARTUP_ACK_PATH_ENV = "PI_SUBAGENT_SANDBOX_STARTUP_ACK_PATH";
|
|
47
|
-
const SANDBOX_STARTUP_ACK_TOKEN_ENV = "PI_SUBAGENT_SANDBOX_STARTUP_ACK_TOKEN";
|
|
48
|
-
// Marks an in-process child so child extensions never mutate the host process
|
|
49
|
-
// state (for example a profile-failure exit code) that a separate child process
|
|
50
|
-
// would legitimately own.
|
|
51
|
-
const IN_PROCESS_CHILD_ENV = "PI_SUBAGENT_SANDBOX_IN_PROCESS_CHILD";
|
|
52
|
-
|
|
53
|
-
function hasTrustedProfileProjectCwd(input: Pick<BuildInProcessChildLaunchInput, "cwd" | "projectTrusted" | "trustedProjectCwd">): boolean {
|
|
54
|
-
if (input.projectTrusted !== true || !input.cwd || !input.trustedProjectCwd) return false;
|
|
55
|
-
return path.resolve(input.cwd) === path.resolve(input.trustedProjectCwd);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
45
|
/**
|
|
59
46
|
* The parts of the launching executor's own child runtime that a child it
|
|
60
47
|
* launches inherits. Serialized into the background runner config; the
|
|
61
48
|
* foreground path passes the executor's full `ChildRuntimeConfig`.
|
|
62
49
|
*/
|
|
63
|
-
export type InheritedChildRuntime = Pick<ChildRuntimeConfig, "depth" | "maxDepth" | "nestedRoute" | "nestedParent" | "capabilityCeiling" | "thinkingCeiling" | "runFanoutBudget">;
|
|
50
|
+
export type InheritedChildRuntime = Pick<ChildRuntimeConfig, "depth" | "maxDepth" | "nestedRoute" | "nestedParent" | "capabilityCeiling" | "thinkingCeiling" | "runFanoutBudget" | "requiredExtensions">;
|
|
64
51
|
|
|
65
52
|
export function inheritedChildRuntime(config: ChildRuntimeConfig | undefined): InheritedChildRuntime | undefined {
|
|
66
53
|
if (!config) return undefined;
|
|
@@ -72,10 +59,14 @@ export function inheritedChildRuntime(config: ChildRuntimeConfig | undefined): I
|
|
|
72
59
|
...(config.capabilityCeiling ? { capabilityCeiling: config.capabilityCeiling } : {}),
|
|
73
60
|
...(config.thinkingCeiling ? { thinkingCeiling: config.thinkingCeiling } : {}),
|
|
74
61
|
...(config.runFanoutBudget ? { runFanoutBudget: config.runFanoutBudget } : {}),
|
|
62
|
+
...(config.requiredExtensions ? { requiredExtensions: config.requiredExtensions } : {}),
|
|
75
63
|
};
|
|
76
64
|
}
|
|
77
65
|
|
|
78
66
|
export interface BuildInProcessChildLaunchInput {
|
|
67
|
+
machine?: HerdrMachineReference;
|
|
68
|
+
remoteSkillNames?: string[];
|
|
69
|
+
remoteReads?: string[] | false;
|
|
79
70
|
parentSessionId?: string;
|
|
80
71
|
forkCacheKey?: string;
|
|
81
72
|
sessionEnabled: boolean;
|
|
@@ -92,6 +83,8 @@ export interface BuildInProcessChildLaunchInput {
|
|
|
92
83
|
excludeTools?: string[];
|
|
93
84
|
extensions?: string[];
|
|
94
85
|
subagentOnlyExtensions?: string[];
|
|
86
|
+
/** Serialized launch snapshot; omitted only for a top-level parent-process lookup. */
|
|
87
|
+
requiredExtensions?: RequiredChildExtensionSnapshot;
|
|
95
88
|
systemPrompt?: string | null;
|
|
96
89
|
mcpDirectTools?: string[];
|
|
97
90
|
extensionBindings?: ExtensionBindings;
|
|
@@ -106,7 +99,6 @@ export interface BuildInProcessChildLaunchInput {
|
|
|
106
99
|
runFanoutBudget?: RunFanoutBudgetDescriptor;
|
|
107
100
|
structuredOutput?: StructuredOutputRuntime;
|
|
108
101
|
fast?: boolean;
|
|
109
|
-
modelCandidates?: readonly string[];
|
|
110
102
|
toolBudget?: ResolvedToolBudget;
|
|
111
103
|
permissionRules?: PermissionRules;
|
|
112
104
|
permissionAuditPath?: string;
|
|
@@ -136,12 +128,21 @@ export interface BuildInProcessChildLaunchInput {
|
|
|
136
128
|
* them and exposes the child environment external extensions read.
|
|
137
129
|
*/
|
|
138
130
|
host: "parent" | "runner";
|
|
131
|
+
/**
|
|
132
|
+
* Pi core tool names the host runtime provides. When set, child tool plans
|
|
133
|
+
* intersect known core slots with this set; declared non-core names remain
|
|
134
|
+
* for child startup validation. Review/scout lanes fail closed when a requested,
|
|
135
|
+
* still-permitted repository inspection tool is missing from that set.
|
|
136
|
+
*/
|
|
137
|
+
hostAvailableBuiltins?: readonly string[];
|
|
139
138
|
}
|
|
140
139
|
|
|
141
140
|
export interface InProcessChildCapture {
|
|
141
|
+
completionIntentContext?(): ArbiterModelContext | undefined;
|
|
142
142
|
structuredOutput(): { called: boolean; value?: unknown; acceptanceReport?: unknown; acceptanceReportProvided: boolean };
|
|
143
143
|
toolDiagnostic(): ChildToolDiagnostic | undefined;
|
|
144
|
-
runtimeAcknowledgedExtensions():
|
|
144
|
+
runtimeAcknowledgedExtensions(): RuntimeAcknowledgedChildExtensions | undefined;
|
|
145
|
+
finalDrainHeld(): boolean;
|
|
145
146
|
}
|
|
146
147
|
|
|
147
148
|
export interface InProcessChildLaunch {
|
|
@@ -149,7 +150,7 @@ export interface InProcessChildLaunch {
|
|
|
149
150
|
config: ChildRuntimeConfig;
|
|
150
151
|
session: Omit<ChildSessionLaunch, "onExtensionError">;
|
|
151
152
|
capture: InProcessChildCapture;
|
|
152
|
-
launchResolvedExtensions:
|
|
153
|
+
launchResolvedExtensions: LaunchResolvedChildExtensions;
|
|
153
154
|
warnings: string[];
|
|
154
155
|
capabilityAudit?: SubagentCapabilityAudit;
|
|
155
156
|
/** Path a blocked child extension writes its startup failure to; see
|
|
@@ -157,6 +158,11 @@ export interface InProcessChildLaunch {
|
|
|
157
158
|
sandboxDiagnosticsPath?: string;
|
|
158
159
|
}
|
|
159
160
|
|
|
161
|
+
/** Actual host create-input boundary. Evidence remains explicitly opt-in and dormant in production. */
|
|
162
|
+
export function createReportedChildSessionInput(launch: InProcessChildLaunch, transcriptWriter?: ChildTranscriptWriter): ChildSessionLaunch {
|
|
163
|
+
return withChildSessionErrorReporting(launch.session, transcriptWriter);
|
|
164
|
+
}
|
|
165
|
+
|
|
160
166
|
/** Escape XML-significant characters in a string for safe attribute interpolation. */
|
|
161
167
|
function escapeXmlAttr(value: string): string {
|
|
162
168
|
return value
|
|
@@ -195,19 +201,20 @@ function childStorage(input: BuildInProcessChildLaunchInput): ChildSessionStorag
|
|
|
195
201
|
}
|
|
196
202
|
|
|
197
203
|
export function buildInProcessChildLaunch(input: BuildInProcessChildLaunchInput): InProcessChildLaunch {
|
|
204
|
+
const requiredExtensions = input.requiredExtensions ?? input.inherited?.requiredExtensions ?? resolveRequiredChildExtensions(input.parentSessionId);
|
|
198
205
|
const toolPlan = resolvePiLaunchToolPlan({
|
|
199
206
|
tools: input.tools,
|
|
200
207
|
excludeTools: input.excludeTools,
|
|
201
208
|
allowNestedSubagents: input.allowNestedSubagents,
|
|
202
209
|
extensions: input.extensions,
|
|
203
210
|
subagentOnlyExtensions: input.subagentOnlyExtensions,
|
|
211
|
+
requiredExtensions,
|
|
204
212
|
mcpDirectTools: input.mcpDirectTools,
|
|
205
213
|
cwd: input.cwd,
|
|
206
214
|
requireReadTool: input.requireReadTool,
|
|
207
215
|
structuredOutput: Boolean(input.structuredOutput),
|
|
208
216
|
fast: input.fast,
|
|
209
217
|
model: input.model,
|
|
210
|
-
modelCandidates: input.modelCandidates,
|
|
211
218
|
capabilityCeiling: input.capabilityCeiling,
|
|
212
219
|
inheritedCapabilityCeiling: inheritedCapabilityCeiling(input.inherited),
|
|
213
220
|
agentName: input.childAgentName,
|
|
@@ -215,60 +222,13 @@ export function buildInProcessChildLaunch(input: BuildInProcessChildLaunchInput)
|
|
|
215
222
|
runtimeSnapshotHost: input.runtimeSnapshotHost,
|
|
216
223
|
sandbox: input.sandbox,
|
|
217
224
|
permissionProfile: input.permissionProfile,
|
|
225
|
+
hostAvailableBuiltins: input.hostAvailableBuiltins,
|
|
218
226
|
});
|
|
219
227
|
|
|
220
|
-
//
|
|
221
|
-
//
|
|
222
|
-
//
|
|
223
|
-
|
|
224
|
-
const sandboxAckPath = toolPlan.sandboxExtension && input.sandbox !== undefined
|
|
225
|
-
? path.join(TEMP_ROOT_DIR, "sandbox-profile-acks", `${randomUUID()}.json`)
|
|
226
|
-
: undefined;
|
|
227
|
-
const sandboxDiagnosticsPath = sandboxAckPath
|
|
228
|
-
? path.join(TEMP_ROOT_DIR, "sandbox-profile-diagnostics", `${randomUUID()}.json`)
|
|
229
|
-
: undefined;
|
|
230
|
-
const sandboxEnv: Record<string, string | undefined> | undefined = sandboxAckPath
|
|
231
|
-
? {
|
|
232
|
-
[SUBAGENT_SANDBOX_PROFILE_ENV]: input.sandbox,
|
|
233
|
-
[SUBAGENT_SANDBOX_PROJECT_TRUST_ENV]: hasTrustedProfileProjectCwd(input) ? "1" : "0",
|
|
234
|
-
[SANDBOX_STARTUP_ACK_PATH_ENV]: sandboxAckPath,
|
|
235
|
-
[SANDBOX_STARTUP_ACK_TOKEN_ENV]: randomUUID(),
|
|
236
|
-
[SANDBOX_DIAGNOSTICS_PATH_ENV]: sandboxDiagnosticsPath,
|
|
237
|
-
...(input.host === "parent" ? { [IN_PROCESS_CHILD_ENV]: "1" } : {}),
|
|
238
|
-
}
|
|
239
|
-
: undefined;
|
|
240
|
-
if (sandboxAckPath) fs.mkdirSync(path.dirname(sandboxAckPath), { recursive: true, mode: 0o700 });
|
|
241
|
-
|
|
242
|
-
// A selected permission profile travels as a bare validated name (the rules
|
|
243
|
-
// live in the child's global pi-permission-system config). The key is
|
|
244
|
-
// transient like the sandbox keys: restored on the host once the child
|
|
245
|
-
// session exists.
|
|
246
|
-
const permissionProfileEnv: Record<string, string | undefined> | undefined =
|
|
247
|
-
input.permissionProfile !== undefined
|
|
248
|
-
? { [SUBAGENT_PERMISSION_PROFILE_ENV]: input.permissionProfile }
|
|
249
|
-
: undefined;
|
|
250
|
-
const childEnv: Record<string, string | undefined> | undefined =
|
|
251
|
-
sandboxEnv !== undefined || permissionProfileEnv !== undefined
|
|
252
|
-
? { ...(sandboxEnv ?? {}), ...(permissionProfileEnv ?? {}) }
|
|
253
|
-
: undefined;
|
|
254
|
-
// The profile key is pinned for every launch, `undefined` included: a child
|
|
255
|
-
// that declares no profile must not inherit the host session's role
|
|
256
|
-
// selection, and one that declares a profile must not be overridden by it
|
|
257
|
-
// (the launcher env wins inside pi-permission-system). It is kept out of
|
|
258
|
-
// `childEnv` so a plain in-process child does not also start receiving the
|
|
259
|
-
// binding and MCP values that only a runner-hosted child used to get.
|
|
260
|
-
const profilePin: Record<string, string | undefined> = {
|
|
261
|
-
[SUBAGENT_PERMISSION_PROFILE_ENV]: input.permissionProfile,
|
|
262
|
-
// Present for every child launch: it is what tells pi-permission-system
|
|
263
|
-
// this selection is authoritative for the child (see the constant).
|
|
264
|
-
[SUBAGENT_PERMISSION_PROFILE_PINNED_ENV]: "1",
|
|
265
|
-
};
|
|
266
|
-
const transientProcessEnv = [
|
|
267
|
-
...new Set([
|
|
268
|
-
...(childEnv ? Object.keys(childEnv) : []),
|
|
269
|
-
...Object.keys(profilePin),
|
|
270
|
-
]),
|
|
271
|
-
];
|
|
228
|
+
// Profile env construction (ack/diagnostics paths, sandbox and permission
|
|
229
|
+
// profile keys, the pinned profile, and the transient host key list) lives
|
|
230
|
+
// in the fork-only profile-launch-env module.
|
|
231
|
+
const { childEnv, profilePin, transientProcessEnv, sandboxDiagnosticsPath } = buildProfileLaunchEnv(input, toolPlan);
|
|
272
232
|
|
|
273
233
|
const inherited = input.inherited;
|
|
274
234
|
const fanout = toolPlan.fanoutAuthorized;
|
|
@@ -297,8 +257,6 @@ export function buildInProcessChildLaunch(input: BuildInProcessChildLaunchInput)
|
|
|
297
257
|
let structuredAcceptanceReport: unknown;
|
|
298
258
|
let structuredCalled = false;
|
|
299
259
|
let structuredAcceptanceProvided = false;
|
|
300
|
-
let toolDiagnostic: ChildToolDiagnostic | undefined;
|
|
301
|
-
let acknowledgedIds: string[] | undefined;
|
|
302
260
|
|
|
303
261
|
const config: ChildRuntimeConfig = {
|
|
304
262
|
...(input.runId ? { runId: input.runId } : {}),
|
|
@@ -317,6 +275,7 @@ export function buildInProcessChildLaunch(input: BuildInProcessChildLaunchInput)
|
|
|
317
275
|
maxDepth: childDepth.maxDepth,
|
|
318
276
|
...(toolPlan.capabilityCeiling ? { capabilityCeiling: toolPlan.capabilityCeiling } : {}),
|
|
319
277
|
...(thinkingCeiling ? { thinkingCeiling } : {}),
|
|
278
|
+
...(toolPlan.requiredExtensions.length > 0 ? { requiredExtensions: toolPlan.requiredExtensions } : {}),
|
|
320
279
|
inheritProjectContext: input.inheritProjectContext,
|
|
321
280
|
inheritGlobalContext: input.inheritGlobalContext,
|
|
322
281
|
inheritSkills: input.inheritSkills,
|
|
@@ -347,10 +306,9 @@ export function buildInProcessChildLaunch(input: BuildInProcessChildLaunchInput)
|
|
|
347
306
|
: {}),
|
|
348
307
|
...(toolPlan.requiredChildTools.length > 0 ? { requiredTools: toolPlan.requiredChildTools } : {}),
|
|
349
308
|
...(toolPlan.effectiveMcpTools.length > 0 ? { mcpDirectTools: toolPlan.effectiveMcpTools } : {}),
|
|
350
|
-
toolDiagnostic: (diagnostic) => { toolDiagnostic = diagnostic; },
|
|
351
|
-
runtimeAcknowledgements: (ids) => { acknowledgedIds = ids; },
|
|
352
309
|
fast: input.fast === true,
|
|
353
310
|
};
|
|
311
|
+
const capturedHooks = createCapturedChildHooks(config, input.host === "runner");
|
|
354
312
|
|
|
355
313
|
const extensionPaths = toolPlan.extensionArgs.filter((extensionPath) => !isSubagentRuntimeExtensionPath(extensionPath));
|
|
356
314
|
const ambientExtensions = input.host === "runner" && !toolPlan.disableAmbientExtensions;
|
|
@@ -359,19 +317,23 @@ export function buildInProcessChildLaunch(input: BuildInProcessChildLaunchInput)
|
|
|
359
317
|
configuredExtensions: toolPlan.configuredExtensions,
|
|
360
318
|
extensionArgs: toolPlan.extensionArgs,
|
|
361
319
|
disableAmbientExtensions: !ambientExtensions,
|
|
320
|
+
requiredExtensions: toolPlan.requiredExtensions,
|
|
362
321
|
});
|
|
363
322
|
const taggedPrompt = input.systemPrompt !== undefined && input.systemPrompt !== null
|
|
364
323
|
? `<active_agent name="${escapeXmlAttr(input.childAgentName)}"/>\n\n${input.systemPrompt}`
|
|
365
324
|
: undefined;
|
|
366
325
|
const session: Omit<ChildSessionLaunch, "onExtensionError"> = {
|
|
367
326
|
cwd: input.cwd,
|
|
327
|
+
...(input.machine ? { machine: input.machine } : {}),
|
|
328
|
+
...(input.machine ? { remoteResources: { agent: input.childAgentName, ...(input.remoteSkillNames ? { skills: input.remoteSkillNames } : {}), ...(input.remoteReads !== undefined ? { reads: input.remoteReads } : {}), ...(toolPlan.explicitToolAllowlist ? { toolCeiling: [...toolPlan.effectiveToolAllowlist] } : toolPlan.capabilityCeiling?.allowedTools ? { toolCeiling: [...toolPlan.capabilityCeiling.allowedTools] } : {}) } } : {}),
|
|
368
329
|
storage: childStorage(input),
|
|
369
330
|
...(input.model ? { model: input.model } : {}),
|
|
370
331
|
...(toolPlan.explicitToolAllowlist ? { tools: toolPlan.effectiveToolAllowlist } : {}),
|
|
371
332
|
...(!toolPlan.explicitToolAllowlist && toolPlan.excludeTools.length > 0 ? { excludeTools: toolPlan.excludeTools } : {}),
|
|
372
333
|
extensionPaths,
|
|
334
|
+
requiredExtensions: toolPlan.requiredExtensions,
|
|
373
335
|
ambientExtensions,
|
|
374
|
-
hooks:
|
|
336
|
+
hooks: capturedHooks.hooks,
|
|
375
337
|
...(input.host === "runner" || childEnv
|
|
376
338
|
? { processEnv: { ...childProcessEnv(input, toolPlan, childEnv), ...profilePin } }
|
|
377
339
|
: { processEnv: profilePin }),
|
|
@@ -389,9 +351,11 @@ export function buildInProcessChildLaunch(input: BuildInProcessChildLaunchInput)
|
|
|
389
351
|
config,
|
|
390
352
|
session,
|
|
391
353
|
capture: {
|
|
354
|
+
completionIntentContext: capturedHooks.completionIntentContext,
|
|
392
355
|
structuredOutput: () => ({ called: structuredCalled, value: structuredValue, acceptanceReport: structuredAcceptanceReport, acceptanceReportProvided: structuredAcceptanceProvided }),
|
|
393
|
-
toolDiagnostic:
|
|
394
|
-
runtimeAcknowledgedExtensions:
|
|
356
|
+
toolDiagnostic: capturedHooks.toolDiagnostic,
|
|
357
|
+
runtimeAcknowledgedExtensions: capturedHooks.runtimeAcknowledgedExtensions,
|
|
358
|
+
finalDrainHeld: capturedHooks.finalDrainHeld,
|
|
395
359
|
},
|
|
396
360
|
launchResolvedExtensions,
|
|
397
361
|
warnings: toolPlan.warnings,
|
|
@@ -14,11 +14,14 @@ export function projectChildLifecycle(event: { type?: string; willRetry?: unknow
|
|
|
14
14
|
if (state) state.compactionRetryActive = event.willRetry === true;
|
|
15
15
|
return event.willRetry === true ? "cancel-drain" : "none";
|
|
16
16
|
}
|
|
17
|
-
if (event.type === "agent_start" || event.type === "auto_retry_start") {
|
|
17
|
+
if (event.type === "agent_start" || event.type === "auto_retry_start" || event.type === "turn_start") {
|
|
18
18
|
if (state) state.compactionRetryActive = false;
|
|
19
|
+
return "cancel-drain";
|
|
20
|
+
}
|
|
21
|
+
if (event.type === "agent_end") {
|
|
22
|
+
if (event.willRetry !== true && state) state.compactionRetryActive = false;
|
|
23
|
+
return "cancel-drain";
|
|
19
24
|
}
|
|
20
|
-
if (event.type === "agent_end" && event.willRetry === true) return "cancel-drain";
|
|
21
|
-
if (event.type === "agent_end" && state) state.compactionRetryActive = false;
|
|
22
25
|
if (event.type === "agent_settled") return state?.compactionRetryActive ? "none" : "start-drain";
|
|
23
26
|
if (terminalAssistantStop) return "start-drain";
|
|
24
27
|
return "none";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { JsonSchemaObject, ResolvedToolBudget, RunFanoutBudgetDescriptor } from "../../shared/types.ts";
|
|
1
|
+
import type { JsonSchemaObject, ResolvedToolBudget, RunFanoutBudgetDescriptor, SubagentState } from "../../shared/types.ts";
|
|
2
2
|
import type { ThinkingLevel } from "../../shared/model-info.ts";
|
|
3
3
|
import type { NestedPathEntry } from "./nested-path.ts";
|
|
4
4
|
import type { PermissionRules } from "./permissions.ts";
|
|
@@ -6,6 +6,7 @@ import type { ChildWatchdogConfig, ChildWatchdogStatusEvent } from "../../watchd
|
|
|
6
6
|
import type { ResolvedWaitToolConfig } from "../background/wait-config.ts";
|
|
7
7
|
import type { ChildToolDiagnostic } from "./tool-availability.ts";
|
|
8
8
|
import type { ResolvedSubagentCapabilityCeiling } from "./capability-ceiling.ts";
|
|
9
|
+
import type { RequiredChildExtensionSnapshot } from "../../shared/required-child-extensions.ts";
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* Set in processes that host child sessions (the async runner). The extension
|
|
@@ -75,6 +76,8 @@ export interface ChildRuntimeConfig {
|
|
|
75
76
|
depth: number;
|
|
76
77
|
maxDepth?: number;
|
|
77
78
|
capabilityCeiling?: ResolvedSubagentCapabilityCeiling;
|
|
79
|
+
/** Immutable root-parent host policy propagated to nested native launches. */
|
|
80
|
+
requiredExtensions?: RequiredChildExtensionSnapshot;
|
|
78
81
|
thinkingCeiling?: ThinkingLevel;
|
|
79
82
|
inheritProjectContext?: boolean;
|
|
80
83
|
inheritGlobalContext?: boolean;
|
|
@@ -86,6 +89,10 @@ export interface ChildRuntimeConfig {
|
|
|
86
89
|
/** Receives child watchdog status events. */
|
|
87
90
|
watchdogStatus?: (event: ChildWatchdogStatusEvent) => void;
|
|
88
91
|
waitTool: ResolvedWaitToolConfig;
|
|
92
|
+
runtimeState?: SubagentState;
|
|
93
|
+
holdFinalDrain?: (held: boolean) => void;
|
|
94
|
+
/** Installation-local downward owner-channel barrier; never inherited or serialized into descendants. */
|
|
95
|
+
hasPendingSupervisorRequest?: () => boolean;
|
|
89
96
|
structuredOutput?: ChildStructuredOutput;
|
|
90
97
|
requiredTools?: string[];
|
|
91
98
|
mcpDirectTools?: string[];
|