@narumitw/pi-plan-mode 0.54.0 → 0.55.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/README.md +33 -36
- package/dist/chunks/{chunk-U5CQ7RQX.js → chunk-AS76FCC5.js} +242 -265
- package/dist/chunks/chunk-AS76FCC5.js.map +7 -0
- package/dist/chunks/{interactive-ui-W3VYAJIQ.js → interactive-ui-UCL5UIJN.js} +43 -51
- package/dist/chunks/interactive-ui-UCL5UIJN.js.map +7 -0
- package/dist/index.ts +224 -321
- package/dist/index.ts.map +3 -3
- package/package.json +1 -1
- package/src/plan-launch-menu.ts +13 -5
- package/src/plan-mode.ts +263 -238
- package/src/required-tools.ts +17 -0
- package/src/settings-menu.ts +36 -47
- package/src/settings.ts +0 -19
- package/src/state.ts +30 -0
- package/src/tool-selection.ts +2 -4
- package/dist/chunks/chunk-U5CQ7RQX.js.map +0 -7
- package/dist/chunks/interactive-ui-W3VYAJIQ.js.map +0 -7
- package/src/helper-tool-visibility.ts +0 -142
package/src/required-tools.ts
CHANGED
|
@@ -2,6 +2,23 @@ import { PLAN_MODE_COMPLETE_TOOL_NAME } from "./completion-tool.js";
|
|
|
2
2
|
import { PLAN_MODE_QUESTION_TOOL_NAME } from "./question-tool.js";
|
|
3
3
|
import { unique } from "./tool-selection.js";
|
|
4
4
|
|
|
5
|
+
export const REQUIRED_PLAN_MODE_TOOL_NAMES = [
|
|
6
|
+
PLAN_MODE_QUESTION_TOOL_NAME,
|
|
7
|
+
PLAN_MODE_COMPLETE_TOOL_NAME,
|
|
8
|
+
] as const;
|
|
9
|
+
|
|
10
|
+
export function planModeHelperToolsAvailable(toolNames: readonly string[]) {
|
|
11
|
+
const active = new Set(toolNames);
|
|
12
|
+
return REQUIRED_PLAN_MODE_TOOL_NAMES.every((name) => active.has(name));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function assertPlanModeHelperToolsAvailable(toolNames: readonly string[]) {
|
|
16
|
+
if (planModeHelperToolsAvailable(toolNames)) return;
|
|
17
|
+
throw new Error(
|
|
18
|
+
"plan_mode_question and plan_mode_complete are unavailable; include them in the active tool allowlist or leave the restrictive tool mode before starting Plan mode",
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
5
22
|
export function withRequiredPlanModeTools(toolNames: string[]) {
|
|
6
23
|
return unique([
|
|
7
24
|
...withoutRequiredPlanModeTools(toolNames),
|
package/src/settings-menu.ts
CHANGED
|
@@ -8,11 +8,9 @@ import {
|
|
|
8
8
|
configuredImplementationPlanRetention,
|
|
9
9
|
configuredPlanExportPath,
|
|
10
10
|
configuredPlanModeToggleShortcut,
|
|
11
|
-
configuredPlanModeToolVisibility,
|
|
12
11
|
IMPLEMENTATION_PLAN_RETENTIONS,
|
|
13
12
|
normalizeKeyId,
|
|
14
13
|
PLAN_MODE_THINKING_LEVELS,
|
|
15
|
-
PLAN_MODE_TOOL_VISIBILITIES,
|
|
16
14
|
type PlanModeSettings,
|
|
17
15
|
type PlanModeSettingsLoadResult,
|
|
18
16
|
type PlanModeSettingsPatch,
|
|
@@ -49,7 +47,6 @@ export interface PlanModeSettingsMenuOptions {
|
|
|
49
47
|
type Screen = "settings" | "tools" | "export" | "shortcut";
|
|
50
48
|
type Action =
|
|
51
49
|
| "set-thinking"
|
|
52
|
-
| "set-tool-visibility"
|
|
53
50
|
| "open-tools"
|
|
54
51
|
| "toggle-tool"
|
|
55
52
|
| "reset-tools"
|
|
@@ -73,6 +70,10 @@ export async function showPlanModeSettings(
|
|
|
73
70
|
(tool) =>
|
|
74
71
|
tool.name !== PLAN_MODE_QUESTION_TOOL_NAME && tool.name !== PLAN_MODE_COMPLETE_TOOL_NAME,
|
|
75
72
|
);
|
|
73
|
+
const toolItemIds = new Map(
|
|
74
|
+
tools.map((tool, index) => [tool.name, `plan-settings-tool:${index}`]),
|
|
75
|
+
);
|
|
76
|
+
const toolsByItemId = new Map(tools.map((tool) => [toolItemIds.get(tool.name) as string, tool]));
|
|
76
77
|
|
|
77
78
|
const loadState = async (): Promise<SettingsMenuState> => {
|
|
78
79
|
const loaded = await readSettings(options.settingsPath);
|
|
@@ -114,7 +115,7 @@ export async function showPlanModeSettings(
|
|
|
114
115
|
id: "defaultPlanTools",
|
|
115
116
|
label: "Plan policy tools",
|
|
116
117
|
description:
|
|
117
|
-
"Choose
|
|
118
|
+
"Choose active tools or retain names to resolve before the first request.",
|
|
118
119
|
currentValue: defaultToolsValue(state.settings.defaultPlanTools),
|
|
119
120
|
action: "open-tools",
|
|
120
121
|
},
|
|
@@ -143,17 +144,6 @@ export async function showPlanModeSettings(
|
|
|
143
144
|
currentValue: configuredPlanModeToggleShortcut(state.settings) ?? "none",
|
|
144
145
|
action: "open-shortcut",
|
|
145
146
|
},
|
|
146
|
-
{
|
|
147
|
-
id: "toolVisibility",
|
|
148
|
-
label: "Plan tools",
|
|
149
|
-
description:
|
|
150
|
-
"Keep Plan helper tools visible, or reveal them after the first plan.",
|
|
151
|
-
currentValue: toolVisibilityLabel(
|
|
152
|
-
configuredPlanModeToolVisibility(state.settings),
|
|
153
|
-
),
|
|
154
|
-
values: PLAN_MODE_TOOL_VISIBILITIES.map(toolVisibilityLabel),
|
|
155
|
-
action: "set-tool-visibility",
|
|
156
|
-
},
|
|
157
147
|
],
|
|
158
148
|
},
|
|
159
149
|
tools: ({ state }) => ({
|
|
@@ -161,11 +151,17 @@ export async function showPlanModeSettings(
|
|
|
161
151
|
title: "Default Plan policy allowlist",
|
|
162
152
|
lines: [
|
|
163
153
|
"Changes apply when a later Plan workflow starts; model-visible tools stay unchanged.",
|
|
164
|
-
"
|
|
154
|
+
"Retained inactive names resolve before that workflow's first request.",
|
|
155
|
+
"Plan mode never activates tools, and non-built-ins run at user risk.",
|
|
165
156
|
],
|
|
166
157
|
enableSearch: true,
|
|
167
158
|
viewportSize: 10,
|
|
168
|
-
items: defaultToolItems(
|
|
159
|
+
items: defaultToolItems(
|
|
160
|
+
tools,
|
|
161
|
+
state.settings.defaultPlanTools,
|
|
162
|
+
activeToolNames,
|
|
163
|
+
toolItemIds,
|
|
164
|
+
),
|
|
169
165
|
action: "toggle-tool",
|
|
170
166
|
actions: [
|
|
171
167
|
{
|
|
@@ -220,16 +216,6 @@ export async function showPlanModeSettings(
|
|
|
220
216
|
`Plan mode thinking level: ${value}. Applies to the next Plan workflow.`,
|
|
221
217
|
);
|
|
222
218
|
},
|
|
223
|
-
"set-tool-visibility": async ({ ctx: actionCtx, value, signal }) => {
|
|
224
|
-
const toolVisibility = toolVisibilityFromLabel(value);
|
|
225
|
-
if (!toolVisibility) return { kind: "rejected" };
|
|
226
|
-
return savePatch(
|
|
227
|
-
actionCtx,
|
|
228
|
-
{ toolVisibility },
|
|
229
|
-
signal,
|
|
230
|
-
`Plan tools: ${toolVisibilityLabel(toolVisibility)}.`,
|
|
231
|
-
);
|
|
232
|
-
},
|
|
233
219
|
"open-tools": async () => ({ kind: "to", screen: "tools" }),
|
|
234
220
|
"set-retention": async ({ ctx: actionCtx, value, signal }) => {
|
|
235
221
|
const implementationPlanRetention = retentionFromLabel(value);
|
|
@@ -276,7 +262,7 @@ export async function showPlanModeSettings(
|
|
|
276
262
|
return result.kind === "stay" ? { kind: "to", screen: "settings" } : result;
|
|
277
263
|
},
|
|
278
264
|
"toggle-tool": async ({ ctx: actionCtx, state, itemId, selected, signal }) => {
|
|
279
|
-
const tool =
|
|
265
|
+
const tool = itemId ? toolsByItemId.get(itemId) : undefined;
|
|
280
266
|
if (!tool || !activeToolNames.has(tool.name) || !canSelectToolInPlanMode(tool)) {
|
|
281
267
|
return { kind: "rejected" };
|
|
282
268
|
}
|
|
@@ -363,16 +349,6 @@ function retentionFromLabel(value: string | undefined) {
|
|
|
363
349
|
return IMPLEMENTATION_PLAN_RETENTIONS.find((retention) => retentionLabel(retention) === value);
|
|
364
350
|
}
|
|
365
351
|
|
|
366
|
-
function toolVisibilityLabel(value: PlanModeSettings["toolVisibility"] | "after-first-plan") {
|
|
367
|
-
return value === "always" ? "Always" : "After first plan";
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
function toolVisibilityFromLabel(value: string | undefined) {
|
|
371
|
-
return PLAN_MODE_TOOL_VISIBILITIES.find(
|
|
372
|
-
(visibility) => toolVisibilityLabel(visibility) === value,
|
|
373
|
-
);
|
|
374
|
-
}
|
|
375
|
-
|
|
376
352
|
function defaultToolsValue(configured: string[] | undefined) {
|
|
377
353
|
if (configured === undefined) return "Automatic safe built-ins";
|
|
378
354
|
if (configured.length === 0) return "No optional tools";
|
|
@@ -383,38 +359,46 @@ function defaultToolItems(
|
|
|
383
359
|
tools: readonly ToolInfo[],
|
|
384
360
|
configured: string[] | undefined,
|
|
385
361
|
activeToolNames: ReadonlySet<string>,
|
|
362
|
+
toolItemIds: ReadonlyMap<string, string>,
|
|
386
363
|
) {
|
|
387
364
|
const selected = new Set(explicitToolNames(tools, configured));
|
|
388
365
|
const availableNames = new Set(tools.map((tool) => tool.name));
|
|
389
366
|
const items = tools.map((tool) => {
|
|
390
367
|
const active = activeToolNames.has(tool.name);
|
|
391
368
|
const selectable = active && canSelectToolInPlanMode(tool);
|
|
392
|
-
const policy = active
|
|
369
|
+
const policy = active
|
|
370
|
+
? toolPolicyLabel(tool)
|
|
371
|
+
: selected.has(tool.name)
|
|
372
|
+
? "not active yet; retained for first-request resolution"
|
|
373
|
+
: "not active in this Pi session";
|
|
393
374
|
const description = tool.description ?? "No description available";
|
|
394
375
|
return {
|
|
395
|
-
id: tool.name,
|
|
376
|
+
id: toolItemIds.get(tool.name) as string,
|
|
396
377
|
label: tool.name,
|
|
397
378
|
description: `${policy} · ${description}`,
|
|
398
379
|
searchText: `${policy} ${description}`,
|
|
399
380
|
selected: selected.has(tool.name),
|
|
400
381
|
disabled: !selectable,
|
|
401
382
|
disabledReason: !active
|
|
402
|
-
?
|
|
383
|
+
? selected.has(tool.name)
|
|
384
|
+
? "Not active yet; retained and resolved before the first request"
|
|
385
|
+
: "Not active in Pi; Plan mode will not activate it"
|
|
403
386
|
: selectable
|
|
404
387
|
? undefined
|
|
405
388
|
: "Blocked by Plan-mode policy",
|
|
406
389
|
};
|
|
407
390
|
});
|
|
408
|
-
for (const name of configured ?? []) {
|
|
391
|
+
for (const [index, name] of (configured ?? []).entries()) {
|
|
409
392
|
if (availableNames.has(name)) continue;
|
|
393
|
+
const label = terminalToolName(name);
|
|
410
394
|
items.push({
|
|
411
|
-
id:
|
|
412
|
-
label
|
|
413
|
-
description: "
|
|
414
|
-
searchText:
|
|
395
|
+
id: `plan-settings-pending:${index}`,
|
|
396
|
+
label,
|
|
397
|
+
description: "pending registration · Retained and resolved before the first request",
|
|
398
|
+
searchText: `${label} pending registration retained settings first request`,
|
|
415
399
|
selected: true,
|
|
416
400
|
disabled: true,
|
|
417
|
-
disabledReason: "
|
|
401
|
+
disabledReason: "Not registered yet; reset defaults to remove retained names",
|
|
418
402
|
});
|
|
419
403
|
}
|
|
420
404
|
return items;
|
|
@@ -426,6 +410,11 @@ function explicitToolNames(tools: readonly ToolInfo[], configured: string[] | un
|
|
|
426
410
|
: [...configured];
|
|
427
411
|
}
|
|
428
412
|
|
|
413
|
+
function terminalToolName(value: string) {
|
|
414
|
+
const safe = safeTerminalText(value) || "(unnamed tool)";
|
|
415
|
+
return safe.length > 120 ? `${safe.slice(0, 119)}…` : safe;
|
|
416
|
+
}
|
|
417
|
+
|
|
429
418
|
function safeTerminalText(value: string) {
|
|
430
419
|
return [...value]
|
|
431
420
|
.map((character) => {
|
package/src/settings.ts
CHANGED
|
@@ -30,8 +30,6 @@ export const IMPLEMENTATION_PLAN_RETENTIONS = [
|
|
|
30
30
|
"clear-after-first-run",
|
|
31
31
|
"keep",
|
|
32
32
|
] as const;
|
|
33
|
-
export const PLAN_MODE_TOOL_VISIBILITIES = ["always", "after-first-plan"] as const;
|
|
34
|
-
export const DEFAULT_PLAN_MODE_TOOL_VISIBILITY = "after-first-plan";
|
|
35
33
|
export const DEFAULT_PLAN_EXPORT_PATH = "PLAN.md";
|
|
36
34
|
const MODIFIERS = new Set(["ctrl", "shift", "alt", "super"]);
|
|
37
35
|
const BASE_KEYS = new Set([
|
|
@@ -91,11 +89,9 @@ const MAX_PLAN_EXPORT_PATH_LENGTH = 4096;
|
|
|
91
89
|
|
|
92
90
|
export type PlanModeThinkingLevel = (typeof PLAN_MODE_THINKING_LEVELS)[number];
|
|
93
91
|
export type ImplementationPlanRetention = (typeof IMPLEMENTATION_PLAN_RETENTIONS)[number];
|
|
94
|
-
export type PlanModeToolVisibility = (typeof PLAN_MODE_TOOL_VISIBILITIES)[number];
|
|
95
92
|
export type PlanModeFixedThinkingLevel = Exclude<PlanModeThinkingLevel, "inherit">;
|
|
96
93
|
export interface PlanModeSettings {
|
|
97
94
|
thinkingLevel: PlanModeThinkingLevel;
|
|
98
|
-
toolVisibility?: PlanModeToolVisibility;
|
|
99
95
|
defaultPlanTools?: string[];
|
|
100
96
|
implementationPlanRetention?: ImplementationPlanRetention;
|
|
101
97
|
defaultPlanExportPath?: string;
|
|
@@ -104,7 +100,6 @@ export interface PlanModeSettings {
|
|
|
104
100
|
}
|
|
105
101
|
export interface PlanModeSettingsPatch {
|
|
106
102
|
thinkingLevel?: PlanModeThinkingLevel;
|
|
107
|
-
toolVisibility?: PlanModeToolVisibility;
|
|
108
103
|
defaultPlanTools?: readonly string[] | null;
|
|
109
104
|
implementationPlanRetention?: ImplementationPlanRetention;
|
|
110
105
|
defaultPlanExportPath?: string | null;
|
|
@@ -148,13 +143,6 @@ export function normalizePlanModeSettings(value: unknown): PlanModeSettings | un
|
|
|
148
143
|
const settings: PlanModeSettings = {
|
|
149
144
|
thinkingLevel: thinkingLevel as PlanModeThinkingLevel,
|
|
150
145
|
};
|
|
151
|
-
if (Object.hasOwn(value, "toolVisibility")) {
|
|
152
|
-
const toolVisibility = Reflect.get(value, "toolVisibility");
|
|
153
|
-
if (!PLAN_MODE_TOOL_VISIBILITIES.includes(toolVisibility as PlanModeToolVisibility)) {
|
|
154
|
-
return undefined;
|
|
155
|
-
}
|
|
156
|
-
settings.toolVisibility = toolVisibility as PlanModeToolVisibility;
|
|
157
|
-
}
|
|
158
146
|
if (Object.hasOwn(value, "defaultPlanTools")) {
|
|
159
147
|
const defaultPlanTools = normalizeToolNames(Reflect.get(value, "defaultPlanTools"));
|
|
160
148
|
if (!defaultPlanTools) return undefined;
|
|
@@ -311,7 +299,6 @@ export function updatePlanModeSettings(
|
|
|
311
299
|
const current = await readSettingsDocumentForUpdate(settingsPath, legacySettingsPath);
|
|
312
300
|
const updated: SettingsDocument = { ...current };
|
|
313
301
|
if (patch.thinkingLevel !== undefined) updated.thinkingLevel = patch.thinkingLevel;
|
|
314
|
-
if (patch.toolVisibility !== undefined) updated.toolVisibility = patch.toolVisibility;
|
|
315
302
|
if (patch.defaultPlanTools === null) delete updated.defaultPlanTools;
|
|
316
303
|
else if (patch.defaultPlanTools !== undefined) {
|
|
317
304
|
updated.defaultPlanTools = [...patch.defaultPlanTools];
|
|
@@ -495,12 +482,6 @@ export function configuredThinkingLevel(
|
|
|
495
482
|
return settings.thinkingLevel === "inherit" ? undefined : settings.thinkingLevel;
|
|
496
483
|
}
|
|
497
484
|
|
|
498
|
-
export function configuredPlanModeToolVisibility(
|
|
499
|
-
settings: PlanModeSettings,
|
|
500
|
-
): PlanModeToolVisibility {
|
|
501
|
-
return settings.toolVisibility ?? DEFAULT_PLAN_MODE_TOOL_VISIBILITY;
|
|
502
|
-
}
|
|
503
|
-
|
|
504
485
|
export function configuredImplementationPlanRetention(
|
|
505
486
|
settings: PlanModeSettings,
|
|
506
487
|
): ImplementationPlanRetention {
|
package/src/state.ts
CHANGED
|
@@ -25,6 +25,13 @@ export interface SavedPlan {
|
|
|
25
25
|
source: PlanCompletionSource;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
+
export interface PlanModeWorkflowToolPolicy {
|
|
29
|
+
kind: "automatic" | "explicit";
|
|
30
|
+
desiredNames?: string[];
|
|
31
|
+
allowedNames: string[];
|
|
32
|
+
resolved: boolean;
|
|
33
|
+
}
|
|
34
|
+
|
|
28
35
|
export interface PlanModeState {
|
|
29
36
|
enabled: boolean;
|
|
30
37
|
latestPlan?: string;
|
|
@@ -34,6 +41,7 @@ export interface PlanModeState {
|
|
|
34
41
|
activeImplementation?: ActiveImplementationPlan;
|
|
35
42
|
selectedToolNames?: string[];
|
|
36
43
|
selectedToolKeys?: string[];
|
|
44
|
+
workflowToolPolicy?: PlanModeWorkflowToolPolicy;
|
|
37
45
|
previousThinkingLevel?: PlanModeFixedThinkingLevel;
|
|
38
46
|
appliedThinkingLevel?: PlanModeFixedThinkingLevel;
|
|
39
47
|
manualThinkingLevel?: PlanModeFixedThinkingLevel;
|
|
@@ -86,6 +94,9 @@ export function restorePlanModeState(entries: unknown[], stateEntryType: string)
|
|
|
86
94
|
activeImplementation,
|
|
87
95
|
selectedToolNames: stringArray(entry.data.selectedToolNames),
|
|
88
96
|
selectedToolKeys: stringArray(entry.data.selectedToolKeys),
|
|
97
|
+
workflowToolPolicy: enabled
|
|
98
|
+
? normalizeWorkflowToolPolicy(entry.data.workflowToolPolicy)
|
|
99
|
+
: undefined,
|
|
89
100
|
previousThinkingLevel: enabled
|
|
90
101
|
? fixedThinkingLevel(entry.data.previousThinkingLevel)
|
|
91
102
|
: undefined,
|
|
@@ -94,6 +105,25 @@ export function restorePlanModeState(entries: unknown[], stateEntryType: string)
|
|
|
94
105
|
};
|
|
95
106
|
}
|
|
96
107
|
|
|
108
|
+
function normalizeWorkflowToolPolicy(value: unknown): PlanModeWorkflowToolPolicy | undefined {
|
|
109
|
+
if (value === undefined) return undefined;
|
|
110
|
+
const denied: PlanModeWorkflowToolPolicy = {
|
|
111
|
+
kind: "automatic",
|
|
112
|
+
allowedNames: [],
|
|
113
|
+
resolved: true,
|
|
114
|
+
};
|
|
115
|
+
if (!isRecord(value)) return denied;
|
|
116
|
+
const kind = value.kind === "automatic" || value.kind === "explicit" ? value.kind : undefined;
|
|
117
|
+
const allowedNames = stringArray(value.allowedNames);
|
|
118
|
+
if (!kind || !allowedNames || typeof value.resolved !== "boolean") return denied;
|
|
119
|
+
if (kind === "automatic") {
|
|
120
|
+
return { kind, allowedNames, resolved: value.resolved };
|
|
121
|
+
}
|
|
122
|
+
const desiredNames = stringArray(value.desiredNames);
|
|
123
|
+
if (!desiredNames) return denied;
|
|
124
|
+
return { kind, desiredNames, allowedNames, resolved: value.resolved };
|
|
125
|
+
}
|
|
126
|
+
|
|
97
127
|
function normalizeSavedPlan(value: unknown): SavedPlan | undefined {
|
|
98
128
|
if (!isRecord(value)) return undefined;
|
|
99
129
|
const source = planCompletionSource(value.source);
|
package/src/tool-selection.ts
CHANGED
|
@@ -44,9 +44,7 @@ export function filterAvailableSelectedToolNames(names: string[], tools: ToolInf
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
export function defaultPlanModeToolNames(tools: ToolInfo[], configuredNames: string[] | undefined) {
|
|
47
|
-
if (configuredNames !== undefined)
|
|
48
|
-
return filterAvailableSelectedToolNames(configuredNames, tools);
|
|
49
|
-
}
|
|
47
|
+
if (configuredNames !== undefined) return unique(configuredNames);
|
|
50
48
|
return tools
|
|
51
49
|
.filter((tool) => isBuiltinTool(tool) && SAFE_BUILTIN_PLAN_TOOLS.has(tool.name))
|
|
52
50
|
.map((tool) => tool.name);
|
|
@@ -70,6 +68,6 @@ export function snapshotPlanModeSelectedNames(
|
|
|
70
68
|
return new Set(
|
|
71
69
|
selectedToolNames === undefined
|
|
72
70
|
? defaultPlanModeToolNames(tools, selection.defaultPlanTools)
|
|
73
|
-
:
|
|
71
|
+
: unique(selectedToolNames),
|
|
74
72
|
);
|
|
75
73
|
}
|