@xzzpig/pi-subagents 0.24.2 → 0.25.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 +37 -0
- package/bundle/agent-management.js +4 -4
- package/bundle/agents.js +3 -3
- package/bundle/child-tool-plan.js +2 -2
- package/bundle/chunk-34TUUBRN.js +1107 -0
- package/bundle/{chunk-SW2VMNIU.js → chunk-5OD3OWTE.js} +2 -2
- package/bundle/{chunk-EUPJB4S7.js → chunk-5Z7JAORM.js} +196 -1219
- package/bundle/{chunk-LCDJWBVM.js → chunk-66JNFRFS.js} +1 -1
- package/bundle/{chunk-ED55MIC2.js → chunk-CGFF4WA3.js} +42 -19
- package/bundle/{chunk-TMHVDPYW.js → chunk-DLVPMML3.js} +263 -154
- package/bundle/{chunk-RU522D5W.js → chunk-FQPV4O6C.js} +183 -28
- package/bundle/chunk-HXRB42AF.js +108 -0
- package/bundle/{chunk-355ECEP2.js → chunk-IH7LQVEE.js} +29 -14
- package/bundle/{chunk-Z6TFJ6BR.js → chunk-INWSUNI6.js} +1 -1
- package/bundle/{chunk-CYY5UMJU.js → chunk-IXCEOEJT.js} +411 -249
- package/bundle/{chunk-WW76JRIX.js → chunk-JAXVBXGF.js} +1 -1
- package/bundle/{chunk-ICNYIALB.js → chunk-JH5H4CYJ.js} +784 -474
- package/bundle/{chunk-224WMDIV.js → chunk-JUYNN63E.js} +350 -123
- package/bundle/{chunk-35GII5EF.js → chunk-JWFLPSTP.js} +41 -117
- package/bundle/{chunk-XWWUDWUW.js → chunk-KRNBJPZ2.js} +670 -400
- package/bundle/{chunk-RB4GELQA.js → chunk-LPJEKHOY.js} +1 -1
- package/bundle/chunk-LYKG4FKH.js +523 -0
- package/bundle/{chunk-X6LOM3Z4.js → chunk-LZ3HBDTR.js} +161 -78
- package/bundle/{chunk-JEA2ZKUA.js → chunk-MMJQMPOK.js} +37 -165
- package/bundle/{chunk-FG6SQJAR.js → chunk-OGPOCGWX.js} +24 -6
- package/bundle/{chunk-FJWI64H7.js → chunk-RMSABUN3.js} +27 -13
- package/bundle/{chunk-H36HBZB2.js → chunk-SJPABBZG.js} +2 -2
- package/bundle/{chunk-4UH4WS4G.js → chunk-SNDCIJMK.js} +23 -12
- package/bundle/{chunk-O4D5PBVI.js → chunk-TM2K53NX.js} +3 -2
- package/bundle/{chunk-3U633XDZ.js → chunk-U3ZDUUTM.js} +11 -3
- package/bundle/{chunk-LVWU2HOO.js → chunk-ULGMXABL.js} +16 -7
- package/bundle/{chunk-WPW4V6HM.js → chunk-W7ZA6TYD.js} +2 -2
- package/bundle/{chunk-BQ2OAB4Q.js → chunk-WWDUNXSE.js} +67 -30
- package/bundle/{chunk-V2KFIGFH.js → chunk-XAC2XNAP.js} +503 -304
- package/bundle/control-channel.js +2 -2
- package/bundle/index.js +1 -1
- package/bundle/intercom-bridge.js +2 -2
- package/bundle/preflight.js +12 -10
- package/bundle/project-panes.js +3 -3
- package/bundle/workflow-resources.js +1 -1
- package/docs/agents.md +27 -6
- package/docs/configuration.md +20 -8
- package/docs/extension-api.md +18 -1
- package/docs/models.md +6 -2
- package/docs/observability.md +2 -0
- package/docs/tool-reference.md +7 -1
- package/docs/workflows.md +30 -2
- package/package.json +2 -2
- package/skills/pi-subagents/SKILL.md +15 -6
- package/skills/pi-subagents/references/prompting-and-roles.md +1 -0
- package/src/agents/agent-management.d.ts +1 -0
- package/src/agents/agent-management.js +46 -18
- package/src/agents/agent-memory.d.ts +1 -4
- package/src/agents/agent-memory.js +1 -4
- package/src/agents/agent-serializer.d.ts +2 -0
- package/src/agents/agent-serializer.js +1 -1
- package/src/agents/agents.d.ts +2 -3
- package/src/agents/agents.js +46 -20
- package/src/agents/frontmatter.js +1 -8
- package/src/agents/global-npm-root.d.ts +1 -0
- package/src/agents/global-npm-root.js +11 -3
- package/src/agents/skills.d.ts +0 -3
- package/src/agents/skills.js +0 -3
- package/src/api/preflight.d.ts +3 -1
- package/src/api/preflight.js +2 -0
- package/src/extension/config.d.ts +1 -0
- package/src/extension/config.js +13 -1
- package/src/extension/herdr-pi-bridge.js +10 -2
- package/src/extension/index.d.ts +0 -13
- package/src/extension/index.js +51 -37
- package/src/extension/public-execution.d.ts +1 -0
- package/src/extension/public-execution.js +4 -0
- package/src/extension/reply-workflow-script.js +24 -4
- package/src/extension/schemas.d.ts +12 -3
- package/src/extension/schemas.js +7 -3
- package/src/extension/session-switch.d.ts +25 -0
- package/src/extension/session-switch.js +138 -0
- package/src/extension/subagent-guide.d.ts +1 -1
- package/src/extension/subagent-guide.js +1 -1
- package/src/extension/subagent-launch-tool.d.ts +25 -0
- package/src/extension/subagent-launch-tool.js +48 -0
- package/src/extension/tool-activation.js +55 -15
- package/src/extension/tool-description.d.ts +1 -1
- package/src/extension/tool-description.js +14 -8
- package/src/inspectors/herdr/actions.d.ts +0 -1
- package/src/inspectors/herdr/actions.js +0 -1
- package/src/inspectors/session-roots-codec.d.ts +0 -1
- package/src/inspectors/session-roots-codec.js +0 -1
- package/src/inspectors/tmux/actions.d.ts +0 -1
- package/src/inspectors/tmux/actions.js +0 -1
- package/src/integrations/herdr-status.js +3 -8
- package/src/intercom/native-supervisor-channel.js +65 -9
- package/src/runs/background/async-execution.d.ts +7 -10
- package/src/runs/background/async-execution.js +66 -29
- package/src/runs/background/async-job-tracker.js +12 -0
- package/src/runs/background/async-resume.d.ts +2 -1
- package/src/runs/background/async-resume.js +114 -40
- package/src/runs/background/async-retention.d.ts +0 -2
- package/src/runs/background/async-retention.js +17 -6
- package/src/runs/background/async-status.d.ts +2 -0
- package/src/runs/background/async-status.js +4 -0
- package/src/runs/background/auto-drain.js +2 -1
- package/src/runs/background/boot-id.d.ts +1 -3
- package/src/runs/background/boot-id.js +1 -3
- package/src/runs/background/completion-batcher.d.ts +3 -4
- package/src/runs/background/completion-batcher.js +2 -3
- package/src/runs/background/control-channel.d.ts +0 -6
- package/src/runs/background/control-channel.js +0 -6
- package/src/runs/background/fleet-view.js +2 -3
- package/src/runs/background/notify.d.ts +0 -2
- package/src/runs/background/notify.js +0 -2
- package/src/runs/background/result-watcher.d.ts +1 -0
- package/src/runs/background/result-watcher.js +59 -29
- package/src/runs/background/resume-guidance.js +4 -2
- package/src/runs/background/retained-children.js +2 -1
- package/src/runs/background/run-child-session.d.ts +2 -3
- package/src/runs/background/run-child-session.js +5 -8
- package/src/runs/background/run-status.js +9 -7
- package/src/runs/background/runner-aliases.js +15 -0
- package/src/runs/background/scheduled-runs.d.ts +3 -1
- package/src/runs/background/scheduled-runs.js +13 -16
- package/src/runs/background/steering.d.ts +2 -11
- package/src/runs/background/steering.js +11 -6
- package/src/runs/background/subagent-runner.d.ts +2 -6
- package/src/runs/background/subagent-runner.js +88 -70
- package/src/runs/background/subagent-wait.js +12 -15
- package/src/runs/background/wait-config.d.ts +2 -0
- package/src/runs/background/wait-config.js +17 -3
- package/src/runs/background/wait-subscriptions.js +124 -12
- package/src/runs/background/wait-tool.js +4 -2
- package/src/runs/background/workflow-terminal-proof.d.ts +0 -1
- package/src/runs/background/workflow-terminal-proof.js +0 -1
- package/src/runs/foreground/async-steering-action.js +24 -9
- package/src/runs/foreground/async-stop-action.d.ts +1 -1
- package/src/runs/foreground/async-stop-action.js +9 -1
- package/src/runs/foreground/execution.d.ts +0 -3
- package/src/runs/foreground/execution.js +68 -84
- package/src/runs/foreground/fork-tool-result-handler.d.ts +60 -0
- package/src/runs/foreground/fork-tool-result-handler.js +83 -0
- package/src/runs/foreground/prompt-audit.js +1 -0
- package/src/runs/foreground/subagent-executor.d.ts +5 -10
- package/src/runs/foreground/subagent-executor.js +164 -49
- package/src/runs/shared/acceptance.js +69 -26
- package/src/runs/shared/async-status-projection.d.ts +2 -0
- package/src/runs/shared/async-status-projection.js +10 -0
- package/src/runs/shared/child-commands.js +15 -2
- package/src/runs/shared/child-hooks.d.ts +1 -7
- package/src/runs/shared/child-hooks.js +13 -5
- package/src/runs/shared/child-launch.js +6 -2
- package/src/runs/shared/child-runtime-config.d.ts +0 -1
- package/src/runs/shared/child-session.d.ts +6 -5
- package/src/runs/shared/child-session.js +85 -38
- package/src/runs/shared/child-tool-plan.d.ts +0 -1
- package/src/runs/shared/child-tool-plan.js +0 -1
- package/src/runs/shared/claude-code-adapter.js +11 -0
- package/src/runs/shared/external-cli-contract.d.ts +49 -0
- package/src/runs/shared/external-cli-contract.js +18 -13
- package/src/runs/shared/external-cli-runner.js +26 -6
- package/src/runs/shared/herdr-connection.js +2 -1
- package/src/runs/shared/herdr-pane-host.d.ts +2 -2
- package/src/runs/shared/herdr-pane-host.js +17 -1
- package/src/runs/shared/herdr-placed-run.js +51 -24
- package/src/runs/shared/lane-metadata.d.ts +0 -1
- package/src/runs/shared/lane-metadata.js +0 -1
- package/src/runs/shared/mcp-config-sources.d.ts +4 -1
- package/src/runs/shared/mcp-config-sources.js +1 -1
- package/src/runs/shared/mcp-direct-tool-allowlist.d.ts +0 -3
- package/src/runs/shared/mcp-direct-tool-allowlist.js +26 -17
- package/src/runs/shared/mcp-direct-tool-grant.js +8 -1
- package/src/runs/shared/model-resolution-diagnostic.d.ts +0 -1
- package/src/runs/shared/model-resolution.d.ts +20 -5
- package/src/runs/shared/model-resolution.js +55 -50
- package/src/runs/shared/model-scope.d.ts +1 -5
- package/src/runs/shared/model-scope.js +1 -5
- package/src/runs/shared/mutation-evidence.d.ts +1 -1
- package/src/runs/shared/mutation-evidence.js +52 -7
- package/src/runs/shared/nested-events.d.ts +1 -0
- package/src/runs/shared/nested-events.js +1 -1
- package/src/runs/shared/parallel-utils.d.ts +0 -1
- package/src/runs/shared/permissions.js +5 -3
- package/src/runs/shared/placement-host.d.ts +5 -1
- package/src/runs/shared/rex-pane-host.d.ts +0 -1
- package/src/runs/shared/rex-pane-host.js +0 -2
- package/src/runs/shared/run-launch-folder.d.ts +12 -0
- package/src/runs/shared/run-launch-folder.js +21 -0
- package/src/runs/shared/runner-launcher.d.ts +12 -1
- package/src/runs/shared/runner-launcher.js +16 -0
- package/src/runs/shared/single-output.d.ts +3 -3
- package/src/runs/shared/single-output.js +5 -3
- package/src/runs/shared/structured-output.d.ts +8 -0
- package/src/runs/shared/structured-output.js +40 -5
- package/src/runs/shared/subagent-prompt-runtime.d.ts +0 -1
- package/src/runs/shared/subagent-prompt-runtime.js +18 -4
- package/src/runs/shared/supervisor-wait-timer.d.ts +16 -0
- package/src/runs/shared/supervisor-wait-timer.js +61 -0
- package/src/runs/shared/tool-timeout.js +2 -1
- package/src/runs/shared/worktree-cleanup-plan.d.ts +0 -1
- package/src/runs/shared/worktree-cleanup-plan.js +0 -1
- package/src/runs/shared/worktree.d.ts +3 -0
- package/src/runs/shared/worktree.js +20 -0
- package/src/shared/artifacts.d.ts +1 -0
- package/src/shared/artifacts.js +132 -22
- package/src/shared/capacity-resilient-json.d.ts +1 -1
- package/src/shared/child-cache-retention.d.ts +1 -2
- package/src/shared/child-cache-retention.js +1 -2
- package/src/shared/fleet-transcript-reader.d.ts +64 -0
- package/src/shared/fleet-transcript-reader.js +376 -0
- package/src/shared/formatters.d.ts +0 -18
- package/src/shared/formatters.js +0 -18
- package/src/shared/pruned-fork.js +2 -2
- package/src/shared/reported-progress.d.ts +1 -0
- package/src/shared/reported-progress.js +12 -0
- package/src/shared/session-succession.d.ts +16 -1
- package/src/shared/session-succession.js +41 -2
- package/src/shared/session-warnings.d.ts +7 -0
- package/src/shared/session-warnings.js +26 -0
- package/src/shared/settings.d.ts +0 -23
- package/src/shared/settings.js +3 -35
- package/src/shared/status-format.d.ts +1 -0
- package/src/shared/status-format.js +1 -1
- package/src/shared/types.d.ts +108 -59
- package/src/shared/types.js +0 -12
- package/src/shared/utils.d.ts +3 -15
- package/src/shared/utils.js +4 -22
- package/src/shared/wait-tool-name.d.ts +8 -0
- package/src/shared/wait-tool-name.js +13 -0
- package/src/slash/slash-commands.js +2 -1
- package/src/slash/subagent-cost.d.ts +3 -2
- package/src/slash/subagent-cost.js +22 -3
- package/src/slash/subagents-admin.js +0 -1
- package/src/tui/fleet-native-transcript.js +1 -1
- package/src/tui/fleet-status.d.ts +0 -5
- package/src/tui/fleet-status.js +4 -24
- package/src/tui/fleet-transcript.d.ts +1 -57
- package/src/tui/fleet-transcript.js +4 -370
- package/src/tui/fleet.js +6 -4
- package/src/tui/render.d.ts +0 -9
- package/src/tui/render.js +194 -68
- package/src/tui/subagent-messages.js +3 -2
- package/src/watchdog/model-selection.js +2 -2
- package/src/watchdog/permission-arbiter.js +1 -0
- package/src/watchdog/register-child.d.ts +2 -3
- package/src/watchdog/register-child.js +2 -3
- package/src/watchdog/review.d.ts +0 -5
- package/src/watchdog/review.js +4 -3
- package/src/watchdog/turn-delta.js +2 -1
- package/src/workflows/scripted-workflow.d.ts +2 -0
- package/src/workflows/scripted-workflow.js +344 -59
- package/src/workflows/structured-workflow-scripts.d.ts +4 -3
- package/src/workflows/structured-workflow-scripts.js +32 -11
- package/src/workflows/workflow-launch-record.d.ts +15 -6
- package/src/workflows/workflow-launch-record.js +30 -12
- package/src/workflows/workflow-receipt.js +36 -53
- package/src/workflows/workflow-resources.js +4 -4
- package/src/workflows/workflow-resume-claim.d.ts +2 -0
- package/src/workflows/workflow-resume-claim.js +3 -3
- package/src/workflows/workflow-resume.d.ts +1 -1
- package/src/workflows/workflow-resume.js +13 -8
- package/src/workflows/workflow-script-worker.d.ts +13 -0
- package/src/workflows/workflow-script-worker.js +81 -0
- package/workflow-script-process.cjs +36 -0
- package/workflow-script-worker.cjs +4 -1
- package/bundle/chunk-U4ODUYAG.js +0 -235
package/src/api/preflight.js
CHANGED
|
@@ -263,6 +263,7 @@ export async function resolveSubagentLaunchContract(input) {
|
|
|
263
263
|
: resolveEffectiveSubagentModel(input.model, agent.model, input.parentModel, availableModels, preferredProvider, {
|
|
264
264
|
scope: modelScopes,
|
|
265
265
|
source: modelOrigin === "explicit" ? "explicit" : "inherited",
|
|
266
|
+
knownProviders: input.knownProviders,
|
|
266
267
|
});
|
|
267
268
|
const effectiveThinkingConfig = input.thinking !== undefined ? input.thinking : agent.thinking;
|
|
268
269
|
const thinkingCeiling = externalRunner ? undefined : intersectThinkingCeilings(discovered.maxThinking, input.thinkingCeiling, input.inheritedThinkingCeiling);
|
|
@@ -270,6 +271,7 @@ export async function resolveSubagentLaunchContract(input) {
|
|
|
270
271
|
scope: modelScopes,
|
|
271
272
|
primaryModelFromParent: modelOrigin === "inherited" || inheritsParentModel(input.model, agent.model, input.parentModel),
|
|
272
273
|
origin: modelOrigin,
|
|
274
|
+
knownProviders: input.knownProviders,
|
|
273
275
|
}).model, effectiveThinkingConfig, input.thinking !== undefined);
|
|
274
276
|
if (!externalRunner) {
|
|
275
277
|
try {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type ExtensionConfig } from "../shared/types.ts";
|
|
2
2
|
export declare function resolveScheduledStoreRoot(value: string): string;
|
|
3
|
+
export declare function resolveConfigDefaultTimeoutMs(raw: unknown): number | undefined;
|
|
3
4
|
export declare function getConfigPath(): string;
|
|
4
5
|
export declare function saveConfig(config: ExtensionConfig, configPath?: string): void;
|
|
5
6
|
export declare function updateConfig(updater: (config: ExtensionConfig) => ExtensionConfig): ExtensionConfig;
|
package/src/extension/config.js
CHANGED
|
@@ -13,7 +13,7 @@ import { validateModelResponseAliases } from "../shared/model-response-aliases.j
|
|
|
13
13
|
import { validateDisabledFeatures } from "../shared/disabled-features.js";
|
|
14
14
|
// Explicit route identity, worktree, checkpoint, and tool-surface policies must not be silently
|
|
15
15
|
// discarded and replaced by the built-in defaults after validation fails.
|
|
16
|
-
const FAIL_CLOSED_CONFIG_KEYS = ["worktreeProvider", "worktreeBranchPrefix", "modelResponseAliases", "modelExclusions", "checkpointBeforeDeadlineMs", "disabledFeatures", "scheduledRuns", "toolActivation", "authorityPolicy", "permissions", "toolBudget", "runnerLaunchers"];
|
|
16
|
+
const FAIL_CLOSED_CONFIG_KEYS = ["worktreeProvider", "worktreeBranchPrefix", "modelResponseAliases", "modelExclusions", "checkpointBeforeDeadlineMs", "disabledFeatures", "scheduledRuns", "toolActivation", "authorityPolicy", "permissions", "toolBudget", "runnerLaunchers", "globalConcurrencyLimit"];
|
|
17
17
|
const ARTIFACT_DIR_PREFERENCES = new Set(["project", "session", "temp"]);
|
|
18
18
|
const FLEET_KEYBINDING_ACTION_SET = new Set(FLEET_KEYBINDING_ACTIONS);
|
|
19
19
|
const KEY_MODIFIERS = new Set(["ctrl", "shift", "alt", "super"]);
|
|
@@ -196,6 +196,12 @@ function validateConfig(config) {
|
|
|
196
196
|
|| config.maxActiveAsyncRunsPerSession < 0)) {
|
|
197
197
|
throw new Error("config.maxActiveAsyncRunsPerSession must be a non-negative integer");
|
|
198
198
|
}
|
|
199
|
+
if (config.globalConcurrencyLimit !== undefined
|
|
200
|
+
&& (typeof config.globalConcurrencyLimit !== "number"
|
|
201
|
+
|| !Number.isInteger(config.globalConcurrencyLimit)
|
|
202
|
+
|| config.globalConcurrencyLimit < 1)) {
|
|
203
|
+
throw new Error("config.globalConcurrencyLimit must be a positive integer");
|
|
204
|
+
}
|
|
199
205
|
if (config.resultScanLogging !== undefined && config.resultScanLogging !== "all" && config.resultScanLogging !== "activity" && config.resultScanLogging !== "off") {
|
|
200
206
|
throw new Error('config.resultScanLogging must be "all", "activity", or "off"');
|
|
201
207
|
}
|
|
@@ -238,6 +244,12 @@ function validateConfig(config) {
|
|
|
238
244
|
validateOrcaProgressTabsConfig(config.orcaProgressTabs);
|
|
239
245
|
validateRunnerLaunchersConfig(config.runnerLaunchers);
|
|
240
246
|
}
|
|
247
|
+
// An invalid value counts as unset; above Node's timer ceiling a timer fires almost at once.
|
|
248
|
+
export function resolveConfigDefaultTimeoutMs(raw) {
|
|
249
|
+
if (typeof raw !== "number" || !Number.isInteger(raw) || raw <= 0 || raw > 2_147_483_647)
|
|
250
|
+
return undefined;
|
|
251
|
+
return raw;
|
|
252
|
+
}
|
|
241
253
|
export function getConfigPath() {
|
|
242
254
|
return path.join(getAgentDir(), "extensions", "subagent", "config.json");
|
|
243
255
|
}
|
|
@@ -13,6 +13,7 @@ import { rewriteSubagentPrompt } from "../runs/shared/subagent-prompt-runtime.js
|
|
|
13
13
|
import { assertNoToolModifierEntries } from "../runs/shared/child-tool-plan.js";
|
|
14
14
|
import { resolveExistingReadPaths } from "../shared/settings.js";
|
|
15
15
|
import { MODEL_ONLY_TOOL } from "../shared/extension-context.js";
|
|
16
|
+
import { captureWatchdogDiffBaseline, createWatchdogDiffTool, WATCHDOG_DIFF_TOOL_NAME } from "../watchdog/diff-tool.js";
|
|
16
17
|
function gitEvidence(cwd) {
|
|
17
18
|
const run = (args) => spawnSync("git", args, { cwd, encoding: "utf8", timeout: 5_000, maxBuffer: 128 * 1024 });
|
|
18
19
|
const inside = run(["rev-parse", "--is-inside-work-tree"]);
|
|
@@ -225,10 +226,14 @@ export default function registerHerdrPiBridge(pi) {
|
|
|
225
226
|
const resolved = resolveRemoteHerdrResources(process.cwd(), { agent: resources.agent, ...(resources.skills ? { skills: resources.skills } : {}), ...(resources.toolCeiling ? { toolCeiling: resources.toolCeiling } : {}), ...(resources.reads !== undefined ? { reads: resources.reads } : {}) }, context ? pi.getActiveTools() : []);
|
|
226
227
|
resolvedSystemPrompt = resolved.systemPrompt;
|
|
227
228
|
resolvedContextPolicy = resolved;
|
|
229
|
+
// A local child gets watchdog_diff from the prompt runtime, which a placed child never loads.
|
|
230
|
+
if (resolved.tools.includes(WATCHDOG_DIFF_TOOL_NAME) && !pi.getAllTools().some((tool) => tool.name === WATCHDOG_DIFF_TOOL_NAME))
|
|
231
|
+
pi.registerTool(createWatchdogDiffTool(captureWatchdogDiffBaseline(process.cwd()), { workingTreeAtLaunch: true }));
|
|
228
232
|
pi.setActiveTools(resolved.tools);
|
|
229
233
|
const acknowledged = context ? pi.getActiveTools() : [];
|
|
230
|
-
|
|
231
|
-
|
|
234
|
+
const missing = resolved.tools.filter((tool) => !acknowledged.includes(tool)), extra = acknowledged.filter((tool) => !resolved.tools.includes(tool));
|
|
235
|
+
if (missing.length || extra.length)
|
|
236
|
+
throw new Error(`Remote Pi did not apply the resolved active-tool set exactly (${[...(missing.length ? [`not available: ${missing.join(", ")}`] : []), ...(extra.length ? [`unexpected: ${extra.join(", ")}`] : [])].join("; ")}).`);
|
|
232
237
|
configured = true;
|
|
233
238
|
send({ type: "configured", requestId: frame.requestId, nativeSessionId, agent: resolved.agent, skills: resolved.skills, model: context?.model?.provider && context.model.id ? `${context.model.provider}/${context.model.id}` : undefined, tools: acknowledged });
|
|
234
239
|
continue;
|
|
@@ -249,9 +254,12 @@ export default function registerHerdrPiBridge(pi) {
|
|
|
249
254
|
}
|
|
250
255
|
}
|
|
251
256
|
catch (error) {
|
|
257
|
+
context?.ui?.notify(`pi-subagents bridge: ${error.message}`, "error");
|
|
252
258
|
socket.destroy(error);
|
|
253
259
|
}
|
|
254
260
|
});
|
|
261
|
+
// Without a listener, a protocol error or peer reset is an uncaught exception that ends the child Pi.
|
|
262
|
+
socket.on("error", () => { });
|
|
255
263
|
socket.on("close", () => { if (client === socket)
|
|
256
264
|
client = undefined; });
|
|
257
265
|
if (context && nativeSessionId)
|
package/src/extension/index.d.ts
CHANGED
|
@@ -1,16 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Subagent Tool
|
|
3
|
-
*
|
|
4
|
-
* Full-featured subagent with sync and async modes.
|
|
5
|
-
* - Sync (default): Streams output, renders markdown, tracks usage
|
|
6
|
-
* - Async: Background execution, emits events when done
|
|
7
|
-
*
|
|
8
|
-
* Public execution mode: workflow (workflow: true reply block, script path, or named resource)
|
|
9
|
-
* Toggle: async parameter (default: true; set asyncByDefault:false in config.json to opt out)
|
|
10
|
-
*
|
|
11
|
-
* Config file: ~/.pi/agent/extensions/subagent/config.json
|
|
12
|
-
* { "asyncByDefault": true, "defaultSubagentContext": "fork", "forkContext": { "mode": "pruned", "model": "provider/model" }, "forceTopLevelAsync": true, "maxSubagentDepth": 1, "intercomBridge": { "mode": "always", "instructionFile": "./intercom-bridge.md" }, "worktreeSetupHook": "./scripts/setup-worktree.mjs" }
|
|
13
|
-
*/
|
|
14
1
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
15
2
|
import { type HerdrStatusRun } from "../integrations/herdr-status.ts";
|
|
16
3
|
import { type SubagentState } from "../shared/types.ts";
|
package/src/extension/index.js
CHANGED
|
@@ -1,16 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Subagent Tool
|
|
3
|
-
*
|
|
4
|
-
* Full-featured subagent with sync and async modes.
|
|
5
|
-
* - Sync (default): Streams output, renders markdown, tracks usage
|
|
6
|
-
* - Async: Background execution, emits events when done
|
|
7
|
-
*
|
|
8
|
-
* Public execution mode: workflow (workflow: true reply block, script path, or named resource)
|
|
9
|
-
* Toggle: async parameter (default: true; set asyncByDefault:false in config.json to opt out)
|
|
10
|
-
*
|
|
11
|
-
* Config file: ~/.pi/agent/extensions/subagent/config.json
|
|
12
|
-
* { "asyncByDefault": true, "defaultSubagentContext": "fork", "forkContext": { "mode": "pruned", "model": "provider/model" }, "forceTopLevelAsync": true, "maxSubagentDepth": 1, "intercomBridge": { "mode": "always", "instructionFile": "./intercom-bridge.md" }, "worktreeSetupHook": "./scripts/setup-worktree.mjs" }
|
|
13
|
-
*/
|
|
14
1
|
import { randomUUID } from "node:crypto";
|
|
15
2
|
import * as fs from "node:fs";
|
|
16
3
|
import * as os from "node:os";
|
|
@@ -26,7 +13,9 @@ import { createSupervisorDispatcher, createSupervisorLaunchHooks, disposeSupervi
|
|
|
26
13
|
import { ensureAccessibleDir } from "../shared/accessible-dir.js";
|
|
27
14
|
import { cleanupAllArtifactDirs, cleanupOldArtifacts, getArtifactsDir } from "../shared/artifacts.js";
|
|
28
15
|
import { resolveCurrentSessionId } from "../shared/session-identity.js";
|
|
29
|
-
import { recordSessionReplacement } from "../shared/session-succession.js";
|
|
16
|
+
import { recordSessionReplacement, recordSessionStart } from "../shared/session-succession.js";
|
|
17
|
+
import { createSessionSwitchGuard } from "./session-switch.js";
|
|
18
|
+
import { reportSessionWarning } from "../shared/session-warnings.js";
|
|
30
19
|
import { getAgentDir } from "../shared/utils.js";
|
|
31
20
|
import { isStaleExtensionContextError, MODEL_ONLY_TOOL, withCachedUiContext } from "../shared/extension-context.js";
|
|
32
21
|
import { currentCompletionOwnerId } from "../shared/completion-owner.js";
|
|
@@ -59,6 +48,7 @@ import { listHerdrProjectPaneRoots, restoreHerdrProjectPaneSnapshots } from "../
|
|
|
59
48
|
import { registerSubagentRpcBridge } from "./rpc.js";
|
|
60
49
|
import { clearSlashSnapshots, getSlashRenderableSnapshot, resolveSlashMessageDetails, restoreSlashFinalSnapshots } from "../slash/slash-live-state.js";
|
|
61
50
|
import { resolveWaitToolConfig } from "../runs/background/subagent-wait.js";
|
|
51
|
+
import { DEFAULT_WAIT_TOOL_NAME, setWaitToolName } from "../shared/wait-tool-name.js";
|
|
62
52
|
import { registerWaitTool } from "../runs/background/wait-tool.js";
|
|
63
53
|
import { registerSubagentToolActivation } from "./tool-activation.js";
|
|
64
54
|
import { recordedPromptSection, registerPinnedTool, setDeclarationPinning } from "./declaration-pinning.js";
|
|
@@ -70,9 +60,9 @@ import { registerGoalAutoContinueGate } from "../goal-auto-continue-gate.js";
|
|
|
70
60
|
import { createParentWake } from "../shared/parent-wake.js";
|
|
71
61
|
import { handleSubagentSteeringNotice } from "./steering-notices.js";
|
|
72
62
|
import { SUBAGENT_CHILD_ENV, SUBAGENT_PARENT_SESSION_ENV } from "../runs/shared/child-runtime-config.js";
|
|
73
|
-
import {
|
|
63
|
+
import { disposeChildSessionsForParent } from "../runs/shared/child-session.js";
|
|
74
64
|
import { resolveCurrentSubagentCapabilityCeiling } from "../runs/shared/capability-ceiling.js";
|
|
75
|
-
import { loadConfig, resolveAsyncByDefault, resolveScheduledStoreRoot } from "./config.js";
|
|
65
|
+
import { loadConfig, resolveAsyncByDefault, resolveConfigDefaultTimeoutMs, resolveScheduledStoreRoot } from "./config.js";
|
|
76
66
|
import { applyInjectionBlock, renderInjectionBlock, resolveInjectableAgents } from "./context-injection.js";
|
|
77
67
|
import { buildSubagentToolDescription, buildSubagentToolPromptMetadata } from "./tool-description.js";
|
|
78
68
|
import { formatWorkflowPreflightSummary, normalizeWorkflowPreflight } from "../workflows/workflow-preflight.js";
|
|
@@ -90,6 +80,7 @@ import { listRetainedChildren } from "../runs/background/retained-children.js";
|
|
|
90
80
|
import { DIRS, DEFAULT_ARTIFACT_CONFIG, SLASH_RESULT_TYPE, SLASH_TEXT_RESULT_TYPE, SUBAGENT_ASYNC_COMPLETE_EVENT, SUBAGENT_ASYNC_STARTED_EVENT, SUBAGENT_PROCESS_TERMINAL_EVENT, SUBAGENT_CONTROL_EVENT, SUBAGENT_STEERING_NOTICE_EVENT, WIDGET_KEY, resolveMaxSubagentSpawnsPerSession, } from "../shared/types.js";
|
|
91
81
|
import { handleSubagentControlNotice, } from "./control-notices.js";
|
|
92
82
|
import { showUpgradeNotice } from "./upgrade-notice.js";
|
|
83
|
+
import { registerSubagentLaunchTool } from "./subagent-launch-tool.js";
|
|
93
84
|
const SLOW_RELOAD_PHASE_MS = 250;
|
|
94
85
|
// Long enough for Pi to finish starting; loading the executor blocks the event loop for tens of ms.
|
|
95
86
|
const MODULE_PRELOAD_DELAY_MS = 1_000;
|
|
@@ -113,10 +104,10 @@ function getRuntimeRegistry() {
|
|
|
113
104
|
globalStore[RUNTIME_REGISTRY_STORE_KEY] = registry;
|
|
114
105
|
return registry;
|
|
115
106
|
}
|
|
116
|
-
function logSlowPhase(label, startedAt) {
|
|
107
|
+
function logSlowPhase(state, label, startedAt) {
|
|
117
108
|
const elapsed = Date.now() - startedAt;
|
|
118
109
|
if (elapsed >= SLOW_RELOAD_PHASE_MS)
|
|
119
|
-
|
|
110
|
+
reportSessionWarning(state, `Subagent reload phase '${label}' took ${elapsed}ms.`, `slow-reload-phase:${label}`);
|
|
120
111
|
}
|
|
121
112
|
function formatWorkflowPreflightCall(input) {
|
|
122
113
|
if (input === undefined)
|
|
@@ -129,7 +120,6 @@ function formatWorkflowPreflightCall(input) {
|
|
|
129
120
|
}
|
|
130
121
|
}
|
|
131
122
|
/**
|
|
132
|
-
* Derive subagent session base directory from parent session file.
|
|
133
123
|
* If parent session is ~/.pi/agent/sessions/abc123.jsonl,
|
|
134
124
|
* returns ~/.pi/agent/sessions/abc123/ as the base.
|
|
135
125
|
* Callers add runId to create the actual session root: abc123/{runId}/
|
|
@@ -237,6 +227,7 @@ export default function registerSubagentExtension(pi) {
|
|
|
237
227
|
const config = loadConfig();
|
|
238
228
|
setDeclarationPinning(pi, config.pinToolDeclarations !== false);
|
|
239
229
|
const waitToolConfig = resolveWaitToolConfig(config.waitTool);
|
|
230
|
+
setWaitToolName(waitToolConfig.name ?? DEFAULT_WAIT_TOOL_NAME);
|
|
240
231
|
const asyncByDefault = resolveAsyncByDefault(config);
|
|
241
232
|
const fleetViewEnabled = config.fleetView !== false;
|
|
242
233
|
const slashCommandsEnabled = config.enableSlashCommands !== false;
|
|
@@ -352,11 +343,13 @@ export default function registerSubagentExtension(pi) {
|
|
|
352
343
|
return (await getExecutor()).executeScheduled(randomUUID(), params, signal, ctx);
|
|
353
344
|
},
|
|
354
345
|
resolveCapabilityCeiling: (sessionId) => resolveCurrentSubagentCapabilityCeiling(sessionId),
|
|
346
|
+
reportWarning: (message, key) => reportSessionWarning(state, message, key),
|
|
355
347
|
});
|
|
356
348
|
let refreshResultDelivery = () => { };
|
|
357
349
|
let advertisedAgents = [];
|
|
358
350
|
let advertisedContext;
|
|
359
351
|
let advertisementGeneration = 0;
|
|
352
|
+
let advertisementLookup;
|
|
360
353
|
let globalRoot = null;
|
|
361
354
|
let advertisementReady = Promise.resolve();
|
|
362
355
|
let notifySessionChange = () => { };
|
|
@@ -380,12 +373,14 @@ export default function registerSubagentExtension(pi) {
|
|
|
380
373
|
};
|
|
381
374
|
const beginAdvertisement = (ctx) => {
|
|
382
375
|
const generation = ++advertisementGeneration;
|
|
376
|
+
advertisementLookup?.abort();
|
|
377
|
+
advertisementLookup = new AbortController();
|
|
383
378
|
notifySessionChange();
|
|
384
379
|
sessionChanged = new Promise((resolve) => { notifySessionChange = resolve; });
|
|
385
380
|
advertisedAgents = [];
|
|
386
381
|
advertisedContext = { cwd: ctx.cwd, model: ctx.model, projectTrusted: typeof ctx.isProjectTrusted === "function" ? ctx.isProjectTrusted() : undefined };
|
|
387
382
|
globalRoot = null;
|
|
388
|
-
advertisementReady = resolveGlobalNpmRoot().then((root) => {
|
|
383
|
+
advertisementReady = resolveGlobalNpmRoot({ signal: advertisementLookup.signal }).then((root) => {
|
|
389
384
|
if (generation !== advertisementGeneration)
|
|
390
385
|
return;
|
|
391
386
|
globalRoot = root;
|
|
@@ -465,6 +460,13 @@ export default function registerSubagentExtension(pi) {
|
|
|
465
460
|
resultScanLogging: config.resultScanLogging,
|
|
466
461
|
});
|
|
467
462
|
const { startResultWatcher, transitionResultDelivery, primeExistingResults, stopResultWatcher } = resultWatcher;
|
|
463
|
+
const sessionSwitchGuard = createSessionSwitchGuard({
|
|
464
|
+
state, asyncDirRoot: DIRS.async, resultsDir: DIRS.results,
|
|
465
|
+
hasPendingResults: () => owedResultRunIds.size > 0 || completionNotifier.hasPendingDelivery() || resultWatcher.hasPendingResults(),
|
|
466
|
+
hasPendingSupervisorRequest: supervisorChannel.hasPendingRequests,
|
|
467
|
+
});
|
|
468
|
+
pi.on("session_before_switch", (event, ctx) => sessionSwitchGuard.beforeSwitch(event.reason, ctx));
|
|
469
|
+
pi.on("session_before_fork", (_event, ctx) => sessionSwitchGuard.beforeSwitch("fork", ctx));
|
|
468
470
|
refreshResultDelivery = resultWatcher.refreshResultDelivery;
|
|
469
471
|
const asyncRetentionAbort = new AbortController();
|
|
470
472
|
let asyncRetentionTimer;
|
|
@@ -496,7 +498,7 @@ export default function registerSubagentExtension(pi) {
|
|
|
496
498
|
});
|
|
497
499
|
}
|
|
498
500
|
catch (error) {
|
|
499
|
-
|
|
501
|
+
reportSessionWarning(state, `Failed to clean retained async subagent state: ${error instanceof Error ? error.message : String(error)}`, "async-retention-cleanup");
|
|
500
502
|
}
|
|
501
503
|
}, ASYNC_RETENTION_DELAY_MS);
|
|
502
504
|
asyncRetentionTimer.unref?.();
|
|
@@ -746,6 +748,7 @@ export default function registerSubagentExtension(pi) {
|
|
|
746
748
|
registerPinnedTool(pi, tool);
|
|
747
749
|
// Declared with the same definition children use, so a fork's tool list equals this session's.
|
|
748
750
|
registerPinnedTool(pi, topLevelSupervisorTool());
|
|
751
|
+
registerSubagentLaunchTool(pi);
|
|
749
752
|
pi.on("before_agent_start", (event, ctx) => {
|
|
750
753
|
if (process.env[SUBAGENT_CHILD_ENV] === "1")
|
|
751
754
|
return undefined;
|
|
@@ -792,8 +795,9 @@ export default function registerSubagentExtension(pi) {
|
|
|
792
795
|
// A headless host may dispose the session as soon as this turn settles, so hand
|
|
793
796
|
// finished results to Pi now; Pi runs the queued completion turn after agent_end.
|
|
794
797
|
// A failed drain rejects without this step so its deadline stays exact.
|
|
798
|
+
// The parent ended its turn to wait for the wake, so the drain lasts as long as a run may.
|
|
795
799
|
if (!ctx.hasUI)
|
|
796
|
-
await drainOutstandingWork({ state, events: pi.events, hasPendingSupervisorRequest: supervisorChannel.hasPendingRequests }).then(resultWatcher.deliverPendingResults);
|
|
800
|
+
await drainOutstandingWork({ state, events: pi.events, hasPendingSupervisorRequest: supervisorChannel.hasPendingRequests, timeoutMs: resolveConfigDefaultTimeoutMs(config.timeoutMs) }).then(resultWatcher.deliverPendingResults);
|
|
797
801
|
}
|
|
798
802
|
finally {
|
|
799
803
|
// Deliver notices after a failed drain without suppressing its rejection.
|
|
@@ -928,11 +932,12 @@ export default function registerSubagentExtension(pi) {
|
|
|
928
932
|
}
|
|
929
933
|
state.activeAsyncCapacity = getActiveAsyncCapacitySnapshot(state.currentSessionId, resolveMaxActiveAsyncRunsPerSession(config.maxActiveAsyncRunsPerSession), { liveWorkflowRunIds: new Set(state.workflowControllers?.keys() ?? []), abandonedSlotReleaseAfterMs: resolveAbandonedSlotReleaseAfterMs(config.capacity?.abandonedSlotReleaseAfterMs) });
|
|
930
934
|
};
|
|
931
|
-
const resetSessionState = (ctx, recovering, previousSessionFile) => {
|
|
935
|
+
const resetSessionState = (ctx, recovering, startup, previousSessionFile) => {
|
|
932
936
|
state.widgetsSuspended = false;
|
|
933
937
|
state.baseCwd = ctx.cwd;
|
|
934
938
|
goalTurnId = 0;
|
|
935
939
|
state.currentSessionId = resolveCurrentSessionId(ctx.sessionManager);
|
|
940
|
+
recordSessionStart(state.currentSessionId, startup);
|
|
936
941
|
// Pi passes previousSessionFile only for new/resume/fork, after tearing that session down in this process.
|
|
937
942
|
if (previousSessionFile)
|
|
938
943
|
recordSessionReplacement(state.currentSessionId, previousSessionFile);
|
|
@@ -966,10 +971,10 @@ export default function registerSubagentExtension(pi) {
|
|
|
966
971
|
state.lastUiContext = ctx;
|
|
967
972
|
let phaseStartedAt = Date.now();
|
|
968
973
|
refreshActiveAsyncCapacity();
|
|
969
|
-
logSlowPhase("active-capacity", phaseStartedAt);
|
|
974
|
+
logSlowPhase(state, "active-capacity", phaseStartedAt);
|
|
970
975
|
phaseStartedAt = Date.now();
|
|
971
976
|
cleanupSessionArtifacts(ctx);
|
|
972
|
-
logSlowPhase("session-artifact-cleanup", phaseStartedAt);
|
|
977
|
+
logSlowPhase(state, "session-artifact-cleanup", phaseStartedAt);
|
|
973
978
|
state.foregroundControls.clear();
|
|
974
979
|
retainedNestedRouteTracker?.clear();
|
|
975
980
|
retainedNestedRouteTracker = undefined;
|
|
@@ -977,21 +982,21 @@ export default function registerSubagentExtension(pi) {
|
|
|
977
982
|
state.lastForegroundControlId = null;
|
|
978
983
|
phaseStartedAt = Date.now();
|
|
979
984
|
resetJobs(ctx);
|
|
980
|
-
logSlowPhase("reset-jobs", phaseStartedAt);
|
|
985
|
+
logSlowPhase(state, "reset-jobs", phaseStartedAt);
|
|
981
986
|
phaseStartedAt = Date.now();
|
|
982
987
|
// Runs other sessions in this folder left when their Pi died, from what this restore reads anyway.
|
|
983
988
|
const interruptedElsewhere = ctx.hasUI ? createInterruptedElsewhereCollector({ currentSessionId: state.currentSessionId, cwd: ctx.cwd, now: Date.now() }) : undefined;
|
|
984
989
|
restoreForegroundRunHistory(state, { resultsDir: DIRS.results, observeForeign: interruptedElsewhere?.observeForegroundRun });
|
|
985
|
-
logSlowPhase("foreground-history", phaseStartedAt);
|
|
990
|
+
logSlowPhase(state, "foreground-history", phaseStartedAt);
|
|
986
991
|
phaseStartedAt = Date.now();
|
|
987
992
|
restoreActiveJobs(ctx, interruptedElsewhere?.observeStatus);
|
|
988
|
-
logSlowPhase("active-job-restore", phaseStartedAt);
|
|
993
|
+
logSlowPhase(state, "active-job-restore", phaseStartedAt);
|
|
989
994
|
phaseStartedAt = Date.now();
|
|
990
995
|
// Read-only and UI-only: never sent to the model, so prompts and history are unchanged.
|
|
991
996
|
if (interruptedElsewhere)
|
|
992
997
|
for (const line of interruptedElsewhere.lines())
|
|
993
998
|
ctx.ui.notify(line, "info");
|
|
994
|
-
logSlowPhase("cross-session-notice", phaseStartedAt);
|
|
999
|
+
logSlowPhase(state, "cross-session-notice", phaseStartedAt);
|
|
995
1000
|
// Before any stored result is delivered, so the interrupted run's notice can name its resume.
|
|
996
1001
|
phaseStartedAt = Date.now();
|
|
997
1002
|
// Launches an earlier session start of this runtime planned and has not started belong to that session.
|
|
@@ -1002,22 +1007,22 @@ export default function registerSubagentExtension(pi) {
|
|
|
1002
1007
|
void launchWorkflowAutoResume(entry, ctx);
|
|
1003
1008
|
}
|
|
1004
1009
|
}
|
|
1005
|
-
logSlowPhase("workflow-auto-resume", phaseStartedAt);
|
|
1010
|
+
logSlowPhase(state, "workflow-auto-resume", phaseStartedAt);
|
|
1006
1011
|
phaseStartedAt = Date.now();
|
|
1007
1012
|
scheduledRunManager.bindSession(ctx);
|
|
1008
|
-
logSlowPhase("scheduled-runs", phaseStartedAt);
|
|
1013
|
+
logSlowPhase(state, "scheduled-runs", phaseStartedAt);
|
|
1009
1014
|
phaseStartedAt = Date.now();
|
|
1010
1015
|
restoreSlashFinalSnapshots(ctx.sessionManager.getEntries());
|
|
1011
|
-
logSlowPhase("slash-snapshots", phaseStartedAt);
|
|
1016
|
+
logSlowPhase(state, "slash-snapshots", phaseStartedAt);
|
|
1012
1017
|
phaseStartedAt = Date.now();
|
|
1013
1018
|
waitSubscriptionManager.restore();
|
|
1014
|
-
logSlowPhase("wait-subscriptions", phaseStartedAt);
|
|
1019
|
+
logSlowPhase(state, "wait-subscriptions", phaseStartedAt);
|
|
1015
1020
|
phaseStartedAt = Date.now();
|
|
1016
1021
|
startResultWatcher();
|
|
1017
|
-
logSlowPhase("result-watcher-start", phaseStartedAt);
|
|
1022
|
+
logSlowPhase(state, "result-watcher-start", phaseStartedAt);
|
|
1018
1023
|
phaseStartedAt = Date.now();
|
|
1019
1024
|
primeExistingResults({ triggerTurn: !recovering });
|
|
1020
|
-
logSlowPhase("result-prime", phaseStartedAt);
|
|
1025
|
+
logSlowPhase(state, "result-prime", phaseStartedAt);
|
|
1021
1026
|
fleetStatus?.setContext(ctx);
|
|
1022
1027
|
};
|
|
1023
1028
|
// Snapshot the injectable-agent advertisement once per session so the
|
|
@@ -1060,6 +1065,12 @@ export default function registerSubagentExtension(pi) {
|
|
|
1060
1065
|
if (runtimeCleaned)
|
|
1061
1066
|
return;
|
|
1062
1067
|
runtimeCleaned = true;
|
|
1068
|
+
sessionSwitchGuard.dispose();
|
|
1069
|
+
++advertisementGeneration;
|
|
1070
|
+
advertisementLookup?.abort();
|
|
1071
|
+
advertisedAgents = [];
|
|
1072
|
+
advertisedContext = undefined;
|
|
1073
|
+
notifySessionChange();
|
|
1063
1074
|
// Synchronously, so a reload's new runtime finds these runs unclaimed when it scans.
|
|
1064
1075
|
cancelPendingWorkflowAutoResumes((entry) => entry.owner === autoResumeOwner);
|
|
1065
1076
|
programStatus.dispose(shutdownReason);
|
|
@@ -1238,7 +1249,7 @@ export default function registerSubagentExtension(pi) {
|
|
|
1238
1249
|
scheduleModulePreload();
|
|
1239
1250
|
const recovering = event.reason === "startup" || event.reason === "reload" || event.reason === "resume";
|
|
1240
1251
|
disposeGoalAutoContinueGate();
|
|
1241
|
-
resetSessionState(ctx, recovering, event.previousSessionFile);
|
|
1252
|
+
resetSessionState(ctx, recovering, event.reason === "startup", event.previousSessionFile);
|
|
1242
1253
|
refreshContextInjectionSnapshot(ctx);
|
|
1243
1254
|
disposeGoalAutoContinueGate = registerGoalAutoContinueGate(pi, {
|
|
1244
1255
|
state,
|
|
@@ -1273,12 +1284,15 @@ export default function registerSubagentExtension(pi) {
|
|
|
1273
1284
|
supervisorChannel.activateTransport();
|
|
1274
1285
|
});
|
|
1275
1286
|
pi.on("session_shutdown", async (event) => {
|
|
1287
|
+
// Captured first: runtimeEntry.cleanup() below clears state.parentSessionFile.
|
|
1288
|
+
const parentSessionFile = state.parentSessionFile ?? undefined;
|
|
1289
|
+
sessionSwitchGuard.sessionShutdown(event);
|
|
1276
1290
|
cancelCompactionResume();
|
|
1277
1291
|
completionNotifier.sessionShutdown(event?.reason);
|
|
1278
1292
|
parentWake.sessionShutdown(event?.reason);
|
|
1279
1293
|
runtimeEntry.cleanup(event?.reason);
|
|
1280
1294
|
try {
|
|
1281
|
-
await
|
|
1295
|
+
await disposeChildSessionsForParent(parentSessionFile);
|
|
1282
1296
|
}
|
|
1283
1297
|
catch (error) {
|
|
1284
1298
|
console.error("Failed to dispose in-process child sessions:", error);
|
|
@@ -44,6 +44,7 @@ export interface PublicSubagentExecutionParams {
|
|
|
44
44
|
suppressRoutineResultIntercom?: unknown;
|
|
45
45
|
runFanoutBudget?: unknown;
|
|
46
46
|
runFanoutAdmitted?: unknown;
|
|
47
|
+
requireLauncher?: unknown;
|
|
47
48
|
}
|
|
48
49
|
export type PublicSubagentExecutionMode = "workflow" | "management";
|
|
49
50
|
export type PublicSubagentExecutionNormalization<T> = {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { normalizeWorktreeBaseRef } from "../runs/shared/worktree.js";
|
|
2
|
+
import { REQUIRE_LAUNCHER_SHAPE_ERROR } from "../runs/shared/runner-launcher.js";
|
|
2
3
|
const RAW_SCRIPT_FORMS = "workflow: true or a workflow script path";
|
|
3
4
|
const REMOVED_WORKFLOW_SCRIPT = "workflowScript was removed; write the script in one ```js workflow block in this reply and call subagent({ workflow: true }), or pass a script file as workflow: \"./path/to/script.js\".";
|
|
4
5
|
const REMOVED_WORKFLOW_SCRIPT_PATH = "workflowScriptPath was removed; pass the script file as workflow: \"./path/to/script.js\" (a workflow value containing '/' is a path).";
|
|
@@ -108,6 +109,9 @@ export function normalizePublicSubagentExecution(params, options = {}) {
|
|
|
108
109
|
return { ok: false, error: "action must be a non-empty management/control action, or omit action and use workflow.", mode: "management" };
|
|
109
110
|
}
|
|
110
111
|
const normalizedAction = typeof action === "string" ? action.trim() : undefined;
|
|
112
|
+
if (params.requireLauncher !== undefined && (normalizedAction !== undefined || hasWorkflowInput || params.tasks !== undefined || params.chain !== undefined || params.parallel !== undefined || params.resume !== undefined)) {
|
|
113
|
+
return { ok: false, error: REQUIRE_LAUNCHER_SHAPE_ERROR, mode: normalizedAction !== undefined ? "management" : "workflow" };
|
|
114
|
+
}
|
|
111
115
|
if (params.baseRef !== undefined && normalizedAction !== undefined && normalizedAction !== "resume" && normalizedAction !== "schedule.create") {
|
|
112
116
|
return { ok: false, error: "baseRef is only supported for child execution, resume, and schedule.create.", mode: "management" };
|
|
113
117
|
}
|
|
@@ -20,17 +20,37 @@ export function readReplyWorkflowScript(sessionManager, toolCallId) {
|
|
|
20
20
|
continue;
|
|
21
21
|
if (!message.content.some((block) => block.type === "toolCall" && block.id === toolCallId))
|
|
22
22
|
continue;
|
|
23
|
-
return scriptFromReply(message.content);
|
|
23
|
+
return scriptFromReply(message.content, () => earlierTurnHasJsBlock(branch, index));
|
|
24
24
|
}
|
|
25
25
|
return { error: "workflow: true only works from a model subagent tool call whose assistant message contains the ```js workflow block; other callers must pass a script path such as workflow: \"./script.js\"." };
|
|
26
26
|
}
|
|
27
|
-
|
|
27
|
+
/** Whether an assistant message earlier in this turn (after the last user message) holds a js block. */
|
|
28
|
+
function earlierTurnHasJsBlock(branch, callIndex) {
|
|
29
|
+
for (let index = callIndex - 1; index >= 0; index--) {
|
|
30
|
+
const entry = branch[index];
|
|
31
|
+
if (entry.type !== "message")
|
|
32
|
+
continue;
|
|
33
|
+
if (entry.message?.role === "user")
|
|
34
|
+
return false;
|
|
35
|
+
if (entry.message?.role !== "assistant" || !Array.isArray(entry.message.content))
|
|
36
|
+
continue;
|
|
37
|
+
const text = entry.message.content.flatMap((block) => block.type === "text" && typeof block.text === "string" ? [block.text] : []).join("\n");
|
|
38
|
+
const { tagged, plain } = workflowBlocks(text);
|
|
39
|
+
if (tagged.length > 0 || plain.length > 0)
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
function scriptFromReply(content, earlierBlock) {
|
|
28
45
|
const replyCalls = content.filter((block) => block.type === "toolCall" && block.name === "subagent"
|
|
29
46
|
&& (block.arguments?.workflow === true || block.arguments?.workflow === "true")).length;
|
|
30
47
|
if (replyCalls > 1)
|
|
31
48
|
return { error: `This reply has ${replyCalls} subagent calls with workflow: true; a reply can carry only one. Pass other scripts as workflow file paths.` };
|
|
32
|
-
if (!content.some((block) => block.type === "text"))
|
|
33
|
-
|
|
49
|
+
if (!content.some((block) => block.type === "text")) {
|
|
50
|
+
if (earlierBlock())
|
|
51
|
+
return { error: "The assistant message that issued this call has no text. A ```js block is in an earlier message of this turn, but workflow: true reads only the message that issues the call. Pass that script's source as options: { script: \"...\" } in place of workflow: true, with the call's other fields unchanged, or write the block and the call in one message." };
|
|
52
|
+
return { error: `The assistant message that issued this call has no text in the session, so no \`\`\`js workflow block reached it. ${SUMMARY_NOTE}` };
|
|
53
|
+
}
|
|
34
54
|
const text = content.flatMap((block) => block.type === "text" && typeof block.text === "string" ? [block.text] : []).join("\n");
|
|
35
55
|
const { tagged, plain, unclosed } = workflowBlocks(text);
|
|
36
56
|
if (unclosed)
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* TypeBox schemas for subagent tool parameters
|
|
3
|
-
*/
|
|
4
1
|
import { Type } from "typebox";
|
|
5
2
|
import type { DisabledFeatureSurface } from "../shared/disabled-features.ts";
|
|
6
3
|
/** Full flat parameter shape accepted by RPC, slash, scheduled and workflow callers. */
|
|
@@ -10,6 +7,7 @@ export declare const SubagentFlatParams: Type.TObject<{
|
|
|
10
7
|
extensionBindings: Type.TOptional<Type.TUnsafe<unknown>>;
|
|
11
8
|
action: Type.TOptional<Type.TString>;
|
|
12
9
|
capabilities: Type.TOptional<Type.TBoolean>;
|
|
10
|
+
search: Type.TOptional<Type.TString>;
|
|
13
11
|
name: Type.TOptional<Type.TString>;
|
|
14
12
|
id: Type.TOptional<Type.TString>;
|
|
15
13
|
runId: Type.TOptional<Type.TString>;
|
|
@@ -22,6 +20,7 @@ export declare const SubagentFlatParams: Type.TObject<{
|
|
|
22
20
|
supersession: Type.TOptional<Type.TUnsafe<unknown>>;
|
|
23
21
|
index: Type.TOptional<Type.TInteger>;
|
|
24
22
|
childId: Type.TOptional<Type.TString>;
|
|
23
|
+
drain: Type.TOptional<Type.TBoolean>;
|
|
25
24
|
toolCallId: Type.TOptional<Type.TString>;
|
|
26
25
|
view: Type.TOptional<Type.TString>;
|
|
27
26
|
lines: Type.TOptional<Type.TInteger>;
|
|
@@ -104,6 +103,10 @@ export declare const SubagentFlatParams: Type.TObject<{
|
|
|
104
103
|
agentScope: Type.TOptional<Type.TString>;
|
|
105
104
|
cwd: Type.TOptional<Type.TString>;
|
|
106
105
|
machine: Type.TOptional<Type.TString>;
|
|
106
|
+
requireLauncher: Type.TOptional<Type.TObject<{
|
|
107
|
+
name: Type.TString;
|
|
108
|
+
definitionDigest: Type.TString;
|
|
109
|
+
}>>;
|
|
107
110
|
artifacts: Type.TOptional<Type.TBoolean>;
|
|
108
111
|
includeProgress: Type.TOptional<Type.TBoolean>;
|
|
109
112
|
share: Type.TOptional<Type.TBoolean>;
|
|
@@ -139,6 +142,7 @@ export declare const SUBAGENT_OPTION_KEYS: readonly string[];
|
|
|
139
142
|
export declare const SubagentOptionParams: Type.TObject<{
|
|
140
143
|
extensionBindings: Type.TOptional<Type.TUnsafe<unknown>>;
|
|
141
144
|
capabilities: Type.TOptional<Type.TBoolean>;
|
|
145
|
+
search: Type.TOptional<Type.TString>;
|
|
142
146
|
name: Type.TOptional<Type.TString>;
|
|
143
147
|
dir: Type.TOptional<Type.TString>;
|
|
144
148
|
handoffPath: Type.TOptional<Type.TString>;
|
|
@@ -149,6 +153,7 @@ export declare const SubagentOptionParams: Type.TObject<{
|
|
|
149
153
|
supersession: Type.TOptional<Type.TUnsafe<unknown>>;
|
|
150
154
|
index: Type.TOptional<Type.TInteger>;
|
|
151
155
|
childId: Type.TOptional<Type.TString>;
|
|
156
|
+
drain: Type.TOptional<Type.TBoolean>;
|
|
152
157
|
toolCallId: Type.TOptional<Type.TString>;
|
|
153
158
|
view: Type.TOptional<Type.TString>;
|
|
154
159
|
lines: Type.TOptional<Type.TInteger>;
|
|
@@ -223,6 +228,10 @@ export declare const SubagentOptionParams: Type.TObject<{
|
|
|
223
228
|
}>>;
|
|
224
229
|
agentScope: Type.TOptional<Type.TString>;
|
|
225
230
|
machine: Type.TOptional<Type.TString>;
|
|
231
|
+
requireLauncher: Type.TOptional<Type.TObject<{
|
|
232
|
+
name: Type.TString;
|
|
233
|
+
definitionDigest: Type.TString;
|
|
234
|
+
}>>;
|
|
226
235
|
artifacts: Type.TOptional<Type.TBoolean>;
|
|
227
236
|
includeProgress: Type.TOptional<Type.TBoolean>;
|
|
228
237
|
share: Type.TOptional<Type.TBoolean>;
|
package/src/extension/schemas.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* TypeBox schemas for subagent tool parameters
|
|
3
|
-
*/
|
|
4
1
|
import { Type } from "typebox";
|
|
2
|
+
import { RUNNER_LAUNCHER_NAME_PATTERN } from "../shared/types.js";
|
|
5
3
|
import { MAX_ARGS_BYTES, MAX_ARGS_DEPTH, MAX_ARGS_FIELDS, MAX_ARGS_ITEMS } from "../workflows/workflow-resources.js";
|
|
6
4
|
function keepTopLevelParameterDescriptions(schema) {
|
|
7
5
|
return pruneNestedDescriptions(schema, []);
|
|
@@ -143,6 +141,7 @@ const SubagentParamProperties = {
|
|
|
143
141
|
description: "Management/control only; omit for execution. validate accepts workflow: true or a script path. Discover actions with {action:\"guide\",options:{topic:\"tool-reference\"}}."
|
|
144
142
|
})),
|
|
145
143
|
capabilities: Type.Optional(Type.Boolean({ description: "list: compact capability rows/details without system prompts." })),
|
|
144
|
+
search: Type.Optional(Type.String({ minLength: 1, description: "list: case-insensitive match on agent name, alias, or description." })),
|
|
146
145
|
name: Type.Optional(Type.String({ description: "schedule.create name." })),
|
|
147
146
|
id: Type.Optional(Type.String({
|
|
148
147
|
description: "Run id/prefix for status/control."
|
|
@@ -161,6 +160,7 @@ const SubagentParamProperties = {
|
|
|
161
160
|
supersession: Type.Optional(Type.Unsafe({ type: "object", additionalProperties: true, description: "lane.recordSupersession evidence; read guide tool-reference." })),
|
|
162
161
|
index: Type.Optional(Type.Integer({ minimum: 0, description: "Zero-based child/transcript index." })),
|
|
163
162
|
childId: Type.Optional(Type.String({ minLength: 1, maxLength: 256, description: "Child-scoped stop identity." })),
|
|
163
|
+
drain: Type.Optional(Type.Boolean({ description: "stop: a live async workflow starts no new children; started ones finish." })),
|
|
164
164
|
toolCallId: Type.Optional(Type.String({ description: "Command tool-call id." })),
|
|
165
165
|
view: Type.Optional(Type.String({
|
|
166
166
|
enum: ["fleet", "transcript"],
|
|
@@ -228,6 +228,10 @@ const SubagentParamProperties = {
|
|
|
228
228
|
agentScope: Type.Optional(Type.String({ description: "user/project/both (default); project wins collisions." })),
|
|
229
229
|
cwd: Type.Optional(Type.String({ description: "Execution/project-pane directory." })),
|
|
230
230
|
machine: Type.Optional(Type.String({ minLength: 1, maxLength: 128, description: "Herdr saved machine id or label (runs an external CLI agent), a Rex host named in settings (runs a Pi child), or \"local\" (a Pi child in a Rex pane here). On another machine, cwd is a directory there." })),
|
|
231
|
+
requireLauncher: Type.Optional(Type.Object({
|
|
232
|
+
name: Type.String({ pattern: RUNNER_LAUNCHER_NAME_PATTERN.source }),
|
|
233
|
+
definitionDigest: Type.String({ pattern: "^[0-9a-f]{64}$" }),
|
|
234
|
+
}, { additionalProperties: false, description: "Top-level single async launch only: refuse unless the agent runs under this launcher with this definition digest (preflight agent.definitionDigest)." })),
|
|
231
235
|
artifacts: Type.Optional(Type.Boolean({ description: "Debug artifacts; default true." })),
|
|
232
236
|
includeProgress: Type.Optional(Type.Boolean({ description: "Full result progress; default false." })),
|
|
233
237
|
share: Type.Optional(Type.Boolean({ description: "Upload session to GitHub Gist; default false." })),
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ExtensionContext, SessionShutdownEvent } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import type { SubagentState } from "../shared/types.ts";
|
|
3
|
+
type SwitchReason = "new" | "resume" | "fork";
|
|
4
|
+
export type SessionSwitchContext = Pick<ExtensionContext, "mode" | "hasUI"> & {
|
|
5
|
+
ui: Pick<ExtensionContext["ui"], "select" | "notify">;
|
|
6
|
+
};
|
|
7
|
+
interface SessionSwitchDeps {
|
|
8
|
+
state: SubagentState;
|
|
9
|
+
asyncDirRoot: string;
|
|
10
|
+
resultsDir: string;
|
|
11
|
+
hasPendingResults(): boolean;
|
|
12
|
+
hasPendingSupervisorRequest(): boolean;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Asks what happens to this session's outstanding background work when a UI session switches away. Without a UI or
|
|
16
|
+
* outstanding work the switch proceeds and the next session inherits the work. The prompt never enters model history.
|
|
17
|
+
*/
|
|
18
|
+
export declare function createSessionSwitchGuard(deps: SessionSwitchDeps): {
|
|
19
|
+
beforeSwitch(reason: SwitchReason, ctx: SessionSwitchContext): Promise<{
|
|
20
|
+
cancel: true;
|
|
21
|
+
} | undefined>;
|
|
22
|
+
sessionShutdown(event: SessionShutdownEvent): void;
|
|
23
|
+
dispose(): void;
|
|
24
|
+
};
|
|
25
|
+
export {};
|