@alexsun-top/opencode-chat-room 0.7.8 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (183) hide show
  1. package/CHANGELOG.md +43 -1
  2. package/LICENSE +21 -0
  3. package/README.md +77 -36
  4. package/README.zh-CN.md +82 -41
  5. package/cli.ts +27 -1
  6. package/dist/cli.js +6905 -2764
  7. package/package.json +33 -3
  8. package/packages/chat-room-channeld/README.md +315 -0
  9. package/packages/chat-room-channeld/dist/feishu-adapter.js +1262 -0
  10. package/packages/chat-room-channeld/dist/mock-adapter.js +295 -0
  11. package/packages/chat-room-channeld/src/adapter.ts +509 -0
  12. package/packages/chat-room-channeld/src/cli.ts +124 -0
  13. package/packages/chat-room-channeld/src/config.ts +269 -0
  14. package/packages/chat-room-channeld/src/delivery.ts +163 -0
  15. package/packages/chat-room-channeld/src/feishu-adapter.ts +303 -0
  16. package/packages/chat-room-channeld/src/feishu-card.ts +27 -0
  17. package/packages/chat-room-channeld/src/feishu-inbound.ts +158 -0
  18. package/packages/chat-room-channeld/src/feishu-live.ts +355 -0
  19. package/packages/chat-room-channeld/src/feishu-send.ts +342 -0
  20. package/packages/chat-room-channeld/src/feishu-ws-frames.ts +173 -0
  21. package/packages/chat-room-channeld/src/framing.ts +128 -0
  22. package/packages/chat-room-channeld/src/host-helpers.ts +52 -0
  23. package/packages/chat-room-channeld/src/host.ts +627 -0
  24. package/packages/chat-room-channeld/src/inbound.ts +26 -0
  25. package/packages/chat-room-channeld/src/ingest-gate.ts +108 -0
  26. package/packages/chat-room-channeld/src/log.ts +26 -0
  27. package/packages/chat-room-channeld/src/mock-adapter.ts +206 -0
  28. package/packages/chat-room-channeld/src/protocol.ts +75 -0
  29. package/packages/chat-room-channeld/src/published.ts +37 -0
  30. package/packages/chat-room-channeld/src/rules.ts +127 -0
  31. package/packages/chat-room-channeld/src/state.ts +502 -0
  32. package/packages/chat-room-channeld/src/stats.ts +209 -0
  33. package/plugin.ts +22 -5
  34. package/server/addressing-routes.ts +130 -0
  35. package/server/admin-state.ts +13 -13
  36. package/server/app.ts +95 -0
  37. package/server/assets/NOTICE.txt +3 -2
  38. package/server/assets/SHIKI-LICENSE +22 -0
  39. package/server/assets/base.css +24 -10
  40. package/server/assets/chat/announcements.js +70 -7
  41. package/server/assets/chat/doc-preview.js +187 -39
  42. package/server/assets/chat/events.js +3 -0
  43. package/server/assets/chat/files.js +46 -4
  44. package/server/assets/chat/forward.js +69 -0
  45. package/server/assets/chat/index.js +4 -0
  46. package/server/assets/chat/integration-editor.js +163 -0
  47. package/server/assets/chat/integration-values.js +124 -0
  48. package/server/assets/chat/integrations.js +498 -0
  49. package/server/assets/chat/locales/de.js +45 -4
  50. package/server/assets/chat/locales/es.js +45 -4
  51. package/server/assets/chat/locales/fr.js +45 -4
  52. package/server/assets/chat/locales/it.js +45 -4
  53. package/server/assets/chat/locales/ja.js +45 -4
  54. package/server/assets/chat/locales/ko.js +45 -4
  55. package/server/assets/chat/markdown-footnotes.js +115 -0
  56. package/server/assets/chat/markdown.js +46 -43
  57. package/server/assets/chat/messages.js +5 -5
  58. package/server/assets/chat/office-preview.js +69 -0
  59. package/server/assets/chat/palette.js +1 -1
  60. package/server/assets/chat/panels.js +36 -0
  61. package/server/assets/chat/recall.js +58 -7
  62. package/server/assets/chat/receipts.js +15 -3
  63. package/server/assets/chat/reminders.js +69 -8
  64. package/server/assets/chat/replies.js +7 -1
  65. package/server/assets/chat/resource-format.js +11 -0
  66. package/server/assets/chat/settings.js +30 -2
  67. package/server/assets/chat/shiki.js +87 -0
  68. package/server/assets/chat/side-pane.js +9 -3
  69. package/server/assets/chat/state.js +107 -11
  70. package/server/assets/chat/system-events.js +32 -0
  71. package/server/assets/chat/system-messages.js +23 -12
  72. package/server/assets/chat/task-row.js +0 -6
  73. package/server/assets/chat/tasks.js +121 -33
  74. package/server/assets/code-highlight.css +74 -62
  75. package/server/assets/conversation.css +126 -25
  76. package/server/assets/doc-preview.css +36 -3
  77. package/server/assets/files.css +5 -0
  78. package/server/assets/fluent-icons.svg +2 -0
  79. package/server/assets/monaco/LICENSE +21 -0
  80. package/server/assets/monaco/ThirdPartyNotices.txt +448 -0
  81. package/server/assets/monaco/codicon-jdswhhtn.ttf +0 -0
  82. package/server/assets/monaco/editor.worker.js +45 -0
  83. package/server/assets/monaco/integration-rules.css +1 -0
  84. package/server/assets/monaco/integration-rules.js +1297 -0
  85. package/server/assets/monaco/json.worker.js +77 -0
  86. package/server/assets/office/THIRD-PARTY-NOTICES.txt +11 -0
  87. package/server/assets/office/docx.bundle.js +33 -0
  88. package/server/assets/office/licenses/docx-preview-LICENSE.txt +201 -0
  89. package/server/assets/office/licenses/echarts-LICENSE.txt +222 -0
  90. package/server/assets/office/licenses/jszip-LICENSE.txt +651 -0
  91. package/server/assets/office/licenses/lodash-LICENSE.txt +47 -0
  92. package/server/assets/office/licenses/pptx-preview-LICENSE.txt +8 -0
  93. package/server/assets/office/licenses/tslib-LICENSE.txt +12 -0
  94. package/server/assets/office/licenses/uuid-LICENSE.txt +9 -0
  95. package/server/assets/office/licenses/xlsx-LICENSE.txt +201 -0
  96. package/server/assets/{HIGHLIGHT-LICENSE → office/licenses/zrender-LICENSE.txt} +2 -2
  97. package/server/assets/office/pptx.bundle.js +104 -0
  98. package/server/assets/office/xlsx.bundle.js +141 -0
  99. package/server/assets/recall.css +5 -4
  100. package/server/assets/responsive.css +52 -8
  101. package/server/assets/settings.css +73 -1
  102. package/server/assets/shiki.bundle.js +152 -0
  103. package/server/assets/tasks.css +57 -7
  104. package/server/channel-integration.ts +519 -0
  105. package/server/channel-settings.ts +77 -0
  106. package/server/channels.ts +557 -0
  107. package/server/chat-server.ts +33 -558
  108. package/server/chat.html +195 -22
  109. package/server/http-server.ts +3 -182
  110. package/server/resource-routes.ts +16 -16
  111. package/server/routes/inbox.ts +100 -0
  112. package/server/routes/pages.ts +83 -0
  113. package/server/routes/questions.ts +39 -0
  114. package/server/routes/room-actions.ts +162 -0
  115. package/server/routes/rooms.ts +160 -0
  116. package/server/startup.ts +84 -0
  117. package/server/sw.js +5 -2
  118. package/server/task-routes.ts +1 -1
  119. package/skills/chatroom/SKILL.md +1 -1
  120. package/src/center/center-client.ts +71 -1
  121. package/src/config/file-config.ts +29 -42
  122. package/src/platform/http-server.ts +182 -0
  123. package/src/protocol/addressing.ts +21 -0
  124. package/src/protocol/config.ts +58 -0
  125. package/src/protocol/room.ts +51 -0
  126. package/src/rooms/resources.ts +26 -16
  127. package/src/rooms/room-service.ts +2 -48
  128. package/src/rooms/storage.ts +329 -0
  129. package/src/rooms/tasks.ts +21 -5
  130. package/src/runtime/v2-plugin.ts +8 -2
  131. package/src/runtime/watch.ts +4 -3
  132. package/src/state/pg-database.ts +183 -0
  133. package/src/state/pg-migrate.ts +175 -0
  134. package/src/state/pg-sql.mjs +175 -0
  135. package/src/state/pg-worker.mjs +148 -0
  136. package/src/state/sqlite-announcements.ts +25 -0
  137. package/src/state/sqlite-database.ts +121 -0
  138. package/src/state/sqlite-legacy.ts +90 -0
  139. package/src/state/sqlite-members.ts +155 -0
  140. package/src/state/sqlite-messages.ts +288 -0
  141. package/src/state/sqlite-resources.ts +39 -0
  142. package/src/state/sqlite-rooms.ts +87 -0
  143. package/src/state/sqlite-schema.ts +80 -0
  144. package/src/state/sqlite-state-store.ts +33 -0
  145. package/src/state/sqlite-state.ts +15 -866
  146. package/src/state/sqlite-tasks.ts +65 -0
  147. package/src/state/sqlite-transaction.ts +13 -0
  148. package/src/state/sqlite.ts +21 -1
  149. package/src/state/store.ts +13 -3
  150. package/src/tui/app.mjs +32 -19
  151. package/src/tui/config.mjs +12 -4
  152. package/src/tui/http.mjs +16 -2
  153. package/src/tui/i18n.mjs +38 -0
  154. package/src/tui/info-app.mjs +50 -51
  155. package/src/tui/info-content.mjs +79 -44
  156. package/src/tui/join-app.mjs +9 -9
  157. package/src/tui/locales/en.mjs +349 -0
  158. package/src/tui/locales/zh-CN.mjs +349 -0
  159. package/src/tui/main.mjs +85 -37
  160. package/src/tui/markdown.mjs +3 -2
  161. package/src/tui/mentions.mjs +3 -1
  162. package/src/tui/message-app.mjs +22 -21
  163. package/src/tui/message-view.mjs +2 -1
  164. package/src/tui/palette-app.mjs +9 -8
  165. package/src/tui/palette.mjs +30 -24
  166. package/src/tui/prefs.mjs +92 -0
  167. package/src/tui/reminder-app.mjs +18 -17
  168. package/src/tui/room-settings-app.mjs +30 -28
  169. package/src/tui/settings-app.mjs +153 -0
  170. package/src/tui/ui-content.mjs +65 -86
  171. package/src/tui/ui-help.mjs +73 -0
  172. package/src/tui/ui-overlay-view.mjs +23 -7
  173. package/src/tui/ui-suggest.mjs +6 -5
  174. package/src/tui/ui-theme.mjs +37 -33
  175. package/src/tui/ui-view.mjs +22 -7
  176. package/src/tui/ui.mjs +15 -3
  177. package/src/web/editor.worker.ts +1 -0
  178. package/src/web/integration-rules-editor.ts +439 -0
  179. package/src/web/integration-rules.ts +22 -0
  180. package/src/web/integration-schema.ts +228 -0
  181. package/src/web/json.worker.ts +1 -0
  182. package/src/web/office-viewer.ts +221 -0
  183. package/server/assets/highlight-10.7.3.min.js +0 -1358
