opencode-cmux 0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Matteo Casonato
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,52 @@
1
+ # opencode-cmux
2
+
3
+ OpenCode plugin that bridges OpenCode events to cmux notifications and sidebar metadata.
4
+
5
+ ## Requirements
6
+
7
+ - OpenCode ≥ 1.0
8
+ - [cmux](https://cmux.app) (macOS app) installed with CLI accessible at `/usr/local/bin/cmux`
9
+ - The plugin is a no-op when not running inside a cmux workspace
10
+
11
+ ## Installation
12
+
13
+ ### npm (recommended)
14
+
15
+ Install the package and add it to `~/.config/opencode/opencode.json`:
16
+
17
+ ```bash
18
+ npm install -g opencode-cmux
19
+ ```
20
+
21
+ ```json
22
+ {
23
+ "plugin": ["opencode-cmux"]
24
+ }
25
+ ```
26
+
27
+ ### Local / development
28
+
29
+ Build the package, then symlink the output directly into OpenCode's plugin directory:
30
+
31
+ ```bash
32
+ ln -sf ~/path/to/opencode-cmux/dist/index.js ~/.config/opencode/plugins/cmux.js
33
+ ```
34
+
35
+ ## What it does
36
+
37
+ | Event | cmux action |
38
+ |---|---|
39
+ | Session starts working | Sidebar status: "working" (amber, terminal icon) |
40
+ | Session completes (primary) | Desktop notification + log + clear status |
41
+ | Session completes (subagent) | Log only (no notification spam) |
42
+ | Session error | Desktop notification + log + clear status |
43
+ | Permission requested | Desktop notification + sidebar status: "waiting" (red, lock icon) |
44
+ | AI has a question (`ask` tool) | Desktop notification + sidebar status: "question" (purple) |
45
+
46
+ ## How it works
47
+
48
+ The plugin responds to OpenCode lifecycle events by firing cmux CLI commands (`cmux notify`, `cmux set-status`, etc.). Each action targets the current cmux workspace, providing ambient awareness of what OpenCode is doing without requiring you to switch context. All commands are no-ops when cmux is not running.
49
+
50
+ ## License
51
+
52
+ MIT
package/dist/cmux.d.ts ADDED
@@ -0,0 +1,19 @@
1
+ import type { PluginInput } from "@opencode-ai/plugin";
2
+ type Shell = PluginInput["$"];
3
+ export declare function isInCmux(): boolean;
4
+ export declare function notify($: Shell, opts: {
5
+ title: string;
6
+ subtitle?: string;
7
+ body?: string;
8
+ }): Promise<void>;
9
+ export declare function setStatus($: Shell, key: string, text: string, opts?: {
10
+ icon?: string;
11
+ color?: string;
12
+ }): Promise<void>;
13
+ export declare function clearStatus($: Shell, key: string): Promise<void>;
14
+ export declare function log($: Shell, message: string, opts?: {
15
+ level?: "info" | "success" | "error" | "warn";
16
+ source?: string;
17
+ }): Promise<void>;
18
+ export {};
19
+ //# sourceMappingURL=cmux.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cmux.d.ts","sourceRoot":"","sources":["../src/cmux.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AAEtD,KAAK,KAAK,GAAG,WAAW,CAAC,GAAG,CAAC,CAAA;AAE7B,wBAAgB,QAAQ,IAAI,OAAO,CAKlC;AAED,wBAAsB,MAAM,CAC1B,CAAC,EAAE,KAAK,EACR,IAAI,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,GACxD,OAAO,CAAC,IAAI,CAAC,CAUf;AAED,wBAAsB,SAAS,CAC7B,CAAC,EAAE,KAAK,EACR,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,GACvC,OAAO,CAAC,IAAI,CAAC,CAUf;AAED,wBAAsB,WAAW,CAAC,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAOtE;AAED,wBAAsB,GAAG,CACvB,CAAC,EAAE,KAAK,EACR,OAAO,EAAE,MAAM,EACf,IAAI,CAAC,EAAE;IAAE,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,GAAG,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GACxE,OAAO,CAAC,IAAI,CAAC,CAef"}
@@ -0,0 +1,4 @@
1
+ import type { Plugin } from "@opencode-ai/plugin";
2
+ declare const plugin: Plugin;
3
+ export default plugin;
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAGjD,QAAA,MAAM,MAAM,EAAE,MAqFb,CAAA;AAED,eAAe,MAAM,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,125 @@
1
+ // src/cmux.ts
2
+ import { existsSync } from "node:fs";
3
+ function isInCmux() {
4
+ return existsSync(process.env.CMUX_SOCKET_PATH ?? "/tmp/cmux.sock") || !!process.env.CMUX_WORKSPACE_ID;
5
+ }
6
+ async function notify($, opts) {
7
+ if (!isInCmux())
8
+ return;
9
+ try {
10
+ const args = ["--title", opts.title];
11
+ if (opts.subtitle !== undefined)
12
+ args.push("--subtitle", opts.subtitle);
13
+ if (opts.body !== undefined)
14
+ args.push("--body", opts.body);
15
+ await $`cmux notify ${args}`.quiet().nothrow();
16
+ } catch {}
17
+ }
18
+ async function setStatus($, key, text, opts) {
19
+ if (!isInCmux())
20
+ return;
21
+ try {
22
+ const args = [key, text];
23
+ if (opts?.icon !== undefined)
24
+ args.push("--icon", opts.icon);
25
+ if (opts?.color !== undefined)
26
+ args.push("--color", opts.color);
27
+ await $`cmux set-status ${args}`.quiet().nothrow();
28
+ } catch {}
29
+ }
30
+ async function clearStatus($, key) {
31
+ if (!isInCmux())
32
+ return;
33
+ try {
34
+ await $`cmux clear-status ${key}`.quiet().nothrow();
35
+ } catch {}
36
+ }
37
+ async function log($, message, opts) {
38
+ if (!isInCmux())
39
+ return;
40
+ try {
41
+ const args = [];
42
+ if (opts?.level !== undefined) {
43
+ const level = opts.level === "warn" ? "warning" : opts.level;
44
+ args.push("--level", level);
45
+ }
46
+ if (opts?.source !== undefined)
47
+ args.push("--source", opts.source);
48
+ args.push("--", message);
49
+ await $`cmux log ${args}`.quiet().nothrow();
50
+ } catch {}
51
+ }
52
+
53
+ // src/index.ts
54
+ var plugin = async ({ client, $ }) => {
55
+ async function fetchSession(sessionID) {
56
+ try {
57
+ const result = await client.session.get({ path: { id: sessionID } });
58
+ if (result.data) {
59
+ return { title: result.data.title, parentID: result.data.parentID };
60
+ }
61
+ return null;
62
+ } catch {
63
+ return null;
64
+ }
65
+ }
66
+ return {
67
+ async event({ event }) {
68
+ if (event.type === "session.status") {
69
+ const { sessionID, status } = event.properties;
70
+ if (status.type === "busy") {
71
+ await setStatus($, "opencode", "working", {
72
+ icon: "terminal",
73
+ color: "#f59e0b"
74
+ });
75
+ return;
76
+ }
77
+ if (status.type === "idle") {
78
+ const session = await fetchSession(sessionID);
79
+ const title = session?.title ?? sessionID;
80
+ if (!session?.parentID) {
81
+ await notify($, { title: `Done: ${title}` });
82
+ await log($, `Done: ${title}`, { level: "success", source: "opencode" });
83
+ await clearStatus($, "opencode");
84
+ } else {
85
+ await log($, `Subagent finished: ${title}`, {
86
+ level: "info",
87
+ source: "opencode"
88
+ });
89
+ }
90
+ return;
91
+ }
92
+ }
93
+ if (event.type === "session.error") {
94
+ const sessionID = event.properties.sessionID;
95
+ const title = sessionID ? (await fetchSession(sessionID))?.title ?? sessionID : "unknown session";
96
+ await notify($, { title: `Error: ${title}` });
97
+ await log($, `Error in session: ${title}`, {
98
+ level: "error",
99
+ source: "opencode"
100
+ });
101
+ await clearStatus($, "opencode");
102
+ }
103
+ },
104
+ async "permission.ask"(input) {
105
+ await notify($, { title: "Needs your permission", subtitle: input.title });
106
+ await setStatus($, "opencode", "waiting", {
107
+ icon: "lock",
108
+ color: "#ef4444"
109
+ });
110
+ },
111
+ async "tool.execute.before"(input) {
112
+ if (input.tool === "ask") {
113
+ await notify($, { title: "Has a question" });
114
+ await setStatus($, "opencode", "question", {
115
+ icon: "help-circle",
116
+ color: "#a855f7"
117
+ });
118
+ }
119
+ }
120
+ };
121
+ };
122
+ var src_default = plugin;
123
+ export {
124
+ src_default as default
125
+ };
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/package.json",
3
+ "name": "opencode-cmux",
4
+ "version": "0.1.0",
5
+ "description": "OpenCode plugin that bridges OpenCode events to cmux notifications and sidebar metadata",
6
+ "type": "module",
7
+ "main": "dist/index.js",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.js",
11
+ "types": "./dist/index.d.ts"
12
+ }
13
+ },
14
+ "types": "dist/index.d.ts",
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "scripts": {
19
+ "build": "tsc --emitDeclarationOnly && bun build src/index.ts --outdir dist --target node",
20
+ "typecheck": "tsc --noEmit",
21
+ "prepublishOnly": "bun run typecheck && bun run build"
22
+ },
23
+ "keywords": [
24
+ "opencode",
25
+ "opencode-plugin",
26
+ "cmux"
27
+ ],
28
+ "author": "Matteo Casonato",
29
+ "license": "MIT",
30
+ "peerDependencies": {
31
+ "@opencode-ai/plugin": ">=1.0.0"
32
+ },
33
+ "devDependencies": {
34
+ "@opencode-ai/plugin": "^1.2.15",
35
+ "@types/node": "^25.3.1",
36
+ "typescript": "^5.9.3"
37
+ }
38
+ }