@alexsun-top/opencode-chat-room 0.8.0 → 0.8.2

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 (176) hide show
  1. package/CHANGELOG.md +52 -0
  2. package/LICENSE +2 -2
  3. package/README.md +40 -8
  4. package/README.zh-CN.md +40 -8
  5. package/cli.ts +27 -1
  6. package/dist/cli.js +5406 -3088
  7. package/package.json +25 -5
  8. package/packages/chat-room-channeld/README.md +111 -33
  9. package/packages/chat-room-channeld/src/adapter.ts +179 -7
  10. package/packages/chat-room-channeld/src/config.ts +63 -1
  11. package/packages/chat-room-channeld/src/delivery.ts +6 -1
  12. package/packages/chat-room-channeld/src/host-helpers.ts +11 -0
  13. package/packages/chat-room-channeld/src/host.ts +142 -9
  14. package/packages/chat-room-channeld/src/inbound.ts +35 -0
  15. package/packages/chat-room-channeld/src/protocol.ts +52 -1
  16. package/packages/chat-room-channeld/src/rules.ts +7 -2
  17. package/packages/chat-room-channeld/src/state.ts +17 -0
  18. package/packages/chat-room-channeld/src/stats.ts +43 -1
  19. package/plugin.ts +1 -1
  20. package/server/admin-state.ts +13 -13
  21. package/server/app.ts +95 -0
  22. package/server/assets/NOTICE.txt +2 -1
  23. package/server/assets/base.css +21 -9
  24. package/server/assets/chat/admin.js +0 -2
  25. package/server/assets/chat/announcements.js +69 -8
  26. package/server/assets/chat/chat-background.js +177 -0
  27. package/server/assets/chat/confirm-dialog.js +0 -1
  28. package/server/assets/chat/create-room-dialog.js +0 -1
  29. package/server/assets/chat/diagram-viewer.js +7 -1
  30. package/server/assets/chat/doc-preview.js +251 -46
  31. package/server/assets/chat/events.js +16 -5
  32. package/server/assets/chat/files.js +53 -7
  33. package/server/assets/chat/image-zoom.js +8 -1
  34. package/server/assets/chat/index.js +6 -2
  35. package/server/assets/chat/integration-account-schema.js +99 -0
  36. package/server/assets/chat/integration-editor.js +163 -0
  37. package/server/assets/chat/integration-values.js +124 -0
  38. package/server/assets/chat/integrations.js +648 -0
  39. package/server/assets/chat/locales/de.js +40 -4
  40. package/server/assets/chat/locales/es.js +40 -4
  41. package/server/assets/chat/locales/fr.js +40 -4
  42. package/server/assets/chat/locales/it.js +40 -4
  43. package/server/assets/chat/locales/ja.js +40 -4
  44. package/server/assets/chat/locales/ko.js +40 -4
  45. package/server/assets/chat/markdown-footnotes.js +1 -1
  46. package/server/assets/chat/markdown.js +45 -8
  47. package/server/assets/chat/messages.js +6 -5
  48. package/server/assets/chat/office-preview.js +69 -0
  49. package/server/assets/chat/palette.js +6 -1
  50. package/server/assets/chat/panels.js +56 -0
  51. package/server/assets/chat/recall.js +58 -7
  52. package/server/assets/chat/receipts.js +17 -6
  53. package/server/assets/chat/reminders.js +68 -9
  54. package/server/assets/chat/replies.js +0 -6
  55. package/server/assets/chat/resource-format.js +11 -0
  56. package/server/assets/chat/rooms.js +1 -6
  57. package/server/assets/chat/settings.js +98 -4
  58. package/server/assets/chat/shortcuts.js +0 -3
  59. package/server/assets/chat/side-pane.js +34 -10
  60. package/server/assets/chat/state.js +125 -12
  61. package/server/assets/chat/system-events.js +58 -0
  62. package/server/assets/chat/system-messages.js +32 -14
  63. package/server/assets/chat/task-row.js +0 -6
  64. package/server/assets/chat/tasks.js +119 -37
  65. package/server/assets/chat/window-controls.js +37 -0
  66. package/server/assets/code-highlight.css +71 -32
  67. package/server/assets/conversation.css +174 -31
  68. package/server/assets/doc-preview.css +40 -3
  69. package/server/assets/files.css +8 -0
  70. package/server/assets/fluent-icons.svg +2 -0
  71. package/server/assets/monaco/LICENSE +21 -0
  72. package/server/assets/monaco/ThirdPartyNotices.txt +448 -0
  73. package/server/assets/monaco/codicon-jdswhhtn.ttf +0 -0
  74. package/server/assets/monaco/editor.worker.js +45 -0
  75. package/server/assets/monaco/integration-rules.css +1 -0
  76. package/server/assets/monaco/integration-rules.js +1605 -0
  77. package/server/assets/monaco/json.worker.js +77 -0
  78. package/server/assets/office/THIRD-PARTY-NOTICES.txt +11 -0
  79. package/server/assets/office/docx.bundle.js +33 -0
  80. package/server/assets/office/licenses/docx-preview-LICENSE.txt +201 -0
  81. package/server/assets/office/licenses/echarts-LICENSE.txt +222 -0
  82. package/server/assets/office/licenses/jszip-LICENSE.txt +651 -0
  83. package/server/assets/office/licenses/lodash-LICENSE.txt +47 -0
  84. package/server/assets/office/licenses/pptx-preview-LICENSE.txt +8 -0
  85. package/server/assets/office/licenses/tslib-LICENSE.txt +12 -0
  86. package/server/assets/office/licenses/uuid-LICENSE.txt +9 -0
  87. package/server/assets/office/licenses/xlsx-LICENSE.txt +201 -0
  88. package/server/assets/office/licenses/zrender-LICENSE.txt +29 -0
  89. package/server/assets/office/pptx.bundle.js +104 -0
  90. package/server/assets/office/xlsx.bundle.js +141 -0
  91. package/server/assets/recall.css +5 -4
  92. package/server/assets/responsive.css +80 -11
  93. package/server/assets/settings.css +185 -9
  94. package/server/assets/tasks.css +57 -7
  95. package/server/assets/window-controls.css +36 -0
  96. package/server/channel-attachments.ts +133 -0
  97. package/server/channel-integration.ts +572 -0
  98. package/server/channel-settings.ts +77 -0
  99. package/server/channels.ts +274 -21
  100. package/server/chat-server.ts +32 -580
  101. package/server/chat.html +234 -34
  102. package/server/http-server.ts +3 -182
  103. package/server/manifest.webmanifest +1 -0
  104. package/server/resource-routes.ts +16 -16
  105. package/server/routes/inbox.ts +100 -0
  106. package/server/routes/pages.ts +83 -0
  107. package/server/routes/questions.ts +39 -0
  108. package/server/routes/room-actions.ts +162 -0
  109. package/server/routes/rooms.ts +160 -0
  110. package/server/startup.ts +84 -0
  111. package/server/sw.js +5 -0
  112. package/server/task-routes.ts +1 -1
  113. package/src/center/center-client.ts +3 -11
  114. package/src/config/file-config.ts +7 -54
  115. package/src/platform/http-server.ts +182 -0
  116. package/src/protocol/addressing.ts +21 -0
  117. package/src/protocol/config.ts +58 -0
  118. package/src/protocol/room.ts +51 -0
  119. package/src/rooms/resources.ts +26 -16
  120. package/src/rooms/room-service.ts +2 -48
  121. package/src/rooms/storage.ts +329 -0
  122. package/src/rooms/tasks.ts +21 -5
  123. package/src/runtime/watch.ts +1 -1
  124. package/src/state/pg-database.ts +183 -0
  125. package/src/state/pg-migrate.ts +175 -0
  126. package/src/state/pg-sql.mjs +175 -0
  127. package/src/state/pg-worker.mjs +133 -0
  128. package/src/state/sqlite-announcements.ts +25 -0
  129. package/src/state/sqlite-database.ts +130 -0
  130. package/src/state/sqlite-legacy.ts +90 -0
  131. package/src/state/sqlite-members.ts +155 -0
  132. package/src/state/sqlite-messages.ts +288 -0
  133. package/src/state/sqlite-resources.ts +39 -0
  134. package/src/state/sqlite-rooms.ts +194 -0
  135. package/src/state/sqlite-schema.ts +80 -0
  136. package/src/state/sqlite-state-store.ts +34 -0
  137. package/src/state/sqlite-state.ts +15 -897
  138. package/src/state/sqlite-tasks.ts +65 -0
  139. package/src/state/sqlite-transaction.ts +13 -0
  140. package/src/state/sqlite.ts +21 -1
  141. package/src/state/store.ts +5 -1
  142. package/src/tui/app.mjs +32 -19
  143. package/src/tui/config.mjs +12 -4
  144. package/src/tui/i18n.mjs +38 -0
  145. package/src/tui/info-app.mjs +50 -51
  146. package/src/tui/info-content.mjs +79 -44
  147. package/src/tui/join-app.mjs +9 -9
  148. package/src/tui/locales/en.mjs +349 -0
  149. package/src/tui/locales/zh-CN.mjs +349 -0
  150. package/src/tui/main.mjs +85 -37
  151. package/src/tui/markdown.mjs +3 -2
  152. package/src/tui/mentions.mjs +3 -1
  153. package/src/tui/message-app.mjs +22 -21
  154. package/src/tui/message-view.mjs +2 -1
  155. package/src/tui/palette-app.mjs +9 -8
  156. package/src/tui/palette.mjs +30 -24
  157. package/src/tui/prefs.mjs +92 -0
  158. package/src/tui/reminder-app.mjs +18 -17
  159. package/src/tui/room-settings-app.mjs +30 -28
  160. package/src/tui/settings-app.mjs +153 -0
  161. package/src/tui/ui-content.mjs +65 -86
  162. package/src/tui/ui-help.mjs +73 -0
  163. package/src/tui/ui-overlay-view.mjs +23 -7
  164. package/src/tui/ui-suggest.mjs +6 -5
  165. package/src/tui/ui-theme.mjs +37 -33
  166. package/src/tui/ui-view.mjs +22 -7
  167. package/src/tui/ui.mjs +15 -3
  168. package/src/web/editor.worker.ts +1 -0
  169. package/src/web/integration-rules-editor.ts +573 -0
  170. package/src/web/integration-rules.ts +26 -0
  171. package/src/web/integration-schema.ts +229 -0
  172. package/src/web/json.worker.ts +1 -0
  173. package/src/web/office-viewer.ts +221 -0
  174. package/packages/chat-room-channeld/dist/feishu-adapter.js +0 -499
  175. package/packages/chat-room-channeld/src/feishu-adapter.ts +0 -473
  176. package/server/assets/chat/forward.js +0 -69