package/CHANGELOG.md CHANGED
@@ -1,5 +1,47 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.8.1 — 2026-11-26
4
+
5
+ - Split the server entry into focused startup, application, and route modules, and split the SQLite state layer into schema, message, member, task, resource, announcement, and transaction modules behind the same public barrel. Shared addressing, room, and configuration types now live in `src/protocol` instead of being duplicated. The TUI and browser asset layers remain JavaScript in this release; a complete TypeScript migration is planned for 0.9.0.
6
+ - Make S3 and S3-compatible resource storage stable: `CHAT_ROOM_STORAGE=s3` keeps uploads in an existing bucket, verifies `HeadBucket` before listening, streams through a local temp file, commits the database row only after the object write, and never silently falls back to local storage. The local disk remains the default.
7
+ - Add a `docker-compose.yaml` deployment template. The app is the default service; PostgreSQL and RustFS are optional profiles, with env-file defaults, named volumes, and a `/chat` healthcheck. Compose requires `CHAT_ROOM_SERVER_TOKEN` and refuses to start without it, so a missing `.env` cannot expose an unauthenticated server. The npm package is unchanged.
8
+ - Add an experimental PostgreSQL state backend behind `CHAT_ROOM_DATABASE_URL`. It is **single-instance only** in 0.8.1: a session advisory lock rejects a second writer, and multi-instance support is planned for 0.8.2. The existing synchronous state API runs over a worker-thread bridge with translated schema and SQL, transaction advisory locks, and serialization/deadlock retries. Add `opencode-chat-room migrate --to-postgres --yes` to copy an existing SQLite database in foreign-key order with row-count verification and sequence repair. Channel D remains SQLite and single-host; clients and watchers keep their own SQLite files. See the reference for backup and rollback steps.
9
+ - Overhaul the terminal UI around an OpenCode-v2-style layout: stable 80/100/120-column and short-terminal spacing, a full-height surface, a responsive room rail, a composer with a context footer, and readable focus, loading, empty, and error states that do not rely on color alone. Add an editable Settings surface for language, theme, display name, and server URL, with `--setup` and `--language/--theme/--server/--name` overrides, token-free `tui.json` preferences, and `/exit`/`/quit` command aliases.
10
+ - Give messages the new Markdown rhythm: tighter heading scale, list spacing, blockquote frames, inline code, wrapping long links and words, tables that scroll without widening the page, and a persistent code-block header with language, wrap, and copy controls; Shiki highlighting, footnotes, and link safety stay unchanged.
11
+ - Render system join, leave, removal, admin, forward, reminder, and notice events as compact rows with a matching icon and subtle tint instead of ordinary message bubbles.
12
+ - Add a Re-edit action to your own recalled messages. It loads the retained text into the composer without restoring the original message or sending anything; a non-empty draft asks before it is replaced.
13
+ - Keep PageUp/PageDown scrolling from fighting the jump-to-latest button or Alt+End, so rapid page keys no longer snap the thread back.
14
+ - Keep the Files dialog usable when it is closed and reopened before the previous close event runs; a late close no longer clears the new list.
15
+ - Widen the app for every side pane at large sizes, including Markdown, text, code, and PDF previews as well as tasks, while keeping the room rail fixed and the conversation at least 700px.
16
+ - Make the preview header download button icon-only, matching copy and close, with a localized accessible name.
17
+ - Replace the read count of an own message with a check icon once every eligible member has read it; partial reads keep the count and reader panel.
18
+ - Fix the Keyboard shortcuts dialog so each key group and its description sit close together instead of at opposite edges.
19
+ - Edit a task in a dedicated dialog while adding one stays inline; saving updates the card and cancel, Escape, or the backdrop discard the draft.
20
+ - Cap each room at 10 tasks by default. Set `CHAT_ROOM_MAX_ROOM_TASKS` to a positive integer to change the cap; creating past it returns 409 with the current limit, and deleting a completed task frees a slot. Task lists now return the current `limit`.
21
+ - Move Reminders into the Options menu and let Settings choose Dialog or Side pane for Announcements, Files, Tasks, and Reminders, persisted per browser.
22
+ - Add an optional borderless window mode. Every client keeps the framed card by default; Settings → Appearance can switch to borderless, the choice persists, and the rail, conversation, and side panes keep their layout.
23
+ - Let touchpad pinch zoom work over the conversation: Ctrl/Cmd+wheel is left to the browser, while a plain wheel still scrolls only the thread and does not chain to the page.
24
+ - Add an admin-only Integrations settings page (enabled by `CHATROOM_ALLOW_ADMIN=true`) for platform accounts, JavaScript adapter upload, and forwarding rules. The server owns the adapter command, validates and handshakes uploads before saving, keeps credentials write-only, and exposes only environment variable names. Account environment edits merge only changed keys, `{}` clears, and `envDelete` removes named keys without touching the rest.
25
+ - Reload, enable, or disable Integrations without restarting the room server. The new configuration is validated before the old runtime stops; a failed start restores it, a bad account fails alone, and in-flight deliveries become `unknown` without automatic resend. An integration started from an external `CHAT_ROOM_CHANNELD_CONFIG` is shown read-only until it is disabled, so the admin page cannot silently replace it.
26
+ - Add the Monaco-based rules editor to Integrations. It loads lazily, supports JSON and YAML, validates rules and inbound routes against the server schema, links errors to their lines, and leaves the textarea usable if the bundle fails; its assets and license ship with the package.
27
+ - Complete Feishu delivery: opt into block Markdown with `FEISHU_CARD_VERSION=2.0`, use a native Feishu reply when the forwarded room parent reached the same target, and relay allowlisted Feishu group text into the room through the opt-in inbound long connection. Inbound events deduplicate persistently, never match outbound rules, and are acknowledged only after the room notification is stored.
28
+ - Preview Word (`.docx`), Excel (`.xlsx`), and PowerPoint (`.pptx`) files in the reading pane or modal. The Office bundles load lazily, sanitize rendered HTML, cap files at 20 MiB, render Excel per sheet with a 2,000-row/100-column limit, reflow PowerPoint slides when the pane or full-screen width changes, and keep Download available when parsing fails.
29
+ - Add a full-screen toggle to every document preview, including Markdown, text/code, PDF, and Office. Escape leaves full screen first and closes the preview on the next press, returning focus to the current file card even after inbox polling rerenders the message list. Each Office parse renders into its own container and is invalidated when the preview closes or switches files, so a slow render cannot leave stale slide or table content behind.
30
+ - Speed up room polling and large room lists: `/rooms/summary` now reads the latest message time with a dedicated aggregate query instead of hydrating each room, and `/rooms` accepts optional `limit`/`offset` while keeping its original response shape when neither is supplied.
31
+
32
+ ## 0.8.0 — 2026-11-25
33
+
34
+ - Let agents address earlier messages directly. `get_message` returns author, sequence, parent, resources, and recall status; a recalled message returns an explicit tombstone without its text or attachments. `send` accepts `parentMessageId`, and `catch_up` reads persisted messages after a cursor with bounded pages, has-more, unread mentions, and open questions. Cross-room, cross-host, non-member, kicked, and pending identities get the same 404, and catch-up never marks messages read or calls the model.
35
+ - Add Channel D forwarding behind `server.channeld`, enabled when configured and off without a config. A room message can be forwarded to a configured target from the message actions; ordinary messages never produce a relay delivery or notification, only an explicit forward does. Channel deliveries and receipts live in a separate `channeld.sqlite`; a terminal delivery records one queryable `result.published` event without message content and then writes a localized system message back to the room; deleting that file with the feature disabled is a full rollback. The release ships an outbound Feishu adapter that sends interactive cards with `lark_md` inline formatting (block Markdown such as headings, lists, and fenced code awaits the card 2.0 upgrade in 0.8.x) and a mock adapter for tests; native Feishu reply and Feishu-to-room inbound relay remain planned for 0.8.x. A config path enables the feature automatically, while no config leaves it off. Queue health is counts-only: `GET /channeld/status` on the server reports queue depth, oldest backlog, delivery states, unknown/retry/rate-limit counts, and event/delivery/receipt gaps without message content.
36
+ - Highlight messages and text/code previews with a lazily loaded Shiki 4.6 bundle covering 16 languages, including TSX and JSX. Light and dark themes reuse the existing code tokens, and a failed or blocked bundle falls back to escaped plain text without losing wrap, copy, or language labels.
37
+ - Give file actions matching Fluent icons: message-card download and preview, the file menu's delete item, the preview header's download, and the already icon-only Files row actions. Icons are 16px, baseline-aligned, keep their accessible labels, and survive language changes.
38
+ - Make the palette search-first: any input that does not start with `/` searches messages as you type, while `/` lists commands only. Typing no longer requires Tab, and commands no longer appear among message results.
39
+ - Widen the task board on large screens while keeping at least 700px for the conversation, and keep the board open when switching rooms.
40
+ - Bound catch-up open-question references at 200 while still reporting the total count, so a room with hundreds of open questions cannot produce an unbounded response.
41
+ - Render Markdown footnotes as numbered internal anchors with a footnote list instead of letting the parser turn a definition into a relative link; only external links open a new tab, and relative or same-origin API links no longer navigate to an unauthenticated error page. A reference inside deeply nested list indentation may render as paragraph text rather than a code block because of Marked's indentation rules; no placeholder text leaks.
42
+ - Resolve the packaged `watch` command and TUI isolation regressions, and report a clear central-only error when a standalone client asks for message addressing.
43
+ - License the project under MIT and streamline the English and Chinese READMEs.
44
+
3
45
  ## 0.7.8 — 2026-11-24
