@narumitw/pi-plan-mode 0.57.1 → 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/README.md +68 -4
- package/dist/chunks/{chunk-57OBPS7P.js → chunk-HF7ZEYIC.js} +169 -164
- package/dist/chunks/chunk-HF7ZEYIC.js.map +7 -0
- package/dist/chunks/{interactive-ui-N2ZKBVNE.js → interactive-ui-UK7IGPOE.js} +312 -32
- package/dist/chunks/interactive-ui-UK7IGPOE.js.map +7 -0
- package/dist/index.ts +670 -212
- package/dist/index.ts.map +4 -4
- package/docs/settings.md +26 -2
- package/package.json +50 -51
- package/src/active-implementation-menu.ts +57 -60
- package/src/command.ts +22 -21
- 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 +52 -0
- package/src/fresh-implementation.ts +312 -205
- package/src/implementation-models.ts +43 -0
- 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 +139 -89
- package/src/plan-action-menus.ts +414 -177
- 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 +2027 -1675
- 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 +489 -377
- package/src/settings.ts +403 -382
- package/src/state.ts +177 -146
- 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-57OBPS7P.js.map +0 -7
- package/dist/chunks/interactive-ui-N2ZKBVNE.js.map +0 -7
package/README.md
CHANGED
|
@@ -11,6 +11,7 @@ Use a Codex-like `/plan` mode to explore a codebase, resolve important questions
|
|
|
11
11
|
- Uses structured questions for important ambiguity and explicit completion for a decision-ready plan.
|
|
12
12
|
- Reviews the complete plan before implementation, export, save, further planning, or discard.
|
|
13
13
|
- Implements in the planning session or a fresh linked session with the approved plan.
|
|
14
|
+
- Configures persistent or one-shot destination model and thinking choices for fresh implementation.
|
|
14
15
|
- Restores Plan state and one saved plan across resume and compaction.
|
|
15
16
|
- Configures the Plan tool allowlist, reviewed shell commands, user-trusted subcommands, export path, plan reinjection, shortcut, and thinking level.
|
|
16
17
|
- Publishes statusline state and cooperates anonymously with Workflow Mutex Protocol v1 participants.
|
|
@@ -45,6 +46,45 @@ Install only from sources you trust because Pi extensions run with Pi's permissi
|
|
|
45
46
|
Run `/plan` to open the state-aware menu, then start Plan mode and ask the agent to inspect and design the change.
|
|
46
47
|
Run `/plan <prompt>` when the first planning request is already known.
|
|
47
48
|
|
|
49
|
+
## 🗺️ How it works
|
|
50
|
+
|
|
51
|
+
Plan mode keeps exploration and implementation on opposite sides of an explicit review boundary:
|
|
52
|
+
|
|
53
|
+
```mermaid
|
|
54
|
+
flowchart LR
|
|
55
|
+
start["Start: /plan or /plan with a prompt"]
|
|
56
|
+
start --> explore["Explore safely: inspect and clarify"]
|
|
57
|
+
explore --> complete["Complete the plan with plan_mode_complete"]
|
|
58
|
+
complete --> review["Review the ready plan"]
|
|
59
|
+
review -->|Revise| explore
|
|
60
|
+
review -->|Implement here| current["Current session: planning context retained"]
|
|
61
|
+
review -->|Start fresh| fresh["Fresh session: approved plan transferred"]
|
|
62
|
+
review -->|Save| saved["Saved for later"]
|
|
63
|
+
review -->|Export| exported["Markdown file"]
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
During planning, the agent can inspect the project and ask material questions, but Plan mode blocks editing tools and unsafe shell forms. Implementation starts only after the plan is complete and you choose a handoff:
|
|
67
|
+
|
|
68
|
+
```mermaid
|
|
69
|
+
sequenceDiagram
|
|
70
|
+
actor User
|
|
71
|
+
participant Pi
|
|
72
|
+
participant Plan as Plan mode
|
|
73
|
+
participant Work as Implementation
|
|
74
|
+
|
|
75
|
+
User->>Pi: Start planning
|
|
76
|
+
Pi->>Plan: Apply the configured Plan tool policy
|
|
77
|
+
Plan->>User: Ask material questions when needed
|
|
78
|
+
User-->>Plan: Answer or refine the request
|
|
79
|
+
Plan->>Pi: Submit the complete plan
|
|
80
|
+
Pi-->>User: Show the ready-plan review
|
|
81
|
+
alt Implement here
|
|
82
|
+
Pi->>Work: Restore Normal mode in the current session
|
|
83
|
+
else Start fresh and implement
|
|
84
|
+
Pi->>Work: Create a fresh session with the approved plan
|
|
85
|
+
end
|
|
86
|
+
```
|
|
87
|
+
|
|
48
88
|
## 💬 Commands
|
|
49
89
|
|
|
50
90
|
| Command | Purpose |
|
|
@@ -57,11 +97,12 @@ Run `/plan <prompt>` when the first planning request is already known.
|
|
|
57
97
|
| `/plan finalize` | Ask the active planner to finish or ask one remaining material question. |
|
|
58
98
|
| `/plan implement` | Implement a completed or saved plan in this session, without a selector. |
|
|
59
99
|
| `/plan save` | Save a ready plan in this Pi session and leave Plan mode. |
|
|
100
|
+
| `/plan settings` | Open the same Plan Settings screen available from the menus. |
|
|
60
101
|
| `/plan export [path]` | Write a ready, saved, or active implementation plan to Markdown. |
|
|
61
102
|
| `/plan exit` (alias: `off`) | Leave Plan mode and discard its ready plan, or clear a saved/active plan. |
|
|
62
103
|
|
|
63
104
|
All routes support TUI and RPC.
|
|
64
|
-
Print and JSON modes reject the menu and `
|
|
105
|
+
Print and JSON modes reject the menu, `tools`, and `settings`; stored-plan display and implementation have [additional mode restrictions](#-planning-and-implementation).
|
|
65
106
|
Exact subcommand words select routes; other text is a planning prompt, so `/plan start a migration` sends a prompt rather than rejecting trailing text.
|
|
66
107
|
There is no startup flag.
|
|
67
108
|
|
|
@@ -151,7 +192,23 @@ Empty, malformed, unclosed, or multiple legacy blocks keep Plan mode active and
|
|
|
151
192
|
After completion, `/plan` opens the ready actions when interactive UI is available.
|
|
152
193
|
The same flat menu shows **Implement here** and **Start fresh and implement**, explains which conversation context each choice uses, and previews the selected **Plan reinjection** policy.
|
|
153
194
|
**Implement here**—and the compatibility route `/plan implement`—appends the Normal contract, lifts the Plan runtime policy, captures the reinjection setting, and starts implementation in the current session with its complete planning conversation and tool calls.
|
|
154
|
-
**Start fresh and implement**
|
|
195
|
+
**Start fresh and implement** opens a settings page before replacement.
|
|
196
|
+
Its searchable model list snapshots the session's scoped models when configured, otherwise Pi's currently available models, and shows each provider, model ID, and friendly name.
|
|
197
|
+
Pi 0.80.6–0.82.1 does not expose session model scopes to extensions, so the list uses all currently available models on those releases.
|
|
198
|
+
One-shot provider and model identifiers are limited to 512 characters each; longer custom identifiers are rejected before the source session is replaced.
|
|
199
|
+
The model and thinking rows start from the persistent **Fresh model** and **Fresh thinking** defaults; when either setting is omitted, they show the planning session's current value with **same as plan** and carry it into the fresh session independently.
|
|
200
|
+
The fixed thinking choices are `off`, `minimal`, `low`, `medium`, `high`, `xhigh`, and `max`.
|
|
201
|
+
Back navigation preserves this menu-local draft, while closing and reopening the menu restores both persistent defaults.
|
|
202
|
+
If the configured model is outside the current scope or no longer available, the row reports the fallback and uses **same as plan** without deleting the stored preference.
|
|
203
|
+
The saved-plan menu keeps its direct fresh-session action without optional rows and applies the same persistent defaults and fallback.
|
|
204
|
+
|
|
205
|
+
Starting from that settings page waits for the source session to become idle, re-resolves and authenticates an explicit model, creates a new session linked to the persisted source as its parent, and transfers the exact approved plan without copying planning messages, tool results, or compaction/branch summaries.
|
|
206
|
+
The destination consumes the one-shot choices before its first provider request, applies an explicit model first, and then applies explicit thinking.
|
|
207
|
+
Concurrent prompts that arrive while those choices are being applied are queued as follow-ups behind the kickoff prompt.
|
|
208
|
+
If durable consumption blocks the kickoff, the handoff reports a partial start and restores a conversation-history prompt to the editor instead of reporting success.
|
|
209
|
+
Changing only the model keeps the planning thinking level; changing only the thinking level keeps the planning model.
|
|
210
|
+
If Pi clamps an unsupported thinking level, the extension reports the effective level.
|
|
211
|
+
If the chosen model disappears or loses authentication after source preflight, the destination reports the race, consumes the intent without retrying it later, and continues with its default model.
|
|
155
212
|
The destination still loads its normal `AGENTS.md`, skills, project resources, and extensions.
|
|
156
213
|
Choosing **Export plan…** asks for a destination, writes the plan, appends the Normal contract, restores inherited thinking, and leaves Plan mode without starting a model turn or changing active tools.
|
|
157
214
|
Choosing **Save for later**—or running `/plan save`—instead stores one plan in the current Pi session before leaving Plan mode.
|
|
@@ -162,6 +219,8 @@ Resume it later to inspect or hand off the ready/saved plan again; this delibera
|
|
|
162
219
|
In-memory sessions create an unlinked fresh session because no parent file exists.
|
|
163
220
|
Escape, Ctrl+C, menu disposal, source replacement/shutdown, model/auth failure, or cancellation by another extension before replacement leaves the source plan unchanged.
|
|
164
221
|
Under **Off — conversation history only**, the destination receives the complete plan in its initial user prompt and does not persist active-plan state.
|
|
222
|
+
When a one-shot runtime choice exists, only that temporary non-model state is persisted and it is removed before the first request.
|
|
223
|
+
If that removal cannot be persisted, the request is not sent and can be retried after session persistence is available.
|
|
165
224
|
If that kickoff fails, the complete request remains in the destination editor and the source remains resumable.
|
|
166
225
|
Under either guaranteed-plan policy, the destination persists active-plan state before kickoff.
|
|
167
226
|
If guaranteed-plan persistence fails, the complete request is placed in the destination editor and the source remains resumable.
|
|
@@ -282,18 +341,23 @@ Guaranteed coexistence with Goal requires `@narumitw/pi-goal` `0.53.0` or newer
|
|
|
282
341
|
|
|
283
342
|
## ⚙️ Settings
|
|
284
343
|
|
|
285
|
-
|
|
344
|
+
Run `/plan settings`, open **Settings** from an inactive `/plan` menu, or edit `<getAgentDir()>/pi-plan-mode.json` (normally `~/.pi/agent/pi-plan-mode.json`).
|
|
286
345
|
The optional file is read at session start and watched for changes; only an explicit save creates it.
|
|
287
346
|
|
|
288
347
|
```json
|
|
289
348
|
{
|
|
290
349
|
"thinkingLevel": "inherit",
|
|
291
350
|
"implementationPlanRetention": "clear-on-start",
|
|
351
|
+
"defaultImplementationModel": {
|
|
352
|
+
"provider": "anthropic",
|
|
353
|
+
"modelId": "claude-sonnet-4-5"
|
|
354
|
+
},
|
|
355
|
+
"defaultImplementationThinkingLevel": "high",
|
|
292
356
|
"defaultPlanExportPath": "PLAN.md"
|
|
293
357
|
}
|
|
294
358
|
```
|
|
295
359
|
|
|
296
|
-
By default, Plan mode inherits thinking, allows active safe built-ins, exports to `PLAN.md`, and relies on ordinary conversation history after implementation starts.
|
|
360
|
+
By default, Plan mode inherits thinking, allows active safe built-ins, uses the planning model and thinking level for fresh implementation, exports to `PLAN.md`, and relies on ordinary conversation history after implementation starts.
|
|
297
361
|
The shortcut is disabled unless configured.
|
|
298
362
|
Settings saves apply to later workflows; an active implementation keeps its captured reinjection policy.
|
|
299
363
|
The export destination affects the next export immediately.
|
|
@@ -118,9 +118,7 @@ function latestAssistantStopReason(messages) {
|
|
|
118
118
|
return void 0;
|
|
119
119
|
}
|
|
120
120
|
function messageTextContent(message) {
|
|
121
|
-
return messageText(
|
|
122
|
-
message?.message ?? message
|
|
123
|
-
);
|
|
121
|
+
return messageText(message?.message ?? message);
|
|
124
122
|
}
|
|
125
123
|
function messageContainsLegacyPlanModeContextArtifact(message) {
|
|
126
124
|
return unwrapSessionMessage(message).customType === PLAN_CONTEXT_MESSAGE_TYPE;
|
|
@@ -304,86 +302,26 @@ function contentText(content) {
|
|
|
304
302
|
}).filter(Boolean).join("\n");
|
|
305
303
|
}
|
|
306
304
|
|
|
307
|
-
// src/implementation-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
return
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
305
|
+
// src/implementation-models.ts
|
|
306
|
+
var MAX_PENDING_IMPLEMENTATION_MODEL_IDENTIFIER_LENGTH = 512;
|
|
307
|
+
function isPendingImplementationModelIdentifier(value) {
|
|
308
|
+
return typeof value === "string" && value.trim().length > 0 && value.length <= MAX_PENDING_IMPLEMENTATION_MODEL_IDENTIFIER_LENGTH;
|
|
309
|
+
}
|
|
310
|
+
function snapshotAvailableImplementationModels(ctx) {
|
|
311
|
+
const getAvailable = ctx.modelRegistry.getAvailable;
|
|
312
|
+
const availableModels = typeof getAvailable === "function" ? getAvailable.call(ctx.modelRegistry) : [];
|
|
313
|
+
const scopedModels = ctx.scopedModels ?? [];
|
|
314
|
+
if (scopedModels.length === 0) return availableModels;
|
|
315
|
+
return scopedModels.flatMap((entry) => {
|
|
316
|
+
const availableModel = availableModels.find(
|
|
317
|
+
(model) => model.provider === entry.model.provider && model.id === entry.model.id
|
|
318
|
+
);
|
|
319
|
+
return availableModel ? [availableModel] : [];
|
|
320
|
+
});
|
|
321
321
|
}
|
|
322
|
-
function
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
return {
|
|
326
|
-
restore(activeImplementation) {
|
|
327
|
-
restoredImplementationAwaitingContext = activeImplementation && activeImplementation.retention !== "keep" ? activeImplementation.id : void 0;
|
|
328
|
-
},
|
|
329
|
-
transformContext(messages, state) {
|
|
330
|
-
const messagesWithoutLegacyContext = messages.filter(
|
|
331
|
-
(message) => !messageContainsLegacyPlanModeContextArtifact(message)
|
|
332
|
-
);
|
|
333
|
-
if (state.enabled) {
|
|
334
|
-
return {
|
|
335
|
-
messages: messagesWithoutLegacyContext.filter(
|
|
336
|
-
(message) => !messageContainsPlanModeImplementationContextArtifact(message) && !messageContainsPlanModeImplementationHandoff(message)
|
|
337
|
-
)
|
|
338
|
-
};
|
|
339
|
-
}
|
|
340
|
-
const activeImplementation = state.activeImplementation;
|
|
341
|
-
const inactiveMessages = activeImplementation ? messagesWithoutLegacyContext : messagesWithoutLegacyContext.filter(
|
|
342
|
-
(message) => !messageContainsPlanModeImplementationContextArtifact(message) && !messageContainsPlanModeImplementationHandoff(message)
|
|
343
|
-
);
|
|
344
|
-
const historyArtifact = activeImplementation ? void 0 : findHistoryImplementationArtifact(inactiveMessages);
|
|
345
|
-
const historyArtifactMessage = historyArtifact ? inactiveMessages[historyArtifact.messageIndex] : void 0;
|
|
346
|
-
const historyToolCallMessage = historyArtifact?.toolCallMessageIndex !== void 0 ? inactiveMessages[historyArtifact.toolCallMessageIndex] : void 0;
|
|
347
|
-
const filteredMessages = inactiveMessages.filter(
|
|
348
|
-
(message) => message === historyArtifactMessage || !messageContainsInactivePlanModeArtifact(message)
|
|
349
|
-
).map(
|
|
350
|
-
(message) => message === historyArtifactMessage && historyArtifact?.kind === "legacy" ? message : stripProposedPlanBlocksFromMessage(message)
|
|
351
|
-
).map(
|
|
352
|
-
(message) => stripPlanModeCompletionCallsFromMessage(
|
|
353
|
-
message,
|
|
354
|
-
message === historyToolCallMessage ? historyArtifact?.toolCallId : void 0
|
|
355
|
-
)
|
|
356
|
-
).filter((message) => !isEmptyAssistantMessage(message));
|
|
357
|
-
if (!activeImplementation) return { messages: filteredMessages };
|
|
358
|
-
const contextualMessages = injectActiveImplementationContext(
|
|
359
|
-
filteredMessages,
|
|
360
|
-
activeImplementation
|
|
361
|
-
);
|
|
362
|
-
const deliveredCurrentHandoff = restoredImplementationAwaitingContext === activeImplementation.id || filteredMessages.some(
|
|
363
|
-
(message) => messageContainsExactPlanModeImplementationHandoff(message, activeImplementation.plan)
|
|
364
|
-
);
|
|
365
|
-
if (!deliveredCurrentHandoff) return { messages: contextualMessages };
|
|
366
|
-
restoredImplementationAwaitingContext = void 0;
|
|
367
|
-
if (activeImplementation.retention === "clear-after-first-run") {
|
|
368
|
-
implementationWithDeliveredContext = activeImplementation.id;
|
|
369
|
-
}
|
|
370
|
-
return {
|
|
371
|
-
messages: contextualMessages,
|
|
372
|
-
clearActiveImplementationId: activeImplementation.retention === "clear-on-start" ? activeImplementation.id : void 0
|
|
373
|
-
};
|
|
374
|
-
},
|
|
375
|
-
implementationSettled(activeImplementation) {
|
|
376
|
-
if (activeImplementation?.retention !== "clear-after-first-run" || implementationWithDeliveredContext !== activeImplementation.id) {
|
|
377
|
-
return void 0;
|
|
378
|
-
}
|
|
379
|
-
implementationWithDeliveredContext = void 0;
|
|
380
|
-
return activeImplementation.id;
|
|
381
|
-
},
|
|
382
|
-
reset() {
|
|
383
|
-
implementationWithDeliveredContext = void 0;
|
|
384
|
-
restoredImplementationAwaitingContext = void 0;
|
|
385
|
-
}
|
|
386
|
-
};
|
|
322
|
+
function findAvailableImplementationModel(models, configured) {
|
|
323
|
+
if (!configured) return void 0;
|
|
324
|
+
return models.find((model) => model.provider === configured.provider && model.id === configured.modelId);
|
|
387
325
|
}
|
|
388
326
|
|
|
389
327
|
// src/settings.ts
|
|
@@ -405,11 +343,8 @@ var PLAN_MODE_THINKING_LEVELS = [
|
|
|
405
343
|
"xhigh",
|
|
406
344
|
"max"
|
|
407
345
|
];
|
|
408
|
-
var
|
|
409
|
-
|
|
410
|
-
"clear-after-first-run",
|
|
411
|
-
"keep"
|
|
412
|
-
];
|
|
346
|
+
var IMPLEMENTATION_THINKING_LEVELS = ["off", "minimal", "low", "medium", "high", "xhigh", "max"];
|
|
347
|
+
var IMPLEMENTATION_PLAN_RETENTIONS = ["clear-on-start", "clear-after-first-run", "keep"];
|
|
413
348
|
var DEFAULT_PLAN_EXPORT_PATH = "PLAN.md";
|
|
414
349
|
var MODIFIERS = /* @__PURE__ */ new Set(["ctrl", "shift", "alt", "super"]);
|
|
415
350
|
var BASE_KEYS = /* @__PURE__ */ new Set([
|
|
@@ -489,17 +424,25 @@ function normalizePlanModeSettings(value) {
|
|
|
489
424
|
}
|
|
490
425
|
if (Object.hasOwn(value, "implementationPlanRetention")) {
|
|
491
426
|
const implementationPlanRetention = Reflect.get(value, "implementationPlanRetention");
|
|
492
|
-
if (!IMPLEMENTATION_PLAN_RETENTIONS.includes(
|
|
493
|
-
implementationPlanRetention
|
|
494
|
-
)) {
|
|
427
|
+
if (!IMPLEMENTATION_PLAN_RETENTIONS.includes(implementationPlanRetention)) {
|
|
495
428
|
return void 0;
|
|
496
429
|
}
|
|
497
430
|
settings.implementationPlanRetention = implementationPlanRetention;
|
|
498
431
|
}
|
|
432
|
+
if (Object.hasOwn(value, "defaultImplementationModel")) {
|
|
433
|
+
const defaultImplementationModel = normalizeImplementationModel(Reflect.get(value, "defaultImplementationModel"));
|
|
434
|
+
if (!defaultImplementationModel) return void 0;
|
|
435
|
+
settings.defaultImplementationModel = defaultImplementationModel;
|
|
436
|
+
}
|
|
437
|
+
if (Object.hasOwn(value, "defaultImplementationThinkingLevel")) {
|
|
438
|
+
const defaultImplementationThinkingLevel = Reflect.get(value, "defaultImplementationThinkingLevel");
|
|
439
|
+
if (!IMPLEMENTATION_THINKING_LEVELS.includes(defaultImplementationThinkingLevel)) {
|
|
440
|
+
return void 0;
|
|
441
|
+
}
|
|
442
|
+
settings.defaultImplementationThinkingLevel = defaultImplementationThinkingLevel;
|
|
443
|
+
}
|
|
499
444
|
if (Object.hasOwn(value, "defaultPlanExportPath")) {
|
|
500
|
-
const defaultPlanExportPath = normalizePlanExportPath(
|
|
501
|
-
Reflect.get(value, "defaultPlanExportPath")
|
|
502
|
-
);
|
|
445
|
+
const defaultPlanExportPath = normalizePlanExportPath(Reflect.get(value, "defaultPlanExportPath"));
|
|
503
446
|
if (!defaultPlanExportPath) return void 0;
|
|
504
447
|
settings.defaultPlanExportPath = defaultPlanExportPath;
|
|
505
448
|
}
|
|
@@ -515,6 +458,17 @@ function normalizePlanModeSettings(value) {
|
|
|
515
458
|
}
|
|
516
459
|
return settings;
|
|
517
460
|
}
|
|
461
|
+
function normalizeImplementationModel(value) {
|
|
462
|
+
if (!isSettingsDocument(value) || Object.keys(value).some((key) => key !== "provider" && key !== "modelId")) {
|
|
463
|
+
return void 0;
|
|
464
|
+
}
|
|
465
|
+
const provider = typeof value.provider === "string" ? value.provider.trim() : value.provider;
|
|
466
|
+
const modelId = typeof value.modelId === "string" ? value.modelId.trim() : value.modelId;
|
|
467
|
+
if (!isPendingImplementationModelIdentifier(provider) || !isPendingImplementationModelIdentifier(modelId)) {
|
|
468
|
+
return void 0;
|
|
469
|
+
}
|
|
470
|
+
return { provider, modelId };
|
|
471
|
+
}
|
|
518
472
|
function normalizeToolNames(value) {
|
|
519
473
|
if (!Array.isArray(value) || !value.every((item) => typeof item === "string" && item.trim().length > 0)) {
|
|
520
474
|
return void 0;
|
|
@@ -551,14 +505,10 @@ function normalizeSafeSubcommands(value) {
|
|
|
551
505
|
const entries = [];
|
|
552
506
|
for (const [command, subcommands] of Object.entries(value)) {
|
|
553
507
|
const normalizedCommand = command.trim();
|
|
554
|
-
if (!normalizedCommand || !Array.isArray(subcommands) || !subcommands.every(
|
|
555
|
-
(item) => typeof item === "string" && item.trim().length > 0
|
|
556
|
-
)) {
|
|
508
|
+
if (!normalizedCommand || !Array.isArray(subcommands) || !subcommands.every((item) => typeof item === "string" && item.trim().length > 0)) {
|
|
557
509
|
return void 0;
|
|
558
510
|
}
|
|
559
|
-
const normalizedSubcommands = Array.from(
|
|
560
|
-
new Set(subcommands.map((subcommand) => subcommand.trim()))
|
|
561
|
-
);
|
|
511
|
+
const normalizedSubcommands = Array.from(new Set(subcommands.map((subcommand) => subcommand.trim())));
|
|
562
512
|
const existing = entries.find(([existingCommand]) => existingCommand === normalizedCommand);
|
|
563
513
|
if (existing) existing[1] = Array.from(/* @__PURE__ */ new Set([...existing[1], ...normalizedSubcommands]));
|
|
564
514
|
else entries.push([normalizedCommand, normalizedSubcommands]);
|
|
@@ -603,6 +553,17 @@ function updatePlanModeSettings(patch, options = {}) {
|
|
|
603
553
|
if (patch.implementationPlanRetention !== void 0) {
|
|
604
554
|
updated.implementationPlanRetention = patch.implementationPlanRetention;
|
|
605
555
|
}
|
|
556
|
+
if (patch.defaultImplementationModel === null) delete updated.defaultImplementationModel;
|
|
557
|
+
else if (patch.defaultImplementationModel !== void 0) {
|
|
558
|
+
const model = normalizeImplementationModel(patch.defaultImplementationModel);
|
|
559
|
+
if (!model) throw invalidSettingsError(settingsPath, "invalid implementation model");
|
|
560
|
+
updated.defaultImplementationModel = model;
|
|
561
|
+
}
|
|
562
|
+
if (patch.defaultImplementationThinkingLevel === null) {
|
|
563
|
+
delete updated.defaultImplementationThinkingLevel;
|
|
564
|
+
} else if (patch.defaultImplementationThinkingLevel !== void 0) {
|
|
565
|
+
updated.defaultImplementationThinkingLevel = patch.defaultImplementationThinkingLevel;
|
|
566
|
+
}
|
|
606
567
|
if (patch.defaultPlanExportPath === null) delete updated.defaultPlanExportPath;
|
|
607
568
|
else if (patch.defaultPlanExportPath !== void 0) {
|
|
608
569
|
updated.defaultPlanExportPath = patch.defaultPlanExportPath;
|
|
@@ -691,9 +652,7 @@ async function readSettingsContents(settingsPath) {
|
|
|
691
652
|
throw new Error(`settings file exceeds ${MAX_SETTINGS_BYTES} bytes`);
|
|
692
653
|
}
|
|
693
654
|
try {
|
|
694
|
-
return new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(
|
|
695
|
-
buffer.subarray(0, offset)
|
|
696
|
-
);
|
|
655
|
+
return new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(buffer.subarray(0, offset));
|
|
697
656
|
} catch {
|
|
698
657
|
throw new Error("settings file is not valid UTF-8");
|
|
699
658
|
}
|
|
@@ -711,10 +670,7 @@ async function publishSettings(settingsPath, document, signal, beforeRename) {
|
|
|
711
670
|
const directory = dirname(settingsPath);
|
|
712
671
|
await mkdir(directory, { recursive: true });
|
|
713
672
|
signal?.throwIfAborted();
|
|
714
|
-
const temporaryPath = join(
|
|
715
|
-
directory,
|
|
716
|
-
`.${basename(settingsPath)}.${process.pid}.${randomUUID()}.tmp`
|
|
717
|
-
);
|
|
673
|
+
const temporaryPath = join(directory, `.${basename(settingsPath)}.${process.pid}.${randomUUID()}.tmp`);
|
|
718
674
|
try {
|
|
719
675
|
await writeFile(temporaryPath, contents, {
|
|
720
676
|
encoding: "utf8",
|
|
@@ -757,6 +713,12 @@ function configuredThinkingLevel(settings) {
|
|
|
757
713
|
function configuredImplementationPlanRetention(settings) {
|
|
758
714
|
return settings.implementationPlanRetention ?? "clear-on-start";
|
|
759
715
|
}
|
|
716
|
+
function configuredImplementationModel(settings) {
|
|
717
|
+
return settings.defaultImplementationModel;
|
|
718
|
+
}
|
|
719
|
+
function configuredImplementationThinkingLevel(settings) {
|
|
720
|
+
return settings.defaultImplementationThinkingLevel;
|
|
721
|
+
}
|
|
760
722
|
function configuredPlanExportPath(settings) {
|
|
761
723
|
return settings.defaultPlanExportPath ?? DEFAULT_PLAN_EXPORT_PATH;
|
|
762
724
|
}
|
|
@@ -764,6 +726,83 @@ function configuredPlanModeToggleShortcut(settings) {
|
|
|
764
726
|
return settings.toggleShortcut;
|
|
765
727
|
}
|
|
766
728
|
|
|
729
|
+
// src/implementation-retention.ts
|
|
730
|
+
function retentionLabel(retention) {
|
|
731
|
+
return {
|
|
732
|
+
"clear-on-start": "Off \u2014 conversation history only",
|
|
733
|
+
"clear-after-first-run": "Through first implementation run",
|
|
734
|
+
keep: "Until manually cleared"
|
|
735
|
+
}[retention];
|
|
736
|
+
}
|
|
737
|
+
function implementationRetentionPreview(retention) {
|
|
738
|
+
return {
|
|
739
|
+
"clear-on-start": "Plan reinjection: Off; use conversation history only.",
|
|
740
|
+
"clear-after-first-run": "Plan reinjection: Through the first implementation run.",
|
|
741
|
+
keep: "Plan reinjection: Until /plan exit."
|
|
742
|
+
}[retention];
|
|
743
|
+
}
|
|
744
|
+
function createImplementationRetentionCoordinator() {
|
|
745
|
+
let implementationWithDeliveredContext;
|
|
746
|
+
let restoredImplementationAwaitingContext;
|
|
747
|
+
return {
|
|
748
|
+
restore(activeImplementation) {
|
|
749
|
+
restoredImplementationAwaitingContext = activeImplementation && activeImplementation.retention !== "keep" ? activeImplementation.id : void 0;
|
|
750
|
+
},
|
|
751
|
+
transformContext(messages, state) {
|
|
752
|
+
const messagesWithoutLegacyContext = messages.filter(
|
|
753
|
+
(message) => !messageContainsLegacyPlanModeContextArtifact(message)
|
|
754
|
+
);
|
|
755
|
+
if (state.enabled) {
|
|
756
|
+
return {
|
|
757
|
+
messages: messagesWithoutLegacyContext.filter(
|
|
758
|
+
(message) => !messageContainsPlanModeImplementationContextArtifact(message) && !messageContainsPlanModeImplementationHandoff(message)
|
|
759
|
+
)
|
|
760
|
+
};
|
|
761
|
+
}
|
|
762
|
+
const activeImplementation = state.activeImplementation;
|
|
763
|
+
const inactiveMessages = activeImplementation ? messagesWithoutLegacyContext : messagesWithoutLegacyContext.filter(
|
|
764
|
+
(message) => !messageContainsPlanModeImplementationContextArtifact(message) && !messageContainsPlanModeImplementationHandoff(message)
|
|
765
|
+
);
|
|
766
|
+
const historyArtifact = activeImplementation ? void 0 : findHistoryImplementationArtifact(inactiveMessages);
|
|
767
|
+
const historyArtifactMessage = historyArtifact ? inactiveMessages[historyArtifact.messageIndex] : void 0;
|
|
768
|
+
const historyToolCallMessage = historyArtifact?.toolCallMessageIndex !== void 0 ? inactiveMessages[historyArtifact.toolCallMessageIndex] : void 0;
|
|
769
|
+
const filteredMessages = inactiveMessages.filter((message) => message === historyArtifactMessage || !messageContainsInactivePlanModeArtifact(message)).map(
|
|
770
|
+
(message) => message === historyArtifactMessage && historyArtifact?.kind === "legacy" ? message : stripProposedPlanBlocksFromMessage(message)
|
|
771
|
+
).map(
|
|
772
|
+
(message) => stripPlanModeCompletionCallsFromMessage(
|
|
773
|
+
message,
|
|
774
|
+
message === historyToolCallMessage ? historyArtifact?.toolCallId : void 0
|
|
775
|
+
)
|
|
776
|
+
).filter((message) => !isEmptyAssistantMessage(message));
|
|
777
|
+
if (!activeImplementation) return { messages: filteredMessages };
|
|
778
|
+
const contextualMessages = injectActiveImplementationContext(filteredMessages, activeImplementation);
|
|
779
|
+
const deliveredCurrentHandoff = restoredImplementationAwaitingContext === activeImplementation.id || filteredMessages.some(
|
|
780
|
+
(message) => messageContainsExactPlanModeImplementationHandoff(message, activeImplementation.plan)
|
|
781
|
+
);
|
|
782
|
+
if (!deliveredCurrentHandoff) return { messages: contextualMessages };
|
|
783
|
+
restoredImplementationAwaitingContext = void 0;
|
|
784
|
+
if (activeImplementation.retention === "clear-after-first-run") {
|
|
785
|
+
implementationWithDeliveredContext = activeImplementation.id;
|
|
786
|
+
}
|
|
787
|
+
return {
|
|
788
|
+
messages: contextualMessages,
|
|
789
|
+
clearActiveImplementationId: activeImplementation.retention === "clear-on-start" ? activeImplementation.id : void 0
|
|
790
|
+
};
|
|
791
|
+
},
|
|
792
|
+
implementationSettled(activeImplementation) {
|
|
793
|
+
if (activeImplementation?.retention !== "clear-after-first-run" || implementationWithDeliveredContext !== activeImplementation.id) {
|
|
794
|
+
return void 0;
|
|
795
|
+
}
|
|
796
|
+
implementationWithDeliveredContext = void 0;
|
|
797
|
+
return activeImplementation.id;
|
|
798
|
+
},
|
|
799
|
+
reset() {
|
|
800
|
+
implementationWithDeliveredContext = void 0;
|
|
801
|
+
restoredImplementationAwaitingContext = void 0;
|
|
802
|
+
}
|
|
803
|
+
};
|
|
804
|
+
}
|
|
805
|
+
|
|
767
806
|
// src/plan-export.ts
|
|
768
807
|
import { mkdir as mkdir2, writeFile as writeFile2 } from "node:fs/promises";
|
|
769
808
|
import { dirname as dirname2, resolve } from "node:path";
|
|
@@ -772,9 +811,7 @@ import { withFileMutationQueue } from "@earendil-works/pi-coding-agent";
|
|
|
772
811
|
async function exportStoredPlan(state, requestedPath, ctx, lifecycle, defaultPath = DEFAULT_PLAN_EXPORT_PATH) {
|
|
773
812
|
const plan = (state.enabled ? state.latestPlan : void 0)?.trim() ?? state.savedPlan?.plan.trim() ?? state.activeImplementation?.plan.trim();
|
|
774
813
|
if (!plan) {
|
|
775
|
-
const error = new Error(
|
|
776
|
-
"No completed plan is available to export. Use /plan finalize when planning is complete."
|
|
777
|
-
);
|
|
814
|
+
const error = new Error("No completed plan is available to export. Use /plan finalize when planning is complete.");
|
|
778
815
|
if (!ctx.hasUI) throw error;
|
|
779
816
|
ctx.ui.notify(error.message, "warning");
|
|
780
817
|
return false;
|
|
@@ -782,14 +819,7 @@ async function exportStoredPlan(state, requestedPath, ctx, lifecycle, defaultPat
|
|
|
782
819
|
const isCurrent = () => !lifecycle || lifecycle.isCurrent() && (!lifecycle.getState || lifecycle.getState() === state);
|
|
783
820
|
let result;
|
|
784
821
|
try {
|
|
785
|
-
result = await exportPlanToFile(
|
|
786
|
-
plan,
|
|
787
|
-
requestedPath,
|
|
788
|
-
ctx.cwd,
|
|
789
|
-
lifecycle?.signal,
|
|
790
|
-
isCurrent,
|
|
791
|
-
defaultPath
|
|
792
|
-
);
|
|
822
|
+
result = await exportPlanToFile(plan, requestedPath, ctx.cwd, lifecycle?.signal, isCurrent, defaultPath);
|
|
793
823
|
} catch (error) {
|
|
794
824
|
if (lifecycle?.signal.aborted || !isCurrent()) return false;
|
|
795
825
|
if (!ctx.hasUI) throw error;
|
|
@@ -815,9 +845,7 @@ async function exportPlanToFile(plan, requestedPath, cwd, signal, isCurrent = ()
|
|
|
815
845
|
`, { encoding: "utf8", flag: "wx" });
|
|
816
846
|
} catch (error) {
|
|
817
847
|
if (isNodeError2(error) && error.code === "EEXIST") {
|
|
818
|
-
throw new Error(
|
|
819
|
-
`Plan export target already exists: ${path}. Choose another path or remove it first.`
|
|
820
|
-
);
|
|
848
|
+
throw new Error(`Plan export target already exists: ${path}. Choose another path or remove it first.`);
|
|
821
849
|
}
|
|
822
850
|
throw error;
|
|
823
851
|
}
|
|
@@ -961,11 +989,7 @@ function normalizePlanModeQuestionParams(input) {
|
|
|
961
989
|
return { ok: true, questions };
|
|
962
990
|
}
|
|
963
991
|
async function answerPlanModeQuestions(questions, ctx, lifecycle) {
|
|
964
|
-
const answers = await askPlanModeQuestions(
|
|
965
|
-
questions,
|
|
966
|
-
ctx,
|
|
967
|
-
() => lifecycle.isCurrent() && lifecycle.isEnabled()
|
|
968
|
-
);
|
|
992
|
+
const answers = await askPlanModeQuestions(questions, ctx, () => lifecycle.isCurrent() && lifecycle.isEnabled());
|
|
969
993
|
if (!lifecycle.isCurrent()) {
|
|
970
994
|
return planModeQuestionCancelled(
|
|
971
995
|
questions,
|
|
@@ -981,11 +1005,7 @@ async function answerPlanModeQuestions(questions, ctx, lifecycle) {
|
|
|
981
1005
|
);
|
|
982
1006
|
}
|
|
983
1007
|
if (!answers) {
|
|
984
|
-
return planModeQuestionCancelled(
|
|
985
|
-
questions,
|
|
986
|
-
"cancelled",
|
|
987
|
-
"User cancelled the Plan-mode question prompt."
|
|
988
|
-
);
|
|
1008
|
+
return planModeQuestionCancelled(questions, "cancelled", "User cancelled the Plan-mode question prompt.");
|
|
989
1009
|
}
|
|
990
1010
|
return planModeQuestionAnswered(questions, answers);
|
|
991
1011
|
}
|
|
@@ -1062,9 +1082,7 @@ function answerFor(question, answer, options) {
|
|
|
1062
1082
|
}
|
|
1063
1083
|
function planModeQuestionAnswered(questions, answers) {
|
|
1064
1084
|
return {
|
|
1065
|
-
content: [
|
|
1066
|
-
{ type: "text", text: formatPlanModeQuestionPayload({ cancelled: false, answers }) }
|
|
1067
|
-
],
|
|
1085
|
+
content: [{ type: "text", text: formatPlanModeQuestionPayload({ cancelled: false, answers }) }],
|
|
1068
1086
|
details: { cancelled: false, questions, answers }
|
|
1069
1087
|
};
|
|
1070
1088
|
}
|
|
@@ -1109,18 +1127,8 @@ var CONFIGURABLE_SAFE_GIT_SUBCOMMANDS = [
|
|
|
1109
1127
|
"ls-tree",
|
|
1110
1128
|
"cat-file"
|
|
1111
1129
|
];
|
|
1112
|
-
var SAFE_GIT_SUBCOMMANDS = [
|
|
1113
|
-
|
|
1114
|
-
...CONFIGURABLE_SAFE_GIT_SUBCOMMANDS
|
|
1115
|
-
];
|
|
1116
|
-
var SAFE_BUILTIN_PLAN_TOOLS = /* @__PURE__ */ new Set([
|
|
1117
|
-
"read",
|
|
1118
|
-
"bash",
|
|
1119
|
-
"powershell",
|
|
1120
|
-
"grep",
|
|
1121
|
-
"find",
|
|
1122
|
-
"ls"
|
|
1123
|
-
]);
|
|
1130
|
+
var SAFE_GIT_SUBCOMMANDS = [...BUILTIN_SAFE_GIT_SUBCOMMANDS, ...CONFIGURABLE_SAFE_GIT_SUBCOMMANDS];
|
|
1131
|
+
var SAFE_BUILTIN_PLAN_TOOLS = /* @__PURE__ */ new Set(["read", "bash", "powershell", "grep", "find", "ls"]);
|
|
1124
1132
|
var BLOCKED_BUILTIN_TOOLS = /* @__PURE__ */ new Set(["edit", "write"]);
|
|
1125
1133
|
var MUTATING_COMMANDS = /* @__PURE__ */ new Set([
|
|
1126
1134
|
"rm",
|
|
@@ -1220,17 +1228,13 @@ function findBlockedCommandSegment(command, safeSubcommands = {}, workingDirecto
|
|
|
1220
1228
|
if (matchesConfiguredSafeSubcommand(command, safeSubcommands)) return void 0;
|
|
1221
1229
|
const segments = splitShellSegments(command);
|
|
1222
1230
|
if (!segments || segments.length === 0) return command.trim() || "(empty command)";
|
|
1223
|
-
return segments.find(
|
|
1224
|
-
(segment) => !isSafeSegment(segment, safeSubcommands, workingDirectory, platform)
|
|
1225
|
-
);
|
|
1231
|
+
return segments.find((segment) => !isSafeSegment(segment, safeSubcommands, workingDirectory, platform));
|
|
1226
1232
|
}
|
|
1227
1233
|
function findBlockedPowerShellCommandSegment(command, safeSubcommands = {}, workingDirectory) {
|
|
1228
1234
|
if (matchesConfiguredSafeSubcommand(command, safeSubcommands)) return void 0;
|
|
1229
1235
|
const segments = splitPowerShellSegments(command);
|
|
1230
1236
|
if (!segments || segments.length === 0) return command.trim() || "(empty command)";
|
|
1231
|
-
return segments.find(
|
|
1232
|
-
(segment) => !isSafePowerShellSegment(segment, safeSubcommands, workingDirectory)
|
|
1233
|
-
);
|
|
1237
|
+
return segments.find((segment) => !isSafePowerShellSegment(segment, safeSubcommands, workingDirectory));
|
|
1234
1238
|
}
|
|
1235
1239
|
function matchesConfiguredSafeSubcommand(command, safeSubcommands) {
|
|
1236
1240
|
const candidate = command.trimStart();
|
|
@@ -1466,9 +1470,7 @@ function hasSafeArguments(command, args) {
|
|
|
1466
1470
|
return false;
|
|
1467
1471
|
}
|
|
1468
1472
|
if (command === "find" && args.some(
|
|
1469
|
-
(argument) => ["-exec", "-execdir", "-ok", "-okdir", "-fprint", "-fprint0", "-fprintf", "-fls"].includes(
|
|
1470
|
-
argument
|
|
1471
|
-
)
|
|
1473
|
+
(argument) => ["-exec", "-execdir", "-ok", "-okdir", "-fprint", "-fprint0", "-fprintf", "-fls"].includes(argument)
|
|
1472
1474
|
)) {
|
|
1473
1475
|
return false;
|
|
1474
1476
|
}
|
|
@@ -1492,9 +1494,7 @@ function hasSafeArguments(command, args) {
|
|
|
1492
1494
|
return false;
|
|
1493
1495
|
}
|
|
1494
1496
|
if (command === "fd" && args.some(
|
|
1495
|
-
(argument) => ["-x", "-X", "--exec", "--exec-batch"].some(
|
|
1496
|
-
(flag) => argument === flag || argument.startsWith(`${flag}=`)
|
|
1497
|
-
)
|
|
1497
|
+
(argument) => ["-x", "-X", "--exec", "--exec-batch"].some((flag) => argument === flag || argument.startsWith(`${flag}=`))
|
|
1498
1498
|
)) {
|
|
1499
1499
|
return false;
|
|
1500
1500
|
}
|
|
@@ -1549,9 +1549,7 @@ function isSafeStructuredCommand(command, args, safeSubcommands, workingDirector
|
|
|
1549
1549
|
}
|
|
1550
1550
|
if (command === "npm") {
|
|
1551
1551
|
if (subcommand === "audit" && subcommandArgs.includes("fix")) return false;
|
|
1552
|
-
if (["list", "ls", "view", "info", "search", "outdated", "audit", "test"].includes(
|
|
1553
|
-
subcommand ?? ""
|
|
1554
|
-
)) {
|
|
1552
|
+
if (["list", "ls", "view", "info", "search", "outdated", "audit", "test"].includes(subcommand ?? "")) {
|
|
1555
1553
|
return true;
|
|
1556
1554
|
}
|
|
1557
1555
|
return subcommand === "run" && ["test", "check", "typecheck", "lint"].includes(args[1] ?? "");
|
|
@@ -1771,10 +1769,12 @@ export {
|
|
|
1771
1769
|
latestAssistantText,
|
|
1772
1770
|
latestAssistantStopReason,
|
|
1773
1771
|
messageTextContent,
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1772
|
+
MAX_PENDING_IMPLEMENTATION_MODEL_IDENTIFIER_LENGTH,
|
|
1773
|
+
isPendingImplementationModelIdentifier,
|
|
1774
|
+
snapshotAvailableImplementationModels,
|
|
1775
|
+
findAvailableImplementationModel,
|
|
1777
1776
|
PLAN_MODE_THINKING_LEVELS,
|
|
1777
|
+
IMPLEMENTATION_THINKING_LEVELS,
|
|
1778
1778
|
IMPLEMENTATION_PLAN_RETENTIONS,
|
|
1779
1779
|
planModeSettingsPath,
|
|
1780
1780
|
normalizeKeyId,
|
|
@@ -1783,8 +1783,13 @@ export {
|
|
|
1783
1783
|
awaitPlanModeSettingsWrites,
|
|
1784
1784
|
configuredThinkingLevel,
|
|
1785
1785
|
configuredImplementationPlanRetention,
|
|
1786
|
+
configuredImplementationModel,
|
|
1787
|
+
configuredImplementationThinkingLevel,
|
|
1786
1788
|
configuredPlanExportPath,
|
|
1787
1789
|
configuredPlanModeToggleShortcut,
|
|
1790
|
+
retentionLabel,
|
|
1791
|
+
implementationRetentionPreview,
|
|
1792
|
+
createImplementationRetentionCoordinator,
|
|
1788
1793
|
exportStoredPlan,
|
|
1789
1794
|
planExportDestination,
|
|
1790
1795
|
PLAN_MODE_QUESTION_TOOL_NAME,
|
|
@@ -1802,4 +1807,4 @@ export {
|
|
|
1802
1807
|
defaultPlanModeToolNames,
|
|
1803
1808
|
snapshotPlanModeSelectedNames
|
|
1804
1809
|
};
|
|
1805
|
-
//# sourceMappingURL=chunk-
|
|
1810
|
+
//# sourceMappingURL=chunk-HF7ZEYIC.js.map
|