package/CHANGELOG.md CHANGED
@@ -1,5 +1,57 @@
1
1
  # Changelog
2
2
 
3
+ ## Unreleased
4
+
5
+ - Add a browser-only chat background in Settings → Appearance: choose an image up to 2 MiB, set its opacity, and show it behind the whole client for every room. The picker shows a thumbnail and the chosen file name, reports reading, applied, and failure states, and choosing Default clears the image. The controls are a single column with no separate Reset button. Add a sixth custom theme after the five built-in themes: pick any color, apply it across the app, derive light or dark text from the color's luminance for contrast, and preview changes live while dragging while persisting only the settled value. Default background mode hides the opacity control.
6
+ - Never prompt for an access key on an unauthenticated instance; the key dialog opens only after a request is actually rejected with 401.
7
+ - Remove the manual Forward action and dialog from the browser UI. Agent forwarding through `GET /rooms/:id/forward-targets` and `POST /rooms/:id/forward`, plus the Channel D outbound queue, stay available; inbound relay, attachments, and notice styling are unchanged.
8
+ - Keep the Apache text for the bundled ECharts license regardless of filesystem order. Office prepack now fails instead of publishing the 168-byte NOTICE as `echarts-LICENSE.txt`, with a regression covering a mixed `LICENSE`/`NOTICE`/`licenses/` directory.
9
+ - Persist only the rows a state write actually changed instead of rewriting every room, participant, message, and registry entry. Concurrent PostgreSQL instances keep each other's committed rooms and registry rows, startup schema creation is serialized, and the single-writer advisory lock is gone. Wake delivery and pending admissions remain host-affine: run one watcher per host.
10
+ - Show the all-read check beside the bubble, bottom-aligned, for both own and incoming messages instead of reserving a separate column or moving it into the action row.
11
+ - Close the active side pane with Alt+Esc and restore focus to its opener. At large sizes the app may grow to 2200px and the pane takes up to 1080px while the conversation keeps at least 650px; the room rail stays fixed at 252px. The pane column animates open and closed unless reduced motion is requested, and adjacent footnote references render as `[1]`, `[2]` with spacing.
12
+ - Forward room images and files to Feishu as native image/file messages instead of dropping them, and import Feishu image/file attachments into room resources. Uploads are size-checked (10 MiB images, 30 MiB files), retries reuse the same Feishu message UUID, and failures appear as an explicit room message.
13
+ - Move platform adapters into the top-level `plugins/` directory as single files (`plugins/feishu`, with the adapter contract in `plugins/README.md`). The Feishu adapter builds to `plugins/feishu/dist/feishu-adapter.ts` by concatenating its typed source without a bundler, so the file keeps real TypeScript annotations, has no relative imports, and runs directly under Node 22.18+; the typed source stays in `plugins/feishu/src`, and the service ships no built-in adapter; the adapter is attached to the GitHub Release. The core launches any adapter through its account's `adapter.command`. Adapters now declare their display name, attachment limits, and account fields during `initialize`; the channeld core contains no platform-specific code, limits, or build step.
14
+ - Render system notices as Markdown with the date first and muted: notices up to three rendered lines keep a 50% pill, longer notices become a 12px rounded card, and inbound Channel relays use the normal message block with attachment cards.
15
+ - Upload a plugin as a single JavaScript or TypeScript file. The server runs an initialize-only probe without credentials, derives the platform, display name, account schema, and declared environment from the adapter, and rejects a file that cannot complete the handshake. The integration account dialog renders the plugin's schema form in place of raw environment rows, with environment variables under Advanced settings; existing accounts keep their stored environment.
16
+ - Download an uploaded plugin from its row with the original adapter filename. Only the file registered for that plugin is served; unknown ids and path-like ids return 404.
17
+ - Preview text and code files in a read-only Monaco editor, and reveal message code-block controls only on hover or keyboard focus; touch screens keep them visible. The integration rule editors default to YAML on the left and JSON on the right, and both use the same JSON Schema validation markers; YAML also shows schema descriptions on hover.
18
+ - Center icon-only buttons consistently, show a rotating chevron on the Advanced settings disclosure, remove the settings backdrop blur and scale animation so hovering cannot create compositing seams, and use one 168×38, 8px-radius size for settings selects and the chat-background opacity control.
19
+ - Support multiple accounts per platform: each account gets its own adapter process, environment, and `CHANNELD_ACCOUNT_ID`, and rules and inbound routes select the exact account. Feishu still permits one long connection per app, so accounts that share an App ID and enable inbound lose events; use separate apps or keep only one inbound account per app.
20
+ - Run adapter child processes with `--experimental-transform-types` in `NODE_OPTIONS` so TypeScript plugins may use enum, namespace, and constructor parameter properties. The server stays strip-only, experimental warnings are suppressed only for adapters, and a compiled `.js` remains the stable long-term form.
21
+ - Align message avatars to the message metadata line, right-align shortcut descriptions, and keep wheel panning responsive while the page is pinch-zoomed.
22
+ - Distinguish the conversation surface with a subtle background, rebalance the side gutters, and show avatars once the layout is wide enough.
23
+ - Use a borderless window-controls-overlay layout when an installed PWA exposes it, and keep the normal framed layout everywhere else.
24
+ - Print `message_id=… room_id=…` in send results and `message_id=… chat_id=… sender=…` in inbound relay headers, so IDs can be copied without parsing prose.
25
+
26
+ ## 0.8.1 — 2026-11-26
27
+
28
+ - 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.
29
+ - 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.
30
+ - 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.
31
+ - 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.
32
+ - 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.
33
+ - 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.
34
+ - 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.
35
+ - 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.
36
+ - Keep PageUp/PageDown scrolling from fighting the jump-to-latest button or Alt+End, so rapid page keys no longer snap the thread back.
37
+ - 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.
38
+ - 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.
39
+ - Make the preview header download button icon-only, matching copy and close, with a localized accessible name.
40
+ - 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.
41
+ - Fix the Keyboard shortcuts dialog so each key group and its description sit close together instead of at opposite edges.
42
+ - 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.
43
+ - 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`.
44
+ - Move Reminders into the Options menu and let Settings choose Dialog or Side pane for Announcements, Files, Tasks, and Reminders, persisted per browser.
45
+ - 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.
46
+ - 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.
47
+ - 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.
48
+ - 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.
49
+ - 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.
50
+ - 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.
51
+ - 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.
52
+ - 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.
53
+ - 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.
54
+
3
55
  ## 0.8.0 — 2026-11-25
4
56
 
5
57
  - 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.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2026 Alex Sun
3
+ Copyright (c) 2026 Summer
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
18
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
19
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
20
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
21
+ SOFTWARE.
package/README.md CHANGED
@@ -26,7 +26,7 @@ When upgrading, quit OpenCode first or run `opencode plugin add @alexsun-top/ope
26
26
  On a machine reachable by the other devices:
