pi-next-steps 1.1.1 → 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 +19 -16
- package/README.md +80 -73
- package/next-steps.ts +280 -82
- package/package.json +22 -16
package/CHANGELOG.md
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
|
|
3
|
-
## 1.1.
|
|
4
|
-
|
|
5
|
-
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
- `
|
|
12
|
-
|
|
13
|
-
-
|
|
14
|
-
|
|
15
|
-
-
|
|
16
|
-
-
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
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
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
* steerOnClick (bool, default false), accentRecommended (bool, default true).
|
|
11
11
|
*/
|
|
12
12
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
13
|
+
import { matchesKey } from "@earendil-works/pi-tui";
|
|
13
14
|
import { existsSync, readFileSync, writeFileSync, mkdirSync } from "node:fs";
|
|
14
15
|
import { join } from "node:path";
|
|
15
16
|
|
|
@@ -50,9 +51,46 @@ function loadSettings(): Settings {
|
|
|
50
51
|
|
|
51
52
|
export default function (pi: ExtensionAPI) {
|
|
52
53
|
const settings = loadSettings();
|
|
53
|
-
let
|
|
54
|
-
// carry-forward queue: array of { options, rec, risky, subtitles, age }
|
|
55
|
-
const queue: { options: string[]; rec: string; risky: string; subtitles: string[]; age: number }[] = [];
|
|
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
|
+
}
|
|
56
94
|
|
|
57
95
|
pi.on("before_agent_start", async (event) => {
|
|
58
96
|
const addition = `
|
|
@@ -60,9 +98,7 @@ When a reply naturally ends with a choice or "say the word and I'll...", call th
|
|
|
60
98
|
let sp = (event.systemPrompt ?? "") + addition;
|
|
61
99
|
if (settings.carryForward && queue.length > 0) {
|
|
62
100
|
const carried = queue
|
|
63
|
-
.
|
|
64
|
-
.reverse()
|
|
65
|
-
.map((q, i) => `[${i + 1} reply back] ${q.options.join(" | ")}`)
|
|
101
|
+
.map((q) => `[${q.age === 1 ? "1 reply" : `${q.age} replies`} back] ${q.options.join(" | ")}`)
|
|
66
102
|
.join("\n");
|
|
67
103
|
sp += `\n\nCarried unanswered options from earlier replies (youngest first):\n${carried}`;
|
|
68
104
|
}
|
|
@@ -96,30 +132,39 @@ When a reply naturally ends with a choice or "say the word and I'll...", call th
|
|
|
96
132
|
|
|
97
133
|
pi.on("turn_end", async (event: any) => {
|
|
98
134
|
// prose-offer rewrite
|
|
99
|
-
if (settings.rewriteProseOffers &&
|
|
135
|
+
if (settings.rewriteProseOffers && states.length === 0) {
|
|
100
136
|
try {
|
|
101
137
|
const msgs = event?.messages ?? [];
|
|
102
138
|
const lastAssistant = [...msgs].reverse().find((m: any) => m?.role === "assistant");
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
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
|
+
}
|
|
108
145
|
const opts = planOffer(text);
|
|
109
146
|
if (opts && opts.length >= 2) {
|
|
110
|
-
|
|
147
|
+
states.push({ options: opts, multi: true, rec: "", risky: "", subtitles: [], alternates: "" });
|
|
111
148
|
}
|
|
112
149
|
} catch {
|
|
113
150
|
// ignore
|
|
114
151
|
}
|
|
115
152
|
}
|
|
116
|
-
if (
|
|
153
|
+
if (states.length > 0) {
|
|
117
154
|
// age existing queue
|
|
118
155
|
for (const q of queue) q.age++;
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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();
|
|
123
168
|
}
|
|
124
169
|
});
|
|
125
170
|
|
|
@@ -191,7 +236,7 @@ When a reply naturally ends with a choice or "say the word and I'll...", call th
|
|
|
191
236
|
}
|
|
192
237
|
}
|
|
193
238
|
const alternates = (args.alternates as string) ?? "";
|
|
194
|
-
|
|
239
|
+
const newState: NextStepsState = {
|
|
195
240
|
options: opts,
|
|
196
241
|
multi: args.multi !== false,
|
|
197
242
|
rec,
|
|
@@ -199,81 +244,182 @@ When a reply naturally ends with a choice or "say the word and I'll...", call th
|
|
|
199
244
|
subtitles: (args.subtitles as string[]) ?? [],
|
|
200
245
|
alternates,
|
|
201
246
|
};
|
|
247
|
+
states.push(newState);
|
|
202
248
|
if (args.carry === true) settings.carryForward = true;
|
|
203
|
-
const recSet = new Set((
|
|
204
|
-
const riskySet = new Set((
|
|
205
|
-
const lines =
|
|
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) => {
|
|
206
252
|
const n = i + 1;
|
|
207
253
|
const tags = [
|
|
208
254
|
settings.accentRecommended && recSet.has(String(n)) ? "★" : "",
|
|
209
|
-
settings.markRisky && riskySet.has(String(n)) ? "
|
|
255
|
+
settings.markRisky && riskySet.has(String(n)) ? "▲" : "",
|
|
210
256
|
].filter(Boolean).join(" ");
|
|
211
|
-
const sub =
|
|
212
|
-
|
|
257
|
+
const sub = newState.subtitles[i] ? ` — ${newState.subtitles[i]}` : "";
|
|
258
|
+
const tagPrefix = tags ? `${tags} ` : "";
|
|
259
|
+
return `${n}. ${tagPrefix}${o}${sub}`;
|
|
213
260
|
});
|
|
214
|
-
|
|
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");
|
|
215
328
|
return {
|
|
216
|
-
content: [{ type: "text", text: `Registered ${opts.length} next steps:\n${lines.join("\n")}
|
|
329
|
+
content: [{ type: "text", text: `Registered ${opts.length} next steps:\n${lines.join("\n")}` }],
|
|
217
330
|
};
|
|
218
331
|
},
|
|
219
332
|
});
|
|
220
333
|
|
|
221
334
|
async function pickAndSend(ctx: any) {
|
|
222
|
-
if (
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
const q = queue[0];
|
|
226
|
-
state = { options: q.options, multi: true, rec: q.rec, risky: q.risky, subtitles: q.subtitles, alternates: "" };
|
|
227
|
-
} else {
|
|
228
|
-
ctx.ui.notify("No next steps registered. Ask the agent to call next_steps.", "warning");
|
|
229
|
-
return;
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
const opts = state.options;
|
|
233
|
-
const recSet = new Set((state.rec || "").split(",").map((s) => s.trim()));
|
|
234
|
-
const riskySet = new Set((state.risky || "").split(",").map((s) => s.trim()));
|
|
235
|
-
// parse alternate groups
|
|
236
|
-
const altGroups: number[][] = [];
|
|
237
|
-
if (state.alternates) {
|
|
238
|
-
for (const g of state.alternates.split("|")) {
|
|
239
|
-
const members = g.split(",").map((s) => parseInt(s.trim(), 10)).filter((n) => !isNaN(n) && n >= 1 && n <= opts.length);
|
|
240
|
-
if (members.length >= 2) altGroups.push(members);
|
|
241
|
-
}
|
|
335
|
+
if (queue.length === 0) {
|
|
336
|
+
ctx.ui.notify("No next steps registered. Ask the agent to call next_steps.", "warning");
|
|
337
|
+
return;
|
|
242
338
|
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
const
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
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
|
+
};
|
|
250
353
|
});
|
|
251
|
-
const
|
|
252
|
-
"
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
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");
|
|
257
416
|
return;
|
|
258
417
|
}
|
|
259
|
-
|
|
260
|
-
.
|
|
261
|
-
.map((s) => parseInt(s.trim(), 10))
|
|
262
|
-
.filter((n) => !isNaN(n) && n >= 1 && n <= opts.length);
|
|
263
|
-
// enforce alternate groups
|
|
264
|
-
for (const g of altGroups) {
|
|
265
|
-
const picked = indices.filter((n) => g.includes(n));
|
|
266
|
-
if (picked.length > 1) {
|
|
267
|
-
// keep the first
|
|
268
|
-
const first = picked[0];
|
|
269
|
-
indices = indices.filter((n) => !g.includes(n) || n === first);
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
if (indices.length === 0) {
|
|
273
|
-
ctx.ui.notify("No valid selection", "warning");
|
|
418
|
+
if (!chosen || chosen.length === 0) {
|
|
419
|
+
ctx.ui.notify("No selection", "info");
|
|
274
420
|
return;
|
|
275
421
|
}
|
|
276
|
-
|
|
422
|
+
// Every picked step travels as one user message, never one message per step.
|
|
277
423
|
const message = chosen.length === 1 ? chosen[0] : chosen.map((c) => `- ${c}`).join("\n");
|
|
278
424
|
if (ctx.isIdle()) {
|
|
279
425
|
pi.sendUserMessage(message);
|
|
@@ -282,18 +428,70 @@ When a reply naturally ends with a choice or "say the word and I'll...", call th
|
|
|
282
428
|
} else {
|
|
283
429
|
pi.sendUserMessage(message, { deliverAs: "followUp" });
|
|
284
430
|
}
|
|
285
|
-
|
|
286
|
-
if (queue.length > 0) queue.shift();
|
|
431
|
+
retirePicked(chosen);
|
|
287
432
|
ctx.ui.notify(`Sent ${chosen.length} step(s)`, "info");
|
|
288
433
|
}
|
|
289
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
|
+
|
|
290
488
|
pi.registerCommand("ns", {
|
|
291
|
-
description: "Pick and send a registered next step
|
|
292
|
-
handler: async (
|
|
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),
|
|
293
491
|
});
|
|
294
492
|
pi.registerCommand("nextsteps", {
|
|
295
|
-
description: "Pick and send a registered next step
|
|
296
|
-
handler: async (
|
|
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),
|
|
297
495
|
});
|
|
298
496
|
pi.registerCommand("nextsteps-settings", {
|
|
299
497
|
description: "Show next-steps settings path.",
|
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
|
+
}
|