@juicesharp/rpiv-ask-user-question 2.13.9 → 2.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -458,6 +458,9 @@ export function registerAskUserQuestionTool(pi: ExtensionAPI): void {
458
458
  pi.registerTool({
459
459
  name: ASK_USER_QUESTION_TOOL_NAME,
460
460
  label: "Ask User Question",
461
+ // Interactive: always a top-level call, never from a codemode script, so
462
+ // codemode "only" keeps declaring it to the model (#310).
463
+ exposure: "model-only",
461
464
  description: guidance.description ?? DEFAULT_TOOL_DESCRIPTION,
462
465
  promptSnippet: guidance.promptSnippet ?? DEFAULT_PROMPT_SNIPPET,
463
466
  promptGuidelines: guidance.promptGuidelines ?? DEFAULT_PROMPT_GUIDELINES,
package/docs/keyboard.md CHANGED
@@ -88,7 +88,8 @@ keeping the header, the question, the focused option and the key hints visible.
88
88
 
89
89
  Wheel and trackpad scrolling reach the transcript only when the terminal reports them as
90
90
  mouse events. A terminal with mouse reporting turned off (Warp, for one) converts them
91
- into ↑/↓ key presses instead, which move between the dialog's options. `PageUp`/`PageDown`
91
+ into ↑/↓ key presses instead, which move between the dialog's options. tmux does the same
92
+ unless mouse mode is on (`set -g mouse on` in `~/.tmux.conf`). `PageUp`/`PageDown`
92
93
  (`Fn+↑`/`Fn+↓` on a Mac keyboard) scroll the transcript either way.
93
94
 
94
95
  Two cases open the questionnaire as an overlay instead:
@@ -99,6 +100,11 @@ Two cases open the questionnaire as an overlay instead:
99
100
  stacks on top, so the question you see is the one your keys reach. `Ctrl+]` shrinks it to
100
101
  its one-line row so `/btw` is readable behind it; the question keeps the keys, so `Esc`
101
102
  cancels the question, and `/btw` closes after the question is answered or cancelled.
103
+ Overlays that never take the keys, such as an extension's status panel, don't count: the
104
+ question still opens in the editor area.
105
+
106
+ While the questionnaire is an overlay, Pi gives it `PageUp`/`PageDown` (and, before Pi 1.2,
107
+ the wheel), so the transcript doesn't scroll until the question is answered or cancelled.
102
108
 
103
109
  ## Collapse mode
104
110
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juicesharp/rpiv-ask-user-question",
3
- "version": "2.13.9",
3
+ "version": "2.14.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",
@@ -101,6 +101,6 @@
101
101
  }
102
102
  },
103
103
  "dependencies": {
104
- "@juicesharp/rpiv-config": "^2.13.9"
104
+ "@juicesharp/rpiv-config": "^2.14.0"
105
105
  }
106
106
  }