27
27
 
28
28
  ```bash
29
- npx --yes --package=@alexsun-top/opencode-chat-room@0.8.0 -- opencode-chat-room --host 0.0.0.0 --port 4399 --token 'your-password'
29
+ npx --yes --package=@alexsun-top/opencode-chat-room@0.8.2 -- opencode-chat-room --host 0.0.0.0 --port 4399 --token 'your-password'
30
30
  ```
31
31
 
32
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:
@@ -49,11 +49,43 @@ docker run --rm -p 4399:4399 -v chat-room-data:/data \
49
49
  ghcr.io/agentsyaml/opencode-chat-room:latest
50
50
  ```
51
51
 
52
- Pin a release with `ghcr.io/agentsyaml/opencode-chat-room:v0.8.0`. Rooms and files live in the `/data` volume; keep it across upgrades. A host bind mount must be writable by uid `10001`.
52
+ Pin a release with `ghcr.io/agentsyaml/opencode-chat-room:v0.8.2`. 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.2`; `DOCKER_REGISTRY` and `SERVICE_NAME` override the image. The healthcheck probes `/chat`.
65
+
66
+ ### S3 file storage
67
+
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).
69
+
70
+ ### PostgreSQL state (experimental, multi-instance)
71
+
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 remains experimental through the 0.8.2 multi-instance milestone. Multiple server processes can share one database: each write transaction takes a transaction-scoped advisory lock and applies only the rows it changed, so instances no longer reject each other or overwrite unrelated rooms, members, messages, and registry entries. Wake delivery and pending admissions are host-affine: only the host recorded for a session wakes it, so run one watcher per host; this milestone does not make watchers active-active. 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.
73
+
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.2 -- \
81
+ opencode-chat-room migrate --to-postgres --yes
82
+ ```
83
+
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.
53
85
 
54
86
  ## Channel D (Feishu outbound)
55
87
 
56
- 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:
88
+ Channel D is an optional forwarding sidecar, not a second chat. It forwards selected room messages to external targets. Platform adapters are single files under the top-level `plugins/` directory: the Feishu adapter is `plugins/feishu/dist/feishu-adapter.ts`, generated by concatenating its typed source without a bundler so the file keeps real TypeScript annotations, attached to the GitHub Release, not shipped in this package and run directly by Node. Typed source lives in `plugins/feishu/src`; the core ships a mock adapter for tests. The core launches any adapter through its account's `adapter.command`. Enable it only in central mode with a config path:
57
89
 
58
90
  ```json
