opencode-auto-rename 1.0.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.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,16 @@
1
1
  /**
2
2
  * Auto-Rename Plugin
3
3
  *
4
- * Automatically renames conversations after the first assistant response.
5
- * Uses the built-in session.summarize() SDK method to generate a title
6
- * from the conversation content.
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.
7
8
  */
9
+ const RENAME_INTERVAL_MS = 5 * 60 * 1000; // 5 minutes
8
10
  export const AutoRenamePlugin = async ({ client }) => {
9
- // Track sessions we've already renamed to avoid repeated calls
10
- const renamed = new Set();
11
+ // Track the first seen and last renamed timestamps per session
12
+ const firstSeen = new Map();
13
+ const lastRenamed = new Map();
11
14
  return {
12
15
  event: async ({ event }) => {
13
16
  if (event.type !== "session.idle")
@@ -15,19 +18,20 @@ export const AutoRenamePlugin = async ({ client }) => {
15
18
  const sessionId = event.properties.sessionID;
16
19
  if (!sessionId)
17
20
  return;
18
- // Skip if we've already renamed this session
19
- if (renamed.has(sessionId))
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
30
+ const lastRenamedAt = lastRenamed.get(sessionId);
31
+ const baseline = lastRenamedAt ?? firstSeen.get(sessionId);
32
+ if (now - baseline < RENAME_INTERVAL_MS)
20
33
  return;
21
34
  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
35
  // Check that there is at least one assistant message
32
36
  const messages = await client.session.messages({
33
37
  path: { id: sessionId },
@@ -36,11 +40,10 @@ export const AutoRenamePlugin = async ({ client }) => {
36
40
  if (!hasAssistantMessage)
37
41
  return;
38
42
  // Use the built-in summarize endpoint to generate a title.
39
- // Omitting body lets OpenCode use the default model.
40
43
  await client.session.summarize({
41
44
  path: { id: sessionId },
42
45
  });
43
- renamed.add(sessionId);
46
+ lastRenamed.set(sessionId, now);
44
47
  }
45
48
  catch (err) {
46
49
  // Log errors but don't crash the plugin
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-auto-rename",
3
- "version": "1.0.0",
3
+ "version": "1.2.0",
4
4
  "description": "OpenCode plugin that automatically renames conversations based on their content",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",