@juicesharp/rpiv-ask-user-question 2.13.6 → 2.13.8

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/docs/keyboard.md CHANGED
@@ -63,7 +63,10 @@ against the canonical English strings.
63
63
  multi-select and whether or not its options carry previews. Notes are stored in a
64
64
  side-band keyed by tab index, not inside the answer, so writing a note does not mark a
65
65
  question as answered — the Submit tab still lists it as outstanding. The note merges into
66
- the answer when you confirm it, and reaches the model as `user notes: <text>`.
66
+ the answer when you confirm it, and reaches the model as `user notes: <text>`. Once the
67
+ editor closes, the question shows the saved note as `Note for this answer: …` (its first
68
+ line), and a preview pane's hint changes to "Note saved: press n to edit"; the Submit tab's
69
+ review uses the same label.
67
70
 
68
71
  On the Submit tab, `n` opens the global note editor instead — one note covering the whole
69
72
  questionnaire. It lives outside every answer, so it survives tab switches and never marks
package/locales/de.json CHANGED
@@ -22,7 +22,9 @@
22
22
 
23
23
  "preview.no_preview": "Keine Vorschau verfügbar",
24
24
  "preview.notes_affordance": "Notizen: drücke n, um Notizen hinzuzufügen",
25
+ "preview.notes_edit_affordance": "Notiz gespeichert: drücke n zum Bearbeiten",
25
26
  "notes.header": "Notizen:",
27
+ "notes.saved_label": "Notiz zu dieser Antwort:",
26
28
 
27
29
  "editor.failed": "Externer Editor fehlgeschlagen",
28
30
 
package/locales/en.json CHANGED
@@ -24,7 +24,9 @@
24
24
 
25
25
  "preview.no_preview": "No preview available",
26
26
  "preview.notes_affordance": "Notes: press n to add notes",
27
+ "preview.notes_edit_affordance": "Note saved: press n to edit",
27
28
  "notes.header": "Notes:",
29
+ "notes.saved_label": "Note for this answer:",
28
30
  "notes.global_header": "Global note:",
29
31
 
30
32
  "editor.failed": "External editor failed",
package/locales/es.json CHANGED
@@ -22,7 +22,9 @@
22
22
 
23
23
  "preview.no_preview": "Vista previa no disponible",
24
24
  "preview.notes_affordance": "Notas: pulsa n para añadir notas",
25
+ "preview.notes_edit_affordance": "Nota guardada: pulsa n para editarla",
25
26
  "notes.header": "Notas:",
27
+ "notes.saved_label": "Nota para esta respuesta:",
26
28
 
27
29
  "editor.failed": "Error del editor externo",
28
30
 
package/locales/fr.json CHANGED
@@ -22,7 +22,9 @@
22
22
 
23
23
  "preview.no_preview": "Aucun aperçu disponible",
24
24
  "preview.notes_affordance": "Notes : appuyez sur n pour ajouter des notes",
25
+ "preview.notes_edit_affordance": "Note enregistrée : appuyez sur n pour la modifier",
25
26
  "notes.header": "Notes :",
27
+ "notes.saved_label": "Note pour cette réponse :",
26
28
 
27
29
  "editor.failed": "Échec de l’éditeur externe",
28
30
 
@@ -22,7 +22,9 @@
22
22
 
23
23
  "preview.no_preview": "Pré-visualização indisponível",
24
24
  "preview.notes_affordance": "Notas: pressione n para adicionar notas",
25
+ "preview.notes_edit_affordance": "Nota salva: pressione n para editar",
25
26
  "notes.header": "Notas:",
27
+ "notes.saved_label": "Nota para esta resposta:",
26
28
 
27
29
  "editor.failed": "Falha no editor externo",
28
30
 
package/locales/pt.json CHANGED
@@ -22,7 +22,9 @@
22
22
 
23
23
  "preview.no_preview": "Pré-visualização indisponível",
24
24
  "preview.notes_affordance": "Notas: prima n para adicionar notas",
25
+ "preview.notes_edit_affordance": "Nota guardada: prima n para editar",
25
26
  "notes.header": "Notas:",
27
+ "notes.saved_label": "Nota para esta resposta:",
26
28
 
27
29
  "editor.failed": "Falha no editor externo",
28
30
 
package/locales/ru.json CHANGED
@@ -22,7 +22,9 @@
22
22
 
23
23
  "preview.no_preview": "Предпросмотр недоступен",
24
24
  "preview.notes_affordance": "Заметки: нажмите n, чтобы добавить заметки",
25
+ "preview.notes_edit_affordance": "Заметка сохранена: нажмите n, чтобы изменить",
25
26
  "notes.header": "Заметки:",
