@juicesharp/rpiv-ask-user-question 2.8.0 → 2.10.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.
@@ -18,6 +18,7 @@ import {
18
18
  import { type DialogUI, hasDialogUI, runRpcQuestionnaire } from "./rpc-fallback.js";
19
19
  import { displayLabel, t } from "./state/i18n-bridge.js";
20
20
  import { sentinelsToAppend } from "./state/row-intent.js";
21
+ import { normalizeQuestionParams } from "./tool/normalize-params.js";
21
22
  import { buildQuestionnaireResponse, buildToolResult } from "./tool/response-envelope.js";
22
23
  import {
23
24
  MAX_OPTIONS,
@@ -310,7 +311,10 @@ export function registerAskUserQuestionTool(pi: ExtensionAPI): void {
310
311
  parameters: QuestionParamsSchema,
311
312
 
312
313
  async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
313
- const typed = params as unknown as QuestionParams;
314
+ // Line-terminator normalization runs once here, ahead of validation, so
315
+ // every downstream consumer — validator, TUI, RPC walker, envelope, prompt
316
+ // event — sees the same clean text (#192).
317
+ const typed = normalizeQuestionParams(params as unknown as QuestionParams);
314
318
  if (!ctx.hasUI) return rejectWithoutUi();
315
319
 
316
320
  const validation = validateQuestionnaire(typed);
package/events.ts CHANGED
@@ -38,7 +38,11 @@ export interface AskUserBlockedEventPayload {
38
38
  }
39
39
 
40
40
  export interface AskUserPromptQuestion {
41
- /** The full question text, exactly as the agent authored it. */
41
+ /**
42
+ * The full question text as the agent authored it, with line terminators
43
+ * normalized at tool entry (`\r\n` → `\n`, lone `\r` removed — #192). The
44
+ * same normalization applies to `header` and every option field below.
45
+ */
42
46
  question: string;
43
47
  /** The short chip/tag shown next to the question. */
44
48
  header: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juicesharp/rpiv-ask-user-question",
3
- "version": "2.8.0",
3
+ "version": "2.10.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",
@@ -56,6 +56,7 @@
56
56
  "state/state-reducer.ts",
57
57
  "state/state.ts",
58
58
  "tool/format-answer.ts",
59
+ "tool/normalize-params.ts",
59
60
  "tool/response-envelope.ts",
60
61
  "tool/types.ts",
61
62
  "tool/validate-questionnaire.ts",
@@ -94,7 +95,7 @@
94
95
  }
95
96
  },
96
97
  "dependencies": {
97
- "@juicesharp/rpiv-config": "^2.8.0",
98
+ "@juicesharp/rpiv-config": "^2.10.0",
98
99
  "typebox": "^1.1.24"
99
100
  }
100
101
  }
@@ -0,0 +1,56 @@
1
+ import type { QuestionParams } from "./types.js";
2
+
3
+ /**
4
+ * Normalize line terminators in one model-supplied text field (#192).
5
+ *
6
+ * Some models serialize a bare carriage return inside tool-call string
7
+ * arguments at token boundaries where the text was meant to be contiguous
8
+ * (`GEMBA\r_LOG\r_FILE` for `GEMBA_LOG_FILE`). A raw CR is a cursor-control
9
+ * byte, not text: pi-tui ≤0.80 writes it straight into the row, so the
10
+ * terminal returns to column 0 and later text overwrites the pointer and
11
+ * number; pi-tui ≥0.84 splits `wrapTextWithAnsi` on `\r`, so one option
12
+ * fragments into stacked rows. Both symptoms have the same fix at our
13
+ * boundary:
14
+ *
15
+ * - `\r\n` → `\n` keeps genuine multi-line content (preview markdown) intact.
16
+ * - a lone `\r` is deleted — never a space (phantom gaps inside words) and
17
+ * never `\n` (reintroduces the vertical fragmentation). This matches
18
+ * pi-coding-agent's own display normalization (`normalizeDisplayText`).
19
+ */
20
+ export function normalizeLineTerminators(text: string): string {
21
+ return text.replace(/\r\n/g, "\n").replace(/\r/g, "");
22
+ }
23
+
24
+ /**
25
+ * Copy `obj`, normalizing the listed keys that hold strings. Keys absent from
26
+ * `obj` (e.g. an omitted `preview`) stay absent so `"preview" in option`
27
+ * checks and `hasPreview` derivations are unchanged.
28
+ */
29
+ function normalizeStringFields<T extends object>(obj: T, keys: readonly (keyof T)[]): T {
30
+ const out = { ...obj };
31
+ for (const key of keys) {
32
+ const value = obj[key];
33
+ if (typeof value === "string") out[key] = normalizeLineTerminators(value) as T[typeof key];
34
+ }
35
+ return out;
36
+ }
37
+
38
+ /**
39
+ * Return a copy of the tool params with every user-facing string field
40
+ * (`question`, `header`, `options[].label`, `options[].description`,
41
+ * `options[].preview`) line-terminator-normalized. Runs once at tool entry,
42
+ * BEFORE `validateQuestionnaire`, so the reserved-label and duplicate-label
43
+ * guards compare the text the user will actually see (`"Other\r"` must not
44
+ * slip past `reserved_label`), and so the TUI, the RPC dialog walker, the
45
+ * envelope echo, and the `rpiv:ask-user:prompt` payload all carry the same
46
+ * clean text. Pure: the input object is never mutated.
47
+ */
48
+ export function normalizeQuestionParams(params: QuestionParams): QuestionParams {
49
+ return {
50
+ ...params,
51
+ questions: params.questions.map((q) => ({
52
+ ...normalizeStringFields(q, ["question", "header"]),
53
+ options: q.options.map((o) => normalizeStringFields(o, ["label", "description", "preview"])),
54
+ })),
55
+ };
56
+ }
@@ -13,7 +13,7 @@ export interface OptionListViewConfig {
13
13
  }
14
14
 
15
15
  /**
16
- * Per-tick projection of OptionListView state. After Phase 11b, `inputBuffer`
16
+ * Per-tick projection of OptionListView state. `inputBuffer`
17
17
  * is part of the props bag — the session-owned `inlineInput` (a headless
18
18
  * `pi-tui` Editor instance) supplies its current `getText()` here per tick.
19
19
  * `OptionListView` is purely props-driven; the imperative buffer surface and
@@ -6,8 +6,7 @@ import type { StatefulView } from "../stateful-view.js";
6
6
  * Per-tick projection of TabBar state. The selector
7
7
  * (`selectTabBarProps`) hoists every render-time derivation
8
8
  * (`allAnswered`, `answered`, `isActive`, `submitActive`) into props so
9
- * `render()` is pure styling. Replaces the prior `setConfig(TabBarConfig)`
10
- * snowflake and the inline `+ 1` magic at `props-adapter.ts:127`.
9
+ * `render()` is pure styling.
11
10
  */
12
11
  export interface TabBarProps {
13
12
  /** One per author-defined question, in order. */