pi-next-steps 1.1.5 → 1.1.6
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/CHANGELOG.md +18 -8
- package/README.md +80 -73
- package/next-steps.ts +502 -370
- package/package.json +22 -16
package/CHANGELOG.md
CHANGED
|
@@ -1,9 +1,19 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
|
|
3
|
-
## 1.1.5 — 2026-11-16
|
|
1
|
+
# Changelog
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
-
|
|
8
|
-
|
|
9
|
-
-
|
|
3
|
+
## 1.1.6 - 2026-11-18
|
|
4
|
+
|
|
5
|
+
- Multiple blocks per reply: every `next_steps` call keeps its own options, so
|
|
6
|
+
one reply can offer several separate choices.
|
|
7
|
+
- Carry-forward works. States are per reply and always cleared, so a block is
|
|
8
|
+
queued once instead of being re-queued on every later turn.
|
|
9
|
+
- Carried entries show their real age (`1 reply back`, `2 replies back`) and
|
|
10
|
+
the list is youngest first.
|
|
11
|
+
- `/ns` opens a tabbed picker over every collected block, newest reply first.
|
|
12
|
+
Space toggles, arrows move and switch block, enter sends.
|
|
13
|
+
- Picked steps retire individually: a block answered during its own reply is
|
|
14
|
+
never carried afterwards, and untouched siblings survive.
|
|
15
|
+
- `/ns clear` drops stale steps from older replies and keeps the last prompt's.
|
|
16
|
+
- `/ns clear X` drops the steps collected in the last X posts.
|
|
17
|
+
- Every selection travels as one user message.
|
|
18
|
+
|
|
19
|
+
## 1.1.5 - 2026-11-16
|
package/README.md
CHANGED
|
@@ -1,73 +1,80 @@
|
|
|
1
|
-
# pi-next-steps
|
|
2
|
-
|
|
3
|
-