59
91
  {
@@ -65,19 +97,19 @@ Channel D is an optional forwarding sidecar, not a second chat. It forwards sele
65
97
  }
66
98
  ```
67
99
 
68
- 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`.
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-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`.
69
101
 
70
- 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. Feishu uses card 1.0 `lark_md` inline formatting; block Markdown, native reply/quote, and inbound relay are planned for 0.8.x.
102
+ Forwarding is explicit and agent-driven: call `GET /rooms/:id/forward-targets` to list matching targets and `POST /rooms/:id/forward` to queue one; the browser UI has no Forward action, and 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, image, and file messages into one idempotent room notification each; attachments are imported into room resources. Inbound events never match outbound rules.
71
103
 
72
104
  ## What you can do
73
105
 
74
106
  - **Rooms and people:** create or join rooms, invite devices, approve joins, manage members and owners, and open direct chats.
75
107
  - **Messages:** reply, mark questions, recall with a recoverable original, and mention people or `@all`.
76
- - **Files:** attach, drag, or paste up to 500 MiB; preview images, media, Markdown, text, code, and PDF; download or delete.
77
- - **Tasks:** track title, assignee, due date, participants, steps, conclusion, and todo/doing/done state in a side pane or modal.
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.
78
110
  - **Reminders:** schedule one-time or cron reminders; text supports `{{time}}`, `{{initiator}}`, and `{{room}}`.
79
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.
80
- - **Terminal:** run `bunx --package @alexsun-top/opencode-chat-room@0.8.0 opencode-chat-room cli` against the same server. It supports rooms, messages, files, reminders, approval, and search. Bun 1.3.14+ is recommended; only the CLI loads OpenTUI.
112
+ - **Terminal:** run `bunx --package @alexsun-top/opencode-chat-room@0.8.2 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.
81
113
  - **Code:** fenced blocks are highlighted by a lazily loaded Shiki bundle with wrap and copy controls.
