@henryqw/pi-herdr-rename 4.0.1 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/extensions/rename.ts +14 -20
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -26,7 +26,7 @@ Outside Herdr, the extension still changes the Pi session name.
|
|
|
26
26
|
|
|
27
27
|
Send the first real prompt. A title appears in the background without delaying the reply.
|
|
28
28
|
|
|
29
|
-
Run `/rename` after the task changes. It generates a new display title and semantic branch from up to
|
|
29
|
+
Run `/rename` after the task changes. It generates a new display title and semantic branch from up to five recent user messages.
|
|
30
30
|
|
|
31
31
|
### Trigger
|
|
32
32
|
|
package/extensions/rename.ts
CHANGED
|
@@ -16,7 +16,8 @@ import {
|
|
|
16
16
|
const WIDGET_KEY = "pi-herdr-rename";
|
|
17
17
|
const WIDGET_RESULT_MS = 2_000;
|
|
18
18
|
const MAX_MESSAGE_CHARS = 1_000;
|
|
19
|
-
const MAX_CONTEXT_CHARS =
|
|
19
|
+
const MAX_CONTEXT_CHARS = 5_000;
|
|
20
|
+
const MAX_CONTEXT_MESSAGES = 5;
|
|
20
21
|
const DISPLAY_MAX_WORDS = 4;
|
|
21
22
|
const DISPLAY_MAX_CHARS = 20;
|
|
22
23
|
const SEMANTIC_TYPE_MAX_CHARS = 12;
|
|
@@ -121,30 +122,23 @@ function latestSessionUserText(ctx: ExtensionContext): string | undefined {
|
|
|
121
122
|
}
|
|
122
123
|
}
|
|
123
124
|
|
|
124
|
-
function
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
if (entry.type !== "message") continue;
|
|
128
|
-
if (entry.message.role !== "user" && entry.message.role !== "assistant") continue;
|
|
125
|
+
function recentUserMessages(ctx: ExtensionContext, fallback?: string): string | undefined {
|
|
126
|
+
const messages = ctx.sessionManager.getBranch().flatMap((entry) => {
|
|
127
|
+
if (entry.type !== "message" || entry.message.role !== "user") return [];
|
|
129
128
|
const text = messageText(entry.message.content).trim();
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
if (!rounds.length && fallback?.trim()) rounds.push({ user: fallback.trim() });
|
|
135
|
-
if (!rounds.length) return undefined;
|
|
129
|
+
return text ? [`user: ${text.slice(0, MAX_MESSAGE_CHARS)}`] : [];
|
|
130
|
+
});
|
|
131
|
+
if (!messages.length && fallback?.trim()) messages.push(`user: ${fallback.trim().slice(0, MAX_MESSAGE_CHARS)}`);
|
|
132
|
+
if (!messages.length) return undefined;
|
|
136
133
|
|
|
137
|
-
const
|
|
138
|
-
`user: ${round.user.slice(0, MAX_MESSAGE_CHARS)}`,
|
|
139
|
-
...(round.assistant ? [`assistant: ${round.assistant.slice(0, MAX_MESSAGE_CHARS)}`] : []),
|
|
140
|
-
]);
|
|
134
|
+
const recentMessages = messages.slice(-MAX_CONTEXT_MESSAGES);
|
|
141
135
|
const selected: string[] = [];
|
|
142
136
|
let remaining = MAX_CONTEXT_CHARS;
|
|
143
|
-
for (let index =
|
|
137
|
+
for (let index = recentMessages.length - 1; index >= 0 && remaining > 0; index--) {
|
|
144
138
|
const separator = selected.length ? 2 : 0;
|
|
145
139
|
const available = remaining - separator;
|
|
146
140
|
if (available <= 0) break;
|
|
147
|
-
const text =
|
|
141
|
+
const text = recentMessages[index].slice(0, available);
|
|
148
142
|
if (!text) break;
|
|
149
143
|
selected.push(text);
|
|
150
144
|
remaining -= text.length + separator;
|
|
@@ -400,9 +394,9 @@ export default function herdrRenameExtension(pi: ExtensionAPI): void {
|
|
|
400
394
|
});
|
|
401
395
|
|
|
402
396
|
pi.registerCommand("rename", {
|
|
403
|
-
description: "Generate a new display title from recent
|
|
397
|
+
description: "Generate a new display title from recent user messages",
|
|
404
398
|
handler: async (_args, ctx) => {
|
|
405
|
-
const context =
|
|
399
|
+
const context = recentUserMessages(ctx, latestUserText);
|
|
406
400
|
if (!context) {
|
|
407
401
|
ctx.ui.notify("No user text is available to rename this chat.", "warning");
|
|
408
402
|
return;
|