@narumitw/pi-plan-mode 0.58.0 → 0.58.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunks/{chunk-QHHHBTDO.js → chunk-HF7ZEYIC.js} +29 -111
- package/dist/chunks/chunk-HF7ZEYIC.js.map +7 -0
- package/dist/chunks/{interactive-ui-UNJGC2RQ.js → interactive-ui-UK7IGPOE.js} +13 -41
- package/dist/chunks/interactive-ui-UK7IGPOE.js.map +7 -0
- package/dist/index.ts +25 -82
- package/dist/index.ts.map +2 -2
- package/package.json +50 -51
- package/src/active-implementation-menu.ts +57 -60
- package/src/command.ts +22 -22
- package/src/completion-tool.ts +53 -56
- package/src/extension-runtime.ts +5 -5
- package/src/finalization-request.ts +40 -44
- package/src/fresh-handoff-coordinator.ts +38 -41
- package/src/fresh-implementation.ts +293 -310
- package/src/implementation-models.ts +25 -30
- package/src/implementation-retention.ts +109 -123
- package/src/message-transform.ts +218 -252
- package/src/mode-contract.ts +46 -49
- package/src/plan-action-controller.ts +134 -155
- package/src/plan-action-menus.ts +390 -408
- package/src/plan-export-controller.ts +23 -28
- package/src/plan-export-screen.ts +13 -13
- package/src/plan-export.ts +85 -102
- package/src/plan-launch-menu.ts +119 -119
- package/src/plan-mode.ts +2017 -2098
- package/src/presentation.ts +84 -108
- package/src/prompt.ts +1 -1
- package/src/question-tool.ts +239 -267
- package/src/required-tools.ts +15 -19
- package/src/saved-plan-menu.ts +82 -84
- package/src/saved-plan-preflight.ts +29 -33
- package/src/settings-menu.ts +470 -513
- package/src/settings.ts +393 -452
- package/src/state.ts +167 -198
- package/src/tool-policy.ts +634 -699
- package/src/tool-selection.ts +39 -44
- package/src/workflow-mutex.ts +66 -66
- package/dist/chunks/chunk-QHHHBTDO.js.map +0 -7
- package/dist/chunks/interactive-ui-UNJGC2RQ.js.map +0 -7
package/src/mode-contract.ts
CHANGED
|
@@ -13,81 +13,78 @@ Earlier Plan-mode restrictions no longer apply, but retain the planning conversa
|
|
|
13
13
|
The visible tool schemas are session capabilities; use only tools appropriate for the current request.`;
|
|
14
14
|
|
|
15
15
|
interface ContractMessage {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
role?: string;
|
|
17
|
+
customType?: string;
|
|
18
|
+
content?: unknown;
|
|
19
|
+
details?: unknown;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
export function modeContractContent(mode: PlanModeContract) {
|
|
23
|
-
|
|
23
|
+
return mode === "plan" ? `${PLAN_CONTRACT_MARKER}\n${buildPlanModePrompt()}` : NORMAL_CONTRACT;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
export function createModeContractMessage(mode: PlanModeContract, timestamp = Date.now()) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
27
|
+
return {
|
|
28
|
+
role: "custom" as const,
|
|
29
|
+
customType: MODE_CONTRACT_MESSAGE_TYPE,
|
|
30
|
+
content: modeContractContent(mode),
|
|
31
|
+
display: false,
|
|
32
|
+
details: { version: MODE_CONTRACT_VERSION, mode },
|
|
33
|
+
timestamp,
|
|
34
|
+
};
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
export function modeContractFromMessage(message: unknown): PlanModeContract | undefined {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
const candidate = unwrapMessage(message);
|
|
39
|
+
if (candidate.customType !== MODE_CONTRACT_MESSAGE_TYPE) return undefined;
|
|
40
|
+
if (candidate.content === modeContractContent("plan")) return "plan";
|
|
41
|
+
if (candidate.content === modeContractContent("normal")) return "normal";
|
|
42
|
+
return undefined;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
export function hasModeContractArtifact(messages: readonly unknown[]) {
|
|
46
|
-
|
|
47
|
-
(message) => unwrapMessage(message).customType === MODE_CONTRACT_MESSAGE_TYPE,
|
|
48
|
-
);
|
|
46
|
+
return messages.some((message) => unwrapMessage(message).customType === MODE_CONTRACT_MESSAGE_TYPE);
|
|
49
47
|
}
|
|
50
48
|
|
|
51
49
|
export function latestModeContract(messages: readonly unknown[]) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
50
|
+
for (let index = messages.length - 1; index >= 0; index -= 1) {
|
|
51
|
+
const mode = modeContractFromMessage(messages[index]);
|
|
52
|
+
if (mode) return { index, mode };
|
|
53
|
+
}
|
|
54
|
+
return undefined;
|
|
57
55
|
}
|
|
58
56
|
|
|
59
57
|
export function reconcileModeContract(messages: unknown[], expected: PlanModeContract) {
|
|
60
|
-
|
|
61
|
-
|
|
58
|
+
const latest = latestModeContract(messages);
|
|
59
|
+
if (latest?.mode === expected) return messages;
|
|
62
60
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
];
|
|
61
|
+
const latestContractIndex = findLatestContractArtifactIndex(messages);
|
|
62
|
+
const insertionIndex = latestContractIndex >= 0 ? latestContractIndex + 1 : leadingSummaryBoundary(messages);
|
|
63
|
+
return [
|
|
64
|
+
...messages.slice(0, insertionIndex),
|
|
65
|
+
createModeContractMessage(expected, 0),
|
|
66
|
+
...messages.slice(insertionIndex),
|
|
67
|
+
];
|
|
71
68
|
}
|
|
72
69
|
|
|
73
70
|
function findLatestContractArtifactIndex(messages: readonly unknown[]) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
71
|
+
for (let index = messages.length - 1; index >= 0; index -= 1) {
|
|
72
|
+
if (unwrapMessage(messages[index]).customType === MODE_CONTRACT_MESSAGE_TYPE) return index;
|
|
73
|
+
}
|
|
74
|
+
return -1;
|
|
78
75
|
}
|
|
79
76
|
|
|
80
77
|
function leadingSummaryBoundary(messages: readonly unknown[]) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
78
|
+
let index = unwrapMessage(messages[0]).role === "system" ? 1 : 0;
|
|
79
|
+
while (index < messages.length) {
|
|
80
|
+
const role = unwrapMessage(messages[index]).role;
|
|
81
|
+
if (role !== "compactionSummary" && role !== "branchSummary") break;
|
|
82
|
+
index += 1;
|
|
83
|
+
}
|
|
84
|
+
return index;
|
|
88
85
|
}
|
|
89
86
|
|
|
90
87
|
function unwrapMessage(message: unknown): ContractMessage {
|
|
91
|
-
|
|
92
|
-
|
|
88
|
+
const entry = message as { message?: unknown } | undefined;
|
|
89
|
+
return (entry?.message ?? message ?? {}) as ContractMessage;
|
|
93
90
|
}
|
|
@@ -1,174 +1,153 @@
|
|
|
1
1
|
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import {
|
|
3
|
-
findAvailableImplementationModel,
|
|
4
|
-
snapshotAvailableImplementationModels,
|
|
5
|
-
} from "./implementation-models.js";
|
|
2
|
+
import { findAvailableImplementationModel, snapshotAvailableImplementationModels } from "./implementation-models.js";
|
|
6
3
|
import type { PlanExportDestination } from "./plan-export.js";
|
|
7
4
|
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
configuredImplementationModel,
|
|
6
|
+
configuredImplementationThinkingLevel,
|
|
7
|
+
type PlanModeFixedThinkingLevel,
|
|
8
|
+
type PlanModeSettings,
|
|
12
9
|
} from "./settings.js";
|
|
13
10
|
import type { ImplementationRuntimeSelection, PlanModeState } from "./state.js";
|
|
14
11
|
|
|
15
12
|
type InteractiveUi = typeof import("./interactive-ui.js");
|
|
16
13
|
|
|
17
14
|
interface MenuLifecycle {
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
signal: AbortSignal;
|
|
16
|
+
isCurrent(): boolean;
|
|
20
17
|
}
|
|
21
18
|
|
|
22
19
|
export type FreshImplementationTiming = "immediate" | "after-settled";
|
|
23
20
|
|
|
24
21
|
interface PlanActionControllerOptions {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
settings(ctx: ExtensionContext, signal: AbortSignal, isCurrent: () => boolean): Promise<boolean>;
|
|
49
|
-
save(ctx: ExtensionContext): void;
|
|
50
|
-
stay(ctx: ExtensionContext): void;
|
|
51
|
-
exitReady(ctx: ExtensionContext): void;
|
|
52
|
-
clearSaved(ctx: ExtensionContext): void;
|
|
22
|
+
loadInteractiveUi(): Promise<InteractiveUi>;
|
|
23
|
+
getState(): PlanModeState;
|
|
24
|
+
captureLifecycle(): MenuLifecycle;
|
|
25
|
+
statusText(): string;
|
|
26
|
+
getThinkingLevel(): PlanModeFixedThinkingLevel | undefined;
|
|
27
|
+
getSettings(): PlanModeSettings;
|
|
28
|
+
implementationOutcome(): string;
|
|
29
|
+
getExportDestination(ctx: ExtensionContext): PlanExportDestination;
|
|
30
|
+
show(ctx: ExtensionContext): void;
|
|
31
|
+
finalize(ctx: ExtensionContext): void;
|
|
32
|
+
implementHere(ctx: ExtensionContext): void | Promise<void>;
|
|
33
|
+
implementFresh(
|
|
34
|
+
ctx: ExtensionContext,
|
|
35
|
+
isCurrent: () => boolean,
|
|
36
|
+
runtime: ImplementationRuntimeSelection | undefined,
|
|
37
|
+
timing: FreshImplementationTiming,
|
|
38
|
+
): void | Promise<void>;
|
|
39
|
+
exportPlan(ctx: ExtensionContext, path: string, signal: AbortSignal, isCurrent: () => boolean): Promise<boolean>;
|
|
40
|
+
settings(ctx: ExtensionContext, signal: AbortSignal, isCurrent: () => boolean): Promise<boolean>;
|
|
41
|
+
save(ctx: ExtensionContext): void;
|
|
42
|
+
stay(ctx: ExtensionContext): void;
|
|
43
|
+
exitReady(ctx: ExtensionContext): void;
|
|
44
|
+
clearSaved(ctx: ExtensionContext): void;
|
|
53
45
|
}
|
|
54
46
|
|
|
55
47
|
export function createPlanActionController(options: PlanActionControllerOptions) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
runtime: ImplementationRuntimeSelection | undefined,
|
|
94
|
-
timing: FreshImplementationTiming,
|
|
95
|
-
) => {
|
|
96
|
-
if (signal.aborted) return;
|
|
97
|
-
const isCurrent =
|
|
98
|
-
timing === "after-settled"
|
|
99
|
-
? lifecycle.isCurrent
|
|
100
|
-
: () => lifecycle.isCurrent() && !signal.aborted;
|
|
101
|
-
return options.implementFresh(ctx, isCurrent, runtime, timing);
|
|
102
|
-
};
|
|
48
|
+
const configuredDefaults = (): ImplementationRuntimeSelection => {
|
|
49
|
+
const settings = options.getSettings();
|
|
50
|
+
const model = configuredImplementationModel(settings);
|
|
51
|
+
const thinkingLevel = configuredImplementationThinkingLevel(settings);
|
|
52
|
+
return {
|
|
53
|
+
...(model ? { model: { ...model } } : {}),
|
|
54
|
+
...(thinkingLevel ? { thinkingLevel } : {}),
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
const effectiveDefaults = (ctx: ExtensionContext): ImplementationRuntimeSelection => {
|
|
58
|
+
const configured = configuredDefaults();
|
|
59
|
+
const availableModel = findAvailableImplementationModel(
|
|
60
|
+
snapshotAvailableImplementationModels(ctx),
|
|
61
|
+
configured.model,
|
|
62
|
+
);
|
|
63
|
+
if (configured.model && !availableModel) {
|
|
64
|
+
ctx.ui.notify("The configured fresh implementation model is unavailable; using the planning model.", "warning");
|
|
65
|
+
}
|
|
66
|
+
const planModel = ctx.model ? { provider: ctx.model.provider, modelId: ctx.model.id } : undefined;
|
|
67
|
+
const model = availableModel ? { provider: availableModel.provider, modelId: availableModel.id } : planModel;
|
|
68
|
+
const thinkingLevel = configured.thinkingLevel ?? options.getThinkingLevel();
|
|
69
|
+
return {
|
|
70
|
+
...(model ? { model } : {}),
|
|
71
|
+
...(thinkingLevel ? { thinkingLevel } : {}),
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
const freshAction = (
|
|
75
|
+
ctx: ExtensionContext,
|
|
76
|
+
lifecycle: MenuLifecycle,
|
|
77
|
+
signal: AbortSignal,
|
|
78
|
+
runtime: ImplementationRuntimeSelection | undefined,
|
|
79
|
+
timing: FreshImplementationTiming,
|
|
80
|
+
) => {
|
|
81
|
+
if (signal.aborted) return;
|
|
82
|
+
const isCurrent = timing === "after-settled" ? lifecycle.isCurrent : () => lifecycle.isCurrent() && !signal.aborted;
|
|
83
|
+
return options.implementFresh(ctx, isCurrent, runtime, timing);
|
|
84
|
+
};
|
|
103
85
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
});
|
|
172
|
-
},
|
|
173
|
-
};
|
|
86
|
+
return {
|
|
87
|
+
async showSaved(ctx: ExtensionContext) {
|
|
88
|
+
const lifecycle = options.captureLifecycle();
|
|
89
|
+
if (!lifecycle.isCurrent() || lifecycle.signal.aborted) return;
|
|
90
|
+
const ui = await options.loadInteractiveUi();
|
|
91
|
+
if (!lifecycle.isCurrent() || lifecycle.signal.aborted) return;
|
|
92
|
+
await ui.showSavedPlanMenu(ctx, {
|
|
93
|
+
statusText: options.statusText(),
|
|
94
|
+
implementationOutcome: options.implementationOutcome,
|
|
95
|
+
getExportDestination: () => options.getExportDestination(ctx),
|
|
96
|
+
signal: lifecycle.signal,
|
|
97
|
+
isCurrent: lifecycle.isCurrent,
|
|
98
|
+
show: () => options.show(ctx),
|
|
99
|
+
implementHere: () => options.implementHere(ctx),
|
|
100
|
+
implementFresh: (signal) => freshAction(ctx, lifecycle, signal, effectiveDefaults(ctx), "immediate"),
|
|
101
|
+
exportPlan: (path, signal) => options.exportPlan(ctx, path, signal, lifecycle.isCurrent),
|
|
102
|
+
settings: (signal) => options.settings(ctx, signal, lifecycle.isCurrent),
|
|
103
|
+
clear: () => options.clearSaved(ctx),
|
|
104
|
+
});
|
|
105
|
+
},
|
|
106
|
+
async showCurrent(ctx: ExtensionContext) {
|
|
107
|
+
if (!ctx.hasUI) {
|
|
108
|
+
ctx.ui.notify(options.statusText(), "info");
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const lifecycle = options.captureLifecycle();
|
|
112
|
+
if (!lifecycle.isCurrent() || lifecycle.signal.aborted) return;
|
|
113
|
+
const ui = await options.loadInteractiveUi();
|
|
114
|
+
if (!lifecycle.isCurrent() || lifecycle.signal.aborted) return;
|
|
115
|
+
await ui.showPlanModeMenu(ctx, {
|
|
116
|
+
statusText: options.statusText(),
|
|
117
|
+
planThinkingLevel: options.getThinkingLevel(),
|
|
118
|
+
implementationDefaults: configuredDefaults(),
|
|
119
|
+
hasReadyPlan: options.getState().latestPlan !== undefined,
|
|
120
|
+
implementationOutcome: options.implementationOutcome,
|
|
121
|
+
getExportDestination: () => options.getExportDestination(ctx),
|
|
122
|
+
...lifecycle,
|
|
123
|
+
show: () => options.show(ctx),
|
|
124
|
+
finalize: () => options.finalize(ctx),
|
|
125
|
+
implementHere: () => options.implementHere(ctx),
|
|
126
|
+
implementFresh: (runtime, signal) => freshAction(ctx, lifecycle, signal, runtime, "immediate"),
|
|
127
|
+
exportPlan: (path, signal) => options.exportPlan(ctx, path, signal, lifecycle.isCurrent),
|
|
128
|
+
save: () => options.save(ctx),
|
|
129
|
+
stay: () => options.stay(ctx),
|
|
130
|
+
exit: () => options.exitReady(ctx),
|
|
131
|
+
});
|
|
132
|
+
},
|
|
133
|
+
async showReady(ctx: ExtensionContext) {
|
|
134
|
+
const lifecycle = options.captureLifecycle();
|
|
135
|
+
if (!lifecycle.isCurrent() || lifecycle.signal.aborted) return;
|
|
136
|
+
const ui = await options.loadInteractiveUi();
|
|
137
|
+
if (!lifecycle.isCurrent() || lifecycle.signal.aborted) return;
|
|
138
|
+
await ui.showReadyPlanMenu(ctx, {
|
|
139
|
+
...lifecycle,
|
|
140
|
+
planThinkingLevel: options.getThinkingLevel(),
|
|
141
|
+
implementationDefaults: configuredDefaults(),
|
|
142
|
+
implementationOutcome: options.implementationOutcome,
|
|
143
|
+
getExportDestination: () => options.getExportDestination(ctx),
|
|
144
|
+
implementHere: () => options.implementHere(ctx),
|
|
145
|
+
implementFresh: (runtime, signal) => freshAction(ctx, lifecycle, signal, runtime, "after-settled"),
|
|
146
|
+
exportPlan: (path, signal) => options.exportPlan(ctx, path, signal, lifecycle.isCurrent),
|
|
147
|
+
save: () => options.save(ctx),
|
|
148
|
+
stay: () => undefined,
|
|
149
|
+
exit: () => options.exitReady(ctx),
|
|
150
|
+
});
|
|
151
|
+
},
|
|
152
|
+
};
|
|
174
153
|
}
|