82
114
  - **Web app:** the interface installs to a phone home screen and starts offline from cache; chat data is never cached.
83
115
 
package/README.zh-CN.md CHANGED
@@ -26,7 +26,7 @@
26
26
  在一台其他设备可访问的机器上运行:
27
27
 
28
28
  ```bash
29
- npx --yes --package=@alexsun-top/opencode-chat-room@0.8.0 -- opencode-chat-room --host 0.0.0.0 --port 4399 --token 'your-password'
29
+ npx --yes --package=@alexsun-top/opencode-chat-room@0.8.2 -- opencode-chat-room --host 0.0.0.0 --port 4399 --token 'your-password'
30
30
  ```
31
31
 
32
32
  服务端支持 Node.js 24.2+、Deno 2 或 Bun。每台运行 OpenCode 的机器设置地址和同一个令牌,然后启动 OpenCode:
@@ -49,11 +49,43 @@ docker run --rm -p 4399:4399 -v chat-room-data:/data \
49
49
  ghcr.io/agentsyaml/opencode-chat-room:latest
50
50
  ```
51
51
 
52
- 用 `ghcr.io/agentsyaml/opencode-chat-room:v0.8.0` 固定版本。房间和文件保存在 `/data` 卷里,升级时不要删除。若改用宿主机目录绑定,目录需允许 uid `10001` 写入。
52
+ 用 `ghcr.io/agentsyaml/opencode-chat-room:v0.8.2` 固定版本。房间和文件保存在 `/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.2` 固定镜像;`DOCKER_REGISTRY` 和 `SERVICE_NAME` 可以覆盖镜像地址。健康检查探测 `/chat`。
65
+
66
+ ### S3 文件存储
67
+
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#环境变量)。
69
+
70
+ ### PostgreSQL 状态(实验性,多实例)
71
+
72
+ 在**服务端**设置 `CHAT_ROOM_DATABASE_URL=postgresql://user:password@host:5432/chatroom`,房间状态就会写入 PostgreSQL 16+,不再使用 `chat-room.sqlite`。该后端在 0.8.2 多实例里程碑完成前仍属实验功能。多个服务端进程可以共用同一个数据库:每个写事务获取事务级 advisory lock,并且只写入发生变化的行,因此实例之间不再互相拒绝,也不会覆盖无关的房间、成员、消息和 registry 条目。唤醒投递和待处理准入是主机亲和的:只有会话登记的那台主机负责唤醒,每个主机只应运行一个 watcher;这个里程碑不把 watcher 做成多活。只应在服务端设置该变量;客户端、watcher 和 Channel D 继续使用各自的 SQLite 文件。Channel D 保持 SQLite、单主机。S3 兼容资源存储已稳定,与数据库选择无关。
73
+
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.2 -- \
81
+ opencode-chat-room migrate --to-postgres --yes
82
+ ```
83
+
84
+ 该命令按外键顺序复制全部状态表,保留 ID 和消息 `seq`,推进 PostgreSQL 序列,校验行数,并拒绝非空目标库。回滚只需切换环境变量:取消 `CHAT_ROOM_DATABASE_URL`,再用未改动的 SQLite 文件启动旧服务端。PostgreSQL 期间写入的消息不会回写到 SQLite。
53
85
 
54
86
  ## Channel D(飞书出站)
55
87
 
56
- Channel D 是可选的转发侧车,不是另一套聊天。它把选定的房间消息转发到外部目标。本版包含飞书出站 adapter 和用于测试的 mock adapter;只在中心模式用配置路径启用:
88
+ Channel D 是可选的转发侧车,不是另一套聊天。它把选定的房间消息转发到外部目标。平台 adapter 是顶层 `plugins/` 目录下的单文件:飞书 adapter 为 `plugins/feishu/dist/feishu-adapter.ts`,由带类型的源码拼接生成、不经过打包器,因此文件里保留真实 TypeScript 类型;它作为 GitHub Release 资产发布,不随本包分发,由 Node 直接运行。带类型源码在 `plugins/feishu/src`;核心只带用于测试的 mock adapter,并通过账号的 `adapter.command` 启动任意 adapter。只在中心模式用配置路径启用:
57
89
 
58
90
  ```json
