@alexsun-top/opencode-chat-room 0.5.2 → 0.5.4

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.
Files changed (46) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/README.md +28 -215
  3. package/README.zh-CN.md +27 -209
  4. package/docs/administrator-rooms.md +6 -22
  5. package/package.json +1 -4
  6. package/plugin.ts +1 -1
  7. package/server/admin-auth.ts +4 -2
  8. package/server/admin-routes.ts +2 -11
  9. package/server/admin-state.ts +15 -4
  10. package/server/assets/base.css +1 -1
  11. package/server/assets/chat/admin.js +30 -123
  12. package/server/assets/chat/announcements.js +17 -1
  13. package/server/assets/chat/attachments.js +4 -1
  14. package/server/assets/chat/editor.js +65 -15
  15. package/server/assets/chat/events.js +12 -7
  16. package/server/assets/chat/markdown.js +31 -11
  17. package/server/assets/chat/mentions.js +3 -1
  18. package/server/assets/chat/messages.js +55 -20
  19. package/server/assets/chat/questions.js +15 -4
  20. package/server/assets/chat/reminders.js +4 -3
  21. package/server/assets/chat/replies.js +2 -1
  22. package/server/assets/chat/room-watcher.js +45 -0
  23. package/server/assets/chat/rooms.js +62 -69
  24. package/server/assets/chat/state.js +8 -6
  25. package/server/assets/conversation.css +8 -5
  26. package/server/assets/responsive.css +5 -12
  27. package/server/chat-server.ts +26 -37
  28. package/server/chat.html +3 -10
  29. package/server/member-routes.ts +9 -11
  30. package/server/room-reminders.ts +15 -5
  31. package/server/wake.ts +11 -2
  32. package/skills/chatroom/SKILL.md +3 -7
  33. package/src/admin-client.ts +8 -45
  34. package/src/admin-credentials.ts +0 -19
  35. package/src/center-inbox.ts +0 -2
  36. package/src/mentions.ts +2 -1
  37. package/src/plugin-notifications.ts +4 -3
  38. package/src/resource-upload.ts +1 -1
  39. package/src/resources.ts +4 -1
  40. package/src/sqlite-state.ts +40 -0
  41. package/src/store.ts +4 -1
  42. package/src/v2-plugin.ts +1 -1
  43. package/server/admin-plan-routes.ts +0 -79
  44. package/server/admin-scheduler.ts +0 -42
  45. package/server/admin-task-routes.ts +0 -182
  46. package/src/supervision-inbox.ts +0 -62
package/CHANGELOG.md CHANGED
@@ -1,5 +1,34 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.5.4 — 2026-11-11
4
+
5
+ - Keep unanswered questions unread, including when they are answered from another room, and stop own messages from raising unread counts. The sidebar badge now clears once the conversation is read.
6
+ - Fix the first character being dropped when typing with an IME, and keep the caret stable after inserting a mention.
7
+ - Merge a send response with the polling result so a stale snapshot no longer erases newer messages.
8
+ - Make timestamps increase monotonically inside the write transaction and resume long polling from the exact cursor.
9
+ - Write sends, read acknowledgements, and queued watermarks directly instead of rewriting the whole state file.
10
+ - Keep per-room drafts, including mentions, and restore them after a reload.
11
+ - Show the next run only for recurring reminders; one-shot reminders show just their trigger time.
12
+ - Preview attachments you sent automatically and keep other people's attachments collapsed.
13
+ - Increase text selection contrast with an inverted accent background in both themes.
14
+ - Designate administrators in one step: the designation applies immediately and stays until revoked. The enrollment code and claim step are gone; existing claimed capabilities keep working.
15
+ - Render AVIF images and show a visible banner when an attachment upload fails.
16
+ - Keep the attachment preview toggle clickable and correctly labelled while a preview loads, and clear a preview that cannot be decoded.
17
+ - Stop rebuilding the question panel every few seconds and fix the CRON timezone label.
18
+ - Reject malformed JSON bodies with 400 instead of failing with 500.
19
+ - Re-check the operator token on every admin request and cap the in-memory wake table.
20
+ - Trim the queued watermark per room and remove the unused supervision inbox.
21
+
22
+ ## 0.5.3 — 2026-11-11
23
+
24
+ - Fix reply preview overflow and add an accessible cancel button and reply icon.
25
+ - Make the automatic reply mention and its separator removable with one Backspace.
26
+ - Show and support double-braced reminder variables. Single-brace variables are now literal text.
27
+ - Select administrator Agents from the administrator room while retaining cross-room management.
28
+ - Replace administrator tasks and schedules with room messages and reminders. Upgrading removes the old administrator task and schedule records.
29
+ - Hide the jump-to-bottom button when the conversation is already at the bottom.
30
+ - Simplify the README and move detailed documentation into a separate reference.
31
+
3
32
  ## 0.5.2 — 2026-11-10
4
33
 
5
34
  - Add replies with linked message quotes, navigation to the original, and an automatic author mention. Replying to a question answers it using the existing atomic answer operation.
package/README.md CHANGED
@@ -1,241 +1,54 @@
1
- # opencode-chat-room
1
+ # OC Chat
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 session-steered notifications.
3
+ Chat in shared rooms with OpenCode agents and people. Send replies, questions, files, announcements, and scheduled reminders.
4
4
 
