@narumitw/pi-plan-mode 0.50.1 → 0.51.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.
- package/README.md +236 -130
- package/dist/chunks/{chunk-6SDTCIHD.ts → chunk-VMD6XCI5.ts} +605 -17
- package/dist/chunks/{chunk-6SDTCIHD.ts.map → chunk-VMD6XCI5.ts.map} +3 -3
- package/dist/chunks/{interactive-ui-JBSBPK6S.ts → interactive-ui-ROT43QBA.ts} +2 -2
- package/dist/index.ts +2 -2
- package/package.json +3 -3
- package/src/question-tool.ts +746 -18
- /package/dist/chunks/{interactive-ui-JBSBPK6S.ts.map → interactive-ui-ROT43QBA.ts.map} +0 -0
|
@@ -1176,7 +1176,19 @@ 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";
|
|
1179
1188
|
var PLAN_MODE_QUESTION_TOOL_NAME = "plan_mode_question";
|
|
1189
|
+
var MAX_PLAN_MODE_RESPONSE_LENGTH = 4e3;
|
|
1190
|
+
var BRACKETED_PASTE_START = "\x1B[200~";
|
|
1191
|
+
var BRACKETED_PASTE_END = "\x1B[201~";
|
|
1180
1192
|
var PLAN_MODE_QUESTION_PARAMS = {
|
|
1181
1193
|
type: "object",
|
|
1182
1194
|
additionalProperties: false,
|
|
@@ -1309,6 +1321,23 @@ async function answerPlanModeQuestions(questions, ctx, lifecycle) {
|
|
|
1309
1321
|
return planModeQuestionAnswered(questions, answers);
|
|
1310
1322
|
}
|
|
1311
1323
|
async function askPlanModeQuestions(questions, ctx, shouldContinue = () => true) {
|
|
1324
|
+
if (ctx.mode === "tui") {
|
|
1325
|
+
const answers = await ctx.ui.custom(
|
|
1326
|
+
(tui, theme, keybindings, done) => new PlanModeQuestionnaire({
|
|
1327
|
+
questions,
|
|
1328
|
+
tui,
|
|
1329
|
+
theme,
|
|
1330
|
+
keybindings,
|
|
1331
|
+
shouldContinue,
|
|
1332
|
+
signal: ctx.signal,
|
|
1333
|
+
onDone: done
|
|
1334
|
+
})
|
|
1335
|
+
);
|
|
1336
|
+
return shouldContinue() ? answers : void 0;
|
|
1337
|
+
}
|
|
1338
|
+
return askPlanModeQuestionsSequentially(questions, ctx, shouldContinue);
|
|
1339
|
+
}
|
|
1340
|
+
async function askPlanModeQuestionsSequentially(questions, ctx, shouldContinue) {
|
|
1312
1341
|
const answers = [];
|
|
1313
1342
|
for (const question of questions) {
|
|
1314
1343
|
const choices = question.options.map(formatPlanModeQuestionChoice);
|
|
@@ -1319,30 +1348,506 @@ async function askPlanModeQuestions(questions, ctx, shouldContinue = () => true)
|
|
|
1319
1348
|
]);
|
|
1320
1349
|
if (!shouldContinue() || !choice) return void 0;
|
|
1321
1350
|
if (choice === otherChoice) {
|
|
1322
|
-
const customAnswer =
|
|
1323
|
-
if (
|
|
1324
|
-
answers.push({
|
|
1325
|
-
id: question.id,
|
|
1326
|
-
header: question.header,
|
|
1327
|
-
question: question.question,
|
|
1328
|
-
answer: customAnswer,
|
|
1329
|
-
wasCustom: true
|
|
1330
|
-
});
|
|
1351
|
+
const customAnswer = await askCustomAnswer(question, ctx, shouldContinue);
|
|
1352
|
+
if (customAnswer === void 0) return void 0;
|
|
1353
|
+
answers.push(answerFor(question, customAnswer, { wasCustom: true }));
|
|
1331
1354
|
continue;
|
|
1332
1355
|
}
|
|
1333
1356
|
const optionIndex = choices.indexOf(choice);
|
|
1334
1357
|
const option = question.options[optionIndex];
|
|
1335
1358
|
if (!option) return void 0;
|
|
1336
|
-
answers.push(
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
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));
|
|
1597
|
+
}
|
|
1598
|
+
return lines;
|
|
1599
|
+
}
|
|
1600
|
+
renderReview(width) {
|
|
1601
|
+
const lines = [this.options.theme.fg("accent", this.options.theme.bold("Review answers")), ""];
|
|
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;
|
|
1622
|
+
}
|
|
1623
|
+
this.finish(
|
|
1624
|
+
this.answers.filter((answer) => answer !== void 0)
|
|
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;
|
|
1637
|
+
}
|
|
1638
|
+
const option = question.options[selected];
|
|
1639
|
+
if (!option) return;
|
|
1640
|
+
const previous = this.answers[this.page];
|
|
1641
|
+
this.answers[this.page] = answerFor(question, option.label, {
|
|
1341
1642
|
wasCustom: false,
|
|
1342
|
-
optionIndex:
|
|
1643
|
+
optionIndex: selected + 1,
|
|
1644
|
+
note: previous?.optionIndex === selected + 1 ? previous.note : void 0
|
|
1343
1645
|
});
|
|
1646
|
+
this.advance();
|
|
1344
1647
|
}
|
|
1345
|
-
|
|
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);
|
|
1835
|
+
}
|
|
1836
|
+
function isUnsafeEditorCharacter(character) {
|
|
1837
|
+
const codePoint = character.codePointAt(0) ?? 0;
|
|
1838
|
+
return character !== "\n" && (codePoint <= 31 || codePoint >= 127 && codePoint <= 159 || codePoint === 8232 || codePoint === 8233 || isBidiControl(codePoint));
|
|
1839
|
+
}
|
|
1840
|
+
function answerFor(question, answer, options) {
|
|
1841
|
+
const result = {
|
|
1842
|
+
id: question.id,
|
|
1843
|
+
header: question.header,
|
|
1844
|
+
question: question.question,
|
|
1845
|
+
answer,
|
|
1846
|
+
wasCustom: options.wasCustom
|
|
1847
|
+
};
|
|
1848
|
+
if (options.optionIndex !== void 0) result.optionIndex = options.optionIndex;
|
|
1849
|
+
if (options.note !== void 0) result.note = options.note;
|
|
1850
|
+
return result;
|
|
1346
1851
|
}
|
|
1347
1852
|
function formatPlanModeQuestionChoice(option, index) {
|
|
1348
1853
|
return `${index + 1}. ${option.label}${option.description ? ` \u2014 ${option.description}` : ""}`;
|
|
@@ -1369,6 +1874,89 @@ function planModeQuestionCancelled(questions, reason, message) {
|
|
|
1369
1874
|
function formatPlanModeQuestionPayload(payload) {
|
|
1370
1875
|
return JSON.stringify(payload, null, 2);
|
|
1371
1876
|
}
|
|
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
|
+
}
|
|
1372
1960
|
function isRecord2(value) {
|
|
1373
1961
|
return typeof value === "object" && value !== null;
|
|
1374
1962
|
}
|
|
@@ -1487,4 +2075,4 @@ export {
|
|
|
1487
2075
|
withRequiredPlanModeTools,
|
|
1488
2076
|
withoutRequiredPlanModeTools
|
|
1489
2077
|
};
|
|
1490
|
-
//# sourceMappingURL=chunk-
|
|
2078
|
+
//# sourceMappingURL=chunk-VMD6XCI5.ts.map
|