59
91
  {
@@ -65,19 +97,19 @@ Channel D 是可选的转发侧车,不是另一套聊天。它把选定的房
65
97
  }
66
98
  ```
67
99
 
68
- 或设置 `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`。
100
+ 或设置 `CHAT_ROOM_CHANNELD_CONFIG=/path/channeld.yml`。有配置就启用,没有配置保持关闭,`CHAT_ROOM_CHANNELD=0` 或 `"enabled": false` 可以覆盖配置强制关闭。YAML 定义账号和规则;详见 [Channel D 参考](docs/reference.zh-CN.md#channel-d-outbound)。飞书 adapter 读取 `FEISHU_APP_ID` 和 `FEISHU_APP_SECRET`,可选 `FEISHU_BASE_URL`;规则目标的 `room` 就是飞书 `chat_id`。
69
101
 
70
- 转发是显式动作:规则命中后消息上出现“转发”操作,普通消息不会被自动转发。终态投递会记录一条仅含 ID/状态的 `result.published` 事件,再向房间写一条本地化系统消息。状态保存在 `<stateDir>/channeld.sqlite`,与房间数据库分开;关闭功能、停止服务并删除该文件即可回滚。飞书使用 card 1.0 `lark_md` 行内格式;块级 Markdown、原生引用和回程计划在 0.8.x。
102
+ 转发是显式的 Agent 动作:用 `GET /rooms/:id/forward-targets` 列出匹配目标,用 `POST /rooms/:id/forward` 排队一次转发;浏览器界面不再提供“转发”操作,普通消息也不会被自动转发。终态投递会记录一条仅含 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/image/file 消息写成一条幂等的房间通知,附件会导入房间资源;入站事件不会匹配出站规则。
71
103
 
72
104
  ## 可以做什么
73
105
 
74
106
  - **房间与人:** 创建或加入房间,连接多台设备,审核加入,管理成员和房主,打开私聊。
75
107
  - **消息:** 回复、标记提问、撤回并保留可恢复的原文、点名成员或 `@all`。
76
- - **文件:** 附件、拖拽或粘贴,单文件默认上限 500 MiB;预览图片、媒体、Markdown、文本、代码和 PDF;支持下载和删除。
77
- - **任务:** 在侧栏或弹窗里跟踪标题、负责人、截止日期、参与人、步骤、结论和 todo/doing/done 状态。
108
+ - **文件:** 附件、拖拽或粘贴,单文件默认上限 500 MiB;预览图片、媒体、Markdown、文本、代码、PDF、Word(.docx)、Excel(.xlsx)和 PowerPoint(.pptx);文档预览可全屏;支持下载和删除。
109
+ - **任务:** 在侧栏或弹窗里跟踪标题、负责人、截止日期、参与人、步骤、结论和 todo/doing/done 状态。每个房间默认最多 10 个任务;设置 `CHAT_ROOM_MAX_ROOM_TASKS` 为正整数可调整上限,房间已满时先删除一个已完成的任务再添加。
78
110
  - **提醒:** 一次性或 cron 提醒;文本支持 `{{time}}`、`{{initiator}}` 和 `{{room}}`。
79
111
  - **搜索与快捷键:** Alt+Space 或 Ctrl+P 搜索消息;输入框开头输入 `/` 过滤命令。Alt+1…9 切换房间,更多快捷键在设置里。
80
- - **终端:** 用 `bunx --package @alexsun-top/opencode-chat-room@0.8.0 opencode-chat-room cli` 连接同一服务端,支持房间、消息、文件、提醒、审核和搜索。推荐 Bun 1.3.14+;只有 CLI 加载 OpenTUI。
112
+ - **终端:** 用 `bunx --package @alexsun-top/opencode-chat-room@0.8.2 opencode-chat-room cli` 连接同一服务端,支持房间、消息、文件、提醒、审核、搜索、语言/主题/显示名/服务器设置和 `/exit`。推荐 Bun 1.3.14+;只有 CLI 加载 OpenTUI。
81
113
  - **代码:** 围栏代码块由懒加载的 Shiki bundle 高亮,带换行和复制控件。
82
114
  - **Web App:** 界面可安装到手机主屏,离线时从缓存启动;聊天数据不会缓存。
83
115
 
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);