4
46
 
5
47
  - Make the web and terminal palettes search-first: anything that does not start with `/` is live message search as you type, and `/` lists commands only. Commands no longer mix into search results, and an idle palette shows a hint instead of a command list. Command filtering matches both the localized label and an English alias, and Chinese/Japanese/Korean IME commits filter on composition end instead of leaving the full list.
@@ -16,7 +58,7 @@
16
58
  - Cache recently viewed room images in the service worker so repeated and offline loads are faster. The cache is bounded (80 entries, 64 MiB, 30-day prune), partitioned by browser identity, cleared when the identity or token changes, and keeps the same security headers on cache hits.
17
59
  - Stop pinch zoom from resizing the app: the viewport height sync ignores non-1 visual viewport scales, so the layout no longer collapses under a zoom gesture.
18
60
  - Tighten the mobile layout: a shorter header, a smaller composer with the input and buttons on one line, and a sliding room drawer with a fading backdrop. Keyboard-shortcut hints are hidden on real mobile devices (Android, iOS, and touch-capable iPadOS) but remain in narrow desktop windows.
19
- - Preview plain-text and code room files in the reading pane with syntax highlighting, and open PDFs in the native viewer. Text-like files, Markdown included, gain a copy action on the message card, in the Files list, and in the preview header; text over 2 MiB shows a download notice instead of rendering.
61
+ - Preview plain-text and code room files in the reading pane with syntax highlighting, and open PDFs in the native viewer. Text-like files, Markdown included, gain a copy action in the Files list and the preview header; text over 2 MiB shows a download notice instead of rendering.
20
62
  - Fix the Codex plugin when Codex copies it into its plugin cache: YAML configuration loads only when needed, so a cached copy without `node_modules` still serves JSON/JSONC configs, and a plugin failure no longer blocks Codex session startup.
21
63
 
22
64
  ## 0.7.7 — 2026-11-23
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Summer
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,10 +1,12 @@
1
1
  # OC Chat
2
2
 
3
- Chat in shared rooms with OpenCode agents and people. Send replies, questions, files, announcements, and scheduled reminders.
3
+ Chat in shared rooms with OpenCode agents and people. Use the web or terminal client; one server connects multiple hosts.
4
4
 
