@mrclrchtr/supi-ask-user 1.12.1 → 1.14.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 +157 -65
- package/node_modules/@mrclrchtr/supi-core/README.md +10 -0
- package/node_modules/@mrclrchtr/supi-core/package.json +3 -1
- package/node_modules/@mrclrchtr/supi-core/src/api.ts +4 -0
- package/node_modules/@mrclrchtr/supi-core/src/footer-registry.ts +57 -0
- package/node_modules/@mrclrchtr/supi-core/src/index.ts +4 -0
- package/node_modules/@mrclrchtr/supi-core/src/progress-widget.ts +98 -17
- package/node_modules/@mrclrchtr/supi-core/src/registry-utils.ts +8 -1
- package/node_modules/@mrclrchtr/supi-core/src/report.ts +121 -0
- package/package.json +2 -2
- package/src/api.ts +7 -5
- package/src/ask-user.ts +23 -7
- package/src/index.ts +7 -5
- package/src/normalize.ts +47 -30
- package/src/render/result.ts +72 -49
- package/src/render/transcript.ts +90 -62
- package/src/schema.ts +8 -30
- package/src/session/controller.ts +226 -193
- package/src/session/lock.ts +1 -1
- package/src/tool/guidance.ts +4 -1
- package/src/types.ts +46 -35
- package/src/ui/choose-renderer.ts +20 -4
- package/src/ui/form-component.ts +574 -0
- package/src/ui/form-render-primitives.ts +71 -0
- package/src/ui/form-render.ts +283 -0
- package/src/ui/form-review-render.ts +144 -0
- package/src/ui/form-view.ts +23 -0
- package/src/ui/{overlay.ts → form.ts} +12 -9
- package/src/ui/types.ts +7 -3
- package/src/ui/overlay-actions.ts +0 -42
- package/src/ui/overlay-component.ts +0 -400
- package/src/ui/overlay-render.ts +0 -230
- package/src/ui/overlay-view.ts +0 -327
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import type { Theme } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { type Editor, truncateToWidth, wrapTextWithAnsi } from "@earendil-works/pi-tui";
|
|
3
|
+
import type { AskUserController } from "../session/controller.ts";
|
|
4
|
+
import type { NormalizedChoiceQuestion } from "../types.ts";
|
|
5
|
+
import {
|
|
6
|
+
formatSplitLine,
|
|
7
|
+
padRight,
|
|
8
|
+
pushWrappedWithPrefix,
|
|
9
|
+
renderMiniBox,
|
|
10
|
+
renderPrompt,
|
|
11
|
+
safeWidth,
|
|
12
|
+
} from "./form-render-primitives.ts";
|
|
13
|
+
import { renderReviewScreen } from "./form-review-render.ts";
|
|
14
|
+
import type { FocusTarget, FormMode } from "./form-view.ts";
|
|
15
|
+
|
|
16
|
+
export interface RenderFormFrameArgs {
|
|
17
|
+
width: number;
|
|
18
|
+
theme: Theme;
|
|
19
|
+
controller: AskUserController;
|
|
20
|
+
mode: FormMode;
|
|
21
|
+
focus: FocusTarget;
|
|
22
|
+
editor: Editor;
|
|
23
|
+
choiceFocusIndex: number;
|
|
24
|
+
reviewFocusIndex: number;
|
|
25
|
+
previewText?: string;
|
|
26
|
+
editorLabel?: string;
|
|
27
|
+
editorContext?: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function renderFormFrame(args: RenderFormFrameArgs): string[] {
|
|
31
|
+
const width = safeWidth(args.width);
|
|
32
|
+
if (width < 8) {
|
|
33
|
+
return renderFrameContent({ ...args, width }).map((line) => truncateToWidth(line, width));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const innerWidth = Math.max(1, width - 4);
|
|
37
|
+
const content = renderFrameContent({ ...args, width: innerWidth });
|
|
38
|
+
const border = args.theme.fg("borderAccent", "│");
|
|
39
|
+
const top = args.theme.fg("borderAccent", `╭${"─".repeat(width - 2)}╮`);
|
|
40
|
+
const bottom = args.theme.fg("borderAccent", `╰${"─".repeat(width - 2)}╯`);
|
|
41
|
+
|
|
42
|
+
return [
|
|
43
|
+
top,
|
|
44
|
+
...content.map((line) => `${border} ${padRight(line, innerWidth)} ${border}`),
|
|
45
|
+
bottom,
|
|
46
|
+
].map((line) => truncateToWidth(line, width));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function renderFrameContent(args: RenderFormFrameArgs): string[] {
|
|
50
|
+
const width = safeWidth(args.width);
|
|
51
|
+
const lines: string[] = [];
|
|
52
|
+
lines.push(...renderHeader(args));
|
|
53
|
+
lines.push("");
|
|
54
|
+
|
|
55
|
+
if (args.mode === "review") {
|
|
56
|
+
lines.push(...renderReviewScreen(args));
|
|
57
|
+
} else if (isEditorMode(args.mode)) {
|
|
58
|
+
lines.push(...renderEditorScreen(args));
|
|
59
|
+
} else {
|
|
60
|
+
const question = args.controller.currentQuestion;
|
|
61
|
+
if (question.type === "text") {
|
|
62
|
+
lines.push(...renderTextScreen(args));
|
|
63
|
+
} else {
|
|
64
|
+
lines.push(...renderChoiceScreen(args));
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
lines.push("");
|
|
69
|
+
lines.push(...wrapTextWithAnsi(args.theme.fg("dim", renderFooter(args)), width));
|
|
70
|
+
return lines.map((line) => truncateToWidth(line, width));
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function renderHeader(args: RenderFormFrameArgs): string[] {
|
|
74
|
+
const lines: string[] = [];
|
|
75
|
+
const { intro, title } = args.controller.questionnaire;
|
|
76
|
+
const titleText = args.theme.fg("accent", args.theme.bold(title ?? "ask_user"));
|
|
77
|
+
const contextText = args.theme.fg("muted", headerContext(args));
|
|
78
|
+
|
|
79
|
+
lines.push(formatSplitLine(titleText, contextText, args.width));
|
|
80
|
+
lines.push(renderProgressLine(args));
|
|
81
|
+
|
|
82
|
+
if (intro) {
|
|
83
|
+
lines.push("");
|
|
84
|
+
lines.push(...renderPrompt(intro, args.width));
|
|
85
|
+
lines.push("");
|
|
86
|
+
lines.push(args.theme.fg("borderMuted", "─".repeat(args.width)));
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return lines;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function headerContext(args: RenderFormFrameArgs): string {
|
|
93
|
+
if (args.mode === "review") return "Review · all questions";
|
|
94
|
+
if (args.mode === "form-comment") return "Review · form comment";
|
|
95
|
+
|
|
96
|
+
const q = args.controller.currentQuestion;
|
|
97
|
+
return `Question ${args.controller.currentIndex + 1}/${args.controller.questionnaire.questions.length} · ${q.header}`;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function renderProgressLine(args: RenderFormFrameArgs): string {
|
|
101
|
+
const questionCount = args.controller.questionnaire.questions.length;
|
|
102
|
+
const totalSteps = questionCount + 1;
|
|
103
|
+
const currentStep =
|
|
104
|
+
args.mode === "review" || args.mode === "form-comment"
|
|
105
|
+
? totalSteps
|
|
106
|
+
: args.controller.currentIndex + 1;
|
|
107
|
+
const segments = Array.from({ length: totalSteps }, (_entry, index) => {
|
|
108
|
+
if (index < currentStep - 1) return args.theme.fg("success", "●");
|
|
109
|
+
if (index === currentStep - 1) return args.theme.fg("accent", "●");
|
|
110
|
+
return args.theme.fg("dim", "○");
|
|
111
|
+
}).join(" ");
|
|
112
|
+
const label =
|
|
113
|
+
args.mode === "review" || args.mode === "form-comment"
|
|
114
|
+
? "Step review"
|
|
115
|
+
: `Step ${currentStep}/${totalSteps}`;
|
|
116
|
+
|
|
117
|
+
return truncateToWidth(`${args.theme.fg("dim", label)} ${segments}`, args.width);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function renderChoiceScreen(args: RenderFormFrameArgs): string[] {
|
|
121
|
+
const lines: string[] = [];
|
|
122
|
+
const question = args.controller.currentQuestion;
|
|
123
|
+
|
|
124
|
+
if (question.type !== "choice") return lines;
|
|
125
|
+
|
|
126
|
+
lines.push(...renderPrompt(question.prompt, args.width));
|
|
127
|
+
if (args.controller.isQuestionMarkedUnanswered(question.id)) {
|
|
128
|
+
lines.push("");
|
|
129
|
+
lines.push(args.theme.fg("warning", "Marked unanswered; comments preserved."));
|
|
130
|
+
}
|
|
131
|
+
lines.push("");
|
|
132
|
+
|
|
133
|
+
if (args.previewText && args.width >= 80) {
|
|
134
|
+
lines.push(...renderChoiceWithPreview(args, question));
|
|
135
|
+
return lines;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
for (let i = 0; i < question.options.length; i += 1) {
|
|
139
|
+
lines.push(...renderChoiceOptionLines(args, question, i, args.width));
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (args.previewText) {
|
|
143
|
+
lines.push("");
|
|
144
|
+
lines.push(...renderPreviewCard(args.theme, args.previewText, args.width));
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return lines;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function renderChoiceWithPreview(
|
|
151
|
+
args: RenderFormFrameArgs,
|
|
152
|
+
question: NormalizedChoiceQuestion,
|
|
153
|
+
): string[] {
|
|
154
|
+
const gap = 2;
|
|
155
|
+
const divider = args.theme.fg("borderMuted", "│");
|
|
156
|
+
const dividerWidth = 1;
|
|
157
|
+
const minLeftWidth = 28;
|
|
158
|
+
const preferredPreviewWidth = Math.max(30, Math.floor(args.width * 0.38));
|
|
159
|
+
const rightWidth = Math.max(
|
|
160
|
+
22,
|
|
161
|
+
Math.min(preferredPreviewWidth, args.width - gap - dividerWidth - gap - minLeftWidth),
|
|
162
|
+
);
|
|
163
|
+
const leftWidth = Math.max(1, args.width - gap - dividerWidth - gap - rightWidth);
|
|
164
|
+
|
|
165
|
+
const optionLines: string[] = [];
|
|
166
|
+
for (let i = 0; i < question.options.length; i += 1) {
|
|
167
|
+
optionLines.push(...renderChoiceOptionLines(args, question, i, leftWidth));
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const previewLines = renderPreviewCard(args.theme, args.previewText ?? "", rightWidth);
|
|
171
|
+
|
|
172
|
+
const merged: string[] = [];
|
|
173
|
+
const maxRows = Math.max(optionLines.length, previewLines.length);
|
|
174
|
+
for (let i = 0; i < maxRows; i += 1) {
|
|
175
|
+
const left = optionLines[i] ?? "";
|
|
176
|
+
const right = previewLines[i] ?? "";
|
|
177
|
+
const mergedLine = `${padRight(left, leftWidth)}${" ".repeat(gap)}${divider}${" ".repeat(gap)}${right}`;
|
|
178
|
+
merged.push(truncateToWidth(mergedLine, args.width));
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return merged;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function renderChoiceOptionLines(
|
|
185
|
+
args: RenderFormFrameArgs,
|
|
186
|
+
question: NormalizedChoiceQuestion,
|
|
187
|
+
optionIndex: number,
|
|
188
|
+
width: number,
|
|
189
|
+
): string[] {
|
|
190
|
+
const lines: string[] = [];
|
|
191
|
+
const opt = question.options[optionIndex];
|
|
192
|
+
const focused = optionIndex === args.choiceFocusIndex;
|
|
193
|
+
const selected = args.controller.isOptionSelected(question.id, opt.value);
|
|
194
|
+
const hasComment = !!args.controller.getOptionComment(question.id, opt.value);
|
|
195
|
+
|
|
196
|
+
const marker = choiceMarker(question.multi, selected);
|
|
197
|
+
const isRecommended = question.recommendedIndexes.includes(optionIndex);
|
|
198
|
+
const prefix = focused ? " → " : " ";
|
|
199
|
+
const label = `${marker} ${opt.label}${isRecommended ? " [recommended]" : ""}${hasComment ? " [comment]" : ""}`;
|
|
200
|
+
pushWrappedWithPrefix({
|
|
201
|
+
lines,
|
|
202
|
+
prefix,
|
|
203
|
+
text: focused ? args.theme.fg("accent", label) : label,
|
|
204
|
+
width,
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
if (opt.description) {
|
|
208
|
+
pushWrappedWithPrefix({
|
|
209
|
+
lines,
|
|
210
|
+
prefix: " ",
|
|
211
|
+
text: args.theme.fg("muted", opt.description),
|
|
212
|
+
width,
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
return lines;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function choiceMarker(multi: boolean, selected: boolean): string {
|
|
220
|
+
if (multi) return selected ? "[x]" : "[ ]";
|
|
221
|
+
return selected ? "(*)" : "( )";
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
function renderTextScreen(args: RenderFormFrameArgs): string[] {
|
|
225
|
+
const lines: string[] = [];
|
|
226
|
+
const question = args.controller.currentQuestion;
|
|
227
|
+
|
|
228
|
+
if (question.type !== "text") return lines;
|
|
229
|
+
|
|
230
|
+
lines.push(...renderPrompt(question.prompt, args.width));
|
|
231
|
+
lines.push("");
|
|
232
|
+
lines.push(args.theme.fg("accent", "Your answer"));
|
|
233
|
+
lines.push(...args.editor.render(safeWidth(args.width)));
|
|
234
|
+
|
|
235
|
+
if (question.placeholder && !args.editor.getText()) {
|
|
236
|
+
lines.push("");
|
|
237
|
+
lines.push(
|
|
238
|
+
...wrapTextWithAnsi(args.theme.fg("dim", `Placeholder: ${question.placeholder}`), args.width),
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
return lines;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
function renderEditorScreen(args: RenderFormFrameArgs): string[] {
|
|
246
|
+
const lines: string[] = [];
|
|
247
|
+
const label = args.editorLabel ?? "Editor";
|
|
248
|
+
const title = args.editorContext ? `${label}: ${args.editorContext}` : label;
|
|
249
|
+
lines.push(args.theme.fg("accent", title));
|
|
250
|
+
lines.push(...args.editor.render(safeWidth(args.width)));
|
|
251
|
+
return lines;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
function renderPreviewCard(theme: Theme, previewText: string, width: number): string[] {
|
|
255
|
+
const innerWidth = Math.max(1, safeWidth(width) - 4);
|
|
256
|
+
return renderMiniBox(theme, "Preview", renderPrompt(previewText, innerWidth), width);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
function renderFooter(args: RenderFormFrameArgs): string {
|
|
260
|
+
if (args.mode === "review") {
|
|
261
|
+
return "Keys: ↑↓ move · Enter edit/submit · c form comment · ←/Shift+Tab back · Esc cancel";
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
if (isEditorMode(args.mode)) {
|
|
265
|
+
return "Keys: Enter save · Esc discard";
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
const question = args.controller.currentQuestion;
|
|
269
|
+
|
|
270
|
+
if (question.type === "text") {
|
|
271
|
+
return "Keys: Enter submit · Alt+C question comment · Alt+U unanswered · Tab next · Shift+Tab back · Esc cancel";
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
if (question.multi) {
|
|
275
|
+
return "Keys: ↑↓ move · Space toggle · Enter accept · c question comment · n option comment · u unanswered · ←/→ or Tab/Shift+Tab · Esc cancel";
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
return "Keys: ↑↓ move · Space select · Enter select · c question comment · n option comment · u unanswered · ←/→ or Tab/Shift+Tab · Esc cancel";
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
function isEditorMode(mode: FormMode): boolean {
|
|
282
|
+
return mode === "question-comment" || mode === "form-comment" || mode === "option-comment";
|
|
283
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import type { Theme } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { truncateToWidth } from "@earendil-works/pi-tui";
|
|
3
|
+
import type { AskUserResponse, NormalizedQuestion } from "../types.ts";
|
|
4
|
+
import type { RenderFormFrameArgs } from "./form-render.ts";
|
|
5
|
+
import {
|
|
6
|
+
pushWrappedWithPrefix,
|
|
7
|
+
renderMiniBox,
|
|
8
|
+
safeWidth,
|
|
9
|
+
wrapLines,
|
|
10
|
+
} from "./form-render-primitives.ts";
|
|
11
|
+
|
|
12
|
+
export function renderReviewScreen(args: RenderFormFrameArgs): string[] {
|
|
13
|
+
const lines: string[] = [];
|
|
14
|
+
const outcome = args.controller.outcome();
|
|
15
|
+
const questionCount = args.controller.questionnaire.questions.length;
|
|
16
|
+
const submitIndex = questionCount;
|
|
17
|
+
|
|
18
|
+
lines.push(args.theme.fg("accent", "Review your answers"));
|
|
19
|
+
lines.push(
|
|
20
|
+
args.theme.fg("dim", "Check answers, comments, and unanswered items before submitting."),
|
|
21
|
+
);
|
|
22
|
+
lines.push("");
|
|
23
|
+
|
|
24
|
+
for (let i = 0; i < outcome.responses.length; i += 1) {
|
|
25
|
+
const resp = outcome.responses[i];
|
|
26
|
+
const question = args.controller.questionnaire.questions[i];
|
|
27
|
+
lines.push(...renderReviewQuestionCard(args, question, resp, i === args.reviewFocusIndex));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (outcome.comment) {
|
|
31
|
+
lines.push("");
|
|
32
|
+
lines.push(...renderMiniBox(args.theme, "Form comment", [outcome.comment], args.width));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
lines.push("");
|
|
36
|
+
lines.push(...renderSubmitCard(args, args.reviewFocusIndex === submitIndex));
|
|
37
|
+
|
|
38
|
+
return lines;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function renderReviewQuestionCard(
|
|
42
|
+
args: RenderFormFrameArgs,
|
|
43
|
+
question: NormalizedQuestion,
|
|
44
|
+
response: AskUserResponse,
|
|
45
|
+
focused: boolean,
|
|
46
|
+
): string[] {
|
|
47
|
+
const width = safeWidth(args.width);
|
|
48
|
+
const prefix = focused ? args.theme.fg("accent", " → ") : " ";
|
|
49
|
+
const headerPrefix = focused
|
|
50
|
+
? args.theme.fg("accent", "╭─ → ")
|
|
51
|
+
: args.theme.fg("borderMuted", "╭─ ");
|
|
52
|
+
const bottom = focused
|
|
53
|
+
? args.theme.fg("accent", `╰${"─".repeat(Math.max(1, width - 2))}╯`)
|
|
54
|
+
: args.theme.fg("borderMuted", `╰${"─".repeat(Math.max(1, width - 2))}╯`);
|
|
55
|
+
const status = response.answer.answered
|
|
56
|
+
? args.theme.fg("success", "[✓]")
|
|
57
|
+
: args.theme.fg("warning", "[?]");
|
|
58
|
+
const lines: string[] = [];
|
|
59
|
+
|
|
60
|
+
pushWrappedWithPrefix({
|
|
61
|
+
lines,
|
|
62
|
+
prefix: headerPrefix,
|
|
63
|
+
text: `${status} ${question.header}`,
|
|
64
|
+
width,
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const bodyLines = renderReviewResponseLines(args.theme, response, width - 3);
|
|
68
|
+
for (const line of bodyLines) {
|
|
69
|
+
lines.push(`${prefix}${truncateToWidth(line, width - 3)}`);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (response.questionComment) {
|
|
73
|
+
pushWrappedWithPrefix({
|
|
74
|
+
lines,
|
|
75
|
+
prefix,
|
|
76
|
+
text: args.theme.fg("dim", `Question comment: ${response.questionComment}`),
|
|
77
|
+
width,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
lines.push(bottom);
|
|
82
|
+
return lines.map((line) => truncateToWidth(line, width));
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function renderSubmitCard(args: RenderFormFrameArgs, focused: boolean): string[] {
|
|
86
|
+
const width = safeWidth(args.width);
|
|
87
|
+
const prefix = focused ? args.theme.fg("accent", " → ") : " ";
|
|
88
|
+
const headerPrefix = focused
|
|
89
|
+
? args.theme.fg("accent", "╭─ → ")
|
|
90
|
+
: args.theme.fg("borderMuted", "╭─ ");
|
|
91
|
+
const bottom = focused
|
|
92
|
+
? args.theme.fg("accent", `╰${"─".repeat(Math.max(1, width - 2))}╯`)
|
|
93
|
+
: args.theme.fg("borderMuted", `╰${"─".repeat(Math.max(1, width - 2))}╯`);
|
|
94
|
+
const lines: string[] = [];
|
|
95
|
+
|
|
96
|
+
pushWrappedWithPrefix({
|
|
97
|
+
lines,
|
|
98
|
+
prefix: headerPrefix,
|
|
99
|
+
text: focused ? args.theme.fg("accent", "Submit form") : "Submit form",
|
|
100
|
+
width,
|
|
101
|
+
});
|
|
102
|
+
pushWrappedWithPrefix({
|
|
103
|
+
lines,
|
|
104
|
+
prefix,
|
|
105
|
+
text: args.theme.fg("dim", "Enter submits · c edits form comment"),
|
|
106
|
+
width,
|
|
107
|
+
});
|
|
108
|
+
lines.push(bottom);
|
|
109
|
+
return lines.map((line) => truncateToWidth(line, width));
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function renderReviewResponseLines(
|
|
113
|
+
theme: Theme,
|
|
114
|
+
response: AskUserResponse,
|
|
115
|
+
width: number,
|
|
116
|
+
): string[] {
|
|
117
|
+
const lines: string[] = [];
|
|
118
|
+
|
|
119
|
+
if (response.answer.kind === "text") {
|
|
120
|
+
lines.push(
|
|
121
|
+
response.answer.answered
|
|
122
|
+
? `Answer: ${response.answer.value ?? ""}`
|
|
123
|
+
: theme.fg("warning", "Answer: unanswered"),
|
|
124
|
+
);
|
|
125
|
+
return wrapLines(lines, safeWidth(width));
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (response.answer.options.length === 0) {
|
|
129
|
+
lines.push(theme.fg("warning", "Answer: unanswered"));
|
|
130
|
+
return wrapLines(lines, safeWidth(width));
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (!response.answer.answered) {
|
|
134
|
+
lines.push(theme.fg("warning", "Answer: unanswered"));
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
for (const option of response.answer.options) {
|
|
138
|
+
const marker = option.selected ? theme.fg("success", "[x]") : theme.fg("dim", "[ ]");
|
|
139
|
+
const comment = option.comment ? theme.fg("dim", ` — ${option.comment}`) : "";
|
|
140
|
+
lines.push(`${marker} ${option.label}${comment}`);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return wrapLines(lines, safeWidth(width));
|
|
144
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { AskUserController } from "../session/controller.ts";
|
|
2
|
+
import type { NormalizedChoiceQuestion } from "../types.ts";
|
|
3
|
+
|
|
4
|
+
export type FocusTarget = "choices" | "editor" | "review";
|
|
5
|
+
export type FormMode =
|
|
6
|
+
| "choice"
|
|
7
|
+
| "text"
|
|
8
|
+
| "review"
|
|
9
|
+
| "question-comment"
|
|
10
|
+
| "form-comment"
|
|
11
|
+
| "option-comment";
|
|
12
|
+
|
|
13
|
+
export function defaultChoiceRowIndex(
|
|
14
|
+
controller: AskUserController,
|
|
15
|
+
question: NormalizedChoiceQuestion,
|
|
16
|
+
): number {
|
|
17
|
+
for (let i = 0; i < question.options.length; i += 1) {
|
|
18
|
+
if (controller.isOptionSelected(question.id, question.options[i].value)) {
|
|
19
|
+
return i;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return 0;
|
|
23
|
+
}
|
|
@@ -1,21 +1,24 @@
|
|
|
1
1
|
import { AskUserController } from "../session/controller.ts";
|
|
2
|
-
import type {
|
|
3
|
-
|
|
2
|
+
import type {
|
|
3
|
+
AskUserInteractionResult,
|
|
4
|
+
AskUserOutcome,
|
|
5
|
+
NormalizedQuestionnaire,
|
|
6
|
+
} from "../types.ts";
|
|
7
|
+
import { AskUserForm } from "./form-component.ts";
|
|
4
8
|
import type { RunQuestionnaireOptions } from "./types.ts";
|
|
5
9
|
|
|
6
|
-
export async function
|
|
10
|
+
export async function runFormQuestionnaire(
|
|
7
11
|
questionnaire: NormalizedQuestionnaire,
|
|
8
12
|
opts: RunQuestionnaireOptions,
|
|
9
|
-
): Promise<AskUserOutcome> {
|
|
13
|
+
): Promise<AskUserOutcome | AskUserInteractionResult | undefined> {
|
|
10
14
|
const controller = new AskUserController(questionnaire);
|
|
11
15
|
if (opts.signal?.aborted) {
|
|
12
|
-
controller.abort();
|
|
13
|
-
return controller.outcome();
|
|
16
|
+
return controller.abort();
|
|
14
17
|
}
|
|
15
18
|
|
|
16
|
-
return opts.ui.custom?.<AskUserOutcome>(
|
|
19
|
+
return opts.ui.custom?.<AskUserOutcome | AskUserInteractionResult>(
|
|
17
20
|
(tui, theme, kb, done) =>
|
|
18
|
-
new
|
|
21
|
+
new AskUserForm({
|
|
19
22
|
tui,
|
|
20
23
|
theme,
|
|
21
24
|
controller,
|
|
@@ -24,5 +27,5 @@ export async function runOverlayQuestionnaire(
|
|
|
24
27
|
keybindings: kb,
|
|
25
28
|
onToggleToolsExpanded: opts.onToggleToolsExpanded,
|
|
26
29
|
}),
|
|
27
|
-
)
|
|
30
|
+
);
|
|
28
31
|
}
|
package/src/ui/types.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import type { KeybindingsManager, Theme } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
import type { Component, TUI } from "@earendil-works/pi-tui";
|
|
3
3
|
import type { AskUserController } from "../session/controller.ts";
|
|
4
|
-
import type {
|
|
4
|
+
import type {
|
|
5
|
+
AskUserInteractionResult,
|
|
6
|
+
AskUserOutcome,
|
|
7
|
+
NormalizedQuestionnaire,
|
|
8
|
+
} from "../types.ts";
|
|
5
9
|
|
|
6
10
|
export interface AskUserUiContext {
|
|
7
11
|
notify?(message: string, type?: "info" | "warning" | "error"): void;
|
|
@@ -27,11 +31,11 @@ export interface RenderContext {
|
|
|
27
31
|
options: RunQuestionnaireOptions;
|
|
28
32
|
}
|
|
29
33
|
|
|
30
|
-
export interface
|
|
34
|
+
export interface FormArgs {
|
|
31
35
|
tui: TUI;
|
|
32
36
|
theme: Theme;
|
|
33
37
|
controller: AskUserController;
|
|
34
|
-
done: (result: AskUserOutcome) => void;
|
|
38
|
+
done: (result: AskUserOutcome | AskUserInteractionResult) => void;
|
|
35
39
|
signal?: AbortSignal;
|
|
36
40
|
keybindings: KeybindingsManager;
|
|
37
41
|
onToggleToolsExpanded?: () => void;
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import type { Theme } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import { SelectList } from "@earendil-works/pi-tui";
|
|
3
|
-
import type { AskUserController } from "../session/controller.ts";
|
|
4
|
-
import { makeSelectListTheme } from "./overlay-render.ts";
|
|
5
|
-
import { buildTextActionItems, type OverlayAction } from "./overlay-view.ts";
|
|
6
|
-
|
|
7
|
-
export interface ActionListState {
|
|
8
|
-
entries: Array<{ action: OverlayAction; label: string }>;
|
|
9
|
-
list: SelectList | undefined;
|
|
10
|
-
index: number;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function createActionList(args: {
|
|
14
|
-
controller: AskUserController;
|
|
15
|
-
theme: Theme;
|
|
16
|
-
actionIndex: number;
|
|
17
|
-
onIndexChange: (index: number) => void;
|
|
18
|
-
onAction: (action: OverlayAction) => void;
|
|
19
|
-
}): ActionListState {
|
|
20
|
-
const actions = buildTextActionItems(args.controller);
|
|
21
|
-
const entries = actions.map(({ action, item }) => ({ action, label: item.label }));
|
|
22
|
-
if (actions.length === 0) {
|
|
23
|
-
return { entries, list: undefined, index: 0 };
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const index = Math.max(0, Math.min(args.actionIndex, actions.length - 1));
|
|
27
|
-
const list = new SelectList(
|
|
28
|
-
actions.map(({ item }) => item),
|
|
29
|
-
Math.min(actions.length, 6),
|
|
30
|
-
makeSelectListTheme(args.theme),
|
|
31
|
-
);
|
|
32
|
-
list.onSelectionChange = (item) => {
|
|
33
|
-
const nextIndex = actions.findIndex(({ item: candidate }) => candidate.value === item.value);
|
|
34
|
-
if (nextIndex >= 0) args.onIndexChange(nextIndex);
|
|
35
|
-
};
|
|
36
|
-
list.onSelect = (item) => {
|
|
37
|
-
const action = actions.find(({ item: candidate }) => candidate.value === item.value)?.action;
|
|
38
|
-
if (action) args.onAction(action);
|
|
39
|
-
};
|
|
40
|
-
list.setSelectedIndex(index);
|
|
41
|
-
return { entries, list, index };
|
|
42
|
-
}
|