@juicesharp/rpiv-ask-user-question 2.6.2 → 2.6.4

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.
@@ -1,6 +1,12 @@
1
1
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
2
2
  import { isKeyRelease, isKeyRepeat, matchesKey } from "@earendil-works/pi-tui";
3
- import { loadConfig, resolveCollapseKey, validateGuidanceFields } from "./config.js";
3
+ import {
4
+ COLLAPSE_KEY_OFF,
5
+ formatKeySpecForDisplay,
6
+ loadConfig,
7
+ resolveCollapseKey,
8
+ validateGuidanceFields,
9
+ } from "./config.js";
4
10
  import {
5
11
  ASK_USER_BLOCKED_EVENT,
6
12
  ASK_USER_PROMPT_EVENT,
@@ -228,7 +234,7 @@ export function registerAskUserQuestionTool(pi: ExtensionAPI): void {
228
234
  let hasAnnouncedHide = false;
229
235
  let removeOverlayInputListener: (() => void) | undefined;
230
236
 
231
- if (collapseKey !== "off" && typeof ctx.ui.onTerminalInput === "function") {
237
+ if (collapseKey !== COLLAPSE_KEY_OFF && typeof ctx.ui.onTerminalInput === "function") {
232
238
  removeOverlayInputListener = ctx.ui.onTerminalInput((data) => {
233
239
  const handle = overlayHandleRef.current;
234
240
  if (!handle) return undefined;
@@ -245,11 +251,18 @@ export function registerAskUserQuestionTool(pi: ExtensionAPI): void {
245
251
  sessionRef.current?.toggleCollapsedExternal();
246
252
  if (handle.isHidden() && !hasAnnouncedHide) {
247
253
  hasAnnouncedHide = true;
248
- ctx.ui.notify?.(`ask_user_question hidden — press ${collapseKey} to reopen`, "info");
254
+ ctx.ui.notify?.(
255
+ `ask_user_question hidden — press ${formatKeySpecForDisplay(collapseKey)} to reopen`,
256
+ "info",
257
+ );
249
258
  }
250
259
  return { consume: true };
251
260
  });
252
261
  }
262
+ // Hiding the overlay is only reversible through the raw listener above, so
263
+ // the session may emit `setHidden` only when it was actually registered;
264
+ // otherwise collapse falls back to the visible one-line row.
265
+ const canReopenWhileHidden = removeOverlayInputListener !== undefined;
253
266
 
254
267
  emitAskUserBlockedEvent(pi, true);
255
268
  try {
@@ -281,6 +294,7 @@ export function registerAskUserQuestionTool(pi: ExtensionAPI): void {
281
294
  }
282
295
  },
283
296
  collapseKey,
297
+ canReopenWhileHidden,
284
298
  });
285
299
  sessionRef.current = session;
286
300
  return session.component;
package/config.ts CHANGED
@@ -68,6 +68,31 @@ export function resolveCollapseKey(config: Pick<AskUserQuestionConfig, "collapse
68
68
  return isValidCollapseKeySpec(raw) ? raw : DEFAULT_COLLAPSE_KEY;
69
69
  }
70
70
 
71
+ // The only compound-word names in SPECIAL_KEYS — first-letter capitalization
72
+ // alone would render them "Pageup"/"Pagedown".
73
+ const COMPOUND_KEY_DISPLAY: Record<string, string> = {
74
+ pageup: "PageUp",
75
+ pagedown: "PageDown",
76
+ };
77
+
78
+ /**
79
+ * Pretty-print a resolved key spec for UI copy: each `+`-part gets its first
80
+ * character uppercased (`"ctrl+]"` → `"Ctrl+]"`, `"alt+o"` → `"Alt+O"`,
81
+ * `"f9"` → `"F9"`, `"ctrl+pagedown"` → `"Ctrl+PageDown"`). Display-only — key
82
+ * matching always uses the raw lowercase spec (`matchesKey` lowercases ids),
83
+ * so never feed the result back into it.
84
+ */
85
+ export function formatKeySpecForDisplay(spec: CollapseKeySpec): string {
86
+ return spec
87
+ .split("+")
88
+ .map(
89
+ (part) =>
90
+ COMPOUND_KEY_DISPLAY[part] ??
91
+ (part.length <= 1 ? part.toUpperCase() : part.charAt(0).toUpperCase() + part.slice(1)),
92
+ )
93
+ .join("+");
94
+ }
95
+
71
96
  export function loadConfig(): AskUserQuestionConfig {
72
97
  return loadJsonConfigWithLegacyFallback<AskUserQuestionConfig>("rpiv-ask-user-question");
73
98
  }
@@ -85,9 +85,10 @@ strict on purpose: Pi's parser takes the last `+`-separated part as the key and
85
85
  unknown parts, so a typo like `"ctr+]"` would otherwise silently capture every bare `]`
86
86
  keypress at the terminal level.
87
87
 
88
- One known rough edge: the footer hint line inside the dialog always reads `Ctrl+] to
89
- collapse` and does not interpolate a custom `collapseKey`. The one-shot notification you
90
- get when the dialog first collapses *does* name your configured key.
88
+ The footer hint inside the dialog names whatever key you configure (`Alt+O to collapse`
89
+ for `"alt+o"`), as do the collapsed one-line footer and the one-shot notification shown
90
+ when the dialog is first hidden. With `"off"` the collapse hint is dropped from the
91
+ footer entirely, since no shortcut can fire.
91
92
 
92
93
  ### `guidance.description`, `guidance.promptSnippet` and `guidance.promptGuidelines`
93
94
 
package/docs/hosts.md CHANGED
@@ -64,7 +64,8 @@ Some parts of the dialog exist only under the right conditions:
64
64
  | `Type something.` row | Always |
65
65
  | Side-by-side preview | An option carries a `preview`, and terminal and pane are both ≥ 100 columns |
66
66
  | Preview pane at all | Single-select questions only |
67
- | Collapse shortcut | `collapseKey` is not `"off"` and the host exposes raw terminal input |
67
+ | Collapse shortcut | `collapseKey` is not `"off"` |
68
+ | Full overlay hide on collapse | The host also exposes raw terminal input (the only path that can reopen a hidden overlay); without it, collapsing shrinks the dialog to a visible one-line row instead |
68
69
  | Localized chrome | `@juicesharp/rpiv-i18n` is installed |
69
70
 
70
71
  ## Loading and startup cost
@@ -71,7 +71,9 @@ No code change is required.
71
71
  1. Copy `locales/en.json` to `locales/<code>.json`, where `<code>` is a locale the SDK
72
72
  supports.
73
73
  2. Translate the values. Keep every key, and keep the placeholders and leading symbols
74
- (`↑/↓`, `⚠`) intact.
74
+ (`↑/↓`, `⚠`) intact. `hint.collapse` and `hint.expand_line` contain a literal `{key}`
75
+ placeholder that is replaced at render time with the user's configured `collapseKey` —
76
+ keep it verbatim, positioned wherever your language's word order wants the key name.
75
77
  3. Restart Pi and select the language with `/languages`.
76
78
 
77
79
  The loader iterates the SDK's supported-locale list over this directory at startup, so a
package/locales/en.json CHANGED
@@ -12,8 +12,8 @@
12
12
  "hint.toggle": "Space to toggle",
13
13
  "hint.notes": "n to add notes",
14
14
  "hint.tab": "Tab to switch questions",
15
- "hint.collapse": "Ctrl+] to collapse",
16
- "hint.expand_line": "Ctrl+] to expand · Esc to cancel",
15
+ "hint.collapse": "{key} to collapse",
16
+ "hint.expand_line": "{key} to expand · Esc to cancel",
17
17
  "hint.cancel": "Esc to cancel",
18
18
 
19
19
  "review.heading": "Review your answers",
package/locales/zh.json CHANGED
@@ -14,8 +14,8 @@
14
14
  "hint.toggle": "空格切换",
15
15
  "hint.notes": "按 n 添加备注",
16
16
  "hint.tab": "Tab 切换问题",
17
- "hint.collapse": "Ctrl+] 折叠",
18
- "hint.expand_line": "Ctrl+] 展开 · Esc 取消",
17
+ "hint.collapse": "{key} 折叠",
18
+ "hint.expand_line": "{key} 展开 · Esc 取消",
19
19
  "hint.cancel": "Esc 取消",
20
20
 
21
21
  "review.heading": "检查你的答案",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juicesharp/rpiv-ask-user-question",
3
- "version": "2.6.2",
3
+ "version": "2.6.4",
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",
@@ -94,7 +94,7 @@
94
94
  }
95
95
  },
