pi-subagents 0.84.0 → 0.85.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +62 -0
- package/bundle/agents.js +3 -3
- package/bundle/child-tool-plan.js +2 -2
- package/bundle/{chunk-235AWJUQ.js → chunk-3UZ5FVVJ.js} +310 -101
- package/bundle/{chunk-F4ASL6OV.js → chunk-7MAE3DJV.js} +1 -1
- package/bundle/{chunk-4E7BKDTX.js → chunk-CS4O36CZ.js} +11 -156
- package/bundle/{chunk-VQVVHSY6.js → chunk-DV2NCNPR.js} +22 -11
- package/bundle/{chunk-G2Z6ZH26.js → chunk-GCSLVFCX.js} +1 -1
- package/bundle/{chunk-2S4K53MV.js → chunk-H2NLFTC5.js} +1 -1
- package/bundle/{chunk-NKQ6JNAS.js → chunk-HFTBF7SG.js} +2 -1
- package/bundle/chunk-HXRB42AF.js +108 -0
- package/bundle/{chunk-7BWGNDNK.js → chunk-IQIWF2VX.js} +190 -1177
- package/bundle/{chunk-XDQORLZ5.js → chunk-JNXT3MPI.js} +15 -6
- package/bundle/{chunk-J5YL7LYR.js → chunk-JO67XSKD.js} +59 -27
- package/bundle/{chunk-JG4QKI5M.js → chunk-JWYG26RE.js} +209 -93
- package/bundle/{chunk-C5P5CHYK.js → chunk-KDMFBYFM.js} +1 -1
- package/bundle/{chunk-V2BZYLEP.js → chunk-KEY3UQMQ.js} +7 -2
- package/bundle/{chunk-NENDSQUY.js → chunk-KZ34KQQH.js} +9 -6
- package/bundle/{chunk-AKOIVLA5.js → chunk-L2ENOFVZ.js} +76 -58
- package/bundle/{chunk-CGN2TVE7.js → chunk-LGMILZNE.js} +322 -18
- package/bundle/{chunk-L3WFKBEI.js → chunk-LTPH2DXH.js} +247 -153
- package/bundle/{chunk-2D52JFLF.js → chunk-N7B2KD74.js} +41 -117
- package/bundle/{chunk-PV63UFUR.js → chunk-O7CPL6H4.js} +183 -28
- package/bundle/{chunk-D3JAFGMO.js → chunk-PHZP3KHB.js} +1 -1
- package/bundle/{chunk-2DHZTCOL.js → chunk-PVIVCDG2.js} +2 -2
- package/bundle/{chunk-LFDBD4PW.js → chunk-QO75KJBT.js} +2 -2
- package/bundle/{chunk-SSG7IEP5.js → chunk-RQAUNAWG.js} +2 -2
- package/bundle/{chunk-PALJGGYC.js → chunk-RV5OGHLO.js} +6 -3
- package/bundle/chunk-T5V5BRCL.js +1067 -0
- package/bundle/{chunk-LNRJCP2Y.js → chunk-UX4SCV5N.js} +337 -207
- package/bundle/{chunk-DZDETGRJ.js → chunk-WOVMHDES.js} +231 -182
- package/bundle/control-channel.js +2 -2
- package/bundle/index.js +1 -1
- package/bundle/intercom-bridge.js +2 -2
- package/bundle/preflight.js +8 -8
- package/bundle/project-panes.js +3 -3
- package/docs/agents.md +17 -2
- package/docs/configuration.md +2 -2
- package/docs/extension-api.md +16 -1
- package/docs/workflows.md +30 -2
- package/package.json +1 -1
- package/src/agents/agent-management.js +27 -11
- package/src/agents/agent-memory.d.ts +1 -4
- package/src/agents/agent-memory.js +1 -4
- package/src/agents/agents.d.ts +1 -3
- package/src/agents/agents.js +7 -6
- 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/extension/config.js +7 -1
- package/src/extension/herdr-pi-bridge.js +10 -2
- package/src/extension/index.d.ts +0 -13
- package/src/extension/index.js +43 -32
- 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 +8 -3
- package/src/extension/schemas.js +5 -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 +25 -11
- package/src/extension/tool-description.js +6 -0
- 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 +5 -9
- package/src/runs/background/async-execution.js +62 -27
- 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 +112 -39
- package/src/runs/background/async-retention.js +6 -1
- 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 +0 -1
- package/src/runs/background/run-child-session.js +1 -1
- package/src/runs/background/run-status.js +4 -3
- package/src/runs/background/scheduled-runs.d.ts +3 -1
- package/src/runs/background/scheduled-runs.js +13 -16
- package/src/runs/background/subagent-runner.d.ts +2 -4
- package/src/runs/background/subagent-runner.js +9 -6
- 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-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/execution.d.ts +0 -3
- package/src/runs/foreground/execution.js +17 -9
- package/src/runs/foreground/subagent-executor.d.ts +3 -2
- package/src/runs/foreground/subagent-executor.js +107 -26
- 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 +1 -1
- package/src/runs/shared/child-session.js +21 -2
- 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-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 +48 -22
- package/src/runs/shared/lane-metadata.d.ts +0 -1
- package/src/runs/shared/lane-metadata.js +0 -1
- 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 +2 -2
- package/src/runs/shared/model-resolution.js +7 -1
- 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 +30 -2
- package/src/runs/shared/subagent-prompt-runtime.d.ts +0 -1
- package/src/runs/shared/subagent-prompt-runtime.js +4 -2
- 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/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 +51 -0
- package/src/shared/fleet-transcript-reader.js +333 -0
- package/src/shared/formatters.d.ts +0 -18
- package/src/shared/formatters.js +0 -18
- 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/types.d.ts +28 -11
- package/src/shared/types.js +0 -12
- package/src/shared/utils.d.ts +0 -14
- package/src/shared/utils.js +0 -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-status.d.ts +0 -5
- package/src/tui/fleet-status.js +4 -24
- package/src/tui/fleet-transcript.d.ts +1 -44
- package/src/tui/fleet-transcript.js +1 -327
- package/src/tui/fleet.js +6 -4
- package/src/tui/render.d.ts +0 -9
- package/src/tui/render.js +81 -47
- package/src/tui/subagent-messages.js +3 -2
- package/src/watchdog/register-child.d.ts +2 -3
- package/src/watchdog/register-child.js +2 -3
- package/src/watchdog/turn-delta.js +2 -1
- package/src/workflows/scripted-workflow.js +241 -20
- package/src/workflows/workflow-launch-record.d.ts +15 -6
- package/src/workflows/workflow-launch-record.js +30 -12
- package/src/workflows/workflow-resume-claim.js +2 -2
- package/src/workflows/workflow-resume.d.ts +1 -1
- package/src/workflows/workflow-resume.js +11 -8
- package/src/workflows/workflow-script-worker.d.ts +13 -0
- package/src/workflows/workflow-script-worker.js +79 -0
- package/workflow-script-process.cjs +36 -0
- package/workflow-script-worker.cjs +4 -1
|
@@ -10,10 +10,10 @@ import {
|
|
|
10
10
|
setInlineWorkflowCoverage,
|
|
11
11
|
setMainThinkingLevelSource,
|
|
12
12
|
widgetRenderKey
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-L2ENOFVZ.js";
|
|
14
14
|
import {
|
|
15
15
|
package_default
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-HFTBF7SG.js";
|
|
17
17
|
import {
|
|
18
18
|
EXTERNAL_JOB_BRIDGE_REQUEST_DIR,
|
|
19
19
|
REVIVAL_ORIGIN_FILE,
|
|
@@ -51,6 +51,7 @@ import {
|
|
|
51
51
|
registerInspectorEventListener,
|
|
52
52
|
registerMainWatchdog,
|
|
53
53
|
registerPiWebSessionLiveness,
|
|
54
|
+
registerSubagentLaunchTool,
|
|
54
55
|
registerSubagentNotify,
|
|
55
56
|
releaseWorkflowResumeClaim,
|
|
56
57
|
resolveSubagentResultStatus,
|
|
@@ -61,23 +62,16 @@ import {
|
|
|
61
62
|
snapshotProviderDiagnostics,
|
|
62
63
|
workflowResumeClaimState,
|
|
63
64
|
workflowResumeRefusal
|
|
64
|
-
} from "./chunk-
|
|
65
|
+
} from "./chunk-WOVMHDES.js";
|
|
65
66
|
import {
|
|
66
|
-
CONTACT_SUPERVISOR_TOOL_NAME,
|
|
67
|
-
NATIVE_SUPERVISOR_TOOL_NAME,
|
|
68
67
|
SUBAGENT_CHILD_ENV,
|
|
69
68
|
SUBAGENT_PARENT_SESSION_ENV,
|
|
70
|
-
SUPERVISOR_REPLY_ENTRY_TYPE,
|
|
71
|
-
SUPERVISOR_REQUEST_MESSAGE_TYPE,
|
|
72
69
|
SubagentFlatParams,
|
|
73
70
|
completionReplayPath,
|
|
74
|
-
createNativeSupervisorChannel,
|
|
75
71
|
createSubagentParamsSchema,
|
|
76
72
|
drainOutstandingWork,
|
|
77
73
|
finalizeToolResult,
|
|
78
74
|
normalizeWatchdogWarningDetails,
|
|
79
|
-
parseSupervisorReplyData,
|
|
80
|
-
parseSupervisorRequestDetails,
|
|
81
75
|
readCompletionArchive,
|
|
82
76
|
readCompletionReplay,
|
|
83
77
|
recordWaitCompletion,
|
|
@@ -87,38 +81,55 @@ import {
|
|
|
87
81
|
resolveCurrentSessionId,
|
|
88
82
|
resolvePiSessionId,
|
|
89
83
|
resolveWaitToolConfig,
|
|
90
|
-
setDeclarationPinning
|
|
91
|
-
|
|
92
|
-
} from "./chunk-7BWGNDNK.js";
|
|
84
|
+
setDeclarationPinning
|
|
85
|
+
} from "./chunk-IQIWF2VX.js";
|
|
93
86
|
import {
|
|
94
87
|
deliverAsyncRunStop,
|
|
95
88
|
ownerConfirmedDead,
|
|
96
89
|
readSessionMessagesTail,
|
|
97
90
|
resolveSubagentRunId,
|
|
98
91
|
restoreForegroundRunHistory
|
|
99
|
-
} from "./chunk-
|
|
92
|
+
} from "./chunk-KZ34KQQH.js";
|
|
100
93
|
import {
|
|
101
94
|
ASYNC_STATUS_SNAPSHOT_KIND,
|
|
102
95
|
ASYNC_STATUS_SNAPSHOT_VERSION,
|
|
103
|
-
MODEL_ONLY_TOOL,
|
|
104
|
-
canRenderComponents,
|
|
105
96
|
decodeUtf8Tail,
|
|
106
97
|
formatAsyncRunProgressLabel,
|
|
107
98
|
formatWorkflowPreflightSummary,
|
|
108
|
-
inheritedSessionIds,
|
|
109
|
-
isStaleExtensionContextError,
|
|
110
99
|
isStoppableAsyncStatusStep,
|
|
111
100
|
listAsyncRuns,
|
|
112
101
|
normalizeWorkflowPreflight,
|
|
113
|
-
ownerSessionIds,
|
|
114
|
-
ownsRun,
|
|
115
102
|
parseWorkflowChildSummary,
|
|
116
|
-
|
|
103
|
+
recoveryDescriptorPath,
|
|
117
104
|
resolveAsyncRunLocation,
|
|
118
105
|
resolveAsyncStatusChild,
|
|
119
|
-
|
|
106
|
+
runLaunchDir,
|
|
107
|
+
stopStoppableAsyncStatusChildren
|
|
108
|
+
} from "./chunk-LTPH2DXH.js";
|
|
109
|
+
import {
|
|
110
|
+
CONTACT_SUPERVISOR_TOOL_NAME,
|
|
111
|
+
NATIVE_SUPERVISOR_TOOL_NAME,
|
|
112
|
+
SUPERVISOR_REPLY_ENTRY_TYPE,
|
|
113
|
+
SUPERVISOR_REQUEST_MESSAGE_TYPE,
|
|
114
|
+
createNativeSupervisorChannel,
|
|
115
|
+
parseSupervisorReplyData,
|
|
116
|
+
parseSupervisorRequestDetails,
|
|
117
|
+
topLevelSupervisorTool
|
|
118
|
+
} from "./chunk-T5V5BRCL.js";
|
|
119
|
+
import {
|
|
120
|
+
MODEL_ONLY_TOOL,
|
|
121
|
+
canRenderComponents,
|
|
122
|
+
inheritedSessionIds,
|
|
123
|
+
isStaleExtensionContextError,
|
|
124
|
+
keepSessionWork,
|
|
125
|
+
ownerSessionIds,
|
|
126
|
+
ownsRun,
|
|
127
|
+
recordSessionReplacement,
|
|
128
|
+
recordSessionStart,
|
|
129
|
+
releaseSessionWork,
|
|
130
|
+
reportSessionWarning,
|
|
120
131
|
withCachedUiContext
|
|
121
|
-
} from "./chunk-
|
|
132
|
+
} from "./chunk-HXRB42AF.js";
|
|
122
133
|
import "./chunk-NF7IEKBH.js";
|
|
123
134
|
import {
|
|
124
135
|
disabledFeatureUseError,
|
|
@@ -129,7 +140,7 @@ import {
|
|
|
129
140
|
resolveDisabledFeatureSurface,
|
|
130
141
|
resolveMaxActiveAsyncRunsPerSession,
|
|
131
142
|
resolveScheduledStoreRoot
|
|
132
|
-
} from "./chunk-
|
|
143
|
+
} from "./chunk-RV5OGHLO.js";
|
|
133
144
|
import {
|
|
134
145
|
ACTIVE_RUN_INDEX_DIR,
|
|
135
146
|
MissionNotFoundError,
|
|
@@ -138,10 +149,12 @@ import {
|
|
|
138
149
|
acknowledgeMissionObserverSnapshot,
|
|
139
150
|
checkRecordedPidLiveness,
|
|
140
151
|
cleanupResultIndexes,
|
|
152
|
+
collectNestedRuns,
|
|
141
153
|
currentCompletionOwnerId,
|
|
142
154
|
encodeIndexSegment,
|
|
143
155
|
findNestedRouteForRootId,
|
|
144
156
|
hasLiveNestedDescendants,
|
|
157
|
+
isActiveAsyncState,
|
|
145
158
|
isRecordedPid,
|
|
146
159
|
isReusableWorkflowStopCause,
|
|
147
160
|
listMissions,
|
|
@@ -178,28 +191,28 @@ import {
|
|
|
178
191
|
withWorkflowChildRunModel,
|
|
179
192
|
writeAsyncResultFile,
|
|
180
193
|
writeResultIndexForData
|
|
181
|
-
} from "./chunk-
|
|
182
|
-
import "./chunk-
|
|
194
|
+
} from "./chunk-LGMILZNE.js";
|
|
195
|
+
import "./chunk-7MAE3DJV.js";
|
|
183
196
|
import {
|
|
184
197
|
shouldUseNativeFsWatch
|
|
185
198
|
} from "./chunk-NIXWDZZV.js";
|
|
186
199
|
import {
|
|
187
200
|
validateIntercomBridgeConfig
|
|
188
|
-
} from "./chunk-
|
|
201
|
+
} from "./chunk-KDMFBYFM.js";
|
|
189
202
|
import "./chunk-7F6RKT6W.js";
|
|
190
|
-
import "./chunk-
|
|
203
|
+
import "./chunk-KEY3UQMQ.js";
|
|
191
204
|
import "./chunk-CTPAE36Y.js";
|
|
192
205
|
import {
|
|
193
206
|
listHerdrProjectPaneRoots,
|
|
194
207
|
restoreHerdrProjectPaneSnapshots
|
|
195
|
-
} from "./chunk-
|
|
208
|
+
} from "./chunk-PVIVCDG2.js";
|
|
196
209
|
import "./chunk-7J4ZXMY7.js";
|
|
197
210
|
import {
|
|
198
211
|
cleanupAllArtifactDirs,
|
|
199
212
|
cleanupOldArtifacts,
|
|
200
213
|
getArtifactPaths,
|
|
201
214
|
getArtifactsDir
|
|
202
|
-
} from "./chunk-
|
|
215
|
+
} from "./chunk-PHZP3KHB.js";
|
|
203
216
|
import {
|
|
204
217
|
listBackgroundWorkProviders
|
|
205
218
|
} from "./chunk-XA3DY6UG.js";
|
|
@@ -207,14 +220,15 @@ import "./chunk-YYREO77V.js";
|
|
|
207
220
|
import "./chunk-UKG4V45O.js";
|
|
208
221
|
import {
|
|
209
222
|
registerRuntimeAgentEventListener
|
|
210
|
-
} from "./chunk-
|
|
223
|
+
} from "./chunk-H2NLFTC5.js";
|
|
211
224
|
import {
|
|
212
225
|
clearRuntimeAgentsForPi,
|
|
213
226
|
listRuntimeAgentConfigs,
|
|
214
227
|
mergeRuntimeAgents
|
|
215
|
-
} from "./chunk-
|
|
228
|
+
} from "./chunk-GCSLVFCX.js";
|
|
216
229
|
import {
|
|
217
230
|
DEFAULT_FILE_SYSTEM_RETRY_DELAYS_MS,
|
|
231
|
+
DEFAULT_WAIT_TOOL_NAME,
|
|
218
232
|
EXTRA_AGENT_DIRS_ENV,
|
|
219
233
|
FileLeaseBusyError,
|
|
220
234
|
SUBAGENT_WATCHDOG_WARNING_TYPE,
|
|
@@ -243,6 +257,7 @@ import {
|
|
|
243
257
|
resolveWatchPath,
|
|
244
258
|
runFileSystemOperationWithRetry,
|
|
245
259
|
serializeAgent,
|
|
260
|
+
setWaitToolName,
|
|
246
261
|
shortenPath,
|
|
247
262
|
splitKnownThinkingSuffix,
|
|
248
263
|
toModelInfo,
|
|
@@ -250,9 +265,10 @@ import {
|
|
|
250
265
|
validateOptionalMachine,
|
|
251
266
|
validateToolBudgetConfig,
|
|
252
267
|
waitForFileSystemRetry,
|
|
268
|
+
waitToolName,
|
|
253
269
|
withSettingsFileLease,
|
|
254
270
|
writeAtomicJson
|
|
255
|
-
} from "./chunk-
|
|
271
|
+
} from "./chunk-UX4SCV5N.js";
|
|
256
272
|
import {
|
|
257
273
|
DEFAULT_ARTIFACT_CONFIG,
|
|
258
274
|
DIRS,
|
|
@@ -307,6 +323,8 @@ import { exec, execFile } from "node:child_process";
|
|
|
307
323
|
import { promises as fs } from "node:fs";
|
|
308
324
|
import path from "node:path";
|
|
309
325
|
async function resolveGlobalNpmRoot(options = {}) {
|
|
326
|
+
const signal = options.signal;
|
|
327
|
+
if (signal?.aborted) return null;
|
|
310
328
|
const env = options.env ?? process.env;
|
|
311
329
|
const offline = env.PI_OFFLINE?.toLowerCase();
|
|
312
330
|
if (offline === "1" || offline === "true" || offline === "yes") return null;
|
|
@@ -317,6 +335,7 @@ async function resolveGlobalNpmRoot(options = {}) {
|
|
|
317
335
|
} catch {
|
|
318
336
|
}
|
|
319
337
|
}
|
|
338
|
+
if (signal?.aborted) return null;
|
|
320
339
|
const timeoutMs = options.timeoutMs ?? 5e3;
|
|
321
340
|
const output = await new Promise((resolve6) => {
|
|
322
341
|
let settled = false;
|
|
@@ -324,6 +343,7 @@ async function resolveGlobalNpmRoot(options = {}) {
|
|
|
324
343
|
if (settled) return;
|
|
325
344
|
settled = true;
|
|
326
345
|
clearTimeout(timer);
|
|
346
|
+
signal?.removeEventListener("abort", cancel);
|
|
327
347
|
resolve6(value);
|
|
328
348
|
};
|
|
329
349
|
const commandOptions = {
|
|
@@ -335,10 +355,12 @@ async function resolveGlobalNpmRoot(options = {}) {
|
|
|
335
355
|
};
|
|
336
356
|
const callback = (error, stdout) => finish(error ? null : stdout.trim());
|
|
337
357
|
const child = (options.platform ?? process.platform) === "win32" ? exec("npm root -g", commandOptions, callback) : execFile("npm", ["root", "-g"], commandOptions, callback);
|
|
338
|
-
const
|
|
358
|
+
const cancel = () => {
|
|
339
359
|
child.kill();
|
|
340
360
|
finish(null);
|
|
341
|
-
}
|
|
361
|
+
};
|
|
362
|
+
const timer = setTimeout(cancel, timeoutMs);
|
|
363
|
+
signal?.addEventListener("abort", cancel, { once: true });
|
|
342
364
|
});
|
|
343
365
|
if (!output) return null;
|
|
344
366
|
try {
|
|
@@ -433,6 +455,113 @@ function ensureAccessibleDir(dirPath, options = {}) {
|
|
|
433
455
|
}
|
|
434
456
|
}
|
|
435
457
|
|
|
458
|
+
// src/extension/session-switch.ts
|
|
459
|
+
var STAY = "Stay here";
|
|
460
|
+
var TAKE = "Switch and take the work";
|
|
461
|
+
var LEAVE = "Switch and leave the work here";
|
|
462
|
+
var RPC_PROMPT_TIMEOUT_MS = 6e4;
|
|
463
|
+
function createSessionSwitchGuard(deps) {
|
|
464
|
+
let leave;
|
|
465
|
+
let checking = false;
|
|
466
|
+
const lifetime = new AbortController();
|
|
467
|
+
const activeRunCount = (sessionId) => {
|
|
468
|
+
const runs = new Set(listAsyncRuns(deps.asyncDirRoot, {
|
|
469
|
+
sessionId,
|
|
470
|
+
states: ["queued", "running"],
|
|
471
|
+
resultsDir: deps.resultsDir,
|
|
472
|
+
includeNested: false
|
|
473
|
+
}).map((run) => run.id));
|
|
474
|
+
for (const job of deps.state.asyncJobs.values()) {
|
|
475
|
+
if (runs.has(job.asyncId) || !ownsRun(sessionId, job.sessionId) || !isActiveAsyncState(job.status)) continue;
|
|
476
|
+
let active = true;
|
|
477
|
+
try {
|
|
478
|
+
const status = readStatus(job.asyncDir);
|
|
479
|
+
active = !status || isActiveAsyncState(status.state);
|
|
480
|
+
} catch {
|
|
481
|
+
}
|
|
482
|
+
if (active) runs.add(job.asyncId);
|
|
483
|
+
}
|
|
484
|
+
for (const id of deps.state.workflowControllers?.keys() ?? []) runs.add(id);
|
|
485
|
+
return runs.size;
|
|
486
|
+
};
|
|
487
|
+
const hasNestedWork = (sessionId) => {
|
|
488
|
+
const routes = /* @__PURE__ */ new Map();
|
|
489
|
+
for (const job of deps.state.asyncJobs.values()) {
|
|
490
|
+
if (!ownsRun(sessionId, job.sessionId)) continue;
|
|
491
|
+
if (job.nestedRoute) routes.set(job.nestedRoute.rootRunId, job.nestedRoute);
|
|
492
|
+
else if (collectNestedRuns(job.nestedChildren).some((run) => isActiveAsyncState(run.state))) return true;
|
|
493
|
+
}
|
|
494
|
+
for (const control of deps.state.foregroundControls.values()) {
|
|
495
|
+
if (control.sessionId && !ownsRun(sessionId, control.sessionId)) continue;
|
|
496
|
+
if (control.nestedRoute) routes.set(control.nestedRoute.rootRunId, control.nestedRoute);
|
|
497
|
+
}
|
|
498
|
+
for (const route of deps.state.retainedForegroundNestedRoutes?.values() ?? []) routes.set(route.rootRunId, route);
|
|
499
|
+
if (deps.state.retainedNestedLookupRoutes?.sessionId === sessionId) {
|
|
500
|
+
for (const route of deps.state.retainedNestedLookupRoutes.routes.values()) routes.set(route.rootRunId, route);
|
|
501
|
+
}
|
|
502
|
+
return [...routes.values()].some((route) => {
|
|
503
|
+
reconcileNestedAsyncDescendants(route, { resultsDir: deps.resultsDir });
|
|
504
|
+
return collectNestedRuns(projectNestedEvents(route).children).some((run) => isActiveAsyncState(run.state));
|
|
505
|
+
});
|
|
506
|
+
};
|
|
507
|
+
return {
|
|
508
|
+
async beforeSwitch(reason, ctx) {
|
|
509
|
+
if (lifetime.signal.aborted || checking) return { cancel: true };
|
|
510
|
+
leave = void 0;
|
|
511
|
+
if (!ctx.hasUI) return;
|
|
512
|
+
checking = true;
|
|
513
|
+
try {
|
|
514
|
+
const sessionId = deps.state.currentSessionId;
|
|
515
|
+
if (!sessionId) throw new Error("The current session identity is unavailable.");
|
|
516
|
+
const runs = activeRunCount(sessionId);
|
|
517
|
+
const nested = hasNestedWork(sessionId);
|
|
518
|
+
const results = deps.hasPendingResults();
|
|
519
|
+
const questions = deps.hasPendingSupervisorRequest();
|
|
520
|
+
if (runs === 0 && !nested && !results && !questions) return;
|
|
521
|
+
const title = [
|
|
522
|
+
"pi-subagents: switch sessions?",
|
|
523
|
+
"",
|
|
524
|
+
"Background subagent work in this session:",
|
|
525
|
+
...runs > 0 ? [` ${runs} run${runs === 1 ? "" : "s"} queued or running`] : [],
|
|
526
|
+
...nested ? [" Nested subagents still running"] : [],
|
|
527
|
+
...results ? [" Undelivered results"] : [],
|
|
528
|
+
...questions ? [" Questions awaiting a reply"] : []
|
|
529
|
+
].join("\n");
|
|
530
|
+
const choice = await ctx.ui.select(title, [STAY, TAKE, LEAVE], { signal: lifetime.signal, timeout: ctx.mode === "rpc" ? RPC_PROMPT_TIMEOUT_MS : void 0 });
|
|
531
|
+
if (lifetime.signal.aborted || deps.state.currentSessionId !== sessionId) return { cancel: true };
|
|
532
|
+
if (choice === TAKE) return;
|
|
533
|
+
if (choice === LEAVE) {
|
|
534
|
+
leave = { sessionId, reason };
|
|
535
|
+
return;
|
|
536
|
+
}
|
|
537
|
+
return { cancel: true };
|
|
538
|
+
} catch (error) {
|
|
539
|
+
const message2 = error instanceof Error ? error.message : String(error);
|
|
540
|
+
try {
|
|
541
|
+
if (!lifetime.signal.aborted) ctx.ui.notify(`Session switch cancelled: ${message2}`, "warning");
|
|
542
|
+
} catch {
|
|
543
|
+
}
|
|
544
|
+
return { cancel: true };
|
|
545
|
+
} finally {
|
|
546
|
+
checking = false;
|
|
547
|
+
}
|
|
548
|
+
},
|
|
549
|
+
// Recorded only once the switch commits, so a switch another extension cancels keeps the default handoff.
|
|
550
|
+
sessionShutdown(event) {
|
|
551
|
+
const left = leave;
|
|
552
|
+
leave = void 0;
|
|
553
|
+
const sessionId = deps.state.currentSessionId;
|
|
554
|
+
if (!sessionId) return;
|
|
555
|
+
if (left && left.sessionId === sessionId && left.reason === event.reason) keepSessionWork(sessionId);
|
|
556
|
+
else releaseSessionWork(sessionId);
|
|
557
|
+
},
|
|
558
|
+
dispose() {
|
|
559
|
+
leave = void 0;
|
|
560
|
+
lifetime.abort();
|
|
561
|
+
}
|
|
562
|
+
};
|
|
563
|
+
}
|
|
564
|
+
|
|
436
565
|
// src/runs/background/async-job-tracker.ts
|
|
437
566
|
import * as fs3 from "node:fs";
|
|
438
567
|
import * as path2 from "node:path";
|
|
@@ -1054,7 +1183,17 @@ function createAsyncJobTracker(pi, state, asyncDirRoot, options = {}) {
|
|
|
1054
1183
|
if (now >= nextLivenessAt) {
|
|
1055
1184
|
nextLivenessAt = now + livenessIntervalMs;
|
|
1056
1185
|
let widgetChanged = false;
|
|
1186
|
+
const owners = state.currentSessionId ? ownerSessionIds(state.currentSessionId) : void 0;
|
|
1057
1187
|
for (const job of state.asyncJobs.values()) {
|
|
1188
|
+
if (owners && job.sessionId !== void 0 && !owners.has(job.sessionId)) {
|
|
1189
|
+
cancelCleanup(job.asyncId);
|
|
1190
|
+
closeJobWatcher(job.asyncId);
|
|
1191
|
+
state.asyncJobs.delete(job.asyncId);
|
|
1192
|
+
state.fleetJobs?.delete(job.asyncId);
|
|
1193
|
+
options.onJobCleanup?.(job.asyncId);
|
|
1194
|
+
widgetChanged = true;
|
|
1195
|
+
continue;
|
|
1196
|
+
}
|
|
1058
1197
|
watchJob(job);
|
|
1059
1198
|
if (refreshJob(job)) widgetChanged = true;
|
|
1060
1199
|
}
|
|
@@ -1287,7 +1426,7 @@ function hasNestedReferences(status) {
|
|
|
1287
1426
|
function hasResumableContract(runDir, status) {
|
|
1288
1427
|
const statusSessionFiles = [status.sessionFile, ...(status.steps ?? []).map((step) => step.sessionFile)];
|
|
1289
1428
|
if (statusSessionFiles.some(existingRegularFile)) return true;
|
|
1290
|
-
const descriptorPath = path3.
|
|
1429
|
+
const descriptorPath = recoveryDescriptorPath(path3.dirname(runDir), status.runId);
|
|
1291
1430
|
if (!fs4.existsSync(descriptorPath)) return false;
|
|
1292
1431
|
const descriptor = readJson(descriptorPath);
|
|
1293
1432
|
if (!descriptor) return true;
|
|
@@ -1836,6 +1975,7 @@ async function cleanupAsyncRetention(options) {
|
|
|
1836
1975
|
}
|
|
1837
1976
|
mutationStateChanged = true;
|
|
1838
1977
|
fs4.rmSync(runDir, { recursive: true });
|
|
1978
|
+
fs4.rmSync(runLaunchDir(options.asyncDirRoot, status.runId), { recursive: true, force: true });
|
|
1839
1979
|
removeRunTombstoneMarker(maintenanceRoot, status.runId);
|
|
1840
1980
|
result.reapedTombstones += 1;
|
|
1841
1981
|
deletedIds.push(`run-tombstone:${status.runId}`);
|
|
@@ -1865,6 +2005,7 @@ async function cleanupAsyncRetention(options) {
|
|
|
1865
2005
|
continue;
|
|
1866
2006
|
}
|
|
1867
2007
|
fs4.rmSync(tombstone, { recursive: true });
|
|
2008
|
+
fs4.rmSync(runLaunchDir(options.asyncDirRoot, status.runId), { recursive: true, force: true });
|
|
1868
2009
|
removeRunTombstoneMarker(maintenanceRoot, status.runId);
|
|
1869
2010
|
result.deletedRuns += 1;
|
|
1870
2011
|
deletedIds.push(`run:${status.runId}`);
|
|
@@ -2020,15 +2161,19 @@ function resultFileIdentity(raw, file) {
|
|
|
2020
2161
|
runId: file.replace(/\.json$/i, "")
|
|
2021
2162
|
};
|
|
2022
2163
|
}
|
|
2023
|
-
function
|
|
2164
|
+
function reportResultWatcherWarning(state, message2, error, key = message2) {
|
|
2165
|
+
const detail = error === void 0 ? "" : `: ${error instanceof Error ? error.message : String(error)}`;
|
|
2166
|
+
reportSessionWarning(state, `${message2}${detail}`, key);
|
|
2167
|
+
}
|
|
2168
|
+
function sanitizeNestedResultChildren(state, value, resultPath, label) {
|
|
2024
2169
|
if (value === void 0) return void 0;
|
|
2025
2170
|
if (!Array.isArray(value)) {
|
|
2026
|
-
|
|
2171
|
+
reportResultWatcherWarning(state, `Ignoring invalid nested children in subagent result file '${resultPath}' at ${label}: expected an array.`);
|
|
2027
2172
|
return void 0;
|
|
2028
2173
|
}
|
|
2029
2174
|
const children = value.map((child) => sanitizeSummary(child)).filter((child) => Boolean(child));
|
|
2030
2175
|
if (children.length !== value.length) {
|
|
2031
|
-
|
|
2176
|
+
reportResultWatcherWarning(state, `Ignoring ${value.length - children.length} invalid nested child record(s) in subagent result file '${resultPath}' at ${label}.`, void 0, `result-nested-records-invalid:${resultPath}:${label}`);
|
|
2032
2177
|
}
|
|
2033
2178
|
return children.length ? children : void 0;
|
|
2034
2179
|
}
|
|
@@ -2074,6 +2219,7 @@ function createResultWatcher(pi, state, resultsDir, completionTtlMs, deps = {})
|
|
|
2074
2219
|
let deliveringPending = 0;
|
|
2075
2220
|
const identityCache = /* @__PURE__ */ new Map();
|
|
2076
2221
|
const reportedMissionSyncFailures = /* @__PURE__ */ new Map();
|
|
2222
|
+
let missionSyncReports = 0;
|
|
2077
2223
|
let deliveryActive = true;
|
|
2078
2224
|
let deliveryEpoch = 0;
|
|
2079
2225
|
let resultScanTimer = null;
|
|
@@ -2096,7 +2242,7 @@ function createResultWatcher(pi, state, resultsDir, completionTtlMs, deps = {})
|
|
|
2096
2242
|
try {
|
|
2097
2243
|
return fsApi.statSync(publicResultPath(file)).isFile();
|
|
2098
2244
|
} catch (error) {
|
|
2099
|
-
if (!isAbsentResultCandidate(error))
|
|
2245
|
+
if (!isAbsentResultCandidate(error)) reportResultWatcherWarning(state, `Failed to inspect subagent result file '${publicResultPath(file)}'`, error);
|
|
2100
2246
|
return false;
|
|
2101
2247
|
}
|
|
2102
2248
|
};
|
|
@@ -2129,7 +2275,7 @@ function createResultWatcher(pi, state, resultsDir, completionTtlMs, deps = {})
|
|
|
2129
2275
|
} catch (error) {
|
|
2130
2276
|
identityCache.delete(file);
|
|
2131
2277
|
if (isAccessDenied(error)) throw error;
|
|
2132
|
-
if (!isAbsentResultCandidate(error))
|
|
2278
|
+
if (!isAbsentResultCandidate(error)) reportResultWatcherWarning(state, `Failed to inspect subagent result file '${resultPath}'`, error);
|
|
2133
2279
|
return void 0;
|
|
2134
2280
|
}
|
|
2135
2281
|
};
|
|
@@ -2147,7 +2293,7 @@ function createResultWatcher(pi, state, resultsDir, completionTtlMs, deps = {})
|
|
|
2147
2293
|
} catch (error) {
|
|
2148
2294
|
identityCache.delete(file);
|
|
2149
2295
|
if (isAccessDenied(error)) throw error;
|
|
2150
|
-
if (!isAbsentResultCandidate(error))
|
|
2296
|
+
if (!isAbsentResultCandidate(error)) reportResultWatcherWarning(state, `Failed to inspect subagent result file '${resultPath}'`, error);
|
|
2151
2297
|
return void 0;
|
|
2152
2298
|
}
|
|
2153
2299
|
};
|
|
@@ -2155,7 +2301,7 @@ function createResultWatcher(pi, state, resultsDir, completionTtlMs, deps = {})
|
|
|
2155
2301
|
try {
|
|
2156
2302
|
return new Set(deps.observedCompletionRunIds?.() ?? []);
|
|
2157
2303
|
} catch (error) {
|
|
2158
|
-
|
|
2304
|
+
reportResultWatcherWarning(state, "Failed to inspect observed subagent completion ids", error);
|
|
2159
2305
|
return /* @__PURE__ */ new Set();
|
|
2160
2306
|
}
|
|
2161
2307
|
};
|
|
@@ -2175,7 +2321,7 @@ function createResultWatcher(pi, state, resultsDir, completionTtlMs, deps = {})
|
|
|
2175
2321
|
if (retireResultSnapshot(publicResultPath(file), read, void 0, CLEANUP_LEASE_WAIT_MS) === "replaced") scheduleResult(file, triggerTurn);
|
|
2176
2322
|
} catch (error) {
|
|
2177
2323
|
if (isAbsentResultCandidate(error)) return;
|
|
2178
|
-
if (!(error instanceof FileLeaseBusyError))
|
|
2324
|
+
if (!(error instanceof FileLeaseBusyError)) reportResultWatcherWarning(state, `Failed to remove delivered subagent result '${publicResultPath(file)}'; will retry`, error);
|
|
2179
2325
|
scheduleResult(file, triggerTurn, RETRY_DELAY_MS);
|
|
2180
2326
|
}
|
|
2181
2327
|
};
|
|
@@ -2190,7 +2336,7 @@ function createResultWatcher(pi, state, resultsDir, completionTtlMs, deps = {})
|
|
|
2190
2336
|
}
|
|
2191
2337
|
} catch (error) {
|
|
2192
2338
|
if (!isAccessDenied(error)) throw error;
|
|
2193
|
-
|
|
2339
|
+
reportResultWatcherWarning(state, `Failed to inspect subagent result file '${publicResultPath(file)}'; will retry`, error);
|
|
2194
2340
|
scheduleResult(file, triggerTurn, RETRY_DELAY_MS);
|
|
2195
2341
|
return;
|
|
2196
2342
|
}
|
|
@@ -2238,7 +2384,7 @@ function createResultWatcher(pi, state, resultsDir, completionTtlMs, deps = {})
|
|
|
2238
2384
|
if (!resultSnapshotReplaced(publicResultPath(file), read)) return false;
|
|
2239
2385
|
} catch (error) {
|
|
2240
2386
|
if (isAccessDenied(error)) throw error;
|
|
2241
|
-
|
|
2387
|
+
reportResultWatcherWarning(state, `Failed to re-read subagent result file '${publicResultPath(file)}'`, error);
|
|
2242
2388
|
}
|
|
2243
2389
|
identityCache.delete(file);
|
|
2244
2390
|
rereadReplacedPayload = true;
|
|
@@ -2253,21 +2399,21 @@ function createResultWatcher(pi, state, resultsDir, completionTtlMs, deps = {})
|
|
|
2253
2399
|
const message2 = error instanceof Error ? error.message : String(error);
|
|
2254
2400
|
if (reportedMissionSyncFailures.get(file) !== message2) {
|
|
2255
2401
|
reportedMissionSyncFailures.set(file, message2);
|
|
2256
|
-
|
|
2402
|
+
reportResultWatcherWarning(state, `Mission completion sync failed for '${resultPath}'`, error, `result-mission-sync-failed:${++missionSyncReports}`);
|
|
2257
2403
|
}
|
|
2258
2404
|
}
|
|
2259
2405
|
try {
|
|
2260
2406
|
deps.observeCompletion?.({ ...data, runId });
|
|
2261
2407
|
} catch (error) {
|
|
2262
2408
|
observerSucceeded = false;
|
|
2263
|
-
|
|
2409
|
+
reportResultWatcherWarning(state, `Completion observer failed for '${resultPath}'`, error);
|
|
2264
2410
|
}
|
|
2265
2411
|
if (observerSucceeded) {
|
|
2266
2412
|
try {
|
|
2267
2413
|
if (acknowledgeMissionObserverSnapshot(publicResultPath(file), read, CLEANUP_LEASE_WAIT_MS) === "replaced") rereadReplacedPayload = true;
|
|
2268
2414
|
} catch (error) {
|
|
2269
2415
|
observerSucceeded = false;
|
|
2270
|
-
if (!(error instanceof FileLeaseBusyError))
|
|
2416
|
+
if (!(error instanceof FileLeaseBusyError)) reportResultWatcherWarning(state, `Failed to acknowledge the mission observer for '${resultPath}'; will retry`, error);
|
|
2271
2417
|
}
|
|
2272
2418
|
}
|
|
2273
2419
|
const epoch = deliveryEpoch;
|
|
@@ -2277,12 +2423,12 @@ function createResultWatcher(pi, state, resultsDir, completionTtlMs, deps = {})
|
|
|
2277
2423
|
sessionId
|
|
2278
2424
|
});
|
|
2279
2425
|
const hasExplicitNestedChildren = data.nestedChildren !== void 0;
|
|
2280
|
-
let nestedChildren = compactNestedResultChildren(sanitizeNestedResultChildren(data.nestedChildren, resultPath, "nestedChildren"));
|
|
2426
|
+
let nestedChildren = compactNestedResultChildren(sanitizeNestedResultChildren(state, data.nestedChildren, resultPath, "nestedChildren"));
|
|
2281
2427
|
if (!nestedChildren?.length && !hasExplicitNestedChildren) {
|
|
2282
2428
|
try {
|
|
2283
2429
|
nestedChildren = compactNestedResultChildren(projectNestedRegistryForRoot(runId)?.children);
|
|
2284
2430
|
} catch (error) {
|
|
2285
|
-
|
|
2431
|
+
reportResultWatcherWarning(state, `Failed to enrich subagent result file '${resultPath}' with nested registry children; will retry later`, error);
|
|
2286
2432
|
scheduleResult(file, triggerTurn, RETRY_DELAY_MS);
|
|
2287
2433
|
return;
|
|
2288
2434
|
}
|
|
@@ -2320,7 +2466,7 @@ ${structuredPreview}` : "(no output)";
|
|
|
2320
2466
|
Output:
|
|
2321
2467
|
${baseOutput}` : ""}` : output;
|
|
2322
2468
|
const sessionPath = result.sessionFile ?? (resultChildren.length === 1 ? data.sessionFile : void 0);
|
|
2323
|
-
const childNestedChildren = sanitizeNestedResultChildren(result.children, resultPath, `results[${index}].children`);
|
|
2469
|
+
const childNestedChildren = sanitizeNestedResultChildren(state, result.children, resultPath, `results[${index}].children`);
|
|
2324
2470
|
const childState = result.state === "running" || result.state === "queued" || result.state === "paused" || result.state === "stopped" ? result.state : result.stopped === true ? "stopped" : data.state === "paused" || !hasResultChildren && (data.state === "stopped" || typeof result.success !== "boolean") ? data.state : void 0;
|
|
2325
2471
|
return {
|
|
2326
2472
|
agent: result.agent ?? data.agent ?? `step-${index + 1}`,
|
|
@@ -2375,7 +2521,7 @@ ${baseOutput}` : ""}` : output;
|
|
|
2375
2521
|
...data.parallelHandoff ? { parallelHandoff: data.parallelHandoff } : {}
|
|
2376
2522
|
}));
|
|
2377
2523
|
if (!ownsCompletion(sessionId, completionOwnerId, epoch)) return;
|
|
2378
|
-
if (!intercomDelivered)
|
|
2524
|
+
if (!intercomDelivered) reportResultWatcherWarning(state, `Subagent async grouped result intercom delivery was not acknowledged for '${resultPath}'.`);
|
|
2379
2525
|
}
|
|
2380
2526
|
const delivery = notifier.deliver({
|
|
2381
2527
|
...data,
|
|
@@ -2416,7 +2562,7 @@ ${baseOutput}` : ""}` : output;
|
|
|
2416
2562
|
}
|
|
2417
2563
|
({ data, read } = marked);
|
|
2418
2564
|
} catch (error) {
|
|
2419
|
-
|
|
2565
|
+
reportResultWatcherWarning(state, `Failed to mark subagent result notification delivered for '${resultPath}'; will retry`, error);
|
|
2420
2566
|
scheduleResult(file, triggerTurn, RETRY_DELAY_MS);
|
|
2421
2567
|
return;
|
|
2422
2568
|
}
|
|
@@ -2442,7 +2588,7 @@ ${baseOutput}` : ""}` : output;
|
|
|
2442
2588
|
} : {}
|
|
2443
2589
|
});
|
|
2444
2590
|
} catch (error) {
|
|
2445
|
-
|
|
2591
|
+
reportResultWatcherWarning(state, `Completion observer failed for '${resultPath}'`, error);
|
|
2446
2592
|
}
|
|
2447
2593
|
if (!observerSucceeded) {
|
|
2448
2594
|
scheduleResult(file, triggerTurn, RETRY_DELAY_MS);
|
|
@@ -2456,9 +2602,9 @@ ${baseOutput}` : ""}` : output;
|
|
|
2456
2602
|
removeDeliveredResult(file, triggerTurn, read);
|
|
2457
2603
|
} catch (error) {
|
|
2458
2604
|
if (isAccessDenied(error)) {
|
|
2459
|
-
|
|
2605
|
+
reportResultWatcherWarning(state, `Failed to process subagent result file '${resultPath}'; will retry`, error);
|
|
2460
2606
|
scheduleResult(file, triggerTurn, RETRY_DELAY_MS);
|
|
2461
|
-
} else if (!isNotFound2(error))
|
|
2607
|
+
} else if (!isNotFound2(error)) reportResultWatcherWarning(state, `Failed to process subagent result file '${resultPath}'`, error);
|
|
2462
2608
|
} finally {
|
|
2463
2609
|
processing.delete(file);
|
|
2464
2610
|
if (rereadReplacedPayload) scheduleResult(file, triggerTurn);
|
|
@@ -2478,7 +2624,7 @@ ${baseOutput}` : ""}` : output;
|
|
|
2478
2624
|
const resultScanLogging = deps.resultScanLogging ?? "activity";
|
|
2479
2625
|
if (resultScanLogging === "off") return;
|
|
2480
2626
|
if (resultScanLogging === "activity" && stats.files === 0 && stats.scheduled === 0) return;
|
|
2481
|
-
|
|
2627
|
+
reportSessionWarning(state, `Subagent result scan inspected ${stats.files} indexed result file(s), scheduled ${stats.scheduled} in ${elapsed}ms (${resultsDir}).`, "slow-result-scan");
|
|
2482
2628
|
};
|
|
2483
2629
|
const indexedResultCandidates = (observed) => {
|
|
2484
2630
|
const files = /* @__PURE__ */ new Set();
|
|
@@ -2506,10 +2652,27 @@ ${baseOutput}` : ""}` : output;
|
|
|
2506
2652
|
}
|
|
2507
2653
|
logScanStats(stats);
|
|
2508
2654
|
} catch (error) {
|
|
2509
|
-
if (!isNotFound2(error))
|
|
2655
|
+
if (!isNotFound2(error)) reportResultWatcherWarning(state, `Failed to scan subagent result index in '${resultsDir}'`, error);
|
|
2510
2656
|
}
|
|
2511
2657
|
return files;
|
|
2512
2658
|
};
|
|
2659
|
+
const hasPendingResults = () => eligibleResultFiles().some((file) => {
|
|
2660
|
+
const payloadPath = resultPayloadPath(file);
|
|
2661
|
+
if (!payloadPath) return false;
|
|
2662
|
+
let raw;
|
|
2663
|
+
try {
|
|
2664
|
+
raw = fsApi.readFileSync(payloadPath, "utf-8");
|
|
2665
|
+
} catch (error) {
|
|
2666
|
+
return !isNotFound2(error);
|
|
2667
|
+
}
|
|
2668
|
+
const identity = resultFileIdentity(raw, file);
|
|
2669
|
+
if (!identity.sessionId || !ownsResult(identity.sessionId, deliveryOwnerId(identity.sessionId, identity.completionOwnerId, identity.completionOwnerProcess, identity.parentWorkflowRunId))) return false;
|
|
2670
|
+
try {
|
|
2671
|
+
return !hasDeliveredNotification(parseResult(raw));
|
|
2672
|
+
} catch {
|
|
2673
|
+
return true;
|
|
2674
|
+
}
|
|
2675
|
+
});
|
|
2513
2676
|
const primeExistingResults = (options = {}) => {
|
|
2514
2677
|
const triggerTurn = options.triggerTurn !== false;
|
|
2515
2678
|
for (const file of eligibleResultFiles()) scheduleResult(file, triggerTurn);
|
|
@@ -2537,7 +2700,7 @@ ${baseOutput}` : ""}` : output;
|
|
|
2537
2700
|
try {
|
|
2538
2701
|
return deps.hasDeliveryDemand?.() === true;
|
|
2539
2702
|
} catch (error) {
|
|
2540
|
-
|
|
2703
|
+
reportResultWatcherWarning(state, "Failed to inspect subagent result delivery demand", error);
|
|
2541
2704
|
return false;
|
|
2542
2705
|
}
|
|
2543
2706
|
};
|
|
@@ -2561,7 +2724,7 @@ ${baseOutput}` : ""}` : output;
|
|
|
2561
2724
|
state.watcher = null;
|
|
2562
2725
|
clearResultScan();
|
|
2563
2726
|
if (state.watcherRestartTimer) return;
|
|
2564
|
-
|
|
2727
|
+
reportResultWatcherWarning(state, `Subagent result watcher for '${resultsDir}' fell back to polling because native fs.watch is unavailable (${errorCode(reason) ?? "unknown error"}).`, void 0, `result-poll-fallback:${resultsDir}`);
|
|
2565
2728
|
primeExistingResults();
|
|
2566
2729
|
state.watcherRestartTimer = timers.setInterval(primeExistingResults, POLL_INTERVAL_MS);
|
|
2567
2730
|
state.watcherRestartTimer.unref?.();
|
|
@@ -2576,7 +2739,7 @@ ${baseOutput}` : ""}` : output;
|
|
|
2576
2739
|
startResultWatcher();
|
|
2577
2740
|
} catch (error) {
|
|
2578
2741
|
if (shouldPoll(error)) return startPolling(error);
|
|
2579
|
-
|
|
2742
|
+
reportResultWatcherWarning(state, `Failed to restart subagent result watcher for '${resultsDir}'`, error);
|
|
2580
2743
|
scheduleRestart();
|
|
2581
2744
|
}
|
|
2582
2745
|
}, WATCHER_RESTART_DELAY_MS);
|
|
@@ -2615,7 +2778,7 @@ ${baseOutput}` : ""}` : output;
|
|
|
2615
2778
|
});
|
|
2616
2779
|
state.watcher.on("error", (error) => {
|
|
2617
2780
|
if (shouldPoll(error)) return startPolling(error);
|
|
2618
|
-
|
|
2781
|
+
reportResultWatcherWarning(state, `Subagent result watcher failed for '${resultsDir}'`, error);
|
|
2619
2782
|
state.watcher?.close();
|
|
2620
2783
|
state.watcher = null;
|
|
2621
2784
|
scheduleRestart();
|
|
@@ -2625,7 +2788,7 @@ ${baseOutput}` : ""}` : output;
|
|
|
2625
2788
|
resultScanTimer.unref?.();
|
|
2626
2789
|
} catch (error) {
|
|
2627
2790
|
if (shouldPoll(error)) return startPolling(error);
|
|
2628
|
-
|
|
2791
|
+
reportResultWatcherWarning(state, `Failed to start subagent result watcher for '${resultsDir}'`, error);
|
|
2629
2792
|
state.watcher = null;
|
|
2630
2793
|
scheduleRestart();
|
|
2631
2794
|
}
|
|
@@ -2649,7 +2812,7 @@ ${baseOutput}` : ""}` : output;
|
|
|
2649
2812
|
processing.clear();
|
|
2650
2813
|
identityCache.clear();
|
|
2651
2814
|
};
|
|
2652
|
-
return { startResultWatcher, transitionResultDelivery, primeExistingResults, deliverPendingResults, stopResultWatcher, refreshResultDelivery: () => {
|
|
2815
|
+
return { startResultWatcher, transitionResultDelivery, primeExistingResults, deliverPendingResults, hasPendingResults, stopResultWatcher, refreshResultDelivery: () => {
|
|
2653
2816
|
primeExistingResults();
|
|
2654
2817
|
startDemandPolling();
|
|
2655
2818
|
} };
|
|
@@ -4060,9 +4223,20 @@ function detailsFromSessionEntry(entry) {
|
|
|
4060
4223
|
}
|
|
4061
4224
|
if (record.type !== "message" || !record.message || typeof record.message !== "object") return void 0;
|
|
4062
4225
|
const message2 = record.message;
|
|
4063
|
-
if (message2.role !== "toolResult" || message2.toolName !== "subagent" && message2.toolName !==
|
|
4226
|
+
if (message2.role !== "toolResult" || message2.toolName !== "subagent" && message2.toolName !== waitToolName() && message2.toolName !== DEFAULT_WAIT_TOOL_NAME) return void 0;
|
|
4064
4227
|
return isSubagentDetails(message2.details) ? message2.details : void 0;
|
|
4065
4228
|
}
|
|
4229
|
+
function notifiedAsyncRuns(entry) {
|
|
4230
|
+
if (!entry || typeof entry !== "object") return [];
|
|
4231
|
+
const record = entry;
|
|
4232
|
+
if (record.type !== "custom_message" || record.customType !== "subagent-notify") return [];
|
|
4233
|
+
const runs = record.details?.runs;
|
|
4234
|
+
if (!Array.isArray(runs)) return [];
|
|
4235
|
+
return runs.flatMap((run) => (
|
|
4236
|
+
// A detached foreground task keeps no async status directory to read usage from.
|
|
4237
|
+
run && typeof run.runId === "string" && run.source !== "foreground" ? [{ runId: run.runId, workflow: run.workflowRunId === run.runId }] : []
|
|
4238
|
+
));
|
|
4239
|
+
}
|
|
4066
4240
|
function metadataUsage(artifactsDirs, input, indexes = [0, void 0]) {
|
|
4067
4241
|
if (!/^[A-Za-z0-9._-]+$/.test(input.runId)) return void 0;
|
|
4068
4242
|
for (const artifactsDir of artifactsDirs) {
|
|
@@ -4111,6 +4285,7 @@ function collectSubagentCost(ctx, state) {
|
|
|
4111
4285
|
const message2 = entry.type === "message" ? entry.message : void 0;
|
|
4112
4286
|
const parentUsage = assistantUsageFromMessage(message2) ?? compactionUsageFromEntry(entry);
|
|
4113
4287
|
if (parentUsage) addUsage(parent, parentUsage);
|
|
4288
|
+
for (const run of notifiedAsyncRuns(entry)) (run.workflow ? workflowRunIds : asyncRunIds).add(run.runId);
|
|
4114
4289
|
const details = detailsFromSessionEntry(entry);
|
|
4115
4290
|
if (!details) continue;
|
|
4116
4291
|
if (details.mode === "workflow" && details.runId && details.asyncId) workflowRunIds.add(details.runId);
|
|
@@ -5185,7 +5360,7 @@ function registerSlashCommands(pi, state, options = {}) {
|
|
|
5185
5360
|
}
|
|
5186
5361
|
fleetOpen = true;
|
|
5187
5362
|
try {
|
|
5188
|
-
const { openSubagentFleet } = await import("./chunk-
|
|
5363
|
+
const { openSubagentFleet } = await import("./chunk-O7CPL6H4.js");
|
|
5189
5364
|
await openSubagentFleet(ctx, state, { asyncDirRoot: DIRS.async, inspectorPlugins: () => getInspectorPlugins(pi), resultsDir: DIRS.results, fleetKeybindings: options.fleetKeybindings });
|
|
5190
5365
|
} finally {
|
|
5191
5366
|
fleetOpen = false;
|
|
@@ -5312,7 +5487,7 @@ ${finalTask}`;
|
|
|
5312
5487
|
ctx.ui.notify(`Foreground run ${control.runId} is not currently detachable.`, "info");
|
|
5313
5488
|
return;
|
|
5314
5489
|
}
|
|
5315
|
-
sendSlashText(pi, `Detached foreground run ${control.runId} without terminating its child. Use subagent({ action: "status", id: ${JSON.stringify(control.runId)} }) or
|
|
5490
|
+
sendSlashText(pi, `Detached foreground run ${control.runId} without terminating its child. Use subagent({ action: "status", id: ${JSON.stringify(control.runId)} }) or ${waitToolName()}({ id: ${JSON.stringify(control.runId)} }) to recover the eventual result. This does not daemonize the process or guarantee survival across Pi reload/restart.`);
|
|
5316
5491
|
};
|
|
5317
5492
|
pi.registerCommand("subagents-detach", {
|
|
5318
5493
|
description: "Detach the active foreground single-subagent run without terminating it",
|
|
@@ -6767,8 +6942,8 @@ function supervisorReminderHeadline(details, status) {
|
|
|
6767
6942
|
return [`${ids.length} supervisor ${ids.length === 1 ? "request" : "requests"} `, { status }];
|
|
6768
6943
|
}
|
|
6769
6944
|
function waitSubscriptionHeadline(details) {
|
|
6770
|
-
if (!isRecord3(details) || typeof details.runId !== "string" || typeof details.outcome !== "string") return [
|
|
6771
|
-
return [
|
|
6945
|
+
if (!isRecord3(details) || typeof details.runId !== "string" || typeof details.outcome !== "string") return [`${waitToolName()} fired`];
|
|
6946
|
+
return [`${waitToolName()}: run ${details.runId} `, { status: details.outcome }];
|
|
6772
6947
|
}
|
|
6773
6948
|
function workflowChildHeadline(message2) {
|
|
6774
6949
|
const { details } = message2;
|
|
@@ -7780,16 +7955,19 @@ function registerSubagentRpcBridge(options) {
|
|
|
7780
7955
|
import { Type } from "typebox";
|
|
7781
7956
|
var LOADER_NAME = "subagents_enable";
|
|
7782
7957
|
var SUBAGENT_NAME = "subagent";
|
|
7783
|
-
var
|
|
7784
|
-
|
|
7958
|
+
var isUnloadSentinel = (name) => name === LOADER_NAME || name === SUBAGENT_NAME || name === waitToolName();
|
|
7959
|
+
function isOwnWaitDefinition(tool) {
|
|
7960
|
+
const properties = tool.parameters?.properties;
|
|
7961
|
+
return typeof properties === "object" && properties !== null && Object.hasOwn(properties, "nonBlocking") && Object.hasOwn(properties, "stopOnAttention");
|
|
7962
|
+
}
|
|
7785
7963
|
function hasNativeToolSelection(messages) {
|
|
7786
7964
|
return messages.some((message2) => message2.role === "system" && (Object.hasOwn(message2, "toolsAdded") || Object.hasOwn(message2, "toolsRemoved")));
|
|
7787
7965
|
}
|
|
7788
7966
|
function setSelection(pi, includeSubagent, includeLoader, includeWait, restore = [], keepParentSupervisor = false) {
|
|
7789
|
-
const next = [...pi.getActiveTools(), ...restore].filter((name) => (includeSubagent || name !== SUBAGENT_NAME && name !== CONTACT_SUPERVISOR_TOOL_NAME && (keepParentSupervisor || name !== NATIVE_SUPERVISOR_TOOL_NAME)) && (includeLoader || name !== LOADER_NAME) && (includeWait || name !==
|
|
7967
|
+
const next = [...pi.getActiveTools(), ...restore].filter((name) => (includeSubagent || name !== SUBAGENT_NAME && name !== CONTACT_SUPERVISOR_TOOL_NAME && (keepParentSupervisor || name !== NATIVE_SUPERVISOR_TOOL_NAME)) && (includeLoader || name !== LOADER_NAME) && (includeWait || name !== waitToolName()));
|
|
7790
7968
|
if (includeSubagent) next.push(SUBAGENT_NAME, CONTACT_SUPERVISOR_TOOL_NAME, NATIVE_SUPERVISOR_TOOL_NAME);
|
|
7791
7969
|
if (includeLoader) next.push(LOADER_NAME);
|
|
7792
|
-
if (includeWait) next.push(
|
|
7970
|
+
if (includeWait) next.push(waitToolName());
|
|
7793
7971
|
pi.setActiveTools([...new Set(next)]);
|
|
7794
7972
|
}
|
|
7795
7973
|
function addsToolsWithoutCheckpoint(model) {
|
|
@@ -7819,12 +7997,13 @@ function applyRecordedSelection(pi, ctx, mode, replyOwed) {
|
|
|
7819
7997
|
const unloadedNames = /* @__PURE__ */ new Set();
|
|
7820
7998
|
const declaredSentinels = /* @__PURE__ */ new Set();
|
|
7821
7999
|
const evidenced = /* @__PURE__ */ new Set();
|
|
8000
|
+
let legacyWaitIsOwn = false;
|
|
7822
8001
|
for (const message2 of messages) {
|
|
7823
8002
|
if (message2.role !== "system") continue;
|
|
7824
|
-
const removedSentinels = (message2.toolsRemoved ?? []).filter((tool) =>
|
|
8003
|
+
const removedSentinels = (message2.toolsRemoved ?? []).filter((tool) => isUnloadSentinel(tool.name));
|
|
7825
8004
|
const allDeclared = removedSentinels.every((tool) => declaredSentinels.has(tool.name));
|
|
7826
8005
|
for (const tool of message2.toolsRemoved ?? []) declaredSentinels.delete(tool.name);
|
|
7827
|
-
for (const tool of message2.toolsAdded ?? []) if (
|
|
8006
|
+
for (const tool of message2.toolsAdded ?? []) if (isUnloadSentinel(tool.name)) declaredSentinels.add(tool.name);
|
|
7828
8007
|
const unloaded = removedSentinels.length > 0 && allDeclared && declaredSentinels.size === 0;
|
|
7829
8008
|
for (const tool of message2.toolsRemoved ?? []) {
|
|
7830
8009
|
if (unloaded) unloadedNames.add(tool.name);
|
|
@@ -7836,19 +8015,21 @@ function applyRecordedSelection(pi, ctx, mode, replyOwed) {
|
|
|
7836
8015
|
for (const tool of message2.toolsAdded ?? []) {
|
|
7837
8016
|
recorded.add(tool.name);
|
|
7838
8017
|
evidenced.add(tool.name);
|
|
8018
|
+
if (tool.name === DEFAULT_WAIT_TOOL_NAME) legacyWaitIsOwn = isOwnWaitDefinition(tool);
|
|
7839
8019
|
}
|
|
7840
8020
|
}
|
|
7841
8021
|
const fresh = lost && !evidenced.has(LOADER_NAME) && !evidenced.has(SUBAGENT_NAME);
|
|
7842
8022
|
const startsEager = fresh && mode === "auto" && !addsToolsWithoutCheckpoint(ctx.model);
|
|
7843
8023
|
const loaderSelected = mode === "dynamic" || recorded.has(LOADER_NAME) || fresh && !startsEager;
|
|
8024
|
+
const waitRecord = waitToolName() !== DEFAULT_WAIT_TOOL_NAME && !evidenced.has(waitToolName()) && legacyWaitIsOwn ? DEFAULT_WAIT_TOOL_NAME : waitToolName();
|
|
7844
8025
|
const source = unloadedNames.size > 0 ? available.find((tool) => tool.name === LOADER_NAME)?.sourceInfo.path : void 0;
|
|
7845
8026
|
const restore = source === void 0 ? [] : available.filter((tool) => unloadedNames.has(tool.name) && recorded.has(tool.name) && tool.sourceInfo.path === source).map((tool) => tool.name);
|
|
7846
|
-
setSelection(pi, recorded.has(SUBAGENT_NAME) || startsEager, loaderSelected, recorded.has(
|
|
8027
|
+
setSelection(pi, recorded.has(SUBAGENT_NAME) || startsEager, loaderSelected, recorded.has(waitRecord) || !evidenced.has(waitRecord) && startsEager, replyOwed ? [...restore, NATIVE_SUPERVISOR_TOOL_NAME] : restore, replyOwed || recorded.has(NATIVE_SUPERVISOR_TOOL_NAME));
|
|
7847
8028
|
return loaderSelected;
|
|
7848
8029
|
}
|
|
7849
8030
|
const eager = mode === "auto" && messages.length === 0 && !addsToolsWithoutCheckpoint(ctx.model);
|
|
7850
8031
|
const kept = (name) => eager || messages.length > 0 && pi.getActiveTools().includes(name);
|
|
7851
|
-
setSelection(pi, kept(SUBAGENT_NAME), !eager, kept(
|
|
8032
|
+
setSelection(pi, kept(SUBAGENT_NAME), !eager, kept(waitToolName()), replyOwed ? [NATIVE_SUPERVISOR_TOOL_NAME] : [], replyOwed || messages.length > 0);
|
|
7852
8033
|
return !eager;
|
|
7853
8034
|
}
|
|
7854
8035
|
function registerSubagentToolActivation(pi, options) {
|
|
@@ -7903,8 +8084,8 @@ ${advertised}` : ""}` }],
|
|
|
7903
8084
|
pi.on("before_agent_start", (event) => {
|
|
7904
8085
|
const available = pi.getAllTools();
|
|
7905
8086
|
if (!Array.isArray(available) || !available.some((tool) => tool.name === LOADER_NAME)) return;
|
|
7906
|
-
const providedWait = available.some((tool) => tool.name ===
|
|
7907
|
-
const names = [...loaderSelected ? [LOADER_NAME] : [], ...providedWait ? [
|
|
8087
|
+
const providedWait = available.some((tool) => tool.name === waitToolName()) && listBackgroundWorkProviders().length > 0;
|
|
8088
|
+
const names = [...loaderSelected ? [LOADER_NAME] : [], ...providedWait ? [waitToolName()] : []];
|
|
7908
8089
|
if (names.length === 0) return;
|
|
7909
8090
|
const selectedTools = event.systemPromptOptions.selectedTools ??= [...pi.getActiveTools()];
|
|
7910
8091
|
for (const name of names) if (!selectedTools.includes(name)) selectedTools.push(name);
|
|
@@ -8074,6 +8255,11 @@ function withMandatorySafetyGuidance(description) {
|
|
|
8074
8255
|
${SUBAGENT_SAFETY_GUIDANCE}` : SUBAGENT_SAFETY_GUIDANCE;
|
|
8075
8256
|
}
|
|
8076
8257
|
function buildSubagentToolDescription(config = {}, options) {
|
|
8258
|
+
const description = describeSubagentTool(config, options);
|
|
8259
|
+
const name = waitToolName();
|
|
8260
|
+
return name === DEFAULT_WAIT_TOOL_NAME ? description : description.replace(/\bbg_wait\b/g, name);
|
|
8261
|
+
}
|
|
8262
|
+
function describeSubagentTool(config, options) {
|
|
8077
8263
|
const on = options?.disabledFeatures ? featureText(options.disabledFeatures) : allEnabled;
|
|
8078
8264
|
if (config.toolDescriptionMode === void 0) return essentials(on);
|
|
8079
8265
|
const mode = resolveToolDescriptionMode(config, options);
|
|
@@ -8397,9 +8583,9 @@ function getRuntimeRegistry() {
|
|
|
8397
8583
|
globalStore[RUNTIME_REGISTRY_STORE_KEY] = registry;
|
|
8398
8584
|
return registry;
|
|
8399
8585
|
}
|
|
8400
|
-
function logSlowPhase(label, startedAt) {
|
|
8586
|
+
function logSlowPhase(state, label, startedAt) {
|
|
8401
8587
|
const elapsed = Date.now() - startedAt;
|
|
8402
|
-
if (elapsed >= SLOW_RELOAD_PHASE_MS)
|
|
8588
|
+
if (elapsed >= SLOW_RELOAD_PHASE_MS) reportSessionWarning(state, `Subagent reload phase '${label}' took ${elapsed}ms.`, `slow-reload-phase:${label}`);
|
|
8403
8589
|
}
|
|
8404
8590
|
function formatWorkflowPreflightCall(input) {
|
|
8405
8591
|
if (input === void 0) return "";
|
|
@@ -8496,6 +8682,7 @@ function registerSubagentExtension(pi) {
|
|
|
8496
8682
|
const config = loadConfig();
|
|
8497
8683
|
setDeclarationPinning(pi, config.pinToolDeclarations !== false);
|
|
8498
8684
|
const waitToolConfig = resolveWaitToolConfig(config.waitTool);
|
|
8685
|
+
setWaitToolName(waitToolConfig.name ?? DEFAULT_WAIT_TOOL_NAME);
|
|
8499
8686
|
const asyncByDefault = resolveAsyncByDefault(config);
|
|
8500
8687
|
const fleetViewEnabled = config.fleetView !== false;
|
|
8501
8688
|
const slashCommandsEnabled = config.enableSlashCommands !== false;
|
|
@@ -8574,7 +8761,7 @@ function registerSubagentExtension(pi) {
|
|
|
8574
8761
|
const ctx = withLastUiContext((current) => current);
|
|
8575
8762
|
if (!ctx) return;
|
|
8576
8763
|
try {
|
|
8577
|
-
const { openSubagentFleet } = await import("./chunk-
|
|
8764
|
+
const { openSubagentFleet } = await import("./chunk-O7CPL6H4.js");
|
|
8578
8765
|
await openSubagentFleet(ctx, state, { initialKey: itemKey, asyncDirRoot: DIRS.async, resultsDir: DIRS.results, fleetKeybindings: config.fleetKeybindings, inspectorPlugins: () => getInspectorPlugins(pi) });
|
|
8579
8766
|
} catch (error) {
|
|
8580
8767
|
if (isStaleExtensionContextError(error)) {
|
|
@@ -8595,13 +8782,15 @@ function registerSubagentExtension(pi) {
|
|
|
8595
8782
|
await waitForAdvertisement();
|
|
8596
8783
|
return (await getExecutor()).executeScheduled(randomUUID3(), params, signal, ctx);
|
|
8597
8784
|
},
|
|
8598
|
-
resolveCapabilityCeiling: (sessionId) => resolveCurrentSubagentCapabilityCeiling(sessionId)
|
|
8785
|
+
resolveCapabilityCeiling: (sessionId) => resolveCurrentSubagentCapabilityCeiling(sessionId),
|
|
8786
|
+
reportWarning: (message2, key) => reportSessionWarning(state, message2, key)
|
|
8599
8787
|
});
|
|
8600
8788
|
let refreshResultDelivery = () => {
|
|
8601
8789
|
};
|
|
8602
8790
|
let advertisedAgents = [];
|
|
8603
8791
|
let advertisedContext;
|
|
8604
8792
|
let advertisementGeneration = 0;
|
|
8793
|
+
let advertisementLookup;
|
|
8605
8794
|
let globalRoot = null;
|
|
8606
8795
|
let advertisementReady = Promise.resolve();
|
|
8607
8796
|
let notifySessionChange = () => {
|
|
@@ -8623,6 +8812,8 @@ function registerSubagentExtension(pi) {
|
|
|
8623
8812
|
};
|
|
8624
8813
|
const beginAdvertisement = (ctx) => {
|
|
8625
8814
|
const generation = ++advertisementGeneration;
|
|
8815
|
+
advertisementLookup?.abort();
|
|
8816
|
+
advertisementLookup = new AbortController();
|
|
8626
8817
|
notifySessionChange();
|
|
8627
8818
|
sessionChanged = new Promise((resolve6) => {
|
|
8628
8819
|
notifySessionChange = resolve6;
|
|
@@ -8630,7 +8821,7 @@ function registerSubagentExtension(pi) {
|
|
|
8630
8821
|
advertisedAgents = [];
|
|
8631
8822
|
advertisedContext = { cwd: ctx.cwd, model: ctx.model, projectTrusted: typeof ctx.isProjectTrusted === "function" ? ctx.isProjectTrusted() : void 0 };
|
|
8632
8823
|
globalRoot = null;
|
|
8633
|
-
advertisementReady = resolveGlobalNpmRoot().then((root) => {
|
|
8824
|
+
advertisementReady = resolveGlobalNpmRoot({ signal: advertisementLookup.signal }).then((root) => {
|
|
8634
8825
|
if (generation !== advertisementGeneration) return;
|
|
8635
8826
|
globalRoot = root;
|
|
8636
8827
|
refreshAdvertisedAgents();
|
|
@@ -8705,6 +8896,15 @@ function registerSubagentExtension(pi) {
|
|
|
8705
8896
|
}
|
|
8706
8897
|
);
|
|
8707
8898
|
const { startResultWatcher, transitionResultDelivery, primeExistingResults, stopResultWatcher } = resultWatcher;
|
|
8899
|
+
const sessionSwitchGuard = createSessionSwitchGuard({
|
|
8900
|
+
state,
|
|
8901
|
+
asyncDirRoot: DIRS.async,
|
|
8902
|
+
resultsDir: DIRS.results,
|
|
8903
|
+
hasPendingResults: () => owedResultRunIds.size > 0 || completionNotifier.hasPendingDelivery() || resultWatcher.hasPendingResults(),
|
|
8904
|
+
hasPendingSupervisorRequest: supervisorChannel.hasPendingRequests
|
|
8905
|
+
});
|
|
8906
|
+
pi.on("session_before_switch", (event, ctx) => sessionSwitchGuard.beforeSwitch(event.reason, ctx));
|
|
8907
|
+
pi.on("session_before_fork", (_event, ctx) => sessionSwitchGuard.beforeSwitch("fork", ctx));
|
|
8708
8908
|
refreshResultDelivery = resultWatcher.refreshResultDelivery;
|
|
8709
8909
|
const asyncRetentionAbort = new AbortController();
|
|
8710
8910
|
let asyncRetentionTimer;
|
|
@@ -8770,7 +8970,7 @@ function registerSubagentExtension(pi) {
|
|
|
8770
8970
|
let executor;
|
|
8771
8971
|
let executorPromise;
|
|
8772
8972
|
let executorModulePromise;
|
|
8773
|
-
const loadExecutorModule = () => executorModulePromise ??= import("./chunk-
|
|
8973
|
+
const loadExecutorModule = () => executorModulePromise ??= import("./chunk-JWYG26RE.js");
|
|
8774
8974
|
const getExecutor = () => {
|
|
8775
8975
|
executorPromise ??= loadExecutorModule().then(({ createSubagentExecutor }) => {
|
|
8776
8976
|
executor = createSubagentExecutor(executorDeps);
|
|
@@ -8784,7 +8984,7 @@ function registerSubagentExtension(pi) {
|
|
|
8784
8984
|
modulePreloadTimer = setTimeout(() => {
|
|
8785
8985
|
loadExecutorModule().catch(() => {
|
|
8786
8986
|
});
|
|
8787
|
-
if (fleetViewEnabled) import("./chunk-
|
|
8987
|
+
if (fleetViewEnabled) import("./chunk-O7CPL6H4.js").catch(() => {
|
|
8788
8988
|
});
|
|
8789
8989
|
}, MODULE_PRELOAD_DELAY_MS);
|
|
8790
8990
|
modulePreloadTimer.unref?.();
|
|
@@ -8944,6 +9144,7 @@ ${close}` }]
|
|
|
8944
9144
|
};
|
|
8945
9145
|
registerPinnedTool(pi, tool);
|
|
8946
9146
|
registerPinnedTool(pi, topLevelSupervisorTool());
|
|
9147
|
+
registerSubagentLaunchTool(pi);
|
|
8947
9148
|
pi.on("before_agent_start", async (event, ctx) => {
|
|
8948
9149
|
await waitForAdvertisement();
|
|
8949
9150
|
const sessionId = state.currentSessionId ?? resolveCurrentSessionId(ctx.sessionManager);
|
|
@@ -9085,11 +9286,12 @@ ${close}` }]
|
|
|
9085
9286
|
{ liveWorkflowRunIds: new Set(state.workflowControllers?.keys() ?? []), abandonedSlotReleaseAfterMs: resolveAbandonedSlotReleaseAfterMs(config.capacity?.abandonedSlotReleaseAfterMs) }
|
|
9086
9287
|
);
|
|
9087
9288
|
};
|
|
9088
|
-
const resetSessionState = (ctx, recovering, previousSessionFile) => {
|
|
9289
|
+
const resetSessionState = (ctx, recovering, startup, previousSessionFile) => {
|
|
9089
9290
|
state.widgetsSuspended = false;
|
|
9090
9291
|
state.baseCwd = ctx.cwd;
|
|
9091
9292
|
goalTurnId = 0;
|
|
9092
9293
|
state.currentSessionId = resolveCurrentSessionId(ctx.sessionManager);
|
|
9294
|
+
recordSessionStart(state.currentSessionId, startup);
|
|
9093
9295
|
if (previousSessionFile) recordSessionReplacement(state.currentSessionId, previousSessionFile);
|
|
9094
9296
|
state.supervisorOwnerSessionId = ctx.sessionManager.getSessionId() || null;
|
|
9095
9297
|
transitionResultDelivery();
|
|
@@ -9116,10 +9318,10 @@ ${close}` }]
|
|
|
9116
9318
|
state.lastUiContext = ctx;
|
|
9117
9319
|
let phaseStartedAt = Date.now();
|
|
9118
9320
|
refreshActiveAsyncCapacity();
|
|
9119
|
-
logSlowPhase("active-capacity", phaseStartedAt);
|
|
9321
|
+
logSlowPhase(state, "active-capacity", phaseStartedAt);
|
|
9120
9322
|
phaseStartedAt = Date.now();
|
|
9121
9323
|
cleanupSessionArtifacts(ctx);
|
|
9122
|
-
logSlowPhase("session-artifact-cleanup", phaseStartedAt);
|
|
9324
|
+
logSlowPhase(state, "session-artifact-cleanup", phaseStartedAt);
|
|
9123
9325
|
state.foregroundControls.clear();
|
|
9124
9326
|
retainedNestedRouteTracker?.clear();
|
|
9125
9327
|
retainedNestedRouteTracker = void 0;
|
|
@@ -9127,17 +9329,17 @@ ${close}` }]
|
|
|
9127
9329
|
state.lastForegroundControlId = null;
|
|
9128
9330
|
phaseStartedAt = Date.now();
|
|
9129
9331
|
resetJobs(ctx);
|
|
9130
|
-
logSlowPhase("reset-jobs", phaseStartedAt);
|
|
9332
|
+
logSlowPhase(state, "reset-jobs", phaseStartedAt);
|
|
9131
9333
|
phaseStartedAt = Date.now();
|
|
9132
9334
|
const interruptedElsewhere = ctx.hasUI ? createInterruptedElsewhereCollector({ currentSessionId: state.currentSessionId, cwd: ctx.cwd, now: Date.now() }) : void 0;
|
|
9133
9335
|
restoreForegroundRunHistory(state, { resultsDir: DIRS.results, observeForeign: interruptedElsewhere?.observeForegroundRun });
|
|
9134
|
-
logSlowPhase("foreground-history", phaseStartedAt);
|
|
9336
|
+
logSlowPhase(state, "foreground-history", phaseStartedAt);
|
|
9135
9337
|
phaseStartedAt = Date.now();
|
|
9136
9338
|
restoreActiveJobs(ctx, interruptedElsewhere?.observeStatus);
|
|
9137
|
-
logSlowPhase("active-job-restore", phaseStartedAt);
|
|
9339
|
+
logSlowPhase(state, "active-job-restore", phaseStartedAt);
|
|
9138
9340
|
phaseStartedAt = Date.now();
|
|
9139
9341
|
if (interruptedElsewhere) for (const line of interruptedElsewhere.lines()) ctx.ui.notify(line, "info");
|
|
9140
|
-
logSlowPhase("cross-session-notice", phaseStartedAt);
|
|
9342
|
+
logSlowPhase(state, "cross-session-notice", phaseStartedAt);
|
|
9141
9343
|
phaseStartedAt = Date.now();
|
|
9142
9344
|
cancelPendingWorkflowAutoResumes((entry) => entry.owner === autoResumeOwner);
|
|
9143
9345
|
if (recovering && ctx.hasUI && config.autoResume !== false) {
|
|
@@ -9145,22 +9347,22 @@ ${close}` }]
|
|
|
9145
9347
|
void launchWorkflowAutoResume(entry, ctx);
|
|
9146
9348
|
}
|
|
9147
9349
|
}
|
|
9148
|
-
logSlowPhase("workflow-auto-resume", phaseStartedAt);
|
|
9350
|
+
logSlowPhase(state, "workflow-auto-resume", phaseStartedAt);
|
|
9149
9351
|
phaseStartedAt = Date.now();
|
|
9150
9352
|
scheduledRunManager.bindSession(ctx);
|
|
9151
|
-
logSlowPhase("scheduled-runs", phaseStartedAt);
|
|
9353
|
+
logSlowPhase(state, "scheduled-runs", phaseStartedAt);
|
|
9152
9354
|
phaseStartedAt = Date.now();
|
|
9153
9355
|
restoreSlashFinalSnapshots(ctx.sessionManager.getEntries());
|
|
9154
|
-
logSlowPhase("slash-snapshots", phaseStartedAt);
|
|
9356
|
+
logSlowPhase(state, "slash-snapshots", phaseStartedAt);
|
|
9155
9357
|
phaseStartedAt = Date.now();
|
|
9156
9358
|
waitSubscriptionManager.restore();
|
|
9157
|
-
logSlowPhase("wait-subscriptions", phaseStartedAt);
|
|
9359
|
+
logSlowPhase(state, "wait-subscriptions", phaseStartedAt);
|
|
9158
9360
|
phaseStartedAt = Date.now();
|
|
9159
9361
|
startResultWatcher();
|
|
9160
|
-
logSlowPhase("result-watcher-start", phaseStartedAt);
|
|
9362
|
+
logSlowPhase(state, "result-watcher-start", phaseStartedAt);
|
|
9161
9363
|
phaseStartedAt = Date.now();
|
|
9162
9364
|
primeExistingResults({ triggerTurn: !recovering });
|
|
9163
|
-
logSlowPhase("result-prime", phaseStartedAt);
|
|
9365
|
+
logSlowPhase(state, "result-prime", phaseStartedAt);
|
|
9164
9366
|
fleetStatus?.setContext(ctx);
|
|
9165
9367
|
};
|
|
9166
9368
|
let runtimeCleaned = false;
|
|
@@ -9170,6 +9372,12 @@ ${close}` }]
|
|
|
9170
9372
|
cleanup(shutdownReason) {
|
|
9171
9373
|
if (runtimeCleaned) return;
|
|
9172
9374
|
runtimeCleaned = true;
|
|
9375
|
+
sessionSwitchGuard.dispose();
|
|
9376
|
+
++advertisementGeneration;
|
|
9377
|
+
advertisementLookup?.abort();
|
|
9378
|
+
advertisedAgents = [];
|
|
9379
|
+
advertisedContext = void 0;
|
|
9380
|
+
notifySessionChange();
|
|
9173
9381
|
cancelPendingWorkflowAutoResumes((entry) => entry.owner === autoResumeOwner);
|
|
9174
9382
|
programStatus.dispose(shutdownReason);
|
|
9175
9383
|
releaseHostSessionLiveness();
|
|
@@ -9320,7 +9528,7 @@ ${close}` }]
|
|
|
9320
9528
|
startSessionMaintenance();
|
|
9321
9529
|
scheduleModulePreload();
|
|
9322
9530
|
const recovering = event.reason === "startup" || event.reason === "reload" || event.reason === "resume";
|
|
9323
|
-
resetSessionState(ctx, recovering, event.previousSessionFile);
|
|
9531
|
+
resetSessionState(ctx, recovering, event.reason === "startup", event.previousSessionFile);
|
|
9324
9532
|
releaseHostSessionLiveness();
|
|
9325
9533
|
const sessionId = ctx.sessionManager.getSessionId();
|
|
9326
9534
|
const sessionFile = ctx.sessionManager.getSessionFile();
|
|
@@ -9345,6 +9553,7 @@ ${close}` }]
|
|
|
9345
9553
|
supervisorChannel.activateTransport();
|
|
9346
9554
|
});
|
|
9347
9555
|
pi.on("session_shutdown", async (event) => {
|
|
9556
|
+
sessionSwitchGuard.sessionShutdown(event);
|
|
9348
9557
|
cancelCompactionResume();
|
|
9349
9558
|
completionNotifier.sessionShutdown(event?.reason);
|
|
9350
9559
|
parentWake.sessionShutdown(event?.reason);
|