@narumitw/pi-plan-mode 0.53.0 → 0.55.0

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.
@@ -1,5 +1,5 @@
1
1
  // @generated by scripts/build-runtime.mjs; do not edit.
2
- // @ts-nocheck -- generated JavaScript uses a .ts extension for Pi's Jiti loader.
2
+ // @ts-nocheck -- the generated entry uses a .ts extension for Pi's Jiti loader.
3
3
 
4
4
  // src/completion-tool.ts
5
5
  import { getMarkdownTheme } from "@earendil-works/pi-coding-agent";
@@ -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 {
@@ -644,7 +410,14 @@ var SAFE_GIT_SUBCOMMANDS = [
644
410
  ...CONFIGURABLE_SAFE_GIT_SUBCOMMANDS
645
411
  ];
646
412
  var SAFE_GH_SUBCOMMAND_PATHS = ["pr view", "pr list", "issue view", "issue list"];
647
- var SAFE_BUILTIN_PLAN_TOOLS = /* @__PURE__ */ new Set(["read", "bash", "grep", "find", "ls"]);
413
+ var SAFE_BUILTIN_PLAN_TOOLS = /* @__PURE__ */ new Set([
414
+ "read",
415
+ "bash",
416
+ "powershell",
417
+ "grep",
418
+ "find",
419
+ "ls"
420
+ ]);
648
421
  var BLOCKED_BUILTIN_TOOLS = /* @__PURE__ */ new Set(["edit", "write"]);
649
422
  var MUTATING_COMMANDS = /* @__PURE__ */ new Set([
650
423
  "rm",
@@ -674,6 +447,21 @@ var MUTATING_COMMANDS = /* @__PURE__ */ new Set([
674
447
  "code",
675
448
  "subl"
676
449
  ]);
450
+ var READ_ONLY_POWERSHELL_COMMANDS = /* @__PURE__ */ new Set([
451
+ "format-list",
452
+ "format-table",
453
+ "get-childitem",
454
+ "get-content",
455
+ "get-item",
456
+ "get-location",
457
+ "measure-object",
458
+ "out-string",
459
+ "resolve-path",
460
+ "select-string",
461
+ "sort-object",
462
+ "test-path",
463
+ "write-output"
464
+ ]);
677
465
  var READ_ONLY_COMMANDS = /* @__PURE__ */ new Set([
678
466
  "cat",
679
467
  "head",
@@ -715,7 +503,7 @@ function isBuiltinTool(tool) {
715
503
  function classifyPlanModeTool(tool) {
716
504
  if (!isBuiltinTool(tool)) return "user-opt-in";
717
505
  if (BLOCKED_BUILTIN_TOOLS.has(tool.name)) return "blocked";
718
- if (tool.name === "bash") return "limited";
506
+ if (tool.name === "bash" || tool.name === "powershell") return "limited";
719
507
  return SAFE_BUILTIN_PLAN_TOOLS.has(tool.name) ? "read-only" : "blocked";
720
508
  }
721
509
  function canSelectToolInPlanMode(tool) {
@@ -730,6 +518,107 @@ function findBlockedCommandSegment(command, safeSubcommands = {}) {
730
518
  if (!segments || segments.length === 0) return command.trim() || "(empty command)";
731
519
  return segments.find((segment) => !isSafeSegment(segment, safeSubcommands));
732
520
  }
521
+ function findBlockedPowerShellCommandSegment(command, safeSubcommands = {}) {
522
+ const segments = splitPowerShellSegments(command);
523
+ if (!segments || segments.length === 0) return command.trim() || "(empty command)";
524
+ return segments.find((segment) => !isSafePowerShellSegment(segment, safeSubcommands));
525
+ }
526
+ function splitPowerShellSegments(command) {
527
+ const trimmed = command.trim();
528
+ if (!trimmed || /[\n\r`\u2018-\u201e]/.test(trimmed)) return void 0;
529
+ const segments = [];
530
+ let quote;
531
+ let start = 0;
532
+ for (let index = 0; index < trimmed.length; index += 1) {
533
+ const character = trimmed[index];
534
+ if (quote === "'") {
535
+ if (character !== "'") continue;
536
+ if (trimmed[index + 1] === "'") {
537
+ index += 1;
538
+ continue;
539
+ }
540
+ quote = void 0;
541
+ continue;
542
+ }
543
+ if (quote === '"') {
544
+ if (character === "$" || character === "`") return void 0;
545
+ if (character === '"') quote = void 0;
546
+ continue;
547
+ }
548
+ if (character === "'" || character === '"') {
549
+ quote = character;
550
+ continue;
551
+ }
552
+ if (["$", "@", "#", "!", "?", "{", "}", "(", ")", "[", "]", ">", "<"].includes(character)) {
553
+ return void 0;
554
+ }
555
+ const next = trimmed[index + 1];
556
+ if (character === "&" || character === "|" && next === "|") return void 0;
557
+ const separatorLength = character === ";" || character === "|" ? 1 : 0;
558
+ if (separatorLength === 0) continue;
559
+ const segment = trimmed.slice(start, index).trim();
560
+ if (!segment) return void 0;
561
+ segments.push(segment);
562
+ index += separatorLength - 1;
563
+ start = index + 1;
564
+ }
565
+ if (quote) return void 0;
566
+ const finalSegment = trimmed.slice(start).trim();
567
+ if (!finalSegment) return void 0;
568
+ segments.push(finalSegment);
569
+ return segments;
570
+ }
571
+ function isSafePowerShellSegment(segment, safeSubcommands) {
572
+ const tokens = powerShellWords(segment);
573
+ if (!tokens || tokens.length === 0 || tokens.includes("--%")) return false;
574
+ const command = tokens[0]?.toLowerCase();
575
+ if (!command) return false;
576
+ const args = tokens.slice(1);
577
+ if (READ_ONLY_POWERSHELL_COMMANDS.has(command)) return true;
578
+ if (command !== "git" && command !== "gh") return false;
579
+ return isSafeStructuredCommand(command, args, safeSubcommands);
580
+ }
581
+ function powerShellWords(segment) {
582
+ const words = [];
583
+ let word = "";
584
+ let hasWord = false;
585
+ let quote;
586
+ for (let index = 0; index < segment.length; index += 1) {
587
+ const character = segment[index];
588
+ if (quote === "'") {
589
+ if (character !== "'") {
590
+ word += character;
591
+ continue;
592
+ }
593
+ if (segment[index + 1] === "'") {
594
+ word += "'";
595
+ index += 1;
596
+ continue;
597
+ }
598
+ quote = void 0;
599
+ continue;
600
+ }
601
+ if (quote === '"') {
602
+ if (character === '"') quote = void 0;
603
+ else word += character;
604
+ continue;
605
+ }
606
+ if (character === "'" || character === '"') {
607
+ quote = character;
608
+ hasWord = true;
609
+ } else if (/\s/.test(character)) {
610
+ if (hasWord) words.push(word);
611
+ word = "";
612
+ hasWord = false;
613
+ } else {
614
+ word += character;
615
+ hasWord = true;
616
+ }
617
+ }
618
+ if (quote) return void 0;
619
+ if (hasWord) words.push(word);
620
+ return words;
621
+ }
733
622
  function splitShellSegments(command) {
734
623
  const trimmed = command.trim();
735
624
  if (!trimmed || /[\n\r`]/.test(trimmed)) return void 0;
@@ -1050,8 +939,6 @@ var IMPLEMENTATION_PLAN_RETENTIONS = [
1050
939
  "clear-after-first-run",
1051
940
  "keep"
1052
941
  ];
1053
- var PLAN_MODE_TOOL_VISIBILITIES = ["always", "after-first-plan"];
1054
- var DEFAULT_PLAN_MODE_TOOL_VISIBILITY = "after-first-plan";
1055
942
  var DEFAULT_PLAN_EXPORT_PATH = "PLAN.md";
1056
943
  var MODIFIERS = /* @__PURE__ */ new Set(["ctrl", "shift", "alt", "super"]);
1057
944
  var BASE_KEYS = /* @__PURE__ */ new Set([
@@ -1124,13 +1011,6 @@ function normalizePlanModeSettings(value) {
1124
1011
  const settings = {
1125
1012
  thinkingLevel
1126
1013
  };
1127
- if (Object.hasOwn(value, "toolVisibility")) {
1128
- const toolVisibility = Reflect.get(value, "toolVisibility");
1129
- if (!PLAN_MODE_TOOL_VISIBILITIES.includes(toolVisibility)) {
1130
- return void 0;
1131
- }
1132
- settings.toolVisibility = toolVisibility;
1133
- }
1134
1014
  if (Object.hasOwn(value, "defaultPlanTools")) {
1135
1015
  const defaultPlanTools = normalizeToolNames(Reflect.get(value, "defaultPlanTools"));
1136
1016
  if (!defaultPlanTools) return void 0;
@@ -1248,7 +1128,6 @@ function updatePlanModeSettings(patch, options = {}) {
1248
1128
  const current = await readSettingsDocumentForUpdate(settingsPath, legacySettingsPath);
1249
1129
  const updated = { ...current };
1250
1130
  if (patch.thinkingLevel !== void 0) updated.thinkingLevel = patch.thinkingLevel;
1251
- if (patch.toolVisibility !== void 0) updated.toolVisibility = patch.toolVisibility;
1252
1131
  if (patch.defaultPlanTools === null) delete updated.defaultPlanTools;
1253
1132
  else if (patch.defaultPlanTools !== void 0) {
1254
1133
  updated.defaultPlanTools = [...patch.defaultPlanTools];
@@ -1407,9 +1286,6 @@ function safeReadError(error) {
1407
1286
  function configuredThinkingLevel(settings) {
1408
1287
  return settings.thinkingLevel === "inherit" ? void 0 : settings.thinkingLevel;
1409
1288
  }
1410
- function configuredPlanModeToolVisibility(settings) {
1411
- return settings.toolVisibility ?? DEFAULT_PLAN_MODE_TOOL_VISIBILITY;
1412
- }
1413
1289
  function configuredImplementationPlanRetention(settings) {
1414
1290
  return settings.implementationPlanRetention ?? "clear-on-start";
1415
1291
  }
@@ -1511,6 +1387,240 @@ function isNodeError2(error) {
1511
1387
  return error instanceof Error && "code" in error;
1512
1388
  }
1513
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
+
1514
1624
  // src/tool-selection.ts
1515
1625
  function toolNameFromLegacyKey(key, tools) {
1516
1626
  const directName = tools.find((tool) => tool.name === key)?.name;
@@ -1569,11 +1679,6 @@ export {
1569
1679
  latestAssistantText,
1570
1680
  latestAssistantStopReason,
1571
1681
  messageTextContent,
1572
- PLAN_MODE_QUESTION_TOOL_NAME,
1573
- PLAN_MODE_QUESTION_PARAMS,
1574
- normalizePlanModeQuestionParams,
1575
- answerPlanModeQuestions,
1576
- planModeQuestionCancelled,
1577
1682
  retentionLabel,
1578
1683
  implementationRetentionPreview,
1579
1684
  createImplementationRetentionCoordinator,
@@ -1581,21 +1686,25 @@ export {
1581
1686
  canSelectToolInPlanMode,
1582
1687
  readCommand,
1583
1688
  findBlockedCommandSegment,
1689
+ findBlockedPowerShellCommandSegment,
1584
1690
  PLAN_MODE_THINKING_LEVELS,
1585
1691
  IMPLEMENTATION_PLAN_RETENTIONS,
1586
- PLAN_MODE_TOOL_VISIBILITIES,
1587
1692
  planModeSettingsPath,
1588
1693
  normalizeKeyId,
1589
1694
  readPlanModeSettings,
1590
1695
  updatePlanModeSettings,
1591
1696
  awaitPlanModeSettingsWrites,
1592
1697
  configuredThinkingLevel,
1593
- configuredPlanModeToolVisibility,
1594
1698
  configuredImplementationPlanRetention,
1595
1699
  configuredPlanExportPath,
1596
1700
  configuredPlanModeToggleShortcut,
1597
1701
  exportStoredPlan,
1598
1702
  planExportDestination,
1703
+ PLAN_MODE_QUESTION_TOOL_NAME,
1704
+ PLAN_MODE_QUESTION_PARAMS,
1705
+ normalizePlanModeQuestionParams,
1706
+ answerPlanModeQuestions,
1707
+ planModeQuestionCancelled,
1599
1708
  compareTools,
1600
1709
  toolPolicyLabel,
1601
1710
  unique,
@@ -1603,4 +1712,4 @@ export {
1603
1712
  defaultPlanModeToolNames,
1604
1713
  snapshotPlanModeSelectedNames
1605
1714
  };
1606
- //# sourceMappingURL=chunk-D2V3VWND.ts.map
1715
+ //# sourceMappingURL=chunk-KSGLZ4S2.js.map