forked from earendil-works/pi
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbookmark.ts
More file actions
50 lines (45 loc) · 1.52 KB
/
Copy pathbookmark.ts
File metadata and controls
50 lines (45 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/**
* Entry bookmarking example.
*
* Shows setLabel to mark entries with labels for easy navigation in /tree.
* Labels appear in the tree view and help you find important points.
*
* Usage: /bookmark [label] - bookmark the last assistant message
*/
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
export default function (pi: ExtensionAPI) {
pi.registerCommand("bookmark", {
description: "Bookmark last message (usage: /bookmark [label])",
handler: async (args, ctx) => {
const label = args.trim() || `bookmark-${Date.now()}`;
// Find the last assistant message entry
const entries = ctx.sessionManager.getEntries();
for (let i = entries.length - 1; i >= 0; i--) {
const entry = entries[i];
if (entry.type === "message" && entry.message.role === "assistant") {
pi.setLabel(entry.id, label);
ctx.ui.notify(`Bookmarked as: ${label}`, "info");
return;
}
}
ctx.ui.notify("No assistant message to bookmark", "warning");
},
});
// Remove bookmark
pi.registerCommand("unbookmark", {
description: "Remove bookmark from last labeled entry",
handler: async (_args, ctx) => {
const entries = ctx.sessionManager.getEntries();
for (let i = entries.length - 1; i >= 0; i--) {
const entry = entries[i];
const label = ctx.sessionManager.getLabel(entry.id);
if (label) {
pi.setLabel(entry.id, undefined);
ctx.ui.notify(`Removed bookmark: ${label}`, "info");
return;
}
}
ctx.ui.notify("No bookmarked entry found", "warning");
},
});
}