pi-agent-extensions 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,181 @@
1
+ # pi-agent-extensions
2
+
3
+ A collection of extensions for the [pi coding agent](https://github.com/badlogic/pi-mono/tree/main/packages/coding-agent).
4
+
5
+ ## Extensions
6
+
7
+ | Extension | Type | Description | Status |
8
+ |-----------|------|-------------|--------|
9
+ | **sessions** | Command | Quick session picker with `/sessions` command | ✅ Stable |
10
+ | **ask_user** | Tool | LLM can ask structured questions with options | ⚙️ Beta (v0.1.0) |
11
+ | **handoff** | Command | Transfer context to a new focused session with `/handoff` | ✅ Stable |
12
+
13
+ ## Install
14
+
15
+ ### From Source (Until Published)
16
+
17
+ ```bash
18
+ # Clone the repository
19
+ git clone https://github.com/jayshah5696/pi-agent-extensions.git
20
+ cd pi-agent-extensions
21
+
22
+ # Install globally
23
+ pi install .
24
+
25
+ # Or install to specific project
26
+ cd ~/your-project
27
+ pi install -l /path/to/pi-agent-extensions
28
+ ```
29
+
30
+ ### Quick Test Without Installing
31
+
32
+ ```bash
33
+ pi -e /path/to/pi-agent-extensions/extensions/sessions/index.ts \
34
+ -e /path/to/pi-agent-extensions/extensions/ask-user/index.ts \
35
+ -e /path/to/pi-agent-extensions/extensions/handoff/index.ts
36
+ ```
37
+
38
+ ### From npm (When Published)
39
+
40
+ ```bash
41
+ pi install npm:pi-agent-extensions
42
+ ```
43
+
44
+ Both extensions will be available immediately after installation.
45
+
46
+ ## Verify Installation
47
+
48
+ After installing, start pi and look for the startup message:
49
+
50
+ ```
51
+ Extensions: sessions, ask_user, handoff
52
+ ```
53
+
54
+ **Test sessions:**
55
+ ```bash
56
+ pi
57
+ /sessions
58
+ ```
59
+
60
+ **Test ask_user:**
61
+ ```bash
62
+ pi
63
+ > Ask me which database I prefer: PostgreSQL or SQLite
64
+ ```
65
+
66
+ The LLM should call the `ask_user` tool and show you options to select.
67
+
68
+ **Test handoff:**
69
+ ```bash
70
+ pi
71
+ # Have a conversation first, then:
72
+ /handoff implement the next feature with proper tests
73
+ ```
74
+
75
+ You'll see a loader while context is extracted, then an editor to review the handoff prompt.
76
+
77
+ ## Uninstall
78
+
79
+ ```bash
80
+ pi remove pi-agent-extensions
81
+ ```
82
+
83
+ ## Extensions
84
+
85
+ ### Sessions
86
+
87
+ Quick session picker for the pi coding agent. Provides a compact `/sessions` selector (default 5 visible rows) with arrow navigation, Enter to switch, and Esc to cancel.
88
+
89
+ **Usage:**
90
+
91
+ ```bash
92
+ /sessions # Show last 5 sessions
93
+ /sessions 10 # Show last 10 sessions
94
+ ```
95
+
96
+ **Features:**
97
+ - Lists sessions from the **current project** only
98
+ - Displays absolute timestamps (`YYYY-MM-DD HH:mm`)
99
+ - Filter by typing (prefix match on session name or cwd)
100
+ - In non-UI mode (`pi -p` or JSON/RPC), sessions are printed to stdout
101
+
102
+ See [docs/extensions/sessions.md](docs/extensions/sessions.md) for details.
103
+
104
+ ### Ask User
105
+
106
+ The LLM can call the `ask_user` tool to gather user input with structured questions and options.
107
+
108
+ **Status:** ⚙️ Beta (v0.1.0) - Core features working, enhanced UI coming soon
109
+
110
+ **Example:**
111
+
112
+ ```typescript
113
+ ask_user({
114
+ questions: [{
115
+ question: "Which database should we use?",
116
+ header: "Database Selection",
117
+ options: [
118
+ { label: "PostgreSQL (Recommended)", description: "Battle-tested relational DB" },
119
+ { label: "SQLite", description: "Lightweight, file-based" },
120
+ { label: "MongoDB", description: "Document store" }
121
+ ]
122
+ }]
123
+ })
124
+ ```
125
+
126
+ **Features:**
127
+ - ✅ Text input questions
128
+ - ✅ Option selection with descriptions
129
+ - ✅ "Other" option always available
130
+ - ✅ Print mode (pending file workflow)
131
+ - ✅ Session persistence
132
+ - ⏸️ Custom TUI components (using built-in helpers for now)
133
+ - ⏸️ Tabbed multi-question UI (sequential currently)
134
+
135
+ See [extensions/ask-user/README.md](extensions/ask-user/README.md) and [docs/extensions/ask-user.md](docs/extensions/ask-user.md) for details.
136
+
137
+ ### Handoff
138
+
139
+ Transfer context to a new focused session. Unlike `/compact` which summarizes everything, `/handoff` extracts only what's relevant to your next goal.
140
+
141
+ **Usage:**
142
+
143
+ ```bash
144
+ /handoff <goal>
145
+ ```
146
+
147
+ **Examples:**
148
+
149
+ ```bash
150
+ /handoff implement team-level handoff with proper tests
151
+ /handoff fix the authentication bug in login flow
152
+ /handoff add unit tests for the parser module
153
+ ```
154
+
155
+ **Features:**
156
+ - Goal-driven context extraction (files, commands, decisions, open questions)
157
+ - Structured JSON extraction with LLM
158
+ - Skill inheritance (preserves last `/skill:` used)
159
+ - Git metadata (branch, dirty state)
160
+ - Session metadata (model, tools, thinking level)
161
+ - Interactive editor to review/edit before creating new session
162
+ - Configurable via `.pi/settings.json`
163
+
164
+ **What gets extracted:**
165
+ - Relevant files with reasons
166
+ - Commands that were run
167
+ - Key context and decisions
168
+ - Open questions/risks
169
+
170
+ See [docs/extensions/handoff.md](docs/extensions/handoff.md) for full documentation.
171
+
172
+ ## Development
173
+
174
+ ```bash
175
+ npm install
176
+ npm test
177
+ ```
178
+
179
+ ## License
180
+
181
+ MIT
package/docs/README.md ADDED
@@ -0,0 +1,32 @@
1
+ # Documentation
2
+
3
+ ## Extensions
4
+
5
+ User-facing documentation for each extension:
6
+
7
+ | Extension | Description |
8
+ |-----------|-------------|
9
+ | [sessions](extensions/sessions.md) | Quick session picker with `/sessions` command |
10
+ | [ask-user](extensions/ask-user.md) | LLM tool for structured user questions |
11
+ | [handoff](extensions/handoff.md) | Context transfer to new focused sessions |
12
+
13
+ ## Guides
14
+
15
+ Setup and usage guides:
16
+
17
+ | Guide | Description |
18
+ |-------|-------------|
19
+ | [Manual Testing](guides/manual-testing.md) | How to manually test the extensions |
20
+ | [Vertex AI Setup](guides/vertex-ai-setup.md) | Using Pi with Google Cloud Vertex AI |
21
+
22
+ ## Development
23
+
24
+ Internal documentation for contributors:
25
+
26
+ ### Handoff
27
+ - [Specification](dev/handoff/spec.md) - Full design spec and rationale
28
+ - [Implementation Log](dev/handoff/implementation-log.md) - Development history
29
+ - [Eval Strategy](dev/handoff/eval-strategy.md) - Testing and evaluation approach
30
+
31
+ ### Ask User
32
+ - [Test Cases](dev/ask-user/test-cases.md) - Comprehensive test coverage plan
@@ -0,0 +1,304 @@
1
+ # ask_user Test Cases
2
+
3
+ **Purpose:** Define comprehensive test coverage before implementation
4
+ **Status:** Draft - Awaiting approval
5
+
6
+ ---
7
+
8
+ ## Test Categories
9
+
10
+ ### 1. Schema Validation
11
+ ### 2. Interactive Mode (TUI)
12
+ ### 3. Non-Interactive Mode (Print)
13
+ ### 4. RPC Mode
14
+ ### 5. Session Persistence
15
+ ### 6. Edge Cases
16
+ ### 7. Integration
17
+
18
+ ---
19
+
20
+ ## 1. Schema Validation Tests
21
+
22
+ ### 1.1 Valid Parameters
23
+ - ✓ Single text question (no options)
24
+ - ✓ Single question with options
25
+ - ✓ Single question with options + descriptions
26
+ - ✓ Single question with header
27
+ - ✓ Multiple questions
28
+ - ✓ Question with multiSelect: true
29
+ - ✓ Question with metadata
30
+
31
+ ### 1.2 Invalid Parameters
32
+ - ✗ Empty questions array
33
+ - ✗ Question with empty string
34
+ - ✗ Option with empty label
35
+ - ✗ Invalid multiSelect value (not boolean)
36
+ - ✗ Malformed option (missing required fields)
37
+
38
+ **Test File:** `tests/ask-user/schema.test.ts`
39
+
40
+ ---
41
+
42
+ ## 2. Interactive Mode (TUI) Tests
43
+
44
+ ### 2.1 Single Text Question
45
+ **Setup:** Question with no options
46
+ **Expected:**
47
+ - Shows text input replacing editor
48
+ - Header displayed if provided
49
+ - User types answer
50
+ - Enter submits → returns `{ answered: true, answers: [{answer: "typed text", wasCustom: true}] }`
51
+ - Esc cancels → returns `{ answered: false, cancelled: true }`
52
+
53
+ ### 2.2 Single Select Question
54
+ **Setup:** Question with 3 options
55
+ **Expected:**
56
+ - Shows numbered options (1, 2, 3, 4. Other)
57
+ - Up/Down navigation works
58
+ - Number keys (1-3) select directly
59
+ - Enter on option returns selected
60
+ - "Other" option allows text input
61
+ - Descriptions shown below labels
62
+
63
+ ### 2.3 Multi-Select Question
64
+ **Setup:** Question with `multiSelect: true`
65
+ **Expected:**
66
+ - Shows checkboxes `[ ]` and `[x]`
67
+ - Space toggles selection
68
+ - Multiple selections allowed
69
+ - Enter submits all selected
70
+ - Returns `answer` as string array
71
+
72
+ ### 2.4 Multiple Questions (Tabbed)
73
+ **Setup:** 3 questions in array
74
+ **Expected:**
75
+ - Shows tab bar with question indicators (□ = unanswered, ■ = answered)
76
+ - Tab/Arrow keys navigate between questions
77
+ - Each question shows correctly
78
+ - Submit tab appears after all questions
79
+ - Can only submit when all answered
80
+ - Esc shows confirmation if any answered
81
+
82
+ ### 2.5 Long Options List
83
+ **Setup:** Question with 15 options
84
+ **Expected:**
85
+ - Scrollable list with "↓ N more..." indicator
86
+ - Number keys 1-9 work for first 9 options
87
+ - Scrolling reveals all options
88
+ - "Other" is always last (accessible via 0 or scroll)
89
+
90
+ ### 2.6 Answer Length Warning
91
+ **Setup:** User types 2500 character answer
92
+ **Expected:**
93
+ - Warning shows: "Answer is long (2,500 chars). Continue? [Y/n]"
94
+ - Y allows submission
95
+ - N returns to editing
96
+
97
+ ### 2.7 Cancellation Behavior
98
+ **Setup:** Multi-question, user answers 2 of 3, presses Esc
99
+ **Expected:**
100
+ - Confirmation dialog: "Discard 2 answers? [Y/n]"
101
+ - Y cancels all, returns `{ answered: false, cancelled: true }`
102
+ - N returns to questions
103
+
104
+ **Test File:** `tests/ask-user/interactive.test.ts` (requires TUI mocking)
105
+
106
+ ---
107
+
108
+ ## 3. Non-Interactive Mode (Print) Tests
109
+
110
+ ### 3.1 Pending File Creation
111
+ **Setup:** Call ask_user in print mode (`pi -p`)
112
+ **Expected:**
113
+ - Creates `.pi/pending-questions.json`
114
+ - Returns message with instructions
115
+ - File contains: sessionId, timestamp, questions with answer: null
116
+ - Tool result has `{ answered: false, pendingFile: ".pi/pending-questions.json" }`
117
+
118
+ ### 3.2 Natural Language Answer Parsing
119
+ **Setup:** Pending file exists, run `pi -p @.pi/pending-questions.json "postgres and call it api-service"`
120
+ **Expected:**
121
+ - LLM parses natural language
122
+ - Fills in answers correctly
123
+ - Deletes pending file
124
+ - Returns `{ answered: true, answers: [...] }`
125
+
126
+ ### 3.3 JSON Direct Edit
127
+ **Setup:** User edits pending JSON, adds answers, runs `pi -c`
128
+ **Expected:**
129
+ - Reads answers from JSON
130
+ - Validates format
131
+ - Returns answers to LLM
132
+ - Deletes pending file
133
+
134
+ ### 3.4 Inline Answers Flag
135
+ **Setup:** `pi -p --answers '["PostgreSQL", "api-service"]'`
136
+ **Expected:**
137
+ - Parses JSON array
138
+ - Matches to questions in order
139
+ - Returns answers
140
+ - No pending file created
141
+
142
+ **Test File:** `tests/ask-user/print-mode.test.ts`
143
+
144
+ ---
145
+
146
+ ## 4. RPC Mode Tests
147
+
148
+ ### 4.1 Request Format
149
+ **Setup:** ask_user called in RPC mode
150
+ **Expected:**
151
+ - Returns structured JSON with type: "ask_user_request"
152
+ - Includes requestId, questions, metadata
153
+
154
+ ### 4.2 Response Handling
155
+ **Setup:** RPC client sends ask_user_response
156
+ **Expected:**
157
+ - Validates response format
158
+ - Matches requestId
159
+ - Returns answers to LLM
160
+
161
+ ### 4.3 Client Disconnection
162
+ **Setup:** Request sent, client disconnects before responding
163
+ **Expected:**
164
+ - Timeout after N seconds (configurable)
165
+ - Returns `{ answered: false, connectionLost: true }`
166
+
167
+ **Test File:** `tests/ask-user/rpc-mode.test.ts`
168
+
169
+ ---
170
+
171
+ ## 5. Session Persistence Tests
172
+
173
+ ### 5.1 Tool Result Storage
174
+ **Setup:** User answers questions
175
+ **Expected:**
176
+ - Tool result stored in session with details:
177
+ - questions array
178
+ - answers array
179
+ - answeredAt timestamp
180
+ - mode: "interactive" | "print" | "rpc"
181
+ - metadata (if provided)
182
+
183
+ ### 5.2 Session Branching
184
+ **Setup:** Navigate to before ask_user, continue from there
185
+ **Expected:**
186
+ - ask_user replays (no answer yet)
187
+ - User can provide different answer
188
+ - New branch created with new answer
189
+
190
+ ### 5.3 Session Resumption
191
+ **Setup:** `pi -c` after answering questions
192
+ **Expected:**
193
+ - Previous Q&A visible in session history
194
+ - Can reference answers later
195
+
196
+ **Test File:** `tests/ask-user/persistence.test.ts`
197
+
198
+ ---
199
+
200
+ ## 6. Edge Cases Tests
201
+
202
+ ### 6.1 Session Interruption
203
+ **Setup:** Terminal closed mid-question
204
+ **Expected:**
205
+ - On `pi -c`, question replays from beginning
206
+ - No partial state saved
207
+
208
+ ### 6.2 Empty Options Array
209
+ **Setup:** Question with `options: []`
210
+ **Expected:**
211
+ - Treated as text input question
212
+ - No "Other" option shown
213
+
214
+ ### 6.3 Single Option
215
+ **Setup:** Question with 1 option
216
+ **Expected:**
217
+ - Shows option + "Other"
218
+ - User can still select option or type custom
219
+
220
+ ### 6.4 Extremely Long Question Text
221
+ **Setup:** Question text is 500 characters
222
+ **Expected:**
223
+ - Text wraps properly
224
+ - UI remains usable
225
+
226
+ ### 6.5 Unicode/Emoji in Options
227
+ **Setup:** Options contain emoji and Unicode
228
+ **Expected:**
229
+ - Renders correctly
230
+ - Selectable without issues
231
+
232
+ ### 6.6 Duplicate Tool Call
233
+ **Setup:** LLM calls ask_user twice in same turn
234
+ **Expected:**
235
+ - Both questions shown (batched or sequential - TBD)
236
+ - OR second call returns warning about duplicate
237
+
238
+ ### 6.7 No UI Available (ctx.hasUI = false)
239
+ **Setup:** Extension loaded in non-interactive environment
240
+ **Expected:**
241
+ - Returns error message
242
+ - Does not attempt to show UI
243
+
244
+ **Test File:** `tests/ask-user/edge-cases.test.ts`
245
+
246
+ ---
247
+
248
+ ## 7. Integration Tests
249
+
250
+ ### 7.1 Compaction with Q&A
251
+ **Setup:** Session with ask_user calls, trigger compaction
252
+ **Expected:**
253
+ - Q&A included in summary
254
+ - Structured data preserved
255
+
256
+ ### 7.2 Tool Rendering
257
+ **Setup:** View session with ask_user calls
258
+ **Expected:**
259
+ - Tool call renders with question text
260
+ - Tool result renders with answers
261
+ - Custom rendering works
262
+
263
+ ### 7.3 With Other Tools
264
+ **Setup:** LLM calls ask_user, then bash, then edit
265
+ **Expected:**
266
+ - No interference between tools
267
+ - State isolated correctly
268
+
269
+ **Test File:** `tests/ask-user/integration.test.ts`
270
+
271
+ ---
272
+
273
+ ## Test Implementation Strategy
274
+
275
+ ### Unit Tests (High Priority)
276
+ - Schema validation
277
+ - Answer parsing logic
278
+ - Session persistence logic
279
+ - Print mode file I/O
280
+
281
+ ### Integration Tests (Medium Priority)
282
+ - Tool registration
283
+ - RPC protocol
284
+ - Compaction integration
285
+
286
+ ### UI Tests (Low Priority / Manual)
287
+ - Interactive TUI flows
288
+ - Visual rendering
289
+ - Keyboard navigation
290
+
291
+ **Note:** TUI tests require mocking or headless testing framework. May start with manual testing for UI, automated for logic.
292
+
293
+ ---
294
+
295
+ ## Questions for Approval
296
+
297
+ 1. **TUI Testing Approach:** Should we mock the TUI for automated tests, or do manual testing for UI?
298
+ 2. **Duplicate ask_user calls:** Should we batch them or handle sequentially?
299
+ 3. **RPC timeout:** What should the default timeout be? 30s? 60s? Configurable?
300
+ 4. **Test coverage target:** Aim for 80%? 90%?
301
+
302
+ ---
303
+
304
+ **Status:** Ready for review and approval before implementation begins.