@narumitw/pi-plan-mode 0.51.0 → 0.51.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 +7 -4
- package/dist/chunks/{chunk-VMD6XCI5.ts → chunk-H3RGWRY7.ts} +53 -608
- package/dist/chunks/{chunk-VMD6XCI5.ts.map → chunk-H3RGWRY7.ts.map} +3 -3
- package/dist/chunks/{interactive-ui-ROT43QBA.ts → interactive-ui-GFNX5OF4.ts} +2 -2
- package/dist/index.ts +2 -2
- package/package.json +2 -2
- package/src/question-tool.ts +65 -738
- /package/dist/chunks/{interactive-ui-ROT43QBA.ts.map → interactive-ui-GFNX5OF4.ts.map} +0 -0
|
@@ -1176,19 +1176,8 @@ function isNodeError2(error) {
|
|
|
1176
1176
|
}
|
|
1177
1177
|
|
|
1178
1178
|
// src/question-tool.ts
|
|
1179
|
-
import { stripVTControlCharacters as stripVTControlCharacters2 } from "node:util";
|
|
1180
|
-
import {
|
|
1181
|
-
Editor,
|
|
1182
|
-
Key,
|
|
1183
|
-
matchesKey,
|
|
1184
|
-
sliceByColumn,
|
|
1185
|
-
truncateToWidth,
|
|
1186
|
-
visibleWidth
|
|
1187
|
-
} from "@earendil-works/pi-tui";
|
|
1188
1179
|
var PLAN_MODE_QUESTION_TOOL_NAME = "plan_mode_question";
|
|
1189
1180
|
var MAX_PLAN_MODE_RESPONSE_LENGTH = 4e3;
|
|
1190
|
-
var BRACKETED_PASTE_START = "\x1B[200~";
|
|
1191
|
-
var BRACKETED_PASTE_END = "\x1B[201~";
|
|
1192
1181
|
var PLAN_MODE_QUESTION_PARAMS = {
|
|
1193
1182
|
type: "object",
|
|
1194
1183
|
additionalProperties: false,
|
|
@@ -1321,521 +1310,63 @@ async function answerPlanModeQuestions(questions, ctx, lifecycle) {
|
|
|
1321
1310
|
return planModeQuestionAnswered(questions, answers);
|
|
1322
1311
|
}
|
|
1323
1312
|
async function askPlanModeQuestions(questions, ctx, shouldContinue = () => true) {
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
}
|
|
1356
|
-
const optionIndex = choices.indexOf(choice);
|
|
1357
|
-
const option = question.options[optionIndex];
|
|
1358
|
-
if (!option) return void 0;
|
|
1359
|
-
answers.push(
|
|
1360
|
-
answerFor(question, option.label, { wasCustom: false, optionIndex: optionIndex + 1 })
|
|
1361
|
-
);
|
|
1362
|
-
}
|
|
1363
|
-
return answers;
|
|
1364
|
-
}
|
|
1365
|
-
async function askCustomAnswer(question, ctx, shouldContinue) {
|
|
1366
|
-
let draft = "";
|
|
1367
|
-
for (; ; ) {
|
|
1368
|
-
const customAnswer = await ctx.ui.editor(question.question, draft);
|
|
1369
|
-
if (!shouldContinue() || !customAnswer?.trim()) return void 0;
|
|
1370
|
-
if (customAnswer.length <= MAX_PLAN_MODE_RESPONSE_LENGTH) return customAnswer;
|
|
1371
|
-
draft = customAnswer;
|
|
1372
|
-
ctx.ui.notify("Custom answer must be 4,000 characters or fewer.", "warning");
|
|
1373
|
-
}
|
|
1374
|
-
}
|
|
1375
|
-
var PlanModeQuestionnaire = class {
|
|
1376
|
-
options;
|
|
1377
|
-
editor;
|
|
1378
|
-
answers;
|
|
1379
|
-
selectedOptions;
|
|
1380
|
-
page = 0;
|
|
1381
|
-
editorKind;
|
|
1382
|
-
message;
|
|
1383
|
-
finished = false;
|
|
1384
|
-
removeAbort = () => {
|
|
1385
|
-
};
|
|
1386
|
-
_focused = false;
|
|
1387
|
-
constructor(options) {
|
|
1388
|
-
this.options = options;
|
|
1389
|
-
this.answers = options.questions.map(() => void 0);
|
|
1390
|
-
this.selectedOptions = options.questions.map(() => 0);
|
|
1391
|
-
const editorTheme = {
|
|
1392
|
-
borderColor: (text) => options.theme.fg("accent", text),
|
|
1393
|
-
selectList: {
|
|
1394
|
-
selectedPrefix: (text) => options.theme.fg("accent", text),
|
|
1395
|
-
selectedText: (text) => options.theme.fg("accent", text),
|
|
1396
|
-
description: (text) => options.theme.fg("muted", text),
|
|
1397
|
-
scrollInfo: (text) => options.theme.fg("dim", text),
|
|
1398
|
-
noMatch: (text) => options.theme.fg("warning", text)
|
|
1399
|
-
}
|
|
1400
|
-
};
|
|
1401
|
-
this.editor = new RawPreservingEditor(options.tui, editorTheme);
|
|
1402
|
-
this.editor.onChange = () => {
|
|
1403
|
-
this.message = void 0;
|
|
1404
|
-
};
|
|
1405
|
-
this.editor.onSubmit = (text) => this.submitEditor(text);
|
|
1406
|
-
if (options.signal) {
|
|
1407
|
-
const abort = () => this.finish(void 0);
|
|
1408
|
-
options.signal.addEventListener("abort", abort, { once: true });
|
|
1409
|
-
this.removeAbort = () => options.signal?.removeEventListener("abort", abort);
|
|
1410
|
-
if (options.signal.aborted) abort();
|
|
1411
|
-
}
|
|
1412
|
-
}
|
|
1413
|
-
get focused() {
|
|
1414
|
-
return this._focused;
|
|
1415
|
-
}
|
|
1416
|
-
set focused(value) {
|
|
1417
|
-
this._focused = value;
|
|
1418
|
-
this.editor.focused = value && this.editorKind !== void 0;
|
|
1419
|
-
}
|
|
1420
|
-
render(width) {
|
|
1421
|
-
const safeWidth = Math.max(1, width);
|
|
1422
|
-
const padding = safeWidth > 1 ? " " : "";
|
|
1423
|
-
const contentWidth = Math.max(1, safeWidth - visibleWidth(padding));
|
|
1424
|
-
const border = this.options.theme.fg("border", "\u2500".repeat(safeWidth));
|
|
1425
|
-
const lines = [border, "", ...this.renderTabs(contentWidth), ""];
|
|
1426
|
-
if (this.page === this.options.questions.length) lines.push(...this.renderReview(contentWidth));
|
|
1427
|
-
else lines.push(...this.renderQuestion(contentWidth));
|
|
1428
|
-
if (this.message)
|
|
1429
|
-
lines.push(...hardWrap(this.options.theme.fg("warning", this.message), contentWidth));
|
|
1430
|
-
lines.push("");
|
|
1431
|
-
lines.push(truncateToWidth(this.renderHints(), contentWidth), "", border);
|
|
1432
|
-
return lines.map((line) => {
|
|
1433
|
-
if (!line || line === border) return line;
|
|
1434
|
-
return `${padding}${truncateToWidth(line, contentWidth)}`;
|
|
1435
|
-
});
|
|
1436
|
-
}
|
|
1437
|
-
handleInput(data) {
|
|
1438
|
-
if (this.finished) return;
|
|
1439
|
-
if (!this.options.shouldContinue() || this.isCancel(data)) {
|
|
1440
|
-
this.finish(void 0);
|
|
1441
|
-
return;
|
|
1442
|
-
}
|
|
1443
|
-
if (this.editorKind) this.handleEditorInput(data);
|
|
1444
|
-
else this.handlePageInput(data);
|
|
1445
|
-
this.options.tui.requestRender();
|
|
1446
|
-
}
|
|
1447
|
-
invalidate() {
|
|
1448
|
-
this.editor.invalidate();
|
|
1449
|
-
}
|
|
1450
|
-
dispose() {
|
|
1451
|
-
this.finish(void 0);
|
|
1452
|
-
}
|
|
1453
|
-
isCancel(data) {
|
|
1454
|
-
return matchesKey(data, Key.ctrl("c")) || this.options.keybindings.matches(data, "tui.select.cancel");
|
|
1455
|
-
}
|
|
1456
|
-
handleEditorInput(data) {
|
|
1457
|
-
const keybindings = this.options.keybindings;
|
|
1458
|
-
if (keybindings.matches(data, "tui.input.newLine")) {
|
|
1459
|
-
this.editor.handleInput(data);
|
|
1460
|
-
} else if (keybindings.matches(data, "tui.input.submit")) {
|
|
1461
|
-
this.submitEditor(this.editor.getExpandedText());
|
|
1462
|
-
} else {
|
|
1463
|
-
this.editor.handleInput(data);
|
|
1464
|
-
}
|
|
1465
|
-
}
|
|
1466
|
-
handlePageInput(data) {
|
|
1467
|
-
const keybindings = this.options.keybindings;
|
|
1468
|
-
const review = this.page === this.options.questions.length;
|
|
1469
|
-
if (keybindings.matches(data, "tui.select.up") || data === "k") {
|
|
1470
|
-
if (!review) this.moveSelection(-1);
|
|
1471
|
-
return;
|
|
1472
|
-
}
|
|
1473
|
-
if (keybindings.matches(data, "tui.select.down") || data === "j") {
|
|
1474
|
-
if (!review) this.moveSelection(1);
|
|
1475
|
-
return;
|
|
1476
|
-
}
|
|
1477
|
-
if (keybindings.matches(data, "tui.select.confirm")) {
|
|
1478
|
-
this.submitPage();
|
|
1479
|
-
return;
|
|
1480
|
-
}
|
|
1481
|
-
if (keybindings.matches(data, "tui.input.tab") || matchesKey(data, Key.right)) {
|
|
1482
|
-
this.movePage(1);
|
|
1483
|
-
return;
|
|
1484
|
-
}
|
|
1485
|
-
if (matchesKey(data, Key.shift("tab")) || matchesKey(data, Key.left)) {
|
|
1486
|
-
this.movePage(-1);
|
|
1487
|
-
return;
|
|
1488
|
-
}
|
|
1489
|
-
if (data.toLowerCase() === "n") {
|
|
1490
|
-
if (review) this.message = "Return to a question to add or edit its note.";
|
|
1491
|
-
else this.editNote();
|
|
1492
|
-
}
|
|
1493
|
-
}
|
|
1494
|
-
renderHints() {
|
|
1495
|
-
const { keybindings, theme } = this.options;
|
|
1496
|
-
const cancel = cancelHint(theme, keybindings);
|
|
1497
|
-
if (this.editorKind) {
|
|
1498
|
-
return [
|
|
1499
|
-
keybindingHint(theme, keybindings, "tui.input.submit", "save"),
|
|
1500
|
-
keybindingHint(theme, keybindings, "tui.input.newLine", "newline"),
|
|
1501
|
-
cancel
|
|
1502
|
-
].join(" ");
|
|
1503
|
-
}
|
|
1504
|
-
const questions = rawKeyHint(theme, questionNavigationKeys(keybindings), "questions");
|
|
1505
|
-
if (this.page === this.options.questions.length) {
|
|
1506
|
-
return [
|
|
1507
|
-
keybindingHint(theme, keybindings, "tui.select.confirm", "submit"),
|
|
1508
|
-
cancel,
|
|
1509
|
-
questions
|
|
1510
|
-
].join(" ");
|
|
1511
|
-
}
|
|
1512
|
-
return [
|
|
1513
|
-
rawKeyHint(theme, selectionNavigationKeys(keybindings), "navigate"),
|
|
1514
|
-
keybindingHint(theme, keybindings, "tui.select.confirm", "select"),
|
|
1515
|
-
cancel,
|
|
1516
|
-
questions,
|
|
1517
|
-
rawKeyHint(theme, "n", "note")
|
|
1518
|
-
].join(" ");
|
|
1519
|
-
}
|
|
1520
|
-
movePage(delta) {
|
|
1521
|
-
const pageCount = this.options.questions.length + 1;
|
|
1522
|
-
this.page = (this.page + delta + pageCount) % pageCount;
|
|
1523
|
-
const answer = this.answers[this.page];
|
|
1524
|
-
const question = this.options.questions[this.page];
|
|
1525
|
-
if (answer?.wasCustom && question) {
|
|
1526
|
-
this.selectedOptions[this.page] = question.options.length;
|
|
1527
|
-
} else if (answer?.optionIndex !== void 0) {
|
|
1528
|
-
this.selectedOptions[this.page] = answer.optionIndex - 1;
|
|
1529
|
-
}
|
|
1530
|
-
this.message = void 0;
|
|
1531
|
-
}
|
|
1532
|
-
renderTabs(width) {
|
|
1533
|
-
const tabs = [
|
|
1534
|
-
...this.options.questions.map((question, index) => {
|
|
1535
|
-
const label = sanitizeTerminalText(question.header) || `Question ${index + 1}`;
|
|
1536
|
-
const answered = this.answers[index] ? "\u2713 " : "";
|
|
1537
|
-
return this.page === index ? `[${answered}${label}]` : `${answered}${label}`;
|
|
1538
|
-
}),
|
|
1539
|
-
this.page === this.options.questions.length ? "[Review]" : "Review"
|
|
1540
|
-
];
|
|
1541
|
-
const lines = [];
|
|
1542
|
-
let line = "";
|
|
1543
|
-
for (const tab of tabs) {
|
|
1544
|
-
const boundedTab = truncateToWidth(tab, width, "\u2026");
|
|
1545
|
-
const candidate = line ? `${line} ${boundedTab}` : boundedTab;
|
|
1546
|
-
if (line && visibleWidth(candidate) > width) {
|
|
1547
|
-
lines.push(this.options.theme.fg("accent", line));
|
|
1548
|
-
line = boundedTab;
|
|
1549
|
-
} else {
|
|
1550
|
-
line = candidate;
|
|
1551
|
-
}
|
|
1552
|
-
}
|
|
1553
|
-
if (line) lines.push(this.options.theme.fg("accent", line));
|
|
1554
|
-
return lines;
|
|
1555
|
-
}
|
|
1556
|
-
renderQuestion(width) {
|
|
1557
|
-
const question = this.options.questions[this.page];
|
|
1558
|
-
if (!question) return [];
|
|
1559
|
-
const lines = hardWrap(
|
|
1560
|
-
this.options.theme.fg(
|
|
1561
|
-
"accent",
|
|
1562
|
-
this.options.theme.bold(sanitizeTerminalText(question.question))
|
|
1563
|
-
),
|
|
1564
|
-
width
|
|
1565
|
-
);
|
|
1566
|
-
lines.push("");
|
|
1567
|
-
question.options.forEach((option, index) => {
|
|
1568
|
-
const selected = this.selectedOptions[this.page] === index;
|
|
1569
|
-
const cursor = selected ? "\u2192" : " ";
|
|
1570
|
-
const label = `${cursor} ${index + 1}. ${sanitizeTerminalText(option.label)}`;
|
|
1571
|
-
const chosen = this.answers[this.page]?.optionIndex === index + 1;
|
|
1572
|
-
const description = option.description ? ` \u2014 ${sanitizeTerminalText(option.description)}` : "";
|
|
1573
|
-
const line = selected ? this.options.theme.fg("accent", `${label}${chosen ? " \u2713" : ""}${description}`) : `${this.options.theme.fg("text", label)}${chosen ? this.options.theme.fg("success", " \u2713") : ""}${description ? this.options.theme.fg("muted", description) : ""}`;
|
|
1574
|
-
lines.push(...hardWrapWithIndent(line, width, visibleWidth(`${cursor} ${index + 1}. `)));
|
|
1575
|
-
});
|
|
1576
|
-
const otherIndex = question.options.length;
|
|
1577
|
-
const otherSelected = this.selectedOptions[this.page] === otherIndex;
|
|
1578
|
-
const otherCursor = otherSelected ? "\u2192" : " ";
|
|
1579
|
-
const otherLabel = `${otherCursor} ${otherIndex + 1}. Other (free-form)`;
|
|
1580
|
-
const otherChosen = this.answers[this.page]?.wasCustom === true;
|
|
1581
|
-
lines.push(
|
|
1582
|
-
otherSelected ? this.options.theme.fg("accent", `${otherLabel}${otherChosen ? " \u2713" : ""}`) : `${this.options.theme.fg("text", otherLabel)}${otherChosen ? this.options.theme.fg("success", " \u2713") : ""}`
|
|
1583
|
-
);
|
|
1584
|
-
const answer = this.answers[this.page];
|
|
1585
|
-
if (answer?.wasCustom)
|
|
1586
|
-
lines.push(...labeledRaw("Answer", answer.answer, width, this.options.theme));
|
|
1587
|
-
if (answer?.note) lines.push(...labeledRaw("Note", answer.note, width, this.options.theme));
|
|
1588
|
-
if (this.editorKind) {
|
|
1589
|
-
lines.push("");
|
|
1590
|
-
lines.push(
|
|
1591
|
-
this.options.theme.fg(
|
|
1592
|
-
"accent",
|
|
1593
|
-
this.editorKind === "answer" ? "Custom answer" : "Optional note"
|
|
1594
|
-
)
|
|
1595
|
-
);
|
|
1596
|
-
lines.push(...this.editor.render(width));
|
|
1313
|
+
const { runQuestionnaire, sanitizeTerminalText } = await import("@narumitw/pi-tui-kit");
|
|
1314
|
+
if (!shouldContinue()) return void 0;
|
|
1315
|
+
const runnerQuestions = questions.map((question, index) => ({
|
|
1316
|
+
id: String(index),
|
|
1317
|
+
header: displayText(question.header, `Question ${index + 1}`, sanitizeTerminalText),
|
|
1318
|
+
prompt: displayText(question.question, `Question ${index + 1}`, sanitizeTerminalText),
|
|
1319
|
+
options: question.options.map((option, optionIndex) => ({
|
|
1320
|
+
...option,
|
|
1321
|
+
label: displayText(option.label, `Option ${optionIndex + 1}`, sanitizeTerminalText)
|
|
1322
|
+
}))
|
|
1323
|
+
}));
|
|
1324
|
+
const result = await runQuestionnaire(ctx, {
|
|
1325
|
+
questions: runnerQuestions,
|
|
1326
|
+
allowNotes: true,
|
|
1327
|
+
maxTextLength: MAX_PLAN_MODE_RESPONSE_LENGTH,
|
|
1328
|
+
signal: ctx.signal,
|
|
1329
|
+
isCurrent: shouldContinue
|
|
1330
|
+
});
|
|
1331
|
+
if (!shouldContinue()) return void 0;
|
|
1332
|
+
return mapQuestionnaireResult(questions, result);
|
|
1333
|
+
}
|
|
1334
|
+
function mapQuestionnaireResult(questions, result) {
|
|
1335
|
+
if (result.kind !== "submitted") return void 0;
|
|
1336
|
+
if (result.answers.length !== questions.length) {
|
|
1337
|
+
throw new Error("Questionnaire returned an incomplete answer set");
|
|
1338
|
+
}
|
|
1339
|
+
const answers = /* @__PURE__ */ new Map();
|
|
1340
|
+
for (const answer of result.answers) {
|
|
1341
|
+
const index = Number(answer.questionId);
|
|
1342
|
+
if (!Number.isSafeInteger(index) || String(index) !== answer.questionId || !questions[index]) {
|
|
1343
|
+
throw new Error("Questionnaire returned an answer for an unknown question");
|
|
1597
1344
|
}
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
this.options.questions.forEach((question, index) => {
|
|
1603
|
-
const answer = this.answers[index];
|
|
1604
|
-
const header = sanitizeTerminalText(question.header) || `Question ${index + 1}`;
|
|
1605
|
-
const label = `${index + 1}. ${header}`;
|
|
1606
|
-
const summary = ` \u2014 ${inlineSummary(answer?.answer ?? "Unanswered")}${answer?.note ? ` \xB7 Note: ${inlineSummary(answer.note)}` : ""}`;
|
|
1607
|
-
const line = `${this.options.theme.fg("text", label)}${this.options.theme.fg("muted", summary)}`;
|
|
1608
|
-
lines.push(...hardWrapWithIndent(line, width, visibleWidth(`${index + 1}. `)));
|
|
1609
|
-
});
|
|
1610
|
-
return lines;
|
|
1611
|
-
}
|
|
1612
|
-
moveSelection(delta) {
|
|
1613
|
-
const optionCount = (this.options.questions[this.page]?.options.length ?? 0) + 1;
|
|
1614
|
-
this.selectedOptions[this.page] = ((this.selectedOptions[this.page] ?? 0) + delta + optionCount) % optionCount;
|
|
1615
|
-
}
|
|
1616
|
-
submitPage() {
|
|
1617
|
-
if (this.page === this.options.questions.length) {
|
|
1618
|
-
const firstMissing = this.answers.findIndex((answer) => !answer);
|
|
1619
|
-
if (firstMissing >= 0) {
|
|
1620
|
-
this.message = "Answer every question before submitting.";
|
|
1621
|
-
return;
|
|
1345
|
+
if (answers.has(index)) throw new Error("Questionnaire returned duplicate answers");
|
|
1346
|
+
if (answer.wasCustom) {
|
|
1347
|
+
if (answer.optionIndex !== void 0) {
|
|
1348
|
+
throw new Error("Questionnaire returned a custom answer with an option index");
|
|
1622
1349
|
}
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
);
|
|
1626
|
-
return;
|
|
1627
|
-
}
|
|
1628
|
-
const question = this.options.questions[this.page];
|
|
1629
|
-
if (!question) return;
|
|
1630
|
-
const selected = this.selectedOptions[this.page] ?? 0;
|
|
1631
|
-
if (selected === question.options.length) {
|
|
1632
|
-
this.beginEditor(
|
|
1633
|
-
"answer",
|
|
1634
|
-
this.answers[this.page]?.wasCustom ? this.answers[this.page]?.answer : ""
|
|
1635
|
-
);
|
|
1636
|
-
return;
|
|
1350
|
+
if (!answer.answer.trim()) return void 0;
|
|
1351
|
+
} else if (answer.optionIndex === void 0 || !questions[index]?.options[answer.optionIndex - 1]) {
|
|
1352
|
+
throw new Error("Questionnaire returned an invalid selected option");
|
|
1637
1353
|
}
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1354
|
+
answers.set(index, answer);
|
|
1355
|
+
}
|
|
1356
|
+
return questions.map((question, index) => {
|
|
1357
|
+
const answer = answers.get(index);
|
|
1358
|
+
if (!answer) throw new Error("Questionnaire returned an incomplete answer set");
|
|
1359
|
+
const answerText = answer.wasCustom ? answer.answer : question.options[(answer.optionIndex ?? 0) - 1]?.label ?? answer.answer;
|
|
1360
|
+
return answerFor(question, answerText, {
|
|
1361
|
+
wasCustom: answer.wasCustom,
|
|
1362
|
+
optionIndex: answer.optionIndex,
|
|
1363
|
+
note: answer.note
|
|
1645
1364
|
});
|
|
1646
|
-
|
|
1647
|
-
}
|
|
1648
|
-
editNote() {
|
|
1649
|
-
const index = this.page;
|
|
1650
|
-
let answer = this.answers[index];
|
|
1651
|
-
const question = this.options.questions[index];
|
|
1652
|
-
const selected = this.selectedOptions[index] ?? 0;
|
|
1653
|
-
if (question && selected === question.options.length && !answer?.wasCustom) {
|
|
1654
|
-
this.beginEditor("answer", "");
|
|
1655
|
-
return;
|
|
1656
|
-
}
|
|
1657
|
-
if (question && selected < question.options.length && answer?.optionIndex !== selected + 1) {
|
|
1658
|
-
const option = question.options[selected];
|
|
1659
|
-
if (option) {
|
|
1660
|
-
answer = answerFor(question, option.label, {
|
|
1661
|
-
wasCustom: false,
|
|
1662
|
-
optionIndex: selected + 1
|
|
1663
|
-
});
|
|
1664
|
-
this.answers[index] = answer;
|
|
1665
|
-
}
|
|
1666
|
-
}
|
|
1667
|
-
if (!answer) {
|
|
1668
|
-
this.message = "Select an answer before adding a note.";
|
|
1669
|
-
return;
|
|
1670
|
-
}
|
|
1671
|
-
this.beginEditor("note", answer.note ?? "");
|
|
1672
|
-
}
|
|
1673
|
-
beginEditor(kind, value) {
|
|
1674
|
-
this.editorKind = kind;
|
|
1675
|
-
this.editor.setText(value ?? "");
|
|
1676
|
-
this.editor.focused = this._focused;
|
|
1677
|
-
this.message = void 0;
|
|
1678
|
-
}
|
|
1679
|
-
submitEditor(value) {
|
|
1680
|
-
if (value.length > MAX_PLAN_MODE_RESPONSE_LENGTH) {
|
|
1681
|
-
this.editor.setText(value);
|
|
1682
|
-
this.message = `${this.editorKind === "answer" ? "Answer" : "Note"} must be 4,000 characters or fewer.`;
|
|
1683
|
-
this.options.tui.requestRender();
|
|
1684
|
-
return;
|
|
1685
|
-
}
|
|
1686
|
-
const index = this.page;
|
|
1687
|
-
if (this.editorKind === "answer") {
|
|
1688
|
-
if (!value.trim()) {
|
|
1689
|
-
this.editor.setText(value);
|
|
1690
|
-
this.message = "Custom answer cannot be empty.";
|
|
1691
|
-
this.options.tui.requestRender();
|
|
1692
|
-
return;
|
|
1693
|
-
}
|
|
1694
|
-
const question = this.options.questions[index];
|
|
1695
|
-
if (!question) return;
|
|
1696
|
-
const previous = this.answers[index];
|
|
1697
|
-
this.answers[index] = answerFor(question, value, {
|
|
1698
|
-
wasCustom: true,
|
|
1699
|
-
note: previous?.wasCustom ? previous.note : void 0
|
|
1700
|
-
});
|
|
1701
|
-
this.editor.setText("");
|
|
1702
|
-
this.editorKind = void 0;
|
|
1703
|
-
this.editor.focused = false;
|
|
1704
|
-
this.advance();
|
|
1705
|
-
return;
|
|
1706
|
-
}
|
|
1707
|
-
const answer = this.answers[index];
|
|
1708
|
-
if (answer) answer.note = value.trim() ? value : void 0;
|
|
1709
|
-
this.editor.setText("");
|
|
1710
|
-
this.editorKind = void 0;
|
|
1711
|
-
this.editor.focused = false;
|
|
1712
|
-
this.message = value.trim() ? "Note saved." : "Note cleared.";
|
|
1713
|
-
this.options.tui.requestRender();
|
|
1714
|
-
}
|
|
1715
|
-
advance() {
|
|
1716
|
-
this.page = Math.min(this.page + 1, this.options.questions.length);
|
|
1717
|
-
this.message = void 0;
|
|
1718
|
-
}
|
|
1719
|
-
finish(answers) {
|
|
1720
|
-
if (this.finished) return;
|
|
1721
|
-
this.finished = true;
|
|
1722
|
-
this.removeAbort();
|
|
1723
|
-
this.removeAbort = () => {
|
|
1724
|
-
};
|
|
1725
|
-
this.editor.focused = false;
|
|
1726
|
-
this.options.onDone(answers);
|
|
1727
|
-
}
|
|
1728
|
-
};
|
|
1729
|
-
var RawPreservingEditor = class {
|
|
1730
|
-
editor;
|
|
1731
|
-
rawByMarker = /* @__PURE__ */ new Map();
|
|
1732
|
-
markerCodePoint = 57344;
|
|
1733
|
-
pasteBuffer;
|
|
1734
|
-
constructor(tui, theme) {
|
|
1735
|
-
this.editor = new Editor(tui, theme, { paddingX: 0 });
|
|
1736
|
-
}
|
|
1737
|
-
get focused() {
|
|
1738
|
-
return this.editor.focused;
|
|
1739
|
-
}
|
|
1740
|
-
set focused(value) {
|
|
1741
|
-
this.editor.focused = value;
|
|
1742
|
-
}
|
|
1743
|
-
set onChange(handler) {
|
|
1744
|
-
this.editor.onChange = handler ? () => handler(this.getExpandedText()) : void 0;
|
|
1745
|
-
}
|
|
1746
|
-
set onSubmit(handler) {
|
|
1747
|
-
this.editor.onSubmit = handler ? (value) => handler(this.decode(value)) : void 0;
|
|
1748
|
-
}
|
|
1749
|
-
handleInput(data) {
|
|
1750
|
-
if (this.pasteBuffer !== void 0) {
|
|
1751
|
-
this.pasteBuffer += data;
|
|
1752
|
-
this.flushPasteBuffer();
|
|
1753
|
-
return;
|
|
1754
|
-
}
|
|
1755
|
-
if (matchesKey(data, Key.backspace)) {
|
|
1756
|
-
this.editor.handleInput(data);
|
|
1757
|
-
return;
|
|
1758
|
-
}
|
|
1759
|
-
const pasteStart = data.indexOf(BRACKETED_PASTE_START);
|
|
1760
|
-
if (pasteStart >= 0) {
|
|
1761
|
-
if (pasteStart > 0) this.editor.handleInput(data.slice(0, pasteStart));
|
|
1762
|
-
this.pasteBuffer = data.slice(pasteStart + BRACKETED_PASTE_START.length);
|
|
1763
|
-
this.flushPasteBuffer();
|
|
1764
|
-
return;
|
|
1765
|
-
}
|
|
1766
|
-
if ([...data].some(
|
|
1767
|
-
(character) => isUnsafeDirectEditorCharacter(character) || this.rawByMarker.has(character)
|
|
1768
|
-
)) {
|
|
1769
|
-
this.editor.handleInput(this.encode(data));
|
|
1770
|
-
return;
|
|
1771
|
-
}
|
|
1772
|
-
this.editor.handleInput(data);
|
|
1773
|
-
}
|
|
1774
|
-
render(width) {
|
|
1775
|
-
return this.editor.render(width).map(
|
|
1776
|
-
(line) => [...line].map((character) => this.rawByMarker.has(character) ? " " : character).join("")
|
|
1777
|
-
);
|
|
1778
|
-
}
|
|
1779
|
-
invalidate() {
|
|
1780
|
-
this.editor.invalidate();
|
|
1781
|
-
}
|
|
1782
|
-
setText(value) {
|
|
1783
|
-
this.rawByMarker.clear();
|
|
1784
|
-
this.markerCodePoint = 57344;
|
|
1785
|
-
this.pasteBuffer = void 0;
|
|
1786
|
-
this.editor.setText(this.encode(value));
|
|
1787
|
-
}
|
|
1788
|
-
getExpandedText() {
|
|
1789
|
-
return this.decode(this.editor.getExpandedText());
|
|
1790
|
-
}
|
|
1791
|
-
flushPasteBuffer() {
|
|
1792
|
-
if (this.pasteBuffer === void 0) return;
|
|
1793
|
-
const pasteEnd = this.pasteBuffer.indexOf(BRACKETED_PASTE_END);
|
|
1794
|
-
if (pasteEnd < 0) return;
|
|
1795
|
-
const raw = this.pasteBuffer.slice(0, pasteEnd);
|
|
1796
|
-
const remaining = this.pasteBuffer.slice(pasteEnd + BRACKETED_PASTE_END.length);
|
|
1797
|
-
this.pasteBuffer = void 0;
|
|
1798
|
-
this.editor.handleInput(`${BRACKETED_PASTE_START}${this.encode(raw)}${BRACKETED_PASTE_END}`);
|
|
1799
|
-
if (remaining) this.handleInput(remaining);
|
|
1800
|
-
}
|
|
1801
|
-
encode(value) {
|
|
1802
|
-
const forbidden = /* @__PURE__ */ new Set([
|
|
1803
|
-
...value,
|
|
1804
|
-
...this.editor.getExpandedText(),
|
|
1805
|
-
...this.rawByMarker.keys()
|
|
1806
|
-
]);
|
|
1807
|
-
return [...value].map((character) => {
|
|
1808
|
-
if (!isUnsafeEditorCharacter(character) && !this.rawByMarker.has(character)) {
|
|
1809
|
-
return character;
|
|
1810
|
-
}
|
|
1811
|
-
const marker = this.nextMarker(forbidden);
|
|
1812
|
-
this.rawByMarker.set(marker, character);
|
|
1813
|
-
forbidden.add(marker);
|
|
1814
|
-
return marker;
|
|
1815
|
-
}).join("");
|
|
1816
|
-
}
|
|
1817
|
-
decode(value) {
|
|
1818
|
-
return [...value].map((character) => this.rawByMarker.get(character) ?? character).join("");
|
|
1819
|
-
}
|
|
1820
|
-
nextMarker(forbidden) {
|
|
1821
|
-
for (; ; ) {
|
|
1822
|
-
if (this.markerCodePoint === 63744) this.markerCodePoint = 983040;
|
|
1823
|
-
if (this.markerCodePoint === 1048574) this.markerCodePoint = 1048576;
|
|
1824
|
-
if (this.markerCodePoint > 1114109) {
|
|
1825
|
-
throw new Error("Plan-mode editor exhausted its safe input markers.");
|
|
1826
|
-
}
|
|
1827
|
-
const marker = String.fromCodePoint(this.markerCodePoint++);
|
|
1828
|
-
if (!forbidden.has(marker)) return marker;
|
|
1829
|
-
}
|
|
1830
|
-
}
|
|
1831
|
-
};
|
|
1832
|
-
function isUnsafeDirectEditorCharacter(character) {
|
|
1833
|
-
const codePoint = character.codePointAt(0) ?? 0;
|
|
1834
|
-
return codePoint >= 127 && codePoint <= 159 || codePoint === 8232 || codePoint === 8233 || isBidiControl(codePoint);
|
|
1365
|
+
});
|
|
1835
1366
|
}
|
|
1836
|
-
function
|
|
1837
|
-
const
|
|
1838
|
-
return
|
|
1367
|
+
function displayText(value, fallback, sanitize) {
|
|
1368
|
+
const sanitized = sanitize(value);
|
|
1369
|
+
return sanitized.trim() ? sanitized : fallback;
|
|
1839
1370
|
}
|
|
1840
1371
|
function answerFor(question, answer, options) {
|
|
1841
1372
|
const result = {
|
|
@@ -1849,9 +1380,6 @@ function answerFor(question, answer, options) {
|
|
|
1849
1380
|
if (options.note !== void 0) result.note = options.note;
|
|
1850
1381
|
return result;
|
|
1851
1382
|
}
|
|
1852
|
-
function formatPlanModeQuestionChoice(option, index) {
|
|
1853
|
-
return `${index + 1}. ${option.label}${option.description ? ` \u2014 ${option.description}` : ""}`;
|
|
1854
|
-
}
|
|
1855
1383
|
function planModeQuestionAnswered(questions, answers) {
|
|
1856
1384
|
return {
|
|
1857
1385
|
content: [
|
|
@@ -1874,89 +1402,6 @@ function planModeQuestionCancelled(questions, reason, message) {
|
|
|
1874
1402
|
function formatPlanModeQuestionPayload(payload) {
|
|
1875
1403
|
return JSON.stringify(payload, null, 2);
|
|
1876
1404
|
}
|
|
1877
|
-
function sanitizeTerminalText(value) {
|
|
1878
|
-
return [...stripVTControlCharacters2(value)].map((character) => {
|
|
1879
|
-
const codePoint = character.codePointAt(0) ?? 0;
|
|
1880
|
-
return codePoint <= 31 || codePoint >= 127 && codePoint <= 159 || codePoint === 8232 || codePoint === 8233 || isBidiControl(codePoint) ? " " : character;
|
|
1881
|
-
}).join("");
|
|
1882
|
-
}
|
|
1883
|
-
function isBidiControl(codePoint) {
|
|
1884
|
-
return codePoint === 1564 || codePoint === 8206 || codePoint === 8207 || codePoint >= 8234 && codePoint <= 8238 || codePoint >= 8294 && codePoint <= 8297;
|
|
1885
|
-
}
|
|
1886
|
-
function keybindingHint(theme, keybindings, keybinding, description) {
|
|
1887
|
-
return rawKeyHint(theme, formatHintKeys(keybindings.getKeys(keybinding)), description);
|
|
1888
|
-
}
|
|
1889
|
-
function rawKeyHint(theme, keys, description) {
|
|
1890
|
-
return `${theme.fg("dim", keys)}${theme.fg("muted", ` ${description}`)}`;
|
|
1891
|
-
}
|
|
1892
|
-
function cancelHint(theme, keybindings) {
|
|
1893
|
-
return rawKeyHint(
|
|
1894
|
-
theme,
|
|
1895
|
-
formatHintKeys([...keybindings.getKeys("tui.select.cancel"), "ctrl+c"]),
|
|
1896
|
-
"cancel"
|
|
1897
|
-
);
|
|
1898
|
-
}
|
|
1899
|
-
function selectionNavigationKeys(keybindings) {
|
|
1900
|
-
const up = keybindings.getKeys("tui.select.up");
|
|
1901
|
-
const down = keybindings.getKeys("tui.select.down");
|
|
1902
|
-
if (up.includes("up") && down.includes("down")) {
|
|
1903
|
-
return formatHintKeys([
|
|
1904
|
-
"\u2191\u2193",
|
|
1905
|
-
...up.filter((key) => key !== "up"),
|
|
1906
|
-
...down.filter((key) => key !== "down")
|
|
1907
|
-
]);
|
|
1908
|
-
}
|
|
1909
|
-
return formatHintKeys([...up, ...down]);
|
|
1910
|
-
}
|
|
1911
|
-
function questionNavigationKeys(keybindings) {
|
|
1912
|
-
return formatHintKeys([...keybindings.getKeys("tui.input.tab"), "shift+tab", "\u2190\u2192"]);
|
|
1913
|
-
}
|
|
1914
|
-
function formatHintKeys(keys) {
|
|
1915
|
-
return [...new Set(keys)].map(formatHintKey).join("/");
|
|
1916
|
-
}
|
|
1917
|
-
function formatHintKey(key) {
|
|
1918
|
-
return key.split("+").map(
|
|
1919
|
-
(part) => process.platform === "darwin" && part.toLowerCase() === "alt" ? "option" : part
|
|
1920
|
-
).join("+");
|
|
1921
|
-
}
|
|
1922
|
-
function inlineSummary(value) {
|
|
1923
|
-
return value.split("\n").map(sanitizeTerminalText).join(" \u21B5 ");
|
|
1924
|
-
}
|
|
1925
|
-
function labeledRaw(label, value, width, theme) {
|
|
1926
|
-
const prefix = `${label}: `;
|
|
1927
|
-
const safe = sanitizeTerminalText(value);
|
|
1928
|
-
const lines = hardWrap(safe, Math.max(1, width - visibleWidth(prefix)));
|
|
1929
|
-
return lines.map(
|
|
1930
|
-
(line, index) => index === 0 ? `${theme.fg("muted", prefix)}${line}` : `${" ".repeat(prefix.length)}${line}`
|
|
1931
|
-
);
|
|
1932
|
-
}
|
|
1933
|
-
function hardWrapWithIndent(value, width, indent) {
|
|
1934
|
-
const safeWidth = Math.max(1, width);
|
|
1935
|
-
const safeIndent = Math.min(Math.max(0, indent), Math.max(0, safeWidth - 1));
|
|
1936
|
-
const continuationWidth = Math.max(1, safeWidth - safeIndent);
|
|
1937
|
-
const columns = visibleWidth(value);
|
|
1938
|
-
if (columns <= safeWidth) return [value];
|
|
1939
|
-
const output = [sliceByColumn(value, 0, safeWidth)];
|
|
1940
|
-
for (let column = safeWidth; column < columns; column += continuationWidth) {
|
|
1941
|
-
output.push(`${" ".repeat(safeIndent)}${sliceByColumn(value, column, continuationWidth)}`);
|
|
1942
|
-
}
|
|
1943
|
-
return output;
|
|
1944
|
-
}
|
|
1945
|
-
function hardWrap(value, width) {
|
|
1946
|
-
const safeWidth = Math.max(1, width);
|
|
1947
|
-
if (!value) return [""];
|
|
1948
|
-
const output = [];
|
|
1949
|
-
for (const sourceLine of value.split("\n")) {
|
|
1950
|
-
const columns = visibleWidth(sourceLine);
|
|
1951
|
-
if (columns === 0) output.push("");
|
|
1952
|
-
else {
|
|
1953
|
-
for (let column = 0; column < columns; column += safeWidth) {
|
|
1954
|
-
output.push(sliceByColumn(sourceLine, column, safeWidth));
|
|
1955
|
-
}
|
|
1956
|
-
}
|
|
1957
|
-
}
|
|
1958
|
-
return output;
|
|
1959
|
-
}
|
|
1960
1405
|
function isRecord2(value) {
|
|
1961
1406
|
return typeof value === "object" && value !== null;
|
|
1962
1407
|
}
|
|
@@ -2075,4 +1520,4 @@ export {
|
|
|
2075
1520
|
withRequiredPlanModeTools,
|
|
2076
1521
|
withoutRequiredPlanModeTools
|
|
2077
1522
|
};
|
|
2078
|
-
//# sourceMappingURL=chunk-
|
|
1523
|
+
//# sourceMappingURL=chunk-H3RGWRY7.ts.map
|