@alexsun-top/opencode-chat-room 0.1.3 → 0.2.1

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/CHANGELOG.md ADDED
@@ -0,0 +1,26 @@
1
+ # Changelog
2
+
3
+ ## 0.2.1
4
+
5
+ - On V2, messages that explicitly mention a registered room name can attempt to background that session's blocking shell or subagent work before routing the notification into the running session.
6
+ - Backgrounding is best-effort: it only targets the current OS user's registered service after PID and version checks. It does not start services or probe ports; if unavailable, normal queue delivery remains. Backgrounded tasks are not cancelled.
7
+ - Polling runs every five seconds. Retry and cross-instance serialization keep background attempts aligned with pending notifications.
8
+ - Fixed token storage fallback when browser storage rejects writes. Entering a token still requires clicking Save.
9
+
10
+ ### Verification
11
+
12
+ The production-only package loaded on OpenCode V1 `1.18.29` and V2 `2.0.29`. Real V2 host tests verified that mentioned foreground shell and subagent tasks moved to the background, messages were handled before their test gates opened, and the original work subsequently completed. Non-mentions, truncated name-prefix lookalikes, late mentions outside the displayed text, and a different registered-service PID did not trigger backgrounding. Tests used an isolated local mock model, not paid providers. Unit tests cover retry identity, background retries, concurrent delivery, and host identity checks.
13
+
14
+ ## 0.2.0
15
+
16
+ - Added V1 and V2 plugin entrypoints so the package works with both OpenCode plugin APIs.
17
+ - Added asynchronous V1 notifications and persistent-queue V2 delivery, plus recovery of unread messages after a destination becomes available again.
18
+ - Restricted polling and optional serve wakeups to sessions observed by a prompt hook or room tool. After restarting OpenCode, use `/room` or the room tool once in each session to resume polling.
19
+ - Excluded test files from the npm package.
20
+ - Updated central-server CLI examples to use `@alexsun-top/opencode-chat-room@0.2.0`.
21
+
22
+ ### Verification
23
+
24
+ Local host checks for 0.2.0 covered OpenCode V1 `1.18.29` and V2 `2.0.29`, using a deterministic mock provider without paid model requests. Both hosts exercised all seven room actions, `/room`, standalone and central notifications, failure recovery, and production-only package installation. See the E2E report supplied with those release verification artifacts. V1 `prompt_async` reports acceptance, not durable queue admission.
25
+
26
+ Existing limits remain: local shared-state writes are last-writer-wins across processes, and room history retains at most 500 messages.
package/README.md CHANGED
@@ -6,8 +6,8 @@ A chat-room plugin for [opencode](https://opencode.ai) that lets multiple sessio
6
6
 
7
7
  - 7 room actions: `create`, `join`, `leave`, `list`, `send`, `poll`, `members` (plus a `/room` command)
8
8
  - **Human web chat UI** served at `GET /chat` (central mode): humans join rooms in the browser and chat with agents on equal footing
9
- - Queue-delivered notifications wrapped in `<notification>…</notification>` so agents can tell push content apart from conversation and won't reply to it
10
- - Incremental read watermark: `poll` only returns messages you haven't seen; a successfully pushed message never repeats, and a failed push is recovered by the next `poll` — nothing is lost, nothing is duplicated
9
+ - Notifications wrapped in `<notification>…</notification>`; V2 uses the persistent session queue, while V1 uses asynchronous prompts
10
+ - Incremental read watermark: `poll` returns unread messages; failed notification attempts remain available for retry. V1 asynchronous acceptance does not guarantee durable delivery.
11
11
  - Two deployment modes: **standalone** (local/shared files, zero config) and **central** (one HTTP server, one env var per client)
12
12
  - Corruption-safe JSON persistence (atomic tmp+rename writes, automatic backup of unparseable files)
13
13
 
@@ -35,6 +35,10 @@ For a local checkout, use a file URL instead:
35
35
 
36
36
  Restart opencode. The `room` tool and the `/room` command are now available in every session.
37
37
 
38
+ ## OpenCode compatibility
39
+
40
+ This plugin supports OpenCode **1.18.29 and newer V1 releases**, plus the current V2 plugin API. Restart OpenCode after changing versions so it loads the matching plugin entrypoint. V1 uses the public `prompt_async` endpoint: a successful HTTP response means the notification was accepted for asynchronous processing, not durably queued. Both V1 and V2 poll only sessions observed by a prompt hook or room tool. After an OpenCode restart, use `/room` or the tool once in each session to resume polling. The optional serve fallback is also limited to sessions observed by that plugin instance. V2 does not assume a local server URL.
41
+
38
42
  ## Standalone mode (default)
39
43
 
40
44
  No configuration needed. All sessions on the same machine share state in `~/.config/opencode/chat-room/` (`rooms.json`, `registry.json`, `notify.log`).
@@ -43,11 +47,13 @@ Typical usage in a session:
43
47
 
44
48
  - Create: ask the agent to *"create a chat room named dev"*, or run `/room create dev`
45
49
  - Join with a name: `room join <roomId> name:"alice"` — the name is your identity in that room (defaults to `user@host`)
46
- - Send: `room send <roomId> "hello team"` — every other registered session gets a queued `<notification>`
50
+ - Send: `room send <roomId> "hello team"` — other registered sessions receive a host-appropriate `<notification>`
47
51
  - Read new messages: `room poll <roomId>` — only unread ones, or just wait for the push
48
52
  - `room list` / `room members <roomId>` / `room leave <roomId>`
49
53
 
50
- Push notifications travel over each session's embedded HTTP server. On one machine this works out of the box; the receiver's watermark only advances when a push actually succeeds (HTTP 2xx), otherwise the message stays unread for the next `poll`.
54
+ Push notifications use the host's supported transport. V1 notifications are ordinary asynchronous prompts; V2 notifications use the persistent session queue. In both cases the unread watermark advances only after the host accepts the notification.
55
+
56
+ On V2, an incoming message that explicitly mentions the registered room name (for example, `@alice`) first attempts to move that session's blocking shell or subagent work into the background, then steers the notification into the still-running session. This only targets the current OpenCode process: the plugin discovers the current OS user's registered service and verifies its PID and version before calling it. If no service is eligible or backgrounding fails, the notification uses the normal queue path; standalone or unregistered services therefore keep queue delivery. A session must still be a room member to receive notifications. No service is started and no ports are probed, and backgrounded tasks are not cancelled. Polling is every five seconds, so this is not instant push.
51
57
 
52
58
  ## Central mode (multi-host)
53
59
 
@@ -57,17 +63,17 @@ On the server machine, install Bun first. `npx`, `pnpx`, and `bunx` only execute
57
63
 
58
64
  ```bash
59
65
  # Show CLI options:
60
- npx --yes --package=@alexsun-top/opencode-chat-room@0.1.3 -- opencode-chat-room --help
66
+ npx --yes --package=@alexsun-top/opencode-chat-room@0.2.1 -- opencode-chat-room --help
61
67
 
62
68
  # Start the local central server (choose any one runner):
63
- npx --yes --package=@alexsun-top/opencode-chat-room@0.1.3 -- opencode-chat-room --host 0.0.0.0 --port 4399
64
- pnpx --package=@alexsun-top/opencode-chat-room@0.1.3 opencode-chat-room --host 0.0.0.0 --port 4399
65
- bunx @alexsun-top/opencode-chat-room@0.1.3 --host 0.0.0.0 --port 4399 --token secret
69
+ npx --yes --package=@alexsun-top/opencode-chat-room@0.2.1 -- opencode-chat-room --host 0.0.0.0 --port 4399
70
+ pnpx --package=@alexsun-top/opencode-chat-room@0.2.1 opencode-chat-room --host 0.0.0.0 --port 4399
71
+ bunx @alexsun-top/opencode-chat-room@0.2.1 --host 0.0.0.0 --port 4399 --token secret
66
72
 
67
73
  # Environment variables also work; CLI options take precedence:
68
74
  CHAT_ROOM_SERVER_HOST=127.0.0.1 CHAT_ROOM_SERVER_PORT=4399 \
69
75
  CHAT_ROOM_SERVER_TOKEN=secret \
70
- bunx @alexsun-top/opencode-chat-room@0.1.3
76
+ bunx @alexsun-top/opencode-chat-room@0.2.1
71
77
 
72
78
  # Local checkout:
73
79
  bun install
@@ -97,12 +103,13 @@ Then start opencode normally. Room state lives on the central server. Clients on
97
103
  | `PORT` | server | Port alias, used when `CHAT_ROOM_SERVER_PORT` is unset | unset |
98
104
  | `CHAT_ROOM_STATE_DIR` | standalone | Directory for `rooms.json`/`registry.json` — point several machines at one shared mount for standalone multi-host | `~/.config/opencode/chat-room/` |
99
105
  | `OPENCODE_SERVER_PASSWORD` | both | opencode server password; used for Basic auth on cross-session pushes | none |
106
+ | `CHAT_ROOM_WAKE_SERVE_URL` | client | Optional OpenCode serve URL used as a fallback for mentioned inactive sessions | unset |
100
107
 
101
108
  ## How notifications work
102
109
 
103
- - **Standalone**: the sender POSTs every unread message to each registered session's embedded server (`/api/session/:id/prompt`, `delivery: "queue"`). Successful pushes advance the receiver's watermark; failed ones leave it alone.
104
- - **Central**: each session pulls its inbox (`GET /inbox?sessionID=…`) and self-pushes a `<notification>` to its own session via `localhost`. Items are grouped per room: a room's watermark only advances when the whole room batch was pushed successfully.
105
- - Every push attempt is appended to `notify.log` (`OK <status> <url>` / `FAIL <reason>`) — check it when notifications seem missing.
110
+ - **Standalone**: V1 sends asynchronous prompts to registered session servers; V2 polls shared local state and admits notifications through its own persistent queue. The watermark advances only on host acceptance.
111
+ - **Central**: sessions pull their inbox (`GET /inbox?sessionID=…`) and admit `<notification>` messages through the host API. Items are grouped per room; a room's queued watermark advances only after admission.
112
+ - Standalone V1 HTTP attempts are appended to `notify.log` (`OK <status> <url>` / `FAIL <reason>`). V2 queue admissions are not currently written there.
106
113
  - Notifications include instructions for the agent: do not reply, do not call tools, unless explicitly addressed.
107
114
 
108
115
  ## Tool reference
package/README.zh-CN.md CHANGED
@@ -6,8 +6,8 @@
6
6
 
7
7
  - 7 种房间操作:`create`、`join`、`leave`、`list`、`send`、`poll`、`members`(另提供 `/room` 命令)
8
8
  - **真人 Web 聊天界面**:中心模式 `GET /chat`——真人可在浏览器中加入房间,与 agent 平等聊天
9
- - 通知以 `<notification>…</notification>` 包裹后经 queue 推送,agent 能区分推送内容与对话,且不会回复推送
10
- - 增量阅读水位:`poll` 只返回未读消息;已成功推送的消息不会重复,推送失败的消息由下一次 `poll` 兜底取回——不丢失、不重复
9
+ - 通知以 `<notification>…</notification>` 包裹;V2 使用持久会话队列,V1 使用异步 prompt
10
+ - 增量阅读水位:`poll` 返回未读消息;通知投递失败后仍可重试。V1 的异步接受不保证通知已持久化送达。
11
11
  - 两种部署模式:**单机模式**(本地/共享文件,零配置)与**中心模式**(一个 HTTP 服务 + 每个客户端一个环境变量)
12
12
  - 防损坏的 JSON 持久化(临时文件 + 原子 rename 写入,解析失败自动备份重建)
13
13
 
@@ -35,6 +35,10 @@
35
35
 
36
36
  重启 opencode。每个会话即可使用 `room` 工具和 `/room` 命令。
37
37
 
38
+ ## OpenCode 兼容性
39
+
40
+ 本插件支持 **OpenCode 1.18.29 及以上的 V1 版本**,以及当前 V2 插件 API。升级或切换版本后请重启 OpenCode,以加载对应入口。V1 使用公开的 `prompt_async` 接口:HTTP 成功表示通知已被异步处理接口接受,不代表已持久化入队。V1 和 V2 都只轮询被 prompt hook 或 room 工具观察到的会话。OpenCode 重启后,每个会话需再次使用工具或命令以恢复轮询。可选 serve 兜底同样只处理该插件实例观察到的会话。V2 不会假设本地服务 URL。
41
+
38
42
  ## 单机模式(默认)
39
43
 
40
44
  无需任何配置。同一台机器上的所有会话共享 `~/.config/opencode/chat-room/` 下的状态(`rooms.json`、`registry.json`、`notify.log`)。
@@ -43,11 +47,13 @@
43
47
 
44
48
  - 创建:让 agent「创建一个名为 dev 的聊天室」,或执行 `/room create dev`
45
49
  - 带名字加入:`room join <房间ID> name:"alice"`——名字即你在该房间的身份(默认 `user@host`)
46
- - 发消息:`room send <房间ID> "大家好"`——其他已注册会话都会收到一条 queue 推送的 `<notification>`
50
+ - 发消息:`room send <房间ID> "大家好"`——其他已注册会话会通过宿主支持的方式收到 `<notification>`
47
51
  - 读新消息:`room poll <房间ID>`——只返回未读部分,或者干脆等推送
48
52
  - 其他:`room list` / `room members <房间ID>` / `room leave <房间ID>`
49
53
 
50
- 推送通知通过各会话的嵌入式 HTTP 服务送达。单机场景开箱即用;只有推送真正成功(HTTP 2xx)才会推进接收方的水位,否则消息保持未读、留待下次 `poll`。
54
+ 推送通知使用宿主支持的传输方式。V1 通知是普通异步 prompt;V2 通知进入持久会话队列。两者都只有在宿主接受通知后才推进未读水位。
55
+
56
+ V2 收到明确提及房间注册名称的消息(例如 `@alice`)时,会先尝试将该会话中正在阻塞的 shell 或子 agent 工作移至后台,再将通知导向仍在运行的会话。此操作只针对当前 OpenCode 进程:插件发现当前操作系统用户注册的服务,并在调用前验证进程 PID 和版本。没有符合条件的服务或后台操作失败时,通知仍走普通队列;独立运行或未注册的服务会保留队列投递。会话仍需加入房间才能收到通知。插件不会启动服务或扫描端口,移至后台的任务也不会被取消。消息每五秒轮询一次,并非即时推送。
51
57
 
52
58
  ## 中心模式(多主机)
53
59
 
@@ -57,17 +63,17 @@
57
63
 
58
64
  ```bash
59
65
  # 查看 CLI 选项:
60
- npx --yes --package=@alexsun-top/opencode-chat-room@0.1.3 -- opencode-chat-room --help
66
+ npx --yes --package=@alexsun-top/opencode-chat-room@0.2.1 -- opencode-chat-room --help
61
67
 
62
68
  # 启动本地中心服务器(三选一):
63
- npx --yes --package=@alexsun-top/opencode-chat-room@0.1.3 -- opencode-chat-room --host 0.0.0.0 --port 4399
64
- pnpx --package=@alexsun-top/opencode-chat-room@0.1.3 opencode-chat-room --host 0.0.0.0 --port 4399
65
- bunx @alexsun-top/opencode-chat-room@0.1.3 --host 0.0.0.0 --port 4399 --token secret
69
+ npx --yes --package=@alexsun-top/opencode-chat-room@0.2.1 -- opencode-chat-room --host 0.0.0.0 --port 4399
70
+ pnpx --package=@alexsun-top/opencode-chat-room@0.2.1 opencode-chat-room --host 0.0.0.0 --port 4399
71
+ bunx @alexsun-top/opencode-chat-room@0.2.1 --host 0.0.0.0 --port 4399 --token secret
66
72
 
67
73
  # 也可以使用环境变量;CLI 参数优先:
68
74
  CHAT_ROOM_SERVER_HOST=127.0.0.1 CHAT_ROOM_SERVER_PORT=4399 \
69
75
  CHAT_ROOM_SERVER_TOKEN=secret \
70
- bunx @alexsun-top/opencode-chat-room@0.1.3
76
+ bunx @alexsun-top/opencode-chat-room@0.2.1
71
77
 
72
78
  # 本地 checkout:
73
79
  bun install
@@ -97,12 +103,13 @@ export CHAT_ROOM_SERVER_TOKEN=secret # 仅当服务器设置了 token 时
97
103
  | `PORT` | 服务器 | 端口别名,仅在未设置 `CHAT_ROOM_SERVER_PORT` 时使用 | 未设置 |
98
104
  | `CHAT_ROOM_STATE_DIR` | 单机模式 | `rooms.json`/`registry.json` 所在目录——多主机单机模式可指向同一共享挂载 | `~/.config/opencode/chat-room/` |
99
105
  | `OPENCODE_SERVER_PASSWORD` | 双端 | opencode 服务器密码;跨会话推送时用作 Basic 认证 | 无 |
106
+ | `CHAT_ROOM_WAKE_SERVE_URL` | 客户端 | 可选的 OpenCode serve 地址,用于兜底唤醒被提及的非活动会话 | 未设置 |
100
107
 
101
108
  ## 通知机制
102
109
 
103
- - **单机模式**:发送方把全部未读消息 POST 到每个已注册会话的嵌入式服务(`/api/session/:id/prompt`,`delivery: "queue"`)。推送成功才推进接收方水位,失败则不动。
104
- - **中心模式**:每个会话自行拉取 inbox(`GET /inbox?sessionID=…`),再经 `localhost` 向自己的会话自推 `<notification>`。消息按房间分组:整个房间批次全部推送成功才推进该房间的水位。
105
- - 每次推送尝试都会追加到 `notify.log`(`OK <状态码> <URL>` / `FAIL <原因>`)——通知疑似缺失时先看它。
110
+ - **单机模式**:V1 向已注册会话的服务发送异步 prompt;V2 轮询共享本地状态,并通过自身持久队列接收通知。只有宿主接受通知后才推进水位。
111
+ - **中心模式**:会话拉取 inbox(`GET /inbox?sessionID=…`),并通过宿主 API 接收 `<notification>`。消息按房间分组;V1 异步接受或 V2 成功入队后,才推进该房间的投递水位。
112
+ - 单机 V1 HTTP 推送尝试会追加到 `notify.log`(`OK <状态码> <URL>` / `FAIL <原因>`);V2 队列入队目前不会写入该日志。
106
113
  - 通知中带有给 agent 的指令:不要回复、不要调用工具,除非被点名。
107
114
 
108
115
  ## 工具参考
package/index.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  // ponytail: library surface — the room domain model; plugin wiring and
2
2
  // file persistence stay internal
3
+ export { default } from "./plugin";
4
+ export { id, server, setup } from "./plugin";
3
5
  export { default as RoomService, RoomError } from "./src/room-service";
4
6
  export type {
5
7
  Message,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alexsun-top/opencode-chat-room",
3
- "version": "0.1.3",
3
+ "version": "0.2.1",
4
4
  "description": "A chat-room plugin and central server for OpenCode.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -11,6 +11,7 @@
11
11
  "main": "./plugin.ts",
12
12
  "exports": {
13
13
  ".": "./index.ts",
14
+ "./server": "./plugin.ts",
14
15
  "./plugin": "./plugin.ts",
15
16
  "./chat-server": "./server/chat-server.ts"
16
17
  },
@@ -22,8 +23,10 @@
22
23
  "plugin.ts",
23
24
  "index.ts",
24
25
  "src",
26
+ "!src/**/*.test.ts",
25
27
  "server/chat-server.ts",
26
28
  "server/chat.html",
29
+ "CHANGELOG.md",
27
30
  "README.md",
28
31
  "README.zh-CN.md"
29
32
  ],
@@ -32,17 +35,20 @@
32
35
  "registry": "https://registry.npmjs.org/"
33
36
  },
34
37
  "scripts": {
35
- "server": "bun run server/chat-server.ts"
38
+ "server": "bun run server/chat-server.ts",
39
+ "test": "bun test",
40
+ "typecheck": "tsc --noEmit"
36
41
  },
37
42
  "devDependencies": {
43
+ "@opencode/plugin": "2.0.29",
38
44
  "@types/bun": "latest"
39
45
  },
40
46
  "peerDependencies": {
41
47
  "typescript": "^5"
42
48
  },
43
49
  "dependencies": {
44
- "@opencode-ai/plugin": "^1.18.16",
45
- "@opencode-ai/sdk": "1.18.16",
50
+ "@opencode-ai/plugin": "^1.18.29",
51
+ "@opencode/client": "2.0.32",
46
52
  "zod": "4.1.8"
47
53
  }
48
54
  }