@juicesharp/rpiv-ask-user-question 1.0.11 → 1.0.12

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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # rpiv-ask-user-question
2
2
 
3
+ <a href="https://github.com/juicesharp/rpiv-mono/tree/main/packages/rpiv-ask-user-question">
4
+ <picture>
5
+ <img src="https://raw.githubusercontent.com/juicesharp/rpiv-mono/main/packages/rpiv-ask-user-question/docs/cover.png" alt="rpiv-ask-user-question cover" width="100%">
6
+ </picture>
7
+ </a>
8
+
3
9
  [![npm version](https://img.shields.io/npm/v/@juicesharp/rpiv-ask-user-question.svg)](https://www.npmjs.com/package/@juicesharp/rpiv-ask-user-question)
4
10
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
11
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juicesharp/rpiv-ask-user-question",
3
- "version": "1.0.11",
3
+ "version": "1.0.12",
4
4
  "description": "Pi extension: lets the model ask you a clarifying question with structured options instead of guessing",
5
5
  "keywords": [
6
6
  "pi-package",
@@ -31,7 +31,6 @@
31
31
  "LICENSE",
32
32
  "README.md",
33
33
  "state/build-questionnaire.ts",
34
- "state/input-buffer.ts",
35
34
  "state/key-router.ts",
36
35
  "state/questionnaire-session.ts",
37
36
  "state/row-intent.ts",
@@ -20,7 +20,6 @@ import { DialogView } from "../view/dialog-builder.js";
20
20
  import { QuestionnairePropsAdapter } from "../view/props-adapter.js";
21
21
  import type { StatefulView } from "../view/stateful-view.js";
22
22
  import type { TabBodyHeights, TabComponents } from "../view/tab-components.js";
23
- import type { InputBuffer } from "./input-buffer.js";
24
23
  import type { PerTabSelector } from "./selectors/contract.js";
25
24
  import { selectActivePreviewPaneIndex } from "./selectors/derivations.js";
26
25
  import {
@@ -41,13 +40,13 @@ export interface QuestionnaireBuildConfig {
41
40
  itemsByTab: ReadonlyArray<readonly WrappingSelectItem[]>;
42
41
  isMulti: boolean;
43
42
  initialState: QuestionnaireState;
44
- inputBuffer: InputBuffer;
45
43
  getCurrentTab: () => number;
46
44
  }
47
45
 
48
46
  export interface QuestionnaireBuilt {
49
47
  adapter: QuestionnairePropsAdapter;
50
48
  notesInput: Input;
49
+ inlineInput: Input;
51
50
  render: (width: number) => string[];
52
51
  invalidate: () => void;
53
52
  }
@@ -97,13 +96,13 @@ class QuestionnaireBuilder {
97
96
  private readonly itemsByTab: ReadonlyArray<readonly WrappingSelectItem[]>;
98
97
  private readonly isMulti: boolean;
99
98
  private readonly initialState: QuestionnaireState;
100
- private readonly inputBuffer: InputBuffer;
101
99
  private readonly getCurrentTab: () => number;
102
100
 
103
101
  private readonly selectTheme: WrappingSelectTheme;
104
102
  private readonly markdownTheme = getMarkdownTheme();
105
103
  private readonly chatRow: ChatRowView;
106
104
  private readonly notesInput = new Input();
105
+ private readonly inlineInput = new Input();
107
106
  private readonly getTerminalWidth = () => this.tui.terminal.columns;
108
107
 
109
108
  constructor(config: QuestionnaireBuildConfig) {
@@ -113,7 +112,6 @@ class QuestionnaireBuilder {
113
112
  this.itemsByTab = config.itemsByTab;
114
113
  this.isMulti = config.isMulti;
115
114
  this.initialState = config.initialState;
116
- this.inputBuffer = config.inputBuffer;
117
115
  this.getCurrentTab = config.getCurrentTab;
118
116
 
119
117
  this.selectTheme = this.makeSelectTheme();
@@ -271,7 +269,7 @@ class QuestionnaireBuilder {
271
269
  questions: this.questions,
272
270
  itemsByTab: this.itemsByTab,
273
271
  tabsByIndex: tabs,
274
- inputBuffer: this.inputBuffer,
272
+ inlineInput: this.inlineInput,
275
273
  globalBindings,
276
274
  perTabBindings,
277
275
  extraInvalidatables: [this.notesInput],
@@ -282,6 +280,7 @@ class QuestionnaireBuilder {
282
280
  return {
283
281
  adapter,
284
282
  notesInput: this.notesInput,
283
+ inlineInput: this.inlineInput,
285
284
  render: (w) => dialog.render(w),
286
285
  invalidate: () => adapter.invalidate(),
287
286
  };
@@ -4,14 +4,14 @@ import { type QuestionData, type QuestionnaireResult, type QuestionParams, SENTI
4
4
  import type { WrappingSelectItem } from "../view/components/wrapping-select.js";
5
5
  import type { QuestionnairePropsAdapter } from "../view/props-adapter.js";
6
6
  import { buildQuestionnaire } from "./build-questionnaire.js";
7
- import { InputBuffer } from "./input-buffer.js";
8
7
  import { type QuestionnaireAction, routeKey } from "./key-router.js";
9
8
  import { computeFocusedOptionHasPreview } from "./selectors/derivations.js";
10
9
  import type { QuestionnaireRuntime, QuestionnaireState } from "./state.js";
11
10
  import { type ApplyContext, type Effect, reduce } from "./state-reducer.js";
12
11
 
13
- const BACKSPACE_CHARS = new Set(["\x7f", "\b"]);
14
- const ESC_SEQUENCE_PREFIX = "\x1b";
12
+ // Module-level constant; reused for cursor-end mutations after setValue rehydration.
13
+ // Ctrl-E → tui.editor.cursorLineEnd (public path; pi-tui keybindings.js:25-28).
14
+ const CURSOR_END = "\x05";
15
15
 
16
16
  export interface QuestionnaireSessionConfig {
17
17
  tui: { terminal: { columns: number }; requestRender(): void };
@@ -51,13 +51,13 @@ function initialState(): QuestionnaireState {
51
51
  */
52
52
  export class QuestionnaireSession {
53
53
  private state: QuestionnaireState = initialState();
54
- private readonly inputBuffer = new InputBuffer();
55
54
 
56
55
  private readonly questions: readonly QuestionData[];
57
56
  private readonly isMulti: boolean;
58
57
  private readonly itemsByTab: WrappingSelectItem[][];
59
58
 
60
59
  private readonly notesInput: Input;
60
+ private readonly inlineInput: Input;
61
61
  private readonly viewAdapter: QuestionnairePropsAdapter;
62
62
 
63
63
  private readonly tui: QuestionnaireSessionConfig["tui"];
@@ -81,11 +81,11 @@ export class QuestionnaireSession {
81
81
  itemsByTab: this.itemsByTab,
82
82
  isMulti: this.isMulti,
83
83
  initialState: this.state,
84
- inputBuffer: this.inputBuffer,
85
84
  getCurrentTab: () => this.state.currentTab,
86
85
  });
87
86
 
88
87
  this.notesInput = built.notesInput;
88
+ this.inlineInput = built.inlineInput;
89
89
  this.viewAdapter = built.adapter;
90
90
 
91
91
  this.component = {
@@ -122,10 +122,11 @@ export class QuestionnaireSession {
122
122
  private runEffect(effect: Effect): void {
123
123
  switch (effect.kind) {
124
124
  case "set_input_buffer":
125
- this.inputBuffer.set(effect.value);
125
+ this.inlineInput.setValue(effect.value);
126
+ this.inlineInput.handleInput(CURSOR_END);
126
127
  return;
127
128
  case "clear_input_buffer":
128
- this.inputBuffer.clear();
129
+ this.inlineInput.setValue("");
129
130
  return;
130
131
  case "set_notes_value":
131
132
  this.notesInput.setValue(effect.value);
@@ -143,25 +144,28 @@ export class QuestionnaireSession {
143
144
  }
144
145
 
145
146
  /**
146
- * Per-keystroke `ignore` fast path: mutates the session-owned input buffer
147
- * directly (no reducer pass) and re-runs `viewAdapter.apply(state)` so the
148
- * new buffer value flows out via `selectOptionListProps`.
147
+ * Per-keystroke `ignore` fast path: delegates to the headless `inlineInput`
148
+ * Input so bracketed-paste accumulator (`input.js:33-63`) and Kitty CSI-u
149
+ * decode (`input.js:155-163`) take effect. Cursor is NOT force-reset here —
150
+ * doing so would corrupt split-chunk pastes (a `\x05` byte mid-paste lands
151
+ * verbatim in `pasteBuffer` and survives `handlePaste`'s narrow strip).
152
+ * Cursor advances naturally via `insertCharacter` on typing/paste; cursor-
153
+ * movement keys (Left/Right/Home/End/word-jumps) are now functional, with
154
+ * the always-end visual cursor marker drawn independently by
155
+ * `WrappingSelect.renderInlineInputRow`. `viewAdapter.apply` is called
156
+ * directly without a reducer round-trip — preserves the D3 fast-path
157
+ * latency profile from Phase 11.
149
158
  */
150
159
  private handleIgnoreInline(data: string): void {
151
160
  if (!this.state.inputMode) return;
152
- if (BACKSPACE_CHARS.has(data)) {
153
- this.inputBuffer.backspace();
154
- this.viewAdapter.apply(this.state);
155
- } else if (data && !data.startsWith(ESC_SEQUENCE_PREFIX)) {
156
- this.inputBuffer.append(data);
157
- this.viewAdapter.apply(this.state);
158
- }
161
+ this.inlineInput.handleInput(data);
162
+ this.viewAdapter.apply(this.state);
159
163
  }
160
164
 
161
165
  private runtime(): QuestionnaireRuntime {
162
166
  return {
163
167
  keybindings: getKeybindings(),
164
- inputBuffer: this.inputBuffer.get(),
168
+ inputBuffer: this.inlineInput.getValue(),
165
169
  questions: this.questions,
166
170
  isMulti: this.isMulti,
167
171
  currentItem: this.currentItem(),
@@ -14,9 +14,10 @@ export interface OptionListViewConfig {
14
14
 
15
15
  /**
16
16
  * Per-tick projection of OptionListView state. After Phase 11b, `inputBuffer`
17
- * is part of the props bag — the session-owned `InputBuffer` cell value flows
18
- * here per tick. `OptionListView` is now purely props-driven; the imperative
19
- * buffer surface and read-back getters are gone.
17
+ * is part of the props bag — the session-owned `inlineInput` (a headless
18
+ * `pi-tui` Input instance) supplies its current `getValue()` here per tick.
19
+ * `OptionListView` is purely props-driven; the imperative buffer surface and
20
+ * read-back getters are gone.
20
21
  */
21
22
  export interface OptionListViewProps {
22
23
  selectedIndex: number;
@@ -121,26 +121,8 @@ export class WrappingSelect implements Component {
121
121
  this.confirmedLabelOverride = labelOverride;
122
122
  }
123
123
 
124
- getInputBuffer(): string {
125
- return this.inputBuffer;
126
- }
127
-
128
124
  setInputBuffer(text: string): void {
129
- this.inputBuffer = this.stripControlChars(text);
130
- }
131
-
132
- appendInput(text: string): void {
133
- const printable = this.stripControlChars(text);
134
- if (printable) this.inputBuffer += printable;
135
- }
136
-
137
- backspaceInput(): void {
138
- if (this.inputBuffer.length === 0) return;
139
- this.inputBuffer = Array.from(this.inputBuffer).slice(0, -1).join("");
140
- }
141
-
142
- clearInputBuffer(): void {
143
- this.inputBuffer = "";
125
+ this.inputBuffer = text;
144
126
  }
145
127
 
146
128
  /** Intentionally empty — input is routed at the container level. */
@@ -252,10 +234,4 @@ export class WrappingSelect implements Component {
252
234
  const wrapped = wrapTextWithAnsi(description, contentWidth);
253
235
  return wrapped.map((segment) => `${continuationPrefix}${this.theme.description(segment)}`);
254
236
  }
255
-
256
- private stripControlChars(text: string): string {
257
- return Array.from(text)
258
- .filter((c) => c >= " ")
259
- .join("");
260
- }
261
237
  }
@@ -1,4 +1,4 @@
1
- import type { InputBuffer } from "../state/input-buffer.js";
1
+ import type { Input } from "@mariozechner/pi-tui";
2
2
  import type { BindingContext, PerTabBindingContext } from "../state/selectors/contract.js";
3
3
  import { selectActivePreviewPaneIndex } from "../state/selectors/derivations.js";
4
4
  import { selectActiveView } from "../state/selectors/focus.js";
@@ -18,7 +18,7 @@ export interface QuestionnairePropsAdapterConfig {
18
18
  questions: readonly QuestionData[];
19
19
  itemsByTab: ReadonlyArray<readonly WrappingSelectItem[]>;
20
20
  tabsByIndex: ReadonlyArray<TabComponents>;
21
- inputBuffer: InputBuffer;
21
+ inlineInput: Input;
22
22
  globalBindings: ReadonlyArray<BoundGlobalBinding>;
23
23
  perTabBindings: ReadonlyArray<BoundPerTabBinding>;
24
24
  /**
@@ -34,16 +34,16 @@ export interface QuestionnairePropsAdapterConfig {
34
34
  * two binding registries. `globalBindings` covers the cross-tab components
35
35
  * (chatRow, dialog, submitPicker?, tabBar?); `perTabBindings` covers the
36
36
  * per-tab kinds (optionList, preview, multiSelect?). The hand-coded fan-out
37
- * collapses to one global loop + one nested per-tab loop. The `inputBuffer`
38
- * cell is read per tick into ctx so `selectOptionListProps` sees the live
39
- * value.
37
+ * collapses to one global loop + one nested per-tab loop. The inline-Other
38
+ * value is read from the headless `inlineInput` instance per tick into ctx so
39
+ * `selectOptionListProps` sees the live value.
40
40
  */
41
41
  export class QuestionnairePropsAdapter {
42
42
  private readonly tui: QuestionnairePropsAdapterConfig["tui"];
43
43
  private readonly questions: readonly QuestionData[];
44
44
  private readonly itemsByTab: ReadonlyArray<readonly WrappingSelectItem[]>;
45
45
  private readonly tabsByIndex: ReadonlyArray<TabComponents>;
46
- private readonly inputBuffer: InputBuffer;
46
+ private readonly inlineInput: Input;
47
47
  private readonly globalBindings: ReadonlyArray<BoundGlobalBinding>;
48
48
  private readonly perTabBindings: ReadonlyArray<BoundPerTabBinding>;
49
49
  private readonly extraInvalidatables: ReadonlyArray<Invalidatable>;
@@ -53,7 +53,7 @@ export class QuestionnairePropsAdapter {
53
53
  this.questions = config.questions;
54
54
  this.itemsByTab = config.itemsByTab;
55
55
  this.tabsByIndex = config.tabsByIndex;
56
- this.inputBuffer = config.inputBuffer;
56
+ this.inlineInput = config.inlineInput;
57
57
  this.globalBindings = config.globalBindings;
58
58
  this.perTabBindings = config.perTabBindings;
59
59
  this.extraInvalidatables = config.extraInvalidatables ?? [];
@@ -70,7 +70,7 @@ export class QuestionnairePropsAdapter {
70
70
  itemsByTab: this.itemsByTab,
71
71
  totalQuestions,
72
72
  activeView,
73
- inputBuffer: this.inputBuffer.get(),
73
+ inputBuffer: this.inlineInput.getValue(),
74
74
  activePreviewPane,
75
75
  };
76
76
 
@@ -1,31 +0,0 @@
1
- /**
2
- * Session-owned input-buffer cell. Mutable by design — the reducer never
3
- * touches it. Mutation paths: effect handlers (`set_input_buffer`,
4
- * `clear_input_buffer`) and the inline-key fast path (`handleIgnoreInline`
5
- * for printable keys + backspace). The value flows to the view per tick via
6
- * `runtime.inputBuffer` → `selectOptionListProps` → OptionListView.
7
- */
8
- export class InputBuffer {
9
- private value = "";
10
-
11
- get(): string {
12
- return this.value;
13
- }
14
-
15
- set(value: string): void {
16
- this.value = value;
17
- }
18
-
19
- clear(): void {
20
- this.value = "";
21
- }
22
-
23
- append(chunk: string): void {
24
- this.value = this.value + chunk;
25
- }
26
-
27
- backspace(): void {
28
- if (this.value.length === 0) return;
29
- this.value = this.value.slice(0, -1);
30
- }
31
- }