@xzzpig/pi-subagents 0.8.0 → 0.9.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 +443 -0
- package/README.md +2 -2
- package/agents/claude-code-writer.md +15 -0
- package/agents/claude-code.md +15 -0
- package/agents/codex-exec-writer.md +15 -0
- package/agents/codex-exec.md +15 -0
- package/agents/cursor-agent-writer.md +14 -0
- package/agents/cursor-agent.md +14 -0
- package/agents/reviewer.md +1 -1
- package/agents/scout.md +1 -1
- package/docs/agents.md +151 -39
- package/docs/configuration.md +81 -22
- package/docs/extension-api.md +69 -14
- package/docs/missions.md +2 -0
- package/docs/models.md +32 -9
- package/docs/observability.md +22 -20
- package/docs/tool-reference.md +123 -14
- package/docs/watchdog.md +92 -114
- package/docs/workflows.md +142 -4
- package/install.mjs +1 -1
- package/package.json +5 -4
- package/prompts/review-loop.md +2 -2
- package/skills/council-mode/SKILL.md +48 -243
- package/skills/council-mode/references/pass-contracts.md +150 -0
- package/skills/pi-subagents/SKILL.md +89 -35
- package/skills/pi-subagents/references/constraints-and-recipes.md +30 -234
- package/skills/pi-subagents/references/execution-controls.md +91 -15
- package/skills/pi-subagents/references/management-authoring-rpc.md +5 -5
- package/skills/pi-subagents/references/multi-lane-orchestration.md +13 -1
- package/skills/pi-subagents/references/prompting-and-roles.md +59 -31
- package/skills/pi-subagents/references/review-and-validation.md +73 -0
- package/src/agents/agent-management.ts +370 -114
- package/src/agents/agent-refinements.ts +4 -4
- package/src/agents/agent-serializer.ts +12 -2
- package/src/agents/agents.ts +919 -372
- package/src/agents/builtin-names.ts +6 -0
- package/src/agents/runtime-agent-events.ts +70 -0
- package/src/agents/runtime-agent-registry.ts +31 -20
- package/src/api/agents.ts +10 -5
- package/src/api/background-work.ts +12 -3
- package/src/api/capability-ceiling.ts +0 -1
- package/src/api/{pi-args.ts → child-tool-plan.ts} +1 -1
- package/src/api/delegation.ts +0 -7
- package/src/api/external-runs.ts +67 -4
- package/src/api/preflight.ts +48 -18
- package/src/api/shared-types.ts +6 -0
- package/src/extension/config.ts +90 -0
- package/src/extension/doctor.ts +5 -13
- package/src/extension/fanout-child.ts +14 -14
- package/src/extension/index.ts +115 -37
- package/src/extension/public-execution.ts +103 -15
- package/src/extension/rpc.ts +120 -25
- package/src/extension/schemas.ts +57 -21
- package/src/extension/tool-description.ts +48 -26
- package/src/inspectors/herdr/actions.ts +2 -1
- package/src/inspectors/herdr/inspector-runner.ts +21 -23
- package/src/inspectors/herdr/session-roots-codec.ts +42 -0
- package/src/integrations/herdr-status.ts +51 -3
- package/src/intercom/native-supervisor-channel.ts +138 -60
- package/src/intercom/result-intercom.ts +2 -0
- package/src/intercom/supervisor-ui.ts +243 -0
- package/src/profiles/profiles.ts +5 -6
- package/src/runs/background/active-async-capacity.ts +103 -18
- package/src/runs/background/async-execution.ts +366 -128
- package/src/runs/background/async-job-tracker.ts +95 -15
- package/src/runs/background/async-resume.ts +45 -28
- package/src/runs/background/async-retention.ts +20 -3
- package/src/runs/background/async-status-snapshot.ts +23 -261
- package/src/runs/background/async-status.ts +189 -14
- package/src/runs/background/auto-drain.ts +1 -1
- package/src/runs/background/chain-append.ts +8 -3
- package/src/runs/background/chain-root-attachment.ts +74 -8
- package/src/runs/background/control-channel.ts +4 -205
- package/src/runs/background/fleet-view.ts +38 -22
- package/src/runs/background/inspect-rpc.ts +8 -8
- package/src/runs/background/notify.ts +238 -12
- package/src/runs/background/process-terminal.ts +16 -0
- package/src/runs/background/result-delivery-ownership.ts +45 -0
- package/src/runs/background/result-files.ts +28 -14
- package/src/runs/background/result-watcher.ts +39 -16
- package/src/runs/background/resume-guidance.ts +2 -2
- package/src/runs/background/retained-children.ts +1 -1
- package/src/runs/background/run-child-session.ts +613 -0
- package/src/runs/background/run-status.ts +84 -17
- package/src/runs/background/runner-aliases.ts +125 -0
- package/src/runs/background/runner-child-sessions.ts +31 -0
- package/src/runs/background/scheduled-runs.ts +174 -18
- package/src/runs/background/stale-run-reconciler.ts +10 -4
- package/src/runs/background/steering.ts +8 -15
- package/src/runs/background/subagent-runner.ts +676 -1161
- package/src/runs/background/subagent-wait.ts +86 -31
- package/src/runs/background/terminal-run-index.ts +1 -1
- package/src/runs/background/wait-completions.ts +43 -2
- package/src/runs/background/wait-config.ts +23 -9
- package/src/runs/background/wait-tool.ts +26 -19
- package/src/runs/foreground/async-steering-action.ts +3 -19
- package/src/runs/foreground/execution.ts +468 -499
- package/src/runs/foreground/foreground-control.ts +13 -0
- package/src/runs/foreground/foreground-history.ts +23 -1
- package/src/runs/foreground/subagent-executor.ts +1172 -400
- package/src/runs/foreground/workflow-detach-reconcile.ts +140 -115
- package/src/runs/foreground/workflow-foreground-steering.ts +24 -98
- package/src/runs/shared/abort-recovery.ts +119 -0
- package/src/runs/shared/acceptance.ts +138 -36
- package/src/runs/shared/async-status-projection.ts +565 -0
- package/src/runs/shared/background-process-options.ts +9 -0
- package/src/runs/shared/capability-ceiling.ts +2 -2
- package/src/runs/shared/child-hooks.ts +25 -0
- package/src/runs/shared/child-identity.ts +32 -6
- package/src/runs/shared/child-launch-plan.ts +151 -0
- package/src/runs/shared/child-launch.ts +314 -0
- package/src/runs/shared/child-lifecycle.ts +25 -0
- package/src/runs/shared/child-runtime-config.ts +126 -0
- package/src/runs/shared/child-session.ts +342 -0
- package/src/runs/shared/child-tool-plan.ts +540 -0
- package/src/runs/shared/claude-code-adapter.ts +133 -0
- package/src/runs/shared/codex-exec-adapter.ts +129 -0
- package/src/runs/shared/completion-evidence.ts +89 -0
- package/src/runs/shared/completion-guard.ts +6 -5
- package/src/runs/shared/cursor-agent-adapter.ts +114 -0
- package/src/runs/shared/dynamic-fanout.ts +3 -3
- package/src/runs/shared/external-cli-contract.ts +167 -0
- package/src/runs/shared/external-cli-preflight.ts +138 -0
- package/src/runs/shared/external-cli-runner.ts +348 -55
- package/src/runs/shared/fast-mode-extension.ts +5 -5
- package/src/runs/shared/host-step-status.ts +231 -0
- package/src/runs/shared/lane-metadata.ts +126 -0
- package/src/runs/shared/launch-cwd.ts +16 -0
- package/src/runs/shared/long-running-guard.ts +2 -1
- package/src/runs/shared/mcp-config-sources.ts +422 -0
- package/src/runs/shared/mcp-direct-tool-allowlist.ts +222 -158
- package/src/runs/shared/mcp-direct-tool-grant.ts +194 -0
- package/src/runs/shared/model-exclusions.ts +139 -9
- package/src/runs/shared/model-fallback.ts +142 -14
- package/src/runs/shared/mutation-evidence.ts +57 -3
- package/src/runs/shared/nested-events.ts +38 -48
- package/src/runs/shared/nested-path.ts +0 -14
- package/src/runs/shared/nested-render.ts +9 -5
- package/src/runs/shared/orca-progress-tabs.ts +12 -7
- package/src/runs/shared/parallel-handoff.ts +423 -7
- package/src/runs/shared/parallel-utils.ts +15 -7
- package/src/runs/shared/permissions.ts +1 -14
- package/src/runs/shared/pi-spawn.ts +69 -35
- package/src/runs/shared/process-signal.ts +16 -0
- package/src/runs/shared/run-fanout-budget.ts +0 -13
- package/src/runs/shared/run-history.ts +21 -1
- package/src/runs/shared/runtime-acknowledged-extensions.ts +0 -27
- package/src/runs/shared/single-output.ts +89 -22
- package/src/runs/shared/structured-output.ts +49 -9
- package/src/runs/shared/subagent-control.ts +6 -2
- package/src/runs/shared/subagent-prompt-runtime.ts +188 -365
- package/src/runs/shared/task-intent.ts +21 -7
- package/src/runs/shared/tool-availability.ts +18 -62
- package/src/runs/shared/tool-budget.ts +0 -14
- package/src/runs/shared/tool-timeout.ts +1 -1
- package/src/runs/shared/workflow-graph.ts +16 -0
- package/src/runs/shared/worktree-cleanup-plan.ts +866 -0
- package/src/runs/shared/worktree.ts +571 -62
- package/src/shared/atomic-json.ts +3 -1
- package/src/shared/child-session-name.ts +46 -0
- package/src/shared/extension-context.ts +24 -0
- package/src/shared/fork-context.ts +21 -12
- package/src/shared/fork-session-cwd.ts +27 -0
- package/src/shared/formatters.ts +18 -3
- package/src/shared/jsonl-writer.ts +11 -0
- package/src/shared/launch-contract.ts +8 -1
- package/src/shared/pruned-fork.ts +450 -0
- package/src/shared/session-file-trust.ts +19 -0
- package/src/shared/session-tokens.ts +14 -3
- package/src/shared/settings.ts +19 -105
- package/src/shared/shortcuts.ts +17 -0
- package/src/shared/thinking-ceiling.ts +0 -6
- package/src/shared/types.ts +524 -70
- package/src/shared/utils.ts +60 -93
- package/src/shared/workflow-child-permit.ts +207 -0
- package/src/slash/delegation-adapters.ts +1 -9
- package/src/slash/delegation-request.ts +0 -4
- package/src/slash/prompt-template-bridge.ts +37 -1
- package/src/slash/slash-bridge.ts +1 -2
- package/src/slash/slash-commands.ts +383 -116
- package/src/slash/slash-live-state.ts +22 -11
- package/src/slash/subagents-admin.ts +29 -12
- package/src/tui/fleet-native-transcript.ts +4 -0
- package/src/tui/fleet-status.ts +217 -82
- package/src/tui/fleet-transcript.ts +11 -5
- package/src/tui/fleet.ts +54 -28
- package/src/tui/render-helpers.ts +31 -0
- package/src/tui/render.ts +1429 -163
- package/src/watchdog/change-signature.ts +40 -1
- package/src/watchdog/child-status.ts +54 -34
- package/src/watchdog/diff-tool.ts +77 -0
- package/src/watchdog/emission-guard.ts +5 -3
- package/src/watchdog/guidance.ts +20 -0
- package/src/watchdog/register-child.ts +28 -25
- package/src/watchdog/register-main.ts +10 -9
- package/src/watchdog/render.ts +4 -5
- package/src/watchdog/review.ts +15 -4
- package/src/watchdog/rules.ts +70 -0
- package/src/watchdog/runtime.ts +75 -92
- package/src/watchdog/scope.ts +0 -11
- package/src/watchdog/settings.ts +48 -104
- package/src/watchdog/turn-delta.ts +1 -1
- package/src/watchdog/types.ts +18 -32
- package/src/watchdog/warning-format.ts +0 -1
- package/src/workflows/chat-progress.ts +7 -3
- package/src/workflows/host-command.ts +235 -0
- package/src/workflows/scripted-workflow.ts +988 -59
- package/src/workflows/workflow-checklist.ts +439 -0
- package/src/workflows/workflow-child-summary.ts +121 -0
- package/src/workflows/workflow-preflight.ts +297 -0
- package/src/workflows/workflow-receipt.ts +232 -6
- package/src/workflows/workflow-resources.ts +150 -0
- package/src/workflows/workflow-settlement.ts +246 -0
- package/src/runs/shared/child-protocol.ts +0 -401
- package/src/runs/shared/pi-args.ts +0 -935
- package/src/runs/shared/subagent-startup-retry.ts +0 -116
- package/src/runs/shared/turn-budget.ts +0 -98
- package/src/shared/post-exit-stdio-guard.ts +0 -85
package/src/api/preflight.ts
CHANGED
|
@@ -1,22 +1,20 @@
|
|
|
1
1
|
import * as fs from "node:fs";
|
|
2
2
|
import * as path from "node:path";
|
|
3
3
|
import { fileURLToPath } from "node:url";
|
|
4
|
-
import {
|
|
4
|
+
import { discoverAgentSnapshot, findBlockingAgentDiagnostic, formatUnknownAgentError, resolveAgentName, unknownAgentDiagnosticContext, type AgentConfig, type AgentDiscoveryAllResult, type AgentScope, type AgentSource } from "../agents/agents.ts";
|
|
5
5
|
import { resolveExecutionAgentScope } from "../agents/agent-scope.ts";
|
|
6
6
|
import { buildSkillInjection, normalizeSkillInput, resolveSkillsWithFallback } from "../agents/skills.ts";
|
|
7
7
|
import { buildAgentMemoryInjection } from "../agents/agent-memory.ts";
|
|
8
|
-
import { buildModelCandidates, inheritsParentModel, resolveEffectiveSubagentModel, type AvailableModelInfo, type ParentModel } from "../runs/shared/model-fallback.ts";
|
|
8
|
+
import { buildModelCandidates, inheritsParentModel, resolveEffectiveSubagentModel, resolveModelOrigin, type AvailableModelInfo, type ParentModel } from "../runs/shared/model-fallback.ts";
|
|
9
9
|
import { resolveModelScopesForAgent } from "../runs/shared/model-scope.ts";
|
|
10
|
-
import { applyThinkingSuffix, resolvePiLaunchToolPlan, type PiLaunchToolPlan } from "../runs/shared/
|
|
10
|
+
import { applyThinkingSuffix, resolvePiLaunchToolPlan, type PiLaunchToolPlan } from "../runs/shared/child-tool-plan.ts";
|
|
11
11
|
import { injectOutputPathSystemPrompt, normalizeSingleOutputOverride, resolveSingleOutputPath } from "../runs/shared/single-output.ts";
|
|
12
12
|
import { getArtifactPaths, getArtifactsDir } from "../shared/artifacts.ts";
|
|
13
13
|
import { resolveEffectiveThinking } from "../shared/model-info.ts";
|
|
14
|
-
import { assertThinkingWithinCeiling,
|
|
14
|
+
import { assertThinkingWithinCeiling, intersectThinkingCeilings, type ThinkingLevel } from "../shared/thinking-ceiling.ts";
|
|
15
15
|
import { SUBAGENT_LIFECYCLE_ARTIFACT_VERSION, type ArtifactDirPreference, type ArtifactPaths, type JsonSchemaObject, type OutputMode } from "../shared/types.ts";
|
|
16
16
|
import { capabilityCeilingAgentRestrictionMessage, intersectSubagentCapabilityCeilings, type ResolvedSubagentCapabilityCeiling, type SubagentCapabilityAudit } from "../runs/shared/capability-ceiling.ts";
|
|
17
|
-
import { appendTurnBudgetSystemPrompt } from "../runs/shared/turn-budget.ts";
|
|
18
17
|
import { resolvePermissionRules } from "../runs/shared/permissions.ts";
|
|
19
|
-
import type { ResolvedTurnBudget } from "../shared/types.ts";
|
|
20
18
|
import type { ResolvedMcpDirectToolSelection } from "../runs/shared/mcp-direct-tool-allowlist.ts";
|
|
21
19
|
import { resolveStepBehavior } from "../shared/settings.ts";
|
|
22
20
|
import { canPreferForkFromSnapshot, resolveSubagentLaunchContext } from "../shared/fork-context.ts";
|
|
@@ -42,8 +40,10 @@ export type SubagentLaunchContractReasonCode =
|
|
|
42
40
|
| "thinking_ceiling"
|
|
43
41
|
| "invalid_extension_bindings";
|
|
44
42
|
|
|
43
|
+
export type SubagentLaunchContractDiagnosticCode = SubagentLaunchContractReasonCode | "host_required" | "snapshot_warning" | "workspace_scope_authority";
|
|
44
|
+
|
|
45
45
|
export interface SubagentLaunchContractDiagnostic {
|
|
46
|
-
code:
|
|
46
|
+
code: SubagentLaunchContractDiagnosticCode;
|
|
47
47
|
severity: "error" | "warning" | "host-required";
|
|
48
48
|
message: string;
|
|
49
49
|
}
|
|
@@ -67,7 +67,6 @@ export interface SubagentLaunchContractInput {
|
|
|
67
67
|
outputMode?: OutputMode;
|
|
68
68
|
outputSchema?: JsonSchemaObject;
|
|
69
69
|
extensionBindings?: ExtensionBindings;
|
|
70
|
-
turnBudget?: ResolvedTurnBudget;
|
|
71
70
|
artifacts?: boolean;
|
|
72
71
|
artifactDir?: ArtifactDirPreference;
|
|
73
72
|
parentSessionFile?: string | null;
|
|
@@ -112,6 +111,7 @@ export interface SubagentLaunchContractSkills {
|
|
|
112
111
|
export interface SubagentLaunchContractTools {
|
|
113
112
|
requestedBuiltin: string[];
|
|
114
113
|
declaredBuiltin: string[];
|
|
114
|
+
excludeTools?: string[];
|
|
115
115
|
effectiveAllowlist: string[];
|
|
116
116
|
explicitAllowlist: boolean;
|
|
117
117
|
requiredChildTools: string[];
|
|
@@ -157,6 +157,7 @@ export interface SubagentLaunchContract {
|
|
|
157
157
|
thinkingCeiling?: ThinkingLevel;
|
|
158
158
|
systemPromptMode: AgentConfig["systemPromptMode"];
|
|
159
159
|
inheritProjectContext: boolean;
|
|
160
|
+
inheritGlobalContext: boolean;
|
|
160
161
|
inheritSkills: boolean;
|
|
161
162
|
skills: SubagentLaunchContractSkills;
|
|
162
163
|
tools: SubagentLaunchContractTools;
|
|
@@ -208,8 +209,25 @@ function resolveLaunchContractContext(input: SubagentLaunchContractInput, agent:
|
|
|
208
209
|
});
|
|
209
210
|
}
|
|
210
211
|
|
|
211
|
-
function
|
|
212
|
-
|
|
212
|
+
function taskWorkspaceScopeAuthorityDiagnostic(task: string | undefined): SubagentLaunchContractDiagnostic | undefined {
|
|
213
|
+
if (!task) return undefined;
|
|
214
|
+
const text = task.replace(/\s+/g, " ").trim();
|
|
215
|
+
if (!text) return undefined;
|
|
216
|
+
const createsWorkspacePackage = /\b(?:add|create|introduce|make|set up)\b.{0,80}\b(?:new\s+)?(?:workspace\s+)?package\b/i.test(text)
|
|
217
|
+
|| /\b(?:new\s+)?package\b.{0,80}\b(?:workspace|monorepo)\b/i.test(text);
|
|
218
|
+
if (!createsWorkspacePackage) return undefined;
|
|
219
|
+
const packageOnlyAuthority = /\b(?:only|solely)\b.{0,40}\b(?:edit|change|modify|touch|write(?:\s+to)?)\b.{0,80}\b(?:package(?:\s+directory)?|packages\/[\w.-]+)\b/i.test(text)
|
|
220
|
+
|| /\b(?:do not|don't|must not)\b.{0,40}\b(?:edit|change|modify|touch|write(?:\s+to)?)\b.{0,80}\b(?:root|workspace|lockfile|metadata)\b/i.test(text)
|
|
221
|
+
|| /\bwithout\b.{0,40}\b(?:root|workspace|lockfile|metadata)\b.{0,40}\b(?:edit|change|modification|write)s?\b/i.test(text);
|
|
222
|
+
if (!packageOnlyAuthority) return undefined;
|
|
223
|
+
return {
|
|
224
|
+
code: "workspace_scope_authority",
|
|
225
|
+
severity: "warning",
|
|
226
|
+
message: "Task asks for a workspace package change while limiting authority to package-scope edits. New workspace packages often need root workspace metadata or lockfile changes, so confirm that authority before launch.",
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function candidateList(inputAgent: string, selected: AgentConfig | undefined, all: AgentDiscoveryAllResult): SubagentLaunchContractAgentCandidate[] {
|
|
213
231
|
return [...all.builtin, ...all.package, ...all.user, ...all.project]
|
|
214
232
|
.filter((agent) => Boolean(resolveAgentName(inputAgent, [agent]).agent))
|
|
215
233
|
.map((agent) => ({
|
|
@@ -225,6 +243,8 @@ function candidateList(inputAgent: string, selected: AgentConfig | undefined, cw
|
|
|
225
243
|
|
|
226
244
|
export async function resolveSubagentLaunchContract(input: SubagentLaunchContractInput): Promise<SubagentLaunchContractResult> {
|
|
227
245
|
const diagnostics: SubagentLaunchContractDiagnostic[] = [];
|
|
246
|
+
const authorityDiagnostic = taskWorkspaceScopeAuthorityDiagnostic(input.task);
|
|
247
|
+
if (authorityDiagnostic) diagnostics.push(authorityDiagnostic);
|
|
228
248
|
const effectiveCwd = path.resolve(input.cwd);
|
|
229
249
|
try {
|
|
230
250
|
if (!fs.statSync(effectiveCwd).isDirectory()) {
|
|
@@ -241,7 +261,9 @@ export async function resolveSubagentLaunchContract(input: SubagentLaunchContrac
|
|
|
241
261
|
return { ok: false, code: "invalid_artifact_dir", message: `Unsupported artifactDir '${String(input.artifactDir)}'; expected 'project', 'session', or 'temp'.`, diagnostics };
|
|
242
262
|
}
|
|
243
263
|
const scope = resolveExecutionAgentScope(input.agentScope);
|
|
244
|
-
const
|
|
264
|
+
const parentProvider = input.preferredProvider ?? input.parentModel?.provider;
|
|
265
|
+
const discovery = discoverAgentSnapshot(effectiveCwd, scope, parentProvider, { includeChains: false });
|
|
266
|
+
const discovered = discovery.effective;
|
|
245
267
|
const resolvedAgent = resolveAgentName(input.agent, discovered.agents);
|
|
246
268
|
const ambiguousCandidates = resolvedAgent.error
|
|
247
269
|
? discovered.agents.filter((agent) => resolveAgentName(input.agent, [agent]).agent)
|
|
@@ -255,7 +277,7 @@ export async function resolveSubagentLaunchContract(input: SubagentLaunchContrac
|
|
|
255
277
|
return { ok: false, code: "ambiguous_agent", message: resolvedAgent.error, diagnostics };
|
|
256
278
|
}
|
|
257
279
|
if (!resolvedAgent.agent) {
|
|
258
|
-
return { ok: false, code: "missing_agent", message:
|
|
280
|
+
return { ok: false, code: "missing_agent", message: formatUnknownAgentError(input.agent, unknownAgentDiagnosticContext(discovered)), diagnostics };
|
|
259
281
|
}
|
|
260
282
|
const agent = resolvedAgent.agent;
|
|
261
283
|
let extensionBindings: ExtensionBindings | undefined;
|
|
@@ -300,22 +322,26 @@ export async function resolveSubagentLaunchContract(input: SubagentLaunchContrac
|
|
|
300
322
|
const availableModels = normalizeAvailableModels(input.availableModels);
|
|
301
323
|
const preferredProvider = agent.modelProvider ?? input.preferredProvider ?? input.parentModel?.provider;
|
|
302
324
|
const modelScopes = resolveModelScopesForAgent(discovered.modelScope, agent.name, input.parentModel);
|
|
325
|
+
const modelOrigin = resolveModelOrigin({ explicitModel: input.model, agentModel: agent.model, parentModel: input.parentModel });
|
|
303
326
|
const primaryModel = externalRunner
|
|
304
327
|
? undefined
|
|
305
|
-
: resolveEffectiveSubagentModel(input.model, agent.model, input.parentModel, availableModels, preferredProvider, {
|
|
328
|
+
: resolveEffectiveSubagentModel(input.model, agent.model, input.parentModel, availableModels, preferredProvider, {
|
|
329
|
+
scope: modelScopes,
|
|
330
|
+
source: modelOrigin === "explicit" ? "explicit" : "inherited",
|
|
331
|
+
});
|
|
306
332
|
const effectiveThinkingConfig = input.thinking !== undefined ? input.thinking : agent.thinking;
|
|
307
333
|
const thinkingCeiling = externalRunner ? undefined : intersectThinkingCeilings(
|
|
308
334
|
discovered.maxThinking,
|
|
309
335
|
input.thinkingCeiling,
|
|
310
336
|
input.inheritedThinkingCeiling,
|
|
311
|
-
decodeThinkingCeiling(process.env[SUBAGENT_THINKING_CEILING_ENV]),
|
|
312
337
|
);
|
|
313
338
|
const model = externalRunner ? undefined : applyThinkingSuffix(primaryModel, effectiveThinkingConfig, input.thinking !== undefined);
|
|
314
339
|
const modelCandidates = externalRunner
|
|
315
340
|
? []
|
|
316
341
|
: buildModelCandidates(primaryModel, agent.fallbackModels, availableModels, preferredProvider, {
|
|
317
342
|
scope: modelScopes,
|
|
318
|
-
primaryModelFromParent: inheritsParentModel(input.model, agent.model, input.parentModel),
|
|
343
|
+
primaryModelFromParent: modelOrigin === "inherited" || inheritsParentModel(input.model, agent.model, input.parentModel),
|
|
344
|
+
origin: modelOrigin,
|
|
319
345
|
})
|
|
320
346
|
.map((candidate) => applyThinkingSuffix(candidate, effectiveThinkingConfig, input.thinking !== undefined) ?? candidate);
|
|
321
347
|
if (!externalRunner) {
|
|
@@ -334,6 +360,8 @@ export async function resolveSubagentLaunchContract(input: SubagentLaunchContrac
|
|
|
334
360
|
try {
|
|
335
361
|
toolPlan = resolvePiLaunchToolPlan({
|
|
336
362
|
tools: agent.tools,
|
|
363
|
+
excludeTools: agent.excludeTools,
|
|
364
|
+
allowNestedSubagents: agent.allowNestedSubagents,
|
|
337
365
|
extensions: agent.extensions,
|
|
338
366
|
subagentOnlyExtensions: agent.subagentOnlyExtensions,
|
|
339
367
|
mcpDirectTools: agent.mcpDirectTools,
|
|
@@ -379,9 +407,7 @@ export async function resolveSubagentLaunchContract(input: SubagentLaunchContrac
|
|
|
379
407
|
const memoryInjection = buildAgentMemoryInjection(agent, effectiveCwd);
|
|
380
408
|
if (memoryInjection) effectiveSystemPrompt = effectiveSystemPrompt ? `${effectiveSystemPrompt}\n\n${memoryInjection}` : memoryInjection;
|
|
381
409
|
effectiveSystemPrompt = injectOutputPathSystemPrompt(effectiveSystemPrompt, outputPath, agent);
|
|
382
|
-
const
|
|
383
|
-
effectiveSystemPrompt = appendTurnBudgetSystemPrompt(effectiveSystemPrompt, turnBudget);
|
|
384
|
-
const candidates = candidateList(input.agent, agent, effectiveCwd);
|
|
410
|
+
const candidates = candidateList(input.agent, agent, discovery.all);
|
|
385
411
|
const shadowedCandidates = candidates.filter((candidate) => !candidate.selected);
|
|
386
412
|
const definitionDigest = agentDefinitionDigest(agent);
|
|
387
413
|
const contractBase: Omit<SubagentLaunchContract, "digest"> = {
|
|
@@ -404,6 +430,7 @@ export async function resolveSubagentLaunchContract(input: SubagentLaunchContrac
|
|
|
404
430
|
...(thinkingCeiling ? { thinkingCeiling } : {}),
|
|
405
431
|
systemPromptMode: agent.systemPromptMode,
|
|
406
432
|
inheritProjectContext: agent.inheritProjectContext,
|
|
433
|
+
inheritGlobalContext: agent.inheritGlobalContext,
|
|
407
434
|
inheritSkills: agent.inheritSkills,
|
|
408
435
|
skills: {
|
|
409
436
|
requested: requestedSkills,
|
|
@@ -413,6 +440,7 @@ export async function resolveSubagentLaunchContract(input: SubagentLaunchContrac
|
|
|
413
440
|
tools: {
|
|
414
441
|
requestedBuiltin: toolPlan.requestedBuiltinTools,
|
|
415
442
|
declaredBuiltin: toolPlan.declaredBuiltinTools,
|
|
443
|
+
...(toolPlan.excludeTools.length > 0 ? { excludeTools: toolPlan.excludeTools } : {}),
|
|
416
444
|
effectiveAllowlist: toolPlan.effectiveToolAllowlist,
|
|
417
445
|
explicitAllowlist: toolPlan.explicitToolAllowlist,
|
|
418
446
|
requiredChildTools: toolPlan.requiredChildTools,
|
|
@@ -459,9 +487,11 @@ export async function resolveSubagentLaunchContract(input: SubagentLaunchContrac
|
|
|
459
487
|
systemPrompt: effectiveSystemPrompt,
|
|
460
488
|
systemPromptMode: agent.systemPromptMode,
|
|
461
489
|
inheritProjectContext: agent.inheritProjectContext,
|
|
490
|
+
inheritGlobalContext: agent.inheritGlobalContext,
|
|
462
491
|
inheritSkills: agent.inheritSkills,
|
|
463
492
|
skills: requestedSkills,
|
|
464
493
|
tools: toolPlan.effectiveToolAllowlist,
|
|
494
|
+
...(toolPlan.excludeTools.length > 0 ? { excludeTools: toolPlan.excludeTools } : {}),
|
|
465
495
|
extensions: toolPlan.extensionArgs,
|
|
466
496
|
mcpDirectTools: toolPlan.effectiveMcpTools,
|
|
467
497
|
...(outputPath ? { outputPath } : {}),
|
package/src/api/shared-types.ts
CHANGED
|
@@ -5,6 +5,8 @@ export {
|
|
|
5
5
|
type AcceptanceInput,
|
|
6
6
|
type AcceptanceLedger,
|
|
7
7
|
type AcceptanceLevel,
|
|
8
|
+
type AgentCapabilitiesSnapshot,
|
|
9
|
+
type AgentCapabilityRow,
|
|
8
10
|
type AsyncStartedEvent,
|
|
9
11
|
type ControlEvent,
|
|
10
12
|
type Details,
|
|
@@ -18,4 +20,8 @@ export {
|
|
|
18
20
|
type SubagentResultStatus,
|
|
19
21
|
type SubagentRunMode,
|
|
20
22
|
type Usage,
|
|
23
|
+
type ManagedWorktreeProvider,
|
|
24
|
+
type WorktreeNaming,
|
|
25
|
+
type WorktreeProvider,
|
|
26
|
+
type WorkflowResourceProvenanceV1,
|
|
21
27
|
} from "../shared/types.ts";
|
package/src/extension/config.ts
CHANGED
|
@@ -6,7 +6,10 @@ import { FLEET_KEYBINDING_ACTIONS, type ArtifactDirPreference, type ExtensionCon
|
|
|
6
6
|
import { validateMissionStoreConfig } from "../missions/store.ts";
|
|
7
7
|
import { validateAuthorityPolicy } from "../policy/authority.ts";
|
|
8
8
|
import { getAgentDir } from "../shared/utils.ts";
|
|
9
|
+
import { DEFAULT_MODEL_EXCLUSION_TTL_MS, MAX_MODEL_EXCLUSION_TTL_MS, setDefaultTTL } from "../runs/shared/model-exclusions.ts";
|
|
9
10
|
import { validatePermissionConfig } from "../runs/shared/permissions.ts";
|
|
11
|
+
import { MAX_ABANDONED_SLOT_RELEASE_AFTER_MS, MIN_ABANDONED_SLOT_RELEASE_AFTER_MS } from "../runs/background/active-async-capacity.ts";
|
|
12
|
+
import { normalizeWorktreeBranchPrefix } from "../runs/shared/worktree.ts";
|
|
10
13
|
|
|
11
14
|
const ARTIFACT_DIR_PREFERENCES = new Set<ArtifactDirPreference>(["project", "session", "temp"]);
|
|
12
15
|
const FLEET_KEYBINDING_ACTION_SET = new Set<string>(FLEET_KEYBINDING_ACTIONS);
|
|
@@ -16,6 +19,23 @@ const BASE_KEY_IDS = new Set([
|
|
|
16
19
|
...Object.values(Key).flatMap((value) => typeof value === "string" ? [value.toLowerCase()] : []),
|
|
17
20
|
]);
|
|
18
21
|
|
|
22
|
+
class PrunedForkConfigError extends Error {}
|
|
23
|
+
|
|
24
|
+
function validateForkContextConfig(value: unknown): void {
|
|
25
|
+
if (value === undefined) return;
|
|
26
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error("config.forkContext must be a JSON object");
|
|
27
|
+
const config = value as Record<string, unknown>;
|
|
28
|
+
if (config.mode !== undefined && config.mode !== "full" && config.mode !== "pruned") {
|
|
29
|
+
throw new Error('config.forkContext.mode must be "full" or "pruned"');
|
|
30
|
+
}
|
|
31
|
+
if (config.model !== undefined && (typeof config.model !== "string" || !config.model.trim())) {
|
|
32
|
+
throw new PrunedForkConfigError("config.forkContext.model must be a non-empty string");
|
|
33
|
+
}
|
|
34
|
+
if (config.mode === "pruned" && config.model === undefined) {
|
|
35
|
+
throw new PrunedForkConfigError('config.forkContext.model is required when config.forkContext.mode is "pruned"');
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
19
39
|
function isValidKeyId(value: string): boolean {
|
|
20
40
|
if (value !== value.trim()) return false;
|
|
21
41
|
const parts = value.toLowerCase().split("+");
|
|
@@ -62,6 +82,31 @@ function validateArtifactConfig(value: unknown): void {
|
|
|
62
82
|
}
|
|
63
83
|
}
|
|
64
84
|
|
|
85
|
+
function validateCapacityConfig(value: unknown): void {
|
|
86
|
+
if (value === undefined) return;
|
|
87
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error("config.capacity must be a JSON object");
|
|
88
|
+
const abandonedSlotReleaseAfterMs = (value as Record<string, unknown>).abandonedSlotReleaseAfterMs;
|
|
89
|
+
if (abandonedSlotReleaseAfterMs !== undefined
|
|
90
|
+
&& abandonedSlotReleaseAfterMs !== false
|
|
91
|
+
&& (typeof abandonedSlotReleaseAfterMs !== "number"
|
|
92
|
+
|| !Number.isInteger(abandonedSlotReleaseAfterMs)
|
|
93
|
+
|| abandonedSlotReleaseAfterMs < MIN_ABANDONED_SLOT_RELEASE_AFTER_MS
|
|
94
|
+
|| abandonedSlotReleaseAfterMs > MAX_ABANDONED_SLOT_RELEASE_AFTER_MS)) {
|
|
95
|
+
throw new Error(`config.capacity.abandonedSlotReleaseAfterMs must be false or an integer from ${MIN_ABANDONED_SLOT_RELEASE_AFTER_MS} to ${MAX_ABANDONED_SLOT_RELEASE_AFTER_MS}`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** Validate the user-controlled TTL policy before it reaches the exclusion store. */
|
|
100
|
+
// TEST:test/unit/pi-coding-agent-dir.test.ts[loads and applies model exclusion TTL config]
|
|
101
|
+
function validateModelExclusionsConfig(value: unknown): void {
|
|
102
|
+
if (value === undefined) return;
|
|
103
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error("config.modelExclusions must be a JSON object");
|
|
104
|
+
const defaultTtlMs = (value as Record<string, unknown>).defaultTtlMs;
|
|
105
|
+
if (defaultTtlMs !== undefined && (typeof defaultTtlMs !== "number" || !Number.isFinite(defaultTtlMs) || defaultTtlMs <= 0 || defaultTtlMs > MAX_MODEL_EXCLUSION_TTL_MS)) {
|
|
106
|
+
throw new Error(`config.modelExclusions.defaultTtlMs must be a finite positive number no greater than ${MAX_MODEL_EXCLUSION_TTL_MS}`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
65
110
|
function validateOrcaProgressTabsConfig(value: unknown): void {
|
|
66
111
|
if (value === undefined) return;
|
|
67
112
|
if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error("config.orcaProgressTabs must be a JSON object");
|
|
@@ -94,9 +139,20 @@ function validateMainWindowRendererConfig(value: unknown): void {
|
|
|
94
139
|
}
|
|
95
140
|
|
|
96
141
|
function validateConfig(config: Record<string, unknown>): void {
|
|
142
|
+
if (config.worktree !== undefined && typeof config.worktree !== "boolean") {
|
|
143
|
+
throw new Error("config.worktree must be a boolean");
|
|
144
|
+
}
|
|
145
|
+
if (config.worktreeProvider !== undefined && config.worktreeProvider !== "auto" && config.worktreeProvider !== "native" && config.worktreeProvider !== "worktrunk") {
|
|
146
|
+
throw new Error('config.worktreeProvider must be "auto", "native", or "worktrunk"');
|
|
147
|
+
}
|
|
148
|
+
if (config.worktreeBranchPrefix !== undefined) {
|
|
149
|
+
if (typeof config.worktreeBranchPrefix !== "string") throw new Error("config.worktreeBranchPrefix must be a string");
|
|
150
|
+
normalizeWorktreeBranchPrefix(config.worktreeBranchPrefix);
|
|
151
|
+
}
|
|
97
152
|
if (config.defaultSubagentContext !== undefined && config.defaultSubagentContext !== "fresh" && config.defaultSubagentContext !== "fork") {
|
|
98
153
|
throw new Error('config.defaultSubagentContext must be "fresh" or "fork"');
|
|
99
154
|
}
|
|
155
|
+
validateForkContextConfig(config.forkContext);
|
|
100
156
|
if (config.foregroundDetachShortcut !== undefined
|
|
101
157
|
&& (typeof config.foregroundDetachShortcut !== "string" || !isValidKeyId(config.foregroundDetachShortcut))) {
|
|
102
158
|
throw new Error("config.foregroundDetachShortcut must be a valid keybinding string such as \"ctrl+b\"");
|
|
@@ -119,6 +175,8 @@ function validateConfig(config: Record<string, unknown>): void {
|
|
|
119
175
|
validateScheduledRunsConfig(config.scheduledRuns);
|
|
120
176
|
validateFleetKeybindingsConfig(config.fleetKeybindings);
|
|
121
177
|
validateArtifactConfig(config.artifactConfig);
|
|
178
|
+
validateCapacityConfig(config.capacity);
|
|
179
|
+
validateModelExclusionsConfig(config.modelExclusions);
|
|
122
180
|
validateMainWindowRendererConfig(config.mainWindowRenderer);
|
|
123
181
|
validateOrcaProgressTabsConfig(config.orcaProgressTabs);
|
|
124
182
|
}
|
|
@@ -150,6 +208,28 @@ export function updateConfig(updater: (config: ExtensionConfig) => ExtensionConf
|
|
|
150
208
|
return next;
|
|
151
209
|
}
|
|
152
210
|
|
|
211
|
+
/**
|
|
212
|
+
* Resolve the default TTL that the process-wide exclusion store should use.
|
|
213
|
+
*
|
|
214
|
+
* @param config Extension configuration after validation.
|
|
215
|
+
* @returns The configured TTL in milliseconds, or the built-in 24-hour default.
|
|
216
|
+
*/
|
|
217
|
+
// TEST:test/unit/pi-coding-agent-dir.test.ts[loads and applies model exclusion TTL config]
|
|
218
|
+
export function resolveModelExclusionTTL(config: Pick<ExtensionConfig, "modelExclusions">): number {
|
|
219
|
+
return config.modelExclusions?.defaultTtlMs ?? DEFAULT_MODEL_EXCLUSION_TTL_MS;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Apply the configured exclusion policy to the process-wide model store.
|
|
224
|
+
*
|
|
225
|
+
* @param config Extension configuration after validation.
|
|
226
|
+
* @returns Nothing.
|
|
227
|
+
*/
|
|
228
|
+
// TEST:test/unit/pi-coding-agent-dir.test.ts[loads and applies model exclusion TTL config]
|
|
229
|
+
export function applyModelExclusionsConfig(config: Pick<ExtensionConfig, "modelExclusions">): void {
|
|
230
|
+
setDefaultTTL(resolveModelExclusionTTL(config), { shortenExisting: config.modelExclusions?.defaultTtlMs !== undefined });
|
|
231
|
+
}
|
|
232
|
+
|
|
153
233
|
export function resolveAsyncByDefault(config: Pick<ExtensionConfig, "asyncByDefault">): boolean {
|
|
154
234
|
return config.asyncByDefault !== false;
|
|
155
235
|
}
|
|
@@ -159,6 +239,16 @@ export function loadConfig(): ExtensionConfig {
|
|
|
159
239
|
try {
|
|
160
240
|
return readConfigForUpdate(configPath);
|
|
161
241
|
} catch (error) {
|
|
242
|
+
if (error instanceof PrunedForkConfigError) throw error;
|
|
243
|
+
// An explicitly requested worktree provider/prefix must not be silently
|
|
244
|
+
// discarded and replaced by the built-in defaults after validation fails.
|
|
245
|
+
try {
|
|
246
|
+
const raw = JSON.parse(fs.readFileSync(configPath, "utf-8")) as unknown;
|
|
247
|
+
if (raw && typeof raw === "object" && !Array.isArray(raw)
|
|
248
|
+
&& (Object.hasOwn(raw, "worktreeProvider") || Object.hasOwn(raw, "worktreeBranchPrefix"))) throw error;
|
|
249
|
+
} catch (readError) {
|
|
250
|
+
if (readError === error) throw error;
|
|
251
|
+
}
|
|
162
252
|
console.error(`Failed to load subagent config from '${configPath}':`, error);
|
|
163
253
|
}
|
|
164
254
|
return {};
|
package/src/extension/doctor.ts
CHANGED
|
@@ -5,8 +5,8 @@ import { mergeAgentsForScope } from "../agents/agent-selection.ts";
|
|
|
5
5
|
import { resolveInjectableAgents } from "./context-injection.ts";
|
|
6
6
|
import { isAsyncAvailable } from "../runs/background/async-execution.ts";
|
|
7
7
|
import { formatSpawnBudgetSummary, getSpawnBudgetSnapshot } from "../runs/shared/spawn-budget.ts";
|
|
8
|
-
import { getActiveAsyncCapacitySnapshot, resolveMaxActiveAsyncRunsPerSession } from "../runs/background/active-async-capacity.ts";
|
|
9
|
-
|
|
8
|
+
import { getActiveAsyncCapacitySnapshot, resolveAbandonedSlotReleaseAfterMs, resolveMaxActiveAsyncRunsPerSession } from "../runs/background/active-async-capacity.ts";
|
|
9
|
+
|
|
10
10
|
import { diagnoseIntercomBridge, type IntercomBridgeDiagnostic } from "../intercom/intercom-bridge.ts";
|
|
11
11
|
import { discoverAvailableSkills, type SkillSource } from "../agents/skills.ts";
|
|
12
12
|
import {
|
|
@@ -189,14 +189,6 @@ function formatSpawnBudgetSection(input: DoctorReportInput): string[] {
|
|
|
189
189
|
}
|
|
190
190
|
|
|
191
191
|
function formatRunFanoutSection(input: DoctorReportInput): string[] {
|
|
192
|
-
try {
|
|
193
|
-
const inherited = decodeRunFanoutBudgetDescriptor(process.env[RUN_FANOUT_BUDGET_ENV]);
|
|
194
|
-
if (inherited) {
|
|
195
|
-
return [`- usage: ${formatRunFanoutBudget(getRunFanoutBudgetSnapshot(inherited)).replace(/^Run fan-out: /, "")}`, `- root run: ${inherited.rootRunId}`, "- reset boundary: cumulative claims are never released; a new top-level run creates a new budget"];
|
|
196
|
-
}
|
|
197
|
-
} catch (error) {
|
|
198
|
-
return [`- inherited budget: invalid — ${errorText(error)}`];
|
|
199
|
-
}
|
|
200
192
|
const configured = resolveMaxSubagentSpawnsPerRun(input.config.maxSubagentSpawnsPerRun);
|
|
201
193
|
const source = normalizeMaxSubagentSpawnsPerRun(process.env.PI_SUBAGENT_MAX_SPAWNS_PER_RUN) !== undefined
|
|
202
194
|
? "environment"
|
|
@@ -208,13 +200,13 @@ function formatActiveAsyncCapacitySection(input: DoctorReportInput): string[] {
|
|
|
208
200
|
const limit = resolveMaxActiveAsyncRunsPerSession(input.config.maxActiveAsyncRunsPerSession);
|
|
209
201
|
const sessionId = input.currentSessionId ?? input.state.currentSessionId;
|
|
210
202
|
const snapshot = sessionId
|
|
211
|
-
? getActiveAsyncCapacitySnapshot(sessionId, limit, { liveWorkflowRunIds: new Set(input.state.workflowControllers?.keys() ?? []) })
|
|
203
|
+
? getActiveAsyncCapacitySnapshot(sessionId, limit, { liveWorkflowRunIds: new Set(input.state.workflowControllers?.keys() ?? []), abandonedSlotReleaseAfterMs: resolveAbandonedSlotReleaseAfterMs(input.config.capacity?.abandonedSlotReleaseAfterMs) })
|
|
212
204
|
: { used: 0, limit: limit ?? 0 };
|
|
213
205
|
input.state.activeAsyncCapacity = snapshot;
|
|
214
206
|
return [
|
|
215
207
|
`- usage: ${snapshot.used}/${snapshot.limit || "unlimited"} used`,
|
|
216
208
|
"- scope: top-level async runs in the current parent session; foreground and nested workflow children are not charged again",
|
|
217
|
-
"- release: terminal
|
|
209
|
+
"- release: terminal state plus matching observed process-terminal proof, or abandoned-timeout for failed runs with a dead runner PID and stale activity when enabled; false keeps unknown-proof slots",
|
|
218
210
|
];
|
|
219
211
|
}
|
|
220
212
|
|
|
@@ -225,7 +217,7 @@ function formatPermissionSystemSection(): string[] {
|
|
|
225
217
|
if (trimmed) {
|
|
226
218
|
lines.push(`- parent session: set (${trimmed})`);
|
|
227
219
|
} else {
|
|
228
|
-
lines.push("- parent session: not set — ask forwarding from
|
|
220
|
+
lines.push("- parent session: not set — ask forwarding from background children will not reach a parent UI");
|
|
229
221
|
}
|
|
230
222
|
const isChild = process.env["PI_SUBAGENT_CHILD"] === "1";
|
|
231
223
|
lines.push(`- subagent process: ${isChild ? "yes (PI_SUBAGENT_CHILD=1)" : "no"}`);
|
|
@@ -6,8 +6,8 @@ import { discoverAgents } from "../agents/agents.ts";
|
|
|
6
6
|
import { getArtifactsDir } from "../shared/artifacts.ts";
|
|
7
7
|
import { createSubagentExecutor, type SubagentParamsLike } from "../runs/foreground/subagent-executor.ts";
|
|
8
8
|
import { resolveWaitToolConfig } from "../runs/background/wait-config.ts";
|
|
9
|
-
import {
|
|
10
|
-
import { readNestedControlRequests,
|
|
9
|
+
import type { ChildRuntimeConfig } from "../runs/shared/child-runtime-config.ts";
|
|
10
|
+
import { readNestedControlRequests, resolveInheritedNestedRoute, type NestedRoute, writeNestedControlResult } from "../runs/shared/nested-events.ts";
|
|
11
11
|
import { deliverSubagentIntercomMessageEvent } from "../intercom/result-intercom.ts";
|
|
12
12
|
import { resolveSubagentIntercomTarget } from "../intercom/intercom-bridge.ts";
|
|
13
13
|
import { createSubagentParamsSchema } from "./schemas.ts";
|
|
@@ -51,12 +51,8 @@ function createChildSafeState(): SubagentState {
|
|
|
51
51
|
};
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
function resolveNestedControlRoute(): NestedRoute | undefined {
|
|
55
|
-
|
|
56
|
-
return resolveNestedRouteFromEnv();
|
|
57
|
-
} catch {
|
|
58
|
-
return undefined;
|
|
59
|
-
}
|
|
54
|
+
function resolveNestedControlRoute(config: ChildRuntimeConfig): NestedRoute | undefined {
|
|
55
|
+
return config.nestedRoute ? resolveInheritedNestedRoute(config.nestedRoute) : undefined;
|
|
60
56
|
}
|
|
61
57
|
|
|
62
58
|
function nestedControlRouteKey(route: NestedRoute): string {
|
|
@@ -145,8 +141,9 @@ function startNestedControlInboxListener(pi: ExtensionAPI, state: SubagentState,
|
|
|
145
141
|
return () => clearInterval(timer);
|
|
146
142
|
}
|
|
147
143
|
|
|
148
|
-
|
|
149
|
-
|
|
144
|
+
/** Register the child-side `subagent` tool for fanout-authorized children. */
|
|
145
|
+
export default function registerFanoutChildSubagentExtension(pi: ExtensionAPI, childConfig: ChildRuntimeConfig): void {
|
|
146
|
+
if (!childConfig.fanoutChild) return;
|
|
150
147
|
|
|
151
148
|
const globalStore = globalThis as Record<string, unknown>;
|
|
152
149
|
const registeredKey = "__piSubagentFanoutChildRegisteredApis";
|
|
@@ -158,18 +155,21 @@ export default function registerFanoutChildSubagentExtension(pi: ExtensionAPI):
|
|
|
158
155
|
registeredApis.add(pi);
|
|
159
156
|
|
|
160
157
|
const config = loadConfig();
|
|
158
|
+
const waitToolConfig = resolveWaitToolConfig(config.waitTool);
|
|
161
159
|
const state = createChildSafeState();
|
|
162
160
|
const executor = createSubagentExecutor({
|
|
163
161
|
pi,
|
|
164
162
|
state,
|
|
165
163
|
config,
|
|
166
164
|
asyncByDefault: resolveAsyncByDefault(config),
|
|
167
|
-
waitToolEnabled:
|
|
165
|
+
waitToolEnabled: waitToolConfig.enabled,
|
|
166
|
+
waitToolDefaultTimeoutMs: waitToolConfig.defaultTimeoutMs,
|
|
168
167
|
tempArtifactsDir: getArtifactsDir(null),
|
|
169
168
|
getSubagentSessionRoot,
|
|
170
169
|
expandTilde,
|
|
171
170
|
discoverAgents,
|
|
172
171
|
allowMutatingManagementActions: false,
|
|
172
|
+
childRuntime: childConfig,
|
|
173
173
|
});
|
|
174
174
|
|
|
175
175
|
const params = createSubagentParamsSchema();
|
|
@@ -178,8 +178,8 @@ export default function registerFanoutChildSubagentExtension(pi: ExtensionAPI):
|
|
|
178
178
|
label: "Subagent",
|
|
179
179
|
description: [
|
|
180
180
|
"Delegate to subagents from child-safe fanout mode.",
|
|
181
|
-
"Allowed management/control actions: list, get, status, interrupt, resume, steer, doctor.",
|
|
182
|
-
"Mutating management actions (create, update, delete, eject, disable, enable, reset, grant-spawn-budget) are blocked in this mode.",
|
|
181
|
+
"Allowed management/control actions: list, get, status, lane.status, interrupt, resume, steer, doctor.",
|
|
182
|
+
"Mutating management actions (create, update, delete, eject, disable, enable, reset, grant-spawn-budget, lane.recordMerge, lane.recordSupersession) are blocked in this mode.",
|
|
183
183
|
].join("\n"),
|
|
184
184
|
parameters: params,
|
|
185
185
|
async execute(id, params, signal, onUpdate, ctx) {
|
|
@@ -188,7 +188,7 @@ export default function registerFanoutChildSubagentExtension(pi: ExtensionAPI):
|
|
|
188
188
|
};
|
|
189
189
|
|
|
190
190
|
pi.registerTool(tool);
|
|
191
|
-
const route = resolveNestedControlRoute();
|
|
191
|
+
const route = resolveNestedControlRoute(childConfig);
|
|
192
192
|
if (!route) return;
|
|
193
193
|
const listenerCleanupKey = "__piSubagentFanoutChildNestedControlInboxCleanups";
|
|
194
194
|
const listenerCleanups = globalStore[listenerCleanupKey] instanceof Map
|