@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.
Files changed (41) hide show
  1. package/README.md +68 -4
  2. package/dist/chunks/{chunk-57OBPS7P.js → chunk-HF7ZEYIC.js} +169 -164
  3. package/dist/chunks/chunk-HF7ZEYIC.js.map +7 -0
  4. package/dist/chunks/{interactive-ui-N2ZKBVNE.js → interactive-ui-UK7IGPOE.js} +312 -32
  5. package/dist/chunks/interactive-ui-UK7IGPOE.js.map +7 -0
  6. package/dist/index.ts +670 -212
  7. package/dist/index.ts.map +4 -4
  8. package/docs/settings.md +26 -2
  9. package/package.json +50 -51
  10. package/src/active-implementation-menu.ts +57 -60
  11. package/src/command.ts +22 -21
  12. package/src/completion-tool.ts +53 -56
  13. package/src/extension-runtime.ts +5 -5
  14. package/src/finalization-request.ts +40 -44
  15. package/src/fresh-handoff-coordinator.ts +52 -0
  16. package/src/fresh-implementation.ts +312 -205
  17. package/src/implementation-models.ts +43 -0
  18. package/src/implementation-retention.ts +109 -123
  19. package/src/message-transform.ts +218 -252
  20. package/src/mode-contract.ts +46 -49
  21. package/src/plan-action-controller.ts +139 -89
  22. package/src/plan-action-menus.ts +414 -177
  23. package/src/plan-export-controller.ts +23 -28
  24. package/src/plan-export-screen.ts +13 -13
  25. package/src/plan-export.ts +85 -102
  26. package/src/plan-launch-menu.ts +119 -119
  27. package/src/plan-mode.ts +2027 -1675
  28. package/src/presentation.ts +84 -108
  29. package/src/prompt.ts +1 -1
  30. package/src/question-tool.ts +239 -267
  31. package/src/required-tools.ts +15 -19
  32. package/src/saved-plan-menu.ts +82 -84
  33. package/src/saved-plan-preflight.ts +29 -33
  34. package/src/settings-menu.ts +489 -377
  35. package/src/settings.ts +403 -382
  36. package/src/state.ts +177 -146
  37. package/src/tool-policy.ts +634 -699
  38. package/src/tool-selection.ts +39 -44
  39. package/src/workflow-mutex.ts +66 -66
  40. package/dist/chunks/chunk-57OBPS7P.js.map +0 -7
  41. package/dist/chunks/interactive-ui-N2ZKBVNE.js.map +0 -7
@@ -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
- label: string;
13
- description?: string;
8
+ label: string;
9
+ description?: string;
14
10
  };
15
11
 
16
12
  export type PlanModeQuestion = {
17
- id: string;
18
- header: string;
19
- question: string;
20
- options: PlanModeQuestionOption[];
13
+ id: string;
14
+ header: string;
15
+ question: string;
16
+ options: PlanModeQuestionOption[];
21
17
  };
22
18
 
