bots-garden/mini-mepublic Fork
⑂ ca58355
Commits
⬇ Clone ▾
git clone https://git.rickub.com/bots-garden/mini-me.git
git clone ssh://git@rickub.com/bots-garden/mini-me.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

Download ZIP

Merge feature/ask-user-other into main

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
agent committed 2026-11-26T18:06:47+01:00 Browse files
ca58355 parents: ce10345 c2eba72
modified .tickets/issues/0258-ask-user-add-an-other-choice-free-answer-to-every.yaml +37 -7
@@ -1,15 +1,17 @@
11 # Managed by IssueSpec. Hand edits are welcome; keep the schema valid.
22 id: 258
33 title: "ask_user: add an \"Other\" choice (free answer) to every choice question"
4-state: open
4+state: closed
55 author:
66 name: k33g
77 email: ph.charriere@gmail.com
88 createdAt: 2026-11-24T19:26:33.000Z
9-updatedAt: 2026-11-24T19:26:33.000Z
9+updatedAt: 2026-11-26T18:00:00.000Z
10+closedAt: 2026-11-26T18:00:00.000Z
1011 labels:
1112 - enhancement
1213 - kind::feature
14+milestone: v2.1.1
1315 epic: Builtin tools
1416 related:
1517 - 84
@@ -58,34 +60,62 @@ body: |
5860 tasks:
5961 - id: 1
6062 title: elicit - add the Other option to choice and multi; mark a typed answer in the result
61- state: open
63+ state: closed
6264 priority: high
6365 author:
6466 name: k33g
6567 email: ph.charriere@gmail.com
6668 createdAt: 2026-11-24T19:26:33.000Z
69+ updatedAt: 2026-11-26T17:30:00.000Z
70+ closedAt: 2026-11-26T17:30:00.000Z
6771 - id: 2
6872 title: Window - Other row opens a text field in the question box
69- state: open
73+ state: closed
7074 priority: high
7175 author:
7276 name: k33g
7377 email: ph.charriere@gmail.com
7478 createdAt: 2026-11-24T19:26:33.000Z
79+ updatedAt: 2026-11-26T17:30:00.000Z
80+ closedAt: 2026-11-26T17:30:00.000Z
7581 - id: 3
7682 title: ACP - Other in the elicitation form; decide for the permission-dialog fallback
77- state: open
83+ state: closed
7884 priority: medium
7985 author:
8086 name: k33g
8187 email: ph.charriere@gmail.com
8288 createdAt: 2026-11-24T19:26:33.000Z
89+ updatedAt: 2026-11-26T17:30:00.000Z
90+ closedAt: 2026-11-26T17:30:00.000Z
8391 - id: 4
8492 title: Tests and docs EN+FR (ask_user)
85- state: open
93+ state: closed
8694 priority: none
8795 author:
8896 name: k33g
8997 email: ph.charriere@gmail.com
9098 createdAt: 2026-11-24T19:26:33.000Z
91-comments: []
99+ updatedAt: 2026-11-26T17:30:00.000Z
100+ closedAt: 2026-11-26T17:30:00.000Z
101+comments:
102+ - id: 1
103+ author:
104+ name: k33g
105+ email: ph.charriere@gmail.com
106+ createdAt: 2026-11-26T17:30:00.000Z
107+ body: |
108+ Implemented on branch feature/ask-user-other. elicit: Question.AllowOther
109+ (on for every ask_user choice/multi, `allow_other: false` turns it off,
110+ an "Other"-like model option is folded into the row), OtherLabel
111+ "Other…", Answer.Other (typed) / OtherAsked (picked where nothing can be
112+ typed); the model reads `typed by the user, not one of your options:
113+ "…"`. Line mode: numbered row, its number asks for the text
114+ (IsOtherPick/ParseOther), multi accepts text between commas. Window:
115+ Other row opens a field, Esc back to the options. ACP: form = enum
116+ value + optional `<name>_other` string (round trip for relayed asked
117+ agents); dialog = an "Other…" button → the model is told to ask in its
118+ reply (decision taken for the open question of the ticket). mm's
119+ wizards (no AllowOther) keep their behaviour. Live: line mode with
120+ gpt-oss 20B — "3" then "SQLite, it is a tiny app" → the model said it
121+ was not one of its options.
@@ -1,15 +1,17 @@
1 # Managed by IssueSpec. Hand edits are welcome; keep the schema valid.1 # Managed by IssueSpec. Hand edits are welcome; keep the schema valid.
2 id: 2582 id: 258
3 title: "ask_user: add an \"Other\" choice (free answer) to every choice question"3 title: "ask_user: add an \"Other\" choice (free answer) to every choice question"
4-state: open4+state: closed
5 author:5 author:
6 name: k33g6 name: k33g
7 email: ph.charriere@gmail.com7 email: ph.charriere@gmail.com
8 createdAt: 2026-11-24T19:26:33.000Z8 createdAt: 2026-11-24T19:26:33.000Z
9-updatedAt: 2026-11-24T19:26:33.000Z9+updatedAt: 2026-11-26T18:00:00.000Z
10+closedAt: 2026-11-26T18:00:00.000Z
10 labels:11 labels:
11 - enhancement12 - enhancement
12 - kind::feature13 - kind::feature
14+milestone: v2.1.1
13 epic: Builtin tools15 epic: Builtin tools
14 related:16 related:
15 - 8417 - 84
@@ -58,34 +60,62 @@ body: |
58 tasks:60 tasks:
59 - id: 161 - id: 1
60 title: elicit - add the Other option to choice and multi; mark a typed answer in the result62 title: elicit - add the Other option to choice and multi; mark a typed answer in the result
61- state: open63+ state: closed
62 priority: high64 priority: high
63 author:65 author:
64 name: k33g66 name: k33g
65 email: ph.charriere@gmail.com67 email: ph.charriere@gmail.com
66 createdAt: 2026-11-24T19:26:33.000Z68 createdAt: 2026-11-24T19:26:33.000Z
69+ updatedAt: 2026-11-26T17:30:00.000Z
70+ closedAt: 2026-11-26T17:30:00.000Z
67 - id: 271 - id: 2
68 title: Window - Other row opens a text field in the question box72 title: Window - Other row opens a text field in the question box
69- state: open73+ state: closed
70 priority: high74 priority: high
71 author:75 author:
72 name: k33g76 name: k33g
73 email: ph.charriere@gmail.com77 email: ph.charriere@gmail.com
74 createdAt: 2026-11-24T19:26:33.000Z78 createdAt: 2026-11-24T19:26:33.000Z
79+ updatedAt: 2026-11-26T17:30:00.000Z
80+ closedAt: 2026-11-26T17:30:00.000Z
75 - id: 381 - id: 3
76 title: ACP - Other in the elicitation form; decide for the permission-dialog fallback82 title: ACP - Other in the elicitation form; decide for the permission-dialog fallback
77- state: open83+ state: closed
78 priority: medium84 priority: medium
79 author:85 author:
80 name: k33g86 name: k33g
81 email: ph.charriere@gmail.com87 email: ph.charriere@gmail.com
82 createdAt: 2026-11-24T19:26:33.000Z88 createdAt: 2026-11-24T19:26:33.000Z
89+ updatedAt: 2026-11-26T17:30:00.000Z
90+ closedAt: 2026-11-26T17:30:00.000Z
83 - id: 491 - id: 4
84 title: Tests and docs EN+FR (ask_user)92 title: Tests and docs EN+FR (ask_user)
85- state: open93+ state: closed
86 priority: none94 priority: none
87 author:95 author:
88 name: k33g96 name: k33g
89 email: ph.charriere@gmail.com97 email: ph.charriere@gmail.com
90 createdAt: 2026-11-24T19:26:33.000Z98 createdAt: 2026-11-24T19:26:33.000Z
91-comments: []99+ updatedAt: 2026-11-26T17:30:00.000Z
100+ closedAt: 2026-11-26T17:30:00.000Z
101+comments:
102+ - id: 1
103+ author:
104+ name: k33g
105+ email: ph.charriere@gmail.com
106+ createdAt: 2026-11-26T17:30:00.000Z
107+ body: |
108+ Implemented on branch feature/ask-user-other. elicit: Question.AllowOther
109+ (on for every ask_user choice/multi, `allow_other: false` turns it off,
110+ an "Other"-like model option is folded into the row), OtherLabel
111+ "Other…", Answer.Other (typed) / OtherAsked (picked where nothing can be
112+ typed); the model reads `typed by the user, not one of your options:
113+ "…"`. Line mode: numbered row, its number asks for the text
114+ (IsOtherPick/ParseOther), multi accepts text between commas. Window:
115+ Other row opens a field, Esc back to the options. ACP: form = enum
116+ value + optional `<name>_other` string (round trip for relayed asked
117+ agents); dialog = an "Other…" button → the model is told to ask in its
118+ reply (decision taken for the open question of the ticket). mm's
119+ wizards (no AllowOther) keep their behaviour. Live: line mode with
120+ gpt-oss 20B — "3" then "SQLite, it is a tiny app" → the model said it
121+ was not one of its options.
modified README.md +1 -0
@@ -152,6 +152,7 @@ The `demos/` directory holds ready-made set-ups (most with a README explaining h
152152 | `demos/kronk/` | mm on Kronk, a coding agent with `mradermacher/Qwopus3.5-4B-Coder.Q8_0`, and the line to change for Qwen3.5 2B |
153153 | `demos/mlx-gemma-4-e4b/` | mm on MLX-Serve, an agent in a `.mm` folder for `lmstudio-community/gemma-4-E4B-it-MLX-8bit` |
154154 | `demos/steer/` | correct the agent while it works: steering a running turn (terminal, window) and `/redirect` (Zed), gpt-oss 20B on llama.cpp |
155+| `demos/ask-user/` | `ask_user`'s `Other…` row: answer with something that is not among the model's options (window, terminal, Zed), Qwen3.5 4B on llama.cpp |
155156 | `demos/smollm3-demo/` | an agent written by `mm init` for SmolLM3-3B in a `.mm` folder, with `toolFormat: xml_tools` and reasoning off |
156157 | `demos/structured-output/` | agents that answer in JSON, and a coordinator using them |
157158 | `demos/structured-output-pizza/` | one JSON agent declared with Go types: a pizza's name → its ingredients (quantity, unit, category, allergens), whether it is vegetarian, its baking time (Gemma 4 E4B on llmman) |
@@ -152,6 +152,7 @@ The `demos/` directory holds ready-made set-ups (most with a README explaining h
152 | `demos/kronk/` | mm on Kronk, a coding agent with `mradermacher/Qwopus3.5-4B-Coder.Q8_0`, and the line to change for Qwen3.5 2B |152 | `demos/kronk/` | mm on Kronk, a coding agent with `mradermacher/Qwopus3.5-4B-Coder.Q8_0`, and the line to change for Qwen3.5 2B |
153 | `demos/mlx-gemma-4-e4b/` | mm on MLX-Serve, an agent in a `.mm` folder for `lmstudio-community/gemma-4-E4B-it-MLX-8bit` |153 | `demos/mlx-gemma-4-e4b/` | mm on MLX-Serve, an agent in a `.mm` folder for `lmstudio-community/gemma-4-E4B-it-MLX-8bit` |
154 | `demos/steer/` | correct the agent while it works: steering a running turn (terminal, window) and `/redirect` (Zed), gpt-oss 20B on llama.cpp |154 | `demos/steer/` | correct the agent while it works: steering a running turn (terminal, window) and `/redirect` (Zed), gpt-oss 20B on llama.cpp |
155+| `demos/ask-user/` | `ask_user`'s `Other…` row: answer with something that is not among the model's options (window, terminal, Zed), Qwen3.5 4B on llama.cpp |
155 | `demos/smollm3-demo/` | an agent written by `mm init` for SmolLM3-3B in a `.mm` folder, with `toolFormat: xml_tools` and reasoning off |156 | `demos/smollm3-demo/` | an agent written by `mm init` for SmolLM3-3B in a `.mm` folder, with `toolFormat: xml_tools` and reasoning off |
156 | `demos/structured-output/` | agents that answer in JSON, and a coordinator using them |157 | `demos/structured-output/` | agents that answer in JSON, and a coordinator using them |
157 | `demos/structured-output-pizza/` | one JSON agent declared with Go types: a pizza's name → its ingredients (quantity, unit, category, allergens), whether it is vegetarian, its baking time (Gemma 4 E4B on llmman) |158 | `demos/structured-output-pizza/` | one JSON agent declared with Go types: a pizza's name → its ingredients (quantity, unit, category, allergens), whether it is vegetarian, its baking time (Gemma 4 E4B on llmman) |
added demos/ask-user/.gitignore +3 -0
new file mode 100644
@@ -0,0 +1,3 @@
1+!.mm
2+.mm/sessions
3+.mm/traces
new file mode 100644
@@ -0,0 +1,3 @@
1+!.mm
2+.mm/sessions
3+.mm/traces
added demos/ask-user/.mm/agent.yaml +65 -0
new file mode 100644
@@ -0,0 +1,65 @@
1+# Kit — a demo agent to try ask_user's "Other…" row (ticket 258).
2+#
3+# Kit helps start a small project. Before it answers, it asks its questions
4+# with the ask_user tool — a choice, a multi and a yes/no — and every choice
5+# question gets a last row, "Other…", where you type your own answer.
6+# See README.en.md.
7+#
8+# cd demos/ask-user && ../../mm -tui window
9+# cd demos/ask-user && ../../mm line mode
10+# Zed: AGENT_CONFIG=<abs path>/demos/ask-user/.mm/agent.yaml, args ["-acp"]
11+
12+provider: llamacpp
13+# Qwen3.5 4B: small and quick, calls tools well with thinking off. The Other
14+# row was first checked with gpt-oss 20B (2026-11-26). Any model that calls
15+# tools works — redo the sampling block with it.
16+model: "unsloth/Qwen3.5-4B-GGUF:Q4_K_M"
17+# No baseUrl: llamacpp's defaults apply — 127.0.0.1:9931 (the Llama app),
18+# then 8080, then host.docker.internal:9931.
19+
20+# Kit only talks and asks: no command, no file.
21+bashTool: false
22+editTools: false
23+planTool: false
24+fetchContentTool: false
25+askUserTool: true
26+skillsDir: no-skills
27+# The model is shared with your other agents: leave it loaded on exit, and
28+# no unload_model tool.
29+unloadOnExit: false
30+unloadModels: false
31+maxTurns: 10
32+firstTokenTimeout: 3m
33+
34+sampling:
35+ # family qwen (mm init's presets), non-thinking: 0.7 / 0.8 / 20
36+ temperature: 0.7
37+ top_p: 0.8
38+ top_k: 20
39+ max_tokens: 4096
40+ parallel_tool_calls: false
41+ chat_template_kwargs:
42+ # reasoning off: short, direct answers
43+ enable_thinking: false
44+
45+sessions:
46+ enabled: true
47+ dir: .mm/sessions
48+
49+acp:
50+ name: kit
51+ title: "Kit (ask_user demo)"
52+
53+system: |
54+ Your name is Kit. You help the user start a small software project.
55+ When the user describes a project, do not guess: call the ask_user tool
56+ ONCE, with these three questions together, before you answer:
57+ - "Which language?" — type choice, options: Go, Python, TypeScript;
58+ - "Which features?" — type multi, options: Tests, Docker, CI;
59+ - "Create a Git repository?" — type confirm.
60+ Never add an "Other" option yourself: the user can always type an answer
61+ of their own, and it comes back marked "typed by the user".
62+ Then answer in a few lines: the plan for the project, using exactly what
63+ the user chose. When an answer was typed by the user, say so ("you chose
64+ … rather than one of my suggestions") and take it into account.
65+ If the user declined, make a reasonable assumption and say which.
new file mode 100644
@@ -0,0 +1,65 @@
1+# Kit — a demo agent to try ask_user's "Other…" row (ticket 258).
2+#
3+# Kit helps start a small project. Before it answers, it asks its questions
4+# with the ask_user tool — a choice, a multi and a yes/no — and every choice
5+# question gets a last row, "Other…", where you type your own answer.
6+# See README.en.md.
7+#
8+# cd demos/ask-user && ../../mm -tui window
9+# cd demos/ask-user && ../../mm line mode
10+# Zed: AGENT_CONFIG=<abs path>/demos/ask-user/.mm/agent.yaml, args ["-acp"]
11+
12+provider: llamacpp
13+# Qwen3.5 4B: small and quick, calls tools well with thinking off. The Other
14+# row was first checked with gpt-oss 20B (2026-11-26). Any model that calls
15+# tools works — redo the sampling block with it.
16+model: "unsloth/Qwen3.5-4B-GGUF:Q4_K_M"
17+# No baseUrl: llamacpp's defaults apply — 127.0.0.1:9931 (the Llama app),
18+# then 8080, then host.docker.internal:9931.
19+
20+# Kit only talks and asks: no command, no file.
21+bashTool: false
22+editTools: false
23+planTool: false
24+fetchContentTool: false
25+askUserTool: true
26+skillsDir: no-skills
27+# The model is shared with your other agents: leave it loaded on exit, and
28+# no unload_model tool.
29+unloadOnExit: false
30+unloadModels: false
31+maxTurns: 10
32+firstTokenTimeout: 3m
33+
34+sampling:
35+ # family qwen (mm init's presets), non-thinking: 0.7 / 0.8 / 20
36+ temperature: 0.7
37+ top_p: 0.8
38+ top_k: 20
39+ max_tokens: 4096
40+ parallel_tool_calls: false
41+ chat_template_kwargs:
42+ # reasoning off: short, direct answers
43+ enable_thinking: false
44+
45+sessions:
46+ enabled: true
47+ dir: .mm/sessions
48+
49+acp:
50+ name: kit
51+ title: "Kit (ask_user demo)"
52+
53+system: |
54+ Your name is Kit. You help the user start a small software project.
55+ When the user describes a project, do not guess: call the ask_user tool
56+ ONCE, with these three questions together, before you answer:
57+ - "Which language?" — type choice, options: Go, Python, TypeScript;
58+ - "Which features?" — type multi, options: Tests, Docker, CI;
59+ - "Create a Git repository?" — type confirm.
60+ Never add an "Other" option yourself: the user can always type an answer
61+ of their own, and it comes back marked "typed by the user".
62+ Then answer in a few lines: the plan for the project, using exactly what
63+ the user chose. When an answer was typed by the user, say so ("you chose
64+ … rather than one of my suggestions") and take it into account.
65+ If the user declined, make a reasonable assumption and say which.
added demos/ask-user/README.en.md +70 -0
new file mode 100644
@@ -0,0 +1,70 @@
1+# ask_user demo — answer with something that is not among the options
2+
3+This folder tries the `Other…` row of the `ask_user` tool (ticket 258). The agent, Kit, helps you start a small project. Before it answers, it asks three questions at once with `ask_user`: a language (a choice), features (a multi) and whether to create a Git repository (a yes/no). Every choice question ends with a row mm adds itself, `Other…`, where you type an answer of your own.
4+
5+| File | What it is |
6+|------|------------|
7+| `.mm/agent.yaml` | the agent: `provider: llamacpp`, `unsloth/Qwen3.5-4B-GGUF:Q4_K_M` (thinking off), no bash and no file tools — it only asks and answers |
8+
9+Version française : [README.fr.md](README.fr.md).
10+
11+## Before you start
12+
13+The model runs on llama-server on 127.0.0.1:9931 (the Llama app, or `llama-server` in router mode) with `unsloth/Qwen3.5-4B-GGUF:Q4_K_M`, a small model (about 3 GB). Another model that calls tools works too: change `model:` in `.mm/agent.yaml`, and the `sampling:` block with it (`mm init` gives the settings of a model family).
14+
15+## In the window
16+
17+```bash
18+cd demos/ask-user
19+../../mm -tui
20+```
21+
22+1. Type `I want to build a small weather CLI.`
23+2. **Which language?** — the last row is `4. Other… (type your own answer)`. Press ↑ (from the first row it wraps to the last), then Enter: a field opens. Escape goes back to the options without declining. Type `Rust`, then Enter. Pressing `4` opens the field too.
24+3. **Which features?** — Space ticks `Tests`, ↓ down to `[+] Other…`, Space opens the field, type `Benchmarks`, Enter: the answer is `Tests` plus your text.
25+4. **Create a Git repository?** — `y`.
26+5. Kit's plan uses Rust and benchmarks: it got them marked `typed by the user, not one of your options`.
27+
28+## In the terminal
29+
30+```bash
31+cd demos/ask-user
32+../../mm
33+```
34+
35+The same questions come one after the other, with numbered options:
36+
37+```text
38+❓ Which language?
39+ 1. Go
40+ 2. Python
41+ 3. TypeScript
42+ 4. Other… (type your own answer)
43+ number, or type your own answer · /skip to decline
44+```
45+
46+Type `4`, then `Rust` on the next line — or type `Rust` straight away. For the features, `1, Benchmarks` ticks Tests and adds your own answer.
47+
48+## In Zed
49+
50+Add the agent to Zed's `settings.json`, with the absolute path of this folder's agent file:
51+
52+```json
53+"agent_servers": {
54+ "kit": {
55+ "type": "custom",
56+ "command": "/absolute/path/to/mm",
57+ "args": ["-acp"],
58+ "env": { "AGENT_CONFIG": "/absolute/path/to/mini-me/demos/ask-user/.mm/agent.yaml" }
59+ }
60+}
61+```
62+
63+An editor that shows ACP forms gets `Other…` as the last value of the language list, and a text field `Your own answer …` under each choice question. An editor that can only show dialogs gets an `Other…` button: a dialog cannot take a text, so Kit asks you again in its reply.
64+
65+## What was checked (2026-11-26, from an sbx sandbox, llama-server router on the Mac)
66+
67+- Line mode, piped input, with gpt-oss 20B then with Qwen3.5 4B (thinking off): `4` then `Rust`, `1, Benchmarks`, `y` — the plan came back in Rust with tests and benchmarks, a Git repository, both times. Neither model said in so many words that Rust was not one of its options, although the system prompt asks it to.
68+- Piped input must wait for each question: lines that arrive while the model is still working are taken as steering (see the steering explanation), not as answers.
69+- The window and Zed were not tried live (no terminal and no editor in the sandbox); their behaviour is covered by unit tests.
70+- The start-up line `[warning: no skills found in …/no-skills …]` is expected: this agent has no skills.
new file mode 100644
@@ -0,0 +1,70 @@
1+# ask_user demo — answer with something that is not among the options
2+
3+This folder tries the `Other…` row of the `ask_user` tool (ticket 258). The agent, Kit, helps you start a small project. Before it answers, it asks three questions at once with `ask_user`: a language (a choice), features (a multi) and whether to create a Git repository (a yes/no). Every choice question ends with a row mm adds itself, `Other…`, where you type an answer of your own.
4+
5+| File | What it is |
6+|------|------------|
7+| `.mm/agent.yaml` | the agent: `provider: llamacpp`, `unsloth/Qwen3.5-4B-GGUF:Q4_K_M` (thinking off), no bash and no file tools — it only asks and answers |
8+
9+Version française : [README.fr.md](README.fr.md).
10+
11+## Before you start
12+
13+The model runs on llama-server on 127.0.0.1:9931 (the Llama app, or `llama-server` in router mode) with `unsloth/Qwen3.5-4B-GGUF:Q4_K_M`, a small model (about 3 GB). Another model that calls tools works too: change `model:` in `.mm/agent.yaml`, and the `sampling:` block with it (`mm init` gives the settings of a model family).
14+
15+## In the window
16+
17+```bash
18+cd demos/ask-user
19+../../mm -tui
20+```
21+
22+1. Type `I want to build a small weather CLI.`
23+2. **Which language?** — the last row is `4. Other… (type your own answer)`. Press ↑ (from the first row it wraps to the last), then Enter: a field opens. Escape goes back to the options without declining. Type `Rust`, then Enter. Pressing `4` opens the field too.
24+3. **Which features?** — Space ticks `Tests`, ↓ down to `[+] Other…`, Space opens the field, type `Benchmarks`, Enter: the answer is `Tests` plus your text.
25+4. **Create a Git repository?** — `y`.
26+5. Kit's plan uses Rust and benchmarks: it got them marked `typed by the user, not one of your options`.
27+
28+## In the terminal
29+
30+```bash
31+cd demos/ask-user
32+../../mm
33+```
34+
35+The same questions come one after the other, with numbered options:
36+
37+```text
38+❓ Which language?
39+ 1. Go
40+ 2. Python
41+ 3. TypeScript
42+ 4. Other… (type your own answer)
43+ number, or type your own answer · /skip to decline
44+```
45+
46+Type `4`, then `Rust` on the next line — or type `Rust` straight away. For the features, `1, Benchmarks` ticks Tests and adds your own answer.
47+
48+## In Zed
49+
50+Add the agent to Zed's `settings.json`, with the absolute path of this folder's agent file:
51+
52+```json
53+"agent_servers": {
54+ "kit": {
55+ "type": "custom",
56+ "command": "/absolute/path/to/mm",
57+ "args": ["-acp"],
58+ "env": { "AGENT_CONFIG": "/absolute/path/to/mini-me/demos/ask-user/.mm/agent.yaml" }
59+ }
60+}
61+```
62+
63+An editor that shows ACP forms gets `Other…` as the last value of the language list, and a text field `Your own answer …` under each choice question. An editor that can only show dialogs gets an `Other…` button: a dialog cannot take a text, so Kit asks you again in its reply.
64+
65+## What was checked (2026-11-26, from an sbx sandbox, llama-server router on the Mac)
66+
67+- Line mode, piped input, with gpt-oss 20B then with Qwen3.5 4B (thinking off): `4` then `Rust`, `1, Benchmarks`, `y` — the plan came back in Rust with tests and benchmarks, a Git repository, both times. Neither model said in so many words that Rust was not one of its options, although the system prompt asks it to.
68+- Piped input must wait for each question: lines that arrive while the model is still working are taken as steering (see the steering explanation), not as answers.
69+- The window and Zed were not tried live (no terminal and no editor in the sandbox); their behaviour is covered by unit tests.
70+- The start-up line `[warning: no skills found in …/no-skills …]` is expected: this agent has no skills.
added demos/ask-user/README.fr.md +70 -0
new file mode 100644
@@ -0,0 +1,70 @@
1+# Démo ask_user — répondre par autre chose que les options proposées
2+
3+Ce dossier sert à essayer la ligne `Other…` de l'outil `ask_user` (ticket 258). L'agent, Kit, vous aide à démarrer un petit projet. Avant de répondre, il pose trois questions d'un coup avec `ask_user` : un langage (un choix), des fonctionnalités (un choix multiple) et s'il faut créer un dépôt Git (un oui/non). Chaque question à choix se termine par une ligne que mm ajoute lui-même, `Other…`, où vous tapez votre propre réponse.
4+
5+| Fichier | Ce que c'est |
6+|---------|--------------|
7+| `.mm/agent.yaml` | l'agent : `provider: llamacpp`, `unsloth/Qwen3.5-4B-GGUF:Q4_K_M` (raisonnement coupé), ni bash ni outils de fichiers — il ne fait que poser des questions et répondre |
8+
9+English version: [README.en.md](README.en.md).
10+
11+## Avant de commencer
12+
13+Le modèle tourne sur llama-server en 127.0.0.1:9931 (l'application Llama, ou `llama-server` en mode routeur) avec `unsloth/Qwen3.5-4B-GGUF:Q4_K_M`, un petit modèle (environ 3 Go). Un autre modèle qui appelle des outils marche aussi : changez `model:` dans `.mm/agent.yaml`, et le bloc `sampling:` avec lui (`mm init` donne les réglages d'une famille de modèles).
14+
15+## Dans la fenêtre
16+
17+```bash
18+cd demos/ask-user
19+../../mm -tui
20+```
21+
22+1. Tapez `I want to build a small weather CLI.`
23+2. **Which language?** — la dernière ligne est `4. Other… (type your own answer)`. Appuyez sur ↑ (depuis la première ligne, on passe à la dernière), puis Entrée : un champ s'ouvre. Échap revient aux options sans refuser. Tapez `Rust`, puis Entrée. La touche `4` ouvre aussi le champ.
24+3. **Which features?** — Espace coche `Tests`, ↓ jusqu'à `[+] Other…`, Espace ouvre le champ, tapez `Benchmarks`, Entrée : la réponse est `Tests` plus votre texte.
25+4. **Create a Git repository?** — `y`.
26+5. Le plan de Kit utilise Rust et des benchmarks : il les a reçus marqués `typed by the user, not one of your options`.
27+
28+## Dans le terminal
29+
30+```bash
31+cd demos/ask-user
32+../../mm
33+```
34+
35+Les mêmes questions arrivent l'une après l'autre, avec des options numérotées :
36+
37+```text
38+❓ Which language?
39+ 1. Go
40+ 2. Python
41+ 3. TypeScript
42+ 4. Other… (type your own answer)
43+ number, or type your own answer · /skip to decline
44+```
45+
46+Tapez `4`, puis `Rust` sur la ligne suivante — ou tapez directement `Rust`. Pour les fonctionnalités, `1, Benchmarks` coche Tests et ajoute votre propre réponse.
47+
48+## Dans Zed
49+
50+Ajoutez l'agent au `settings.json` de Zed, avec le chemin absolu du fichier d'agent de ce dossier :
51+
52+```json
53+"agent_servers": {
54+ "kit": {
55+ "type": "custom",
56+ "command": "/chemin/absolu/vers/mm",
57+ "args": ["-acp"],
58+ "env": { "AGENT_CONFIG": "/chemin/absolu/vers/mini-me/demos/ask-user/.mm/agent.yaml" }
59+ }
60+}
61+```
62+
63+Un éditeur qui affiche les formulaires ACP reçoit `Other…` comme dernière valeur de la liste des langages, et un champ texte `Your own answer …` sous chaque question à choix. Un éditeur qui ne sait afficher que des dialogues reçoit un bouton `Other…` : un dialogue ne peut pas recevoir de texte, Kit vous repose donc la question dans sa réponse.
64+
65+## Ce qui a été vérifié (26/11/2026, depuis un sandbox sbx, routeur llama-server sur le Mac)
66+
67+- Mode ligne, entrée par un pipe, avec gpt-oss 20B puis avec Qwen3.5 4B (raisonnement coupé) : `4` puis `Rust`, `1, Benchmarks`, `y` — le plan est revenu en Rust avec tests et benchmarks, et un dépôt Git, les deux fois. Aucun des deux modèles n'a dit en toutes lettres que Rust n'était pas une de ses options, bien que le prompt système le lui demande.
68+- Une entrée par un pipe doit attendre chaque question : les lignes qui arrivent pendant que le modèle travaille encore sont prises comme un pilotage (steer), pas comme des réponses.
69+- La fenêtre et Zed n'ont pas été essayés en vrai (ni terminal ni éditeur dans le sandbox) ; leur comportement est couvert par des tests unitaires.
70+- La ligne de démarrage `[warning: no skills found in …/no-skills …]` est normale : cet agent n'a pas de skill.
new file mode 100644
@@ -0,0 +1,70 @@
1+# Démo ask_user — répondre par autre chose que les options proposées
2+
3+Ce dossier sert à essayer la ligne `Other…` de l'outil `ask_user` (ticket 258). L'agent, Kit, vous aide à démarrer un petit projet. Avant de répondre, il pose trois questions d'un coup avec `ask_user` : un langage (un choix), des fonctionnalités (un choix multiple) et s'il faut créer un dépôt Git (un oui/non). Chaque question à choix se termine par une ligne que mm ajoute lui-même, `Other…`, où vous tapez votre propre réponse.
4+
5+| Fichier | Ce que c'est |
6+|---------|--------------|
7+| `.mm/agent.yaml` | l'agent : `provider: llamacpp`, `unsloth/Qwen3.5-4B-GGUF:Q4_K_M` (raisonnement coupé), ni bash ni outils de fichiers — il ne fait que poser des questions et répondre |
8+
9+English version: [README.en.md](README.en.md).
10+
11+## Avant de commencer
12+
13+Le modèle tourne sur llama-server en 127.0.0.1:9931 (l'application Llama, ou `llama-server` en mode routeur) avec `unsloth/Qwen3.5-4B-GGUF:Q4_K_M`, un petit modèle (environ 3 Go). Un autre modèle qui appelle des outils marche aussi : changez `model:` dans `.mm/agent.yaml`, et le bloc `sampling:` avec lui (`mm init` donne les réglages d'une famille de modèles).
14+
15+## Dans la fenêtre
16+
17+```bash
18+cd demos/ask-user
19+../../mm -tui
20+```
21+
22+1. Tapez `I want to build a small weather CLI.`
23+2. **Which language?** — la dernière ligne est `4. Other… (type your own answer)`. Appuyez sur ↑ (depuis la première ligne, on passe à la dernière), puis Entrée : un champ s'ouvre. Échap revient aux options sans refuser. Tapez `Rust`, puis Entrée. La touche `4` ouvre aussi le champ.
24+3. **Which features?** — Espace coche `Tests`, ↓ jusqu'à `[+] Other…`, Espace ouvre le champ, tapez `Benchmarks`, Entrée : la réponse est `Tests` plus votre texte.
25+4. **Create a Git repository?** — `y`.
26+5. Le plan de Kit utilise Rust et des benchmarks : il les a reçus marqués `typed by the user, not one of your options`.
27+
28+## Dans le terminal
29+
30+```bash
31+cd demos/ask-user
32+../../mm
33+```
34+
35+Les mêmes questions arrivent l'une après l'autre, avec des options numérotées :
36+
37+```text
38+❓ Which language?
39+ 1. Go
40+ 2. Python
41+ 3. TypeScript
42+ 4. Other… (type your own answer)
43+ number, or type your own answer · /skip to decline
44+```
45+
46+Tapez `4`, puis `Rust` sur la ligne suivante — ou tapez directement `Rust`. Pour les fonctionnalités, `1, Benchmarks` coche Tests et ajoute votre propre réponse.
47+
48+## Dans Zed
49+
50+Ajoutez l'agent au `settings.json` de Zed, avec le chemin absolu du fichier d'agent de ce dossier :
51+
52+```json
53+"agent_servers": {
54+ "kit": {
55+ "type": "custom",
56+ "command": "/chemin/absolu/vers/mm",
57+ "args": ["-acp"],
58+ "env": { "AGENT_CONFIG": "/chemin/absolu/vers/mini-me/demos/ask-user/.mm/agent.yaml" }
59+ }
60+}
61+```
62+
63+Un éditeur qui affiche les formulaires ACP reçoit `Other…` comme dernière valeur de la liste des langages, et un champ texte `Your own answer …` sous chaque question à choix. Un éditeur qui ne sait afficher que des dialogues reçoit un bouton `Other…` : un dialogue ne peut pas recevoir de texte, Kit vous repose donc la question dans sa réponse.
64+
65+## Ce qui a été vérifié (26/11/2026, depuis un sandbox sbx, routeur llama-server sur le Mac)
66+
67+- Mode ligne, entrée par un pipe, avec gpt-oss 20B puis avec Qwen3.5 4B (raisonnement coupé) : `4` puis `Rust`, `1, Benchmarks`, `y` — le plan est revenu en Rust avec tests et benchmarks, et un dépôt Git, les deux fois. Aucun des deux modèles n'a dit en toutes lettres que Rust n'était pas une de ses options, bien que le prompt système le lui demande.
68+- Une entrée par un pipe doit attendre chaque question : les lignes qui arrivent pendant que le modèle travaille encore sont prises comme un pilotage (steer), pas comme des réponses.
69+- La fenêtre et Zed n'ont pas été essayés en vrai (ni terminal ni éditeur dans le sandbox) ; leur comportement est couvert par des tests unitaires.
70+- La ligne de démarrage `[warning: no skills found in …/no-skills …]` est normale : cet agent n'a pas de skill.
modified docs/en/explanation/asking-the-user.md +6 -0
@@ -32,6 +32,12 @@ The tool declares its input loosely: no enum, nothing required, and each questio
3232
3333 The tool's description ends with a complete example call, which the schema can no longer show.
3434
35+## An "Other" row mm adds itself
36+
37+The model's options are its guess at the possible answers, and the right one is sometimes not among them (ticket 258). So every `choice` and `multi` question gets a last row, `Other…`, where the user types an answer of their own. mm adds it rather than asking the model to: small models forget such an option, or write it in their own words (`Other (please specify)`), and then nothing happens when it is picked. An option the model wrote that means "something else" is folded into the row, so it never appears twice. The model can still turn the row off with `allow_other: false` when only its options make sense.
38+
39+What the model reads back says the answer was typed — `typed by the user, not one of your options: "…"` — so it does not look for it among its options. An editor dialog is the one place where nothing can be typed: its `Other…` button tells the model to ask again in its reply, a plain question being the only free text such an editor offers.
40+
3541 ## Waiting for a human
3642
3743 mm's watchdog keeps counting while a tool runs (ticket 57), so a question left unanswered for 20 seconds would have ended the turn as a hung server. While a question waits, the tool beats the watchdog every second; a stopped turn still cancels the question. For a called agent's question, the asker's watchdog is beaten the same way.
@@ -32,6 +32,12 @@ The tool declares its input loosely: no enum, nothing required, and each questio
32 32
33 The tool's description ends with a complete example call, which the schema can no longer show.33 The tool's description ends with a complete example call, which the schema can no longer show.
34 34
35+## An "Other" row mm adds itself
36+
37+The model's options are its guess at the possible answers, and the right one is sometimes not among them (ticket 258). So every `choice` and `multi` question gets a last row, `Other…`, where the user types an answer of their own. mm adds it rather than asking the model to: small models forget such an option, or write it in their own words (`Other (please specify)`), and then nothing happens when it is picked. An option the model wrote that means "something else" is folded into the row, so it never appears twice. The model can still turn the row off with `allow_other: false` when only its options make sense.
38+
39+What the model reads back says the answer was typed — `typed by the user, not one of your options: "…"` — so it does not look for it among its options. An editor dialog is the one place where nothing can be typed: its `Other…` button tells the model to ask again in its reply, a plain question being the only free text such an editor offers.
40+
35 ## Waiting for a human41 ## Waiting for a human
36 42
37 mm's watchdog keeps counting while a tool runs (ticket 57), so a question left unanswered for 20 seconds would have ended the turn as a hung server. While a question waits, the tool beats the watchdog every second; a stopped turn still cancels the question. For a called agent's question, the asker's watchdog is beaten the same way.43 mm's watchdog keeps counting while a tool runs (ticket 57), so a question left unanswered for 20 seconds would have ended the turn as a hung server. While a question waits, the tool beats the watchdog every second; a stopped turn still cancels the question. For a called agent's question, the asker's watchdog is beaten the same way.
modified docs/en/how-to/let-the-agent-ask-you.md +10 -7
@@ -24,14 +24,16 @@ Each question is printed with numbered options:
2424 1. React
2525 2. Vue
2626 3. Svelte
27- number, or another answer · /skip to decline
27+ 4. Other… (type your own answer)
28+ number, or type your own answer · /skip to decline
2829 ? 2
2930 ```
3031
3132 1. Type the number of an option, or its text, or its first letters (`sv`), and press Enter. For several choices, type the numbers separated by commas: `1,3`.
32-2. For a yes or no, type `y` or `n` (`o` and `non` work too).
33-3. For a free answer, type it. Enter on an empty line takes the default when there is one.
34-4. Several questions come one after the other.
33+2. None of the options fits? Type your own answer instead (`Solid`), or the `Other…` row's number, then your answer on the next line. On a several-choice question, add it after the numbers: `1, Solid`. The agent reads it as typed by you, not as one of its options.
34+3. For a yes or no, type `y` or `n` (`o` and `non` work too).
35+4. For a free answer, type it. Enter on an empty line takes the default when there is one.
36+5. Several questions come one after the other.
3537
3638 To refuse to answer, type `/skip`. `/abort` stops the turn, question included.
3739
@@ -41,14 +43,15 @@ The question replaces the input box, its options over the bottom of the conversa
4143
4244 1. A choice: ↑↓ then Enter, or the option's number.
4345 2. Several choices: ↑↓, Space to tick each one, Enter to send.
44-3. Yes or no: `y` or `n`.
45-4. A text: type it in the box, then Enter.
46+3. None of the options fits: choose the last row, `Other…`, type your answer, then Enter (Escape goes back to the options).
47+4. Yes or no: `y` or `n`.
48+5. A text: type it in the box, then Enter.
4649
4750 Escape refuses to answer.
4851
4952 ## Answer in an editor (ACP)
5053
51-Nothing to do on mm's side: an editor that supports ACP's elicitation forms shows the questions as a form. One that does not shows each choice or yes/no question as a dialog whose buttons are the options, plus `Decline`. With such an editor, free-text and several-choice questions cannot be asked: the agent is told so and assumes.
54+Nothing to do on mm's side: an editor that supports ACP's elicitation forms shows the questions as a form. One that does not shows each choice or yes/no question as a dialog whose buttons are the options, plus `Other…` and `Decline`; a dialog cannot take a text, so `Other…` makes the agent ask you again in its reply. With such an editor, free-text and several-choice questions cannot be asked: the agent is told so and assumes.
5255
5356 ## Turn the tool off
5457
@@ -24,14 +24,16 @@ Each question is printed with numbered options:
24 1. React24 1. React
25 2. Vue25 2. Vue
26 3. Svelte26 3. Svelte
27- number, or another answer · /skip to decline27+ 4. Other… (type your own answer)
28+ number, or type your own answer · /skip to decline
28 ? 229 ? 2
29 ```30 ```
30 31
31 1. Type the number of an option, or its text, or its first letters (`sv`), and press Enter. For several choices, type the numbers separated by commas: `1,3`.32 1. Type the number of an option, or its text, or its first letters (`sv`), and press Enter. For several choices, type the numbers separated by commas: `1,3`.
32-2. For a yes or no, type `y` or `n` (`o` and `non` work too).33+2. None of the options fits? Type your own answer instead (`Solid`), or the `Other…` row's number, then your answer on the next line. On a several-choice question, add it after the numbers: `1, Solid`. The agent reads it as typed by you, not as one of its options.
33-3. For a free answer, type it. Enter on an empty line takes the default when there is one.34+3. For a yes or no, type `y` or `n` (`o` and `non` work too).
34-4. Several questions come one after the other.35+4. For a free answer, type it. Enter on an empty line takes the default when there is one.
36+5. Several questions come one after the other.
35 37
36 To refuse to answer, type `/skip`. `/abort` stops the turn, question included.38 To refuse to answer, type `/skip`. `/abort` stops the turn, question included.
37 39
@@ -41,14 +43,15 @@ The question replaces the input box, its options over the bottom of the conversa
41 43
42 1. A choice: ↑↓ then Enter, or the option's number.44 1. A choice: ↑↓ then Enter, or the option's number.
43 2. Several choices: ↑↓, Space to tick each one, Enter to send.45 2. Several choices: ↑↓, Space to tick each one, Enter to send.
44-3. Yes or no: `y` or `n`.46+3. None of the options fits: choose the last row, `Other…`, type your answer, then Enter (Escape goes back to the options).
45-4. A text: type it in the box, then Enter.47+4. Yes or no: `y` or `n`.
48+5. A text: type it in the box, then Enter.
46 49
47 Escape refuses to answer.50 Escape refuses to answer.
48 51
49 ## Answer in an editor (ACP)52 ## Answer in an editor (ACP)
50 53
51-Nothing to do on mm's side: an editor that supports ACP's elicitation forms shows the questions as a form. One that does not shows each choice or yes/no question as a dialog whose buttons are the options, plus `Decline`. With such an editor, free-text and several-choice questions cannot be asked: the agent is told so and assumes.54+Nothing to do on mm's side: an editor that supports ACP's elicitation forms shows the questions as a form. One that does not shows each choice or yes/no question as a dialog whose buttons are the options, plus `Other…` and `Decline`; a dialog cannot take a text, so `Other…` makes the agent ask you again in its reply. With such an editor, free-text and several-choice questions cannot be asked: the agent is told so and assumes.
52 55
53 ## Turn the tool off56 ## Turn the tool off
54 57
modified docs/en/reference/tools.md +6 -5
@@ -288,20 +288,21 @@ Declared unless `askUserTool: false` (on by default), and never beside a `struct
288288 | `questions` | array of objects | — | 1 to 4 questions, asked together. A single question sent without the list (its fields at the top level) is accepted. |
289289 | `questions[].question` | string | — | The question. |
290290 | `questions[].type` | string | `choice` when `options` are given, `text` otherwise | `choice` (one option), `multi` (any number of options), `text` (a free answer), `confirm` (yes or no). Synonyms accepted: `single`, `select`, `radio`, `enum`, `one` → `choice`; `multiple`, `multiselect`, `checkbox`, `checkboxes`, `many` → `multi`; `input`, `string`, `free`, `freetext` → `text`; `yesno`, `yes_no`, `boolean`, `bool`, `confirmation` → `confirm`. |
291-| `questions[].options` | array of strings | — | For `choice` and `multi`: at least two, trimmed, duplicates (ignoring case) dropped. Ignored for `text` and `confirm`. |
291+| `questions[].options` | array of strings | — | For `choice` and `multi`: at least two, trimmed, duplicates (ignoring case) dropped. An option meaning "something else" (`Other`, `Other…`, `Other (please specify)`, `Autre`, `Something else`…) is not kept as an option: it is the Other row (below). Ignored for `text` and `confirm`. |
292+| `questions[].allow_other` | boolean | `true` | `choice` and `multi` (ticket 258): mm adds a last row, `Other…`, where the user types an answer of their own. `false` (or `allowOther: false`, `"no"`): only the options. Ignored for `text` and `confirm`. |
292293 | `questions[].default` | string | none | Kept only when it means something: one of the options (`choice`), a yes or a no in English or French (`confirm`), any text (`text`). None for `multi`. |
293294
294295 The declared schema describes a question's fields in words, without `properties`: llama.cpp would impose them in alphabetical order (see [the explanation](../explanation/asking-the-user.md)).
295296
296297 | Aspect | Behaviour |
297298 |--------|-----------|
298-| Line mode | `❓ ask_user: N question(s)`, then each question in turn: `❓ <question>`, one ` N. <option>` line per option (`(default)` after the default), a hint, and ` ? `. One typed line answers it. `choice`: a number, an option's text, the start of exactly one option, or any other text (taken as the answer). `multi`: numbers separated by commas, spaces or semicolons, all in range. `confirm`: `y`/`yes`/`o`/`oui`/`true`/`1` or `n`/`no`/`non`/`false`/`0`. `text`: the text. An empty line takes the default, else asks again; a line that does not answer prints the hint again. `/skip` declines; other slash commands keep their meaning (`/abort`, `/quit` stop the turn and cancel the question). |
299-| Window (`-tui`) | The question replaces the input box, `(i/N)` after it when there are several; the options are drawn over the bottom of the conversation, the highlighted one in reverse with `❯`. `choice`: ↑↓ (wrapping) and Enter, or a digit 1–9. `multi`: ↑↓, Space ticks (`[x]`), Enter sends when at least one is ticked. `confirm`: `y`/`o` or `n`, or ←→↑↓ and Enter. `text`: typed in the box (prefilled with the default), Backspace, Enter. Escape declines the whole form. The tool call shows `… waiting for your answer`. |
300-| Editor (ACP) | The client advertised `clientCapabilities.elicitation.form`: one `elicitation/create` request per call (see [ACP](acp.md#elicitationcreate-requests-sent)). Otherwise, when every question is a `choice` or a `confirm`: one `session/request_permission` dialog per question, its buttons the options (`Yes`/`No` for a `confirm`) and `Decline`. Otherwise: nobody can be asked. |
299+| Line mode | `❓ ask_user: N question(s)`, then each question in turn: `❓ <question>`, one ` N. <option>` line per option (`(default)` after the default), a hint, and ` ? `. One typed line answers it. `choice`: a number, an option's text, the start of exactly one option, or any other text (the user's own answer). With the Other row, ` N. Other… (type your own answer)` comes last; its number prints ` your own answer (/skip to decline):` and the next line is the answer (an empty one asks again). `multi`: numbers separated by commas, spaces or semicolons, all in range, and, with the Other row, text between the commas (`2, a QA box`) as the user's own answer beside the ticked options. `confirm`: `y`/`yes`/`o`/`oui`/`true`/`1` or `n`/`no`/`non`/`false`/`0`. `text`: the text. An empty line takes the default, else asks again; a line that does not answer prints the hint again. `/skip` declines; other slash commands keep their meaning (`/abort`, `/quit` stop the turn and cancel the question). |
300+| Window (`-tui`) | The question replaces the input box, `(i/N)` after it when there are several; the options are drawn over the bottom of the conversation, the highlighted one in reverse with `❯`. `choice`: ↑↓ (wrapping) and Enter, or a digit 1–9. `multi`: ↑↓, Space ticks (`[x]`), Enter sends when at least one is ticked. The Other row comes last (`Other… (type your own answer)`, `[+]` on a `multi`): Enter, Space or its digit opens a field; Enter sends the typed text (with the ticked options on a `multi`; an empty field is not an answer), Escape goes back to the options. `confirm`: `y`/`o` or `n`, or ←→↑↓ and Enter. `text`: typed in the box (prefilled with the default), Backspace, Enter. Escape declines the whole form. The tool call shows `… waiting for your answer`. |
301+| Editor (ACP) | The client advertised `clientCapabilities.elicitation.form`: one `elicitation/create` request per call (see [ACP](acp.md#elicitationcreate-requests-sent)). Otherwise, when every question is a `choice` or a `confirm`: one `session/request_permission` dialog per question, its buttons the options (`Yes`/`No` for a `confirm`), `Other…` for a `choice` with the Other row, and `Decline`. A dialog has no text field: `Other…` answers with a request to ask in the reply (see Result). Otherwise: nobody can be asked. In the form, the Other row is `Other…` at the end of a `choice`'s `enum` and an optional string property `<name>_other` (`Your own answer …`); an asked agent's form is relayed with both. |
301302 | Asked agent (`/ask`, `ask_agent`) | Its questions come up to the asking agent's user, through the asking agent's own front end, each prefixed `<agent> asks: `. With `mm --ask`, nobody can be asked. |
302303 | One-shot (`-p`) | Nobody can be asked. |
303304 | Watchdog | While a question waits, the generation's watchdog is beaten every second: waiting for a human does not end the turn. A stopped turn cancels the question. |
304-| Result | Answered: `The user answered:` then one `- <question> → <answer>` line per question (several options joined by `, `). Declined: `[the user declined to answer: do not ask the same thing again; go on without it or stop]`. Cancelled: `[the question was cancelled before the user answered]`. Nobody to ask: `[the user cannot be asked in this mode: make a reasonable assumption, say which, and go on]`. Anything but an answer ends the call as failed in the window and the editor. |
305+| Result | Answered: `The user answered:` then one `- <question> → <answer>` line per question (several options joined by `, `). The user's own answer reads `typed by the user, not one of your options: "<text>"`, after the ticked options and ` + ` on a `multi`; `Other…` chosen where nothing could be typed reads `the user wants to give an answer that is not one of your options: ask them for it in your reply, as a plain question`. Declined: `[the user declined to answer: do not ask the same thing again; go on without it or stop]`. Cancelled: `[the question was cancelled before the user answered]`. Nobody to ask: `[the user cannot be asked in this mode: make a reasonable assumption, say which, and go on]`. Anything but an answer ends the call as failed in the window and the editor. |
305306 | Errors | `[ask_user: no question — send questions: [{question, type, options}]]`; `[ask_user: N questions — ask at most 4 at a time]`; `[ask_user: question N has no text]`; `[ask_user: question N is a choice question — give it at least two options]` (or `multi`); `[ask_user: question N has type "x" — use choice, multi, text or confirm]`. |
306307
307308 ## `save_answer`
@@ -288,20 +288,21 @@ Declared unless `askUserTool: false` (on by default), and never beside a `struct
288 | `questions` | array of objects | — | 1 to 4 questions, asked together. A single question sent without the list (its fields at the top level) is accepted. |288 | `questions` | array of objects | — | 1 to 4 questions, asked together. A single question sent without the list (its fields at the top level) is accepted. |
289 | `questions[].question` | string | — | The question. |289 | `questions[].question` | string | — | The question. |
290 | `questions[].type` | string | `choice` when `options` are given, `text` otherwise | `choice` (one option), `multi` (any number of options), `text` (a free answer), `confirm` (yes or no). Synonyms accepted: `single`, `select`, `radio`, `enum`, `one` → `choice`; `multiple`, `multiselect`, `checkbox`, `checkboxes`, `many` → `multi`; `input`, `string`, `free`, `freetext` → `text`; `yesno`, `yes_no`, `boolean`, `bool`, `confirmation` → `confirm`. |290 | `questions[].type` | string | `choice` when `options` are given, `text` otherwise | `choice` (one option), `multi` (any number of options), `text` (a free answer), `confirm` (yes or no). Synonyms accepted: `single`, `select`, `radio`, `enum`, `one` → `choice`; `multiple`, `multiselect`, `checkbox`, `checkboxes`, `many` → `multi`; `input`, `string`, `free`, `freetext` → `text`; `yesno`, `yes_no`, `boolean`, `bool`, `confirmation` → `confirm`. |
291-| `questions[].options` | array of strings | — | For `choice` and `multi`: at least two, trimmed, duplicates (ignoring case) dropped. Ignored for `text` and `confirm`. |291+| `questions[].options` | array of strings | — | For `choice` and `multi`: at least two, trimmed, duplicates (ignoring case) dropped. An option meaning "something else" (`Other`, `Other…`, `Other (please specify)`, `Autre`, `Something else`…) is not kept as an option: it is the Other row (below). Ignored for `text` and `confirm`. |
292+| `questions[].allow_other` | boolean | `true` | `choice` and `multi` (ticket 258): mm adds a last row, `Other…`, where the user types an answer of their own. `false` (or `allowOther: false`, `"no"`): only the options. Ignored for `text` and `confirm`. |
292 | `questions[].default` | string | none | Kept only when it means something: one of the options (`choice`), a yes or a no in English or French (`confirm`), any text (`text`). None for `multi`. |293 | `questions[].default` | string | none | Kept only when it means something: one of the options (`choice`), a yes or a no in English or French (`confirm`), any text (`text`). None for `multi`. |
293 294
294 The declared schema describes a question's fields in words, without `properties`: llama.cpp would impose them in alphabetical order (see [the explanation](../explanation/asking-the-user.md)).295 The declared schema describes a question's fields in words, without `properties`: llama.cpp would impose them in alphabetical order (see [the explanation](../explanation/asking-the-user.md)).
295 296
296 | Aspect | Behaviour |297 | Aspect | Behaviour |
297 |--------|-----------|298 |--------|-----------|
298-| Line mode | `❓ ask_user: N question(s)`, then each question in turn: `❓ <question>`, one ` N. <option>` line per option (`(default)` after the default), a hint, and ` ? `. One typed line answers it. `choice`: a number, an option's text, the start of exactly one option, or any other text (taken as the answer). `multi`: numbers separated by commas, spaces or semicolons, all in range. `confirm`: `y`/`yes`/`o`/`oui`/`true`/`1` or `n`/`no`/`non`/`false`/`0`. `text`: the text. An empty line takes the default, else asks again; a line that does not answer prints the hint again. `/skip` declines; other slash commands keep their meaning (`/abort`, `/quit` stop the turn and cancel the question). |299+| Line mode | `❓ ask_user: N question(s)`, then each question in turn: `❓ <question>`, one ` N. <option>` line per option (`(default)` after the default), a hint, and ` ? `. One typed line answers it. `choice`: a number, an option's text, the start of exactly one option, or any other text (the user's own answer). With the Other row, ` N. Other… (type your own answer)` comes last; its number prints ` your own answer (/skip to decline):` and the next line is the answer (an empty one asks again). `multi`: numbers separated by commas, spaces or semicolons, all in range, and, with the Other row, text between the commas (`2, a QA box`) as the user's own answer beside the ticked options. `confirm`: `y`/`yes`/`o`/`oui`/`true`/`1` or `n`/`no`/`non`/`false`/`0`. `text`: the text. An empty line takes the default, else asks again; a line that does not answer prints the hint again. `/skip` declines; other slash commands keep their meaning (`/abort`, `/quit` stop the turn and cancel the question). |
299-| Window (`-tui`) | The question replaces the input box, `(i/N)` after it when there are several; the options are drawn over the bottom of the conversation, the highlighted one in reverse with `❯`. `choice`: ↑↓ (wrapping) and Enter, or a digit 1–9. `multi`: ↑↓, Space ticks (`[x]`), Enter sends when at least one is ticked. `confirm`: `y`/`o` or `n`, or ←→↑↓ and Enter. `text`: typed in the box (prefilled with the default), Backspace, Enter. Escape declines the whole form. The tool call shows `… waiting for your answer`. |300+| Window (`-tui`) | The question replaces the input box, `(i/N)` after it when there are several; the options are drawn over the bottom of the conversation, the highlighted one in reverse with `❯`. `choice`: ↑↓ (wrapping) and Enter, or a digit 1–9. `multi`: ↑↓, Space ticks (`[x]`), Enter sends when at least one is ticked. The Other row comes last (`Other… (type your own answer)`, `[+]` on a `multi`): Enter, Space or its digit opens a field; Enter sends the typed text (with the ticked options on a `multi`; an empty field is not an answer), Escape goes back to the options. `confirm`: `y`/`o` or `n`, or ←→↑↓ and Enter. `text`: typed in the box (prefilled with the default), Backspace, Enter. Escape declines the whole form. The tool call shows `… waiting for your answer`. |
300-| Editor (ACP) | The client advertised `clientCapabilities.elicitation.form`: one `elicitation/create` request per call (see [ACP](acp.md#elicitationcreate-requests-sent)). Otherwise, when every question is a `choice` or a `confirm`: one `session/request_permission` dialog per question, its buttons the options (`Yes`/`No` for a `confirm`) and `Decline`. Otherwise: nobody can be asked. |301+| Editor (ACP) | The client advertised `clientCapabilities.elicitation.form`: one `elicitation/create` request per call (see [ACP](acp.md#elicitationcreate-requests-sent)). Otherwise, when every question is a `choice` or a `confirm`: one `session/request_permission` dialog per question, its buttons the options (`Yes`/`No` for a `confirm`), `Other…` for a `choice` with the Other row, and `Decline`. A dialog has no text field: `Other…` answers with a request to ask in the reply (see Result). Otherwise: nobody can be asked. In the form, the Other row is `Other…` at the end of a `choice`'s `enum` and an optional string property `<name>_other` (`Your own answer …`); an asked agent's form is relayed with both. |
301 | Asked agent (`/ask`, `ask_agent`) | Its questions come up to the asking agent's user, through the asking agent's own front end, each prefixed `<agent> asks: `. With `mm --ask`, nobody can be asked. |302 | Asked agent (`/ask`, `ask_agent`) | Its questions come up to the asking agent's user, through the asking agent's own front end, each prefixed `<agent> asks: `. With `mm --ask`, nobody can be asked. |
302 | One-shot (`-p`) | Nobody can be asked. |303 | One-shot (`-p`) | Nobody can be asked. |
303 | Watchdog | While a question waits, the generation's watchdog is beaten every second: waiting for a human does not end the turn. A stopped turn cancels the question. |304 | Watchdog | While a question waits, the generation's watchdog is beaten every second: waiting for a human does not end the turn. A stopped turn cancels the question. |
304-| Result | Answered: `The user answered:` then one `- <question> → <answer>` line per question (several options joined by `, `). Declined: `[the user declined to answer: do not ask the same thing again; go on without it or stop]`. Cancelled: `[the question was cancelled before the user answered]`. Nobody to ask: `[the user cannot be asked in this mode: make a reasonable assumption, say which, and go on]`. Anything but an answer ends the call as failed in the window and the editor. |305+| Result | Answered: `The user answered:` then one `- <question> → <answer>` line per question (several options joined by `, `). The user's own answer reads `typed by the user, not one of your options: "<text>"`, after the ticked options and ` + ` on a `multi`; `Other…` chosen where nothing could be typed reads `the user wants to give an answer that is not one of your options: ask them for it in your reply, as a plain question`. Declined: `[the user declined to answer: do not ask the same thing again; go on without it or stop]`. Cancelled: `[the question was cancelled before the user answered]`. Nobody to ask: `[the user cannot be asked in this mode: make a reasonable assumption, say which, and go on]`. Anything but an answer ends the call as failed in the window and the editor. |
305 | Errors | `[ask_user: no question — send questions: [{question, type, options}]]`; `[ask_user: N questions — ask at most 4 at a time]`; `[ask_user: question N has no text]`; `[ask_user: question N is a choice question — give it at least two options]` (or `multi`); `[ask_user: question N has type "x" — use choice, multi, text or confirm]`. |306 | Errors | `[ask_user: no question — send questions: [{question, type, options}]]`; `[ask_user: N questions — ask at most 4 at a time]`; `[ask_user: question N has no text]`; `[ask_user: question N is a choice question — give it at least two options]` (or `multi`); `[ask_user: question N has type "x" — use choice, multi, text or confirm]`. |
306 307
307 ## `save_answer`308 ## `save_answer`
modified docs/fr/explanation/asking-the-user.md +6 -0
@@ -32,6 +32,12 @@ L'outil déclare son entrée de façon souple : pas d'enum, rien d'obligatoire,
3232
3333 La description de l'outil se termine par un exemple d'appel complet, que le schéma ne peut plus montrer.
3434
35+## Une ligne « Other » que mm ajoute lui-même
36+
37+Les options du modèle sont sa supposition des réponses possibles, et la bonne n'en fait parfois pas partie (ticket 258). Chaque question `choice` et `multi` reçoit donc une dernière ligne, `Other…`, où l'utilisateur tape sa propre réponse. C'est mm qui l'ajoute, plutôt que de le demander au modèle : les petits modèles oublient une telle option, ou l'écrivent à leur façon (`Other (please specify)`), et il ne se passe alors rien quand on la choisit. Une option du modèle qui signifie « autre chose » est fondue dans cette ligne, elle n'apparaît donc jamais deux fois. Le modèle peut toujours la désactiver avec `allow_other: false` quand seules ses options ont un sens.
38+
39+Ce que le modèle relit dit que la réponse a été tapée — `typed by the user, not one of your options: "…"` — pour qu'il ne la cherche pas parmi ses options. Le dialogue d'un éditeur est le seul endroit où rien ne peut être tapé : son bouton `Other…` demande au modèle de reposer la question dans sa réponse, une question en clair étant le seul texte libre qu'un tel éditeur offre.
40+
3541 ## Attendre un humain
3642
3743 Le chien de garde de mm continue de compter pendant qu'un outil s'exécute (ticket 57) : une question restée 20 secondes sans réponse aurait terminé le tour comme un serveur bloqué. Tant qu'une question attend, l'outil relance le chien de garde chaque seconde ; un tour arrêté annule toujours la question. Pour la question d'un agent appelé, le chien de garde de l'appelant est relancé de la même façon.
@@ -32,6 +32,12 @@ L'outil déclare son entrée de façon souple : pas d'enum, rien d'obligatoire,
32 32
33 La description de l'outil se termine par un exemple d'appel complet, que le schéma ne peut plus montrer.33 La description de l'outil se termine par un exemple d'appel complet, que le schéma ne peut plus montrer.
34 34
35+## Une ligne « Other » que mm ajoute lui-même
36+
37+Les options du modèle sont sa supposition des réponses possibles, et la bonne n'en fait parfois pas partie (ticket 258). Chaque question `choice` et `multi` reçoit donc une dernière ligne, `Other…`, où l'utilisateur tape sa propre réponse. C'est mm qui l'ajoute, plutôt que de le demander au modèle : les petits modèles oublient une telle option, ou l'écrivent à leur façon (`Other (please specify)`), et il ne se passe alors rien quand on la choisit. Une option du modèle qui signifie « autre chose » est fondue dans cette ligne, elle n'apparaît donc jamais deux fois. Le modèle peut toujours la désactiver avec `allow_other: false` quand seules ses options ont un sens.
38+
39+Ce que le modèle relit dit que la réponse a été tapée — `typed by the user, not one of your options: "…"` — pour qu'il ne la cherche pas parmi ses options. Le dialogue d'un éditeur est le seul endroit où rien ne peut être tapé : son bouton `Other…` demande au modèle de reposer la question dans sa réponse, une question en clair étant le seul texte libre qu'un tel éditeur offre.
40+
35 ## Attendre un humain41 ## Attendre un humain
36 42
37 Le chien de garde de mm continue de compter pendant qu'un outil s'exécute (ticket 57) : une question restée 20 secondes sans réponse aurait terminé le tour comme un serveur bloqué. Tant qu'une question attend, l'outil relance le chien de garde chaque seconde ; un tour arrêté annule toujours la question. Pour la question d'un agent appelé, le chien de garde de l'appelant est relancé de la même façon.43 Le chien de garde de mm continue de compter pendant qu'un outil s'exécute (ticket 57) : une question restée 20 secondes sans réponse aurait terminé le tour comme un serveur bloqué. Tant qu'une question attend, l'outil relance le chien de garde chaque seconde ; un tour arrêté annule toujours la question. Pour la question d'un agent appelé, le chien de garde de l'appelant est relancé de la même façon.
modified docs/fr/how-to/let-the-agent-ask-you.md +10 -7
@@ -24,14 +24,16 @@ Chaque question s'affiche avec des options numérotées :
2424 1. React
2525 2. Vue
2626 3. Svelte
27- number, or another answer · /skip to decline
27+ 4. Other… (type your own answer)
28+ number, or type your own answer · /skip to decline
2829 ? 2
2930 ```
3031
3132 1. Tapez le numéro d'une option, ou son texte, ou ses premières lettres (`sv`), puis Entrée. Pour plusieurs choix, tapez les numéros séparés par des virgules : `1,3`.
32-2. Pour un oui ou un non, tapez `o` ou `n` (`y` et `non` marchent aussi).
33-3. Pour une réponse libre, tapez-la. Entrée sur une ligne vide prend la valeur par défaut quand il y en a une.
34-4. Plusieurs questions arrivent l'une après l'autre.
33+2. Aucune option ne convient ? Tapez votre propre réponse à la place (`Solid`), ou le numéro de la ligne `Other…`, puis votre réponse sur la ligne suivante. Sur une question à choix multiple, ajoutez-la après les numéros : `1, Solid`. L'agent la lit comme tapée par vous, pas comme une de ses options.
34+3. Pour un oui ou un non, tapez `o` ou `n` (`y` et `non` marchent aussi).
35+4. Pour une réponse libre, tapez-la. Entrée sur une ligne vide prend la valeur par défaut quand il y en a une.
36+5. Plusieurs questions arrivent l'une après l'autre.
3537
3638 Pour refuser de répondre, tapez `/skip`. `/abort` arrête le tour, question comprise.
3739
@@ -41,14 +43,15 @@ La question remplace la boîte de saisie, ses options au bas de la conversation
4143
4244 1. Un choix : ↑↓ puis Entrée, ou le numéro de l'option.
4345 2. Plusieurs choix : ↑↓, Espace pour cocher chacun, Entrée pour envoyer.
44-3. Oui ou non : `o` ou `n`.
45-4. Un texte : tapez-le dans la boîte, puis Entrée.
46+3. Aucune option ne convient : choisissez la dernière ligne, `Other…`, tapez votre réponse, puis Entrée (Échap revient aux options).
47+4. Oui ou non : `o` ou `n`.
48+5. Un texte : tapez-le dans la boîte, puis Entrée.
4649
4750 Échap refuse de répondre.
4851
4952 ## Répondre dans un éditeur (ACP)
5053
51-Rien à faire côté mm : un éditeur qui prend en charge les formulaires d'elicitation d'ACP affiche les questions sous forme de formulaire. Un éditeur qui ne les prend pas en charge montre chaque question à choix ou oui/non dans un dialogue dont les boutons sont les options, plus `Decline`. Avec un tel éditeur, les questions à texte libre et à choix multiple ne peuvent pas être posées : l'agent en est averti et fait une hypothèse.
54+Rien à faire côté mm : un éditeur qui prend en charge les formulaires d'elicitation d'ACP affiche les questions sous forme de formulaire. Un éditeur qui ne les prend pas en charge montre chaque question à choix ou oui/non dans un dialogue dont les boutons sont les options, plus `Other…` et `Decline` ; un dialogue ne peut pas recevoir de texte, `Other…` fait donc reposer la question par l'agent dans sa réponse. Avec un tel éditeur, les questions à texte libre et à choix multiple ne peuvent pas être posées : l'agent en est averti et fait une hypothèse.
5255
5356 ## Couper l'outil
5457
@@ -24,14 +24,16 @@ Chaque question s'affiche avec des options numérotées :
24 1. React24 1. React
25 2. Vue25 2. Vue
26 3. Svelte26 3. Svelte
27- number, or another answer · /skip to decline27+ 4. Other… (type your own answer)
28+ number, or type your own answer · /skip to decline
28 ? 229 ? 2
29 ```30 ```
30 31
31 1. Tapez le numéro d'une option, ou son texte, ou ses premières lettres (`sv`), puis Entrée. Pour plusieurs choix, tapez les numéros séparés par des virgules : `1,3`.32 1. Tapez le numéro d'une option, ou son texte, ou ses premières lettres (`sv`), puis Entrée. Pour plusieurs choix, tapez les numéros séparés par des virgules : `1,3`.
32-2. Pour un oui ou un non, tapez `o` ou `n` (`y` et `non` marchent aussi).33+2. Aucune option ne convient ? Tapez votre propre réponse à la place (`Solid`), ou le numéro de la ligne `Other…`, puis votre réponse sur la ligne suivante. Sur une question à choix multiple, ajoutez-la après les numéros : `1, Solid`. L'agent la lit comme tapée par vous, pas comme une de ses options.
33-3. Pour une réponse libre, tapez-la. Entrée sur une ligne vide prend la valeur par défaut quand il y en a une.34+3. Pour un oui ou un non, tapez `o` ou `n` (`y` et `non` marchent aussi).
34-4. Plusieurs questions arrivent l'une après l'autre.35+4. Pour une réponse libre, tapez-la. Entrée sur une ligne vide prend la valeur par défaut quand il y en a une.
36+5. Plusieurs questions arrivent l'une après l'autre.
35 37
36 Pour refuser de répondre, tapez `/skip`. `/abort` arrête le tour, question comprise.38 Pour refuser de répondre, tapez `/skip`. `/abort` arrête le tour, question comprise.
37 39
@@ -41,14 +43,15 @@ La question remplace la boîte de saisie, ses options au bas de la conversation
41 43
42 1. Un choix : ↑↓ puis Entrée, ou le numéro de l'option.44 1. Un choix : ↑↓ puis Entrée, ou le numéro de l'option.
43 2. Plusieurs choix : ↑↓, Espace pour cocher chacun, Entrée pour envoyer.45 2. Plusieurs choix : ↑↓, Espace pour cocher chacun, Entrée pour envoyer.
44-3. Oui ou non : `o` ou `n`.46+3. Aucune option ne convient : choisissez la dernière ligne, `Other…`, tapez votre réponse, puis Entrée (Échap revient aux options).
45-4. Un texte : tapez-le dans la boîte, puis Entrée.47+4. Oui ou non : `o` ou `n`.
48+5. Un texte : tapez-le dans la boîte, puis Entrée.
46 49
47 Échap refuse de répondre.50 Échap refuse de répondre.
48 51
49 ## Répondre dans un éditeur (ACP)52 ## Répondre dans un éditeur (ACP)
50 53
51-Rien à faire côté mm : un éditeur qui prend en charge les formulaires d'elicitation d'ACP affiche les questions sous forme de formulaire. Un éditeur qui ne les prend pas en charge montre chaque question à choix ou oui/non dans un dialogue dont les boutons sont les options, plus `Decline`. Avec un tel éditeur, les questions à texte libre et à choix multiple ne peuvent pas être posées : l'agent en est averti et fait une hypothèse.54+Rien à faire côté mm : un éditeur qui prend en charge les formulaires d'elicitation d'ACP affiche les questions sous forme de formulaire. Un éditeur qui ne les prend pas en charge montre chaque question à choix ou oui/non dans un dialogue dont les boutons sont les options, plus `Other…` et `Decline` ; un dialogue ne peut pas recevoir de texte, `Other…` fait donc reposer la question par l'agent dans sa réponse. Avec un tel éditeur, les questions à texte libre et à choix multiple ne peuvent pas être posées : l'agent en est averti et fait une hypothèse.
52 55
53 ## Couper l'outil56 ## Couper l'outil
54 57
modified docs/fr/reference/tools.md +5 -4
@@ -289,19 +289,20 @@ Déclaré sauf avec `askUserTool: false` (actif par défaut), et jamais à côt
289289 | `questions[].question` | chaîne | — | La question. |
290290 | `questions[].type` | chaîne | `choice` quand `options` est donné, `text` sinon | `choice` (une option), `multi` (un nombre quelconque d'options), `text` (réponse libre), `confirm` (oui ou non). Synonymes acceptés : `single`, `select`, `radio`, `enum`, `one` → `choice` ; `multiple`, `multiselect`, `checkbox`, `checkboxes`, `many` → `multi` ; `input`, `string`, `free`, `freetext` → `text` ; `yesno`, `yes_no`, `boolean`, `bool`, `confirmation` → `confirm`. |
291291 | `questions[].options` | tableau de chaînes | — | Pour `choice` et `multi` : au moins deux, espaces retirés, doublons (sans tenir compte de la casse) supprimés. Ignoré pour `text` et `confirm`. |
292+| `questions[].allow_other` | booléen | `true` | `choice` et `multi` (ticket 258) : mm ajoute une dernière ligne, `Other…`, où l'utilisateur tape sa propre réponse. `false` (ou `allowOther: false`, `"no"`) : les options seules. Ignoré pour `text` et `confirm`. Une option signifiant « autre chose » (`Other`, `Other…`, `Other (please specify)`, `Autre`, `Something else`…) n'est pas gardée comme option : c'est cette ligne. |
292293 | `questions[].default` | chaîne | aucun | Gardé seulement s'il a un sens : une des options (`choice`), un oui ou un non en anglais ou en français (`confirm`), un texte quelconque (`text`). Aucun pour `multi`. |
293294
294295 Le schéma déclaré décrit les champs d'une question en mots, sans `properties` : llama.cpp les imposerait dans l'ordre alphabétique (voir [l'explication](../explanation/asking-the-user.md)).
295296
296297 | Aspect | Comportement |
297298 |--------|--------------|
298-| Mode ligne | `❓ ask_user: N question(s)`, puis chaque question à son tour : `❓ <question>`, une ligne ` N. <option>` par option (`(default)` après le défaut), une aide, et ` ? `. Une ligne tapée y répond. `choice` : un numéro, le texte d'une option, le début d'une seule option, ou tout autre texte (pris comme réponse). `multi` : des numéros séparés par des virgules, espaces ou points-virgules, tous valides. `confirm` : `y`/`yes`/`o`/`oui`/`true`/`1` ou `n`/`no`/`non`/`false`/`0`. `text` : le texte. Une ligne vide prend le défaut, sinon la question est reposée ; une ligne qui ne répond pas réaffiche l'aide. `/skip` refuse ; les autres commandes gardent leur sens (`/abort`, `/quit` arrêtent le tour et annulent la question). |
299-| Fenêtre (`-tui`) | La question remplace la boîte de saisie, suivie de `(i/N)` quand il y en a plusieurs ; les options sont dessinées au bas de la conversation, celle en surbrillance en vidéo inverse avec `❯`. `choice` : ↑↓ (en boucle) et Entrée, ou un chiffre de 1 à 9. `multi` : ↑↓, Espace coche (`[x]`), Entrée envoie quand au moins une option est cochée. `confirm` : `y`/`o` ou `n`, ou ←→↑↓ et Entrée. `text` : saisi dans la boîte (pré-remplie avec le défaut), Retour arrière, Entrée. Échap refuse tout le formulaire. L'appel d'outil affiche `… waiting for your answer`. |
300-| Éditeur (ACP) | Le client a annoncé `clientCapabilities.elicitation.form` : une requête `elicitation/create` par appel (voir [ACP](acp.md#requêtes-elicitationcreate-envoyées)). Sinon, quand chaque question est un `choice` ou un `confirm` : un dialogue `session/request_permission` par question, dont les boutons sont les options (`Yes`/`No` pour un `confirm`) et `Decline`. Sinon : personne ne peut être interrogé. |
299+| Mode ligne | `❓ ask_user: N question(s)`, puis chaque question à son tour : `❓ <question>`, une ligne ` N. <option>` par option (`(default)` après le défaut), une aide, et ` ? `. Une ligne tapée y répond. `choice` : un numéro, le texte d'une option, le début d'une seule option, ou tout autre texte (la réponse propre de l'utilisateur). Avec la ligne Other, ` N. Other… (type your own answer)` vient en dernier ; son numéro affiche ` your own answer (/skip to decline):` et la ligne suivante est la réponse (une ligne vide la redemande). `multi` : des numéros séparés par des virgules, espaces ou points-virgules, tous valides, et, avec la ligne Other, du texte entre les virgules (`2, a QA box`) comme réponse propre à côté des options cochées. `confirm` : `y`/`yes`/`o`/`oui`/`true`/`1` ou `n`/`no`/`non`/`false`/`0`. `text` : le texte. Une ligne vide prend le défaut, sinon la question est reposée ; une ligne qui ne répond pas réaffiche l'aide. `/skip` refuse ; les autres commandes gardent leur sens (`/abort`, `/quit` arrêtent le tour et annulent la question). |
300+| Fenêtre (`-tui`) | La question remplace la boîte de saisie, suivie de `(i/N)` quand il y en a plusieurs ; les options sont dessinées au bas de la conversation, celle en surbrillance en vidéo inverse avec `❯`. `choice` : ↑↓ (en boucle) et Entrée, ou un chiffre de 1 à 9. `multi` : ↑↓, Espace coche (`[x]`), Entrée envoie quand au moins une option est cochée. La ligne Other vient en dernier (`Other… (type your own answer)`, `[+]` sur un `multi`) : Entrée, Espace ou son chiffre ouvre un champ ; Entrée envoie le texte tapé (avec les options cochées sur un `multi` ; un champ vide n'est pas une réponse), Échap revient aux options. `confirm` : `y`/`o` ou `n`, ou ←→↑↓ et Entrée. `text` : saisi dans la boîte (pré-remplie avec le défaut), Retour arrière, Entrée. Échap refuse tout le formulaire. L'appel d'outil affiche `… waiting for your answer`. |
301+| Éditeur (ACP) | Le client a annoncé `clientCapabilities.elicitation.form` : une requête `elicitation/create` par appel (voir [ACP](acp.md#requêtes-elicitationcreate-envoyées)). Sinon, quand chaque question est un `choice` ou un `confirm` : un dialogue `session/request_permission` par question, dont les boutons sont les options (`Yes`/`No` pour un `confirm`), `Other…` pour un `choice` avec la ligne Other, et `Decline`. Un dialogue n'a pas de champ de texte : `Other…` répond par une demande de poser la question dans la réponse (voir Résultat). Sinon : personne ne peut être interrogé. Dans le formulaire, la ligne Other est `Other…` à la fin de l'`enum` d'un `choice` et une propriété texte facultative `<nom>_other` (`Your own answer …`) ; le formulaire d'un agent interrogé est relayé avec les deux. |
301302 | Agent interrogé (`/ask`, `ask_agent`) | Ses questions remontent à l'utilisateur de l'agent qui l'interroge, par l'interface de ce dernier, chacune préfixée `<agent> asks: `. Avec `mm --ask`, personne ne peut être interrogé. |
302303 | Exécution unique (`-p`) | Personne ne peut être interrogé. |
303304 | Chien de garde | Tant qu'une question attend, le chien de garde de la génération est relancé chaque seconde : attendre un humain ne termine pas le tour. Un tour arrêté annule la question. |
304-| Résultat | Répondu : `The user answered:` puis une ligne `- <question> → <réponse>` par question (plusieurs options jointes par `, `). Refusé : `[the user declined to answer: do not ask the same thing again; go on without it or stop]`. Annulé : `[the question was cancelled before the user answered]`. Personne à interroger : `[the user cannot be asked in this mode: make a reasonable assumption, say which, and go on]`. Tout ce qui n'est pas une réponse termine l'appel en échec dans la fenêtre et l'éditeur. |
305+| Résultat | Répondu : `The user answered:` puis une ligne `- <question> → <réponse>` par question (plusieurs options jointes par `, `). La réponse propre de l'utilisateur se lit `typed by the user, not one of your options: "<texte>"`, après les options cochées et ` + ` sur un `multi` ; `Other…` choisi là où rien ne pouvait être tapé se lit `the user wants to give an answer that is not one of your options: ask them for it in your reply, as a plain question`. Refusé : `[the user declined to answer: do not ask the same thing again; go on without it or stop]`. Annulé : `[the question was cancelled before the user answered]`. Personne à interroger : `[the user cannot be asked in this mode: make a reasonable assumption, say which, and go on]`. Tout ce qui n'est pas une réponse termine l'appel en échec dans la fenêtre et l'éditeur. |
305306 | Erreurs | `[ask_user: no question — send questions: [{question, type, options}]]` ; `[ask_user: N questions — ask at most 4 at a time]` ; `[ask_user: question N has no text]` ; `[ask_user: question N is a choice question — give it at least two options]` (ou `multi`) ; `[ask_user: question N has type "x" — use choice, multi, text or confirm]`. |
306307
307308 ## `save_answer`
@@ -289,19 +289,20 @@ Déclaré sauf avec `askUserTool: false` (actif par défaut), et jamais à côt
289 | `questions[].question` | chaîne | — | La question. |289 | `questions[].question` | chaîne | — | La question. |
290 | `questions[].type` | chaîne | `choice` quand `options` est donné, `text` sinon | `choice` (une option), `multi` (un nombre quelconque d'options), `text` (réponse libre), `confirm` (oui ou non). Synonymes acceptés : `single`, `select`, `radio`, `enum`, `one` → `choice` ; `multiple`, `multiselect`, `checkbox`, `checkboxes`, `many` → `multi` ; `input`, `string`, `free`, `freetext` → `text` ; `yesno`, `yes_no`, `boolean`, `bool`, `confirmation` → `confirm`. |290 | `questions[].type` | chaîne | `choice` quand `options` est donné, `text` sinon | `choice` (une option), `multi` (un nombre quelconque d'options), `text` (réponse libre), `confirm` (oui ou non). Synonymes acceptés : `single`, `select`, `radio`, `enum`, `one` → `choice` ; `multiple`, `multiselect`, `checkbox`, `checkboxes`, `many` → `multi` ; `input`, `string`, `free`, `freetext` → `text` ; `yesno`, `yes_no`, `boolean`, `bool`, `confirmation` → `confirm`. |
291 | `questions[].options` | tableau de chaînes | — | Pour `choice` et `multi` : au moins deux, espaces retirés, doublons (sans tenir compte de la casse) supprimés. Ignoré pour `text` et `confirm`. |291 | `questions[].options` | tableau de chaînes | — | Pour `choice` et `multi` : au moins deux, espaces retirés, doublons (sans tenir compte de la casse) supprimés. Ignoré pour `text` et `confirm`. |
292+| `questions[].allow_other` | booléen | `true` | `choice` et `multi` (ticket 258) : mm ajoute une dernière ligne, `Other…`, où l'utilisateur tape sa propre réponse. `false` (ou `allowOther: false`, `"no"`) : les options seules. Ignoré pour `text` et `confirm`. Une option signifiant « autre chose » (`Other`, `Other…`, `Other (please specify)`, `Autre`, `Something else`…) n'est pas gardée comme option : c'est cette ligne. |
292 | `questions[].default` | chaîne | aucun | Gardé seulement s'il a un sens : une des options (`choice`), un oui ou un non en anglais ou en français (`confirm`), un texte quelconque (`text`). Aucun pour `multi`. |293 | `questions[].default` | chaîne | aucun | Gardé seulement s'il a un sens : une des options (`choice`), un oui ou un non en anglais ou en français (`confirm`), un texte quelconque (`text`). Aucun pour `multi`. |
293 294
294 Le schéma déclaré décrit les champs d'une question en mots, sans `properties` : llama.cpp les imposerait dans l'ordre alphabétique (voir [l'explication](../explanation/asking-the-user.md)).295 Le schéma déclaré décrit les champs d'une question en mots, sans `properties` : llama.cpp les imposerait dans l'ordre alphabétique (voir [l'explication](../explanation/asking-the-user.md)).
295 296
296 | Aspect | Comportement |297 | Aspect | Comportement |
297 |--------|--------------|298 |--------|--------------|
298-| Mode ligne | `❓ ask_user: N question(s)`, puis chaque question à son tour : `❓ <question>`, une ligne ` N. <option>` par option (`(default)` après le défaut), une aide, et ` ? `. Une ligne tapée y répond. `choice` : un numéro, le texte d'une option, le début d'une seule option, ou tout autre texte (pris comme réponse). `multi` : des numéros séparés par des virgules, espaces ou points-virgules, tous valides. `confirm` : `y`/`yes`/`o`/`oui`/`true`/`1` ou `n`/`no`/`non`/`false`/`0`. `text` : le texte. Une ligne vide prend le défaut, sinon la question est reposée ; une ligne qui ne répond pas réaffiche l'aide. `/skip` refuse ; les autres commandes gardent leur sens (`/abort`, `/quit` arrêtent le tour et annulent la question). |299+| Mode ligne | `❓ ask_user: N question(s)`, puis chaque question à son tour : `❓ <question>`, une ligne ` N. <option>` par option (`(default)` après le défaut), une aide, et ` ? `. Une ligne tapée y répond. `choice` : un numéro, le texte d'une option, le début d'une seule option, ou tout autre texte (la réponse propre de l'utilisateur). Avec la ligne Other, ` N. Other… (type your own answer)` vient en dernier ; son numéro affiche ` your own answer (/skip to decline):` et la ligne suivante est la réponse (une ligne vide la redemande). `multi` : des numéros séparés par des virgules, espaces ou points-virgules, tous valides, et, avec la ligne Other, du texte entre les virgules (`2, a QA box`) comme réponse propre à côté des options cochées. `confirm` : `y`/`yes`/`o`/`oui`/`true`/`1` ou `n`/`no`/`non`/`false`/`0`. `text` : le texte. Une ligne vide prend le défaut, sinon la question est reposée ; une ligne qui ne répond pas réaffiche l'aide. `/skip` refuse ; les autres commandes gardent leur sens (`/abort`, `/quit` arrêtent le tour et annulent la question). |
299-| Fenêtre (`-tui`) | La question remplace la boîte de saisie, suivie de `(i/N)` quand il y en a plusieurs ; les options sont dessinées au bas de la conversation, celle en surbrillance en vidéo inverse avec `❯`. `choice` : ↑↓ (en boucle) et Entrée, ou un chiffre de 1 à 9. `multi` : ↑↓, Espace coche (`[x]`), Entrée envoie quand au moins une option est cochée. `confirm` : `y`/`o` ou `n`, ou ←→↑↓ et Entrée. `text` : saisi dans la boîte (pré-remplie avec le défaut), Retour arrière, Entrée. Échap refuse tout le formulaire. L'appel d'outil affiche `… waiting for your answer`. |300+| Fenêtre (`-tui`) | La question remplace la boîte de saisie, suivie de `(i/N)` quand il y en a plusieurs ; les options sont dessinées au bas de la conversation, celle en surbrillance en vidéo inverse avec `❯`. `choice` : ↑↓ (en boucle) et Entrée, ou un chiffre de 1 à 9. `multi` : ↑↓, Espace coche (`[x]`), Entrée envoie quand au moins une option est cochée. La ligne Other vient en dernier (`Other… (type your own answer)`, `[+]` sur un `multi`) : Entrée, Espace ou son chiffre ouvre un champ ; Entrée envoie le texte tapé (avec les options cochées sur un `multi` ; un champ vide n'est pas une réponse), Échap revient aux options. `confirm` : `y`/`o` ou `n`, ou ←→↑↓ et Entrée. `text` : saisi dans la boîte (pré-remplie avec le défaut), Retour arrière, Entrée. Échap refuse tout le formulaire. L'appel d'outil affiche `… waiting for your answer`. |
300-| Éditeur (ACP) | Le client a annoncé `clientCapabilities.elicitation.form` : une requête `elicitation/create` par appel (voir [ACP](acp.md#requêtes-elicitationcreate-envoyées)). Sinon, quand chaque question est un `choice` ou un `confirm` : un dialogue `session/request_permission` par question, dont les boutons sont les options (`Yes`/`No` pour un `confirm`) et `Decline`. Sinon : personne ne peut être interrogé. |301+| Éditeur (ACP) | Le client a annoncé `clientCapabilities.elicitation.form` : une requête `elicitation/create` par appel (voir [ACP](acp.md#requêtes-elicitationcreate-envoyées)). Sinon, quand chaque question est un `choice` ou un `confirm` : un dialogue `session/request_permission` par question, dont les boutons sont les options (`Yes`/`No` pour un `confirm`), `Other…` pour un `choice` avec la ligne Other, et `Decline`. Un dialogue n'a pas de champ de texte : `Other…` répond par une demande de poser la question dans la réponse (voir Résultat). Sinon : personne ne peut être interrogé. Dans le formulaire, la ligne Other est `Other…` à la fin de l'`enum` d'un `choice` et une propriété texte facultative `<nom>_other` (`Your own answer …`) ; le formulaire d'un agent interrogé est relayé avec les deux. |
301 | Agent interrogé (`/ask`, `ask_agent`) | Ses questions remontent à l'utilisateur de l'agent qui l'interroge, par l'interface de ce dernier, chacune préfixée `<agent> asks: `. Avec `mm --ask`, personne ne peut être interrogé. |302 | Agent interrogé (`/ask`, `ask_agent`) | Ses questions remontent à l'utilisateur de l'agent qui l'interroge, par l'interface de ce dernier, chacune préfixée `<agent> asks: `. Avec `mm --ask`, personne ne peut être interrogé. |
302 | Exécution unique (`-p`) | Personne ne peut être interrogé. |303 | Exécution unique (`-p`) | Personne ne peut être interrogé. |
303 | Chien de garde | Tant qu'une question attend, le chien de garde de la génération est relancé chaque seconde : attendre un humain ne termine pas le tour. Un tour arrêté annule la question. |304 | Chien de garde | Tant qu'une question attend, le chien de garde de la génération est relancé chaque seconde : attendre un humain ne termine pas le tour. Un tour arrêté annule la question. |
304-| Résultat | Répondu : `The user answered:` puis une ligne `- <question> → <réponse>` par question (plusieurs options jointes par `, `). Refusé : `[the user declined to answer: do not ask the same thing again; go on without it or stop]`. Annulé : `[the question was cancelled before the user answered]`. Personne à interroger : `[the user cannot be asked in this mode: make a reasonable assumption, say which, and go on]`. Tout ce qui n'est pas une réponse termine l'appel en échec dans la fenêtre et l'éditeur. |305+| Résultat | Répondu : `The user answered:` puis une ligne `- <question> → <réponse>` par question (plusieurs options jointes par `, `). La réponse propre de l'utilisateur se lit `typed by the user, not one of your options: "<texte>"`, après les options cochées et ` + ` sur un `multi` ; `Other…` choisi là où rien ne pouvait être tapé se lit `the user wants to give an answer that is not one of your options: ask them for it in your reply, as a plain question`. Refusé : `[the user declined to answer: do not ask the same thing again; go on without it or stop]`. Annulé : `[the question was cancelled before the user answered]`. Personne à interroger : `[the user cannot be asked in this mode: make a reasonable assumption, say which, and go on]`. Tout ce qui n'est pas une réponse termine l'appel en échec dans la fenêtre et l'éditeur. |
305 | Erreurs | `[ask_user: no question — send questions: [{question, type, options}]]` ; `[ask_user: N questions — ask at most 4 at a time]` ; `[ask_user: question N has no text]` ; `[ask_user: question N is a choice question — give it at least two options]` (ou `multi`) ; `[ask_user: question N has type "x" — use choice, multi, text or confirm]`. |306 | Erreurs | `[ask_user: no question — send questions: [{question, type, options}]]` ; `[ask_user: N questions — ask at most 4 at a time]` ; `[ask_user: question N has no text]` ; `[ask_user: question N is a choice question — give it at least two options]` (ou `multi`) ; `[ask_user: question N has type "x" — use choice, multi, text or confirm]`. |
306 307
307 ## `save_answer`308 ## `save_answer`
modified internal/acp/elicit.go +16 -3
@@ -19,7 +19,9 @@ import (
1919 // draws as a form;
2020 // 2. it did not, and every question is a choice or a yes/no: each question
2121 // goes as a `session/request_permission` dialog whose buttons are the
22-// options — every ACP editor shows that dialog;
22+// options — every ACP editor shows that dialog. A dialog has no text
23+// field: its "Other…" button (ticket 258) tells the model to ask for the
24+// user's own answer in its reply;
2325 // 3. otherwise (free text, several choices): nobody can be asked here, and
2426 // the model is told so.
2527
@@ -78,8 +80,12 @@ func choicesOnly(f elicit.Form) bool {
7880 return true
7981 }
8082
81-// declineOption is the dialog button that declines the question.
82-const declineOption = "decline"
83+// declineOption is the dialog button that declines the question;
84+// otherOption the one that asks for another answer (ticket 258).
85+const (
86+ declineOption = "decline"
87+ otherOption = "other"
88+)
8389
8490 // elicitByPermission asks each question as a permission dialog whose buttons
8591 // are its options, plus one to decline. The dialog belongs to the ask_user
@@ -95,6 +101,9 @@ func (k *sink) elicitByPermission(ctx context.Context, ev ui.ToolEvent, f elicit
95101 for i, label := range labels {
96102 options = append(options, sdk.PermissionOption{OptionId: sdk.PermissionOptionId(fmt.Sprint(i)), Name: label, Kind: sdk.PermissionOptionKindAllowOnce})
97103 }
104+ if q.Kind == elicit.Choice && q.AllowOther {
105+ options = append(options, sdk.PermissionOption{OptionId: otherOption, Name: elicit.OtherLabel, Kind: sdk.PermissionOptionKindAllowOnce})
106+ }
98107 options = append(options, sdk.PermissionOption{OptionId: declineOption, Name: "Decline", Kind: sdk.PermissionOptionKindRejectOnce})
99108 resp, err := k.f.conn.RequestPermission(ctx, sdk.RequestPermissionRequest{
100109 SessionId: k.sid,
@@ -114,6 +123,10 @@ func (k *sink) elicitByPermission(ctx context.Context, ev ui.ToolEvent, f elicit
114123 if chosen == declineOption {
115124 return elicit.Result{Status: elicit.Declined}
116125 }
126+ if chosen == otherOption {
127+ res.Answers = append(res.Answers, elicit.Answer{OtherAsked: true})
128+ continue
129+ }
117130 var i int
118131 if _, err := fmt.Sscan(chosen, &i); err != nil || i < 0 || i >= len(labels) {
119132 return elicit.Result{Status: elicit.Cancelled}
@@ -19,7 +19,9 @@ import (
19 // draws as a form;19 // draws as a form;
20 // 2. it did not, and every question is a choice or a yes/no: each question20 // 2. it did not, and every question is a choice or a yes/no: each question
21 // goes as a `session/request_permission` dialog whose buttons are the21 // goes as a `session/request_permission` dialog whose buttons are the
22-// options — every ACP editor shows that dialog;22+// options — every ACP editor shows that dialog. A dialog has no text
23+// field: its "Other…" button (ticket 258) tells the model to ask for the
24+// user's own answer in its reply;
23 // 3. otherwise (free text, several choices): nobody can be asked here, and25 // 3. otherwise (free text, several choices): nobody can be asked here, and
24 // the model is told so.26 // the model is told so.
25 27
@@ -78,8 +80,12 @@ func choicesOnly(f elicit.Form) bool {
78 return true80 return true
79 }81 }
80 82
81-// declineOption is the dialog button that declines the question.83+// declineOption is the dialog button that declines the question;
82-const declineOption = "decline"84+// otherOption the one that asks for another answer (ticket 258).
85+const (
86+ declineOption = "decline"
87+ otherOption = "other"
88+)
83 89
84 // elicitByPermission asks each question as a permission dialog whose buttons90 // elicitByPermission asks each question as a permission dialog whose buttons
85 // are its options, plus one to decline. The dialog belongs to the ask_user91 // are its options, plus one to decline. The dialog belongs to the ask_user
@@ -95,6 +101,9 @@ func (k *sink) elicitByPermission(ctx context.Context, ev ui.ToolEvent, f elicit
95 for i, label := range labels {101 for i, label := range labels {
96 options = append(options, sdk.PermissionOption{OptionId: sdk.PermissionOptionId(fmt.Sprint(i)), Name: label, Kind: sdk.PermissionOptionKindAllowOnce})102 options = append(options, sdk.PermissionOption{OptionId: sdk.PermissionOptionId(fmt.Sprint(i)), Name: label, Kind: sdk.PermissionOptionKindAllowOnce})
97 }103 }
104+ if q.Kind == elicit.Choice && q.AllowOther {
105+ options = append(options, sdk.PermissionOption{OptionId: otherOption, Name: elicit.OtherLabel, Kind: sdk.PermissionOptionKindAllowOnce})
106+ }
98 options = append(options, sdk.PermissionOption{OptionId: declineOption, Name: "Decline", Kind: sdk.PermissionOptionKindRejectOnce})107 options = append(options, sdk.PermissionOption{OptionId: declineOption, Name: "Decline", Kind: sdk.PermissionOptionKindRejectOnce})
99 resp, err := k.f.conn.RequestPermission(ctx, sdk.RequestPermissionRequest{108 resp, err := k.f.conn.RequestPermission(ctx, sdk.RequestPermissionRequest{
100 SessionId: k.sid,109 SessionId: k.sid,
@@ -114,6 +123,10 @@ func (k *sink) elicitByPermission(ctx context.Context, ev ui.ToolEvent, f elicit
114 if chosen == declineOption {123 if chosen == declineOption {
115 return elicit.Result{Status: elicit.Declined}124 return elicit.Result{Status: elicit.Declined}
116 }125 }
126+ if chosen == otherOption {
127+ res.Answers = append(res.Answers, elicit.Answer{OtherAsked: true})
128+ continue
129+ }
117 var i int130 var i int
118 if _, err := fmt.Sscan(chosen, &i); err != nil || i < 0 || i >= len(labels) {131 if _, err := fmt.Sscan(chosen, &i); err != nil || i < 0 || i >= len(labels) {
119 return elicit.Result{Status: elicit.Cancelled}132 return elicit.Result{Status: elicit.Cancelled}
modified internal/acp/elicit_test.go +51 -0
@@ -192,3 +192,54 @@ func TestLiftElicitationScope(t *testing.T) {
192192 t.Error("another message was rewritten")
193193 }
194194 }
195+
196+// Ticket 258, form mode: the Other row is the enum's last value plus a
197+// <name>_other text field, not required; the typed text comes back as the
198+// user's own answer.
199+func TestElicitFormCarriesOther(t *testing.T) {
200+ w, k := initialized(t, `{"elicitation":{"form":{}}}`)
201+ f := elicit.Form{Questions: []elicit.Question{
202+ {Name: "q1", Prompt: "Which environment?", Kind: elicit.Choice, Options: []string{"Dev", "Prod"}, AllowOther: true},
203+ }}
204+ got := elicitAsync(k, f)
205+ req := w.nextRequest()
206+ schema := req["params"].(map[string]any)["requestedSchema"].(map[string]any)
207+ props := schema["properties"].(map[string]any)
208+ enum := props["q1"].(map[string]any)["enum"].([]any)
209+ if enum[len(enum)-1] != elicit.OtherLabel || props["q1_other"] == nil {
210+ t.Fatalf("schema: %v", props)
211+ }
212+ if req, _ := schema["required"].([]any); len(req) != 1 || req[0] != "q1" {
213+ t.Errorf("required = %v", schema["required"])
214+ }
215+ w.reply(req["id"], `{"action":"accept","content":{"q1":"Other…","q1_other":"a QA box"}}`)
216+ res := <-got
217+ if res.Status != elicit.Answered || !reflect.DeepEqual(res.Answers, []elicit.Answer{{Other: "a QA box"}}) {
218+ t.Errorf("got %+v", res)
219+ }
220+}
221+
222+// Ticket 258, dialog fallback: an "Other…" button, which a dialog cannot
223+// follow with a text field — the model is told to ask in its reply.
224+func TestElicitPermissionOtherButton(t *testing.T) {
225+ w, k := initialized(t, `{}`)
226+ got := elicitAsync(k, elicit.Form{Questions: []elicit.Question{
227+ {Name: "q1", Prompt: "Which environment?", Kind: elicit.Choice, Options: []string{"Dev", "Prod"}, AllowOther: true},
228+ }})
229+ req := w.nextRequest()
230+ var names []string
231+ for _, o := range req["params"].(map[string]any)["options"].([]any) {
232+ names = append(names, o.(map[string]any)["name"].(string))
233+ }
234+ if strings.Join(names, ",") != "Dev,Prod,Other…,Decline" {
235+ t.Errorf("buttons: %v", names)
236+ }
237+ w.reply(req["id"], `{"outcome":{"outcome":"selected","optionId":"other"}}`)
238+ res := <-got
239+ if res.Status != elicit.Answered || !res.Answers[0].OtherAsked {
240+ t.Errorf("got %+v", res)
241+ }
242+ if !strings.Contains(res.Text(elicit.Form{Questions: []elicit.Question{{Prompt: "Which environment?"}}}), "ask them for it in your reply") {
243+ t.Errorf("text: %s", res.Text(elicit.Form{}))
244+ }
245+}
@@ -192,3 +192,54 @@ func TestLiftElicitationScope(t *testing.T) {
192 t.Error("another message was rewritten")192 t.Error("another message was rewritten")
193 }193 }
194 }194 }
195+
196+// Ticket 258, form mode: the Other row is the enum's last value plus a
197+// <name>_other text field, not required; the typed text comes back as the
198+// user's own answer.
199+func TestElicitFormCarriesOther(t *testing.T) {
200+ w, k := initialized(t, `{"elicitation":{"form":{}}}`)
201+ f := elicit.Form{Questions: []elicit.Question{
202+ {Name: "q1", Prompt: "Which environment?", Kind: elicit.Choice, Options: []string{"Dev", "Prod"}, AllowOther: true},
203+ }}
204+ got := elicitAsync(k, f)
205+ req := w.nextRequest()
206+ schema := req["params"].(map[string]any)["requestedSchema"].(map[string]any)
207+ props := schema["properties"].(map[string]any)
208+ enum := props["q1"].(map[string]any)["enum"].([]any)
209+ if enum[len(enum)-1] != elicit.OtherLabel || props["q1_other"] == nil {
210+ t.Fatalf("schema: %v", props)
211+ }
212+ if req, _ := schema["required"].([]any); len(req) != 1 || req[0] != "q1" {
213+ t.Errorf("required = %v", schema["required"])
214+ }
215+ w.reply(req["id"], `{"action":"accept","content":{"q1":"Other…","q1_other":"a QA box"}}`)
216+ res := <-got
217+ if res.Status != elicit.Answered || !reflect.DeepEqual(res.Answers, []elicit.Answer{{Other: "a QA box"}}) {
218+ t.Errorf("got %+v", res)
219+ }
220+}
221+
222+// Ticket 258, dialog fallback: an "Other…" button, which a dialog cannot
223+// follow with a text field — the model is told to ask in its reply.
224+func TestElicitPermissionOtherButton(t *testing.T) {
225+ w, k := initialized(t, `{}`)
226+ got := elicitAsync(k, elicit.Form{Questions: []elicit.Question{
227+ {Name: "q1", Prompt: "Which environment?", Kind: elicit.Choice, Options: []string{"Dev", "Prod"}, AllowOther: true},
228+ }})
229+ req := w.nextRequest()
230+ var names []string
231+ for _, o := range req["params"].(map[string]any)["options"].([]any) {
232+ names = append(names, o.(map[string]any)["name"].(string))
233+ }
234+ if strings.Join(names, ",") != "Dev,Prod,Other…,Decline" {
235+ t.Errorf("buttons: %v", names)
236+ }
237+ w.reply(req["id"], `{"outcome":{"outcome":"selected","optionId":"other"}}`)
238+ res := <-got
239+ if res.Status != elicit.Answered || !res.Answers[0].OtherAsked {
240+ t.Errorf("got %+v", res)
241+ }
242+ if !strings.Contains(res.Text(elicit.Form{Questions: []elicit.Question{{Prompt: "Which environment?"}}}), "ask them for it in your reply") {
243+ t.Errorf("text: %s", res.Text(elicit.Form{}))
244+ }
245+}
added internal/agent/askother_test.go +33 -0
new file mode 100644
@@ -0,0 +1,33 @@
1+package agent
2+
3+import (
4+ "testing"
5+
6+ "mm/internal/elicit"
7+)
8+
9+// The line mode's ask_user (ticket 258): the Other row's number asks for
10+// the text, which is the answer; an empty line asks again; typing the text
11+// straight away works too.
12+func TestFormRequestOtherRow(t *testing.T) {
13+ form := elicit.Form{Questions: []elicit.Question{
14+ {Name: "q1", Prompt: "Env?", Kind: elicit.Choice, Options: []string{"Dev", "Prod"}, AllowOther: true},
15+ {Name: "q2", Prompt: "Env again?", Kind: elicit.Choice, Options: []string{"Dev", "Prod"}, AllowOther: true},
16+ }}
17+ r := &formRequest{form: form, reply: make(chan elicit.Result, 1)}
18+ for _, line := range []string{"3", " ", "a QA box"} {
19+ if r.take(line) {
20+ t.Fatalf("form finished on %q", line)
21+ }
22+ }
23+ if r.next != 1 || r.answers[0].Other != "a QA box" || r.other {
24+ t.Fatalf("after the Other row: next %d, answers %+v, other %v", r.next, r.answers, r.other)
25+ }
26+ if !r.take("staging box") {
27+ t.Fatal("the form did not finish")
28+ }
29+ res := <-r.reply
30+ if res.Status != elicit.Answered || res.Answers[1].Other != "staging box" {
31+ t.Errorf("result = %+v", res)
32+ }
33+}
new file mode 100644
@@ -0,0 +1,33 @@
1+package agent
2+
3+import (
4+ "testing"
5+
6+ "mm/internal/elicit"
7+)
8+
9+// The line mode's ask_user (ticket 258): the Other row's number asks for
10+// the text, which is the answer; an empty line asks again; typing the text
11+// straight away works too.
12+func TestFormRequestOtherRow(t *testing.T) {
13+ form := elicit.Form{Questions: []elicit.Question{
14+ {Name: "q1", Prompt: "Env?", Kind: elicit.Choice, Options: []string{"Dev", "Prod"}, AllowOther: true},
15+ {Name: "q2", Prompt: "Env again?", Kind: elicit.Choice, Options: []string{"Dev", "Prod"}, AllowOther: true},
16+ }}
17+ r := &formRequest{form: form, reply: make(chan elicit.Result, 1)}
18+ for _, line := range []string{"3", " ", "a QA box"} {
19+ if r.take(line) {
20+ t.Fatalf("form finished on %q", line)
21+ }
22+ }
23+ if r.next != 1 || r.answers[0].Other != "a QA box" || r.other {
24+ t.Fatalf("after the Other row: next %d, answers %+v, other %v", r.next, r.answers, r.other)
25+ }
26+ if !r.take("staging box") {
27+ t.Fatal("the form did not finish")
28+ }
29+ res := <-r.reply
30+ if res.Status != elicit.Answered || res.Answers[1].Other != "staging box" {
31+ t.Errorf("result = %+v", res)
32+ }
33+}
modified internal/agent/prompt.go +18 -1
@@ -185,6 +185,9 @@ type formRequest struct {
185185 next int // the question being asked
186186 answers []elicit.Answer
187187 reply chan elicit.Result // buffered: the REPL never blocks answering
188+ // other: the user picked the Other row by its number (ticket 258); the
189+ // next line is their own answer.
190+ other bool
188191 }
189192
190193 func (r *formRequest) show() {
@@ -212,12 +215,26 @@ func (r *formRequest) take(line string) bool {
212215 return true
213216 }
214217 q := r.form.Questions[r.next]
218+ if !r.other && elicit.IsOtherPick(q, line) {
219+ r.other = true
220+ dimln(" " + elicit.OtherPrompt)
221+ fmt.Print(" ? ")
222+ return false
223+ }
215224 a, ok := elicit.ParseLine(q, line)
225+ if r.other {
226+ a, ok = elicit.ParseOther(line)
227+ }
216228 if !ok {
217- dimln(" " + elicit.Hint(q))
229+ if r.other {
230+ dimln(" " + elicit.OtherPrompt)
231+ } else {
232+ dimln(" " + elicit.Hint(q))
233+ }
218234 fmt.Print(" ? ")
219235 return false
220236 }
237+ r.other = false
221238 r.answers = append(r.answers, a)
222239 r.next++
223240 if r.next < len(r.form.Questions) {
@@ -185,6 +185,9 @@ type formRequest struct {
185 next int // the question being asked185 next int // the question being asked
186 answers []elicit.Answer186 answers []elicit.Answer
187 reply chan elicit.Result // buffered: the REPL never blocks answering187 reply chan elicit.Result // buffered: the REPL never blocks answering
188+ // other: the user picked the Other row by its number (ticket 258); the
189+ // next line is their own answer.
190+ other bool
188 }191 }
189 192
190 func (r *formRequest) show() {193 func (r *formRequest) show() {
@@ -212,12 +215,26 @@ func (r *formRequest) take(line string) bool {
212 return true215 return true
213 }216 }
214 q := r.form.Questions[r.next]217 q := r.form.Questions[r.next]
218+ if !r.other && elicit.IsOtherPick(q, line) {
219+ r.other = true
220+ dimln(" " + elicit.OtherPrompt)
221+ fmt.Print(" ? ")
222+ return false
223+ }
215 a, ok := elicit.ParseLine(q, line)224 a, ok := elicit.ParseLine(q, line)
225+ if r.other {
226+ a, ok = elicit.ParseOther(line)
227+ }
216 if !ok {228 if !ok {
217- dimln(" " + elicit.Hint(q))229+ if r.other {
230+ dimln(" " + elicit.OtherPrompt)
231+ } else {
232+ dimln(" " + elicit.Hint(q))
233+ }
218 fmt.Print(" ? ")234 fmt.Print(" ? ")
219 return false235 return false
220 }236 }
237+ r.other = false
221 r.answers = append(r.answers, a)238 r.answers = append(r.answers, a)
222 r.next++239 r.next++
223 if r.next < len(r.form.Questions) {240 if r.next < len(r.form.Questions) {
modified internal/elicit/elicit.go +89 -5
@@ -44,10 +44,20 @@ type Question struct {
4444 Name string // stable key: q1, q2… — the property name of an ACP form
4545 Prompt string // what the user reads
4646 Kind Kind //
47- Options []string // Choice and Multi only, at least two, no duplicates
47+ Options []string // Choice and Multi only, no duplicates, never an "Other" one
4848 Default string // optional: an option (Choice), "yes"/"no" (Confirm), a text
49+ // AllowOther (ticket 258): Choice and Multi offer a last row, OtherLabel,
50+ // where the user types an answer of their own — added by mm, not by the
51+ // model (small models forget it). On for every ask_user choice question
52+ // unless the model sent allow_other: false; off for the questions mm's
53+ // own wizards build.
54+ AllowOther bool
4955 }
5056
57+// OtherLabel is the row mm adds to a choice question that allows another
58+// answer.
59+const OtherLabel = "Other…"
60+
5161 // Form is one call's questions.
5262 type Form struct {
5363 Questions []Question
@@ -55,9 +65,33 @@ type Form struct {
5565
5666 // Answer is the user's answer to one question. Values holds the chosen
5767 // options (one for Choice, any number for Multi), the typed text (Text, or a
58-// Choice answered with another text), or "yes"/"no" (Confirm).
68+// Choice of a question without AllowOther answered with another text), or
69+// "yes"/"no" (Confirm). Other is the answer the user typed on the Other row
70+// (ticket 258) — alone for a Choice, beside the ticked options for a Multi.
71+// OtherAsked says the user chose Other where nothing could be typed (an
72+// editor's dialog buttons): the model is told to ask in its reply.
5973 type Answer struct {
60- Values []string
74+ Values []string
75+ Other string
76+ OtherAsked bool
77+}
78+
79+// value is the answer as the model reads it after the question's arrow.
80+func (a Answer) value() string {
81+ var parts []string
82+ if len(a.Values) > 0 {
83+ parts = append(parts, strings.Join(a.Values, ", "))
84+ }
85+ switch {
86+ case a.Other != "":
87+ parts = append(parts, fmt.Sprintf("typed by the user, not one of your options: %q", a.Other))
88+ case a.OtherAsked:
89+ parts = append(parts, "the user wants to give an answer that is not one of your options: ask them for it in your reply, as a plain question")
90+ }
91+ if len(parts) == 0 {
92+ return "(no answer)"
93+ }
94+ return strings.Join(parts, " + ")
6195 }
6296
6397 // Status says how a question ended.
@@ -95,8 +129,8 @@ func (r Result) Text(f Form) string {
95129 b.WriteString("The user answered:")
96130 for i, q := range f.Questions {
97131 value := "(no answer)"
98- if i < len(r.Answers) && len(r.Answers[i].Values) > 0 {
99- value = strings.Join(r.Answers[i].Values, ", ")
132+ if i < len(r.Answers) {
133+ value = r.Answers[i].value()
100134 }
101135 fmt.Fprintf(&b, "\n- %s → %s", q.Prompt, value)
102136 }
@@ -177,6 +211,16 @@ func normalizeQuestion(fields map[string]any, n int) (Question, string) {
177211 if len(q.Options) < 2 {
178212 return q, fmt.Sprintf("[ask_user: question %d is a %s question — give it at least two options]", n, q.Kind)
179213 }
214+ // Another answer is always possible, unless the model said only the
215+ // options make sense; an "Other" the model wrote is that row, not
216+ // a second one.
217+ q.AllowOther = !isFalse(fields["allow_other"]) && !isFalse(fields["allowOther"])
218+ if kept := withoutOther(q.Options); len(kept) < len(q.Options) {
219+ q.Options, q.AllowOther = kept, true
220+ }
221+ if len(q.Options) == 0 {
222+ q.Kind = Text
223+ }
180224 default:
181225 q.Options = nil
182226 }
@@ -205,6 +249,46 @@ func normalizeDefault(q Question, raw string) string {
205249 return "" // Multi: no default
206250 }
207251
252+// otherWords are the options a model writes for "something else": they are
253+// the Other row mm adds, not options of their own.
254+var otherWords = map[string]bool{
255+ "other": true, "others": true, "other answer": true, "something else": true,
256+ "autre": true, "autres": true, "autre réponse": true, "autre chose": true,
257+}
258+
259+// isOtherOption reports whether an option stands for "another answer":
260+// "Other", "Other…", "Other (please specify)", "Autre…".
261+func isOtherOption(option string) bool {
262+ o := strings.ToLower(strings.TrimSpace(option))
263+ if i := strings.IndexAny(o, "(:"); i > 0 {
264+ o = o[:i]
265+ }
266+ o = strings.TrimRight(strings.TrimSpace(o), ".…")
267+ return otherWords[o]
268+}
269+
270+func withoutOther(options []string) []string {
271+ var kept []string
272+ for _, option := range options {
273+ if !isOtherOption(option) {
274+ kept = append(kept, option)
275+ }
276+ }
277+ return kept
278+}
279+
280+// isFalse reads a JSON false, or the words a model may write for it.
281+func isFalse(v any) bool {
282+ switch x := v.(type) {
283+ case bool:
284+ return !x
285+ case string:
286+ yes, ok := parseYesNo(x)
287+ return ok && !yes
288+ }
289+ return false
290+}
291+
208292 func cleanOptions(v any) []string {
209293 list, _ := v.([]any)
210294 seen := map[string]bool{}
@@ -44,10 +44,20 @@ type Question struct {
44 Name string // stable key: q1, q2… — the property name of an ACP form44 Name string // stable key: q1, q2… — the property name of an ACP form
45 Prompt string // what the user reads45 Prompt string // what the user reads
46 Kind Kind //46 Kind Kind //
47- Options []string // Choice and Multi only, at least two, no duplicates47+ Options []string // Choice and Multi only, no duplicates, never an "Other" one
48 Default string // optional: an option (Choice), "yes"/"no" (Confirm), a text48 Default string // optional: an option (Choice), "yes"/"no" (Confirm), a text
49+ // AllowOther (ticket 258): Choice and Multi offer a last row, OtherLabel,
50+ // where the user types an answer of their own — added by mm, not by the
51+ // model (small models forget it). On for every ask_user choice question
52+ // unless the model sent allow_other: false; off for the questions mm's
53+ // own wizards build.
54+ AllowOther bool
49 }55 }
50 56
57+// OtherLabel is the row mm adds to a choice question that allows another
58+// answer.
59+const OtherLabel = "Other…"
60+
51 // Form is one call's questions.61 // Form is one call's questions.
52 type Form struct {62 type Form struct {
53 Questions []Question63 Questions []Question
@@ -55,9 +65,33 @@ type Form struct {
55 65
56 // Answer is the user's answer to one question. Values holds the chosen66 // Answer is the user's answer to one question. Values holds the chosen
57 // options (one for Choice, any number for Multi), the typed text (Text, or a67 // options (one for Choice, any number for Multi), the typed text (Text, or a
58-// Choice answered with another text), or "yes"/"no" (Confirm).68+// Choice of a question without AllowOther answered with another text), or
69+// "yes"/"no" (Confirm). Other is the answer the user typed on the Other row
70+// (ticket 258) — alone for a Choice, beside the ticked options for a Multi.
71+// OtherAsked says the user chose Other where nothing could be typed (an
72+// editor's dialog buttons): the model is told to ask in its reply.
59 type Answer struct {73 type Answer struct {
60- Values []string74+ Values []string
75+ Other string
76+ OtherAsked bool
77+}
78+
79+// value is the answer as the model reads it after the question's arrow.
80+func (a Answer) value() string {
81+ var parts []string
82+ if len(a.Values) > 0 {
83+ parts = append(parts, strings.Join(a.Values, ", "))
84+ }
85+ switch {
86+ case a.Other != "":
87+ parts = append(parts, fmt.Sprintf("typed by the user, not one of your options: %q", a.Other))
88+ case a.OtherAsked:
89+ parts = append(parts, "the user wants to give an answer that is not one of your options: ask them for it in your reply, as a plain question")
90+ }
91+ if len(parts) == 0 {
92+ return "(no answer)"
93+ }
94+ return strings.Join(parts, " + ")
61 }95 }
62 96
63 // Status says how a question ended.97 // Status says how a question ended.
@@ -95,8 +129,8 @@ func (r Result) Text(f Form) string {
95 b.WriteString("The user answered:")129 b.WriteString("The user answered:")
96 for i, q := range f.Questions {130 for i, q := range f.Questions {
97 value := "(no answer)"131 value := "(no answer)"
98- if i < len(r.Answers) && len(r.Answers[i].Values) > 0 {132+ if i < len(r.Answers) {
99- value = strings.Join(r.Answers[i].Values, ", ")133+ value = r.Answers[i].value()
100 }134 }
101 fmt.Fprintf(&b, "\n- %s → %s", q.Prompt, value)135 fmt.Fprintf(&b, "\n- %s → %s", q.Prompt, value)
102 }136 }
@@ -177,6 +211,16 @@ func normalizeQuestion(fields map[string]any, n int) (Question, string) {
177 if len(q.Options) < 2 {211 if len(q.Options) < 2 {
178 return q, fmt.Sprintf("[ask_user: question %d is a %s question — give it at least two options]", n, q.Kind)212 return q, fmt.Sprintf("[ask_user: question %d is a %s question — give it at least two options]", n, q.Kind)
179 }213 }
214+ // Another answer is always possible, unless the model said only the
215+ // options make sense; an "Other" the model wrote is that row, not
216+ // a second one.
217+ q.AllowOther = !isFalse(fields["allow_other"]) && !isFalse(fields["allowOther"])
218+ if kept := withoutOther(q.Options); len(kept) < len(q.Options) {
219+ q.Options, q.AllowOther = kept, true
220+ }
221+ if len(q.Options) == 0 {
222+ q.Kind = Text
223+ }
180 default:224 default:
181 q.Options = nil225 q.Options = nil
182 }226 }
@@ -205,6 +249,46 @@ func normalizeDefault(q Question, raw string) string {
205 return "" // Multi: no default249 return "" // Multi: no default
206 }250 }
207 251
252+// otherWords are the options a model writes for "something else": they are
253+// the Other row mm adds, not options of their own.
254+var otherWords = map[string]bool{
255+ "other": true, "others": true, "other answer": true, "something else": true,
256+ "autre": true, "autres": true, "autre réponse": true, "autre chose": true,
257+}
258+
259+// isOtherOption reports whether an option stands for "another answer":
260+// "Other", "Other…", "Other (please specify)", "Autre…".
261+func isOtherOption(option string) bool {
262+ o := strings.ToLower(strings.TrimSpace(option))
263+ if i := strings.IndexAny(o, "(:"); i > 0 {
264+ o = o[:i]
265+ }
266+ o = strings.TrimRight(strings.TrimSpace(o), ".…")
267+ return otherWords[o]
268+}
269+
270+func withoutOther(options []string) []string {
271+ var kept []string
272+ for _, option := range options {
273+ if !isOtherOption(option) {
274+ kept = append(kept, option)
275+ }
276+ }
277+ return kept
278+}
279+
280+// isFalse reads a JSON false, or the words a model may write for it.
281+func isFalse(v any) bool {
282+ switch x := v.(type) {
283+ case bool:
284+ return !x
285+ case string:
286+ yes, ok := parseYesNo(x)
287+ return ok && !yes
288+ }
289+ return false
290+}
291+
208 func cleanOptions(v any) []string {292 func cleanOptions(v any) []string {
209 list, _ := v.([]any)293 list, _ := v.([]any)
210 seen := map[string]bool{}294 seen := map[string]bool{}
modified internal/elicit/elicit_test.go +2 -2
@@ -34,8 +34,8 @@ func TestNormalizeReadsTheFourKinds(t *testing.T) {
3434 t.Fatal(problem)
3535 }
3636 want := []Question{
37- {Name: "q1", Prompt: "Which environment?", Kind: Choice, Options: []string{"Dev", "Prod"}},
38- {Name: "q2", Prompt: "Which features?", Kind: Multi, Options: []string{"A", "B", "C"}},
37+ {Name: "q1", Prompt: "Which environment?", Kind: Choice, Options: []string{"Dev", "Prod"}, AllowOther: true},
38+ {Name: "q2", Prompt: "Which features?", Kind: Multi, Options: []string{"A", "B", "C"}, AllowOther: true},
3939 {Name: "q3", Prompt: "Project name?", Kind: Text},
4040 {Name: "q4", Prompt: "Deploy now?", Kind: Confirm},
4141 }
@@ -34,8 +34,8 @@ func TestNormalizeReadsTheFourKinds(t *testing.T) {
34 t.Fatal(problem)34 t.Fatal(problem)
35 }35 }
36 want := []Question{36 want := []Question{
37- {Name: "q1", Prompt: "Which environment?", Kind: Choice, Options: []string{"Dev", "Prod"}},37+ {Name: "q1", Prompt: "Which environment?", Kind: Choice, Options: []string{"Dev", "Prod"}, AllowOther: true},
38- {Name: "q2", Prompt: "Which features?", Kind: Multi, Options: []string{"A", "B", "C"}},38+ {Name: "q2", Prompt: "Which features?", Kind: Multi, Options: []string{"A", "B", "C"}, AllowOther: true},
39 {Name: "q3", Prompt: "Project name?", Kind: Text},39 {Name: "q3", Prompt: "Project name?", Kind: Text},
40 {Name: "q4", Prompt: "Deploy now?", Kind: Confirm},40 {Name: "q4", Prompt: "Deploy now?", Kind: Confirm},
41 }41 }
modified internal/elicit/example_test.go +2 -1
@@ -27,7 +27,8 @@ func Example() {
2727 // 1. Development
2828 // 2. Staging
2929 // 3. Production
30- // number, or another answer · /skip to decline
30+ // 4. Other… (type your own answer)
31+ // number, or type your own answer · /skip to decline
3132 // The user answered:
3233 // - Which environment? → Staging
3334 }
@@ -27,7 +27,8 @@ func Example() {
27 // 1. Development27 // 1. Development
28 // 2. Staging28 // 2. Staging
29 // 3. Production29 // 3. Production
30- // number, or another answer · /skip to decline30+ // 4. Other… (type your own answer)
31+ // number, or type your own answer · /skip to decline
31 // The user answered:32 // The user answered:
32 // - Which environment? → Staging33 // - Which environment? → Staging
33 }34 }
modified internal/elicit/line.go +96 -13
@@ -16,7 +16,8 @@ import (
1616 // // ? Which environment would you like to use?
1717 // // 1. Development
1818 // // 2. Staging
19-// // number, or another answer · /skip to decline
19+// // 3. Other… (type your own answer)
20+// // number, or type your own answer · /skip to decline
2021 func Lines(q Question) []string {
2122 out := []string{"? " + q.Prompt}
2223 for i, option := range q.Options {
@@ -26,18 +27,46 @@ func Lines(q Question) []string {
2627 }
2728 out = append(out, fmt.Sprintf(" %d. %s%s", i+1, option, mark))
2829 }
30+ if q.AllowOther {
31+ out = append(out, fmt.Sprintf(" %d. %s (type your own answer)", len(q.Options)+1, OtherLabel))
32+ }
2933 return append(out, " "+Hint(q))
3034 }
3135
36+// IsOtherPick reports whether line picks q's Other row by its number: the
37+// caller then asks for the text on the next line (OtherPrompt) and answers
38+// with ParseOther.
39+func IsOtherPick(q Question, line string) bool {
40+ if !q.AllowOther || (q.Kind != Choice && q.Kind != Multi) {
41+ return false
42+ }
43+ n, err := strconv.Atoi(strings.TrimSpace(line))
44+ return err == nil && n == len(q.Options)+1
45+}
46+
47+// OtherPrompt is the line mode's prompt for the Other row's text.
48+const OtherPrompt = "your own answer (/skip to decline):"
49+
50+// ParseOther reads the text typed after picking the Other row; ok is false
51+// on an empty line.
52+func ParseOther(line string) (Answer, bool) {
53+ text := strings.TrimSpace(line)
54+ return Answer{Other: text}, text != ""
55+}
56+
3257 // Hint is the one-line reminder of how to answer q in the line mode.
3358 func Hint(q Question) string {
3459 var how string
35- switch q.Kind {
36- case Choice:
60+ switch {
61+ case q.Kind == Choice && q.AllowOther:
62+ how = "number, or type your own answer"
63+ case q.Kind == Choice:
3764 how = "number, or another answer"
38- case Multi:
65+ case q.Kind == Multi && q.AllowOther:
66+ how = "numbers separated by commas (1,3), and/or your own answer"
67+ case q.Kind == Multi:
3968 how = "numbers separated by commas (1,3)"
40- case Confirm:
69+ case q.Kind == Confirm:
4170 how = "y or n"
4271 if q.Default != "" {
4372 how += " (Enter = " + q.Default + ")"
@@ -83,7 +112,10 @@ func ParseLine(q Question, line string) (Answer, bool) {
83112
84113 // parseChoice: a number in range, an option's text or the start of exactly
85114 // one option ("n" for "No" — models ask yes/no as a choice too), or — like
86-// the "Other" row of a menu — any other text, taken as the answer.
115+// the "Other" row of a menu — any other text, taken as the answer: the
116+// user's own (Other) when the question allows one, the value itself for the
117+// questions of mm's wizards. The Other row's number is not an answer: see
118+// IsOtherPick.
87119 func parseChoice(q Question, line string) (Answer, bool) {
88120 if n, err := strconv.Atoi(line); err == nil {
89121 if n < 1 || n > len(q.Options) {
@@ -97,6 +129,9 @@ func parseChoice(q Question, line string) (Answer, bool) {
97129 if option, ok := matchPrefix(q.Options, line); ok {
98130 return Answer{Values: []string{option}}, true
99131 }
132+ if q.AllowOther {
133+ return Answer{Other: line}, true
134+ }
100135 return Answer{Values: []string{line}}, true
101136 }
102137
@@ -116,15 +151,29 @@ func matchPrefix(options []string, text string) (string, bool) {
116151 }
117152
118153 // parseMulti: numbers separated by commas or spaces, every one in range.
119-// Duplicates count once; the options keep their order.
154+// Duplicates count once; the options keep their order. When the question
155+// allows another answer, the line may also hold text — "1, 3, a QA box" —
156+// which is the user's own answer (Other), beside the ticked options.
120157 func parseMulti(q Question, line string) (Answer, bool) {
121158 picked := make([]bool, len(q.Options))
122- for _, field := range strings.FieldsFunc(line, func(r rune) bool { return r == ',' || r == ' ' || r == ';' }) {
123- n, err := strconv.Atoi(field)
124- if err != nil || n < 1 || n > len(q.Options) {
125- return Answer{}, false
159+ var other []string
160+ for _, item := range strings.FieldsFunc(line, func(r rune) bool { return r == ',' || r == ';' }) {
161+ item = strings.TrimSpace(item)
162+ numbers, ok := pickNumbers(q, item, picked)
163+ switch {
164+ case ok:
165+ case numbers:
166+ return Answer{}, false // a number out of range
167+ default:
168+ if option, found := matchOption(q.Options, item); found {
169+ picked[indexOf(q.Options, option)] = true
170+ continue
171+ }
172+ if !q.AllowOther {
173+ return Answer{}, false
174+ }
175+ other = append(other, item)
126176 }
127- picked[n-1] = true
128177 }
129178 var a Answer
130179 for i, on := range picked {
@@ -132,7 +181,41 @@ func parseMulti(q Question, line string) (Answer, bool) {
132181 a.Values = append(a.Values, q.Options[i])
133182 }
134183 }
135- return a, len(a.Values) > 0
184+ a.Other = strings.Join(other, ", ")
185+ return a, len(a.Values) > 0 || a.Other != ""
186+}
187+
188+// pickNumbers ticks the options an item names by number ("1 3" counts as
189+// two). numbers says the item is made of numbers only; ok that every one is
190+// in range.
191+func pickNumbers(q Question, item string, picked []bool) (numbers, ok bool) {
192+ fields := strings.Fields(item)
193+ var ns []int
194+ for _, field := range fields {
195+ n, err := strconv.Atoi(field)
196+ if err != nil {
197+ return false, false
198+ }
199+ ns = append(ns, n)
200+ }
201+ for _, n := range ns {
202+ if n < 1 || n > len(q.Options) {
203+ return true, false
204+ }
205+ }
206+ for _, n := range ns {
207+ picked[n-1] = true
208+ }
209+ return len(ns) > 0, len(ns) > 0
210+}
211+
212+func indexOf(list []string, s string) int {
213+ for i, x := range list {
214+ if x == s {
215+ return i
216+ }
217+ }
218+ return -1
136219 }
137220
138221 // IsSkip reports whether a typed line declines the question.
@@ -16,7 +16,8 @@ import (
16 // // ? Which environment would you like to use?16 // // ? Which environment would you like to use?
17 // // 1. Development17 // // 1. Development
18 // // 2. Staging18 // // 2. Staging
19-// // number, or another answer · /skip to decline19+// // 3. Other… (type your own answer)
20+// // number, or type your own answer · /skip to decline
20 func Lines(q Question) []string {21 func Lines(q Question) []string {
21 out := []string{"? " + q.Prompt}22 out := []string{"? " + q.Prompt}
22 for i, option := range q.Options {23 for i, option := range q.Options {
@@ -26,18 +27,46 @@ func Lines(q Question) []string {
26 }27 }
27 out = append(out, fmt.Sprintf(" %d. %s%s", i+1, option, mark))28 out = append(out, fmt.Sprintf(" %d. %s%s", i+1, option, mark))
28 }29 }
30+ if q.AllowOther {
31+ out = append(out, fmt.Sprintf(" %d. %s (type your own answer)", len(q.Options)+1, OtherLabel))
32+ }
29 return append(out, " "+Hint(q))33 return append(out, " "+Hint(q))
30 }34 }
31 35
36+// IsOtherPick reports whether line picks q's Other row by its number: the
37+// caller then asks for the text on the next line (OtherPrompt) and answers
38+// with ParseOther.
39+func IsOtherPick(q Question, line string) bool {
40+ if !q.AllowOther || (q.Kind != Choice && q.Kind != Multi) {
41+ return false
42+ }
43+ n, err := strconv.Atoi(strings.TrimSpace(line))
44+ return err == nil && n == len(q.Options)+1
45+}
46+
47+// OtherPrompt is the line mode's prompt for the Other row's text.
48+const OtherPrompt = "your own answer (/skip to decline):"
49+
50+// ParseOther reads the text typed after picking the Other row; ok is false
51+// on an empty line.
52+func ParseOther(line string) (Answer, bool) {
53+ text := strings.TrimSpace(line)
54+ return Answer{Other: text}, text != ""
55+}
56+
32 // Hint is the one-line reminder of how to answer q in the line mode.57 // Hint is the one-line reminder of how to answer q in the line mode.
33 func Hint(q Question) string {58 func Hint(q Question) string {
34 var how string59 var how string
35- switch q.Kind {60+ switch {
36- case Choice:61+ case q.Kind == Choice && q.AllowOther:
62+ how = "number, or type your own answer"
63+ case q.Kind == Choice:
37 how = "number, or another answer"64 how = "number, or another answer"
38- case Multi:65+ case q.Kind == Multi && q.AllowOther:
66+ how = "numbers separated by commas (1,3), and/or your own answer"
67+ case q.Kind == Multi:
39 how = "numbers separated by commas (1,3)"68 how = "numbers separated by commas (1,3)"
40- case Confirm:69+ case q.Kind == Confirm:
41 how = "y or n"70 how = "y or n"
42 if q.Default != "" {71 if q.Default != "" {
43 how += " (Enter = " + q.Default + ")"72 how += " (Enter = " + q.Default + ")"
@@ -83,7 +112,10 @@ func ParseLine(q Question, line string) (Answer, bool) {
83 112
84 // parseChoice: a number in range, an option's text or the start of exactly113 // parseChoice: a number in range, an option's text or the start of exactly
85 // one option ("n" for "No" — models ask yes/no as a choice too), or — like114 // one option ("n" for "No" — models ask yes/no as a choice too), or — like
86-// the "Other" row of a menu — any other text, taken as the answer.115+// the "Other" row of a menu — any other text, taken as the answer: the
116+// user's own (Other) when the question allows one, the value itself for the
117+// questions of mm's wizards. The Other row's number is not an answer: see
118+// IsOtherPick.
87 func parseChoice(q Question, line string) (Answer, bool) {119 func parseChoice(q Question, line string) (Answer, bool) {
88 if n, err := strconv.Atoi(line); err == nil {120 if n, err := strconv.Atoi(line); err == nil {
89 if n < 1 || n > len(q.Options) {121 if n < 1 || n > len(q.Options) {
@@ -97,6 +129,9 @@ func parseChoice(q Question, line string) (Answer, bool) {
97 if option, ok := matchPrefix(q.Options, line); ok {129 if option, ok := matchPrefix(q.Options, line); ok {
98 return Answer{Values: []string{option}}, true130 return Answer{Values: []string{option}}, true
99 }131 }
132+ if q.AllowOther {
133+ return Answer{Other: line}, true
134+ }
100 return Answer{Values: []string{line}}, true135 return Answer{Values: []string{line}}, true
101 }136 }
102 137
@@ -116,15 +151,29 @@ func matchPrefix(options []string, text string) (string, bool) {
116 }151 }
117 152
118 // parseMulti: numbers separated by commas or spaces, every one in range.153 // parseMulti: numbers separated by commas or spaces, every one in range.
119-// Duplicates count once; the options keep their order.154+// Duplicates count once; the options keep their order. When the question
155+// allows another answer, the line may also hold text — "1, 3, a QA box" —
156+// which is the user's own answer (Other), beside the ticked options.
120 func parseMulti(q Question, line string) (Answer, bool) {157 func parseMulti(q Question, line string) (Answer, bool) {
121 picked := make([]bool, len(q.Options))158 picked := make([]bool, len(q.Options))
122- for _, field := range strings.FieldsFunc(line, func(r rune) bool { return r == ',' || r == ' ' || r == ';' }) {159+ var other []string
123- n, err := strconv.Atoi(field)160+ for _, item := range strings.FieldsFunc(line, func(r rune) bool { return r == ',' || r == ';' }) {
124- if err != nil || n < 1 || n > len(q.Options) {161+ item = strings.TrimSpace(item)
125- return Answer{}, false162+ numbers, ok := pickNumbers(q, item, picked)
163+ switch {
164+ case ok:
165+ case numbers:
166+ return Answer{}, false // a number out of range
167+ default:
168+ if option, found := matchOption(q.Options, item); found {
169+ picked[indexOf(q.Options, option)] = true
170+ continue
171+ }
172+ if !q.AllowOther {
173+ return Answer{}, false
174+ }
175+ other = append(other, item)
126 }176 }
127- picked[n-1] = true
128 }177 }
129 var a Answer178 var a Answer
130 for i, on := range picked {179 for i, on := range picked {
@@ -132,7 +181,41 @@ func parseMulti(q Question, line string) (Answer, bool) {
132 a.Values = append(a.Values, q.Options[i])181 a.Values = append(a.Values, q.Options[i])
133 }182 }
134 }183 }
135- return a, len(a.Values) > 0184+ a.Other = strings.Join(other, ", ")
185+ return a, len(a.Values) > 0 || a.Other != ""
186+}
187+
188+// pickNumbers ticks the options an item names by number ("1 3" counts as
189+// two). numbers says the item is made of numbers only; ok that every one is
190+// in range.
191+func pickNumbers(q Question, item string, picked []bool) (numbers, ok bool) {
192+ fields := strings.Fields(item)
193+ var ns []int
194+ for _, field := range fields {
195+ n, err := strconv.Atoi(field)
196+ if err != nil {
197+ return false, false
198+ }
199+ ns = append(ns, n)
200+ }
201+ for _, n := range ns {
202+ if n < 1 || n > len(q.Options) {
203+ return true, false
204+ }
205+ }
206+ for _, n := range ns {
207+ picked[n-1] = true
208+ }
209+ return len(ns) > 0, len(ns) > 0
210+}
211+
212+func indexOf(list []string, s string) int {
213+ for i, x := range list {
214+ if x == s {
215+ return i
216+ }
217+ }
218+ return -1
136 }219 }
137 220
138 // IsSkip reports whether a typed line declines the question.221 // IsSkip reports whether a typed line declines the question.
added internal/elicit/other_test.go +150 -0
new file mode 100644
@@ -0,0 +1,150 @@
1+package elicit
2+
3+import (
4+ "reflect"
5+ "strings"
6+ "testing"
7+)
8+
9+// Ticket 258: every choice and multi question gets the Other row, unless the
10+// model turns it off; an "Other" the model wrote is that row, not a second
11+// one; text, confirm and mm's own questions never get it.
12+func TestNormalizeAddsOtherToChoices(t *testing.T) {
13+ form, problem := Normalize(questions(
14+ map[string]any{"question": "Env?", "options": options("Dev", "Prod")},
15+ map[string]any{"question": "Env again?", "options": options("Dev", "Prod"), "allow_other": false},
16+ map[string]any{"question": "Colour?", "options": options("Red", "Blue", "Other (please specify)")},
17+ map[string]any{"question": "Deploy?", "type": "confirm"},
18+ ))
19+ if problem != "" {
20+ t.Fatal(problem)
21+ }
22+ q := form.Questions
23+ if !q[0].AllowOther || q[1].AllowOther || q[3].AllowOther {
24+ t.Errorf("AllowOther = %v %v %v", q[0].AllowOther, q[1].AllowOther, q[3].AllowOther)
25+ }
26+ if !q[2].AllowOther || !reflect.DeepEqual(q[2].Options, []string{"Red", "Blue"}) {
27+ t.Errorf("model's Other not folded into the row: %+v", q[2])
28+ }
29+ form, _ = Normalize(questions(map[string]any{"question": "Env?", "options": options("Dev", "Prod"), "allowOther": "no"}))
30+ if form.Questions[0].AllowOther {
31+ t.Error(`allowOther: "no" ignored`)
32+ }
33+ for _, o := range []string{"Other", "other…", "Autre...", "Something else", "Other: specify"} {
34+ if !isOtherOption(o) {
35+ t.Errorf("%q is not taken for Other", o)
36+ }
37+ }
38+ for _, o := range []string{"Otherwise", "Mother", "None"} {
39+ if isOtherOption(o) {
40+ t.Errorf("%q taken for Other", o)
41+ }
42+ }
43+}
44+
45+// The line mode: the row is numbered after the options; its number asks
46+// for the text; typed text is the user's own answer — for a multi, beside
47+// the ticked options.
48+func TestLineModeOther(t *testing.T) {
49+ q := Question{Prompt: "Env?", Kind: Choice, Options: []string{"Dev", "Prod"}, AllowOther: true}
50+ lines := Lines(q)
51+ if lines[3] != " 3. Other… (type your own answer)" || !strings.Contains(lines[4], "type your own answer") {
52+ t.Errorf("lines = %q", lines)
53+ }
54+ if !IsOtherPick(q, " 3 ") || IsOtherPick(q, "2") || IsOtherPick(Question{Kind: Choice, Options: q.Options}, "3") {
55+ t.Error("IsOtherPick")
56+ }
57+ if a, ok := ParseLine(q, "3"); ok {
58+ t.Errorf("the Other number is an answer: %+v", a)
59+ }
60+ if a, ok := ParseOther(" a QA box "); !ok || a.Other != "a QA box" {
61+ t.Errorf("ParseOther = %+v, %v", a, ok)
62+ }
63+ if _, ok := ParseOther(" "); ok {
64+ t.Error("empty Other accepted")
65+ }
66+ if a, _ := ParseLine(q, "a QA box"); a.Other != "a QA box" || a.Values != nil {
67+ t.Errorf("typed text = %+v", a)
68+ }
69+ // mm's own wizards: no Other row, typed text is the value.
70+ if a, _ := ParseLine(Question{Kind: Choice, Options: q.Options}, "custom"); !reflect.DeepEqual(a.Values, []string{"custom"}) || a.Other != "" {
71+ t.Errorf("wizard choice = %+v", a)
72+ }
73+
74+ m := Question{Kind: Multi, Options: []string{"A", "B", "C"}, AllowOther: true}
75+ cases := []struct {
76+ line string
77+ values []string
78+ other string
79+ ok bool
80+ }{
81+ {"1, 3", []string{"A", "C"}, "", true},
82+ {"1 3", []string{"A", "C"}, "", true},
83+ {"2, a QA box", []string{"B"}, "a QA box", true},
84+ {"b, d", []string{"B"}, "d", true},
85+ {"just this", nil, "just this", true},
86+ {"1, 9", nil, "", false},
87+ }
88+ for _, c := range cases {
89+ a, ok := ParseLine(m, c.line)
90+ if ok != c.ok || (ok && (!reflect.DeepEqual(a.Values, c.values) || a.Other != c.other)) {
91+ t.Errorf("multi %q → %+v %v", c.line, a, ok)
92+ }
93+ }
94+ if _, ok := ParseLine(Question{Kind: Multi, Options: m.Options}, "1, d"); ok {
95+ t.Error("multi without Other accepted a text")
96+ }
97+}
98+
99+// What the model reads says the text was typed, not picked.
100+func TestResultTextMarksTheTypedAnswer(t *testing.T) {
101+ form := Form{Questions: []Question{{Prompt: "Env?"}, {Prompt: "Features?"}, {Prompt: "Colour?"}}}
102+ res := Result{Status: Answered, Answers: []Answer{
103+ {Other: "a QA box"},
104+ {Values: []string{"A"}, Other: "logging"},
105+ {OtherAsked: true},
106+ }}
107+ want := "The user answered:\n" +
108+ `- Env? → typed by the user, not one of your options: "a QA box"` + "\n" +
109+ `- Features? → A + typed by the user, not one of your options: "logging"` + "\n" +
110+ "- Colour? → the user wants to give an answer that is not one of your options: ask them for it in your reply, as a plain question"
111+ if got := res.Text(form); got != want {
112+ t.Errorf("got\n%s\nwant\n%s", got, want)
113+ }
114+}
115+
116+// Over ACP's form: OtherLabel ends a choice's enum, <name>_other holds the
117+// text; the schema and the content come back the same way an asked agent's
118+// question is relayed.
119+func TestSchemaCarriesOther(t *testing.T) {
120+ form, _ := Normalize(questions(
121+ map[string]any{"question": "Env?", "options": options("Dev", "Prod")},
122+ map[string]any{"question": "Features?", "type": "multi", "options": options("A", "B")},
123+ ))
124+ s := Schema(form)
125+ props := s["properties"].(map[string]any)
126+ enum := props["q1"].(map[string]any)["enum"].([]any)
127+ if enum[len(enum)-1] != OtherLabel || props["q1_other"] == nil || props["q2_other"] == nil {
128+ t.Fatalf("schema: %v", props)
129+ }
130+ if req := s["required"].([]any); len(req) != 2 {
131+ t.Errorf("required = %v, want only q1 and q2", req)
132+ }
133+ back, ok := FromSchema(s)
134+ if !ok || !reflect.DeepEqual(back, form) {
135+ t.Fatalf("schema round trip:\n%+v\nwant\n%+v", back, form)
136+ }
137+ answers := []Answer{{Other: "a QA box"}, {Values: []string{"A"}, Other: "logging"}}
138+ content := Content(form, answers)
139+ if content["q1"] != OtherLabel || content["q1_other"] != "a QA box" || content["q2_other"] != "logging" {
140+ t.Errorf("content = %v", content)
141+ }
142+ if got := FromContent(form, content); !reflect.DeepEqual(got.Answers, answers) {
143+ t.Errorf("content round trip: %+v", got.Answers)
144+ }
145+ // Other picked in the enum, nothing typed: the model is told to ask.
146+ got := FromContent(form, map[string]any{"q1": OtherLabel, "q2": []any{"B"}})
147+ if !got.Answers[0].OtherAsked || got.Answers[0].Values != nil || got.Answers[1].OtherAsked {
148+ t.Errorf("Other without text: %+v", got.Answers)
149+ }
150+}
new file mode 100644
@@ -0,0 +1,150 @@
1+package elicit
2+
3+import (
4+ "reflect"
5+ "strings"
6+ "testing"
7+)
8+
9+// Ticket 258: every choice and multi question gets the Other row, unless the
10+// model turns it off; an "Other" the model wrote is that row, not a second
11+// one; text, confirm and mm's own questions never get it.
12+func TestNormalizeAddsOtherToChoices(t *testing.T) {
13+ form, problem := Normalize(questions(
14+ map[string]any{"question": "Env?", "options": options("Dev", "Prod")},
15+ map[string]any{"question": "Env again?", "options": options("Dev", "Prod"), "allow_other": false},
16+ map[string]any{"question": "Colour?", "options": options("Red", "Blue", "Other (please specify)")},
17+ map[string]any{"question": "Deploy?", "type": "confirm"},
18+ ))
19+ if problem != "" {
20+ t.Fatal(problem)
21+ }
22+ q := form.Questions
23+ if !q[0].AllowOther || q[1].AllowOther || q[3].AllowOther {
24+ t.Errorf("AllowOther = %v %v %v", q[0].AllowOther, q[1].AllowOther, q[3].AllowOther)
25+ }
26+ if !q[2].AllowOther || !reflect.DeepEqual(q[2].Options, []string{"Red", "Blue"}) {
27+ t.Errorf("model's Other not folded into the row: %+v", q[2])
28+ }
29+ form, _ = Normalize(questions(map[string]any{"question": "Env?", "options": options("Dev", "Prod"), "allowOther": "no"}))
30+ if form.Questions[0].AllowOther {
31+ t.Error(`allowOther: "no" ignored`)
32+ }
33+ for _, o := range []string{"Other", "other…", "Autre...", "Something else", "Other: specify"} {
34+ if !isOtherOption(o) {
35+ t.Errorf("%q is not taken for Other", o)
36+ }
37+ }
38+ for _, o := range []string{"Otherwise", "Mother", "None"} {
39+ if isOtherOption(o) {
40+ t.Errorf("%q taken for Other", o)
41+ }
42+ }
43+}
44+
45+// The line mode: the row is numbered after the options; its number asks
46+// for the text; typed text is the user's own answer — for a multi, beside
47+// the ticked options.
48+func TestLineModeOther(t *testing.T) {
49+ q := Question{Prompt: "Env?", Kind: Choice, Options: []string{"Dev", "Prod"}, AllowOther: true}
50+ lines := Lines(q)
51+ if lines[3] != " 3. Other… (type your own answer)" || !strings.Contains(lines[4], "type your own answer") {
52+ t.Errorf("lines = %q", lines)
53+ }
54+ if !IsOtherPick(q, " 3 ") || IsOtherPick(q, "2") || IsOtherPick(Question{Kind: Choice, Options: q.Options}, "3") {
55+ t.Error("IsOtherPick")
56+ }
57+ if a, ok := ParseLine(q, "3"); ok {
58+ t.Errorf("the Other number is an answer: %+v", a)
59+ }
60+ if a, ok := ParseOther(" a QA box "); !ok || a.Other != "a QA box" {
61+ t.Errorf("ParseOther = %+v, %v", a, ok)
62+ }
63+ if _, ok := ParseOther(" "); ok {
64+ t.Error("empty Other accepted")
65+ }
66+ if a, _ := ParseLine(q, "a QA box"); a.Other != "a QA box" || a.Values != nil {
67+ t.Errorf("typed text = %+v", a)
68+ }
69+ // mm's own wizards: no Other row, typed text is the value.
70+ if a, _ := ParseLine(Question{Kind: Choice, Options: q.Options}, "custom"); !reflect.DeepEqual(a.Values, []string{"custom"}) || a.Other != "" {
71+ t.Errorf("wizard choice = %+v", a)
72+ }
73+
74+ m := Question{Kind: Multi, Options: []string{"A", "B", "C"}, AllowOther: true}
75+ cases := []struct {
76+ line string
77+ values []string
78+ other string
79+ ok bool
80+ }{
81+ {"1, 3", []string{"A", "C"}, "", true},
82+ {"1 3", []string{"A", "C"}, "", true},
83+ {"2, a QA box", []string{"B"}, "a QA box", true},
84+ {"b, d", []string{"B"}, "d", true},
85+ {"just this", nil, "just this", true},
86+ {"1, 9", nil, "", false},
87+ }
88+ for _, c := range cases {
89+ a, ok := ParseLine(m, c.line)
90+ if ok != c.ok || (ok && (!reflect.DeepEqual(a.Values, c.values) || a.Other != c.other)) {
91+ t.Errorf("multi %q → %+v %v", c.line, a, ok)
92+ }
93+ }
94+ if _, ok := ParseLine(Question{Kind: Multi, Options: m.Options}, "1, d"); ok {
95+ t.Error("multi without Other accepted a text")
96+ }
97+}
98+
99+// What the model reads says the text was typed, not picked.
100+func TestResultTextMarksTheTypedAnswer(t *testing.T) {
101+ form := Form{Questions: []Question{{Prompt: "Env?"}, {Prompt: "Features?"}, {Prompt: "Colour?"}}}
102+ res := Result{Status: Answered, Answers: []Answer{
103+ {Other: "a QA box"},
104+ {Values: []string{"A"}, Other: "logging"},
105+ {OtherAsked: true},
106+ }}
107+ want := "The user answered:\n" +
108+ `- Env? → typed by the user, not one of your options: "a QA box"` + "\n" +
109+ `- Features? → A + typed by the user, not one of your options: "logging"` + "\n" +
110+ "- Colour? → the user wants to give an answer that is not one of your options: ask them for it in your reply, as a plain question"
111+ if got := res.Text(form); got != want {
112+ t.Errorf("got\n%s\nwant\n%s", got, want)
113+ }
114+}
115+
116+// Over ACP's form: OtherLabel ends a choice's enum, <name>_other holds the
117+// text; the schema and the content come back the same way an asked agent's
118+// question is relayed.
119+func TestSchemaCarriesOther(t *testing.T) {
120+ form, _ := Normalize(questions(
121+ map[string]any{"question": "Env?", "options": options("Dev", "Prod")},
122+ map[string]any{"question": "Features?", "type": "multi", "options": options("A", "B")},
123+ ))
124+ s := Schema(form)
125+ props := s["properties"].(map[string]any)
126+ enum := props["q1"].(map[string]any)["enum"].([]any)
127+ if enum[len(enum)-1] != OtherLabel || props["q1_other"] == nil || props["q2_other"] == nil {
128+ t.Fatalf("schema: %v", props)
129+ }
130+ if req := s["required"].([]any); len(req) != 2 {
131+ t.Errorf("required = %v, want only q1 and q2", req)
132+ }
133+ back, ok := FromSchema(s)
134+ if !ok || !reflect.DeepEqual(back, form) {
135+ t.Fatalf("schema round trip:\n%+v\nwant\n%+v", back, form)
136+ }
137+ answers := []Answer{{Other: "a QA box"}, {Values: []string{"A"}, Other: "logging"}}
138+ content := Content(form, answers)
139+ if content["q1"] != OtherLabel || content["q1_other"] != "a QA box" || content["q2_other"] != "logging" {
140+ t.Errorf("content = %v", content)
141+ }
142+ if got := FromContent(form, content); !reflect.DeepEqual(got.Answers, answers) {
143+ t.Errorf("content round trip: %+v", got.Answers)
144+ }
145+ // Other picked in the enum, nothing typed: the model is told to ask.
146+ got := FromContent(form, map[string]any{"q1": OtherLabel, "q2": []any{"B"}})
147+ if !got.Answers[0].OtherAsked || got.Answers[0].Values != nil || got.Answers[1].OtherAsked {
148+ t.Errorf("Other without text: %+v", got.Answers)
149+ }
150+}
modified internal/elicit/schema.go +75 -5
@@ -31,23 +31,45 @@ func Message(f Form) string {
3131 // Text → {"type": "string", "title": …}
3232 // Confirm → {"type": "boolean", "title": …}
3333 //
34-// Every question is required: declining is the user's other way out.
34+// A question that allows another answer (ticket 258) gets OtherLabel at the
35+// end of a Choice's enum and a second, optional property <name>_other — a
36+// free string — where the user types it. Every question is required:
37+// declining is the user's other way out.
3538 func Schema(f Form) map[string]any {
3639 properties := map[string]any{}
3740 var required []any
3841 for _, q := range f.Questions {
3942 properties[q.Name] = propertySchema(q)
4043 required = append(required, q.Name)
44+ if q.AllowOther && (q.Kind == Choice || q.Kind == Multi) {
45+ properties[OtherName(q)] = map[string]any{"type": "string", "title": otherTitle(q)}
46+ }
4147 }
4248 return map[string]any{"type": "object", "properties": properties, "required": required}
4349 }
4450
51+// OtherName is the property that holds q's typed answer in a form.
52+func OtherName(q Question) string { return q.Name + otherSuffix }
53+
54+const otherSuffix = "_other"
55+
56+func otherTitle(q Question) string {
57+ if q.Kind == Choice {
58+ return "Your own answer (pick " + OtherLabel + " above)"
59+ }
60+ return "Your own answer (optional)"
61+}
62+
4563 func propertySchema(q Question) map[string]any {
4664 p := map[string]any{"title": q.Prompt}
4765 switch q.Kind {
4866 case Choice:
4967 p["type"] = "string"
50- p["enum"] = toAny(q.Options)
68+ options := q.Options
69+ if q.AllowOther {
70+ options = append(append([]string(nil), options...), OtherLabel)
71+ }
72+ p["enum"] = toAny(options)
5173 case Multi:
5274 p["type"] = "array"
5375 p["items"] = map[string]any{"type": "string", "enum": toAny(q.Options)}
@@ -85,7 +107,16 @@ func FromSchema(schema map[string]any) (Form, bool) {
85107 if p == nil {
86108 continue
87109 }
88- form.Questions = append(form.Questions, questionOf(name, p))
110+ // q1_other beside q1 is q1's Other row, not a question (Schema).
111+ if base, ok := strings.CutSuffix(name, otherSuffix); ok && properties[base] != nil {
112+ continue
113+ }
114+ q := questionOf(name, p)
115+ if properties[OtherName(q)] != nil && (q.Kind == Choice || q.Kind == Multi) {
116+ q.AllowOther = true
117+ q.Options = withoutOther(q.Options)
118+ }
119+ form.Questions = append(form.Questions, q)
89120 }
90121 return form, len(form.Questions) > 0
91122 }
@@ -161,7 +192,8 @@ func Content(f Form, answers []Answer) map[string]any {
161192 if i >= len(answers) {
162193 break
163194 }
164- values := answers[i].Values
195+ a := answers[i]
196+ values := a.Values
165197 switch q.Kind {
166198 case Multi:
167199 content[q.Name] = toAny(values)
@@ -172,6 +204,14 @@ func Content(f Form, answers []Answer) map[string]any {
172204 content[q.Name] = values[0]
173205 }
174206 }
207+ if q.AllowOther && (a.Other != "" || a.OtherAsked) {
208+ if q.Kind == Choice {
209+ content[q.Name] = OtherLabel
210+ }
211+ if a.Other != "" {
212+ content[OtherName(q)] = a.Other
213+ }
214+ }
175215 }
176216 return content
177217 }
@@ -183,11 +223,41 @@ func Content(f Form, answers []Answer) map[string]any {
183223 func FromContent(f Form, content map[string]any) Result {
184224 res := Result{Status: Answered}
185225 for _, q := range f.Questions {
186- res.Answers = append(res.Answers, Answer{Values: valuesOf(q, content[q.Name])})
226+ res.Answers = append(res.Answers, answerOf(q, content))
187227 }
188228 return res
189229 }
190230
231+// answerOf reads one question's answer from a form's content: its values,
232+// and — when it allows another answer — the text typed in <name>_other.
233+// OtherLabel among the values is the Other row, not an option; picked
234+// with nothing typed, the model is told to ask (OtherAsked).
235+func answerOf(q Question, content map[string]any) Answer {
236+ a := Answer{Values: valuesOf(q, content[q.Name])}
237+ if !q.AllowOther {
238+ return a
239+ }
240+ picked := false
241+ kept := a.Values[:0]
242+ for _, v := range a.Values {
243+ if v == OtherLabel || isOtherOption(v) {
244+ picked = true
245+ continue
246+ }
247+ kept = append(kept, v)
248+ }
249+ a.Values = kept
250+ a.Other = strings.TrimSpace(str(content[OtherName(q)]))
251+ if q.Kind == Choice && a.Other != "" {
252+ a.Values = nil // a choice has one answer: the typed one wins
253+ }
254+ a.OtherAsked = picked && a.Other == ""
255+ if len(a.Values) == 0 {
256+ a.Values = nil
257+ }
258+ return a
259+}
260+
191261 func valuesOf(q Question, v any) []string {
192262 switch x := v.(type) {
193263 case nil:
@@ -31,23 +31,45 @@ func Message(f Form) string {
31 // Text → {"type": "string", "title": …}31 // Text → {"type": "string", "title": …}
32 // Confirm → {"type": "boolean", "title": …}32 // Confirm → {"type": "boolean", "title": …}
33 //33 //
34-// Every question is required: declining is the user's other way out.34+// A question that allows another answer (ticket 258) gets OtherLabel at the
35+// end of a Choice's enum and a second, optional property <name>_other — a
36+// free string — where the user types it. Every question is required:
37+// declining is the user's other way out.
35 func Schema(f Form) map[string]any {38 func Schema(f Form) map[string]any {
36 properties := map[string]any{}39 properties := map[string]any{}
37 var required []any40 var required []any
38 for _, q := range f.Questions {41 for _, q := range f.Questions {
39 properties[q.Name] = propertySchema(q)42 properties[q.Name] = propertySchema(q)
40 required = append(required, q.Name)43 required = append(required, q.Name)
44+ if q.AllowOther && (q.Kind == Choice || q.Kind == Multi) {
45+ properties[OtherName(q)] = map[string]any{"type": "string", "title": otherTitle(q)}
46+ }
41 }47 }
42 return map[string]any{"type": "object", "properties": properties, "required": required}48 return map[string]any{"type": "object", "properties": properties, "required": required}
43 }49 }
44 50
51+// OtherName is the property that holds q's typed answer in a form.
52+func OtherName(q Question) string { return q.Name + otherSuffix }
53+
54+const otherSuffix = "_other"
55+
56+func otherTitle(q Question) string {
57+ if q.Kind == Choice {
58+ return "Your own answer (pick " + OtherLabel + " above)"
59+ }
60+ return "Your own answer (optional)"
61+}
62+
45 func propertySchema(q Question) map[string]any {63 func propertySchema(q Question) map[string]any {
46 p := map[string]any{"title": q.Prompt}64 p := map[string]any{"title": q.Prompt}
47 switch q.Kind {65 switch q.Kind {
48 case Choice:66 case Choice:
49 p["type"] = "string"67 p["type"] = "string"
50- p["enum"] = toAny(q.Options)68+ options := q.Options
69+ if q.AllowOther {
70+ options = append(append([]string(nil), options...), OtherLabel)
71+ }
72+ p["enum"] = toAny(options)
51 case Multi:73 case Multi:
52 p["type"] = "array"74 p["type"] = "array"
53 p["items"] = map[string]any{"type": "string", "enum": toAny(q.Options)}75 p["items"] = map[string]any{"type": "string", "enum": toAny(q.Options)}
@@ -85,7 +107,16 @@ func FromSchema(schema map[string]any) (Form, bool) {
85 if p == nil {107 if p == nil {
86 continue108 continue
87 }109 }
88- form.Questions = append(form.Questions, questionOf(name, p))110+ // q1_other beside q1 is q1's Other row, not a question (Schema).
111+ if base, ok := strings.CutSuffix(name, otherSuffix); ok && properties[base] != nil {
112+ continue
113+ }
114+ q := questionOf(name, p)
115+ if properties[OtherName(q)] != nil && (q.Kind == Choice || q.Kind == Multi) {
116+ q.AllowOther = true
117+ q.Options = withoutOther(q.Options)
118+ }
119+ form.Questions = append(form.Questions, q)
89 }120 }
90 return form, len(form.Questions) > 0121 return form, len(form.Questions) > 0
91 }122 }
@@ -161,7 +192,8 @@ func Content(f Form, answers []Answer) map[string]any {
161 if i >= len(answers) {192 if i >= len(answers) {
162 break193 break
163 }194 }
164- values := answers[i].Values195+ a := answers[i]
196+ values := a.Values
165 switch q.Kind {197 switch q.Kind {
166 case Multi:198 case Multi:
167 content[q.Name] = toAny(values)199 content[q.Name] = toAny(values)
@@ -172,6 +204,14 @@ func Content(f Form, answers []Answer) map[string]any {
172 content[q.Name] = values[0]204 content[q.Name] = values[0]
173 }205 }
174 }206 }
207+ if q.AllowOther && (a.Other != "" || a.OtherAsked) {
208+ if q.Kind == Choice {
209+ content[q.Name] = OtherLabel
210+ }
211+ if a.Other != "" {
212+ content[OtherName(q)] = a.Other
213+ }
214+ }
175 }215 }
176 return content216 return content
177 }217 }
@@ -183,11 +223,41 @@ func Content(f Form, answers []Answer) map[string]any {
183 func FromContent(f Form, content map[string]any) Result {223 func FromContent(f Form, content map[string]any) Result {
184 res := Result{Status: Answered}224 res := Result{Status: Answered}
185 for _, q := range f.Questions {225 for _, q := range f.Questions {
186- res.Answers = append(res.Answers, Answer{Values: valuesOf(q, content[q.Name])})226+ res.Answers = append(res.Answers, answerOf(q, content))
187 }227 }
188 return res228 return res
189 }229 }
190 230
231+// answerOf reads one question's answer from a form's content: its values,
232+// and — when it allows another answer — the text typed in <name>_other.
233+// OtherLabel among the values is the Other row, not an option; picked
234+// with nothing typed, the model is told to ask (OtherAsked).
235+func answerOf(q Question, content map[string]any) Answer {
236+ a := Answer{Values: valuesOf(q, content[q.Name])}
237+ if !q.AllowOther {
238+ return a
239+ }
240+ picked := false
241+ kept := a.Values[:0]
242+ for _, v := range a.Values {
243+ if v == OtherLabel || isOtherOption(v) {
244+ picked = true
245+ continue
246+ }
247+ kept = append(kept, v)
248+ }
249+ a.Values = kept
250+ a.Other = strings.TrimSpace(str(content[OtherName(q)]))
251+ if q.Kind == Choice && a.Other != "" {
252+ a.Values = nil // a choice has one answer: the typed one wins
253+ }
254+ a.OtherAsked = picked && a.Other == ""
255+ if len(a.Values) == 0 {
256+ a.Values = nil
257+ }
258+ return a
259+}
260+
191 func valuesOf(q Question, v any) []string {261 func valuesOf(q Question, v any) []string {
192 switch x := v.(type) {262 switch x := v.(type) {
193 case nil:263 case nil:
modified internal/tools/askuser.go +3 -2
@@ -49,7 +49,8 @@ var askUserSchema = map[string]any{
4949 "items": map[string]any{
5050 "type": "object",
5151 "description": "One question: question (its text, short), type (choice = exactly one of the options, multi = any number of them, text = a free answer, confirm = yes or no; default: choice when options are given, text otherwise), " +
52- "options (a list of short strings, at least two, for choice and multi), default (optional: the suggested answer).",
52+ "options (a list of short strings, at least two, for choice and multi; do not add an \"Other\" option: the user can always type their own answer), default (optional: the suggested answer), " +
53+ "allow_other (optional, choice and multi: false when only the options make sense — the user then cannot type another answer).",
5354 },
5455 },
5556 },
@@ -58,7 +59,7 @@ var askUserSchema = map[string]any{
5859 // askUserDescription ends with a complete call: a 9B model given only the
5960 // schema wrote a choice question without its options (measured, Qwen3.5 9B
6061 // — the schema's properties reach it sorted, options before question).
61-const askUserDescription = `Ask the user one or more questions and wait for the answers. Use it when you need a decision or a piece of information only the user has — which option to take, a name, a yes or no before something irreversible — instead of guessing. Do not use it for what you can find yourself (read the files, run a command), nor to chat. Prefer choices over free text when the possible answers are known. The result is the user's answers, or a sentence saying they declined (then do not ask the same thing again) or cannot be asked in this mode (then make a reasonable assumption and say which).
62+const askUserDescription = `Ask the user one or more questions and wait for the answers. Use it when you need a decision or a piece of information only the user has — which option to take, a name, a yes or no before something irreversible — instead of guessing. Do not use it for what you can find yourself (read the files, run a command), nor to chat. Prefer choices over free text when the possible answers are known; the user can always type an answer of their own instead (it comes back marked "typed by the user"). The result is the user's answers, or a sentence saying they declined (then do not ask the same thing again) or cannot be asked in this mode (then make a reasonable assumption and say which).
6263 Example: {"questions": [{"question": "Which framework?", "type": "choice", "options": ["React", "Vue", "Svelte"]}, {"question": "Add TypeScript?", "type": "confirm"}]}`
6364
6465 // AskUser declares the `ask_user` tool. The caller declares it only when
@@ -49,7 +49,8 @@ var askUserSchema = map[string]any{
49 "items": map[string]any{49 "items": map[string]any{
50 "type": "object",50 "type": "object",
51 "description": "One question: question (its text, short), type (choice = exactly one of the options, multi = any number of them, text = a free answer, confirm = yes or no; default: choice when options are given, text otherwise), " +51 "description": "One question: question (its text, short), type (choice = exactly one of the options, multi = any number of them, text = a free answer, confirm = yes or no; default: choice when options are given, text otherwise), " +
52- "options (a list of short strings, at least two, for choice and multi), default (optional: the suggested answer).",52+ "options (a list of short strings, at least two, for choice and multi; do not add an \"Other\" option: the user can always type their own answer), default (optional: the suggested answer), " +
53+ "allow_other (optional, choice and multi: false when only the options make sense — the user then cannot type another answer).",
53 },54 },
54 },55 },
55 },56 },
@@ -58,7 +59,7 @@ var askUserSchema = map[string]any{
58 // askUserDescription ends with a complete call: a 9B model given only the59 // askUserDescription ends with a complete call: a 9B model given only the
59 // schema wrote a choice question without its options (measured, Qwen3.5 9B60 // schema wrote a choice question without its options (measured, Qwen3.5 9B
60 // — the schema's properties reach it sorted, options before question).61 // — the schema's properties reach it sorted, options before question).
61-const askUserDescription = `Ask the user one or more questions and wait for the answers. Use it when you need a decision or a piece of information only the user has — which option to take, a name, a yes or no before something irreversible — instead of guessing. Do not use it for what you can find yourself (read the files, run a command), nor to chat. Prefer choices over free text when the possible answers are known. The result is the user's answers, or a sentence saying they declined (then do not ask the same thing again) or cannot be asked in this mode (then make a reasonable assumption and say which).62+const askUserDescription = `Ask the user one or more questions and wait for the answers. Use it when you need a decision or a piece of information only the user has — which option to take, a name, a yes or no before something irreversible — instead of guessing. Do not use it for what you can find yourself (read the files, run a command), nor to chat. Prefer choices over free text when the possible answers are known; the user can always type an answer of their own instead (it comes back marked "typed by the user"). The result is the user's answers, or a sentence saying they declined (then do not ask the same thing again) or cannot be asked in this mode (then make a reasonable assumption and say which).
62 Example: {"questions": [{"question": "Which framework?", "type": "choice", "options": ["React", "Vue", "Svelte"]}, {"question": "Add TypeScript?", "type": "confirm"}]}`63 Example: {"questions": [{"question": "Which framework?", "type": "choice", "options": ["React", "Vue", "Svelte"]}, {"question": "Add TypeScript?", "type": "confirm"}]}`
63 64
64 // AskUser declares the `ask_user` tool. The caller declares it only when65 // AskUser declares the `ask_user` tool. The caller declares it only when
modified internal/tui/question.go +72 -5
@@ -20,6 +20,10 @@ import (
2020 // multi ↑↓, Space to tick, Enter to send (one at least)
2121 // confirm y/o or n, or ←→ Enter
2222 // text type, Enter (an empty line takes the default)
23+// other the last row of a choice or multi (ticket 258): Enter (or its
24+// number, or Space) opens a field for the user's own answer;
25+// Enter sends it — beside the ticked options for a multi —,
26+// Escape goes back to the options
2327 // any Escape declines
2428 //
2529 // Several questions are asked one after the other; the answers go back
@@ -84,6 +88,9 @@ type formView struct {
8488 checked []bool
8589 text []rune
8690 answers []elicit.Answer
91+ // typingOther: the Other row was chosen, the box is a text field for
92+ // the user's own answer (ticket 258).
93+ typingOther bool
8794 }
8895
8996 // syncForm follows the runner's pending form: a new one starts at its first
@@ -103,7 +110,7 @@ func (f *formView) question() elicit.Question { return f.ask.form.Questions[f.in
103110 // start prepares the current question: the highlight on its default.
104111 func (f *formView) start() {
105112 q := f.question()
106- f.cursor, f.text = 0, nil
113+ f.cursor, f.text, f.typingOther = 0, nil, false
107114 f.checked = make([]bool, len(q.Options))
108115 switch q.Kind {
109116 case elicit.Choice:
@@ -125,6 +132,9 @@ func (f *formView) start() {
125132 func (f *formView) rows() int {
126133 switch q := f.question(); q.Kind {
127134 case elicit.Choice, elicit.Multi:
135+ if q.AllowOther {
136+ return len(q.Options) + 1 // the Other row
137+ }
128138 return len(q.Options)
129139 case elicit.Confirm:
130140 return 2
@@ -135,6 +145,10 @@ func (f *formView) rows() int {
135145 // handleFormKey is the keymap while a form is shown.
136146 func (v *View) handleFormKey(ev *tcell.EventKey) {
137147 f := v.form
148+ if f.typingOther {
149+ v.formOtherKey(ev)
150+ return
151+ }
138152 if ev.Key() == tcell.KeyEscape {
139153 v.finishForm(elicit.Result{Status: elicit.Declined})
140154 return
@@ -153,16 +167,24 @@ func (v *View) handleFormKey(ev *tcell.EventKey) {
153167 // formListKey: choice and multi.
154168 func (v *View) formListKey(ev *tcell.EventKey) {
155169 f, q := v.form, v.form.question()
170+ rows := f.rows()
171+ onOther := q.AllowOther && f.cursor == len(q.Options)
156172 switch {
157173 case ev.Key() == tcell.KeyUp:
158- f.cursor = (f.cursor + len(q.Options) - 1) % len(q.Options)
174+ f.cursor = (f.cursor + rows - 1) % rows
159175 case ev.Key() == tcell.KeyDown, ev.Key() == tcell.KeyTab:
160- f.cursor = (f.cursor + 1) % len(q.Options)
176+ f.cursor = (f.cursor + 1) % rows
177+ case onOther && (ev.Key() == tcell.KeyEnter || ev.Key() == tcell.KeyRune && ev.Rune() == ' '):
178+ f.typingOther, f.text = true, nil
161179 case q.Kind == elicit.Multi && ev.Key() == tcell.KeyRune && ev.Rune() == ' ':
162180 f.checked[f.cursor] = !f.checked[f.cursor]
163181 case q.Kind == elicit.Choice && ev.Key() == tcell.KeyRune && ev.Rune() >= '1' && ev.Rune() <= '9':
164- if n := int(ev.Rune() - '0'); n <= len(q.Options) {
182+ n := int(ev.Rune() - '0')
183+ switch {
184+ case n <= len(q.Options):
165185 v.submitAnswer(elicit.Answer{Values: []string{q.Options[n-1]}})
186+ case q.AllowOther && n == len(q.Options)+1:
187+ f.cursor, f.typingOther, f.text = n-1, true, nil
166188 }
167189 case ev.Key() == tcell.KeyEnter && q.Kind == elicit.Choice:
168190 v.submitAnswer(elicit.Answer{Values: []string{q.Options[f.cursor]}})
@@ -179,6 +201,37 @@ func (v *View) formListKey(ev *tcell.EventKey) {
179201 }
180202 }
181203
204+// formOtherKey: the field for the user's own answer. Enter sends it (a
205+// multi's ticked options with it); an empty field is not an answer yet;
206+// Escape goes back to the options rather than declining.
207+func (v *View) formOtherKey(ev *tcell.EventKey) {
208+ f, q := v.form, v.form.question()
209+ switch ev.Key() {
210+ case tcell.KeyEscape:
211+ f.typingOther, f.text = false, nil
212+ case tcell.KeyRune:
213+ f.text = append(f.text, ev.Rune())
214+ case tcell.KeyBackspace, tcell.KeyBackspace2:
215+ if len(f.text) > 0 {
216+ f.text = f.text[:len(f.text)-1]
217+ }
218+ case tcell.KeyEnter:
219+ other := strings.TrimSpace(string(f.text))
220+ if other == "" {
221+ return
222+ }
223+ a := elicit.Answer{Other: other}
224+ if q.Kind == elicit.Multi {
225+ for i, on := range f.checked {
226+ if on {
227+ a.Values = append(a.Values, q.Options[i])
228+ }
229+ }
230+ }
231+ v.submitAnswer(a)
232+ }
233+}
234+
182235 func (v *View) formConfirmKey(ev *tcell.EventKey) {
183236 f := v.form
184237 switch {
@@ -238,6 +291,13 @@ func (v *View) drawFormBox(p painter) {
238291 title += fmt.Sprintf(" (%d/%d)", f.index+1, n)
239292 }
240293 p.textLimited(0, 0, p.width(), title, stAsk)
294+ if f.typingOther {
295+ p.text(0, 1, ">", stPrompt)
296+ p.textLimited(2, 1, max(p.width()-2, 0), string(f.text), stBody)
297+ p.showCursor(2+min(len(f.text), max(p.width()-3, 0)), 1)
298+ p.textLimited(2, 2, max(p.width()-2, 0), "your own answer · Enter send · Esc back to the options", stNotice)
299+ return
300+ }
241301 if q.Kind == elicit.Text {
242302 p.text(0, 1, ">", stPrompt)
243303 text := string(f.text)
@@ -272,6 +332,9 @@ func (v *View) drawFormChoices(p painter) {
272332 if q.Kind == elicit.Confirm {
273333 labels = []string{"Yes", "No"}
274334 }
335+ if q.AllowOther && q.Kind != elicit.Confirm {
336+ labels = append(append([]string(nil), labels...), elicit.OtherLabel+" (type your own answer)")
337+ }
275338 shown := min(rows, p.height())
276339 first := max(f.cursor-shown+1, 0) // keep the highlight visible
277340 width := 0
@@ -286,10 +349,14 @@ func (v *View) drawFormChoices(p painter) {
286349 if at == f.cursor {
287350 mark = "❯ "
288351 }
352+ other := at == len(q.Options) // the Other row, when there is one
289353 switch q.Kind {
290354 case elicit.Multi:
291355 box := "[ ] "
292- if f.checked[at] {
356+ switch {
357+ case other:
358+ box = "[+] "
359+ case f.checked[at]:
293360 box = "[x] "
294361 }
295362 mark += box
@@ -20,6 +20,10 @@ import (
20 // multi ↑↓, Space to tick, Enter to send (one at least)20 // multi ↑↓, Space to tick, Enter to send (one at least)
21 // confirm y/o or n, or ←→ Enter21 // confirm y/o or n, or ←→ Enter
22 // text type, Enter (an empty line takes the default)22 // text type, Enter (an empty line takes the default)
23+// other the last row of a choice or multi (ticket 258): Enter (or its
24+// number, or Space) opens a field for the user's own answer;
25+// Enter sends it — beside the ticked options for a multi —,
26+// Escape goes back to the options
23 // any Escape declines27 // any Escape declines
24 //28 //
25 // Several questions are asked one after the other; the answers go back29 // Several questions are asked one after the other; the answers go back
@@ -84,6 +88,9 @@ type formView struct {
84 checked []bool88 checked []bool
85 text []rune89 text []rune
86 answers []elicit.Answer90 answers []elicit.Answer
91+ // typingOther: the Other row was chosen, the box is a text field for
92+ // the user's own answer (ticket 258).
93+ typingOther bool
87 }94 }
88 95
89 // syncForm follows the runner's pending form: a new one starts at its first96 // syncForm follows the runner's pending form: a new one starts at its first
@@ -103,7 +110,7 @@ func (f *formView) question() elicit.Question { return f.ask.form.Questions[f.in
103 // start prepares the current question: the highlight on its default.110 // start prepares the current question: the highlight on its default.
104 func (f *formView) start() {111 func (f *formView) start() {
105 q := f.question()112 q := f.question()
106- f.cursor, f.text = 0, nil113+ f.cursor, f.text, f.typingOther = 0, nil, false
107 f.checked = make([]bool, len(q.Options))114 f.checked = make([]bool, len(q.Options))
108 switch q.Kind {115 switch q.Kind {
109 case elicit.Choice:116 case elicit.Choice:
@@ -125,6 +132,9 @@ func (f *formView) start() {
125 func (f *formView) rows() int {132 func (f *formView) rows() int {
126 switch q := f.question(); q.Kind {133 switch q := f.question(); q.Kind {
127 case elicit.Choice, elicit.Multi:134 case elicit.Choice, elicit.Multi:
135+ if q.AllowOther {
136+ return len(q.Options) + 1 // the Other row
137+ }
128 return len(q.Options)138 return len(q.Options)
129 case elicit.Confirm:139 case elicit.Confirm:
130 return 2140 return 2
@@ -135,6 +145,10 @@ func (f *formView) rows() int {
135 // handleFormKey is the keymap while a form is shown.145 // handleFormKey is the keymap while a form is shown.
136 func (v *View) handleFormKey(ev *tcell.EventKey) {146 func (v *View) handleFormKey(ev *tcell.EventKey) {
137 f := v.form147 f := v.form
148+ if f.typingOther {
149+ v.formOtherKey(ev)
150+ return
151+ }
138 if ev.Key() == tcell.KeyEscape {152 if ev.Key() == tcell.KeyEscape {
139 v.finishForm(elicit.Result{Status: elicit.Declined})153 v.finishForm(elicit.Result{Status: elicit.Declined})
140 return154 return
@@ -153,16 +167,24 @@ func (v *View) handleFormKey(ev *tcell.EventKey) {
153 // formListKey: choice and multi.167 // formListKey: choice and multi.
154 func (v *View) formListKey(ev *tcell.EventKey) {168 func (v *View) formListKey(ev *tcell.EventKey) {
155 f, q := v.form, v.form.question()169 f, q := v.form, v.form.question()
170+ rows := f.rows()
171+ onOther := q.AllowOther && f.cursor == len(q.Options)
156 switch {172 switch {
157 case ev.Key() == tcell.KeyUp:173 case ev.Key() == tcell.KeyUp:
158- f.cursor = (f.cursor + len(q.Options) - 1) % len(q.Options)174+ f.cursor = (f.cursor + rows - 1) % rows
159 case ev.Key() == tcell.KeyDown, ev.Key() == tcell.KeyTab:175 case ev.Key() == tcell.KeyDown, ev.Key() == tcell.KeyTab:
160- f.cursor = (f.cursor + 1) % len(q.Options)176+ f.cursor = (f.cursor + 1) % rows
177+ case onOther && (ev.Key() == tcell.KeyEnter || ev.Key() == tcell.KeyRune && ev.Rune() == ' '):
178+ f.typingOther, f.text = true, nil
161 case q.Kind == elicit.Multi && ev.Key() == tcell.KeyRune && ev.Rune() == ' ':179 case q.Kind == elicit.Multi && ev.Key() == tcell.KeyRune && ev.Rune() == ' ':
162 f.checked[f.cursor] = !f.checked[f.cursor]180 f.checked[f.cursor] = !f.checked[f.cursor]
163 case q.Kind == elicit.Choice && ev.Key() == tcell.KeyRune && ev.Rune() >= '1' && ev.Rune() <= '9':181 case q.Kind == elicit.Choice && ev.Key() == tcell.KeyRune && ev.Rune() >= '1' && ev.Rune() <= '9':
164- if n := int(ev.Rune() - '0'); n <= len(q.Options) {182+ n := int(ev.Rune() - '0')
183+ switch {
184+ case n <= len(q.Options):
165 v.submitAnswer(elicit.Answer{Values: []string{q.Options[n-1]}})185 v.submitAnswer(elicit.Answer{Values: []string{q.Options[n-1]}})
186+ case q.AllowOther && n == len(q.Options)+1:
187+ f.cursor, f.typingOther, f.text = n-1, true, nil
166 }188 }
167 case ev.Key() == tcell.KeyEnter && q.Kind == elicit.Choice:189 case ev.Key() == tcell.KeyEnter && q.Kind == elicit.Choice:
168 v.submitAnswer(elicit.Answer{Values: []string{q.Options[f.cursor]}})190 v.submitAnswer(elicit.Answer{Values: []string{q.Options[f.cursor]}})
@@ -179,6 +201,37 @@ func (v *View) formListKey(ev *tcell.EventKey) {
179 }201 }
180 }202 }
181 203
204+// formOtherKey: the field for the user's own answer. Enter sends it (a
205+// multi's ticked options with it); an empty field is not an answer yet;
206+// Escape goes back to the options rather than declining.
207+func (v *View) formOtherKey(ev *tcell.EventKey) {
208+ f, q := v.form, v.form.question()
209+ switch ev.Key() {
210+ case tcell.KeyEscape:
211+ f.typingOther, f.text = false, nil
212+ case tcell.KeyRune:
213+ f.text = append(f.text, ev.Rune())
214+ case tcell.KeyBackspace, tcell.KeyBackspace2:
215+ if len(f.text) > 0 {
216+ f.text = f.text[:len(f.text)-1]
217+ }
218+ case tcell.KeyEnter:
219+ other := strings.TrimSpace(string(f.text))
220+ if other == "" {
221+ return
222+ }
223+ a := elicit.Answer{Other: other}
224+ if q.Kind == elicit.Multi {
225+ for i, on := range f.checked {
226+ if on {
227+ a.Values = append(a.Values, q.Options[i])
228+ }
229+ }
230+ }
231+ v.submitAnswer(a)
232+ }
233+}
234+
182 func (v *View) formConfirmKey(ev *tcell.EventKey) {235 func (v *View) formConfirmKey(ev *tcell.EventKey) {
183 f := v.form236 f := v.form
184 switch {237 switch {
@@ -238,6 +291,13 @@ func (v *View) drawFormBox(p painter) {
238 title += fmt.Sprintf(" (%d/%d)", f.index+1, n)291 title += fmt.Sprintf(" (%d/%d)", f.index+1, n)
239 }292 }
240 p.textLimited(0, 0, p.width(), title, stAsk)293 p.textLimited(0, 0, p.width(), title, stAsk)
294+ if f.typingOther {
295+ p.text(0, 1, ">", stPrompt)
296+ p.textLimited(2, 1, max(p.width()-2, 0), string(f.text), stBody)
297+ p.showCursor(2+min(len(f.text), max(p.width()-3, 0)), 1)
298+ p.textLimited(2, 2, max(p.width()-2, 0), "your own answer · Enter send · Esc back to the options", stNotice)
299+ return
300+ }
241 if q.Kind == elicit.Text {301 if q.Kind == elicit.Text {
242 p.text(0, 1, ">", stPrompt)302 p.text(0, 1, ">", stPrompt)
243 text := string(f.text)303 text := string(f.text)
@@ -272,6 +332,9 @@ func (v *View) drawFormChoices(p painter) {
272 if q.Kind == elicit.Confirm {332 if q.Kind == elicit.Confirm {
273 labels = []string{"Yes", "No"}333 labels = []string{"Yes", "No"}
274 }334 }
335+ if q.AllowOther && q.Kind != elicit.Confirm {
336+ labels = append(append([]string(nil), labels...), elicit.OtherLabel+" (type your own answer)")
337+ }
275 shown := min(rows, p.height())338 shown := min(rows, p.height())
276 first := max(f.cursor-shown+1, 0) // keep the highlight visible339 first := max(f.cursor-shown+1, 0) // keep the highlight visible
277 width := 0340 width := 0
@@ -286,10 +349,14 @@ func (v *View) drawFormChoices(p painter) {
286 if at == f.cursor {349 if at == f.cursor {
287 mark = "❯ "350 mark = "❯ "
288 }351 }
352+ other := at == len(q.Options) // the Other row, when there is one
289 switch q.Kind {353 switch q.Kind {
290 case elicit.Multi:354 case elicit.Multi:
291 box := "[ ] "355 box := "[ ] "
292- if f.checked[at] {356+ switch {
357+ case other:
358+ box = "[+] "
359+ case f.checked[at]:
293 box = "[x] "360 box = "[x] "
294 }361 }
295 mark += box362 mark += box
modified internal/tui/question_test.go +48 -0
@@ -151,3 +151,51 @@ func waitFor(t *testing.T, cond func() bool) {
151151 time.Sleep(time.Millisecond)
152152 }
153153 }
154+
155+// Ticket 258: a choice that allows another answer shows the Other row
156+// last; Enter on it opens a field; Escape there goes back to the options
157+// (not a decline); Enter sends the typed text as the user's own answer.
158+func TestFormOtherRowOnAChoice(t *testing.T) {
159+ q := envChoice
160+ q.AllowOther = true
161+ hs, got := formHarness(t, form(q))
162+ if text := hs.screenText(); !strings.Contains(text, "4. Other… (type your own answer)") {
163+ t.Fatalf("no Other row:\n%s", text)
164+ }
165+ hs.key(tcell.KeyUp, tcell.ModNone) // from the first row up to the last: Other
166+ hs.key(tcell.KeyEnter, tcell.ModNone)
167+ if !hs.v.form.typingOther || !strings.Contains(hs.screenText(), "Esc back to the options") {
168+ t.Fatalf("Enter on Other did not open the field:\n%s", hs.screenText())
169+ }
170+ hs.key(tcell.KeyEscape, tcell.ModNone)
171+ if hs.v.form == nil || hs.v.form.typingOther || len(*got) != 0 {
172+ t.Fatalf("Escape in the field declined or stayed: %+v", *got)
173+ }
174+ hs.typeText("4") // the Other row's number opens the field too
175+ hs.key(tcell.KeyEnter, tcell.ModNone) // empty: not an answer yet
176+ hs.typeText("a QA box")
177+ hs.key(tcell.KeyEnter, tcell.ModNone)
178+ want := []elicit.Result{{Status: elicit.Answered, Answers: []elicit.Answer{{Other: "a QA box"}}}}
179+ if !reflect.DeepEqual(*got, want) {
180+ t.Errorf("got %+v", *got)
181+ }
182+}
183+
184+// On a multi, the typed answer goes back with the ticked options.
185+func TestFormOtherRowOnAMulti(t *testing.T) {
186+ q := elicit.Question{Name: "q1", Prompt: "Features?", Kind: elicit.Multi, Options: []string{"A", "B"}, AllowOther: true}
187+ hs, got := formHarness(t, form(q))
188+ hs.typeText(" ") // tick A
189+ hs.key(tcell.KeyDown, tcell.ModNone) // B
190+ hs.key(tcell.KeyDown, tcell.ModNone) // Other
191+ if !strings.Contains(hs.screenText(), "[+] Other…") {
192+ t.Fatalf("no Other row:\n%s", hs.screenText())
193+ }
194+ hs.typeText(" ") // Space on Other opens the field
195+ hs.typeText("logging")
196+ hs.key(tcell.KeyEnter, tcell.ModNone)
197+ want := []elicit.Result{{Status: elicit.Answered, Answers: []elicit.Answer{{Values: []string{"A"}, Other: "logging"}}}}
198+ if !reflect.DeepEqual(*got, want) {
199+ t.Errorf("got %+v", *got)
200+ }
201+}
@@ -151,3 +151,51 @@ func waitFor(t *testing.T, cond func() bool) {
151 time.Sleep(time.Millisecond)151 time.Sleep(time.Millisecond)
152 }152 }
153 }153 }
154+
155+// Ticket 258: a choice that allows another answer shows the Other row
156+// last; Enter on it opens a field; Escape there goes back to the options
157+// (not a decline); Enter sends the typed text as the user's own answer.
158+func TestFormOtherRowOnAChoice(t *testing.T) {
159+ q := envChoice
160+ q.AllowOther = true
161+ hs, got := formHarness(t, form(q))
162+ if text := hs.screenText(); !strings.Contains(text, "4. Other… (type your own answer)") {
163+ t.Fatalf("no Other row:\n%s", text)
164+ }
165+ hs.key(tcell.KeyUp, tcell.ModNone) // from the first row up to the last: Other
166+ hs.key(tcell.KeyEnter, tcell.ModNone)
167+ if !hs.v.form.typingOther || !strings.Contains(hs.screenText(), "Esc back to the options") {
168+ t.Fatalf("Enter on Other did not open the field:\n%s", hs.screenText())
169+ }
170+ hs.key(tcell.KeyEscape, tcell.ModNone)
171+ if hs.v.form == nil || hs.v.form.typingOther || len(*got) != 0 {
172+ t.Fatalf("Escape in the field declined or stayed: %+v", *got)
173+ }
174+ hs.typeText("4") // the Other row's number opens the field too
175+ hs.key(tcell.KeyEnter, tcell.ModNone) // empty: not an answer yet
176+ hs.typeText("a QA box")
177+ hs.key(tcell.KeyEnter, tcell.ModNone)
178+ want := []elicit.Result{{Status: elicit.Answered, Answers: []elicit.Answer{{Other: "a QA box"}}}}
179+ if !reflect.DeepEqual(*got, want) {
180+ t.Errorf("got %+v", *got)
181+ }
182+}
183+
184+// On a multi, the typed answer goes back with the ticked options.
185+func TestFormOtherRowOnAMulti(t *testing.T) {
186+ q := elicit.Question{Name: "q1", Prompt: "Features?", Kind: elicit.Multi, Options: []string{"A", "B"}, AllowOther: true}
187+ hs, got := formHarness(t, form(q))
188+ hs.typeText(" ") // tick A
189+ hs.key(tcell.KeyDown, tcell.ModNone) // B
190+ hs.key(tcell.KeyDown, tcell.ModNone) // Other
191+ if !strings.Contains(hs.screenText(), "[+] Other…") {
192+ t.Fatalf("no Other row:\n%s", hs.screenText())
193+ }
194+ hs.typeText(" ") // Space on Other opens the field
195+ hs.typeText("logging")
196+ hs.key(tcell.KeyEnter, tcell.ModNone)
197+ want := []elicit.Result{{Status: elicit.Answered, Answers: []elicit.Answer{{Values: []string{"A"}, Other: "logging"}}}}
198+ if !reflect.DeepEqual(*got, want) {
199+ t.Errorf("got %+v", *got)
200+ }
201+}