27
+ "notes.saved_label": "Заметка к этому ответу:",
26
28
 
27
29
  "editor.failed": "Ошибка внешнего редактора",
28
30
 
package/locales/uk.json CHANGED
@@ -22,7 +22,9 @@
22
22
 
23
23
  "preview.no_preview": "Попередній перегляд недоступний",
24
24
  "preview.notes_affordance": "Нотатки: натисніть n, щоб додати нотатки",
25
+ "preview.notes_edit_affordance": "Нотатку збережено: натисніть n, щоб змінити",
25
26
  "notes.header": "Нотатки:",
27
+ "notes.saved_label": "Нотатка до цієї відповіді:",
26
28
 
27
29
  "editor.failed": "Помилка зовнішнього редактора",
28
30
 
package/locales/zh.json CHANGED
@@ -24,7 +24,9 @@
24
24
 
25
25
  "preview.no_preview": "暂无预览",
26
26
  "preview.notes_affordance": "备注:按 n 添加",
27
+ "preview.notes_edit_affordance": "备注已保存:按 n 编辑",
27
28
  "notes.header": "备注:",
29
+ "notes.saved_label": "此回答的备注:",
28
30
 
29
31
  "editor.failed": "外部编辑器启动失败",
30
32
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juicesharp/rpiv-ask-user-question",
3
- "version": "2.13.6",
3
+ "version": "2.13.8",
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",
@@ -99,6 +99,6 @@
99
99
  }
100
100
  },
101
101
  "dependencies": {
102
- "@juicesharp/rpiv-config": "^2.13.6"
102
+ "@juicesharp/rpiv-config": "^2.13.8"
103
103
  }
104
104
  }
@@ -38,3 +38,18 @@ export function selectActivePreviewPaneIndex(currentTab: number, totalQuestions:
38
38
  if (totalQuestions <= 0) return 0;
39
39
  return Math.min(currentTab, totalQuestions - 1);
40
40
  }
41
+
42
+ /**
43
+ * The committed note for a question tab, or `undefined` when it has none. Same precedence as
44
+ * the reducer's editor seeding (`notesValueFor`): the in-flight side-band (`notesByTab`) is
45
+ * authoritative — a note saved before the question is answered lives only there, and a
46
+ * present empty string means the note was cleared — with `answer.notes` as the mirror.
47
+ */
48
+ export function selectSavedNote(
49
+ notesByTab: ReadonlyMap<number, string>,
50
+ answers: ReadonlyMap<number, QuestionAnswer>,
51
+ tab: number,
52
+ ): string | undefined {
53
+ const note = notesByTab.get(tab) ?? answers.get(tab)?.notes;
54
+ return note && note.length > 0 ? note : undefined;
55
+ }
@@ -6,7 +6,7 @@ import type { TabBarProps } from "../../view/components/tab-bar.js";
6
6
  import type { DialogProps } from "../../view/dialog-builder.js";
7
7
  import { displayLabel } from "../i18n-bridge.js";
8
8
  import type { GlobalSelector, PerTabBindingContext, PerTabSelector } from "./contract.js";
9
- import { selectConfirmedIndicator } from "./derivations.js";
9
+ import { selectConfirmedIndicator, selectSavedNote } from "./derivations.js";
10
10
 
