@narumitw/pi-plan-mode 0.47.0 → 0.48.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 +101 -50
- package/package.json +1 -1
- package/src/active-implementation-menu.ts +11 -9
- package/src/command.ts +6 -1
- package/src/fresh-implementation.ts +213 -0
- package/src/implementation-retention.ts +122 -0
- package/src/message-transform.ts +1 -1
- package/src/plan-action-controller.ts +93 -0
- package/src/plan-action-menus.ts +73 -36
- package/src/plan-export-controller.ts +38 -0
- package/src/plan-export-screen.ts +19 -0
- package/src/plan-export.ts +31 -5
- package/src/plan-launch-menu.ts +122 -0
- package/src/plan-mode.ts +221 -236
- package/src/saved-plan-menu.ts +39 -14
- package/src/settings-menu.ts +346 -0
- package/src/settings.ts +275 -44
- package/src/state.ts +13 -2
- package/src/tool-policy.ts +14 -47
- package/src/tool-selection.ts +65 -1
package/src/saved-plan-menu.ts
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
import { defineMenu, runMenu } from "@narumitw/pi-tui-kit";
|
|
3
|
+
import { type PlanExportDestinationProvider, planExportInputScreen } from "./plan-export-screen.js";
|
|
3
4
|
|
|
4
5
|
interface SavedPlanMenuOptions {
|
|
5
6
|
statusText: string;
|
|
7
|
+
implementationOutcome(): string;
|
|
8
|
+
getExportDestination: PlanExportDestinationProvider;
|
|
6
9
|
signal: AbortSignal;
|
|
7
10
|
isCurrent(): boolean;
|
|
8
11
|
show(): void;
|
|
9
|
-
|
|
12
|
+
implementHere(): void | Promise<void>;
|
|
13
|
+
implementFresh(signal: AbortSignal): void | Promise<void>;
|
|
10
14
|
exportPlan(path: string, signal: AbortSignal): Promise<boolean>;
|
|
15
|
+
settings(signal: AbortSignal): Promise<boolean>;
|
|
11
16
|
clear(): void;
|
|
12
17
|
}
|
|
13
18
|
|
|
@@ -18,42 +23,62 @@ export async function showSavedPlanMenu(ctx: ExtensionContext, options: SavedPla
|
|
|
18
23
|
);
|
|
19
24
|
}
|
|
20
25
|
type Screen = "saved" | "export";
|
|
21
|
-
type Action = "show" | "implement" | "export" | "clear";
|
|
26
|
+
type Action = "show" | "implement-here" | "implement-fresh" | "export" | "settings" | "clear";
|
|
22
27
|
const menu = defineMenu<undefined, Screen, Action, ExtensionContext>({
|
|
23
28
|
start: "saved",
|
|
24
29
|
screens: {
|
|
25
30
|
saved: () => ({
|
|
26
31
|
kind: "actions",
|
|
27
32
|
title: "Saved plan",
|
|
28
|
-
lines: [
|
|
33
|
+
lines: [
|
|
34
|
+
options.statusText,
|
|
35
|
+
"Implement here keeps this planning conversation.",
|
|
36
|
+
"Start fresh transfers only the approved plan to a new session.",
|
|
37
|
+
options.implementationOutcome(),
|
|
38
|
+
],
|
|
29
39
|
items: [
|
|
30
40
|
{ id: "show", label: "Show saved plan", action: "show" },
|
|
31
|
-
{
|
|
41
|
+
{
|
|
42
|
+
id: "implement-here",
|
|
43
|
+
label: "Implement here",
|
|
44
|
+
description: "Continue in this session with the planning conversation.",
|
|
45
|
+
action: "implement-here",
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
id: "implement-fresh",
|
|
49
|
+
label: "Start fresh and implement",
|
|
50
|
+
description: "Open a new linked session; transfer only the approved plan.",
|
|
51
|
+
action: "implement-fresh",
|
|
52
|
+
busyLabel: "Starting fresh implementation session…",
|
|
53
|
+
},
|
|
32
54
|
{ id: "export", label: "Export plan…", to: "export" },
|
|
55
|
+
{ id: "settings", label: "Settings", action: "settings" },
|
|
33
56
|
{ id: "clear", label: "Clear saved plan", action: "clear" },
|
|
34
57
|
],
|
|
35
58
|
hint: "close",
|
|
36
59
|
}),
|
|
37
|
-
export: () => (
|
|
38
|
-
kind: "input",
|
|
39
|
-
title: "Export plan",
|
|
40
|
-
lines: ["Existing paths are never overwritten."],
|
|
41
|
-
placeholder: "PLAN.md",
|
|
42
|
-
action: "export",
|
|
43
|
-
hint: "back",
|
|
44
|
-
}),
|
|
60
|
+
export: () => planExportInputScreen(options.getExportDestination),
|
|
45
61
|
},
|
|
46
62
|
actions: {
|
|
47
63
|
show: async () => {
|
|
48
64
|
options.show();
|
|
49
65
|
return { kind: "close" };
|
|
50
66
|
},
|
|
51
|
-
implement: async () => {
|
|
52
|
-
await options.
|
|
67
|
+
"implement-here": async () => {
|
|
68
|
+
await options.implementHere();
|
|
69
|
+
return { kind: "close" };
|
|
70
|
+
},
|
|
71
|
+
"implement-fresh": async ({ signal }) => {
|
|
72
|
+
await options.implementFresh(signal);
|
|
53
73
|
return { kind: "close" };
|
|
54
74
|
},
|
|
55
75
|
export: async ({ value, signal }) =>
|
|
56
76
|
(await options.exportPlan(value ?? "", signal)) ? { kind: "close" } : { kind: "rejected" },
|
|
77
|
+
settings: async ({ signal }) => {
|
|
78
|
+
const close = await options.settings(signal);
|
|
79
|
+
if (signal.aborted || !options.isCurrent()) return { kind: "rejected" };
|
|
80
|
+
return close ? { kind: "close" } : { kind: "stay" };
|
|
81
|
+
},
|
|
57
82
|
clear: async () => {
|
|
58
83
|
options.clear();
|
|
59
84
|
return { kind: "close" };
|
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
import type { ExtensionContext, ToolInfo } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { defineMenu, type RunMenuResult, runMenu } from "@narumitw/pi-tui-kit";
|
|
3
|
+
import { PLAN_MODE_COMPLETE_TOOL_NAME } from "./completion-tool.js";
|
|
4
|
+
import { retentionLabel } from "./implementation-retention.js";
|
|
5
|
+
import { planExportDestination } from "./plan-export.js";
|
|
6
|
+
import { PLAN_MODE_QUESTION_TOOL_NAME } from "./question-tool.js";
|
|
7
|
+
import {
|
|
8
|
+
configuredImplementationPlanRetention,
|
|
9
|
+
configuredPlanExportPath,
|
|
10
|
+
IMPLEMENTATION_PLAN_RETENTIONS,
|
|
11
|
+
PLAN_MODE_THINKING_LEVELS,
|
|
12
|
+
type PlanModeSettings,
|
|
13
|
+
type PlanModeSettingsLoadResult,
|
|
14
|
+
type PlanModeSettingsPatch,
|
|
15
|
+
planModeSettingsPath,
|
|
16
|
+
readPlanModeSettings,
|
|
17
|
+
type UpdatePlanModeSettingsOptions,
|
|
18
|
+
updatePlanModeSettings,
|
|
19
|
+
} from "./settings.js";
|
|
20
|
+
import { canSelectToolInPlanMode } from "./tool-policy.js";
|
|
21
|
+
import { defaultPlanModeToolNames, toolPolicyLabel } from "./tool-selection.js";
|
|
22
|
+
|
|
23
|
+
interface SettingsMenuState {
|
|
24
|
+
kind: "valid" | "invalid";
|
|
25
|
+
settings: PlanModeSettings;
|
|
26
|
+
notice?: string;
|
|
27
|
+
reason?: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface PlanModeSettingsMenuOptions {
|
|
31
|
+
tools: readonly ToolInfo[];
|
|
32
|
+
signal: AbortSignal;
|
|
33
|
+
isCurrent(): boolean;
|
|
34
|
+
settingsPath?: string;
|
|
35
|
+
legacySettingsPath?: string;
|
|
36
|
+
readSettings?: (settingsPath?: string) => Promise<PlanModeSettingsLoadResult>;
|
|
37
|
+
updateSettings?: (
|
|
38
|
+
patch: PlanModeSettingsPatch,
|
|
39
|
+
options?: UpdatePlanModeSettingsOptions,
|
|
40
|
+
) => Promise<PlanModeSettings>;
|
|
41
|
+
onSaved(settings: PlanModeSettings): void;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
type Screen = "settings" | "tools" | "export";
|
|
45
|
+
type Action =
|
|
46
|
+
| "set-thinking"
|
|
47
|
+
| "open-tools"
|
|
48
|
+
| "toggle-tool"
|
|
49
|
+
| "reset-tools"
|
|
50
|
+
| "set-retention"
|
|
51
|
+
| "open-export"
|
|
52
|
+
| "set-export";
|
|
53
|
+
|
|
54
|
+
export async function showPlanModeSettings(
|
|
55
|
+
ctx: ExtensionContext,
|
|
56
|
+
options: PlanModeSettingsMenuOptions,
|
|
57
|
+
): Promise<RunMenuResult> {
|
|
58
|
+
const settingsPath = options.settingsPath ?? planModeSettingsPath();
|
|
59
|
+
const readSettings = options.readSettings ?? readPlanModeSettings;
|
|
60
|
+
const updateSettings = options.updateSettings ?? updatePlanModeSettings;
|
|
61
|
+
const tools = options.tools.filter(
|
|
62
|
+
(tool) =>
|
|
63
|
+
tool.name !== PLAN_MODE_QUESTION_TOOL_NAME && tool.name !== PLAN_MODE_COMPLETE_TOOL_NAME,
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
const loadState = async (): Promise<SettingsMenuState> => {
|
|
67
|
+
const loaded = await readSettings(options.settingsPath);
|
|
68
|
+
if (loaded.kind === "invalid") {
|
|
69
|
+
return {
|
|
70
|
+
kind: "invalid",
|
|
71
|
+
settings: { thinkingLevel: "inherit" },
|
|
72
|
+
notice: loaded.notice,
|
|
73
|
+
reason: loaded.reason,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
kind: "valid",
|
|
78
|
+
settings: loaded.kind === "loaded" ? loaded.settings : { thinkingLevel: "inherit" },
|
|
79
|
+
notice: loaded.notice,
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const menu = defineMenu<SettingsMenuState, Screen, Action, ExtensionContext>({
|
|
84
|
+
start: "settings",
|
|
85
|
+
screens: {
|
|
86
|
+
settings: ({ state }) =>
|
|
87
|
+
state.kind === "invalid"
|
|
88
|
+
? invalidScreen(settingsPath, state)
|
|
89
|
+
: {
|
|
90
|
+
kind: "settings",
|
|
91
|
+
title: "Plan Mode Settings",
|
|
92
|
+
lines: settingsLines(settingsPath, state.notice),
|
|
93
|
+
items: [
|
|
94
|
+
{
|
|
95
|
+
id: "thinkingLevel",
|
|
96
|
+
label: "Plan thinking",
|
|
97
|
+
description: "Set the thinking level when the next Plan workflow starts.",
|
|
98
|
+
currentValue: state.settings.thinkingLevel,
|
|
99
|
+
values: PLAN_MODE_THINKING_LEVELS,
|
|
100
|
+
action: "set-thinking",
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
id: "defaultPlanTools",
|
|
104
|
+
label: "Plan tools",
|
|
105
|
+
description:
|
|
106
|
+
"Choose persistent defaults; a launch-time selection still overrides them for that session.",
|
|
107
|
+
currentValue: defaultToolsValue(state.settings.defaultPlanTools),
|
|
108
|
+
action: "open-tools",
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
id: "implementationPlanRetention",
|
|
112
|
+
label: "After Implement",
|
|
113
|
+
description: "Choose how long the accepted plan keeps guiding implementation.",
|
|
114
|
+
currentValue: retentionLabel(
|
|
115
|
+
configuredImplementationPlanRetention(state.settings),
|
|
116
|
+
),
|
|
117
|
+
values: IMPLEMENTATION_PLAN_RETENTIONS.map(retentionLabel),
|
|
118
|
+
action: "set-retention",
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
id: "defaultPlanExportPath",
|
|
122
|
+
label: "Export destination",
|
|
123
|
+
description: "Set the destination used when an export omits its path.",
|
|
124
|
+
currentValue: safeTerminalText(configuredPlanExportPath(state.settings)),
|
|
125
|
+
action: "open-export",
|
|
126
|
+
},
|
|
127
|
+
],
|
|
128
|
+
},
|
|
129
|
+
tools: ({ state }) => ({
|
|
130
|
+
kind: "multiSelect",
|
|
131
|
+
title: "Default Plan-mode tools",
|
|
132
|
+
lines: [
|
|
133
|
+
"Changes apply when a later Plan workflow starts; required Plan tools stay enabled.",
|
|
134
|
+
"Non-built-in tools run at user risk.",
|
|
135
|
+
],
|
|
136
|
+
enableSearch: true,
|
|
137
|
+
viewportSize: 10,
|
|
138
|
+
items: defaultToolItems(tools, state.settings.defaultPlanTools),
|
|
139
|
+
action: "toggle-tool",
|
|
140
|
+
actions: [
|
|
141
|
+
{
|
|
142
|
+
id: "reset-tools",
|
|
143
|
+
label: "Use automatic safe built-ins",
|
|
144
|
+
action: "reset-tools",
|
|
145
|
+
},
|
|
146
|
+
],
|
|
147
|
+
hint: "back",
|
|
148
|
+
}),
|
|
149
|
+
export: ({ state }) => {
|
|
150
|
+
const configured = configuredPlanExportPath(state.settings);
|
|
151
|
+
const destination = planExportDestination(configured, ctx.cwd);
|
|
152
|
+
return {
|
|
153
|
+
kind: "input",
|
|
154
|
+
title: "Export destination",
|
|
155
|
+
lines: [
|
|
156
|
+
`Configured: ${destination.configuredPath}`,
|
|
157
|
+
`Resolves here to: ${destination.resolvedPath}`,
|
|
158
|
+
"Submit an empty value to reset to PLAN.md. Changes affect the next export.",
|
|
159
|
+
],
|
|
160
|
+
placeholder: configured,
|
|
161
|
+
action: "set-export",
|
|
162
|
+
hint: "back",
|
|
163
|
+
};
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
actions: {
|
|
167
|
+
"set-thinking": async ({ ctx: actionCtx, value, signal }) => {
|
|
168
|
+
if (
|
|
169
|
+
!PLAN_MODE_THINKING_LEVELS.includes(value as (typeof PLAN_MODE_THINKING_LEVELS)[number])
|
|
170
|
+
) {
|
|
171
|
+
return { kind: "rejected" };
|
|
172
|
+
}
|
|
173
|
+
return savePatch(
|
|
174
|
+
actionCtx,
|
|
175
|
+
{ thinkingLevel: value as PlanModeSettings["thinkingLevel"] },
|
|
176
|
+
signal,
|
|
177
|
+
`Plan mode thinking level: ${value}. Applies to the next Plan workflow.`,
|
|
178
|
+
);
|
|
179
|
+
},
|
|
180
|
+
"open-tools": async () => ({ kind: "to", screen: "tools" }),
|
|
181
|
+
"set-retention": async ({ ctx: actionCtx, value, signal }) => {
|
|
182
|
+
const implementationPlanRetention = retentionFromLabel(value);
|
|
183
|
+
if (!implementationPlanRetention) return { kind: "rejected" };
|
|
184
|
+
return savePatch(
|
|
185
|
+
actionCtx,
|
|
186
|
+
{ implementationPlanRetention },
|
|
187
|
+
signal,
|
|
188
|
+
`After Implement: ${retentionLabel(implementationPlanRetention)}. Applies to the next Implement action.`,
|
|
189
|
+
);
|
|
190
|
+
},
|
|
191
|
+
"open-export": async () => ({ kind: "to", screen: "export" }),
|
|
192
|
+
"set-export": async ({ ctx: actionCtx, value, signal }) => {
|
|
193
|
+
const defaultPlanExportPath = value?.trim() || null;
|
|
194
|
+
const result = await savePatch(
|
|
195
|
+
actionCtx,
|
|
196
|
+
{ defaultPlanExportPath },
|
|
197
|
+
signal,
|
|
198
|
+
defaultPlanExportPath
|
|
199
|
+
? `Default Plan export destination: ${safeTerminalText(defaultPlanExportPath)}.`
|
|
200
|
+
: "Default Plan export destination reset to PLAN.md.",
|
|
201
|
+
);
|
|
202
|
+
return result.kind === "stay" ? { kind: "to", screen: "settings" } : result;
|
|
203
|
+
},
|
|
204
|
+
"toggle-tool": async ({ ctx: actionCtx, state, itemId, selected, signal }) => {
|
|
205
|
+
const tool = tools.find((candidate) => candidate.name === itemId);
|
|
206
|
+
if (!tool || !canSelectToolInPlanMode(tool)) return { kind: "rejected" };
|
|
207
|
+
const names = explicitToolNames(tools, state.settings.defaultPlanTools);
|
|
208
|
+
const next = selected
|
|
209
|
+
? Array.from(new Set([...names, tool.name]))
|
|
210
|
+
: names.filter((name) => name !== tool.name);
|
|
211
|
+
return savePatch(
|
|
212
|
+
actionCtx,
|
|
213
|
+
{ defaultPlanTools: next },
|
|
214
|
+
signal,
|
|
215
|
+
`Default Plan-mode tools: ${next.length === 0 ? "required tools only" : `${next.length} selected`}.`,
|
|
216
|
+
);
|
|
217
|
+
},
|
|
218
|
+
"reset-tools": async ({ ctx: actionCtx, state, signal }) => {
|
|
219
|
+
if (state.settings.defaultPlanTools === undefined) return { kind: "stay" };
|
|
220
|
+
return savePatch(
|
|
221
|
+
actionCtx,
|
|
222
|
+
{ defaultPlanTools: null },
|
|
223
|
+
signal,
|
|
224
|
+
"Default Plan-mode tools: automatic safe built-ins.",
|
|
225
|
+
);
|
|
226
|
+
},
|
|
227
|
+
},
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
return runMenu(ctx, menu, {
|
|
231
|
+
getState: loadState,
|
|
232
|
+
signal: options.signal,
|
|
233
|
+
isCurrent: options.isCurrent,
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
async function savePatch(
|
|
237
|
+
actionCtx: ExtensionContext,
|
|
238
|
+
patch: PlanModeSettingsPatch,
|
|
239
|
+
signal: AbortSignal,
|
|
240
|
+
successMessage: string,
|
|
241
|
+
) {
|
|
242
|
+
if (signal.aborted || !options.isCurrent()) return { kind: "rejected" as const };
|
|
243
|
+
try {
|
|
244
|
+
const saved = await updateSettings(patch, {
|
|
245
|
+
settingsPath: options.settingsPath,
|
|
246
|
+
legacySettingsPath: options.legacySettingsPath,
|
|
247
|
+
signal,
|
|
248
|
+
});
|
|
249
|
+
if (options.isCurrent()) options.onSaved(saved);
|
|
250
|
+
if (signal.aborted || !options.isCurrent()) return { kind: "rejected" as const };
|
|
251
|
+
actionCtx.ui.notify(successMessage, "info");
|
|
252
|
+
return { kind: "stay" as const };
|
|
253
|
+
} catch (error) {
|
|
254
|
+
if (!signal.aborted && options.isCurrent()) {
|
|
255
|
+
actionCtx.ui.notify(
|
|
256
|
+
`Could not save Plan mode settings; the previous value remains: ${safeTerminalText(formatError(error))}`,
|
|
257
|
+
"error",
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
return { kind: "rejected" as const };
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function settingsLines(settingsPath: string, notice: string | undefined) {
|
|
266
|
+
return [
|
|
267
|
+
`User settings · ${safeTerminalText(settingsPath)}`,
|
|
268
|
+
"Plan defaults apply to the next workflow; handoff and export choices apply to their next action.",
|
|
269
|
+
...(notice ? [safeTerminalText(notice)] : []),
|
|
270
|
+
];
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function invalidScreen(settingsPath: string, state: SettingsMenuState) {
|
|
274
|
+
return {
|
|
275
|
+
kind: "detail" as const,
|
|
276
|
+
title: "Plan Mode Settings · Read only",
|
|
277
|
+
lines: [
|
|
278
|
+
`Invalid settings file. Fix ${safeTerminalText(settingsPath)} before saving.`,
|
|
279
|
+
safeTerminalText(state.reason ?? "The settings file is invalid."),
|
|
280
|
+
...(state.notice ? [safeTerminalText(state.notice)] : []),
|
|
281
|
+
],
|
|
282
|
+
hint: "back" as const,
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
function retentionFromLabel(value: string | undefined) {
|
|
287
|
+
return IMPLEMENTATION_PLAN_RETENTIONS.find((retention) => retentionLabel(retention) === value);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
function defaultToolsValue(configured: string[] | undefined) {
|
|
291
|
+
if (configured === undefined) return "Automatic safe built-ins";
|
|
292
|
+
if (configured.length === 0) return "Required tools only";
|
|
293
|
+
return `${configured.length} selected`;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
function defaultToolItems(tools: readonly ToolInfo[], configured: string[] | undefined) {
|
|
297
|
+
const selected = new Set(explicitToolNames(tools, configured));
|
|
298
|
+
const availableNames = new Set(tools.map((tool) => tool.name));
|
|
299
|
+
const items = tools.map((tool) => {
|
|
300
|
+
const selectable = canSelectToolInPlanMode(tool);
|
|
301
|
+
const policy = toolPolicyLabel(tool);
|
|
302
|
+
const description = tool.description ?? "No description available";
|
|
303
|
+
return {
|
|
304
|
+
id: tool.name,
|
|
305
|
+
label: tool.name,
|
|
306
|
+
description: `${policy} · ${description}`,
|
|
307
|
+
searchText: `${policy} ${description}`,
|
|
308
|
+
selected: selected.has(tool.name),
|
|
309
|
+
disabled: !selectable,
|
|
310
|
+
disabledReason: selectable ? undefined : "Blocked by Plan-mode policy",
|
|
311
|
+
};
|
|
312
|
+
});
|
|
313
|
+
for (const name of configured ?? []) {
|
|
314
|
+
if (availableNames.has(name)) continue;
|
|
315
|
+
items.push({
|
|
316
|
+
id: name,
|
|
317
|
+
label: name,
|
|
318
|
+
description: "unavailable · Retained in settings but unavailable in this session",
|
|
319
|
+
searchText: "unavailable retained settings",
|
|
320
|
+
selected: true,
|
|
321
|
+
disabled: true,
|
|
322
|
+
disabledReason: "Unavailable in this session; reset defaults to remove unavailable names",
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
return items;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
function explicitToolNames(tools: readonly ToolInfo[], configured: string[] | undefined) {
|
|
329
|
+
return configured === undefined
|
|
330
|
+
? defaultPlanModeToolNames([...tools], undefined)
|
|
331
|
+
: [...configured];
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
function safeTerminalText(value: string) {
|
|
335
|
+
return [...value]
|
|
336
|
+
.map((character) => {
|
|
337
|
+
const codePoint = character.codePointAt(0) ?? 0;
|
|
338
|
+
return codePoint <= 0x1f || (codePoint >= 0x7f && codePoint <= 0x9f) ? " " : character;
|
|
339
|
+
})
|
|
340
|
+
.join("")
|
|
341
|
+
.trim();
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
function formatError(error: unknown) {
|
|
345
|
+
return error instanceof Error ? error.message : String(error);
|
|
346
|
+
}
|