opencode-auto-rename 1.1.0 → 1.3.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/dist/index.js +21 -18
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Auto-Rename Plugin
|
|
3
3
|
*
|
|
4
|
-
* Automatically
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* Automatically names conversations and keeps titles updated as they evolve.
|
|
5
|
+
*
|
|
6
|
+
* - Renames immediately after the first assistant response.
|
|
7
|
+
* - Re-renames every 3 assistant messages to keep the title relevant.
|
|
8
8
|
*/
|
|
9
|
-
const
|
|
9
|
+
const RENAME_EVERY_N = 3;
|
|
10
10
|
export const AutoRenamePlugin = async ({ client }) => {
|
|
11
|
-
// Track the last
|
|
12
|
-
const
|
|
11
|
+
// Track the assistant message count at which we last renamed each session
|
|
12
|
+
const lastRenamedAtCount = new Map();
|
|
13
13
|
return {
|
|
14
14
|
event: async ({ event }) => {
|
|
15
15
|
if (event.type !== "session.idle")
|
|
@@ -17,25 +17,28 @@ export const AutoRenamePlugin = async ({ client }) => {
|
|
|
17
17
|
const sessionId = event.properties.sessionID;
|
|
18
18
|
if (!sessionId)
|
|
19
19
|
return;
|
|
20
|
-
const now = Date.now();
|
|
21
|
-
const lastRenamedAt = lastRenamed.get(sessionId);
|
|
22
|
-
// Skip if we renamed this session recently (within the interval)
|
|
23
|
-
if (lastRenamedAt && now - lastRenamedAt < RENAME_INTERVAL_MS)
|
|
24
|
-
return;
|
|
25
20
|
try {
|
|
26
|
-
//
|
|
21
|
+
// Fetch messages to count assistant responses
|
|
27
22
|
const messages = await client.session.messages({
|
|
28
23
|
path: { id: sessionId },
|
|
29
24
|
});
|
|
30
|
-
const
|
|
31
|
-
|
|
25
|
+
const assistantCount = messages.data?.filter((m) => m.info.role === "assistant").length ?? 0;
|
|
26
|
+
// Need at least one assistant message
|
|
27
|
+
if (assistantCount === 0)
|
|
28
|
+
return;
|
|
29
|
+
const lastCount = lastRenamedAtCount.get(sessionId) ?? 0;
|
|
30
|
+
// Rename on the first assistant message (count=1, lastCount=0)
|
|
31
|
+
// then every RENAME_EVERY_N new assistant messages after that
|
|
32
|
+
const isFirstMessage = lastCount === 0;
|
|
33
|
+
const newMessagesSinceRename = assistantCount - lastCount;
|
|
34
|
+
const shouldRename = isFirstMessage || newMessagesSinceRename >= RENAME_EVERY_N;
|
|
35
|
+
if (!shouldRename)
|
|
32
36
|
return;
|
|
33
|
-
// Use the built-in summarize endpoint to generate a title
|
|
34
|
-
// Omitting body lets OpenCode use the default model.
|
|
37
|
+
// Use the built-in summarize endpoint to generate a title
|
|
35
38
|
await client.session.summarize({
|
|
36
39
|
path: { id: sessionId },
|
|
37
40
|
});
|
|
38
|
-
|
|
41
|
+
lastRenamedAtCount.set(sessionId, assistantCount);
|
|
39
42
|
}
|
|
40
43
|
catch (err) {
|
|
41
44
|
// Log errors but don't crash the plugin
|