@juicesharp/rpiv-ask-user-question 1.14.5 → 1.14.7

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/locales/en.json CHANGED
@@ -11,6 +11,8 @@
11
11
  "hint.toggle": "Space to toggle",
12
12
  "hint.notes": "n to add notes",
13
13
  "hint.tab": "Tab to switch questions",
14
+ "hint.collapse": "Ctrl+] to collapse",
15
+ "hint.expand_line": "Ctrl+] to expand · Esc to cancel",
14
16
  "hint.cancel": "Esc to cancel",
15
17
 
16
18
  "review.heading": "Review your answers",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juicesharp/rpiv-ask-user-question",
3
- "version": "1.14.5",
3
+ "version": "1.14.7",
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",
@@ -87,6 +87,6 @@
87
87
  }
88
88
  },
89
89
  "dependencies": {
90
- "@juicesharp/rpiv-config": "^1.14.5"
90
+ "@juicesharp/rpiv-config": "^1.14.7"
91
91
  }
92
92
  }
@@ -29,6 +29,8 @@ export type QuestionnaireAction =
29
29
  */
30
30
  | { kind: "focus_options"; optionIndex: number }
31
31
  | { kind: "notes_forward"; data: string }
32
+ /** Flip `state.collapsed`. Always available, regardless of inner mode (see top intercept in `routeKey`). */
33
+ | { kind: "toggle_collapsed" }
32
34
  | { kind: "ignore" };
33
35
 
