@oh-my-pi/user-prompt 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,130 @@
1
+ # User Prompt Plugin
2
+
3
+ Interactive user prompting tool for gathering user input during agent execution.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ omp install oh-my-pi/plugins/user-prompt
9
+ ```
10
+
11
+ ## Tool
12
+
13
+ ### `user_prompt`
14
+
15
+ Asks the user questions during execution and returns their response. Useful for:
16
+
17
+ - Gathering user preferences or requirements
18
+ - Clarifying ambiguous instructions
19
+ - Getting decisions on implementation choices
20
+ - Offering choices about what direction to take
21
+
22
+ ## Features
23
+
24
+ ### Enhanced UI (when available)
25
+
26
+ The plugin provides custom TUI components that integrate directly into pi's interface:
27
+
28
+ **Single-select with inline "Other" input:**
29
+ ```
30
+ ─────────────────────────────────────────────
31
+ Which database would you like to use?
32
+
33
+ → PostgreSQL (Recommended)
34
+ MySQL
35
+ SQLite
36
+ MongoDB
37
+ Other (type your own)
38
+
39
+ ↑↓ navigate · enter select · esc cancel
40
+ ─────────────────────────────────────────────
41
+ ```
42
+
43
+ When "Other" is selected, an inline text input appears - no separate dialog needed.
44
+
45
+ **Multi-select with checkboxes:**
46
+ ```
47
+ ─────────────────────────────────────────────
48
+ Which features should I implement?
49
+
50
+ → [X] Authentication
51
+ [X] API endpoints
52
+ [ ] Database models
53
+ [ ] Unit tests
54
+ [ ] Documentation
55
+
56
+ ↑↓ navigate · space toggle · enter confirm · esc cancel
57
+ ─────────────────────────────────────────────
58
+ ```
59
+
60
+ Space toggles selection, Enter confirms. Selected items show `[X]` in green with white text.
61
+
62
+ ### Fallback Mode
63
+
64
+ If the enhanced UI cannot be loaded, the plugin gracefully falls back to using pi's built-in `select()` and `input()` methods.
65
+
66
+ ## Parameters
67
+
68
+ | Parameter | Type | Required | Description |
69
+ |-----------|------|----------|-------------|
70
+ | `question` | string | Yes | The question to ask the user |
71
+ | `options` | array | Yes | Array of `{label: string}` options to present |
72
+ | `multiSelect` | boolean | No | Allow multiple selections (default: false) |
73
+
74
+ ## Usage Notes
75
+
76
+ - Users can always select "Other" to provide custom text input
77
+ - Use `multiSelect: true` to allow multiple answers to be selected
78
+ - If you recommend a specific option, make that the first option and add "(Recommended)" at the end of the label
79
+
80
+ ## Examples
81
+
82
+ ### Single-choice question
83
+
84
+ ```json
85
+ {
86
+ "question": "Which database would you like to use?",
87
+ "options": [
88
+ {"label": "PostgreSQL (Recommended)"},
89
+ {"label": "MySQL"},
90
+ {"label": "SQLite"},
91
+ {"label": "MongoDB"}
92
+ ]
93
+ }
94
+ ```
95
+
96
+ ### Multi-select question
97
+
98
+ ```json
99
+ {
100
+ "question": "Which features should I implement?",
101
+ "options": [
102
+ {"label": "Authentication"},
103
+ {"label": "API endpoints"},
104
+ {"label": "Database models"},
105
+ {"label": "Unit tests"},
106
+ {"label": "Documentation"}
107
+ ],
108
+ "multiSelect": true
109
+ }
110
+ ```
111
+
112
+ ## Response Format
113
+
114
+ The tool returns the user's selection in a structured format:
115
+
116
+ - **Single selection**: `"User selected: PostgreSQL (Recommended)"`
117
+ - **Multi-selection**: `"User selected: Authentication, API endpoints, Unit tests"`
118
+ - **Custom input**: `"User provided custom input: Use Redis for caching"`
119
+ - **Cancelled**: `"User cancelled the selection"`
120
+
121
+ ## How It Works
122
+
123
+ The plugin hooks into pi's interactive mode at runtime to provide custom TUI components. It:
124
+
125
+ 1. Dynamically imports pi's theme for consistent styling
126
+ 2. Locates the InteractiveMode instance to access the editor container
127
+ 3. Swaps in custom components (MultiSelectList, SelectWithInput) when prompting
128
+ 4. Restores the normal editor when done
129
+
130
+ This approach provides a seamless, native-feeling UI without requiring upstream changes to pi.
package/package.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "@oh-my-pi/user-prompt",
3
+ "version": "0.3.0",
4
+ "description": "Interactive user prompting tool for gathering user input during execution",
5
+ "keywords": ["omp-plugin", "user-prompt", "interactive", "questions", "input"],
6
+ "author": "Can Bölük <me@can.ac>",
7
+ "license": "MIT",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/can1357/oh-my-pi.git",
11
+ "directory": "plugins/user-prompt"
12
+ },
13
+ "omp": {
14
+ "install": [
15
+ { "src": "tools/user-prompt/index.ts", "dest": "agent/tools/user-prompt/index.ts" }
16
+ ]
17
+ },
18
+ "files": ["tools"]
19
+ }
@@ -0,0 +1,235 @@
1
+ /**
2
+ * User Prompt Tool - Ask questions to the user during execution
3
+ *
4
+ * Use this tool when you need to ask the user questions during execution.
5
+ * This allows you to:
6
+ * 1. Gather user preferences or requirements
7
+ * 2. Clarify ambiguous instructions
8
+ * 3. Get decisions on implementation choices as you work
9
+ * 4. Offer choices to the user about what direction to take
10
+ *
11
+ * Usage notes:
12
+ * - Users will always be able to select "Other" to provide custom text input
13
+ * - Use multi: true to allow multiple answers to be selected for a question
14
+ * - If you recommend a specific option, make that the first option in the list
15
+ * and add "(Recommended)" at the end of the label
16
+ */
17
+
18
+ import { Type } from "@sinclair/typebox";
19
+ import { Text } from "@mariozechner/pi-tui";
20
+ import type { CustomAgentTool, CustomToolFactory, ToolAPI } from "@mariozechner/pi-coding-agent";
21
+
22
+ // =============================================================================
23
+ // Tool Definition
24
+ // =============================================================================
25
+
26
+ const OTHER_OPTION = "Other (type your own)";
27
+
28
+ const OptionItem = Type.Object({
29
+ label: Type.String({ description: "Display label for this option" }),
30
+ });
31
+
32
+ const UserPromptParams = Type.Object({
33
+ question: Type.String({ description: "The question to ask the user" }),
34
+ options: Type.Array(OptionItem, {
35
+ description: "Available options for the user to choose from.",
36
+ minItems: 1,
37
+ }),
38
+ multi: Type.Optional(Type.Boolean({
39
+ description: "Allow multiple options to be selected (default: false)",
40
+ default: false,
41
+ })),
42
+ });
43
+
44
+ interface UserPromptDetails {
45
+ question: string;
46
+ options: string[];
47
+ multi: boolean;
48
+ selectedOptions: string[];
49
+ customInput?: string;
50
+ }
51
+
52
+ const DESCRIPTION = `Use this tool when you need to ask the user questions during execution. This allows you to:
53
+ 1. Gather user preferences or requirements
54
+ 2. Clarify ambiguous instructions
55
+ 3. Get decisions on implementation choices as you work
56
+ 4. Offer choices to the user about what direction to take.
57
+
58
+ Usage notes:
59
+ - Users will always be able to select "Other" to provide custom text input
60
+ - Use multi: true to allow multiple answers to be selected for a question
61
+ - If you recommend a specific option, make that the first option in the list and add "(Recommended)" at the end of the label
62
+
63
+ Example usage:
64
+
65
+ <example>
66
+ assistant: Let me ask which features you want to include.
67
+ assistant: Uses the user_prompt tool:
68
+ {
69
+ "question": "Which features should I implement?",
70
+ "options": [
71
+ {"label": "Authentication"},
72
+ {"label": "API endpoints"},
73
+ {"label": "Database models"},
74
+ {"label": "Unit tests"},
75
+ {"label": "Documentation"}
76
+ ],
77
+ "multi": true
78
+ }
79
+ </example>`;
80
+
81
+ const factory: CustomToolFactory = (pi: ToolAPI) => {
82
+ const tool: CustomAgentTool<typeof UserPromptParams, UserPromptDetails> = {
83
+ name: "user_prompt",
84
+ label: "User Prompt",
85
+ description: DESCRIPTION,
86
+ parameters: UserPromptParams,
87
+
88
+ async execute(_toolCallId, params, _signal, _onUpdate) {
89
+ const { question, options, multi = false } = params;
90
+ const optionLabels = options.map((o) => o.label);
91
+
92
+ if (!pi.hasUI) {
93
+ return {
94
+ content: [{ type: "text", text: "Error: User prompt requires interactive mode" }],
95
+ details: { question, options: optionLabels, multi, selectedOptions: [] },
96
+ };
97
+ }
98
+
99
+ let selectedOptions: string[] = [];
100
+ let customInput: string | undefined;
101
+
102
+ if (multi) {
103
+ // Multi-select: show checkboxes in the label to indicate selection state
104
+ const DONE = "✓ Done selecting";
105
+ const selected = new Set<string>();
106
+
107
+ while (true) {
108
+ // Build options with checkbox indicators
109
+ const opts: string[] = [];
110
+
111
+ // Add "Done" option if any selected
112
+ if (selected.size > 0) {
113
+ opts.push(DONE);
114
+ }
115
+
116
+ // Add all options with [X] or [ ] prefix
117
+ for (const opt of optionLabels) {
118
+ const checkbox = selected.has(opt) ? "[X]" : "[ ]";
119
+ opts.push(`${checkbox} ${opt}`);
120
+ }
121
+
122
+ // Add "Other" option
123
+ opts.push(OTHER_OPTION);
124
+
125
+ const prefix = selected.size > 0 ? `(${selected.size} selected) ` : "";
126
+ const choice = await pi.ui.select(`${prefix}${question}`, opts);
127
+
128
+ if (choice === null || choice === DONE) break;
129
+
130
+ if (choice === OTHER_OPTION) {
131
+ const input = await pi.ui.input("Enter your response:");
132
+ if (input) customInput = input;
133
+ break;
134
+ }
135
+
136
+ // Toggle selection - extract the actual option name
137
+ const optMatch = choice.match(/^\[.\] (.+)$/);
138
+ if (optMatch) {
139
+ const opt = optMatch[1];
140
+ if (selected.has(opt)) {
141
+ selected.delete(opt);
142
+ } else {
143
+ selected.add(opt);
144
+ }
145
+ }
146
+ }
147
+ selectedOptions = Array.from(selected);
148
+ } else {
149
+ // Single select with "Other" option
150
+ const choice = await pi.ui.select(question, [...optionLabels, OTHER_OPTION]);
151
+ if (choice === OTHER_OPTION) {
152
+ const input = await pi.ui.input("Enter your response:");
153
+ if (input) customInput = input;
154
+ } else if (choice) {
155
+ selectedOptions = [choice];
156
+ }
157
+ }
158
+
159
+ const details: UserPromptDetails = {
160
+ question,
161
+ options: optionLabels,
162
+ multi,
163
+ selectedOptions,
164
+ customInput,
165
+ };
166
+
167
+ let responseText: string;
168
+ if (customInput) {
169
+ responseText = `User provided custom input: ${customInput}`;
170
+ } else if (selectedOptions.length > 0) {
171
+ responseText = multi
172
+ ? `User selected: ${selectedOptions.join(", ")}`
173
+ : `User selected: ${selectedOptions[0]}`;
174
+ } else {
175
+ responseText = "User cancelled the selection";
176
+ }
177
+
178
+ return { content: [{ type: "text", text: responseText }], details };
179
+ },
180
+
181
+ renderCall(args, t) {
182
+ if (!args.question) {
183
+ return new Text(t.fg("error", "user_prompt: no question provided"), 0, 0);
184
+ }
185
+
186
+ const multiTag = args.multi ? t.fg("muted", " [multi-select]") : "";
187
+ let text = t.fg("toolTitle", "? ") + t.fg("accent", args.question) + multiTag;
188
+
189
+ if (args.options?.length) {
190
+ for (const opt of args.options) {
191
+ text += "\n" + t.fg("dim", " ○ ") + t.fg("muted", opt.label);
192
+ }
193
+ text += "\n" + t.fg("dim", " ○ ") + t.fg("muted", "Other (custom input)");
194
+ }
195
+
196
+ return new Text(text, 0, 0);
197
+ },
198
+
199
+ renderResult(result, { expanded }, t) {
200
+ const { details } = result;
201
+ if (!details) {
202
+ const txt = result.content[0];
203
+ return new Text(txt?.type === "text" ? txt.text : "", 0, 0);
204
+ }
205
+
206
+ let text = t.fg("toolTitle", "? ") + t.fg("accent", details.question);
207
+
208
+ if (details.customInput) {
209
+ // Custom input provided
210
+ text += "\n" + t.fg("dim", " ⎿ ") + t.fg("success", details.customInput);
211
+ } else if (details.selectedOptions.length > 0) {
212
+ // Show only selected options
213
+ const selected = details.selectedOptions;
214
+ if (selected.length === 1) {
215
+ text += "\n" + t.fg("dim", " ⎿ ") + t.fg("success", selected[0]);
216
+ } else {
217
+ // Multiple selections
218
+ for (let i = 0; i < selected.length; i++) {
219
+ const isLast = i === selected.length - 1;
220
+ const branch = isLast ? "└─" : "├─";
221
+ text += "\n" + t.fg("dim", ` ${branch} `) + t.fg("success", selected[i]);
222
+ }
223
+ }
224
+ } else {
225
+ text += "\n" + t.fg("dim", " ⎿ ") + t.fg("warning", "Cancelled");
226
+ }
227
+
228
+ return new Text(text, 0, 0);
229
+ },
230
+ };
231
+
232
+ return tool;
233
+ };
234
+
235
+ export default factory;