@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/question-tool.ts
CHANGED
|
@@ -1,328 +1,300 @@
|
|
|
1
1
|
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import type {
|
|
3
|
-
QuestionnaireAnswer,
|
|
4
|
-
QuestionnaireQuestion,
|
|
5
|
-
RunQuestionnaireResult,
|
|
6
|
-
} from "@narumitw/pi-tui-kit";
|
|
2
|
+
import type { QuestionnaireAnswer, QuestionnaireQuestion, RunQuestionnaireResult } from "@narumitw/pi-tui-kit";
|
|
7
3
|
|
|
8
4
|
export const PLAN_MODE_QUESTION_TOOL_NAME = "plan_mode_question";
|
|
9
5
|
export const MAX_PLAN_MODE_RESPONSE_LENGTH = 4_000;
|
|
10
6
|
|
|
11
7
|
export type PlanModeQuestionOption = {
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
label: string;
|
|
9
|
+
description?: string;
|
|
14
10
|
};
|
|
15
11
|
|
|
16
12
|
export type PlanModeQuestion = {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
13
|
+
id: string;
|
|
14
|
+
header: string;
|
|
15
|
+
question: string;
|
|
16
|
+
options: PlanModeQuestionOption[];
|
|
21
17
|
};
|
|
22
18
|
|
|
23
19
|
export type PlanModeQuestionAnswer = {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
20
|
+
id: string;
|
|
21
|
+
header: string;
|
|
22
|
+
question: string;
|
|
23
|
+
answer: string;
|
|
24
|
+
wasCustom: boolean;
|
|
25
|
+
optionIndex?: number;
|
|
26
|
+
note?: string;
|
|
31
27
|
};
|
|
32
28
|
|
|
33
|
-
type PlanModeQuestionReason =
|
|
34
|
-
| "cancelled"
|
|
35
|
-
| "ui_unavailable"
|
|
36
|
-
| "plan_mode_inactive"
|
|
37
|
-
| "invalid_input";
|
|
29
|
+
type PlanModeQuestionReason = "cancelled" | "ui_unavailable" | "plan_mode_inactive" | "invalid_input";
|
|
38
30
|
|
|
39
31
|
type PlanModeQuestionDetails = {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
32
|
+
cancelled: boolean;
|
|
33
|
+
reason?: PlanModeQuestionReason;
|
|
34
|
+
questions: PlanModeQuestion[];
|
|
35
|
+
answers?: PlanModeQuestionAnswer[];
|
|
44
36
|
};
|
|
45
37
|
|
|
46
38
|
export const PLAN_MODE_QUESTION_PARAMS = {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
-
|
|
39
|
+
type: "object",
|
|
40
|
+
additionalProperties: false,
|
|
41
|
+
required: ["questions"],
|
|
42
|
+
properties: {
|
|
43
|
+
questions: {
|
|
44
|
+
type: "array",
|
|
45
|
+
minItems: 1,
|
|
46
|
+
maxItems: 3,
|
|
47
|
+
description: "Questions to show the user. Prefer 1 and do not exceed 3.",
|
|
48
|
+
items: {
|
|
49
|
+
type: "object",
|
|
50
|
+
additionalProperties: false,
|
|
51
|
+
required: ["id", "header", "question", "options"],
|
|
52
|
+
properties: {
|
|
53
|
+
id: {
|
|
54
|
+
type: "string",
|
|
55
|
+
description: "Stable identifier for mapping answers (snake_case).",
|
|
56
|
+
},
|
|
57
|
+
header: {
|
|
58
|
+
type: "string",
|
|
59
|
+
description: "Short header label shown in the UI (12 or fewer chars).",
|
|
60
|
+
},
|
|
61
|
+
question: { type: "string", description: "Single-sentence prompt shown to the user." },
|
|
62
|
+
options: {
|
|
63
|
+
type: "array",
|
|
64
|
+
minItems: 2,
|
|
65
|
+
maxItems: 4,
|
|
66
|
+
description:
|
|
67
|
+
"Provide 2-4 mutually exclusive choices. Put the recommended option first when there is a clear default.",
|
|
68
|
+
items: {
|
|
69
|
+
type: "object",
|
|
70
|
+
additionalProperties: false,
|
|
71
|
+
required: ["label", "description"],
|
|
72
|
+
properties: {
|
|
73
|
+
label: { type: "string", description: "User-facing label (1-5 words)." },
|
|
74
|
+
description: {
|
|
75
|
+
type: "string",
|
|
76
|
+
description: "One short sentence explaining impact/tradeoff if selected.",
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
},
|
|
93
85
|
} as const;
|
|
94
86
|
|
|
95
|
-
type NormalizePlanModeQuestionParamsResult =
|
|
96
|
-
| { ok: true; questions: PlanModeQuestion[] }
|
|
97
|
-
| { ok: false; error: string };
|
|
87
|
+
type NormalizePlanModeQuestionParamsResult = { ok: true; questions: PlanModeQuestion[] } | { ok: false; error: string };
|
|
98
88
|
|
|
99
|
-
export function normalizePlanModeQuestionParams(
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
return { ok: false, error: "questions must contain 1-3 items" };
|
|
107
|
-
}
|
|
89
|
+
export function normalizePlanModeQuestionParams(input: unknown): NormalizePlanModeQuestionParamsResult {
|
|
90
|
+
if (!isRecord(input) || !Array.isArray(input.questions)) {
|
|
91
|
+
return { ok: false, error: "questions must be an array" };
|
|
92
|
+
}
|
|
93
|
+
if (input.questions.length < 1 || input.questions.length > 3) {
|
|
94
|
+
return { ok: false, error: "questions must contain 1-3 items" };
|
|
95
|
+
}
|
|
108
96
|
|
|
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
|
-
|
|
97
|
+
const questions: PlanModeQuestion[] = [];
|
|
98
|
+
for (const [questionIndex, rawQuestion] of input.questions.entries()) {
|
|
99
|
+
if (!isRecord(rawQuestion)) {
|
|
100
|
+
return { ok: false, error: `question ${questionIndex + 1} must be an object` };
|
|
101
|
+
}
|
|
102
|
+
const id = stringField(rawQuestion.id);
|
|
103
|
+
const header = stringField(rawQuestion.header);
|
|
104
|
+
const question = stringField(rawQuestion.question);
|
|
105
|
+
if (!id || !header || !question) {
|
|
106
|
+
return {
|
|
107
|
+
ok: false,
|
|
108
|
+
error: `question ${questionIndex + 1} requires non-empty id, header, and question`,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
if (!Array.isArray(rawQuestion.options)) {
|
|
112
|
+
return { ok: false, error: `question ${questionIndex + 1} options must be an array` };
|
|
113
|
+
}
|
|
114
|
+
if (rawQuestion.options.length < 2 || rawQuestion.options.length > 4) {
|
|
115
|
+
return { ok: false, error: `question ${questionIndex + 1} options must contain 2-4 items` };
|
|
116
|
+
}
|
|
117
|
+
const options: PlanModeQuestionOption[] = [];
|
|
118
|
+
for (const [optionIndex, rawOption] of rawQuestion.options.entries()) {
|
|
119
|
+
if (!isRecord(rawOption)) {
|
|
120
|
+
return {
|
|
121
|
+
ok: false,
|
|
122
|
+
error: `question ${questionIndex + 1} option ${optionIndex + 1} must be an object`,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
const label = stringField(rawOption.label);
|
|
126
|
+
if (!label) {
|
|
127
|
+
return {
|
|
128
|
+
ok: false,
|
|
129
|
+
error: `question ${questionIndex + 1} option ${optionIndex + 1} requires a label`,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
const description = stringField(rawOption.description);
|
|
133
|
+
if (!description) {
|
|
134
|
+
return {
|
|
135
|
+
ok: false,
|
|
136
|
+
error: `question ${questionIndex + 1} option ${optionIndex + 1} requires a description`,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
options.push({ label, description });
|
|
140
|
+
}
|
|
141
|
+
questions.push({ id, header, question, options });
|
|
142
|
+
}
|
|
143
|
+
return { ok: true, questions };
|
|
156
144
|
}
|
|
157
145
|
|
|
158
146
|
export async function answerPlanModeQuestions(
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
147
|
+
questions: PlanModeQuestion[],
|
|
148
|
+
ctx: ExtensionContext,
|
|
149
|
+
lifecycle: { isCurrent(): boolean; isEnabled(): boolean },
|
|
162
150
|
) {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
if (!answers) {
|
|
183
|
-
return planModeQuestionCancelled(
|
|
184
|
-
questions,
|
|
185
|
-
"cancelled",
|
|
186
|
-
"User cancelled the Plan-mode question prompt.",
|
|
187
|
-
);
|
|
188
|
-
}
|
|
189
|
-
return planModeQuestionAnswered(questions, answers);
|
|
151
|
+
const answers = await askPlanModeQuestions(questions, ctx, () => lifecycle.isCurrent() && lifecycle.isEnabled());
|
|
152
|
+
if (!lifecycle.isCurrent()) {
|
|
153
|
+
return planModeQuestionCancelled(
|
|
154
|
+
questions,
|
|
155
|
+
"cancelled",
|
|
156
|
+
"Plan-mode question cancelled because the session changed.",
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
if (!lifecycle.isEnabled()) {
|
|
160
|
+
return planModeQuestionCancelled(
|
|
161
|
+
questions,
|
|
162
|
+
"plan_mode_inactive",
|
|
163
|
+
"Plan-mode question cancelled because Plan mode is no longer active.",
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
if (!answers) {
|
|
167
|
+
return planModeQuestionCancelled(questions, "cancelled", "User cancelled the Plan-mode question prompt.");
|
|
168
|
+
}
|
|
169
|
+
return planModeQuestionAnswered(questions, answers);
|
|
190
170
|
}
|
|
191
171
|
|
|
192
172
|
export async function askPlanModeQuestions(
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
173
|
+
questions: PlanModeQuestion[],
|
|
174
|
+
ctx: ExtensionContext,
|
|
175
|
+
shouldContinue: () => boolean = () => true,
|
|
196
176
|
): Promise<PlanModeQuestionAnswer[] | undefined> {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
177
|
+
const { runQuestionnaire, sanitizeTerminalText } = await import("@narumitw/pi-tui-kit");
|
|
178
|
+
if (!shouldContinue()) return undefined;
|
|
179
|
+
const runnerQuestions: QuestionnaireQuestion<string>[] = questions.map((question, index) => ({
|
|
180
|
+
id: String(index),
|
|
181
|
+
header: displayText(question.header, `Question ${index + 1}`, sanitizeTerminalText),
|
|
182
|
+
prompt: displayText(question.question, `Question ${index + 1}`, sanitizeTerminalText),
|
|
183
|
+
options: question.options.map((option, optionIndex) => ({
|
|
184
|
+
...option,
|
|
185
|
+
label: displayText(option.label, `Option ${optionIndex + 1}`, sanitizeTerminalText),
|
|
186
|
+
})),
|
|
187
|
+
}));
|
|
188
|
+
const result = await runQuestionnaire(ctx, {
|
|
189
|
+
questions: runnerQuestions,
|
|
190
|
+
allowNotes: true,
|
|
191
|
+
maxTextLength: MAX_PLAN_MODE_RESPONSE_LENGTH,
|
|
192
|
+
signal: ctx.signal,
|
|
193
|
+
isCurrent: shouldContinue,
|
|
194
|
+
});
|
|
195
|
+
if (!shouldContinue()) return undefined;
|
|
196
|
+
return mapQuestionnaireResult(questions, result);
|
|
217
197
|
}
|
|
218
198
|
|
|
219
199
|
function mapQuestionnaireResult(
|
|
220
|
-
|
|
221
|
-
|
|
200
|
+
questions: PlanModeQuestion[],
|
|
201
|
+
result: RunQuestionnaireResult<string>,
|
|
222
202
|
): PlanModeQuestionAnswer[] | undefined {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
203
|
+
if (result.kind !== "submitted") return undefined;
|
|
204
|
+
if (result.answers.length !== questions.length) {
|
|
205
|
+
throw new Error("Questionnaire returned an incomplete answer set");
|
|
206
|
+
}
|
|
227
207
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
}
|
|
246
|
-
answers.set(index, answer);
|
|
247
|
-
}
|
|
208
|
+
const answers = new Map<number, QuestionnaireAnswer<string>>();
|
|
209
|
+
for (const answer of result.answers) {
|
|
210
|
+
const index = Number(answer.questionId);
|
|
211
|
+
if (!Number.isSafeInteger(index) || String(index) !== answer.questionId || !questions[index]) {
|
|
212
|
+
throw new Error("Questionnaire returned an answer for an unknown question");
|
|
213
|
+
}
|
|
214
|
+
if (answers.has(index)) throw new Error("Questionnaire returned duplicate answers");
|
|
215
|
+
if (answer.wasCustom) {
|
|
216
|
+
if (answer.optionIndex !== undefined) {
|
|
217
|
+
throw new Error("Questionnaire returned a custom answer with an option index");
|
|
218
|
+
}
|
|
219
|
+
if (!answer.answer.trim()) return undefined;
|
|
220
|
+
} else if (answer.optionIndex === undefined || !questions[index]?.options[answer.optionIndex - 1]) {
|
|
221
|
+
throw new Error("Questionnaire returned an invalid selected option");
|
|
222
|
+
}
|
|
223
|
+
answers.set(index, answer);
|
|
224
|
+
}
|
|
248
225
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
226
|
+
return questions.map((question, index) => {
|
|
227
|
+
const answer = answers.get(index);
|
|
228
|
+
if (!answer) throw new Error("Questionnaire returned an incomplete answer set");
|
|
229
|
+
const answerText = answer.wasCustom
|
|
230
|
+
? answer.answer
|
|
231
|
+
: (question.options[(answer.optionIndex ?? 0) - 1]?.label ?? answer.answer);
|
|
232
|
+
return answerFor(question, answerText, {
|
|
233
|
+
wasCustom: answer.wasCustom,
|
|
234
|
+
optionIndex: answer.optionIndex,
|
|
235
|
+
note: answer.note,
|
|
236
|
+
});
|
|
237
|
+
});
|
|
261
238
|
}
|
|
262
239
|
|
|
263
240
|
function displayText(value: string, fallback: string, sanitize: (value: string) => string): string {
|
|
264
|
-
|
|
265
|
-
|
|
241
|
+
const sanitized = sanitize(value);
|
|
242
|
+
return sanitized.trim() ? sanitized : fallback;
|
|
266
243
|
}
|
|
267
244
|
|
|
268
245
|
function answerFor(
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
246
|
+
question: PlanModeQuestion,
|
|
247
|
+
answer: string,
|
|
248
|
+
options: { wasCustom: boolean; optionIndex?: number; note?: string },
|
|
272
249
|
): PlanModeQuestionAnswer {
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
250
|
+
const result: PlanModeQuestionAnswer = {
|
|
251
|
+
id: question.id,
|
|
252
|
+
header: question.header,
|
|
253
|
+
question: question.question,
|
|
254
|
+
answer,
|
|
255
|
+
wasCustom: options.wasCustom,
|
|
256
|
+
};
|
|
257
|
+
if (options.optionIndex !== undefined) result.optionIndex = options.optionIndex;
|
|
258
|
+
if (options.note !== undefined) result.note = options.note;
|
|
259
|
+
return result;
|
|
283
260
|
}
|
|
284
261
|
|
|
285
|
-
export function planModeQuestionAnswered(
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
content: [
|
|
291
|
-
{ type: "text" as const, text: formatPlanModeQuestionPayload({ cancelled: false, answers }) },
|
|
292
|
-
],
|
|
293
|
-
details: { cancelled: false, questions, answers } satisfies PlanModeQuestionDetails,
|
|
294
|
-
};
|
|
262
|
+
export function planModeQuestionAnswered(questions: PlanModeQuestion[], answers: PlanModeQuestionAnswer[]) {
|
|
263
|
+
return {
|
|
264
|
+
content: [{ type: "text" as const, text: formatPlanModeQuestionPayload({ cancelled: false, answers }) }],
|
|
265
|
+
details: { cancelled: false, questions, answers } satisfies PlanModeQuestionDetails,
|
|
266
|
+
};
|
|
295
267
|
}
|
|
296
268
|
|
|
297
269
|
export function planModeQuestionCancelled(
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
270
|
+
questions: PlanModeQuestion[],
|
|
271
|
+
reason: PlanModeQuestionReason,
|
|
272
|
+
message: string,
|
|
301
273
|
) {
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
274
|
+
return {
|
|
275
|
+
content: [
|
|
276
|
+
{
|
|
277
|
+
type: "text" as const,
|
|
278
|
+
text: formatPlanModeQuestionPayload({ cancelled: true, reason, message }),
|
|
279
|
+
},
|
|
280
|
+
],
|
|
281
|
+
details: { cancelled: true, reason, questions } satisfies PlanModeQuestionDetails,
|
|
282
|
+
};
|
|
311
283
|
}
|
|
312
284
|
|
|
313
285
|
function formatPlanModeQuestionPayload(payload: {
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
286
|
+
cancelled: boolean;
|
|
287
|
+
reason?: PlanModeQuestionReason;
|
|
288
|
+
message?: string;
|
|
289
|
+
answers?: PlanModeQuestionAnswer[];
|
|
318
290
|
}) {
|
|
319
|
-
|
|
291
|
+
return JSON.stringify(payload, null, 2);
|
|
320
292
|
}
|
|
321
293
|
|
|
322
294
|
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
323
|
-
|
|
295
|
+
return typeof value === "object" && value !== null;
|
|
324
296
|
}
|
|
325
297
|
|
|
326
298
|
function stringField(value: unknown) {
|
|
327
|
-
|
|
299
|
+
return typeof value === "string" ? value.trim() : undefined;
|
|
328
300
|
}
|
package/src/required-tools.ts
CHANGED
|
@@ -2,34 +2,30 @@ 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;
|
|
5
|
+
export const REQUIRED_PLAN_MODE_TOOL_NAMES = [PLAN_MODE_QUESTION_TOOL_NAME, PLAN_MODE_COMPLETE_TOOL_NAME] as const;
|
|
9
6
|
|
|
10
7
|
export function planModeHelperToolsAvailable(toolNames: readonly string[]) {
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
const active = new Set(toolNames);
|
|
9
|
+
return REQUIRED_PLAN_MODE_TOOL_NAMES.every((name) => active.has(name));
|
|
13
10
|
}
|
|
14
11
|
|
|
15
12
|
export function assertPlanModeHelperToolsAvailable(toolNames: readonly string[]) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
13
|
+
if (planModeHelperToolsAvailable(toolNames)) return;
|
|
14
|
+
throw new Error(
|
|
15
|
+
"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",
|
|
16
|
+
);
|
|
20
17
|
}
|
|
21
18
|
|
|
22
19
|
export function withRequiredPlanModeTools(toolNames: string[]) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
20
|
+
return unique([
|
|
21
|
+
...withoutRequiredPlanModeTools(toolNames),
|
|
22
|
+
PLAN_MODE_QUESTION_TOOL_NAME,
|
|
23
|
+
PLAN_MODE_COMPLETE_TOOL_NAME,
|
|
24
|
+
]);
|
|
28
25
|
}
|
|
29
26
|
|
|
30
27
|
export function withoutRequiredPlanModeTools(toolNames: string[]) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
);
|
|
28
|
+
return toolNames.filter(
|
|
29
|
+
(toolName) => toolName !== PLAN_MODE_QUESTION_TOOL_NAME && toolName !== PLAN_MODE_COMPLETE_TOOL_NAME,
|
|
30
|
+
);
|
|
35
31
|
}
|