@narumitw/pi-plan-mode 0.58.0 → 0.58.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/dist/chunks/{chunk-QHHHBTDO.js → chunk-HF7ZEYIC.js} +29 -111
- package/dist/chunks/chunk-HF7ZEYIC.js.map +7 -0
- package/dist/chunks/{interactive-ui-UNJGC2RQ.js → interactive-ui-UK7IGPOE.js} +13 -41
- package/dist/chunks/interactive-ui-UK7IGPOE.js.map +7 -0
- package/dist/index.ts +25 -82
- package/dist/index.ts.map +2 -2
- package/package.json +50 -51
- package/src/active-implementation-menu.ts +57 -60
- package/src/command.ts +22 -22
- package/src/completion-tool.ts +53 -56
- package/src/extension-runtime.ts +5 -5
- package/src/finalization-request.ts +40 -44
- package/src/fresh-handoff-coordinator.ts +38 -41
- package/src/fresh-implementation.ts +293 -310
- package/src/implementation-models.ts +25 -30
- package/src/implementation-retention.ts +109 -123
- package/src/message-transform.ts +218 -252
- package/src/mode-contract.ts +46 -49
- package/src/plan-action-controller.ts +134 -155
- package/src/plan-action-menus.ts +390 -408
- package/src/plan-export-controller.ts +23 -28
- package/src/plan-export-screen.ts +13 -13
- package/src/plan-export.ts +85 -102
- package/src/plan-launch-menu.ts +119 -119
- package/src/plan-mode.ts +2017 -2098
- package/src/presentation.ts +84 -108
- package/src/prompt.ts +1 -1
- package/src/question-tool.ts +239 -267
- package/src/required-tools.ts +15 -19
- package/src/saved-plan-menu.ts +82 -84
- package/src/saved-plan-preflight.ts +29 -33
- package/src/settings-menu.ts +470 -513
- package/src/settings.ts +393 -452
- package/src/state.ts +167 -198
- package/src/tool-policy.ts +634 -699
- package/src/tool-selection.ts +39 -44
- package/src/workflow-mutex.ts +66 -66
- package/dist/chunks/chunk-QHHHBTDO.js.map +0 -7
- package/dist/chunks/interactive-ui-UNJGC2RQ.js.map +0 -7
|
@@ -4,35 +4,30 @@ import { configuredPlanExportPath, type PlanModeSettings } from "./settings.js";
|
|
|
4
4
|
import type { PlanModeState } from "./state.js";
|
|
5
5
|
|
|
6
6
|
interface PlanExportControllerOptions {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
getState(): PlanModeState;
|
|
8
|
+
getSettings(): PlanModeSettings;
|
|
9
|
+
finishReady(ctx: ExtensionContext): void;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export function createPlanExportController(options: PlanExportControllerOptions) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
},
|
|
34
|
-
getDestination(ctx: ExtensionContext) {
|
|
35
|
-
return planExportDestination(configuredPlanExportPath(options.getSettings()), ctx.cwd);
|
|
36
|
-
},
|
|
37
|
-
};
|
|
13
|
+
return {
|
|
14
|
+
export(path: string | undefined, ctx: ExtensionContext, signal: AbortSignal, isCurrent: () => boolean) {
|
|
15
|
+
const state = options.getState();
|
|
16
|
+
return exportStoredPlan(
|
|
17
|
+
state,
|
|
18
|
+
path,
|
|
19
|
+
ctx,
|
|
20
|
+
{
|
|
21
|
+
signal,
|
|
22
|
+
isCurrent,
|
|
23
|
+
getState: options.getState,
|
|
24
|
+
finishReady: () => options.finishReady(ctx),
|
|
25
|
+
},
|
|
26
|
+
configuredPlanExportPath(options.getSettings()),
|
|
27
|
+
);
|
|
28
|
+
},
|
|
29
|
+
getDestination(ctx: ExtensionContext) {
|
|
30
|
+
return planExportDestination(configuredPlanExportPath(options.getSettings()), ctx.cwd);
|
|
31
|
+
},
|
|
32
|
+
};
|
|
38
33
|
}
|
|
@@ -3,17 +3,17 @@ import type { PlanExportDestination } from "./plan-export.js";
|
|
|
3
3
|
export type PlanExportDestinationProvider = () => PlanExportDestination;
|
|
4
4
|
|
|
5
5
|
export function planExportInputScreen(getDestination: PlanExportDestinationProvider) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
6
|
+
const destination = getDestination();
|
|
7
|
+
return {
|
|
8
|
+
kind: "input" as const,
|
|
9
|
+
title: "Export plan",
|
|
10
|
+
lines: [
|
|
11
|
+
"Existing paths are never overwritten.",
|
|
12
|
+
`Default: ${destination.configuredPath}`,
|
|
13
|
+
`Resolves to: ${destination.resolvedPath}`,
|
|
14
|
+
],
|
|
15
|
+
placeholder: destination.configuredPath,
|
|
16
|
+
action: "export" as const,
|
|
17
|
+
hint: "back" as const,
|
|
18
|
+
};
|
|
19
19
|
}
|
package/src/plan-export.ts
CHANGED
|
@@ -8,138 +8,121 @@ import type { PlanModeState } from "./state.js";
|
|
|
8
8
|
export { DEFAULT_PLAN_EXPORT_PATH };
|
|
9
9
|
|
|
10
10
|
export interface PlanExportResult {
|
|
11
|
-
|
|
11
|
+
path: string;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
export interface PlanExportDestination {
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
configuredPath: string;
|
|
16
|
+
resolvedPath: string;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
export interface PlanExportLifecycle {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
signal: AbortSignal;
|
|
21
|
+
isCurrent(): boolean;
|
|
22
|
+
getState?(): PlanModeState;
|
|
23
|
+
finishReady?(): void;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
export async function exportStoredPlan(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
state: PlanModeState,
|
|
28
|
+
requestedPath: string | undefined,
|
|
29
|
+
ctx: ExtensionContext,
|
|
30
|
+
lifecycle?: PlanExportLifecycle,
|
|
31
|
+
defaultPath = DEFAULT_PLAN_EXPORT_PATH,
|
|
32
32
|
) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
return false;
|
|
44
|
-
}
|
|
33
|
+
const plan =
|
|
34
|
+
(state.enabled ? state.latestPlan : undefined)?.trim() ??
|
|
35
|
+
state.savedPlan?.plan.trim() ??
|
|
36
|
+
state.activeImplementation?.plan.trim();
|
|
37
|
+
if (!plan) {
|
|
38
|
+
const error = new Error("No completed plan is available to export. Use /plan finalize when planning is complete.");
|
|
39
|
+
if (!ctx.hasUI) throw error;
|
|
40
|
+
ctx.ui.notify(error.message, "warning");
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
45
43
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
);
|
|
59
|
-
} catch (error: unknown) {
|
|
60
|
-
if (lifecycle?.signal.aborted || !isCurrent()) return false;
|
|
61
|
-
if (!ctx.hasUI) throw error;
|
|
62
|
-
const detail = error instanceof Error ? error.message : String(error);
|
|
63
|
-
ctx.ui.notify(safeNotification(`Unable to export plan: ${detail}`), "error");
|
|
64
|
-
return false;
|
|
65
|
-
}
|
|
44
|
+
const isCurrent = () =>
|
|
45
|
+
!lifecycle || (lifecycle.isCurrent() && (!lifecycle.getState || lifecycle.getState() === state));
|
|
46
|
+
let result: PlanExportResult;
|
|
47
|
+
try {
|
|
48
|
+
result = await exportPlanToFile(plan, requestedPath, ctx.cwd, lifecycle?.signal, isCurrent, defaultPath);
|
|
49
|
+
} catch (error: unknown) {
|
|
50
|
+
if (lifecycle?.signal.aborted || !isCurrent()) return false;
|
|
51
|
+
if (!ctx.hasUI) throw error;
|
|
52
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
53
|
+
ctx.ui.notify(safeNotification(`Unable to export plan: ${detail}`), "error");
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
66
56
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
return true;
|
|
57
|
+
if (!isCurrent()) return false;
|
|
58
|
+
const finishedReady = state.enabled && Boolean(state.latestPlan?.trim()) && lifecycle?.finishReady !== undefined;
|
|
59
|
+
if (finishedReady) lifecycle.finishReady?.();
|
|
60
|
+
const detail = finishedReady ? " Plan mode disabled." : "";
|
|
61
|
+
ctx.ui.notify(safeNotification(`Plan exported to ${result.path}.${detail}`), "info");
|
|
62
|
+
return true;
|
|
74
63
|
}
|
|
75
64
|
|
|
76
65
|
export async function exportPlanToFile(
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
66
|
+
plan: string,
|
|
67
|
+
requestedPath: string | undefined,
|
|
68
|
+
cwd: string,
|
|
69
|
+
signal?: AbortSignal,
|
|
70
|
+
isCurrent: () => boolean = () => true,
|
|
71
|
+
defaultPath = DEFAULT_PLAN_EXPORT_PATH,
|
|
83
72
|
): Promise<PlanExportResult> {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
});
|
|
100
|
-
return { path };
|
|
73
|
+
const path = resolvePlanExportPath(requestedPath, cwd, defaultPath);
|
|
74
|
+
await withFileMutationQueue(path, async () => {
|
|
75
|
+
throwIfCancelled(signal, isCurrent);
|
|
76
|
+
await mkdir(dirname(path), { recursive: true });
|
|
77
|
+
throwIfCancelled(signal, isCurrent);
|
|
78
|
+
try {
|
|
79
|
+
await writeFile(path, `${plan}\n`, { encoding: "utf8", flag: "wx" });
|
|
80
|
+
} catch (error: unknown) {
|
|
81
|
+
if (isNodeError(error) && error.code === "EEXIST") {
|
|
82
|
+
throw new Error(`Plan export target already exists: ${path}. Choose another path or remove it first.`);
|
|
83
|
+
}
|
|
84
|
+
throw error;
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
return { path };
|
|
101
88
|
}
|
|
102
89
|
|
|
103
90
|
export function planExportDestination(defaultPath: string, cwd: string): PlanExportDestination {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
91
|
+
return {
|
|
92
|
+
configuredPath: safeNotification(defaultPath),
|
|
93
|
+
resolvedPath: safeNotification(resolvePlanExportPath(undefined, cwd, defaultPath)),
|
|
94
|
+
};
|
|
108
95
|
}
|
|
109
96
|
|
|
110
97
|
export function resolvePlanExportPath(
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
98
|
+
requestedPath: string | undefined,
|
|
99
|
+
cwd: string,
|
|
100
|
+
defaultPath = DEFAULT_PLAN_EXPORT_PATH,
|
|
114
101
|
) {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
102
|
+
const rawPath = requestedPath?.trim() || defaultPath;
|
|
103
|
+
const normalizedPath = rawPath.startsWith("@") ? rawPath.slice(1) : rawPath;
|
|
104
|
+
if (!normalizedPath.trim()) throw new Error("Plan export path must not be empty.");
|
|
105
|
+
if (normalizedPath.includes("\0")) {
|
|
106
|
+
throw new Error("Plan export path must not contain NUL bytes.");
|
|
107
|
+
}
|
|
108
|
+
return resolve(cwd, normalizedPath);
|
|
122
109
|
}
|
|
123
110
|
|
|
124
111
|
function safeNotification(value: string) {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}
|
|
133
|
-
return sanitized;
|
|
112
|
+
let sanitized = "";
|
|
113
|
+
for (const character of stripVTControlCharacters(value)) {
|
|
114
|
+
const codePoint = character.codePointAt(0);
|
|
115
|
+
sanitized +=
|
|
116
|
+
codePoint !== undefined && codePoint > 0x1f && !(codePoint >= 0x7f && codePoint <= 0x9f) ? character : " ";
|
|
117
|
+
}
|
|
118
|
+
return sanitized;
|
|
134
119
|
}
|
|
135
120
|
|
|
136
121
|
function throwIfCancelled(signal: AbortSignal | undefined, isCurrent: () => boolean) {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
? signal.reason
|
|
140
|
-
: new DOMException("Plan export cancelled", "AbortError");
|
|
122
|
+
if (!signal?.aborted && isCurrent()) return;
|
|
123
|
+
throw signal?.reason instanceof Error ? signal.reason : new DOMException("Plan export cancelled", "AbortError");
|
|
141
124
|
}
|
|
142
125
|
|
|
143
126
|
function isNodeError(error: unknown): error is NodeJS.ErrnoException {
|
|
144
|
-
|
|
127
|
+
return error instanceof Error && "code" in error;
|
|
145
128
|
}
|
package/src/plan-launch-menu.ts
CHANGED
|
@@ -2,129 +2,129 @@ import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
|
2
2
|
import { defineMenu, runMenu } from "@narumitw/pi-tui-kit";
|
|
3
3
|
|
|
4
4
|
export interface PlanLaunchTool {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
name: string;
|
|
6
|
+
label?: string;
|
|
7
|
+
description: string;
|
|
8
|
+
searchText: string;
|
|
9
|
+
disabled: boolean;
|
|
10
|
+
disabledReason?: string;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
interface PlanLaunchMenuOptions {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
14
|
+
statusText: string;
|
|
15
|
+
toolSummary(selectedNames: ReadonlySet<string>): string;
|
|
16
|
+
getSelectedNames(): ReadonlySet<string>;
|
|
17
|
+
tools: readonly PlanLaunchTool[];
|
|
18
|
+
signal: AbortSignal;
|
|
19
|
+
isCurrent(): boolean;
|
|
20
|
+
initialScreen?: "main" | "tools";
|
|
21
|
+
start(signal: AbortSignal): void;
|
|
22
|
+
startWithTools(toolNames: string[], signal: AbortSignal): void;
|
|
23
|
+
settings(signal: AbortSignal): Promise<boolean>;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
export async function showPlanLaunchMenu(ctx: ExtensionContext, options: PlanLaunchMenuOptions) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
27
|
+
type Screen = "main" | "tools" | "help";
|
|
28
|
+
type Action = "start" | "toggle-tool" | "start-with-tools" | "settings";
|
|
29
|
+
const selectedNames = new Set(options.getSelectedNames());
|
|
30
|
+
const toolItems = options.tools.map((tool, index) => ({
|
|
31
|
+
id: `plan-tool:${index}`,
|
|
32
|
+
tool,
|
|
33
|
+
}));
|
|
34
|
+
const toolsByItemId = new Map(toolItems.map(({ id, tool }) => [id, tool]));
|
|
35
|
+
let draftChanged = false;
|
|
36
|
+
const menu = defineMenu<undefined, Screen, Action, ExtensionContext>({
|
|
37
|
+
start: options.initialScreen ?? "main",
|
|
38
|
+
screens: {
|
|
39
|
+
main: () => ({
|
|
40
|
+
kind: "actions",
|
|
41
|
+
title: "Plan mode",
|
|
42
|
+
lines: [options.statusText, options.toolSummary(selectedNames)],
|
|
43
|
+
items: [
|
|
44
|
+
{ id: "start", label: "Start Plan mode", action: "start" },
|
|
45
|
+
{ id: "tools", label: "Choose tools, then start…", to: "tools" },
|
|
46
|
+
{ id: "settings", label: "Settings", action: "settings" },
|
|
47
|
+
{ id: "help", label: "How Plan mode works", to: "help" },
|
|
48
|
+
],
|
|
49
|
+
hint: "close",
|
|
50
|
+
}),
|
|
51
|
+
tools: () => ({
|
|
52
|
+
kind: "multiSelect",
|
|
53
|
+
title: "Choose Plan policy allowlist",
|
|
54
|
+
lines: [
|
|
55
|
+
"Policy changes apply only when you start Plan mode; first use may also reveal Plan helpers.",
|
|
56
|
+
options.toolSummary(selectedNames),
|
|
57
|
+
"Active tools can be chosen now; retained names resolve before the first request.",
|
|
58
|
+
"Plan mode never activates tools, and non-built-ins run at user risk.",
|
|
59
|
+
],
|
|
60
|
+
enableSearch: true,
|
|
61
|
+
viewportSize: 10,
|
|
62
|
+
items: toolItems.map(({ id, tool }) => ({
|
|
63
|
+
id,
|
|
64
|
+
label: tool.label ?? tool.name,
|
|
65
|
+
description: tool.description,
|
|
66
|
+
searchText: tool.searchText,
|
|
67
|
+
selected: selectedNames.has(tool.name),
|
|
68
|
+
disabled: tool.disabled,
|
|
69
|
+
disabledReason: tool.disabledReason,
|
|
70
|
+
})),
|
|
71
|
+
action: "toggle-tool",
|
|
72
|
+
actions: [
|
|
73
|
+
{
|
|
74
|
+
id: "start-with-tools",
|
|
75
|
+
label: "Done — start with this policy",
|
|
76
|
+
action: "start-with-tools",
|
|
77
|
+
},
|
|
78
|
+
],
|
|
79
|
+
hint: "back",
|
|
80
|
+
}),
|
|
81
|
+
help: () => ({
|
|
82
|
+
kind: "detail",
|
|
83
|
+
title: "How Plan mode works",
|
|
84
|
+
lines: [
|
|
85
|
+
"Plan mode uses read-only exploration to understand the project before implementation.",
|
|
86
|
+
"The agent can ask important decision questions, then returns a complete implementation-ready plan.",
|
|
87
|
+
"File mutation stays blocked until you explicitly choose to implement the completed plan.",
|
|
88
|
+
],
|
|
89
|
+
hint: "back",
|
|
90
|
+
}),
|
|
91
|
+
},
|
|
92
|
+
actions: {
|
|
93
|
+
start: async ({ signal }) => {
|
|
94
|
+
if (signal.aborted || !options.isCurrent()) return { kind: "rejected" };
|
|
95
|
+
options.start(signal);
|
|
96
|
+
return { kind: "close" };
|
|
97
|
+
},
|
|
98
|
+
"toggle-tool": async ({ itemId, selected, signal }) => {
|
|
99
|
+
if (signal.aborted || !options.isCurrent()) return { kind: "rejected" };
|
|
100
|
+
const tool = itemId ? toolsByItemId.get(itemId) : undefined;
|
|
101
|
+
if (!tool || tool.disabled) return { kind: "rejected" };
|
|
102
|
+
if (selected) selectedNames.add(tool.name);
|
|
103
|
+
else selectedNames.delete(tool.name);
|
|
104
|
+
draftChanged = true;
|
|
105
|
+
return { kind: "stay" };
|
|
106
|
+
},
|
|
107
|
+
"start-with-tools": async ({ signal }) => {
|
|
108
|
+
if (signal.aborted || !options.isCurrent()) return { kind: "rejected" };
|
|
109
|
+
options.startWithTools(Array.from(selectedNames), signal);
|
|
110
|
+
return { kind: "close" };
|
|
111
|
+
},
|
|
112
|
+
settings: async ({ signal }) => {
|
|
113
|
+
if (signal.aborted || !options.isCurrent()) return { kind: "rejected" };
|
|
114
|
+
const close = await options.settings(signal);
|
|
115
|
+
if (signal.aborted || !options.isCurrent()) return { kind: "rejected" };
|
|
116
|
+
if (close) return { kind: "close" };
|
|
117
|
+
if (!draftChanged) {
|
|
118
|
+
selectedNames.clear();
|
|
119
|
+
for (const name of options.getSelectedNames()) selectedNames.add(name);
|
|
120
|
+
}
|
|
121
|
+
return { kind: "stay" };
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
});
|
|
125
|
+
await runMenu(ctx, menu, {
|
|
126
|
+
getState: () => undefined,
|
|
127
|
+
signal: options.signal,
|
|
128
|
+
isCurrent: options.isCurrent,
|
|
129
|
+
});
|
|
130
130
|
}
|