@narumitw/pi-subagents 2.1.3 → 3.0.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/README.md +181 -1250
- package/dist/child-communication-bridge.ts +136 -0
- package/dist/child-communication-bridge.ts.map +7 -0
- package/dist/chunks/chunk-UKTWUQRM.js +667 -0
- package/dist/chunks/chunk-UKTWUQRM.js.map +7 -0
- package/dist/index.ts +1448 -1598
- package/dist/index.ts.map +4 -4
- package/docs/design-principles.md +31 -0
- package/docs/ipc-transport-idea.md +103 -0
- package/docs/tools.md +109 -0
- package/package.json +11 -19
- package/src/broker-credentials.ts +71 -0
- package/src/child-communication-bridge.ts +153 -0
- package/src/child-communication-tools.ts +147 -0
- package/src/completion-renderer.ts +60 -0
- package/src/index.ts +1 -1
- package/src/message-broker.ts +628 -0
- package/src/model-output.ts +42 -0
- package/src/process.ts +688 -0
- package/src/runtime.ts +538 -0
- package/src/subagents.ts +33 -34
- package/src/tools.ts +416 -0
- package/src/types.ts +85 -0
- package/src/widget.ts +130 -0
- package/dist/chunks/auto-transport-FUUKFDIG.ts +0 -109
- package/dist/chunks/auto-transport-FUUKFDIG.ts.map +0 -7
- package/dist/chunks/capability-grant-PR72SWWS.ts +0 -19
- package/dist/chunks/capability-grant-PR72SWWS.ts.map +0 -7
- package/dist/chunks/child-peer-bridge.ts +0 -108
- package/dist/chunks/child-peer-bridge.ts.map +0 -7
- package/dist/chunks/chunk-2LMJU25E.ts +0 -1641
- package/dist/chunks/chunk-2LMJU25E.ts.map +0 -7
- package/dist/chunks/chunk-47SK2QYC.ts +0 -56
- package/dist/chunks/chunk-47SK2QYC.ts.map +0 -7
- package/dist/chunks/chunk-4AQSF7AS.ts +0 -29
- package/dist/chunks/chunk-4AQSF7AS.ts.map +0 -7
- package/dist/chunks/chunk-5DGRMKNV.ts +0 -126
- package/dist/chunks/chunk-5DGRMKNV.ts.map +0 -7
- package/dist/chunks/chunk-6H6TBBED.ts +0 -108
- package/dist/chunks/chunk-6H6TBBED.ts.map +0 -7
- package/dist/chunks/chunk-6KJ34M6S.ts +0 -159
- package/dist/chunks/chunk-6KJ34M6S.ts.map +0 -7
- package/dist/chunks/chunk-6NSJVPXX.ts +0 -480
- package/dist/chunks/chunk-6NSJVPXX.ts.map +0 -7
- package/dist/chunks/chunk-7AAJEUSL.ts +0 -238
- package/dist/chunks/chunk-7AAJEUSL.ts.map +0 -7
- package/dist/chunks/chunk-BFK2Z4ZF.ts +0 -189
- package/dist/chunks/chunk-BFK2Z4ZF.ts.map +0 -7
- package/dist/chunks/chunk-BOAXY55Y.ts +0 -153
- package/dist/chunks/chunk-BOAXY55Y.ts.map +0 -7
- package/dist/chunks/chunk-D4CR7T73.ts +0 -353
- package/dist/chunks/chunk-D4CR7T73.ts.map +0 -7
- package/dist/chunks/chunk-FEVPWRMU.ts +0 -300
- package/dist/chunks/chunk-FEVPWRMU.ts.map +0 -7
- package/dist/chunks/chunk-G6VZTCFH.ts +0 -70
- package/dist/chunks/chunk-G6VZTCFH.ts.map +0 -7
- package/dist/chunks/chunk-H3FP6DLR.ts +0 -160
- package/dist/chunks/chunk-H3FP6DLR.ts.map +0 -7
- package/dist/chunks/chunk-HA36LPCO.ts +0 -130
- package/dist/chunks/chunk-HA36LPCO.ts.map +0 -7
- package/dist/chunks/chunk-HOP5FXDT.ts +0 -27
- package/dist/chunks/chunk-HOP5FXDT.ts.map +0 -7
- package/dist/chunks/chunk-IGAMVWFN.ts +0 -139
- package/dist/chunks/chunk-IGAMVWFN.ts.map +0 -7
- package/dist/chunks/chunk-ILEQ27AL.ts +0 -45
- package/dist/chunks/chunk-ILEQ27AL.ts.map +0 -7
- package/dist/chunks/chunk-ITVWPNU4.ts +0 -819
- package/dist/chunks/chunk-ITVWPNU4.ts.map +0 -7
- package/dist/chunks/chunk-IWC32VPY.ts +0 -172
- package/dist/chunks/chunk-IWC32VPY.ts.map +0 -7
- package/dist/chunks/chunk-JSZIP73U.ts +0 -362
- package/dist/chunks/chunk-JSZIP73U.ts.map +0 -7
- package/dist/chunks/chunk-JU6LUNLP.ts +0 -380
- package/dist/chunks/chunk-JU6LUNLP.ts.map +0 -7
- package/dist/chunks/chunk-KMGKCEO4.ts +0 -38
- package/dist/chunks/chunk-KMGKCEO4.ts.map +0 -7
- package/dist/chunks/chunk-LASD73CM.ts +0 -339
- package/dist/chunks/chunk-LASD73CM.ts.map +0 -7
- package/dist/chunks/chunk-LEOYDZI3.ts +0 -22
- package/dist/chunks/chunk-LEOYDZI3.ts.map +0 -7
- package/dist/chunks/chunk-LL4LP2T7.ts +0 -737
- package/dist/chunks/chunk-LL4LP2T7.ts.map +0 -7
- package/dist/chunks/chunk-N2T5IN4X.ts +0 -18
- package/dist/chunks/chunk-N2T5IN4X.ts.map +0 -7
- package/dist/chunks/chunk-N7BLVXKK.ts +0 -73
- package/dist/chunks/chunk-N7BLVXKK.ts.map +0 -7
- package/dist/chunks/chunk-NLT67IZS.ts +0 -322
- package/dist/chunks/chunk-NLT67IZS.ts.map +0 -7
- package/dist/chunks/chunk-NTRPLF46.ts +0 -63
- package/dist/chunks/chunk-NTRPLF46.ts.map +0 -7
- package/dist/chunks/chunk-ONDTY4EL.ts +0 -91
- package/dist/chunks/chunk-ONDTY4EL.ts.map +0 -7
- package/dist/chunks/chunk-OVPHFGKO.ts +0 -1769
- package/dist/chunks/chunk-OVPHFGKO.ts.map +0 -7
- package/dist/chunks/chunk-P7OH4XMF.ts +0 -60
- package/dist/chunks/chunk-P7OH4XMF.ts.map +0 -7
- package/dist/chunks/chunk-PBZMBTNJ.ts +0 -422
- package/dist/chunks/chunk-PBZMBTNJ.ts.map +0 -7
- package/dist/chunks/chunk-PGLSFLYW.ts +0 -52
- package/dist/chunks/chunk-PGLSFLYW.ts.map +0 -7
- package/dist/chunks/chunk-RRR66UWR.ts +0 -28
- package/dist/chunks/chunk-RRR66UWR.ts.map +0 -7
- package/dist/chunks/chunk-RSUXZD6S.ts +0 -275
- package/dist/chunks/chunk-RSUXZD6S.ts.map +0 -7
- package/dist/chunks/chunk-RTCVYIZA.ts +0 -221
- package/dist/chunks/chunk-RTCVYIZA.ts.map +0 -7
- package/dist/chunks/chunk-RY2AEGMZ.ts +0 -34
- package/dist/chunks/chunk-RY2AEGMZ.ts.map +0 -7
- package/dist/chunks/chunk-SWGQLFSD.ts +0 -60
- package/dist/chunks/chunk-SWGQLFSD.ts.map +0 -7
- package/dist/chunks/chunk-TM2R67J3.ts +0 -52
- package/dist/chunks/chunk-TM2R67J3.ts.map +0 -7
- package/dist/chunks/chunk-TMZRHIIK.ts +0 -497
- package/dist/chunks/chunk-TMZRHIIK.ts.map +0 -7
- package/dist/chunks/chunk-TZ34IQ3M.ts +0 -59
- package/dist/chunks/chunk-TZ34IQ3M.ts.map +0 -7
- package/dist/chunks/chunk-UMBPMVJW.ts +0 -22
- package/dist/chunks/chunk-UMBPMVJW.ts.map +0 -7
- package/dist/chunks/chunk-VDG7LTYE.ts +0 -80
- package/dist/chunks/chunk-VDG7LTYE.ts.map +0 -7
- package/dist/chunks/chunk-X4NMONPE.ts +0 -73
- package/dist/chunks/chunk-X4NMONPE.ts.map +0 -7
- package/dist/chunks/chunk-YPJEN6NU.ts +0 -65
- package/dist/chunks/chunk-YPJEN6NU.ts.map +0 -7
- package/dist/chunks/chunk-YU53SHA7.ts +0 -328
- package/dist/chunks/chunk-YU53SHA7.ts.map +0 -7
- package/dist/chunks/completion-delivery-RSJU6BXL.ts +0 -17
- package/dist/chunks/completion-delivery-RSJU6BXL.ts.map +0 -7
- package/dist/chunks/config-status-FKGDECZ3.ts +0 -35
- package/dist/chunks/config-status-FKGDECZ3.ts.map +0 -7
- package/dist/chunks/config-ui-ABHYNGQ7.ts +0 -1212
- package/dist/chunks/config-ui-ABHYNGQ7.ts.map +0 -7
- package/dist/chunks/consult-LJU3IQY5.ts +0 -519
- package/dist/chunks/consult-LJU3IQY5.ts.map +0 -7
- package/dist/chunks/context-QDKLVQXE.ts +0 -11
- package/dist/chunks/context-QDKLVQXE.ts.map +0 -7
- package/dist/chunks/create-stateful-transport-JWC2EFYL.ts +0 -130
- package/dist/chunks/create-stateful-transport-JWC2EFYL.ts.map +0 -7
- package/dist/chunks/cwd-policy-NB6XZ5GF.ts +0 -17
- package/dist/chunks/cwd-policy-NB6XZ5GF.ts.map +0 -7
- package/dist/chunks/delegation-contract-LA56I5DT.ts +0 -24
- package/dist/chunks/delegation-contract-LA56I5DT.ts.map +0 -7
- package/dist/chunks/discovery-MIFB2U4Y.ts +0 -12
- package/dist/chunks/discovery-MIFB2U4Y.ts.map +0 -7
- package/dist/chunks/execution-Q2JZLKJA.ts +0 -4037
- package/dist/chunks/execution-Q2JZLKJA.ts.map +0 -7
- package/dist/chunks/in-process-transport-HJ6TZXC3.ts +0 -39
- package/dist/chunks/in-process-transport-HJ6TZXC3.ts.map +0 -7
- package/dist/chunks/inspect-UH2TKH6E.ts +0 -634
- package/dist/chunks/inspect-UH2TKH6E.ts.map +0 -7
- package/dist/chunks/peer-communication-KL36Z6CO.ts +0 -294
- package/dist/chunks/peer-communication-KL36Z6CO.ts.map +0 -7
- package/dist/chunks/persistence-UY3PY6E5.ts +0 -348
- package/dist/chunks/persistence-UY3PY6E5.ts.map +0 -7
- package/dist/chunks/registry-BT54L6CY.ts +0 -1445
- package/dist/chunks/registry-BT54L6CY.ts.map +0 -7
- package/dist/chunks/retained-semantic-state-GM75FZGE.ts +0 -81
- package/dist/chunks/retained-semantic-state-GM75FZGE.ts.map +0 -7
- package/dist/chunks/rpc-transport-7R7DVCEB.ts +0 -1222
- package/dist/chunks/rpc-transport-7R7DVCEB.ts.map +0 -7
- package/dist/chunks/runtime-policy-5YELCOVC.ts +0 -15
- package/dist/chunks/runtime-policy-5YELCOVC.ts.map +0 -7
- package/dist/chunks/semantic-snapshot-WPJ3UAFW.ts +0 -19
- package/dist/chunks/semantic-snapshot-WPJ3UAFW.ts.map +0 -7
- package/dist/chunks/spawn-idempotency-BNHOSMZW.ts +0 -13
- package/dist/chunks/spawn-idempotency-BNHOSMZW.ts.map +0 -7
- package/dist/chunks/stateful-lifecycle-JAR6K55H.ts +0 -15
- package/dist/chunks/stateful-lifecycle-JAR6K55H.ts.map +0 -7
- package/dist/chunks/subprocess-transport-VHZJRBTW.ts +0 -160
- package/dist/chunks/subprocess-transport-VHZJRBTW.ts.map +0 -7
- package/dist/chunks/usage-recording-store-CW3EH2SZ.ts +0 -164
- package/dist/chunks/usage-recording-store-CW3EH2SZ.ts.map +0 -7
- package/dist/chunks/workspace-WDKLN72J.ts +0 -11
- package/dist/chunks/workspace-WDKLN72J.ts.map +0 -7
- package/docs/async-runtime-protocol.md +0 -84
- package/docs/implementation-notes/pi-subagents-capability-matrix.md +0 -62
- package/docs/implementation-notes/pi-subagents-current-direction.md +0 -99
- package/docs/implementation-notes/pi-subagents-rpc-v1.md +0 -153
- package/docs/pi-subagents-diagrams.md +0 -183
- package/src/adaptive-scheduler.ts +0 -224
- package/src/admission-benchmark.ts +0 -95
- package/src/admission-policy.ts +0 -78
- package/src/agent-projection.ts +0 -53
- package/src/agents/built-ins.ts +0 -71
- package/src/agents/catalog.ts +0 -241
- package/src/agents/discovery.ts +0 -265
- package/src/agents/types.ts +0 -100
- package/src/agents.ts +0 -51
- package/src/async-subagent-benchmark.ts +0 -532
- package/src/auto-transport.ts +0 -121
- package/src/blocking-status.ts +0 -63
- package/src/cached-module-loader.ts +0 -18
- package/src/capabilities.ts +0 -145
- package/src/capability-grant.ts +0 -115
- package/src/capability-router.ts +0 -107
- package/src/child-peer-bridge.ts +0 -124
- package/src/child-peer-tools.ts +0 -132
- package/src/completion-delivery.ts +0 -409
- package/src/completion-render.ts +0 -190
- package/src/completion-requirement.ts +0 -479
- package/src/completion-routing.ts +0 -24
- package/src/config-registration.ts +0 -114
- package/src/config-status.ts +0 -217
- package/src/config-ui.ts +0 -983
- package/src/consult-policy.ts +0 -15
- package/src/consult-registration.ts +0 -125
- package/src/consult-render.ts +0 -194
- package/src/consult-resources.ts +0 -51
- package/src/consult-tool.ts +0 -95
- package/src/consult.ts +0 -566
- package/src/context.ts +0 -126
- package/src/create-stateful-transport.ts +0 -157
- package/src/cwd-policy.ts +0 -183
- package/src/delegation-contract.ts +0 -463
- package/src/execution/budget.ts +0 -56
- package/src/execution/runtime-policy.ts +0 -19
- package/src/execution-plan.ts +0 -322
- package/src/execution-ui.ts +0 -259
- package/src/execution.ts +0 -1679
- package/src/in-process-transport.ts +0 -941
- package/src/inspect-registration.ts +0 -64
- package/src/inspect-render.ts +0 -334
- package/src/inspect-tool.ts +0 -45
- package/src/inspect.ts +0 -769
- package/src/integration-controller.ts +0 -98
- package/src/limits.ts +0 -75
- package/src/orchestration-metrics.ts +0 -116
- package/src/outcome.ts +0 -61
- package/src/panel-child-group.ts +0 -35
- package/src/panel-contract.ts +0 -343
- package/src/panel-evidence.ts +0 -59
- package/src/panel-execution.ts +0 -769
- package/src/panel-failure.ts +0 -56
- package/src/panel-planning.ts +0 -175
- package/src/panel-presets.ts +0 -3
- package/src/panel-prompts.ts +0 -132
- package/src/panel-reconciliation.ts +0 -57
- package/src/panel-render.ts +0 -103
- package/src/parallel-limit-ui.ts +0 -113
- package/src/params.ts +0 -278
- package/src/peer-communication.ts +0 -352
- package/src/peer-transport.ts +0 -49
- package/src/persistence.ts +0 -522
- package/src/pi-args.ts +0 -43
- package/src/pi-invocation.ts +0 -168
- package/src/process-control.ts +0 -43
- package/src/prompt-resources.ts +0 -38
- package/src/prompt-source-safety.ts +0 -48
- package/src/protocol.ts +0 -76
- package/src/registry-types.ts +0 -204
- package/src/registry.ts +0 -1698
- package/src/render-common.ts +0 -252
- package/src/render.ts +0 -704
- package/src/result-contract.ts +0 -431
- package/src/retained-semantic-state.ts +0 -100
- package/src/rpc-timeout-finalization.ts +0 -207
- package/src/rpc-transport-metadata.ts +0 -65
- package/src/rpc-transport.ts +0 -1035
- package/src/rpc-turn-capture.ts +0 -217
- package/src/runner-outcome.ts +0 -31
- package/src/runner-result.ts +0 -55
- package/src/runner-types.ts +0 -102
- package/src/runner-usage.ts +0 -48
- package/src/runner.ts +0 -866
- package/src/safe-text.ts +0 -67
- package/src/semantic-snapshot.ts +0 -214
- package/src/session-guidance-contract.ts +0 -399
- package/src/settings/inspection.ts +0 -302
- package/src/settings/schema.ts +0 -195
- package/src/settings-reader.ts +0 -215
- package/src/settings.ts +0 -452
- package/src/spawn-idempotency.ts +0 -68
- package/src/stateful-agent-view.ts +0 -85
- package/src/stateful-config.ts +0 -13
- package/src/stateful-guidance.ts +0 -29
- package/src/stateful-lifecycle.ts +0 -74
- package/src/stateful-limit-ui.ts +0 -249
- package/src/stateful-limits.ts +0 -96
- package/src/stateful-prompt.ts +0 -49
- package/src/stateful-registration.ts +0 -1320
- package/src/stateful-render.ts +0 -318
- package/src/stateful-safety.ts +0 -47
- package/src/stateful-tool-params.ts +0 -215
- package/src/stateful.ts +0 -12
- package/src/subagent-details.ts +0 -43
- package/src/subagents-extension.ts +0 -355
- package/src/subprocess-transport.ts +0 -145
- package/src/supervision.ts +0 -104
- package/src/task-path.ts +0 -65
- package/src/timeout-checkpoint.ts +0 -305
- package/src/timeout-finalization.ts +0 -75
- package/src/tool-schema-compatibility.ts +0 -73
- package/src/transport-types.ts +0 -74
- package/src/transport-ui.ts +0 -135
- package/src/transport.ts +0 -43
- package/src/turn-budget.ts +0 -109
- package/src/usage-format.ts +0 -42
- package/src/usage-recording-config.ts +0 -13
- package/src/usage-recording-store.ts +0 -183
- package/src/usage-recording.ts +0 -478
- package/src/verification-harness.ts +0 -516
- package/src/verification-policy.ts +0 -67
- package/src/verification-receipt.ts +0 -275
- package/src/verified-execution-benchmark.ts +0 -86
- package/src/verified-execution-contract.ts +0 -191
- package/src/verified-execution-schema.ts +0 -32
- package/src/work-item-ledger.ts +0 -1404
- package/src/work-item-persistence.ts +0 -254
- package/src/workflow-completion-controller.ts +0 -397
- package/src/workflow-planning.ts +0 -172
- package/src/workflow-tree-identity.ts +0 -289
- package/src/workflow-ui.ts +0 -69
- package/src/workflow-verification.ts +0 -296
- package/src/workspace.ts +0 -174
package/src/config-ui.ts
DELETED
|
@@ -1,983 +0,0 @@
|
|
|
1
|
-
import type { ExtensionAPI, ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import { discoverAgents } from "./agents/discovery.js";
|
|
3
|
-
import type {
|
|
4
|
-
CompletionDelivery,
|
|
5
|
-
ConsultationCwdPolicy,
|
|
6
|
-
ConsultResourcePolicy,
|
|
7
|
-
DelegationCwdPolicy,
|
|
8
|
-
} from "./agents/types.js";
|
|
9
|
-
import {
|
|
10
|
-
completionLabel,
|
|
11
|
-
consultationCwdLabel,
|
|
12
|
-
consultResourceLabel,
|
|
13
|
-
currentWorkflow,
|
|
14
|
-
delegationCwdLabel,
|
|
15
|
-
formatManagerSummary,
|
|
16
|
-
helpLines,
|
|
17
|
-
showSubagentHelp,
|
|
18
|
-
showSubagentStatus,
|
|
19
|
-
statusLines,
|
|
20
|
-
} from "./config-status.js";
|
|
21
|
-
import {
|
|
22
|
-
applyAgentModel,
|
|
23
|
-
applyAgentThinking,
|
|
24
|
-
applyAgentTimeout,
|
|
25
|
-
executionAgentPickerScreen,
|
|
26
|
-
executionAgentScreen,
|
|
27
|
-
executionModelInputScreen,
|
|
28
|
-
executionModelScreen,
|
|
29
|
-
executionThinkingScreen,
|
|
30
|
-
executionTimeoutInputScreen,
|
|
31
|
-
resetAgentExecution,
|
|
32
|
-
} from "./execution-ui.js";
|
|
33
|
-
import {
|
|
34
|
-
applyBlockingParallelLimitSetting,
|
|
35
|
-
blockingParallelLimitScreen,
|
|
36
|
-
} from "./parallel-limit-ui.js";
|
|
37
|
-
import type { ManagedAgent } from "./registry.js";
|
|
38
|
-
import { safeTerminalLine as safeTerminalText } from "./safe-text.js";
|
|
39
|
-
import type { DelegationWorkflow } from "./settings/inspection.js";
|
|
40
|
-
import {
|
|
41
|
-
hasOwn,
|
|
42
|
-
inspectBlockingParallelLimitSettings,
|
|
43
|
-
inspectCompletionDeliverySettings,
|
|
44
|
-
inspectConsultResourceSettings,
|
|
45
|
-
inspectCwdPolicySettings,
|
|
46
|
-
inspectDelegationWorkflowSettings,
|
|
47
|
-
inspectUsageRecordingSettings,
|
|
48
|
-
readSubagentSettings,
|
|
49
|
-
sameToolSet,
|
|
50
|
-
uniqueToolNames,
|
|
51
|
-
updateAgentToolsSetting,
|
|
52
|
-
updateCompletionDeliverySetting,
|
|
53
|
-
updateConsultResourceSetting,
|
|
54
|
-
updateCwdPolicySetting,
|
|
55
|
-
updateDelegationWorkflowSetting,
|
|
56
|
-
updateUsageRecordingSetting,
|
|
57
|
-
} from "./settings.js";
|
|
58
|
-
import { formatStatefulAgentLine, type StatefulSubagentRuntimeStatus } from "./stateful.js";
|
|
59
|
-
import {
|
|
60
|
-
applyStatefulLimitSetting,
|
|
61
|
-
formatDetachedLimitSummary,
|
|
62
|
-
formatEmptyStatefulRuntime,
|
|
63
|
-
statefulLimitInputScreen,
|
|
64
|
-
statefulLimitListScreen,
|
|
65
|
-
} from "./stateful-limit-ui.js";
|
|
66
|
-
import { isStatefulLimitField, type StatefulLimitField } from "./stateful-limits.js";
|
|
67
|
-
import { applyTransportSetting, transportLabel, transportSettingsScreen } from "./transport-ui.js";
|
|
68
|
-
import type { UsageRecordingStatus } from "./usage-recording.js";
|
|
69
|
-
import { USAGE_RECORDING_RETENTION_DAYS } from "./usage-recording-config.js";
|
|
70
|
-
import { showWorkflowPreview, workflowLabel } from "./workflow-ui.js";
|
|
71
|
-
|
|
72
|
-
const SUBCOMMANDS = [
|
|
73
|
-
{ value: "settings", label: "settings", description: "Open grouped subagent settings" },
|
|
74
|
-
{ value: "status", label: "status", description: "Show detailed subagent diagnostics" },
|
|
75
|
-
{ value: "help", label: "help", description: "Show subagent first steps and safety help" },
|
|
76
|
-
];
|
|
77
|
-
const TOOL_VIEWPORT_SIZE = 10;
|
|
78
|
-
|
|
79
|
-
export interface SubagentSettingsRuntime {
|
|
80
|
-
getBlockingEnabled(): boolean;
|
|
81
|
-
getMaxParallelTasks(): number;
|
|
82
|
-
getCompletionDelivery(): CompletionDelivery;
|
|
83
|
-
getConsultResourcePolicy(): ConsultResourcePolicy;
|
|
84
|
-
getConsultationCwdPolicy(): ConsultationCwdPolicy;
|
|
85
|
-
getDelegationCwdPolicy(): DelegationCwdPolicy;
|
|
86
|
-
getUsageRecordingEnabled?(): boolean;
|
|
87
|
-
getUsageRecordingStatus?(): UsageRecordingStatus;
|
|
88
|
-
setUsageRecordingEnabled?(value: boolean): Promise<void>;
|
|
89
|
-
setMaxParallelTasks(value: number): void;
|
|
90
|
-
setCompletionDelivery(value: CompletionDelivery): void;
|
|
91
|
-
setConsultResourcePolicy(value: ConsultResourcePolicy): void;
|
|
92
|
-
setConsultationCwdPolicy(value: ConsultationCwdPolicy): void;
|
|
93
|
-
setDelegationCwdPolicy(value: DelegationCwdPolicy): void;
|
|
94
|
-
getRuntimeStatus(): StatefulSubagentRuntimeStatus;
|
|
95
|
-
listAgents(includeClosed?: boolean): ManagedAgent[];
|
|
96
|
-
clearAgents(): Promise<number>;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
export interface SubagentMenuOwner {
|
|
100
|
-
generation: number;
|
|
101
|
-
controller: AbortController;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
interface ToolDraft {
|
|
105
|
-
agentName: string;
|
|
106
|
-
agentSource: string;
|
|
107
|
-
allTools: string[];
|
|
108
|
-
defaultTools?: string[];
|
|
109
|
-
orderedTools: string[];
|
|
110
|
-
selected: Set<string>;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
export function registerSubagentConfigLifecycle(pi: ExtensionAPI): SubagentMenuOwner {
|
|
114
|
-
const owner: SubagentMenuOwner = { generation: 0, controller: new AbortController() };
|
|
115
|
-
pi.on("session_start", () => {
|
|
116
|
-
owner.generation += 1;
|
|
117
|
-
owner.controller.abort(new DOMException("Subagent session replaced", "AbortError"));
|
|
118
|
-
owner.controller = new AbortController();
|
|
119
|
-
});
|
|
120
|
-
pi.on("session_shutdown", () => {
|
|
121
|
-
owner.generation += 1;
|
|
122
|
-
owner.controller.abort(new DOMException("Subagent session shut down", "AbortError"));
|
|
123
|
-
});
|
|
124
|
-
return owner;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
export function registerSubagentConfigCommand(
|
|
128
|
-
pi: ExtensionAPI,
|
|
129
|
-
runtime: SubagentSettingsRuntime,
|
|
130
|
-
owner = registerSubagentConfigLifecycle(pi),
|
|
131
|
-
) {
|
|
132
|
-
registerSubagentPrimaryCommand(pi, runtime, owner);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
function registerSubagentPrimaryCommand(
|
|
136
|
-
pi: ExtensionAPI,
|
|
137
|
-
runtime: SubagentSettingsRuntime,
|
|
138
|
-
owner: SubagentMenuOwner,
|
|
139
|
-
) {
|
|
140
|
-
pi.registerCommand("subagents", {
|
|
141
|
-
description: "Manage subagents, settings, diagnostics, and help",
|
|
142
|
-
getArgumentCompletions(prefix: string) {
|
|
143
|
-
const normalized = prefix.trim().toLowerCase();
|
|
144
|
-
const matches = SUBCOMMANDS.filter((item) => item.value.startsWith(normalized));
|
|
145
|
-
return matches.length > 0 ? matches : null;
|
|
146
|
-
},
|
|
147
|
-
async handler(args, ctx) {
|
|
148
|
-
const subcommand = args.trim().toLowerCase();
|
|
149
|
-
if (!subcommand) {
|
|
150
|
-
await showSubagentManager(pi, ctx, runtime, owner);
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
switch (subcommand) {
|
|
154
|
-
case "settings":
|
|
155
|
-
await showSubagentSettings(pi, ctx, runtime, owner);
|
|
156
|
-
return;
|
|
157
|
-
case "status":
|
|
158
|
-
showSubagentStatus(ctx, runtime);
|
|
159
|
-
return;
|
|
160
|
-
case "help":
|
|
161
|
-
showSubagentHelp(ctx, runtime);
|
|
162
|
-
return;
|
|
163
|
-
default:
|
|
164
|
-
if (ctx.mode === "tui" || ctx.hasUI) {
|
|
165
|
-
ctx.ui.notify(`Unknown /subagents subcommand: ${subcommand}`, "warning");
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
},
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
export async function showSubagentManager(
|
|
173
|
-
pi: ExtensionAPI,
|
|
174
|
-
ctx: ExtensionCommandContext,
|
|
175
|
-
runtime: SubagentSettingsRuntime,
|
|
176
|
-
owner: SubagentMenuOwner,
|
|
177
|
-
start: "main" | "settings-hub" = "main",
|
|
178
|
-
) {
|
|
179
|
-
if (ctx.mode !== "tui") {
|
|
180
|
-
showSubagentStatus(ctx, runtime);
|
|
181
|
-
return;
|
|
182
|
-
}
|
|
183
|
-
const generation = owner.generation;
|
|
184
|
-
const isCurrent = () => generation === owner.generation && !owner.controller.signal.aborted;
|
|
185
|
-
const { defineMenu, runMenu } = await import("@narumitw/pi-tui-kit");
|
|
186
|
-
if (!isCurrent()) return;
|
|
187
|
-
let availableAgents = discoverAgents(ctx.cwd, "user", readSubagentSettings() ?? {}).agents;
|
|
188
|
-
let toolDraft: ToolDraft | undefined;
|
|
189
|
-
let selectedExecutionAgent: (typeof availableAgents)[number] | undefined;
|
|
190
|
-
let selectedStatefulLimit: StatefulLimitField = "maxAgents";
|
|
191
|
-
type Screen =
|
|
192
|
-
| "main"
|
|
193
|
-
| "workflow"
|
|
194
|
-
| "agents"
|
|
195
|
-
| "settings-hub"
|
|
196
|
-
| "access-settings"
|
|
197
|
-
| "behavior-settings"
|
|
198
|
-
| "agent-settings"
|
|
199
|
-
| "runtime-settings"
|
|
200
|
-
| "transport"
|
|
201
|
-
| "execution-agent-picker"
|
|
202
|
-
| "execution-agent"
|
|
203
|
-
| "execution-thinking"
|
|
204
|
-
| "execution-model"
|
|
205
|
-
| "execution-model-input"
|
|
206
|
-
| "execution-timeout"
|
|
207
|
-
| "parallel-limit"
|
|
208
|
-
| "stateful-limits"
|
|
209
|
-
| "stateful-limit-input"
|
|
210
|
-
| "status"
|
|
211
|
-
| "help"
|
|
212
|
-
| "agent-picker"
|
|
213
|
-
| "tool-draft";
|
|
214
|
-
type Action =
|
|
215
|
-
| "set-workflow"
|
|
216
|
-
| "clear-agents"
|
|
217
|
-
| "set-transport"
|
|
218
|
-
| "pick-execution-agent"
|
|
219
|
-
| "set-agent-thinking"
|
|
220
|
-
| "set-agent-model"
|
|
221
|
-
| "set-agent-timeout"
|
|
222
|
-
| "reset-agent-execution"
|
|
223
|
-
| "set-parallel-limit"
|
|
224
|
-
| "pick-stateful-limit"
|
|
225
|
-
| "set-stateful-limit"
|
|
226
|
-
| "set-completion"
|
|
227
|
-
| "set-consult-resources"
|
|
228
|
-
| "set-consultation-cwd"
|
|
229
|
-
| "set-delegation-cwd"
|
|
230
|
-
| "set-usage-recording"
|
|
231
|
-
| "load-agent-picker"
|
|
232
|
-
| "pick-agent"
|
|
233
|
-
| "toggle-tool"
|
|
234
|
-
| "save-tools"
|
|
235
|
-
| "discard-tools"
|
|
236
|
-
| "back";
|
|
237
|
-
const menu = defineMenu<undefined, Screen, Action, ExtensionCommandContext>({
|
|
238
|
-
start,
|
|
239
|
-
screens: {
|
|
240
|
-
main: () => {
|
|
241
|
-
const status = runtime.getRuntimeStatus();
|
|
242
|
-
const workflow = inspectDelegationWorkflowSettings();
|
|
243
|
-
return {
|
|
244
|
-
kind: "actions",
|
|
245
|
-
title: "Subagents",
|
|
246
|
-
lines: formatManagerSummary(runtime, status, workflow).split("\n"),
|
|
247
|
-
items: [
|
|
248
|
-
{
|
|
249
|
-
id: "workflow",
|
|
250
|
-
label: "How subagents run",
|
|
251
|
-
description: "Choose whether Pi stays available while subagents work",
|
|
252
|
-
to: "workflow",
|
|
253
|
-
},
|
|
254
|
-
{
|
|
255
|
-
id: "agents",
|
|
256
|
-
label: "Current subagents",
|
|
257
|
-
description: `${status.activeAgents} working · ${status.retainedAgents} saved for follow-up`,
|
|
258
|
-
to: "agents",
|
|
259
|
-
},
|
|
260
|
-
{
|
|
261
|
-
id: "settings",
|
|
262
|
-
label: "Settings",
|
|
263
|
-
description: "Folders, completion, privacy, agent defaults, and advanced options",
|
|
264
|
-
to: "settings-hub",
|
|
265
|
-
},
|
|
266
|
-
{
|
|
267
|
-
id: "status",
|
|
268
|
-
label: "Diagnostics",
|
|
269
|
-
description: "Detailed runtime values, setting sources, and file paths",
|
|
270
|
-
to: "status",
|
|
271
|
-
},
|
|
272
|
-
{
|
|
273
|
-
id: "help",
|
|
274
|
-
label: "Help",
|
|
275
|
-
description: "First steps, settings behavior, commands, and safety",
|
|
276
|
-
to: "help",
|
|
277
|
-
},
|
|
278
|
-
],
|
|
279
|
-
hint: "close",
|
|
280
|
-
};
|
|
281
|
-
},
|
|
282
|
-
workflow: () => {
|
|
283
|
-
const snapshot = inspectDelegationWorkflowSettings();
|
|
284
|
-
const active = currentWorkflow(runtime, runtime.getRuntimeStatus());
|
|
285
|
-
return {
|
|
286
|
-
kind: "actions",
|
|
287
|
-
title: "How Subagents Run",
|
|
288
|
-
lines: [
|
|
289
|
-
`Current: ${workflowLabel(active)}`,
|
|
290
|
-
"Choose a workflow based on the tools and blocking behavior you need.",
|
|
291
|
-
"The blocking subagent tool is deprecated and remains available only for compatibility.",
|
|
292
|
-
"subagent_consult and subagent_await remain supported blocking helpers.",
|
|
293
|
-
"For results needed in the current answer, enable automatic continuation in Settings.",
|
|
294
|
-
...(snapshot.value !== active
|
|
295
|
-
? [`Configured after reload: ${workflowLabel(snapshot.value)}`]
|
|
296
|
-
: []),
|
|
297
|
-
...(snapshot.error
|
|
298
|
-
? [
|
|
299
|
-
`Settings cannot be edited: ${safeTerminalText(snapshot.error)}`,
|
|
300
|
-
`Repair ${safeTerminalText(snapshot.path)} and retry.`,
|
|
301
|
-
]
|
|
302
|
-
: []),
|
|
303
|
-
],
|
|
304
|
-
items: snapshot.error
|
|
305
|
-
? []
|
|
306
|
-
: [
|
|
307
|
-
{
|
|
308
|
-
id: "all",
|
|
309
|
-
label: workflowLabel("all"),
|
|
310
|
-
description:
|
|
311
|
-
"Background agents plus deprecated subagent and supported blocking helpers",
|
|
312
|
-
action: "set-workflow" as const,
|
|
313
|
-
},
|
|
314
|
-
{
|
|
315
|
-
id: "async-only",
|
|
316
|
-
label: workflowLabel("async-only"),
|
|
317
|
-
description: "Subagents work in the background while you continue using Pi",
|
|
318
|
-
action: "set-workflow" as const,
|
|
319
|
-
},
|
|
320
|
-
{
|
|
321
|
-
id: "blocking-only",
|
|
322
|
-
label: workflowLabel("blocking-only"),
|
|
323
|
-
description:
|
|
324
|
-
"No background agents; deprecated subagent plus read-only consultation",
|
|
325
|
-
action: "set-workflow" as const,
|
|
326
|
-
},
|
|
327
|
-
],
|
|
328
|
-
hint: "back",
|
|
329
|
-
};
|
|
330
|
-
},
|
|
331
|
-
agents: () => {
|
|
332
|
-
const agents = runtime.listAgents();
|
|
333
|
-
const status = runtime.getRuntimeStatus();
|
|
334
|
-
return {
|
|
335
|
-
kind: "actions",
|
|
336
|
-
title: "Current Subagents",
|
|
337
|
-
lines: agents.length
|
|
338
|
-
? [
|
|
339
|
-
"Working subagents and subagents saved for follow-up in this session.",
|
|
340
|
-
...agents.map(formatStatefulAgentLine),
|
|
341
|
-
]
|
|
342
|
-
: [formatEmptyStatefulRuntime(status)],
|
|
343
|
-
items: [
|
|
344
|
-
...(agents.length > 0
|
|
345
|
-
? [
|
|
346
|
-
{
|
|
347
|
-
id: "clear",
|
|
348
|
-
label: "Clear current subagents",
|
|
349
|
-
description: "Stop running work and remove subagents saved for follow-up",
|
|
350
|
-
action: "clear-agents" as const,
|
|
351
|
-
},
|
|
352
|
-
]
|
|
353
|
-
: []),
|
|
354
|
-
{ id: "back", label: "Back", action: "back" },
|
|
355
|
-
],
|
|
356
|
-
hint: "back",
|
|
357
|
-
};
|
|
358
|
-
},
|
|
359
|
-
"settings-hub": () => ({
|
|
360
|
-
kind: "actions",
|
|
361
|
-
title: "Subagent Settings",
|
|
362
|
-
lines: [
|
|
363
|
-
"Changes are saved immediately.",
|
|
364
|
-
"Transport and background-agent limits take effect after /reload.",
|
|
365
|
-
],
|
|
366
|
-
items: [
|
|
367
|
-
{
|
|
368
|
-
id: "access",
|
|
369
|
-
label: "Folders and trusted resources",
|
|
370
|
-
description: "Where subagents can start and what trusted consultations can load",
|
|
371
|
-
to: "access-settings",
|
|
372
|
-
},
|
|
373
|
-
{
|
|
374
|
-
id: "behavior",
|
|
375
|
-
label: "Completion and privacy",
|
|
376
|
-
description: "What Pi does when work finishes and optional local recording",
|
|
377
|
-
to: "behavior-settings",
|
|
378
|
-
},
|
|
379
|
-
{
|
|
380
|
-
id: "agents",
|
|
381
|
-
label: "Agent defaults",
|
|
382
|
-
description: "Tools, model, thinking effort, and time limit for each subagent",
|
|
383
|
-
to: "agent-settings",
|
|
384
|
-
},
|
|
385
|
-
{
|
|
386
|
-
id: "runtime",
|
|
387
|
-
label: "Advanced runtime settings",
|
|
388
|
-
description: "Transport and capacity controls that most users can leave unchanged",
|
|
389
|
-
to: "runtime-settings",
|
|
390
|
-
},
|
|
391
|
-
{ id: "back", label: "Back", action: "back" },
|
|
392
|
-
],
|
|
393
|
-
hint: "back",
|
|
394
|
-
}),
|
|
395
|
-
"access-settings": () => subagentAccessSettingsScreen(runtime),
|
|
396
|
-
"behavior-settings": () => subagentBehaviorSettingsScreen(runtime),
|
|
397
|
-
"agent-settings": () => ({
|
|
398
|
-
kind: "actions",
|
|
399
|
-
title: "Agent Defaults",
|
|
400
|
-
lines: ["Choose the starting settings for each subagent."],
|
|
401
|
-
items: [
|
|
402
|
-
{
|
|
403
|
-
id: "agent-tools",
|
|
404
|
-
label: "Tool permissions",
|
|
405
|
-
description: "Choose which tools each subagent may use",
|
|
406
|
-
action: "load-agent-picker",
|
|
407
|
-
},
|
|
408
|
-
{
|
|
409
|
-
id: "execution",
|
|
410
|
-
label: "Model, thinking, and time limit",
|
|
411
|
-
description: "Choose how each subagent starts unless a request overrides it",
|
|
412
|
-
to: "execution-agent-picker",
|
|
413
|
-
},
|
|
414
|
-
{ id: "back", label: "Back", action: "back" },
|
|
415
|
-
],
|
|
416
|
-
hint: "back",
|
|
417
|
-
}),
|
|
418
|
-
"runtime-settings": () => {
|
|
419
|
-
const limit = inspectBlockingParallelLimitSettings();
|
|
420
|
-
return {
|
|
421
|
-
kind: "actions",
|
|
422
|
-
title: "Advanced Runtime Settings",
|
|
423
|
-
lines: ["Most users can leave these settings unchanged."],
|
|
424
|
-
items: [
|
|
425
|
-
{
|
|
426
|
-
id: "transport",
|
|
427
|
-
label: "Transport",
|
|
428
|
-
description: `How Pi hosts background subagents · Current: ${transportLabel(runtime.getRuntimeStatus().transport)}`,
|
|
429
|
-
to: "transport",
|
|
430
|
-
},
|
|
431
|
-
{
|
|
432
|
-
id: "parallel-limit",
|
|
433
|
-
label: "Blocking worker limit",
|
|
434
|
-
description: `Maximum subagents per blocking request · Current: ${runtime.getMaxParallelTasks()}`,
|
|
435
|
-
to: "parallel-limit",
|
|
436
|
-
disabled: limit.error !== undefined,
|
|
437
|
-
disabledReason: limit.error
|
|
438
|
-
? `Repair ${safeTerminalText(limit.path)} before editing this setting`
|
|
439
|
-
: undefined,
|
|
440
|
-
},
|
|
441
|
-
{
|
|
442
|
-
id: "stateful-limits",
|
|
443
|
-
label: "Background agent limits",
|
|
444
|
-
description: formatDetachedLimitSummary(runtime.getRuntimeStatus()),
|
|
445
|
-
to: "stateful-limits",
|
|
446
|
-
},
|
|
447
|
-
{ id: "back", label: "Back", action: "back" },
|
|
448
|
-
],
|
|
449
|
-
hint: "back",
|
|
450
|
-
};
|
|
451
|
-
},
|
|
452
|
-
transport: () => transportSettingsScreen(runtime),
|
|
453
|
-
"execution-agent-picker": () => executionAgentPickerScreen(availableAgents),
|
|
454
|
-
"execution-agent": () => executionAgentScreen(selectedExecutionAgent),
|
|
455
|
-
"execution-thinking": () => executionThinkingScreen(selectedExecutionAgent),
|
|
456
|
-
"execution-model": () => executionModelScreen(selectedExecutionAgent, ctx),
|
|
457
|
-
"execution-model-input": () => executionModelInputScreen(selectedExecutionAgent),
|
|
458
|
-
"execution-timeout": () => executionTimeoutInputScreen(selectedExecutionAgent),
|
|
459
|
-
"parallel-limit": () => blockingParallelLimitScreen(runtime),
|
|
460
|
-
"stateful-limits": () => statefulLimitListScreen(runtime),
|
|
461
|
-
"stateful-limit-input": () => statefulLimitInputScreen(selectedStatefulLimit, runtime),
|
|
462
|
-
status: () => ({
|
|
463
|
-
kind: "detail",
|
|
464
|
-
title: "Subagent Diagnostics",
|
|
465
|
-
lines: statusLines(runtime),
|
|
466
|
-
hint: "back",
|
|
467
|
-
}),
|
|
468
|
-
help: () => ({
|
|
469
|
-
kind: "detail",
|
|
470
|
-
title: "Subagents Help",
|
|
471
|
-
lines: helpLines(runtime),
|
|
472
|
-
hint: "back",
|
|
473
|
-
}),
|
|
474
|
-
"agent-picker": () => {
|
|
475
|
-
const settings = readSubagentSettings() ?? {};
|
|
476
|
-
const configured = settings.agents ?? {};
|
|
477
|
-
return {
|
|
478
|
-
kind: "actions",
|
|
479
|
-
title: "Tool Permissions",
|
|
480
|
-
lines: ["Choose a subagent to change which tools it may use."],
|
|
481
|
-
items: availableAgents.map((agent) => {
|
|
482
|
-
const override = configured[agent.name];
|
|
483
|
-
const hasOverride = override ? hasOwn(override, "tools") : false;
|
|
484
|
-
const summary = hasOverride
|
|
485
|
-
? override?.tools && override.tools.length > 0
|
|
486
|
-
? override.tools.join(", ")
|
|
487
|
-
: "none"
|
|
488
|
-
: "defaults";
|
|
489
|
-
return {
|
|
490
|
-
id: agent.name,
|
|
491
|
-
label: safeTerminalText(agent.name),
|
|
492
|
-
description: safeTerminalText(`${agent.source} · tools: ${summary}`),
|
|
493
|
-
action: "pick-agent" as const,
|
|
494
|
-
};
|
|
495
|
-
}),
|
|
496
|
-
hint: "back",
|
|
497
|
-
};
|
|
498
|
-
},
|
|
499
|
-
"tool-draft": () => ({
|
|
500
|
-
kind: "multiSelect",
|
|
501
|
-
title: toolDraft ? `${safeTerminalText(toolDraft.agentName)} tools` : "Agent tools",
|
|
502
|
-
enableSearch: true,
|
|
503
|
-
lines: toolDraft
|
|
504
|
-
? [
|
|
505
|
-
`Source: ${safeTerminalText(toolDraft.agentSource)}`,
|
|
506
|
-
"Toggle a draft, then Save changes.",
|
|
507
|
-
]
|
|
508
|
-
: ["No agent selected."],
|
|
509
|
-
viewportSize: TOOL_VIEWPORT_SIZE,
|
|
510
|
-
items:
|
|
511
|
-
toolDraft?.orderedTools.map((name) => {
|
|
512
|
-
const available = toolDraft?.allTools.includes(name) ?? false;
|
|
513
|
-
return {
|
|
514
|
-
id: name,
|
|
515
|
-
label: safeTerminalText(name),
|
|
516
|
-
description: available ? "Available tool" : "Configured tool is not currently loaded",
|
|
517
|
-
searchText: available ? "available tool" : "configured unavailable preserved",
|
|
518
|
-
selected: toolDraft?.selected.has(name) ?? false,
|
|
519
|
-
disabled: !available,
|
|
520
|
-
disabledReason: available
|
|
521
|
-
? undefined
|
|
522
|
-
: "Unavailable; preserved until explicitly changed in JSON",
|
|
523
|
-
};
|
|
524
|
-
}) ?? [],
|
|
525
|
-
action: "toggle-tool",
|
|
526
|
-
actions: [
|
|
527
|
-
{ id: "save", label: "Save changes", action: "save-tools" },
|
|
528
|
-
{ id: "discard", label: "Discard draft", action: "discard-tools" },
|
|
529
|
-
],
|
|
530
|
-
hint: "back",
|
|
531
|
-
doneLabel: "Close without saving",
|
|
532
|
-
}),
|
|
533
|
-
},
|
|
534
|
-
actions: {
|
|
535
|
-
"set-workflow": async ({ itemId, signal }) => {
|
|
536
|
-
if (!isWorkflow(itemId)) return { kind: "rejected" };
|
|
537
|
-
const snapshot = inspectDelegationWorkflowSettings();
|
|
538
|
-
if (snapshot.error) return { kind: "rejected" };
|
|
539
|
-
const active = currentWorkflow(runtime, runtime.getRuntimeStatus());
|
|
540
|
-
if (itemId === active && itemId === snapshot.value) {
|
|
541
|
-
ctx.ui.notify(`Subagents already use ${workflowLabel(itemId)}.`, "info");
|
|
542
|
-
return { kind: "stay" };
|
|
543
|
-
}
|
|
544
|
-
const requiresReload = itemId !== active;
|
|
545
|
-
if (requiresReload && blockReloadWithRetainedAgents(ctx, runtime)) {
|
|
546
|
-
return { kind: "rejected" };
|
|
547
|
-
}
|
|
548
|
-
if (!(await showWorkflowPreview(ctx, active, itemId, requiresReload, signal))) {
|
|
549
|
-
return signal.aborted || !isCurrent() ? { kind: "close" } : { kind: "rejected" };
|
|
550
|
-
}
|
|
551
|
-
if (signal.aborted || !isCurrent()) return { kind: "close" };
|
|
552
|
-
if (requiresReload && blockReloadWithRetainedAgents(ctx, runtime)) {
|
|
553
|
-
return { kind: "rejected" };
|
|
554
|
-
}
|
|
555
|
-
try {
|
|
556
|
-
updateDelegationWorkflowSetting(itemId);
|
|
557
|
-
} catch (error) {
|
|
558
|
-
ctx.ui.notify(
|
|
559
|
-
`How subagents run was not saved: ${formatError(error)}. The current choice is unchanged.`,
|
|
560
|
-
"error",
|
|
561
|
-
);
|
|
562
|
-
return { kind: "rejected" };
|
|
563
|
-
}
|
|
564
|
-
if (!requiresReload) {
|
|
565
|
-
ctx.ui.notify(
|
|
566
|
-
`Saved ${workflowLabel(itemId)}. The current tool surface already matches.`,
|
|
567
|
-
"info",
|
|
568
|
-
);
|
|
569
|
-
return { kind: "stay" };
|
|
570
|
-
}
|
|
571
|
-
ctx.ui.notify(
|
|
572
|
-
`Saved ${workflowLabel(itemId)}. Reloading subagent tools… If the tool surface does not refresh, run /reload.`,
|
|
573
|
-
"info",
|
|
574
|
-
);
|
|
575
|
-
await ctx.reload();
|
|
576
|
-
return { kind: "close" };
|
|
577
|
-
},
|
|
578
|
-
"clear-agents": async ({ signal }) => {
|
|
579
|
-
const agents = runtime.listAgents();
|
|
580
|
-
if (agents.length === 0) return { kind: "stay" };
|
|
581
|
-
const confirmed = await ctx.ui.confirm(
|
|
582
|
-
"Clear current subagents?",
|
|
583
|
-
`Stop work and remove ${agents.length} subagent${agents.length === 1 ? "" : "s"} saved for follow-up?`,
|
|
584
|
-
{ signal },
|
|
585
|
-
);
|
|
586
|
-
if (signal.aborted || !isCurrent()) return { kind: "close" };
|
|
587
|
-
if (!confirmed) return { kind: "rejected" };
|
|
588
|
-
if (
|
|
589
|
-
runtime
|
|
590
|
-
.listAgents()
|
|
591
|
-
.map((agent) => agent.id)
|
|
592
|
-
.join("\0") !== agents.map((agent) => agent.id).join("\0")
|
|
593
|
-
) {
|
|
594
|
-
ctx.ui.notify(
|
|
595
|
-
"Current subagents changed while confirming; review the list again.",
|
|
596
|
-
"warning",
|
|
597
|
-
);
|
|
598
|
-
return { kind: "rejected" };
|
|
599
|
-
}
|
|
600
|
-
const cleared = await runtime.clearAgents();
|
|
601
|
-
if (signal.aborted || !isCurrent()) return { kind: "close" };
|
|
602
|
-
ctx.ui.notify(`Cleared ${cleared} current subagent${cleared === 1 ? "" : "s"}.`, "info");
|
|
603
|
-
return { kind: "stay" };
|
|
604
|
-
},
|
|
605
|
-
"set-transport": async ({ itemId, signal }) =>
|
|
606
|
-
applyTransportSetting(itemId, ctx, runtime, signal, isCurrent),
|
|
607
|
-
"pick-execution-agent": async ({ itemId }) => {
|
|
608
|
-
selectedExecutionAgent = availableAgents.find((agent) => agent.name === itemId);
|
|
609
|
-
return selectedExecutionAgent
|
|
610
|
-
? { kind: "to", screen: "execution-agent" as const }
|
|
611
|
-
: { kind: "rejected" as const };
|
|
612
|
-
},
|
|
613
|
-
"set-agent-thinking": async ({ value }) =>
|
|
614
|
-
applyAgentThinking(selectedExecutionAgent, value, ctx),
|
|
615
|
-
"set-agent-model": async ({ itemId, value }) => {
|
|
616
|
-
const selected = value ?? (itemId.startsWith("model:") ? itemId.slice(6) : undefined);
|
|
617
|
-
return applyAgentModel(
|
|
618
|
-
selectedExecutionAgent,
|
|
619
|
-
selected === "__inherited__" ? undefined : selected,
|
|
620
|
-
ctx,
|
|
621
|
-
);
|
|
622
|
-
},
|
|
623
|
-
"set-agent-timeout": async ({ value }) =>
|
|
624
|
-
applyAgentTimeout(selectedExecutionAgent, value, ctx),
|
|
625
|
-
"reset-agent-execution": async () => resetAgentExecution(selectedExecutionAgent, ctx),
|
|
626
|
-
"set-parallel-limit": async ({ value }) =>
|
|
627
|
-
applyBlockingParallelLimitSetting(value, ctx, runtime),
|
|
628
|
-
"pick-stateful-limit": async ({ itemId }) => {
|
|
629
|
-
if (!isStatefulLimitField(itemId)) return { kind: "rejected" };
|
|
630
|
-
selectedStatefulLimit = itemId;
|
|
631
|
-
return { kind: "to", screen: "stateful-limit-input" };
|
|
632
|
-
},
|
|
633
|
-
"set-stateful-limit": async ({ value, signal }) =>
|
|
634
|
-
applyStatefulLimitSetting(selectedStatefulLimit, value, ctx, runtime, {
|
|
635
|
-
signal,
|
|
636
|
-
isCurrent,
|
|
637
|
-
}),
|
|
638
|
-
"set-completion": async ({ value }) => applyCompletionSetting(value, ctx, runtime),
|
|
639
|
-
"set-consult-resources": async ({ value }) =>
|
|
640
|
-
applyConsultResourceSetting(value, ctx, runtime),
|
|
641
|
-
"set-consultation-cwd": async ({ value }) => applyConsultationCwdSetting(value, ctx, runtime),
|
|
642
|
-
"set-delegation-cwd": async ({ value }) => applyDelegationCwdSetting(value, ctx, runtime),
|
|
643
|
-
"set-usage-recording": async ({ value, signal }) =>
|
|
644
|
-
applyUsageRecordingSetting(value, ctx, runtime, { signal, isCurrent }),
|
|
645
|
-
"load-agent-picker": async () => {
|
|
646
|
-
availableAgents = discoverAgents(ctx.cwd, "user", readSubagentSettings() ?? {}).agents;
|
|
647
|
-
if (availableAgents.length === 0) {
|
|
648
|
-
ctx.ui.notify("No agents found", "warning");
|
|
649
|
-
return { kind: "rejected" };
|
|
650
|
-
}
|
|
651
|
-
return { kind: "to", screen: "agent-picker" };
|
|
652
|
-
},
|
|
653
|
-
"pick-agent": async ({ itemId }) => {
|
|
654
|
-
const agent = availableAgents.find((candidate) => candidate.name === itemId);
|
|
655
|
-
if (!agent) return { kind: "rejected" };
|
|
656
|
-
const settings = readSubagentSettings() ?? {};
|
|
657
|
-
const configured = settings.agents?.[agent.name];
|
|
658
|
-
const configuredTools =
|
|
659
|
-
configured && hasOwn(configured, "tools") ? (configured.tools ?? []) : undefined;
|
|
660
|
-
const defaults = discoverAgents(ctx.cwd, "user").agents.find(
|
|
661
|
-
(candidate) => candidate.name === agent.name,
|
|
662
|
-
)?.tools;
|
|
663
|
-
const allTools = uniqueToolNames(pi.getAllTools().map((tool) => tool.name)).sort((a, b) =>
|
|
664
|
-
a.localeCompare(b),
|
|
665
|
-
);
|
|
666
|
-
const selected = uniqueToolNames(configuredTools ?? defaults ?? allTools);
|
|
667
|
-
const selectedSet = new Set(selected);
|
|
668
|
-
toolDraft = {
|
|
669
|
-
agentName: agent.name,
|
|
670
|
-
agentSource: agent.source,
|
|
671
|
-
allTools,
|
|
672
|
-
defaultTools: defaults,
|
|
673
|
-
orderedTools: [...selected, ...allTools.filter((name) => !selectedSet.has(name))],
|
|
674
|
-
selected: selectedSet,
|
|
675
|
-
};
|
|
676
|
-
return { kind: "to", screen: "tool-draft" };
|
|
677
|
-
},
|
|
678
|
-
"toggle-tool": async ({ itemId, selected }) => {
|
|
679
|
-
if (!toolDraft?.allTools.includes(itemId)) return { kind: "rejected" };
|
|
680
|
-
if (selected) toolDraft.selected.add(itemId);
|
|
681
|
-
else toolDraft.selected.delete(itemId);
|
|
682
|
-
return { kind: "stay" };
|
|
683
|
-
},
|
|
684
|
-
"save-tools": async () => {
|
|
685
|
-
if (!toolDraft) return { kind: "rejected" };
|
|
686
|
-
const selected = toolDraft.orderedTools.filter((name) => toolDraft?.selected.has(name));
|
|
687
|
-
const restoredDefaults =
|
|
688
|
-
toolDraft.defaultTools === undefined
|
|
689
|
-
? sameToolSet(selected, toolDraft.allTools)
|
|
690
|
-
: sameToolSet(selected, toolDraft.defaultTools);
|
|
691
|
-
try {
|
|
692
|
-
updateAgentToolsSetting(toolDraft.agentName, restoredDefaults ? undefined : selected);
|
|
693
|
-
} catch (error) {
|
|
694
|
-
ctx.ui.notify(`Agent tool settings were not saved: ${formatError(error)}`, "error");
|
|
695
|
-
return { kind: "rejected" };
|
|
696
|
-
}
|
|
697
|
-
ctx.ui.notify(
|
|
698
|
-
restoredDefaults
|
|
699
|
-
? `${safeTerminalText(toolDraft.agentName)}: defaults restored`
|
|
700
|
-
: `${safeTerminalText(toolDraft.agentName)}: ${selected.length} tool${selected.length === 1 ? "" : "s"} configured`,
|
|
701
|
-
"info",
|
|
702
|
-
);
|
|
703
|
-
toolDraft = undefined;
|
|
704
|
-
return { kind: "back" };
|
|
705
|
-
},
|
|
706
|
-
"discard-tools": async () => {
|
|
707
|
-
toolDraft = undefined;
|
|
708
|
-
return { kind: "back" };
|
|
709
|
-
},
|
|
710
|
-
back: async () => ({ kind: "back" }),
|
|
711
|
-
},
|
|
712
|
-
});
|
|
713
|
-
await runMenu(ctx, menu, {
|
|
714
|
-
getState: () => undefined,
|
|
715
|
-
signal: owner.controller.signal,
|
|
716
|
-
isCurrent,
|
|
717
|
-
});
|
|
718
|
-
}
|
|
719
|
-
|
|
720
|
-
export async function showSubagentSettings(
|
|
721
|
-
pi: ExtensionAPI,
|
|
722
|
-
ctx: ExtensionCommandContext,
|
|
723
|
-
runtime: SubagentSettingsRuntime,
|
|
724
|
-
owner: SubagentMenuOwner,
|
|
725
|
-
) {
|
|
726
|
-
const snapshot = inspectConsultResourceSettings();
|
|
727
|
-
if (ctx.mode !== "tui") {
|
|
728
|
-
if (ctx.hasUI) {
|
|
729
|
-
ctx.ui.notify(
|
|
730
|
-
`User settings apply to this and future sessions. Edit settings manually: ${safeTerminalText(snapshot.path)}`,
|
|
731
|
-
"info",
|
|
732
|
-
);
|
|
733
|
-
}
|
|
734
|
-
return;
|
|
735
|
-
}
|
|
736
|
-
await showSubagentManager(pi, ctx, runtime, owner, "settings-hub");
|
|
737
|
-
}
|
|
738
|
-
|
|
739
|
-
function subagentAccessSettingsScreen(runtime: SubagentSettingsRuntime) {
|
|
740
|
-
const consult = inspectConsultResourceSettings();
|
|
741
|
-
const cwdPolicy = inspectCwdPolicySettings();
|
|
742
|
-
const error = consult.error ?? cwdPolicy.error;
|
|
743
|
-
return {
|
|
744
|
-
kind: "settings" as const,
|
|
745
|
-
title: error ? "Folders and Trusted Resources · Read only" : "Folders and Trusted Resources",
|
|
746
|
-
lines: [
|
|
747
|
-
"Choose where subagents may start and what read-only consultations may load.",
|
|
748
|
-
"These settings do not restrict files, shell commands, network access, or OS permissions.",
|
|
749
|
-
"Manage saved folder trust with Pi /trust, then restart Pi.",
|
|
750
|
-
safeTerminalText(consult.path),
|
|
751
|
-
...(error ? [`Settings cannot be edited: ${safeTerminalText(error)}`] : []),
|
|
752
|
-
],
|
|
753
|
-
items: error
|
|
754
|
-
? []
|
|
755
|
-
: [
|
|
756
|
-
{
|
|
757
|
-
id: "consultationCwd",
|
|
758
|
-
label: "Where read-only consultations can start",
|
|
759
|
-
description:
|
|
760
|
-
"Use only this workspace, or allow other folders without loading untrusted project resources.",
|
|
761
|
-
currentValue: consultationCwdLabel(runtime.getConsultationCwdPolicy()),
|
|
762
|
-
values: ["Any folder · no project resources when untrusted", "This workspace only"],
|
|
763
|
-
action: "set-consultation-cwd" as const,
|
|
764
|
-
},
|
|
765
|
-
{
|
|
766
|
-
id: "delegationCwd",
|
|
767
|
-
label: "Where subagents can start",
|
|
768
|
-
description:
|
|
769
|
-
"Limit subagents to this workspace, saved-trusted folders, or any folder Pi can access.",
|
|
770
|
-
currentValue: delegationCwdLabel(runtime.getDelegationCwdPolicy()),
|
|
771
|
-
values: [
|
|
772
|
-
"This workspace or saved-trusted folders",
|
|
773
|
-
"This workspace only",
|
|
774
|
-
"Any folder Pi can access",
|
|
775
|
-
],
|
|
776
|
-
action: "set-delegation-cwd" as const,
|
|
777
|
-
},
|
|
778
|
-
{
|
|
779
|
-
id: "consultResources",
|
|
780
|
-
label: "Resources for trusted read-only consultations",
|
|
781
|
-
description:
|
|
782
|
-
"Choose how much project context, skills, and prompt guidance a trusted consultation may load.",
|
|
783
|
-
currentValue: consultResourceLabel(runtime.getConsultResourcePolicy()),
|
|
784
|
-
values: ["Project context only", "No project resources", "All trusted resources"],
|
|
785
|
-
action: "set-consult-resources" as const,
|
|
786
|
-
},
|
|
787
|
-
],
|
|
788
|
-
};
|
|
789
|
-
}
|
|
790
|
-
|
|
791
|
-
function subagentBehaviorSettingsScreen(runtime: SubagentSettingsRuntime) {
|
|
792
|
-
const completion = inspectCompletionDeliverySettings();
|
|
793
|
-
const usageRecording = inspectUsageRecordingSettings();
|
|
794
|
-
const error = completion.error ?? usageRecording.error;
|
|
795
|
-
return {
|
|
796
|
-
kind: "settings" as const,
|
|
797
|
-
title: error ? "Completion and Privacy · Read only" : "Completion and Privacy",
|
|
798
|
-
lines: [
|
|
799
|
-
"These changes apply immediately and to future sessions.",
|
|
800
|
-
safeTerminalText(completion.path),
|
|
801
|
-
...(error ? [`Settings cannot be edited: ${safeTerminalText(error)}`] : []),
|
|
802
|
-
],
|
|
803
|
-
items: error
|
|
804
|
-
? []
|
|
805
|
-
: [
|
|
806
|
-
{
|
|
807
|
-
id: "completionDelivery",
|
|
808
|
-
label: "When background work finishes",
|
|
809
|
-
description:
|
|
810
|
-
"Wait for your next message, or steer results into active work and continue automatically from idle.",
|
|
811
|
-
currentValue: completionLabel(runtime.getCompletionDelivery()),
|
|
812
|
-
values: ["Wait for my next message", "Continue automatically when work finishes"],
|
|
813
|
-
action: "set-completion" as const,
|
|
814
|
-
},
|
|
815
|
-
{
|
|
816
|
-
id: "usageRecording",
|
|
817
|
-
label: "Local usage recording",
|
|
818
|
-
description: `Optionally keep content-free timing and lifecycle events on this device for ${USAGE_RECORDING_RETENTION_DAYS} days.`,
|
|
819
|
-
currentValue: runtime.getUsageRecordingEnabled?.() ? "On · local only" : "Off",
|
|
820
|
-
values: ["Off", "On · local only"],
|
|
821
|
-
action: "set-usage-recording" as const,
|
|
822
|
-
},
|
|
823
|
-
],
|
|
824
|
-
};
|
|
825
|
-
}
|
|
826
|
-
|
|
827
|
-
async function applyUsageRecordingSetting(
|
|
828
|
-
value: string | undefined,
|
|
829
|
-
ctx: ExtensionCommandContext,
|
|
830
|
-
runtime: SubagentSettingsRuntime,
|
|
831
|
-
options: { signal: AbortSignal; isCurrent: () => boolean },
|
|
832
|
-
) {
|
|
833
|
-
if (options.signal.aborted || !options.isCurrent()) return { kind: "close" as const };
|
|
834
|
-
const previous = runtime.getUsageRecordingEnabled?.() ?? false;
|
|
835
|
-
const next = value === "On · local only";
|
|
836
|
-
if (next === previous) return { kind: "stay" as const };
|
|
837
|
-
if (!runtime.setUsageRecordingEnabled) {
|
|
838
|
-
ctx.ui.notify("Usage recording is unavailable in this session.", "error");
|
|
839
|
-
return { kind: "rejected" as const };
|
|
840
|
-
}
|
|
841
|
-
try {
|
|
842
|
-
updateUsageRecordingSetting(next);
|
|
843
|
-
} catch (error) {
|
|
844
|
-
ctx.ui.notify(`Subagent settings were not saved: ${formatError(error)}`, "error");
|
|
845
|
-
return { kind: "rejected" as const };
|
|
846
|
-
}
|
|
847
|
-
try {
|
|
848
|
-
await runtime.setUsageRecordingEnabled(next);
|
|
849
|
-
if (options.signal.aborted || !options.isCurrent()) return { kind: "close" as const };
|
|
850
|
-
ctx.ui.notify(
|
|
851
|
-
next
|
|
852
|
-
? `Local content-free usage recording enabled. Records stay on this device for ${USAGE_RECORDING_RETENTION_DAYS} days.`
|
|
853
|
-
: "Local usage recording disabled. Existing records expire under the retention policy.",
|
|
854
|
-
"info",
|
|
855
|
-
);
|
|
856
|
-
return { kind: "stay" as const };
|
|
857
|
-
} catch (error) {
|
|
858
|
-
if (options.signal.aborted || !options.isCurrent()) return { kind: "close" as const };
|
|
859
|
-
try {
|
|
860
|
-
updateUsageRecordingSetting(previous);
|
|
861
|
-
await runtime.setUsageRecordingEnabled(previous);
|
|
862
|
-
if (options.signal.aborted || !options.isCurrent()) return { kind: "close" as const };
|
|
863
|
-
} catch (rollbackError) {
|
|
864
|
-
if (options.signal.aborted || !options.isCurrent()) return { kind: "close" as const };
|
|
865
|
-
ctx.ui.notify(
|
|
866
|
-
`Usage recording could not be applied or rolled back: ${formatError(new AggregateError([error, rollbackError]))}`,
|
|
867
|
-
"error",
|
|
868
|
-
);
|
|
869
|
-
return { kind: "rejected" as const };
|
|
870
|
-
}
|
|
871
|
-
ctx.ui.notify(`Subagent settings were not applied: ${formatError(error)}`, "error");
|
|
872
|
-
return { kind: "rejected" as const };
|
|
873
|
-
}
|
|
874
|
-
}
|
|
875
|
-
|
|
876
|
-
function applyCompletionSetting(
|
|
877
|
-
value: string | undefined,
|
|
878
|
-
ctx: ExtensionCommandContext,
|
|
879
|
-
runtime: SubagentSettingsRuntime,
|
|
880
|
-
) {
|
|
881
|
-
const previous = runtime.getCompletionDelivery();
|
|
882
|
-
const next: CompletionDelivery =
|
|
883
|
-
value === "Continue automatically when work finishes" ? "auto-resume" : "next-turn";
|
|
884
|
-
if (next === previous) return { kind: "stay" as const };
|
|
885
|
-
try {
|
|
886
|
-
updateCompletionDeliverySetting(next);
|
|
887
|
-
runtime.setCompletionDelivery(next);
|
|
888
|
-
ctx.ui.notify(`Saved and applied: ${completionLabel(next)}.`, "info");
|
|
889
|
-
return { kind: "stay" as const };
|
|
890
|
-
} catch (error) {
|
|
891
|
-
ctx.ui.notify(`Subagent settings were not saved: ${formatError(error)}`, "error");
|
|
892
|
-
return { kind: "rejected" as const };
|
|
893
|
-
}
|
|
894
|
-
}
|
|
895
|
-
|
|
896
|
-
function applyConsultResourceSetting(
|
|
897
|
-
value: string | undefined,
|
|
898
|
-
ctx: ExtensionCommandContext,
|
|
899
|
-
runtime: SubagentSettingsRuntime,
|
|
900
|
-
) {
|
|
901
|
-
const previous = runtime.getConsultResourcePolicy();
|
|
902
|
-
const next: ConsultResourcePolicy =
|
|
903
|
-
value === "No project resources"
|
|
904
|
-
? "none"
|
|
905
|
-
: value === "All trusted resources"
|
|
906
|
-
? "all"
|
|
907
|
-
: "project-context";
|
|
908
|
-
if (next === previous) return { kind: "stay" as const };
|
|
909
|
-
try {
|
|
910
|
-
updateConsultResourceSetting(next);
|
|
911
|
-
runtime.setConsultResourcePolicy(next);
|
|
912
|
-
ctx.ui.notify(`Saved and applied: ${consultResourceLabel(next)}.`, "info");
|
|
913
|
-
return { kind: "stay" as const };
|
|
914
|
-
} catch (error) {
|
|
915
|
-
ctx.ui.notify(`Subagent settings were not saved: ${formatError(error)}`, "error");
|
|
916
|
-
return { kind: "rejected" as const };
|
|
917
|
-
}
|
|
918
|
-
}
|
|
919
|
-
|
|
920
|
-
function applyConsultationCwdSetting(
|
|
921
|
-
value: string | undefined,
|
|
922
|
-
ctx: ExtensionCommandContext,
|
|
923
|
-
runtime: SubagentSettingsRuntime,
|
|
924
|
-
) {
|
|
925
|
-
const previous = runtime.getConsultationCwdPolicy();
|
|
926
|
-
const next: ConsultationCwdPolicy =
|
|
927
|
-
value === "This workspace only" ? "current-workspace" : "anywhere";
|
|
928
|
-
if (next === previous) return { kind: "stay" as const };
|
|
929
|
-
try {
|
|
930
|
-
updateCwdPolicySetting("consultation", next);
|
|
931
|
-
runtime.setConsultationCwdPolicy(next);
|
|
932
|
-
ctx.ui.notify(`Saved and applied: ${consultationCwdLabel(next)}.`, "info");
|
|
933
|
-
return { kind: "stay" as const };
|
|
934
|
-
} catch (error) {
|
|
935
|
-
ctx.ui.notify(`Subagent settings were not saved: ${formatError(error)}`, "error");
|
|
936
|
-
return { kind: "rejected" as const };
|
|
937
|
-
}
|
|
938
|
-
}
|
|
939
|
-
|
|
940
|
-
function applyDelegationCwdSetting(
|
|
941
|
-
value: string | undefined,
|
|
942
|
-
ctx: ExtensionCommandContext,
|
|
943
|
-
runtime: SubagentSettingsRuntime,
|
|
944
|
-
) {
|
|
945
|
-
const previous = runtime.getDelegationCwdPolicy();
|
|
946
|
-
const next: DelegationCwdPolicy =
|
|
947
|
-
value === "This workspace only"
|
|
948
|
-
? "current-workspace"
|
|
949
|
-
: value === "Any folder Pi can access"
|
|
950
|
-
? "anywhere"
|
|
951
|
-
: "trusted-targets";
|
|
952
|
-
if (next === previous) return { kind: "stay" as const };
|
|
953
|
-
try {
|
|
954
|
-
updateCwdPolicySetting("delegation", next);
|
|
955
|
-
runtime.setDelegationCwdPolicy(next);
|
|
956
|
-
ctx.ui.notify(`Saved and applied: ${delegationCwdLabel(next)}.`, "info");
|
|
957
|
-
return { kind: "stay" as const };
|
|
958
|
-
} catch (error) {
|
|
959
|
-
ctx.ui.notify(`Subagent settings were not saved: ${formatError(error)}`, "error");
|
|
960
|
-
return { kind: "rejected" as const };
|
|
961
|
-
}
|
|
962
|
-
}
|
|
963
|
-
|
|
964
|
-
function blockReloadWithRetainedAgents(
|
|
965
|
-
ctx: ExtensionCommandContext,
|
|
966
|
-
runtime: SubagentSettingsRuntime,
|
|
967
|
-
): boolean {
|
|
968
|
-
const status = runtime.getRuntimeStatus();
|
|
969
|
-
if (status.retainedAgents === 0) return false;
|
|
970
|
-
ctx.ui.notify(
|
|
971
|
-
`Cannot reload while ${status.retainedAgents} subagent${status.retainedAgents === 1 ? " is" : "s are"} saved for follow-up (${status.activeAgents} working). Open Current subagents and clear them after their work is safe to discard, then change how subagents run.`,
|
|
972
|
-
"warning",
|
|
973
|
-
);
|
|
974
|
-
return true;
|
|
975
|
-
}
|
|
976
|
-
|
|
977
|
-
function isWorkflow(value: string): value is Exclude<DelegationWorkflow, "disabled"> {
|
|
978
|
-
return value === "all" || value === "async-only" || value === "blocking-only";
|
|
979
|
-
}
|
|
980
|
-
|
|
981
|
-
function formatError(error: unknown): string {
|
|
982
|
-
return safeTerminalText(error instanceof Error ? error.message : String(error));
|
|
983
|
-
}
|