@alexsun-top/opencode-chat-room 0.2.1 → 0.2.3
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 +20 -1
- package/README.md +29 -20
- package/README.zh-CN.md +27 -21
- package/cli.ts +26 -1
- package/package.json +4 -1
- package/plugin.ts +111 -135
- package/server/chat-server.ts +48 -328
- package/server/history-route.ts +25 -0
- package/server/inbox.ts +9 -0
- package/server/wake.ts +91 -0
- package/src/background.ts +67 -8
- package/src/center-client.ts +8 -2
- package/src/center-inbox.ts +99 -21
- package/src/center-wake.ts +2 -2
- package/src/plugin-notifications.ts +13 -6
- package/src/queue-transport.ts +7 -1
- package/src/queue.ts +17 -55
- package/src/receiver-owner.ts +37 -0
- package/src/receiver-state.ts +92 -0
- package/src/room-service.ts +2 -4
- package/src/session-delivery.ts +51 -0
- package/src/sqlite-state.ts +265 -0
- package/src/store.ts +29 -141
- package/src/v2-plugin.ts +17 -32
- package/src/v2-receiver.ts +109 -0
- package/src/watch.ts +355 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.3
|
|
4
|
+
|
|
5
|
+
- V2 room notifications steer the running session by default. Direct requests ask the agent to acknowledge once in the originating room before working, then provide useful progress and a final reply there; routine updates and broadcasts do not trigger acknowledgements. Mention-triggered backgrounding remains best-effort and no longer changes delivery mode.
|
|
6
|
+
- Notification prompts include the originating room ID. Steering takes effect at a safe boundary and does not cancel or guarantee detachment of blocking work; V1 `prompt_async` behavior is unchanged.
|
|
7
|
+
|
|
8
|
+
### Verification
|
|
9
|
+
|
|
10
|
+
The sanitized unit suite passed (68 tests). The production-only 0.2.3 archive installed with `--omit=dev`; isolated CLI version and watcher start/status/stop checks passed. An isolated OpenCode V2 `2.0.29` service with a deterministic local model admitted both a routine notification and an explicit mention as durable inbox events with `steer`. The scripted request used the room tool to acknowledge first, check membership, send progress, and send the final reply; the original shell task continued and completed. This exercises the prompt and tool flow with a deterministic model, not arbitrary model compliance. V1 `prompt_async` compatibility remains covered by tests.
|
|
11
|
+
|
|
12
|
+
## 0.2.2
|
|
13
|
+
|
|
14
|
+
- Replaced standalone and central room state with normalized SQLite, using cross-process write transactions. Valid legacy `rooms.json`/`registry.json` data is imported once; the originals remain untouched. Full message history is retained and read in bounded pages. SQLite WAL requires a local filesystem, not NFS/SMB.
|
|
15
|
+
- Added manual V2 resident watcher commands: `watch run`, `start`, `status`, and `stop`. The watcher retries discovery while OpenCode is offline and polls only memberships owned by the current user's registered V2 service. It does not start OpenCode, install OS startup services, or auto-start from room activity.
|
|
16
|
+
- Added private cross-process delivery leases and durable pending-admission records so the plugin and watcher coordinate retries. A crash after host admission but before cursor commit can retry the same admission; delivery is not exactly-once.
|
|
17
|
+
|
|
18
|
+
### Verification
|
|
19
|
+
|
|
20
|
+
Isolated real-host checks of the production-only 0.2.1 archive used OpenCode V1 `1.18.29` and V2 `2.0.29` with a localhost deterministic mock. The V2 watcher recovered offline, delivered a same-name `@` after 125 backlog messages without loading the plugin, and advanced the cursor; a concurrent plugin/watcher shell-gate test produced one admission and completed the original task. V1 loaded the room tool and command. Two SQLite writer processes persisted 500 messages across a new-process read. The 0.2.2 archive matches the checkout and production install in all 26 runtime files; relative to the host-tested 0.2.1 archive, only `cli.ts` help handling and `src/watch.ts` profile/control checks changed. The 0.2.2 production-installed CLI passed offline start/status/stop checks, and unit tests cover concurrent starts, stale recovery, and control-response validation. No paid model provider was used.
|
|
21
|
+
|
|
3
22
|
## 0.2.1
|
|
4
23
|
|
|
5
24
|
- 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.
|
|
@@ -23,4 +42,4 @@ The production-only package loaded on OpenCode V1 `1.18.29` and V2 `2.0.29`. Rea
|
|
|
23
42
|
|
|
24
43
|
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
44
|
|
|
26
|
-
|
|
45
|
+
In 0.2.0, JSON state writes were last-writer-wins across processes and room history was capped at 500 messages. SQLite transactions and persistent history replace those limits; JSON history already trimmed by older versions cannot be recovered.
|
package/README.md
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
# opencode-chat-room
|
|
2
2
|
|
|
3
|
-
A chat-room plugin for [opencode](https://opencode.ai) that lets multiple sessions — windows on one machine or agents across several hosts — talk to each other through shared rooms, with
|
|
3
|
+
A chat-room plugin for [opencode](https://opencode.ai) that lets multiple sessions — windows on one machine or agents across several hosts — talk to each other through shared rooms, with session-steered notifications.
|
|
4
4
|
|
|
5
5
|
## Features
|
|
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
|
-
- Notifications wrapped in `<notification>…</notification>`; V2
|
|
9
|
+
- Notifications wrapped in `<notification>…</notification>`; V2 steers the persistent session, while V1 uses asynchronous prompts
|
|
10
10
|
- Incremental read watermark: `poll` returns unread messages; failed notification attempts remain available for retry. V1 asynchronous acceptance does not guarantee durable delivery.
|
|
11
|
-
- Two deployment modes: **standalone** (local
|
|
12
|
-
-
|
|
11
|
+
- Two deployment modes: **standalone** (local SQLite, zero config) and **central** (one HTTP server, one env var per client)
|
|
12
|
+
- Normalized SQLite storage with transactional legacy JSON migration and append-only message history
|
|
13
13
|
|
|
14
14
|
## Installation
|
|
15
15
|
|
|
@@ -37,11 +37,15 @@ Restart opencode. The `room` tool and the `/room` command are now available in e
|
|
|
37
37
|
|
|
38
38
|
## OpenCode compatibility
|
|
39
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.
|
|
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. V1 polls only sessions observed by a prompt hook or room tool. V2 also restores explicitly joined sessions bound to the current user's verified local service. Existing memberships from earlier versions are not automatically claimed: rejoin each room once in the session you want the current V2 service to receive. Without the optional watcher, at least one project with the plugin loaded must remain open for polling. The owner binding is scoped to the current user's service URL and port; changing ports requires rejoining. Profiles that copy both OpenCode's session database and this private owner binding cannot be distinguished by the plugin.
|
|
41
41
|
|
|
42
42
|
## Standalone mode (default)
|
|
43
43
|
|
|
44
|
-
No configuration needed.
|
|
44
|
+
No configuration needed. State is stored in `~/.config/opencode/chat-room/chat-room.sqlite` (or the directory selected by `CHAT_ROOM_STATE_DIR`). On first use, valid `rooms.json` and `registry.json` files are migrated in one transaction and left untouched as backups. Messages are retained in SQLite; `room poll` returns up to 100 unread messages at a time, and the authenticated history endpoint supports keyset pages of up to 200 messages.
|
|
45
|
+
|
|
46
|
+
SQLite uses WAL and requires a local filesystem. Do not place standalone state on NFS/SMB or another shared network mount; use central mode for multi-host rooms. Messages already trimmed from old JSON files cannot be recovered.
|
|
47
|
+
|
|
48
|
+
Central deployments expose authenticated history pages at `GET /rooms/<roomId>/history?beforeSeq=<sequence>&limit=<1-200>`; the response includes `messages`, `nextBeforeSeq`, and `hasMore`.
|
|
45
49
|
|
|
46
50
|
Typical usage in a session:
|
|
47
51
|
|
|
@@ -51,9 +55,15 @@ Typical usage in a session:
|
|
|
51
55
|
- Read new messages: `room poll <roomId>` — only unread ones, or just wait for the push
|
|
52
56
|
- `room list` / `room members <roomId>` / `room leave <roomId>`
|
|
53
57
|
|
|
54
|
-
Push notifications use the host's supported transport. V1 notifications are ordinary asynchronous prompts; V2 notifications
|
|
58
|
+
Push notifications use the host's supported transport. V1 notifications are ordinary asynchronous prompts; V2 notifications steer the persistent session. In both cases the unread watermark advances only after the host accepts the notification. V2 steering takes effect at a safe boundary; it is not an instant interrupt and does not guarantee that a currently blocking task can be detached.
|
|
59
|
+
|
|
60
|
+
On V2, every notification steers the session when observed. 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. 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, steering still proceeds. A session must still be a room member to receive notifications; only explicitly mentioned sessions can be restored by the watcher when OpenCode is not running. 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.
|
|
61
|
+
|
|
62
|
+
For a direct request, the notification asks the agent to acknowledge it once in the originating room before working, then send useful progress updates and its final response there. Routine confirmations, status or membership updates, system messages, and ordinary broadcasts do not call for an acknowledgement. The prompt includes the room ID so the agent can address the right room.
|
|
63
|
+
|
|
64
|
+
### Resident V2 watcher
|
|
55
65
|
|
|
56
|
-
|
|
66
|
+
Run `opencode-chat-room watch start` to keep V2 delivery polling after the project that loaded the plugin closes. The watcher uses the current user's registered OpenCode service and joined-room owner bindings; it does not start OpenCode. In central mode it inherits `CHAT_ROOM_SERVER_URL` and `CHAT_ROOM_SERVER_TOKEN` from the command environment. If the service is offline, it stays running and retries. `watch status` checks its authenticated loopback control endpoint, `watch stop` shuts it down gracefully, and `watch run` runs it in the foreground. Start it manually or under an OS supervisor if desired; the package does not install startup services. The watcher also does not auto-start when you send or receive a message. Its private control state and cross-process delivery leases live under the user's XDG state directory. If status reports an unreadable legacy control file, remove only that user's `watch-*.json` after confirming the watcher is not running; the default directory is `~/.local/state/opencode/chat-room`.
|
|
57
67
|
|
|
58
68
|
## Central mode (multi-host)
|
|
59
69
|
|
|
@@ -63,17 +73,17 @@ On the server machine, install Bun first. `npx`, `pnpx`, and `bunx` only execute
|
|
|
63
73
|
|
|
64
74
|
```bash
|
|
65
75
|
# Show CLI options:
|
|
66
|
-
npx --yes --package=@alexsun-top/opencode-chat-room@0.2.
|
|
76
|
+
npx --yes --package=@alexsun-top/opencode-chat-room@0.2.3 -- opencode-chat-room --help
|
|
67
77
|
|
|
68
78
|
# Start the local central server (choose any one runner):
|
|
69
|
-
npx --yes --package=@alexsun-top/opencode-chat-room@0.2.
|
|
70
|
-
pnpx --package=@alexsun-top/opencode-chat-room@0.2.
|
|
71
|
-
bunx @alexsun-top/opencode-chat-room@0.2.
|
|
79
|
+
npx --yes --package=@alexsun-top/opencode-chat-room@0.2.3 -- opencode-chat-room --host 0.0.0.0 --port 4399
|
|
80
|
+
pnpx --package=@alexsun-top/opencode-chat-room@0.2.3 opencode-chat-room --host 0.0.0.0 --port 4399
|
|
81
|
+
bunx @alexsun-top/opencode-chat-room@0.2.3 --host 0.0.0.0 --port 4399 --token secret
|
|
72
82
|
|
|
73
83
|
# Environment variables also work; CLI options take precedence:
|
|
74
84
|
CHAT_ROOM_SERVER_HOST=127.0.0.1 CHAT_ROOM_SERVER_PORT=4399 \
|
|
75
85
|
CHAT_ROOM_SERVER_TOKEN=secret \
|
|
76
|
-
bunx @alexsun-top/opencode-chat-room@0.2.
|
|
86
|
+
bunx @alexsun-top/opencode-chat-room@0.2.3
|
|
77
87
|
|
|
78
88
|
# Local checkout:
|
|
79
89
|
bun install
|
|
@@ -101,15 +111,15 @@ Then start opencode normally. Room state lives on the central server. Clients on
|
|
|
101
111
|
| `HOST` | server | Host alias, used when `CHAT_ROOM_SERVER_HOST` is unset | unset |
|
|
102
112
|
| `CHAT_ROOM_SERVER_PORT` | server | Central server listen port; takes precedence over `PORT` | `4399` |
|
|
103
113
|
| `PORT` | server | Port alias, used when `CHAT_ROOM_SERVER_PORT` is unset | unset |
|
|
104
|
-
| `CHAT_ROOM_STATE_DIR` | standalone |
|
|
114
|
+
| `CHAT_ROOM_STATE_DIR` | standalone | Local directory for `chat-room.sqlite` and legacy JSON migration files; keep it on a local filesystem | `~/.config/opencode/chat-room/` |
|
|
105
115
|
| `OPENCODE_SERVER_PASSWORD` | both | opencode server password; used for Basic auth on cross-session pushes | none |
|
|
106
116
|
| `CHAT_ROOM_WAKE_SERVE_URL` | client | Optional OpenCode serve URL used as a fallback for mentioned inactive sessions | unset |
|
|
107
117
|
|
|
108
118
|
## How notifications work
|
|
109
119
|
|
|
110
|
-
- **Standalone**: V1 sends asynchronous prompts to registered session servers; V2 polls shared local state and
|
|
111
|
-
- **Central**: sessions pull their inbox (`GET /inbox?sessionID=…`) and
|
|
112
|
-
- Standalone V1 HTTP attempts are appended to `notify.log` (`OK <status> <url>` / `FAIL <reason>`). V2
|
|
120
|
+
- **Standalone**: V1 sends asynchronous prompts to registered session servers; V2 polls shared local state and steers notifications through its persistent session API. The watermark advances only on host acceptance.
|
|
121
|
+
- **Central**: sessions pull their inbox (`GET /inbox?sessionID=…`) and steer `<notification>` messages through the host API. Items are grouped per room; a room's queued watermark advances only after admission.
|
|
122
|
+
- Standalone V1 HTTP attempts are appended to `notify.log` (`OK <status> <url>` / `FAIL <reason>`). V2 notification admissions are not currently written there.
|
|
113
123
|
- Notifications include instructions for the agent: do not reply, do not call tools, unless explicitly addressed.
|
|
114
124
|
|
|
115
125
|
## Tool reference
|
|
@@ -128,9 +138,8 @@ Note: `join` with `name:"alice"` registers the identity `alice` for that session
|
|
|
128
138
|
|
|
129
139
|
## Limitations
|
|
130
140
|
|
|
131
|
-
- Standalone mode
|
|
132
|
-
- Shared-directory multi-host standalone compares timestamps, so machines must be NTP-synced. Central mode is unaffected (the server timestamps messages).
|
|
141
|
+
- Standalone mode uses a local SQLite database with cross-process write transactions. Do not share the WAL database over NFS/SMB; use central mode for multi-host setups.
|
|
133
142
|
- Sessions on the same machine share the host identity (`user@host`); pass distinct `name` values on join to tell members apart.
|
|
134
143
|
- The central server is unauthenticated unless `CHAT_ROOM_SERVER_TOKEN` is set — anyone who can reach the port can read/write rooms. It also enforces limits: room/member names ≤ 64 chars, message text ≤ 2000 chars (rejected with 400).
|
|
135
|
-
-
|
|
144
|
+
- SQLite retains message history without automatic deletion. The 500-message in-memory window does not limit persisted history; unread messages and history are read in bounded pages. Back up the database regularly.
|
|
136
145
|
- `notify.log` grows without rotation.
|
package/README.zh-CN.md
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
# opencode-chat-room
|
|
2
2
|
|
|
3
|
-
一个 [opencode](https://opencode.ai) 聊天室插件:让多个会话——同一台机器的多个窗口,或多台主机上的多个 agent——通过共享房间互相交流,并支持
|
|
3
|
+
一个 [opencode](https://opencode.ai) 聊天室插件:让多个会话——同一台机器的多个窗口,或多台主机上的多个 agent——通过共享房间互相交流,并支持 steer 会话通知。
|
|
4
4
|
|
|
5
5
|
## 特性
|
|
6
6
|
|
|
7
7
|
- 7 种房间操作:`create`、`join`、`leave`、`list`、`send`、`poll`、`members`(另提供 `/room` 命令)
|
|
8
8
|
- **真人 Web 聊天界面**:中心模式 `GET /chat`——真人可在浏览器中加入房间,与 agent 平等聊天
|
|
9
|
-
- 通知以 `<notification>…</notification>` 包裹;V2
|
|
9
|
+
- 通知以 `<notification>…</notification>` 包裹;V2 steer 持久会话,V1 使用异步 prompt
|
|
10
10
|
- 增量阅读水位:`poll` 返回未读消息;通知投递失败后仍可重试。V1 的异步接受不保证通知已持久化送达。
|
|
11
|
-
-
|
|
12
|
-
-
|
|
11
|
+
- 两种部署模式:**单机模式**(本地 SQLite,零配置)与**中心模式**(一个 HTTP 服务 + 每个客户端一个环境变量)
|
|
12
|
+
- 规范化 SQLite 持久化、事务式迁移旧 JSON,并保留完整追加式消息历史
|
|
13
13
|
|
|
14
14
|
## 安装
|
|
15
15
|
|
|
@@ -37,11 +37,13 @@
|
|
|
37
37
|
|
|
38
38
|
## OpenCode 兼容性
|
|
39
39
|
|
|
40
|
-
本插件支持 **OpenCode 1.18.29 及以上的 V1 版本**,以及当前 V2 插件 API。升级或切换版本后请重启 OpenCode,以加载对应入口。V1 使用公开的 `prompt_async` 接口:HTTP 成功表示通知已被异步处理接口接受,不代表已持久化入队。V1
|
|
40
|
+
本插件支持 **OpenCode 1.18.29 及以上的 V1 版本**,以及当前 V2 插件 API。升级或切换版本后请重启 OpenCode,以加载对应入口。V1 使用公开的 `prompt_async` 接口:HTTP 成功表示通知已被异步处理接口接受,不代表已持久化入队。V1 仅轮询被 prompt hook 或 room 工具观察到的会话。V2 还会恢复绑定到当前用户已验证本地服务的显式加入会话。旧版本已有的成员关系不会自动认领:请在希望接收通知的会话中将每个房间重新加入一次。不使用可选 watcher 时,至少需要一个已加载插件的项目保持打开,以运行接收器。所有者绑定范围是当前用户的服务 URL 和端口;修改端口后需重新加入。若配置文件同时复制了 OpenCode 会话数据库和此私有绑定文件,插件无法区分这些配置文件。
|
|
41
41
|
|
|
42
42
|
## 单机模式(默认)
|
|
43
43
|
|
|
44
|
-
|
|
44
|
+
无需任何配置。同一台机器上的会话将状态保存在 `~/.config/opencode/chat-room/chat-room.sqlite`(也可用 `CHAT_ROOM_STATE_DIR` 指定目录)。首次使用时会在一个事务中迁移有效的 `rooms.json`/`registry.json`,原文件保留。SQLite 保存完整消息历史;`room poll` 每次最多返回 100 条未读消息。
|
|
45
|
+
|
|
46
|
+
SQLite WAL 需要本地文件系统。不要把单机状态放在 NFS/SMB 等网络共享盘;多主机请使用中心模式。旧 JSON 已经裁剪掉的消息无法恢复。中心模式提供需认证的历史分页接口 `GET /rooms/<房间ID>/history?beforeSeq=<序号>&limit=<1-200>`,响应包含 `messages`、`nextBeforeSeq` 和 `hasMore`。
|
|
45
47
|
|
|
46
48
|
典型用法:
|
|
47
49
|
|
|
@@ -51,9 +53,15 @@
|
|
|
51
53
|
- 读新消息:`room poll <房间ID>`——只返回未读部分,或者干脆等推送
|
|
52
54
|
- 其他:`room list` / `room members <房间ID>` / `room leave <房间ID>`
|
|
53
55
|
|
|
54
|
-
推送通知使用宿主支持的传输方式。V1 通知是普通异步 prompt;V2
|
|
56
|
+
推送通知使用宿主支持的传输方式。V1 通知是普通异步 prompt;V2 通知通过持久会话 API steer。两者都只有在宿主接受通知后才推进未读水位。V2 steer 会在安全边界生效,并非即时打断,也不保证正在阻塞的任务一定能够移至后台。
|
|
57
|
+
|
|
58
|
+
V2 在观察到通知时都会 steer 会话。收到明确提及房间注册名称的消息(例如 `@alice`)时,还会先尝试将该会话中正在阻塞的 shell 或子 agent 工作移至后台。此操作只针对当前 OpenCode 进程:插件发现当前操作系统用户注册的服务,并在调用前验证进程 PID 和版本。没有符合条件的服务或后台操作失败时,仍会 steer。会话仍需加入房间才能收到通知;OpenCode 未运行时,watcher 只会恢复明确被提及的会话。插件不会启动服务或扫描端口,移至后台的任务也不会被取消。消息每五秒轮询一次,并非即时推送。
|
|
59
|
+
|
|
60
|
+
对于直接请求,通知会要求 agent 先在原房间发送一次简短确认,再开始处理,之后可发送有用的进度更新和最终回复。例行确认、状态或成员变更、系统消息及普通广播不需要确认。提示中包含房间 ID,确保回复发往正确房间。
|
|
61
|
+
|
|
62
|
+
### V2 常驻 watcher
|
|
55
63
|
|
|
56
|
-
|
|
64
|
+
运行 `opencode-chat-room watch start`,即可在关闭加载插件的项目后继续轮询 V2 消息。Watcher 使用当前用户已注册的 OpenCode 服务及已加入房间的所有者绑定,不会启动 OpenCode。中心模式下会继承执行该命令时的 `CHAT_ROOM_SERVER_URL` 和 `CHAT_ROOM_SERVER_TOKEN`。服务离线时,watcher 会继续运行并重试。`watch status` 检查经过认证的本机回环控制接口,`watch stop` 会优雅停止,`watch run` 则在前台运行。可手动启动,也可交由操作系统的进程管理器监督;包不会安装开机启动服务,也不会在消息收发时自动启动 watcher。私有控制状态和跨进程投递租约保存在用户的 XDG 状态目录中。若状态显示控制文件无法读取,请确认 watcher 已停止后,仅删除该用户的 `watch-*.json`;默认目录为 `~/.local/state/opencode/chat-room`。
|
|
57
65
|
|
|
58
66
|
## 中心模式(多主机)
|
|
59
67
|
|
|
@@ -63,17 +71,17 @@ V2 收到明确提及房间注册名称的消息(例如 `@alice`)时,会
|
|
|
63
71
|
|
|
64
72
|
```bash
|
|
65
73
|
# 查看 CLI 选项:
|
|
66
|
-
npx --yes --package=@alexsun-top/opencode-chat-room@0.2.
|
|
74
|
+
npx --yes --package=@alexsun-top/opencode-chat-room@0.2.3 -- opencode-chat-room --help
|
|
67
75
|
|
|
68
76
|
# 启动本地中心服务器(三选一):
|
|
69
|
-
npx --yes --package=@alexsun-top/opencode-chat-room@0.2.
|
|
70
|
-
pnpx --package=@alexsun-top/opencode-chat-room@0.2.
|
|
71
|
-
bunx @alexsun-top/opencode-chat-room@0.2.
|
|
77
|
+
npx --yes --package=@alexsun-top/opencode-chat-room@0.2.3 -- opencode-chat-room --host 0.0.0.0 --port 4399
|
|
78
|
+
pnpx --package=@alexsun-top/opencode-chat-room@0.2.3 opencode-chat-room --host 0.0.0.0 --port 4399
|
|
79
|
+
bunx @alexsun-top/opencode-chat-room@0.2.3 --host 0.0.0.0 --port 4399 --token secret
|
|
72
80
|
|
|
73
81
|
# 也可以使用环境变量;CLI 参数优先:
|
|
74
82
|
CHAT_ROOM_SERVER_HOST=127.0.0.1 CHAT_ROOM_SERVER_PORT=4399 \
|
|
75
83
|
CHAT_ROOM_SERVER_TOKEN=secret \
|
|
76
|
-
bunx @alexsun-top/opencode-chat-room@0.2.
|
|
84
|
+
bunx @alexsun-top/opencode-chat-room@0.2.3
|
|
77
85
|
|
|
78
86
|
# 本地 checkout:
|
|
79
87
|
bun install
|
|
@@ -101,16 +109,15 @@ export CHAT_ROOM_SERVER_TOKEN=secret # 仅当服务器设置了 token 时
|
|
|
101
109
|
| `HOST` | 服务器 | 主机名别名,仅在未设置 `CHAT_ROOM_SERVER_HOST` 时使用 | 未设置 |
|
|
102
110
|
| `CHAT_ROOM_SERVER_PORT` | 服务器 | 中心服务器监听端口;优先于 `PORT` | `4399` |
|
|
103
111
|
| `PORT` | 服务器 | 端口别名,仅在未设置 `CHAT_ROOM_SERVER_PORT` 时使用 | 未设置 |
|
|
104
|
-
| `CHAT_ROOM_STATE_DIR` | 单机模式 |
|
|
112
|
+
| `CHAT_ROOM_STATE_DIR` | 单机模式 | SQLite 数据库及迁移源 JSON 文件所在目录;必须位于本地文件系统 | `~/.config/opencode/chat-room/` |
|
|
105
113
|
| `OPENCODE_SERVER_PASSWORD` | 双端 | opencode 服务器密码;跨会话推送时用作 Basic 认证 | 无 |
|
|
106
114
|
| `CHAT_ROOM_WAKE_SERVE_URL` | 客户端 | 可选的 OpenCode serve 地址,用于兜底唤醒被提及的非活动会话 | 未设置 |
|
|
107
115
|
|
|
108
116
|
## 通知机制
|
|
109
117
|
|
|
110
|
-
- **单机模式**:V1 向已注册会话的服务发送异步 prompt;V2
|
|
111
|
-
- **中心模式**:会话拉取 inbox(`GET /inbox?sessionID=…`),并通过宿主 API
|
|
112
|
-
- 单机 V1 HTTP 推送尝试会追加到 `notify.log`(`OK <状态码> <URL>` / `FAIL <原因>`);V2
|
|
113
|
-
- 通知中带有给 agent 的指令:不要回复、不要调用工具,除非被点名。
|
|
118
|
+
- **单机模式**:V1 向已注册会话的服务发送异步 prompt;V2 轮询共享本地状态,并通过持久会话 API steer 通知。只有宿主接受通知后才推进水位。
|
|
119
|
+
- **中心模式**:会话拉取 inbox(`GET /inbox?sessionID=…`),并通过宿主 API steer `<notification>`。消息按房间分组;V1 异步接受或 V2 成功接收后,才推进该房间的投递水位。
|
|
120
|
+
- 单机 V1 HTTP 推送尝试会追加到 `notify.log`(`OK <状态码> <URL>` / `FAIL <原因>`);V2 推送目前不会写入该日志。
|
|
114
121
|
|
|
115
122
|
## 工具参考
|
|
116
123
|
|
|
@@ -128,9 +135,8 @@ export CHAT_ROOM_SERVER_TOKEN=secret # 仅当服务器设置了 token 时
|
|
|
128
135
|
|
|
129
136
|
## 已知限制
|
|
130
137
|
|
|
131
|
-
-
|
|
132
|
-
- 共享目录的多主机单机模式依赖时间戳比较,各机器需 NTP 对时。中心模式不受影响(由服务器统一打时间戳)。
|
|
138
|
+
- 单机模式通过 SQLite WAL 和跨进程事务保存状态。数据库必须位于本地文件系统;多主机场景请使用中心模式,不要共享 WAL 数据库目录。
|
|
133
139
|
- 同一台机器的会话共享 `user@host` 身份;用不同的 `name` 加入以区分成员。
|
|
134
140
|
- 中心服务器不设 `CHAT_ROOM_SERVER_TOKEN` 时无认证——任何能访问端口的人都能读写房间。服务端另有输入限制:房间/成员名 ≤ 64 字符、消息文本 ≤ 2000 字符(超限返回 400)。
|
|
135
|
-
-
|
|
141
|
+
- SQLite 持续保留历史消息,不自动删除。500 条只是内存工作窗口,不是磁盘保留上限;未读消息和历史记录均分页读取。请定期备份数据库。
|
|
136
142
|
- `notify.log` 会持续增长,暂无轮转。
|
package/cli.ts
CHANGED
|
@@ -7,7 +7,10 @@ Options:
|
|
|
7
7
|
-v, --version Show the package version
|
|
8
8
|
-H, --host <host> Bind hostname
|
|
9
9
|
-p, --port <port> Bind port (1-65535)
|
|
10
|
-
-t, --token <token> Enable bearer token authentication
|
|
10
|
+
-t, --token <token> Enable bearer token authentication
|
|
11
|
+
|
|
12
|
+
Commands:
|
|
13
|
+
watch run|start|status|stop`;
|
|
11
14
|
|
|
12
15
|
type ValueOption = "host" | "port" | "token";
|
|
13
16
|
const values: Partial<Record<ValueOption, string>> = {};
|
|
@@ -34,6 +37,28 @@ function validatePort(value: string): void {
|
|
|
34
37
|
}
|
|
35
38
|
|
|
36
39
|
const args = process.argv.slice(2);
|
|
40
|
+
if (args[0] === "watch") {
|
|
41
|
+
const action = args[1];
|
|
42
|
+
if ((args.length === 2 && (action === "help" || action === "--help")) ||
|
|
43
|
+
(args.length === 3 && args[2] === "--help")) {
|
|
44
|
+
console.log("Usage: opencode-chat-room watch run|start|status|stop");
|
|
45
|
+
process.exit(0);
|
|
46
|
+
}
|
|
47
|
+
if (args.length !== 2 || !["run", "start", "status", "stop"].includes(action ?? "")) {
|
|
48
|
+
fail("Expected watch run, start, status, or stop");
|
|
49
|
+
}
|
|
50
|
+
const watcher = await import("./src/watch");
|
|
51
|
+
try {
|
|
52
|
+
if (action === "run") await watcher.runWatcher();
|
|
53
|
+
else if (action === "start") console.log(await watcher.startWatcher());
|
|
54
|
+
else if (action === "status") console.log(await watcher.watchStatus());
|
|
55
|
+
else console.log(await watcher.stopWatcher());
|
|
56
|
+
} catch (error) {
|
|
57
|
+
console.error(`watch: ${error instanceof Error ? error.message : "operation failed"}`);
|
|
58
|
+
process.exitCode = 1;
|
|
59
|
+
}
|
|
60
|
+
process.exit(process.exitCode ?? 0);
|
|
61
|
+
}
|
|
37
62
|
for (let i = 0; i < args.length; i += 1) {
|
|
38
63
|
const arg = args[i]!;
|
|
39
64
|
if (arg === "-h" || arg === "--help") {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alexsun-top/opencode-chat-room",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "A chat-room plugin and central server for OpenCode.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -25,6 +25,9 @@
|
|
|
25
25
|
"src",
|
|
26
26
|
"!src/**/*.test.ts",
|
|
27
27
|
"server/chat-server.ts",
|
|
28
|
+
"server/inbox.ts",
|
|
29
|
+
"server/history-route.ts",
|
|
30
|
+
"server/wake.ts",
|
|
28
31
|
"server/chat.html",
|
|
29
32
|
"CHANGELOG.md",
|
|
30
33
|
"README.md",
|