opencode-auto-rename 1.0.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.
@@ -0,0 +1,9 @@
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
+ export declare const AutoRenamePlugin: Plugin;
package/dist/index.js ADDED
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Auto-Rename Plugin
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.
7
+ */
8
+ export const AutoRenamePlugin = async ({ client }) => {
9
+ // Track sessions we've already renamed to avoid repeated calls
10
+ const renamed = new Set();
11
+ return {
12
+ event: async ({ event }) => {
13
+ if (event.type !== "session.idle")
14
+ return;
15
+ const sessionId = event.properties.sessionID;
16
+ if (!sessionId)
17
+ return;
18
+ // Skip if we've already renamed this session
19
+ if (renamed.has(sessionId))
20
+ return;
21
+ 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
+ // Check that there is at least one assistant message
32
+ const messages = await client.session.messages({
33
+ path: { id: sessionId },
34
+ });
35
+ const hasAssistantMessage = messages.data?.some((m) => m.info.role === "assistant");
36
+ if (!hasAssistantMessage)
37
+ return;
38
+ // Use the built-in summarize endpoint to generate a title.
39
+ // Omitting body lets OpenCode use the default model.
40
+ await client.session.summarize({
41
+ path: { id: sessionId },
42
+ });
43
+ renamed.add(sessionId);
44
+ }
45
+ catch (err) {
46
+ // Log errors but don't crash the plugin
47
+ await client.app.log({
48
+ body: {
49
+ service: "auto-rename",
50
+ level: "warn",
51
+ message: `Failed to auto-rename session ${sessionId}: ${err}`,
52
+ },
53
+ });
54
+ }
55
+ },
56
+ };
57
+ };
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "opencode-auto-rename",
3
+ "version": "1.0.0",
4
+ "description": "OpenCode plugin that automatically renames conversations based on their content",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "scripts": {
11
+ "build": "tsc"
12
+ },
13
+ "keywords": [
14
+ "opencode",
15
+ "opencode-plugin",
16
+ "auto-rename"
17
+ ],
18
+ "license": "MIT",
19
+ "peerDependencies": {
20
+ "@opencode-ai/plugin": "*"
21
+ },
22
+ "devDependencies": {
23
+ "@opencode-ai/plugin": "latest",
24
+ "typescript": "^5.0.0"
25
+ }
26
+ }