@xzzpig/pi-subagents 0.24.2 → 0.25.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +37 -0
- package/bundle/agent-management.js +4 -4
- package/bundle/agents.js +3 -3
- package/bundle/child-tool-plan.js +2 -2
- package/bundle/chunk-34TUUBRN.js +1107 -0
- package/bundle/{chunk-SW2VMNIU.js → chunk-5OD3OWTE.js} +2 -2
- package/bundle/{chunk-EUPJB4S7.js → chunk-5Z7JAORM.js} +196 -1219
- package/bundle/{chunk-LCDJWBVM.js → chunk-66JNFRFS.js} +1 -1
- package/bundle/{chunk-ED55MIC2.js → chunk-CGFF4WA3.js} +42 -19
- package/bundle/{chunk-TMHVDPYW.js → chunk-DLVPMML3.js} +263 -154
- package/bundle/{chunk-RU522D5W.js → chunk-FQPV4O6C.js} +183 -28
- package/bundle/chunk-HXRB42AF.js +108 -0
- package/bundle/{chunk-355ECEP2.js → chunk-IH7LQVEE.js} +29 -14
- package/bundle/{chunk-Z6TFJ6BR.js → chunk-INWSUNI6.js} +1 -1
- package/bundle/{chunk-CYY5UMJU.js → chunk-IXCEOEJT.js} +411 -249
- package/bundle/{chunk-WW76JRIX.js → chunk-JAXVBXGF.js} +1 -1
- package/bundle/{chunk-ICNYIALB.js → chunk-JH5H4CYJ.js} +784 -474
- package/bundle/{chunk-224WMDIV.js → chunk-JUYNN63E.js} +350 -123
- package/bundle/{chunk-35GII5EF.js → chunk-JWFLPSTP.js} +41 -117
- package/bundle/{chunk-XWWUDWUW.js → chunk-KRNBJPZ2.js} +670 -400
- package/bundle/{chunk-RB4GELQA.js → chunk-LPJEKHOY.js} +1 -1
- package/bundle/chunk-LYKG4FKH.js +523 -0
- package/bundle/{chunk-X6LOM3Z4.js → chunk-LZ3HBDTR.js} +161 -78
- package/bundle/{chunk-JEA2ZKUA.js → chunk-MMJQMPOK.js} +37 -165
- package/bundle/{chunk-FG6SQJAR.js → chunk-OGPOCGWX.js} +24 -6
- package/bundle/{chunk-FJWI64H7.js → chunk-RMSABUN3.js} +27 -13
- package/bundle/{chunk-H36HBZB2.js → chunk-SJPABBZG.js} +2 -2
- package/bundle/{chunk-4UH4WS4G.js → chunk-SNDCIJMK.js} +23 -12
- package/bundle/{chunk-O4D5PBVI.js → chunk-TM2K53NX.js} +3 -2
- package/bundle/{chunk-3U633XDZ.js → chunk-U3ZDUUTM.js} +11 -3
- package/bundle/{chunk-LVWU2HOO.js → chunk-ULGMXABL.js} +16 -7
- package/bundle/{chunk-WPW4V6HM.js → chunk-W7ZA6TYD.js} +2 -2
- package/bundle/{chunk-BQ2OAB4Q.js → chunk-WWDUNXSE.js} +67 -30
- package/bundle/{chunk-V2KFIGFH.js → chunk-XAC2XNAP.js} +503 -304
- package/bundle/control-channel.js +2 -2
- package/bundle/index.js +1 -1
- package/bundle/intercom-bridge.js +2 -2
- package/bundle/preflight.js +12 -10
- package/bundle/project-panes.js +3 -3
- package/bundle/workflow-resources.js +1 -1
- package/docs/agents.md +27 -6
- package/docs/configuration.md +20 -8
- package/docs/extension-api.md +18 -1
- package/docs/models.md +6 -2
- package/docs/observability.md +2 -0
- package/docs/tool-reference.md +7 -1
- package/docs/workflows.md +30 -2
- package/package.json +2 -2
- package/skills/pi-subagents/SKILL.md +15 -6
- package/skills/pi-subagents/references/prompting-and-roles.md +1 -0
- package/src/agents/agent-management.d.ts +1 -0
- package/src/agents/agent-management.js +46 -18
- package/src/agents/agent-memory.d.ts +1 -4
- package/src/agents/agent-memory.js +1 -4
- package/src/agents/agent-serializer.d.ts +2 -0
- package/src/agents/agent-serializer.js +1 -1
- package/src/agents/agents.d.ts +2 -3
- package/src/agents/agents.js +46 -20
- package/src/agents/frontmatter.js +1 -8
- package/src/agents/global-npm-root.d.ts +1 -0
- package/src/agents/global-npm-root.js +11 -3
- package/src/agents/skills.d.ts +0 -3
- package/src/agents/skills.js +0 -3
- package/src/api/preflight.d.ts +3 -1
- package/src/api/preflight.js +2 -0
- package/src/extension/config.d.ts +1 -0
- package/src/extension/config.js +13 -1
- package/src/extension/herdr-pi-bridge.js +10 -2
- package/src/extension/index.d.ts +0 -13
- package/src/extension/index.js +51 -37
- package/src/extension/public-execution.d.ts +1 -0
- package/src/extension/public-execution.js +4 -0
- package/src/extension/reply-workflow-script.js +24 -4
- package/src/extension/schemas.d.ts +12 -3
- package/src/extension/schemas.js +7 -3
- package/src/extension/session-switch.d.ts +25 -0
- package/src/extension/session-switch.js +138 -0
- package/src/extension/subagent-guide.d.ts +1 -1
- package/src/extension/subagent-guide.js +1 -1
- package/src/extension/subagent-launch-tool.d.ts +25 -0
- package/src/extension/subagent-launch-tool.js +48 -0
- package/src/extension/tool-activation.js +55 -15
- package/src/extension/tool-description.d.ts +1 -1
- package/src/extension/tool-description.js +14 -8
- package/src/inspectors/herdr/actions.d.ts +0 -1
- package/src/inspectors/herdr/actions.js +0 -1
- package/src/inspectors/session-roots-codec.d.ts +0 -1
- package/src/inspectors/session-roots-codec.js +0 -1
- package/src/inspectors/tmux/actions.d.ts +0 -1
- package/src/inspectors/tmux/actions.js +0 -1
- package/src/integrations/herdr-status.js +3 -8
- package/src/intercom/native-supervisor-channel.js +65 -9
- package/src/runs/background/async-execution.d.ts +7 -10
- package/src/runs/background/async-execution.js +66 -29
- package/src/runs/background/async-job-tracker.js +12 -0
- package/src/runs/background/async-resume.d.ts +2 -1
- package/src/runs/background/async-resume.js +114 -40
- package/src/runs/background/async-retention.d.ts +0 -2
- package/src/runs/background/async-retention.js +17 -6
- package/src/runs/background/async-status.d.ts +2 -0
- package/src/runs/background/async-status.js +4 -0
- package/src/runs/background/auto-drain.js +2 -1
- package/src/runs/background/boot-id.d.ts +1 -3
- package/src/runs/background/boot-id.js +1 -3
- package/src/runs/background/completion-batcher.d.ts +3 -4
- package/src/runs/background/completion-batcher.js +2 -3
- package/src/runs/background/control-channel.d.ts +0 -6
- package/src/runs/background/control-channel.js +0 -6
- package/src/runs/background/fleet-view.js +2 -3
- package/src/runs/background/notify.d.ts +0 -2
- package/src/runs/background/notify.js +0 -2
- package/src/runs/background/result-watcher.d.ts +1 -0
- package/src/runs/background/result-watcher.js +59 -29
- package/src/runs/background/resume-guidance.js +4 -2
- package/src/runs/background/retained-children.js +2 -1
- package/src/runs/background/run-child-session.d.ts +2 -3
- package/src/runs/background/run-child-session.js +5 -8
- package/src/runs/background/run-status.js +9 -7
- package/src/runs/background/runner-aliases.js +15 -0
- package/src/runs/background/scheduled-runs.d.ts +3 -1
- package/src/runs/background/scheduled-runs.js +13 -16
- package/src/runs/background/steering.d.ts +2 -11
- package/src/runs/background/steering.js +11 -6
- package/src/runs/background/subagent-runner.d.ts +2 -6
- package/src/runs/background/subagent-runner.js +88 -70
- package/src/runs/background/subagent-wait.js +12 -15
- package/src/runs/background/wait-config.d.ts +2 -0
- package/src/runs/background/wait-config.js +17 -3
- package/src/runs/background/wait-subscriptions.js +124 -12
- package/src/runs/background/wait-tool.js +4 -2
- package/src/runs/background/workflow-terminal-proof.d.ts +0 -1
- package/src/runs/background/workflow-terminal-proof.js +0 -1
- package/src/runs/foreground/async-steering-action.js +24 -9
- package/src/runs/foreground/async-stop-action.d.ts +1 -1
- package/src/runs/foreground/async-stop-action.js +9 -1
- package/src/runs/foreground/execution.d.ts +0 -3
- package/src/runs/foreground/execution.js +68 -84
- package/src/runs/foreground/fork-tool-result-handler.d.ts +60 -0
- package/src/runs/foreground/fork-tool-result-handler.js +83 -0
- package/src/runs/foreground/prompt-audit.js +1 -0
- package/src/runs/foreground/subagent-executor.d.ts +5 -10
- package/src/runs/foreground/subagent-executor.js +164 -49
- package/src/runs/shared/acceptance.js +69 -26
- package/src/runs/shared/async-status-projection.d.ts +2 -0
- package/src/runs/shared/async-status-projection.js +10 -0
- package/src/runs/shared/child-commands.js +15 -2
- package/src/runs/shared/child-hooks.d.ts +1 -7
- package/src/runs/shared/child-hooks.js +13 -5
- package/src/runs/shared/child-launch.js +6 -2
- package/src/runs/shared/child-runtime-config.d.ts +0 -1
- package/src/runs/shared/child-session.d.ts +6 -5
- package/src/runs/shared/child-session.js +85 -38
- package/src/runs/shared/child-tool-plan.d.ts +0 -1
- package/src/runs/shared/child-tool-plan.js +0 -1
- package/src/runs/shared/claude-code-adapter.js +11 -0
- package/src/runs/shared/external-cli-contract.d.ts +49 -0
- package/src/runs/shared/external-cli-contract.js +18 -13
- package/src/runs/shared/external-cli-runner.js +26 -6
- package/src/runs/shared/herdr-connection.js +2 -1
- package/src/runs/shared/herdr-pane-host.d.ts +2 -2
- package/src/runs/shared/herdr-pane-host.js +17 -1
- package/src/runs/shared/herdr-placed-run.js +51 -24
- package/src/runs/shared/lane-metadata.d.ts +0 -1
- package/src/runs/shared/lane-metadata.js +0 -1
- package/src/runs/shared/mcp-config-sources.d.ts +4 -1
- package/src/runs/shared/mcp-config-sources.js +1 -1
- package/src/runs/shared/mcp-direct-tool-allowlist.d.ts +0 -3
- package/src/runs/shared/mcp-direct-tool-allowlist.js +26 -17
- package/src/runs/shared/mcp-direct-tool-grant.js +8 -1
- package/src/runs/shared/model-resolution-diagnostic.d.ts +0 -1
- package/src/runs/shared/model-resolution.d.ts +20 -5
- package/src/runs/shared/model-resolution.js +55 -50
- package/src/runs/shared/model-scope.d.ts +1 -5
- package/src/runs/shared/model-scope.js +1 -5
- package/src/runs/shared/mutation-evidence.d.ts +1 -1
- package/src/runs/shared/mutation-evidence.js +52 -7
- package/src/runs/shared/nested-events.d.ts +1 -0
- package/src/runs/shared/nested-events.js +1 -1
- package/src/runs/shared/parallel-utils.d.ts +0 -1
- package/src/runs/shared/permissions.js +5 -3
- package/src/runs/shared/placement-host.d.ts +5 -1
- package/src/runs/shared/rex-pane-host.d.ts +0 -1
- package/src/runs/shared/rex-pane-host.js +0 -2
- package/src/runs/shared/run-launch-folder.d.ts +12 -0
- package/src/runs/shared/run-launch-folder.js +21 -0
- package/src/runs/shared/runner-launcher.d.ts +12 -1
- package/src/runs/shared/runner-launcher.js +16 -0
- package/src/runs/shared/single-output.d.ts +3 -3
- package/src/runs/shared/single-output.js +5 -3
- package/src/runs/shared/structured-output.d.ts +8 -0
- package/src/runs/shared/structured-output.js +40 -5
- package/src/runs/shared/subagent-prompt-runtime.d.ts +0 -1
- package/src/runs/shared/subagent-prompt-runtime.js +18 -4
- package/src/runs/shared/supervisor-wait-timer.d.ts +16 -0
- package/src/runs/shared/supervisor-wait-timer.js +61 -0
- package/src/runs/shared/tool-timeout.js +2 -1
- package/src/runs/shared/worktree-cleanup-plan.d.ts +0 -1
- package/src/runs/shared/worktree-cleanup-plan.js +0 -1
- package/src/runs/shared/worktree.d.ts +3 -0
- package/src/runs/shared/worktree.js +20 -0
- package/src/shared/artifacts.d.ts +1 -0
- package/src/shared/artifacts.js +132 -22
- package/src/shared/capacity-resilient-json.d.ts +1 -1
- package/src/shared/child-cache-retention.d.ts +1 -2
- package/src/shared/child-cache-retention.js +1 -2
- package/src/shared/fleet-transcript-reader.d.ts +64 -0
- package/src/shared/fleet-transcript-reader.js +376 -0
- package/src/shared/formatters.d.ts +0 -18
- package/src/shared/formatters.js +0 -18
- package/src/shared/pruned-fork.js +2 -2
- package/src/shared/reported-progress.d.ts +1 -0
- package/src/shared/reported-progress.js +12 -0
- package/src/shared/session-succession.d.ts +16 -1
- package/src/shared/session-succession.js +41 -2
- package/src/shared/session-warnings.d.ts +7 -0
- package/src/shared/session-warnings.js +26 -0
- package/src/shared/settings.d.ts +0 -23
- package/src/shared/settings.js +3 -35
- package/src/shared/status-format.d.ts +1 -0
- package/src/shared/status-format.js +1 -1
- package/src/shared/types.d.ts +108 -59
- package/src/shared/types.js +0 -12
- package/src/shared/utils.d.ts +3 -15
- package/src/shared/utils.js +4 -22
- package/src/shared/wait-tool-name.d.ts +8 -0
- package/src/shared/wait-tool-name.js +13 -0
- package/src/slash/slash-commands.js +2 -1
- package/src/slash/subagent-cost.d.ts +3 -2
- package/src/slash/subagent-cost.js +22 -3
- package/src/slash/subagents-admin.js +0 -1
- package/src/tui/fleet-native-transcript.js +1 -1
- package/src/tui/fleet-status.d.ts +0 -5
- package/src/tui/fleet-status.js +4 -24
- package/src/tui/fleet-transcript.d.ts +1 -57
- package/src/tui/fleet-transcript.js +4 -370
- package/src/tui/fleet.js +6 -4
- package/src/tui/render.d.ts +0 -9
- package/src/tui/render.js +194 -68
- package/src/tui/subagent-messages.js +3 -2
- package/src/watchdog/model-selection.js +2 -2
- package/src/watchdog/permission-arbiter.js +1 -0
- package/src/watchdog/register-child.d.ts +2 -3
- package/src/watchdog/register-child.js +2 -3
- package/src/watchdog/review.d.ts +0 -5
- package/src/watchdog/review.js +4 -3
- package/src/watchdog/turn-delta.js +2 -1
- package/src/workflows/scripted-workflow.d.ts +2 -0
- package/src/workflows/scripted-workflow.js +344 -59
- package/src/workflows/structured-workflow-scripts.d.ts +4 -3
- package/src/workflows/structured-workflow-scripts.js +32 -11
- package/src/workflows/workflow-launch-record.d.ts +15 -6
- package/src/workflows/workflow-launch-record.js +30 -12
- package/src/workflows/workflow-receipt.js +36 -53
- package/src/workflows/workflow-resources.js +4 -4
- package/src/workflows/workflow-resume-claim.d.ts +2 -0
- package/src/workflows/workflow-resume-claim.js +3 -3
- package/src/workflows/workflow-resume.d.ts +1 -1
- package/src/workflows/workflow-resume.js +13 -8
- package/src/workflows/workflow-script-worker.d.ts +13 -0
- package/src/workflows/workflow-script-worker.js +81 -0
- package/workflow-script-process.cjs +36 -0
- package/workflow-script-worker.cjs +4 -1
- package/bundle/chunk-U4ODUYAG.js +0 -235
|
@@ -11,10 +11,10 @@ import {
|
|
|
11
11
|
setInlineWorkflowCoverage,
|
|
12
12
|
setMainThinkingLevelSource,
|
|
13
13
|
widgetRenderKey
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-LZ3HBDTR.js";
|
|
15
15
|
import {
|
|
16
16
|
package_default
|
|
17
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-TM2K53NX.js";
|
|
18
18
|
import {
|
|
19
19
|
EXTERNAL_JOB_BRIDGE_REQUEST_DIR,
|
|
20
20
|
REVIVAL_ORIGIN_FILE,
|
|
@@ -31,7 +31,7 @@ import {
|
|
|
31
31
|
createWaitSubscriptionManager,
|
|
32
32
|
deliverSubagentResultIntercomEvent,
|
|
33
33
|
deriveChildSessionName,
|
|
34
|
-
|
|
34
|
+
disposeChildSessionsForParent,
|
|
35
35
|
externalJobBridgeEligibility,
|
|
36
36
|
flattenSubagentToolOptions,
|
|
37
37
|
formatControlNoticeMessage,
|
|
@@ -51,6 +51,7 @@ import {
|
|
|
51
51
|
registerInspectorEventListener,
|
|
52
52
|
registerMainWatchdog,
|
|
53
53
|
registerPiWebSessionLiveness,
|
|
54
|
+
registerSubagentLaunchTool,
|
|
54
55
|
registerSubagentNotify,
|
|
55
56
|
releaseWorkflowResumeClaim,
|
|
56
57
|
renderInjectionBlock,
|
|
@@ -64,27 +65,20 @@ import {
|
|
|
64
65
|
snapshotProviderDiagnostics,
|
|
65
66
|
workflowResumeClaimState,
|
|
66
67
|
workflowResumeRefusal
|
|
67
|
-
} from "./chunk-
|
|
68
|
+
} from "./chunk-IXCEOEJT.js";
|
|
68
69
|
import {
|
|
69
70
|
listHerdrProjectPaneRoots,
|
|
70
71
|
restoreHerdrProjectPaneSnapshots
|
|
71
|
-
} from "./chunk-
|
|
72
|
+
} from "./chunk-SJPABBZG.js";
|
|
72
73
|
import {
|
|
73
|
-
CONTACT_SUPERVISOR_TOOL_NAME,
|
|
74
|
-
NATIVE_SUPERVISOR_TOOL_NAME,
|
|
75
74
|
SUBAGENT_CHILD_ENV,
|
|
76
75
|
SUBAGENT_PARENT_SESSION_ENV,
|
|
77
|
-
SUPERVISOR_REPLY_ENTRY_TYPE,
|
|
78
|
-
SUPERVISOR_REQUEST_MESSAGE_TYPE,
|
|
79
76
|
SubagentFlatParams,
|
|
80
77
|
completionReplayPath,
|
|
81
|
-
createNativeSupervisorChannel,
|
|
82
78
|
createSubagentParamsSchema,
|
|
83
79
|
drainOutstandingWork,
|
|
84
80
|
finalizeToolResult,
|
|
85
81
|
normalizeWatchdogWarningDetails,
|
|
86
|
-
parseSupervisorReplyData,
|
|
87
|
-
parseSupervisorRequestDetails,
|
|
88
82
|
readCompletionArchive,
|
|
89
83
|
readCompletionReplay,
|
|
90
84
|
recordWaitCompletion,
|
|
@@ -94,50 +88,68 @@ import {
|
|
|
94
88
|
resolveCurrentSessionId,
|
|
95
89
|
resolvePiSessionId,
|
|
96
90
|
resolveWaitToolConfig,
|
|
97
|
-
setDeclarationPinning
|
|
98
|
-
|
|
99
|
-
} from "./chunk-EUPJB4S7.js";
|
|
91
|
+
setDeclarationPinning
|
|
92
|
+
} from "./chunk-5Z7JAORM.js";
|
|
100
93
|
import {
|
|
101
94
|
deliverAsyncRunStop,
|
|
102
95
|
ownerConfirmedDead,
|
|
103
96
|
readSessionMessagesTail,
|
|
104
97
|
resolveSubagentRunId,
|
|
105
98
|
restoreForegroundRunHistory
|
|
106
|
-
} from "./chunk-
|
|
99
|
+
} from "./chunk-ULGMXABL.js";
|
|
107
100
|
import "./chunk-7J4ZXMY7.js";
|
|
108
101
|
import {
|
|
109
102
|
ASYNC_STATUS_SNAPSHOT_KIND,
|
|
110
103
|
ASYNC_STATUS_SNAPSHOT_VERSION,
|
|
111
|
-
MODEL_ONLY_TOOL,
|
|
112
|
-
canRenderComponents,
|
|
113
104
|
decodeUtf8Tail,
|
|
114
105
|
formatAsyncRunProgressLabel,
|
|
115
106
|
formatWorkflowPreflightSummary,
|
|
116
|
-
inheritedSessionIds,
|
|
117
|
-
isStaleExtensionContextError,
|
|
118
107
|
isStoppableAsyncStatusStep,
|
|
119
108
|
listAsyncRuns,
|
|
120
109
|
normalizeWorkflowPreflight,
|
|
121
|
-
ownerSessionIds,
|
|
122
|
-
ownsRun,
|
|
123
110
|
parseWorkflowChildSummary,
|
|
124
|
-
|
|
111
|
+
recoveryDescriptorPath,
|
|
125
112
|
resolveAsyncRunLocation,
|
|
126
113
|
resolveAsyncStatusChild,
|
|
127
|
-
|
|
114
|
+
runLaunchDir,
|
|
115
|
+
stopStoppableAsyncStatusChildren
|
|
116
|
+
} from "./chunk-DLVPMML3.js";
|
|
117
|
+
import {
|
|
118
|
+
CONTACT_SUPERVISOR_TOOL_NAME,
|
|
119
|
+
NATIVE_SUPERVISOR_TOOL_NAME,
|
|
120
|
+
SUPERVISOR_REPLY_ENTRY_TYPE,
|
|
121
|
+
SUPERVISOR_REQUEST_MESSAGE_TYPE,
|
|
122
|
+
createNativeSupervisorChannel,
|
|
123
|
+
parseSupervisorReplyData,
|
|
124
|
+
parseSupervisorRequestDetails,
|
|
125
|
+
topLevelSupervisorTool
|
|
126
|
+
} from "./chunk-34TUUBRN.js";
|
|
127
|
+
import {
|
|
128
|
+
MODEL_ONLY_TOOL,
|
|
129
|
+
canRenderComponents,
|
|
130
|
+
inheritedSessionIds,
|
|
131
|
+
isStaleExtensionContextError,
|
|
132
|
+
keepSessionWork,
|
|
133
|
+
ownerSessionIds,
|
|
134
|
+
ownsRun,
|
|
135
|
+
recordSessionReplacement,
|
|
136
|
+
recordSessionStart,
|
|
137
|
+
releaseSessionWork,
|
|
138
|
+
reportSessionWarning,
|
|
128
139
|
withCachedUiContext
|
|
129
|
-
} from "./chunk-
|
|
130
|
-
import "./chunk-
|
|
140
|
+
} from "./chunk-HXRB42AF.js";
|
|
141
|
+
import "./chunk-RMSABUN3.js";
|
|
131
142
|
import {
|
|
132
143
|
disabledFeatureUseError,
|
|
133
144
|
getActiveAsyncCapacitySnapshot,
|
|
134
145
|
loadConfig,
|
|
135
146
|
resolveAbandonedSlotReleaseAfterMs,
|
|
136
147
|
resolveAsyncByDefault,
|
|
148
|
+
resolveConfigDefaultTimeoutMs,
|
|
137
149
|
resolveDisabledFeatureSurface,
|
|
138
150
|
resolveMaxActiveAsyncRunsPerSession,
|
|
139
151
|
resolveScheduledStoreRoot
|
|
140
|
-
} from "./chunk-
|
|
152
|
+
} from "./chunk-U3ZDUUTM.js";
|
|
141
153
|
import {
|
|
142
154
|
ACTIVE_RUN_INDEX_DIR,
|
|
143
155
|
MissionNotFoundError,
|
|
@@ -146,10 +158,12 @@ import {
|
|
|
146
158
|
acknowledgeMissionObserverSnapshot,
|
|
147
159
|
checkRecordedPidLiveness,
|
|
148
160
|
cleanupResultIndexes,
|
|
161
|
+
collectNestedRuns,
|
|
149
162
|
currentCompletionOwnerId,
|
|
150
163
|
encodeIndexSegment,
|
|
151
164
|
findNestedRouteForRootId,
|
|
152
165
|
hasLiveNestedDescendants,
|
|
166
|
+
isActiveAsyncState,
|
|
153
167
|
isRecordedPid,
|
|
154
168
|
isReusableWorkflowStopCause,
|
|
155
169
|
listMissions,
|
|
@@ -186,26 +200,26 @@ import {
|
|
|
186
200
|
withWorkflowChildRunModel,
|
|
187
201
|
writeAsyncResultFile,
|
|
188
202
|
writeResultIndexForData
|
|
189
|
-
} from "./chunk-
|
|
203
|
+
} from "./chunk-JH5H4CYJ.js";
|
|
190
204
|
import {
|
|
191
205
|
cleanupAllArtifactDirs,
|
|
192
206
|
cleanupOldArtifacts,
|
|
193
207
|
getArtifactPaths,
|
|
194
208
|
getArtifactsDir
|
|
195
|
-
} from "./chunk-
|
|
209
|
+
} from "./chunk-LYKG4FKH.js";
|
|
196
210
|
import {
|
|
197
211
|
editableAgentConfig,
|
|
198
212
|
preservedAgentFrontmatterFields
|
|
199
|
-
} from "./chunk-
|
|
200
|
-
import "./chunk-
|
|
213
|
+
} from "./chunk-CGFF4WA3.js";
|
|
214
|
+
import "./chunk-LPJEKHOY.js";
|
|
201
215
|
import {
|
|
202
216
|
shouldUseNativeFsWatch
|
|
203
217
|
} from "./chunk-NIXWDZZV.js";
|
|
204
218
|
import {
|
|
205
219
|
validateIntercomBridgeConfig
|
|
206
|
-
} from "./chunk-
|
|
220
|
+
} from "./chunk-JAXVBXGF.js";
|
|
207
221
|
import "./chunk-BGIYHF2W.js";
|
|
208
|
-
import "./chunk-
|
|
222
|
+
import "./chunk-IH7LQVEE.js";
|
|
209
223
|
import "./chunk-CTPAE36Y.js";
|
|
210
224
|
import {
|
|
211
225
|
listBackgroundWorkProviders
|
|
@@ -214,14 +228,15 @@ import "./chunk-YYREO77V.js";
|
|
|
214
228
|
import "./chunk-UKG4V45O.js";
|
|
215
229
|
import {
|
|
216
230
|
registerRuntimeAgentEventListener
|
|
217
|
-
} from "./chunk-
|
|
231
|
+
} from "./chunk-66JNFRFS.js";
|
|
218
232
|
import {
|
|
219
233
|
clearRuntimeAgentsForPi,
|
|
220
234
|
listRuntimeAgentConfigs,
|
|
221
235
|
mergeRuntimeAgents
|
|
222
|
-
} from "./chunk-
|
|
236
|
+
} from "./chunk-INWSUNI6.js";
|
|
223
237
|
import {
|
|
224
238
|
DEFAULT_FILE_SYSTEM_RETRY_DELAYS_MS,
|
|
239
|
+
DEFAULT_WAIT_TOOL_NAME,
|
|
225
240
|
EXTRA_AGENT_DIRS_ENV,
|
|
226
241
|
FileLeaseBusyError,
|
|
227
242
|
SUBAGENT_WATCHDOG_WARNING_TYPE,
|
|
@@ -251,6 +266,7 @@ import {
|
|
|
251
266
|
resolveWatchPath,
|
|
252
267
|
runFileSystemOperationWithRetry,
|
|
253
268
|
serializeAgent,
|
|
269
|
+
setWaitToolName,
|
|
254
270
|
shortenPath,
|
|
255
271
|
splitKnownThinkingSuffix,
|
|
256
272
|
toModelInfo,
|
|
@@ -258,9 +274,10 @@ import {
|
|
|
258
274
|
validateOptionalMachine,
|
|
259
275
|
validateToolBudgetConfig,
|
|
260
276
|
waitForFileSystemRetry,
|
|
277
|
+
waitToolName,
|
|
261
278
|
withSettingsFileLease,
|
|
262
279
|
writeAtomicJson
|
|
263
|
-
} from "./chunk-
|
|
280
|
+
} from "./chunk-XAC2XNAP.js";
|
|
264
281
|
import {
|
|
265
282
|
DEFAULT_ARTIFACT_CONFIG,
|
|
266
283
|
DIRS,
|
|
@@ -320,6 +337,8 @@ import { exec, execFile } from "node:child_process";
|
|
|
320
337
|
import { promises as fs } from "node:fs";
|
|
321
338
|
import path from "node:path";
|
|
322
339
|
async function resolveGlobalNpmRoot(options = {}) {
|
|
340
|
+
const signal = options.signal;
|
|
341
|
+
if (signal?.aborted) return null;
|
|
323
342
|
const env = options.env ?? process.env;
|
|
324
343
|
const offline = env.PI_OFFLINE?.toLowerCase();
|
|
325
344
|
if (offline === "1" || offline === "true" || offline === "yes") return null;
|
|
@@ -330,6 +349,7 @@ async function resolveGlobalNpmRoot(options = {}) {
|
|
|
330
349
|
} catch {
|
|
331
350
|
}
|
|
332
351
|
}
|
|
352
|
+
if (signal?.aborted) return null;
|
|
333
353
|
const timeoutMs = options.timeoutMs ?? 5e3;
|
|
334
354
|
const output = await new Promise((resolve6) => {
|
|
335
355
|
let settled = false;
|
|
@@ -337,6 +357,7 @@ async function resolveGlobalNpmRoot(options = {}) {
|
|
|
337
357
|
if (settled) return;
|
|
338
358
|
settled = true;
|
|
339
359
|
clearTimeout(timer);
|
|
360
|
+
signal?.removeEventListener("abort", cancel);
|
|
340
361
|
resolve6(value);
|
|
341
362
|
};
|
|
342
363
|
const commandOptions = {
|
|
@@ -348,10 +369,12 @@ async function resolveGlobalNpmRoot(options = {}) {
|
|
|
348
369
|
};
|
|
349
370
|
const callback = (error, stdout) => finish(error ? null : stdout.trim());
|
|
350
371
|
const child = (options.platform ?? process.platform) === "win32" ? exec("npm root -g", commandOptions, callback) : execFile("npm", ["root", "-g"], commandOptions, callback);
|
|
351
|
-
const
|
|
372
|
+
const cancel = () => {
|
|
352
373
|
child.kill();
|
|
353
374
|
finish(null);
|
|
354
|
-
}
|
|
375
|
+
};
|
|
376
|
+
const timer = setTimeout(cancel, timeoutMs);
|
|
377
|
+
signal?.addEventListener("abort", cancel, { once: true });
|
|
355
378
|
});
|
|
356
379
|
if (!output) return null;
|
|
357
380
|
try {
|
|
@@ -786,6 +809,113 @@ function ensureAccessibleDir(dirPath, options = {}) {
|
|
|
786
809
|
}
|
|
787
810
|
}
|
|
788
811
|
|
|
812
|
+
// src/extension/session-switch.ts
|
|
813
|
+
var STAY = "Stay here";
|
|
814
|
+
var TAKE = "Switch and take the work";
|
|
815
|
+
var LEAVE = "Switch and leave the work here";
|
|
816
|
+
var RPC_PROMPT_TIMEOUT_MS = 6e4;
|
|
817
|
+
function createSessionSwitchGuard(deps) {
|
|
818
|
+
let leave;
|
|
819
|
+
let checking = false;
|
|
820
|
+
const lifetime = new AbortController();
|
|
821
|
+
const activeRunCount = (sessionId) => {
|
|
822
|
+
const runs = new Set(listAsyncRuns(deps.asyncDirRoot, {
|
|
823
|
+
sessionId,
|
|
824
|
+
states: ["queued", "running"],
|
|
825
|
+
resultsDir: deps.resultsDir,
|
|
826
|
+
includeNested: false
|
|
827
|
+
}).map((run) => run.id));
|
|
828
|
+
for (const job of deps.state.asyncJobs.values()) {
|
|
829
|
+
if (runs.has(job.asyncId) || !ownsRun(sessionId, job.sessionId) || !isActiveAsyncState(job.status)) continue;
|
|
830
|
+
let active = true;
|
|
831
|
+
try {
|
|
832
|
+
const status = readStatus(job.asyncDir);
|
|
833
|
+
active = !status || isActiveAsyncState(status.state);
|
|
834
|
+
} catch {
|
|
835
|
+
}
|
|
836
|
+
if (active) runs.add(job.asyncId);
|
|
837
|
+
}
|
|
838
|
+
for (const id of deps.state.workflowControllers?.keys() ?? []) runs.add(id);
|
|
839
|
+
return runs.size;
|
|
840
|
+
};
|
|
841
|
+
const hasNestedWork = (sessionId) => {
|
|
842
|
+
const routes = /* @__PURE__ */ new Map();
|
|
843
|
+
for (const job of deps.state.asyncJobs.values()) {
|
|
844
|
+
if (!ownsRun(sessionId, job.sessionId)) continue;
|
|
845
|
+
if (job.nestedRoute) routes.set(job.nestedRoute.rootRunId, job.nestedRoute);
|
|
846
|
+
else if (collectNestedRuns(job.nestedChildren).some((run) => isActiveAsyncState(run.state))) return true;
|
|
847
|
+
}
|
|
848
|
+
for (const control of deps.state.foregroundControls.values()) {
|
|
849
|
+
if (control.sessionId && !ownsRun(sessionId, control.sessionId)) continue;
|
|
850
|
+
if (control.nestedRoute) routes.set(control.nestedRoute.rootRunId, control.nestedRoute);
|
|
851
|
+
}
|
|
852
|
+
for (const route of deps.state.retainedForegroundNestedRoutes?.values() ?? []) routes.set(route.rootRunId, route);
|
|
853
|
+
if (deps.state.retainedNestedLookupRoutes?.sessionId === sessionId) {
|
|
854
|
+
for (const route of deps.state.retainedNestedLookupRoutes.routes.values()) routes.set(route.rootRunId, route);
|
|
855
|
+
}
|
|
856
|
+
return [...routes.values()].some((route) => {
|
|
857
|
+
reconcileNestedAsyncDescendants(route, { resultsDir: deps.resultsDir });
|
|
858
|
+
return collectNestedRuns(projectNestedEvents(route).children).some((run) => isActiveAsyncState(run.state));
|
|
859
|
+
});
|
|
860
|
+
};
|
|
861
|
+
return {
|
|
862
|
+
async beforeSwitch(reason, ctx) {
|
|
863
|
+
if (lifetime.signal.aborted || checking) return { cancel: true };
|
|
864
|
+
leave = void 0;
|
|
865
|
+
if (!ctx.hasUI) return;
|
|
866
|
+
checking = true;
|
|
867
|
+
try {
|
|
868
|
+
const sessionId = deps.state.currentSessionId;
|
|
869
|
+
if (!sessionId) throw new Error("The current session identity is unavailable.");
|
|
870
|
+
const runs = activeRunCount(sessionId);
|
|
871
|
+
const nested = hasNestedWork(sessionId);
|
|
872
|
+
const results = deps.hasPendingResults();
|
|
873
|
+
const questions = deps.hasPendingSupervisorRequest();
|
|
874
|
+
if (runs === 0 && !nested && !results && !questions) return;
|
|
875
|
+
const title = [
|
|
876
|
+
"pi-subagents: switch sessions?",
|
|
877
|
+
"",
|
|
878
|
+
"Background subagent work in this session:",
|
|
879
|
+
...runs > 0 ? [` ${runs} run${runs === 1 ? "" : "s"} queued or running`] : [],
|
|
880
|
+
...nested ? [" Nested subagents still running"] : [],
|
|
881
|
+
...results ? [" Undelivered results"] : [],
|
|
882
|
+
...questions ? [" Questions awaiting a reply"] : []
|
|
883
|
+
].join("\n");
|
|
884
|
+
const choice = await ctx.ui.select(title, [STAY, TAKE, LEAVE], { signal: lifetime.signal, timeout: ctx.mode === "rpc" ? RPC_PROMPT_TIMEOUT_MS : void 0 });
|
|
885
|
+
if (lifetime.signal.aborted || deps.state.currentSessionId !== sessionId) return { cancel: true };
|
|
886
|
+
if (choice === TAKE) return;
|
|
887
|
+
if (choice === LEAVE) {
|
|
888
|
+
leave = { sessionId, reason };
|
|
889
|
+
return;
|
|
890
|
+
}
|
|
891
|
+
return { cancel: true };
|
|
892
|
+
} catch (error) {
|
|
893
|
+
const message2 = error instanceof Error ? error.message : String(error);
|
|
894
|
+
try {
|
|
895
|
+
if (!lifetime.signal.aborted) ctx.ui.notify(`Session switch cancelled: ${message2}`, "warning");
|
|
896
|
+
} catch {
|
|
897
|
+
}
|
|
898
|
+
return { cancel: true };
|
|
899
|
+
} finally {
|
|
900
|
+
checking = false;
|
|
901
|
+
}
|
|
902
|
+
},
|
|
903
|
+
// Recorded only once the switch commits, so a switch another extension cancels keeps the default handoff.
|
|
904
|
+
sessionShutdown(event) {
|
|
905
|
+
const left = leave;
|
|
906
|
+
leave = void 0;
|
|
907
|
+
const sessionId = deps.state.currentSessionId;
|
|
908
|
+
if (!sessionId) return;
|
|
909
|
+
if (left && left.sessionId === sessionId && left.reason === event.reason) keepSessionWork(sessionId);
|
|
910
|
+
else releaseSessionWork(sessionId);
|
|
911
|
+
},
|
|
912
|
+
dispose() {
|
|
913
|
+
leave = void 0;
|
|
914
|
+
lifetime.abort();
|
|
915
|
+
}
|
|
916
|
+
};
|
|
917
|
+
}
|
|
918
|
+
|
|
789
919
|
// src/runs/background/async-job-tracker.ts
|
|
790
920
|
import * as fs3 from "node:fs";
|
|
791
921
|
import * as path2 from "node:path";
|
|
@@ -1411,7 +1541,17 @@ function createAsyncJobTracker(pi, state, asyncDirRoot, options = {}) {
|
|
|
1411
1541
|
if (now >= nextLivenessAt) {
|
|
1412
1542
|
nextLivenessAt = now + livenessIntervalMs;
|
|
1413
1543
|
let widgetChanged = false;
|
|
1544
|
+
const owners = state.currentSessionId ? ownerSessionIds(state.currentSessionId) : void 0;
|
|
1414
1545
|
for (const job of state.asyncJobs.values()) {
|
|
1546
|
+
if (owners && job.sessionId !== void 0 && !owners.has(job.sessionId)) {
|
|
1547
|
+
cancelCleanup(job.asyncId);
|
|
1548
|
+
closeJobWatcher(job.asyncId);
|
|
1549
|
+
state.asyncJobs.delete(job.asyncId);
|
|
1550
|
+
state.fleetJobs?.delete(job.asyncId);
|
|
1551
|
+
options.onJobCleanup?.(job.asyncId);
|
|
1552
|
+
widgetChanged = true;
|
|
1553
|
+
continue;
|
|
1554
|
+
}
|
|
1415
1555
|
watchJob(job);
|
|
1416
1556
|
if (refreshJob(job)) widgetChanged = true;
|
|
1417
1557
|
}
|
|
@@ -1645,7 +1785,7 @@ function hasNestedReferences(status) {
|
|
|
1645
1785
|
function hasResumableContract(runDir, status) {
|
|
1646
1786
|
const statusSessionFiles = [status.sessionFile, ...(status.steps ?? []).map((step) => step.sessionFile)];
|
|
1647
1787
|
if (statusSessionFiles.some(existingRegularFile)) return true;
|
|
1648
|
-
const descriptorPath = path3.
|
|
1788
|
+
const descriptorPath = recoveryDescriptorPath(path3.dirname(runDir), status.runId);
|
|
1649
1789
|
if (!fs4.existsSync(descriptorPath)) return false;
|
|
1650
1790
|
const descriptor = readJson(descriptorPath);
|
|
1651
1791
|
if (!descriptor) return true;
|
|
@@ -1789,9 +1929,13 @@ async function computeProcessStartIdentity(pid) {
|
|
|
1789
1929
|
}
|
|
1790
1930
|
if (process.platform === "win32") {
|
|
1791
1931
|
const started = await new Promise((resolve6) => {
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1932
|
+
try {
|
|
1933
|
+
execFile2("powershell.exe", ["-NoProfile", "-Command", `(Get-CimInstance Win32_Process -Filter "ProcessId=${pid}").CreationDate`], { encoding: "utf-8", windowsHide: true, timeout: 5e3 }, (error, stdout) => {
|
|
1934
|
+
resolve6(error ? "" : stdout.trim());
|
|
1935
|
+
});
|
|
1936
|
+
} catch {
|
|
1937
|
+
resolve6("");
|
|
1938
|
+
}
|
|
1795
1939
|
});
|
|
1796
1940
|
return started ? `win:${started}` : void 0;
|
|
1797
1941
|
}
|
|
@@ -2194,6 +2338,7 @@ async function cleanupAsyncRetention(options) {
|
|
|
2194
2338
|
}
|
|
2195
2339
|
mutationStateChanged = true;
|
|
2196
2340
|
fs4.rmSync(runDir, { recursive: true });
|
|
2341
|
+
fs4.rmSync(runLaunchDir(options.asyncDirRoot, status.runId), { recursive: true, force: true });
|
|
2197
2342
|
removeRunTombstoneMarker(maintenanceRoot, status.runId);
|
|
2198
2343
|
result.reapedTombstones += 1;
|
|
2199
2344
|
deletedIds.push(`run-tombstone:${status.runId}`);
|
|
@@ -2223,6 +2368,7 @@ async function cleanupAsyncRetention(options) {
|
|
|
2223
2368
|
continue;
|
|
2224
2369
|
}
|
|
2225
2370
|
fs4.rmSync(tombstone, { recursive: true });
|
|
2371
|
+
fs4.rmSync(runLaunchDir(options.asyncDirRoot, status.runId), { recursive: true, force: true });
|
|
2226
2372
|
removeRunTombstoneMarker(maintenanceRoot, status.runId);
|
|
2227
2373
|
result.deletedRuns += 1;
|
|
2228
2374
|
deletedIds.push(`run:${status.runId}`);
|
|
@@ -2378,15 +2524,19 @@ function resultFileIdentity(raw, file) {
|
|
|
2378
2524
|
runId: file.replace(/\.json$/i, "")
|
|
2379
2525
|
};
|
|
2380
2526
|
}
|
|
2381
|
-
function
|
|
2527
|
+
function reportResultWatcherWarning(state, message2, error, key = message2) {
|
|
2528
|
+
const detail = error === void 0 ? "" : `: ${error instanceof Error ? error.message : String(error)}`;
|
|
2529
|
+
reportSessionWarning(state, `${message2}${detail}`, key);
|
|
2530
|
+
}
|
|
2531
|
+
function sanitizeNestedResultChildren(state, value, resultPath, label) {
|
|
2382
2532
|
if (value === void 0) return void 0;
|
|
2383
2533
|
if (!Array.isArray(value)) {
|
|
2384
|
-
|
|
2534
|
+
reportResultWatcherWarning(state, `Ignoring invalid nested children in subagent result file '${resultPath}' at ${label}: expected an array.`);
|
|
2385
2535
|
return void 0;
|
|
2386
2536
|
}
|
|
2387
2537
|
const children = value.map((child) => sanitizeSummary(child)).filter((child) => Boolean(child));
|
|
2388
2538
|
if (children.length !== value.length) {
|
|
2389
|
-
|
|
2539
|
+
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}`);
|
|
2390
2540
|
}
|
|
2391
2541
|
return children.length ? children : void 0;
|
|
2392
2542
|
}
|
|
@@ -2432,6 +2582,7 @@ function createResultWatcher(pi, state, resultsDir, completionTtlMs, deps = {})
|
|
|
2432
2582
|
let deliveringPending = 0;
|
|
2433
2583
|
const identityCache = /* @__PURE__ */ new Map();
|
|
2434
2584
|
const reportedMissionSyncFailures = /* @__PURE__ */ new Map();
|
|
2585
|
+
let missionSyncReports = 0;
|
|
2435
2586
|
let deliveryActive = true;
|
|
2436
2587
|
let deliveryEpoch = 0;
|
|
2437
2588
|
let resultScanTimer = null;
|
|
@@ -2454,7 +2605,7 @@ function createResultWatcher(pi, state, resultsDir, completionTtlMs, deps = {})
|
|
|
2454
2605
|
try {
|
|
2455
2606
|
return fsApi.statSync(publicResultPath(file)).isFile();
|
|
2456
2607
|
} catch (error) {
|
|
2457
|
-
if (!isAbsentResultCandidate(error))
|
|
2608
|
+
if (!isAbsentResultCandidate(error)) reportResultWatcherWarning(state, `Failed to inspect subagent result file '${publicResultPath(file)}'`, error);
|
|
2458
2609
|
return false;
|
|
2459
2610
|
}
|
|
2460
2611
|
};
|
|
@@ -2487,7 +2638,7 @@ function createResultWatcher(pi, state, resultsDir, completionTtlMs, deps = {})
|
|
|
2487
2638
|
} catch (error) {
|
|
2488
2639
|
identityCache.delete(file);
|
|
2489
2640
|
if (isAccessDenied(error)) throw error;
|
|
2490
|
-
if (!isAbsentResultCandidate(error))
|
|
2641
|
+
if (!isAbsentResultCandidate(error)) reportResultWatcherWarning(state, `Failed to inspect subagent result file '${resultPath}'`, error);
|
|
2491
2642
|
return void 0;
|
|
2492
2643
|
}
|
|
2493
2644
|
};
|
|
@@ -2505,7 +2656,7 @@ function createResultWatcher(pi, state, resultsDir, completionTtlMs, deps = {})
|
|
|
2505
2656
|
} catch (error) {
|
|
2506
2657
|
identityCache.delete(file);
|
|
2507
2658
|
if (isAccessDenied(error)) throw error;
|
|
2508
|
-
if (!isAbsentResultCandidate(error))
|
|
2659
|
+
if (!isAbsentResultCandidate(error)) reportResultWatcherWarning(state, `Failed to inspect subagent result file '${resultPath}'`, error);
|
|
2509
2660
|
return void 0;
|
|
2510
2661
|
}
|
|
2511
2662
|
};
|
|
@@ -2513,7 +2664,7 @@ function createResultWatcher(pi, state, resultsDir, completionTtlMs, deps = {})
|
|
|
2513
2664
|
try {
|
|
2514
2665
|
return new Set(deps.observedCompletionRunIds?.() ?? []);
|
|
2515
2666
|
} catch (error) {
|
|
2516
|
-
|
|
2667
|
+
reportResultWatcherWarning(state, "Failed to inspect observed subagent completion ids", error);
|
|
2517
2668
|
return /* @__PURE__ */ new Set();
|
|
2518
2669
|
}
|
|
2519
2670
|
};
|
|
@@ -2533,7 +2684,7 @@ function createResultWatcher(pi, state, resultsDir, completionTtlMs, deps = {})
|
|
|
2533
2684
|
if (retireResultSnapshot(publicResultPath(file), read, void 0, CLEANUP_LEASE_WAIT_MS) === "replaced") scheduleResult(file, triggerTurn);
|
|
2534
2685
|
} catch (error) {
|
|
2535
2686
|
if (isAbsentResultCandidate(error)) return;
|
|
2536
|
-
if (!(error instanceof FileLeaseBusyError))
|
|
2687
|
+
if (!(error instanceof FileLeaseBusyError)) reportResultWatcherWarning(state, `Failed to remove delivered subagent result '${publicResultPath(file)}'; will retry`, error);
|
|
2537
2688
|
scheduleResult(file, triggerTurn, RETRY_DELAY_MS);
|
|
2538
2689
|
}
|
|
2539
2690
|
};
|
|
@@ -2548,7 +2699,7 @@ function createResultWatcher(pi, state, resultsDir, completionTtlMs, deps = {})
|
|
|
2548
2699
|
}
|
|
2549
2700
|
} catch (error) {
|
|
2550
2701
|
if (!isAccessDenied(error)) throw error;
|
|
2551
|
-
|
|
2702
|
+
reportResultWatcherWarning(state, `Failed to inspect subagent result file '${publicResultPath(file)}'; will retry`, error);
|
|
2552
2703
|
scheduleResult(file, triggerTurn, RETRY_DELAY_MS);
|
|
2553
2704
|
return;
|
|
2554
2705
|
}
|
|
@@ -2596,7 +2747,7 @@ function createResultWatcher(pi, state, resultsDir, completionTtlMs, deps = {})
|
|
|
2596
2747
|
if (!resultSnapshotReplaced(publicResultPath(file), read)) return false;
|
|
2597
2748
|
} catch (error) {
|
|
2598
2749
|
if (isAccessDenied(error)) throw error;
|
|
2599
|
-
|
|
2750
|
+
reportResultWatcherWarning(state, `Failed to re-read subagent result file '${publicResultPath(file)}'`, error);
|
|
2600
2751
|
}
|
|
2601
2752
|
identityCache.delete(file);
|
|
2602
2753
|
rereadReplacedPayload = true;
|
|
@@ -2611,21 +2762,21 @@ function createResultWatcher(pi, state, resultsDir, completionTtlMs, deps = {})
|
|
|
2611
2762
|
const message2 = error instanceof Error ? error.message : String(error);
|
|
2612
2763
|
if (reportedMissionSyncFailures.get(file) !== message2) {
|
|
2613
2764
|
reportedMissionSyncFailures.set(file, message2);
|
|
2614
|
-
|
|
2765
|
+
reportResultWatcherWarning(state, `Mission completion sync failed for '${resultPath}'`, error, `result-mission-sync-failed:${++missionSyncReports}`);
|
|
2615
2766
|
}
|
|
2616
2767
|
}
|
|
2617
2768
|
try {
|
|
2618
2769
|
deps.observeCompletion?.({ ...data, runId });
|
|
2619
2770
|
} catch (error) {
|
|
2620
2771
|
observerSucceeded = false;
|
|
2621
|
-
|
|
2772
|
+
reportResultWatcherWarning(state, `Completion observer failed for '${resultPath}'`, error);
|
|
2622
2773
|
}
|
|
2623
2774
|
if (observerSucceeded) {
|
|
2624
2775
|
try {
|
|
2625
2776
|
if (acknowledgeMissionObserverSnapshot(publicResultPath(file), read, CLEANUP_LEASE_WAIT_MS) === "replaced") rereadReplacedPayload = true;
|
|
2626
2777
|
} catch (error) {
|
|
2627
2778
|
observerSucceeded = false;
|
|
2628
|
-
if (!(error instanceof FileLeaseBusyError))
|
|
2779
|
+
if (!(error instanceof FileLeaseBusyError)) reportResultWatcherWarning(state, `Failed to acknowledge the mission observer for '${resultPath}'; will retry`, error);
|
|
2629
2780
|
}
|
|
2630
2781
|
}
|
|
2631
2782
|
const epoch = deliveryEpoch;
|
|
@@ -2635,12 +2786,12 @@ function createResultWatcher(pi, state, resultsDir, completionTtlMs, deps = {})
|
|
|
2635
2786
|
sessionId
|
|
2636
2787
|
});
|
|
2637
2788
|
const hasExplicitNestedChildren = data.nestedChildren !== void 0;
|
|
2638
|
-
let nestedChildren = compactNestedResultChildren(sanitizeNestedResultChildren(data.nestedChildren, resultPath, "nestedChildren"));
|
|
2789
|
+
let nestedChildren = compactNestedResultChildren(sanitizeNestedResultChildren(state, data.nestedChildren, resultPath, "nestedChildren"));
|
|
2639
2790
|
if (!nestedChildren?.length && !hasExplicitNestedChildren) {
|
|
2640
2791
|
try {
|
|
2641
2792
|
nestedChildren = compactNestedResultChildren(projectNestedRegistryForRoot(runId)?.children);
|
|
2642
2793
|
} catch (error) {
|
|
2643
|
-
|
|
2794
|
+
reportResultWatcherWarning(state, `Failed to enrich subagent result file '${resultPath}' with nested registry children; will retry later`, error);
|
|
2644
2795
|
scheduleResult(file, triggerTurn, RETRY_DELAY_MS);
|
|
2645
2796
|
return;
|
|
2646
2797
|
}
|
|
@@ -2678,7 +2829,7 @@ ${structuredPreview}` : "(no output)";
|
|
|
2678
2829
|
Output:
|
|
2679
2830
|
${baseOutput}` : ""}` : output;
|
|
2680
2831
|
const sessionPath = result.sessionFile ?? (resultChildren.length === 1 ? data.sessionFile : void 0);
|
|
2681
|
-
const childNestedChildren = sanitizeNestedResultChildren(result.children, resultPath, `results[${index}].children`);
|
|
2832
|
+
const childNestedChildren = sanitizeNestedResultChildren(state, result.children, resultPath, `results[${index}].children`);
|
|
2682
2833
|
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;
|
|
2683
2834
|
return {
|
|
2684
2835
|
agent: result.agent ?? data.agent ?? `step-${index + 1}`,
|
|
@@ -2733,7 +2884,7 @@ ${baseOutput}` : ""}` : output;
|
|
|
2733
2884
|
...data.parallelHandoff ? { parallelHandoff: data.parallelHandoff } : {}
|
|
2734
2885
|
}));
|
|
2735
2886
|
if (!ownsCompletion(sessionId, completionOwnerId, epoch)) return;
|
|
2736
|
-
if (!intercomDelivered)
|
|
2887
|
+
if (!intercomDelivered) reportResultWatcherWarning(state, `Subagent async grouped result intercom delivery was not acknowledged for '${resultPath}'.`);
|
|
2737
2888
|
}
|
|
2738
2889
|
const delivery = notifier.deliver({
|
|
2739
2890
|
...data,
|
|
@@ -2774,7 +2925,7 @@ ${baseOutput}` : ""}` : output;
|
|
|
2774
2925
|
}
|
|
2775
2926
|
({ data, read } = marked);
|
|
2776
2927
|
} catch (error) {
|
|
2777
|
-
|
|
2928
|
+
reportResultWatcherWarning(state, `Failed to mark subagent result notification delivered for '${resultPath}'; will retry`, error);
|
|
2778
2929
|
scheduleResult(file, triggerTurn, RETRY_DELAY_MS);
|
|
2779
2930
|
return;
|
|
2780
2931
|
}
|
|
@@ -2800,7 +2951,7 @@ ${baseOutput}` : ""}` : output;
|
|
|
2800
2951
|
} : {}
|
|
2801
2952
|
});
|
|
2802
2953
|
} catch (error) {
|
|
2803
|
-
|
|
2954
|
+
reportResultWatcherWarning(state, `Completion observer failed for '${resultPath}'`, error);
|
|
2804
2955
|
}
|
|
2805
2956
|
if (!observerSucceeded) {
|
|
2806
2957
|
scheduleResult(file, triggerTurn, RETRY_DELAY_MS);
|
|
@@ -2814,9 +2965,9 @@ ${baseOutput}` : ""}` : output;
|
|
|
2814
2965
|
removeDeliveredResult(file, triggerTurn, read);
|
|
2815
2966
|
} catch (error) {
|
|
2816
2967
|
if (isAccessDenied(error)) {
|
|
2817
|
-
|
|
2968
|
+
reportResultWatcherWarning(state, `Failed to process subagent result file '${resultPath}'; will retry`, error);
|
|
2818
2969
|
scheduleResult(file, triggerTurn, RETRY_DELAY_MS);
|
|
2819
|
-
} else if (!isNotFound2(error))
|
|
2970
|
+
} else if (!isNotFound2(error)) reportResultWatcherWarning(state, `Failed to process subagent result file '${resultPath}'`, error);
|
|
2820
2971
|
} finally {
|
|
2821
2972
|
processing.delete(file);
|
|
2822
2973
|
if (rereadReplacedPayload) scheduleResult(file, triggerTurn);
|
|
@@ -2836,7 +2987,7 @@ ${baseOutput}` : ""}` : output;
|
|
|
2836
2987
|
const resultScanLogging = deps.resultScanLogging ?? "activity";
|
|
2837
2988
|
if (resultScanLogging === "off") return;
|
|
2838
2989
|
if (resultScanLogging === "activity" && stats.files === 0 && stats.scheduled === 0) return;
|
|
2839
|
-
|
|
2990
|
+
reportSessionWarning(state, `Subagent result scan inspected ${stats.files} indexed result file(s), scheduled ${stats.scheduled} in ${elapsed}ms (${resultsDir}).`, "slow-result-scan");
|
|
2840
2991
|
};
|
|
2841
2992
|
const indexedResultCandidates = (observed) => {
|
|
2842
2993
|
const files = /* @__PURE__ */ new Set();
|
|
@@ -2864,10 +3015,27 @@ ${baseOutput}` : ""}` : output;
|
|
|
2864
3015
|
}
|
|
2865
3016
|
logScanStats(stats);
|
|
2866
3017
|
} catch (error) {
|
|
2867
|
-
if (!isNotFound2(error))
|
|
3018
|
+
if (!isNotFound2(error)) reportResultWatcherWarning(state, `Failed to scan subagent result index in '${resultsDir}'`, error);
|
|
2868
3019
|
}
|
|
2869
3020
|
return files;
|
|
2870
3021
|
};
|
|
3022
|
+
const hasPendingResults = () => eligibleResultFiles().some((file) => {
|
|
3023
|
+
const payloadPath = resultPayloadPath(file);
|
|
3024
|
+
if (!payloadPath) return false;
|
|
3025
|
+
let raw;
|
|
3026
|
+
try {
|
|
3027
|
+
raw = fsApi.readFileSync(payloadPath, "utf-8");
|
|
3028
|
+
} catch (error) {
|
|
3029
|
+
return !isNotFound2(error);
|
|
3030
|
+
}
|
|
3031
|
+
const identity = resultFileIdentity(raw, file);
|
|
3032
|
+
if (!identity.sessionId || !ownsResult(identity.sessionId, deliveryOwnerId(identity.sessionId, identity.completionOwnerId, identity.completionOwnerProcess, identity.parentWorkflowRunId))) return false;
|
|
3033
|
+
try {
|
|
3034
|
+
return !hasDeliveredNotification(parseResult(raw));
|
|
3035
|
+
} catch {
|
|
3036
|
+
return true;
|
|
3037
|
+
}
|
|
3038
|
+
});
|
|
2871
3039
|
const primeExistingResults = (options = {}) => {
|
|
2872
3040
|
const triggerTurn = options.triggerTurn !== false;
|
|
2873
3041
|
for (const file of eligibleResultFiles()) scheduleResult(file, triggerTurn);
|
|
@@ -2895,7 +3063,7 @@ ${baseOutput}` : ""}` : output;
|
|
|
2895
3063
|
try {
|
|
2896
3064
|
return deps.hasDeliveryDemand?.() === true;
|
|
2897
3065
|
} catch (error) {
|
|
2898
|
-
|
|
3066
|
+
reportResultWatcherWarning(state, "Failed to inspect subagent result delivery demand", error);
|
|
2899
3067
|
return false;
|
|
2900
3068
|
}
|
|
2901
3069
|
};
|
|
@@ -2919,7 +3087,7 @@ ${baseOutput}` : ""}` : output;
|
|
|
2919
3087
|
state.watcher = null;
|
|
2920
3088
|
clearResultScan();
|
|
2921
3089
|
if (state.watcherRestartTimer) return;
|
|
2922
|
-
|
|
3090
|
+
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}`);
|
|
2923
3091
|
primeExistingResults();
|
|
2924
3092
|
state.watcherRestartTimer = timers.setInterval(primeExistingResults, POLL_INTERVAL_MS);
|
|
2925
3093
|
state.watcherRestartTimer.unref?.();
|
|
@@ -2934,7 +3102,7 @@ ${baseOutput}` : ""}` : output;
|
|
|
2934
3102
|
startResultWatcher();
|
|
2935
3103
|
} catch (error) {
|
|
2936
3104
|
if (shouldPoll(error)) return startPolling(error);
|
|
2937
|
-
|
|
3105
|
+
reportResultWatcherWarning(state, `Failed to restart subagent result watcher for '${resultsDir}'`, error);
|
|
2938
3106
|
scheduleRestart();
|
|
2939
3107
|
}
|
|
2940
3108
|
}, WATCHER_RESTART_DELAY_MS);
|
|
@@ -2973,7 +3141,7 @@ ${baseOutput}` : ""}` : output;
|
|
|
2973
3141
|
});
|
|
2974
3142
|
state.watcher.on("error", (error) => {
|
|
2975
3143
|
if (shouldPoll(error)) return startPolling(error);
|
|
2976
|
-
|
|
3144
|
+
reportResultWatcherWarning(state, `Subagent result watcher failed for '${resultsDir}'`, error);
|
|
2977
3145
|
state.watcher?.close();
|
|
2978
3146
|
state.watcher = null;
|
|
2979
3147
|
scheduleRestart();
|
|
@@ -2983,7 +3151,7 @@ ${baseOutput}` : ""}` : output;
|
|
|
2983
3151
|
resultScanTimer.unref?.();
|
|
2984
3152
|
} catch (error) {
|
|
2985
3153
|
if (shouldPoll(error)) return startPolling(error);
|
|
2986
|
-
|
|
3154
|
+
reportResultWatcherWarning(state, `Failed to start subagent result watcher for '${resultsDir}'`, error);
|
|
2987
3155
|
state.watcher = null;
|
|
2988
3156
|
scheduleRestart();
|
|
2989
3157
|
}
|
|
@@ -3007,7 +3175,7 @@ ${baseOutput}` : ""}` : output;
|
|
|
3007
3175
|
processing.clear();
|
|
3008
3176
|
identityCache.clear();
|
|
3009
3177
|
};
|
|
3010
|
-
return { startResultWatcher, transitionResultDelivery, primeExistingResults, deliverPendingResults, stopResultWatcher, refreshResultDelivery: () => {
|
|
3178
|
+
return { startResultWatcher, transitionResultDelivery, primeExistingResults, deliverPendingResults, hasPendingResults, stopResultWatcher, refreshResultDelivery: () => {
|
|
3011
3179
|
primeExistingResults();
|
|
3012
3180
|
startDemandPolling();
|
|
3013
3181
|
} };
|
|
@@ -4418,9 +4586,20 @@ function detailsFromSessionEntry(entry) {
|
|
|
4418
4586
|
}
|
|
4419
4587
|
if (record.type !== "message" || !record.message || typeof record.message !== "object") return void 0;
|
|
4420
4588
|
const message2 = record.message;
|
|
4421
|
-
if (message2.role !== "toolResult" || message2.toolName !== "subagent" && message2.toolName !==
|
|
4589
|
+
if (message2.role !== "toolResult" || message2.toolName !== "subagent" && message2.toolName !== waitToolName() && message2.toolName !== DEFAULT_WAIT_TOOL_NAME) return void 0;
|
|
4422
4590
|
return isSubagentDetails(message2.details) ? message2.details : void 0;
|
|
4423
4591
|
}
|
|
4592
|
+
function notifiedAsyncRuns(entry) {
|
|
4593
|
+
if (!entry || typeof entry !== "object") return [];
|
|
4594
|
+
const record = entry;
|
|
4595
|
+
if (record.type !== "custom_message" || record.customType !== "subagent-notify") return [];
|
|
4596
|
+
const runs = record.details?.runs;
|
|
4597
|
+
if (!Array.isArray(runs)) return [];
|
|
4598
|
+
return runs.flatMap((run) => (
|
|
4599
|
+
// A detached foreground task keeps no async status directory to read usage from.
|
|
4600
|
+
run && typeof run.runId === "string" && run.source !== "foreground" ? [{ runId: run.runId, workflow: run.workflowRunId === run.runId }] : []
|
|
4601
|
+
));
|
|
4602
|
+
}
|
|
4424
4603
|
function metadataUsage(artifactsDirs, input, indexes = [0, void 0]) {
|
|
4425
4604
|
if (!/^[A-Za-z0-9._-]+$/.test(input.runId)) return void 0;
|
|
4426
4605
|
for (const artifactsDir of artifactsDirs) {
|
|
@@ -4469,6 +4648,7 @@ function collectSubagentCost(ctx, state) {
|
|
|
4469
4648
|
const message2 = entry.type === "message" ? entry.message : void 0;
|
|
4470
4649
|
const parentUsage = assistantUsageFromMessage(message2) ?? compactionUsageFromEntry(entry);
|
|
4471
4650
|
if (parentUsage) addUsage(parent, parentUsage);
|
|
4651
|
+
for (const run of notifiedAsyncRuns(entry)) (run.workflow ? workflowRunIds : asyncRunIds).add(run.runId);
|
|
4472
4652
|
const details = detailsFromSessionEntry(entry);
|
|
4473
4653
|
if (!details) continue;
|
|
4474
4654
|
if (details.mode === "workflow" && details.runId && details.asyncId) workflowRunIds.add(details.runId);
|
|
@@ -5564,7 +5744,7 @@ function registerSlashCommands(pi, state, options = {}) {
|
|
|
5564
5744
|
}
|
|
5565
5745
|
fleetOpen = true;
|
|
5566
5746
|
try {
|
|
5567
|
-
const { openSubagentFleet } = await import("./chunk-
|
|
5747
|
+
const { openSubagentFleet } = await import("./chunk-FQPV4O6C.js");
|
|
5568
5748
|
await openSubagentFleet(ctx, state, { asyncDirRoot: DIRS.async, inspectorPlugins: () => getInspectorPlugins(pi), resultsDir: DIRS.results, fleetKeybindings: options.fleetKeybindings, events: pi.events });
|
|
5569
5749
|
} finally {
|
|
5570
5750
|
fleetOpen = false;
|
|
@@ -5691,7 +5871,7 @@ ${finalTask}`;
|
|
|
5691
5871
|
ctx.ui.notify(`Foreground run ${control.runId} is not currently detachable.`, "info");
|
|
5692
5872
|
return;
|
|
5693
5873
|
}
|
|
5694
|
-
sendSlashText(pi, `Detached foreground run ${control.runId} without terminating its child. Use subagent({ action: "status", id: ${JSON.stringify(control.runId)} }) or
|
|
5874
|
+
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.`);
|
|
5695
5875
|
};
|
|
5696
5876
|
pi.registerCommand("subagents-detach", {
|
|
5697
5877
|
description: "Detach the active foreground single-subagent run without terminating it",
|
|
@@ -7141,8 +7321,8 @@ function supervisorReminderHeadline(details, status) {
|
|
|
7141
7321
|
return [`${ids.length} supervisor ${ids.length === 1 ? "request" : "requests"} `, { status }];
|
|
7142
7322
|
}
|
|
7143
7323
|
function waitSubscriptionHeadline(details) {
|
|
7144
|
-
if (!isRecord3(details) || typeof details.runId !== "string" || typeof details.outcome !== "string") return [
|
|
7145
|
-
return [
|
|
7324
|
+
if (!isRecord3(details) || typeof details.runId !== "string" || typeof details.outcome !== "string") return [`${waitToolName()} fired`];
|
|
7325
|
+
return [`${waitToolName()}: run ${details.runId} `, { status: details.outcome }];
|
|
7146
7326
|
}
|
|
7147
7327
|
function workflowChildHeadline(message2) {
|
|
7148
7328
|
const { details } = message2;
|
|
@@ -8154,16 +8334,19 @@ function registerSubagentRpcBridge(options) {
|
|
|
8154
8334
|
import { Type } from "typebox";
|
|
8155
8335
|
var LOADER_NAME = "subagents_enable";
|
|
8156
8336
|
var SUBAGENT_NAME = "subagent";
|
|
8157
|
-
var
|
|
8158
|
-
|
|
8337
|
+
var isUnloadSentinel = (name) => name === LOADER_NAME || name === SUBAGENT_NAME || name === waitToolName();
|
|
8338
|
+
function isOwnWaitDefinition(tool) {
|
|
8339
|
+
const properties = tool.parameters?.properties;
|
|
8340
|
+
return typeof properties === "object" && properties !== null && Object.hasOwn(properties, "nonBlocking") && Object.hasOwn(properties, "stopOnAttention");
|
|
8341
|
+
}
|
|
8159
8342
|
function hasNativeToolSelection(messages) {
|
|
8160
8343
|
return messages.some((message2) => message2.role === "system" && (Object.hasOwn(message2, "toolsAdded") || Object.hasOwn(message2, "toolsRemoved")));
|
|
8161
8344
|
}
|
|
8162
8345
|
function setSelection(pi, includeSubagent, includeLoader, includeWait, restore = [], keepParentSupervisor = false) {
|
|
8163
|
-
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 !==
|
|
8346
|
+
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()));
|
|
8164
8347
|
if (includeSubagent) next.push(SUBAGENT_NAME, CONTACT_SUPERVISOR_TOOL_NAME, NATIVE_SUPERVISOR_TOOL_NAME);
|
|
8165
8348
|
if (includeLoader) next.push(LOADER_NAME);
|
|
8166
|
-
if (includeWait) next.push(
|
|
8349
|
+
if (includeWait) next.push(waitToolName());
|
|
8167
8350
|
pi.setActiveTools([...new Set(next)]);
|
|
8168
8351
|
}
|
|
8169
8352
|
function addsToolsWithoutCheckpoint(model) {
|
|
@@ -8186,19 +8369,25 @@ function applyRecordedSelection(pi, ctx, mode, replyOwed) {
|
|
|
8186
8369
|
const available = pi.getAllTools();
|
|
8187
8370
|
if (!Array.isArray(available) || !Array.isArray(pi.getActiveTools())) return true;
|
|
8188
8371
|
if (!available.some((tool) => tool.name === LOADER_NAME)) return true;
|
|
8189
|
-
|
|
8372
|
+
let messages = ctx.sessionManager.buildSessionContext().messages;
|
|
8373
|
+
if (messages[0]?.role === "system" && messages[1]?.role === "compactionSummary") {
|
|
8374
|
+
const branch = ctx.sessionManager.getBranch();
|
|
8375
|
+
const history = branch.slice(0, branch.findLastIndex((entry) => entry.type === "compaction")).flatMap((entry) => entry.type === "message" && entry.message.role === "system" ? [entry.message] : []);
|
|
8376
|
+
messages = [...history, ...messages.slice(1)];
|
|
8377
|
+
}
|
|
8190
8378
|
const lost = messages.find((message2) => message2.role === "system" || message2.role === "compactionSummary")?.role === "compactionSummary";
|
|
8191
8379
|
if (lost || hasNativeToolSelection(messages)) {
|
|
8192
8380
|
const recorded = /* @__PURE__ */ new Set();
|
|
8193
8381
|
const unloadedNames = /* @__PURE__ */ new Set();
|
|
8194
8382
|
const declaredSentinels = /* @__PURE__ */ new Set();
|
|
8195
8383
|
const evidenced = /* @__PURE__ */ new Set();
|
|
8384
|
+
let legacyWaitIsOwn = false;
|
|
8196
8385
|
for (const message2 of messages) {
|
|
8197
8386
|
if (message2.role !== "system") continue;
|
|
8198
|
-
const removedSentinels = (message2.toolsRemoved ?? []).filter((tool) =>
|
|
8387
|
+
const removedSentinels = (message2.toolsRemoved ?? []).filter((tool) => isUnloadSentinel(tool.name));
|
|
8199
8388
|
const allDeclared = removedSentinels.every((tool) => declaredSentinels.has(tool.name));
|
|
8200
8389
|
for (const tool of message2.toolsRemoved ?? []) declaredSentinels.delete(tool.name);
|
|
8201
|
-
for (const tool of message2.toolsAdded ?? []) if (
|
|
8390
|
+
for (const tool of message2.toolsAdded ?? []) if (isUnloadSentinel(tool.name)) declaredSentinels.add(tool.name);
|
|
8202
8391
|
const unloaded = removedSentinels.length > 0 && allDeclared && declaredSentinels.size === 0;
|
|
8203
8392
|
for (const tool of message2.toolsRemoved ?? []) {
|
|
8204
8393
|
if (unloaded) unloadedNames.add(tool.name);
|
|
@@ -8210,19 +8399,21 @@ function applyRecordedSelection(pi, ctx, mode, replyOwed) {
|
|
|
8210
8399
|
for (const tool of message2.toolsAdded ?? []) {
|
|
8211
8400
|
recorded.add(tool.name);
|
|
8212
8401
|
evidenced.add(tool.name);
|
|
8402
|
+
if (tool.name === DEFAULT_WAIT_TOOL_NAME) legacyWaitIsOwn = isOwnWaitDefinition(tool);
|
|
8213
8403
|
}
|
|
8214
8404
|
}
|
|
8215
8405
|
const fresh = lost && !evidenced.has(LOADER_NAME) && !evidenced.has(SUBAGENT_NAME);
|
|
8216
8406
|
const startsEager = fresh && mode === "auto" && !addsToolsWithoutCheckpoint(ctx.model);
|
|
8217
8407
|
const loaderSelected = mode === "dynamic" || recorded.has(LOADER_NAME) || fresh && !startsEager;
|
|
8408
|
+
const waitRecord = waitToolName() !== DEFAULT_WAIT_TOOL_NAME && !evidenced.has(waitToolName()) && legacyWaitIsOwn ? DEFAULT_WAIT_TOOL_NAME : waitToolName();
|
|
8218
8409
|
const source = unloadedNames.size > 0 ? available.find((tool) => tool.name === LOADER_NAME)?.sourceInfo.path : void 0;
|
|
8219
8410
|
const restore = source === void 0 ? [] : available.filter((tool) => unloadedNames.has(tool.name) && recorded.has(tool.name) && tool.sourceInfo.path === source).map((tool) => tool.name);
|
|
8220
|
-
setSelection(pi, recorded.has(SUBAGENT_NAME) || startsEager, loaderSelected, recorded.has(
|
|
8411
|
+
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));
|
|
8221
8412
|
return loaderSelected;
|
|
8222
8413
|
}
|
|
8223
8414
|
const eager = mode === "auto" && messages.length === 0 && !addsToolsWithoutCheckpoint(ctx.model);
|
|
8224
8415
|
const kept = (name) => eager || messages.length > 0 && pi.getActiveTools().includes(name);
|
|
8225
|
-
setSelection(pi, kept(SUBAGENT_NAME), !eager, kept(
|
|
8416
|
+
setSelection(pi, kept(SUBAGENT_NAME), !eager, kept(waitToolName()), replyOwed ? [NATIVE_SUPERVISOR_TOOL_NAME] : [], replyOwed || messages.length > 0);
|
|
8226
8417
|
return !eager;
|
|
8227
8418
|
}
|
|
8228
8419
|
function registerSubagentToolActivation(pi, options) {
|
|
@@ -8267,18 +8458,26 @@ ${advertised}` : ""}` }],
|
|
|
8267
8458
|
};
|
|
8268
8459
|
registerPinnedTool(pi, loader);
|
|
8269
8460
|
let loaderSelected = true;
|
|
8461
|
+
let undeclared;
|
|
8462
|
+
const activationState = () => [LOADER_NAME, SUBAGENT_NAME].map((name) => pi.getActiveTools().includes(name)).join();
|
|
8270
8463
|
const replyOwed = () => options.hasPendingSupervisorRequest?.() === true;
|
|
8271
|
-
|
|
8464
|
+
const decide = (ctx) => {
|
|
8272
8465
|
loaderSelected = applyRecordedSelection(pi, ctx, mode, replyOwed());
|
|
8466
|
+
undeclared = Array.isArray(pi.getActiveTools()) ? activationState() : void 0;
|
|
8467
|
+
};
|
|
8468
|
+
pi.on("session_start", (_event, ctx) => decide(ctx));
|
|
8469
|
+
pi.on("session_tree", (_event, ctx) => decide(ctx));
|
|
8470
|
+
pi.on("agent_start", () => {
|
|
8471
|
+
undeclared = void 0;
|
|
8273
8472
|
});
|
|
8274
|
-
pi.on("
|
|
8275
|
-
loaderSelected
|
|
8473
|
+
pi.on("model_select", (_event, ctx) => {
|
|
8474
|
+
if (mode === "auto" && ctx.isIdle() && undeclared === activationState() && loaderSelected !== addsToolsWithoutCheckpoint(ctx.model) && ctx.sessionManager.buildSessionContext().messages.length === 0) decide(ctx);
|
|
8276
8475
|
});
|
|
8277
8476
|
pi.on("before_agent_start", (event) => {
|
|
8278
8477
|
const available = pi.getAllTools();
|
|
8279
8478
|
if (!Array.isArray(available) || !available.some((tool) => tool.name === LOADER_NAME)) return;
|
|
8280
|
-
const providedWait = available.some((tool) => tool.name ===
|
|
8281
|
-
const names = [...loaderSelected ? [LOADER_NAME] : [], ...providedWait ? [
|
|
8479
|
+
const providedWait = available.some((tool) => tool.name === waitToolName()) && listBackgroundWorkProviders().length > 0;
|
|
8480
|
+
const names = [...loaderSelected ? [LOADER_NAME] : [], ...providedWait ? [waitToolName()] : []];
|
|
8282
8481
|
if (names.length === 0) return;
|
|
8283
8482
|
const selectedTools = event.systemPromptOptions.selectedTools ??= [...pi.getActiveTools()];
|
|
8284
8483
|
for (const name of names) if (!selectedTools.includes(name)) selectedTools.push(name);
|
|
@@ -8415,7 +8614,6 @@ var allEnabled = featureText(resolveDisabledFeatureSurface({}));
|
|
|
8415
8614
|
var DEFAULT_SUBAGENT_TOOL_DESCRIPTION = essentials(allEnabled);
|
|
8416
8615
|
var SUBAGENT_TOOL_PROMPT_SNIPPET = "Delegate focused work to child agents; compose multi-child work in one workflow call.";
|
|
8417
8616
|
var STRUCTURED_SUBAGENT_TOOL_PROMPT_SNIPPET = "Delegate focused work to child agents; compose multi-child work in one chain or tasks call.";
|
|
8418
|
-
var COMPACT_SUBAGENT_TOOL_DESCRIPTION = DEFAULT_SUBAGENT_TOOL_DESCRIPTION;
|
|
8419
8617
|
var FULL_SUBAGENT_TOOL_DESCRIPTION = fullDescription(allEnabled);
|
|
8420
8618
|
function isToolDescriptionMode(value) {
|
|
8421
8619
|
return value === "full" || value === "compact" || value === "custom";
|
|
@@ -8442,15 +8640,15 @@ function customDescriptionPaths(options) {
|
|
|
8442
8640
|
path12.join(agentDir, CUSTOM_TOOL_DESCRIPTION_FILE)
|
|
8443
8641
|
];
|
|
8444
8642
|
}
|
|
8445
|
-
function renderCustomTemplate(template, options) {
|
|
8643
|
+
function renderCustomTemplate(template, on, options) {
|
|
8446
8644
|
const cwd = options?.cwd ?? process.cwd();
|
|
8447
8645
|
const agentDir = options?.agentDir ?? getAgentDir();
|
|
8448
8646
|
const projectConfigDir = getProjectConfigDir(cwd);
|
|
8449
8647
|
const variables = {
|
|
8450
|
-
fullDescription: () =>
|
|
8451
|
-
full: () =>
|
|
8452
|
-
compactDescription: () =>
|
|
8453
|
-
compact: () =>
|
|
8648
|
+
fullDescription: () => fullDescription(on),
|
|
8649
|
+
full: () => fullDescription(on),
|
|
8650
|
+
compactDescription: () => essentials(on),
|
|
8651
|
+
compact: () => essentials(on),
|
|
8454
8652
|
safetyGuidance: () => SUBAGENT_SAFETY_GUIDANCE,
|
|
8455
8653
|
safety: () => SUBAGENT_SAFETY_GUIDANCE,
|
|
8456
8654
|
agentDir: () => agentDir,
|
|
@@ -8463,7 +8661,7 @@ function renderCustomTemplate(template, options) {
|
|
|
8463
8661
|
return raw;
|
|
8464
8662
|
});
|
|
8465
8663
|
}
|
|
8466
|
-
function loadCustomToolDescription(options) {
|
|
8664
|
+
function loadCustomToolDescription(on, options) {
|
|
8467
8665
|
for (const filePath of customDescriptionPaths(options)) {
|
|
8468
8666
|
let stat;
|
|
8469
8667
|
try {
|
|
@@ -8487,7 +8685,7 @@ function loadCustomToolDescription(options) {
|
|
|
8487
8685
|
warn(options, `Ignoring empty custom tool description '${filePath}'.`);
|
|
8488
8686
|
continue;
|
|
8489
8687
|
}
|
|
8490
|
-
const rendered = renderCustomTemplate(template, options).trim();
|
|
8688
|
+
const rendered = renderCustomTemplate(template, on, options).trim();
|
|
8491
8689
|
if (!rendered) {
|
|
8492
8690
|
warn(options, `Ignoring custom tool description '${filePath}' because it rendered empty.`);
|
|
8493
8691
|
continue;
|
|
@@ -8506,12 +8704,17 @@ function withMandatorySafetyGuidance(description) {
|
|
|
8506
8704
|
${SUBAGENT_SAFETY_GUIDANCE}` : SUBAGENT_SAFETY_GUIDANCE;
|
|
8507
8705
|
}
|
|
8508
8706
|
function buildSubagentToolDescription(config = {}, options) {
|
|
8707
|
+
const description = describeSubagentTool(config, options);
|
|
8708
|
+
const name = waitToolName();
|
|
8709
|
+
return name === DEFAULT_WAIT_TOOL_NAME ? description : description.replace(/\bbg_wait\b/g, name);
|
|
8710
|
+
}
|
|
8711
|
+
function describeSubagentTool(config, options) {
|
|
8509
8712
|
const on = options?.disabledFeatures ? featureText(options.disabledFeatures) : allEnabled;
|
|
8510
8713
|
if (config.toolDescriptionMode === void 0) return essentials(on);
|
|
8511
8714
|
const mode = resolveToolDescriptionMode(config, options);
|
|
8512
8715
|
if (mode === "compact") return essentials(on);
|
|
8513
8716
|
if (mode === "custom") {
|
|
8514
|
-
const custom = loadCustomToolDescription(options);
|
|
8717
|
+
const custom = loadCustomToolDescription(on, options);
|
|
8515
8718
|
if (custom) return withMandatorySafetyGuidance(custom);
|
|
8516
8719
|
warn(options, `${CUSTOM_TOOL_DESCRIPTION_FILE} was not found or valid for toolDescriptionMode "custom"; using full description.`);
|
|
8517
8720
|
}
|
|
@@ -8829,9 +9032,9 @@ function getRuntimeRegistry() {
|
|
|
8829
9032
|
globalStore[RUNTIME_REGISTRY_STORE_KEY] = registry;
|
|
8830
9033
|
return registry;
|
|
8831
9034
|
}
|
|
8832
|
-
function logSlowPhase(label, startedAt) {
|
|
9035
|
+
function logSlowPhase(state, label, startedAt) {
|
|
8833
9036
|
const elapsed = Date.now() - startedAt;
|
|
8834
|
-
if (elapsed >= SLOW_RELOAD_PHASE_MS)
|
|
9037
|
+
if (elapsed >= SLOW_RELOAD_PHASE_MS) reportSessionWarning(state, `Subagent reload phase '${label}' took ${elapsed}ms.`, `slow-reload-phase:${label}`);
|
|
8835
9038
|
}
|
|
8836
9039
|
function formatWorkflowPreflightCall(input) {
|
|
8837
9040
|
if (input === void 0) return "";
|
|
@@ -8928,6 +9131,7 @@ function registerSubagentExtension(pi) {
|
|
|
8928
9131
|
const config = loadConfig();
|
|
8929
9132
|
setDeclarationPinning(pi, config.pinToolDeclarations !== false);
|
|
8930
9133
|
const waitToolConfig = resolveWaitToolConfig(config.waitTool);
|
|
9134
|
+
setWaitToolName(waitToolConfig.name ?? DEFAULT_WAIT_TOOL_NAME);
|
|
8931
9135
|
const asyncByDefault = resolveAsyncByDefault(config);
|
|
8932
9136
|
const fleetViewEnabled = config.fleetView !== false;
|
|
8933
9137
|
const slashCommandsEnabled = config.enableSlashCommands !== false;
|
|
@@ -9009,7 +9213,7 @@ function registerSubagentExtension(pi) {
|
|
|
9009
9213
|
const ctx = withLastUiContext((current) => current);
|
|
9010
9214
|
if (!ctx) return;
|
|
9011
9215
|
try {
|
|
9012
|
-
const { openSubagentFleet } = await import("./chunk-
|
|
9216
|
+
const { openSubagentFleet } = await import("./chunk-FQPV4O6C.js");
|
|
9013
9217
|
await openSubagentFleet(ctx, state, { initialKey: itemKey, asyncDirRoot: DIRS.async, resultsDir: DIRS.results, fleetKeybindings: config.fleetKeybindings, inspectorPlugins: () => getInspectorPlugins(pi), events: pi.events });
|
|
9014
9218
|
} catch (error) {
|
|
9015
9219
|
if (isStaleExtensionContextError(error)) {
|
|
@@ -9032,13 +9236,15 @@ function registerSubagentExtension(pi) {
|
|
|
9032
9236
|
await waitForAdvertisement();
|
|
9033
9237
|
return (await getExecutor()).executeScheduled(randomUUID3(), params, signal, ctx);
|
|
9034
9238
|
},
|
|
9035
|
-
resolveCapabilityCeiling: (sessionId) => resolveCurrentSubagentCapabilityCeiling(sessionId)
|
|
9239
|
+
resolveCapabilityCeiling: (sessionId) => resolveCurrentSubagentCapabilityCeiling(sessionId),
|
|
9240
|
+
reportWarning: (message2, key) => reportSessionWarning(state, message2, key)
|
|
9036
9241
|
});
|
|
9037
9242
|
let refreshResultDelivery = () => {
|
|
9038
9243
|
};
|
|
9039
9244
|
let advertisedAgents = [];
|
|
9040
9245
|
let advertisedContext;
|
|
9041
9246
|
let advertisementGeneration = 0;
|
|
9247
|
+
let advertisementLookup;
|
|
9042
9248
|
let globalRoot = null;
|
|
9043
9249
|
let advertisementReady = Promise.resolve();
|
|
9044
9250
|
let notifySessionChange = () => {
|
|
@@ -9060,6 +9266,8 @@ function registerSubagentExtension(pi) {
|
|
|
9060
9266
|
};
|
|
9061
9267
|
const beginAdvertisement = (ctx) => {
|
|
9062
9268
|
const generation = ++advertisementGeneration;
|
|
9269
|
+
advertisementLookup?.abort();
|
|
9270
|
+
advertisementLookup = new AbortController();
|
|
9063
9271
|
notifySessionChange();
|
|
9064
9272
|
sessionChanged = new Promise((resolve6) => {
|
|
9065
9273
|
notifySessionChange = resolve6;
|
|
@@ -9067,7 +9275,7 @@ function registerSubagentExtension(pi) {
|
|
|
9067
9275
|
advertisedAgents = [];
|
|
9068
9276
|
advertisedContext = { cwd: ctx.cwd, model: ctx.model, projectTrusted: typeof ctx.isProjectTrusted === "function" ? ctx.isProjectTrusted() : void 0 };
|
|
9069
9277
|
globalRoot = null;
|
|
9070
|
-
advertisementReady = resolveGlobalNpmRoot().then((root) => {
|
|
9278
|
+
advertisementReady = resolveGlobalNpmRoot({ signal: advertisementLookup.signal }).then((root) => {
|
|
9071
9279
|
if (generation !== advertisementGeneration) return;
|
|
9072
9280
|
globalRoot = root;
|
|
9073
9281
|
refreshAdvertisedAgents();
|
|
@@ -9142,6 +9350,15 @@ function registerSubagentExtension(pi) {
|
|
|
9142
9350
|
}
|
|
9143
9351
|
);
|
|
9144
9352
|
const { startResultWatcher, transitionResultDelivery, primeExistingResults, stopResultWatcher } = resultWatcher;
|
|
9353
|
+
const sessionSwitchGuard = createSessionSwitchGuard({
|
|
9354
|
+
state,
|
|
9355
|
+
asyncDirRoot: DIRS.async,
|
|
9356
|
+
resultsDir: DIRS.results,
|
|
9357
|
+
hasPendingResults: () => owedResultRunIds.size > 0 || completionNotifier.hasPendingDelivery() || resultWatcher.hasPendingResults(),
|
|
9358
|
+
hasPendingSupervisorRequest: supervisorChannel.hasPendingRequests
|
|
9359
|
+
});
|
|
9360
|
+
pi.on("session_before_switch", (event, ctx) => sessionSwitchGuard.beforeSwitch(event.reason, ctx));
|
|
9361
|
+
pi.on("session_before_fork", (_event, ctx) => sessionSwitchGuard.beforeSwitch("fork", ctx));
|
|
9145
9362
|
refreshResultDelivery = resultWatcher.refreshResultDelivery;
|
|
9146
9363
|
const asyncRetentionAbort = new AbortController();
|
|
9147
9364
|
let asyncRetentionTimer;
|
|
@@ -9171,7 +9388,7 @@ function registerSubagentExtension(pi) {
|
|
|
9171
9388
|
])
|
|
9172
9389
|
});
|
|
9173
9390
|
} catch (error) {
|
|
9174
|
-
|
|
9391
|
+
reportSessionWarning(state, `Failed to clean retained async subagent state: ${error instanceof Error ? error.message : String(error)}`, "async-retention-cleanup");
|
|
9175
9392
|
}
|
|
9176
9393
|
}, ASYNC_RETENTION_DELAY_MS);
|
|
9177
9394
|
asyncRetentionTimer.unref?.();
|
|
@@ -9207,7 +9424,7 @@ function registerSubagentExtension(pi) {
|
|
|
9207
9424
|
let executor;
|
|
9208
9425
|
let executorPromise;
|
|
9209
9426
|
let executorModulePromise;
|
|
9210
|
-
const loadExecutorModule = () => executorModulePromise ??= import("./chunk-
|
|
9427
|
+
const loadExecutorModule = () => executorModulePromise ??= import("./chunk-KRNBJPZ2.js");
|
|
9211
9428
|
const getExecutor = () => {
|
|
9212
9429
|
executorPromise ??= loadExecutorModule().then(({ createSubagentExecutor }) => {
|
|
9213
9430
|
executor = createSubagentExecutor(executorDeps);
|
|
@@ -9221,7 +9438,7 @@ function registerSubagentExtension(pi) {
|
|
|
9221
9438
|
modulePreloadTimer = setTimeout(() => {
|
|
9222
9439
|
loadExecutorModule().catch(() => {
|
|
9223
9440
|
});
|
|
9224
|
-
if (fleetViewEnabled) import("./chunk-
|
|
9441
|
+
if (fleetViewEnabled) import("./chunk-FQPV4O6C.js").catch(() => {
|
|
9225
9442
|
});
|
|
9226
9443
|
}, MODULE_PRELOAD_DELAY_MS);
|
|
9227
9444
|
modulePreloadTimer.unref?.();
|
|
@@ -9387,6 +9604,7 @@ ${close}` }]
|
|
|
9387
9604
|
};
|
|
9388
9605
|
registerPinnedTool(pi, tool);
|
|
9389
9606
|
registerPinnedTool(pi, topLevelSupervisorTool());
|
|
9607
|
+
registerSubagentLaunchTool(pi);
|
|
9390
9608
|
pi.on("before_agent_start", (event, ctx) => {
|
|
9391
9609
|
if (process.env[SUBAGENT_CHILD_ENV] === "1") return void 0;
|
|
9392
9610
|
const projectTrusted = typeof ctx.isProjectTrusted !== "function" || ctx.isProjectTrusted() !== false;
|
|
@@ -9419,7 +9637,7 @@ ${close}` }]
|
|
|
9419
9637
|
const active = activeAsyncJobCount();
|
|
9420
9638
|
if (active > 0) ctx.ui.notify(`${active} background subagent run${active === 1 ? " is" : "s are"} still active${slashCommandsEnabled ? " \xB7 /subagents-stop" : ""}`, "info");
|
|
9421
9639
|
}
|
|
9422
|
-
if (!ctx.hasUI) await drainOutstandingWork({ state, events: pi.events, hasPendingSupervisorRequest: supervisorChannel.hasPendingRequests }).then(resultWatcher.deliverPendingResults);
|
|
9640
|
+
if (!ctx.hasUI) await drainOutstandingWork({ state, events: pi.events, hasPendingSupervisorRequest: supervisorChannel.hasPendingRequests, timeoutMs: resolveConfigDefaultTimeoutMs(config.timeoutMs) }).then(resultWatcher.deliverPendingResults);
|
|
9423
9641
|
} finally {
|
|
9424
9642
|
const ownerSessionId = state.currentSessionId;
|
|
9425
9643
|
if (ownerSessionId) {
|
|
@@ -9545,11 +9763,12 @@ ${close}` }]
|
|
|
9545
9763
|
{ liveWorkflowRunIds: new Set(state.workflowControllers?.keys() ?? []), abandonedSlotReleaseAfterMs: resolveAbandonedSlotReleaseAfterMs(config.capacity?.abandonedSlotReleaseAfterMs) }
|
|
9546
9764
|
);
|
|
9547
9765
|
};
|
|
9548
|
-
const resetSessionState = (ctx, recovering, previousSessionFile) => {
|
|
9766
|
+
const resetSessionState = (ctx, recovering, startup, previousSessionFile) => {
|
|
9549
9767
|
state.widgetsSuspended = false;
|
|
9550
9768
|
state.baseCwd = ctx.cwd;
|
|
9551
9769
|
goalTurnId = 0;
|
|
9552
9770
|
state.currentSessionId = resolveCurrentSessionId(ctx.sessionManager);
|
|
9771
|
+
recordSessionStart(state.currentSessionId, startup);
|
|
9553
9772
|
if (previousSessionFile) recordSessionReplacement(state.currentSessionId, previousSessionFile);
|
|
9554
9773
|
state.supervisorOwnerSessionId = ctx.sessionManager.getSessionId() || null;
|
|
9555
9774
|
disposeSupervisorRoutingForOwner(pi, state.supervisorOwnerSessionId);
|
|
@@ -9577,10 +9796,10 @@ ${close}` }]
|
|
|
9577
9796
|
state.lastUiContext = ctx;
|
|
9578
9797
|
let phaseStartedAt = Date.now();
|
|
9579
9798
|
refreshActiveAsyncCapacity();
|
|
9580
|
-
logSlowPhase("active-capacity", phaseStartedAt);
|
|
9799
|
+
logSlowPhase(state, "active-capacity", phaseStartedAt);
|
|
9581
9800
|
phaseStartedAt = Date.now();
|
|
9582
9801
|
cleanupSessionArtifacts(ctx);
|
|
9583
|
-
logSlowPhase("session-artifact-cleanup", phaseStartedAt);
|
|
9802
|
+
logSlowPhase(state, "session-artifact-cleanup", phaseStartedAt);
|
|
9584
9803
|
state.foregroundControls.clear();
|
|
9585
9804
|
retainedNestedRouteTracker?.clear();
|
|
9586
9805
|
retainedNestedRouteTracker = void 0;
|
|
@@ -9588,17 +9807,17 @@ ${close}` }]
|
|
|
9588
9807
|
state.lastForegroundControlId = null;
|
|
9589
9808
|
phaseStartedAt = Date.now();
|
|
9590
9809
|
resetJobs(ctx);
|
|
9591
|
-
logSlowPhase("reset-jobs", phaseStartedAt);
|
|
9810
|
+
logSlowPhase(state, "reset-jobs", phaseStartedAt);
|
|
9592
9811
|
phaseStartedAt = Date.now();
|
|
9593
9812
|
const interruptedElsewhere = ctx.hasUI ? createInterruptedElsewhereCollector({ currentSessionId: state.currentSessionId, cwd: ctx.cwd, now: Date.now() }) : void 0;
|
|
9594
9813
|
restoreForegroundRunHistory(state, { resultsDir: DIRS.results, observeForeign: interruptedElsewhere?.observeForegroundRun });
|
|
9595
|
-
logSlowPhase("foreground-history", phaseStartedAt);
|
|
9814
|
+
logSlowPhase(state, "foreground-history", phaseStartedAt);
|
|
9596
9815
|
phaseStartedAt = Date.now();
|
|
9597
9816
|
restoreActiveJobs(ctx, interruptedElsewhere?.observeStatus);
|
|
9598
|
-
logSlowPhase("active-job-restore", phaseStartedAt);
|
|
9817
|
+
logSlowPhase(state, "active-job-restore", phaseStartedAt);
|
|
9599
9818
|
phaseStartedAt = Date.now();
|
|
9600
9819
|
if (interruptedElsewhere) for (const line of interruptedElsewhere.lines()) ctx.ui.notify(line, "info");
|
|
9601
|
-
logSlowPhase("cross-session-notice", phaseStartedAt);
|
|
9820
|
+
logSlowPhase(state, "cross-session-notice", phaseStartedAt);
|
|
9602
9821
|
phaseStartedAt = Date.now();
|
|
9603
9822
|
cancelPendingWorkflowAutoResumes((entry) => entry.owner === autoResumeOwner);
|
|
9604
9823
|
if (recovering && ctx.hasUI && config.autoResume !== false) {
|
|
@@ -9606,22 +9825,22 @@ ${close}` }]
|
|
|
9606
9825
|
void launchWorkflowAutoResume(entry, ctx);
|
|
9607
9826
|
}
|
|
9608
9827
|
}
|
|
9609
|
-
logSlowPhase("workflow-auto-resume", phaseStartedAt);
|
|
9828
|
+
logSlowPhase(state, "workflow-auto-resume", phaseStartedAt);
|
|
9610
9829
|
phaseStartedAt = Date.now();
|
|
9611
9830
|
scheduledRunManager.bindSession(ctx);
|
|
9612
|
-
logSlowPhase("scheduled-runs", phaseStartedAt);
|
|
9831
|
+
logSlowPhase(state, "scheduled-runs", phaseStartedAt);
|
|
9613
9832
|
phaseStartedAt = Date.now();
|
|
9614
9833
|
restoreSlashFinalSnapshots(ctx.sessionManager.getEntries());
|
|
9615
|
-
logSlowPhase("slash-snapshots", phaseStartedAt);
|
|
9834
|
+
logSlowPhase(state, "slash-snapshots", phaseStartedAt);
|
|
9616
9835
|
phaseStartedAt = Date.now();
|
|
9617
9836
|
waitSubscriptionManager.restore();
|
|
9618
|
-
logSlowPhase("wait-subscriptions", phaseStartedAt);
|
|
9837
|
+
logSlowPhase(state, "wait-subscriptions", phaseStartedAt);
|
|
9619
9838
|
phaseStartedAt = Date.now();
|
|
9620
9839
|
startResultWatcher();
|
|
9621
|
-
logSlowPhase("result-watcher-start", phaseStartedAt);
|
|
9840
|
+
logSlowPhase(state, "result-watcher-start", phaseStartedAt);
|
|
9622
9841
|
phaseStartedAt = Date.now();
|
|
9623
9842
|
primeExistingResults({ triggerTurn: !recovering });
|
|
9624
|
-
logSlowPhase("result-prime", phaseStartedAt);
|
|
9843
|
+
logSlowPhase(state, "result-prime", phaseStartedAt);
|
|
9625
9844
|
fleetStatus?.setContext(ctx);
|
|
9626
9845
|
};
|
|
9627
9846
|
let contextInjectionProjectTrusted;
|
|
@@ -9657,6 +9876,12 @@ ${close}` }]
|
|
|
9657
9876
|
cleanup(shutdownReason) {
|
|
9658
9877
|
if (runtimeCleaned) return;
|
|
9659
9878
|
runtimeCleaned = true;
|
|
9879
|
+
sessionSwitchGuard.dispose();
|
|
9880
|
+
++advertisementGeneration;
|
|
9881
|
+
advertisementLookup?.abort();
|
|
9882
|
+
advertisedAgents = [];
|
|
9883
|
+
advertisedContext = void 0;
|
|
9884
|
+
notifySessionChange();
|
|
9660
9885
|
cancelPendingWorkflowAutoResumes((entry) => entry.owner === autoResumeOwner);
|
|
9661
9886
|
programStatus.dispose(shutdownReason);
|
|
9662
9887
|
releaseHostSessionLiveness();
|
|
@@ -9809,7 +10034,7 @@ ${close}` }]
|
|
|
9809
10034
|
scheduleModulePreload();
|
|
9810
10035
|
const recovering = event.reason === "startup" || event.reason === "reload" || event.reason === "resume";
|
|
9811
10036
|
disposeGoalAutoContinueGate();
|
|
9812
|
-
resetSessionState(ctx, recovering, event.previousSessionFile);
|
|
10037
|
+
resetSessionState(ctx, recovering, event.reason === "startup", event.previousSessionFile);
|
|
9813
10038
|
refreshContextInjectionSnapshot(ctx);
|
|
9814
10039
|
disposeGoalAutoContinueGate = registerGoalAutoContinueGate(pi, {
|
|
9815
10040
|
state,
|
|
@@ -9843,12 +10068,14 @@ ${close}` }]
|
|
|
9843
10068
|
supervisorChannel.activateTransport();
|
|
9844
10069
|
});
|
|
9845
10070
|
pi.on("session_shutdown", async (event) => {
|
|
10071
|
+
const parentSessionFile = state.parentSessionFile ?? void 0;
|
|
10072
|
+
sessionSwitchGuard.sessionShutdown(event);
|
|
9846
10073
|
cancelCompactionResume();
|
|
9847
10074
|
completionNotifier.sessionShutdown(event?.reason);
|
|
9848
10075
|
parentWake.sessionShutdown(event?.reason);
|
|
9849
10076
|
runtimeEntry.cleanup(event?.reason);
|
|
9850
10077
|
try {
|
|
9851
|
-
await
|
|
10078
|
+
await disposeChildSessionsForParent(parentSessionFile);
|
|
9852
10079
|
} catch (error) {
|
|
9853
10080
|
console.error("Failed to dispose in-process child sessions:", error);
|
|
9854
10081
|
}
|