@narumitw/pi-plan-mode 0.54.0 → 0.55.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 +33 -36
- package/dist/chunks/{chunk-U5CQ7RQX.js → chunk-AS76FCC5.js} +242 -265
- package/dist/chunks/chunk-AS76FCC5.js.map +7 -0
- package/dist/chunks/{interactive-ui-W3VYAJIQ.js → interactive-ui-UCL5UIJN.js} +43 -51
- package/dist/chunks/interactive-ui-UCL5UIJN.js.map +7 -0
- package/dist/index.ts +224 -321
- package/dist/index.ts.map +3 -3
- package/package.json +1 -1
- package/src/plan-launch-menu.ts +13 -5
- package/src/plan-mode.ts +263 -238
- package/src/required-tools.ts +17 -0
- package/src/settings-menu.ts +36 -47
- package/src/settings.ts +0 -19
- package/src/state.ts +30 -0
- package/src/tool-selection.ts +2 -4
- package/dist/chunks/chunk-U5CQ7RQX.js.map +0 -7
- package/dist/chunks/interactive-ui-W3VYAJIQ.js.map +0 -7
- package/src/helper-tool-visibility.ts +0 -142
|
@@ -304,240 +304,6 @@ function contentText(content) {
|
|
|
304
304
|
}).filter(Boolean).join("\n");
|
|
305
305
|
}
|
|
306
306
|
|
|
307
|
-
// src/question-tool.ts
|
|
308
|
-
var PLAN_MODE_QUESTION_TOOL_NAME = "plan_mode_question";
|
|
309
|
-
var MAX_PLAN_MODE_RESPONSE_LENGTH = 4e3;
|
|
310
|
-
var PLAN_MODE_QUESTION_PARAMS = {
|
|
311
|
-
type: "object",
|
|
312
|
-
additionalProperties: false,
|
|
313
|
-
required: ["questions"],
|
|
314
|
-
properties: {
|
|
315
|
-
questions: {
|
|
316
|
-
type: "array",
|
|
317
|
-
minItems: 1,
|
|
318
|
-
maxItems: 3,
|
|
319
|
-
description: "Questions to show the user. Prefer 1 and do not exceed 3.",
|
|
320
|
-
items: {
|
|
321
|
-
type: "object",
|
|
322
|
-
additionalProperties: false,
|
|
323
|
-
required: ["id", "header", "question", "options"],
|
|
324
|
-
properties: {
|
|
325
|
-
id: {
|
|
326
|
-
type: "string",
|
|
327
|
-
description: "Stable identifier for mapping answers (snake_case)."
|
|
328
|
-
},
|
|
329
|
-
header: {
|
|
330
|
-
type: "string",
|
|
331
|
-
description: "Short header label shown in the UI (12 or fewer chars)."
|
|
332
|
-
},
|
|
333
|
-
question: { type: "string", description: "Single-sentence prompt shown to the user." },
|
|
334
|
-
options: {
|
|
335
|
-
type: "array",
|
|
336
|
-
minItems: 2,
|
|
337
|
-
maxItems: 4,
|
|
338
|
-
description: "Provide 2-4 mutually exclusive choices. Put the recommended option first when there is a clear default.",
|
|
339
|
-
items: {
|
|
340
|
-
type: "object",
|
|
341
|
-
additionalProperties: false,
|
|
342
|
-
required: ["label", "description"],
|
|
343
|
-
properties: {
|
|
344
|
-
label: { type: "string", description: "User-facing label (1-5 words)." },
|
|
345
|
-
description: {
|
|
346
|
-
type: "string",
|
|
347
|
-
description: "One short sentence explaining impact/tradeoff if selected."
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
};
|
|
357
|
-
function normalizePlanModeQuestionParams(input) {
|
|
358
|
-
if (!isRecord2(input) || !Array.isArray(input.questions)) {
|
|
359
|
-
return { ok: false, error: "questions must be an array" };
|
|
360
|
-
}
|
|
361
|
-
if (input.questions.length < 1 || input.questions.length > 3) {
|
|
362
|
-
return { ok: false, error: "questions must contain 1-3 items" };
|
|
363
|
-
}
|
|
364
|
-
const questions = [];
|
|
365
|
-
for (const [questionIndex, rawQuestion] of input.questions.entries()) {
|
|
366
|
-
if (!isRecord2(rawQuestion)) {
|
|
367
|
-
return { ok: false, error: `question ${questionIndex + 1} must be an object` };
|
|
368
|
-
}
|
|
369
|
-
const id = stringField(rawQuestion.id);
|
|
370
|
-
const header = stringField(rawQuestion.header);
|
|
371
|
-
const question = stringField(rawQuestion.question);
|
|
372
|
-
if (!id || !header || !question) {
|
|
373
|
-
return {
|
|
374
|
-
ok: false,
|
|
375
|
-
error: `question ${questionIndex + 1} requires non-empty id, header, and question`
|
|
376
|
-
};
|
|
377
|
-
}
|
|
378
|
-
if (!Array.isArray(rawQuestion.options)) {
|
|
379
|
-
return { ok: false, error: `question ${questionIndex + 1} options must be an array` };
|
|
380
|
-
}
|
|
381
|
-
if (rawQuestion.options.length < 2 || rawQuestion.options.length > 4) {
|
|
382
|
-
return { ok: false, error: `question ${questionIndex + 1} options must contain 2-4 items` };
|
|
383
|
-
}
|
|
384
|
-
const options = [];
|
|
385
|
-
for (const [optionIndex, rawOption] of rawQuestion.options.entries()) {
|
|
386
|
-
if (!isRecord2(rawOption)) {
|
|
387
|
-
return {
|
|
388
|
-
ok: false,
|
|
389
|
-
error: `question ${questionIndex + 1} option ${optionIndex + 1} must be an object`
|
|
390
|
-
};
|
|
391
|
-
}
|
|
392
|
-
const label = stringField(rawOption.label);
|
|
393
|
-
if (!label) {
|
|
394
|
-
return {
|
|
395
|
-
ok: false,
|
|
396
|
-
error: `question ${questionIndex + 1} option ${optionIndex + 1} requires a label`
|
|
397
|
-
};
|
|
398
|
-
}
|
|
399
|
-
const description = stringField(rawOption.description);
|
|
400
|
-
if (!description) {
|
|
401
|
-
return {
|
|
402
|
-
ok: false,
|
|
403
|
-
error: `question ${questionIndex + 1} option ${optionIndex + 1} requires a description`
|
|
404
|
-
};
|
|
405
|
-
}
|
|
406
|
-
options.push({ label, description });
|
|
407
|
-
}
|
|
408
|
-
questions.push({ id, header, question, options });
|
|
409
|
-
}
|
|
410
|
-
return { ok: true, questions };
|
|
411
|
-
}
|
|
412
|
-
async function answerPlanModeQuestions(questions, ctx, lifecycle) {
|
|
413
|
-
const answers = await askPlanModeQuestions(
|
|
414
|
-
questions,
|
|
415
|
-
ctx,
|
|
416
|
-
() => lifecycle.isCurrent() && lifecycle.isEnabled()
|
|
417
|
-
);
|
|
418
|
-
if (!lifecycle.isCurrent()) {
|
|
419
|
-
return planModeQuestionCancelled(
|
|
420
|
-
questions,
|
|
421
|
-
"cancelled",
|
|
422
|
-
"Plan-mode question cancelled because the session changed."
|
|
423
|
-
);
|
|
424
|
-
}
|
|
425
|
-
if (!lifecycle.isEnabled()) {
|
|
426
|
-
return planModeQuestionCancelled(
|
|
427
|
-
questions,
|
|
428
|
-
"plan_mode_inactive",
|
|
429
|
-
"Plan-mode question cancelled because Plan mode is no longer active."
|
|
430
|
-
);
|
|
431
|
-
}
|
|
432
|
-
if (!answers) {
|
|
433
|
-
return planModeQuestionCancelled(
|
|
434
|
-
questions,
|
|
435
|
-
"cancelled",
|
|
436
|
-
"User cancelled the Plan-mode question prompt."
|
|
437
|
-
);
|
|
438
|
-
}
|
|
439
|
-
return planModeQuestionAnswered(questions, answers);
|
|
440
|
-
}
|
|
441
|
-
async function askPlanModeQuestions(questions, ctx, shouldContinue = () => true) {
|
|
442
|
-
const { runQuestionnaire, sanitizeTerminalText } = await import("@narumitw/pi-tui-kit");
|
|
443
|
-
if (!shouldContinue()) return void 0;
|
|
444
|
-
const runnerQuestions = questions.map((question, index) => ({
|
|
445
|
-
id: String(index),
|
|
446
|
-
header: displayText(question.header, `Question ${index + 1}`, sanitizeTerminalText),
|
|
447
|
-
prompt: displayText(question.question, `Question ${index + 1}`, sanitizeTerminalText),
|
|
448
|
-
options: question.options.map((option, optionIndex) => ({
|
|
449
|
-
...option,
|
|
450
|
-
label: displayText(option.label, `Option ${optionIndex + 1}`, sanitizeTerminalText)
|
|
451
|
-
}))
|
|
452
|
-
}));
|
|
453
|
-
const result = await runQuestionnaire(ctx, {
|
|
454
|
-
questions: runnerQuestions,
|
|
455
|
-
allowNotes: true,
|
|
456
|
-
maxTextLength: MAX_PLAN_MODE_RESPONSE_LENGTH,
|
|
457
|
-
signal: ctx.signal,
|
|
458
|
-
isCurrent: shouldContinue
|
|
459
|
-
});
|
|
460
|
-
if (!shouldContinue()) return void 0;
|
|
461
|
-
return mapQuestionnaireResult(questions, result);
|
|
462
|
-
}
|
|
463
|
-
function mapQuestionnaireResult(questions, result) {
|
|
464
|
-
if (result.kind !== "submitted") return void 0;
|
|
465
|
-
if (result.answers.length !== questions.length) {
|
|
466
|
-
throw new Error("Questionnaire returned an incomplete answer set");
|
|
467
|
-
}
|
|
468
|
-
const answers = /* @__PURE__ */ new Map();
|
|
469
|
-
for (const answer of result.answers) {
|
|
470
|
-
const index = Number(answer.questionId);
|
|
471
|
-
if (!Number.isSafeInteger(index) || String(index) !== answer.questionId || !questions[index]) {
|
|
472
|
-
throw new Error("Questionnaire returned an answer for an unknown question");
|
|
473
|
-
}
|
|
474
|
-
if (answers.has(index)) throw new Error("Questionnaire returned duplicate answers");
|
|
475
|
-
if (answer.wasCustom) {
|
|
476
|
-
if (answer.optionIndex !== void 0) {
|
|
477
|
-
throw new Error("Questionnaire returned a custom answer with an option index");
|
|
478
|
-
}
|
|
479
|
-
if (!answer.answer.trim()) return void 0;
|
|
480
|
-
} else if (answer.optionIndex === void 0 || !questions[index]?.options[answer.optionIndex - 1]) {
|
|
481
|
-
throw new Error("Questionnaire returned an invalid selected option");
|
|
482
|
-
}
|
|
483
|
-
answers.set(index, answer);
|
|
484
|
-
}
|
|
485
|
-
return questions.map((question, index) => {
|
|
486
|
-
const answer = answers.get(index);
|
|
487
|
-
if (!answer) throw new Error("Questionnaire returned an incomplete answer set");
|
|
488
|
-
const answerText = answer.wasCustom ? answer.answer : question.options[(answer.optionIndex ?? 0) - 1]?.label ?? answer.answer;
|
|
489
|
-
return answerFor(question, answerText, {
|
|
490
|
-
wasCustom: answer.wasCustom,
|
|
491
|
-
optionIndex: answer.optionIndex,
|
|
492
|
-
note: answer.note
|
|
493
|
-
});
|
|
494
|
-
});
|
|
495
|
-
}
|
|
496
|
-
function displayText(value, fallback, sanitize) {
|
|
497
|
-
const sanitized = sanitize(value);
|
|
498
|
-
return sanitized.trim() ? sanitized : fallback;
|
|
499
|
-
}
|
|
500
|
-
function answerFor(question, answer, options) {
|
|
501
|
-
const result = {
|
|
502
|
-
id: question.id,
|
|
503
|
-
header: question.header,
|
|
504
|
-
question: question.question,
|
|
505
|
-
answer,
|
|
506
|
-
wasCustom: options.wasCustom
|
|
507
|
-
};
|
|
508
|
-
if (options.optionIndex !== void 0) result.optionIndex = options.optionIndex;
|
|
509
|
-
if (options.note !== void 0) result.note = options.note;
|
|
510
|
-
return result;
|
|
511
|
-
}
|
|
512
|
-
function planModeQuestionAnswered(questions, answers) {
|
|
513
|
-
return {
|
|
514
|
-
content: [
|
|
515
|
-
{ type: "text", text: formatPlanModeQuestionPayload({ cancelled: false, answers }) }
|
|
516
|
-
],
|
|
517
|
-
details: { cancelled: false, questions, answers }
|
|
518
|
-
};
|
|
519
|
-
}
|
|
520
|
-
function planModeQuestionCancelled(questions, reason, message) {
|
|
521
|
-
return {
|
|
522
|
-
content: [
|
|
523
|
-
{
|
|
524
|
-
type: "text",
|
|
525
|
-
text: formatPlanModeQuestionPayload({ cancelled: true, reason, message })
|
|
526
|
-
}
|
|
527
|
-
],
|
|
528
|
-
details: { cancelled: true, reason, questions }
|
|
529
|
-
};
|
|
530
|
-
}
|
|
531
|
-
function formatPlanModeQuestionPayload(payload) {
|
|
532
|
-
return JSON.stringify(payload, null, 2);
|
|
533
|
-
}
|
|
534
|
-
function isRecord2(value) {
|
|
535
|
-
return typeof value === "object" && value !== null;
|
|
536
|
-
}
|
|
537
|
-
function stringField(value) {
|
|
538
|
-
return typeof value === "string" ? value.trim() : void 0;
|
|
539
|
-
}
|
|
540
|
-
|
|
541
307
|
// src/implementation-retention.ts
|
|
542
308
|
function retentionLabel(retention) {
|
|
543
309
|
return {
|
|
@@ -1173,8 +939,6 @@ var IMPLEMENTATION_PLAN_RETENTIONS = [
|
|
|
1173
939
|
"clear-after-first-run",
|
|
1174
940
|
"keep"
|
|
1175
941
|
];
|
|
1176
|
-
var PLAN_MODE_TOOL_VISIBILITIES = ["always", "after-first-plan"];
|
|
1177
|
-
var DEFAULT_PLAN_MODE_TOOL_VISIBILITY = "after-first-plan";
|
|
1178
942
|
var DEFAULT_PLAN_EXPORT_PATH = "PLAN.md";
|
|
1179
943
|
var MODIFIERS = /* @__PURE__ */ new Set(["ctrl", "shift", "alt", "super"]);
|
|
1180
944
|
var BASE_KEYS = /* @__PURE__ */ new Set([
|
|
@@ -1247,13 +1011,6 @@ function normalizePlanModeSettings(value) {
|
|
|
1247
1011
|
const settings = {
|
|
1248
1012
|
thinkingLevel
|
|
1249
1013
|
};
|
|
1250
|
-
if (Object.hasOwn(value, "toolVisibility")) {
|
|
1251
|
-
const toolVisibility = Reflect.get(value, "toolVisibility");
|
|
1252
|
-
if (!PLAN_MODE_TOOL_VISIBILITIES.includes(toolVisibility)) {
|
|
1253
|
-
return void 0;
|
|
1254
|
-
}
|
|
1255
|
-
settings.toolVisibility = toolVisibility;
|
|
1256
|
-
}
|
|
1257
1014
|
if (Object.hasOwn(value, "defaultPlanTools")) {
|
|
1258
1015
|
const defaultPlanTools = normalizeToolNames(Reflect.get(value, "defaultPlanTools"));
|
|
1259
1016
|
if (!defaultPlanTools) return void 0;
|
|
@@ -1371,7 +1128,6 @@ function updatePlanModeSettings(patch, options = {}) {
|
|
|
1371
1128
|
const current = await readSettingsDocumentForUpdate(settingsPath, legacySettingsPath);
|
|
1372
1129
|
const updated = { ...current };
|
|
1373
1130
|
if (patch.thinkingLevel !== void 0) updated.thinkingLevel = patch.thinkingLevel;
|
|
1374
|
-
if (patch.toolVisibility !== void 0) updated.toolVisibility = patch.toolVisibility;
|
|
1375
1131
|
if (patch.defaultPlanTools === null) delete updated.defaultPlanTools;
|
|
1376
1132
|
else if (patch.defaultPlanTools !== void 0) {
|
|
1377
1133
|
updated.defaultPlanTools = [...patch.defaultPlanTools];
|
|
@@ -1530,9 +1286,6 @@ function safeReadError(error) {
|
|
|
1530
1286
|
function configuredThinkingLevel(settings) {
|
|
1531
1287
|
return settings.thinkingLevel === "inherit" ? void 0 : settings.thinkingLevel;
|
|
1532
1288
|
}
|
|
1533
|
-
function configuredPlanModeToolVisibility(settings) {
|
|
1534
|
-
return settings.toolVisibility ?? DEFAULT_PLAN_MODE_TOOL_VISIBILITY;
|
|
1535
|
-
}
|
|
1536
1289
|
function configuredImplementationPlanRetention(settings) {
|
|
1537
1290
|
return settings.implementationPlanRetention ?? "clear-on-start";
|
|
1538
1291
|
}
|
|
@@ -1634,6 +1387,240 @@ function isNodeError2(error) {
|
|
|
1634
1387
|
return error instanceof Error && "code" in error;
|
|
1635
1388
|
}
|
|
1636
1389
|
|
|
1390
|
+
// src/question-tool.ts
|
|
1391
|
+
var PLAN_MODE_QUESTION_TOOL_NAME = "plan_mode_question";
|
|
1392
|
+
var MAX_PLAN_MODE_RESPONSE_LENGTH = 4e3;
|
|
1393
|
+
var PLAN_MODE_QUESTION_PARAMS = {
|
|
1394
|
+
type: "object",
|
|
1395
|
+
additionalProperties: false,
|
|
1396
|
+
required: ["questions"],
|
|
1397
|
+
properties: {
|
|
1398
|
+
questions: {
|
|
1399
|
+
type: "array",
|
|
1400
|
+
minItems: 1,
|
|
1401
|
+
maxItems: 3,
|
|
1402
|
+
description: "Questions to show the user. Prefer 1 and do not exceed 3.",
|
|
1403
|
+
items: {
|
|
1404
|
+
type: "object",
|
|
1405
|
+
additionalProperties: false,
|
|
1406
|
+
required: ["id", "header", "question", "options"],
|
|
1407
|
+
properties: {
|
|
1408
|
+
id: {
|
|
1409
|
+
type: "string",
|
|
1410
|
+
description: "Stable identifier for mapping answers (snake_case)."
|
|
1411
|
+
},
|
|
1412
|
+
header: {
|
|
1413
|
+
type: "string",
|
|
1414
|
+
description: "Short header label shown in the UI (12 or fewer chars)."
|
|
1415
|
+
},
|
|
1416
|
+
question: { type: "string", description: "Single-sentence prompt shown to the user." },
|
|
1417
|
+
options: {
|
|
1418
|
+
type: "array",
|
|
1419
|
+
minItems: 2,
|
|
1420
|
+
maxItems: 4,
|
|
1421
|
+
description: "Provide 2-4 mutually exclusive choices. Put the recommended option first when there is a clear default.",
|
|
1422
|
+
items: {
|
|
1423
|
+
type: "object",
|
|
1424
|
+
additionalProperties: false,
|
|
1425
|
+
required: ["label", "description"],
|
|
1426
|
+
properties: {
|
|
1427
|
+
label: { type: "string", description: "User-facing label (1-5 words)." },
|
|
1428
|
+
description: {
|
|
1429
|
+
type: "string",
|
|
1430
|
+
description: "One short sentence explaining impact/tradeoff if selected."
|
|
1431
|
+
}
|
|
1432
|
+
}
|
|
1433
|
+
}
|
|
1434
|
+
}
|
|
1435
|
+
}
|
|
1436
|
+
}
|
|
1437
|
+
}
|
|
1438
|
+
}
|
|
1439
|
+
};
|
|
1440
|
+
function normalizePlanModeQuestionParams(input) {
|
|
1441
|
+
if (!isRecord2(input) || !Array.isArray(input.questions)) {
|
|
1442
|
+
return { ok: false, error: "questions must be an array" };
|
|
1443
|
+
}
|
|
1444
|
+
if (input.questions.length < 1 || input.questions.length > 3) {
|
|
1445
|
+
return { ok: false, error: "questions must contain 1-3 items" };
|
|
1446
|
+
}
|
|
1447
|
+
const questions = [];
|
|
1448
|
+
for (const [questionIndex, rawQuestion] of input.questions.entries()) {
|
|
1449
|
+
if (!isRecord2(rawQuestion)) {
|
|
1450
|
+
return { ok: false, error: `question ${questionIndex + 1} must be an object` };
|
|
1451
|
+
}
|
|
1452
|
+
const id = stringField(rawQuestion.id);
|
|
1453
|
+
const header = stringField(rawQuestion.header);
|
|
1454
|
+
const question = stringField(rawQuestion.question);
|
|
1455
|
+
if (!id || !header || !question) {
|
|
1456
|
+
return {
|
|
1457
|
+
ok: false,
|
|
1458
|
+
error: `question ${questionIndex + 1} requires non-empty id, header, and question`
|
|
1459
|
+
};
|
|
1460
|
+
}
|
|
1461
|
+
if (!Array.isArray(rawQuestion.options)) {
|
|
1462
|
+
return { ok: false, error: `question ${questionIndex + 1} options must be an array` };
|
|
1463
|
+
}
|
|
1464
|
+
if (rawQuestion.options.length < 2 || rawQuestion.options.length > 4) {
|
|
1465
|
+
return { ok: false, error: `question ${questionIndex + 1} options must contain 2-4 items` };
|
|
1466
|
+
}
|
|
1467
|
+
const options = [];
|
|
1468
|
+
for (const [optionIndex, rawOption] of rawQuestion.options.entries()) {
|
|
1469
|
+
if (!isRecord2(rawOption)) {
|
|
1470
|
+
return {
|
|
1471
|
+
ok: false,
|
|
1472
|
+
error: `question ${questionIndex + 1} option ${optionIndex + 1} must be an object`
|
|
1473
|
+
};
|
|
1474
|
+
}
|
|
1475
|
+
const label = stringField(rawOption.label);
|
|
1476
|
+
if (!label) {
|
|
1477
|
+
return {
|
|
1478
|
+
ok: false,
|
|
1479
|
+
error: `question ${questionIndex + 1} option ${optionIndex + 1} requires a label`
|
|
1480
|
+
};
|
|
1481
|
+
}
|
|
1482
|
+
const description = stringField(rawOption.description);
|
|
1483
|
+
if (!description) {
|
|
1484
|
+
return {
|
|
1485
|
+
ok: false,
|
|
1486
|
+
error: `question ${questionIndex + 1} option ${optionIndex + 1} requires a description`
|
|
1487
|
+
};
|
|
1488
|
+
}
|
|
1489
|
+
options.push({ label, description });
|
|
1490
|
+
}
|
|
1491
|
+
questions.push({ id, header, question, options });
|
|
1492
|
+
}
|
|
1493
|
+
return { ok: true, questions };
|
|
1494
|
+
}
|
|
1495
|
+
async function answerPlanModeQuestions(questions, ctx, lifecycle) {
|
|
1496
|
+
const answers = await askPlanModeQuestions(
|
|
1497
|
+
questions,
|
|
1498
|
+
ctx,
|
|
1499
|
+
() => lifecycle.isCurrent() && lifecycle.isEnabled()
|
|
1500
|
+
);
|
|
1501
|
+
if (!lifecycle.isCurrent()) {
|
|
1502
|
+
return planModeQuestionCancelled(
|
|
1503
|
+
questions,
|
|
1504
|
+
"cancelled",
|
|
1505
|
+
"Plan-mode question cancelled because the session changed."
|
|
1506
|
+
);
|
|
1507
|
+
}
|
|
1508
|
+
if (!lifecycle.isEnabled()) {
|
|
1509
|
+
return planModeQuestionCancelled(
|
|
1510
|
+
questions,
|
|
1511
|
+
"plan_mode_inactive",
|
|
1512
|
+
"Plan-mode question cancelled because Plan mode is no longer active."
|
|
1513
|
+
);
|
|
1514
|
+
}
|
|
1515
|
+
if (!answers) {
|
|
1516
|
+
return planModeQuestionCancelled(
|
|
1517
|
+
questions,
|
|
1518
|
+
"cancelled",
|
|
1519
|
+
"User cancelled the Plan-mode question prompt."
|
|
1520
|
+
);
|
|
1521
|
+
}
|
|
1522
|
+
return planModeQuestionAnswered(questions, answers);
|
|
1523
|
+
}
|
|
1524
|
+
async function askPlanModeQuestions(questions, ctx, shouldContinue = () => true) {
|
|
1525
|
+
const { runQuestionnaire, sanitizeTerminalText } = await import("@narumitw/pi-tui-kit");
|
|
1526
|
+
if (!shouldContinue()) return void 0;
|
|
1527
|
+
const runnerQuestions = questions.map((question, index) => ({
|
|
1528
|
+
id: String(index),
|
|
1529
|
+
header: displayText(question.header, `Question ${index + 1}`, sanitizeTerminalText),
|
|
1530
|
+
prompt: displayText(question.question, `Question ${index + 1}`, sanitizeTerminalText),
|
|
1531
|
+
options: question.options.map((option, optionIndex) => ({
|
|
1532
|
+
...option,
|
|
1533
|
+
label: displayText(option.label, `Option ${optionIndex + 1}`, sanitizeTerminalText)
|
|
1534
|
+
}))
|
|
1535
|
+
}));
|
|
1536
|
+
const result = await runQuestionnaire(ctx, {
|
|
1537
|
+
questions: runnerQuestions,
|
|
1538
|
+
allowNotes: true,
|
|
1539
|
+
maxTextLength: MAX_PLAN_MODE_RESPONSE_LENGTH,
|
|
1540
|
+
signal: ctx.signal,
|
|
1541
|
+
isCurrent: shouldContinue
|
|
1542
|
+
});
|
|
1543
|
+
if (!shouldContinue()) return void 0;
|
|
1544
|
+
return mapQuestionnaireResult(questions, result);
|
|
1545
|
+
}
|
|
1546
|
+
function mapQuestionnaireResult(questions, result) {
|
|
1547
|
+
if (result.kind !== "submitted") return void 0;
|
|
1548
|
+
if (result.answers.length !== questions.length) {
|
|
1549
|
+
throw new Error("Questionnaire returned an incomplete answer set");
|
|
1550
|
+
}
|
|
1551
|
+
const answers = /* @__PURE__ */ new Map();
|
|
1552
|
+
for (const answer of result.answers) {
|
|
1553
|
+
const index = Number(answer.questionId);
|
|
1554
|
+
if (!Number.isSafeInteger(index) || String(index) !== answer.questionId || !questions[index]) {
|
|
1555
|
+
throw new Error("Questionnaire returned an answer for an unknown question");
|
|
1556
|
+
}
|
|
1557
|
+
if (answers.has(index)) throw new Error("Questionnaire returned duplicate answers");
|
|
1558
|
+
if (answer.wasCustom) {
|
|
1559
|
+
if (answer.optionIndex !== void 0) {
|
|
1560
|
+
throw new Error("Questionnaire returned a custom answer with an option index");
|
|
1561
|
+
}
|
|
1562
|
+
if (!answer.answer.trim()) return void 0;
|
|
1563
|
+
} else if (answer.optionIndex === void 0 || !questions[index]?.options[answer.optionIndex - 1]) {
|
|
1564
|
+
throw new Error("Questionnaire returned an invalid selected option");
|
|
1565
|
+
}
|
|
1566
|
+
answers.set(index, answer);
|
|
1567
|
+
}
|
|
1568
|
+
return questions.map((question, index) => {
|
|
1569
|
+
const answer = answers.get(index);
|
|
1570
|
+
if (!answer) throw new Error("Questionnaire returned an incomplete answer set");
|
|
1571
|
+
const answerText = answer.wasCustom ? answer.answer : question.options[(answer.optionIndex ?? 0) - 1]?.label ?? answer.answer;
|
|
1572
|
+
return answerFor(question, answerText, {
|
|
1573
|
+
wasCustom: answer.wasCustom,
|
|
1574
|
+
optionIndex: answer.optionIndex,
|
|
1575
|
+
note: answer.note
|
|
1576
|
+
});
|
|
1577
|
+
});
|
|
1578
|
+
}
|
|
1579
|
+
function displayText(value, fallback, sanitize) {
|
|
1580
|
+
const sanitized = sanitize(value);
|
|
1581
|
+
return sanitized.trim() ? sanitized : fallback;
|
|
1582
|
+
}
|
|
1583
|
+
function answerFor(question, answer, options) {
|
|
1584
|
+
const result = {
|
|
1585
|
+
id: question.id,
|
|
1586
|
+
header: question.header,
|
|
1587
|
+
question: question.question,
|
|
1588
|
+
answer,
|
|
1589
|
+
wasCustom: options.wasCustom
|
|
1590
|
+
};
|
|
1591
|
+
if (options.optionIndex !== void 0) result.optionIndex = options.optionIndex;
|
|
1592
|
+
if (options.note !== void 0) result.note = options.note;
|
|
1593
|
+
return result;
|
|
1594
|
+
}
|
|
1595
|
+
function planModeQuestionAnswered(questions, answers) {
|
|
1596
|
+
return {
|
|
1597
|
+
content: [
|
|
1598
|
+
{ type: "text", text: formatPlanModeQuestionPayload({ cancelled: false, answers }) }
|
|
1599
|
+
],
|
|
1600
|
+
details: { cancelled: false, questions, answers }
|
|
1601
|
+
};
|
|
1602
|
+
}
|
|
1603
|
+
function planModeQuestionCancelled(questions, reason, message) {
|
|
1604
|
+
return {
|
|
1605
|
+
content: [
|
|
1606
|
+
{
|
|
1607
|
+
type: "text",
|
|
1608
|
+
text: formatPlanModeQuestionPayload({ cancelled: true, reason, message })
|
|
1609
|
+
}
|
|
1610
|
+
],
|
|
1611
|
+
details: { cancelled: true, reason, questions }
|
|
1612
|
+
};
|
|
1613
|
+
}
|
|
1614
|
+
function formatPlanModeQuestionPayload(payload) {
|
|
1615
|
+
return JSON.stringify(payload, null, 2);
|
|
1616
|
+
}
|
|
1617
|
+
function isRecord2(value) {
|
|
1618
|
+
return typeof value === "object" && value !== null;
|
|
1619
|
+
}
|
|
1620
|
+
function stringField(value) {
|
|
1621
|
+
return typeof value === "string" ? value.trim() : void 0;
|
|
1622
|
+
}
|
|
1623
|
+
|
|
1637
1624
|
// src/tool-selection.ts
|
|
1638
1625
|
function toolNameFromLegacyKey(key, tools) {
|
|
1639
1626
|
const directName = tools.find((tool) => tool.name === key)?.name;
|
|
@@ -1662,20 +1649,14 @@ function toolSourceLabel(tool) {
|
|
|
1662
1649
|
function unique(values) {
|
|
1663
1650
|
return Array.from(new Set(values));
|
|
1664
1651
|
}
|
|
1665
|
-
function filterAvailableSelectedToolNames(names, tools) {
|
|
1666
|
-
const availableNames = new Set(tools.filter(canSelectToolInPlanMode).map((tool) => tool.name));
|
|
1667
|
-
return unique(names.filter((name) => availableNames.has(name)));
|
|
1668
|
-
}
|
|
1669
1652
|
function defaultPlanModeToolNames(tools, configuredNames) {
|
|
1670
|
-
if (configuredNames !== void 0)
|
|
1671
|
-
return filterAvailableSelectedToolNames(configuredNames, tools);
|
|
1672
|
-
}
|
|
1653
|
+
if (configuredNames !== void 0) return unique(configuredNames);
|
|
1673
1654
|
return tools.filter((tool) => isBuiltinTool(tool) && SAFE_BUILTIN_PLAN_TOOLS.has(tool.name)).map((tool) => tool.name);
|
|
1674
1655
|
}
|
|
1675
1656
|
function snapshotPlanModeSelectedNames(tools, selection) {
|
|
1676
1657
|
const selectedToolNames = selection.selectedToolNames ?? selection.selectedToolKeys?.map((key) => toolNameFromLegacyKey(key, tools)).filter((name) => name !== void 0);
|
|
1677
1658
|
return new Set(
|
|
1678
|
-
selectedToolNames === void 0 ? defaultPlanModeToolNames(tools, selection.defaultPlanTools) :
|
|
1659
|
+
selectedToolNames === void 0 ? defaultPlanModeToolNames(tools, selection.defaultPlanTools) : unique(selectedToolNames)
|
|
1679
1660
|
);
|
|
1680
1661
|
}
|
|
1681
1662
|
|
|
@@ -1692,11 +1673,6 @@ export {
|
|
|
1692
1673
|
latestAssistantText,
|
|
1693
1674
|
latestAssistantStopReason,
|
|
1694
1675
|
messageTextContent,
|
|
1695
|
-
PLAN_MODE_QUESTION_TOOL_NAME,
|
|
1696
|
-
PLAN_MODE_QUESTION_PARAMS,
|
|
1697
|
-
normalizePlanModeQuestionParams,
|
|
1698
|
-
answerPlanModeQuestions,
|
|
1699
|
-
planModeQuestionCancelled,
|
|
1700
1676
|
retentionLabel,
|
|
1701
1677
|
implementationRetentionPreview,
|
|
1702
1678
|
createImplementationRetentionCoordinator,
|
|
@@ -1707,24 +1683,25 @@ export {
|
|
|
1707
1683
|
findBlockedPowerShellCommandSegment,
|
|
1708
1684
|
PLAN_MODE_THINKING_LEVELS,
|
|
1709
1685
|
IMPLEMENTATION_PLAN_RETENTIONS,
|
|
1710
|
-
PLAN_MODE_TOOL_VISIBILITIES,
|
|
1711
1686
|
planModeSettingsPath,
|
|
1712
1687
|
normalizeKeyId,
|
|
1713
1688
|
readPlanModeSettings,
|
|
1714
1689
|
updatePlanModeSettings,
|
|
1715
1690
|
awaitPlanModeSettingsWrites,
|
|
1716
1691
|
configuredThinkingLevel,
|
|
1717
|
-
configuredPlanModeToolVisibility,
|
|
1718
1692
|
configuredImplementationPlanRetention,
|
|
1719
1693
|
configuredPlanExportPath,
|
|
1720
1694
|
configuredPlanModeToggleShortcut,
|
|
1721
1695
|
exportStoredPlan,
|
|
1722
1696
|
planExportDestination,
|
|
1697
|
+
PLAN_MODE_QUESTION_TOOL_NAME,
|
|
1698
|
+
PLAN_MODE_QUESTION_PARAMS,
|
|
1699
|
+
normalizePlanModeQuestionParams,
|
|
1700
|
+
answerPlanModeQuestions,
|
|
1701
|
+
planModeQuestionCancelled,
|
|
1723
1702
|
compareTools,
|
|
1724
1703
|
toolPolicyLabel,
|
|
1725
|
-
unique,
|
|
1726
|
-
filterAvailableSelectedToolNames,
|
|
1727
1704
|
defaultPlanModeToolNames,
|
|
1728
1705
|
snapshotPlanModeSelectedNames
|
|
1729
1706
|
};
|
|
1730
|
-
//# sourceMappingURL=chunk-
|
|
1707
|
+
//# sourceMappingURL=chunk-AS76FCC5.js.map
|