@juicesharp/rpiv-ask-user-question 2.0.0 → 2.2.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.
- package/README.md +68 -86
- package/ask-user-question.ts +48 -9
- package/docs/configuration.md +112 -0
- package/docs/hosts.md +87 -0
- package/docs/keyboard.md +96 -0
- package/docs/localization.md +83 -0
- package/docs/tool-schema.md +121 -0
- package/events.ts +12 -0
- package/index.ts +4 -1
- package/locales/de.json +5 -1
- package/locales/en.json +4 -0
- package/locales/es.json +5 -1
- package/locales/fr.json +5 -1
- package/locales/pt-BR.json +5 -1
- package/locales/pt.json +5 -1
- package/locales/ru.json +5 -1
- package/locales/uk.json +5 -1
- package/locales/zh.json +4 -0
- package/package.json +7 -2
- package/state/build-questionnaire.ts +28 -12
- package/state/external-editor.ts +62 -0
- package/state/key-router.ts +53 -10
- package/state/questionnaire-session.ts +45 -33
- package/state/selectors/derivations.ts +0 -16
- package/state/state-reducer.ts +62 -23
- package/state/state.ts +4 -2
- package/tool/types.ts +2 -2
- package/view/components/inline-input.ts +20 -50
- package/view/components/multi-select-view.ts +70 -84
- package/view/components/option-list-view.ts +1 -1
- package/view/components/wrapping-select.ts +15 -18
- package/view/dialog-builder.ts +17 -10
- package/view/props-adapter.ts +11 -17
- package/view/tab-content-strategy.ts +12 -10
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# Localization
|
|
2
|
+
|
|
3
|
+
How the dialog picks its language, which languages ship, and how to add one.
|
|
4
|
+
|
|
5
|
+
## Enabling it
|
|
6
|
+
|
|
7
|
+
The extension works standalone: install only this package and you get the full dialog in
|
|
8
|
+
English. Localization needs one more install:
|
|
9
|
+
|
|
10
|
+
```sh
|
|
11
|
+
pi install npm:@juicesharp/rpiv-i18n
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Restart your Pi session. If you installed through
|
|
15
|
+
[`@juicesharp/rpiv-pi`](https://www.npmjs.com/package/@juicesharp/rpiv-pi) and ran
|
|
16
|
+
`/rpiv-setup`, you already have it.
|
|
17
|
+
|
|
18
|
+
The dependency is a genuinely optional peer. This package loads the SDK inside a
|
|
19
|
+
`try`/`catch` at startup; when it is absent, every string falls back to its inline English
|
|
20
|
+
literal at the call site. There is no warning and no crash — the dialog simply renders in
|
|
21
|
+
English.
|
|
22
|
+
|
|
23
|
+
## Picking a language
|
|
24
|
+
|
|
25
|
+
With the SDK installed, the locale resolves in this order, first hit wins:
|
|
26
|
+
|
|
27
|
+
1. `pi --locale <code>` on the command line
|
|
28
|
+
2. `~/.config/rpiv-i18n/locale.json`
|
|
29
|
+
3. `LANG` / `LC_ALL` from the environment
|
|
30
|
+
4. English
|
|
31
|
+
|
|
32
|
+
`/languages` opens an interactive picker and flips the strings live — the dialog reads its
|
|
33
|
+
strings at render time, so an open questionnaire follows the change. Both `/languages` and
|
|
34
|
+
`--locale` are registered by `@juicesharp/rpiv-i18n`, not by this package.
|
|
35
|
+
|
|
36
|
+
## Shipped languages
|
|
37
|
+
|
|
38
|
+
Nine locale files ship in `locales/`:
|
|
39
|
+
|
|
40
|
+
| Code | Language |
|
|
41
|
+
| --- | --- |
|
|
42
|
+
| `de` | Deutsch |
|
|
43
|
+
| `en` | English |
|
|
44
|
+
| `es` | Español |
|
|
45
|
+
| `fr` | Français |
|
|
46
|
+
| `pt` | Português |
|
|
47
|
+
| `pt-BR` | Português (Brasil) |
|
|
48
|
+
| `ru` | Русский |
|
|
49
|
+
| `uk` | Українська |
|
|
50
|
+
| `zh` | 中文 |
|
|
51
|
+
|
|
52
|
+
## What is translated, and what is not
|
|
53
|
+
|
|
54
|
+
Translation covers the chrome you read: the `Type something.` and `Next` sentinel rows,
|
|
55
|
+
the footer hint segments (including the collapsed-state line), the Submit picker labels,
|
|
56
|
+
the review-tab heading with its submit-readiness prompt and incomplete-answers warning, the
|
|
57
|
+
preview pane's empty and notes-affordance lines, the notes header, the external-editor
|
|
58
|
+
failure notification, and the two RPC dialog prompts. Twenty-three keys in total, all under the namespace
|
|
59
|
+
`@juicesharp/rpiv-ask-user-question`.
|
|
60
|
+
|
|
61
|
+
Everything the *model* reads stays English by design: the tool description, the parameter
|
|
62
|
+
schema descriptions, error messages, and the reserved-label list. Those are prompt inputs,
|
|
63
|
+
not UI, and translating them would change model behavior rather than your reading
|
|
64
|
+
experience. It also means reserved-label validation compares against fixed English
|
|
65
|
+
strings, so `Type something.` is rejected as an authored option label in every locale.
|
|
66
|
+
|
|
67
|
+
## Adding a language
|
|
68
|
+
|
|
69
|
+
No code change is required.
|
|
70
|
+
|
|
71
|
+
1. Copy `locales/en.json` to `locales/<code>.json`, where `<code>` is a locale the SDK
|
|
72
|
+
supports.
|
|
73
|
+
2. Translate the values. Keep every key, and keep the placeholders and leading symbols
|
|
74
|
+
(`↑/↓`, `⚠`) intact.
|
|
75
|
+
3. Restart Pi and select the language with `/languages`.
|
|
76
|
+
|
|
77
|
+
The loader iterates the SDK's supported-locale list over this directory at startup, so a
|
|
78
|
+
new file is picked up automatically. See the
|
|
79
|
+
[`@juicesharp/rpiv-i18n`](https://www.npmjs.com/package/@juicesharp/rpiv-i18n) README,
|
|
80
|
+
section "Contributing translations", for the full convention.
|
|
81
|
+
|
|
82
|
+
Keys are looked up individually with an English fallback, so a partially translated file
|
|
83
|
+
is safe — untranslated keys render in English rather than blank.
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# Tool schema
|
|
2
|
+
|
|
3
|
+
The complete programmatic surface of `ask_user_question`: what the model sends, what
|
|
4
|
+
validation rejects, what comes back, and the event other extensions can listen to.
|
|
5
|
+
|
|
6
|
+
## Parameters
|
|
7
|
+
|
|
8
|
+
```ts
|
|
9
|
+
ask_user_question({
|
|
10
|
+
questions: [
|
|
11
|
+
{
|
|
12
|
+
question: string, // full question text, ends with "?"
|
|
13
|
+
header: string, // chip label, max 16 chars
|
|
14
|
+
options: [
|
|
15
|
+
{
|
|
16
|
+
label: string, // 1-5 words, max 60 chars
|
|
17
|
+
description: string, // what the choice means / its trade-off
|
|
18
|
+
preview?: string, // markdown rendered next to the options
|
|
19
|
+
},
|
|
20
|
+
// … 2-4 options total
|
|
21
|
+
],
|
|
22
|
+
multiSelect?: boolean, // default false
|
|
23
|
+
},
|
|
24
|
+
// … 1-4 questions total
|
|
25
|
+
]
|
|
26
|
+
})
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Limits
|
|
30
|
+
|
|
31
|
+
| Field | Constraint | Enforced by |
|
|
32
|
+
| --- | --- | --- |
|
|
33
|
+
| `questions` | 1-4 entries | TypeBox schema + `validateQuestionnaire` |
|
|
34
|
+
| `questions[].header` | max 16 characters | TypeBox schema only |
|
|
35
|
+
| `questions[].options` | 2-4 entries | TypeBox schema (both bounds) + `validateQuestionnaire` (minimum only) |
|
|
36
|
+
| `options[].label` | max 60 characters | TypeBox schema only |
|
|
37
|
+
| `options[].preview` | single-select questions only | tool description (multi-select tabs render checkbox rows) |
|
|
38
|
+
|
|
39
|
+
The two `maxLength` limits are checked by the parameter schema before `execute` runs;
|
|
40
|
+
the runtime validator does not re-check them.
|
|
41
|
+
|
|
42
|
+
### Reserved option labels
|
|
43
|
+
|
|
44
|
+
Authoring any of `"Other"`, `"Type something."`, or `"Next"` as an option label is
|
|
45
|
+
rejected with `reserved_label`. The last two are the runtime sentinel rows the dialog
|
|
46
|
+
appends itself; `"Other"` is reserved because models are conditioned to reach for it.
|
|
47
|
+
Reservation is unconditional — a single-select question rejects `"Next"` even though
|
|
48
|
+
that row is never appended there.
|
|
49
|
+
|
|
50
|
+
## Validation errors
|
|
51
|
+
|
|
52
|
+
Every rejection returns `cancelled: true`, an empty `answers` array, and an `error`
|
|
53
|
+
code. The `content[0].text` string is written for the model, not for a log.
|
|
54
|
+
|
|
55
|
+
| `error` | Cause |
|
|
56
|
+
| --- | --- |
|
|
57
|
+
| `no_questions` | `questions` was empty |
|
|
58
|
+
| `too_many_questions` | more than 4 questions in one call |
|
|
59
|
+
| `duplicate_question` | two questions with identical text |
|
|
60
|
+
| `empty_options` | a question carried fewer than 2 options |
|
|
61
|
+
| `reserved_label` | an option used a reserved label |
|
|
62
|
+
| `duplicate_option_label` | two options in one question share a label |
|
|
63
|
+
| `no_ui` | the run has no UI (`ctx.hasUI === false`) |
|
|
64
|
+
| `no_custom_ui` | the host cannot render custom UI and exposes no `select`/`input` dialogs |
|
|
65
|
+
| `session_load_failed` | the dialog module failed to import (dependencies changed on disk mid-session) |
|
|
66
|
+
| `stale_module_cache` | the loader cached a broken module after an earlier failed import; needs a Pi restart |
|
|
67
|
+
|
|
68
|
+
`reserved_label` short-circuits before `duplicate_option_label`.
|
|
69
|
+
|
|
70
|
+
## Result
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
{
|
|
74
|
+
content: [{ type: "text", text: string }], // envelope prose, or the decline message
|
|
75
|
+
details: {
|
|
76
|
+
answers: Array<{
|
|
77
|
+
questionIndex: number,
|
|
78
|
+
question: string,
|
|
79
|
+
kind: "option" | "custom" | "multi",
|
|
80
|
+
answer: string | null, // option label, typed text, or null for multi
|
|
81
|
+
selected?: string[], // chosen labels, multi-select only
|
|
82
|
+
notes?: string, // free-text note, when you wrote one
|
|
83
|
+
preview?: string, // echoed back when the chosen option carried a preview
|
|
84
|
+
}>,
|
|
85
|
+
cancelled: boolean,
|
|
86
|
+
error?: QuestionnaireError, // one of the codes above
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Envelope text
|
|
92
|
+
|
|
93
|
+
On success the text reads `User has answered your questions: "<question>"="<answer>". …
|
|
94
|
+
You can now continue with the user's answers in mind.` A chosen option's `preview` is
|
|
95
|
+
appended as `selected preview: <markdown>`, and a note as `user notes: <text>`.
|
|
96
|
+
|
|
97
|
+
Cancelling, and any result that produces no answer segments, both collapse to the single
|
|
98
|
+
string `User declined to answer questions` so the model sees one canonical signal.
|
|
99
|
+
Partial submission is allowed: unanswered questions simply contribute no segment.
|
|
100
|
+
|
|
101
|
+
## Event contract
|
|
102
|
+
|
|
103
|
+
The package publishes one event on Pi's event bus, emitted after validation passes and
|
|
104
|
+
before the dialog is shown. Import it from the `/events` subpath:
|
|
105
|
+
|
|
106
|
+
```ts
|
|
107
|
+
import { ASK_USER_PROMPT_EVENT, type AskUserPromptEventPayload } from "@juicesharp/rpiv-ask-user-question/events";
|
|
108
|
+
|
|
109
|
+
pi.events.on(ASK_USER_PROMPT_EVENT, (payload: AskUserPromptEventPayload) => {
|
|
110
|
+
// payload.questions[].{ question, header, multiSelect, options[] }
|
|
111
|
+
// payload.questions[].options[].{ label, description, hasPreview }
|
|
112
|
+
});
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
The channel name is `rpiv:ask-user:prompt`. Preview *content* is deliberately not shipped
|
|
116
|
+
in the payload — only `hasPreview: boolean` — so listeners forwarding the event across a
|
|
117
|
+
process or network boundary stay cheap.
|
|
118
|
+
|
|
119
|
+
Stability policy for the `rpiv:*` namespace: channel names are immutable, payload changes
|
|
120
|
+
are append-only and always optional, payloads stay JSON-safe, and any breaking change ships
|
|
121
|
+
as a new channel (e.g. `rpiv:ask-user:prompt.v2`) rather than a version field.
|
package/events.ts
CHANGED
|
@@ -25,6 +25,18 @@ export interface AskUserPromptEventPayload {
|
|
|
25
25
|
questions: ReadonlyArray<AskUserPromptQuestion>;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
+
/**
|
|
29
|
+
* Emitted while the questionnaire is awaiting user input (TUI `ui.custom` and
|
|
30
|
+
* RPC dialog walker). Cleared with `{ active: false }` in `finally` so listeners
|
|
31
|
+
* can distinguish blocked-on-human from working.
|
|
32
|
+
*/
|
|
33
|
+
export const ASK_USER_BLOCKED_EVENT = "rpiv:ask-user:blocked" as const;
|
|
34
|
+
|
|
35
|
+
export interface AskUserBlockedEventPayload {
|
|
36
|
+
/** True while input is awaited; false when the wait ends (answer, cancel, or error). */
|
|
37
|
+
active: boolean;
|
|
38
|
+
}
|
|
39
|
+
|
|
28
40
|
export interface AskUserPromptQuestion {
|
|
29
41
|
/** The full question text, exactly as the agent authored it. */
|
|
30
42
|
question: string;
|
package/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* rpiv-ask-user-question — Pi extension. Registers the `ask_user_question`
|
|
3
|
-
* tool: a structured option selector with
|
|
3
|
+
* tool: a structured option selector with an automatically appended
|
|
4
|
+
* `Type something.` custom-answer row.
|
|
4
5
|
*
|
|
5
6
|
* Sentinel labels and TUI chrome strings localize at render time via the i18n
|
|
6
7
|
* bridge. Strings are registered with rpiv-i18n here, once, at module init —
|
|
@@ -39,7 +40,9 @@ try {
|
|
|
39
40
|
}
|
|
40
41
|
|
|
41
42
|
export {
|
|
43
|
+
ASK_USER_BLOCKED_EVENT,
|
|
42
44
|
ASK_USER_PROMPT_EVENT,
|
|
45
|
+
type AskUserBlockedEventPayload,
|
|
43
46
|
type AskUserPromptEventPayload,
|
|
44
47
|
type AskUserPromptOption,
|
|
45
48
|
type AskUserPromptQuestion,
|
package/locales/de.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"_meta.notes": "Auto-translated draft. Native-speaker review welcome via PR. TUI symbols (↑/↓, ⚠) and key names (Enter, Esc, Tab, Space, n) are universal CLI conventions and stay untranslated.",
|
|
2
|
+
"_meta.notes": "Auto-translated draft. Native-speaker review welcome via PR. TUI symbols (↑/↓, ⚠) and key names (Enter, Esc, Tab, Space, n, Ctrl+G, Ctrl+U) are universal CLI conventions and stay untranslated.",
|
|
3
3
|
|
|
4
4
|
"sentinel.other": "Schreibe etwas.",
|
|
5
5
|
"sentinel.next": "Weiter",
|
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
|
|
10
10
|
"hint.enter": "Enter zum Auswählen",
|
|
11
11
|
"hint.navigate": "↑/↓ zur Navigation",
|
|
12
|
+
"hint.newline": "Umschalt+Enter für neue Zeile",
|
|
13
|
+
"hint.clear": "Ctrl+U zum Leeren",
|
|
12
14
|
"hint.toggle": "Leertaste zum Umschalten",
|
|
13
15
|
"hint.notes": "n für Notizen",
|
|
14
16
|
"hint.tab": "Tab wechselt die Frage",
|
|
@@ -22,6 +24,8 @@
|
|
|
22
24
|
"preview.notes_affordance": "Notizen: drücke n, um Notizen hinzuzufügen",
|
|
23
25
|
"notes.header": "Notizen:",
|
|
24
26
|
|
|
27
|
+
"editor.failed": "Externer Editor fehlgeschlagen",
|
|
28
|
+
|
|
25
29
|
"rpc.multi_instructions": "Gib die Nummern aller zutreffenden Optionen durch Komma getrennt ein (z. B. \"1,3\") oder tippe eine eigene Antwort als Text.",
|
|
26
30
|
"rpc.custom_answer_title": "Gib deine Antwort ein:"
|
|
27
31
|
}
|
package/locales/en.json
CHANGED
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
|
|
8
8
|
"hint.enter": "Enter to select",
|
|
9
9
|
"hint.navigate": "↑/↓ to navigate",
|
|
10
|
+
"hint.newline": "Shift+Enter for newline",
|
|
11
|
+
"hint.clear": "Ctrl+U to clear",
|
|
10
12
|
"hint.toggle": "Space to toggle",
|
|
11
13
|
"hint.notes": "n to add notes",
|
|
12
14
|
"hint.tab": "Tab to switch questions",
|
|
@@ -22,6 +24,8 @@
|
|
|
22
24
|
"preview.notes_affordance": "Notes: press n to add notes",
|
|
23
25
|
"notes.header": "Notes:",
|
|
24
26
|
|
|
27
|
+
"editor.failed": "External editor failed",
|
|
28
|
+
|
|
25
29
|
"rpc.multi_instructions": "Enter the numbers of all that apply, comma-separated (e.g. \"1,3\"), or type a custom answer as plain text.",
|
|
26
30
|
"rpc.custom_answer_title": "Type your answer:"
|
|
27
31
|
}
|
package/locales/es.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"_meta.notes": "Auto-translated draft. Native-speaker review welcome via PR. TUI symbols (↑/↓, ⚠) and key names (Enter, Esc, Tab, Space, n) are universal CLI conventions and stay untranslated.",
|
|
2
|
+
"_meta.notes": "Auto-translated draft. Native-speaker review welcome via PR. TUI symbols (↑/↓, ⚠) and key names (Enter, Esc, Tab, Space, n, Ctrl+G, Ctrl+U) are universal CLI conventions and stay untranslated.",
|
|
3
3
|
|
|
4
4
|
"sentinel.other": "Escribe algo.",
|
|
5
5
|
"sentinel.next": "Siguiente",
|
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
|
|
10
10
|
"hint.enter": "Enter para seleccionar",
|
|
11
11
|
"hint.navigate": "↑/↓ para navegar",
|
|
12
|
+
"hint.newline": "Mayús+Enter para nueva línea",
|
|
13
|
+
"hint.clear": "Ctrl+U para borrar",
|
|
12
14
|
"hint.toggle": "Espacio para alternar",
|
|
13
15
|
"hint.notes": "n para añadir notas",
|
|
14
16
|
"hint.tab": "Tab para cambiar de pregunta",
|
|
@@ -22,6 +24,8 @@
|
|
|
22
24
|
"preview.notes_affordance": "Notas: pulsa n para añadir notas",
|
|
23
25
|
"notes.header": "Notas:",
|
|
24
26
|
|
|
27
|
+
"editor.failed": "Error del editor externo",
|
|
28
|
+
|
|
25
29
|
"rpc.multi_instructions": "Introduce los números de todas las opciones que apliquen, separados por comas (p. ej. \"1,3\"), o escribe una respuesta propia como texto.",
|
|
26
30
|
"rpc.custom_answer_title": "Escribe tu respuesta:"
|
|
27
31
|
}
|
package/locales/fr.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"_meta.notes": "Auto-translated draft. Native-speaker review welcome via PR. TUI symbols (↑/↓, ⚠) and key names (Enter, Esc, Tab, Space, n) are universal CLI conventions and stay untranslated.",
|
|
2
|
+
"_meta.notes": "Auto-translated draft. Native-speaker review welcome via PR. TUI symbols (↑/↓, ⚠) and key names (Enter, Esc, Tab, Space, n, Ctrl+G, Ctrl+U) are universal CLI conventions and stay untranslated.",
|
|
3
3
|
|
|
4
4
|
"sentinel.other": "Écrivez quelque chose.",
|
|
5
5
|
"sentinel.next": "Suivant",
|
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
|
|
10
10
|
"hint.enter": "Entrée pour sélectionner",
|
|
11
11
|
"hint.navigate": "↑/↓ pour naviguer",
|
|
12
|
+
"hint.newline": "Maj+Entrée pour une nouvelle ligne",
|
|
13
|
+
"hint.clear": "Ctrl+U pour effacer",
|
|
12
14
|
"hint.toggle": "Espace pour basculer",
|
|
13
15
|
"hint.notes": "n pour ajouter des notes",
|
|
14
16
|
"hint.tab": "Tab pour changer de question",
|
|
@@ -22,6 +24,8 @@
|
|
|
22
24
|
"preview.notes_affordance": "Notes : appuyez sur n pour ajouter des notes",
|
|
23
25
|
"notes.header": "Notes :",
|
|
24
26
|
|
|
27
|
+
"editor.failed": "Échec de l’éditeur externe",
|
|
28
|
+
|
|
25
29
|
"rpc.multi_instructions": "Saisissez les numéros de toutes les options applicables, séparés par des virgules (p. ex. « 1,3 »), ou tapez une réponse libre en texte.",
|
|
26
30
|
"rpc.custom_answer_title": "Tapez votre réponse :"
|
|
27
31
|
}
|
package/locales/pt-BR.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"_meta.notes": "Auto-translated draft. Native-speaker review welcome via PR. TUI symbols (↑/↓, ⚠) and key names (Enter, Esc, Tab, Space, n) are universal CLI conventions and stay untranslated.",
|
|
2
|
+
"_meta.notes": "Auto-translated draft. Native-speaker review welcome via PR. TUI symbols (↑/↓, ⚠) and key names (Enter, Esc, Tab, Space, n, Ctrl+G, Ctrl+U) are universal CLI conventions and stay untranslated.",
|
|
3
3
|
|
|
4
4
|
"sentinel.other": "Digite algo.",
|
|
5
5
|
"sentinel.next": "Próximo",
|
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
|
|
10
10
|
"hint.enter": "Enter para selecionar",
|
|
11
11
|
"hint.navigate": "↑/↓ para navegar",
|
|
12
|
+
"hint.newline": "Shift+Enter para nova linha",
|
|
13
|
+
"hint.clear": "Ctrl+U para limpar",
|
|
12
14
|
"hint.toggle": "Espaço para alternar",
|
|
13
15
|
"hint.notes": "n para adicionar notas",
|
|
14
16
|
"hint.tab": "Tab para trocar de pergunta",
|
|
@@ -22,6 +24,8 @@
|
|
|
22
24
|
"preview.notes_affordance": "Notas: pressione n para adicionar notas",
|
|
23
25
|
"notes.header": "Notas:",
|
|
24
26
|
|
|
27
|
+
"editor.failed": "Falha no editor externo",
|
|
28
|
+
|
|
25
29
|
"rpc.multi_instructions": "Digite os números de todas as opções aplicáveis, separados por vírgula (ex.: \"1,3\") ou digite uma resposta própria em texto.",
|
|
26
30
|
"rpc.custom_answer_title": "Digite sua resposta:"
|
|
27
31
|
}
|
package/locales/pt.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"_meta.notes": "European Portuguese (Portugal). Auto-translated draft. Native-speaker review welcome via PR. Distinct from pt-BR (Brasil): differs in lexicon (utilizador / você), conjugation, and some terms. TUI symbols (↑/↓, ⚠) and key names (Enter, Esc, Tab, Space, n) are universal CLI conventions and stay untranslated.",
|
|
2
|
+
"_meta.notes": "European Portuguese (Portugal). Auto-translated draft. Native-speaker review welcome via PR. Distinct from pt-BR (Brasil): differs in lexicon (utilizador / você), conjugation, and some terms. TUI symbols (↑/↓, ⚠) and key names (Enter, Esc, Tab, Space, n, Ctrl+G, Ctrl+U) are universal CLI conventions and stay untranslated.",
|
|
3
3
|
|
|
4
4
|
"sentinel.other": "Escreva algo.",
|
|
5
5
|
"sentinel.next": "Seguinte",
|
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
|
|
10
10
|
"hint.enter": "Enter para selecionar",
|
|
11
11
|
"hint.navigate": "↑/↓ para navegar",
|
|
12
|
+
"hint.newline": "Shift+Enter para nova linha",
|
|
13
|
+
"hint.clear": "Ctrl+U para limpar",
|
|
12
14
|
"hint.toggle": "Espaço para alternar",
|
|
13
15
|
"hint.notes": "n para adicionar notas",
|
|
14
16
|
"hint.tab": "Tab para mudar de pergunta",
|
|
@@ -22,6 +24,8 @@
|
|
|
22
24
|
"preview.notes_affordance": "Notas: prima n para adicionar notas",
|
|
23
25
|
"notes.header": "Notas:",
|
|
24
26
|
|
|
27
|
+
"editor.failed": "Falha no editor externo",
|
|
28
|
+
|
|
25
29
|
"rpc.multi_instructions": "Introduza os números de todas as opções aplicáveis, separados por vírgulas (ex.: \"1,3\") ou escreva uma resposta própria em texto.",
|
|
26
30
|
"rpc.custom_answer_title": "Escreva a sua resposta:"
|
|
27
31
|
}
|
package/locales/ru.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"_meta.notes": "Auto-translated draft. Native-speaker review welcome via PR. TUI symbols (↑/↓, ⚠) and key names (Enter, Esc, Tab, Space, n) are universal CLI conventions and stay untranslated.",
|
|
2
|
+
"_meta.notes": "Auto-translated draft. Native-speaker review welcome via PR. TUI symbols (↑/↓, ⚠) and key names (Enter, Esc, Tab, Space, n, Ctrl+G, Ctrl+U) are universal CLI conventions and stay untranslated.",
|
|
3
3
|
|
|
4
4
|
"sentinel.other": "Введите что-нибудь.",
|
|
5
5
|
"sentinel.next": "Далее",
|
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
|
|
10
10
|
"hint.enter": "Enter — выбрать",
|
|
11
11
|
"hint.navigate": "↑/↓ — навигация",
|
|
12
|
+
"hint.newline": "Shift+Enter — новая строка",
|
|
13
|
+
"hint.clear": "Ctrl+U — очистить",
|
|
12
14
|
"hint.toggle": "Space — переключить",
|
|
13
15
|
"hint.notes": "n — добавить заметки",
|
|
14
16
|
"hint.tab": "Tab — следующий вопрос",
|
|
@@ -22,6 +24,8 @@
|
|
|
22
24
|
"preview.notes_affordance": "Заметки: нажмите n, чтобы добавить заметки",
|
|
23
25
|
"notes.header": "Заметки:",
|
|
24
26
|
|
|
27
|
+
"editor.failed": "Ошибка внешнего редактора",
|
|
28
|
+
|
|
25
29
|
"rpc.multi_instructions": "Введите номера всех подходящих вариантов через запятую (например, \"1,3\") или введите свой ответ текстом.",
|
|
26
30
|
"rpc.custom_answer_title": "Введите свой ответ:"
|
|
27
31
|
}
|
package/locales/uk.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"_meta.notes": "Auto-translated draft. Native-speaker review welcome via PR. TUI symbols (↑/↓, ⚠) and key names (Enter, Esc, Tab, Space, n) are universal CLI conventions and stay untranslated.",
|
|
2
|
+
"_meta.notes": "Auto-translated draft. Native-speaker review welcome via PR. TUI symbols (↑/↓, ⚠) and key names (Enter, Esc, Tab, Space, n, Ctrl+G, Ctrl+U) are universal CLI conventions and stay untranslated.",
|
|
3
3
|
|
|
4
4
|
"sentinel.other": "Введіть щось.",
|
|
5
5
|
"sentinel.next": "Далі",
|
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
|
|
10
10
|
"hint.enter": "Enter — обрати",
|
|
11
11
|
"hint.navigate": "↑/↓ — навігація",
|
|
12
|
+
"hint.newline": "Shift+Enter — новий рядок",
|
|
13
|
+
"hint.clear": "Ctrl+U — очистити",
|
|
12
14
|
"hint.toggle": "Space — перемкнути",
|
|
13
15
|
"hint.notes": "n — додати нотатки",
|
|
14
16
|
"hint.tab": "Tab — наступне питання",
|
|
@@ -22,6 +24,8 @@
|
|
|
22
24
|
"preview.notes_affordance": "Нотатки: натисніть n, щоб додати нотатки",
|
|
23
25
|
"notes.header": "Нотатки:",
|
|
24
26
|
|
|
27
|
+
"editor.failed": "Помилка зовнішнього редактора",
|
|
28
|
+
|
|
25
29
|
"rpc.multi_instructions": "Введіть номери всіх відповідних варіантів через кому (наприклад, \"1,3\") або введіть власну відповідь текстом.",
|
|
26
30
|
"rpc.custom_answer_title": "Введіть свою відповідь:"
|
|
27
31
|
}
|
package/locales/zh.json
CHANGED
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
|
|
10
10
|
"hint.enter": "回车选择",
|
|
11
11
|
"hint.navigate": "↑/↓ 导航",
|
|
12
|
+
"hint.newline": "Shift+Enter 换行",
|
|
13
|
+
"hint.clear": "Ctrl+U 清空",
|
|
12
14
|
"hint.toggle": "空格切换",
|
|
13
15
|
"hint.notes": "按 n 添加备注",
|
|
14
16
|
"hint.tab": "Tab 切换问题",
|
|
@@ -24,6 +26,8 @@
|
|
|
24
26
|
"preview.notes_affordance": "备注:按 n 添加",
|
|
25
27
|
"notes.header": "备注:",
|
|
26
28
|
|
|
29
|
+
"editor.failed": "外部编辑器启动失败",
|
|
30
|
+
|
|
27
31
|
"rpc.multi_instructions": "输入所有适用选项的编号,用逗号分隔(例如 \"1,3\"),或直接输入自定义回答。",
|
|
28
32
|
"rpc.custom_answer_title": "输入你的回答:"
|
|
29
33
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@juicesharp/rpiv-ask-user-question",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.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",
|
|
@@ -38,8 +38,13 @@
|
|
|
38
38
|
"reconcile.ts",
|
|
39
39
|
"LICENSE",
|
|
40
40
|
"locales/",
|
|
41
|
+
"docs/",
|
|
42
|
+
"!docs/*.png",
|
|
43
|
+
"!docs/*.jpg",
|
|
44
|
+
"!docs/*.svg",
|
|
41
45
|
"README.md",
|
|
42
46
|
"state/build-questionnaire.ts",
|
|
47
|
+
"state/external-editor.ts",
|
|
43
48
|
"state/i18n-bridge.ts",
|
|
44
49
|
"state/key-router.ts",
|
|
45
50
|
"state/questionnaire-session.ts",
|
|
@@ -88,7 +93,7 @@
|
|
|
88
93
|
}
|
|
89
94
|
},
|
|
90
95
|
"dependencies": {
|
|
91
|
-
"@juicesharp/rpiv-config": "^2.
|
|
96
|
+
"@juicesharp/rpiv-config": "^2.2.0",
|
|
92
97
|
"typebox": "^1.1.24"
|
|
93
98
|
}
|
|
94
99
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getMarkdownTheme, type Theme } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import {
|
|
2
|
+
import { Editor, type EditorTheme, type TUI } from "@earendil-works/pi-tui";
|
|
3
3
|
import type { QuestionData } from "../tool/types.js";
|
|
4
4
|
import {
|
|
5
5
|
type BoundGlobalBinding,
|
|
@@ -33,7 +33,7 @@ import {
|
|
|
33
33
|
import type { QuestionnaireState } from "./state.js";
|
|
34
34
|
|
|
35
35
|
export interface QuestionnaireBuildConfig {
|
|
36
|
-
tui:
|
|
36
|
+
tui: TUI;
|
|
37
37
|
theme: Theme;
|
|
38
38
|
questions: readonly QuestionData[];
|
|
39
39
|
itemsByTab: ReadonlyArray<readonly WrappingSelectItem[]>;
|
|
@@ -44,8 +44,8 @@ export interface QuestionnaireBuildConfig {
|
|
|
44
44
|
|
|
45
45
|
export interface QuestionnaireBuilt {
|
|
46
46
|
adapter: QuestionnairePropsAdapter;
|
|
47
|
-
notesInput:
|
|
48
|
-
inlineInput:
|
|
47
|
+
notesInput: Editor;
|
|
48
|
+
inlineInput: Editor;
|
|
49
49
|
render: (width: number) => string[];
|
|
50
50
|
invalidate: () => void;
|
|
51
51
|
}
|
|
@@ -56,10 +56,23 @@ interface HeightComputers {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
function previewBodyHeights(pane: PreviewPane): (width: number) => TabBodyHeights {
|
|
59
|
-
return (width) =>
|
|
60
|
-
current
|
|
61
|
-
max: pane.maxNaturalHeight(width)
|
|
62
|
-
}
|
|
59
|
+
return (width) => {
|
|
60
|
+
const current = pane.naturalHeight(width);
|
|
61
|
+
return { current, max: Math.max(current, pane.maxNaturalHeight(width)) };
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function editorTheme(theme: Theme): EditorTheme {
|
|
66
|
+
return {
|
|
67
|
+
borderColor: (text) => theme.fg("borderMuted", text),
|
|
68
|
+
selectList: {
|
|
69
|
+
selectedPrefix: (text) => theme.bg("selectedBg", theme.fg("accent", text)),
|
|
70
|
+
selectedText: (text) => theme.bg("selectedBg", theme.bold(text)),
|
|
71
|
+
description: (text) => theme.fg("muted", text),
|
|
72
|
+
scrollInfo: (text) => theme.fg("dim", text),
|
|
73
|
+
noMatch: (text) => theme.fg("warning", text),
|
|
74
|
+
},
|
|
75
|
+
};
|
|
63
76
|
}
|
|
64
77
|
|
|
65
78
|
function multiSelectBodyHeights(view: MultiSelectView): (width: number) => TabBodyHeights {
|
|
@@ -74,8 +87,8 @@ const isActiveTab: PerTabSelector<boolean> = (s, ctx) =>
|
|
|
74
87
|
|
|
75
88
|
/**
|
|
76
89
|
* Pure factory: assembles every TUI component, the props adapter, and a
|
|
77
|
-
* lifecycle handle. Session-state dependencies arrive via `getCurrentTab
|
|
78
|
-
* the
|
|
90
|
+
* lifecycle handle. Session-state dependencies arrive via `getCurrentTab`; live
|
|
91
|
+
* custom text stays in the headless Editor. Initial paint is delegated to
|
|
79
92
|
* `adapter.apply(initialState)` (called by the session at construction-end);
|
|
80
93
|
* no selector is invoked here.
|
|
81
94
|
*/
|
|
@@ -99,8 +112,8 @@ class QuestionnaireBuilder {
|
|
|
99
112
|
|
|
100
113
|
private readonly selectTheme: WrappingSelectTheme;
|
|
101
114
|
private readonly markdownTheme = getMarkdownTheme();
|
|
102
|
-
private readonly notesInput
|
|
103
|
-
private readonly inlineInput
|
|
115
|
+
private readonly notesInput: Editor;
|
|
116
|
+
private readonly inlineInput: Editor;
|
|
104
117
|
private readonly getTerminalWidth = () => this.tui.terminal.columns;
|
|
105
118
|
private readonly getTerminalRows = () => this.tui.terminal.rows;
|
|
106
119
|
|
|
@@ -114,6 +127,9 @@ class QuestionnaireBuilder {
|
|
|
114
127
|
this.getCurrentTab = config.getCurrentTab;
|
|
115
128
|
|
|
116
129
|
this.selectTheme = this.makeSelectTheme();
|
|
130
|
+
const textEditorTheme = editorTheme(this.theme);
|
|
131
|
+
this.notesInput = new Editor(this.tui, textEditorTheme);
|
|
132
|
+
this.inlineInput = new Editor(this.tui, textEditorTheme);
|
|
117
133
|
}
|
|
118
134
|
|
|
119
135
|
build(): QuestionnaireBuilt {
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
|
|
6
|
+
export interface ExternalEditorTui {
|
|
7
|
+
stop(): void;
|
|
8
|
+
start(): void;
|
|
9
|
+
requestRender(force?: boolean): void;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function runEditor(command: string, file: string): Promise<void> {
|
|
13
|
+
// Keep the command grammar identical to Pi's built-in external-editor flow. A
|
|
14
|
+
// separate shell or argv parser here would make Ctrl+G behave differently.
|
|
15
|
+
const [editor, ...args] = command.split(" ");
|
|
16
|
+
if (!editor) return Promise.reject(new Error("External editor command is empty"));
|
|
17
|
+
|
|
18
|
+
return new Promise((resolve, reject) => {
|
|
19
|
+
const child = spawn(editor, [...args, file], {
|
|
20
|
+
stdio: "inherit",
|
|
21
|
+
shell: process.platform === "win32",
|
|
22
|
+
});
|
|
23
|
+
child.once("error", reject);
|
|
24
|
+
child.once("close", (code, signal) => {
|
|
25
|
+
if (code === 0) {
|
|
26
|
+
resolve();
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const reason = signal ? `signal ${signal}` : `exit code ${code ?? "unknown"}`;
|
|
30
|
+
reject(new Error(`External editor exited with ${reason}`));
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Edit a custom answer with Pi's configured external-editor command. The TUI lifecycle
|
|
37
|
+
* and one-trailing-newline normalization intentionally match Pi's main editor flow.
|
|
38
|
+
*/
|
|
39
|
+
export async function editWithExternalEditor(tui: ExternalEditorTui, command: string, value: string): Promise<string> {
|
|
40
|
+
const tempDir = mkdtempSync(join(tmpdir(), "rpiv-ask-user-question-"));
|
|
41
|
+
const tempFile = join(tempDir, "answer.md");
|
|
42
|
+
let tuiStopped = false;
|
|
43
|
+
|
|
44
|
+
try {
|
|
45
|
+
writeFileSync(tempFile, value, "utf8");
|
|
46
|
+
tui.stop();
|
|
47
|
+
tuiStopped = true;
|
|
48
|
+
process.stdout.write(`Launching external editor: ${command}\nPi will resume when the editor exits.\n`);
|
|
49
|
+
await runEditor(command, tempFile);
|
|
50
|
+
return readFileSync(tempFile, "utf8").replace(/\r?\n$/, "");
|
|
51
|
+
} finally {
|
|
52
|
+
try {
|
|
53
|
+
rmSync(tempDir, { recursive: true, force: true });
|
|
54
|
+
} catch {
|
|
55
|
+
// Temp cleanup is best effort; never leave the TUI stopped because it failed.
|
|
56
|
+
}
|
|
57
|
+
if (tuiStopped) {
|
|
58
|
+
tui.start();
|
|
59
|
+
tui.requestRender(true);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|