|
|
4
|
-
|
|
5
|
-
**Next Steps** puts the end of a reply to work. Instead of the agent asking "say the word and I'll push the branch", the reply ends with a row of selectable steps, and one pick sends that step as the next message. Pick several and one send delivers them together.
|
|
6
|
-
|
|
7
|
-
A Pi port of the Hermes **Next Steps** plugin, adapted for the Pi coding agent's extension API.
|
|
8
|
-
|
|
9
|
-
## Features
|
|
10
|
-
|
|
11
|
-
- **Tool-driven offers.** The agent calls the `next_steps` tool with 2-6 short option strings at the end of a choice reply.
|
|
12
|
-
- **Recommended marks.** Options the classifier prefers carry a `★` tag and start selected. Several may be recommended when the steps belong together.
|
|
13
|
-
- **Risky pills.** An option that could damage files, a build, or money carries a `⚠` tag. Off by default.
|
|
14
|
-
- **Subtitles.** A chip can carry a dim second line when the label alone would be read wrongly.
|
|
15
|
-
- **Multi-select.** Pick comma-separated indices (`1,3`) and one send delivers them together.
|
|
16
|
-
- **Auto-classification.** When `rec`/`risky` are omitted, the extension asks the session model to classify the options (best-effort).
|
|
17
|
-
- **System-prompt guidance.** The model is told to call `next_steps` at choice points instead of asking in prose.
|
|
18
|
-
|
|
19
|
-
## Install
|
|
20
|
-
|
|
21
|
-
```bash
|
|
22
|
-
pi install npm:pi-next-steps
|
|
23
|
-
# or from git:
|
|
24
|
-
pi install git:github.com/apoapostolov/pi-next-steps
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
Then reload Pi so the extension loads.
|
|
28
|
-
|
|
29
|
-
## Usage
|
|
30
|
-
|
|
31
|
-
The agent calls `next_steps` automatically when a reply ends with a choice. You can also invoke it manually from the TUI:
|
|
32
|
-
|
|
33
|
-
```
|
|
34
|
-
/ns
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
-
|
|
69
|
-
-
|
|
70
|
-
|
|
71
|
-
##
|
|
72
|
-
|
|
73
|
-
|
|
1
|
+
# pi-next-steps
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
**Next Steps** puts the end of a reply to work. Instead of the agent asking "say the word and I'll push the branch", the reply ends with a row of selectable steps, and one pick sends that step as the next message. Pick several and one send delivers them together.
|
|
6
|
+
|
|
7
|
+
A Pi port of the Hermes **Next Steps** plugin, adapted for the Pi coding agent's extension API.
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- **Tool-driven offers.** The agent calls the `next_steps` tool with 2-6 short option strings at the end of a choice reply.
|
|
12
|
+
- **Recommended marks.** Options the classifier prefers carry a `★` tag and start selected. Several may be recommended when the steps belong together.
|
|
13
|
+
- **Risky pills.** An option that could damage files, a build, or money carries a `⚠` tag. Off by default.
|
|
14
|
+
- **Subtitles.** A chip can carry a dim second line when the label alone would be read wrongly.
|
|
15
|
+
- **Multi-select.** Pick comma-separated indices (`1,3`) and one send delivers them together.
|
|
16
|
+
- **Auto-classification.** When `rec`/`risky` are omitted, the extension asks the session model to classify the options (best-effort).
|
|
17
|
+
- **System-prompt guidance.** The model is told to call `next_steps` at choice points instead of asking in prose.
|
|
18
|
+
|
|
19
|
+
## Install
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
pi install npm:pi-next-steps
|
|
23
|
+
# or from git:
|
|
24
|
+
pi install git:github.com/apoapostolov/pi-next-steps
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Then reload Pi so the extension loads.
|
|
28
|
+
|
|
29
|
+
## Usage
|
|
30
|
+
|
|
31
|
+
The agent calls `next_steps` automatically when a reply ends with a choice. You can also invoke it manually from the TUI:
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
/ns
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
A tabbed picker opens with one tab per collected reply, newest first. Space toggles a label, arrows move and switch tab, Enter sends. Every chosen step travels as one user message, so a pick that spans several tabs still costs one turn. Carried labels show how many offering replies back they came from.
|
|
38
|
+
|
|
39
|
+
Clear what you no longer want:
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
/ns clear # drop stale steps from older replies, keep the last prompt's
|
|
43
|
+
/ns clear 2 # drop the steps collected in the last 2 posts
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Alias: `/nextsteps`.
|
|
47
|
+
|
|
48
|
+
## Tool parameters
|
|
49
|
+
|
|
50
|
+
| Parameter | Type | Description |
|
|
51
|
+
|---|---|---|
|
|
52
|
+
| `options` | `string[]` | The option labels to offer (2-6 recommended). |
|
|
53
|
+
| `multi` | `boolean` | Allow picking multiple (default `true`). |
|
|
54
|
+
| `rec` | `string` | Comma-separated 1-based indices to mark recommended. |
|
|
55
|
+
| `risky` | `string` | Comma-separated 1-based indices to mark risky. |
|
|
56
|
+
| `subtitles` | `string[]` | Optional dim second lines, one per option. |
|
|
57
|
+
|
|
58
|
+
## Example directive (no tool calling)
|
|
59
|
+
|
|
60
|
+
When tool calling is unavailable, the same row can be expressed as a directive:
|
|
61
|
+
|
|
62
|
+
```
|
|
63
|
+
::nextsteps{multi="1" rec="1" risky="2" q1="Push the branch and open the PR" q2="Force-push over the review commit" q3="Write the release note first" d2="Rewrites origin, discarding the commit already there"}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Requirements
|
|
67
|
+
|
|
68
|
+
- Pi 1.5+
|
|
69
|
+
- A Nerd Font (for the `★`/`⚠` glyphs) is recommended but not required.
|
|
70
|
+
|
|
71
|
+
## Limits
|
|
72
|
+
|
|
73
|
+
- A step is a sentence. A vague option sends a vague request; the plugin does not rewrite what the agent wrote.
|
|
74
|
+
- Ticks are per block. Two blocks in one reply keep separate picks.
|
|
75
|
+
- The RISKY pill is an opinion from a classifier reading labels and context, not a reading of your repository.
|
|
76
|
+
- Auto-classification is best-effort and may fail on providers that require extra headers (e.g. opencode-go).
|
|
77
|
+
|
|
78
|
+
## License
|
|
79
|
+
|
|
80
|
+
MIT. Inspired by [Follow-up Chips](https://github.com/nuonrg/hermes-plugin-followup-chips) and the Hermes Next Steps plugin.
|
package/next-steps.ts
CHANGED
|
@@ -1,370 +1,502 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* next-steps for Pi: a port of the Hermes "Next Steps" plugin.
|
|
3
|
-
*
|
|
4
|
-
* The agent calls the `next_steps` tool with a list of option strings at the end
|
|
5
|
-
* of a reply. The extension stores them and exposes `/ns` (alias `/nextsteps`)
|
|
6
|
-
* to pick one or more and send them as the next user turn.
|
|
7
|
-
*
|
|
8
|
-
* Settings: ~/.pi/agent/next-steps.json
|
|
9
|
-
* markRisky (bool, default false), carryForward (bool, default false),
|
|
10
|
-
* steerOnClick (bool, default false), accentRecommended (bool, default true).
|
|
11
|
-
*/
|
|
12
|
-
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
13
|
-
import { matchesKey } from "@earendil-works/pi-tui";
|
|
14
|
-
import { existsSync, readFileSync, writeFileSync, mkdirSync } from "node:fs";
|
|
15
|
-
import { join } from "node:path";
|
|
16
|
-
|
|
17
|
-
interface NextStepsState {
|
|
18
|
-
options: string[];
|
|
19
|
-
multi: boolean;
|
|
20
|
-
rec: string;
|
|
21
|
-
risky: string;
|
|
22
|
-
subtitles: string[];
|
|
23
|
-
alternates: string;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
interface Settings {
|
|
27
|
-
markRisky: boolean;
|
|
28
|
-
carryForward: boolean;
|
|
29
|
-
steerOnClick: boolean;
|
|
30
|
-
accentRecommended: boolean;
|
|
31
|
-
rewriteProseOffers: boolean;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const SETTINGS_PATH = join(process.env.HOME || process.env.USERPROFILE || ".", ".pi", "agent", "next-steps.json");
|
|
35
|
-
|
|
36
|
-
function loadSettings(): Settings {
|
|
37
|
-
const defaults: Settings = { markRisky: false, carryForward: false, steerOnClick: false, accentRecommended: true, rewriteProseOffers: false };
|
|
38
|
-
try {
|
|
39
|
-
if (existsSync(SETTINGS_PATH)) {
|
|
40
|
-
const raw = JSON.parse(readFileSync(SETTINGS_PATH, "utf8"));
|
|
41
|
-
return { ...defaults, ...raw };
|
|
42
|
-
}
|
|
43
|
-
} catch {}
|
|
44
|
-
// write defaults
|
|
45
|
-
try {
|
|
46
|
-
mkdirSync(join(process.env.HOME || process.env.USERPROFILE || ".", ".pi", "agent"), { recursive: true });
|
|
47
|
-
writeFileSync(SETTINGS_PATH, JSON.stringify(defaults, null, 2));
|
|
48
|
-
} catch {}
|
|
49
|
-
return defaults;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export default function (pi: ExtensionAPI) {
|
|
53
|
-
const settings = loadSettings();
|
|
54
|
-
let
|
|
55
|
-
// carry-forward queue: array of { options, rec, risky, subtitles, age }
|
|
56
|
-
const queue: { options: string[]; rec: string; risky: string; subtitles: string[]; age: number }[] = [];
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
if (
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
//
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
.
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
1
|
+
/**
|
|
2
|
+
* next-steps for Pi: a port of the Hermes "Next Steps" plugin.
|
|
3
|
+
*
|
|
4
|
+
* The agent calls the `next_steps` tool with a list of option strings at the end
|
|
5
|
+
* of a reply. The extension stores them and exposes `/ns` (alias `/nextsteps`)
|
|
6
|
+
* to pick one or more and send them as the next user turn.
|
|
7
|
+
*
|
|
8
|
+
* Settings: ~/.pi/agent/next-steps.json
|
|
9
|
+
* markRisky (bool, default false), carryForward (bool, default false),
|
|
10
|
+
* steerOnClick (bool, default false), accentRecommended (bool, default true).
|
|
11
|
+
*/
|
|
12
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
13
|
+
import { matchesKey } from "@earendil-works/pi-tui";
|
|
14
|
+
import { existsSync, readFileSync, writeFileSync, mkdirSync } from "node:fs";
|
|
15
|
+
import { join } from "node:path";
|
|
16
|
+
|
|
17
|
+
interface NextStepsState {
|
|
18
|
+
options: string[];
|
|
19
|
+
multi: boolean;
|
|
20
|
+
rec: string;
|
|
21
|
+
risky: string;
|
|
22
|
+
subtitles: string[];
|
|
23
|
+
alternates: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface Settings {
|
|
27
|
+
markRisky: boolean;
|
|
28
|
+
carryForward: boolean;
|
|
29
|
+
steerOnClick: boolean;
|
|
30
|
+
accentRecommended: boolean;
|
|
31
|
+
rewriteProseOffers: boolean;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const SETTINGS_PATH = join(process.env.HOME || process.env.USERPROFILE || ".", ".pi", "agent", "next-steps.json");
|
|
35
|
+
|
|
36
|
+
function loadSettings(): Settings {
|
|
37
|
+
const defaults: Settings = { markRisky: false, carryForward: false, steerOnClick: false, accentRecommended: true, rewriteProseOffers: false };
|
|
38
|
+
try {
|
|
39
|
+
if (existsSync(SETTINGS_PATH)) {
|
|
40
|
+
const raw = JSON.parse(readFileSync(SETTINGS_PATH, "utf8"));
|
|
41
|
+
return { ...defaults, ...raw };
|
|
42
|
+
}
|
|
43
|
+
} catch {}
|
|
44
|
+
// write defaults
|
|
45
|
+
try {
|
|
46
|
+
mkdirSync(join(process.env.HOME || process.env.USERPROFILE || ".", ".pi", "agent"), { recursive: true });
|
|
47
|
+
writeFileSync(SETTINGS_PATH, JSON.stringify(defaults, null, 2));
|
|
48
|
+
} catch {}
|
|
49
|
+
return defaults;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export default function (pi: ExtensionAPI) {
|
|
53
|
+
const settings = loadSettings();
|
|
54
|
+
let states: NextStepsState[] = [];
|
|
55
|
+
// carry-forward queue: array of { options, rec, risky, subtitles, age, reply }, newest first
|
|
56
|
+
const queue: { options: string[]; rec: string; risky: string; subtitles: string[]; age: number; reply: number }[] = [];
|
|
57
|
+
// Counts replies that offered steps, so `/ns clear X` can target the last X posts.
|
|
58
|
+
let replyCounter = 0;
|
|
59
|
+
const keyOf = (options: string[]) => options.join("\u0000");
|
|
60
|
+
// Labels answered during their own turn; only what is left gets carried.
|
|
61
|
+
const pickedThisTurn = new Set<string>();
|
|
62
|
+
|
|
63
|
+
// Drop answered labels from a block and remap its tags so the indexes still line up.
|
|
64
|
+
function withoutPicked(st: NextStepsState) {
|
|
65
|
+
const keep: number[] = [];
|
|
66
|
+
st.options.forEach((o, i) => {
|
|
67
|
+
if (!pickedThisTurn.has(o)) keep.push(i);
|
|
68
|
+
});
|
|
69
|
+
const remap = (list: string) =>
|
|
70
|
+
list
|
|
71
|
+
.split(",")
|
|
72
|
+
.map((s) => parseInt(s.trim(), 10))
|
|
73
|
+
.filter((n) => !isNaN(n))
|
|
74
|
+
.map((n) => keep.indexOf(n - 1) + 1)
|
|
75
|
+
.filter((n) => n > 0)
|
|
76
|
+
.join(",");
|
|
77
|
+
return {
|
|
78
|
+
options: keep.map((i) => st.options[i]),
|
|
79
|
+
rec: remap(st.rec),
|
|
80
|
+
risky: remap(st.risky),
|
|
81
|
+
subtitles: keep.map((i) => st.subtitles[i] ?? ""),
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Remove picked labels from every carried block; a block with nothing left is dropped.
|
|
86
|
+
function retirePicked(picked: string[]) {
|
|
87
|
+
const set = new Set(picked);
|
|
88
|
+
for (let i = queue.length - 1; i >= 0; i--) {
|
|
89
|
+
const rest = queue[i].options.filter((o) => !set.has(o));
|
|
90
|
+
if (rest.length === 0) queue.splice(i, 1);
|
|
91
|
+
else queue[i] = { ...queue[i], options: rest };
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
pi.on("before_agent_start", async (event) => {
|
|
96
|
+
const addition = `
|
|
97
|
+
When a reply naturally ends with a choice or "say the word and I'll...", call the next_steps tool with 2-6 short option strings instead of asking in prose. Mark recommended options with rec (comma indices). Use subtitles when a label alone is ambiguous.`;
|
|
98
|
+
let sp = (event.systemPrompt ?? "") + addition;
|
|
99
|
+
if (settings.carryForward && queue.length > 0) {
|
|
100
|
+
const carried = queue
|
|
101
|
+
.map((q) => `[${q.age === 1 ? "1 reply" : `${q.age} replies`} back] ${q.options.join(" | ")}`)
|
|
102
|
+
.join("\n");
|
|
103
|
+
sp += `\n\nCarried unanswered options from earlier replies (youngest first):\n${carried}`;
|
|
104
|
+
}
|
|
105
|
+
return { systemPrompt: sp };
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
// Prose-offer parser: detect a trailing offer in the last assistant message.
|
|
109
|
+
function planOffer(text: string): string[] | null {
|
|
110
|
+
if (!text || !text.trim()) return null;
|
|
111
|
+
const TRIGGER = /(?:want me to|should i|shall i|do you want|pick one|choose one)\b/i;
|
|
112
|
+
const blocks = text.split("\n\n");
|
|
113
|
+
let last = -1;
|
|
114
|
+
for (let i = blocks.length - 1; i >= 0; i--) {
|
|
115
|
+
if (blocks[i].trim()) { last = i; break; }
|
|
116
|
+
}
|
|
117
|
+
if (last < 0) return null;
|
|
118
|
+
const lastBlock = blocks[last].trim();
|
|
119
|
+
if (!TRIGGER.test(lastBlock)) return null;
|
|
120
|
+
// extract bullets
|
|
121
|
+
const bullets: string[] = [];
|
|
122
|
+
for (const line of lastBlock.split("\n")) {
|
|
123
|
+
const m = line.match(/^[-*•]\s+(.+)$/);
|
|
124
|
+
if (m) bullets.push(m[1].trim());
|
|
125
|
+
}
|
|
126
|
+
if (bullets.length >= 2) return bullets.slice(0, 6);
|
|
127
|
+
// single sentence option
|
|
128
|
+
const sentence = lastBlock.replace(TRIGGER, "").trim();
|
|
129
|
+
if (sentence.length > 0 && sentence.length < 120) return [sentence];
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
pi.on("turn_end", async (event: any) => {
|
|
134
|
+
// prose-offer rewrite
|
|
135
|
+
if (settings.rewriteProseOffers && states.length === 0) {
|
|
136
|
+
try {
|
|
137
|
+
const msgs = event?.messages ?? [];
|
|
138
|
+
const lastAssistant = [...msgs].reverse().find((m: any) => m?.role === "assistant");
|
|
139
|
+
let text = "";
|
|
140
|
+
if (typeof lastAssistant?.content === "string") {
|
|
141
|
+
text = lastAssistant.content;
|
|
142
|
+
} else if (Array.isArray(lastAssistant?.content)) {
|
|
143
|
+
text = lastAssistant.content.map((c: any) => c?.text ?? "").join("");
|
|
144
|
+
}
|
|
145
|
+
const opts = planOffer(text);
|
|
146
|
+
if (opts && opts.length >= 2) {
|
|
147
|
+
states.push({ options: opts, multi: true, rec: "", risky: "", subtitles: [], alternates: "" });
|
|
148
|
+
}
|
|
149
|
+
} catch {
|
|
150
|
+
// ignore
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
if (states.length > 0) {
|
|
154
|
+
// age existing queue
|
|
155
|
+
for (const q of queue) q.age++;
|
|
156
|
+
replyCounter++;
|
|
157
|
+
for (const st of states) {
|
|
158
|
+
const rest = withoutPicked(st);
|
|
159
|
+
if (rest.options.length === 0) continue;
|
|
160
|
+
const key = keyOf(rest.options);
|
|
161
|
+
if (queue.some((q) => q.age === 0 && keyOf(q.options) === key)) continue;
|
|
162
|
+
queue.unshift({ ...rest, age: 0, reply: replyCounter });
|
|
163
|
+
}
|
|
164
|
+
while (queue.length > 30) queue.pop();
|
|
165
|
+
// States are per reply; the queue is the only place a block survives.
|
|
166
|
+
states = [];
|
|
167
|
+
pickedThisTurn.clear();
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
pi.registerTool({
|
|
172
|
+
name: "next_steps",
|
|
173
|
+
label: "Next Steps",
|
|
174
|
+
description:
|
|
175
|
+
"Offer selectable next-step options at the end of a reply. Call this when the user faces a choice or the reply naturally ends with 'say the word and I'll...'. Provide 2-6 short option strings.",
|
|
176
|
+
parameters: {
|
|
177
|
+
type: "object",
|
|
178
|
+
properties: {
|
|
179
|
+
options: { type: "array", items: { type: "string" }, description: "The option labels to offer." },
|
|
180
|
+
multi: { type: "boolean", description: "Allow picking multiple (default true)." },
|
|
181
|
+
rec: { type: "string", description: "Comma-separated 1-based indices to mark recommended." },
|
|
182
|
+
risky: { type: "string", description: "Comma-separated 1-based indices to mark risky." },
|
|
183
|
+
subtitles: { type: "array", items: { type: "string" }, description: "Optional dim second lines, one per option." },
|
|
184
|
+
alternates: { type: "string", description: "Groups of mutually exclusive indices, e.g. '1,3|2'." },
|
|
185
|
+
carry: { type: "boolean", description: "Record this reply's options for carry-forward (default follows setting)." },
|
|
186
|
+
},
|
|
187
|
+
required: ["options"],
|
|
188
|
+
},
|
|
189
|
+
execute: async (_toolCallId, params, _signal, _onUpdate, ctx) => {
|
|
190
|
+
const args = (params ?? {}) as any;
|
|
191
|
+
const opts = ((args.options as string[]) ?? []).map((s) => String(s).trim()).filter(Boolean);
|
|
192
|
+
if (opts.length === 0) {
|
|
193
|
+
ctx.ui.notify("next_steps: no options", "warning");
|
|
194
|
+
return { content: [{ type: "text", text: "No options provided." }] };
|
|
195
|
+
}
|
|
196
|
+
let rec = (args.rec as string) ?? "";
|
|
197
|
+
let risky = (args.risky as string) ?? "";
|
|
198
|
+
// Auto-classify when not provided (best-effort, silent on failure)
|
|
199
|
+
if (!rec && !risky && settings.markRisky && ctx?.model) {
|
|
200
|
+
try {
|
|
201
|
+
const model = ctx.model;
|
|
202
|
+
const auth = await ctx.modelRegistry.getApiKeyAndHeaders(model);
|
|
203
|
+
if (auth.ok) {
|
|
204
|
+
const context: any = {
|
|
205
|
+
systemPrompt: "You are a classifier. Reply with JSON only.",
|
|
206
|
+
messages: [
|
|
207
|
+
{
|
|
208
|
+
role: "user",
|
|
209
|
+
content: `Classify these next-step options. Return ONLY JSON: {"rec":[1-based indices of recommended options], "risky":[1-based indices of risky/damaging options]}. Mark 1-2 recommended when steps belong together, never all, never mutually exclusive pairs. Mark risky only options that could damage files, builds, or money.\nOptions:\n${opts.map((o, i) => `${i + 1}. ${o}`).join("\n")}`,
|
|
210
|
+
timestamp: Date.now(),
|
|
211
|
+
},
|
|
212
|
+
],
|
|
213
|
+
};
|
|
214
|
+
const stream = ctx.modelRegistry.streamSimple(model, context, { apiKey: auth.apiKey, headers: auth.headers, baseUrl: auth.baseUrl });
|
|
215
|
+
let msg: any = null;
|
|
216
|
+
for await (const ev of stream) {
|
|
217
|
+
if (ev.type === "done") msg = ev.message;
|
|
218
|
+
}
|
|
219
|
+
if (!msg) msg = await stream.result();
|
|
220
|
+
const text = Array.isArray(msg?.content)
|
|
221
|
+
? msg.content.map((c: any) => c?.text ?? "").join("")
|
|
222
|
+
: String(msg?.content ?? "");
|
|
223
|
+
const m = text.match(/\{[\s\S]*\}/);
|
|
224
|
+
if (m) {
|
|
225
|
+
try {
|
|
226
|
+
const j = JSON.parse(m[0]);
|
|
227
|
+
if (Array.isArray(j.rec)) rec = j.rec.join(",");
|
|
228
|
+
if (Array.isArray(j.risky)) risky = j.risky.join(",");
|
|
229
|
+
} catch {
|
|
230
|
+
// ignore parse errors
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
} catch {
|
|
235
|
+
// classification best-effort
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
const alternates = (args.alternates as string) ?? "";
|
|
239
|
+
const newState: NextStepsState = {
|
|
240
|
+
options: opts,
|
|
241
|
+
multi: args.multi !== false,
|
|
242
|
+
rec,
|
|
243
|
+
risky,
|
|
244
|
+
subtitles: (args.subtitles as string[]) ?? [],
|
|
245
|
+
alternates,
|
|
246
|
+
};
|
|
247
|
+
states.push(newState);
|
|
248
|
+
if (args.carry === true) settings.carryForward = true;
|
|
249
|
+
const recSet = new Set((states[0].rec || "").split(",").map((s) => s.trim()));
|
|
250
|
+
const riskySet = new Set((states[0].risky || "").split(",").map((s) => s.trim()));
|
|
251
|
+
const lines = newState.options.map((o, i) => {
|
|
252
|
+
const n = i + 1;
|
|
253
|
+
const tags = [
|
|
254
|
+
settings.accentRecommended && recSet.has(String(n)) ? "★" : "",
|
|
255
|
+
settings.markRisky && riskySet.has(String(n)) ? "▲" : "",
|
|
256
|
+
].filter(Boolean).join(" ");
|
|
257
|
+
const sub = newState.subtitles[i] ? ` — ${newState.subtitles[i]}` : "";
|
|
258
|
+
const tagPrefix = tags ? `${tags} ` : "";
|
|
259
|
+
return `${n}. ${tagPrefix}${o}${sub}`;
|
|
260
|
+
});
|
|
261
|
+
// Render an interactive choice right away instead of forcing /ns.
|
|
262
|
+
const choiceLabels = newState.options.map((o, i) => {
|
|
263
|
+
const n = i + 1;
|
|
264
|
+
const recTag = settings.accentRecommended && recSet.has(String(n)) ? " ★ RECOMMENDED" : "";
|
|
265
|
+
const riskyTag = settings.markRisky && riskySet.has(String(n)) ? " ▲ RISKY" : "";
|
|
266
|
+
const sub = newState.subtitles[i] ? ` — ${newState.subtitles[i]}` : "";
|
|
267
|
+
return `${o}${sub}${recTag}${riskyTag}`;
|
|
268
|
+
});
|
|
269
|
+
try {
|
|
270
|
+
const selected = new Set<number>();
|
|
271
|
+
const result = await ctx.ui.custom<number[] | null>((tui, theme, _kb, done) => {
|
|
272
|
+
let cursor = 0;
|
|
273
|
+
const component = {
|
|
274
|
+
focused: true,
|
|
275
|
+
render(_width: number): string[] {
|
|
276
|
+
const lines: string[] = [];
|
|
277
|
+
lines.push(theme.fg("accent", "Next steps (space toggle, enter confirm):"));
|
|
278
|
+
for (let i = 0; i < choiceLabels.length; i++) {
|
|
279
|
+
const check = selected.has(i) ? "[x]" : "[ ]";
|
|
280
|
+
const prefix = i === cursor ? theme.fg("accent", "> ") : " ";
|
|
281
|
+
lines.push(`${prefix}${check} ${choiceLabels[i]}`);
|
|
282
|
+
}
|
|
283
|
+
lines.push(theme.fg("dim", "space toggle · ↑↓ move · enter/tab confirm · esc cancel"));
|
|
284
|
+
return lines;
|
|
285
|
+
},
|
|
286
|
+
invalidate() {},
|
|
287
|
+
handleInput(data: string) {
|
|
288
|
+
if (matchesKey(data, "up") || matchesKey(data, "k")) {
|
|
289
|
+
cursor = (cursor - 1 + choiceLabels.length) % choiceLabels.length;
|
|
290
|
+
tui.requestRender();
|
|
291
|
+
} else if (matchesKey(data, "down") || matchesKey(data, "j")) {
|
|
292
|
+
cursor = (cursor + 1) % choiceLabels.length;
|
|
293
|
+
tui.requestRender();
|
|
294
|
+
} else if (matchesKey(data, "space")) {
|
|
295
|
+
if (selected.has(cursor)) selected.delete(cursor);
|
|
296
|
+
else selected.add(cursor);
|
|
297
|
+
tui.requestRender();
|
|
298
|
+
} else if (matchesKey(data, "enter") || matchesKey(data, "tab")) {
|
|
299
|
+
done(Array.from(selected).sort((a, b) => a - b));
|
|
300
|
+
} else if (matchesKey(data, "escape") || matchesKey(data, "ctrl+c")) {
|
|
301
|
+
done(null);
|
|
302
|
+
}
|
|
303
|
+
},
|
|
304
|
+
};
|
|
305
|
+
return component;
|
|
306
|
+
});
|
|
307
|
+
if (result && result.length > 0) {
|
|
308
|
+
const chosen = result.map((n) => newState.options[n]);
|
|
309
|
+
const message = chosen.length === 1 ? chosen[0] : chosen.map((c) => `- ${c}`).join("\n");
|
|
310
|
+
if (ctx.isIdle()) {
|
|
311
|
+
pi.sendUserMessage(message);
|
|
312
|
+
} else if (settings.steerOnClick) {
|
|
313
|
+
pi.sendUserMessage(message, { deliverAs: "steer" });
|
|
314
|
+
} else {
|
|
315
|
+
pi.sendUserMessage(message, { deliverAs: "followUp" });
|
|
316
|
+
}
|
|
317
|
+
for (const c of chosen) pickedThisTurn.add(c);
|
|
318
|
+
retirePicked(chosen);
|
|
319
|
+
ctx.ui.notify(`Sent ${chosen.length} step(s)`, "info");
|
|
320
|
+
} else if (result !== null) {
|
|
321
|
+
// empty selection (enter with nothing toggled) — send nothing
|
|
322
|
+
ctx.ui.notify("No selection", "info");
|
|
323
|
+
}
|
|
324
|
+
} catch {
|
|
325
|
+
// Non-interactive mode or UI unavailable; fall back to /ns.
|
|
326
|
+
}
|
|
327
|
+
ctx.ui.notify(`Next steps registered.`, "info");
|
|
328
|
+
return {
|
|
329
|
+
content: [{ type: "text", text: `Registered ${opts.length} next steps:\n${lines.join("\n")}` }],
|
|
330
|
+
};
|
|
331
|
+
},
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
async function pickAndSend(ctx: any) {
|
|
335
|
+
if (queue.length === 0) {
|
|
336
|
+
ctx.ui.notify("No next steps registered. Ask the agent to call next_steps.", "warning");
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
// One tab per collected block, newest first. Carried blocks keep their real age.
|
|
340
|
+
const blocks = queue.map((q) => {
|
|
341
|
+
const recSet = new Set((q.rec || "").split(",").map((s) => s.trim()));
|
|
342
|
+
const riskySet = new Set((q.risky || "").split(",").map((s) => s.trim()));
|
|
343
|
+
return {
|
|
344
|
+
age: q.age,
|
|
345
|
+
items: q.options.map((o, i) => {
|
|
346
|
+
const tags = [
|
|
347
|
+
settings.accentRecommended && recSet.has(String(i + 1)) ? "★" : "",
|
|
348
|
+
settings.markRisky && riskySet.has(String(i + 1)) ? "▲" : "",
|
|
349
|
+
].filter(Boolean).join(" ");
|
|
350
|
+
return { option: o, text: `${tags ? tags + " " : ""}${o}` };
|
|
351
|
+
}),
|
|
352
|
+
};
|
|
353
|
+
});
|
|
354
|
+
const tabLabel = (i: number) =>
|
|
355
|
+
i === 0 ? "this reply" : blocks[i].age === 1 ? "1 reply back" : `${blocks[i].age} replies back`;
|
|
356
|
+
let chosen: string[] | null = null;
|
|
357
|
+
try {
|
|
358
|
+
chosen = await ctx.ui.custom<string[] | null>((tui, theme, _kb, done) => {
|
|
359
|
+
let tab = 0;
|
|
360
|
+
let cursor = 0;
|
|
361
|
+
const picked = new Set<string>();
|
|
362
|
+
const component = {
|
|
363
|
+
focused: true,
|
|
364
|
+
render(_width: number): string[] {
|
|
365
|
+
const out: string[] = [];
|
|
366
|
+
const head = blocks
|
|
367
|
+
.map((_, i) =>
|
|
368
|
+
i === tab ? theme.fg("accent", `[${tabLabel(i)}]`) : theme.fg("dim", ` ${tabLabel(i)} `),
|
|
369
|
+
)
|
|
370
|
+
.join(" · ");
|
|
371
|
+
out.push(`${theme.fg("accent", "Next steps")} ${head}`);
|
|
372
|
+
blocks[tab].items.forEach((item, i) => {
|
|
373
|
+
const mark = picked.has(`${tab}:${i}`) ? "[x]" : "[ ]";
|
|
374
|
+
const prefix = i === cursor ? theme.fg("accent", "> ") : " ";
|
|
375
|
+
out.push(`${prefix}${mark} ${item.text}`);
|
|
376
|
+
});
|
|
377
|
+
out.push(theme.fg("dim", "space toggle · ↑↓ move · ←→ block · enter/tab confirm · esc cancel"));
|
|
378
|
+
return out;
|
|
379
|
+
},
|
|
380
|
+
invalidate() {},
|
|
381
|
+
handleInput(data: string) {
|
|
382
|
+
const n = blocks[tab].items.length;
|
|
383
|
+
if (matchesKey(data, "up") || matchesKey(data, "k")) {
|
|
384
|
+
cursor = (cursor - 1 + n) % n;
|
|
385
|
+
} else if (matchesKey(data, "down") || matchesKey(data, "j")) {
|
|
386
|
+
cursor = (cursor + 1) % n;
|
|
387
|
+
} else if (matchesKey(data, "left") || matchesKey(data, "h")) {
|
|
388
|
+
tab = (tab - 1 + blocks.length) % blocks.length;
|
|
389
|
+
cursor = 0;
|
|
390
|
+
} else if (matchesKey(data, "right") || matchesKey(data, "l")) {
|
|
391
|
+
tab = (tab + 1) % blocks.length;
|
|
392
|
+
cursor = 0;
|
|
393
|
+
} else if (matchesKey(data, "space")) {
|
|
394
|
+
const k = `${tab}:${cursor}`;
|
|
395
|
+
if (picked.has(k)) picked.delete(k);
|
|
396
|
+
else picked.add(k);
|
|
397
|
+
} else if (matchesKey(data, "enter") || matchesKey(data, "tab")) {
|
|
398
|
+
done(
|
|
399
|
+
Array.from(picked).map((k) => {
|
|
400
|
+
const [b, i] = k.split(":").map(Number);
|
|
401
|
+
return blocks[b].items[i].option;
|
|
402
|
+
}),
|
|
403
|
+
);
|
|
404
|
+
return;
|
|
405
|
+
} else if (matchesKey(data, "escape") || matchesKey(data, "ctrl+c")) {
|
|
406
|
+
done(null);
|
|
407
|
+
return;
|
|
408
|
+
}
|
|
409
|
+
tui.requestRender();
|
|
410
|
+
},
|
|
411
|
+
};
|
|
412
|
+
return component;
|
|
413
|
+
});
|
|
414
|
+
} catch {
|
|
415
|
+
ctx.ui.notify("Selection UI unavailable in this session.", "warning");
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
if (!chosen || chosen.length === 0) {
|
|
419
|
+
ctx.ui.notify("No selection", "info");
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
// Every picked step travels as one user message, never one message per step.
|
|
423
|
+
const message = chosen.length === 1 ? chosen[0] : chosen.map((c) => `- ${c}`).join("\n");
|
|
424
|
+
if (ctx.isIdle()) {
|
|
425
|
+
pi.sendUserMessage(message);
|
|
426
|
+
} else if (settings.steerOnClick) {
|
|
427
|
+
pi.sendUserMessage(message, { deliverAs: "steer" });
|
|
428
|
+
} else {
|
|
429
|
+
pi.sendUserMessage(message, { deliverAs: "followUp" });
|
|
430
|
+
}
|
|
431
|
+
retirePicked(chosen);
|
|
432
|
+
ctx.ui.notify(`Sent ${chosen.length} step(s)`, "info");
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
// `/ns clear` drops everything older than the newest reply; `/ns clear X` drops the last X posts.
|
|
436
|
+
async function clearSteps(arg: string, ctx: any) {
|
|
437
|
+
const trimmed = arg.trim();
|
|
438
|
+
if (queue.length === 0) {
|
|
439
|
+
ctx.ui.notify("No collected next steps to clear.", "info");
|
|
440
|
+
return;
|
|
441
|
+
}
|
|
442
|
+
if (/^clear$/i.test(trimmed)) {
|
|
443
|
+
const before = queue.length;
|
|
444
|
+
const newest = queue[0].reply;
|
|
445
|
+
for (let i = queue.length - 1; i >= 0; i--) {
|
|
446
|
+
if (queue[i].reply < newest) queue.splice(i, 1);
|
|
447
|
+
}
|
|
448
|
+
const dropped = before - queue.length;
|
|
449
|
+
ctx.ui.notify(
|
|
450
|
+
dropped > 0
|
|
451
|
+
? `Cleared ${dropped} stale step(s). Kept the newest reply.`
|
|
452
|
+
: "Nothing stale to clear. Use /ns clear X for the last X posts.",
|
|
453
|
+
"info",
|
|
454
|
+
);
|
|
455
|
+
return;
|
|
456
|
+
}
|
|
457
|
+
const m = trimmed.match(/^clear\s+(\d+)$/i);
|
|
458
|
+
if (m) {
|
|
459
|
+
const n = parseInt(m[1], 10);
|
|
460
|
+
if (n < 1) {
|
|
461
|
+
ctx.ui.notify("Usage: /ns clear [X]", "warning");
|
|
462
|
+
return;
|
|
463
|
+
}
|
|
464
|
+
const cutoff = replyCounter - n + 1;
|
|
465
|
+
const before = queue.length;
|
|
466
|
+
for (let i = queue.length - 1; i >= 0; i--) {
|
|
467
|
+
if (queue[i].reply >= cutoff) queue.splice(i, 1);
|
|
468
|
+
}
|
|
469
|
+
const dropped = before - queue.length;
|
|
470
|
+
ctx.ui.notify(
|
|
471
|
+
dropped > 0
|
|
472
|
+
? `Cleared ${dropped} step(s) from the last ${n} post(s).`
|
|
473
|
+
: `No collected steps in the last ${n} post(s).`,
|
|
474
|
+
"info",
|
|
475
|
+
);
|
|
476
|
+
return;
|
|
477
|
+
}
|
|
478
|
+
ctx.ui.notify("Usage: /ns clear (stale) or /ns clear X (last X posts)", "warning");
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
const runOrClear = async (args: string, ctx: any) => {
|
|
482
|
+
const a = (args ?? "").trim();
|
|
483
|
+
if (!a) return pickAndSend(ctx);
|
|
484
|
+
if (/^clear\b/i.test(a) || /^clear$/i.test(a)) return clearSteps(a, ctx);
|
|
485
|
+
ctx.ui.notify("Usage: /ns or /ns clear [X]", "warning");
|
|
486
|
+
};
|
|
487
|
+
|
|
488
|
+
pi.registerCommand("ns", {
|
|
489
|
+
description: "Pick and send a registered next step, or /ns clear [X] to drop collected steps.",
|
|
490
|
+
handler: async (args, ctx) => runOrClear(args, ctx),
|
|
491
|
+
});
|
|
492
|
+
pi.registerCommand("nextsteps", {
|
|
493
|
+
description: "Pick and send a registered next step, or /nextsteps clear [X] to drop collected steps.",
|
|
494
|
+
handler: async (args, ctx) => runOrClear(args, ctx),
|
|
495
|
+
});
|
|
496
|
+
pi.registerCommand("nextsteps-settings", {
|
|
497
|
+
description: "Show next-steps settings path.",
|
|
498
|
+
handler: async (_args, ctx) => {
|
|
499
|
+
ctx.ui.notify(`Settings: ${SETTINGS_PATH}`, "info");
|
|
500
|
+
},
|
|
501
|
+
});
|
|
502
|
+
}
|
package/package.json
CHANGED
|
@@ -1,16 +1,22 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "pi-next-steps",
|
|
3
|
-
"version": "1.1.
|
|
4
|
-
"description": "Next Steps extension for the Pi coding agent",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"main": "next-steps.ts",
|
|
7
|
-
"pi": {
|
|
8
|
-
"extensions": [
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "pi-next-steps",
|
|
3
|
+
"version": "1.1.6",
|
|
4
|
+
"description": "Next Steps extension for the Pi coding agent",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "next-steps.ts",
|
|
7
|
+
"pi": {
|
|
8
|
+
"extensions": [
|
|
9
|
+
"./next-steps.ts"
|
|
10
|
+
]
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"pi",
|
|
14
|
+
"pi-extension",
|
|
15
|
+
"next-steps"
|
|
16
|
+
],
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "https://github.com/apoapostolov/pi-next-steps.git"
|
|
21
|
+
}
|
|
22
|
+
}
|