96
96
  "dependencies": {
97
- "@juicesharp/rpiv-config": "^2.6.2",
97
+ "@juicesharp/rpiv-config": "^2.6.4",
98
98
  "typebox": "^1.1.24"
99
99
  }
100
100
  }
@@ -40,6 +40,13 @@ export interface QuestionnaireBuildConfig {
40
40
  isMulti: boolean;
41
41
  initialState: QuestionnaireState;
42
42
  getCurrentTab: () => number;
43
+ /**
44
+ * Resolved collapse key spec (`"ctrl+]"`, `"alt+o"`, or `"off"`). Threaded to
45
+ * `DialogConfig` as construction-time config so the footer hint can name the
46
+ * real key — deliberately NOT part of `QuestionnaireState`, which stays free
47
+ * of runtime context.
48
+ */
49
+ collapseKey: string;
43
50
  }
44
51
 
45
52
  export interface QuestionnaireBuilt {
@@ -109,6 +116,7 @@ class QuestionnaireBuilder {
109
116
  private readonly isMulti: boolean;
110
117
  private readonly initialState: QuestionnaireState;
111
118
  private readonly getCurrentTab: () => number;
119
+ private readonly collapseKey: string;
112
120
 
113
121
  private readonly selectTheme: WrappingSelectTheme;
114
122
  private readonly markdownTheme = getMarkdownTheme();
@@ -125,6 +133,7 @@ class QuestionnaireBuilder {
125
133
  this.isMulti = config.isMulti;
126
134
  this.initialState = config.initialState;
127
135
  this.getCurrentTab = config.getCurrentTab;
136
+ this.collapseKey = config.collapseKey;
128
137
 
129
138
  this.selectTheme = this.makeSelectTheme();
130
139
  const textEditorTheme = editorTheme(this.theme);
@@ -258,6 +267,7 @@ class QuestionnaireBuilder {
258
267
  getBodyHeight: heights.global,
259
268
  getCurrentBodyHeight: heights.current,
260
269
  getTerminalRows: this.getTerminalRows,
270
+ collapseKey: this.collapseKey,
261
271
  },
262
272
  { state: this.initialState, activePreviewPane: this.pickInitialActivePreview(tabs) },
263
273
  );
@@ -174,7 +174,9 @@ export function routeKey(data: string, state: QuestionnaireState, runtime: Quest
174
174
  // replaces the lazily imported QuestionnaireSession graph on disk. Passing
175
175
  // undefined into matchesKey reaches parseKeyId().toLowerCase() and crashes the
176
176
  // entire host process, so keep the runtime boundary defensive even though the
177
- // TypeScript contract requires a string.
177
+ // TypeScript contract requires a string. The "off" literal is deliberate:
178
+ // importing COLLAPSE_KEY_OFF would pull ../config.js (and its rpiv-config
179
+ // loader graph) into this pure module for a string that cannot change.
178
180
  if (
179
181
  typeof runtime.collapseKey === "string" &&
180
182
  runtime.collapseKey !== "off" &&
@@ -1,8 +1,9 @@
1
1
  import type { Theme } from "@earendil-works/pi-coding-agent";
2
2
  import type { Editor, OverlayHandle, TUI } from "@earendil-works/pi-tui";
3
+ import { COLLAPSE_KEY_OFF, formatKeySpecForDisplay } from "../config.js";
3
4
  import type { QuestionData, QuestionnaireResult, QuestionParams } from "../tool/types.js";
4
5
  import type { WrappingSelectItem } from "../view/components/wrapping-select.js";
5
- import { COLLAPSED_HINT } from "../view/dialog-builder.js";
6
+ import { COLLAPSED_HINT_TEMPLATE, HINT_PART_CANCEL, KEY_PLACEHOLDER } from "../view/dialog-builder.js";
6
7
  import type { QuestionnairePropsAdapter } from "../view/props-adapter.js";
7
8
  import { buildQuestionnaire } from "./build-questionnaire.js";
8
9
  import { t } from "./i18n-bridge.js";
@@ -21,6 +22,14 @@ export interface QuestionnaireSessionConfig {
21
22
  editInput: (value: string) => Promise<string | undefined>;
22
23
  /** Key spec for the collapse/expand shortcut, e.g. `"ctrl+]"` or `"alt+o"`. */
23
24
  collapseKey: string;
25
+ /**
26
+ * True iff `execute()` registered the raw `ctx.ui.onTerminalInput` listener — the only
27
+ * path that can reach a hidden overlay. Gates the `set_overlay_hidden` effect: a host
28
+ * that delivers an `OverlayHandle` but no raw terminal input must fall back to the
29
+ * visible one-line collapsed row (which keeps focus and input routing), or collapsing
30
+ * would hide the overlay into a state nothing can reopen.
31
+ */
32
+ canReopenWhileHidden: boolean;
24
33
  }
25
34
 
26
35
  export interface QuestionnaireSessionComponent {
@@ -64,6 +73,7 @@ export class QuestionnaireSession {
64
73
  private readonly keybindings: QuestionnaireRuntime["keybindings"];
65
74
  private readonly editInput: QuestionnaireSessionConfig["editInput"];
66
75
  private readonly collapseKey: string;
76
+ private readonly canReopenWhileHidden: boolean;
67
77
  private inputEditorOpen = false;
68
78
 
69
79
  /**
@@ -86,6 +96,7 @@ export class QuestionnaireSession {
86
96
  this.keybindings = config.keybindings;
87
97
  this.editInput = config.editInput;
88
98
  this.collapseKey = config.collapseKey;
99
+ this.canReopenWhileHidden = config.canReopenWhileHidden;
89
100
 
90
101
  const built = buildQuestionnaire({
91
102
  tui: this.tui,
@@ -95,6 +106,7 @@ export class QuestionnaireSession {
95
106
  isMulti: this.isMulti,
96
107
  initialState: this.state,
97
108
  getCurrentTab: () => this.state.currentTab,
109
+ collapseKey: this.collapseKey,
98
110
  });
99
111
 
100
112
  this.notesInput = built.notesInput;
@@ -106,10 +118,18 @@ export class QuestionnaireSession {
106
118
  // the overlay to `min(lines.length, maxHeight)`, so returning one line shrinks
107
119
  // the bottom-anchored overlay from full-height to one row and the transcript
108
120
  // behind it becomes readable (#47). The overlay stays focused and in the
109
- // stack, so Ctrl+] still routes here to expand.
110
- const collapsedRender = (_width: number): string[] => [
111
- theme.fg("dim", ` ${t("hint.expand_line", COLLAPSED_HINT)} `),
112
- ];
121
+ // stack, so the collapse key still routes here to expand. `t` stays inside the
122
+ // closure (live locale updates); the key display is static per session.
123
+ //
124
+ // With collapseKey "off" the router and raw listener never toggle `collapsed`,
125
+ // but `toggleCollapsedExternal()` is a public ungated entry — fall back to the
126
+ // cancel-only line rather than rendering a literal "Off to expand".
127
+ const collapseKeyDisplay = formatKeySpecForDisplay(this.collapseKey);
128
+ const collapsedHintLine = (): string =>
129
+ this.collapseKey === COLLAPSE_KEY_OFF
130
+ ? t("hint.cancel", HINT_PART_CANCEL)
131
+ : t("hint.expand_line", COLLAPSED_HINT_TEMPLATE).replace(KEY_PLACEHOLDER, collapseKeyDisplay);
132
+ const collapsedRender = (_width: number): string[] => [theme.fg("dim", ` ${collapsedHintLine()} `)];
113
133
 
114
134
  this.component = {
115
135
  render: (width) => (this.state.collapsed ? collapsedRender(width) : built.render(width)),
@@ -178,8 +198,11 @@ export class QuestionnaireSession {
178
198
  return;
179
199
  case "set_overlay_hidden":
180
200
  // No-op until `setOverlayHandle` has been called (the handle arrives via
181
- // `ctx.ui.custom`'s `onHandle` right after the overlay is shown).
182
- this.overlayHandle?.setHidden(effect.hidden);
201
+ // `ctx.ui.custom`'s `onHandle` right after the overlay is shown), and
202
+ // suppressed entirely when no raw terminal listener exists — hiding would
203
+ // then be irreversible (pi-tui routes no input to a hidden overlay), so the
204
+ // visible one-line collapsed row serves as the fallback rendering instead.
205
+ if (this.canReopenWhileHidden) this.overlayHandle?.setHidden(effect.hidden);
183
206
  return;
184
207
  case "done":
185
208
  this.done(effect.result);
package/state/state.ts CHANGED
@@ -25,12 +25,20 @@ export interface QuestionnaireState {
25
25
  /** Canonical mirror of the in-flight notes editor; runtime mirrors after `forward_notes_keystroke`. */
26
26
  notesDraft: string;
27
27
  /**
28
- * Collapsed mode: the questionnaire shrinks to a single hint row so the agent transcript
29
- * behind the bottom-anchored overlay becomes readable. Toggled by `Ctrl+]` from any state;
30
- * while true, every keystroke except cancel is swallowed (see `routeKey`). The overlay
31
- * stays focused so the expand key never falls through to an underlying overlay (e.g.
32
- * `/btw`) — that focus-restore property is the entire reason we render a collapsed row
33
- * instead of calling `OverlayHandle.setHidden(true)`.
28
+ * Collapsed mode: the questionnaire gets out of the way so the agent transcript behind
29
+ * the bottom-anchored overlay becomes readable. Toggled by the configured collapse key
30
+ * from any state; while true, every keystroke except cancel is swallowed (see
31
+ * `routeKey`). Two renderings, chosen by host capability:
32
+ *
33
+ * - Hosts with an `OverlayHandle` AND a raw `onTerminalInput` listener (real pi-tui):
34
+ * the `set_overlay_hidden` effect fully hides the overlay; the raw listener registered
35
+ * in `execute()` reopens it, because pi-tui routes no input to a hidden overlay.
36
+ * - Hosts without the raw listener (or without a handle): the overlay stays visible and
37
+ * shrinks to a single hint row. The row keeps focus and input routing, so the same key
38
+ * expands it and Esc cancels, and the expand key never falls through to an underlying
39
+ * overlay (e.g. `/btw`). The session gates `set_overlay_hidden` on the listener's
40
+ * existence (`canReopenWhileHidden`) so a handle-bearing host without raw input can
41
+ * never hide the overlay into a state nothing can reopen.
34
42
  */
35
43
  collapsed: boolean;
36
44
  }
@@ -1,5 +1,6 @@
1
1
  import { DynamicBorder, type Theme } from "@earendil-works/pi-coding-agent";
2
2
  import { type Component, Container, type Editor, Spacer } from "@earendil-works/pi-tui";
3
+ import { DEFAULT_COLLAPSE_KEY, formatKeySpecForDisplay } from "../config.js";
3
4
  import type { QuestionnaireState } from "../state/state.js";
4
5
  import type { QuestionData } from "../tool/types.js";
5
6
  import type { PreviewPaneProps } from "./components/preview/preview-pane.js";
@@ -16,8 +17,21 @@ export const HINT_PART_TOGGLE = "Space to toggle";
16
17
  export const HINT_PART_NOTES = "n to add notes";
17
18
  export const HINT_PART_TAB = "Tab to switch questions";
18
19
  export const HINT_PART_CANCEL = "Esc to cancel";
19
- export const HINT_PART_COLLAPSE = "Ctrl+] to collapse";
20
- export const HINT_PART_EXPAND = "Ctrl+] to expand";
20
+ /**
21
+ * Collapse/expand hint copy is templated on `KEY_PLACEHOLDER` because the
22
+ * shortcut is configurable (`collapseKey`) and `rpiv-i18n`'s `tr` has no
23
+ * interpolation — locale entries carry the same `{key}` placeholder and call
24
+ * sites `.replace()` it with `formatKeySpecForDisplay(collapseKey)` after
25
+ * lookup, so per-locale word order is preserved.
26
+ */
27
+ export const KEY_PLACEHOLDER = "{key}";
28
+ export const HINT_PART_COLLAPSE_TEMPLATE = `${KEY_PLACEHOLDER} to collapse`;
29
+ export const HINT_PART_EXPAND_TEMPLATE = `${KEY_PLACEHOLDER} to expand`;
30
+ /** Default-key (`Ctrl+]`) rendering of the collapse template, for tests and default-config assertions. */
31
+ export const HINT_PART_COLLAPSE = HINT_PART_COLLAPSE_TEMPLATE.replace(
32
+ KEY_PLACEHOLDER,
33
+ formatKeySpecForDisplay(DEFAULT_COLLAPSE_KEY),
34
+ );
21
35
  /**
22
36
  * `HINT_SINGLE` / `HINT_MULTI` are the resting core hint for NON-multiSelect
23
37
  * question tabs only: `buildHintText` drops `NOTES` while the notes editor is
@@ -33,8 +47,12 @@ export const HINT_SINGLE = [HINT_PART_ENTER, HINT_PART_NAV, HINT_PART_NOTES, HIN
33
47
  export const HINT_MULTI = [HINT_PART_ENTER, HINT_PART_NAV, HINT_PART_NOTES, HINT_PART_TAB, HINT_PART_CANCEL].join(
34
48
  " · ",
35
49
  );
36
- /** Single-line footer shown by `QuestionnaireSession` when `state.collapsed === true`. Bypasses `buildHintText`. */
37
- export const COLLAPSED_HINT = [HINT_PART_EXPAND, HINT_PART_CANCEL].join(" · ");
50
+ /**
51
+ * Template for the single-line footer shown by `QuestionnaireSession` when
52
+ * `state.collapsed === true`. Bypasses `buildHintText`; the session replaces
53
+ * `KEY_PLACEHOLDER` with the configured key's display form.
54
+ */
55
+ export const COLLAPSED_HINT_TEMPLATE = [HINT_PART_EXPAND_TEMPLATE, HINT_PART_CANCEL].join(" · ");
38
56
  export const REVIEW_HEADING = "Review your answers";
39
57
  export const READY_PROMPT = "Ready to submit your answers?";
40
58
  export const INCOMPLETE_WARNING_PREFIX = "⚠ Answer remaining questions before submitting:";
@@ -67,6 +85,13 @@ export interface DialogConfig {
67
85
  getCurrentBodyHeight: (width: number) => number;
68
86
  /** Terminal height getter. Mirrors `getTerminalWidth` — reads `tui.terminal.rows` at render time. */
69
87
  getTerminalRows: () => number;
88
+ /**
89
+ * Resolved collapse/expand key spec (`resolveCollapseKey` output: `"ctrl+]"`,
90
+ * `"alt+o"`, or `"off"`). Construction-time config, NOT canonical state —
91
+ * `QuestionnaireRuntime.collapseKey` must never reach view setProps consumers.
92
+ * The footer hint interpolates it, and drops the collapse part when `"off"`.
93
+ */
94
+ collapseKey: string;
70
95
  }
71
96
 
72
97
  /**
@@ -95,6 +120,7 @@ export class DialogView implements StatefulView<DialogProps> {
95
120
  notesInput: config.notesInput,
96
121
  isMulti: config.isMulti,
97
122
  getCurrentBodyHeight: config.getCurrentBodyHeight,
123
+ collapseKey: config.collapseKey,
98
124
  });
99
125
  this.submitStrategy = config.isMulti
100
126
  ? new SubmitTabStrategy({
@@ -1,5 +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.js";
3
4
  import { t } from "../state/i18n-bridge.js";
4
5
  import { formatAnswerScalar } from "../tool/format-answer.js";
5
6
  import type { QuestionData } from "../tool/types.js";
@@ -8,7 +9,7 @@ import {
8
9
  type DialogState,
9
10
  HINT_PART_CANCEL,
10
11
  HINT_PART_CLEAR,
11
- HINT_PART_COLLAPSE,
12
+ HINT_PART_COLLAPSE_TEMPLATE,
12
13
  HINT_PART_ENTER,
13
14
  HINT_PART_NAV,
14
15
  HINT_PART_NEW_LINE,
@@ -16,6 +17,7 @@ import {
16
17
  HINT_PART_TAB,
17
18
  HINT_PART_TOGGLE,
18
19
  INCOMPLETE_WARNING_PREFIX,
20
+ KEY_PLACEHOLDER,
19
21
  READY_PROMPT,
20
22
  REVIEW_HEADING,
21
23
  } from "./dialog-builder.js";
@@ -86,6 +88,8 @@ export interface QuestionTabStrategyConfig {
86
88
  notesInput: Editor;
87
89
  isMulti: boolean;
88
90
  getCurrentBodyHeight: (width: number) => number;
91
+ /** Resolved collapse key spec (`"ctrl+]"`, `"alt+o"`, or `"off"`). Drives the footer's collapse hint. */
92
+ collapseKey: string;
89
93
  }
90
94
 
91
95
  export class QuestionTabStrategy implements TabContentStrategy {
@@ -137,7 +141,10 @@ export class QuestionTabStrategy implements TabContentStrategy {
137
141
  // drops the trailing parts (collapse hint first, then cancel) with `…`.
138
142
  return [
139
143
  new Spacer(1),
140
- new OneLineClippedText(this.config.theme.fg("dim", buildHintText(question, this.config.isMulti, state)), 1),
144
+ new OneLineClippedText(
145
+ this.config.theme.fg("dim", buildHintText(question, this.config.isMulti, state, this.config.collapseKey)),
146
+ 1,
147
+ ),
141
148
  ];
142
149
  }
143
150
 
@@ -228,21 +235,35 @@ export class SubmitTabStrategy implements TabContentStrategy {
228
235
 
229
236
  /**
230
237
  * Build the controls hint line. Order:
231
- * Enter · ↑/↓ [· Space toggle] [· n notes] [· Tab switch] · Esc · Ctrl+] collapse
238
+ * Enter · ↑/↓ [· Space toggle] [· n notes] [· Tab switch] · Esc [· <key> collapse]
232
239
  * [· Shift+Enter newline] [· Ctrl+U clear]
233
240
  *
234
241
  * `NOTES` is part of the resting (notes-closed) core — it drops while the notes
235
242
  * editor or custom-answer input has the keyboard. Ctrl+G is Pi's global external-
236
243
  * editor shortcut and needs no local hint; the context-specific clear shortcut is
237
244
  * appended at the far right while input mode is active.
245
+ *
246
+ * The collapse part interpolates the configured `collapseKey` (display-cased)
247
+ * and is omitted entirely when the shortcut is `"off"` — `routeKey` and the raw
248
+ * terminal listener both refuse to collapse in that case, so advertising a key
249
+ * would be a lie.
238
250
  */
239
- export function buildHintText(question: QuestionData | undefined, isMulti: boolean, state: DialogState): string {
251
+ export function buildHintText(
252
+ question: QuestionData | undefined,
253
+ isMulti: boolean,
254
+ state: DialogState,
255
+ collapseKey: string,
256
+ ): string {
240
257
  const parts: string[] = [t("hint.enter", HINT_PART_ENTER), t("hint.navigate", HINT_PART_NAV)];
241
258
  if (question?.multiSelect === true) parts.push(t("hint.toggle", HINT_PART_TOGGLE));
242
259
  if (question && !state.notesVisible && !state.inputMode) parts.push(t("hint.notes", HINT_PART_NOTES));
243
260
  if (isMulti) parts.push(t("hint.tab", HINT_PART_TAB));
244
261
  parts.push(t("hint.cancel", HINT_PART_CANCEL));
245
- parts.push(t("hint.collapse", HINT_PART_COLLAPSE));
262
+ if (collapseKey !== COLLAPSE_KEY_OFF) {
263
+ parts.push(
264
+ t("hint.collapse", HINT_PART_COLLAPSE_TEMPLATE).replace(KEY_PLACEHOLDER, formatKeySpecForDisplay(collapseKey)),
265
+ );
266
+ }
246
267
  if (state.notesVisible || state.inputMode) parts.push(t("hint.newline", HINT_PART_NEW_LINE));
247
268
  if (state.inputMode) parts.push(t("hint.clear", HINT_PART_CLEAR));
248
269
  return parts.join(" · ");