package/presentation.ts CHANGED
@@ -51,9 +51,19 @@ export const YIELD_TO_OVERLAY: QuestionnaireResult = Object.freeze({
51
51
  * the user cannot see. Stacking as an overlay instead keeps the question visible and
52
52
  * focused, and pi-tui returns focus to the other overlay when it closes. A host that
53
53
  * allocates the rows itself (rpiv-pi lane console) owns its geometry and is left alone.
54
+ *
55
+ * Only a capturing overlay counts. A `nonCapturing` one (a HUD or status panel) never
56
+ * takes keyboard focus, so the inline question stays focused and keeps the transcript
57
+ * scrollable; yielding to it would mount a focused overlay, which in fullscreen Pi takes
58
+ * the viewport's PageUp/PageDown (and, before Pi 1.2, the wheel) until answered (#313).
59
+ * pi-tui's `getTopmostVisibleOverlay()` applies that rule but is private in its typings,
60
+ * so it is duck-typed, with `hasOverlay()` as the fallback for hosts without it.
54
61
  */
55
62
  export function mustYieldInlineSlot(tui: { terminal: object; hasOverlay?: () => boolean }): boolean {
56
- return !hostAllocatesRows(tui.terminal) && typeof tui.hasOverlay === "function" && tui.hasOverlay();
63
+ if (hostAllocatesRows(tui.terminal)) return false;
64
+ const { getTopmostVisibleOverlay } = tui as { getTopmostVisibleOverlay?: () => unknown };
65
+ if (typeof getTopmostVisibleOverlay === "function") return getTopmostVisibleOverlay.call(tui) !== undefined;
66
+ return typeof tui.hasOverlay === "function" && tui.hasOverlay();
57
67
  }
58
68
 
59
69
  export const inlineRowBudget: RowBudget = (terminalRows) =>
@@ -1,5 +1,5 @@
1
1
  import { DynamicBorder, type Theme } from "@earendil-works/pi-coding-agent";
2
- import { type Component, Container, type Editor, Spacer } from "@earendil-works/pi-tui";
2
+ import { type Component, Container, CURSOR_MARKER, type Editor, Spacer } from "@earendil-works/pi-tui";
3
3
  import type { QuestionnaireState } from "../state/state.ts";
4
4
  import type { QuestionData } from "../tool/types.ts";
5
5
  import type { PreviewPaneProps } from "./components/preview/preview-pane.ts";
@@ -48,6 +48,11 @@ function renderChromeOnly(natural: string[], topFixed: number, bottomFixed: numb
48
48
  return chromeOnly.length > termRows ? chromeOnly.slice(0, termRows) : chromeOnly;
49
49
  }
50
50
 
51
+ /** Shift an end-exclusive row range by `delta` rows; undefined (no focus) passes through. */
52
+ function offsetRange(range: [number, number] | undefined, delta: number): [number, number] | undefined {
53
+ return range && [range[0] + delta, range[1] + delta];
54
+ }
55
+
51
56
  export type DialogState = QuestionnaireState;
52
57
 
53
58
  /** Per-tick projection of dialog state. Written by the adapter; read by the strategy thunk. */
@@ -195,13 +200,14 @@ export class DialogView implements StatefulView<DialogProps> {
195
200
  // below — that would draw the bottom border and hint twice (#260).
196
201
  const windowRows = Math.min(availableMiddle, middleRows);
197
202
  const rowsBeforeBody = pinHeading ? 0 : headingHeight;
198
- const focusedRange = strategy.focusedItemRowRange(width, state);
199
- const scrollStart = computeScrollStart(focusedRange, rowsBeforeBody, windowRows, middleRows);
203
+ // Scroll-to-focus target in middle-region rows. While the notes editor is open it is the
204
+ // keyboard's target, so the window follows it rather than the focused option (#317).
205
+ const focusedRange = state.notesVisible
206
+ ? this.notesFocusRange(natural.slice(top, top + middleRows), strategy, width, windowRows)
207
+ : offsetRange(strategy.focusedItemRowRange(width, state), rowsBeforeBody);
208
+ const scrollStart = computeScrollStart(focusedRange, 0, windowRows, middleRows);
200
209
  const scrollableMiddle = natural.slice(top + scrollStart, top + scrollStart + windowRows);
201
- const focusedInWindow: [number, number] | undefined = focusedRange && [
202
- rowsBeforeBody + focusedRange[0] - scrollStart,
203
- rowsBeforeBody + focusedRange[1] - scrollStart,
204
- ];
210
+ const focusedInWindow = offsetRange(focusedRange, -scrollStart);
205
211
  decorateOverflow(
206
212
  scrollableMiddle,
207
213
  scrollStart > 0,
@@ -221,6 +227,25 @@ export class DialogView implements StatefulView<DialogProps> {
221
227
  return 1 + strategy.midRows(this.liveProps.state).reduce((rows, c) => rows + c.render(width).length, 0);
222
228
  }
223
229
 
230
+ /**
231
+ * Focus range, in middle-region rows, for the open notes editor. Mid rows end the middle
232
+ * region, so the whole editor block (header included) is kept in view when it fits; a taller
233
+ * one is followed by the row carrying the editor's cursor marker, so typed text and an IME
234
+ * composition window stay on screen (#317).
235
+ */
236
+ private notesFocusRange(
237
+ middle: readonly string[],
238
+ strategy: TabContentStrategy,
239
+ width: number,
240
+ windowRows: number,
241
+ ): [number, number] {
242
+ const notesRows = this.rowsAroundBody(strategy, width) - 1;
243
+ const notesStart = middle.length - notesRows;
244
+ if (notesRows <= windowRows) return [notesStart, middle.length];
245
+ const cursorRow = middle.findIndex((line, i) => i >= notesStart && line.includes(CURSOR_MARKER));
246
+ return cursorRow === -1 ? [notesStart, middle.length] : [cursorRow, cursorRow + 1];
247
+ }
248
+
224
249
  /**
225
250
  * Hand the active question's preview pane the rows its body may use this frame, so a body
226
251
  * taller than the space fits itself — options scroll in their column, the preview box