pi-next-steps 1.1.5 → 1.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/CHANGELOG.md +23 -9
- package/README.md +82 -73
- package/next-steps.ts +296 -83
- package/package.json +22 -16
package/CHANGELOG.md
CHANGED
|
@@ -1,9 +1,23 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
|
|
3
|
-
## 1.
|
|
4
|
-
|
|
5
|
-
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
-
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 1.2.0 - 2026-11-18
|
|
4
|
+
|
|
5
|
+
- `/ns` can delete stale carried steps without leaving the picker. Ctrl+D on a stale row arms it in red, and a second Ctrl+D deletes it. Shift+Ctrl+D arms every stale row in red, and a second Shift+Ctrl+D deletes all of them. The current reply's rows stay untouched.
|
|
6
|
+
|
|
7
|
+
## 1.1.6 - 2026-11-18
|
|
8
|
+
|
|
9
|
+
- Multiple blocks per reply: every `next_steps` call keeps its own options, so
|
|
10
|
+
one reply can offer several separate choices.
|
|
11
|
+
- Carry-forward works. States are per reply and always cleared, so a block is
|
|
12
|
+
queued once instead of being re-queued on every later turn.
|
|
13
|
+
- Carried entries show their real age (`1 reply back`, `2 replies back`) and
|
|
14
|
+
the list is youngest first.
|
|
15
|
+
- `/ns` opens a tabbed picker over every collected block, newest reply first.
|
|
16
|
+
Space toggles, arrows move and switch block, enter sends.
|
|
17
|
+
- Picked steps retire individually: a block answered during its own reply is
|
|
18
|
+
never carried afterwards, and untouched siblings survive.
|
|
19
|
+
- `/ns clear` drops stale steps from older replies and keeps the last prompt's.
|
|
20
|
+
- `/ns clear X` drops the steps collected in the last X posts.
|
|
21
|
+
- Every selection travels as one user message.
|
|
22
|
+
|
|
23
|
+
## 1.1.5 - 2026-11-16
|
package/README.md
CHANGED
|
@@ -1,73 +1,82 @@
|
|
|
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
|
+
Stale carried steps can be pruned from the picker. On an older tab, Ctrl+D turns the focused row red, then Ctrl+D again deletes it. Shift+Ctrl+D turns every stale row red, and a second Shift+Ctrl+D deletes all of them. The current reply's rows cannot be deleted this way. `/ns clear` remains the coarse option when you want whole older replies gone at once.
|
|
40
|
+
|
|
41
|
+
Clear what you no longer want:
|
|
42
|
+
|
|
43
|
+
```
|
|
44
|
+
/ns clear # drop stale steps from older replies, keep the last prompt's
|
|
45
|
+
/ns clear 2 # drop the steps collected in the last 2 posts
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Alias: `/nextsteps`.
|
|
49
|
+
|
|
50
|
+
## Tool parameters
|
|
51
|
+
|
|
52
|
+
| Parameter | Type | Description |
|
|
53
|
+
|---|---|---|
|
|
54
|
+
| `options` | `string[]` | The option labels to offer (2-6 recommended). |
|
|
55
|
+
| `multi` | `boolean` | Allow picking multiple (default `true`). |
|
|
56
|
+
| `rec` | `string` | Comma-separated 1-based indices to mark recommended. |
|
|
57
|
+
| `risky` | `string` | Comma-separated 1-based indices to mark risky. |
|
|
58
|
+
| `subtitles` | `string[]` | Optional dim second lines, one per option. |
|
|
59
|
+
|
|
60
|
+
## Example directive (no tool calling)
|
|
61
|
+
|
|
62
|
+
When tool calling is unavailable, the same row can be expressed as a directive:
|
|
63
|
+
|
|
64
|
+
```
|
|
65
|
+
::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"}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Requirements
|
|
69
|
+
|
|
70
|
+
- Pi 1.5+
|
|
71
|
+
- A Nerd Font (for the `★`/`⚠` glyphs) is recommended but not required.
|
|
72
|
+
|
|
73
|
+
## Limits
|
|
74
|
+
|
|
75
|
+
- A step is a sentence. A vague option sends a vague request; the plugin does not rewrite what the agent wrote.
|
|
76
|
+
- Ticks are per block. Two blocks in one reply keep separate picks.
|
|
77
|
+
- The RISKY pill is an opinion from a classifier reading labels and context, not a reading of your repository.
|
|
78
|
+
- Auto-classification is best-effort and may fail on providers that require extra headers (e.g. opencode-go).
|
|
79
|
+
|
|
80
|
+
## License
|
|
81
|
+
|
|
82
|
+
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
|
@@ -23,6 +23,15 @@ interface NextStepsState {
|
|
|
23
23
|
alternates: string;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
interface QueueEntry {
|
|
27
|
+
options: string[];
|
|
28
|
+
rec: string;
|
|
29
|
+
risky: string;
|
|
30
|
+
subtitles: string[];
|
|
31
|
+
age: number;
|
|
32
|
+
reply: number;
|
|
33
|
+
}
|
|
34
|
+
|
|
26
35
|
interface Settings {
|
|
27
36
|
markRisky: boolean;
|
|
28
37
|
carryForward: boolean;
|
|
@@ -51,9 +60,61 @@ function loadSettings(): Settings {
|
|
|
51
60
|
|
|
52
61
|
export default function (pi: ExtensionAPI) {
|
|
53
62
|
const settings = loadSettings();
|
|
54
|
-
let
|
|
55
|
-
// carry-forward queue
|
|
56
|
-
const queue:
|
|
63
|
+
let states: NextStepsState[] = [];
|
|
64
|
+
// carry-forward queue, newest first
|
|
65
|
+
const queue: QueueEntry[] = [];
|
|
66
|
+
// Counts replies that offered steps, so `/ns clear X` can target the last X posts.
|
|
67
|
+
let replyCounter = 0;
|
|
68
|
+
const keyOf = (options: string[]) => options.join("\u0000");
|
|
69
|
+
// Labels answered during their own turn; only what is left gets carried.
|
|
70
|
+
const pickedThisTurn = new Set<string>();
|
|
71
|
+
|
|
72
|
+
// Drop answered labels from a block and remap its tags so the indexes still line up.
|
|
73
|
+
function withoutPicked(st: NextStepsState) {
|
|
74
|
+
const keep: number[] = [];
|
|
75
|
+
st.options.forEach((o, i) => {
|
|
76
|
+
if (!pickedThisTurn.has(o)) keep.push(i);
|
|
77
|
+
});
|
|
78
|
+
const remap = (list: string) =>
|
|
79
|
+
list
|
|
80
|
+
.split(",")
|
|
81
|
+
.map((s) => parseInt(s.trim(), 10))
|
|
82
|
+
.filter((n) => !isNaN(n))
|
|
83
|
+
.map((n) => keep.indexOf(n - 1) + 1)
|
|
84
|
+
.filter((n) => n > 0)
|
|
85
|
+
.join(",");
|
|
86
|
+
return {
|
|
87
|
+
options: keep.map((i) => st.options[i]),
|
|
88
|
+
rec: remap(st.rec),
|
|
89
|
+
risky: remap(st.risky),
|
|
90
|
+
subtitles: keep.map((i) => st.subtitles[i] ?? ""),
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Remove one carried option and keep its recommendation, risk and subtitle indexes aligned.
|
|
95
|
+
function dropOption(q: QueueEntry, index: number) {
|
|
96
|
+
q.options.splice(index, 1);
|
|
97
|
+
q.subtitles.splice(index, 1);
|
|
98
|
+
const remap = (list: string) =>
|
|
99
|
+
list
|
|
100
|
+
.split(",")
|
|
101
|
+
.map((s) => parseInt(s.trim(), 10))
|
|
102
|
+
.filter((n) => !isNaN(n) && n !== index + 1)
|
|
103
|
+
.map((n) => (n > index + 1 ? n - 1 : n))
|
|
104
|
+
.join(",");
|
|
105
|
+
q.rec = remap(q.rec);
|
|
106
|
+
q.risky = remap(q.risky);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Remove picked labels from every carried block; a block with nothing left is dropped.
|
|
110
|
+
function retirePicked(picked: string[]) {
|
|
111
|
+
const set = new Set(picked);
|
|
112
|
+
for (let i = queue.length - 1; i >= 0; i--) {
|
|
113
|
+
const rest = queue[i].options.filter((o) => !set.has(o));
|
|
114
|
+
if (rest.length === 0) queue.splice(i, 1);
|
|
115
|
+
else queue[i] = { ...queue[i], options: rest };
|
|
116
|
+
}
|
|
117
|
+
}
|
|
57
118
|
|
|
58
119
|
pi.on("before_agent_start", async (event) => {
|
|
59
120
|
const addition = `
|
|
@@ -61,9 +122,7 @@ When a reply naturally ends with a choice or "say the word and I'll...", call th
|
|
|
61
122
|
let sp = (event.systemPrompt ?? "") + addition;
|
|
62
123
|
if (settings.carryForward && queue.length > 0) {
|
|
63
124
|
const carried = queue
|
|
64
|
-
.
|
|
65
|
-
.reverse()
|
|
66
|
-
.map((q, i) => `[${i + 1} reply back] ${q.options.join(" | ")}`)
|
|
125
|
+
.map((q) => `[${q.age === 1 ? "1 reply" : `${q.age} replies`} back] ${q.options.join(" | ")}`)
|
|
67
126
|
.join("\n");
|
|
68
127
|
sp += `\n\nCarried unanswered options from earlier replies (youngest first):\n${carried}`;
|
|
69
128
|
}
|
|
@@ -97,30 +156,39 @@ When a reply naturally ends with a choice or "say the word and I'll...", call th
|
|
|
97
156
|
|
|
98
157
|
pi.on("turn_end", async (event: any) => {
|
|
99
158
|
// prose-offer rewrite
|
|
100
|
-
if (settings.rewriteProseOffers &&
|
|
159
|
+
if (settings.rewriteProseOffers && states.length === 0) {
|
|
101
160
|
try {
|
|
102
161
|
const msgs = event?.messages ?? [];
|
|
103
162
|
const lastAssistant = [...msgs].reverse().find((m: any) => m?.role === "assistant");
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
163
|
+
let text = "";
|
|
164
|
+
if (typeof lastAssistant?.content === "string") {
|
|
165
|
+
text = lastAssistant.content;
|
|
166
|
+
} else if (Array.isArray(lastAssistant?.content)) {
|
|
167
|
+
text = lastAssistant.content.map((c: any) => c?.text ?? "").join("");
|
|
168
|
+
}
|
|
109
169
|
const opts = planOffer(text);
|
|
110
170
|
if (opts && opts.length >= 2) {
|
|
111
|
-
|
|
171
|
+
states.push({ options: opts, multi: true, rec: "", risky: "", subtitles: [], alternates: "" });
|
|
112
172
|
}
|
|
113
173
|
} catch {
|
|
114
174
|
// ignore
|
|
115
175
|
}
|
|
116
176
|
}
|
|
117
|
-
if (
|
|
177
|
+
if (states.length > 0) {
|
|
118
178
|
// age existing queue
|
|
119
179
|
for (const q of queue) q.age++;
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
180
|
+
replyCounter++;
|
|
181
|
+
for (const st of states) {
|
|
182
|
+
const rest = withoutPicked(st);
|
|
183
|
+
if (rest.options.length === 0) continue;
|
|
184
|
+
const key = keyOf(rest.options);
|
|
185
|
+
if (queue.some((q) => q.age === 0 && keyOf(q.options) === key)) continue;
|
|
186
|
+
queue.unshift({ ...rest, age: 0, reply: replyCounter });
|
|
187
|
+
}
|
|
188
|
+
while (queue.length > 30) queue.pop();
|
|
189
|
+
// States are per reply; the queue is the only place a block survives.
|
|
190
|
+
states = [];
|
|
191
|
+
pickedThisTurn.clear();
|
|
124
192
|
}
|
|
125
193
|
});
|
|
126
194
|
|
|
@@ -192,7 +260,7 @@ When a reply naturally ends with a choice or "say the word and I'll...", call th
|
|
|
192
260
|
}
|
|
193
261
|
}
|
|
194
262
|
const alternates = (args.alternates as string) ?? "";
|
|
195
|
-
|
|
263
|
+
const newState: NextStepsState = {
|
|
196
264
|
options: opts,
|
|
197
265
|
multi: args.multi !== false,
|
|
198
266
|
rec,
|
|
@@ -200,24 +268,26 @@ When a reply naturally ends with a choice or "say the word and I'll...", call th
|
|
|
200
268
|
subtitles: (args.subtitles as string[]) ?? [],
|
|
201
269
|
alternates,
|
|
202
270
|
};
|
|
271
|
+
states.push(newState);
|
|
203
272
|
if (args.carry === true) settings.carryForward = true;
|
|
204
|
-
const recSet = new Set((
|
|
205
|
-
const riskySet = new Set((
|
|
206
|
-
const lines =
|
|
273
|
+
const recSet = new Set((states[0].rec || "").split(",").map((s) => s.trim()));
|
|
274
|
+
const riskySet = new Set((states[0].risky || "").split(",").map((s) => s.trim()));
|
|
275
|
+
const lines = newState.options.map((o, i) => {
|
|
207
276
|
const n = i + 1;
|
|
208
277
|
const tags = [
|
|
209
278
|
settings.accentRecommended && recSet.has(String(n)) ? "★" : "",
|
|
210
279
|
settings.markRisky && riskySet.has(String(n)) ? "▲" : "",
|
|
211
280
|
].filter(Boolean).join(" ");
|
|
212
|
-
const sub =
|
|
213
|
-
|
|
281
|
+
const sub = newState.subtitles[i] ? ` — ${newState.subtitles[i]}` : "";
|
|
282
|
+
const tagPrefix = tags ? `${tags} ` : "";
|
|
283
|
+
return `${n}. ${tagPrefix}${o}${sub}`;
|
|
214
284
|
});
|
|
215
285
|
// Render an interactive choice right away instead of forcing /ns.
|
|
216
|
-
const choiceLabels =
|
|
286
|
+
const choiceLabels = newState.options.map((o, i) => {
|
|
217
287
|
const n = i + 1;
|
|
218
288
|
const recTag = settings.accentRecommended && recSet.has(String(n)) ? " ★ RECOMMENDED" : "";
|
|
219
289
|
const riskyTag = settings.markRisky && riskySet.has(String(n)) ? " ▲ RISKY" : "";
|
|
220
|
-
const sub =
|
|
290
|
+
const sub = newState.subtitles[i] ? ` — ${newState.subtitles[i]}` : "";
|
|
221
291
|
return `${o}${sub}${recTag}${riskyTag}`;
|
|
222
292
|
});
|
|
223
293
|
try {
|
|
@@ -259,7 +329,7 @@ When a reply naturally ends with a choice or "say the word and I'll...", call th
|
|
|
259
329
|
return component;
|
|
260
330
|
});
|
|
261
331
|
if (result && result.length > 0) {
|
|
262
|
-
const chosen = result.map((n) =>
|
|
332
|
+
const chosen = result.map((n) => newState.options[n]);
|
|
263
333
|
const message = chosen.length === 1 ? chosen[0] : chosen.map((c) => `- ${c}`).join("\n");
|
|
264
334
|
if (ctx.isIdle()) {
|
|
265
335
|
pi.sendUserMessage(message);
|
|
@@ -268,7 +338,8 @@ When a reply naturally ends with a choice or "say the word and I'll...", call th
|
|
|
268
338
|
} else {
|
|
269
339
|
pi.sendUserMessage(message, { deliverAs: "followUp" });
|
|
270
340
|
}
|
|
271
|
-
|
|
341
|
+
for (const c of chosen) pickedThisTurn.add(c);
|
|
342
|
+
retirePicked(chosen);
|
|
272
343
|
ctx.ui.notify(`Sent ${chosen.length} step(s)`, "info");
|
|
273
344
|
} else if (result !== null) {
|
|
274
345
|
// empty selection (enter with nothing toggled) — send nothing
|
|
@@ -285,61 +356,151 @@ When a reply naturally ends with a choice or "say the word and I'll...", call th
|
|
|
285
356
|
});
|
|
286
357
|
|
|
287
358
|
async function pickAndSend(ctx: any) {
|
|
288
|
-
if (
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
const q = queue[0];
|
|
292
|
-
state = { options: q.options, multi: true, rec: q.rec, risky: q.risky, subtitles: q.subtitles, alternates: "" };
|
|
293
|
-
} else {
|
|
294
|
-
ctx.ui.notify("No next steps registered. Ask the agent to call next_steps.", "warning");
|
|
295
|
-
return;
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
const opts = state.options;
|
|
299
|
-
const recSet = new Set((state.rec || "").split(",").map((s) => s.trim()));
|
|
300
|
-
const riskySet = new Set((state.risky || "").split(",").map((s) => s.trim()));
|
|
301
|
-
// parse alternate groups
|
|
302
|
-
const altGroups: number[][] = [];
|
|
303
|
-
if (state.alternates) {
|
|
304
|
-
for (const g of state.alternates.split("|")) {
|
|
305
|
-
const members = g.split(",").map((s) => parseInt(s.trim(), 10)).filter((n) => !isNaN(n) && n >= 1 && n <= opts.length);
|
|
306
|
-
if (members.length >= 2) altGroups.push(members);
|
|
307
|
-
}
|
|
359
|
+
if (queue.length === 0) {
|
|
360
|
+
ctx.ui.notify("No next steps registered. Ask the agent to call next_steps.", "warning");
|
|
361
|
+
return;
|
|
308
362
|
}
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
const
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
363
|
+
// One tab per collected block, newest first. Carried blocks keep their real age.
|
|
364
|
+
const blocks = queue.map((q) => {
|
|
365
|
+
const recSet = new Set((q.rec || "").split(",").map((s) => s.trim()));
|
|
366
|
+
const riskySet = new Set((q.risky || "").split(",").map((s) => s.trim()));
|
|
367
|
+
return {
|
|
368
|
+
age: q.age,
|
|
369
|
+
items: q.options.map((o, i) => {
|
|
370
|
+
const tags = [
|
|
371
|
+
settings.accentRecommended && recSet.has(String(i + 1)) ? "★" : "",
|
|
372
|
+
settings.markRisky && riskySet.has(String(i + 1)) ? "▲" : "",
|
|
373
|
+
].filter(Boolean).join(" ");
|
|
374
|
+
return { option: o, text: `${tags ? tags + " " : ""}${o}` };
|
|
375
|
+
}),
|
|
376
|
+
};
|
|
316
377
|
});
|
|
317
|
-
const
|
|
318
|
-
"
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
378
|
+
const tabLabel = (i: number) =>
|
|
379
|
+
i === 0 ? "this reply" : blocks[i].age === 1 ? "1 reply back" : `${blocks[i].age} replies back`;
|
|
380
|
+
let chosen: string[] | null = null;
|
|
381
|
+
try {
|
|
382
|
+
chosen = await ctx.ui.custom<string[] | null>((tui, theme, _kb, done) => {
|
|
383
|
+
let tab = 0;
|
|
384
|
+
let cursor = 0;
|
|
385
|
+
let picked = new Set<string>();
|
|
386
|
+
let armed = new Set<string>();
|
|
387
|
+
const staleKeys = () => {
|
|
388
|
+
const keys: string[] = [];
|
|
389
|
+
blocks.forEach((block, b) => {
|
|
390
|
+
if (b > 0) block.items.forEach((_, i) => keys.push(`${b}:${i}`));
|
|
391
|
+
});
|
|
392
|
+
return keys;
|
|
393
|
+
};
|
|
394
|
+
const reindex = (set: Set<string>, block: number, item?: number) => {
|
|
395
|
+
const out = new Set<string>();
|
|
396
|
+
for (const key of set) {
|
|
397
|
+
const [b, i] = key.split(":").map(Number);
|
|
398
|
+
if (b === block && (item === undefined || i === item)) continue;
|
|
399
|
+
out.add(`${b > block ? b - 1 : b}:${b === block && item !== undefined && i > item ? i - 1 : i}`);
|
|
400
|
+
}
|
|
401
|
+
return out;
|
|
402
|
+
};
|
|
403
|
+
const deleteArmed = (keys: string[]) => {
|
|
404
|
+
const byBlock = new Map<number, number[]>();
|
|
405
|
+
for (const key of keys) {
|
|
406
|
+
const [b, i] = key.split(":").map(Number);
|
|
407
|
+
byBlock.set(b, [...(byBlock.get(b) ?? []), i]);
|
|
408
|
+
}
|
|
409
|
+
for (const b of [...byBlock.keys()].sort((x, y) => y - x)) {
|
|
410
|
+
const items = byBlock.get(b);
|
|
411
|
+
if (!items) continue;
|
|
412
|
+
for (const i of items.sort((x, y) => y - x)) {
|
|
413
|
+
blocks[b].items.splice(i, 1);
|
|
414
|
+
dropOption(queue[b], i);
|
|
415
|
+
picked = reindex(picked, b, i);
|
|
416
|
+
armed = reindex(armed, b, i);
|
|
417
|
+
}
|
|
418
|
+
if (blocks[b].items.length === 0) {
|
|
419
|
+
blocks.splice(b, 1);
|
|
420
|
+
queue.splice(b, 1);
|
|
421
|
+
picked = reindex(picked, b);
|
|
422
|
+
armed = reindex(armed, b);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
tab = Math.min(tab, blocks.length - 1);
|
|
426
|
+
cursor = Math.min(cursor, Math.max(0, blocks[tab].items.length - 1));
|
|
427
|
+
armed.clear();
|
|
428
|
+
};
|
|
429
|
+
const component = {
|
|
430
|
+
focused: true,
|
|
431
|
+
render(_width: number): string[] {
|
|
432
|
+
const out: string[] = [];
|
|
433
|
+
const head = blocks
|
|
434
|
+
.map((_, i) =>
|
|
435
|
+
i === tab ? theme.fg("accent", `[${tabLabel(i)}]`) : theme.fg("dim", ` ${tabLabel(i)} `),
|
|
436
|
+
)
|
|
437
|
+
.join(" · ");
|
|
438
|
+
out.push(`${theme.fg("accent", "Next steps")} ${head}`);
|
|
439
|
+
blocks[tab].items.forEach((item, i) => {
|
|
440
|
+
const key = `${tab}:${i}`;
|
|
441
|
+
const mark = picked.has(key) ? "[x]" : "[ ]";
|
|
442
|
+
const prefix = i === cursor ? theme.fg("accent", "> ") : " ";
|
|
443
|
+
const text = armed.has(key) ? theme.fg("error", `[del] ${item.text}`) : item.text;
|
|
444
|
+
out.push(`${prefix}${mark} ${text}`);
|
|
445
|
+
});
|
|
446
|
+
out.push(theme.fg("dim", "space toggle · ↑↓ move · ←→ block · ctrl+d delete stale · shift+ctrl+d all stale · enter/tab confirm · esc cancel"));
|
|
447
|
+
return out;
|
|
448
|
+
},
|
|
449
|
+
invalidate() {},
|
|
450
|
+
handleInput(data: string) {
|
|
451
|
+
const all = matchesKey(data, "shift+ctrl+d");
|
|
452
|
+
if (all || matchesKey(data, "ctrl+d")) {
|
|
453
|
+
let targets: string[] = [];
|
|
454
|
+
if (all) targets = staleKeys();
|
|
455
|
+
else if (tab > 0) targets = [`${tab}:${cursor}`];
|
|
456
|
+
if (targets.length > 0) {
|
|
457
|
+
if (targets.every((key) => armed.has(key))) deleteArmed(targets);
|
|
458
|
+
else for (const key of targets) armed.add(key);
|
|
459
|
+
tui.requestRender();
|
|
460
|
+
return;
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
const n = blocks[tab].items.length;
|
|
464
|
+
if (matchesKey(data, "up") || matchesKey(data, "k")) {
|
|
465
|
+
cursor = (cursor - 1 + n) % n;
|
|
466
|
+
} else if (matchesKey(data, "down") || matchesKey(data, "j")) {
|
|
467
|
+
cursor = (cursor + 1) % n;
|
|
468
|
+
} else if (matchesKey(data, "left") || matchesKey(data, "h")) {
|
|
469
|
+
tab = (tab - 1 + blocks.length) % blocks.length;
|
|
470
|
+
cursor = 0;
|
|
471
|
+
} else if (matchesKey(data, "right") || matchesKey(data, "l")) {
|
|
472
|
+
tab = (tab + 1) % blocks.length;
|
|
473
|
+
cursor = 0;
|
|
474
|
+
} else if (matchesKey(data, "space")) {
|
|
475
|
+
const key = `${tab}:${cursor}`;
|
|
476
|
+
if (picked.has(key)) picked.delete(key);
|
|
477
|
+
else picked.add(key);
|
|
478
|
+
} else if (matchesKey(data, "enter") || matchesKey(data, "tab")) {
|
|
479
|
+
done(
|
|
480
|
+
Array.from(picked).map((key) => {
|
|
481
|
+
const [b, i] = key.split(":").map(Number);
|
|
482
|
+
return blocks[b].items[i].option;
|
|
483
|
+
}),
|
|
484
|
+
);
|
|
485
|
+
return;
|
|
486
|
+
} else if (matchesKey(data, "escape") || matchesKey(data, "ctrl+c")) {
|
|
487
|
+
done(null);
|
|
488
|
+
return;
|
|
489
|
+
}
|
|
490
|
+
tui.requestRender();
|
|
491
|
+
},
|
|
492
|
+
};
|
|
493
|
+
return component;
|
|
494
|
+
});
|
|
495
|
+
} catch {
|
|
496
|
+
ctx.ui.notify("Selection UI unavailable in this session.", "warning");
|
|
323
497
|
return;
|
|
324
498
|
}
|
|
325
|
-
|
|
326
|
-
.
|
|
327
|
-
.map((s) => parseInt(s.trim(), 10))
|
|
328
|
-
.filter((n) => !isNaN(n) && n >= 1 && n <= opts.length);
|
|
329
|
-
// enforce alternate groups
|
|
330
|
-
for (const g of altGroups) {
|
|
331
|
-
const picked = indices.filter((n) => g.includes(n));
|
|
332
|
-
if (picked.length > 1) {
|
|
333
|
-
// keep the first
|
|
334
|
-
const first = picked[0];
|
|
335
|
-
indices = indices.filter((n) => !g.includes(n) || n === first);
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
if (indices.length === 0) {
|
|
339
|
-
ctx.ui.notify("No valid selection", "warning");
|
|
499
|
+
if (!chosen || chosen.length === 0) {
|
|
500
|
+
ctx.ui.notify("No selection", "info");
|
|
340
501
|
return;
|
|
341
502
|
}
|
|
342
|
-
|
|
503
|
+
// Every picked step travels as one user message, never one message per step.
|
|
343
504
|
const message = chosen.length === 1 ? chosen[0] : chosen.map((c) => `- ${c}`).join("\n");
|
|
344
505
|
if (ctx.isIdle()) {
|
|
345
506
|
pi.sendUserMessage(message);
|
|
@@ -348,18 +509,70 @@ When a reply naturally ends with a choice or "say the word and I'll...", call th
|
|
|
348
509
|
} else {
|
|
349
510
|
pi.sendUserMessage(message, { deliverAs: "followUp" });
|
|
350
511
|
}
|
|
351
|
-
|
|
352
|
-
if (queue.length > 0) queue.shift();
|
|
512
|
+
retirePicked(chosen);
|
|
353
513
|
ctx.ui.notify(`Sent ${chosen.length} step(s)`, "info");
|
|
354
514
|
}
|
|
355
515
|
|
|
516
|
+
// `/ns clear` drops everything older than the newest reply; `/ns clear X` drops the last X posts.
|
|
517
|
+
async function clearSteps(arg: string, ctx: any) {
|
|
518
|
+
const trimmed = arg.trim();
|
|
519
|
+
if (queue.length === 0) {
|
|
520
|
+
ctx.ui.notify("No collected next steps to clear.", "info");
|
|
521
|
+
return;
|
|
522
|
+
}
|
|
523
|
+
if (/^clear$/i.test(trimmed)) {
|
|
524
|
+
const before = queue.length;
|
|
525
|
+
const newest = queue[0].reply;
|
|
526
|
+
for (let i = queue.length - 1; i >= 0; i--) {
|
|
527
|
+
if (queue[i].reply < newest) queue.splice(i, 1);
|
|
528
|
+
}
|
|
529
|
+
const dropped = before - queue.length;
|
|
530
|
+
ctx.ui.notify(
|
|
531
|
+
dropped > 0
|
|
532
|
+
? `Cleared ${dropped} stale step(s). Kept the newest reply.`
|
|
533
|
+
: "Nothing stale to clear. Use /ns clear X for the last X posts.",
|
|
534
|
+
"info",
|
|
535
|
+
);
|
|
536
|
+
return;
|
|
537
|
+
}
|
|
538
|
+
const m = trimmed.match(/^clear\s+(\d+)$/i);
|
|
539
|
+
if (m) {
|
|
540
|
+
const n = parseInt(m[1], 10);
|
|
541
|
+
if (n < 1) {
|
|
542
|
+
ctx.ui.notify("Usage: /ns clear [X]", "warning");
|
|
543
|
+
return;
|
|
544
|
+
}
|
|
545
|
+
const cutoff = replyCounter - n + 1;
|
|
546
|
+
const before = queue.length;
|
|
547
|
+
for (let i = queue.length - 1; i >= 0; i--) {
|
|
548
|
+
if (queue[i].reply >= cutoff) queue.splice(i, 1);
|
|
549
|
+
}
|
|
550
|
+
const dropped = before - queue.length;
|
|
551
|
+
ctx.ui.notify(
|
|
552
|
+
dropped > 0
|
|
553
|
+
? `Cleared ${dropped} step(s) from the last ${n} post(s).`
|
|
554
|
+
: `No collected steps in the last ${n} post(s).`,
|
|
555
|
+
"info",
|
|
556
|
+
);
|
|
557
|
+
return;
|
|
558
|
+
}
|
|
559
|
+
ctx.ui.notify("Usage: /ns clear (stale) or /ns clear X (last X posts)", "warning");
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
const runOrClear = async (args: string, ctx: any) => {
|
|
563
|
+
const a = (args ?? "").trim();
|
|
564
|
+
if (!a) return pickAndSend(ctx);
|
|
565
|
+
if (/^clear\b/i.test(a) || /^clear$/i.test(a)) return clearSteps(a, ctx);
|
|
566
|
+
ctx.ui.notify("Usage: /ns or /ns clear [X]", "warning");
|
|
567
|
+
};
|
|
568
|
+
|
|
356
569
|
pi.registerCommand("ns", {
|
|
357
|
-
description: "Pick and send a registered next step
|
|
358
|
-
handler: async (
|
|
570
|
+
description: "Pick and send a registered next step, or /ns clear [X] to drop collected steps.",
|
|
571
|
+
handler: async (args, ctx) => runOrClear(args, ctx),
|
|
359
572
|
});
|
|
360
573
|
pi.registerCommand("nextsteps", {
|
|
361
|
-
description: "Pick and send a registered next step
|
|
362
|
-
handler: async (
|
|
574
|
+
description: "Pick and send a registered next step, or /nextsteps clear [X] to drop collected steps.",
|
|
575
|
+
handler: async (args, ctx) => runOrClear(args, ctx),
|
|
363
576
|
});
|
|
364
577
|
pi.registerCommand("nextsteps-settings", {
|
|
365
578
|
description: "Show next-steps settings path.",
|
package/package.json
CHANGED
|
@@ -1,16 +1,22 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "pi-next-steps",
|
|
3
|
-
"version": "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.2.0",
|
|
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
|
+
}
|