11
11
  function emptyMultiSelectProps(ctx: PerTabBindingContext): MultiSelectViewProps {
12
12
  return {
@@ -82,6 +82,7 @@ export const selectSubmitPickerProps: GlobalSelector<SubmitPickerProps> = (state
82
82
 
83
83
  export const selectPreviewPaneProps: PerTabSelector<PreviewPaneProps> = (state, ctx) => ({
84
84
  notesVisible: state.notesVisible,
85
+ hasNote: selectSavedNote(state.notesByTab, state.answers, ctx.i) !== undefined,
85
86
  selectedIndex: state.optionIndex,
86
87
  focused: ctx.activeView === "options",
87
88
  inputMode: state.inputMode,
@@ -22,6 +22,21 @@ import type { PreviewLayoutMode } from "./preview-layout-decider.js";
22
22
  * Re-exported by `preview-pane.ts` for the existing test surface.
23
23
  */
24
24
  export const NOTES_AFFORDANCE_TEXT = "Notes: press n to add notes";
25
+ /** Affordance text once the question carries a saved note (#197). */
26
+ export const NOTES_EDIT_AFFORDANCE_TEXT = "Note saved: press n to edit";
27
+
28
+ /**
29
+ * Which notes affordance the block shows under the preview: `add` / `edit` (no note yet /
30
+ * a saved note) while the pane is focused with the notes editor closed, `none` otherwise.
31
+ * Decided by the pane from its props; the row itself is kept either way (height-stable).
32
+ */
33
+ export type NotesAffordance = "add" | "edit" | "none";
34
+
35
+ function affordanceText(affordance: Exclude<NotesAffordance, "none">): string {
36
+ return affordance === "edit"
37
+ ? t("preview.notes_edit_affordance", NOTES_EDIT_AFFORDANCE_TEXT)
38
+ : t("preview.notes_affordance", NOTES_AFFORDANCE_TEXT);
39
+ }
25
40
 
26
41
  /** Content row budget for a layout mode: preview cap minus border + affordance overhead. */
27
42
  function contentBudgetFor(mode: PreviewLayoutMode): number {
@@ -93,7 +108,7 @@ export class PreviewBlockRenderer {
93
108
 
94
109
  /**
95
110
  * Height contribution of the preview block — always equal to `renderBlock(...).length`
96
- * for the same arguments (the affordance overhead is not gated by `focused`/`notesVisible`).
111
+ * for the same arguments (the affordance overhead is not gated by the `NotesAffordance`).
97
112
  * `maxRows` is the row allowance the dialog can give the block; see `fitBlock`.
98
113
  */
99
114
  blockHeight(width: number, optionIndex: number, mode: PreviewLayoutMode, maxRows?: number): number {
@@ -104,18 +119,16 @@ export class PreviewBlockRenderer {
104
119
 
105
120
  /**
106
121
  * Render the preview block at `width`: bordered box, then (when it fits) a blank separator
107
- * and the notes-affordance row. `focused` and `notesVisible` together gate the affordance
108
- * text (visible only when the focused option carries a preview AND notes mode is inactive);
109
- * its row is emitted (empty when gated) whenever the block keeps it, so the row count only
110
- * depends on the fit. Under a `maxRows` allowance the box always closes and its bottom border
122
+ * and the notes-affordance row. `affordance` picks the text (`none` blanks it), shown only when
123
+ * the option carries a preview; the row is emitted (empty when gated) whenever the block keeps
124
+ * it, so the row count only depends on the fit. Under a `maxRows` allowance the box always closes and its bottom border
111
125
  * counts the lines left out; with no room for a box the block is empty.
112
126
  */
113
127
  renderBlock(
114
128
  width: number,
115
129
  optionIndex: number,
116
130
  mode: PreviewLayoutMode,
117
- focused: boolean,
118
- notesVisible: boolean,
131
+ affordance: NotesAffordance,
119
132
  maxRows?: number,
120
133
  ): string[] {
121
134
  const maxInnerWidth = innerWidthFor(width);
@@ -130,10 +143,7 @@ export class PreviewBlockRenderer {
130
143
  const boxedLines = renderBorderedBox(contentLines, boxWidth, colorFn, hidden);
131
144
  if (!fit.affordance) return boxedLines;
132
145
 
133
- const showAffordance = focused && !notesVisible && this.cache.has(optionIndex);
134
- const affordance = showAffordance
135
- ? this.theme.fg("muted", t("preview.notes_affordance", NOTES_AFFORDANCE_TEXT))
136
- : "";
137
- return [...boxedLines, "", affordance];
146
+ const text = affordance !== "none" && this.cache.has(optionIndex) ? affordanceText(affordance) : "";
147
+ return [...boxedLines, "", text ? this.theme.fg("muted", text) : ""];
138
148
  }
139
149
  }
@@ -4,7 +4,7 @@ import type { QuestionData } from "../../../tool/types.js";
4
4
  import { windowLines } from "../../scroll-window.js";
5
5
  import type { StatefulView } from "../../stateful-view.js";
6
6
  import type { OptionListView } from "../option-list-view.js";
7
- import type { PreviewBlockRenderer } from "./preview-block-renderer.js";
7
+ import type { NotesAffordance, PreviewBlockRenderer } from "./preview-block-renderer.js";
8
8
  import {
9
9
  bodyWidths,
10
10
  columnWidths,
@@ -24,7 +24,7 @@ export {
24
24
  NO_PREVIEW_TEXT,
25
25
  NOTES_AFFORDANCE_OVERHEAD,
26
26
  } from "./markdown-content-cache.js";
27
- export { NOTES_AFFORDANCE_TEXT, PreviewBlockRenderer } from "./preview-block-renderer.js";
27
+ export { NOTES_AFFORDANCE_TEXT, NOTES_EDIT_AFFORDANCE_TEXT, PreviewBlockRenderer } from "./preview-block-renderer.js";
28
28
  export {
29
29
  BORDER_HORIZONTAL_OVERHEAD,
30
30
  BORDER_INNER_PADDING_HORIZONTAL,
@@ -51,6 +51,8 @@ export {
51
51
  */
52
52
  export interface PreviewPaneProps {
53
53
  notesVisible: boolean;
54
+ /** The question carries a saved note — the affordance offers to edit it rather than add one (#197). */
55
+ hasNote: boolean;
54
56
  selectedIndex: number;
55
57
  focused: boolean;
56
58
  /**
@@ -111,7 +113,7 @@ export class PreviewPane implements StatefulView<PreviewPaneProps>, Component {
111
113
  this.optionListView = config.optionListView;
112
114
  this.previewBlock = config.previewBlock;
113
115
  this.theme = config.theme;
114
- this.props = { notesVisible: false, selectedIndex: 0, focused: false, inputMode: false };
116
+ this.props = { notesVisible: false, hasNote: false, selectedIndex: 0, focused: false, inputMode: false };
115
117
  }
116
118
 
117
119
  setGlobalLeftWidth(getter: (paneWidth: number) => number): void {
@@ -127,6 +129,13 @@ export class PreviewPane implements StatefulView<PreviewPaneProps>, Component {
127
129
  }
128
130
 
129
131
  /** Render-time geometry from `DialogView` (not canonical state, so not a prop). */
132
+ /** The notes affordance under the preview: shown while focused with the notes editor closed. */
133
+ private notesAffordance(): NotesAffordance {
134
+ const { focused, notesVisible, hasNote } = this.props;
135
+ if (!focused || notesVisible) return "none";
136
+ return hasNote ? "edit" : "add";
137
+ }
138
+
130
139
  setRowAllowance(rows: number | undefined): void {
131
140
  this.rowAllowance = rows;
132
141
  }
@@ -171,7 +180,8 @@ export class PreviewPane implements StatefulView<PreviewPaneProps>, Component {
171
180
  width: number,
172
181
  mode: PreviewLayoutMode,
173
182
  ): { lines: string[]; focus: [number, number] | undefined } {
174
- const { selectedIndex, focused, notesVisible } = this.props;
183
+ const { selectedIndex } = this.props;
184
+ const affordance = this.notesAffordance();
175
185
  const options = this.optionListView.render(width);
176
186
  const focus = this.optionListView.focusedItemRowRange(width);
177
187
  const gap = Array<string>(STACKED_GAP_ROWS).fill("");
@@ -179,11 +189,7 @@ export class PreviewPane implements StatefulView<PreviewPaneProps>, Component {
179
189
  const fullBlock = this.previewBlock.blockHeight(width, selectedIndex, mode);
180
190
  if (allowance === undefined || options.length + STACKED_GAP_ROWS + fullBlock <= allowance) {
181
191
  return {
182
- lines: [
183
- ...options,
184
- ...gap,
185
- ...this.previewBlock.renderBlock(width, selectedIndex, mode, focused, notesVisible),
186
- ],
192
+ lines: [...options, ...gap, ...this.previewBlock.renderBlock(width, selectedIndex, mode, affordance)],
187
193
  focus,
188
194
  };
189
195
  }
@@ -194,7 +200,7 @@ export class PreviewPane implements StatefulView<PreviewPaneProps>, Component {
194
200
  Math.min(fullBlock, allowance - STACKED_GAP_ROWS - Math.min(options.length, optionsFloor));
195
201
  const roomy = previewRowsWith(focusRows + 2);
196
202
  const previewRows = roomy >= MIN_BOX_ROWS ? roomy : previewRowsWith(focusRows);
197
- const block = this.previewBlock.renderBlock(width, selectedIndex, mode, focused, notesVisible, previewRows);
203
+ const block = this.previewBlock.renderBlock(width, selectedIndex, mode, affordance, previewRows);
198
204
  const optionRows = allowance - (block.length > 0 ? STACKED_GAP_ROWS + block.length : 0);
199
205
  const windowed = windowLines(options, Math.max(1, optionRows), focus, this.theme);
200
206
  return {
@@ -296,8 +302,7 @@ export class PreviewPane implements StatefulView<PreviewPaneProps>, Component {
296
302
  inner,
297
303
  this.props.selectedIndex,
298
304
  mode,
299
- this.props.focused,
300
- this.props.notesVisible,
305
+ this.notesAffordance(),
301
306
  maxRows,
302
307
  );
303
308
  const boxWidth = Math.max(1, visibleWidth(contentLines[0] ?? ""));
@@ -159,12 +159,17 @@ export class DialogView implements StatefulView<DialogProps> {
159
159
  const natural = this.buildContainerFromStrategy(strategy, headingRowCache).render(width);
160
160
 
161
161
  // Residual spacer: equalizes total height across tabs (only needed when no overflow).
162
+ // Resting mid rows (a question's saved-note row, #197) come out of the spacer's slack,
163
+ // so a tab with a note keeps the shared height when the body leaves room. The open
164
+ // notes editor deliberately grows the dialog instead, so it is not absorbed.
165
+ const restingMidRows = state.notesVisible ? 0 : this.rowsAroundBody(strategy, width) - 1;
162
166
  const spacerRows = Math.max(
163
167
  0,
164
168
  this.config.getBodyHeight(width) +
165
169
  this.maxFooterRowCount -
166
170
  strategy.bodyHeight(width, state) -
167
- strategy.footerRowCount,
171
+ strategy.footerRowCount -
172
+ restingMidRows,
168
173
  );
169
174
 
170
175
  // The spacer is padding for a stable cross-tab footprint, not content: when only the
@@ -2,6 +2,7 @@ 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
3
  import { COLLAPSE_KEY_OFF, formatKeySpecForDisplay } from "../config.js";
4
4
  import { t } from "../state/i18n-bridge.js";
5
+ import { selectSavedNote } from "../state/selectors/derivations.js";
5
6
  import { formatAnswerScalar } from "../tool/format-answer.js";
6
7
  import type { QuestionData } from "../tool/types.js";
7
8
  import type { PreviewPane, PreviewPaneProps } from "./components/preview/preview-pane.js";
@@ -28,6 +29,8 @@ const NOTES_HEADER = "Notes:";
28
29
  const GLOBAL_NOTES_HEADER = "Global note:";
29
30
  const REVIEW_GLOBAL_HINT = "n to add a note";
30
31
  const REVIEW_NOTE_LABEL = "Note";
32
+ /** Label for a question's saved note — the question tab's resting row and the review entry (#197). */
33
+ const SAVED_NOTE_LABEL = "Note for this answer:";
31
34
 
32
35
  /**
33
36
  * Single-row, width-clipped chrome cell. The footer row count is invariant
@@ -128,12 +131,22 @@ export class QuestionTabStrategy implements TabContentStrategy {
128
131
  }
129
132
 
130
133
  midRows(state: DialogState): Component[] {
131
- if (!state.notesVisible) return [];
132
- return [
133
- new Text(this.config.theme.fg("muted", t("notes.header", NOTES_HEADER)), 1, 0),
134
- this.config.notesInput,
135
- new Spacer(1),
136
- ];
134
+ if (state.notesVisible) {
135
+ return [
136
+ new Text(this.config.theme.fg("muted", t("notes.header", NOTES_HEADER)), 1, 0),
137
+ this.config.notesInput,
138
+ new Spacer(1),
139
+ ];
140
+ }
141
+ // A saved note stays visible once its editor closes (#197): one clipped row, so a long
142
+ // or multi-line note cannot crowd the options — `n` reopens it in full. Mid rows are
143
+ // subtracted from the body allowance (`DialogView.rowsAroundBody`), so the row is
144
+ // height-safe.
145
+ const note = selectSavedNote(state.notesByTab, state.answers, state.currentTab);
146
+ if (note === undefined) return [];
147
+ const [firstLine = "", ...rest] = note.split("\n");
148
+ const text = `${t("notes.saved_label", SAVED_NOTE_LABEL)} ${firstLine}${rest.length > 0 ? " …" : ""}`;
149
+ return [new OneLineClippedText(this.config.theme.fg("dim", text), 1)];
137
150
  }
138
151
 
139
152
  footerRows(state: DialogState): Component[] {
@@ -193,7 +206,13 @@ export class SubmitTabStrategy implements TabContentStrategy {
193
206
  new Text(` ${this.config.theme.fg("muted", "→")} ${this.config.theme.fg("text", answerText)}`, 1, 0),
194
207
  );
195
208
  if (a.notes && a.notes.length > 0) {
196
- c.addChild(new Text(this.config.theme.fg("dim", ` notes: ${a.notes}`), 1, 0));
209
+ c.addChild(
210
+ new Text(
211
+ this.config.theme.fg("dim", ` ${t("notes.saved_label", SAVED_NOTE_LABEL)} ${a.notes}`),
212
+ 1,
213
+ 0,
214
+ ),
215
+ );
197
216
  }
198
217
  }
199
218
  // Committed global note (#182) as a review entry — pressing `n` gets visible