@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 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 three recent rounds.
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
 
@@ -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 = 2_000;
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 recentConversation(ctx: ExtensionContext, fallback?: string): string | undefined {
125
- const rounds: Array<{ user: string; assistant?: string }> = [];
126
- for (const entry of ctx.sessionManager.getBranch()) {
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
- if (!text) continue;
131
- if (entry.message.role === "user") rounds.push({ user: text });
132
- else if (entry.message.role === "assistant" && rounds.length) rounds[rounds.length - 1].assistant = text;
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 messages = rounds.slice(-3).flatMap((round) => [
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 = messages.length - 1; index >= 0 && remaining > 0; 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 = messages[index].slice(0, available);
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 conversation context",
397
+ description: "Generate a new display title from recent user messages",
404
398
  handler: async (_args, ctx) => {
405
- const context = recentConversation(ctx, latestUserText);
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@henryqw/pi-herdr-rename",
3
- "version": "4.0.1",
3
+ "version": "4.1.0",
4
4
  "description": "Generate short Pi display titles and rename the current Herdr location.",
5
5
  "keywords": [
6
6
  "pi-package",