@henryqw/pi-herdr-rename 4.0.1 → 4.1.1
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 +16 -15
- package/extensions/rename.ts +14 -20
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
# `@henryqw/pi-herdr-rename`
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
## Why
|
|
6
|
-
|
|
7
|
-
- **Created for**: Users who cannot identify conversations from generated workspace labels.
|
|
8
|
-
- **Advantage**: One concise title labels Pi and Herdr, maps to Git, and returns on resume without another model call.
|
|
3
|
+
Replace hard-to-identify generated workspace labels with one short Pi conversation title. The title labels Pi and Herdr, maps to Git, and returns on resume without another model call.
|
|
9
4
|
|
|
10
5
|
## Install
|
|
11
6
|
|
|
@@ -18,15 +13,17 @@ Run `/task-models` and configure the `fast` profile. Herdr is required for pane,
|
|
|
18
13
|
|
|
19
14
|
Outside Herdr, the extension still changes the Pi session name.
|
|
20
15
|
|
|
21
|
-
##
|
|
16
|
+
## Works with
|
|
22
17
|
|
|
23
|
-
[`@henryqw/pi-task-models`](https://pi.henry.wang/extensions/pi-task-models)
|
|
18
|
+
**Required.** [`@henryqw/pi-task-models`](https://pi.henry.wang/extensions/pi-task-models) provides shared title-generation model profiles.
|
|
24
19
|
|
|
25
20
|
## Use
|
|
26
21
|
|
|
27
22
|
Send the first real prompt. A title appears in the background without delaying the reply.
|
|
28
23
|
|
|
29
|
-
Run `/rename` after the task changes. It generates a new display title and semantic branch from up to
|
|
24
|
+
Run `/rename` after the task changes. It generates a new display title and semantic branch from up to five recent user messages.
|
|
25
|
+
|
|
26
|
+
## Flow
|
|
30
27
|
|
|
31
28
|
### Trigger
|
|
32
29
|
|
|
@@ -34,8 +31,6 @@ The first real user prompt generates a title in the background after Pi expands
|
|
|
34
31
|
|
|
35
32
|
### Title and branch rules
|
|
36
33
|
|
|
37
|
-
Display titles are natural task phrases. They are preferably three or four words and always at most four words and 20 characters.
|
|
38
|
-
|
|
39
34
|
A semantic branch is a Git-safe branch name made from a task type and the display-title words. Model classification stays internal. For example, `refactor: update task logic` displays as `Update task logic` and maps to `refactor/update-task-logic`.
|
|
40
35
|
|
|
41
36
|
- In a linked worktree, a detached checkout or Herdr `worktree/...` branch is renamed.
|
|
@@ -45,12 +40,18 @@ A semantic branch is a Git-safe branch name made from a task type and the displa
|
|
|
45
40
|
- The enclosing Herdr tab updates only when this pane is the tab's only pane.
|
|
46
41
|
- Outside Herdr, only the Pi session name changes.
|
|
47
42
|
|
|
48
|
-
### Model
|
|
43
|
+
### Model route and resume
|
|
49
44
|
|
|
50
45
|
The shared [`pi-task-models` config](https://pi.henry.wang/extensions/pi-task-models#config) is at `~/.pi/agent/config/pi-task-models/config.json`. It can explicitly override the local `pi-herdr-rename/rename` declaration, which defaults to `fast`.
|
|
51
46
|
|
|
52
|
-
The extension tries the assigned profile primary, then fallback, while honoring the configured thinking level. It never substitutes the current session model.
|
|
47
|
+
The extension tries the assigned profile primary, then fallback, while honoring the configured thinking level. It never substitutes the current session model.
|
|
48
|
+
|
|
49
|
+
Resuming a session created by this version reapplies the saved display title and semantic branch without another model request.
|
|
50
|
+
|
|
51
|
+
## Limits and recovery
|
|
52
|
+
|
|
53
|
+
Display titles are natural task phrases. They are preferably three or four words and always at most four words and 20 characters.
|
|
53
54
|
|
|
54
|
-
|
|
55
|
+
A missing shared task-model config warns once at session start. Run `/task-models` to configure rename routing. No viable route leaves titles unchanged.
|
|
55
56
|
|
|
56
|
-
Older titles receive no migration.
|
|
57
|
+
Herdr and Git synchronization failures appear as warnings. Cancellation by a newer rename remains silent. Older titles receive no migration.
|
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;
|