@xzzpig/pi-subagents 0.16.0 → 0.19.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 +233 -1
- package/README.md +5 -3
- package/agents/claude-code-writer.md +1 -0
- package/agents/codex-exec-writer.md +1 -0
- package/agents/cursor-agent-writer.md +1 -0
- package/agents/reviewer.md +3 -2
- package/agents/worker.md +3 -2
- package/docs/agents.md +34 -21
- package/docs/configuration.md +82 -7
- package/docs/extension-api.md +75 -8
- package/docs/missions.md +13 -13
- package/docs/models.md +7 -5
- package/docs/observability.md +23 -13
- package/docs/standalone-background.md +5 -5
- package/docs/tool-reference.md +98 -100
- package/docs/watchdog.md +2 -0
- package/docs/workflows.md +214 -162
- package/inspector-runner.mjs +1 -1
- package/node_modules/@xzzpig/pi-components/package.json +4 -4
- package/package.json +15 -9
- package/prompts/council.md +6 -3
- package/prompts/review-loop.md +1 -1
- package/runner-peer-loader.mjs +4 -7
- package/runner-peer-preload.mjs +5 -7
- package/skills/council-mode/SKILL.md +1 -1
- package/skills/pi-subagents/SKILL.md +13 -5
- package/skills/pi-subagents/references/constraints-and-recipes.md +8 -5
- package/skills/pi-subagents/references/execution-controls.md +72 -69
- package/skills/pi-subagents/references/management-authoring-rpc.md +4 -4
- package/skills/pi-subagents/references/multi-lane-orchestration.md +9 -1
- package/skills/pi-subagents/references/prompting-and-roles.md +52 -54
- package/src/agents/advertised-agent-prompt.ts +21 -41
- package/src/agents/agent-eject.ts +3 -3
- package/src/agents/agent-management.ts +63 -54
- package/src/agents/agent-memory.ts +90 -3
- package/src/agents/agent-serializer.ts +4 -4
- package/src/agents/agents.ts +132 -51
- package/src/agents/global-npm-root.ts +58 -0
- package/src/agents/proactive-skills.ts +4 -1
- package/src/agents/runtime-agent-registry.ts +14 -11
- package/src/agents/skills.ts +42 -9
- package/src/api/delegation.ts +15 -0
- package/src/api/inspectors.ts +27 -0
- package/src/api/preflight.ts +7 -2
- package/src/extension/config.ts +12 -4
- package/src/extension/control-notices.ts +3 -0
- package/src/extension/doctor.ts +10 -4
- package/src/extension/fanout-child.ts +20 -3
- package/src/extension/herdr-pi-bridge.ts +2 -0
- package/src/extension/index.ts +168 -206
- package/src/extension/public-execution.ts +69 -35
- package/src/extension/reply-workflow-script.ts +58 -0
- package/src/extension/rpc.ts +39 -11
- package/src/extension/schemas.ts +47 -138
- package/src/extension/subagent-guide.ts +12 -4
- package/src/extension/tool-activation.ts +146 -0
- package/src/extension/tool-description.ts +62 -27
- package/src/extension/upgrade-notice.ts +40 -0
- package/src/inspectors/ghostty/plugin.ts +13 -1
- package/src/inspectors/plugins.ts +70 -3
- package/src/integrations/herdr-status.ts +19 -3
- package/src/intercom/intercom-bridge.ts +2 -0
- package/src/intercom/native-supervisor-channel.ts +26 -16
- package/src/intercom/result-intercom.ts +4 -0
- package/src/runs/background/active-async-capacity.ts +3 -25
- package/src/runs/background/async-execution.ts +60 -95
- package/src/runs/background/async-job-tracker.ts +91 -56
- package/src/runs/background/async-resume.ts +16 -8
- package/src/runs/background/async-retention.ts +46 -16
- package/src/runs/background/async-status.ts +2 -0
- package/src/runs/background/await-async-run.ts +76 -0
- package/src/runs/background/binary-bootstrap.ts +34 -6
- package/src/runs/background/chain-root-attachment.ts +4 -4
- package/src/runs/background/control-channel.ts +18 -2
- package/src/runs/background/fleet-view.ts +51 -7
- package/src/runs/background/notify.ts +98 -7
- package/src/runs/background/pid-namespace.ts +18 -0
- package/src/runs/background/process-terminal-candidate.ts +98 -0
- package/src/runs/background/process-terminal.ts +17 -96
- package/src/runs/background/result-watcher.ts +1 -1
- package/src/runs/background/retained-children.ts +3 -2
- package/src/runs/background/run-child-session.ts +20 -6
- package/src/runs/background/run-id-resolver.ts +10 -5
- package/src/runs/background/run-status.ts +16 -4
- package/src/runs/background/runner-aliases.ts +54 -16
- package/src/runs/background/runner-child-launch.ts +4 -2
- package/src/runs/background/runner-startup-failure.ts +56 -0
- package/src/runs/background/scheduled-runs.ts +5 -5
- package/src/runs/background/stale-run-reconciler.ts +19 -3
- package/src/runs/background/subagent-runner-bootstrap.ts +276 -0
- package/src/runs/background/subagent-runner.ts +111 -288
- package/src/runs/background/wait-tool.ts +2 -0
- package/src/runs/background/workflow-terminal-proof.ts +68 -0
- package/src/runs/foreground/async-stop-action.ts +17 -3
- package/src/runs/foreground/execution.ts +111 -139
- package/src/runs/foreground/prompt-audit.ts +3 -9
- package/src/runs/foreground/subagent-executor.ts +715 -258
- package/src/runs/shared/acceptance.ts +167 -68
- package/src/runs/shared/async-status-projection.ts +5 -0
- package/src/runs/shared/capability-ceiling.ts +4 -1
- package/src/runs/shared/child-hooks.ts +1 -16
- package/src/runs/shared/child-launch.ts +37 -16
- package/src/runs/shared/child-runtime-config.ts +3 -0
- package/src/runs/shared/child-session.ts +144 -8
- package/src/runs/shared/child-tool-plan.ts +38 -116
- package/src/runs/shared/dynamic-fanout.ts +1 -1
- package/src/runs/shared/external-cli-runner.ts +3 -1
- package/src/runs/shared/external-job-bridge.ts +54 -0
- package/src/runs/shared/git-environment.ts +29 -0
- package/src/runs/shared/mcp-config-sources.ts +5 -1
- package/src/runs/shared/mcp-direct-tool-allowlist.ts +104 -12
- package/src/runs/shared/mcp-direct-tool-grant.ts +22 -6
- package/src/runs/shared/model-resolution.ts +35 -10
- package/src/runs/shared/model-scope.ts +28 -9
- package/src/runs/shared/nested-events.ts +12 -0
- package/src/runs/shared/orca-progress-tabs.ts +3 -2
- package/src/runs/shared/parallel-utils.ts +4 -1
- package/src/runs/shared/pi-spawn.ts +1 -3
- package/src/runs/shared/single-output.ts +11 -2
- package/src/runs/shared/structured-output.ts +227 -7
- package/src/runs/shared/subagent-control.ts +2 -16
- package/src/runs/shared/subagent-prompt-runtime.ts +29 -5
- package/src/runs/shared/tool-availability.ts +2 -2
- package/src/runs/shared/tool-budget.ts +21 -0
- package/src/runs/shared/usage-reconciliation.ts +73 -0
- package/src/runs/shared/worktree.ts +36 -9
- package/src/shared/child-session-name.ts +4 -2
- package/src/shared/disabled-features.ts +123 -0
- package/src/shared/extension-context.ts +13 -0
- package/src/shared/fork-context.ts +11 -4
- package/src/shared/launch-contract.ts +1 -1
- package/src/shared/model-info.ts +9 -0
- package/src/shared/pruned-fork.ts +69 -56
- package/src/shared/settings.ts +1 -1
- package/src/shared/types.ts +73 -16
- package/src/slash/delegation-adapters.ts +25 -1
- package/src/slash/prompt-template-bridge.ts +18 -3
- package/src/slash/prompt-workflows.ts +12 -1
- package/src/slash/slash-commands.ts +17 -246
- package/src/slash/subagent-cost.ts +313 -0
- package/src/slash/subagents-admin.ts +4 -5
- package/src/tui/fleet-status.ts +38 -8
- package/src/tui/fleet.ts +21 -6
- package/src/tui/render.ts +166 -71
- package/src/tui/running-tone.ts +28 -0
- package/src/watchdog/diff-tool.ts +47 -12
- package/src/watchdog/permission-arbiter.ts +13 -15
- package/src/watchdog/register-child.ts +13 -5
- package/src/watchdog/register-main.ts +3 -3
- package/src/watchdog/review.ts +16 -16
- package/src/watchdog/runtime.ts +2 -1
- package/src/watchdog/turn-delta.ts +12 -6
- package/src/workflows/chat-progress.ts +2 -2
- package/src/workflows/scripted-workflow.ts +225 -59
- package/src/workflows/structured-workflow-scripts.ts +177 -0
- package/src/workflows/workflow-checklist.ts +6 -0
- package/src/workflows/workflow-child-summary.ts +4 -2
- package/src/workflows/workflow-receipt.ts +8 -2
- package/src/workflows/workflow-resources.ts +37 -12
- package/src/workflows/workflow-reuse.ts +120 -0
- package/src/workflows/workflow-revival.ts +123 -0
- package/src/workflows/workflow-settlement.ts +4 -1
- package/src/runs/shared/completion-evidence.ts +0 -89
- package/src/runs/shared/completion-guard.ts +0 -255
- package/src/runs/shared/llm-intent-arbiter.ts +0 -321
- package/src/runs/shared/task-intent.ts +0 -244
package/src/extension/index.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* - Sync (default): Streams output, renders markdown, tracks usage
|
|
6
6
|
* - Async: Background execution, emits events when done
|
|
7
7
|
*
|
|
8
|
-
* Public execution mode: workflow (
|
|
8
|
+
* Public execution mode: workflow (workflow: true reply block, script path, or named resource)
|
|
9
9
|
* Toggle: async parameter (default: true; set asyncByDefault:false in config.json to opt out)
|
|
10
10
|
*
|
|
11
11
|
* Config file: ~/.pi/agent/extensions/subagent/config.json
|
|
@@ -19,25 +19,27 @@ import * as path from "node:path";
|
|
|
19
19
|
import type { AgentToolResult } from "@earendil-works/pi-agent-core";
|
|
20
20
|
import { keyText, type ExtensionAPI, type ExtensionContext, type ToolDefinition } from "@earendil-works/pi-coding-agent";
|
|
21
21
|
import { Box, Container, Spacer, Text, truncateToWidth, visibleWidth, wrapTextWithAnsi, type Component } from "@earendil-works/pi-tui";
|
|
22
|
-
import { clearAgentDiscoveryCache, discoverAgents, discoverAgentsAll, type AgentConfig, type AgentScope } from "../agents/agents.ts";
|
|
23
|
-
import {
|
|
22
|
+
import { clearAgentDiscoveryCache, discoverAgentSnapshot, discoverAgents, discoverAgentsAll, type AgentConfig, type AgentScope } from "../agents/agents.ts";
|
|
23
|
+
import { resolveGlobalNpmRoot } from "../agents/global-npm-root.ts";
|
|
24
|
+
import { buildAdvertisedAgentCatalog, buildAdvertisedAgentPrompt } from "../agents/advertised-agent-prompt.ts";
|
|
24
25
|
import { mergeAgentsForScope } from "../agents/agent-selection.ts";
|
|
25
|
-
import { clearRuntimeAgentsForPi } from "../agents/runtime-agent-registry.ts";
|
|
26
|
+
import { clearRuntimeAgentsForPi, listRuntimeAgentConfigs, mergeRuntimeAgents } from "../agents/runtime-agent-registry.ts";
|
|
26
27
|
import { discoverAgentsWithRuntime } from "../agents/runtime-discovery.ts";
|
|
27
28
|
import { registerRuntimeAgentEventListener } from "../agents/runtime-agent-events.ts";
|
|
28
29
|
import { ensureAccessibleDir } from "../shared/accessible-dir.ts";
|
|
29
30
|
import { cleanupAllArtifactDirs, cleanupOldArtifacts, getArtifactsDir } from "../shared/artifacts.ts";
|
|
30
31
|
import { resolveCurrentSessionId } from "../shared/session-identity.ts";
|
|
31
32
|
import { getAgentDir } from "../shared/utils.ts";
|
|
32
|
-
import { isStaleExtensionContextError, withCachedUiContext } from "../shared/extension-context.ts";
|
|
33
|
+
import { isStaleExtensionContextError, MODEL_ONLY_TOOL, withCachedUiContext } from "../shared/extension-context.ts";
|
|
33
34
|
import { currentCompletionOwnerId } from "../shared/completion-owner.ts";
|
|
34
35
|
import { cleanupOldChainDirs } from "../shared/settings.ts";
|
|
35
36
|
import { clearLegacyResultAnimationTimer, renderSubagentResult, renderSubagentSummary, setInlineWorkflowCoverage } from "../tui/render.ts";
|
|
36
|
-
import {
|
|
37
|
-
import { createBuiltinInspectorPlugins } from "../inspectors/plugins.ts";
|
|
37
|
+
import { getInspectorPlugins, registerInspectorEventListener } from "../inspectors/plugins.ts";
|
|
38
38
|
import { SubagentFleetStatus, resolveFleetViewPlacement } from "../tui/fleet-status.ts";
|
|
39
|
+
import { readMainThinkingLevel, setMainThinkingLevelSource } from "../tui/running-tone.ts";
|
|
39
40
|
import { createSubagentParamsSchema } from "./schemas.ts";
|
|
40
|
-
import {
|
|
41
|
+
import { resolveDisabledFeatureSurface } from "../shared/disabled-features.ts";
|
|
42
|
+
import type { SubagentParamsLike } from "../runs/foreground/subagent-executor.ts";
|
|
41
43
|
import { createAsyncJobTracker } from "../runs/background/async-job-tracker.ts";
|
|
42
44
|
import { getActiveAsyncCapacitySnapshot, resolveAbandonedSlotReleaseAfterMs, resolveMaxActiveAsyncRunsPerSession } from "../runs/background/active-async-capacity.ts";
|
|
43
45
|
import { cleanupResultIndexes, missionObserverResultCandidateFiles } from "../runs/background/result-files.ts";
|
|
@@ -65,6 +67,7 @@ import { registerSubagentRpcBridge } from "./rpc.ts";
|
|
|
65
67
|
import { clearSlashSnapshots, getSlashRenderableSnapshot, resolveSlashMessageDetails, restoreSlashFinalSnapshots, type SlashMessageDetails } from "../slash/slash-live-state.ts";
|
|
66
68
|
import { resolveWaitToolConfig } from "../runs/background/subagent-wait.ts";
|
|
67
69
|
import { registerWaitTool } from "../runs/background/wait-tool.ts";
|
|
70
|
+
import { registerSubagentToolActivation } from "./tool-activation.ts";
|
|
68
71
|
import { createWaitSubscriptionManager } from "../runs/background/wait-subscriptions.ts";
|
|
69
72
|
import { drainOutstandingWork } from "../runs/background/auto-drain.ts";
|
|
70
73
|
import registerSubagentNotify, { parseSubagentNotifyContent, type SubagentNotifyDetails } from "../runs/background/notify.ts";
|
|
@@ -77,7 +80,9 @@ import { loadConfig, resolveAsyncByDefault, resolveScheduledStoreRoot } from "./
|
|
|
77
80
|
import { applyInjectionBlock, renderInjectionBlock, resolveInjectableAgents } from "./context-injection.ts";
|
|
78
81
|
import { buildSubagentToolDescription, buildSubagentToolPromptMetadata } from "./tool-description.ts";
|
|
79
82
|
import { formatWorkflowPreflightSummary, normalizeWorkflowPreflight } from "../workflows/workflow-preflight.ts";
|
|
83
|
+
import { runtimeReplacedAbortReason } from "../workflows/workflow-reuse.ts";
|
|
80
84
|
import { finalizeToolResult } from "./tool-result.ts";
|
|
85
|
+
import { removedModelWorkflowFieldError } from "./public-execution.ts";
|
|
81
86
|
import { collectGoalContinuationNotices } from "../missions/goal-driver.ts";
|
|
82
87
|
import { restoreForegroundRunHistory } from "../runs/foreground/foreground-history.ts";
|
|
83
88
|
import { resolveMissionStoreLocation } from "../missions/store.ts";
|
|
@@ -104,12 +109,19 @@ import {
|
|
|
104
109
|
SUBAGENT_CONTROL_MESSAGE_TYPE,
|
|
105
110
|
type SubagentControlMessageDetails,
|
|
106
111
|
} from "./control-notices.ts";
|
|
112
|
+
import { showUpgradeNotice } from "./upgrade-notice.ts";
|
|
107
113
|
|
|
108
114
|
export { loadConfig, resolveAsyncByDefault } from "./config.ts";
|
|
109
115
|
|
|
110
116
|
const SLOW_RELOAD_PHASE_MS = 250;
|
|
117
|
+
// Long enough for Pi to finish starting; loading the executor blocks the event loop for tens of ms.
|
|
118
|
+
const MODULE_PRELOAD_DELAY_MS = 1_000;
|
|
111
119
|
const RUNTIME_REGISTRY_STORE_KEY = "__piSubagentRuntimeRegistry";
|
|
112
120
|
|
|
121
|
+
type SubagentExecutorModule = typeof import("../runs/foreground/subagent-executor.ts");
|
|
122
|
+
type SubagentExecutor = ReturnType<SubagentExecutorModule["createSubagentExecutor"]>;
|
|
123
|
+
type SubagentExecutorDeps = Parameters<SubagentExecutorModule["createSubagentExecutor"]>[0];
|
|
124
|
+
|
|
113
125
|
interface SubagentRuntimeEntry {
|
|
114
126
|
cleanup(): void;
|
|
115
127
|
sessionManager: object | null;
|
|
@@ -145,128 +157,6 @@ function logSlowPhase(label: string, startedAt: number): void {
|
|
|
145
157
|
if (elapsed >= SLOW_RELOAD_PHASE_MS) console.error(`Subagent reload phase '${label}' took ${elapsed}ms.`);
|
|
146
158
|
}
|
|
147
159
|
|
|
148
|
-
function workflowLaneKeys(script: string): string[] {
|
|
149
|
-
const keys: string[] = [];
|
|
150
|
-
const seen = new Set<string>();
|
|
151
|
-
const add = (key: string): void => {
|
|
152
|
-
if (!seen.has(key)) {
|
|
153
|
-
seen.add(key);
|
|
154
|
-
keys.push(key);
|
|
155
|
-
}
|
|
156
|
-
};
|
|
157
|
-
const isIdentifier = (char: string | undefined): boolean => char !== undefined && /[\w$]/.test(char);
|
|
158
|
-
const skipTrivia = (start: number): number => {
|
|
159
|
-
let index = start;
|
|
160
|
-
while (index < script.length) {
|
|
161
|
-
if (/\s/.test(script[index]!)) index += 1;
|
|
162
|
-
else if (script.startsWith("//", index)) {
|
|
163
|
-
const end = script.indexOf("\n", index + 2);
|
|
164
|
-
index = end === -1 ? script.length : end + 1;
|
|
165
|
-
} else if (script.startsWith("/*", index)) {
|
|
166
|
-
const end = script.indexOf("*/", index + 2);
|
|
167
|
-
index = end === -1 ? script.length : end + 2;
|
|
168
|
-
} else break;
|
|
169
|
-
}
|
|
170
|
-
return index;
|
|
171
|
-
};
|
|
172
|
-
const readLiteral = (start: number): { key?: string; end: number } | undefined => {
|
|
173
|
-
const quote = script[start];
|
|
174
|
-
if (quote !== "'" && quote !== '"' && quote !== "`") return undefined;
|
|
175
|
-
let index = start + 1;
|
|
176
|
-
let dynamicTemplate = false;
|
|
177
|
-
while (index < script.length) {
|
|
178
|
-
if (script[index] === "\\") {
|
|
179
|
-
index += 2;
|
|
180
|
-
continue;
|
|
181
|
-
}
|
|
182
|
-
if (quote === "`" && script.startsWith("${", index)) dynamicTemplate = true;
|
|
183
|
-
if (script[index] === quote) return { key: dynamicTemplate ? undefined : script.slice(start + 1, index), end: index + 1 };
|
|
184
|
-
if (quote !== "`" && /[\r\n]/.test(script[index]!)) return { end: index + 1 };
|
|
185
|
-
index += 1;
|
|
186
|
-
}
|
|
187
|
-
return { end: script.length };
|
|
188
|
-
};
|
|
189
|
-
|
|
190
|
-
const collectRunsAllKeys = (start: number): number => {
|
|
191
|
-
let index = skipTrivia(start);
|
|
192
|
-
if (script[index] !== "(") return start;
|
|
193
|
-
index = skipTrivia(index + 1);
|
|
194
|
-
if (script[index] !== "[") return start;
|
|
195
|
-
let arrayDepth = 1;
|
|
196
|
-
let objectDepth = 0;
|
|
197
|
-
let directChildObject = false;
|
|
198
|
-
let expectingElement = true;
|
|
199
|
-
for (index += 1; index < script.length; index += 1) {
|
|
200
|
-
index = skipTrivia(index);
|
|
201
|
-
const literal = readLiteral(index);
|
|
202
|
-
if (literal) {
|
|
203
|
-
index = literal.end - 1;
|
|
204
|
-
continue;
|
|
205
|
-
}
|
|
206
|
-
if (script[index] === "[") {
|
|
207
|
-
arrayDepth += 1;
|
|
208
|
-
expectingElement = false;
|
|
209
|
-
continue;
|
|
210
|
-
}
|
|
211
|
-
if (script[index] === "]") {
|
|
212
|
-
arrayDepth -= 1;
|
|
213
|
-
if (arrayDepth === 0) return index + 1;
|
|
214
|
-
continue;
|
|
215
|
-
}
|
|
216
|
-
if (script[index] === "{") {
|
|
217
|
-
objectDepth += 1;
|
|
218
|
-
if (objectDepth === 1) directChildObject = arrayDepth === 1 && expectingElement;
|
|
219
|
-
expectingElement = false;
|
|
220
|
-
continue;
|
|
221
|
-
}
|
|
222
|
-
if (script[index] === "}") {
|
|
223
|
-
objectDepth -= 1;
|
|
224
|
-
if (objectDepth === 0) directChildObject = false;
|
|
225
|
-
continue;
|
|
226
|
-
}
|
|
227
|
-
if (script[index] === "," && arrayDepth === 1 && objectDepth === 0) {
|
|
228
|
-
expectingElement = true;
|
|
229
|
-
continue;
|
|
230
|
-
}
|
|
231
|
-
if (directChildObject && objectDepth === 1 && !isIdentifier(script[index - 1]) && script.startsWith("key", index) && !isIdentifier(script[index + 3])) {
|
|
232
|
-
const colon = skipTrivia(index + 3);
|
|
233
|
-
const key = script[colon] === ":" ? readLiteral(skipTrivia(colon + 1)) : undefined;
|
|
234
|
-
if (key) {
|
|
235
|
-
const next = skipTrivia(key.end);
|
|
236
|
-
if (key.key !== undefined && (script[next] === "," || script[next] === "}")) add(key.key);
|
|
237
|
-
index = key.end - 1;
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
return index;
|
|
242
|
-
};
|
|
243
|
-
|
|
244
|
-
for (let index = 0; index < script.length;) {
|
|
245
|
-
index = skipTrivia(index);
|
|
246
|
-
const literal = readLiteral(index);
|
|
247
|
-
if (literal) {
|
|
248
|
-
index = literal.end;
|
|
249
|
-
continue;
|
|
250
|
-
}
|
|
251
|
-
if (!isIdentifier(script[index - 1]) && script.startsWith("runs.run", index) && !isIdentifier(script[index + 8])) {
|
|
252
|
-
const open = skipTrivia(index + 8);
|
|
253
|
-
const key = script[open] === "(" ? readLiteral(skipTrivia(open + 1)) : undefined;
|
|
254
|
-
if (key) {
|
|
255
|
-
const next = skipTrivia(key.end);
|
|
256
|
-
if (key.key !== undefined && (script[next] === "," || script[next] === ")")) add(key.key);
|
|
257
|
-
index = key.end;
|
|
258
|
-
continue;
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
if (!isIdentifier(script[index - 1]) && script.startsWith("runs.all", index) && !isIdentifier(script[index + 8])) {
|
|
262
|
-
index = collectRunsAllKeys(index + 8);
|
|
263
|
-
continue;
|
|
264
|
-
}
|
|
265
|
-
index += 1;
|
|
266
|
-
}
|
|
267
|
-
return keys;
|
|
268
|
-
}
|
|
269
|
-
|
|
270
160
|
function formatWorkflowPreflightCall(input: unknown): string {
|
|
271
161
|
if (input === undefined) return "";
|
|
272
162
|
try {
|
|
@@ -276,18 +166,6 @@ function formatWorkflowPreflightCall(input: unknown): string {
|
|
|
276
166
|
}
|
|
277
167
|
}
|
|
278
168
|
|
|
279
|
-
function formatWorkflowManifest(script: string, async: unknown, clarify: unknown, preflightInput?: unknown): string {
|
|
280
|
-
if (clarify === true) return "workflow script · rejected: clarify UI unsupported";
|
|
281
|
-
const keys = workflowLaneKeys(script);
|
|
282
|
-
// The workflow executor starts background work unless callers pass async:false.
|
|
283
|
-
const mode = async === false ? "foreground" : "background";
|
|
284
|
-
const preflight = formatWorkflowPreflightCall(preflightInput);
|
|
285
|
-
if (keys.length === 0) return `workflow script · ${mode}${preflight ? ` · ${preflight}` : ""}`;
|
|
286
|
-
const visibleKeys = keys.slice(0, 4).join(", ");
|
|
287
|
-
const remainder = keys.length > 4 ? `, +${keys.length - 4}` : "";
|
|
288
|
-
return `workflow · ${mode} · ${keys.length} lane${keys.length === 1 ? "" : "s"}: ${visibleKeys}${remainder}${preflight ? ` · ${preflight}` : ""}`;
|
|
289
|
-
}
|
|
290
|
-
|
|
291
169
|
/**
|
|
292
170
|
* Derive subagent session base directory from parent session file.
|
|
293
171
|
* If parent session is ~/.pi/agent/sessions/abc123.jsonl,
|
|
@@ -407,18 +285,31 @@ export function projectActiveHerdrRuns(state: SubagentState): HerdrStatusRun[] {
|
|
|
407
285
|
existing.push(...children);
|
|
408
286
|
foregroundChildrenByWorkflow.set(control.parentWorkflowRunId, existing);
|
|
409
287
|
}
|
|
288
|
+
|
|
289
|
+
// Keep each async child under its own ID: completion and attention events
|
|
290
|
+
// address that ID directly. The workflow row accounts only for foreground
|
|
291
|
+
// children; its own coordinator and step summaries are not leaf agents.
|
|
410
292
|
return [...state.asyncJobs.values()]
|
|
411
293
|
.filter((job) => active(job.status))
|
|
412
294
|
.map((job) => {
|
|
413
|
-
const children = job.mode === "workflow" ? foregroundChildrenByWorkflow.get(job.asyncId) : undefined;
|
|
414
295
|
const currentStep = job.steps?.find((step) => step.status === "running")
|
|
415
296
|
?? (job.currentStep !== undefined ? job.steps?.[job.currentStep] : undefined)
|
|
416
297
|
?? job.steps?.find((step) => step.status === "pending");
|
|
298
|
+
if (job.mode === "workflow") {
|
|
299
|
+
const children = foregroundChildrenByWorkflow.get(job.asyncId) ?? [];
|
|
300
|
+
return {
|
|
301
|
+
id: job.asyncId,
|
|
302
|
+
coordinator: true as const,
|
|
303
|
+
agents: children.map((child) => child.agent),
|
|
304
|
+
...(currentStep?.label ? { taskLabel: currentStep.label } : {}),
|
|
305
|
+
needsAttention: job.activityState === "needs_attention" || children.some((child) => child.needsAttention),
|
|
306
|
+
};
|
|
307
|
+
}
|
|
417
308
|
return {
|
|
418
309
|
id: job.asyncId,
|
|
419
|
-
agents:
|
|
310
|
+
agents: job.agents,
|
|
420
311
|
...(currentStep?.label ? { taskLabel: currentStep.label } : {}),
|
|
421
|
-
needsAttention: job.activityState === "needs_attention"
|
|
312
|
+
needsAttention: job.activityState === "needs_attention",
|
|
422
313
|
};
|
|
423
314
|
});
|
|
424
315
|
}
|
|
@@ -428,6 +319,7 @@ export default function registerSubagentExtension(pi: ExtensionAPI): void {
|
|
|
428
319
|
return;
|
|
429
320
|
}
|
|
430
321
|
const runtimeRegistry = getRuntimeRegistry();
|
|
322
|
+
setMainThinkingLevelSource(() => readMainThinkingLevel(() => pi.getThinkingLevel()));
|
|
431
323
|
|
|
432
324
|
DIRS.results = ensureAccessibleDir(DIRS.results);
|
|
433
325
|
DIRS.async = ensureAccessibleDir(DIRS.async);
|
|
@@ -490,7 +382,8 @@ export default function registerSubagentExtension(pi: ExtensionAPI): void {
|
|
|
490
382
|
};
|
|
491
383
|
|
|
492
384
|
const supervisorChannel = createNativeSupervisorChannel(pi, state, {
|
|
493
|
-
|
|
385
|
+
// Owner states are created only by scheduled execution, which loads the executor first.
|
|
386
|
+
getCurrentOwnerStates: () => executor?.getCurrentSupervisorOwnerStates() ?? [],
|
|
494
387
|
});
|
|
495
388
|
const waitSubscriptionManager = createWaitSubscriptionManager(pi, state);
|
|
496
389
|
const mainWatchdog = registerMainWatchdog(pi);
|
|
@@ -502,7 +395,8 @@ export default function registerSubagentExtension(pi: ExtensionAPI): void {
|
|
|
502
395
|
const ctx = withLastUiContext((current) => current);
|
|
503
396
|
if (!ctx) return;
|
|
504
397
|
try {
|
|
505
|
-
|
|
398
|
+
const { openSubagentFleet } = await import("../tui/fleet.ts");
|
|
399
|
+
await openSubagentFleet(ctx, state, { initialKey: itemKey, asyncDirRoot: DIRS.async, resultsDir: DIRS.results, fleetKeybindings: config.fleetKeybindings, inspectorPlugins: () => getInspectorPlugins(pi), events: pi.events });
|
|
506
400
|
} catch (error) {
|
|
507
401
|
if (isStaleExtensionContextError(error)) {
|
|
508
402
|
if (state.lastUiContext === ctx) state.lastUiContext = null;
|
|
@@ -512,44 +406,83 @@ export default function registerSubagentExtension(pi: ExtensionAPI): void {
|
|
|
512
406
|
}
|
|
513
407
|
}, { placement: fleetViewPlacement, onWorkflowCoverageChange: setInlineWorkflowCoverage })
|
|
514
408
|
: undefined;
|
|
515
|
-
let executorScheduled: ((id: string, params: SubagentParamsLike, signal: AbortSignal, ctx: ExtensionContext) => Promise<AgentToolResult<Details>>) | undefined;
|
|
516
409
|
let goalTurnId = 0;
|
|
517
|
-
let parentSessionEnvValue: string | null = null;
|
|
518
410
|
let releaseHostSessionLiveness = () => {};
|
|
519
411
|
const scheduledStoreRoot = config.scheduledRuns?.storeRoot === undefined ? undefined : resolveScheduledStoreRoot(config.scheduledRuns.storeRoot);
|
|
520
412
|
const scheduledRunManager = createScheduledRunManager({
|
|
521
413
|
config,
|
|
522
414
|
storeRoot: scheduledStoreRoot,
|
|
523
|
-
launch: (params, ctx, signal) => {
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
content: [{ type: "text", text: "Scheduled subagent launch is unavailable (executor not ready)." }],
|
|
527
|
-
isError: true,
|
|
528
|
-
details: { mode: "management" as const, results: [] },
|
|
529
|
-
});
|
|
530
|
-
}
|
|
531
|
-
return executorScheduled(randomUUID(), params, signal, ctx);
|
|
415
|
+
launch: async (params, ctx, signal) => {
|
|
416
|
+
await waitForAdvertisement();
|
|
417
|
+
return (await getExecutor()).executeScheduled(randomUUID(), params, signal, ctx);
|
|
532
418
|
},
|
|
533
419
|
resolveCapabilityCeiling: (sessionId) => resolveCurrentSubagentCapabilityCeiling(sessionId),
|
|
534
420
|
});
|
|
535
421
|
let refreshResultDelivery = () => {};
|
|
536
422
|
let advertisedAgents: AgentConfig[] = [];
|
|
537
423
|
let advertisedContext: Pick<ExtensionContext, "cwd" | "model"> | undefined;
|
|
424
|
+
let advertisementGeneration = 0;
|
|
425
|
+
let globalRoot: string | null = null;
|
|
426
|
+
let advertisementReady: Promise<void | { error: unknown }> = Promise.resolve();
|
|
427
|
+
let notifySessionChange = () => {};
|
|
428
|
+
let sessionChanged: Promise<void> = Promise.resolve();
|
|
429
|
+
const waitForAdvertisement = async () => {
|
|
430
|
+
let pending: typeof advertisementReady;
|
|
431
|
+
do {
|
|
432
|
+
pending = advertisementReady;
|
|
433
|
+
const result = await Promise.race([pending, sessionChanged]);
|
|
434
|
+
if (pending === advertisementReady && result) throw result.error;
|
|
435
|
+
} while (pending !== advertisementReady);
|
|
436
|
+
};
|
|
538
437
|
const refreshAdvertisedAgents = () => {
|
|
539
438
|
advertisedAgents = [];
|
|
540
439
|
if (!advertisedContext) return;
|
|
541
440
|
clearAgentDiscoveryCache();
|
|
542
|
-
advertisedAgents = discoverAgents(advertisedContext.cwd, "both", advertisedContext.model?.provider).agents
|
|
441
|
+
advertisedAgents = discoverAgents(advertisedContext.cwd, "both", advertisedContext.model?.provider, { globalNpmRoot: globalRoot }).agents
|
|
543
442
|
.filter((agent) => agent.advertise === true);
|
|
544
443
|
};
|
|
444
|
+
const beginAdvertisement = (ctx: ExtensionContext) => {
|
|
445
|
+
const generation = ++advertisementGeneration;
|
|
446
|
+
notifySessionChange();
|
|
447
|
+
sessionChanged = new Promise<void>((resolve) => { notifySessionChange = resolve; });
|
|
448
|
+
advertisedAgents = [];
|
|
449
|
+
advertisedContext = { cwd: ctx.cwd, model: ctx.model };
|
|
450
|
+
globalRoot = null;
|
|
451
|
+
advertisementReady = resolveGlobalNpmRoot().then((root) => {
|
|
452
|
+
if (generation !== advertisementGeneration) return;
|
|
453
|
+
globalRoot = root;
|
|
454
|
+
refreshAdvertisedAgents();
|
|
455
|
+
}).catch((error) => {
|
|
456
|
+
if (generation !== advertisementGeneration) return;
|
|
457
|
+
// Settle without an unhandled rejection if no turn follows session_start.
|
|
458
|
+
console.error("Failed to refresh advertised agents:", error);
|
|
459
|
+
return { error };
|
|
460
|
+
});
|
|
461
|
+
};
|
|
545
462
|
const hasResultDeliveryDemand = () => {
|
|
546
463
|
if ([...state.asyncJobs.values()].some((job) => job.status === "queued" || job.status === "running")) return true;
|
|
547
464
|
if (state.foregroundControls.size > 0) return true;
|
|
548
465
|
if (scheduledRunManager.observedCompletionRunIds().size > 0) return true;
|
|
549
466
|
return missionObserverResultCandidateFiles(DIRS.results).length > 0;
|
|
550
467
|
};
|
|
551
|
-
const discoverAgentsForRuntime = (cwd: string, scope: AgentScope, preferredModelProvider?: string) =>
|
|
552
|
-
|
|
468
|
+
const discoverAgentsForRuntime = (cwd: string, scope: AgentScope, preferredModelProvider?: string) => {
|
|
469
|
+
if (listRuntimeAgentConfigs(pi).length === 0) return discoverAgents(cwd, scope, preferredModelProvider, { globalNpmRoot: globalRoot });
|
|
470
|
+
const snapshot = discoverAgentSnapshot(cwd, scope, preferredModelProvider, { includeChains: false, globalNpmRoot: globalRoot });
|
|
471
|
+
const discovered = snapshot.effective;
|
|
472
|
+
const all = snapshot.all;
|
|
473
|
+
const configuredAgents: AgentConfig[] = [
|
|
474
|
+
...all.builtin,
|
|
475
|
+
...all.package,
|
|
476
|
+
...all.user,
|
|
477
|
+
...all.project,
|
|
478
|
+
];
|
|
479
|
+
const merged = mergeRuntimeAgents(pi, discovered, configuredAgents, { cwd, scope, preferredModelProvider });
|
|
480
|
+
if (discovered.maxThinking === undefined) return merged;
|
|
481
|
+
return {
|
|
482
|
+
...merged,
|
|
483
|
+
agents: merged.agents.map((agent) => agent.maxThinking === discovered.maxThinking ? agent : { ...agent, maxThinking: discovered.maxThinking }),
|
|
484
|
+
};
|
|
485
|
+
};
|
|
553
486
|
const { ensurePoller, refreshWidget, handleStarted, handleComplete, resetJobs, restoreActiveJobs, dispose: disposeAsyncJobTracker } = createAsyncJobTracker(pi, state, DIRS.async, {
|
|
554
487
|
widgetEnabled: asyncWidgetEnabled,
|
|
555
488
|
onJobTerminal: () => refreshResultDelivery(),
|
|
@@ -607,7 +540,7 @@ export default function registerSubagentExtension(pi: ExtensionAPI): void {
|
|
|
607
540
|
}
|
|
608
541
|
};
|
|
609
542
|
|
|
610
|
-
const executorDeps:
|
|
543
|
+
const executorDeps: SubagentExecutorDeps = {
|
|
611
544
|
pi,
|
|
612
545
|
state,
|
|
613
546
|
config,
|
|
@@ -620,6 +553,7 @@ export default function registerSubagentExtension(pi: ExtensionAPI): void {
|
|
|
620
553
|
getSubagentSessionRoot,
|
|
621
554
|
expandTilde,
|
|
622
555
|
discoverAgents: discoverAgentsForRuntime,
|
|
556
|
+
discoverAgentsAll: (cwd, provider) => discoverAgentsAll(cwd, provider, { globalNpmRoot: globalRoot }),
|
|
623
557
|
onAgentsChanged: () => {
|
|
624
558
|
try {
|
|
625
559
|
refreshAdvertisedAgents();
|
|
@@ -633,8 +567,31 @@ export default function registerSubagentExtension(pi: ExtensionAPI): void {
|
|
|
633
567
|
refreshResultDelivery: () => refreshResultDelivery(),
|
|
634
568
|
trackRetainedNestedRoute: undefined,
|
|
635
569
|
};
|
|
636
|
-
|
|
637
|
-
|
|
570
|
+
let executor: SubagentExecutor | undefined;
|
|
571
|
+
let executorPromise: Promise<SubagentExecutor> | undefined;
|
|
572
|
+
let executorModulePromise: Promise<SubagentExecutorModule> | undefined;
|
|
573
|
+
const loadExecutorModule = () => executorModulePromise ??= import("../runs/foreground/subagent-executor.ts");
|
|
574
|
+
const getExecutor = (): Promise<SubagentExecutor> => {
|
|
575
|
+
executorPromise ??= loadExecutorModule().then(({ createSubagentExecutor }) => {
|
|
576
|
+
executor = createSubagentExecutor(executorDeps);
|
|
577
|
+
return executor;
|
|
578
|
+
});
|
|
579
|
+
return executorPromise;
|
|
580
|
+
};
|
|
581
|
+
// Loading these on first use could happen days after startup, when pi-subagents may have
|
|
582
|
+
// changed on disk and the new files would import stale cached copies of modules loaded at
|
|
583
|
+
// startup. Load them shortly after a session starts instead, off Pi's startup path; child
|
|
584
|
+
// runtimes return before registration and never schedule this.
|
|
585
|
+
let modulePreloadTimer: ReturnType<typeof setTimeout> | undefined;
|
|
586
|
+
const scheduleModulePreload = () => {
|
|
587
|
+
if (executorModulePromise || modulePreloadTimer) return;
|
|
588
|
+
modulePreloadTimer = setTimeout(() => {
|
|
589
|
+
// Errors surface from the first call that needs the module.
|
|
590
|
+
loadExecutorModule().catch(() => {});
|
|
591
|
+
if (fleetViewEnabled) import("../tui/fleet.ts").catch(() => {});
|
|
592
|
+
}, MODULE_PRELOAD_DELAY_MS);
|
|
593
|
+
modulePreloadTimer.unref?.();
|
|
594
|
+
};
|
|
638
595
|
|
|
639
596
|
pi.registerMessageRenderer<SupervisorRequestMessageDetails>(SUPERVISOR_REQUEST_MESSAGE_TYPE, renderSupervisorRequest);
|
|
640
597
|
// SAFETY: `registerEntryRenderer` is not part of the typed ExtensionAPI in the
|
|
@@ -723,9 +680,13 @@ export default function registerSubagentExtension(pi: ExtensionAPI): void {
|
|
|
723
680
|
return new SubagentControlNoticeComponent({ ...details, noticeText: formatSubagentControlNotice(details, content) }, theme);
|
|
724
681
|
});
|
|
725
682
|
|
|
683
|
+
const executeSubagentReady = async (id: string, params: SubagentParamsLike, signal: AbortSignal, onUpdate: ((result: AgentToolResult<Details>) => void) | undefined, ctx: ExtensionContext) => {
|
|
684
|
+
await waitForAdvertisement();
|
|
685
|
+
return (await getExecutor()).executePublic(id, params, signal, onUpdate, ctx);
|
|
686
|
+
};
|
|
726
687
|
const executeSubagentCollapsed = (id: string, params: SubagentParamsLike, signal: AbortSignal, onUpdate: ((result: AgentToolResult<Details>) => void) | undefined, ctx: ExtensionContext) => {
|
|
727
688
|
if (ctx.hasUI) ctx.ui.setToolsExpanded(false);
|
|
728
|
-
return
|
|
689
|
+
return executeSubagentReady(id, params, signal, onUpdate, ctx);
|
|
729
690
|
};
|
|
730
691
|
|
|
731
692
|
const slashBridge = registerSlashSubagentBridge({
|
|
@@ -740,29 +701,35 @@ export default function registerSubagentExtension(pi: ExtensionAPI): void {
|
|
|
740
701
|
getContext: () => state.lastUiContext,
|
|
741
702
|
execute: (requestId, params, signal, ctx, onUpdate) =>
|
|
742
703
|
executeSubagentCollapsed(requestId, params, signal, onUpdate, ctx),
|
|
743
|
-
executeStructured: (requestId, params, signal, ctx, onUpdate) => {
|
|
704
|
+
executeStructured: async (requestId, params, signal, ctx, onUpdate) => {
|
|
744
705
|
if (ctx.hasUI) ctx.ui.setToolsExpanded(false);
|
|
745
|
-
|
|
706
|
+
await waitForAdvertisement();
|
|
707
|
+
return (await getExecutor()).executeDelegated(requestId, params, signal, onUpdate, ctx);
|
|
746
708
|
},
|
|
747
709
|
});
|
|
748
710
|
|
|
711
|
+
const disabledFeatures = resolveDisabledFeatureSurface(config);
|
|
749
712
|
const rpcBridge = registerSubagentRpcBridge({
|
|
750
713
|
events: pi.events,
|
|
751
714
|
getContext: () => state.lastUiContext,
|
|
752
|
-
execute:
|
|
715
|
+
execute: executeSubagentReady,
|
|
753
716
|
state,
|
|
717
|
+
disabledFeatures,
|
|
754
718
|
});
|
|
755
719
|
|
|
756
720
|
|
|
757
|
-
const parameters = createSubagentParamsSchema();
|
|
721
|
+
const parameters = createSubagentParamsSchema(disabledFeatures);
|
|
758
722
|
const tool: ToolDefinition<typeof parameters, Details> = {
|
|
759
723
|
name: "subagent",
|
|
724
|
+
...MODEL_ONLY_TOOL,
|
|
760
725
|
label: "Subagent",
|
|
761
|
-
description: buildSubagentToolDescription(config),
|
|
762
|
-
...buildSubagentToolPromptMetadata(config),
|
|
726
|
+
description: buildSubagentToolDescription(config, { disabledFeatures }),
|
|
727
|
+
...buildSubagentToolPromptMetadata(config, disabledFeatures),
|
|
763
728
|
parameters,
|
|
764
729
|
|
|
765
730
|
async execute(id, params, signal, onUpdate, ctx) {
|
|
731
|
+
const removedField = removedModelWorkflowFieldError(params);
|
|
732
|
+
if (removedField) throw new Error(removedField);
|
|
766
733
|
return finalizeToolResult(await executeSubagentCollapsed(id, params as SubagentParamsLike, signal ?? new AbortController().signal, onUpdate, ctx));
|
|
767
734
|
},
|
|
768
735
|
|
|
@@ -776,15 +743,9 @@ export default function registerSubagentExtension(pi: ExtensionAPI): void {
|
|
|
776
743
|
0, 0,
|
|
777
744
|
);
|
|
778
745
|
}
|
|
779
|
-
if (args.
|
|
746
|
+
if (args.workflow !== undefined)
|
|
780
747
|
return new Text(
|
|
781
|
-
`${title}${gap}${
|
|
782
|
-
0,
|
|
783
|
-
0,
|
|
784
|
-
);
|
|
785
|
-
if (args.workflowScriptPath)
|
|
786
|
-
return new Text(
|
|
787
|
-
`${title}${gap}${theme.fg("accent", args.workflowScriptPath)}${args.async === true ? `${gap}${theme.fg("warning", "[async]")}` : ""}${args.preflight !== undefined ? `${gap}${theme.fg("dim", formatWorkflowPreflightCall(args.preflight))}` : ""}`,
|
|
748
|
+
`${title}${gap}${theme.fg("accent", args.workflow === true ? "workflow (reply block)" : `workflow ${String(args.workflow)}`)}${args.async === true ? `${gap}${theme.fg("warning", "[async]")}` : ""}${args.preflight !== undefined ? `${gap}${theme.fg("dim", formatWorkflowPreflightCall(args.preflight))}` : ""}`,
|
|
788
749
|
0,
|
|
789
750
|
0,
|
|
790
751
|
);
|
|
@@ -817,17 +778,18 @@ export default function registerSubagentExtension(pi: ExtensionAPI): void {
|
|
|
817
778
|
return next ? { systemPrompt: next } : undefined;
|
|
818
779
|
});
|
|
819
780
|
|
|
820
|
-
pi.on("before_agent_start", (event, ctx) => {
|
|
821
|
-
|
|
781
|
+
pi.on("before_agent_start", async (event, ctx) => {
|
|
782
|
+
await waitForAdvertisement();
|
|
783
|
+
if (!event.systemPromptOptions.selectedTools.includes("subagent")) return;
|
|
822
784
|
const sessionId = state.currentSessionId ?? resolveCurrentSessionId(ctx.sessionManager);
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
const
|
|
827
|
-
if (
|
|
785
|
+
// Structured sections let Pi append a transcript delta instead of replacing the
|
|
786
|
+
// cached system prompt. Set the section on every turn it applies: Pi rebuilds the
|
|
787
|
+
// options each turn, and an unset turn records a removal.
|
|
788
|
+
const catalog = buildAdvertisedAgentCatalog(advertisedAgents, resolveCurrentSubagentCapabilityCeiling(sessionId));
|
|
789
|
+
if (catalog) event.systemPromptOptions.sections.advertised_subagents = catalog;
|
|
828
790
|
});
|
|
829
791
|
|
|
830
|
-
registerWaitTool(pi, state, waitToolConfig.enabled, waitSubscriptionManager, waitToolConfig.defaultTimeoutMs);
|
|
792
|
+
registerWaitTool(pi, state, waitToolConfig.enabled, waitSubscriptionManager, waitToolConfig.defaultTimeoutMs, undefined, supervisorChannel.hasPendingRequests);
|
|
831
793
|
|
|
832
794
|
pi.on("agent_end", async (_event, ctx) => {
|
|
833
795
|
if (!ctx.hasUI) await drainOutstandingWork({ state, events: pi.events, hasPendingSupervisorRequest: supervisorChannel.hasPendingRequests });
|
|
@@ -853,6 +815,7 @@ export default function registerSubagentExtension(pi: ExtensionAPI): void {
|
|
|
853
815
|
const disposeSlashCommands = registerSlashCommands(pi, state, {
|
|
854
816
|
fleetKeybindings: config.fleetKeybindings,
|
|
855
817
|
foregroundDetachShortcut: config.foregroundDetachShortcut,
|
|
818
|
+
workflowScriptsDisabled: disabledFeatures.features.has("workflow-scripts"),
|
|
856
819
|
});
|
|
857
820
|
|
|
858
821
|
let visibleControlNotices = new Set<string>();
|
|
@@ -891,6 +854,7 @@ export default function registerSubagentExtension(pi: ExtensionAPI): void {
|
|
|
891
854
|
};
|
|
892
855
|
const eventUnsubscribes = [
|
|
893
856
|
registerRuntimeAgentEventListener(pi),
|
|
857
|
+
registerInspectorEventListener(pi),
|
|
894
858
|
pi.events.on(SUBAGENT_ASYNC_STARTED_EVENT, asyncStartedHandler),
|
|
895
859
|
pi.events.on(SUBAGENT_ASYNC_COMPLETE_EVENT, asyncCompleteHandler),
|
|
896
860
|
pi.events.on(SUBAGENT_PROCESS_TERMINAL_EVENT, () => {
|
|
@@ -978,17 +942,10 @@ export default function registerSubagentExtension(pi: ExtensionAPI): void {
|
|
|
978
942
|
};
|
|
979
943
|
const projectPaneOwnerRoot = path.resolve(ctx.cwd);
|
|
980
944
|
restoreHerdrProjectPaneSnapshots(state, [...new Set([...(state.herdrProjectPanes?.keys() ?? []), ...listHerdrProjectPaneRoots(projectPaneOwnerRoot), projectPaneOwnerRoot])]);
|
|
981
|
-
//
|
|
982
|
-
//
|
|
983
|
-
// child host: the runner process inherits the parent's value through
|
|
984
|
-
// its environment at spawn time and must not overwrite it with a child
|
|
985
|
-
// session's identity.
|
|
945
|
+
// Root hosts may contain independent sessions, so a process-global parent
|
|
946
|
+
// identity is unsafe. Dedicated child runners retain their launch-owned value.
|
|
986
947
|
if (!process.env[SUBAGENT_CHILD_ENV]) {
|
|
987
|
-
|
|
988
|
-
if (sessionId) {
|
|
989
|
-
process.env[SUBAGENT_PARENT_SESSION_ENV] = sessionId;
|
|
990
|
-
parentSessionEnvValue = sessionId;
|
|
991
|
-
}
|
|
948
|
+
delete process.env[SUBAGENT_PARENT_SESSION_ENV];
|
|
992
949
|
}
|
|
993
950
|
state.lastUiContext = ctx;
|
|
994
951
|
let phaseStartedAt = Date.now();
|
|
@@ -1065,13 +1022,12 @@ export default function registerSubagentExtension(pi: ExtensionAPI): void {
|
|
|
1065
1022
|
cleanup() {
|
|
1066
1023
|
if (runtimeCleaned) return;
|
|
1067
1024
|
runtimeCleaned = true;
|
|
1068
|
-
const shuttingDownParentSession = parentSessionEnvValue;
|
|
1069
1025
|
releaseHostSessionLiveness();
|
|
1070
1026
|
releaseHostSessionLiveness = () => {};
|
|
1071
1027
|
// Workflow continuations retain their launch context; abort them before
|
|
1072
1028
|
// teardown so a reload cannot launch through a stale context.
|
|
1073
1029
|
for (const controller of state.workflowControllers?.values() ?? []) {
|
|
1074
|
-
if (!controller.signal.aborted) controller.abort(
|
|
1030
|
+
if (!controller.signal.aborted) controller.abort(runtimeReplacedAbortReason());
|
|
1075
1031
|
}
|
|
1076
1032
|
state.workflowControllers?.clear();
|
|
1077
1033
|
state.workflowChildStops?.clear();
|
|
@@ -1080,6 +1036,8 @@ export default function registerSubagentExtension(pi: ExtensionAPI): void {
|
|
|
1080
1036
|
resultIndexCleanupTimer = undefined;
|
|
1081
1037
|
if (asyncRetentionTimer) clearTimeout(asyncRetentionTimer);
|
|
1082
1038
|
asyncRetentionTimer = undefined;
|
|
1039
|
+
if (modulePreloadTimer) clearTimeout(modulePreloadTimer);
|
|
1040
|
+
modulePreloadTimer = undefined;
|
|
1083
1041
|
asyncRetentionAbort.abort();
|
|
1084
1042
|
stopResultWatcher();
|
|
1085
1043
|
resultDeliveryOwnership.clear();
|
|
@@ -1113,10 +1071,6 @@ export default function registerSubagentExtension(pi: ExtensionAPI): void {
|
|
|
1113
1071
|
state.supervisorOwnerSessionId = null;
|
|
1114
1072
|
state.statusProjectionSessionId = null;
|
|
1115
1073
|
state.parentSessionFile = null;
|
|
1116
|
-
parentSessionEnvValue = null;
|
|
1117
|
-
if (shuttingDownParentSession && process.env[SUBAGENT_PARENT_SESSION_ENV] === shuttingDownParentSession) {
|
|
1118
|
-
delete process.env[SUBAGENT_PARENT_SESSION_ENV];
|
|
1119
|
-
}
|
|
1120
1074
|
if (runtimeEntry.sessionManager && runtimeRegistry.bySessionManager.get(runtimeEntry.sessionManager) === runtimeEntry) {
|
|
1121
1075
|
runtimeRegistry.bySessionManager.delete(runtimeEntry.sessionManager);
|
|
1122
1076
|
}
|
|
@@ -1190,6 +1144,7 @@ export default function registerSubagentExtension(pi: ExtensionAPI): void {
|
|
|
1190
1144
|
pi.on("session_start", (event, ctx) => {
|
|
1191
1145
|
installRuntime(ctx);
|
|
1192
1146
|
startSessionMaintenance();
|
|
1147
|
+
scheduleModulePreload();
|
|
1193
1148
|
const recovering = event.reason === "startup" || event.reason === "reload" || event.reason === "resume";
|
|
1194
1149
|
resetSessionState(ctx, recovering, event.previousSessionFile);
|
|
1195
1150
|
refreshContextInjectionSnapshot(ctx);
|
|
@@ -1227,8 +1182,15 @@ export default function registerSubagentExtension(pi: ExtensionAPI): void {
|
|
|
1227
1182
|
await herdrStatusBridge.flush();
|
|
1228
1183
|
});
|
|
1229
1184
|
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1185
|
+
// Child processes and Herdr panes never load this module; in-process children have no UI.
|
|
1186
|
+
pi.on("session_start", (_event, ctx) => void showUpgradeNotice(ctx).catch((error) => console.error("Failed to show the pi-subagents upgrade notice:", error)));
|
|
1187
|
+
pi.on("session_start", (_event, ctx) => beginAdvertisement(ctx));
|
|
1188
|
+
|
|
1189
|
+
registerSubagentToolActivation(pi, {
|
|
1190
|
+
mode: config.toolActivation,
|
|
1191
|
+
advertisedPrompt: async () => {
|
|
1192
|
+
await waitForAdvertisement();
|
|
1193
|
+
return buildAdvertisedAgentPrompt(advertisedAgents, resolveCurrentSubagentCapabilityCeiling(state.currentSessionId ?? undefined));
|
|
1194
|
+
},
|
|
1233
1195
|
});
|
|
1234
1196
|
}
|