@juicesharp/rpiv-ask-user-question 2.14.1 → 2.15.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 +1 -0
- package/ask-user-question.ts +24 -3
- package/config.ts +23 -0
- package/docs/configuration.md +15 -0
- package/docs/keyboard.md +2 -1
- package/locales/de.json +7 -4
- package/locales/en.json +8 -5
- package/locales/es.json +7 -4
- package/locales/fr.json +7 -4
- package/locales/pt-BR.json +7 -4
- package/locales/pt.json +7 -4
- package/locales/ru.json +7 -4
- package/locales/uk.json +7 -4
- package/locales/zh.json +7 -4
- package/package.json +4 -3
- package/state/build-questionnaire.ts +6 -0
- package/state/key-router.ts +49 -8
- package/state/questionnaire-session.ts +6 -0
- package/state/state-reducer.ts +13 -1
- package/state/state.ts +2 -0
- package/view/components/preview/preview-block-renderer.ts +19 -7
- package/view/dialog-builder.ts +4 -0
- package/view/dialog-copy.ts +13 -2
- package/view/tab-content-strategy.ts +24 -8
- package/view/transcript.ts +144 -0
package/README.md
CHANGED
|
@@ -52,6 +52,7 @@ Optional. Settings live in `~/.config/rpiv-ask-user-question/config.json`; the f
|
|
|
52
52
|
| Setting | What it does | Default |
|
|
53
53
|
| --- | --- | --- |
|
|
54
54
|
| `collapseKey` | Key that collapses and expands the dialog. Accepts Pi keybinding ids such as `alt+o`; `"off"` disables the shortcut. | `"ctrl+]"` |
|
|
55
|
+
| `notesKey` | Key that opens the notes editor. Any single character, including non-Latin ones such as `т`, or a Pi keybinding id such as `ctrl+n`. | `"n"` |
|
|
55
56
|
| `guidance.description` | Full replacement for the tool description the model sees. A non-empty string replaces the built-in text entirely — no merging. | built-in description |
|
|
56
57
|
| `guidance.promptSnippet` | One-line description of the tool in the system prompt — tune how eagerly the model asks. | built-in snippet |
|
|
57
58
|
| `guidance.promptGuidelines` | Usage guidelines given to the model, as a list of strings. | 4 built-in guidelines |
|
package/ask-user-question.ts
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
formatKeySpecForDisplay,
|
|
7
7
|
loadConfig,
|
|
8
8
|
resolveCollapseKey,
|
|
9
|
+
resolveNotesKey,
|
|
9
10
|
validateGuidanceFields,
|
|
10
11
|
} from "./config.ts";
|
|
11
12
|
import {
|
|
@@ -41,6 +42,7 @@ import {
|
|
|
41
42
|
} from "./tool/types.ts";
|
|
42
43
|
import { validateQuestionnaire } from "./tool/validate-questionnaire.ts";
|
|
43
44
|
import type { WrappingSelectItem } from "./view/components/wrapping-select.ts";
|
|
45
|
+
import { renderAskCall, renderAskResult } from "./view/transcript.ts";
|
|
44
46
|
|
|
45
47
|
function emitAskUserPromptEvent(pi: ExtensionAPI, params: QuestionParams, toolCallId: string): void {
|
|
46
48
|
const payload: AskUserPromptEventPayload = {
|
|
@@ -199,14 +201,25 @@ function makeSessionFactory(config: {
|
|
|
199
201
|
typed: QuestionParams;
|
|
200
202
|
itemsByTab: WrappingSelectItem[][];
|
|
201
203
|
collapseKey: string;
|
|
204
|
+
notesKey: string;
|
|
202
205
|
canReopenWhileHidden: boolean;
|
|
203
206
|
presentation: Presentation;
|
|
204
207
|
sessionRef: SessionRef;
|
|
205
208
|
open: OpenQuestionnaire;
|
|
206
209
|
Session: SessionModule["QuestionnaireSession"];
|
|
207
210
|
}) {
|
|
208
|
-
const {
|
|
209
|
-
|
|
211
|
+
const {
|
|
212
|
+
ctx,
|
|
213
|
+
typed,
|
|
214
|
+
itemsByTab,
|
|
215
|
+
collapseKey,
|
|
216
|
+
notesKey,
|
|
217
|
+
canReopenWhileHidden,
|
|
218
|
+
presentation,
|
|
219
|
+
sessionRef,
|
|
220
|
+
open,
|
|
221
|
+
Session,
|
|
222
|
+
} = config;
|
|
210
223
|
return (
|
|
211
224
|
tui: TUI,
|
|
212
225
|
theme: Theme,
|
|
@@ -252,6 +265,7 @@ function makeSessionFactory(config: {
|
|
|
252
265
|
}
|
|
253
266
|
},
|
|
254
267
|
collapseKey,
|
|
268
|
+
notesKey,
|
|
255
269
|
canReopenWhileHidden,
|
|
256
270
|
rowBudget: rowBudgetForHost(tui.terminal, presentation.rowBudget),
|
|
257
271
|
});
|
|
@@ -279,6 +293,7 @@ async function mountQuestionnaire(config: {
|
|
|
279
293
|
typed: QuestionParams;
|
|
280
294
|
itemsByTab: WrappingSelectItem[][];
|
|
281
295
|
collapseKey: string;
|
|
296
|
+
notesKey: string;
|
|
282
297
|
presentation: Presentation;
|
|
283
298
|
open: OpenQuestionnaire;
|
|
284
299
|
Session: SessionModule["QuestionnaireSession"];
|
|
@@ -357,7 +372,9 @@ async function runTuiPath(pi: ExtensionAPI, ctx: ExtensionContext, typed: Questi
|
|
|
357
372
|
// with non-US layouts (e.g. Latin American, where `]` is shifted) can override
|
|
358
373
|
// via the `collapseKey` config field. `resolveCollapseKey` also accepts the
|
|
359
374
|
// sentinel value `"off"` to disable the shortcut entirely.
|
|
360
|
-
const
|
|
375
|
+
const config = loadConfig();
|
|
376
|
+
const collapseKey = resolveCollapseKey(config);
|
|
377
|
+
const notesKey = resolveNotesKey(config);
|
|
361
378
|
const mount = (p: Presentation) =>
|
|
362
379
|
Promise.race([
|
|
363
380
|
mountQuestionnaire({
|
|
@@ -365,6 +382,7 @@ async function runTuiPath(pi: ExtensionAPI, ctx: ExtensionContext, typed: Questi
|
|
|
365
382
|
typed,
|
|
366
383
|
itemsByTab,
|
|
367
384
|
collapseKey,
|
|
385
|
+
notesKey,
|
|
368
386
|
presentation: p,
|
|
369
387
|
open,
|
|
370
388
|
Session: QuestionnaireSession,
|
|
@@ -467,6 +485,9 @@ export function registerAskUserQuestionTool(pi: ExtensionAPI): void {
|
|
|
467
485
|
parameters: QuestionParamsSchema,
|
|
468
486
|
// Undo double-encoded nested arguments before Pi validates them (#244).
|
|
469
487
|
prepareArguments: prepareQuestionArguments,
|
|
488
|
+
renderCall: (args, theme) => renderAskCall(args, theme),
|
|
489
|
+
renderResult: (result, { expanded }, theme, context) =>
|
|
490
|
+
renderAskResult(result, context?.args, theme, { expanded, isError: context?.isError ?? false }),
|
|
470
491
|
|
|
471
492
|
async execute(toolCallId, params, _signal, _onUpdate, ctx) {
|
|
472
493
|
// Line-terminator normalization runs once here, ahead of validation, so
|
package/config.ts
CHANGED
|
@@ -6,6 +6,7 @@ export type CollapseKeySpec = string;
|
|
|
6
6
|
|
|
7
7
|
export const DEFAULT_COLLAPSE_KEY: CollapseKeySpec = "ctrl+]";
|
|
8
8
|
export const COLLAPSE_KEY_OFF: CollapseKeySpec = "off";
|
|
9
|
+
export const DEFAULT_NOTES_KEY = "n";
|
|
9
10
|
|
|
10
11
|
export interface AskUserQuestionConfig {
|
|
11
12
|
guidance?: GuidanceFields;
|
|
@@ -17,6 +18,12 @@ export interface AskUserQuestionConfig {
|
|
|
17
18
|
* Pass `"off"` to disable the collapse shortcut entirely.
|
|
18
19
|
*/
|
|
19
20
|
collapseKey?: CollapseKeySpec;
|
|
21
|
+
/**
|
|
22
|
+
* Key that opens the notes editor. Defaults to `"n"`. A single character of any
|
|
23
|
+
* script (e.g. `"т"` on a Cyrillic layout) matches as typed; anything else is a
|
|
24
|
+
* key spec in the `collapseKey` format, e.g. `"ctrl+n"`.
|
|
25
|
+
*/
|
|
26
|
+
notesKey?: string;
|
|
20
27
|
}
|
|
21
28
|
|
|
22
29
|
// Named keys accepted by pi-tui's `matchesKey` (keys.js switch on the parsed base key).
|
|
@@ -68,6 +75,22 @@ export function resolveCollapseKey(config: Pick<AskUserQuestionConfig, "collapse
|
|
|
68
75
|
return isValidCollapseKeySpec(raw) ? raw : DEFAULT_COLLAPSE_KEY;
|
|
69
76
|
}
|
|
70
77
|
|
|
78
|
+
// Keys the questionnaire already navigates with — a notes key on one of them would shadow it.
|
|
79
|
+
const NOTES_KEY_RESERVED = new Set(["space", "enter", "return", "tab", "escape", "esc", "up", "down", "left", "right"]);
|
|
80
|
+
|
|
81
|
+
export function resolveNotesKey(config: Pick<AskUserQuestionConfig, "notesKey">): string {
|
|
82
|
+
const raw = config.notesKey?.trim();
|
|
83
|
+
if (!raw) return DEFAULT_NOTES_KEY;
|
|
84
|
+
if ([...raw].length === 1) return raw;
|
|
85
|
+
const spec = raw.toLowerCase();
|
|
86
|
+
return isValidCollapseKeySpec(spec) && !NOTES_KEY_RESERVED.has(spec) ? spec : DEFAULT_NOTES_KEY;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** A single-character notes key shows as configured (`n`, not `N`); a spec is display-cased. */
|
|
90
|
+
export function formatNotesKeyForDisplay(notesKey: string): string {
|
|
91
|
+
return [...notesKey].length === 1 ? notesKey : formatKeySpecForDisplay(notesKey);
|
|
92
|
+
}
|
|
93
|
+
|
|
71
94
|
// The only compound-word names in SPECIAL_KEYS — first-letter capitalization
|
|
72
95
|
// alone would render them "Pageup"/"Pagedown".
|
|
73
96
|
const COMPOUND_KEY_DISPLAY: Record<string, string> = {
|
package/docs/configuration.md
CHANGED
|
@@ -59,6 +59,7 @@ type are likewise dropped back to their default without a warning.
|
|
|
59
59
|
| Setting | What it does | Default |
|
|
60
60
|
| --- | --- | --- |
|
|
61
61
|
| `collapseKey` | Key that collapses and expands the dialog. | `"ctrl+]"` |
|
|
62
|
+
| `notesKey` | Key that opens the notes editor. | `"n"` |
|
|
62
63
|
| `guidance.description` | Full text of the tool description the model sees. Replaces the built-in default entirely — no merging. | built-in description |
|
|
63
64
|
| `guidance.promptSnippet` | One-line snippet describing the tool in the system prompt. | built-in snippet |
|
|
64
65
|
| `guidance.promptGuidelines` | List of usage guidelines given to the model. | 4 built-in guidelines |
|
|
@@ -90,6 +91,20 @@ for `"alt+o"`), as do the collapsed one-line footer and the one-shot notificatio
|
|
|
90
91
|
when the dialog is first hidden. With `"off"` the collapse hint is dropped from the
|
|
91
92
|
footer entirely, since no shortcut can fire.
|
|
92
93
|
|
|
94
|
+
### `notesKey`
|
|
95
|
+
|
|
96
|
+
A single character matches exactly as your keyboard types it, in any script. On a
|
|
97
|
+
Cyrillic layout, for example, the key that types `n` on a Latin layout types `т`, so set
|
|
98
|
+
`"т"`. Values are trimmed; a single character keeps its case.
|
|
99
|
+
|
|
100
|
+
Anything longer is a key spec in the `collapseKey` format, such as `"ctrl+n"` or `"alt+o"`.
|
|
101
|
+
In terminals that use the Kitty keyboard protocol, a modified spec like `"ctrl+n"` also
|
|
102
|
+
works on non-Latin layouts, because the terminal reports the key's Latin equivalent.
|
|
103
|
+
|
|
104
|
+
A spec that does not match the grammar, or that names a key the dialog already uses
|
|
105
|
+
(`space`, `enter`, `return`, `tab`, `escape`, `esc`, and the arrow keys), is rejected and
|
|
106
|
+
`"n"` is used. The notes hints in the dialog name whatever key you configure.
|
|
107
|
+
|
|
93
108
|
### `guidance.description`, `guidance.promptSnippet` and `guidance.promptGuidelines`
|
|
94
109
|
|
|
95
110
|
`guidance.description` replaces the entire built-in description Pi registers for the
|
package/docs/keyboard.md
CHANGED
|
@@ -12,8 +12,9 @@ adapts to the size of your terminal.
|
|
|
12
12
|
| `Shift+Enter` | Insert a newline. | `Type something.` input, notes editor |
|
|
13
13
|
| `Esc` | Cancel the whole questionnaire. | Everywhere except the notes editor, where it closes notes |
|
|
14
14
|
| `Tab` / `Shift+Tab` | Next / previous tab, wrapping. `→` / `←` do the same. | Multi-question dialogs only |
|
|
15
|
+
| `1`–`9` | Act on the row with that number: answer with it on a single-select question, toggle it on a multi-select one, or move to `Type something.` (no digit reaches `Next`). Inside `Type something.` and the notes editor, digits are text. | Option list |
|
|
15
16
|
| `Space` | Toggle the focused authored option. In `Type something.`, Space inserts text. | Multi-select questions |
|
|
16
|
-
| `n` | Open the notes editor for the focused question — or, on the Submit tab, the global note for the whole questionnaire. | Every question tab; the Submit tab in multi-question dialogs |
|
|
17
|
+
| `n` | Open the notes editor for the focused question — or, on the Submit tab, the global note for the whole questionnaire. Configurable via `notesKey`. | Every question tab; the Submit tab in multi-question dialogs |
|
|
17
18
|
| `Ctrl+G` | Open Pi's configured external editor with the current custom-answer draft. | `Type something.` input |
|
|
18
19
|
| `Ctrl+U` | Clear the current custom-answer draft. | `Type something.` input |
|
|
19
20
|
| `Ctrl+]` | Collapse or expand the dialog. Configurable via `collapseKey`. | Everywhere, including while collapsed |
|
package/locales/de.json
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"hint.newline": "Umschalt+Enter für neue Zeile",
|
|
13
13
|
"hint.clear": "Ctrl+U zum Leeren",
|
|
14
14
|
"hint.toggle": "Leertaste zum Umschalten",
|
|
15
|
-
"hint.notes": "
|
|
15
|
+
"hint.notes": "{key} für Notizen",
|
|
16
16
|
"hint.tab": "Tab wechselt die Frage",
|
|
17
17
|
"hint.cancel": "Esc zum Abbrechen",
|
|
18
18
|
|
|
@@ -21,13 +21,16 @@
|
|
|
21
21
|
"review.incomplete": "⚠ Beantworte die verbleibenden Fragen vor dem Senden:",
|
|
22
22
|
|
|
23
23
|
"preview.no_preview": "Keine Vorschau verfügbar",
|
|
24
|
-
"preview.notes_affordance": "Notizen: drücke
|
|
25
|
-
"preview.notes_edit_affordance": "Notiz gespeichert: drücke
|
|
24
|
+
"preview.notes_affordance": "Notizen: drücke {key}, um Notizen hinzuzufügen",
|
|
25
|
+
"preview.notes_edit_affordance": "Notiz gespeichert: drücke {key} zum Bearbeiten",
|
|
26
26
|
"notes.header": "Notizen:",
|
|
27
27
|
"notes.saved_label": "Notiz zu dieser Antwort:",
|
|
28
28
|
|
|
29
29
|
"editor.failed": "Externer Editor fehlgeschlagen",
|
|
30
30
|
|
|
31
31
|
"rpc.multi_instructions": "Gib die Nummern aller zutreffenden Optionen durch Kommas getrennt ein (z. B. \"1,3\"). Füge \"; eigene Antwort\" hinzu, um eigenen Text einzuschließen, oder gib nur eigenen Text ein.",
|
|
32
|
-
"rpc.custom_answer_title": "Gib deine Antwort ein:"
|
|
32
|
+
"rpc.custom_answer_title": "Gib deine Antwort ein:",
|
|
33
|
+
|
|
34
|
+
"transcript.not_answered": "nicht beantwortet",
|
|
35
|
+
"transcript.no_answer": "keine Antwort"
|
|
33
36
|
}
|
package/locales/en.json
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"hint.newline": "Shift+Enter for newline",
|
|
11
11
|
"hint.clear": "Ctrl+U to clear",
|
|
12
12
|
"hint.toggle": "Space to toggle",
|
|
13
|
-
"hint.notes": "
|
|
13
|
+
"hint.notes": "{key} to add notes",
|
|
14
14
|
"hint.tab": "Tab to switch questions",
|
|
15
15
|
"hint.collapse": "{key} to collapse",
|
|
16
16
|
"hint.expand_line": "{key} to expand · Esc to cancel",
|
|
@@ -19,12 +19,12 @@
|
|
|
19
19
|
"review.heading": "Review your answers",
|
|
20
20
|
"review.ready": "Ready to submit your answers?",
|
|
21
21
|
"review.incomplete": "⚠ Answer remaining questions before submitting:",
|
|
22
|
-
"review.global_hint": "
|
|
22
|
+
"review.global_hint": "{key} to add a note",
|
|
23
23
|
"review.note_label": "Note",
|
|
24
24
|
|
|
25
25
|
"preview.no_preview": "No preview available",
|
|
26
|
-
"preview.notes_affordance": "Notes: press
|
|
27
|
-
"preview.notes_edit_affordance": "Note saved: press
|
|
26
|
+
"preview.notes_affordance": "Notes: press {key} to add notes",
|
|
27
|
+
"preview.notes_edit_affordance": "Note saved: press {key} to edit",
|
|
28
28
|
"notes.header": "Notes:",
|
|
29
29
|
"notes.saved_label": "Note for this answer:",
|
|
30
30
|
"notes.global_header": "Global note:",
|
|
@@ -32,5 +32,8 @@
|
|
|
32
32
|
"editor.failed": "External editor failed",
|
|
33
33
|
|
|
34
34
|
"rpc.multi_instructions": "Enter the numbers of all that apply, comma-separated (e.g. \"1,3\"). Add \"; custom answer\" to include your own text, or type only custom text.",
|
|
35
|
-
"rpc.custom_answer_title": "Type your answer:"
|
|
35
|
+
"rpc.custom_answer_title": "Type your answer:",
|
|
36
|
+
|
|
37
|
+
"transcript.not_answered": "not answered",
|
|
38
|
+
"transcript.no_answer": "no answer"
|
|
36
39
|
}
|
package/locales/es.json
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"hint.newline": "Mayús+Enter para nueva línea",
|
|
13
13
|
"hint.clear": "Ctrl+U para borrar",
|
|
14
14
|
"hint.toggle": "Espacio para alternar",
|
|
15
|
-
"hint.notes": "
|
|
15
|
+
"hint.notes": "{key} para añadir notas",
|
|
16
16
|
"hint.tab": "Tab para cambiar de pregunta",
|
|
17
17
|
"hint.cancel": "Esc para cancelar",
|
|
18
18
|
|
|
@@ -21,13 +21,16 @@
|
|
|
21
21
|
"review.incomplete": "⚠ Responde las preguntas restantes antes de enviar:",
|
|
22
22
|
|
|
23
23
|
"preview.no_preview": "Vista previa no disponible",
|
|
24
|
-
"preview.notes_affordance": "Notas: pulsa
|
|
25
|
-
"preview.notes_edit_affordance": "Nota guardada: pulsa
|
|
24
|
+
"preview.notes_affordance": "Notas: pulsa {key} para añadir notas",
|
|
25
|
+
"preview.notes_edit_affordance": "Nota guardada: pulsa {key} para editarla",
|
|
26
26
|
"notes.header": "Notas:",
|
|
27
27
|
"notes.saved_label": "Nota para esta respuesta:",
|
|
28
28
|
|
|
29
29
|
"editor.failed": "Error del editor externo",
|
|
30
30
|
|
|
31
31
|
"rpc.multi_instructions": "Introduce los números de todas las opciones que correspondan, separados por comas (p. ej. \"1,3\"). Añade \"; respuesta propia\" para incluir texto propio, o escribe solo texto propio.",
|
|
32
|
-
"rpc.custom_answer_title": "Escribe tu respuesta:"
|
|
32
|
+
"rpc.custom_answer_title": "Escribe tu respuesta:",
|
|
33
|
+
|
|
34
|
+
"transcript.not_answered": "sin responder",
|
|
35
|
+
"transcript.no_answer": "sin respuesta"
|
|
33
36
|
}
|
package/locales/fr.json
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"hint.newline": "Maj+Entrée pour une nouvelle ligne",
|
|
13
13
|
"hint.clear": "Ctrl+U pour effacer",
|
|
14
14
|
"hint.toggle": "Espace pour basculer",
|
|
15
|
-
"hint.notes": "
|
|
15
|
+
"hint.notes": "{key} pour ajouter des notes",
|
|
16
16
|
"hint.tab": "Tab pour changer de question",
|
|
17
17
|
"hint.cancel": "Échap pour annuler",
|
|
18
18
|
|
|
@@ -21,13 +21,16 @@
|
|
|
21
21
|
"review.incomplete": "⚠ Répondez aux questions restantes avant d'envoyer :",
|
|
22
22
|
|
|
23
23
|
"preview.no_preview": "Aucun aperçu disponible",
|
|
24
|
-
"preview.notes_affordance": "Notes : appuyez sur
|
|
25
|
-
"preview.notes_edit_affordance": "Note enregistrée : appuyez sur
|
|
24
|
+
"preview.notes_affordance": "Notes : appuyez sur {key} pour ajouter des notes",
|
|
25
|
+
"preview.notes_edit_affordance": "Note enregistrée : appuyez sur {key} pour la modifier",
|
|
26
26
|
"notes.header": "Notes :",
|
|
27
27
|
"notes.saved_label": "Note pour cette réponse :",
|
|
28
28
|
|
|
29
29
|
"editor.failed": "Échec de l’éditeur externe",
|
|
30
30
|
|
|
31
31
|
"rpc.multi_instructions": "Saisissez les numéros de toutes les options applicables, séparés par des virgules (p. ex. « 1,3 »). Ajoutez « ; réponse libre » pour inclure votre propre texte, ou saisissez uniquement ce texte.",
|
|
32
|
-
"rpc.custom_answer_title": "Tapez votre réponse :"
|
|
32
|
+
"rpc.custom_answer_title": "Tapez votre réponse :",
|
|
33
|
+
|
|
34
|
+
"transcript.not_answered": "sans réponse",
|
|
35
|
+
"transcript.no_answer": "aucune réponse"
|
|
33
36
|
}
|
package/locales/pt-BR.json
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"hint.newline": "Shift+Enter para nova linha",
|
|
13
13
|
"hint.clear": "Ctrl+U para limpar",
|
|
14
14
|
"hint.toggle": "Espaço para alternar",
|
|
15
|
-
"hint.notes": "
|
|
15
|
+
"hint.notes": "{key} para adicionar notas",
|
|
16
16
|
"hint.tab": "Tab para trocar de pergunta",
|
|
17
17
|
"hint.cancel": "Esc para cancelar",
|
|
18
18
|
|
|
@@ -21,13 +21,16 @@
|
|
|
21
21
|
"review.incomplete": "⚠ Responda as perguntas restantes antes de enviar:",
|
|
22
22
|
|
|
23
23
|
"preview.no_preview": "Pré-visualização indisponível",
|
|
24
|
-
"preview.notes_affordance": "Notas: pressione
|
|
25
|
-
"preview.notes_edit_affordance": "Nota salva: pressione
|
|
24
|
+
"preview.notes_affordance": "Notas: pressione {key} para adicionar notas",
|
|
25
|
+
"preview.notes_edit_affordance": "Nota salva: pressione {key} para editar",
|
|
26
26
|
"notes.header": "Notas:",
|
|
27
27
|
"notes.saved_label": "Nota para esta resposta:",
|
|
28
28
|
|
|
29
29
|
"editor.failed": "Falha no editor externo",
|
|
30
30
|
|
|
31
31
|
"rpc.multi_instructions": "Digite os números de todas as opções aplicáveis, separados por vírgulas (ex.: \"1,3\"). Adicione \"; resposta própria\" para incluir texto próprio, ou digite apenas esse texto.",
|
|
32
|
-
"rpc.custom_answer_title": "Digite sua resposta:"
|
|
32
|
+
"rpc.custom_answer_title": "Digite sua resposta:",
|
|
33
|
+
|
|
34
|
+
"transcript.not_answered": "não respondida",
|
|
35
|
+
"transcript.no_answer": "sem resposta"
|
|
33
36
|
}
|
package/locales/pt.json
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"hint.newline": "Shift+Enter para nova linha",
|
|
13
13
|
"hint.clear": "Ctrl+U para limpar",
|
|
14
14
|
"hint.toggle": "Espaço para alternar",
|
|
15
|
-
"hint.notes": "
|
|
15
|
+
"hint.notes": "{key} para adicionar notas",
|
|
16
16
|
"hint.tab": "Tab para mudar de pergunta",
|
|
17
17
|
"hint.cancel": "Esc para cancelar",
|
|
18
18
|
|
|
@@ -21,13 +21,16 @@
|
|
|
21
21
|
"review.incomplete": "⚠ Responda às perguntas restantes antes de enviar:",
|
|
22
22
|
|
|
23
23
|
"preview.no_preview": "Pré-visualização indisponível",
|
|
24
|
-
"preview.notes_affordance": "Notas: prima
|
|
25
|
-
"preview.notes_edit_affordance": "Nota guardada: prima
|
|
24
|
+
"preview.notes_affordance": "Notas: prima {key} para adicionar notas",
|
|
25
|
+
"preview.notes_edit_affordance": "Nota guardada: prima {key} para editar",
|
|
26
26
|
"notes.header": "Notas:",
|
|
27
27
|
"notes.saved_label": "Nota para esta resposta:",
|
|
28
28
|
|
|
29
29
|
"editor.failed": "Falha no editor externo",
|
|
30
30
|
|
|
31
31
|
"rpc.multi_instructions": "Introduza os números de todas as opções aplicáveis, separados por vírgulas (ex.: \"1,3\"). Adicione \"; resposta própria\" para incluir texto próprio, ou escreva apenas esse texto.",
|
|
32
|
-
"rpc.custom_answer_title": "Escreva a sua resposta:"
|
|
32
|
+
"rpc.custom_answer_title": "Escreva a sua resposta:",
|
|
33
|
+
|
|
34
|
+
"transcript.not_answered": "não respondida",
|
|
35
|
+
"transcript.no_answer": "sem resposta"
|
|
33
36
|
}
|
package/locales/ru.json
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"hint.newline": "Shift+Enter — новая строка",
|
|
13
13
|
"hint.clear": "Ctrl+U — очистить",
|
|
14
14
|
"hint.toggle": "Space — переключить",
|
|
15
|
-
"hint.notes": "
|
|
15
|
+
"hint.notes": "{key} — добавить заметки",
|
|
16
16
|
"hint.tab": "Tab — следующий вопрос",
|
|
17
17
|
"hint.cancel": "Esc — отменить",
|
|
18
18
|
|
|
@@ -21,13 +21,16 @@
|
|
|
21
21
|
"review.incomplete": "⚠ Ответьте на оставшиеся вопросы перед отправкой:",
|
|
22
22
|
|
|
23
23
|
"preview.no_preview": "Предпросмотр недоступен",
|
|
24
|
-
"preview.notes_affordance": "Заметки: нажмите
|
|
25
|
-
"preview.notes_edit_affordance": "Заметка сохранена: нажмите
|
|
24
|
+
"preview.notes_affordance": "Заметки: нажмите {key}, чтобы добавить заметки",
|
|
25
|
+
"preview.notes_edit_affordance": "Заметка сохранена: нажмите {key}, чтобы изменить",
|
|
26
26
|
"notes.header": "Заметки:",
|
|
27
27
|
"notes.saved_label": "Заметка к этому ответу:",
|
|
28
28
|
|
|
29
29
|
"editor.failed": "Ошибка внешнего редактора",
|
|
30
30
|
|
|
31
31
|
"rpc.multi_instructions": "Введите номера всех подходящих вариантов через запятую (например, \"1,3\"). Добавьте \"; свой ответ\", чтобы включить собственный текст, или введите только этот текст.",
|
|
32
|
-
"rpc.custom_answer_title": "Введите свой ответ:"
|
|
32
|
+
"rpc.custom_answer_title": "Введите свой ответ:",
|
|
33
|
+
|
|
34
|
+
"transcript.not_answered": "без ответа",
|
|
35
|
+
"transcript.no_answer": "ответа нет"
|
|
33
36
|
}
|
package/locales/uk.json
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"hint.newline": "Shift+Enter — новий рядок",
|
|
13
13
|
"hint.clear": "Ctrl+U — очистити",
|
|
14
14
|
"hint.toggle": "Space — перемкнути",
|
|
15
|
-
"hint.notes": "
|
|
15
|
+
"hint.notes": "{key} — додати нотатки",
|
|
16
16
|
"hint.tab": "Tab — наступне питання",
|
|
17
17
|
"hint.cancel": "Esc — скасувати",
|
|
18
18
|
|
|
@@ -21,13 +21,16 @@
|
|
|
21
21
|
"review.incomplete": "⚠ Дайте відповіді на решту питань перед надсиланням:",
|
|
22
22
|
|
|
23
23
|
"preview.no_preview": "Попередній перегляд недоступний",
|
|
24
|
-
"preview.notes_affordance": "Нотатки: натисніть
|
|
25
|
-
"preview.notes_edit_affordance": "Нотатку збережено: натисніть
|
|
24
|
+
"preview.notes_affordance": "Нотатки: натисніть {key}, щоб додати нотатки",
|
|
25
|
+
"preview.notes_edit_affordance": "Нотатку збережено: натисніть {key}, щоб змінити",
|
|
26
26
|
"notes.header": "Нотатки:",
|
|
27
27
|
"notes.saved_label": "Нотатка до цієї відповіді:",
|
|
28
28
|
|
|
29
29
|
"editor.failed": "Помилка зовнішнього редактора",
|
|
30
30
|
|
|
31
31
|
"rpc.multi_instructions": "Введіть номери всіх відповідних варіантів через кому (наприклад, \"1,3\"). Додайте \"; власна відповідь\", щоб включити власний текст, або введіть лише цей текст.",
|
|
32
|
-
"rpc.custom_answer_title": "Введіть свою відповідь:"
|
|
32
|
+
"rpc.custom_answer_title": "Введіть свою відповідь:",
|
|
33
|
+
|
|
34
|
+
"transcript.not_answered": "без відповіді",
|
|
35
|
+
"transcript.no_answer": "відповіді немає"
|
|
33
36
|
}
|
package/locales/zh.json
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"hint.newline": "Shift+Enter 换行",
|
|
13
13
|
"hint.clear": "Ctrl+U 清空",
|
|
14
14
|
"hint.toggle": "空格切换",
|
|
15
|
-
"hint.notes": "按
|
|
15
|
+
"hint.notes": "按 {key} 添加备注",
|
|
16
16
|
"hint.tab": "Tab 切换问题",
|
|
17
17
|
"hint.collapse": "{key} 折叠",
|
|
18
18
|
"hint.expand_line": "{key} 展开 · Esc 取消",
|
|
@@ -23,13 +23,16 @@
|
|
|
23
23
|
"review.incomplete": "⚠ 提交前请先回答以下问题:",
|
|
24
24
|
|
|
25
25
|
"preview.no_preview": "暂无预览",
|
|
26
|
-
"preview.notes_affordance": "备注:按
|
|
27
|
-
"preview.notes_edit_affordance": "备注已保存:按
|
|
26
|
+
"preview.notes_affordance": "备注:按 {key} 添加",
|
|
27
|
+
"preview.notes_edit_affordance": "备注已保存:按 {key} 编辑",
|
|
28
28
|
"notes.header": "备注:",
|
|
29
29
|
"notes.saved_label": "此回答的备注:",
|
|
30
30
|
|
|
31
31
|
"editor.failed": "外部编辑器启动失败",
|
|
32
32
|
|
|
33
33
|
"rpc.multi_instructions": "输入所有适用选项的编号,用逗号分隔(例如 \"1,3\")。添加 \"; 自定义回答\" 可同时包含自定义文本,也可以只输入自定义文本。",
|
|
34
|
-
"rpc.custom_answer_title": "输入你的回答:"
|
|
34
|
+
"rpc.custom_answer_title": "输入你的回答:",
|
|
35
|
+
|
|
36
|
+
"transcript.not_answered": "未回答",
|
|
37
|
+
"transcript.no_answer": "无回答"
|
|
35
38
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@juicesharp/rpiv-ask-user-question",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.15.0",
|
|
4
4
|
"description": "Pi extension. A structured questionnaire the model can put to you when it would otherwise guess, with typed options instead of free-form replies.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package",
|
|
@@ -81,7 +81,8 @@
|
|
|
81
81
|
"view/scroll-window.ts",
|
|
82
82
|
"view/stateful-view.ts",
|
|
83
83
|
"view/tab-components.ts",
|
|
84
|
-
"view/tab-content-strategy.ts"
|
|
84
|
+
"view/tab-content-strategy.ts",
|
|
85
|
+
"view/transcript.ts"
|
|
85
86
|
],
|
|
86
87
|
"pi": {
|
|
87
88
|
"image": "https://raw.githubusercontent.com/juicesharp/rpiv-mono/main/packages/rpiv-ask-user-question/docs/cover.png",
|
|
@@ -101,6 +102,6 @@
|
|
|
101
102
|
}
|
|
102
103
|
},
|
|
103
104
|
"dependencies": {
|
|
104
|
-
"@juicesharp/rpiv-config": "^2.
|
|
105
|
+
"@juicesharp/rpiv-config": "^2.15.0"
|
|
105
106
|
}
|
|
106
107
|
}
|
|
@@ -47,6 +47,8 @@ export interface QuestionnaireBuildConfig {
|
|
|
47
47
|
* of runtime context.
|
|
48
48
|
*/
|
|
49
49
|
collapseKey: string;
|
|
50
|
+
/** Resolved notes key (`resolveNotesKey` output), threaded to the hints that name it. */
|
|
51
|
+
notesKey: string;
|
|
50
52
|
/**
|
|
51
53
|
* Maps `tui.terminal.rows` to the rows the dialog may render — identity for the
|
|
52
54
|
* overlay, a capped share for the inline editor slot (`../presentation.ts`). Applied
|
|
@@ -123,6 +125,7 @@ class QuestionnaireBuilder {
|
|
|
123
125
|
private readonly initialState: QuestionnaireState;
|
|
124
126
|
private readonly getCurrentTab: () => number;
|
|
125
127
|
private readonly collapseKey: string;
|
|
128
|
+
private readonly notesKey: string;
|
|
126
129
|
private readonly rowBudget: (terminalRows: number) => number;
|
|
127
130
|
|
|
128
131
|
private readonly selectTheme: WrappingSelectTheme;
|
|
@@ -141,6 +144,7 @@ class QuestionnaireBuilder {
|
|
|
141
144
|
this.initialState = config.initialState;
|
|
142
145
|
this.getCurrentTab = config.getCurrentTab;
|
|
143
146
|
this.collapseKey = config.collapseKey;
|
|
147
|
+
this.notesKey = config.notesKey;
|
|
144
148
|
this.rowBudget = config.rowBudget;
|
|
145
149
|
|
|
146
150
|
this.selectTheme = this.makeSelectTheme();
|
|
@@ -191,6 +195,7 @@ class QuestionnaireBuilder {
|
|
|
191
195
|
question,
|
|
192
196
|
theme: this.theme,
|
|
193
197
|
markdownTheme: this.markdownTheme,
|
|
198
|
+
notesKey: this.notesKey,
|
|
194
199
|
});
|
|
195
200
|
const preview = new PreviewPane({
|
|
196
201
|
question,
|
|
@@ -277,6 +282,7 @@ class QuestionnaireBuilder {
|
|
|
277
282
|
getCurrentBodyHeight: heights.current,
|
|
278
283
|
getTerminalRows: this.getTerminalRows,
|
|
279
284
|
collapseKey: this.collapseKey,
|
|
285
|
+
notesKey: this.notesKey,
|
|
280
286
|
},
|
|
281
287
|
{ state: this.initialState, activePreviewPane: this.pickInitialActivePreview(tabs) },
|
|
282
288
|
);
|
package/state/key-router.ts
CHANGED
|
@@ -15,7 +15,17 @@ const KEYBIND_CLEAR = "tui.editor.deleteToLineStart";
|
|
|
15
15
|
const KEYBIND_EXTERNAL_EDITOR = "app.editor.external";
|
|
16
16
|
|
|
17
17
|
const NOTES_ACTIVATE_KEY = "n";
|
|
18
|
-
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The notes shortcut. A single-character key matches the character as typed, so a
|
|
21
|
+
* non-Latin one works (pi-tui's key parser knows only ASCII); anything else matches as
|
|
22
|
+
* a pi-tui key spec. A non-string key — a stale outer module, as with `collapseKey`
|
|
23
|
+
* below — falls back to `n`.
|
|
24
|
+
*/
|
|
25
|
+
function matchesNotesKey(data: string, notesKey: unknown): boolean {
|
|
26
|
+
const key = typeof notesKey === "string" ? notesKey : NOTES_ACTIVATE_KEY;
|
|
27
|
+
return data === key || matchesKey(data, key as Parameters<typeof matchesKey>[1]);
|
|
28
|
+
}
|
|
19
29
|
|
|
20
30
|
export type QuestionnaireAction =
|
|
21
31
|
| { kind: "nav"; nextIndex: number; inputValue: string }
|
|
@@ -225,19 +235,37 @@ function routeSubmitTab(
|
|
|
225
235
|
// answers flow through `orderedAnswers()` in the host.
|
|
226
236
|
return state.submitChoiceIndex === 1 ? { kind: "cancel" } : { kind: "submit" };
|
|
227
237
|
}
|
|
228
|
-
// Global note (#182):
|
|
238
|
+
// Global note (#182): the notes key on the Submit tab opens the notes editor scoped to the whole
|
|
229
239
|
// questionnaire at the pseudo-index (`questions.length` in notesByTab). Reachable only
|
|
230
240
|
// with the editor closed — `routeKey` dispatches notesVisible traffic to
|
|
231
241
|
// `routeNotesMode` before the submit-tab block runs. The branch shadows nothing above
|
|
232
|
-
// it (cancel, tab switch, submit-nav, confirm):
|
|
242
|
+
// it (cancel, tab switch, submit-nav, confirm): the default `n` matches none of them
|
|
233
243
|
// under default bindings, and a user who deliberately binds one of those actions to
|
|
234
244
|
// `n` keeps that mapping because the earlier branch still wins (Enter still submits).
|
|
235
|
-
if (data
|
|
245
|
+
if (matchesNotesKey(data, runtime.notesKey)) {
|
|
236
246
|
return { kind: "notes_enter" };
|
|
237
247
|
}
|
|
238
248
|
return { kind: "ignore" };
|
|
239
249
|
}
|
|
240
250
|
|
|
251
|
+
const DIGIT_KEYS = ["1", "2", "3", "4", "5", "6", "7", "8", "9"] as const;
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* The row a digit hotkey names: `1`-`9` follow the list's numbering, so the
|
|
255
|
+
* unnumbered Next row has no digit. One key per keystroke — a pasted `"12"`
|
|
256
|
+
* matches none. Checked after every keybinding, so a digit bound to an action
|
|
257
|
+
* keeps that action.
|
|
258
|
+
*/
|
|
259
|
+
function digitRow(
|
|
260
|
+
data: string,
|
|
261
|
+
runtime: QuestionnaireRuntime,
|
|
262
|
+
): { index: number; activatesInputMode: boolean } | undefined {
|
|
263
|
+
const index = DIGIT_KEYS.findIndex((digit) => matchesKey(data, digit));
|
|
264
|
+
const item = runtime.items[index];
|
|
265
|
+
if (!item || !ROW_INTENT_META[item.kind].numbered) return undefined;
|
|
266
|
+
return { index, activatesInputMode: ROW_INTENT_META[item.kind].activatesInputMode };
|
|
267
|
+
}
|
|
268
|
+
|
|
241
269
|
function routeMultiSelectTab(
|
|
242
270
|
kb: QuestionnaireKeybindings,
|
|
243
271
|
data: string,
|
|
@@ -249,7 +277,7 @@ function routeMultiSelectTab(
|
|
|
249
277
|
// Space toggles the focused row's checkbox. Suppressed on rows whose META declares
|
|
250
278
|
// `blocksMultiToggle` (the Next sentinel) or `activatesInputMode` (the "Type
|
|
251
279
|
// something." row — it is an inline input, not a checkable option).
|
|
252
|
-
if (data
|
|
280
|
+
if (matchesKey(data, Key.space)) {
|
|
253
281
|
if (focusedMeta?.blocksMultiToggle) return { kind: "ignore" };
|
|
254
282
|
if (focusedMeta?.activatesInputMode) return { kind: "ignore" };
|
|
255
283
|
return { kind: "toggle", index: state.optionIndex };
|
|
@@ -266,7 +294,11 @@ function routeMultiSelectTab(
|
|
|
266
294
|
return buildMultiConfirmAction(state, runtime);
|
|
267
295
|
}
|
|
268
296
|
if (kb.matches(data, KEYBIND_CANCEL)) return { kind: "cancel" };
|
|
269
|
-
|
|
297
|
+
// A digit toggles its row; the Type something. row's digit focuses it instead.
|
|
298
|
+
const row = digitRow(data, runtime);
|
|
299
|
+
if (!row) return { kind: "ignore" };
|
|
300
|
+
if (row.activatesInputMode) return { kind: "nav", nextIndex: row.index, inputValue: runtime.inputBuffer };
|
|
301
|
+
return { kind: "toggle", index: row.index };
|
|
270
302
|
}
|
|
271
303
|
|
|
272
304
|
function routeSingleSelectTab(
|
|
@@ -281,7 +313,16 @@ function routeSingleSelectTab(
|
|
|
281
313
|
return { kind: "confirm", answer, autoAdvanceTab: computeAutoAdvanceTab(state, runtime) };
|
|
282
314
|
}
|
|
283
315
|
if (kb.matches(data, KEYBIND_CANCEL)) return { kind: "cancel" };
|
|
284
|
-
|
|
316
|
+
// A digit answers with its row, as Enter on it would; the Type something. row's digit focuses it instead.
|
|
317
|
+
const row = digitRow(data, runtime);
|
|
318
|
+
if (!row) return { kind: "ignore" };
|
|
319
|
+
if (row.activatesInputMode) return { kind: "nav", nextIndex: row.index, inputValue: runtime.inputBuffer };
|
|
320
|
+
const answer = buildSingleSelectAnswer(
|
|
321
|
+
{ ...state, optionIndex: row.index },
|
|
322
|
+
{ ...runtime, currentItem: runtime.items[row.index] },
|
|
323
|
+
);
|
|
324
|
+
if (!answer) return { kind: "ignore" };
|
|
325
|
+
return { kind: "confirm", answer, autoAdvanceTab: computeAutoAdvanceTab(state, runtime) };
|
|
285
326
|
}
|
|
286
327
|
|
|
287
328
|
export function routeKey(data: string, state: QuestionnaireState, runtime: QuestionnaireRuntime): QuestionnaireAction {
|
|
@@ -342,7 +383,7 @@ export function routeKey(data: string, state: QuestionnaireState, runtime: Quest
|
|
|
342
383
|
// "Type something.") is irrelevant: the gate sits ABOVE the multi-select
|
|
343
384
|
// toggle block and the Next sentinel never activates inputMode, so `n` is
|
|
344
385
|
// neither swallowed earlier nor blocked by `blocksMultiToggle`.
|
|
345
|
-
if (data
|
|
386
|
+
if (matchesNotesKey(data, runtime.notesKey)) {
|
|
346
387
|
return { kind: "notes_enter" };
|
|
347
388
|
}
|
|
348
389
|
|
|
@@ -22,6 +22,8 @@ export interface QuestionnaireSessionConfig {
|
|
|
22
22
|
editInput: (value: string) => Promise<string | undefined>;
|
|
23
23
|
/** Key spec for the collapse/expand shortcut, e.g. `"ctrl+]"` or `"alt+o"`. */
|
|
24
24
|
collapseKey: string;
|
|
25
|
+
/** Key that opens the notes editor (`resolveNotesKey` output). */
|
|
26
|
+
notesKey: string;
|
|
25
27
|
/**
|
|
26
28
|
* True iff `execute()` registered the raw `ctx.ui.onTerminalInput` listener — the only
|
|
27
29
|
* path that can reach a hidden overlay. Gates the `set_overlay_hidden` effect: a host
|
|
@@ -75,6 +77,7 @@ export class QuestionnaireSession {
|
|
|
75
77
|
private readonly keybindings: QuestionnaireRuntime["keybindings"];
|
|
76
78
|
private readonly editInput: QuestionnaireSessionConfig["editInput"];
|
|
77
79
|
private readonly collapseKey: string;
|
|
80
|
+
private readonly notesKey: string;
|
|
78
81
|
private readonly canReopenWhileHidden: boolean;
|
|
79
82
|
private inputEditorOpen = false;
|
|
80
83
|
|
|
@@ -98,6 +101,7 @@ export class QuestionnaireSession {
|
|
|
98
101
|
this.keybindings = config.keybindings;
|
|
99
102
|
this.editInput = config.editInput;
|
|
100
103
|
this.collapseKey = config.collapseKey;
|
|
104
|
+
this.notesKey = config.notesKey;
|
|
101
105
|
this.canReopenWhileHidden = config.canReopenWhileHidden;
|
|
102
106
|
|
|
103
107
|
const built = buildQuestionnaire({
|
|
@@ -109,6 +113,7 @@ export class QuestionnaireSession {
|
|
|
109
113
|
initialState: this.state,
|
|
110
114
|
getCurrentTab: () => this.state.currentTab,
|
|
111
115
|
collapseKey: this.collapseKey,
|
|
116
|
+
notesKey: this.notesKey,
|
|
112
117
|
rowBudget: config.rowBudget,
|
|
113
118
|
});
|
|
114
119
|
|
|
@@ -251,6 +256,7 @@ export class QuestionnaireSession {
|
|
|
251
256
|
currentItem: this.currentItem(),
|
|
252
257
|
items: this.itemsByTab[this.state.currentTab] ?? [],
|
|
253
258
|
collapseKey: this.collapseKey,
|
|
259
|
+
notesKey: this.notesKey,
|
|
254
260
|
};
|
|
255
261
|
}
|
|
256
262
|
|
package/state/state-reducer.ts
CHANGED
|
@@ -124,12 +124,24 @@ function withoutCustomDraft(state: QuestionnaireState, tab: number): ReadonlyMap
|
|
|
124
124
|
return drafts;
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
+
/**
|
|
128
|
+
* Row focused on entering a tab: the chosen option, or Next for a multi-select answer, so a
|
|
129
|
+
* stray Enter re-confirms the answer instead of replacing it with row 0. A custom answer
|
|
130
|
+
* starts at row 0, since focusing its row would enter input mode.
|
|
131
|
+
*/
|
|
132
|
+
function answeredRowIndex(answer: QuestionAnswer | undefined, items: readonly WrappingSelectItem[]): number {
|
|
133
|
+
let index = -1;
|
|
134
|
+
if (answer?.kind === "option") index = items.findIndex((i) => i.kind === "option" && i.label === answer.answer);
|
|
135
|
+
if (answer?.kind === "multi") index = items.findIndex((i) => i.kind === "next");
|
|
136
|
+
return Math.max(0, index);
|
|
137
|
+
}
|
|
138
|
+
|
|
127
139
|
function switchTabResult(state: QuestionnaireState, nextTab: number, ctx: ApplyContext): ApplyResult {
|
|
128
140
|
const notesValue = notesValueFor(state, nextTab);
|
|
129
141
|
const transitioned: QuestionnaireState = {
|
|
130
142
|
...state,
|
|
131
143
|
currentTab: nextTab,
|
|
132
|
-
optionIndex:
|
|
144
|
+
optionIndex: answeredRowIndex(state.answers.get(nextTab), ctx.itemsByTab[nextTab] ?? []),
|
|
133
145
|
inputMode: false,
|
|
134
146
|
notesVisible: false,
|
|
135
147
|
submitChoiceIndex: 0,
|
package/state/state.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { Theme } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
import type { MarkdownTheme } from "@earendil-works/pi-tui";
|
|
3
|
+
import { DEFAULT_NOTES_KEY, formatNotesKeyForDisplay } from "../../../config.ts";
|
|
3
4
|
import { t } from "../../../state/i18n-bridge.ts";
|
|
4
5
|
import type { QuestionData } from "../../../tool/types.ts";
|
|
6
|
+
import { KEY_PLACEHOLDER } from "../../dialog-copy.ts";
|
|
5
7
|
import {
|
|
6
8
|
MAX_PREVIEW_HEIGHT_SIDE_BY_SIDE,
|
|
7
9
|
MAX_PREVIEW_HEIGHT_STACKED,
|
|
@@ -21,9 +23,12 @@ import type { PreviewLayoutMode } from "./preview-layout-decider.ts";
|
|
|
21
23
|
* Affordance text shown below the bordered preview when focused on a preview-bearing option.
|
|
22
24
|
* Re-exported by `preview-pane.ts` for the existing test surface.
|
|
23
25
|
*/
|
|
24
|
-
export const
|
|
26
|
+
export const NOTES_AFFORDANCE_TEMPLATE = `Notes: press ${KEY_PLACEHOLDER} to add notes`;
|
|
25
27
|
/** Affordance text once the question carries a saved note (#197). */
|
|
26
|
-
export const
|
|
28
|
+
export const NOTES_EDIT_AFFORDANCE_TEMPLATE = `Note saved: press ${KEY_PLACEHOLDER} to edit`;
|
|
29
|
+
/** Default-key (`n`) renderings of the two affordance templates. */
|
|
30
|
+
export const NOTES_AFFORDANCE_TEXT = NOTES_AFFORDANCE_TEMPLATE.replace(KEY_PLACEHOLDER, DEFAULT_NOTES_KEY);
|
|
31
|
+
export const NOTES_EDIT_AFFORDANCE_TEXT = NOTES_EDIT_AFFORDANCE_TEMPLATE.replace(KEY_PLACEHOLDER, DEFAULT_NOTES_KEY);
|
|
27
32
|
|
|
28
33
|
/**
|
|
29
34
|
* Which notes affordance the block shows under the preview: `add` / `edit` (no note yet /
|
|
@@ -32,10 +37,12 @@ export const NOTES_EDIT_AFFORDANCE_TEXT = "Note saved: press n to edit";
|
|
|
32
37
|
*/
|
|
33
38
|
export type NotesAffordance = "add" | "edit" | "none";
|
|
34
39
|
|
|
35
|
-
function affordanceText(affordance: Exclude<NotesAffordance, "none"
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
40
|
+
function affordanceText(affordance: Exclude<NotesAffordance, "none">, notesKey: string): string {
|
|
41
|
+
const text =
|
|
42
|
+
affordance === "edit"
|
|
43
|
+
? t("preview.notes_edit_affordance", NOTES_EDIT_AFFORDANCE_TEMPLATE)
|
|
44
|
+
: t("preview.notes_affordance", NOTES_AFFORDANCE_TEMPLATE);
|
|
45
|
+
return text.replace(KEY_PLACEHOLDER, formatNotesKeyForDisplay(notesKey));
|
|
39
46
|
}
|
|
40
47
|
|
|
41
48
|
/** Content row budget for a layout mode: preview cap minus border + affordance overhead. */
|
|
@@ -73,6 +80,8 @@ export interface PreviewBlockRendererConfig {
|
|
|
73
80
|
question: QuestionData;
|
|
74
81
|
theme: Theme;
|
|
75
82
|
markdownTheme: MarkdownTheme;
|
|
83
|
+
/** Resolved notes key (`resolveNotesKey` output), named by the affordance. */
|
|
84
|
+
notesKey: string;
|
|
76
85
|
}
|
|
77
86
|
|
|
78
87
|
/**
|
|
@@ -88,9 +97,11 @@ export interface PreviewBlockRendererConfig {
|
|
|
88
97
|
export class PreviewBlockRenderer {
|
|
89
98
|
private readonly theme: Theme;
|
|
90
99
|
private readonly cache: MarkdownContentCache;
|
|
100
|
+
private readonly notesKey: string;
|
|
91
101
|
|
|
92
102
|
constructor(config: PreviewBlockRendererConfig) {
|
|
93
103
|
this.theme = config.theme;
|
|
104
|
+
this.notesKey = config.notesKey;
|
|
94
105
|
this.cache = new MarkdownContentCache(config.question, config.theme, config.markdownTheme);
|
|
95
106
|
}
|
|
96
107
|
|
|
@@ -143,7 +154,8 @@ export class PreviewBlockRenderer {
|
|
|
143
154
|
const boxedLines = renderBorderedBox(contentLines, boxWidth, colorFn, hidden);
|
|
144
155
|
if (!fit.affordance) return boxedLines;
|
|
145
156
|
|
|
146
|
-
const text =
|
|
157
|
+
const text =
|
|
158
|
+
affordance !== "none" && this.cache.has(optionIndex) ? affordanceText(affordance, this.notesKey) : "";
|
|
147
159
|
return [...boxedLines, "", text ? this.theme.fg("muted", text) : ""];
|
|
148
160
|
}
|
|
149
161
|
}
|
package/view/dialog-builder.ts
CHANGED
|
@@ -87,6 +87,8 @@ export interface DialogConfig {
|
|
|
87
87
|
* The footer hint interpolates it, and drops the collapse part when `"off"`.
|
|
88
88
|
*/
|
|
89
89
|
collapseKey: string;
|
|
90
|
+
/** Resolved notes key (`resolveNotesKey` output), named by both tabs' notes hints. */
|
|
91
|
+
notesKey: string;
|
|
90
92
|
}
|
|
91
93
|
|
|
92
94
|
/**
|
|
@@ -116,6 +118,7 @@ export class DialogView implements StatefulView<DialogProps> {
|
|
|
116
118
|
isMulti: config.isMulti,
|
|
117
119
|
getCurrentBodyHeight: config.getCurrentBodyHeight,
|
|
118
120
|
collapseKey: config.collapseKey,
|
|
121
|
+
notesKey: config.notesKey,
|
|
119
122
|
});
|
|
120
123
|
this.submitStrategy = config.isMulti
|
|
121
124
|
? new SubmitTabStrategy({
|
|
@@ -123,6 +126,7 @@ export class DialogView implements StatefulView<DialogProps> {
|
|
|
123
126
|
questions: config.questions,
|
|
124
127
|
submitPicker: config.submitPicker,
|
|
125
128
|
notesInput: config.notesInput,
|
|
129
|
+
notesKey: config.notesKey,
|
|
126
130
|
})
|
|
127
131
|
: undefined;
|
|
128
132
|
this.maxFooterRowCount = Math.max(this.questionStrategy.footerRowCount, this.submitStrategy?.footerRowCount ?? 0);
|
package/view/dialog-copy.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_COLLAPSE_KEY,
|
|
3
|
+
DEFAULT_NOTES_KEY,
|
|
4
|
+
formatKeySpecForDisplay,
|
|
5
|
+
formatNotesKeyForDisplay,
|
|
6
|
+
} from "../config.ts";
|
|
2
7
|
|
|
3
8
|
/** Leaf: imports nothing from `view/`, so `dialog-builder` and `tab-content-strategy` never form a runtime cycle (#208). */
|
|
4
9
|
|
|
@@ -7,7 +12,6 @@ export const HINT_PART_NAV = "↑/↓ to navigate";
|
|
|
7
12
|
export const HINT_PART_NEW_LINE = "Shift+Enter for newline";
|
|
8
13
|
export const HINT_PART_CLEAR = "Ctrl+U to clear";
|
|
9
14
|
export const HINT_PART_TOGGLE = "Space to toggle";
|
|
10
|
-
export const HINT_PART_NOTES = "n to add notes";
|
|
11
15
|
export const HINT_PART_TAB = "Tab to switch questions";
|
|
12
16
|
export const HINT_PART_CANCEL = "Esc to cancel";
|
|
13
17
|
/**
|
|
@@ -20,6 +24,13 @@ export const HINT_PART_CANCEL = "Esc to cancel";
|
|
|
20
24
|
export const KEY_PLACEHOLDER = "{key}";
|
|
21
25
|
export const HINT_PART_COLLAPSE_TEMPLATE = `${KEY_PLACEHOLDER} to collapse`;
|
|
22
26
|
export const HINT_PART_EXPAND_TEMPLATE = `${KEY_PLACEHOLDER} to expand`;
|
|
27
|
+
/** Notes hint, templated the same way on the configurable `notesKey`. */
|
|
28
|
+
export const HINT_PART_NOTES_TEMPLATE = `${KEY_PLACEHOLDER} to add notes`;
|
|
29
|
+
/** Default-key (`n`) rendering of the notes template. */
|
|
30
|
+
export const HINT_PART_NOTES = HINT_PART_NOTES_TEMPLATE.replace(
|
|
31
|
+
KEY_PLACEHOLDER,
|
|
32
|
+
formatNotesKeyForDisplay(DEFAULT_NOTES_KEY),
|
|
33
|
+
);
|
|
23
34
|
/** Default-key (`Ctrl+]`) rendering of the collapse template, for tests and default-config assertions. */
|
|
24
35
|
export const HINT_PART_COLLAPSE = HINT_PART_COLLAPSE_TEMPLATE.replace(
|
|
25
36
|
KEY_PLACEHOLDER,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Theme } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
import { type Component, Container, type Editor, Spacer, Text, truncateToWidth } from "@earendil-works/pi-tui";
|
|
3
|
-
import { COLLAPSE_KEY_OFF, formatKeySpecForDisplay } from "../config.ts";
|
|
3
|
+
import { COLLAPSE_KEY_OFF, formatKeySpecForDisplay, formatNotesKeyForDisplay } from "../config.ts";
|
|
4
4
|
import { t } from "../state/i18n-bridge.ts";
|
|
5
5
|
import { selectSavedNote } from "../state/selectors/derivations.ts";
|
|
6
6
|
import { formatAnswerScalar } from "../tool/format-answer.ts";
|
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
HINT_PART_ENTER,
|
|
15
15
|
HINT_PART_NAV,
|
|
16
16
|
HINT_PART_NEW_LINE,
|
|
17
|
-
|
|
17
|
+
HINT_PART_NOTES_TEMPLATE,
|
|
18
18
|
HINT_PART_TAB,
|
|
19
19
|
HINT_PART_TOGGLE,
|
|
20
20
|
INCOMPLETE_WARNING_PREFIX,
|
|
@@ -27,7 +27,7 @@ import type { TabComponents } from "./tab-components.ts";
|
|
|
27
27
|
|
|
28
28
|
const NOTES_HEADER = "Notes:";
|
|
29
29
|
const GLOBAL_NOTES_HEADER = "Global note:";
|
|
30
|
-
const
|
|
30
|
+
const REVIEW_GLOBAL_HINT_TEMPLATE = `${KEY_PLACEHOLDER} to add a note`;
|
|
31
31
|
const REVIEW_NOTE_LABEL = "Note";
|
|
32
32
|
/** Label for a question's saved note — the question tab's resting row and the review entry (#197). */
|
|
33
33
|
const SAVED_NOTE_LABEL = "Note for this answer:";
|
|
@@ -96,6 +96,8 @@ export interface QuestionTabStrategyConfig {
|
|
|
96
96
|
getCurrentBodyHeight: (width: number) => number;
|
|
97
97
|
/** Resolved collapse key spec (`"ctrl+]"`, `"alt+o"`, or `"off"`). Drives the footer's collapse hint. */
|
|
98
98
|
collapseKey: string;
|
|
99
|
+
/** Resolved notes key (`resolveNotesKey` output). Named by the footer's notes hint. */
|
|
100
|
+
notesKey: string;
|
|
99
101
|
}
|
|
100
102
|
|
|
101
103
|
export class QuestionTabStrategy implements TabContentStrategy {
|
|
@@ -158,7 +160,10 @@ export class QuestionTabStrategy implements TabContentStrategy {
|
|
|
158
160
|
return [
|
|
159
161
|
new Spacer(1),
|
|
160
162
|
new OneLineClippedText(
|
|
161
|
-
this.config.theme.fg(
|
|
163
|
+
this.config.theme.fg(
|
|
164
|
+
"dim",
|
|
165
|
+
buildHintText(question, this.config.isMulti, state, this.config.collapseKey, this.config.notesKey),
|
|
166
|
+
),
|
|
162
167
|
1,
|
|
163
168
|
),
|
|
164
169
|
];
|
|
@@ -178,6 +183,8 @@ export interface SubmitTabStrategyConfig {
|
|
|
178
183
|
submitPicker: Component | undefined;
|
|
179
184
|
/** Shared notes Editor — mounted into midRows while the global-note editor is open on this tab. */
|
|
180
185
|
notesInput: Editor;
|
|
186
|
+
/** Resolved notes key (`resolveNotesKey` output). Named by the global-note hint. */
|
|
187
|
+
notesKey: string;
|
|
181
188
|
}
|
|
182
189
|
|
|
183
190
|
export class SubmitTabStrategy implements TabContentStrategy {
|
|
@@ -277,7 +284,9 @@ export class SubmitTabStrategy implements TabContentStrategy {
|
|
|
277
284
|
// with no hint wedged between them. Always present so footerRowCount stays
|
|
278
285
|
// exactly 5. OneLineClippedText (not pi-tui Text) — a wrapped hint would inflate
|
|
279
286
|
// the footer past footerRowCount and desync the chrome's cross-tab height math.
|
|
280
|
-
out.push(
|
|
287
|
+
out.push(
|
|
288
|
+
new OneLineClippedText(this.config.theme.fg("dim", buildSubmitHintText(state, this.config.notesKey)), 1),
|
|
289
|
+
);
|
|
281
290
|
return out;
|
|
282
291
|
}
|
|
283
292
|
|
|
@@ -306,10 +315,12 @@ export function buildHintText(
|
|
|
306
315
|
isMulti: boolean,
|
|
307
316
|
state: DialogState,
|
|
308
317
|
collapseKey: string,
|
|
318
|
+
notesKey: string,
|
|
309
319
|
): string {
|
|
310
320
|
const parts: string[] = [t("hint.enter", HINT_PART_ENTER), t("hint.navigate", HINT_PART_NAV)];
|
|
311
321
|
if (question?.multiSelect === true) parts.push(t("hint.toggle", HINT_PART_TOGGLE));
|
|
312
|
-
if (question && !state.notesVisible && !state.inputMode)
|
|
322
|
+
if (question && !state.notesVisible && !state.inputMode)
|
|
323
|
+
parts.push(notesHint("hint.notes", HINT_PART_NOTES_TEMPLATE, notesKey));
|
|
313
324
|
if (isMulti) parts.push(t("hint.tab", HINT_PART_TAB));
|
|
314
325
|
parts.push(t("hint.cancel", HINT_PART_CANCEL));
|
|
315
326
|
if (collapseKey !== COLLAPSE_KEY_OFF) {
|
|
@@ -328,10 +339,15 @@ export function buildHintText(
|
|
|
328
339
|
* open the note part drops (the editor is the affordance then) and the Shift+Enter
|
|
329
340
|
* newline hint is appended after cancel, mirroring the question tabs' notes-open shape.
|
|
330
341
|
*/
|
|
331
|
-
export function buildSubmitHintText(state: DialogState): string {
|
|
342
|
+
export function buildSubmitHintText(state: DialogState, notesKey: string): string {
|
|
332
343
|
const parts: string[] = [t("hint.enter", HINT_PART_ENTER), t("hint.navigate", HINT_PART_NAV)];
|
|
333
|
-
if (!state.notesVisible) parts.push(
|
|
344
|
+
if (!state.notesVisible) parts.push(notesHint("review.global_hint", REVIEW_GLOBAL_HINT_TEMPLATE, notesKey));
|
|
334
345
|
parts.push(t("hint.cancel", HINT_PART_CANCEL));
|
|
335
346
|
if (state.notesVisible) parts.push(t("hint.newline", HINT_PART_NEW_LINE));
|
|
336
347
|
return parts.join(" · ");
|
|
337
348
|
}
|
|
349
|
+
|
|
350
|
+
/** A notes hint with the configured key in place of `{key}`. */
|
|
351
|
+
function notesHint(key: string, template: string, notesKey: string): string {
|
|
352
|
+
return t(key, template).replace(KEY_PLACEHOLDER, formatNotesKeyForDisplay(notesKey));
|
|
353
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import type { Theme } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { type Component, truncateToWidth, visibleWidth, wrapTextWithAnsi } from "@earendil-works/pi-tui";
|
|
3
|
+
import { t } from "../state/i18n-bridge.ts";
|
|
4
|
+
import { NO_INPUT_PLACEHOLDER } from "../tool/format-answer.ts";
|
|
5
|
+
import {
|
|
6
|
+
isQuestionnaireResult,
|
|
7
|
+
type QuestionAnswer,
|
|
8
|
+
type QuestionnaireResult,
|
|
9
|
+
type QuestionParams,
|
|
10
|
+
} from "../tool/types.ts";
|
|
11
|
+
import { stripFenceMarkers } from "./components/preview/preview-box-renderer.ts";
|
|
12
|
+
|
|
13
|
+
const INDENT = " ";
|
|
14
|
+
const COLUMN_GAP = " ";
|
|
15
|
+
const RECOMMENDED_SUFFIX = /\s*\(Recommended\)$/;
|
|
16
|
+
|
|
17
|
+
type ToolResultView = { content: ReadonlyArray<{ type: string; text?: string }>; details?: unknown };
|
|
18
|
+
|
|
19
|
+
/** Lines laid out at render time, so wrapping and truncation follow the terminal width. */
|
|
20
|
+
class WidthLines implements Component {
|
|
21
|
+
constructor(private readonly layout: (width: number) => string[]) {}
|
|
22
|
+
render(width: number): string[] {
|
|
23
|
+
return this.layout(width);
|
|
24
|
+
}
|
|
25
|
+
invalidate(): void {}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** `Ask Format · Migration`: the headers name the questions. */
|
|
29
|
+
export function renderAskCall(args: QuestionParams | undefined, theme: Theme): Component {
|
|
30
|
+
const headers = (args?.questions ?? []).map((q) => q?.header).filter(Boolean);
|
|
31
|
+
const title = theme.fg("toolTitle", theme.bold("Ask"));
|
|
32
|
+
const text = headers.length > 0 ? `${title} ${theme.fg("accent", headers.join(" · "))}` : title;
|
|
33
|
+
return new WidthLines((width) => [truncateToWidth(text, width, "…")]);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The transcript receipt: one `✓ answer` line for a single question, an aligned
|
|
38
|
+
* header/answer table for several. A failure shows `✗` with the first line of the
|
|
39
|
+
* model-facing message; a declined questionnaire shows a dimmed `✗ no answer`.
|
|
40
|
+
*/
|
|
41
|
+
export function renderAskResult(
|
|
42
|
+
result: ToolResultView,
|
|
43
|
+
args: QuestionParams | undefined,
|
|
44
|
+
theme: Theme,
|
|
45
|
+
options: { expanded: boolean; isError: boolean },
|
|
46
|
+
): Component {
|
|
47
|
+
const details = isQuestionnaireResult(result.details) ? result.details : undefined;
|
|
48
|
+
if (options.isError || details?.error) {
|
|
49
|
+
return new WidthLines(() => [theme.fg("error", `✗ ${firstTextLine(result)}`)]);
|
|
50
|
+
}
|
|
51
|
+
if (!details) return new WidthLines(() => [theme.fg("success", "✓")]);
|
|
52
|
+
if (details.cancelled) {
|
|
53
|
+
return new WidthLines(() => [theme.fg("dim", `✗ ${t("transcript.no_answer", "no answer")}`)]);
|
|
54
|
+
}
|
|
55
|
+
const questions = args?.questions ?? [];
|
|
56
|
+
return new WidthLines((width) =>
|
|
57
|
+
questions.length > 1
|
|
58
|
+
? tableLines(details, args as QuestionParams, theme, options.expanded, width)
|
|
59
|
+
: singleLines(details, questions[0]?.question, theme, options.expanded, width),
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function singleLines(
|
|
64
|
+
details: QuestionnaireResult,
|
|
65
|
+
questionText: string | undefined,
|
|
66
|
+
theme: Theme,
|
|
67
|
+
expanded: boolean,
|
|
68
|
+
width: number,
|
|
69
|
+
): string[] {
|
|
70
|
+
const answer = details.answers[0];
|
|
71
|
+
const lines = hanging(`${theme.fg("success", "✓")} `, answerText(answer, theme), width);
|
|
72
|
+
lines.push(...detailLines(answer, expanded ? questionText : undefined, INDENT, theme, width));
|
|
73
|
+
return [...lines, ...globalNoteLines(details, theme, width)];
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function tableLines(
|
|
77
|
+
details: QuestionnaireResult,
|
|
78
|
+
args: QuestionParams,
|
|
79
|
+
theme: Theme,
|
|
80
|
+
expanded: boolean,
|
|
81
|
+
width: number,
|
|
82
|
+
): string[] {
|
|
83
|
+
const headerWidth = Math.max(...args.questions.map((q) => visibleWidth(q.header)));
|
|
84
|
+
const answerIndent = " ".repeat(INDENT.length + headerWidth + COLUMN_GAP.length);
|
|
85
|
+
const lines = args.questions.flatMap((q, i) => {
|
|
86
|
+
const answer = details.answers.find((a) => a.questionIndex === i);
|
|
87
|
+
const header = q.header + " ".repeat(headerWidth - visibleWidth(q.header));
|
|
88
|
+
const row = hanging(`${INDENT}${theme.fg("muted", header)}${COLUMN_GAP}`, answerText(answer, theme), width);
|
|
89
|
+
return [...row, ...detailLines(answer, expanded ? q.question : undefined, answerIndent, theme, width)];
|
|
90
|
+
});
|
|
91
|
+
return [...lines, ...globalNoteLines(details, theme, width)];
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Under an answer: the question text and chosen preview when expanded, then the answer's note. */
|
|
95
|
+
function detailLines(
|
|
96
|
+
answer: QuestionAnswer | undefined,
|
|
97
|
+
questionText: string | undefined,
|
|
98
|
+
indent: string,
|
|
99
|
+
theme: Theme,
|
|
100
|
+
width: number,
|
|
101
|
+
): string[] {
|
|
102
|
+
const lines: string[] = [];
|
|
103
|
+
if (questionText) lines.push(...hanging(indent, theme.fg("dim", questionText), width));
|
|
104
|
+
if (questionText && answer?.preview) {
|
|
105
|
+
for (const line of stripFenceMarkers(answer.preview.split("\n"))) {
|
|
106
|
+
lines.push(truncateToWidth(`${indent}${theme.fg("dim", `│ ${line}`)}`, width, "…"));
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
if (answer?.notes) lines.push(...hanging(indent, theme.fg("dim", `✎ ${answer.notes}`), width));
|
|
110
|
+
return lines;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function globalNoteLines(details: QuestionnaireResult, theme: Theme, width: number): string[] {
|
|
114
|
+
return details.globalNote ? hanging(INDENT, theme.fg("dim", `✎ ${details.globalNote}`), width) : [];
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function answerText(answer: QuestionAnswer | undefined, theme: Theme): string {
|
|
118
|
+
if (!answer) return theme.fg("dim", t("transcript.not_answered", "not answered"));
|
|
119
|
+
const typed = answer.answer ? `"${answer.answer}"` : undefined;
|
|
120
|
+
const picks =
|
|
121
|
+
answer.kind === "option"
|
|
122
|
+
? [label(answer.answer ?? "")]
|
|
123
|
+
: answer.kind === "custom"
|
|
124
|
+
? [typed]
|
|
125
|
+
: [...(answer.selected ?? []).map(label), typed];
|
|
126
|
+
return theme.fg("toolOutput", picks.filter(Boolean).join(", ") || NO_INPUT_PLACEHOLDER);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function label(text: string): string {
|
|
130
|
+
return text.replace(RECOMMENDED_SUFFIX, "");
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** `prefix` then `text` wrapped to the width left after it; continuation lines align under the text. */
|
|
134
|
+
function hanging(prefix: string, text: string, width: number): string[] {
|
|
135
|
+
const indent = visibleWidth(prefix);
|
|
136
|
+
return wrapTextWithAnsi(text, Math.max(1, width - indent)).map(
|
|
137
|
+
(line, i) => (i === 0 ? prefix : " ".repeat(indent)) + line,
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function firstTextLine(result: ToolResultView): string {
|
|
142
|
+
const text = result.content.find((c) => c.type === "text")?.text ?? "";
|
|
143
|
+
return text.split("\n")[0] ?? "";
|
|
144
|
+
}
|