@narumitw/pi-plan-mode 0.58.0 → 0.58.2
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-L2CXUWCH.ts} +29 -111
- package/dist/chunks/chunk-L2CXUWCH.ts.map +7 -0
- package/dist/chunks/{interactive-ui-UNJGC2RQ.js → interactive-ui-VHZ5GODE.ts} +13 -41
- package/dist/chunks/interactive-ui-VHZ5GODE.ts.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/state.ts
CHANGED
|
@@ -1,259 +1,228 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
normalizePlanModeCompletion,
|
|
3
|
+
PLAN_MODE_COMPLETE_TOOL_NAME,
|
|
4
|
+
planFromCompletionDetails,
|
|
5
5
|
} from "./completion-tool.js";
|
|
6
|
+
import { type ImplementationModelOverride, isPendingImplementationModelIdentifier } from "./implementation-models.js";
|
|
6
7
|
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
IMPLEMENTATION_PLAN_RETENTIONS,
|
|
12
|
-
type ImplementationPlanRetention,
|
|
13
|
-
PLAN_MODE_THINKING_LEVELS,
|
|
14
|
-
type PlanModeFixedThinkingLevel,
|
|
8
|
+
IMPLEMENTATION_PLAN_RETENTIONS,
|
|
9
|
+
type ImplementationPlanRetention,
|
|
10
|
+
PLAN_MODE_THINKING_LEVELS,
|
|
11
|
+
type PlanModeFixedThinkingLevel,
|
|
15
12
|
} from "./settings.js";
|
|
16
13
|
|
|
17
14
|
export type { ImplementationModelOverride } from "./implementation-models.js";
|
|
18
15
|
export {
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
isPendingImplementationModelIdentifier,
|
|
17
|
+
MAX_PENDING_IMPLEMENTATION_MODEL_IDENTIFIER_LENGTH,
|
|
21
18
|
} from "./implementation-models.js";
|
|
22
19
|
|
|
23
20
|
export type PlanCompletionSource = typeof PLAN_MODE_COMPLETE_TOOL_NAME | "legacy_proposed_plan";
|
|
24
21
|
|
|
25
22
|
export interface ActiveImplementationPlan {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
23
|
+
id: string;
|
|
24
|
+
plan: string;
|
|
25
|
+
source: PlanCompletionSource;
|
|
26
|
+
startedAt: number;
|
|
27
|
+
retention?: ImplementationPlanRetention;
|
|
31
28
|
}
|
|
32
29
|
|
|
33
30
|
export interface SavedPlan {
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
plan: string;
|
|
32
|
+
source: PlanCompletionSource;
|
|
36
33
|
}
|
|
37
34
|
|
|
38
35
|
export interface ImplementationRuntimeSelection {
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
model?: ImplementationModelOverride;
|
|
37
|
+
thinkingLevel?: PlanModeFixedThinkingLevel;
|
|
41
38
|
}
|
|
42
39
|
|
|
43
40
|
export interface PendingImplementationRuntime extends ImplementationRuntimeSelection {
|
|
44
|
-
|
|
41
|
+
version: 1;
|
|
45
42
|
}
|
|
46
43
|
|
|
47
44
|
export interface PlanModeWorkflowToolPolicy {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
45
|
+
kind: "automatic" | "explicit";
|
|
46
|
+
desiredNames?: string[];
|
|
47
|
+
allowedNames: string[];
|
|
48
|
+
resolved: boolean;
|
|
52
49
|
}
|
|
53
50
|
|
|
54
51
|
export interface PlanModeState {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
52
|
+
enabled: boolean;
|
|
53
|
+
latestPlan?: string;
|
|
54
|
+
latestPlanSource?: PlanCompletionSource;
|
|
55
|
+
awaitingAction: boolean;
|
|
56
|
+
savedPlan?: SavedPlan;
|
|
57
|
+
activeImplementation?: ActiveImplementationPlan;
|
|
58
|
+
pendingImplementationRuntime?: PendingImplementationRuntime;
|
|
59
|
+
selectedToolNames?: string[];
|
|
60
|
+
selectedToolKeys?: string[];
|
|
61
|
+
workflowToolPolicy?: PlanModeWorkflowToolPolicy;
|
|
62
|
+
previousThinkingLevel?: PlanModeFixedThinkingLevel;
|
|
63
|
+
appliedThinkingLevel?: PlanModeFixedThinkingLevel;
|
|
64
|
+
manualThinkingLevel?: PlanModeFixedThinkingLevel;
|
|
68
65
|
}
|
|
69
66
|
|
|
70
67
|
type SessionEntry = {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
68
|
+
type?: string;
|
|
69
|
+
customType?: string;
|
|
70
|
+
data?: unknown;
|
|
71
|
+
message?: {
|
|
72
|
+
role?: string;
|
|
73
|
+
toolName?: string;
|
|
74
|
+
details?: unknown;
|
|
75
|
+
};
|
|
79
76
|
};
|
|
80
77
|
|
|
81
78
|
export function restorePlanModeState(entries: unknown[], stateEntryType: string): PlanModeState {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
workflowToolPolicy: enabled
|
|
122
|
-
? normalizeWorkflowToolPolicy(entry.data.workflowToolPolicy)
|
|
123
|
-
: undefined,
|
|
124
|
-
previousThinkingLevel: enabled
|
|
125
|
-
? fixedThinkingLevel(entry.data.previousThinkingLevel)
|
|
126
|
-
: undefined,
|
|
127
|
-
appliedThinkingLevel: enabled ? fixedThinkingLevel(entry.data.appliedThinkingLevel) : undefined,
|
|
128
|
-
manualThinkingLevel: enabled ? fixedThinkingLevel(entry.data.manualThinkingLevel) : undefined,
|
|
129
|
-
};
|
|
79
|
+
const branch = entries as SessionEntry[];
|
|
80
|
+
let stateEntryIndex = -1;
|
|
81
|
+
for (let index = branch.length - 1; index >= 0; index -= 1) {
|
|
82
|
+
const candidate = branch[index];
|
|
83
|
+
if (candidate?.type === "custom" && candidate.customType === stateEntryType) {
|
|
84
|
+
stateEntryIndex = index;
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
const entry = branch[stateEntryIndex];
|
|
89
|
+
if (!isRecord(entry?.data)) return { enabled: false, awaitingAction: false };
|
|
90
|
+
|
|
91
|
+
const enabled = entry.data.enabled === true;
|
|
92
|
+
const persistedSource = enabled ? planCompletionSource(entry.data.latestPlanSource) : undefined;
|
|
93
|
+
const persistedPlan = enabled ? normalizePersistedPlan(entry.data.latestPlan) : undefined;
|
|
94
|
+
const recoveredPlan = enabled && !persistedPlan ? latestCompletionPlan(branch.slice(stateEntryIndex + 1)) : undefined;
|
|
95
|
+
const latestPlan = persistedPlan ?? recoveredPlan;
|
|
96
|
+
const activeImplementation = enabled ? undefined : normalizeActiveImplementation(entry.data.activeImplementation);
|
|
97
|
+
const savedPlan = enabled || activeImplementation ? undefined : normalizeSavedPlan(entry.data.savedPlan);
|
|
98
|
+
const pendingImplementationRuntime = enabled
|
|
99
|
+
? undefined
|
|
100
|
+
: normalizePendingImplementationRuntime(entry.data.pendingImplementationRuntime);
|
|
101
|
+
return {
|
|
102
|
+
enabled,
|
|
103
|
+
latestPlan,
|
|
104
|
+
latestPlanSource: enabled
|
|
105
|
+
? ((persistedPlan ? persistedSource : undefined) ?? (recoveredPlan ? PLAN_MODE_COMPLETE_TOOL_NAME : undefined))
|
|
106
|
+
: undefined,
|
|
107
|
+
awaitingAction: enabled && latestPlan !== undefined,
|
|
108
|
+
savedPlan,
|
|
109
|
+
activeImplementation,
|
|
110
|
+
pendingImplementationRuntime,
|
|
111
|
+
selectedToolNames: stringArray(entry.data.selectedToolNames),
|
|
112
|
+
selectedToolKeys: stringArray(entry.data.selectedToolKeys),
|
|
113
|
+
workflowToolPolicy: enabled ? normalizeWorkflowToolPolicy(entry.data.workflowToolPolicy) : undefined,
|
|
114
|
+
previousThinkingLevel: enabled ? fixedThinkingLevel(entry.data.previousThinkingLevel) : undefined,
|
|
115
|
+
appliedThinkingLevel: enabled ? fixedThinkingLevel(entry.data.appliedThinkingLevel) : undefined,
|
|
116
|
+
manualThinkingLevel: enabled ? fixedThinkingLevel(entry.data.manualThinkingLevel) : undefined,
|
|
117
|
+
};
|
|
130
118
|
}
|
|
131
119
|
|
|
132
120
|
function normalizeWorkflowToolPolicy(value: unknown): PlanModeWorkflowToolPolicy | undefined {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
121
|
+
if (value === undefined) return undefined;
|
|
122
|
+
const denied: PlanModeWorkflowToolPolicy = {
|
|
123
|
+
kind: "automatic",
|
|
124
|
+
allowedNames: [],
|
|
125
|
+
resolved: true,
|
|
126
|
+
};
|
|
127
|
+
if (!isRecord(value)) return denied;
|
|
128
|
+
const kind = value.kind === "automatic" || value.kind === "explicit" ? value.kind : undefined;
|
|
129
|
+
const allowedNames = stringArray(value.allowedNames);
|
|
130
|
+
if (!kind || !allowedNames || typeof value.resolved !== "boolean") return denied;
|
|
131
|
+
if (kind === "automatic") {
|
|
132
|
+
return { kind, allowedNames, resolved: value.resolved };
|
|
133
|
+
}
|
|
134
|
+
const desiredNames = stringArray(value.desiredNames);
|
|
135
|
+
if (!desiredNames) return denied;
|
|
136
|
+
return { kind, desiredNames, allowedNames, resolved: value.resolved };
|
|
149
137
|
}
|
|
150
138
|
|
|
151
139
|
function normalizeSavedPlan(value: unknown): SavedPlan | undefined {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
function normalizePendingImplementationRuntime(
|
|
160
|
-
|
|
161
|
-
)
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
}
|
|
186
|
-
const thinkingLevel =
|
|
187
|
-
value.thinkingLevel === undefined ? undefined : fixedThinkingLevel(value.thinkingLevel);
|
|
188
|
-
if (value.thinkingLevel !== undefined && !thinkingLevel) return undefined;
|
|
189
|
-
if (!model && !thinkingLevel) return undefined;
|
|
190
|
-
return {
|
|
191
|
-
version: 1,
|
|
192
|
-
...(model ? { model } : {}),
|
|
193
|
-
...(thinkingLevel ? { thinkingLevel } : {}),
|
|
194
|
-
};
|
|
140
|
+
if (!isRecord(value)) return undefined;
|
|
141
|
+
const source = planCompletionSource(value.source);
|
|
142
|
+
const normalized = normalizePlanModeCompletion({ plan: value.plan });
|
|
143
|
+
if (!source || !normalized.ok) return undefined;
|
|
144
|
+
return { plan: normalized.plan, source };
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function normalizePendingImplementationRuntime(value: unknown): PendingImplementationRuntime | undefined {
|
|
148
|
+
if (!isRecord(value) || value.version !== 1) return undefined;
|
|
149
|
+
if (Object.keys(value).some((key) => key !== "version" && key !== "model" && key !== "thinkingLevel")) {
|
|
150
|
+
return undefined;
|
|
151
|
+
}
|
|
152
|
+
let model: ImplementationModelOverride | undefined;
|
|
153
|
+
if (value.model !== undefined) {
|
|
154
|
+
if (!isRecord(value.model) || Object.keys(value.model).some((key) => key !== "provider" && key !== "modelId")) {
|
|
155
|
+
return undefined;
|
|
156
|
+
}
|
|
157
|
+
if (
|
|
158
|
+
!isPendingImplementationModelIdentifier(value.model.provider) ||
|
|
159
|
+
!isPendingImplementationModelIdentifier(value.model.modelId)
|
|
160
|
+
) {
|
|
161
|
+
return undefined;
|
|
162
|
+
}
|
|
163
|
+
model = { provider: value.model.provider, modelId: value.model.modelId };
|
|
164
|
+
}
|
|
165
|
+
const thinkingLevel = value.thinkingLevel === undefined ? undefined : fixedThinkingLevel(value.thinkingLevel);
|
|
166
|
+
if (value.thinkingLevel !== undefined && !thinkingLevel) return undefined;
|
|
167
|
+
if (!model && !thinkingLevel) return undefined;
|
|
168
|
+
return {
|
|
169
|
+
version: 1,
|
|
170
|
+
...(model ? { model } : {}),
|
|
171
|
+
...(thinkingLevel ? { thinkingLevel } : {}),
|
|
172
|
+
};
|
|
195
173
|
}
|
|
196
174
|
|
|
197
175
|
function normalizeActiveImplementation(value: unknown): ActiveImplementationPlan | undefined {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
if (!id || !source || !normalized.ok || startedAt === undefined) return undefined;
|
|
212
|
-
const retention = IMPLEMENTATION_PLAN_RETENTIONS.includes(
|
|
213
|
-
value.retention as ImplementationPlanRetention,
|
|
214
|
-
)
|
|
215
|
-
? (value.retention as ImplementationPlanRetention)
|
|
216
|
-
: "keep";
|
|
217
|
-
return { id, plan: normalized.plan, source, startedAt, retention };
|
|
176
|
+
if (!isRecord(value)) return undefined;
|
|
177
|
+
const id = typeof value.id === "string" && /^[A-Za-z0-9._:-]{1,128}$/u.test(value.id) ? value.id : undefined;
|
|
178
|
+
const source = planCompletionSource(value.source);
|
|
179
|
+
const normalized = normalizePlanModeCompletion({ plan: value.plan });
|
|
180
|
+
const startedAt =
|
|
181
|
+
typeof value.startedAt === "number" && Number.isSafeInteger(value.startedAt) && value.startedAt >= 0
|
|
182
|
+
? value.startedAt
|
|
183
|
+
: undefined;
|
|
184
|
+
if (!id || !source || !normalized.ok || startedAt === undefined) return undefined;
|
|
185
|
+
const retention = IMPLEMENTATION_PLAN_RETENTIONS.includes(value.retention as ImplementationPlanRetention)
|
|
186
|
+
? (value.retention as ImplementationPlanRetention)
|
|
187
|
+
: "keep";
|
|
188
|
+
return { id, plan: normalized.plan, source, startedAt, retention };
|
|
218
189
|
}
|
|
219
190
|
|
|
220
191
|
function normalizePersistedPlan(value: unknown) {
|
|
221
|
-
|
|
222
|
-
|
|
192
|
+
const normalized = normalizePlanModeCompletion({ plan: value });
|
|
193
|
+
return normalized.ok ? normalized.plan : undefined;
|
|
223
194
|
}
|
|
224
195
|
|
|
225
196
|
function latestCompletionPlan(entries: SessionEntry[]) {
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
197
|
+
for (let index = entries.length - 1; index >= 0; index -= 1) {
|
|
198
|
+
const message = entries[index]?.message;
|
|
199
|
+
if (message?.role !== "toolResult" || message.toolName !== PLAN_MODE_COMPLETE_TOOL_NAME) {
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
const plan = planFromCompletionDetails(message.details);
|
|
203
|
+
if (plan) return plan;
|
|
204
|
+
}
|
|
205
|
+
return undefined;
|
|
235
206
|
}
|
|
236
207
|
|
|
237
208
|
function planCompletionSource(value: unknown): PlanCompletionSource | undefined {
|
|
238
|
-
|
|
239
|
-
? value
|
|
240
|
-
: undefined;
|
|
209
|
+
return value === PLAN_MODE_COMPLETE_TOOL_NAME || value === "legacy_proposed_plan" ? value : undefined;
|
|
241
210
|
}
|
|
242
211
|
|
|
243
212
|
function fixedThinkingLevel(value: unknown): PlanModeFixedThinkingLevel | undefined {
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
213
|
+
return typeof value === "string" &&
|
|
214
|
+
value !== "inherit" &&
|
|
215
|
+
PLAN_MODE_THINKING_LEVELS.includes(value as (typeof PLAN_MODE_THINKING_LEVELS)[number])
|
|
216
|
+
? (value as PlanModeFixedThinkingLevel)
|
|
217
|
+
: undefined;
|
|
249
218
|
}
|
|
250
219
|
|
|
251
220
|
function stringArray(value: unknown) {
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
221
|
+
return Array.isArray(value) && value.every((item): item is string => typeof item === "string")
|
|
222
|
+
? Array.from(new Set(value))
|
|
223
|
+
: undefined;
|
|
255
224
|
}
|
|
256
225
|
|
|
257
226
|
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
258
|
-
|
|
227
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
259
228
|
}
|