@alexsun-top/opencode-chat-room 0.1.2 → 0.2.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/CHANGELOG.md +15 -0
- package/README.md +17 -12
- package/README.zh-CN.md +17 -12
- package/index.ts +2 -0
- package/package.json +9 -4
- package/plugin.ts +147 -301
- package/server/chat-server.ts +128 -41
- package/src/center-client.ts +24 -528
- package/src/center-inbox.ts +106 -0
- package/src/center-wake.ts +118 -0
- package/src/plugin-notifications.ts +163 -0
- package/src/queue-transport.ts +129 -0
- package/src/queue.ts +14 -9
- package/src/store.ts +2 -0
- package/src/v1-plugin.ts +55 -0
- package/src/v2-plugin.ts +120 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
- Added V1 and V2 plugin entrypoints so the package works with both OpenCode plugin APIs.
|
|
6
|
+
- Added asynchronous V1 notifications and persistent-queue V2 delivery, plus recovery of unread messages after a destination becomes available again.
|
|
7
|
+
- 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.
|
|
8
|
+
- Excluded test files from the npm package.
|
|
9
|
+
- Updated central-server CLI examples to use `@alexsun-top/opencode-chat-room@0.2.0`.
|
|
10
|
+
|
|
11
|
+
### Verification
|
|
12
|
+
|
|
13
|
+
Local host checks 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; the packed runtime files match the current source. See the E2E report supplied with the release verification artifacts. V1 `prompt_async` reports acceptance, not durable queue admission.
|
|
14
|
+
|
|
15
|
+
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
|
-
-
|
|
10
|
-
- Incremental read watermark: `poll`
|
|
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,11 @@ 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"` —
|
|
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
|
|
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.
|
|
51
55
|
|
|
52
56
|
## Central mode (multi-host)
|
|
53
57
|
|
|
@@ -57,17 +61,17 @@ On the server machine, install Bun first. `npx`, `pnpx`, and `bunx` only execute
|
|
|
57
61
|
|
|
58
62
|
```bash
|
|
59
63
|
# Show CLI options:
|
|
60
|
-
npx --yes --package=@alexsun-top/opencode-chat-room@0.
|
|
64
|
+
npx --yes --package=@alexsun-top/opencode-chat-room@0.2.0 -- opencode-chat-room --help
|
|
61
65
|
|
|
62
66
|
# Start the local central server (choose any one runner):
|
|
63
|
-
npx --yes --package=@alexsun-top/opencode-chat-room@0.
|
|
64
|
-
pnpx --package=@alexsun-top/opencode-chat-room@0.
|
|
65
|
-
bunx @alexsun-top/opencode-chat-room@0.
|
|
67
|
+
npx --yes --package=@alexsun-top/opencode-chat-room@0.2.0 -- opencode-chat-room --host 0.0.0.0 --port 4399
|
|
68
|
+
pnpx --package=@alexsun-top/opencode-chat-room@0.2.0 opencode-chat-room --host 0.0.0.0 --port 4399
|
|
69
|
+
bunx @alexsun-top/opencode-chat-room@0.2.0 --host 0.0.0.0 --port 4399 --token secret
|
|
66
70
|
|
|
67
71
|
# Environment variables also work; CLI options take precedence:
|
|
68
72
|
CHAT_ROOM_SERVER_HOST=127.0.0.1 CHAT_ROOM_SERVER_PORT=4399 \
|
|
69
73
|
CHAT_ROOM_SERVER_TOKEN=secret \
|
|
70
|
-
bunx @alexsun-top/opencode-chat-room@0.
|
|
74
|
+
bunx @alexsun-top/opencode-chat-room@0.2.0
|
|
71
75
|
|
|
72
76
|
# Local checkout:
|
|
73
77
|
bun install
|
|
@@ -97,12 +101,13 @@ Then start opencode normally. Room state lives on the central server. Clients on
|
|
|
97
101
|
| `PORT` | server | Port alias, used when `CHAT_ROOM_SERVER_PORT` is unset | unset |
|
|
98
102
|
| `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
103
|
| `OPENCODE_SERVER_PASSWORD` | both | opencode server password; used for Basic auth on cross-session pushes | none |
|
|
104
|
+
| `CHAT_ROOM_WAKE_SERVE_URL` | client | Optional OpenCode serve URL used as a fallback for mentioned inactive sessions | unset |
|
|
100
105
|
|
|
101
106
|
## How notifications work
|
|
102
107
|
|
|
103
|
-
- **Standalone**:
|
|
104
|
-
- **Central**:
|
|
105
|
-
-
|
|
108
|
+
- **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.
|
|
109
|
+
- **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.
|
|
110
|
+
- Standalone V1 HTTP attempts are appended to `notify.log` (`OK <status> <url>` / `FAIL <reason>`). V2 queue admissions are not currently written there.
|
|
106
111
|
- Notifications include instructions for the agent: do not reply, do not call tools, unless explicitly addressed.
|
|
107
112
|
|
|
108
113
|
## 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>`
|
|
10
|
-
- 增量阅读水位:`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,11 @@
|
|
|
43
47
|
|
|
44
48
|
- 创建:让 agent「创建一个名为 dev 的聊天室」,或执行 `/room create dev`
|
|
45
49
|
- 带名字加入:`room join <房间ID> name:"alice"`——名字即你在该房间的身份(默认 `user@host`)
|
|
46
|
-
- 发消息:`room send <房间ID> "大家好"
|
|
50
|
+
- 发消息:`room send <房间ID> "大家好"`——其他已注册会话会通过宿主支持的方式收到 `<notification>`
|
|
47
51
|
- 读新消息:`room poll <房间ID>`——只返回未读部分,或者干脆等推送
|
|
48
52
|
- 其他:`room list` / `room members <房间ID>` / `room leave <房间ID>`
|
|
49
53
|
|
|
50
|
-
|
|
54
|
+
推送通知使用宿主支持的传输方式。V1 通知是普通异步 prompt;V2 通知进入持久会话队列。两者都只有在宿主接受通知后才推进未读水位。
|
|
51
55
|
|
|
52
56
|
## 中心模式(多主机)
|
|
53
57
|
|
|
@@ -57,17 +61,17 @@
|
|
|
57
61
|
|
|
58
62
|
```bash
|
|
59
63
|
# 查看 CLI 选项:
|
|
60
|
-
npx --yes --package=@alexsun-top/opencode-chat-room@0.
|
|
64
|
+
npx --yes --package=@alexsun-top/opencode-chat-room@0.2.0 -- opencode-chat-room --help
|
|
61
65
|
|
|
62
66
|
# 启动本地中心服务器(三选一):
|
|
63
|
-
npx --yes --package=@alexsun-top/opencode-chat-room@0.
|
|
64
|
-
pnpx --package=@alexsun-top/opencode-chat-room@0.
|
|
65
|
-
bunx @alexsun-top/opencode-chat-room@0.
|
|
67
|
+
npx --yes --package=@alexsun-top/opencode-chat-room@0.2.0 -- opencode-chat-room --host 0.0.0.0 --port 4399
|
|
68
|
+
pnpx --package=@alexsun-top/opencode-chat-room@0.2.0 opencode-chat-room --host 0.0.0.0 --port 4399
|
|
69
|
+
bunx @alexsun-top/opencode-chat-room@0.2.0 --host 0.0.0.0 --port 4399 --token secret
|
|
66
70
|
|
|
67
71
|
# 也可以使用环境变量;CLI 参数优先:
|
|
68
72
|
CHAT_ROOM_SERVER_HOST=127.0.0.1 CHAT_ROOM_SERVER_PORT=4399 \
|
|
69
73
|
CHAT_ROOM_SERVER_TOKEN=secret \
|
|
70
|
-
bunx @alexsun-top/opencode-chat-room@0.
|
|
74
|
+
bunx @alexsun-top/opencode-chat-room@0.2.0
|
|
71
75
|
|
|
72
76
|
# 本地 checkout:
|
|
73
77
|
bun install
|
|
@@ -97,12 +101,13 @@ export CHAT_ROOM_SERVER_TOKEN=secret # 仅当服务器设置了 token 时
|
|
|
97
101
|
| `PORT` | 服务器 | 端口别名,仅在未设置 `CHAT_ROOM_SERVER_PORT` 时使用 | 未设置 |
|
|
98
102
|
| `CHAT_ROOM_STATE_DIR` | 单机模式 | `rooms.json`/`registry.json` 所在目录——多主机单机模式可指向同一共享挂载 | `~/.config/opencode/chat-room/` |
|
|
99
103
|
| `OPENCODE_SERVER_PASSWORD` | 双端 | opencode 服务器密码;跨会话推送时用作 Basic 认证 | 无 |
|
|
104
|
+
| `CHAT_ROOM_WAKE_SERVE_URL` | 客户端 | 可选的 OpenCode serve 地址,用于兜底唤醒被提及的非活动会话 | 未设置 |
|
|
100
105
|
|
|
101
106
|
## 通知机制
|
|
102
107
|
|
|
103
|
-
-
|
|
104
|
-
-
|
|
105
|
-
-
|
|
108
|
+
- **单机模式**:V1 向已注册会话的服务发送异步 prompt;V2 轮询共享本地状态,并通过自身持久队列接收通知。只有宿主接受通知后才推进水位。
|
|
109
|
+
- **中心模式**:会话拉取 inbox(`GET /inbox?sessionID=…`),并通过宿主 API 接收 `<notification>`。消息按房间分组;V1 异步接受或 V2 成功入队后,才推进该房间的投递水位。
|
|
110
|
+
- 单机 V1 HTTP 推送尝试会追加到 `notify.log`(`OK <状态码> <URL>` / `FAIL <原因>`);V2 队列入队目前不会写入该日志。
|
|
106
111
|
- 通知中带有给 agent 的指令:不要回复、不要调用工具,除非被点名。
|
|
107
112
|
|
|
108
113
|
## 工具参考
|
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.
|
|
3
|
+
"version": "0.2.0",
|
|
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,19 @@
|
|
|
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.
|
|
45
|
-
"@opencode-ai/sdk": "1.18.16",
|
|
50
|
+
"@opencode-ai/plugin": "^1.18.29",
|
|
46
51
|
"zod": "4.1.8"
|
|
47
52
|
}
|
|
48
53
|
}
|