5
- [简体中文](README.zh-CN.md) · [Technical reference](https://github.com/agentsyaml/opencode-chat-room/blob/main/docs/reference.en.md)
5
+ [简体中文](README.zh-CN.md) · [Technical reference](docs/reference.en.md) · [Changelog](CHANGELOG.md)
6
6
 
7
- ## 1. Install the plugin
7
+ ## Quick start
8
+
9
+ ### 1. Add the plugin
8
10
 
9
11
  Install [Bun](https://bun.sh), then add the plugin to `~/.config/opencode/opencode.json`:
10
12
 
@@ -15,21 +17,19 @@ Install [Bun](https://bun.sh), then add the plugin to `~/.config/opencode/openco
15
17
  }
16
18
  ```
17
19
 
18
- Restart OpenCode. Ask an agent to create a room named `dev`, or enter `/room create dev`.
20
+ Restart OpenCode and ask an agent to create a room, or enter `/room create dev`.
19
21
 
20
- When upgrading an existing install, quit OpenCode first or use `opencode plugin add @alexsun-top/opencode-chat-room@<version>`. Editing the version in `opencode.json` while the host is running can leave an empty package directory under `~/.cache/opencode/npm/`, which makes the plugin fail to load. Delete that directory and run `opencode plugin add` again to recover.
22
+ When upgrading, quit OpenCode first or run `opencode plugin add @alexsun-top/opencode-chat-room@<version>`. Editing the version while OpenCode is running can leave a broken package cache under `~/.cache/opencode/npm/`; delete that directory and add the plugin again to recover.
21
23
 
22
- ## 2. Connect multiple devices
24
+ ### 2. Start a server
23
25
 
24
- On a machine reachable by the other devices, start the server. Replace `your-password` with a shared password:
26
+ On a machine reachable by the other devices:
25
27
 
26
28
  ```bash
27
- npx --yes --package=@alexsun-top/opencode-chat-room@0.7.8 -- opencode-chat-room --host 0.0.0.0 --port 4399 --token 'your-password'
29
+ npx --yes --package=@alexsun-top/opencode-chat-room@0.8.1 -- opencode-chat-room --host 0.0.0.0 --port 4399 --token 'your-password'
28
30
  ```
29
31
 
30
- The server runs on Node.js 24.2+, Deno 2, or Bun; `bunx` and Deno commands are in the [reference](docs/reference.en.md#central-mode-multi-host). OpenCode itself still runs on Bun.
31
-
32
- On each machine running OpenCode, set the server address and the same password, then start OpenCode from that environment:
32
+ The server runs on Node.js 24.2+, Deno 2, or Bun. On each OpenCode machine, set the address and the same token, then start OpenCode:
33
33
 
34
34
  ```bash
35
35
  export CHAT_ROOM_SERVER_URL="http://SERVER_IP:4399"
@@ -37,47 +37,88 @@ export CHAT_ROOM_SERVER_TOKEN="your-password"
37
37
  opencode
38
38
  ```
39
39
 
40
- Environment variables can be replaced by an optional `chatroom.json`, `chatroom.jsonc`, `chatroom.yaml`, or `chatroom.yml`; see the [configuration reference](docs/reference.en.md#configuration-file). Environment variables still override the file.
40
+ Open `http://SERVER_IP:4399/chat` and enter the token in Settings. Environment variables can be replaced by a `chatroom.json`, `chatroom.jsonc`, `chatroom.yaml`, or `chatroom.yml`; see the [configuration reference](docs/reference.en.md#configuration-file).
41
41
 
42
- Open `http://SERVER_IP:4399/chat` in a browser and enter the same password in Settings. The same dialog, available before joining and from the chat menu, groups language, theme, scrolling, and the access token under General, Appearance, and Connection. Create or join a room there, and ask each agent to join it too.
43
-
44
- **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. Join approval controls the normal join flow; it is not per-user authentication, so it does not stop a password holder from misrepresenting itself.
42
+ **Security:** anyone with the shared token can access and manage rooms, including direct chats. Join approval controls the normal join flow, not per-user authentication. Share the token only with trusted people and protect network access to the server.
45
43
 
46
44
  ### Docker
47
45
 
48
- Every release also publishes a container image, so nothing needs to be built:
49
-
50
46
  ```bash
51
47
  docker run --rm -p 4399:4399 -v chat-room-data:/data \
52
48
  -e CHAT_ROOM_SERVER_TOKEN='your-password' \
53
49
  ghcr.io/agentsyaml/opencode-chat-room:latest
54
50
  ```
55
51
 
56
- Pin a release with `ghcr.io/agentsyaml/opencode-chat-room:v0.7.8`. Rooms, messages and receipts live in the `/data` volume; keep it mounted across upgrades. If you bind-mount a host directory instead of a named volume, make it writable by uid `10001`.
52
+ Pin a release with `ghcr.io/agentsyaml/opencode-chat-room:v0.8.1`. Rooms and files live in the `/data` volume; keep it across upgrades. A host bind mount must be writable by uid `10001`.
53
+
54
+ ### Docker Compose
55
+
56
+ The repository's `docker-compose.yaml` runs the app by default and keeps PostgreSQL and RustFS behind optional profiles. Copy `.env.example` to `.env` and set `CHAT_ROOM_SERVER_TOKEN`; Compose refuses to start without it instead of exposing an unauthenticated server. Then:
57
+
58
+ ```bash
59
+ docker compose up -d --build
60
+ docker compose --profile postgres up -d # optional PostgreSQL state
61
+ docker compose --profile rustfs up -d # optional S3-compatible storage
62
+ ```
63
+
64
+ Set `CHAT_ROOM_DATABASE_URL=postgresql://chatroom:CHANGEME@postgres:5432/chatroom` in `.env` when using the PostgreSQL profile. For RustFS, set `CHAT_ROOM_STORAGE=s3`, `CHAT_ROOM_S3_ENDPOINT=http://rustfs:9000`, `CHAT_ROOM_S3_BUCKET=chat-room`, and matching access keys, and create the bucket before starting the app. Pin the image with `BUILD_VERSION=v0.8.1`; `DOCKER_REGISTRY` and `SERVICE_NAME` override the image. The healthcheck probes `/chat`.
65
+
66
+ ### S3 file storage
57
67
 
58
- ## 3. Start chatting
68
+ Files are stored beside the SQLite database by default. To keep them in S3 or an S3-compatible store (RustFS, MinIO, AWS S3), set `CHAT_ROOM_STORAGE=s3`, `CHAT_ROOM_S3_BUCKET`, `CHAT_ROOM_S3_ACCESS_KEY_ID`, and `CHAT_ROOM_S3_SECRET_ACCESS_KEY`; optionally set `CHAT_ROOM_S3_ENDPOINT`, `CHAT_ROOM_S3_REGION` (default `us-east-1`), `CHAT_ROOM_S3_PREFIX` (default `chat-room`), and `CHAT_ROOM_S3_FORCE_PATH_STYLE` (default true when an endpoint is set). The bucket must exist; startup fails if it is unreachable, credentials are rejected, or a required variable is missing. Uploads stream through a local temp file and only commit the database row after the S3 object is written. Files stay cached under the state directory unless `CHAT_ROOM_S3_LOCAL_CACHE=0` (also `false` or `off`); cached reads survive an S3 outage, but uploads and uncached reads fail instead of falling back to local storage. Minimal IAM permissions on the bucket: `s3:PutObject`, `s3:GetObject`, `s3:DeleteObject`, `s3:ListBucket`, and `s3:HeadBucket`, scoped to `<prefix>/*` where applicable. See the [reference](docs/reference.en.md#environment-variables).
59
69
 
60
- - Ask an agent to create a room, join a room, or send a message; you can also use the web interface.
61
- - When creating or editing a room, turn on **Require approval to join**. You and other human administrators approve people and Agents from the member panel; a designated management agent can also approve Agent requests. A pending applicant is not a member yet.
62
- - The Edit room dialog groups room details, joining and approval, members and roles, and ownership. Only the owner sees the ownership tab.
63
- - Use Reply to respond to a message. Mark a message as a question when you need an answer.
64
- - Use the room's reminder button for one-time or recurring reminders. Times default to the server's time zone.
65
- - Reminder text supports `{{time}}`, `{{initiator}}`, and `{{room}}`.
66
- - A compact shortcut chip under the composer shows Alt+/ (Option+/ on Mac); click it or press the keys to open the sheet. Alt+1…9 switches to a joined room by its position in the rail, Alt+Home/Alt+End smoothly scroll to the oldest/latest loaded message, and PageUp/PageDown scrolls the conversation in one animated step while you type, and Settings sets that step with a slider as a percentage of the conversation height (default 90%).
67
- - Press Alt+Space (Option+Space on Mac) or Ctrl+P anywhere, including the composer, to search messages. Search starts in the current room; Tab switches to all joined rooms and back. Type `/` to filter common commands instead. ↑/↓ and Enter open a result and highlight it in the conversation; Esc or a backdrop click closes and returns to the composer.
68
- - Attach files, drag them in, or paste images. The default limit is 500 MiB per file. Room Options also opens Announcements, Files, and Tasks. Files can be filtered by uploader, preview supported media and Markdown documents, and downloaded or deleted. Tasks open in a fixed right pane on wide screens and a modal on small ones. A task tracks title, description, assignee, due date, participants, checklist steps, conclusion, and todo/doing/done status; members create tasks, creators and human administrators manage them, assignees update status or step completion, and completed tasks can be cleared from the pane header.
69
- - In a terminal, run `bunx --package @alexsun-top/opencode-chat-room@0.7.8 opencode-chat-room cli` against the same server. The terminal client is built into the main package, renders Markdown with highlighted mentions, and supports room navigation, pending joins, sending, members, announcements, questions and asking, files, reminders, room settings, join approvals, recall/reveal/reply by message ID, settings, and Alt+Space (or Ctrl+P) search. Typing `/` at the start of the composer opens a filtered inline command popup without leaving the input; typing `@` suggests room members and `@all`, inserts a highlighted mention, and sends the canonical mention tag. Commands include quit. It uses OpenTUI: Bun 1.3.14+ is recommended, Node.js 26.4+ needs `--experimental-ffi`, and Deno is not supported for this client. If `bunx` starts the package with Node but a supported Bun is installed, the CLI relaunches itself with Bun. Only `cli` loads OpenTUI; the server and `watch` stay on Node.js 24.2+, Deno 2, and Bun.
70
- - Fenced code blocks are syntax-highlighted locally. Hover or focus a block for icon-only wrap and copy controls.
71
- - Agents can recall a message by ID; the original stays available to current members.
72
- - Agents can use the `room` tool's `read_resource` action to save an attachment to a temporary file before opening it.
70
+ ### PostgreSQL state (experimental, single-instance)
73
71
 
74
- ### Install as an app
72
+ Set `CHAT_ROOM_DATABASE_URL=postgresql://user:password@host:5432/chatroom` on the **server** to keep room state in PostgreSQL 16+ instead of `chat-room.sqlite`. This backend is experimental in 0.8.1 and single-instance only: the server holds a session advisory lock, and a second chat-room process fails startup with a clear error. Multi-instance support is planned for 0.8.2. Set the variable only on the server; clients, watchers, and Channel D keep their own SQLite files. Channel D remains SQLite and single-host. S3-compatible resource storage is stable and independent of the database choice.
75
73
 
76
- The web interface ships a web app manifest and a service worker, so a phone can add it to the home screen and open it without browser chrome. When the network is gone it starts from the cached interface; chat data itself is never cached. When a new version is ready, a bottom-left prompt lets you update now or later; choosing later keeps the current page and applies it on the next open. Browsers only grant this over HTTPS (or on `localhost`), so put the server behind an HTTPS reverse proxy if you want the install prompt to appear.
74
+ Stop the server and make a WAL-safe SQLite backup before migrating:
75
+
76
+ ```bash
77
+ sqlite3 ~/.config/opencode/chat-room/chat-room.sqlite \
78
+ ".backup '$HOME/chat-room.sqlite.backup'"
79
+ CHAT_ROOM_DATABASE_URL=postgresql://user:password@host:5432/chatroom \
80
+ npx --yes --package=@alexsun-top/opencode-chat-room@0.8.1 -- \
81
+ opencode-chat-room migrate --to-postgres --yes
82
+ ```
77
83
 
78
- For OpenCode sessions on one machine, no server or environment variables are needed. The web interface and multi-machine chat require the central server.
84
+ The command copies all state tables in foreign-key order, preserves IDs and message `seq` values, advances the PostgreSQL sequence, verifies row counts, and refuses a non-empty target. Rollback is an environment switch: unset `CHAT_ROOM_DATABASE_URL` and start the server from the untouched SQLite file. Messages written while PostgreSQL was active are not copied back to SQLite.
85
+
86
+ ## Channel D (Feishu outbound)
87
+
88
+ Channel D is an optional forwarding sidecar, not a second chat. It forwards selected room messages to external targets. This release includes an outbound Feishu adapter and a mock adapter for tests; enable it only in central mode with a config path:
89
+
90
+ ```json
91
+ {
92
+ "server": {
93
+ "channeld": {
94
+ "config": "/etc/chatroom/channeld.yml"
95
+ }
96
+ }
97
+ }
98
+ ```
99
+
100
+ Or set `CHAT_ROOM_CHANNELD_CONFIG=/path/channeld.yml`. A config enables it; no config keeps it off, and `CHAT_ROOM_CHANNELD=0` or `"enabled": false` overrides the config. The YAML defines accounts and rules; see the [Channel D reference](docs/reference.en.md#channel-d-feishu-outbound). The Feishu adapter reads `FEISHU_APP_ID` and `FEISHU_APP_SECRET`, with optional `FEISHU_BASE_URL`; a rule target's `room` is the Feishu `chat_id`.
101
+
102
+ Forwarding is explicit: messages gain a Forward action when a rule matches, ordinary messages are never relayed automatically. Terminal deliveries record an ID/state-only `result.published` event and write a localized system message back to the room. State lives in `<stateDir>/channeld.sqlite`, separate from the room database; disable the feature, stop the server, and delete that file to roll back. With `CHATROOM_ALLOW_ADMIN=true`, Settings → Integrations manages accounts, uploaded JavaScript adapters, and forwarding rules without editing YAML. `POST /channeld/reload`, `/channeld/enable`, and `/channeld/disable` swap the relay runtime without restarting the center: invalid configs keep the old runtime, a failed restart restores the previous runtime, and in-flight deliveries become `unknown` without auto-resend. Persistence uses an existing writable JSON or YAML room config; otherwise the response reports that a restart is required. Admins can upload JavaScript adapters with `POST /channeld/plugins` (max 256 KiB, handshaken before saving) and manage accounts/rules with `GET`/`PUT /channeld/integration`; the server owns the `node` command and stores env values write-only under `<stateDir>/integrations`, returning only env keys plus the uploaded plugin list; omitting an account's `env` keeps its current values, a non-empty `env` merges only the listed keys, `env: {}` clears, and `envDelete` removes named keys. Feishu cards default to card 1.0 `lark_md`; set `FEISHU_CARD_VERSION=2.0` for block Markdown, and a forwarded room reply whose `answer_to` parent reached the same target uses a native Feishu reply. Opt-in inbound (`FEISHU_INBOUND=1` plus `FEISHU_INBOUND_CHATS` and an `inbound` route) turns allowlisted Feishu group text/post messages into one idempotent room notification each; inbound events never match outbound rules.
103
+
104
+ ## What you can do
105
+
106
+ - **Rooms and people:** create or join rooms, invite devices, approve joins, manage members and owners, and open direct chats.
107
+ - **Messages:** reply, mark questions, recall with a recoverable original, and mention people or `@all`.
108
+ - **Files:** attach, drag, or paste up to 500 MiB; preview images, media, Markdown, text, code, PDF, Word (.docx), Excel (.xlsx), and PowerPoint (.pptx); open any document preview full screen; download or delete.
109
+ - **Tasks:** track title, assignee, due date, participants, steps, conclusion, and todo/doing/done state in a side pane or modal. Each room holds at most 10 tasks by default; set `CHAT_ROOM_MAX_ROOM_TASKS` to a positive integer to change the cap, and delete a completed task first when the room is full.
110
+ - **Reminders:** schedule one-time or cron reminders; text supports `{{time}}`, `{{initiator}}`, and `{{room}}`.
111
+ - **Search and shortcuts:** Alt+Space or Ctrl+P searches messages; `/` filters commands in the composer. Alt+1…9 switches rooms. More shortcuts are in Settings.
112
+ - **Terminal:** run `bunx --package @alexsun-top/opencode-chat-room@0.8.1 opencode-chat-room cli` against the same server. It supports rooms, messages, files, reminders, approval, search, editable settings for language/theme/name/server, and `/exit`. Bun 1.3.14+ is recommended; only the CLI loads OpenTUI.
113
+ - **Code:** fenced blocks are highlighted by a lazily loaded Shiki bundle with wrap and copy controls.
114
+ - **Web app:** the interface installs to a phone home screen and starts offline from cache; chat data is never cached.
79
115
 
80
116
  ## More help
81
117
 
82
- - [Configuration, administrator features, and API reference](https://github.com/agentsyaml/opencode-chat-room/blob/main/docs/reference.en.md)
118
+ - [Configuration, administrator features, and API reference](docs/reference.en.md)
83
119
  - [Changelog](CHANGELOG.md)
120
+ - Ask an agent in a room; the bundled `chatroom` skill describes the full room workflow.
121
+
122
+ ## License
123
+
124
+ MIT
package/README.zh-CN.md CHANGED
@@ -1,12 +1,14 @@
1
1
  # OC Chat
2
2
 
3
- 让多个 OpenCode 会话和真人在同一个房间里聊天。支持回复、提问、附件、公告和定时提醒。
3
+ 与 OpenCode Agent 和人在共享房间里聊天。用网页或终端客户端;一个服务端连接多台主机。
4
4
 
5
- [English](README.md) · [详细技术说明](https://github.com/agentsyaml/opencode-chat-room/blob/main/docs/reference.zh-CN.md)
5
+ [English](README.md) · [技术参考](docs/reference.zh-CN.md) · [更新日志](CHANGELOG.md)
6
6
 
7
- ## 1. 安装插件
7
+ ## 快速开始
8
8
 
9
- 先安装 [Bun](https://bun.sh),然后在 `~/.config/opencode/opencode.json` 中添加:
9
+ ### 1. 安装插件
10
+
11
+ 先安装 [Bun](https://bun.sh),再把插件加入 `~/.config/opencode/opencode.json`:
10
12
 
11
13
  ```json
12
14
  {
@@ -15,69 +17,108 @@
15
17
  }
16
18
  ```
17
19
 
18
- 重启 OpenCode。现在你可以让 Agent「创建一个叫 dev 的聊天室」,或输入 `/room create dev`。
20
+ 重启 OpenCode,让 Agent 创建一个房间,或输入 `/room create dev`。
19
21
 
20
- 升级已有安装时,先退出 OpenCode,或使用 `opencode plugin add @alexsun-top/opencode-chat-room@<版本>`。在宿主运行中直接改 `opencode.json` 里的版本号,可能在 `~/.cache/opencode/npm/` 下留下空目录,导致插件加载失败。遇到时删掉该空目录,再执行一次 `opencode plugin add`。
22
+ 升级时先退出 OpenCode,或运行 `opencode plugin add @alexsun-top/opencode-chat-room@<version>`。在 OpenCode 运行时改版本号可能在 `~/.cache/opencode/npm/` 留下损坏的包缓存;删除该目录后重新添加插件即可恢复。
21
23
 
22
- ## 2. 多台设备一起使用
24
+ ### 2. 启动服务端
23
25
 
24
- 在一台可被其他设备访问的机器上启动服务器,把 `换成自己的密码` 换成共享密码:
26
+ 在一台其他设备可访问的机器上运行:
25
27
 
26
28
  ```bash
27
- npx --yes --package=@alexsun-top/opencode-chat-room@0.7.8 -- opencode-chat-room --host 0.0.0.0 --port 4399 --token '换成自己的密码'
29
+ npx --yes --package=@alexsun-top/opencode-chat-room@0.8.1 -- opencode-chat-room --host 0.0.0.0 --port 4399 --token 'your-password'
28
30
  ```
29
31
 
30
- 服务端可在 Node.js 24.2+、Deno 2 或 Bun 上运行;`bunx` 与 Deno 命令见[参考文档](docs/reference.zh-CN.md)。OpenCode 本身仍运行在 Bun 上。
31
-
32
- 在每台运行 OpenCode 的机器上设置服务器地址和相同密码,再从该环境启动 OpenCode:
32
+ 服务端支持 Node.js 24.2+、Deno 2 或 Bun。每台运行 OpenCode 的机器设置地址和同一个令牌,然后启动 OpenCode:
33
33
 
34
34
  ```bash
35
- export CHAT_ROOM_SERVER_URL="http://服务器IP:4399"
36
- export CHAT_ROOM_SERVER_TOKEN="换成自己的密码"
35
+ export CHAT_ROOM_SERVER_URL="http://SERVER_IP:4399"
36
+ export CHAT_ROOM_SERVER_TOKEN="your-password"
37
37
  opencode
38
38
  ```
39
39
 
40
- 也可以用可选的 `chatroom.json`、`chatroom.jsonc`、`chatroom.yaml` 或 `chatroom.yml` 替代环境变量;详见[配置文件说明](docs/reference.zh-CN.md#配置文件)。环境变量仍然优先于文件。
40
+ 打开 `http://SERVER_IP:4399/chat`,在设置里填入同一个令牌。也可以用 `chatroom.json`、`chatroom.jsonc`、`chatroom.yaml` 或 `chatroom.yml` 代替环境变量;详见[配置参考](docs/reference.zh-CN.md#配置文件)。
41
41
 
42
- 在浏览器打开 `http://服务器IP:4399/chat`,在设置窗口中填入相同密码。同一个设置窗口在加入房间前和聊天菜单中都能打开,按通用、外观、连接三个类别组织语言、主题、滚动选项和访问令牌。然后创建或加入房间,每个 Agent 也需要加入同一个房间。
43
-
44
- **安全提示:**共享密码的持有人可以访问和管理房间,包括私聊;请只分享给可信任的人,并保护服务器网络访问。加入审核只约束正常加入流程,不是按用户认证,无法阻止密码持有人伪装身份。
42
+ **安全:** 持有共享令牌的人可以访问和管理所有房间,包括私聊。加入审核只控制正常加入流程,不是按用户认证。令牌只发给可信的人,并保护服务端的网络访问。
45
43
 
46
44
  ### Docker
47
45
 
48
- 每次发版同时发布容器镜像,不需要自己构建:
49
-
50
46
  ```bash
51
47
  docker run --rm -p 4399:4399 -v chat-room-data:/data \
52
- -e CHAT_ROOM_SERVER_TOKEN='换成自己的密码' \
48
+ -e CHAT_ROOM_SERVER_TOKEN='your-password' \
53
49
  ghcr.io/agentsyaml/opencode-chat-room:latest
54
50
  ```
55
51
 
56
- 用 `ghcr.io/agentsyaml/opencode-chat-room:v0.7.8` 可以固定到具体版本。房间、消息和回执都保存在 `/data` 卷里,升级时保留该卷即可。如果改用宿主目录做挂载,需要让该目录对 uid `10001` 可写。
52
+ 用 `ghcr.io/agentsyaml/opencode-chat-room:v0.8.1` 固定版本。房间和文件保存在 `/data` 卷里,升级时不要删除。若改用宿主机目录绑定,目录需允许 uid `10001` 写入。
53
+
54
+ ### Docker Compose
55
+
56
+ 仓库里的 `docker-compose.yaml` 默认只运行主应用,PostgreSQL 和 RustFS 通过可选 profile 启动。先复制 `.env.example` 为 `.env` 并设置 `CHAT_ROOM_SERVER_TOKEN`;缺少该令牌时 Compose 会拒绝启动,避免暴露未认证服务。然后:
57
+
58
+ ```bash
59
+ docker compose up -d --build
60
+ docker compose --profile postgres up -d # 可选 PostgreSQL 状态
61
+ docker compose --profile rustfs up -d # 可选 S3 兼容存储
62
+ ```
63
+
64
+ 使用 PostgreSQL profile 时,在 `.env` 里设置 `CHAT_ROOM_DATABASE_URL=postgresql://chatroom:CHANGEME@postgres:5432/chatroom`。使用 RustFS 时,设置 `CHAT_ROOM_STORAGE=s3`、`CHAT_ROOM_S3_ENDPOINT=http://rustfs:9000`、`CHAT_ROOM_S3_BUCKET=chat-room` 和对应的访问密钥,并在启动应用前创建存储桶。用 `BUILD_VERSION=v0.8.1` 固定镜像;`DOCKER_REGISTRY` 和 `SERVICE_NAME` 可以覆盖镜像地址。健康检查探测 `/chat`。
65
+
66
+ ### S3 文件存储
57
67
 
58
- ## 3. 开始聊天
68
+ 文件默认与 SQLite 数据库放在一起。要改用 S3 或兼容 S3 的存储(RustFS、MinIO、AWS S3),设置 `CHAT_ROOM_STORAGE=s3`、`CHAT_ROOM_S3_BUCKET`、`CHAT_ROOM_S3_ACCESS_KEY_ID` 和 `CHAT_ROOM_S3_SECRET_ACCESS_KEY`;可选 `CHAT_ROOM_S3_ENDPOINT`、`CHAT_ROOM_S3_REGION`(默认 `us-east-1`)、`CHAT_ROOM_S3_PREFIX`(默认 `chat-room`)和 `CHAT_ROOM_S3_FORCE_PATH_STYLE`(设置 endpoint 时默认 true)。存储桶必须已存在;桶不可达、凭证被拒或缺少必填变量时服务端拒绝启动。上传先写入本地临时文件,S3 对象写入成功后才提交数据库记录。除非设置 `CHAT_ROOM_S3_LOCAL_CACHE=0`(也支持 `false` 或 `off`),文件会同时缓存到状态目录;S3 故障时缓存读取仍可用,但上传和未缓存的读取会直接失败,不会回退到本地存储。桶上的最小 IAM 权限:`s3:PutObject`、`s3:GetObject`、`s3:DeleteObject`、`s3:ListBucket`、`s3:HeadBucket`,可按 `<prefix>/*` 缩小范围。详见[参考](docs/reference.zh-CN.md#环境变量)。
59
69
 
60
- - 让 Agent 创建房间、加入房间或发送消息;也可以在网页里操作。
61
- - 创建或编辑房间时可开启「需审核加入」。你和其他人类管理员在成员面板审核人和 Agent;被指定的管理 Agent 也可以审核 Agent 的申请。待审核的申请人还不算成员。
62
- - 编辑房间按房间资料、加入与审核、成员与角色、所有权分组;所有权仅房主可见。
63
- - 回复消息时点击回复;需要对方回答的问题可标记为「问题」。
64
- - 点击房间里的提醒按钮,可创建一次性或周期提醒。默认使用服务器时区。
65
- - 提醒正文支持 `{{time}}`、`{{initiator}}`、`{{room}}` 模板变量。
66
- - 输入框下方保留唯一快捷键入口,以紧凑标签显示 Alt+/(Mac 为 Option+/);点击或按快捷键都能打开面板。Alt+1…9 按房间在侧栏中的位置切换已加入房间,Alt+Home/Alt+End 平滑滚动到最早/最新的已加载消息,输入时用 PageUp/PageDown 按动画滚动一屏,步长可在设置中用滑动条按会话高度百分比调整(默认 90%)。
67
- - 在任意位置(包括输入框)按 Alt+Space(Mac 为 Option+Space)或 Ctrl+P 打开搜索:默认搜索当前房间,按 Tab 切换到全部已加入房间;输入 `/` 可改为过滤常用命令。↑/↓ 加 Enter 打开结果并在会话中高亮;Esc 或点击遮罩关闭并回到输入框。
68
- - 点击附件按钮、拖入文件或粘贴图片即可分享;默认单文件上限为 500 MiB。房间选项里还有“公告”“文件”和“任务”;文件可以按上传者筛选、预览支持的媒体和 Markdown 文档,并下载或删除。任务在宽屏固定显示于右侧,小屏使用弹窗。任务包含标题、描述、负责人、截止日期、参与人员、完成步骤、结论,以及待办/进行中/完成状态;成员可新建,创建者和人类管理员可管理,负责人可更新状态或勾选步骤,面板顶部可以清除已完成任务。
69
- - 终端里可以运行 `bunx --package @alexsun-top/opencode-chat-room@0.7.8 opencode-chat-room cli` 连接同一个服务器。终端客户端已并入主包,会渲染 Markdown 并高亮提及,支持房间切换、待审批加入、发消息、成员、公告、提问与发起提问、文件、提醒、房间设置、加入审核、按消息 ID 撤回/揭示/回复、设置和 Alt+Space(或 Ctrl+P)搜索;在输入框开头输入 `/` 会在输入框上方展开可过滤的命令建议,不会离开输入框;输入 `@` 会出现房间成员和 `@all` 建议,选中后在输入框内高亮显示,发送时转换为标准提及标签 `<at>@名字</at>`。命令包含退出程序。它使用 OpenTUI:推荐 Bun 1.3.14+,Node.js 26.4+ 需要 `--experimental-ffi`,Deno 不支持该客户端。如果 `bunx` 使用 Node 启动但本机安装了受支持的 Bun,CLI 会自动改用 Bun 重新启动。只有 `cli` 会加载 OpenTUI;服务端和 `watch` 仍支持 Node.js 24.2+、Deno 2 和 Bun。
70
- - 围栏代码块会在本地做语法高亮;鼠标悬停或键盘聚焦时显示纯图标的自动换行和复制按钮。
71
- - Agent 可按消息 ID 撤回;当前成员仍可查看原文。
72
- - Agent 收到附件后可通过 `room` 的 `read_resource` 操作保存到临时文件,再打开查看。
70
+ ### PostgreSQL 状态(实验性,单实例)
73
71
 
74
- ### 安装为应用
72
+ 在**服务端**设置 `CHAT_ROOM_DATABASE_URL=postgresql://user:password@host:5432/chatroom`,房间状态就会写入 PostgreSQL 16+,不再使用 `chat-room.sqlite`。该后端在 0.8.1 中属于实验功能,且只支持单实例:服务端会持有会话级 advisory lock,第二个 chat-room 进程会启动失败并给出明确错误。多实例支持计划在 0.8.2 提供。只应在服务端设置该变量;客户端、watcher 和 Channel D 继续使用各自的 SQLite 文件。Channel D 保持 SQLite、单主机。S3 兼容资源存储已稳定,与数据库选择无关。
75
73
 
76
- 网页端带 Web App Manifest 与 Service Worker:手机可以「添加到主屏幕」,以独立窗口打开,断网时从本地缓存的界面启动。聊天数据本身不进缓存,所以不会看到过期消息。新版本准备好后,左下角会提示立即升级或稍后;选择稍后不会打断当前页面,下次打开时应用更新。浏览器只在 HTTPS(或 `localhost`)下允许这项能力,想让安装入口出现,需要给服务端套一层 HTTPS 反向代理。
74
+ 迁移前先停止服务端,并做一次 WAL 安全的 SQLite 备份:
75
+
76
+ ```bash
77
+ sqlite3 ~/.config/opencode/chat-room/chat-room.sqlite \
78
+ ".backup '$HOME/chat-room.sqlite.backup'"
79
+ CHAT_ROOM_DATABASE_URL=postgresql://user:password@host:5432/chatroom \
80
+ npx --yes --package=@alexsun-top/opencode-chat-room@0.8.1 -- \
81
+ opencode-chat-room migrate --to-postgres --yes
82
+ ```
77
83
 
78
- 只在同一台机器的 OpenCode 会话之间聊天时,无需启动服务器或设置环境变量。网页聊天和跨机器聊天需要中心服务器。
84
+ 该命令按外键顺序复制全部状态表,保留 ID 和消息 `seq`,推进 PostgreSQL 序列,校验行数,并拒绝非空目标库。回滚只需切换环境变量:取消 `CHAT_ROOM_DATABASE_URL`,再用未改动的 SQLite 文件启动旧服务端。PostgreSQL 期间写入的消息不会回写到 SQLite。
85
+
86
+ ## Channel D(飞书出站)
87
+
88
+ Channel D 是可选的转发侧车,不是另一套聊天。它把选定的房间消息转发到外部目标。本版包含飞书出站 adapter 和用于测试的 mock adapter;只在中心模式用配置路径启用:
89
+
90
+ ```json
91
+ {
92
+ "server": {
93
+ "channeld": {
94
+ "config": "/etc/chatroom/channeld.yml"
95
+ }
96
+ }
97
+ }
98
+ ```
99
+
100
+ 或设置 `CHAT_ROOM_CHANNELD_CONFIG=/path/channeld.yml`。有配置就启用,没有配置保持关闭,`CHAT_ROOM_CHANNELD=0` 或 `"enabled": false` 可以覆盖配置强制关闭。YAML 定义账号和规则;详见 [Channel D 参考](docs/reference.zh-CN.md#channel-d飞书出站)。飞书 adapter 读取 `FEISHU_APP_ID` 和 `FEISHU_APP_SECRET`,可选 `FEISHU_BASE_URL`;规则目标的 `room` 就是飞书 `chat_id`。
101
+
102
+ 转发是显式动作:规则命中后消息上出现“转发”操作,普通消息不会被自动转发。终态投递会记录一条仅含 ID/状态的 `result.published` 事件,再向房间写一条本地化系统消息。状态保存在 `<stateDir>/channeld.sqlite`,与房间数据库分开;关闭功能、停止服务并删除该文件即可回滚。设置 `CHATROOM_ALLOW_ADMIN=true` 后,可在“设置 → 平台集成”中管理账号、上传 JavaScript adapter 和编辑转发规则,无需手改 YAML。也可用 `POST /channeld/reload`、`/channeld/enable`、`/channeld/disable` 在不重启中心服务的情况下切换中继运行时:新配置无效时保留旧运行时,新运行时启动失败会恢复旧运行时,在途投递变为 `unknown` 且不会自动重发。只有存在可写的 JSON 或 YAML 房间配置时才会持久化,否则响应会提示需要重启。管理员还可用 `POST /channeld/plugins` 上传 JavaScript adapter(上限 256 KiB,保存前先握手),通过 `GET`/`PUT /channeld/integration` 管理账号和规则;`node` 命令由服务端固定,环境变量只写不读地保存在 `<stateDir>/integrations`,接口只返回变量名和已上传插件列表;账号的 `env` 非空时只合并列出的键,`{}` 清空,`envDelete` 删除指定键,省略 `env` 保留当前值。飞书卡片默认使用 card 1.0 `lark_md`;设置 `FEISHU_CARD_VERSION=2.0` 可启用块级 Markdown,房间回复的 `answer_to` 父消息若已投递到同一目标则使用飞书原生回复。可选入站(`FEISHU_INBOUND=1`、`FEISHU_INBOUND_CHATS` 和 `inbound` 路由)把允许列表群聊里的飞书 text/post 消息写成一条幂等的房间通知;入站事件不会匹配出站规则。
103
+
104
+ ## 可以做什么
105
+
106
+ - **房间与人:** 创建或加入房间,连接多台设备,审核加入,管理成员和房主,打开私聊。
107
+ - **消息:** 回复、标记提问、撤回并保留可恢复的原文、点名成员或 `@all`。
108
+ - **文件:** 附件、拖拽或粘贴,单文件默认上限 500 MiB;预览图片、媒体、Markdown、文本、代码、PDF、Word(.docx)、Excel(.xlsx)和 PowerPoint(.pptx);文档预览可全屏;支持下载和删除。
109
+ - **任务:** 在侧栏或弹窗里跟踪标题、负责人、截止日期、参与人、步骤、结论和 todo/doing/done 状态。每个房间默认最多 10 个任务;设置 `CHAT_ROOM_MAX_ROOM_TASKS` 为正整数可调整上限,房间已满时先删除一个已完成的任务再添加。
110
+ - **提醒:** 一次性或 cron 提醒;文本支持 `{{time}}`、`{{initiator}}` 和 `{{room}}`。
111
+ - **搜索与快捷键:** Alt+Space 或 Ctrl+P 搜索消息;输入框开头输入 `/` 过滤命令。Alt+1…9 切换房间,更多快捷键在设置里。
112
+ - **终端:** 用 `bunx --package @alexsun-top/opencode-chat-room@0.8.1 opencode-chat-room cli` 连接同一服务端,支持房间、消息、文件、提醒、审核、搜索、语言/主题/显示名/服务器设置和 `/exit`。推荐 Bun 1.3.14+;只有 CLI 加载 OpenTUI。
113
+ - **代码:** 围栏代码块由懒加载的 Shiki bundle 高亮,带换行和复制控件。
114
+ - **Web App:** 界面可安装到手机主屏,离线时从缓存启动;聊天数据不会缓存。
79
115
 
80
116
  ## 更多帮助
81
117
 
82
- - [详细配置、管理员功能和 API](https://github.com/agentsyaml/opencode-chat-room/blob/main/docs/reference.zh-CN.md)
83
- - [更新记录](CHANGELOG.md)
118
+ - [配置、管理员功能与 API 参考](docs/reference.zh-CN.md)
119
+ - [更新日志](CHANGELOG.md)
120
+ - 在房间里问 Agent;内置的 `chatroom` skill 说明了完整的房间工作流。
121
+
122
+ ## 许可证
123
+
124
+ MIT
package/cli.ts CHANGED
@@ -14,6 +14,8 @@ Options:
14
14
  -t, --token <token> Enable bearer token authentication
15
15
 
16
16
  Commands:
17
+ migrate [--to-postgres] --yes
18
+ Copy the SQLite state database to PostgreSQL
17
19
  cli [--name <name>] Open the terminal client
18
20
  watch run|start|status|stop`;
19
21
 
@@ -92,6 +94,30 @@ if (args[0] === "watch") {
92
94
  }
93
95
  process.exit(process.exitCode ?? 0);
94
96
  }
97
+ if (args[0] === "migrate") {
98
+ const rest = args.slice(1);
99
+ if (rest.includes("--help") || rest.includes("-h")) {
100
+ console.log("Usage: opencode-chat-room migrate [--to-postgres] --yes\n" +
101
+ "Copies CHAT_ROOM_STATE_DIR/chat-room.sqlite into CHAT_ROOM_DATABASE_URL.\n" +
102
+ "Stop the server and make a WAL-safe backup before using --yes.");
103
+ process.exit(0);
104
+ }
105
+ for (const arg of rest) {
106
+ if (arg !== "--to-postgres" && arg !== "--yes") fail(`Unknown migrate option: ${arg}`);
107
+ }
108
+ const { migrateToPostgres } = await import("./src/state/pg-migrate.ts");
109
+ const { loadRoomConfig, resolveServerSettings } = await import("./src/config/file-config.ts");
110
+ const settings = resolveServerSettings(loadRoomConfig());
111
+ if (!process.env.CHAT_ROOM_STATE_DIR && settings.stateDir) process.env.CHAT_ROOM_STATE_DIR = settings.stateDir;
112
+ const { databasePath } = await import("./src/state/store.ts");
113
+ try {
114
+ await migrateToPostgres({ sourcePath: databasePath(), assumeYes: rest.includes("--yes") });
115
+ } catch (error) {
116
+ console.error(`migrate: ${error instanceof Error ? error.message : "operation failed"}`);
117
+ process.exit(1);
118
+ }
119
+ process.exit(0);
120
+ }
95
121
  for (let i = 0; i < args.length; i += 1) {
96
122
  const arg = args[i]!;
97
123
  if (arg === "-h" || arg === "--help") {
@@ -160,5 +186,5 @@ if (values.token !== undefined) {
160
186
  }
161
187
 
162
188
  const { default: server } = await import("./server/chat-server.ts");
163
- const { startServer } = await import("./server/http-server.ts");
189
+ const { startServer } = await import("./src/platform/http-server.ts");
164
190
  await startServer(server);