@juicesharp/rpiv-ask-user-question 1.1.3 → 1.1.5

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
@@ -11,20 +11,20 @@
11
11
  [![npm version](https://img.shields.io/npm/v/@juicesharp/rpiv-ask-user-question.svg)](https://www.npmjs.com/package/@juicesharp/rpiv-ask-user-question)
12
12
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
13
13
 
14
- Let the model ask you structured clarifying questions instead of guessing. `rpiv-ask-user-question` adds the `ask_user_question` tool to [Pi Agent](https://github.com/badlogic/pi-mono) — a tabbed dialog with single- and multi-select questions, side-by-side previews, per-option notes, and a Submit tab that reviews answers before they go back to the model.
14
+ Let the model ask you structured clarifying questions instead of guessing. `rpiv-ask-user-question` adds the `ask_user_question` tool to [Pi Agent](https://github.com/badlogic/pi-mono) - a tabbed dialog with single- and multi-select questions, side-by-side previews, per-option notes, and a Submit tab that reviews answers before they go back to the model.
15
15
 
16
16
  ![Side-by-side code preview](https://raw.githubusercontent.com/juicesharp/rpiv-mono/main/packages/rpiv-ask-user-question/docs/code-preview.jpg)
17
17
 
18
18
  ## Features
19
19
 
20
- - **Multi-question dialogs** — ask several questions in one turn with a tab bar (`Tab` to switch).
21
- - **Preview pane** — render an ASCII diagram, code snippet, or markdown next to each option, side-by-side or stacked depending on terminal width.
22
- - **Per-option notes** — press `n` on a previewed option to attach a free-text note that travels back with the answer.
23
- - **Multi-select questions** — checkboxes with `Space` to toggle, Enter-as-toggle on rows, a `Next` sentinel to advance, and toggles persisted across tab switches.
24
- - **Submit tab** — review every answer before submitting; warns about unanswered questions and offers a Submit picker.
25
- - **Chat row on every tab** — redirect the conversation without leaving the dialog.
26
- - **"Other" free-text fallback** — type a custom answer when no option fits.
27
- - **Localized UI** — sentinel rows, hints, submit/cancel labels, review pane, and notes affordance display in the user's chosen language via `@juicesharp/rpiv-i18n`. Ships Deutsch / English / Español / Français / Português (PT) / Português (BR) / Русский / Українська; switch with `/languages` or `pi --locale <code>`. LLM-facing copy (tool description, schemas, errors) stays English by design.
20
+ - **Multi-question dialogs** - ask several questions in one turn with a tab bar (`Tab` to switch).
21
+ - **Preview pane** - render an ASCII diagram, code snippet, or markdown next to each option, side-by-side or stacked depending on terminal width.
22
+ - **Per-option notes** - press `n` on a previewed option to attach a free-text note that travels back with the answer.
23
+ - **Multi-select questions** - checkboxes with `Space` to toggle, Enter-as-toggle on rows, a `Next` sentinel to advance, and toggles persisted across tab switches.
24
+ - **Submit tab** - review every answer before submitting; warns about unanswered questions and offers a Submit picker.
25
+ - **Chat row on every tab** - redirect the conversation without leaving the dialog.
26
+ - **"Other" free-text fallback** - type a custom answer when no option fits.
27
+ - **Localized UI** - sentinel rows, hints, submit/cancel labels, review pane, and notes affordance display in the user's chosen language via `@juicesharp/rpiv-i18n`. Ships Deutsch / English / Español / Français / Português (PT) / Português (BR) / Русский / Українська; switch with `/languages` or `pi --locale <code>`. LLM-facing copy (tool description, schemas, errors) stays English by design.
28
28
 
29
29
  ## Screens
30
30
 
@@ -32,7 +32,7 @@ Let the model ask you structured clarifying questions instead of guessing. `rpiv
32
32
  |---|---|
33
33
  | ![Single-question dialog](https://raw.githubusercontent.com/juicesharp/rpiv-mono/main/packages/rpiv-ask-user-question/docs/single-question.jpg) | ![Multi-tab + ASCII preview](https://raw.githubusercontent.com/juicesharp/rpiv-mono/main/packages/rpiv-ask-user-question/docs/multi-tab-preview.jpg) |
34
34
  | ![Multi-select with checkboxes](https://raw.githubusercontent.com/juicesharp/rpiv-mono/main/packages/rpiv-ask-user-question/docs/multi-select.jpg) | ![Submit tab review](https://raw.githubusercontent.com/juicesharp/rpiv-mono/main/packages/rpiv-ask-user-question/docs/submit-tab.jpg) |
35
- | ![Localized UI — German](https://raw.githubusercontent.com/juicesharp/rpiv-mono/main/packages/rpiv-ask-user-question/docs/localized-german-ui.jpg) | |
35
+ | ![Localized UI - German](https://raw.githubusercontent.com/juicesharp/rpiv-mono/main/packages/rpiv-ask-user-question/docs/localized-german-ui.jpg) | |
36
36
 
37
37
  ## Install
38
38
 
@@ -42,19 +42,66 @@ pi install npm:@juicesharp/rpiv-ask-user-question
42
42
 
43
43
  Then restart your Pi session.
44
44
 
45
- ### Optional: language picker + `--locale` flag
45
+ ### Optional: localization
46
46
 
47
- The dialog auto-detects your UI locale from `LANG` / `LC_ALL` and falls back to English; with that alone, a user whose shell is set to e.g. `pt_BR.UTF-8` already sees Portuguese without any extra step. To **change locale interactively** (`/languages` slash command) or **pin one at startup** (`pi --locale uk`), also install the SDK that owns those surfaces:
47
+ `rpiv-ask-user-question` works standalone - install only this package and you get the full English UI. Install `@juicesharp/rpiv-i18n` alongside it to flip sentinel labels, dialog hints, review-tab heading, and chat-summary lines to your active locale:
48
48
 
49
49
  ```bash
50
50
  pi install npm:@juicesharp/rpiv-i18n
51
51
  ```
52
52
 
53
- Without it, locale detection still works via `~/.config/rpiv-i18n/locale.json` (hand-edit `{"locale":"uk"}` and restart) and your shell environment — only the picker and flag are missing. Users who installed via `pi install npm:@juicesharp/rpiv-pi` + `/rpiv-setup` get the SDK automatically.
53
+ With the SDK present, locale resolves from `--locale <code>` → `~/.config/rpiv-i18n/locale.json` → `LANG` / `LC_ALL` → English. The `/languages` interactive picker and `pi --locale <code>` startup flag are also enabled. Without the SDK, the dialog stays online and renders English at every call site - no warning, no crash. Users who installed via `pi install npm:@juicesharp/rpiv-pi` + `/rpiv-setup` get the SDK automatically.
54
54
 
55
55
  ## Tool
56
56
 
57
- - **`ask_user_question`** — present one or more structured questions, each with 2+ options, optional `multiSelect`, optional per-option `preview`, and an optional free-text "Other" fallback. Returns the user's selection(s) plus any notes. See the tool's `promptGuidelines` for usage policy.
57
+ - **`ask_user_question`** - present one or more structured questions, each with 2+ options, optional `multiSelect`, optional per-option `preview`, and an optional free-text "Other" fallback. Returns the user's selection(s) plus any notes. See the tool's `promptGuidelines` for usage policy.
58
+
59
+ ### Schema
60
+
61
+ ```ts
62
+ ask_user_question({
63
+ questions: [
64
+ {
65
+ question: string, // full question text, ends with "?"
66
+ header: string, // chip label, max 12 chars
67
+ options: [
68
+ {
69
+ label: string, // 1-5 words, max 60 chars
70
+ description: string, // explains the choice / its trade-off
71
+ preview?: string, // optional markdown shown next to options
72
+ },
73
+ // … 2-4 options total
74
+ ],
75
+ multiSelect?: boolean, // default false
76
+ },
77
+ // … 1-4 questions total
78
+ ]
79
+ })
80
+ ```
81
+
82
+ Reserved option labels (rejected at validation): `"Other"`, plus the runtime sentinels (`"Type something."`, `"Chat about this"`, `"Next →"`).
83
+
84
+ Returns:
85
+
86
+ ```ts
87
+ {
88
+ content: [{ type: "text", text: string }], // human-readable envelope or DECLINE_MESSAGE
89
+ details: {
90
+ answers: Array<{
91
+ questionIndex: number,
92
+ question: string,
93
+ kind: "option" | "custom" | "chat" | "multi",
94
+ answer: string | null,
95
+ selected?: string[], // present for multi-select
96
+ notes?: string, // free-text note, when typed
97
+ preview?: string, // echoed back when option carried a preview
98
+ }>,
99
+ cancelled: boolean,
100
+ error?: "no_ui" | "no_questions" | "empty_options" | "too_many_questions"
101
+ | "duplicate_question" | "duplicate_option_label" | "reserved_label",
102
+ }
103
+ }
104
+ ```
58
105
 
59
106
  ## License
60
107
 
@@ -58,7 +58,7 @@ Preview content is rendered as markdown in a monospace box. Multi-line text with
58
58
  `Use ask_user_question whenever the user's request is underspecified and you cannot proceed without concrete decisions — you can ask up to ${MAX_QUESTIONS} questions per invocation.`,
59
59
  `Each question MUST have ${MIN_OPTIONS}-${MAX_OPTIONS} options. Every option requires a concise label (1-5 words) and a description explaining what the choice means or its trade-offs. The user can additionally type a custom answer ("Type something." row is appended automatically to single-select questions) or pick "Chat about this" to abandon the questionnaire.`,
60
60
  `Set multiSelect: true when multiple answers are valid; this suppresses the "Type something." row. Provide an options[].preview markdown string when an option benefits from richer side-by-side context (mockups, code snippets, diagrams, configs) — single-select only. NOTE: any non-empty preview on a single-select question ALSO suppresses the "Type something." row (no room in the side-by-side layout); "Chat about this" remains the escape hatch. If you recommend a specific option, make it the first option and append "(Recommended)" to its label.`,
61
- "This replaces the AskUserQuestion tool from Claude Code. Do not stack multiple ask_user_question calls back-to-back — group all clarifying questions into one invocation.",
61
+ "Do not stack multiple ask_user_question calls back-to-back — group all clarifying questions into one invocation.",
62
62
  ],
63
63
  parameters: QuestionParamsSchema,
64
64
 
package/index.ts CHANGED
@@ -2,9 +2,12 @@
2
2
  * rpiv-ask-user-question — Pi extension. Registers the `ask_user_question`
3
3
  * tool: a structured option selector with a free-text "Other" fallback.
4
4
  *
5
- * Sentinel labels (and TUI chrome strings in subsequent phases) localize at
6
- * render time via the i18n bridge. Strings are registered with rpiv-i18n
7
- * here, once, at module init.
5
+ * Sentinel labels and TUI chrome strings localize at render time via the i18n
6
+ * bridge. Strings are registered with rpiv-i18n here, once, at module init —
7
+ * but only when the SDK is actually installed. If `@juicesharp/rpiv-i18n` is
8
+ * missing (standalone install of just this package), the dynamic-load shim
9
+ * no-ops and the bridge's `t(key, fallback)` returns the inline English literal
10
+ * at every call site. The extension stays online either way.
8
11
  *
9
12
  * Adding a locale: drop `locales/<code>.json` next to en.json (mirroring the
10
13
  * key set), then add the load + entry to the `registerStrings` call below.
@@ -14,11 +17,13 @@
14
17
 
15
18
  import { readFileSync } from "node:fs";
16
19
  import { fileURLToPath } from "node:url";
17
- import { registerStrings, type TranslationMap } from "@juicesharp/rpiv-i18n";
18
20
  import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
19
21
  import { registerAskUserQuestionTool } from "./ask-user-question.js";
20
22
  import { I18N_NAMESPACE } from "./state/i18n-bridge.js";
21
23
 
24
+ type TranslationMap = Readonly<Record<string, string>>;
25
+ type I18nSDK = { registerStrings: (namespace: string, byLocale: Record<string, TranslationMap>) => void };
26
+
22
27
  function loadLocale(code: string): TranslationMap {
23
28
  // A missing or malformed locale file degrades gracefully: registerStrings
24
29
  // records an empty map for the locale, so render-time `tr(key, fallback)`
@@ -37,16 +42,25 @@ function loadLocale(code: string): TranslationMap {
37
42
  }
38
43
  }
39
44
 
40
- registerStrings(I18N_NAMESPACE, {
41
- de: loadLocale("de"),
42
- en: loadLocale("en"),
43
- es: loadLocale("es"),
44
- fr: loadLocale("fr"),
45
- pt: loadLocale("pt"),
46
- "pt-BR": loadLocale("pt-BR"),
47
- ru: loadLocale("ru"),
48
- uk: loadLocale("uk"),
49
- });
45
+ // Dynamic import keeps `@juicesharp/rpiv-i18n` a soft optional peer: when the
46
+ // SDK is installed alongside this package the strings register and
47
+ // `/languages` flips them live; when it isn't, the import rejects here, we
48
+ // no-op, and the bridge's English-fallback shim keeps the extension online.
49
+ try {
50
+ const sdk = (await import("@juicesharp/rpiv-i18n")) as I18nSDK;
51
+ sdk.registerStrings(I18N_NAMESPACE, {
52
+ de: loadLocale("de"),
53
+ en: loadLocale("en"),
54
+ es: loadLocale("es"),
55
+ fr: loadLocale("fr"),
56
+ pt: loadLocale("pt"),
57
+ "pt-BR": loadLocale("pt-BR"),
58
+ ru: loadLocale("ru"),
59
+ uk: loadLocale("uk"),
60
+ });
61
+ } catch {
62
+ // SDK absent — extension still loads with English-only UI.
63
+ }
50
64
 
51
65
  export default function (pi: ExtensionAPI) {
52
66
  registerAskUserQuestionTool(pi);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@juicesharp/rpiv-ask-user-question",
3
- "version": "1.1.3",
4
- "description": "Pi extension: lets the model ask you a clarifying question with structured options instead of guessing",
3
+ "version": "1.1.5",
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",
7
7
  "pi-extension",
@@ -75,5 +75,10 @@
75
75
  "@mariozechner/pi-coding-agent": "*",
76
76
  "@mariozechner/pi-tui": "*",
77
77
  "typebox": "*"
78
+ },
79
+ "peerDependenciesMeta": {
80
+ "@juicesharp/rpiv-i18n": {
81
+ "optional": true
82
+ }
78
83
  }
79
84
  }
@@ -1,8 +1,13 @@
1
1
  /**
2
2
  * i18n bridge for rpiv-ask-user-question — single thin import surface so every
3
- * call site routes through one place. Backed by `@juicesharp/rpiv-i18n`'s SDK.
3
+ * call site routes through one place. Backed by `@juicesharp/rpiv-i18n`'s SDK
4
+ * when available; degrades to canonical-English fallbacks when not.
4
5
  *
5
- * - `t(key, fallback)` is `scope("@juicesharp/rpiv-ask-user-question")`.
6
+ * - `t(key, fallback)` is `scope("@juicesharp/rpiv-ask-user-question")` if the
7
+ * SDK is installed (live `/languages` updates propagate). If the SDK is
8
+ * missing (standalone install without rpiv-i18n), `t` is an identity
9
+ * passthrough that returns the inline English fallback at every call site,
10
+ * so the extension stays online with English UI.
6
11
  * - `displayLabel(kind)` resolves a sentinel kind to its locale-aware label,
7
12
  * with the canonical English `ROW_INTENT_META[kind].label` as fallback so
8
13
  * nothing renders blank if the namespace isn't registered.
@@ -15,12 +20,31 @@
15
20
  * the canonical `ROW_INTENT_META[kind].label`, never `displayLabel(kind)`.
16
21
  */
17
22
 
18
- import { scope } from "@juicesharp/rpiv-i18n";
19
23
  import { ROW_INTENT_META, type SentinelKind } from "./row-intent.js";
20
24
 
21
25
  export const I18N_NAMESPACE = "@juicesharp/rpiv-ask-user-question";
22
26
 
23
- export const t = scope(I18N_NAMESPACE);
27
+ type ScopeFn = (key: string, fallback: string) => string;
28
+ type I18nSDK = { scope: (namespace: string) => ScopeFn };
29
+
30
+ // Prefer the live SDK if installed: closures it returns track the active
31
+ // locale, so /languages picker propagates to our render call sites. If the
32
+ // SDK isn't installed (standalone install of this extension without
33
+ // rpiv-i18n), the dynamic import fails, every t(key, fallback) returns the
34
+ // canonical English literal, and the extension stays online.
35
+ //
36
+ // Top-level await is required so a synchronous `t(...)` call from any
37
+ // downstream module sees the resolved scope; ESM module loading awaits this
38
+ // before evaluating any importer.
39
+ let scopeImpl: ScopeFn;
40
+ try {
41
+ const sdk = (await import("@juicesharp/rpiv-i18n")) as I18nSDK;
42
+ scopeImpl = sdk.scope(I18N_NAMESPACE);
43
+ } catch {
44
+ scopeImpl = (_key, fallback) => fallback;
45
+ }
46
+
47
+ export const t: ScopeFn = scopeImpl;
24
48
 
25
49
  export function displayLabel(kind: SentinelKind): string {
26
50
  return t(`sentinel.${kind}`, ROW_INTENT_META[kind].label);