opencode-auto-rename 1.2.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.
Files changed (2) hide show
  1. package/dist/index.js +21 -26
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,16 +1,15 @@
1
1
  /**
2
2
  * Auto-Rename Plugin
3
3
  *
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.
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 RENAME_INTERVAL_MS = 5 * 60 * 1000; // 5 minutes
9
+ const RENAME_EVERY_N = 3;
10
10
  export const AutoRenamePlugin = async ({ client }) => {
11
- // Track the first seen and last renamed timestamps per session
12
- const firstSeen = new Map();
13
- const lastRenamed = new Map();
11
+ // Track the assistant message count at which we last renamed each session
12
+ const lastRenamedAtCount = new Map();
14
13
  return {
15
14
  event: async ({ event }) => {
16
15
  if (event.type !== "session.idle")
@@ -18,32 +17,28 @@ export const AutoRenamePlugin = async ({ client }) => {
18
17
  const sessionId = event.properties.sessionID;
19
18
  if (!sessionId)
20
19
  return;
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)
33
- return;
34
20
  try {
35
- // Check that there is at least one assistant message
21
+ // Fetch messages to count assistant responses
36
22
  const messages = await client.session.messages({
37
23
  path: { id: sessionId },
38
24
  });
39
- const hasAssistantMessage = messages.data?.some((m) => m.info.role === "assistant");
40
- if (!hasAssistantMessage)
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)
41
36
  return;
42
- // Use the built-in summarize endpoint to generate a title.
37
+ // Use the built-in summarize endpoint to generate a title
43
38
  await client.session.summarize({
44
39
  path: { id: sessionId },
45
40
  });
46
- lastRenamed.set(sessionId, now);
41
+ lastRenamedAtCount.set(sessionId, assistantCount);
47
42
  }
48
43
  catch (err) {
49
44
  // 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.2.0",
3
+ "version": "1.3.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",