opencode-auto-rename 1.1.0 → 1.2.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 +16 -8
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Auto-Rename Plugin
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* Periodically re-renames conversations to keep the title relevant as
|
|
5
|
+
* the conversation evolves. Skips the first idle event (OpenCode already
|
|
6
|
+
* names the session initially) and only renames after 5+ minutes have
|
|
7
|
+
* passed since the session was first seen.
|
|
8
8
|
*/
|
|
9
9
|
const RENAME_INTERVAL_MS = 5 * 60 * 1000; // 5 minutes
|
|
10
10
|
export const AutoRenamePlugin = async ({ client }) => {
|
|
11
|
-
// Track the last
|
|
11
|
+
// Track the first seen and last renamed timestamps per session
|
|
12
|
+
const firstSeen = new Map();
|
|
12
13
|
const lastRenamed = new Map();
|
|
13
14
|
return {
|
|
14
15
|
event: async ({ event }) => {
|
|
@@ -18,9 +19,17 @@ export const AutoRenamePlugin = async ({ client }) => {
|
|
|
18
19
|
if (!sessionId)
|
|
19
20
|
return;
|
|
20
21
|
const now = Date.now();
|
|
22
|
+
// Record when we first see a session and skip it —
|
|
23
|
+
// OpenCode already handles the initial naming.
|
|
24
|
+
if (!firstSeen.has(sessionId)) {
|
|
25
|
+
firstSeen.set(sessionId, now);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
// Only rename if enough time has passed since we first saw it
|
|
29
|
+
// or since the last rename
|
|
21
30
|
const lastRenamedAt = lastRenamed.get(sessionId);
|
|
22
|
-
|
|
23
|
-
if (
|
|
31
|
+
const baseline = lastRenamedAt ?? firstSeen.get(sessionId);
|
|
32
|
+
if (now - baseline < RENAME_INTERVAL_MS)
|
|
24
33
|
return;
|
|
25
34
|
try {
|
|
26
35
|
// Check that there is at least one assistant message
|
|
@@ -31,7 +40,6 @@ export const AutoRenamePlugin = async ({ client }) => {
|
|
|
31
40
|
if (!hasAssistantMessage)
|
|
32
41
|
return;
|
|
33
42
|
// Use the built-in summarize endpoint to generate a title.
|
|
34
|
-
// Omitting body lets OpenCode use the default model.
|
|
35
43
|
await client.session.summarize({
|
|
36
44
|
path: { id: sessionId },
|
|
37
45
|
});
|