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.
Files changed (2) hide show
  1. package/dist/index.js +21 -18
  2. 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 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.
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 last rename timestamp per session
12
- const lastRenamed = new Map();
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
- // Check that there is at least one assistant message
21
+ // Fetch messages to count assistant responses
27
22
  const messages = await client.session.messages({
28
23
  path: { id: sessionId },
29
24
  });
30
- const hasAssistantMessage = messages.data?.some((m) => m.info.role === "assistant");
31
- 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)
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
- lastRenamed.set(sessionId, now);
41
+ lastRenamedAtCount.set(sessionId, assistantCount);
39
42
  }
40
43
  catch (err) {
41
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.1.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",