@narumitw/pi-plan-mode 0.54.0 → 0.55.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 +17 -27
- package/dist/chunks/{chunk-U5CQ7RQX.js → chunk-KSGLZ4S2.js} +240 -255
- package/dist/chunks/chunk-KSGLZ4S2.js.map +7 -0
- package/dist/chunks/{interactive-ui-W3VYAJIQ.js → interactive-ui-PSDKEVVG.js} +2 -32
- package/dist/chunks/interactive-ui-PSDKEVVG.js.map +7 -0
- package/dist/index.ts +39 -283
- package/dist/index.ts.map +3 -3
- package/package.json +1 -1
- package/src/plan-mode.ts +28 -203
- package/src/required-tools.ts +17 -0
- package/src/settings-menu.ts +0 -34
- package/src/settings.ts +0 -19
- 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/package.json
CHANGED
package/src/plan-mode.ts
CHANGED
|
@@ -27,10 +27,6 @@ import {
|
|
|
27
27
|
formatTransferredPlanPrompt,
|
|
28
28
|
startFreshImplementationFromState,
|
|
29
29
|
} from "./fresh-implementation.js";
|
|
30
|
-
import {
|
|
31
|
-
PlanModeHelperVisibilityPolicy,
|
|
32
|
-
type PlanModeHelperVisibilitySnapshot,
|
|
33
|
-
} from "./helper-tool-visibility.js";
|
|
34
30
|
import {
|
|
35
31
|
createImplementationRetentionCoordinator,
|
|
36
32
|
implementationRetentionPreview,
|
|
@@ -65,7 +61,11 @@ import {
|
|
|
65
61
|
PLAN_MODE_QUESTION_TOOL_NAME,
|
|
66
62
|
planModeQuestionCancelled,
|
|
67
63
|
} from "./question-tool.js";
|
|
68
|
-
import {
|
|
64
|
+
import {
|
|
65
|
+
assertPlanModeHelperToolsAvailable,
|
|
66
|
+
planModeHelperToolsAvailable,
|
|
67
|
+
withRequiredPlanModeTools,
|
|
68
|
+
} from "./required-tools.js";
|
|
69
69
|
import {
|
|
70
70
|
preflightSavedPlanImplementation,
|
|
71
71
|
savedPlanBlocksNewWorkflow,
|
|
@@ -74,11 +74,9 @@ import {
|
|
|
74
74
|
awaitPlanModeSettingsWrites,
|
|
75
75
|
configuredImplementationPlanRetention,
|
|
76
76
|
configuredPlanModeToggleShortcut,
|
|
77
|
-
configuredPlanModeToolVisibility,
|
|
78
77
|
configuredThinkingLevel,
|
|
79
78
|
type PlanModeSettings,
|
|
80
79
|
type PlanModeSettingsPatch,
|
|
81
|
-
type PlanModeToolVisibility,
|
|
82
80
|
planModeSettingsPath,
|
|
83
81
|
readPlanModeSettings,
|
|
84
82
|
type UpdatePlanModeSettingsOptions,
|
|
@@ -125,7 +123,6 @@ interface PlanModeDependencies {
|
|
|
125
123
|
// activation path cannot bypass the same atomic transition by crossing module-owned state.
|
|
126
124
|
export default function planMode(pi: ExtensionAPI, dependencies: PlanModeDependencies = {}) {
|
|
127
125
|
const workflowMutex = new WorkflowMutex(pi);
|
|
128
|
-
const helperVisibility = new PlanModeHelperVisibilityPolicy(pi);
|
|
129
126
|
let workflowOwner: WorkflowMutexOwner | undefined;
|
|
130
127
|
let currentSession: object | undefined;
|
|
131
128
|
let currentSessionContext: ExtensionContext | undefined;
|
|
@@ -197,11 +194,7 @@ export default function planMode(pi: ExtensionAPI, dependencies: PlanModeDepende
|
|
|
197
194
|
name: PLAN_MODE_QUESTION_TOOL_NAME,
|
|
198
195
|
label: "Plan question",
|
|
199
196
|
description:
|
|
200
|
-
"Ask
|
|
201
|
-
promptSnippet: "Ask user decision questions while Plan mode is active",
|
|
202
|
-
promptGuidelines: [
|
|
203
|
-
"In Plan mode, use plan_mode_question for important preferences, tradeoffs, or assumptions that cannot be discovered from read-only exploration.",
|
|
204
|
-
],
|
|
197
|
+
"Ask one to three structured questions only when the latest effective Plan contract explicitly says /plan mode is active. Tool visibility alone does not activate Plan mode. Never call for ordinary planning requests, the writing-plans skill, roadmaps, checklists, or plan-file work.",
|
|
205
198
|
parameters: PLAN_MODE_QUESTION_PARAMS,
|
|
206
199
|
async execute(_toolCallId, params: unknown, _signal, _onUpdate, ctx) {
|
|
207
200
|
if (!state.enabled || !workflowMutex.isOwner(workflowOwner)) {
|
|
@@ -243,11 +236,7 @@ export default function planMode(pi: ExtensionAPI, dependencies: PlanModeDepende
|
|
|
243
236
|
name: PLAN_MODE_COMPLETE_TOOL_NAME,
|
|
244
237
|
label: "Complete plan",
|
|
245
238
|
description:
|
|
246
|
-
"Submit
|
|
247
|
-
promptSnippet: "Submit the final Plan-mode implementation plan",
|
|
248
|
-
promptGuidelines: [
|
|
249
|
-
"Call plan_mode_complete alone as the final action only after the implementation plan is decision-complete.",
|
|
250
|
-
],
|
|
239
|
+
"Submit a decision-ready plan only when the latest effective Plan contract explicitly says /plan mode is active, and call it alone as the final action. Tool visibility alone does not activate Plan mode. Never call for ordinary planning requests, the writing-plans skill, roadmaps, checklists, or plan-file work.",
|
|
251
240
|
parameters: PLAN_MODE_COMPLETE_PARAMS,
|
|
252
241
|
renderResult: renderPlanModeCompletion,
|
|
253
242
|
async execute(_toolCallId, params: unknown, _signal, _onUpdate, ctx) {
|
|
@@ -388,21 +377,15 @@ export default function planMode(pi: ExtensionAPI, dependencies: PlanModeDepende
|
|
|
388
377
|
generation: number,
|
|
389
378
|
ctx: ExtensionContext | undefined,
|
|
390
379
|
showWarnings: boolean,
|
|
391
|
-
applyWatchedVisibility = false,
|
|
392
380
|
) => {
|
|
393
381
|
const loadedSettings = await readPlanModeRuntimeSettings();
|
|
394
382
|
if (generation !== menuGeneration || menuController.signal.aborted) {
|
|
395
383
|
return undefined;
|
|
396
384
|
}
|
|
397
|
-
|
|
398
|
-
const nextSettings =
|
|
385
|
+
settings =
|
|
399
386
|
loadedSettings.kind === "loaded"
|
|
400
387
|
? loadedSettings.settings
|
|
401
388
|
: ({ thinkingLevel: "inherit" } satisfies PlanModeSettings);
|
|
402
|
-
if (applyWatchedVisibility && ctx) {
|
|
403
|
-
applyWatchedHelperVisibility(previousSettings, nextSettings, ctx);
|
|
404
|
-
}
|
|
405
|
-
settings = nextSettings;
|
|
406
389
|
applyPlanModeShortcut(configuredPlanModeToggleShortcut(settings));
|
|
407
390
|
if (!ctx || !showWarnings) return loadedSettings;
|
|
408
391
|
if (loadedSettings.kind === "invalid") {
|
|
@@ -430,7 +413,7 @@ export default function planMode(pi: ExtensionAPI, dependencies: PlanModeDepende
|
|
|
430
413
|
}
|
|
431
414
|
settingsReloadTimer = setTimeout(() => {
|
|
432
415
|
settingsReloadTimer = undefined;
|
|
433
|
-
void applyPlanModeSettings(generation, currentSessionContext, false
|
|
416
|
+
void applyPlanModeSettings(generation, currentSessionContext, false);
|
|
434
417
|
}, 75);
|
|
435
418
|
};
|
|
436
419
|
|
|
@@ -457,7 +440,6 @@ export default function planMode(pi: ExtensionAPI, dependencies: PlanModeDepende
|
|
|
457
440
|
|
|
458
441
|
pi.on("session_start", async (event, ctx) => {
|
|
459
442
|
const generation = ++menuGeneration;
|
|
460
|
-
const previousToolVisibility = configuredPlanModeToolVisibility(settings);
|
|
461
443
|
finalizationRequest.reset();
|
|
462
444
|
currentSession = ctx.sessionManager;
|
|
463
445
|
currentSessionContext = ctx;
|
|
@@ -479,12 +461,7 @@ export default function planMode(pi: ExtensionAPI, dependencies: PlanModeDepende
|
|
|
479
461
|
await applyPlanModeSettings(generation, ctx, true);
|
|
480
462
|
if (generation !== menuGeneration || menuController.signal.aborted) return;
|
|
481
463
|
startPlanModeSettingsWatch(generation);
|
|
482
|
-
if (restoredState
|
|
483
|
-
if (!installRestoredState(restoredState, ctx, previousToolVisibility)) return;
|
|
484
|
-
} else {
|
|
485
|
-
reconcileInactiveHelperVisibility(previousToolVisibility, ctx);
|
|
486
|
-
if (!installRestoredState(restoredState, ctx)) return;
|
|
487
|
-
}
|
|
464
|
+
if (!installRestoredState(restoredState, ctx)) return;
|
|
488
465
|
implementationRetention.restore(state.activeImplementation);
|
|
489
466
|
updateUi(ctx);
|
|
490
467
|
});
|
|
@@ -750,16 +727,13 @@ export default function planMode(pi: ExtensionAPI, dependencies: PlanModeDepende
|
|
|
750
727
|
workflowOwner = owner;
|
|
751
728
|
|
|
752
729
|
const previousState = state;
|
|
753
|
-
const previousHelperVisibility = helperVisibility.snapshot();
|
|
754
730
|
try {
|
|
755
|
-
|
|
731
|
+
assertPlanModeHelperToolsAvailable(safeGetActiveTools());
|
|
756
732
|
if (!publishModeContract("plan", ctx)) {
|
|
757
|
-
helperVisibility.restore(previousHelperVisibility);
|
|
758
733
|
releaseWorkflowOwner();
|
|
759
734
|
return false;
|
|
760
735
|
}
|
|
761
736
|
} catch (error: unknown) {
|
|
762
|
-
helperVisibility.restore(previousHelperVisibility);
|
|
763
737
|
releaseWorkflowOwner();
|
|
764
738
|
return reportHelperActivationFailure(ctx, error);
|
|
765
739
|
}
|
|
@@ -781,7 +755,7 @@ export default function planMode(pi: ExtensionAPI, dependencies: PlanModeDepende
|
|
|
781
755
|
updateUi(ctx);
|
|
782
756
|
return true;
|
|
783
757
|
} catch (error: unknown) {
|
|
784
|
-
rollbackNewActivation(previousState, ctx
|
|
758
|
+
rollbackNewActivation(previousState, ctx);
|
|
785
759
|
throw error;
|
|
786
760
|
}
|
|
787
761
|
}
|
|
@@ -789,7 +763,6 @@ export default function planMode(pi: ExtensionAPI, dependencies: PlanModeDepende
|
|
|
789
763
|
function enterPlanModeWithPrompt(prompt: string, ctx: ExtensionContext) {
|
|
790
764
|
const previousState = state;
|
|
791
765
|
const previousOwner = workflowOwner;
|
|
792
|
-
const previousHelperVisibility = helperVisibility.snapshot();
|
|
793
766
|
const wasEnabled = state.enabled;
|
|
794
767
|
if (!enterPlanMode(ctx)) return;
|
|
795
768
|
if (!wasEnabled) {
|
|
@@ -797,7 +770,7 @@ export default function planMode(pi: ExtensionAPI, dependencies: PlanModeDepende
|
|
|
797
770
|
}
|
|
798
771
|
if (sendPlanModeUserMessage(prompt, ctx)) return;
|
|
799
772
|
if (wasEnabled) return;
|
|
800
|
-
rollbackNewActivation(previousState, ctx, previousOwner
|
|
773
|
+
rollbackNewActivation(previousState, ctx, previousOwner);
|
|
801
774
|
}
|
|
802
775
|
|
|
803
776
|
function exitPlanMode(ctx: ExtensionContext) {
|
|
@@ -1097,9 +1070,9 @@ export default function planMode(pi: ExtensionAPI, dependencies: PlanModeDepende
|
|
|
1097
1070
|
if (!lifecycle.isCurrent() || lifecycle.signal.aborted) return;
|
|
1098
1071
|
const tools = selectableTools();
|
|
1099
1072
|
await ui.showPlanLaunchMenu(ctx, {
|
|
1100
|
-
statusText:
|
|
1101
|
-
? "Status: Off — Plan
|
|
1102
|
-
: "Status: Off — Plan
|
|
1073
|
+
statusText: planModeHelperToolsAvailable(safeGetActiveTools())
|
|
1074
|
+
? "Status: Off — visible Plan helpers stay inactive until /plan starts."
|
|
1075
|
+
: "Status: Off — required Plan helpers are unavailable under the active tool policy.",
|
|
1103
1076
|
initialScreen,
|
|
1104
1077
|
getSelectedNames: () => snapshotPlanModeSelectedNames(tools, toolSelectionSnapshot()),
|
|
1105
1078
|
toolSummary: (selectedNames) => {
|
|
@@ -1196,7 +1169,7 @@ export default function planMode(pi: ExtensionAPI, dependencies: PlanModeDepende
|
|
|
1196
1169
|
signal,
|
|
1197
1170
|
isCurrent,
|
|
1198
1171
|
settingsPath: dependencies.settingsPath,
|
|
1199
|
-
updateSettings:
|
|
1172
|
+
updateSettings: dependencies.updateSettings ?? updatePlanModeSettings,
|
|
1200
1173
|
onSaved: (saved) => {
|
|
1201
1174
|
if (!isCurrent()) return;
|
|
1202
1175
|
settings = saved;
|
|
@@ -1209,63 +1182,6 @@ export default function planMode(pi: ExtensionAPI, dependencies: PlanModeDepende
|
|
|
1209
1182
|
return result.kind === "closed" && "reason" in result && result.reason === "close";
|
|
1210
1183
|
}
|
|
1211
1184
|
|
|
1212
|
-
async function updateSettingsWithRuntime(
|
|
1213
|
-
patch: PlanModeSettingsPatch,
|
|
1214
|
-
options: UpdatePlanModeSettingsOptions | undefined,
|
|
1215
|
-
ctx: ExtensionContext,
|
|
1216
|
-
isCurrent: () => boolean,
|
|
1217
|
-
) {
|
|
1218
|
-
const previousVisibility = configuredPlanModeToolVisibility(settings);
|
|
1219
|
-
const nextVisibility = patch.toolVisibility ?? previousVisibility;
|
|
1220
|
-
const persistSettings = dependencies.updateSettings ?? updatePlanModeSettings;
|
|
1221
|
-
if (nextVisibility === previousVisibility) {
|
|
1222
|
-
return persistSettings(patch, options);
|
|
1223
|
-
}
|
|
1224
|
-
if (!ctx.isIdle()) {
|
|
1225
|
-
throw new Error("Wait for Pi to become idle before changing Plan tool visibility.");
|
|
1226
|
-
}
|
|
1227
|
-
bindWorkflowSessionIfNeeded(ctx);
|
|
1228
|
-
const applicationSession = ctx.sessionManager;
|
|
1229
|
-
const applicationGeneration = menuGeneration;
|
|
1230
|
-
const applicationIsCurrent = () =>
|
|
1231
|
-
currentSession === applicationSession &&
|
|
1232
|
-
menuGeneration === applicationGeneration &&
|
|
1233
|
-
isCurrent();
|
|
1234
|
-
const retainedOwner = workflowMutex.isOwner(workflowOwner);
|
|
1235
|
-
const temporaryOwner = retainedOwner ? workflowOwner : workflowMutex.acquire();
|
|
1236
|
-
if (!temporaryOwner) {
|
|
1237
|
-
throw new Error(
|
|
1238
|
-
"Another workflow is active in this session. Plan tool visibility was not changed.",
|
|
1239
|
-
);
|
|
1240
|
-
}
|
|
1241
|
-
const visibilitySnapshot = helperVisibility.snapshot();
|
|
1242
|
-
try {
|
|
1243
|
-
helperVisibility.applyVisibilityChange(previousVisibility, nextVisibility, ctx);
|
|
1244
|
-
const saved = await persistSettings(patch, options);
|
|
1245
|
-
if (!applicationIsCurrent()) {
|
|
1246
|
-
throw new DOMException("Plan settings session replaced", "AbortError");
|
|
1247
|
-
}
|
|
1248
|
-
settings = saved;
|
|
1249
|
-
applyPlanModeShortcut(configuredPlanModeToggleShortcut(saved));
|
|
1250
|
-
return saved;
|
|
1251
|
-
} catch (error) {
|
|
1252
|
-
if (applicationIsCurrent()) {
|
|
1253
|
-
try {
|
|
1254
|
-
helperVisibility.restore(visibilitySnapshot);
|
|
1255
|
-
} catch (rollbackError) {
|
|
1256
|
-
throw new AggregateError(
|
|
1257
|
-
[error, rollbackError],
|
|
1258
|
-
"Plan tool visibility settings failed and runtime rollback was incomplete.",
|
|
1259
|
-
);
|
|
1260
|
-
}
|
|
1261
|
-
}
|
|
1262
|
-
throw error;
|
|
1263
|
-
} finally {
|
|
1264
|
-
if (!retainedOwner) workflowMutex.release(temporaryOwner);
|
|
1265
|
-
if (!isCurrent()) latestCommandContext = undefined;
|
|
1266
|
-
}
|
|
1267
|
-
}
|
|
1268
|
-
|
|
1269
1185
|
function allowModeTransition(ctx: ExtensionContext, action: string) {
|
|
1270
1186
|
if (ctx.isIdle()) return true;
|
|
1271
1187
|
const message = `Cannot ${action} while an agent run is active. Wait for the run to settle, then retry.`;
|
|
@@ -1305,82 +1221,6 @@ export default function planMode(pi: ExtensionAPI, dependencies: PlanModeDepende
|
|
|
1305
1221
|
activeToolBaseline = withRequiredPlanModeTools(safeGetActiveTools());
|
|
1306
1222
|
}
|
|
1307
1223
|
|
|
1308
|
-
function applyWatchedHelperVisibility(
|
|
1309
|
-
previousSettings: PlanModeSettings,
|
|
1310
|
-
nextSettings: PlanModeSettings,
|
|
1311
|
-
ctx: ExtensionContext,
|
|
1312
|
-
) {
|
|
1313
|
-
const previousVisibility = configuredPlanModeToolVisibility(previousSettings);
|
|
1314
|
-
const nextVisibility = configuredPlanModeToolVisibility(nextSettings);
|
|
1315
|
-
if (previousVisibility === nextVisibility) return;
|
|
1316
|
-
if (state.enabled) {
|
|
1317
|
-
helperVisibility.deferVisibilityChange(nextVisibility);
|
|
1318
|
-
return;
|
|
1319
|
-
}
|
|
1320
|
-
try {
|
|
1321
|
-
if (!ctx.isIdle()) {
|
|
1322
|
-
helperVisibility.deferVisibilityChange(nextVisibility);
|
|
1323
|
-
return;
|
|
1324
|
-
}
|
|
1325
|
-
} catch {
|
|
1326
|
-
helperVisibility.deferVisibilityChange(nextVisibility);
|
|
1327
|
-
return;
|
|
1328
|
-
}
|
|
1329
|
-
const owner = workflowMutex.acquire();
|
|
1330
|
-
if (!owner) {
|
|
1331
|
-
helperVisibility.deferVisibilityChange(nextVisibility);
|
|
1332
|
-
return;
|
|
1333
|
-
}
|
|
1334
|
-
const snapshot = helperVisibility.snapshot();
|
|
1335
|
-
try {
|
|
1336
|
-
helperVisibility.applyVisibilityChange(previousVisibility, nextVisibility, ctx);
|
|
1337
|
-
} catch (error: unknown) {
|
|
1338
|
-
helperVisibility.restore(snapshot);
|
|
1339
|
-
helperVisibility.deferVisibilityChange(nextVisibility);
|
|
1340
|
-
if (ctx.hasUI) {
|
|
1341
|
-
const detail = safeTerminalText(error instanceof Error ? error.message : String(error));
|
|
1342
|
-
ctx.ui.notify(
|
|
1343
|
-
`Could not apply reloaded Plan tool visibility; the current tool envelope remains unchanged until a later safe boundary: ${detail}`,
|
|
1344
|
-
"warning",
|
|
1345
|
-
);
|
|
1346
|
-
}
|
|
1347
|
-
} finally {
|
|
1348
|
-
workflowMutex.release(owner);
|
|
1349
|
-
}
|
|
1350
|
-
}
|
|
1351
|
-
|
|
1352
|
-
function reconcileInactiveHelperVisibility(
|
|
1353
|
-
previousVisibility: PlanModeToolVisibility,
|
|
1354
|
-
ctx: ExtensionContext,
|
|
1355
|
-
) {
|
|
1356
|
-
const owner = workflowMutex.acquire();
|
|
1357
|
-
if (!owner) {
|
|
1358
|
-
if (ctx.hasUI) {
|
|
1359
|
-
ctx.ui.notify(
|
|
1360
|
-
"Plan tool visibility was deferred because another workflow is active in this session.",
|
|
1361
|
-
"warning",
|
|
1362
|
-
);
|
|
1363
|
-
}
|
|
1364
|
-
return false;
|
|
1365
|
-
}
|
|
1366
|
-
const snapshot = helperVisibility.snapshot();
|
|
1367
|
-
try {
|
|
1368
|
-
const visibility = configuredPlanModeToolVisibility(settings);
|
|
1369
|
-
helperVisibility.prepareSessionStart(visibility, previousVisibility);
|
|
1370
|
-
helperVisibility.reconcileInactiveState(visibility);
|
|
1371
|
-
return true;
|
|
1372
|
-
} catch (error: unknown) {
|
|
1373
|
-
helperVisibility.restore(snapshot);
|
|
1374
|
-
if (ctx.hasUI) {
|
|
1375
|
-
const detail = safeTerminalText(error instanceof Error ? error.message : String(error));
|
|
1376
|
-
ctx.ui.notify(`Could not apply Plan tool visibility: ${detail}`, "error");
|
|
1377
|
-
}
|
|
1378
|
-
return false;
|
|
1379
|
-
} finally {
|
|
1380
|
-
workflowMutex.release(owner);
|
|
1381
|
-
}
|
|
1382
|
-
}
|
|
1383
|
-
|
|
1384
1224
|
function planModePolicyToolNames() {
|
|
1385
1225
|
return workflowAllowedToolNames ?? computePlanModePolicyToolNames();
|
|
1386
1226
|
}
|
|
@@ -1482,15 +1322,10 @@ export default function planMode(pi: ExtensionAPI, dependencies: PlanModeDepende
|
|
|
1482
1322
|
}
|
|
1483
1323
|
}
|
|
1484
1324
|
|
|
1485
|
-
function installRestoredState(
|
|
1486
|
-
candidate: PlanModeState,
|
|
1487
|
-
ctx: ExtensionContext,
|
|
1488
|
-
previousToolVisibility?: PlanModeToolVisibility,
|
|
1489
|
-
) {
|
|
1325
|
+
function installRestoredState(candidate: PlanModeState, ctx: ExtensionContext) {
|
|
1490
1326
|
const previousState = state;
|
|
1491
1327
|
const previousWorkflowAllowedToolNames = workflowAllowedToolNames;
|
|
1492
1328
|
const previousOwner = workflowOwner;
|
|
1493
|
-
const previousHelperVisibility = helperVisibility.snapshot();
|
|
1494
1329
|
const wasEnabled = state.enabled;
|
|
1495
1330
|
if (candidate.enabled && !workflowMutex.isOwner(workflowOwner)) {
|
|
1496
1331
|
const owner = workflowMutex.acquire();
|
|
@@ -1505,24 +1340,17 @@ export default function planMode(pi: ExtensionAPI, dependencies: PlanModeDepende
|
|
|
1505
1340
|
|
|
1506
1341
|
try {
|
|
1507
1342
|
if (candidate.enabled) {
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
helperVisibility.restore(previousHelperVisibility);
|
|
1517
|
-
state = { enabled: false, awaitingAction: false };
|
|
1518
|
-
workflowAllowedToolNames = undefined;
|
|
1519
|
-
if (workflowOwner !== previousOwner) {
|
|
1520
|
-
workflowMutex.release(workflowOwner);
|
|
1521
|
-
workflowOwner = previousOwner;
|
|
1522
|
-
}
|
|
1523
|
-
reportRestoredHelpersUnavailable(ctx);
|
|
1524
|
-
return false;
|
|
1343
|
+
try {
|
|
1344
|
+
assertPlanModeHelperToolsAvailable(safeGetActiveTools());
|
|
1345
|
+
} catch {
|
|
1346
|
+
state = { enabled: false, awaitingAction: false };
|
|
1347
|
+
workflowAllowedToolNames = undefined;
|
|
1348
|
+
if (workflowOwner !== previousOwner) {
|
|
1349
|
+
workflowMutex.release(workflowOwner);
|
|
1350
|
+
workflowOwner = previousOwner;
|
|
1525
1351
|
}
|
|
1352
|
+
reportRestoredHelpersUnavailable(ctx);
|
|
1353
|
+
return false;
|
|
1526
1354
|
}
|
|
1527
1355
|
}
|
|
1528
1356
|
if (wasEnabled && !candidate.enabled) {
|
|
@@ -1540,7 +1368,6 @@ export default function planMode(pi: ExtensionAPI, dependencies: PlanModeDepende
|
|
|
1540
1368
|
} finally {
|
|
1541
1369
|
state = previousState;
|
|
1542
1370
|
workflowAllowedToolNames = previousWorkflowAllowedToolNames;
|
|
1543
|
-
helperVisibility.restore(previousHelperVisibility);
|
|
1544
1371
|
if (workflowOwner !== previousOwner) {
|
|
1545
1372
|
workflowMutex.release(workflowOwner);
|
|
1546
1373
|
workflowOwner = previousOwner;
|
|
@@ -1554,7 +1381,6 @@ export default function planMode(pi: ExtensionAPI, dependencies: PlanModeDepende
|
|
|
1554
1381
|
previousState: PlanModeState,
|
|
1555
1382
|
ctx: ExtensionContext,
|
|
1556
1383
|
previousOwner?: WorkflowMutexOwner,
|
|
1557
|
-
previousHelperVisibility?: PlanModeHelperVisibilitySnapshot,
|
|
1558
1384
|
) {
|
|
1559
1385
|
const activatedOwner = workflowOwner;
|
|
1560
1386
|
readyPresentationIntent = undefined;
|
|
@@ -1567,7 +1393,6 @@ export default function planMode(pi: ExtensionAPI, dependencies: PlanModeDepende
|
|
|
1567
1393
|
state = previousState;
|
|
1568
1394
|
workflowAllowedToolNames = undefined;
|
|
1569
1395
|
try {
|
|
1570
|
-
if (previousHelperVisibility) helperVisibility.restore(previousHelperVisibility);
|
|
1571
1396
|
persistState();
|
|
1572
1397
|
updateUi(ctx);
|
|
1573
1398
|
} finally {
|
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"
|
|
@@ -143,17 +140,6 @@ export async function showPlanModeSettings(
|
|
|
143
140
|
currentValue: configuredPlanModeToggleShortcut(state.settings) ?? "none",
|
|
144
141
|
action: "open-shortcut",
|
|
145
142
|
},
|
|
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
143
|
],
|
|
158
144
|
},
|
|
159
145
|
tools: ({ state }) => ({
|
|
@@ -220,16 +206,6 @@ export async function showPlanModeSettings(
|
|
|
220
206
|
`Plan mode thinking level: ${value}. Applies to the next Plan workflow.`,
|
|
221
207
|
);
|
|
222
208
|
},
|
|
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
209
|
"open-tools": async () => ({ kind: "to", screen: "tools" }),
|
|
234
210
|
"set-retention": async ({ ctx: actionCtx, value, signal }) => {
|
|
235
211
|
const implementationPlanRetention = retentionFromLabel(value);
|
|
@@ -363,16 +339,6 @@ function retentionFromLabel(value: string | undefined) {
|
|
|
363
339
|
return IMPLEMENTATION_PLAN_RETENTIONS.find((retention) => retentionLabel(retention) === value);
|
|
364
340
|
}
|
|
365
341
|
|
|
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
342
|
function defaultToolsValue(configured: string[] | undefined) {
|
|
377
343
|
if (configured === undefined) return "Automatic safe built-ins";
|
|
378
344
|
if (configured.length === 0) return "No optional tools";
|
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 {
|