opencode-auto-rename 1.0.0 → 1.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/dist/index.d.ts +0 -7
- package/dist/index.js +12 -17
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,2 @@
|
|
|
1
1
|
import type { Plugin } from "@opencode-ai/plugin";
|
|
2
|
-
/**
|
|
3
|
-
* Auto-Rename Plugin
|
|
4
|
-
*
|
|
5
|
-
* Automatically renames conversations after the first assistant response.
|
|
6
|
-
* Uses the built-in session.summarize() SDK method to generate a title
|
|
7
|
-
* from the conversation content.
|
|
8
|
-
*/
|
|
9
2
|
export declare const AutoRenamePlugin: Plugin;
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Auto-Rename Plugin
|
|
3
3
|
*
|
|
4
|
-
* Automatically renames conversations
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* Automatically renames conversations based on their content.
|
|
5
|
+
* Renames on the first assistant response, then periodically re-renames
|
|
6
|
+
* if at least 5 minutes have passed since the last rename to keep the
|
|
7
|
+
* title relevant as the conversation evolves.
|
|
7
8
|
*/
|
|
9
|
+
const RENAME_INTERVAL_MS = 5 * 60 * 1000; // 5 minutes
|
|
8
10
|
export const AutoRenamePlugin = async ({ client }) => {
|
|
9
|
-
// Track
|
|
10
|
-
const
|
|
11
|
+
// Track the last rename timestamp per session
|
|
12
|
+
const lastRenamed = new Map();
|
|
11
13
|
return {
|
|
12
14
|
event: async ({ event }) => {
|
|
13
15
|
if (event.type !== "session.idle")
|
|
@@ -15,19 +17,12 @@ export const AutoRenamePlugin = async ({ client }) => {
|
|
|
15
17
|
const sessionId = event.properties.sessionID;
|
|
16
18
|
if (!sessionId)
|
|
17
19
|
return;
|
|
18
|
-
|
|
19
|
-
|
|
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)
|
|
20
24
|
return;
|
|
21
25
|
try {
|
|
22
|
-
// Fetch the session to check its current title
|
|
23
|
-
const session = await client.session.get({
|
|
24
|
-
path: { id: sessionId },
|
|
25
|
-
});
|
|
26
|
-
// Only rename if the session has no meaningful title yet.
|
|
27
|
-
// OpenCode sets the title to "New Session" or leaves it empty by default.
|
|
28
|
-
const title = session.data?.title?.trim() ?? "";
|
|
29
|
-
if (title && title !== "New Session")
|
|
30
|
-
return;
|
|
31
26
|
// Check that there is at least one assistant message
|
|
32
27
|
const messages = await client.session.messages({
|
|
33
28
|
path: { id: sessionId },
|
|
@@ -40,7 +35,7 @@ export const AutoRenamePlugin = async ({ client }) => {
|
|
|
40
35
|
await client.session.summarize({
|
|
41
36
|
path: { id: sessionId },
|
|
42
37
|
});
|
|
43
|
-
|
|
38
|
+
lastRenamed.set(sessionId, now);
|
|
44
39
|
}
|
|
45
40
|
catch (err) {
|
|
46
41
|
// Log errors but don't crash the plugin
|