23
19
  export type PlanModeQuestionAnswer = {
24
- id: string;
25
- header: string;
26
- question: string;
27
- answer: string;
28
- wasCustom: boolean;
29
- optionIndex?: number;
30
- note?: string;
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
- cancelled: boolean;
41
- reason?: PlanModeQuestionReason;
42
- questions: PlanModeQuestion[];
43
- answers?: PlanModeQuestionAnswer[];
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
- type: "object",
48
- additionalProperties: false,
49
- required: ["questions"],
50
- properties: {
51
- questions: {
52
- type: "array",
53
- minItems: 1,
54
- maxItems: 3,
55
- description: "Questions to show the user. Prefer 1 and do not exceed 3.",
56
- items: {
57
- type: "object",
58
- additionalProperties: false,
59
- required: ["id", "header", "question", "options"],
60
- properties: {
61
- id: {
62
- type: "string",
63
- description: "Stable identifier for mapping answers (snake_case).",
64
- },
65
- header: {
66
- type: "string",
67
- description: "Short header label shown in the UI (12 or fewer chars).",
68
- },
69
- question: { type: "string", description: "Single-sentence prompt shown to the user." },
70
- options: {
71
- type: "array",
72
- minItems: 2,
73
- maxItems: 4,
74
- description:
75
- "Provide 2-4 mutually exclusive choices. Put the recommended option first when there is a clear default.",
76
- items: {
77
- type: "object",
78
- additionalProperties: false,
79
- required: ["label", "description"],
80
- properties: {
81
- label: { type: "string", description: "User-facing label (1-5 words)." },
82
- description: {
83
- type: "string",
84
- description: "One short sentence explaining impact/tradeoff if selected.",
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
- input: unknown,
101
- ): NormalizePlanModeQuestionParamsResult {
102
- if (!isRecord(input) || !Array.isArray(input.questions)) {
103
- return { ok: false, error: "questions must be an array" };
104
- }
105
- if (input.questions.length < 1 || input.questions.length > 3) {
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
- const questions: PlanModeQuestion[] = [];
110
- for (const [questionIndex, rawQuestion] of input.questions.entries()) {
111
- if (!isRecord(rawQuestion)) {
112
- return { ok: false, error: `question ${questionIndex + 1} must be an object` };
113
- }
114
- const id = stringField(rawQuestion.id);
115
- const header = stringField(rawQuestion.header);
116
- const question = stringField(rawQuestion.question);
117
- if (!id || !header || !question) {
118
- return {
119
- ok: false,
120
- error: `question ${questionIndex + 1} requires non-empty id, header, and question`,
121
- };
122
- }
123
- if (!Array.isArray(rawQuestion.options)) {
124
- return { ok: false, error: `question ${questionIndex + 1} options must be an array` };
125
- }
126
- if (rawQuestion.options.length < 2 || rawQuestion.options.length > 4) {
127
- return { ok: false, error: `question ${questionIndex + 1} options must contain 2-4 items` };
128
- }
129
- const options: PlanModeQuestionOption[] = [];
130
- for (const [optionIndex, rawOption] of rawQuestion.options.entries()) {
131
- if (!isRecord(rawOption)) {
132
- return {
133
- ok: false,
134
- error: `question ${questionIndex + 1} option ${optionIndex + 1} must be an object`,
135
- };
136
- }
137
- const label = stringField(rawOption.label);
138
- if (!label) {
139
- return {
140
- ok: false,
141
- error: `question ${questionIndex + 1} option ${optionIndex + 1} requires a label`,
142
- };
143
- }
144
- const description = stringField(rawOption.description);
145
- if (!description) {
146
- return {
147
- ok: false,
148
- error: `question ${questionIndex + 1} option ${optionIndex + 1} requires a description`,
149
- };
150
- }
151
- options.push({ label, description });
152
- }
153
- questions.push({ id, header, question, options });
154
- }
155
- return { ok: true, questions };
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
- questions: PlanModeQuestion[],
160
- ctx: ExtensionContext,
161
- lifecycle: { isCurrent(): boolean; isEnabled(): boolean },
147
+ questions: PlanModeQuestion[],
148
+ ctx: ExtensionContext,
149
+ lifecycle: { isCurrent(): boolean; isEnabled(): boolean },
162
150
  ) {
163
- const answers = await askPlanModeQuestions(
164
- questions,
165
- ctx,
166
- () => lifecycle.isCurrent() && lifecycle.isEnabled(),
167
- );
168
- if (!lifecycle.isCurrent()) {
169
- return planModeQuestionCancelled(
170
- questions,
171
- "cancelled",
172
- "Plan-mode question cancelled because the session changed.",
173
- );
174
- }
175
- if (!lifecycle.isEnabled()) {
176
- return planModeQuestionCancelled(
177
- questions,
178
- "plan_mode_inactive",
179
- "Plan-mode question cancelled because Plan mode is no longer active.",
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
- questions: PlanModeQuestion[],
194
- ctx: ExtensionContext,
195
- shouldContinue: () => boolean = () => true,
173
+ questions: PlanModeQuestion[],
174
+ ctx: ExtensionContext,
175
+ shouldContinue: () => boolean = () => true,
196
176
  ): Promise<PlanModeQuestionAnswer[] | undefined> {
197
- const { runQuestionnaire, sanitizeTerminalText } = await import("@narumitw/pi-tui-kit");
198
- if (!shouldContinue()) return undefined;
199
- const runnerQuestions: QuestionnaireQuestion<string>[] = questions.map((question, index) => ({
200
- id: String(index),
201
- header: displayText(question.header, `Question ${index + 1}`, sanitizeTerminalText),
202
- prompt: displayText(question.question, `Question ${index + 1}`, sanitizeTerminalText),
203
- options: question.options.map((option, optionIndex) => ({
204
- ...option,
205
- label: displayText(option.label, `Option ${optionIndex + 1}`, sanitizeTerminalText),
206
- })),
207
- }));
208
- const result = await runQuestionnaire(ctx, {
209
- questions: runnerQuestions,
210
- allowNotes: true,
211
- maxTextLength: MAX_PLAN_MODE_RESPONSE_LENGTH,
212
- signal: ctx.signal,
213
- isCurrent: shouldContinue,
214
- });
215
- if (!shouldContinue()) return undefined;
216
- return mapQuestionnaireResult(questions, result);
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
- questions: PlanModeQuestion[],
221
- result: RunQuestionnaireResult<string>,
200
+ questions: PlanModeQuestion[],
201
+ result: RunQuestionnaireResult<string>,
222
202
  ): PlanModeQuestionAnswer[] | undefined {
223
- if (result.kind !== "submitted") return undefined;
224
- if (result.answers.length !== questions.length) {
225
- throw new Error("Questionnaire returned an incomplete answer set");
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
- const answers = new Map<number, QuestionnaireAnswer<string>>();
229
- for (const answer of result.answers) {
230
- const index = Number(answer.questionId);
231
- if (!Number.isSafeInteger(index) || String(index) !== answer.questionId || !questions[index]) {
232
- throw new Error("Questionnaire returned an answer for an unknown question");
233
- }
234
- if (answers.has(index)) throw new Error("Questionnaire returned duplicate answers");
235
- if (answer.wasCustom) {
236
- if (answer.optionIndex !== undefined) {
237
- throw new Error("Questionnaire returned a custom answer with an option index");
238
- }
239
- if (!answer.answer.trim()) return undefined;
240
- } else if (
241
- answer.optionIndex === undefined ||
242
- !questions[index]?.options[answer.optionIndex - 1]
243
- ) {
244
- throw new Error("Questionnaire returned an invalid selected option");
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
- return questions.map((question, index) => {
250
- const answer = answers.get(index);
251
- if (!answer) throw new Error("Questionnaire returned an incomplete answer set");
252
- const answerText = answer.wasCustom
253
- ? answer.answer
254
- : (question.options[(answer.optionIndex ?? 0) - 1]?.label ?? answer.answer);
255
- return answerFor(question, answerText, {
256
- wasCustom: answer.wasCustom,
257
- optionIndex: answer.optionIndex,
258
- note: answer.note,
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
- const sanitized = sanitize(value);
265
- return sanitized.trim() ? sanitized : fallback;
241
+ const sanitized = sanitize(value);
242
+ return sanitized.trim() ? sanitized : fallback;
266
243
  }
267
244
 
268
245
  function answerFor(
269
- question: PlanModeQuestion,
270
- answer: string,
271
- options: { wasCustom: boolean; optionIndex?: number; note?: string },
246
+ question: PlanModeQuestion,
247
+ answer: string,
248
+ options: { wasCustom: boolean; optionIndex?: number; note?: string },
272
249
  ): PlanModeQuestionAnswer {
273
- const result: PlanModeQuestionAnswer = {
274
- id: question.id,
275
- header: question.header,
276
- question: question.question,
277
- answer,
278
- wasCustom: options.wasCustom,
279
- };
280
- if (options.optionIndex !== undefined) result.optionIndex = options.optionIndex;
281
- if (options.note !== undefined) result.note = options.note;
282
- return result;
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
- questions: PlanModeQuestion[],
287
- answers: PlanModeQuestionAnswer[],
288
- ) {
289
- return {
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
- questions: PlanModeQuestion[],
299
- reason: PlanModeQuestionReason,
300
- message: string,
270
+ questions: PlanModeQuestion[],
271
+ reason: PlanModeQuestionReason,
272
+ message: string,
301
273
  ) {
302
- return {
303
- content: [
304
- {
305
- type: "text" as const,
306
- text: formatPlanModeQuestionPayload({ cancelled: true, reason, message }),
307
- },
308
- ],
309
- details: { cancelled: true, reason, questions } satisfies PlanModeQuestionDetails,
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
- cancelled: boolean;
315
- reason?: PlanModeQuestionReason;
316
- message?: string;
317
- answers?: PlanModeQuestionAnswer[];
286
+ cancelled: boolean;
287
+ reason?: PlanModeQuestionReason;
288
+ message?: string;
289
+ answers?: PlanModeQuestionAnswer[];
318
290
  }) {
319
- return JSON.stringify(payload, null, 2);
291
+ return JSON.stringify(payload, null, 2);
320
292
  }
321
293
 
322
294
  function isRecord(value: unknown): value is Record<string, unknown> {
323
- return typeof value === "object" && value !== null;
295
+ return typeof value === "object" && value !== null;
324
296
  }
325
297
 
326
298
  function stringField(value: unknown) {
327
- return typeof value === "string" ? value.trim() : undefined;
299
+ return typeof value === "string" ? value.trim() : undefined;
328
300
  }
@@ -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
- const active = new Set(toolNames);
12
- return REQUIRED_PLAN_MODE_TOOL_NAMES.every((name) => active.has(name));
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
- if (planModeHelperToolsAvailable(toolNames)) return;
17
- throw new Error(
18
- "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",
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
- return unique([
24
- ...withoutRequiredPlanModeTools(toolNames),
25
- PLAN_MODE_QUESTION_TOOL_NAME,
26
- PLAN_MODE_COMPLETE_TOOL_NAME,
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
- return toolNames.filter(
32
- (toolName) =>
33
- toolName !== PLAN_MODE_QUESTION_TOOL_NAME && toolName !== PLAN_MODE_COMPLETE_TOOL_NAME,
34
- );
28
+ return toolNames.filter(
29
+ (toolName) => toolName !== PLAN_MODE_QUESTION_TOOL_NAME && toolName !== PLAN_MODE_COMPLETE_TOOL_NAME,
30
+ );
35
31
  }