pi-ask-user 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -9,6 +9,30 @@ A Pi package that adds an interactive `ask_user` tool for collecting user decisi
9
9
  - Optional freeform responses
10
10
  - Context display support
11
11
  - Graceful fallback when interactive UI is unavailable
12
+ - Bundled `ask-user` skill for mandatory decision-gating in high-stakes or ambiguous tasks
13
+
14
+ ## Bundled skill: `ask-user`
15
+
16
+ This package now ships a skill at `skills/ask-user/SKILL.md` that nudges/mandates the agent to use `ask_user` when:
17
+
18
+ - architectural trade-offs are high impact
19
+ - requirements are ambiguous or conflicting
20
+ - assumptions would materially change implementation
21
+
22
+ The skill follows a "decision handshake" flow:
23
+
24
+ 1. Gather evidence and summarize context
25
+ 2. Ask one focused question via `ask_user`
26
+ 3. Wait for explicit user choice
27
+ 4. Confirm the decision, then proceed
28
+
29
+ See: `skills/ask-user/references/ask-user-skill-extension-spec.md`.
30
+
31
+ ## Demo
32
+
33
+ ![ask_user demo](./media/ask-user-demo.gif)
34
+
35
+ High-quality video: [ask-user-demo.mp4](./media/ask-user-demo.mp4)
12
36
 
13
37
  ## Install
14
38
 
@@ -37,27 +61,3 @@ The registered tool name is:
37
61
  }