34
36
  export interface QuestionnaireKeybindings {
@@ -147,6 +149,29 @@ function prevNavOnUp(state: QuestionnaireState, runtime: QuestionnaireRuntime):
147
149
  export function routeKey(data: string, state: QuestionnaireState, runtime: QuestionnaireRuntime): QuestionnaireAction {
148
150
  const kb = runtime.keybindings;
149
151
 
152
+ // Collapse/expand toggle is a UI-level affordance — intercepted at the top so it
153
+ // works from every inner state (notes, inputMode, chat, submit tab, multi-select)
154
+ // without reaching any branch that would otherwise consume the keystroke. The
155
+ // questionnaire stays in pi-tui's overlay stack with focus while collapsed, so the
156
+ // expand key never falls through to a lower overlay (e.g. `/btw`) — that's why we
157
+ // toggle state instead of calling `OverlayHandle.setHidden(true)`.
158
+ //
159
+ // Ctrl+] (GS, 0x1d): chosen after Alt+Tab (OS-reserved on macOS), Ctrl+P (collides
160
+ // with pi-coding-agent "cycle model" + the user's virtual terminal), and F2 (taken
161
+ // by macOS function-key behavior) were all eliminated. Ctrl+] is free in every
162
+ // mainstream macOS terminal (Terminal.app, iTerm2, Warp), every multiplexer (tmux,
163
+ // zellij, screen — none use it as a prefix), and the legacy telnet/ssh escape role
164
+ // doesn't apply because our overlay runs in-process.
165
+ if (matchesKey(data, Key.ctrl("]"))) return { kind: "toggle_collapsed" };
166
+
167
+ // Collapsed-mode lockout: while collapsed, swallow every keystroke except cancel so
168
+ // the user can read the now-uncovered transcript without accidentally mutating
169
+ // answers or notes. The collapse toggle itself is already handled above.
170
+ if (state.collapsed) {
171
+ if (kb.matches(data, KEYBIND_CANCEL)) return { kind: "cancel" };
172
+ return { kind: "ignore" };
173
+ }
174
+
150
175
  if (state.notesVisible) {
151
176
  if (kb.matches(data, KEYBIND_CANCEL)) return { kind: "notes_exit" };
152
177
  if (kb.matches(data, KEYBIND_CONFIRM)) return { kind: "notes_exit" };
@@ -2,9 +2,10 @@ import type { Theme } from "@earendil-works/pi-coding-agent";
2
2
  import { getKeybindings, type Input } from "@earendil-works/pi-tui";
3
3
  import type { QuestionData, QuestionnaireResult, QuestionParams } from "../tool/types.js";
4
4
  import type { WrappingSelectItem } from "../view/components/wrapping-select.js";
5
+ import { COLLAPSED_HINT } from "../view/dialog-builder.js";
5
6
  import type { QuestionnairePropsAdapter } from "../view/props-adapter.js";
6
7
  import { buildQuestionnaire } from "./build-questionnaire.js";
7
- import { displayLabel } from "./i18n-bridge.js";
8
+ import { displayLabel, t } from "./i18n-bridge.js";
8
9
  import { type QuestionnaireAction, routeKey } from "./key-router.js";
9
10
  import { computeFocusedOptionHasPreview } from "./selectors/derivations.js";
10
11
  import type { QuestionnaireRuntime, QuestionnaireState } from "./state.js";
@@ -41,6 +42,7 @@ function initialState(): QuestionnaireState {
41
42
  focusedOptionHasPreview: false,
42
43
  submitChoiceIndex: 0,
43
44
  notesDraft: "",
45
+ collapsed: false,
44
46
  };
45
47
  }
46
48
 
@@ -89,8 +91,18 @@ export class QuestionnaireSession {
89
91
  this.inlineInput = built.inlineInput;
90
92
  this.viewAdapter = built.adapter;
91
93
 
94
+ const theme = config.theme;
95
+ // Collapsed render: a single dim row at the bottom of the overlay. pi-tui sizes
96
+ // the overlay to `min(lines.length, maxHeight)`, so returning one line shrinks
97
+ // the bottom-anchored overlay from full-height to one row and the transcript
98
+ // behind it becomes readable (#47). The overlay stays focused and in the
99
+ // stack, so Ctrl+] still routes here to expand.
100
+ const collapsedRender = (_width: number): string[] => [
101
+ theme.fg("dim", ` ${t("hint.expand_line", COLLAPSED_HINT)} `),
102
+ ];
103
+
92
104
  this.component = {
93
- render: built.render,
105
+ render: (width) => (this.state.collapsed ? collapsedRender(width) : built.render(width)),
94
106
  invalidate: built.invalidate,
95
107
  handleInput: (data) => this.dispatch(data),
96
108
  };
@@ -254,6 +254,10 @@ const notesForwardHandler: Handler<"notes_forward"> = (s, a, _c) => ({
254
254
  state: s,
255
255
  effects: [{ kind: "forward_notes_keystroke", data: a.data }],
256
256
  });
257
+ const toggleCollapsedHandler: Handler<"toggle_collapsed"> = (s, _a, _c) => ({
258
+ state: { ...s, collapsed: !s.collapsed },
259
+ effects: [],
260
+ });
257
261
  const ignoreHandler: Handler<"ignore"> = (s, _a, _c) => ({ state: s, effects: [] });
258
262
 
259
263
  /**
@@ -276,6 +280,7 @@ const HANDLERS: { [K in QuestionnaireAction["kind"]]: Handler<K> } = {
276
280
  submit_nav: submitNavHandler,
277
281
  focus_chat: focusChatHandler,
278
282
  focus_options: focusOptionsHandler,
283
+ toggle_collapsed: toggleCollapsedHandler,
279
284
  ignore: ignoreHandler,
280
285
  };
281
286
 
package/state/state.ts CHANGED
@@ -25,6 +25,15 @@ export interface QuestionnaireState {
25
25
  submitChoiceIndex: number;
26
26
  /** Canonical mirror of the in-flight notes editor; runtime mirrors after `forward_notes_keystroke`. */
27
27
  notesDraft: string;
28
+ /**
29
+ * Collapsed mode: the questionnaire shrinks to a single hint row so the agent transcript
30
+ * behind the bottom-anchored overlay becomes readable. Toggled by `Ctrl+]` from any state;
31
+ * while true, every keystroke except cancel is swallowed (see `routeKey`). The overlay
32
+ * stays focused so the expand key never falls through to an underlying overlay (e.g.
33
+ * `/btw`) — that focus-restore property is the entire reason we render a collapsed row
34
+ * instead of calling `OverlayHandle.setHidden(true)`.
35
+ */
36
+ collapsed: boolean;
28
37
  }
29
38
 
30
39
  /**
@@ -15,10 +15,20 @@ export const HINT_PART_TOGGLE = "Space to toggle";
15
15
  export const HINT_PART_NOTES = "n to add notes";
16
16
  export const HINT_PART_TAB = "Tab to switch questions";
17
17
  export const HINT_PART_CANCEL = "Esc to cancel";
18
+ export const HINT_PART_COLLAPSE = "Ctrl+] to collapse";
19
+ export const HINT_PART_EXPAND = "Ctrl+] to expand";
20
+ /**
21
+ * `HINT_SINGLE` / `HINT_MULTI` describe the CORE hint that must always be visible —
22
+ * the collapse affordance is appended AFTER cancel by `buildHintText` so the core
23
+ * stays a contiguous prefix substring of the rendered line. On narrow terminals the
24
+ * collapse tail clips with `…` (`OneLineClippedText`); the core is preserved.
25
+ */
18
26
  export const HINT_SINGLE = [HINT_PART_ENTER, HINT_PART_NAV, HINT_PART_CANCEL].join(" · ");
19
27
  export const HINT_MULTI = [HINT_PART_ENTER, HINT_PART_NAV, HINT_PART_TAB, HINT_PART_CANCEL].join(" · ");
20
28
  export const HINT_MULTISELECT_SUFFIX = ` · ${HINT_PART_TOGGLE}`;
21
29
  export const HINT_NOTES_SUFFIX = ` · ${HINT_PART_NOTES}`;
30
+ /** Single-line footer shown by `QuestionnaireSession` when `state.collapsed === true`. Bypasses `buildHintText`. */
31
+ export const COLLAPSED_HINT = [HINT_PART_EXPAND, HINT_PART_CANCEL].join(" · ");
22
32
  export const REVIEW_HEADING = "Review your answers";
23
33
  export const READY_PROMPT = "Ready to submit your answers?";
24
34
  export const INCOMPLETE_WARNING_PREFIX = "⚠ Answer remaining questions before submitting:";
@@ -1,5 +1,5 @@
1
1
  import type { Theme } from "@earendil-works/pi-coding-agent";
2
- import { type Component, Container, type Input, Spacer, Text } from "@earendil-works/pi-tui";
2
+ import { type Component, Container, type Input, Spacer, Text, truncateToWidth } from "@earendil-works/pi-tui";
3
3
  import { t } from "../state/i18n-bridge.js";
4
4
  import { formatAnswerScalar } from "../tool/format-answer.js";
5
5
  import type { QuestionData } from "../tool/types.js";
@@ -8,6 +8,7 @@ import type { PreviewPane, PreviewPaneProps } from "./components/preview/preview
8
8
  import {
9
9
  type DialogState,
10
10
  HINT_PART_CANCEL,
11
+ HINT_PART_COLLAPSE,
11
12
  HINT_PART_ENTER,
12
13
  HINT_PART_NAV,
13
14
  HINT_PART_NOTES,
@@ -22,6 +23,32 @@ import type { TabComponents } from "./tab-components.js";
22
23
 
23
24
  const NOTES_HEADER = "Notes:";
24
25
 
26
+ /**
27
+ * Single-row, width-clipped chrome cell. The footer row count is invariant
28
+ * (`QuestionTabStrategy.footerRowCount = 4`) — pi-tui's `Text` word-wraps when
29
+ * the styled hint exceeds `width`, inflating that row count and desyncing the
30
+ * `bodyHeight + footerRowCount` math in `DialogView.render`. Clipping with
31
+ * `truncateToWidth` (ANSI-aware, matches `multi-select-view.ts` usage) keeps
32
+ * the hint on one line; the collapse affordance falls off the right edge with
33
+ * `…` on terminals too narrow to advertise it.
34
+ */
35
+ class OneLineClippedText implements Component {
36
+ constructor(
37
+ private readonly text: string,
38
+ private readonly paddingLeft: number = 0,
39
+ ) {}
40
+
41
+ render(width: number): string[] {
42
+ const pad = " ".repeat(this.paddingLeft);
43
+ const avail = Math.max(0, width - this.paddingLeft);
44
+ return [pad + truncateToWidth(this.text, avail, "…", false)];
45
+ }
46
+
47
+ invalidate(): void {}
48
+
49
+ handleInput(_data: string): void {}
50
+ }
51
+
25
52
  /**
26
53
  * Per-tab content provider. Pure functional — closes over construction-time
27
54
  * config; per-tick state threads through method args. The chrome wrapper
@@ -104,11 +131,16 @@ export class QuestionTabStrategy implements TabContentStrategy {
104
131
 
105
132
  footerRows(state: DialogState): Component[] {
106
133
  const question = this.config.questions[state.currentTab];
134
+ // OneLineClippedText (not pi-tui `Text`) — `buildHintText` now includes the
135
+ // collapse affordance, pushing the rendered string past 80 columns; `Text` would
136
+ // wrap and break the strategy's `footerRowCount = 4` invariant. Clipping on
137
+ // narrow terminals drops the trailing parts (collapse hint first, then cancel)
138
+ // with `…`.
107
139
  return [
108
140
  new Spacer(1),
109
141
  this.config.chatRow,
110
142
  new Spacer(1),
111
- new Text(this.config.theme.fg("dim", buildHintText(question, this.config.isMulti, state)), 1, 0),
143
+ new OneLineClippedText(this.config.theme.fg("dim", buildHintText(question, this.config.isMulti, state)), 1),
112
144
  ];
113
145
  }
114
146
 
@@ -198,9 +230,14 @@ export class SubmitTabStrategy implements TabContentStrategy {
198
230
  }
199
231
 
200
232
  /**
201
- * Build the controls hint line. Order is fixed so `HINT_SINGLE` / `HINT_MULTI`
202
- * remain contiguous substrings of the result:
203
- * Enter · ↑/↓ [· Space toggle] [· n notes] [· Tab switch] · Esc
233
+ * Build the controls hint line. Order:
234
+ * Enter · ↑/↓ [· Space toggle] [· n notes] [· Tab switch] · Esc · Ctrl+] collapse
235
+ *
236
+ * `HINT_SINGLE` / `HINT_MULTI` are the CORE prefix that must always render — the
237
+ * collapse affordance is appended last so the core stays a contiguous substring even
238
+ * when the trailing part is clipped by `OneLineClippedText` on terminals < ~95 cols.
239
+ * This is the trade we picked over wrapping (which would inflate `footerRowCount`
240
+ * and desync the height math in `DialogView.render`).
204
241
  */
205
242
  export function buildHintText(question: QuestionData | undefined, isMulti: boolean, state: DialogState): string {
206
243
  const parts: string[] = [t("hint.enter", HINT_PART_ENTER), t("hint.navigate", HINT_PART_NAV)];
@@ -210,5 +247,6 @@ export function buildHintText(question: QuestionData | undefined, isMulti: boole
210
247
  }
211
248
  if (isMulti) parts.push(t("hint.tab", HINT_PART_TAB));
212
249
  parts.push(t("hint.cancel", HINT_PART_CANCEL));
250
+ parts.push(t("hint.collapse", HINT_PART_COLLAPSE));
213
251
  return parts.join(" · ");
214
252
  }