pi-subagents 0.88.0 → 0.88.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 +18 -0
- package/bundle/child-tool-plan.js +2 -2
- package/bundle/{chunk-SVIXQDIV.js → chunk-4ZQBZDF3.js} +2 -2
- package/bundle/{chunk-YZPVALSQ.js → chunk-5EMPFFO4.js} +3 -3
- package/bundle/{chunk-CKLZ5FGU.js → chunk-6CG2VAG4.js} +1 -1
- package/bundle/{chunk-6EUQPQY7.js → chunk-7OX6O7DQ.js} +3 -3
- package/bundle/{chunk-3DT5X2QC.js → chunk-CPSUJHZE.js} +11 -8
- package/bundle/{chunk-3MFYKBKI.js → chunk-D32H53HM.js} +3 -3
- package/bundle/{chunk-PJSOS2Q4.js → chunk-DSHQWGHO.js} +1 -1
- package/bundle/{chunk-4PM6RDE5.js → chunk-FLNDHNPE.js} +46 -28
- package/bundle/{chunk-RHYVKQQL.js → chunk-LV3CPYXJ.js} +2 -2
- package/bundle/{chunk-47GJDBIK.js → chunk-N6TAAIB3.js} +2 -2
- package/bundle/{chunk-4UGWHREQ.js → chunk-PCZEQQAQ.js} +75 -40
- package/bundle/{chunk-IZEKQEY4.js → chunk-PYKBTBY6.js} +23 -6
- package/bundle/{chunk-6PR44R7E.js → chunk-RMZAAXIR.js} +1 -1
- package/bundle/{chunk-UVDLJXL6.js → chunk-VTUUOLM4.js} +3 -3
- package/bundle/{chunk-CTPAE36Y.js → chunk-YARY7JWU.js} +22 -0
- package/bundle/{chunk-MTPICU4A.js → chunk-YQSTGPEU.js} +7 -7
- package/bundle/{chunk-XAOHLFJO.js → chunk-ZJ2BT5TI.js} +21 -16
- package/bundle/index.js +1 -1
- package/bundle/preflight.js +4 -4
- package/bundle/required-child-extensions.js +1 -1
- package/docs/agents.md +4 -2
- package/docs/workflows.md +3 -1
- package/package.json +1 -1
- package/src/extension/index.d.ts +1 -1
- package/src/extension/index.js +43 -20
- package/src/extension/subagent-launch-tool.d.ts +6 -2
- package/src/extension/subagent-launch-tool.js +13 -9
- package/src/runs/background/stale-run-reconciler.js +17 -8
- package/src/runs/foreground/subagent-executor.js +11 -6
- package/src/runs/shared/child-launch.js +6 -3
- package/src/runs/shared/child-session.d.ts +1 -1
- package/src/runs/shared/child-session.js +3 -27
- package/src/runs/shared/mcp-direct-tool-allowlist.d.ts +5 -3
- package/src/runs/shared/mcp-direct-tool-allowlist.js +5 -4
- package/src/shared/compaction-interruption.d.ts +9 -0
- package/src/shared/compaction-interruption.js +47 -0
- package/src/shared/parent-wake.d.ts +3 -2
- package/src/shared/parent-wake.js +14 -3
- package/src/shared/required-child-extensions.d.ts +2 -0
- package/src/shared/required-child-extensions.js +27 -0
- package/src/tui/fleet.d.ts +7 -2
- package/src/tui/fleet.js +22 -0
|
@@ -7,32 +7,32 @@ import {
|
|
|
7
7
|
safeTranscriptEvent,
|
|
8
8
|
steerAsyncRun,
|
|
9
9
|
steerWorkflowForegroundTarget
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-7OX6O7DQ.js";
|
|
11
11
|
import {
|
|
12
12
|
FLEET_STATUS_WIDGET_KEY,
|
|
13
13
|
runningTone,
|
|
14
14
|
stepTaskSummary
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-5EMPFFO4.js";
|
|
16
16
|
import {
|
|
17
17
|
foregroundChildStateLabel,
|
|
18
18
|
formatAsyncRunTranscript,
|
|
19
19
|
stopAsyncRun
|
|
20
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-LV3CPYXJ.js";
|
|
21
21
|
import {
|
|
22
22
|
contextModeBadge,
|
|
23
23
|
contextModeLabel,
|
|
24
24
|
decodeUtf8Tail,
|
|
25
25
|
listAsyncRuns
|
|
26
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-4ZQBZDF3.js";
|
|
27
27
|
import {
|
|
28
28
|
reportSessionWarning
|
|
29
29
|
} from "./chunk-HXRB42AF.js";
|
|
30
|
-
import "./chunk-
|
|
30
|
+
import "./chunk-CPSUJHZE.js";
|
|
31
31
|
import "./chunk-W6HIYD2Z.js";
|
|
32
32
|
import "./chunk-NIXWDZZV.js";
|
|
33
33
|
import "./chunk-47ZN7NKR.js";
|
|
34
34
|
import "./chunk-7F6RKT6W.js";
|
|
35
|
-
import "./chunk-
|
|
35
|
+
import "./chunk-YARY7JWU.js";
|
|
36
36
|
import "./chunk-7J4ZXMY7.js";
|
|
37
37
|
import {
|
|
38
38
|
getArtifactPaths,
|
|
@@ -940,6 +940,10 @@ var SubagentFleetComponent = class {
|
|
|
940
940
|
actionBusy = false;
|
|
941
941
|
transcriptCache;
|
|
942
942
|
disposed = false;
|
|
943
|
+
// Undefined until a TUI first focuses the overlay, so a fleet rendered outside one still draws.
|
|
944
|
+
hasFocus;
|
|
945
|
+
// The component focused when the fleet opened (the overlay's preFocus).
|
|
946
|
+
openedOver;
|
|
943
947
|
refreshTimer;
|
|
944
948
|
refreshMs;
|
|
945
949
|
tui;
|
|
@@ -951,6 +955,7 @@ var SubagentFleetComponent = class {
|
|
|
951
955
|
keybindings;
|
|
952
956
|
constructor(tui, theme, state, done, options = {}) {
|
|
953
957
|
this.tui = tui;
|
|
958
|
+
this.openedOver = tui.getFocusedComponent?.();
|
|
954
959
|
this.viewport = new FleetViewport(() => this.tui.requestRender());
|
|
955
960
|
this.theme = theme;
|
|
956
961
|
this.markdownTheme = options.markdownTheme ?? getMarkdownTheme();
|
|
@@ -1120,6 +1125,14 @@ var SubagentFleetComponent = class {
|
|
|
1120
1125
|
scrollDetail(delta) {
|
|
1121
1126
|
this.viewport.scroll.scrollBy(delta);
|
|
1122
1127
|
}
|
|
1128
|
+
get focused() {
|
|
1129
|
+
return this.hasFocus === true;
|
|
1130
|
+
}
|
|
1131
|
+
set focused(value) {
|
|
1132
|
+
if (value === this.hasFocus) return;
|
|
1133
|
+
this.hasFocus = value;
|
|
1134
|
+
this.tui.requestRender();
|
|
1135
|
+
}
|
|
1123
1136
|
handleMouse(event) {
|
|
1124
1137
|
if (this.steerDraft !== void 0 || this.redoGuidanceDraft !== void 0 || this.stopConfirming || this.actionBusy) {
|
|
1125
1138
|
return { handled: true, render: false };
|
|
@@ -1417,6 +1430,10 @@ var SubagentFleetComponent = class {
|
|
|
1417
1430
|
return { header: [], body: this.withActionLines(lines) };
|
|
1418
1431
|
}
|
|
1419
1432
|
render(width) {
|
|
1433
|
+
if (this.hasFocus === false && this.tui.getFocusedComponent?.() !== this.openedOver) {
|
|
1434
|
+
this.renderedLayout = void 0;
|
|
1435
|
+
return [];
|
|
1436
|
+
}
|
|
1420
1437
|
const layout = fleetLayout(width, this.tui.terminal?.rows ?? 32, this.selected, this.snapshot.items);
|
|
1421
1438
|
this.renderedLayout = layout;
|
|
1422
1439
|
if (!layout) return [truncateToWidth2("Subagent fleet needs at least 36 columns. Esc closes.", width)];
|
|
@@ -14,11 +14,11 @@ import {
|
|
|
14
14
|
resolveCurrentSessionId,
|
|
15
15
|
resolveWatchdogReviewModel,
|
|
16
16
|
startWatchdogDiffBaselineCapture
|
|
17
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-N6TAAIB3.js";
|
|
18
18
|
import {
|
|
19
19
|
agentStreamOptions,
|
|
20
20
|
opencodeSessionHeaders
|
|
21
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-4ZQBZDF3.js";
|
|
22
22
|
import {
|
|
23
23
|
registerNativeSupervisorClient
|
|
24
24
|
} from "./chunk-CYKNHFXB.js";
|
|
@@ -27,7 +27,7 @@ import {
|
|
|
27
27
|
} from "./chunk-HXRB42AF.js";
|
|
28
28
|
import {
|
|
29
29
|
inheritedNestedRouteOf
|
|
30
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-CPSUJHZE.js";
|
|
31
31
|
import {
|
|
32
32
|
CHILD_WATCHDOG_STATUS_EVENT,
|
|
33
33
|
DEFAULT_WAIT_TOOL_NAME,
|
|
@@ -68,6 +68,27 @@ function assertRequiredChildExtensionsAdmitted(snapshots, launch) {
|
|
|
68
68
|
const route = launch.machine ? `machine '${launch.machine}'` : launch.runnerType !== void 0 && launch.runnerType !== "pi" ? `runner.type='${launch.runnerType}'` : void 0;
|
|
69
69
|
if (route) throw new Error(`Agent '${launch.agent}' cannot run on ${route}: the host requires child extensions (${ids.join(", ")}) for every runner, and only local native Pi children load them.`);
|
|
70
70
|
}
|
|
71
|
+
function childExtensionFileIdentity(extensionPath) {
|
|
72
|
+
if (!path.isAbsolute(extensionPath)) return void 0;
|
|
73
|
+
try {
|
|
74
|
+
const stat = fs.statSync(extensionPath, { bigint: true });
|
|
75
|
+
return stat.isFile() ? `${stat.dev}:${stat.ino}` : void 0;
|
|
76
|
+
} catch {
|
|
77
|
+
return void 0;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
function createRequiredChildExtensionIdentity(requiredPaths) {
|
|
81
|
+
const aliases = new Map([...requiredPaths].map((extensionPath) => [extensionPath, childExtensionFileIdentity(extensionPath) ?? extensionPath]));
|
|
82
|
+
const identities = new Set(aliases.values());
|
|
83
|
+
return (extensionPath) => {
|
|
84
|
+
const known = aliases.get(extensionPath);
|
|
85
|
+
if (known !== void 0) return known;
|
|
86
|
+
const identity = childExtensionFileIdentity(extensionPath);
|
|
87
|
+
if (identity === void 0 || !identities.has(identity)) return void 0;
|
|
88
|
+
aliases.set(extensionPath, identity);
|
|
89
|
+
return identity;
|
|
90
|
+
};
|
|
91
|
+
}
|
|
71
92
|
function hasMandatoryRequiredChildExtensions(snapshot) {
|
|
72
93
|
return snapshot?.some((entry) => entry.requireForAllRunners) === true;
|
|
73
94
|
}
|
|
@@ -88,6 +109,7 @@ export {
|
|
|
88
109
|
registerRequiredChildExtensions,
|
|
89
110
|
resolveRequiredChildExtensions,
|
|
90
111
|
assertRequiredChildExtensionsAdmitted,
|
|
112
|
+
createRequiredChildExtensionIdentity,
|
|
91
113
|
hasMandatoryRequiredChildExtensions,
|
|
92
114
|
writeRetainedRequiredChildExtensions,
|
|
93
115
|
readRetainedRequiredChildExtensions
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
2
|
rewriteSubagentPrompt
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-VTUUOLM4.js";
|
|
4
4
|
import {
|
|
5
5
|
package_default
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-6CG2VAG4.js";
|
|
7
7
|
import {
|
|
8
8
|
WATCHDOG_DIFF_TOOL_NAME,
|
|
9
9
|
captureWatchdogDiffBaseline,
|
|
10
10
|
createWatchdogDiffTool
|
|
11
|
-
} from "./chunk-
|
|
12
|
-
import "./chunk-
|
|
11
|
+
} from "./chunk-N6TAAIB3.js";
|
|
12
|
+
import "./chunk-4ZQBZDF3.js";
|
|
13
13
|
import "./chunk-CYKNHFXB.js";
|
|
14
14
|
import {
|
|
15
15
|
MODEL_ONLY_TOOL
|
|
@@ -18,14 +18,14 @@ import "./chunk-W2BZS6UC.js";
|
|
|
18
18
|
import {
|
|
19
19
|
appendAgentRefinementOverlay
|
|
20
20
|
} from "./chunk-XIA5GSEU.js";
|
|
21
|
-
import "./chunk-
|
|
21
|
+
import "./chunk-CPSUJHZE.js";
|
|
22
22
|
import "./chunk-NIXWDZZV.js";
|
|
23
23
|
import "./chunk-47ZN7NKR.js";
|
|
24
24
|
import "./chunk-7F6RKT6W.js";
|
|
25
25
|
import {
|
|
26
26
|
assertNoToolModifierEntries
|
|
27
|
-
} from "./chunk-
|
|
28
|
-
import "./chunk-
|
|
27
|
+
} from "./chunk-D32H53HM.js";
|
|
28
|
+
import "./chunk-YARY7JWU.js";
|
|
29
29
|
import "./chunk-YDZ7BZD5.js";
|
|
30
30
|
import {
|
|
31
31
|
HERDR_PI_MAX_FRAME_BYTES,
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
projectRuntimeAcknowledgedExtensions,
|
|
4
4
|
registerSubagentPromptBoundary,
|
|
5
5
|
registerSubagentPromptRuntime
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-VTUUOLM4.js";
|
|
7
7
|
import {
|
|
8
8
|
INSPECTOR_ACTIONS,
|
|
9
9
|
canQueueRetainedAsyncFollowUp,
|
|
@@ -25,7 +25,7 @@ import {
|
|
|
25
25
|
updateSteeringTarget,
|
|
26
26
|
waitForSteeringAction,
|
|
27
27
|
workflowAsyncChildSteeringGuidance
|
|
28
|
-
} from "./chunk-
|
|
28
|
+
} from "./chunk-7OX6O7DQ.js";
|
|
29
29
|
import {
|
|
30
30
|
PLACED_RESTORE_UNSUPPORTED,
|
|
31
31
|
formatHerdrMachineRunnerUnsupported,
|
|
@@ -119,7 +119,7 @@ import {
|
|
|
119
119
|
workflowScriptDigest,
|
|
120
120
|
workflowStopCause,
|
|
121
121
|
writeWorkflowReceipt
|
|
122
|
-
} from "./chunk-
|
|
122
|
+
} from "./chunk-PCZEQQAQ.js";
|
|
123
123
|
import {
|
|
124
124
|
SUBAGENT_PARENT_SESSION_ENV,
|
|
125
125
|
applyWatchdogLaunchRules,
|
|
@@ -132,7 +132,7 @@ import {
|
|
|
132
132
|
resolveWatchdogConfig,
|
|
133
133
|
sendRuleViolationWarning,
|
|
134
134
|
writeWatchdogModelSettings
|
|
135
|
-
} from "./chunk-
|
|
135
|
+
} from "./chunk-N6TAAIB3.js";
|
|
136
136
|
import {
|
|
137
137
|
MAX_REMEMBERED_FOREGROUND_RUNS,
|
|
138
138
|
discardRunningForegroundRun,
|
|
@@ -145,7 +145,7 @@ import {
|
|
|
145
145
|
resolveSubagentRunId,
|
|
146
146
|
resolveWorkflowChatProgress,
|
|
147
147
|
stopAsyncRun
|
|
148
|
-
} from "./chunk-
|
|
148
|
+
} from "./chunk-LV3CPYXJ.js";
|
|
149
149
|
import {
|
|
150
150
|
RunFanoutLimitError,
|
|
151
151
|
annotateWorkflowPreflightTrace,
|
|
@@ -206,7 +206,7 @@ import {
|
|
|
206
206
|
writeRunFanoutBudgetDescriptor,
|
|
207
207
|
writeWorkflowLaunchRecord,
|
|
208
208
|
writeWorktreeSetupHandoff
|
|
209
|
-
} from "./chunk-
|
|
209
|
+
} from "./chunk-4ZQBZDF3.js";
|
|
210
210
|
import {
|
|
211
211
|
NATIVE_SUPERVISOR_TOOL_NAME,
|
|
212
212
|
createNativeSupervisorChannel,
|
|
@@ -253,7 +253,7 @@ import {
|
|
|
253
253
|
resolveDisabledFeatureSurface,
|
|
254
254
|
resolveMaxActiveAsyncRunsPerSession,
|
|
255
255
|
transferActiveAsyncCapacity
|
|
256
|
-
} from "./chunk-
|
|
256
|
+
} from "./chunk-RMZAAXIR.js";
|
|
257
257
|
import {
|
|
258
258
|
DEFAULT_STALE_TERMINAL_ACTIVE_MARKER_MS,
|
|
259
259
|
MACHINE_DIFF_OPTIONS,
|
|
@@ -339,7 +339,7 @@ import {
|
|
|
339
339
|
writeNestedControlRequest,
|
|
340
340
|
writeNestedControlResult,
|
|
341
341
|
writeNestedEvent
|
|
342
|
-
} from "./chunk-
|
|
342
|
+
} from "./chunk-CPSUJHZE.js";
|
|
343
343
|
import {
|
|
344
344
|
closeSteerInbox,
|
|
345
345
|
consumeSteerRequests,
|
|
@@ -371,14 +371,15 @@ import {
|
|
|
371
371
|
resolvePiLaunchToolPlan,
|
|
372
372
|
resolveRuntimeModulePath,
|
|
373
373
|
supervisorChannelDir
|
|
374
|
-
} from "./chunk-
|
|
374
|
+
} from "./chunk-D32H53HM.js";
|
|
375
375
|
import {
|
|
376
376
|
assertRequiredChildExtensionsAdmitted,
|
|
377
|
+
createRequiredChildExtensionIdentity,
|
|
377
378
|
hasMandatoryRequiredChildExtensions,
|
|
378
379
|
readRetainedRequiredChildExtensions,
|
|
379
380
|
resolveRequiredChildExtensions,
|
|
380
381
|
writeRetainedRequiredChildExtensions
|
|
381
|
-
} from "./chunk-
|
|
382
|
+
} from "./chunk-YARY7JWU.js";
|
|
382
383
|
import {
|
|
383
384
|
HERDR_PROJECT_PANE_ACTIONS,
|
|
384
385
|
handleHerdrProjectPaneAction
|
|
@@ -1226,7 +1227,8 @@ function childProcessEnv(input, toolPlan) {
|
|
|
1226
1227
|
else if (!toolPlan.capabilityCeiling && input.mcpDirectTools?.length) env[MCP_DIRECT_TOOLS_ENV] = input.mcpDirectTools.join(",");
|
|
1227
1228
|
else if (toolPlan.capabilityCeiling && toolPlan.effectiveMcpSelections.length && !toolPlan.capabilityCeiling.denyExtensions) {
|
|
1228
1229
|
env[MCP_DIRECT_TOOLS_ENV] = toolPlan.effectiveMcpSelections.map((selection) => selection.selector).join(",");
|
|
1229
|
-
} else env[MCP_DIRECT_TOOLS_ENV] =
|
|
1230
|
+
} else if (input.tools === void 0 && !toolPlan.capabilityCeiling) env[MCP_DIRECT_TOOLS_ENV] = void 0;
|
|
1231
|
+
else env[MCP_DIRECT_TOOLS_ENV] = "__none__";
|
|
1230
1232
|
return env;
|
|
1231
1233
|
}
|
|
1232
1234
|
function childStorage(input) {
|
|
@@ -1268,7 +1270,8 @@ function buildInProcessChildLaunch(input) {
|
|
|
1268
1270
|
runtimeSnapshotHost: input.runtimeSnapshotHost
|
|
1269
1271
|
});
|
|
1270
1272
|
if (input.host === "parent" && input.runtimeSnapshotHost && toolPlan.builtinMcpTools?.length) {
|
|
1271
|
-
const
|
|
1273
|
+
const requiredExtensionIdentity = createRequiredChildExtensionIdentity(toolPlan.requiredExtensions.map(({ path: path19 }) => path19));
|
|
1274
|
+
const servers = extensionOnlyMcpServers(toolPlan.effectiveMcpSelections, input.runtimeSnapshotHost, input.cwd, input.projectTrusted !== false, (extensionPath) => requiredExtensionIdentity(extensionPath) !== void 0);
|
|
1272
1275
|
if (servers.length) throw new Error(`Agent '${input.childAgentName}' selects MCP tools from servers that extensions registered (${servers.join(", ")}). Only background children (async: true) load those extensions; run the agent in the background or add the server to the global mcp.json or a trusted project's .pi/mcp.json.`);
|
|
1273
1276
|
}
|
|
1274
1277
|
toolPlan.capabilityCeiling = intersectSubagentCapabilityCeilings(toolPlan.capabilityCeiling, agentCapabilityCeiling);
|
|
@@ -15065,8 +15068,9 @@ Parent action: ${COMPLETION_ACTION}` : content,
|
|
|
15065
15068
|
inheritedNestedRoute(deps2)?.rootRunId
|
|
15066
15069
|
);
|
|
15067
15070
|
preparedChildParams = childRequest;
|
|
15068
|
-
const
|
|
15069
|
-
if (
|
|
15071
|
+
const approval = await approveWorkflowChildLaunch(ctx, () => workflowChildLaunchArgs(workflowRunId, key, childRequest, childParams.agent, parentCwd, discoverWorkflowAgents), workflowSignal);
|
|
15072
|
+
if ("refusal" in approval) return buildRequestedModeError(childRequest, approval.refusal);
|
|
15073
|
+
if (approval.task !== void 0 && childRequest.action !== "resume") childRequest.task = approval.task;
|
|
15070
15074
|
if (workflowUsageBudget.budget) workflowOwnedUsageBudgets.set(childRequest, workflowUsageBudget.budget);
|
|
15071
15075
|
if (workflowRequiredExtensions) workflowRetainedRequiredExtensions.set(childRequest, workflowRequiredExtensions);
|
|
15072
15076
|
workflowLaunchObservers.set(childRequest, (launch) => {
|
|
@@ -15352,8 +15356,9 @@ Parent action: ${COMPLETION_ACTION}` : content,
|
|
|
15352
15356
|
inheritedNestedRoute(deps2)?.rootRunId
|
|
15353
15357
|
);
|
|
15354
15358
|
preparedChildParams = childRequest;
|
|
15355
|
-
const
|
|
15356
|
-
if (
|
|
15359
|
+
const approval = await approveWorkflowChildLaunch(ctx, () => workflowChildLaunchArgs(foregroundWorkflowRunId, key, childRequest, childParams.agent, ctx.cwd, discoverWorkflowAgents), workflowSignal);
|
|
15360
|
+
if ("refusal" in approval) return buildRequestedModeError(childRequest, approval.refusal);
|
|
15361
|
+
if (approval.task !== void 0 && childRequest.action !== "resume") childRequest.task = approval.task;
|
|
15357
15362
|
if (workflowUsageBudget.budget) workflowOwnedUsageBudgets.set(childRequest, workflowUsageBudget.budget);
|
|
15358
15363
|
if (workflowRequiredExtensions) workflowRetainedRequiredExtensions.set(childRequest, workflowRequiredExtensions);
|
|
15359
15364
|
if (delegatedWorkflowPermit) {
|
package/bundle/index.js
CHANGED
|
@@ -17,7 +17,7 @@ function readInstalledPackageVersion() {
|
|
|
17
17
|
var loadedPackageVersion = readInstalledPackageVersion();
|
|
18
18
|
|
|
19
19
|
// index.ts
|
|
20
|
-
var registerExtension = process.env[HERDR_PI_MODE_ENV] === "1" ? (await import("./chunk-
|
|
20
|
+
var registerExtension = process.env[HERDR_PI_MODE_ENV] === "1" ? (await import("./chunk-YQSTGPEU.js")).default : process.env.PI_SUBAGENT_CHILD === "1" ? void 0 : (await import("./chunk-FLNDHNPE.js")).default;
|
|
21
21
|
function registerSubagentExtension(pi) {
|
|
22
22
|
const installedVersion = readInstalledPackageVersion();
|
|
23
23
|
if (installedVersion !== loadedPackageVersion) {
|
package/bundle/preflight.js
CHANGED
|
@@ -6,13 +6,13 @@ import {
|
|
|
6
6
|
import "./chunk-XIA5GSEU.js";
|
|
7
7
|
import {
|
|
8
8
|
loadConfig
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-RMZAAXIR.js";
|
|
10
10
|
import {
|
|
11
11
|
nestedResultsPath,
|
|
12
12
|
processTerminalCandidatePath,
|
|
13
13
|
processTerminalPath,
|
|
14
14
|
resultFilePath
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-CPSUJHZE.js";
|
|
16
16
|
import {
|
|
17
17
|
applyIntercomBridgeToAgent,
|
|
18
18
|
resolveIntercomBridge,
|
|
@@ -26,11 +26,11 @@ import {
|
|
|
26
26
|
import {
|
|
27
27
|
applyThinkingSuffix,
|
|
28
28
|
resolvePiLaunchToolPlan
|
|
29
|
-
} from "./chunk-
|
|
29
|
+
} from "./chunk-D32H53HM.js";
|
|
30
30
|
import {
|
|
31
31
|
assertRequiredChildExtensionsAdmitted,
|
|
32
32
|
resolveRequiredChildExtensions
|
|
33
|
-
} from "./chunk-
|
|
33
|
+
} from "./chunk-YARY7JWU.js";
|
|
34
34
|
import {
|
|
35
35
|
getArtifactPaths,
|
|
36
36
|
getArtifactsDir
|
package/docs/agents.md
CHANGED
|
@@ -591,9 +591,11 @@ Examples:
|
|
|
591
591
|
|
|
592
592
|
### MCP tools
|
|
593
593
|
|
|
594
|
-
When [pi-mcp-adapter](https://github.com/nicobailon/pi-mcp-adapter) is not installed, `mcp:server` and `mcp:server/tool` entries resolve against Pi's built-in MCP. Name the server and tool as the server reports them: `mcp:my-docs/get-item` selects the tool Pi registers as `mcp__my_docs__get_item`. The server part may also use the `-`→`_` form of its name that Pi's MCP namespace uses, such as `mcp:my_docs`. The child connects the servers in Pi's `mcp.json` (the project's `.pi/mcp.json` only when the parent trusts the project) and gets only the selected tools, as direct tools, whatever exposure the server is configured with; tools configured as `hidden` cannot be selected. Servers that an extension adds with `pi.registerMcpServer()` work in background children, because the registering extension loads there too.
|
|
594
|
+
When [pi-mcp-adapter](https://github.com/nicobailon/pi-mcp-adapter) is not installed, `mcp:server` and `mcp:server/tool` entries resolve against Pi's built-in MCP. Name the server and tool as the server reports them: `mcp:my-docs/get-item` selects the tool Pi registers as `mcp__my_docs__get_item`. The server part may also use the `-`→`_` form of its name that Pi's MCP namespace uses, such as `mcp:my_docs`. The child connects the servers in Pi's `mcp.json` (the project's `.pi/mcp.json` only when the parent trusts the project) and gets only the selected tools, as direct tools, whatever exposure the server is configured with; tools configured as `hidden` cannot be selected. Servers that an extension adds with `pi.registerMcpServer()` work in background children, because the registering extension loads there too. Foreground children load no ambient extensions, so they get only the servers their required child extensions (see Required host extensions) register, and a foreground launch that selects a server from any other extension fails and says to use `async: true`. The child waits for the selected servers' current MCP connection attempts before its first prompt, then rejects the launch if any selected tool is missing or not available as a direct tool. Pi's MCP request timeout still bounds each connection; stopping, interrupting, timing out, or shutting down the child cancels the startup wait. An unrelated server does not delay this check.
|
|
595
595
|
|
|
596
|
-
When pi-mcp-adapter is installed, it keeps priority and provides the direct MCP tools.
|
|
596
|
+
When pi-mcp-adapter is installed, it keeps priority and provides the direct MCP tools. A background child with omitted `tools` and no capability ceiling uses the adapter's configured direct tools, including `directTools: true`. This also applies to agents that set only `excludeTools`: the child loads the configured tools, then excludes the listed names.
|
|
597
|
+
|
|
598
|
+
With an explicit `tools` allowlist, include `mcp:` entries for the direct MCP tools the child needs. A capability ceiling continues to restrict the child's MCP selections. The generic `mcp` proxy tool can still be used for discovery when available. The adapter caches tool metadata at startup, so after connecting a new MCP server for the first time, restart Pi before relying on direct tools. Selectors for servers explicitly configured with `disabled: true` are skipped; unknown servers and enabled servers without matching cached tools still fail the launch. Server `includeTools` and `excludeTools` policies are enforced while resolving cached metadata for children: both accept exact names and `*`/`?` glob patterns against raw, generated-resource, and server/short/mcp/none-prefixed names, with `excludeTools` taking precedence. `mcp:` entries must name servers from the adapter's configuration files. A server that exists only in the adapter's runtime snapshot (registered at runtime, not persisted) cannot be provided to a child: children are pi sessions inside the parent or the runner process, not `pi` processes that could receive an MCP config argument, so such a launch fails with an error saying that MCP tools must come from an ambient adapter extension in a background child. An `mcp:` entry named `subagent` does not authorize nested fanout; declare the builtin `subagent` tool or set `allowNestedSubagents: true`. If a resolved direct MCP name is missing from the child registry, pi-subagents keeps the launch failed under the strict allowlist and reports the registration mismatch; check the resolved names against what the host or pi-mcp-adapter actually registers before child startup.
|
|
597
599
|
|
|
598
600
|
### Extension loading
|
|
599
601
|
|
package/docs/workflows.md
CHANGED
|
@@ -149,7 +149,9 @@ The host resolves the name and validates bounded plain-JSON `args` before starti
|
|
|
149
149
|
|
|
150
150
|
### Approving workflow children in permission extensions
|
|
151
151
|
|
|
152
|
-
Before a workflow starts a child, pi-subagents makes a nested `subagent_launch` tool call, so permission extensions see it in their `tool_call` handler like any other tool call. This covers reply-block, file and named workflows, and `chain` and `tasks`. The call's input is `{ workflowRunId, key, agent?, task?, cwd?, model?, async?, worktree?, resume?, commands?, output? }`. `cwd` is the absolute directory the child starts in. It is left out for a resumed child, which keeps its earlier directory, and for a child placed on another machine. `commands` lists, in run order, the shell commands the child's `gate`, `acceptance.verify` or agent `acceptance` will run on this machine after the child finishes, each `{ command, cwd?, env? }`. A command's `cwd` is absolute and is left out when the child's is; for a `worktree: true` child it names the source directory, because the worktree does not exist yet. `env` lists only the variables the command sets on top of the parent's environment. `output` is the absolute path of the file the child's `output` writes. The other optional fields appear when the child request sets them. A blocked or failed call stops that child, so its commands never run and its output file is never written; it fails with `Workflow child '<key>' was not started: …` and the block reason.
|
|
152
|
+
Before a workflow starts a child, pi-subagents makes a nested `subagent_launch` tool call, so permission extensions see it in their `tool_call` handler like any other tool call. This covers reply-block, file and named workflows, and `chain` and `tasks`. The call's input is `{ workflowRunId, key, agent?, task?, cwd?, model?, async?, worktree?, resume?, commands?, output? }`. `cwd` is the absolute directory the child starts in. It is left out for a resumed child, which keeps its earlier directory, and for a child placed on another machine. `commands` lists, in run order, the shell commands the child's `gate`, `acceptance.verify` or agent `acceptance` will run on this machine after the child finishes, each `{ command, cwd?, env? }`. A command's `cwd` is absolute and is left out when the child's is; for a `worktree: true` child it names the source directory, because the worktree does not exist yet. `env` lists only the variables the command sets on top of the parent's environment. `output` is the absolute path of the file the child's `output` writes. The other optional fields appear when the child request sets them. A blocked or failed call stops that child, so its commands never run and its output file is never written; it fails with `Workflow child '<key>' was not started: …` and the block reason. The tool is not declared to the model.
|
|
153
|
+
|
|
154
|
+
A handler may also change `task` in place (`event.input.task = …`). A freshly launched child then receives the changed text, after `{previous}` is filled in and before any fork preamble is added. Changes to any other field, and to a resumed child's message, are ignored. Handlers run in registration order, so one registered earlier sees the original text.
|
|
153
155
|
|
|
154
156
|
Extensions that ask about tools they have no rule for ask once per workflow child until you allow `subagent_launch`. Ones that deny unknown tools without a UI, as in `pi -p`, refuse every workflow child until you allow it.
|
|
155
157
|
|
package/package.json
CHANGED
package/src/extension/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
import { type HerdrStatusRun } from "../integrations/herdr-status.ts";
|
|
3
3
|
import { type SubagentState } from "../shared/types.ts";
|
|
4
4
|
export declare function projectActiveHerdrRuns(state: SubagentState): HerdrStatusRun[];
|
package/src/extension/index.js
CHANGED
|
@@ -2,6 +2,7 @@ import { randomUUID } from "node:crypto";
|
|
|
2
2
|
import * as fs from "node:fs";
|
|
3
3
|
import * as os from "node:os";
|
|
4
4
|
import * as path from "node:path";
|
|
5
|
+
import { AgentSession } from "@earendil-works/pi-coding-agent";
|
|
5
6
|
import { Box, Container, Spacer, Text } from "@earendil-works/pi-tui";
|
|
6
7
|
import { clearAgentDiscoveryCache, discoverAgentSnapshot, discoverAgents, discoverAgentsAll } from "../agents/agents.js";
|
|
7
8
|
import { resolveGlobalNpmRoot } from "../agents/global-npm-root.js";
|
|
@@ -13,6 +14,7 @@ import { cleanupAllArtifactDirs, cleanupOldArtifacts, getArtifactsDir } from "..
|
|
|
13
14
|
import { resolveCurrentSessionId } from "../shared/session-identity.js";
|
|
14
15
|
import { recordSessionReplacement, recordSessionStart } from "../shared/session-succession.js";
|
|
15
16
|
import { createSessionSwitchGuard } from "./session-switch.js";
|
|
17
|
+
import { compactionInProgress, compactionInterruptedRun, installCompactionInterruptionCapture, takeCompactionAbort } from "../shared/compaction-interruption.js";
|
|
16
18
|
import { reportSessionWarning } from "../shared/session-warnings.js";
|
|
17
19
|
import { getAgentDir } from "../shared/utils.js";
|
|
18
20
|
import { isStaleExtensionContextError, MODEL_ONLY_TOOL, withCachedUiContext } from "../shared/extension-context.js";
|
|
@@ -215,6 +217,7 @@ export default function registerSubagentExtension(pi) {
|
|
|
215
217
|
if (process.env[SUBAGENT_CHILD_ENV] === "1") {
|
|
216
218
|
return;
|
|
217
219
|
}
|
|
220
|
+
installCompactionInterruptionCapture(AgentSession);
|
|
218
221
|
const runtimeRegistry = getRuntimeRegistry();
|
|
219
222
|
setMainThinkingLevelSource(() => readMainThinkingLevel(() => pi.getThinkingLevel()));
|
|
220
223
|
DIRS.results = ensureAccessibleDir(DIRS.results);
|
|
@@ -747,7 +750,7 @@ export default function registerSubagentExtension(pi) {
|
|
|
747
750
|
try {
|
|
748
751
|
// The run is still active here, so its signal tells a user stop (Esc) apart from a finished or failed run.
|
|
749
752
|
// Pi skips agent_before_settle after an abort. Background runs keep going, but they must not restart the parent.
|
|
750
|
-
if (ctx.hasUI && ctx.signal?.aborted) {
|
|
753
|
+
if (ctx.hasUI && ctx.signal?.aborted && !takeCompactionAbort(ctx.sessionManager)) {
|
|
751
754
|
parentWake.userAborted();
|
|
752
755
|
const active = activeAsyncJobCount();
|
|
753
756
|
if (active > 0)
|
|
@@ -1110,7 +1113,12 @@ export default function registerSubagentExtension(pi) {
|
|
|
1110
1113
|
}
|
|
1111
1114
|
};
|
|
1112
1115
|
let compactionResumeTimer;
|
|
1113
|
-
|
|
1116
|
+
let compactionInterruptedParent = false;
|
|
1117
|
+
const cancelCompactionResume = () => {
|
|
1118
|
+
clearTimeout(compactionResumeTimer);
|
|
1119
|
+
compactionResumeTimer = undefined;
|
|
1120
|
+
compactionInterruptedParent = false;
|
|
1121
|
+
};
|
|
1114
1122
|
pi.on("agent_start", () => {
|
|
1115
1123
|
cancelCompactionResume();
|
|
1116
1124
|
parentWake.agentStarted();
|
|
@@ -1132,38 +1140,53 @@ export default function registerSubagentExtension(pi) {
|
|
|
1132
1140
|
if (event.reason !== "manual")
|
|
1133
1141
|
suspendWidgetsForCompaction();
|
|
1134
1142
|
});
|
|
1135
|
-
//
|
|
1136
|
-
//
|
|
1137
|
-
//
|
|
1138
|
-
|
|
1143
|
+
// parentWake only appends wakes during a manual compaction. Once every overlapping compaction has ended, wake
|
|
1144
|
+
// the parent once if a wake was deferred, or if a successful compaction cut off a working parent with
|
|
1145
|
+
// background work (Pi never continues that run). Pi emits session_compact before it clears its compaction
|
|
1146
|
+
// state, so wait until the session is idle and compact() has returned. A run that starts first cancels it.
|
|
1147
|
+
const wakeAfterCompaction = (completed) => (event, ctx) => {
|
|
1139
1148
|
if (event.reason !== "manual")
|
|
1140
1149
|
return;
|
|
1141
|
-
|
|
1150
|
+
const sessionManager = ctx.sessionManager;
|
|
1151
|
+
if (completed && compactionInterruptedRun(sessionManager))
|
|
1152
|
+
compactionInterruptedParent = true;
|
|
1153
|
+
if (compactionResumeTimer)
|
|
1142
1154
|
return;
|
|
1143
|
-
cancelCompactionResume();
|
|
1144
1155
|
const sessionId = state.currentSessionId;
|
|
1145
1156
|
const deadline = Date.now() + COMPACTION_RESUME_DEADLINE_MS;
|
|
1146
|
-
const
|
|
1147
|
-
|
|
1157
|
+
const wakeWhenIdle = () => {
|
|
1158
|
+
compactionResumeTimer = undefined;
|
|
1159
|
+
if (state.currentSessionId !== sessionId)
|
|
1148
1160
|
return;
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1161
|
+
let idle;
|
|
1162
|
+
try {
|
|
1163
|
+
idle = ctx.isIdle();
|
|
1164
|
+
}
|
|
1165
|
+
catch {
|
|
1166
|
+
return; // Replaced or reloaded: the new session's runtime owns its notices.
|
|
1167
|
+
}
|
|
1168
|
+
// Past the deadline the next compaction event polls again.
|
|
1169
|
+
if (!idle || compactionInProgress(sessionManager)) {
|
|
1153
1170
|
if (Date.now() < deadline)
|
|
1154
|
-
compactionResumeTimer = setTimeout(
|
|
1171
|
+
compactionResumeTimer = setTimeout(wakeWhenIdle, COMPACTION_RESUME_POLL_MS);
|
|
1155
1172
|
return;
|
|
1156
1173
|
}
|
|
1157
|
-
|
|
1158
|
-
|
|
1174
|
+
const interrupted = compactionInterruptedParent && activeAsyncJobCount() > 0 && withLastUiContext(() => true) === true;
|
|
1175
|
+
compactionInterruptedParent = false;
|
|
1176
|
+
if (!parentWake.takeDeferredWake() && !interrupted)
|
|
1177
|
+
return;
|
|
1159
1178
|
parentWake.sendMessage({
|
|
1160
1179
|
customType: "subagent-compaction-resume",
|
|
1161
|
-
content:
|
|
1180
|
+
content: interrupted
|
|
1181
|
+
? "Compaction is complete. Resume the parent task now; background subagent results will arrive separately when ready."
|
|
1182
|
+
: "Compaction is complete. Act on the background subagent notices above.",
|
|
1162
1183
|
display: false,
|
|
1163
1184
|
}, { triggerTurn: true });
|
|
1164
1185
|
};
|
|
1165
|
-
compactionResumeTimer = setTimeout(
|
|
1166
|
-
}
|
|
1186
|
+
compactionResumeTimer = setTimeout(wakeWhenIdle, COMPACTION_RESUME_POLL_MS);
|
|
1187
|
+
};
|
|
1188
|
+
pi.on("session_compact", wakeAfterCompaction(true));
|
|
1189
|
+
pi.on("session_compact_failed", wakeAfterCompaction(false));
|
|
1167
1190
|
pi.on("session_start", (event, ctx) => {
|
|
1168
1191
|
parentWake.bindSession(ctx);
|
|
1169
1192
|
completionNotifier.bindSession(ctx.sessionManager);
|
|
@@ -20,6 +20,10 @@ declare const parameters: Type.TObject<{
|
|
|
20
20
|
export type SubagentLaunchArgs = Static<typeof parameters>;
|
|
21
21
|
/** Not declared to the model, so the system prompt and tool list stay unchanged. */
|
|
22
22
|
export declare function registerSubagentLaunchTool(pi: ExtensionAPI): void;
|
|
23
|
-
/** Offers a workflow child start to the session's `tool_call` handlers; returns the refusal,
|
|
24
|
-
export declare function approveWorkflowChildLaunch(ctx: ExtensionContext, describe: () => SubagentLaunchArgs, signal: AbortSignal): Promise<
|
|
23
|
+
/** Offers a workflow child start to the session's `tool_call` handlers; returns the refusal, or the task the handlers left. */
|
|
24
|
+
export declare function approveWorkflowChildLaunch(ctx: ExtensionContext, describe: () => SubagentLaunchArgs, signal: AbortSignal): Promise<{
|
|
25
|
+
refusal: string;
|
|
26
|
+
} | {
|
|
27
|
+
task?: string;
|
|
28
|
+
}>;
|
|
25
29
|
export {};
|
|
@@ -22,27 +22,31 @@ export function registerSubagentLaunchTool(pi) {
|
|
|
22
22
|
pi.registerTool({
|
|
23
23
|
name: SUBAGENT_LAUNCH_TOOL,
|
|
24
24
|
label: "Subagent launch",
|
|
25
|
-
description: "A workflow is about to start this subagent. Blocking this call stops that child from starting.",
|
|
25
|
+
description: "A workflow is about to start this subagent. Blocking this call stops that child from starting; changing its task changes what the child is told.",
|
|
26
26
|
parameters,
|
|
27
27
|
exposure: "deferred",
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
// Pi hands execute the input after every tool_call handler ran, so a handler's change to task arrives here.
|
|
29
|
+
async execute(_toolCallId, params) {
|
|
30
|
+
return { content: [{ type: "text", text: "Records approval for a workflow child launch; it starts nothing itself." }], details: { task: params.task } };
|
|
30
31
|
},
|
|
31
32
|
});
|
|
32
33
|
}
|
|
33
|
-
/** Offers a workflow child start to the session's `tool_call` handlers; returns the refusal,
|
|
34
|
+
/** Offers a workflow child start to the session's `tool_call` handlers; returns the refusal, or the task the handlers left. */
|
|
34
35
|
export async function approveWorkflowChildLaunch(ctx, describe, signal) {
|
|
35
36
|
// Starts with no tool call behind them (schedule ticks, auto-resume, RPC) have no executeTool, and a tool
|
|
36
37
|
// allowlist that leaves the tool out unregisters it: no handler could see the call in either case.
|
|
37
38
|
if (!("executeTool" in ctx))
|
|
38
|
-
return
|
|
39
|
+
return {};
|
|
39
40
|
const toolCtx = ctx;
|
|
40
41
|
if (!toolCtx.tools.some((tool) => tool.name === SUBAGENT_LAUNCH_TOOL))
|
|
41
|
-
return
|
|
42
|
+
return {};
|
|
42
43
|
const args = describe();
|
|
43
44
|
const outcome = await toolCtx.executeTool(SUBAGENT_LAUNCH_TOOL, args, { signal });
|
|
44
|
-
if (!outcome.isError)
|
|
45
|
-
|
|
45
|
+
if (!outcome.isError) {
|
|
46
|
+
// Pi doesn't validate the input again after a handler changes it.
|
|
47
|
+
const task = outcome.result.details?.task;
|
|
48
|
+
return { task: typeof task === "string" ? task : undefined };
|
|
49
|
+
}
|
|
46
50
|
const reason = outcome.result.content.flatMap((block) => block.type === "text" ? [block.text] : []).join("\n").trim();
|
|
47
|
-
return `Workflow child '${args.key}' was not started: the ${SUBAGENT_LAUNCH_TOOL} call was refused${reason ? `: ${reason}` : "."}
|
|
51
|
+
return { refusal: `Workflow child '${args.key}' was not started: the ${SUBAGENT_LAUNCH_TOOL} call was refused${reason ? `: ${reason}` : "."}` };
|
|
48
52
|
}
|