38
62
  ```
39
63
 
40
- ## Local development
41
-
42
- ```bash
43
- pi -e ./index.ts
44
- ```
45
-
46
- ## Release workflow
47
-
48
- ### One-time setup
49
-
50
- 1. Add `NPM_TOKEN` in GitHub repo secrets.
51
- 2. Keep `package.json` version in sync with release tag.
52
-
53
- ### Publish with provenance (recommended)
54
-
55
- - Create tag: `vX.Y.Z`
56
- - Create a GitHub Release for that tag
57
- - The `publish.yml` workflow publishes to npm with `--provenance`
58
-
59
- You can also trigger the publish workflow manually from GitHub Actions.
60
-
61
- ## License
62
-
63
- MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-ask-user",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "description": "Interactive ask_user tool for pi-coding-agent with multi-select and freeform input UI",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -28,10 +28,14 @@
28
28
  "pi": {
29
29
  "extensions": [
30
30
  "./index.ts"
31
+ ],
32
+ "skills": [
33
+ "./skills"
31
34
  ]
32
35
  },
33
36
  "files": [
34
37
  "index.ts",
38
+ "skills",
35
39
  "README.md",
36
40
  "LICENSE"
37
41
  ],
@@ -0,0 +1,162 @@
1
+ ---
2
+ name: ask-user
3
+ description: "You MUST use this before high-stakes architectural decisions, irreversible changes, or when requirements are ambiguous. Runs a decision handshake with the ask_user tool: summarize context, present structured options, collect explicit user choice, then proceed."
4
+ metadata:
5
+ short-description: Decision gate for ambiguity and high-stakes choices
6
+ ---
7
+
8
+ # Ask User Decision Gate
9
+
10
+ Use this skill to force explicit user alignment before consequential decisions.
11
+
12
+ This skill is about **decision control**, not general chit-chat.
13
+
14
+ ## Non-negotiable rule
15
+
16
+ Invoke `ask_user` before proceeding when **any** of the following is true:
17
+
18
+ 1. The next step changes architecture, schema, API contracts, deployment strategy, or security posture.
19
+ 2. The work is costly to undo (large refactor, migration, destructive edit, production-facing behavior change).
20
+ 3. Requirements, constraints, or success criteria are unclear, conflicting, or missing.
21
+ 4. Multiple valid options exist and the trade-off is preference-dependent.
22
+ 5. You are about to assume something that can materially change implementation.
23
+
24
+ Do **not** skip this gate unless the user has already provided a clear, explicit decision for the exact trade-off.
25
+
26
+ ## Agent Protocol Handshake (required)
27
+
28
+ Follow this handshake in order.
29
+
30
+ ### 1) Detect boundary
31
+ Classify the current step as:
32
+ - `high_stakes`
33
+ - `ambiguous`
34
+ - `both`
35
+ - `clear` (no gate needed)
36
+
37
+ If classification is not `clear`, continue.
38
+
39
+ ### 2) Gather evidence first
40
+ Before asking, gather context from available tools (`read`, `bash`, `exa`, `ref`, etc.).
41
+ Do not ask the user to decide blind.
42
+
43
+ ### 3) Synthesize context
44
+ Prepare a short neutral summary (3-7 bullets or short paragraph) covering:
45
+ - current state
46
+ - key constraints
47
+ - trade-offs
48
+ - recommendation (if any)
49
+
50
+ ### 4) Ask one focused question
51
+ Call `ask_user` with one decision at a time:
52
+ - `question`: concrete decision prompt
53
+ - `context`: synthesized summary
54
+ - `options`: 2-5 clear choices when possible
55
+ - `allowMultiple`: `false` unless independent selections are genuinely needed
56
+ - `allowFreeform`: usually `true`
57
+
58
+ ### 5) Commit the decision
59
+ After response:
60
+ - restate the decision in plain language
61
+ - state what will be done next
62
+ - proceed with implementation
63
+
64
+ ### 6) Re-open only on new ambiguity
65
+ Ask again only if materially new uncertainty appears.
66
+ Avoid repetitive confirmation loops.
67
+
68
+ ## Anti-overasking guardrails (required)
69
+
70
+ Apply a strict question budget per decision boundary:
71
+
72
+ - **Max 1** `ask_user` call per decision boundary in normal cases.
73
+ - **Max 2** `ask_user` calls for the same boundary when first response is unclear/cancelled.
74
+ - Never ask the same trade-off again without new evidence.
75
+
76
+ Escalation ladder:
77
+
78
+ 1. **Attempt 1:** structured options + concise context.
79
+ 2. **Attempt 2 (only if needed):** narrower question with agent recommendation and explicit choices:
80
+ - `Proceed with recommended option`
81
+ - `Choose another option` (freeform)
82
+ - `Stop for now`
83
+
84
+ After attempt 2:
85
+
86
+ - If boundary is `high_stakes` or `both`: **stop and mark blocked**. Do not keep asking.
87
+ - If boundary is `ambiguous` only and user says “your call” or equivalent: proceed with the most reversible default and state assumptions explicitly.
88
+
89
+ ## `ask_user` payload quality standard
90
+
91
+ ### Question quality
92
+ Use:
93
+ - “Which option should we adopt for X?”
94
+ - “Do you want A (fast) or B (safer) for Y?”
95
+
96
+ Avoid:
97
+ - broad/open prompts with no decision boundary
98
+ - multiple unrelated decisions in one question
99
+ - questions that should be answered by reading code/docs first
100
+
101
+ ### Option quality
102
+ Options must be:
103
+ - mutually understandable
104
+ - short and outcome-oriented
105
+ - explicit on trade-offs
106
+
107
+ Good options include a short description when trade-offs are non-obvious.
108
+
109
+ ## Recommended patterns
110
+
111
+ ### Single-select architecture decision
112
+
113
+ ```json
114
+ {
115
+ "question": "Which caching strategy should we use for the first release?",
116
+ "context": "Current API has p95 latency issues. Redis is fastest but adds infra complexity; in-memory cache is simpler but not shared across instances.",
117
+ "options": [
118
+ { "title": "In-memory cache", "description": "Simpler rollout, weaker horizontal consistency" },
119
+ { "title": "Redis cache", "description": "Better consistency and scalability, more ops overhead" }
120
+ ],
121
+ "allowMultiple": false,
122
+ "allowFreeform": true
123
+ }
124
+ ```
125
+
126
+ ### Multi-select when decisions are independent
127
+
128
+ ```json
129
+ {
130
+ "question": "Select the first-wave hardening items to implement now.",
131
+ "context": "We can ship quickly with baseline controls, then add targeted hardening. Budget is limited to 1-2 days.",
132
+ "options": [
133
+ "Rate limiting",
134
+ "Audit logging",
135
+ "Input schema validation",
136
+ "Secrets rotation"
137
+ ],
138
+ "allowMultiple": true,
139
+ "allowFreeform": true
140
+ }
141
+ ```
142
+
143
+ ## Anti-patterns
144
+
145
+ - Asking `ask_user` without first gathering context
146
+ - Using it for trivial formatting choices
147
+ - Forcing options when freeform is clearly better
148
+ - Asking the same question repeatedly without new information
149
+ - Proceeding with high-stakes implementation after unclear/cancelled answer
150
+
151
+ ## If user cancels or answer is unclear
152
+
153
+ Pause execution and explain what is blocked.
154
+ Use at most one narrower follow-up `ask_user` question (attempt 2).
155
+ After that, do not continue asking in a loop:
156
+ - for high-stakes decisions: remain blocked until explicit decision
157
+ - for ambiguity-only decisions: proceed only if user delegated the choice ("your call")
158
+
159
+ ## Additional reference
160
+
161
+ For full trigger matrix, UX conventions, and extension interaction details, read:
162
+ - `references/ask-user-skill-extension-spec.md`
@@ -0,0 +1,250 @@
1
+ # Ask User Skill × Extension Interaction Spec
2
+
3
+ ## Purpose
4
+
5
+ Define how the `ask-user` skill (prompt-time behavior) and the `ask_user` extension tool (runtime UI) cooperate to create reliable human-in-the-loop decisions.
6
+
7
+ This spec optimizes for:
8
+ - explicit user control at decision boundaries
9
+ - low-friction interactive UX
10
+ - minimal context bloat (progressive disclosure)
11
+ - deterministic behavior across high-stakes workflows
12
+
13
+ ---
14
+
15
+ ## 1) 2026 Pattern Alignment
16
+
17
+ This design intentionally follows three emerging patterns used by modern agent systems.
18
+
19
+ ### A. Progressive Disclosure
20
+
21
+ The skill uses layered loading:
22
+
23
+ 1. **Metadata layer** (`name`, `description`) always in prompt.
24
+ 2. **Core protocol layer** (`SKILL.md`) loaded only when relevant.
25
+ 3. **Detailed reference layer** (`references/*.md`) loaded only when needed.
26
+
27
+ Implication: keep `SKILL.md` concise and decision-focused; move large examples and policy details into references.
28
+
29
+ ### B. Agent Protocol Handshakes
30
+
31
+ High-impact actions require a handshake:
32
+
33
+ `detect boundary -> summarize evidence -> ask -> explicit user choice -> commit -> execute`
34
+
35
+ The handshake prevents implicit assumptions from silently becoming implementation decisions.
36
+
37
+ ### C. Context-Aware Loading
38
+
39
+ Questions must be formed from current evidence (repo state, docs, logs, external research), not from generic prompts.
40
+
41
+ The `context` field in `ask_user` is the transport for this condensed evidence.
42
+
43
+ ---
44
+
45
+ ## 2) System Model
46
+
47
+ ### Components
48
+
49
+ 1. **Skill layer (`skills/ask-user/SKILL.md`)**
50
+ - decides *when* user interaction is mandatory
51
+ - enforces handshake behavior
52
+
53
+ 2. **Extension layer (`index.ts`, tool `ask_user`)**
54
+ - renders question UX (single-select, multi-select, freeform)
55
+ - returns normalized answer text to the agent
56
+
57
+ 3. **Model runtime**
58
+ - interprets skill guidance
59
+ - calls `ask_user` with structured payload
60
+ - resumes execution after explicit user response
61
+
62
+ ### Contract boundary
63
+
64
+ - Skill controls policy and decision gating.
65
+ - Extension controls interaction mechanics.
66
+ - Model must not bypass skill policy for high-stakes/ambiguous decisions.
67
+
68
+ ---
69
+
70
+ ## 3) Trigger Matrix (When to Call `ask_user`)
71
+
72
+ | Scenario | Must Ask? | Why |
73
+ |---|---:|---|
74
+ | Architecture trade-off (e.g., queue vs cron, SQL vs KV) | Yes | Preference-sensitive, high blast radius |
75
+ | Data schema / migration path selection | Yes | Costly to reverse |
76
+ | Security/compliance posture trade-off | Yes | Risk ownership is human |
77
+ | Requirements conflict or ambiguity | Yes | Need explicit intent |
78
+ | Non-trivial scope cut/prioritization | Yes | Product decision, not purely technical |
79
+ | Purely local refactor with identical behavior | Usually no | No policy-level decision |
80
+ | Formatting-only edits | No | Trivial |
81
+ | User already gave explicit choice for exact trade-off | No (unless new ambiguity) | Decision already captured |
82
+
83
+ ---
84
+
85
+ ## 4) Handshake State Machine
86
+
87
+ ```text
88
+ DISCOVER -> CLASSIFY -> (CLEAR -> EXECUTE)
89
+ -> (AMBIGUOUS/HIGH_STAKES -> EVIDENCE -> ASK -> WAIT -> COMMIT -> EXECUTE)
90
+ ```
91
+
92
+ ### State definitions
93
+
94
+ - **DISCOVER**: inspect task and current project state.
95
+ - **CLASSIFY**: decide whether decision gate is required.
96
+ - **EVIDENCE**: gather and compress decision context.
97
+ - **ASK**: invoke `ask_user` with a single focused decision.
98
+ - **WAIT**: pause implementation until response arrives.
99
+ - **COMMIT**: restate chosen option and intended next action.
100
+ - **EXECUTE**: implement according to confirmed decision.
101
+
102
+ ### Cancellation behavior
103
+
104
+ If user cancels or response is unclear:
105
+ - enforce a **max two-attempt budget** for the same decision boundary
106
+ - attempt 1: normal structured question
107
+ - attempt 2: narrower question with explicit recommendation + `Proceed with recommendation / Choose another / Stop`
108
+
109
+ After attempt 2:
110
+ - for `high_stakes` or `both`: do not continue; report blocked status
111
+ - for `ambiguous` only: proceed only when user delegates choice (e.g., "your call"), using the most reversible default and explicit assumptions
112
+
113
+ ---
114
+
115
+ ## 5) `ask_user` Payload Design Standard
116
+
117
+ ### Field mapping
118
+
119
+ | Field | Required | Rule |
120
+ |---|---:|---|
121
+ | `question` | Yes | One decision only, concrete and action-bound |
122
+ | `context` | Recommended | 3-7 bullets or short paragraph with evidence and trade-offs |
123
+ | `options` | Optional | Prefer 2-5 choices when stable alternatives exist |
124
+ | `allowMultiple` | Optional | `true` only for independent selections |
125
+ | `allowFreeform` | Optional | Usually `true`; set `false` only when strict menu required |
126
+
127
+ ### Style rules
128
+
129
+ - Keep options concise, decision-oriented, and contrastive.
130
+ - Include brief descriptions for non-obvious trade-offs.
131
+ - Avoid stacking unrelated questions.
132
+ - Ask after evidence gathering, not before.
133
+
134
+ ---
135
+
136
+ ## 6) UX Guidance for Best Outcomes
137
+
138
+ ### Good interaction shape
139
+
140
+ 1. Agent summarizes known constraints.
141
+ 2. Agent asks one clear question.
142
+ 3. User selects an option quickly (or writes freeform).
143
+ 4. Agent confirms and proceeds.
144
+
145
+ ### Avoid
146
+
147
+ - long speculative context dumps
148
+ - “What do you want?” without options
149
+ - repeated confirmation of unchanged decisions
150
+ - more than two attempts for the same decision boundary
151
+ - hidden assumptions after user response
152
+
153
+ ### Recommended defaults
154
+
155
+ - `allowFreeform: true`
156
+ - `allowMultiple: false`
157
+ - `options`: include concise titles + descriptions for trade-offs
158
+
159
+ ---
160
+
161
+ ## 7) Runtime and Fallback Semantics
162
+
163
+ The extension already provides these behavior guarantees:
164
+
165
+ 1. **Interactive mode with UI**
166
+ - single-select list, multi-select list, or freeform editor
167
+
168
+ 2. **No options provided**
169
+ - freeform input prompt is used
170
+
171
+ 3. **No interactive UI available**
172
+ - tool returns an error-style textual fallback that includes question/context/options
173
+
174
+ Design implication:
175
+ - skill should prefer structured options when ambiguity is high
176
+ - but always permit freeform for unanticipated requirements
177
+
178
+ ---
179
+
180
+ ## 8) Quality Rubric
181
+
182
+ A decision-gated interaction is successful when all are true:
183
+
184
+ - [ ] High-stakes or ambiguous boundary was detected
185
+ - [ ] Context was gathered before asking
186
+ - [ ] At most two decision questions were asked for the same boundary (normally one)
187
+ - [ ] User response was explicit
188
+ - [ ] Agent restated decision before execution
189
+ - [ ] Implementation followed the selected path
190
+
191
+ Failure signals:
192
+ - agent made architectural choice without user decision
193
+ - question lacked trade-off context
194
+ - user answer ignored or overwritten
195
+
196
+ ---
197
+
198
+ ## 9) Example Protocol Templates
199
+
200
+ ### Template: architecture fork
201
+
202
+ ```json
203
+ {
204
+ "question": "Which implementation path should we use for v1?",
205
+ "context": "Path A is faster to ship but less extensible. Path B takes longer but supports plugin-style growth. Existing deadline is 2 weeks.",
206
+ "options": [
207
+ { "title": "Path A (ship fast)", "description": "Lowest scope, revisit architecture later" },
208
+ { "title": "Path B (extensible)", "description": "Higher initial effort, cleaner long-term composition" }
209
+ ],
210
+ "allowMultiple": false,
211
+ "allowFreeform": true
212
+ }
213
+ ```
214
+
215
+ ### Template: ambiguity cleanup
216
+
217
+ ```json
218
+ {
219
+ "question": "Which requirement should be prioritized first?",
220
+ "context": "Current request mixes performance tuning and UI redesign. Doing both now risks delaying delivery.",
221
+ "options": [
222
+ "Performance first",
223
+ "UI redesign first",
224
+ "Do a minimal pass on both"
225
+ ],
226
+ "allowMultiple": false,
227
+ "allowFreeform": true
228
+ }
229
+ ```
230
+
231
+ ---
232
+
233
+ ## 10) Packaging + Distribution Notes
234
+
235
+ To ship this skill with the extension package:
236
+
237
+ - include `skills/` in npm package files
238
+ - register skills in `package.json` under `pi.skills`
239
+
240
+ This ensures the skill is discoverable at startup and available for implicit invocation.
241
+
242
+ ---
243
+
244
+ ## 11) Future Enhancements (Optional)
245
+
246
+ - **Decision memory log**: append chosen options to a lightweight session decision ledger.
247
+ - **Adaptive option generation**: tailor options by repo language/framework context.
248
+ - **Confidence thresholding**: auto-trigger ask gate when model confidence in requirements is low.
249
+
250
+ These are optional and not required for initial rollout.