@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/src/state.ts
CHANGED
|
@@ -1,197 +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
|
-
|
|
8
|
+
IMPLEMENTATION_PLAN_RETENTIONS,
|
|
9
|
+
type ImplementationPlanRetention,
|
|
10
|
+
PLAN_MODE_THINKING_LEVELS,
|
|
11
|
+
type PlanModeFixedThinkingLevel,
|
|
11
12
|
} from "./settings.js";
|
|
12
13
|
|
|
14
|
+
export type { ImplementationModelOverride } from "./implementation-models.js";
|
|
15
|
+
export {
|
|
16
|
+
isPendingImplementationModelIdentifier,
|
|
17
|
+
MAX_PENDING_IMPLEMENTATION_MODEL_IDENTIFIER_LENGTH,
|
|
18
|
+
} from "./implementation-models.js";
|
|
19
|
+
|
|
13
20
|
export type PlanCompletionSource = typeof PLAN_MODE_COMPLETE_TOOL_NAME | "legacy_proposed_plan";
|
|
14
21
|
|
|
15
22
|
export interface ActiveImplementationPlan {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
23
|
+
id: string;
|
|
24
|
+
plan: string;
|
|
25
|
+
source: PlanCompletionSource;
|
|
26
|
+
startedAt: number;
|
|
27
|
+
retention?: ImplementationPlanRetention;
|
|
21
28
|
}
|
|
22
29
|
|
|
23
30
|
export interface SavedPlan {
|
|
24
|
-
|
|
25
|
-
|
|
31
|
+
plan: string;
|
|
32
|
+
source: PlanCompletionSource;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface ImplementationRuntimeSelection {
|
|
36
|
+
model?: ImplementationModelOverride;
|
|
37
|
+
thinkingLevel?: PlanModeFixedThinkingLevel;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface PendingImplementationRuntime extends ImplementationRuntimeSelection {
|
|
41
|
+
version: 1;
|
|
26
42
|
}
|
|
27
43
|
|
|
28
44
|
export interface PlanModeWorkflowToolPolicy {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
45
|
+
kind: "automatic" | "explicit";
|
|
46
|
+
desiredNames?: string[];
|
|
47
|
+
allowedNames: string[];
|
|
48
|
+
resolved: boolean;
|
|
33
49
|
}
|
|
34
50
|
|
|
35
51
|
export interface PlanModeState {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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;
|
|
48
65
|
}
|
|
49
66
|
|
|
50
67
|
type SessionEntry = {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
68
|
+
type?: string;
|
|
69
|
+
customType?: string;
|
|
70
|
+
data?: unknown;
|
|
71
|
+
message?: {
|
|
72
|
+
role?: string;
|
|
73
|
+
toolName?: string;
|
|
74
|
+
details?: unknown;
|
|
75
|
+
};
|
|
59
76
|
};
|
|
60
77
|
|
|
61
78
|
export function restorePlanModeState(entries: unknown[], stateEntryType: string): PlanModeState {
|
|
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
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
? fixedThinkingLevel(entry.data.previousThinkingLevel)
|
|
102
|
-
: undefined,
|
|
103
|
-
appliedThinkingLevel: enabled ? fixedThinkingLevel(entry.data.appliedThinkingLevel) : undefined,
|
|
104
|
-
manualThinkingLevel: enabled ? fixedThinkingLevel(entry.data.manualThinkingLevel) : undefined,
|
|
105
|
-
};
|
|
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
|
+
};
|
|
106
118
|
}
|
|
107
119
|
|
|
108
120
|
function normalizeWorkflowToolPolicy(value: unknown): PlanModeWorkflowToolPolicy | undefined {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
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 };
|
|
125
137
|
}
|
|
126
138
|
|
|
127
139
|
function normalizeSavedPlan(value: unknown): SavedPlan | undefined {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
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
|
+
};
|
|
133
173
|
}
|
|
134
174
|
|
|
135
175
|
function normalizeActiveImplementation(value: unknown): ActiveImplementationPlan | undefined {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
if (!id || !source || !normalized.ok || startedAt === undefined) return undefined;
|
|
150
|
-
const retention = IMPLEMENTATION_PLAN_RETENTIONS.includes(
|
|
151
|
-
value.retention as ImplementationPlanRetention,
|
|
152
|
-
)
|
|
153
|
-
? (value.retention as ImplementationPlanRetention)
|
|
154
|
-
: "keep";
|
|
155
|
-
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 };
|
|
156
189
|
}
|
|
157
190
|
|
|
158
191
|
function normalizePersistedPlan(value: unknown) {
|
|
159
|
-
|
|
160
|
-
|
|
192
|
+
const normalized = normalizePlanModeCompletion({ plan: value });
|
|
193
|
+
return normalized.ok ? normalized.plan : undefined;
|
|
161
194
|
}
|
|
162
195
|
|
|
163
196
|
function latestCompletionPlan(entries: SessionEntry[]) {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
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;
|
|
173
206
|
}
|
|
174
207
|
|
|
175
208
|
function planCompletionSource(value: unknown): PlanCompletionSource | undefined {
|
|
176
|
-
|
|
177
|
-
? value
|
|
178
|
-
: undefined;
|
|
209
|
+
return value === PLAN_MODE_COMPLETE_TOOL_NAME || value === "legacy_proposed_plan" ? value : undefined;
|
|
179
210
|
}
|
|
180
211
|
|
|
181
212
|
function fixedThinkingLevel(value: unknown): PlanModeFixedThinkingLevel | undefined {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
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;
|
|
187
218
|
}
|
|
188
219
|
|
|
189
220
|
function stringArray(value: unknown) {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
221
|
+
return Array.isArray(value) && value.every((item): item is string => typeof item === "string")
|
|
222
|
+
? Array.from(new Set(value))
|
|
223
|
+
: undefined;
|
|
193
224
|
}
|
|
194
225
|
|
|
195
226
|
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
196
|
-
|
|
227
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
197
228
|
}
|