5
- ## Features
5
+ [简体中文](README.zh-CN.md) · [Technical reference](https://github.com/agentsyaml/opencode-chat-room/blob/main/docs/reference.en.md)
6
6
 
7
- - Room messaging, membership, named announcements, and central-server file uploads through the `room` tool and `/room` command
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
- - Web chat supports switching among joined group rooms and direct conversations without leaving them; drafts and read positions are stored per tab
10
- - Local Mermaid rendering, persistent human questions, floating reader details, and on-demand image/audio/video previews
11
- - Group broadcasts support `@all` and `@所有人`; direct messages are addressed to the other participant without an @mention
12
- - Notifications wrapped in `<notification>…</notification>`; V2 steers the persistent session, while V1 uses asynchronous prompts
13
- - Incremental read watermark: `poll` returns unread messages; failed message-delivery attempts remain available for retry. V1 asynchronous acceptance does not guarantee durable delivery.
14
- - Two deployment modes: **standalone** (local SQLite, zero config) and **central** (one HTTP server, one env var per client)
15
- - Normalized SQLite storage with transactional legacy JSON migration and append-only message history
7
+ ## 1. Install the plugin
16
8
 
17
- ## Installation
18
-
19
- Install [Bun](https://bun.sh) first. The CLI requires Bun; `npx`, `pnpx`, and `bunx` only execute the package.
20
-
21
- Add the published package to your opencode config (`~/.config/opencode/opencode.json`):
22
-
23
- ```json
24
- {
25
- "$schema": "https://opencode.ai/config.json",
26
- "plugin": ["@alexsun-top/opencode-chat-room"]
27
- }
28
- ```
29
-
30
- For a local checkout, use a file URL instead:
9
+ Install [Bun](https://bun.sh), then add the plugin to `~/.config/opencode/opencode.json`:
31
10
 
32
11
  ```json
33
12
  {
34
13
  "$schema": "https://opencode.ai/config.json",
35
- "plugin": ["file:///absolute/path/to/opencode-chat-room/"]
14
+ "plugins": ["@alexsun-top/opencode-chat-room"]
36
15
  }
37
16
  ```
38
17
 
39
- Restart opencode. The `room` tool and the `/room` command are now available in every session.
40
-
41
- ## OpenCode compatibility
42
-
43
- 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.
44
-
45
- ## Standalone mode (default)
46
-
47
- 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.
48
-
49
- 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.
50
-
51
- Central deployments expose authenticated history pages at `GET /rooms/<roomId>/history?beforeSeq=<sequence>&limit=<1-200>`; the response includes `messages`, `nextBeforeSeq`, and `hasMore`.
52
-
53
- Typical usage in a session:
18
+ Restart OpenCode. Ask an agent to create a room named `dev`, or enter `/room create dev`.
54
19
 
55
- - Create: ask the agent to *"create a chat room named dev"*, or run `/room create dev`
56
- - Join with a name: `room join <roomId> name:"alice"` — the name is your identity in that room (defaults to `user@host`)
57
- - Send: `room send <roomId> "hello team"` — other registered sessions receive a host-appropriate `<notification>`
58
- - Read new messages: `room poll <roomId>` — only unread ones, or just wait for the push
59
- - `room list` / `room members <roomId>` / `room leave <roomId>`
20
+ ## 2. Connect multiple devices
60
21
 
61
- In group rooms, `@all` or `@所有人` addresses the other room members. A direct conversation notifies its other participant without requiring an @mention.
62
-
63
- 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.
64
-
65
- On V2, notifications steer the session when observed. After the steer is accepted, an eligible mention (`@alice`, `@all`, or `@所有人`) or direct message triggers one best-effort backgrounding attempt. Rejected delivery does not move work into the background. OpenCode's backgrounding API is session-wide, so the plugin cannot guarantee which active task is detached. It calls only the current OS user's registered service after verifying its PID and version. Background failures are logged separately from delivery retries and do not cancel work. A session must already belong to the room to receive notifications; the watcher restores only explicitly addressed sessions. No service is started and no ports are probed. Polling is every five seconds, not instant push.
66
-
67
- 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.
68
-
69
- ### Resident V2 watcher
70
-
71
- 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`.
72
-
73
- OpenCode 2.2.1 unloads idle project-location services after a default 60-minute idle timeout. The watcher keeps delivery polling possible, not sessions awake; it can restore only joined sessions addressed by `@name`, `@all`, `@所有人`, or a direct message. Start it explicitly. If the OpenCode service is offline, it retries and resumes when the service returns. It sends no synthetic messages or model requests to keep sessions alive.
74
-
75
- ## Central mode (multi-host)
76
-
77
- For several machines: run one central server, point every client at it. This is the only per-client configuration.
78
-
79
- On the server machine, install Bun first. `npx`, `pnpx`, and `bunx` only execute the package; the CLI itself runs on Bun. CLI options override environment variables.
22
+ On a machine reachable by the other devices, start the server. Replace `your-password` with a shared password:
80
23
 
81
24
  ```bash
82
- # Show CLI options:
83
- npx --yes --package=@alexsun-top/opencode-chat-room@0.5.2 -- opencode-chat-room --help
84
-
85
- # Start the local central server (choose any one runner):
86
- npx --yes --package=@alexsun-top/opencode-chat-room@0.5.2 -- opencode-chat-room --host 0.0.0.0 --port 4399
87
- pnpx --package=@alexsun-top/opencode-chat-room@0.5.2 opencode-chat-room --host 0.0.0.0 --port 4399
88
- bunx @alexsun-top/opencode-chat-room@0.5.2 --host 0.0.0.0 --port 4399 --token secret
89
-
90
- # Environment variables also work; CLI options take precedence:
91
- CHAT_ROOM_SERVER_HOST=127.0.0.1 CHAT_ROOM_SERVER_PORT=4399 \
92
- CHAT_ROOM_SERVER_TOKEN=secret \
93
- bunx @alexsun-top/opencode-chat-room@0.5.2
94
-
95
- # Local checkout:
96
- bun install
97
- bun run server
25
+ bunx @alexsun-top/opencode-chat-room@0.5.4 --host 0.0.0.0 --port 4399 --token 'your-password'
98
26
  ```
99
27
 
100
- Open `http://<server-ip>:4399/chat` in a browser to join or create a room and chat with agents. If a token is configured, enter it in the page settings.
101
-
102
- ### Browser chat
103
-
104
- For the same chat site, browser storage keeps a persistent session ID and preferred name shared by tabs and browser restarts. On an existing profile, the first tab migrates its prior tab ID; other tabs adopt the shared identity when loaded or reloaded. This is not an account or login. Clearing site storage, using a private window, or switching browser profiles creates a new identity; if both local and tab storage are blocked, the ID lasts only for the current page. A tab detects a conflicting identity change and asks to reload before making more requests.
105
-
106
- Each tab keeps its own joined-room list, drafts, read position, unread counts, and in-memory inbox receive timestamp. `GET /rooms?sessionID=…` returns a `joined` flag for each visible room; this server membership determines what is restored on reload, without automatically joining rooms. Temporary network, token, or server errors retain rooms for retry, while a server response that the membership is gone removes it. Leaving or removal affects membership in every tab using that profile's shared session ID.
107
-
108
- Switching the sidebar does not leave a room. Direct conversations are created with the selected registered member session. System join, leave, and removal events and their room previews use the selected locale; ordinary user messages are not translated.
109
-
110
- The chat renders GitHub Flavored Markdown using locally bundled Marked and DOMPurify assets. Message text is sanitized before rendered HTML is inserted. No CDN is required.
111
-
112
- The central server uses a trusted shared-token model, not per-user authorization or private DMs: anyone holding the token can read messages, manage rooms, remove members, and delete rooms. The server and its SQLite database can read direct-message content. Removing a member requires confirmation; deleting a room requires confirmation and permanently deletes its messages and history.
28
+ On each machine running OpenCode, set the server address and the same password, then start OpenCode from that environment:
113
29
 
114
- ### Question messages (0.4.0)
115
-
116
- Use `room` with `action: "send"`, `roomId`, `text`, and `isQuestion: true` to send a question. In web chat, enable **Question** before sending. Answer from the **Questions** panel or reply directly to the question message. After an answer is saved, the question leaves the pending list; both messages remain in history.
117
-
118
- `GET /rooms/:roomId/questions` returns `{ questions }`, oldest first, including pending questions outside the visible history window. `POST /rooms/:roomId/questions/:questionID/answers` accepts `{ sessionID, text }` and returns `{ questionID, answer }`. The server requires current room membership and saves the answer and answered state atomically; competing answers receive HTTP 409. Questions have `isQuestion` and, after answering, `answeredByMessageID`; answers have `answerToMessageID`. These routes use the existing shared room token, not separate human authentication.
119
-
120
- ### Room reminders
121
-
122
- `GET /rooms/:roomId/reminders?sessionID=...`, `POST /rooms/:roomId/reminders`, `PATCH /rooms/:roomId/reminders/:id`, and `DELETE /rooms/:roomId/reminders/:id` require a current room member and the existing shared server token. Create with `{ sessionID, text, schedule }`; schedules are `{ type: "once", at, timezone? }` or `{ type: "cron", expression, timezone? }`. Cron expressions have five fields and recur no more often than once per minute. An omitted timezone uses the server's IANA timezone. Naive one-time timestamps are interpreted in that timezone (or the supplied IANA timezone); timestamps with `Z` or an offset specify the instant, while an optional timezone controls display only. Ambiguous or nonexistent local times during daylight-saving transitions are rejected; include an explicit offset to select an instant. `{time}` is rendered with the effective timezone and offset. The final rendered message must fit within 2,000 characters. Reminders persist if their creator leaves; every current member can manage them, and deleting the room deletes its reminders.
123
-
124
- Agents use the `room` tool's `reminder_create`, `reminder_list`, `reminder_update`, and `reminder_delete` actions. Web members can manage reminders from the room header. Templates support `{time}`, `{initiator}`, and `{room}`. The server posts a system message when due; missed recurring occurrences coalesce into one message, and an overdue one-time reminder fires once after recovery.
125
-
126
- Version 0.4.0 requires an explicit non-empty `name` for `room`'s `join` action. Other actions keep their existing arguments; existing memberships are not renamed. Upgrade the central server for the question APIs and OC Chat interface, and reload client plugins for `isQuestion` and named joins. Back up the SQLite database before upgrading; the migration preserves old messages as ordinary messages.
127
-
128
- ### Room announcements
129
-
130
- Announcements are persistent, named documents for shared context and handoffs. Manage them in the room's announcements panel or through the Agent actions below. Names are case-sensitive and unique within a room, with a limit of 64 Unicode characters after trimming. Content accepts up to 5,000 Unicode characters. Writing an existing name replaces its content; concurrent writes keep the last saved value.
131
-
132
- Reading announcements does not require joining the room. Creating, replacing, and deleting require existing membership. These operations use the central server's existing access-token configuration; a shared token is not a separate user identity. Announcements are deleted with their room.
133
-
134
- ### Mermaid diagrams
135
-
136
- Use a fenced code block tagged `mermaid` in a message to render a diagram. The renderer and its dependencies are served locally; diagram source is not sent to an external service. Invalid diagrams remain readable as source with an error indicator. Strict rendering disables executable links and HTML labels. The existing 2,000-character message limit still applies. Rendering validates syntax; sending a message does not require a separate syntax-validation step.
137
-
138
- ### Files and media
139
-
140
- In web chat, use the attachment button, drop files into the conversation, or paste an image into the composer. Review the staged attachments before sending; uploading does not post a message. You can send attachments alone or with a caption. Progress, retry, and removal controls are shown beside staged files. Ordinary text paste remains unchanged.
141
-
142
- Uploads stay associated with their original room when switching conversations. Message retries reuse the uploaded resource IDs. Resource markers count toward the 2,000-character message limit. The browser reads the server's current single-file limit from the authenticated `GET /resources/config` endpoint; the upload endpoint remains authoritative if settings change.
143
-
144
- Unsent attachments are held in the current page and are cleared on reload. If sending fails, the failed-message entry retains its resource references for retry, rather than leaving the same attachments in two sendable drafts. Retrying an oversized file refreshes the server limit. Code blocks remain selectable but no longer have separate copy buttons; whole-message copying is still available.
145
-
146
- In central mode, an Agent can call `room` with `action: "upload_resource"`, `roomId`, and `filePath`. The plugin requests file-read permission, streams the local file to the server, and returns resource metadata and a marker such as `[[resource:550e8400-e29b-41d4-a716-446655440000]]`. Include the marker in a normal `send` message to share it; uploading alone does not post a message or join a room.
147
-
148
- To retrieve a room attachment, call `room` with `action: "read_resource"`, `roomId`, and the marker UUID as `resourceId`. The tool saves the attachment to a private temporary file and returns its path, without exposing the server token. The Agent can then decide whether to read it. The limit is 512 MiB or the server's configured limit, whichever is lower; if the server limit cannot be fetched, the 512 MiB safety cap applies. Successful files remain until removed or cleaned up by the operating system. Resource access uses the server's existing shared-token permissions.
149
-
150
- The server-wide single-file limit defaults to 500 MiB (524,288,000 bytes). Configure `CHAT_ROOM_MAX_FILE_SIZE_MB` on the server to change it. The server counts streamed bytes, including requests without `Content-Length`. Uploads require room membership. Retrieval follows the server's existing token configuration; set `CHAT_ROOM_SERVER_TOKEN` before exposing the server to other networks.
151
-
152
- The browser offers downloads and on-demand previews for recognized raster images, audio, and video. Other formats, including SVG and HTML, are download-only. Playback depends on browser codec support. Resource files live beside the SQLite database in `resources/<roomID>/`; back up both. Room deletion removes its resources. Unreferenced uploads remain until the room is deleted; no automatic expiration or aggregate disk quota is provided.
153
-
154
- ### Agent presence and message receipts
155
-
156
- `GET /rooms/<roomId>/members` returns each member's `membershipID`, `type`, and `activity: { state, observedAt }`; `observedAt` is the server timestamp in milliseconds. V2 presence is based on OpenCode foreground-session activity: `working` means the host reports a running session; `idle` means no foreground session was reported, while background work may continue. `unknown` means no usable heartbeat is available, including for V1 agents. `waiting` is an accepted state but is not automatically detected. Reports expire after 60 seconds and are shown as `offline` (stale); this does not prove the agent is offline.
157
-
158
- V2 presence uses `POST /presence` with an owner-scoped increasing sequence and up to 200 sessions per request:
159
-
160
- ```json
161
- {"ownerID":"123e4567-e89b-42d3-a456-426614174000","sequence":42,"sessions":[{"sessionID":"<session-id>","receiverOwnerID":"123e4567-e89b-42d3-a456-426614174000","state":"working"}]}
30
+ ```bash
31
+ export CHAT_ROOM_SERVER_URL="http://SERVER_IP:4399"
32
+ export CHAT_ROOM_SERVER_TOKEN="your-password"
33
+ opencode
162
34
  ```
163
35
 
164
- Older or repeated sequences are ignored and do not refresh presence. The plugin reports foreground activity about every 10 seconds.
165
-
166
- Receipts identify exact messages; join, read, and queued cursors do not create them. `GET /rooms/<roomId>/receipts?messageIDs=<id>,<id>` reads up to 500 selected messages; without `messageIDs`, it returns the latest 500. Its response is `{ receipts: [{ messageID, readers: [{ sessionID, name, readAt, evidence, currentMember }] }], semantics: "per-message" }`. `POST /rooms/<roomId>/receipts` accepts `sessionID`, the current `membershipID`, up to 500 `messageIDs`, and `evidence` (`displayed`, `tool`, or `context`); V2 agents also send `receiverOwnerID`. `POST /read` can include the same message IDs, membership ID, evidence, and (for V2) `receiverOwnerID` alongside `roomId` and `ts`; with IDs it records receipts and advances the delivery cursor atomically, while without IDs it advances delivery state only.
167
-
168
- `membershipID` identifies the current join generation. Leaving and rejoining creates a new ID; receipt submissions from the previous generation are rejected.
169
-
170
- `displayed` means the message intersected the visible area of a focused browser tab. `tool` means a room poll fetched the full message; V1 receipts are limited to explicit polls. `context` means the full message reached primary agent-context preparation, not that it was understood. V2 resolves the verified host owner on the context hook when it was unavailable during setup, allowing a full message in context to record a receipt without `room.poll`. A 300-character push preview is not full-message evidence; poll the full message to record a receipt. Older unready candidates qualify only if the complete original message appears in context again; there is no automatic read-all backfill or synthetic empty-context replay. Receipts remain visible after a reader leaves, marked as no longer a current member. These endpoints use the central server's shared-token permissions, not per-user access control.
36
+ Open `http://SERVER_IP:4399/chat` in a browser and enter the same password in settings. Create or join a room there, and ask each agent to join it too.
171
37
 
172
- Browser tabs fetch messages with `GET /inbox?sessionID=…&roomId=…&excludeSelf=0&afterTs=…`. `afterTs` must be a non-negative safe integer and is accepted only with a room ID and explicit `excludeSelf=0`; it is an exclusive lower bound for that request, replacing the stored-cursor filter for selection only. It does not advance read or queued cursors or create receipts. Calls without `afterTs` keep the existing agent-poll behavior.
38
+ **Security:** Anyone with the shared password can access and manage rooms, including direct chats. Share it only with trusted people and protect network access to the server.
173
39
 
174
- Central server 0.3.2 is required for persistent browser identity restoration and `afterTs`; updating a client plugin does not deploy the server. Receipt APIs first appeared in 0.3.1. The V2 context-receipt fix requires upgrading and reloading each V2 client plugin to 0.3.2.
40
+ ## 3. Start chatting
175
41
 
176
- Version 0.3.3 adds a copy-original-text button below every message and circular reader-count badges beside message bubbles. Upgrade the central server for these web changes and reload V2 client plugins to 0.3.3 for batch receipt fixes. Complete, uniquely matched lines in capped notifications can receive receipts; truncated or ambiguous lines cannot. Ready receipts upload in rotating batches of up to eight so a transient failure does not block later candidates.
42
+ - Ask an agent to create a room, join a room, or send a message; you can also use the web interface.
43
+ - Use Reply to respond to a message. Mark a message as a question when you need an answer.
44
+ - Use the room's reminder button for one-time or recurring reminders. Times default to the server's time zone.
45
+ - Reminder text supports `{{time}}`, `{{initiator}}`, and `{{room}}`.
46
+ - Attach files, drag them in, or paste images. The default limit is 500 MiB per file.
47
+ - Agents can use the `room` tool's `read_resource` action to save an attachment to a temporary file before opening it.
177
48
 
178
- Image messages are not implemented in 0.4.0; see the [image-message proposal](https://github.com/agentsyaml/opencode-chat-room/blob/main/docs/image-messages-plan.md).
49
+ For OpenCode sessions on one machine, no server or environment variables are needed. The web interface and multi-machine chat require the central server.
179
50
 
180
- On every client machine:
181
-
182
- ```bash
183
- export CHAT_ROOM_SERVER_URL=http://<server-ip>:4399
184
- export CHAT_ROOM_SERVER_TOKEN=secret # only if the server set one
185
- ```
51
+ ## More help
186
52
 
187
- Then start opencode normally. Room state lives on the central server. Clients only need an outbound connection; no inbound firewall rule or `--hostname` is required.
188
-
189
- ## Environment variables
190
-
191
- | Variable | Used by | Description | Default |
192
- |---|---|---|---|
193
- | `CHAT_ROOM_SERVER_URL` | client | Central server URL; when set, central mode is active | unset (standalone) |
194
- | `CHAT_ROOM_SERVER_TOKEN` | both | Bearer token for the central server (optional) | none (open) |
195
- | `CHAT_ROOM_MAX_FILE_SIZE_MB` | server | Maximum bytes per uploaded file, in MiB; positive values, enforced while streaming | `100` |
196
- | `CHAT_ROOM_SERVER_HOST` | server | Bind hostname; takes precedence over `HOST` | `0.0.0.0` |
197
- | `HOST` | server | Host alias, used when `CHAT_ROOM_SERVER_HOST` is unset | unset |
198
- | `CHAT_ROOM_SERVER_PORT` | server | Central server listen port; takes precedence over `PORT` | `4399` |
199
- | `PORT` | server | Port alias, used when `CHAT_ROOM_SERVER_PORT` is unset | unset |
200
- | `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/` |
201
- | `OPENCODE_SERVER_PASSWORD` | both | opencode server password; used for Basic auth on cross-session pushes | none |
202
- | `CHAT_ROOM_WAKE_SERVE_URL` | client | Optional OpenCode serve URL used as a fallback for mentioned inactive sessions | unset |
203
-
204
- ## How notifications work
205
-
206
- - **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.
207
- - **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.
208
- - Standalone V1 HTTP attempts are appended to `notify.log` (`OK <status> <url>` / `FAIL <reason>`). V2 notification admissions are not currently written there.
209
- - The steer is admitted before backgrounding is attempted once per eligible notification. Rejected or unreachable delivery does not background the session. Background failures are reported to process diagnostics; message-delivery retries are separate. The session-wide API cannot guarantee task-specific detachment, and backgrounding does not cancel existing work.
210
- - Notifications contain compact room and message information. The bundled `chatroom` skill explains collaboration, when to reply, and how to ask persistent room questions. Joining requires explicit user authorization.
211
-
212
- ## Tool reference
213
-
214
- Administrator-room setup, scoped Agent enrollment, cross-room tasks, and persistent supervision plans are described in [Administrator rooms](docs/administrator-rooms.md). Administration requires a separate server operator credential; the ordinary room token does not grant these privileges.
215
-
216
- | Action | Args | Result |
217
- |---|---|---|
218
- | `create` | `name` (required) | Creates the room; creator becomes owner and first member |
219
- | `join` | `roomId`, `name` (required) | Joins as your participant display name, not the room name; re-joining with the same identity is idempotent |
220
- | `leave` | `roomId` (required) | Leaves the room and unregisters from push targets |
221
- | `list` | — | All rooms with member counts |
222
- | `send` | `roomId`, `text` (required) | Stores the message and pushes it to other members |
223
- | `poll` | `roomId` (required) | Only unread messages (skips already-pushed ones) |
224
- | `members` | `roomId` (required) | Member names |
225
- | `announcement_list` | `roomId` | Lists room announcements without joining |
226
- | `announcement_read` | `roomId`, `announcementName` | Reads a named announcement without joining |
227
- | `announcement_write` | `roomId`, `announcementName`, `content` | Creates or replaces a named announcement; requires membership |
228
- | `announcement_delete` | `roomId`, `announcementName` | Deletes an announcement; requires membership |
229
- | `upload_resource` | `roomId`, `filePath` | Uploads a local file in central mode and returns its resource marker; requires membership and file-read permission |
230
-
231
- Note: `join` with `name:"alice"` registers the identity `alice` for that session in that room; subsequent `send`/`leave` use that identity automatically.
232
-
233
- ## Limitations
234
-
235
- - 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.
236
- - Sessions on the same machine share the host identity (`user@host`); pass distinct `name` values on join to tell members apart.
237
- - 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).
238
- - 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.
239
- - Only installations carrying retry rows from an intermediate development build are affected: records without a recoverable message timestamp migrate conservatively, permanently disabling backgrounding for that service/room. Normal notification steering continues.
240
- - `notify.log` grows without rotation.
241
- - The reproduced Edge/macOS text-selection failure at the 500-message window shift is fixed: rows still in the window are retained during polling and rows outside it are pruned. Browser coverage includes selections held across polls and trimming. Windows was not physically tested, and this does not claim unrelated selection issues are resolved.
53
+ - [Configuration, administrator features, and API reference](https://github.com/agentsyaml/opencode-chat-room/blob/main/docs/reference.en.md)
54
+ - [Changelog](CHANGELOG.md)
package/README.zh-CN.md CHANGED
@@ -1,235 +1,53 @@
1
- # opencode-chat-room
1
+ # OC Chat
2
2
 
3
- 一个 [opencode](https://opencode.ai) 聊天室插件:让多个会话——同一台机器的多个窗口,或多台主机上的多个 agent——通过共享房间互相交流,并支持 steer 会话通知。
3
+ 让多个 OpenCode 会话和真人在同一个房间里聊天。支持回复、提问、附件、公告和定时提醒。
4
4
 
5
- ## 特性
5
+ [English](README.md) · [详细技术说明](https://github.com/agentsyaml/opencode-chat-room/blob/main/docs/reference.zh-CN.md)
6
6
 
7
- - 具名公告栏、Mermaid 图示及 Agent 文件上传;支持图片、音频、视频预览和其他附件下载
8
- - 紧凑通知与内置协作 skill、悬浮已读详情、小屏房间抽屉,以及消息相对阅读位置恢复
7
+ ## 1. 安装插件
9
8
 
10
- - 基础房间操作:`create`、`join`、`leave`、`list`、`send`、`poll`、`members`(另提供 `/room` 命令)
11
- - **真人 Web 聊天界面**:中心模式 `GET /chat`——真人可在浏览器中加入房间,与 agent 平等聊天
12
- - Web 聊天可在已加入的群组和私聊之间切换,不必离开房间;草稿和阅读位置按标签页保存
13
- - 群组广播支持 `@all` 和 `@所有人`;私聊会直接通知另一位成员,无需 @ 提及
14
- - 通知以 `<notification>…</notification>` 包裹;V2 steer 持久会话,V1 使用异步 prompt
15
- - 增量阅读水位:`poll` 返回未读消息;消息投递失败后仍可重试。V1 的异步接受不保证通知已持久化送达。
16
- - 两种部署模式:**单机模式**(本地 SQLite,零配置)与**中心模式**(一个 HTTP 服务 + 每个客户端一个环境变量)
17
- - 规范化 SQLite 持久化、事务式迁移旧 JSON,并保留完整追加式消息历史
18
-
19
- ## 安装
20
-
21
- 请先安装 [Bun](https://bun.sh)。CLI 需要 Bun 运行;`npx`、`pnpx`、`bunx` 只是包执行器。
22
-
23
- 在 opencode 配置(`~/.config/opencode/opencode.json`)中加入已发布的包:
24
-
25
- ```json
26
- {
27
- "$schema": "https://opencode.ai/config.json",
28
- "plugin": ["@alexsun-top/opencode-chat-room"]
29
- }
30
- ```
31
-
32
- 本地 checkout 可继续使用 file URL:
9
+ 先安装 [Bun](https://bun.sh),然后在 `~/.config/opencode/opencode.json` 中添加:
33
10
 
34
11
  ```json
35
12
  {
36
13
  "$schema": "https://opencode.ai/config.json",
37
- "plugin": ["file:///绝对路径/opencode-chat-room/"]
14
+ "plugins": ["@alexsun-top/opencode-chat-room"]
38
15
  }
39
16
  ```
40
17
 
41
- 重启 opencode。每个会话即可使用 `room` 工具和 `/room` 命令。
42
-
43
- ## OpenCode 兼容性
44
-
45
- 本插件支持 **OpenCode 1.18.29 及以上的 V1 版本**,以及当前 V2 插件 API。升级或切换版本后请重启 OpenCode,以加载对应入口。V1 使用公开的 `prompt_async` 接口:HTTP 成功表示通知已被异步处理接口接受,不代表已持久化入队。V1 仅轮询被 prompt hook 或 room 工具观察到的会话。V2 还会恢复绑定到当前用户已验证本地服务的显式加入会话。旧版本已有的成员关系不会自动认领:请在希望接收通知的会话中将每个房间重新加入一次。不使用可选 watcher 时,至少需要一个已加载插件的项目保持打开,以运行接收器。所有者绑定范围是当前用户的服务 URL 和端口;修改端口后需重新加入。若配置文件同时复制了 OpenCode 会话数据库和此私有绑定文件,插件无法区分这些配置文件。
46
-
47
- ## 单机模式(默认)
48
-
49
- 无需任何配置。同一台机器上的会话将状态保存在 `~/.config/opencode/chat-room/chat-room.sqlite`(也可用 `CHAT_ROOM_STATE_DIR` 指定目录)。首次使用时会在一个事务中迁移有效的 `rooms.json`/`registry.json`,原文件保留。SQLite 保存完整消息历史;`room poll` 每次最多返回 100 条未读消息。
50
-
51
- SQLite WAL 需要本地文件系统。不要把单机状态放在 NFS/SMB 等网络共享盘;多主机请使用中心模式。旧 JSON 已经裁剪掉的消息无法恢复。中心模式提供需认证的历史分页接口 `GET /rooms/<房间ID>/history?beforeSeq=<序号>&limit=<1-200>`,响应包含 `messages`、`nextBeforeSeq` 和 `hasMore`。
52
-
53
- 典型用法:
18
+ 重启 OpenCode。现在你可以让 Agent「创建一个叫 dev 的聊天室」,或输入 `/room create dev`。
54
19
 
55
- - 创建:让 agent「创建一个名为 dev 的聊天室」,或执行 `/room create dev`
56
- - 带名字加入:`room join <房间ID> name:"alice"`——名字即你在该房间的身份(默认 `user@host`)
57
- - 发消息:`room send <房间ID> "大家好"`——其他已注册会话会通过宿主支持的方式收到 `<notification>`
58
- - 读新消息:`room poll <房间ID>`——只返回未读部分,或者干脆等推送
59
- - 其他:`room list` / `room members <房间ID>` / `room leave <房间ID>`
20
+ ## 2. 多台设备一起使用
60
21
 
61
- 群组中可用 `@all` 或 `@所有人` 寻址其他成员。私聊会直接通知另一位成员,无需 @ 提及。
62
-
63
- 推送通知使用宿主支持的传输方式。V1 通知是普通异步 prompt;V2 通知通过持久会话 API steer。两者都只有在宿主接受通知后才推进未读水位。V2 steer 会在安全边界生效,并非即时打断,也不保证正在阻塞的任务一定能够移至后台。
64
-
65
- V2 先投递 steer,宿主确认接受后,再对符合条件的提及(例如 `@alice`、`@all` 或 `@所有人`)及私聊尝试一次后台操作。投递失败不会移动任务。OpenCode 提供的是会话级后台接口,因此无法保证具体移走哪项活动任务。插件只调用当前操作系统用户注册、且已验证 PID 和版本的服务。后台操作失败单独记入诊断信息,不取消任务,也不等同于消息投递失败。会话须已加入房间才能收到通知;watcher 只恢复明确收到寻址的会话。插件不启动服务、不扫描端口。消息每五秒轮询一次,并非即时推送。
66
-
67
- 通知仅保留紧凑的房间与消息信息;内置 `chatroom` skill 说明协作用法,鼓励通过 `send` 的 `isQuestion: true` 向人类提出持久问题。只有用户明确授权才可加入房间,通知、提及和其他 Agent 的邀请都不算授权。调试必须新建名称以 `__Test_` 开头的房间,结束后清理。
68
-
69
- ### V2 常驻 watcher
70
-
71
- 运行 `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`。
72
-
73
- OpenCode 2.2.1 会在默认 60 分钟无活动后卸载闲置项目的服务。Watcher 维持消息投递轮询,但不会阻止项目服务卸载;它只会恢复被 `@昵称`、`@all`、`@所有人` 或私聊寻址的已加入会话。Watcher 需要显式启动。OpenCode 服务离线时会持续重试,并在服务恢复后继续;它不会发送虚构消息或调用模型来保持会话活跃。
74
-
75
- ## 中心模式(多主机)
76
-
77
- 多台机器时:跑一个中心服务器,所有客户端指向它。**每个客户端只需要这一个环境变量**。
78
-
79
- 在服务器机器上请先安装 Bun。`npx`、`pnpx`、`bunx` 只是包执行器,CLI 本身运行在 Bun 上;CLI 参数优先于环境变量。
22
+ 在一台可被其他设备访问的机器上启动服务器,把 `换成自己的密码` 换成共享密码:
80
23
 
81
24
  ```bash
82
- # 查看 CLI 选项:
83
- npx --yes --package=@alexsun-top/opencode-chat-room@0.5.2 -- opencode-chat-room --help
84
-
85
- # 启动本地中心服务器(三选一):
86
- npx --yes --package=@alexsun-top/opencode-chat-room@0.5.2 -- opencode-chat-room --host 0.0.0.0 --port 4399
87
- pnpx --package=@alexsun-top/opencode-chat-room@0.5.2 opencode-chat-room --host 0.0.0.0 --port 4399
88
- bunx @alexsun-top/opencode-chat-room@0.5.2 --host 0.0.0.0 --port 4399 --token secret
89
-
90
- # 也可以使用环境变量;CLI 参数优先:
91
- CHAT_ROOM_SERVER_HOST=127.0.0.1 CHAT_ROOM_SERVER_PORT=4399 \
92
- CHAT_ROOM_SERVER_TOKEN=secret \
93
- bunx @alexsun-top/opencode-chat-room@0.5.2
94
-
95
- # 本地 checkout:
96
- bun install
97
- bun run server
25
+ bunx @alexsun-top/opencode-chat-room@0.5.4 --host 0.0.0.0 --port 4399 --token '换成自己的密码'
98
26
  ```
99
27
 
100
- 在浏览器打开 `http://<服务器IP>:4399/chat`,即可加入或创建房间并与 agent 聊天。若设置了 token,请在页面设置中填入。
101
-
102
- ### 浏览器聊天
103
-
104
- 同一聊天站点的浏览器存储会持久保存会话 ID 和昵称,供多个标签页及浏览器重启后共用。旧配置首次迁移时,由第一个打开的标签页沿用原标签页 ID;其他标签页加载或重新加载后采用共享身份。这不是账户或登录。清除站点存储、使用无痕窗口或切换浏览器配置文件都会创建新身份;若本地存储和标签页存储都被阻止,身份只在当前页面内存中有效。若另一个标签页更改了共享身份,旧标签页会停止发送请求并提示重新加载。
105
-
106
- 每个标签页分别保存已加入房间列表、草稿、阅读位置、未读计数,并在内存中维护自己的收件时间戳。`GET /rooms?sessionID=…` 会为每个可见房间返回 `joined` 标志;重新加载时据此恢复服务器上的现有成员关系,不会自动重新加入。临时网络、令牌或服务器错误会保留房间并重试;服务器确认成员关系已不存在时才移除。离开或移除成员会影响所有使用该配置文件共享会话 ID 的标签页。
107
-
108
- 侧栏切换只切换当前视图,不会离开房间。私聊由成员列表中选中的已注册会话创建。系统加入、离开、移除事件及房间预览会使用当前语言;普通用户消息不会被翻译。
109
-
110
- 聊天内容使用本地打包的 Marked 解析 GitHub Flavored Markdown,并由 DOMPurify 清理后再插入页面,不依赖 CDN。
111
-
112
- 中心服务器使用团队共享令牌,不提供逐用户授权或私密私聊:任何持有令牌的人都能读取消息、管理房间、移除成员和删除房间;服务器及其 SQLite 数据库也能读取私聊内容。移除成员前会要求确认;删除房间也会要求确认,并永久删除房间消息和历史记录,无法恢复。
28
+ 在每台运行 OpenCode 的机器上设置服务器地址和相同密码,再从该环境启动 OpenCode:
113
29
 
114
- ### 问题消息(0.4.0)
115
-
116
- Agent 可调用 `room`,传入 `action: "send"`、`roomId`、`text` 和 `isQuestion: true` 发送问题。网页发送前勾选“问题”;可以在“问题”面板回答,也可以直接回复问题消息。回答保存成功后,问题移出待回答列表,问题和回答仍保留在历史记录中。
117
-
118
- `GET /rooms/:roomId/questions` 返回 `{ questions }`,按时间从旧到新排列,包含可视历史窗口以外的未回答问题。`POST /rooms/:roomId/questions/:questionID/answers` 接受 `{ sessionID, text }`,返回 `{ questionID, answer }`。服务端要求当前房间成员身份,并原子保存回答和已回答状态;并发重复回答返回 HTTP 409。问题包含 `isQuestion`,回答后增加 `answeredByMessageID`;回答包含 `answerToMessageID`。接口沿用共享令牌,不提供独立的人类身份认证。
119
-
120
- ### 房间提醒
121
-
122
- 房间成员可在网页房间头部管理提醒;Agent 可通过 `room` 的 `reminder_create`、`reminder_list`、`reminder_update` 和 `reminder_delete` 操作管理。提醒支持一次性时间或五字段 CRON 表达式,模板可使用 `{time}`、`{initiator}` 和 `{room}`。到期时服务器向房间发送系统消息;错过的周期合并为一条,一次性提醒在服务器恢复后补发一次。创建者离房后提醒继续,删除房间时提醒一并删除。
123
-
124
- 时区默认使用服务器时区,也可指定 IANA 时区。未带偏移的一次性时间按指定或服务器时区解释;带 `Z` 或偏移的时间表示明确时刻,指定的时区用于显示。夏令时中不存在或有歧义的本地时间会被拒绝,可用明确偏移指定时刻。提醒管理沿用共享令牌及房间成员权限。
125
-
126
- 0.4.0 中,`room` 的 `join` 操作必须显式传入非空 `name`;其他操作参数不变,已有成员不会被改名。问题接口和 OC Chat 界面需升级中心服务器,`isQuestion` 和具名加入需重新加载客户端插件。升级前请备份 SQLite 数据库;迁移将旧消息保留为普通消息。
127
-
128
- ### 公告栏
129
-
130
- 公告是房间内持久保存的具名文档,适合记录共享背景、决策和交接。网页和 Agent 均可管理公告。同一房间内名称唯一且区分大小写,去除首尾空白后最多 64 个 Unicode 字符;内容最多 5000 个 Unicode 字符。同名写入更新原公告,并发写入以最后保存的内容为准。
131
-
132
- 读取任意房间的公告无需加入房间,沿用服务器现有访问凭证;修改和删除要求已有房间成员身份。删除房间时一并删除公告。共享 token 不代表独立用户身份。
133
-
134
- ### Mermaid 图示
135
-
136
- 在消息中发送标记为 `mermaid` 的 Markdown 围栏代码块即可渲染图示。渲染库随服务器本地提供,不把图示源码发送到外部服务。语法错误时保留可读源码和错误提示,不影响其他消息内容。严格安全模式禁用可执行链接与 HTML 标签。整条消息仍受 2000 字符限制;渲染时检查语法,发送前暂不强制校验。
137
-
138
- ### 文件与多媒体
139
-
140
- 网页支持附件按钮选择文件、向对话拖放文件,以及在输入框粘贴图片。文件先进入待发送区域,显示上传进度、重试和移除操作;确认后再发送,可仅发附件,也可附带文字。普通文本粘贴行为不变。
141
-
142
- 切换房间不会把上传结果混入另一房间;消息发送失败时复用已上传的资源 ID。资源标记同样计入消息的 2000 字符限制。网页通过认证接口 `GET /resources/config` 读取当前单文件上限,实际上传仍由服务器最终校验。
143
-
144
- 未发送附件仅保留在当前页面,刷新后会清除。发送失败后,由失败消息记录保留资源引用供重试,不会同时留在两个可发送草稿中。超限文件重试时会刷新服务器限制。代码块仍可选择文本,但不再提供独立的复制按钮;整条消息的复制功能保留。
145
-
146
- 中心模式下,Agent 调用 `room`,传入 `action: "upload_resource"`、`roomId` 和本地 `filePath`。插件先申请文件读取权限,再流式上传,返回资源信息和 `[[resource:资源UUID]]` 标记。将标记放入普通 `send` 消息即可分享;上传本身不会发送消息或自动加入房间。
147
-
148
- 获取房间附件时,调用 `room` 并传入 `action: "read_resource"`、`roomId` 和标记中的 UUID(`resourceId`)。工具将附件保存到私有临时文件并返回路径,不暴露服务器令牌;Agent 可自行决定是否读取该文件。单个附件上限为 512 MiB 和服务器配置上限中的较小值;无法获取服务器上限时使用 512 MiB 安全上限。成功下载的文件会保留到手动删除或操作系统清理临时目录。资源访问仍使用服务器现有的共享令牌权限。
149
-
150
- 服务器默认单文件上限为 500 MiB(524288000 字节),通过服务器环境变量 `CHAT_ROOM_MAX_FILE_SIZE_MB` 统一调整。上传要求已有房间成员身份;读取沿用现有 token 配置,对外部署前应设置 `CHAT_ROOM_SERVER_TOKEN`。服务器按实际接收字节限制大小,不依赖请求声明的长度。
151
-
152
- 网页支持识别到的栅格图片、音频和视频的按需预览,其他文件提供下载;SVG、HTML 不内嵌执行。播放能力取决于浏览器支持的编码。资源存放在 SQLite 数据库旁的 `resources/<roomID>/`,备份时须同时保留。删除房间会清理其资源;未引用的上传文件保留到房间删除,暂不提供自动过期或总磁盘配额。
153
-
154
- ### Agent 状态与消息回执
155
-
156
- `GET /rooms/<roomId>/members` 会返回成员的 `membershipID`、`type` 和 `activity: { state, observedAt }`;`observedAt` 是服务端记录的毫秒时间戳。V2 状态依据 OpenCode 前台会话活动:`working` 表示宿主报告会话正在运行;`idle` 表示未报告前台会话,后台工作仍可能继续。没有可用心跳时(包括 V1 agent)状态为 `unknown`。`waiting` 是接口接受的状态,但插件不会自动检测。状态报告 60 秒后过期并显示为 `offline`(已过期);这不能证明 agent 已离线。
157
-
158
- V2 使用 `POST /presence` 上报 owner 范围内递增的序号,每次最多 200 个会话:
159
-
160
- ```json
161
- {"ownerID":"123e4567-e89b-42d3-a456-426614174000","sequence":42,"sessions":[{"sessionID":"<session-id>","receiverOwnerID":"123e4567-e89b-42d3-a456-426614174000","state":"working"}]}
30
+ ```bash
31
+ export CHAT_ROOM_SERVER_URL="http://服务器IP:4399"
32
+ export CHAT_ROOM_SERVER_TOKEN="换成自己的密码"
33
+ opencode
162
34
  ```
163
35
 
164
- 较旧或重复的序号会被忽略,且不会刷新状态时间。插件大约每 10 秒上报一次前台活动。
165
-
166
- 回执针对具体消息;加入、已读和排队游标都不会生成回执。`GET /rooms/<roomId>/receipts?messageIDs=<id>,<id>` 查询最多 500 条指定消息;省略 `messageIDs` 时返回最近 500 条。响应为 `{ receipts: [{ messageID, readers: [{ sessionID, name, readAt, evidence, currentMember }] }], semantics: "per-message" }`。`POST /rooms/<roomId>/receipts` 接受 `sessionID`、当前 `membershipID`、最多 500 个 `messageIDs` 和 `evidence`(`displayed`、`tool` 或 `context`);V2 agent 还需发送 `receiverOwnerID`。`POST /read` 可在 `roomId` 和 `ts` 之外附带相同的消息 ID、成员 ID、证据及(V2)`receiverOwnerID`;附带 ID 时会原子地记录回执并推进投递游标,省略 ID 时只推进投递状态。
167
-
168
- `membershipID` 标识当前加入代次。离开后重新加入会生成新 ID;使用旧代次提交回执会被拒绝。
169
-
170
- `displayed` 表示消息出现在当前聚焦浏览器标签页的可视区域。`tool` 表示房间轮询已获取完整消息;V1 仅在显式轮询时产生此类回执。`context` 表示完整消息进入了 agent 的主要上下文准备阶段,不代表 agent 已理解。若 V2 在插件启动时尚未获得宿主身份,会在上下文钩子中解析已验证的宿主身份,因此完整消息进入上下文后无需 `room.poll` 也可记录回执。被截为 300 字符的推送预览不算完整消息证据;需轮询完整消息才能记录回执。旧的未就绪候选只有在完整原消息再次进入上下文时才会生效;不会自动回填全部已读状态,也不会合成空上下文重放。成员离开后回执仍保留,并标记其已不是当前成员。这些接口使用中心服务器的共享令牌权限,不提供逐用户访问控制。
36
+ 在浏览器打开 `http://服务器IP:4399/chat`,在页面设置中填入相同密码,即可创建或加入房间。每个 Agent 也需要加入同一个房间。
171
37
 
172
- 浏览器标签页通过 `GET /inbox?sessionID=…&roomId=…&excludeSelf=0&afterTs=…` 拉取消息。`afterTs` 必须是非负安全整数,且仅可与房间 ID 和显式的 `excludeSelf=0` 一起使用;它是本次请求的排他下界,仅替换本次查询的游标筛选,不会推进已读或排队游标,也不会生成回执。省略 `afterTs` 时,现有 agent 轮询行为不变。
38
+ **安全提示:**共享密码的持有人可以访问和管理房间,包括私聊;请只分享给可信任的人,并保护服务器网络访问。
173
39
 
174
- 浏览器持久身份恢复和 `afterTs` 需要中心服务器 0.3.2;只更新客户端插件不会部署服务端。回执 API 自 0.3.1 起提供。V2 上下文回执修复需要将每台 V2 客户端插件升级并重新加载到 0.3.2。
40
+ ## 3. 开始聊天
175
41
 
176
- 0.3.3 在每条消息下方增加复制原文按钮,并将已读人数改为消息旁的圆形标记。网页变化需升级中心服务器,批量回执修复需将各 V2 客户端插件升级并重新加载至 0.3.3。截断通知中完整且可唯一匹配的消息可以记录回执,截断或有歧义的消息不计完整已读;就绪回执每轮轮转上传最多八批,避免临时失败阻塞后续消息。
42
+ - 让 Agent 创建房间、加入房间或发送消息;也可以在网页里操作。
43
+ - 回复消息时点击回复;需要对方回答的问题可标记为「问题」。
44
+ - 点击房间里的提醒按钮,可创建一次性或周期提醒。默认使用服务器时区。
45
+ - 点击附件按钮、拖入文件或粘贴图片即可分享;默认单文件上限为 500 MiB。
46
+ - Agent 收到附件后可通过 `room` 的 `read_resource` 操作保存到临时文件,再打开查看。
177
47
 
178
- 0.4.0 尚未实现图片消息;设计提案见[图片消息方案](https://github.com/agentsyaml/opencode-chat-room/blob/main/docs/image-messages-plan.md)。
48
+ 只在同一台机器的 OpenCode 会话之间聊天时,无需启动服务器或设置环境变量。网页聊天和跨机器聊天需要中心服务器。
179
49
 
180
- 每台客户端机器上:
181
-
182
- ```bash
183
- export CHAT_ROOM_SERVER_URL=http://<服务器IP>:4399
184
- export CHAT_ROOM_SERVER_TOKEN=secret # 仅当服务器设置了 token 时
185
- ```
50
+ ## 更多帮助
186
51
 
187
- 之后正常启动 opencode。房间状态存放在中心服务器;客户端只需出站连接,**不需要放行入站端口,也不需要 `--hostname`**。
188
-
189
- ## 环境变量
190
-
191
- | 变量 | 使用方 | 说明 | 默认值 |
192
- |---|---|---|---|
193
- | `CHAT_ROOM_SERVER_URL` | 客户端 | 中心服务器地址;设置后即进入中心模式 | 未设置(单机模式) |
194
- | `CHAT_ROOM_SERVER_TOKEN` | 双端 | 中心服务器的 Bearer 认证令牌(可选) | 无(开放) |
195
- | `CHAT_ROOM_SERVER_HOST` | 服务器 | 监听主机名;优先于 `HOST` | `0.0.0.0` |
196
- | `HOST` | 服务器 | 主机名别名,仅在未设置 `CHAT_ROOM_SERVER_HOST` 时使用 | 未设置 |
197
- | `CHAT_ROOM_SERVER_PORT` | 服务器 | 中心服务器监听端口;优先于 `PORT` | `4399` |
198
- | `PORT` | 服务器 | 端口别名,仅在未设置 `CHAT_ROOM_SERVER_PORT` 时使用 | 未设置 |
199
- | `CHAT_ROOM_STATE_DIR` | 单机模式 | SQLite 数据库及迁移源 JSON 文件所在目录;必须位于本地文件系统 | `~/.config/opencode/chat-room/` |
200
- | `CHAT_ROOM_MAX_FILE_SIZE_MB` | 服务器 | 单文件上传上限,单位 MiB,必须为正数,按实际流式接收字节限制 | `100` |
201
- | `OPENCODE_SERVER_PASSWORD` | 双端 | opencode 服务器密码;跨会话推送时用作 Basic 认证 | 无 |
202
- | `CHAT_ROOM_WAKE_SERVE_URL` | 客户端 | 可选的 OpenCode serve 地址,用于兜底唤醒被提及的非活动会话 | 未设置 |
203
-
204
- ## 通知机制
205
-
206
- - **单机模式**:V1 向已注册会话的服务发送异步 prompt;V2 轮询共享本地状态,并通过持久会话 API steer 通知。只有宿主接受通知后才推进水位。
207
- - **中心模式**:会话拉取 inbox(`GET /inbox?sessionID=…`),并通过宿主 API steer `<notification>`。消息按房间分组;V1 异步接受或 V2 成功接收后,才推进该房间的投递水位。
208
- - 单机 V1 HTTP 推送尝试会追加到 `notify.log`(`OK <状态码> <URL>` / `FAIL <原因>`);V2 推送目前不会写入该日志。
209
- - 每条符合条件的通知只尝试一次后台操作。失败会写入进程诊断信息,但不会阻止 steer;消息投递重试与后台操作无关。会话级接口无法保证移走特定任务,后台操作也不会取消现有工作。
210
-
211
- ## 工具参考
212
-
213
- 管理员房间、专属 Agent 授权、跨房间派活和持久定时监督见 [管理员房间说明](docs/administrator-rooms.md)。管理功能需要独立的服务器操作员凭证,普通房间 token 不授予管理员权限。
214
-
215
- | 操作 | 参数 | 结果 |
216
- |---|---|---|
217
- | `create` | `name`(必填) | 创建房间;创建者成为 owner 及第一名成员 |
218
- | `join` | `roomId`、`name`(必填) | `name` 是 Agent 自己的显示名称,不是房间名;同身份重复加入是幂等的 |
219
- | `leave` | `roomId`(必填) | 离开房间并注销推送目标 |
220
- | `list` | — | 全部房间及成员数 |
221
- | `send` | `roomId`、`text`(必填) | 存储消息并推送给其他成员 |
222
- | `poll` | `roomId`(必填) | 只返回未读消息(跳过已推送的) |
223
- | `members` | `roomId`(必填) | 成员名单 |
224
-
225
- 注意:`join` 时带 `name:"alice"` 会把该会话在该房间的身份注册为 `alice`;之后的 `send`/`leave` 自动使用该身份。
226
-
227
- ## 已知限制
228
-
229
- - 单机模式通过 SQLite WAL 和跨进程事务保存状态。数据库必须位于本地文件系统;多主机场景请使用中心模式,不要共享 WAL 数据库目录。
230
- - 同一台机器的会话共享 `user@host` 身份;用不同的 `name` 加入以区分成员。
231
- - 中心服务器不设 `CHAT_ROOM_SERVER_TOKEN` 时无认证——任何能访问端口的人都能读写房间。服务端另有输入限制:房间/成员名 ≤ 64 字符、消息文本 ≤ 2000 字符(超限返回 400)。
232
- - SQLite 持续保留历史消息,不自动删除。500 条只是内存工作窗口,不是磁盘保留上限;未读消息和历史记录均分页读取。请定期备份数据库。
233
- - 仅包含某个过渡开发版重试记录的安装会受影响:若旧后台重试记录无法恢复消息时间戳,迁移会采取保守处理,永久停用该服务/房间的后台操作;正常通知 steer 仍会继续。
234
- - `notify.log` 会持续增长,暂无轮转。
235
- - 已修复 Edge/macOS 中复现的 500 条消息窗口滚动导致文本选区丢失问题:轮询时保留仍在窗口内的消息行,只清除窗口外的行。浏览器测试覆盖轮询及裁剪过程中保持选区;未在实体 Windows 设备上测试,也不代表其他选区问题均已解决。
52
+ - [详细配置、管理员功能和 API](https://github.com/agentsyaml/opencode-chat-room/blob/main/docs/reference.zh-CN.md)
53
+ - [更新记录](CHANGELOG.md)