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

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 (59) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/README.md +3 -3
  3. package/README.zh-CN.md +3 -3
  4. package/dist/cli.js +80 -28
  5. package/package.json +2 -2
  6. package/server/assets/chat/announcements.js +5 -2
  7. package/server/assets/chat/clipboard.js +30 -0
  8. package/server/assets/chat/copy-action.js +48 -0
  9. package/server/assets/chat/diagram-viewer.js +253 -0
  10. package/server/assets/chat/doc-preview.js +150 -12
  11. package/server/assets/chat/events.js +25 -4
  12. package/server/assets/chat/files.js +26 -5
  13. package/server/assets/chat/history-loader.js +3 -1
  14. package/server/assets/chat/index.js +9 -1
  15. package/server/assets/chat/join-requests.js +6 -3
  16. package/server/assets/chat/locales/de.js +2 -2
  17. package/server/assets/chat/locales/es.js +2 -2
  18. package/server/assets/chat/locales/fr.js +2 -2
  19. package/server/assets/chat/locales/it.js +2 -2
  20. package/server/assets/chat/locales/ja.js +2 -2
  21. package/server/assets/chat/locales/ko.js +2 -2
  22. package/server/assets/chat/markdown.js +55 -92
  23. package/server/assets/chat/messages.js +6 -3
  24. package/server/assets/chat/palette.js +32 -15
  25. package/server/assets/chat/pwa.js +2 -0
  26. package/server/assets/chat/questions.js +5 -0
  27. package/server/assets/chat/resource-format.js +74 -0
  28. package/server/assets/chat/rooms.js +3 -0
  29. package/server/assets/chat/side-pane.js +136 -0
  30. package/server/assets/chat/state.js +49 -8
  31. package/server/assets/chat/task-row.js +2 -1
  32. package/server/assets/chat/tasks.js +29 -2
  33. package/server/assets/chat/viewport.js +5 -0
  34. package/server/assets/conversation.css +25 -1
  35. package/server/assets/diagram-viewer.css +141 -0
  36. package/server/assets/doc-preview.css +24 -5
  37. package/server/assets/responsive.css +82 -13
  38. package/server/assets/tasks.css +1 -4
  39. package/server/chat-server.ts +9 -4
  40. package/server/chat.html +23 -2
  41. package/server/resource-routes.ts +3 -1
  42. package/server/sw.js +235 -2
  43. package/skills/chatroom/SKILL.md +1 -1
  44. package/src/agent/chatroom-skill.ts +8 -2
  45. package/src/rooms/resources.ts +2 -2
  46. package/src/runtime/watch.ts +38 -5
  47. package/src/state/sqlite-state.ts +26 -8
  48. package/src/state/store.ts +2 -2
  49. package/src/tui/app.mjs +10 -2
  50. package/src/tui/http.mjs +2 -2
  51. package/src/tui/info-app.mjs +24 -15
  52. package/src/tui/join-app.mjs +3 -3
  53. package/src/tui/main.mjs +1 -1
  54. package/src/tui/markdown.mjs +5 -3
  55. package/src/tui/mentions.mjs +3 -3
  56. package/src/tui/message-app.mjs +14 -11
  57. package/src/tui/palette-app.mjs +10 -7
  58. package/src/tui/reminder-app.mjs +14 -10
  59. package/src/tui/ui-content.mjs +3 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.7.8 — 2026-11-24
4
+
5
+ - 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.
6
+ - Keep the task board open when switching rooms, with the room name and task list following the new room. Unsaved edits are no longer discarded by another status change or refresh.
7
+ - Share one resizable width between the Markdown preview and the task board. Drag the separator, use arrow keys with Home/End, or double-click to reset; the pane stays within limits that keep the conversation at least 420px wide, the 252px room rail never changes width, and the chosen width persists.
8
+ - Tell agents to keep the room task list current themselves through `task_*`.
9
+ - Deduplicate message sends with a client message ID, so retrying after a lost response cannot post twice or wake the recipient twice. Web failed-message retry and terminal draft retry reuse the original ID.
10
+ - Page room files with a `before` cursor instead of an offset, so uploading while paging no longer hides a file.
11
+ - Fix the packaged `watch` command: resolve the skill in the published layout, launch the daemon through the real CLI entry, and wait for a timed-out watcher to exit before releasing its claim.
12
+ - Pin terminal prompt actions (announcements, questions, files, reminders, recall, reply, join review) to the room they were opened in, and keep text typed during a failed send.
13
+ - Pause background room polling while the tab is hidden, refresh the member list after a room switch, clear stale question banners, merge duplicate day separators, and guard double deletes.
14
+ - Add `clientMessageID` and file `before` cursor coverage, a packaged CLI layout test, and isolated TUI test runs.
15
+ - Render Mermaid diagrams with the active theme's palette instead of Mermaid's defaults, and re-render them in place when the theme or language changes. Click a diagram in a message or the Markdown preview to open a full-screen viewer with zoom, pan, reset, and keyboard dismissal.
16
+ - 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
+ - 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
+ - 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.
20
+ - 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
+
3
22
  ## 0.7.7 — 2026-11-23
4
23
 
5
24
  - Expand room tasks into a right-side task board on wide screens and a modal on narrow ones. Tasks now include title, description, assignee, due date, participant list, checklist steps, conclusion, and todo/doing/done status; the header can clear completed tasks. Members create tasks, creators and human administrators manage them, assignees change status or step completion. Agents get `task_list`, `task_create`, `task_update`, and `task_delete` with the same fields and step progress. Editing a task keeps participants and the assignee who later left the room, so an unrelated change cannot silently drop or block them.
package/README.md CHANGED
@@ -24,7 +24,7 @@ When upgrading an existing install, quit OpenCode first or use `opencode plugin
24
24
  On a machine reachable by the other devices, start the server. Replace `your-password` with a shared password:
25
25
 
26
26
  ```bash
27
- npx --yes --package=@alexsun-top/opencode-chat-room@0.7.7 -- opencode-chat-room --host 0.0.0.0 --port 4399 --token 'your-password'
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'
28
28
  ```
29
29
 
30
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.
@@ -53,7 +53,7 @@ docker run --rm -p 4399:4399 -v chat-room-data:/data \
53
53
  ghcr.io/agentsyaml/opencode-chat-room:latest
54
54
  ```
55
55
 
56
- Pin a release with `ghcr.io/agentsyaml/opencode-chat-room:v0.7.7`. 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`.
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`.
57
57
 
58
58
  ## 3. Start chatting
59
59
 
@@ -66,7 +66,7 @@ Pin a release with `ghcr.io/agentsyaml/opencode-chat-room:v0.7.7`. Rooms, messag
66
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
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
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.7 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.
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
70
  - Fenced code blocks are syntax-highlighted locally. Hover or focus a block for icon-only wrap and copy controls.
71
71
  - Agents can recall a message by ID; the original stays available to current members.
72
72
  - Agents can use the `room` tool's `read_resource` action to save an attachment to a temporary file before opening it.
package/README.zh-CN.md CHANGED
@@ -24,7 +24,7 @@
24
24
  在一台可被其他设备访问的机器上启动服务器,把 `换成自己的密码` 换成共享密码:
25
25
 
26
26
  ```bash
27
- npx --yes --package=@alexsun-top/opencode-chat-room@0.7.7 -- opencode-chat-room --host 0.0.0.0 --port 4399 --token '换成自己的密码'
27
+ npx --yes --package=@alexsun-top/opencode-chat-room@0.7.8 -- opencode-chat-room --host 0.0.0.0 --port 4399 --token '换成自己的密码'
28
28
  ```
29
29
 
30
30
  服务端可在 Node.js 24.2+、Deno 2 或 Bun 上运行;`bunx` 与 Deno 命令见[参考文档](docs/reference.zh-CN.md)。OpenCode 本身仍运行在 Bun 上。
@@ -53,7 +53,7 @@ docker run --rm -p 4399:4399 -v chat-room-data:/data \
53
53
  ghcr.io/agentsyaml/opencode-chat-room:latest
54
54
  ```
55
55
 
56
- 用 `ghcr.io/agentsyaml/opencode-chat-room:v0.7.7` 可以固定到具体版本。房间、消息和回执都保存在 `/data` 卷里,升级时保留该卷即可。如果改用宿主目录做挂载,需要让该目录对 uid `10001` 可写。
56
+ 用 `ghcr.io/agentsyaml/opencode-chat-room:v0.7.8` 可以固定到具体版本。房间、消息和回执都保存在 `/data` 卷里,升级时保留该卷即可。如果改用宿主目录做挂载,需要让该目录对 uid `10001` 可写。
57
57
 
58
58
  ## 3. 开始聊天
59
59
 
@@ -66,7 +66,7 @@ docker run --rm -p 4399:4399 -v chat-room-data:/data \
66
66
  - 输入框下方保留唯一快捷键入口,以紧凑标签显示 Alt+/(Mac 为 Option+/);点击或按快捷键都能打开面板。Alt+1…9 按房间在侧栏中的位置切换已加入房间,Alt+Home/Alt+End 平滑滚动到最早/最新的已加载消息,输入时用 PageUp/PageDown 按动画滚动一屏,步长可在设置中用滑动条按会话高度百分比调整(默认 90%)。
67
67
  - 在任意位置(包括输入框)按 Alt+Space(Mac 为 Option+Space)或 Ctrl+P 打开搜索:默认搜索当前房间,按 Tab 切换到全部已加入房间;输入 `/` 可改为过滤常用命令。↑/↓ 加 Enter 打开结果并在会话中高亮;Esc 或点击遮罩关闭并回到输入框。
68
68
  - 点击附件按钮、拖入文件或粘贴图片即可分享;默认单文件上限为 500 MiB。房间选项里还有“公告”“文件”和“任务”;文件可以按上传者筛选、预览支持的媒体和 Markdown 文档,并下载或删除。任务在宽屏固定显示于右侧,小屏使用弹窗。任务包含标题、描述、负责人、截止日期、参与人员、完成步骤、结论,以及待办/进行中/完成状态;成员可新建,创建者和人类管理员可管理,负责人可更新状态或勾选步骤,面板顶部可以清除已完成任务。
69
- - 终端里可以运行 `bunx --package @alexsun-top/opencode-chat-room@0.7.7 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。
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
70
  - 围栏代码块会在本地做语法高亮;鼠标悬停或键盘聚焦时显示纯图标的自动换行和复制按钮。
71
71
  - Agent 可按消息 ID 撤回;当前成员仍可查看原文。
72
72
  - Agent 收到附件后可通过 `room` 的 `read_resource` 操作保存到临时文件,再打开查看。
package/dist/cli.js CHANGED
@@ -854,9 +854,10 @@ async function putResource(file, resource) {
854
854
  return true;
855
855
  });
856
856
  }
857
- async function listResources(file, roomID, limit = 500, offset = 0) {
857
+ async function listResources(file, roomID, limit = 500, offset = 0, beforeID) {
858
858
  const db = await initialize2(file);
859
- const items = db.query("SELECT id,room_id AS roomID,name,mime_type AS mimeType,size,created_at AS createdAt,uploader_session_id AS uploaderSessionID,uploader_name AS uploaderName FROM resources WHERE room_id=? ORDER BY created_at DESC, id DESC LIMIT ? OFFSET ?").all(roomID, limit, offset);
859
+ const cursor = beforeID ? db.query("SELECT created_at AS createdAt,id FROM resources WHERE room_id=? AND id=?").get(roomID, beforeID) : null;
860
+ const items = cursor ? db.query("SELECT id,room_id AS roomID,name,mime_type AS mimeType,size,created_at AS createdAt,uploader_session_id AS uploaderSessionID,uploader_name AS uploaderName FROM resources WHERE room_id=? AND (created_at<? OR (created_at=? AND id<?)) ORDER BY created_at DESC, id DESC LIMIT ?").all(roomID, cursor.createdAt, cursor.createdAt, cursor.id, limit) : db.query("SELECT id,room_id AS roomID,name,mime_type AS mimeType,size,created_at AS createdAt,uploader_session_id AS uploaderSessionID,uploader_name AS uploaderName FROM resources WHERE room_id=? ORDER BY created_at DESC, id DESC LIMIT ? OFFSET ?").all(roomID, limit, offset);
860
861
  const total = Number(db.query("SELECT COUNT(*) AS count FROM resources WHERE room_id=?").get(roomID)?.count ?? 0);
861
862
  return { items, total };
862
863
  }
@@ -920,6 +921,10 @@ async function ensureRoomColumns(db) {
920
921
  db.exec("ALTER TABLE messages ADD COLUMN recalled_at INTEGER");
921
922
  if (!messageColumns.some((column) => column.name === "recalled_by"))
922
923
  db.exec("ALTER TABLE messages ADD COLUMN recalled_by TEXT");
924
+ if (!messageColumns.some((column) => column.name === "client_msg_id"))
925
+ db.exec("ALTER TABLE messages ADD COLUMN client_msg_id TEXT");
926
+ db.exec("DROP INDEX IF EXISTS messages_client_id");
927
+ db.exec("CREATE UNIQUE INDEX IF NOT EXISTS messages_client_id ON messages(room_id,sender_session_id,client_msg_id) WHERE client_msg_id IS NOT NULL");
923
928
  db.exec("CREATE INDEX IF NOT EXISTS messages_pending_questions ON messages(room_id,is_question,answered_by,seq)");
924
929
  db.exec("CREATE INDEX IF NOT EXISTS messages_room_recalled ON messages(room_id,recalled_at)");
925
930
  const taskColumns = db.query("PRAGMA table_info(room_tasks)").all();
@@ -1278,7 +1283,7 @@ async function answerQuestion(file, roomID, questionID, sessionID, text) {
1278
1283
  return { status: "ok", answer };
1279
1284
  });
1280
1285
  }
1281
- async function appendRoomMessage(file, roomID, sessionID, text, isQuestion) {
1286
+ async function appendRoomMessage(file, roomID, sessionID, text, isQuestion, clientMessageID) {
1282
1287
  const db = await openStateDatabase(file);
1283
1288
  return immediate2(db, () => {
1284
1289
  if (!db.query("SELECT 1 FROM rooms WHERE id=?").get(roomID))
@@ -1286,6 +1291,11 @@ async function appendRoomMessage(file, roomID, sessionID, text, isQuestion) {
1286
1291
  const member = db.query("SELECT g.name,r.kind FROM registry g JOIN rooms r ON r.id=g.room_id JOIN participants p ON p.room_id=g.room_id AND p.id=CASE WHEN r.kind='direct' THEN g.session_id ELSE g.name END WHERE g.room_id=? AND g.session_id=?").get(roomID, sessionID);
1287
1292
  if (!member)
1288
1293
  return { status: "member" };
1294
+ if (clientMessageID) {
1295
+ const existing = db.query("SELECT id,room_id,sender_id,sender_session_id,text,created_at,is_question,answer_to,answered_by FROM messages WHERE room_id=? AND client_msg_id=? AND sender_session_id=?").get(roomID, clientMessageID, sessionID);
1296
+ if (existing)
1297
+ return { status: "ok", message: rowMessage(existing), duplicate: true };
1298
+ }
1289
1299
  const tail = db.query("SELECT created_at FROM messages WHERE room_id=? ORDER BY seq DESC LIMIT 1").get(roomID);
1290
1300
  const message = {
1291
1301
  id: randomUUID4(),
@@ -1296,12 +1306,12 @@ async function appendRoomMessage(file, roomID, sessionID, text, isQuestion) {
1296
1306
  createdAt: Math.max(Date.now(), (tail?.created_at ?? 0) + 1),
1297
1307
  ...isQuestion ? { isQuestion: true } : {}
1298
1308
  };
1299
- db.query("INSERT INTO messages(id,room_id,sender_id,sender_session_id,text,created_at,is_question) VALUES(?,?,?,?,?,?,?)").run(message.id, roomID, message.senderId, sessionID, text, message.createdAt, isQuestion ? 1 : 0);
1309
+ db.query("INSERT INTO messages(id,room_id,sender_id,sender_session_id,text,created_at,is_question,client_msg_id) VALUES(?,?,?,?,?,?,?,?)").run(message.id, roomID, message.senderId, sessionID, text, message.createdAt, isQuestion ? 1 : 0, clientMessageID ?? null);
1300
1310
  noteMessageInsert(db, roomID);
1301
1311
  return { status: "ok", message };
1302
1312
  });
1303
1313
  }
1304
- async function sendReply(file, roomID, targetID, sessionID, text) {
1314
+ async function sendReply(file, roomID, targetID, sessionID, text, clientMessageID) {
1305
1315
  const db = await openStateDatabase(file);
1306
1316
  return immediate2(db, () => {
1307
1317
  if (!db.query("SELECT 1 FROM rooms WHERE id=?").get(roomID))
@@ -1309,6 +1319,11 @@ async function sendReply(file, roomID, targetID, sessionID, text) {
1309
1319
  const member = db.query("SELECT g.name,r.kind FROM registry g JOIN rooms r ON r.id=g.room_id JOIN participants p ON p.room_id=g.room_id AND p.id=CASE WHEN r.kind='direct' THEN g.session_id ELSE g.name END WHERE g.room_id=? AND g.session_id=?").get(roomID, sessionID);
1310
1320
  if (!member)
1311
1321
  return { status: "member" };
1322
+ if (clientMessageID) {
1323
+ const existing = db.query("SELECT id,room_id,sender_id,sender_session_id,text,created_at,is_question,answer_to,answered_by FROM messages WHERE room_id=? AND client_msg_id=? AND sender_session_id=?").get(roomID, clientMessageID, sessionID);
1324
+ if (existing)
1325
+ return { status: "ok", message: rowMessage(existing), duplicate: true };
1326
+ }
1312
1327
  const target = db.query("SELECT is_question,recalled_at FROM messages WHERE room_id=? AND id=?").get(roomID, targetID);
1313
1328
  if (!target || target.recalled_at !== null)
1314
1329
  return { status: "target" };
@@ -1316,7 +1331,7 @@ async function sendReply(file, roomID, targetID, sessionID, text) {
1316
1331
  return { status: "question" };
1317
1332
  const tail = db.query("SELECT created_at FROM messages WHERE room_id=? ORDER BY seq DESC LIMIT 1").get(roomID);
1318
1333
  const message = { id: randomUUID4(), roomId: roomID, senderId: member.kind === "direct" ? sessionID : member.name, senderSessionID: sessionID, text, createdAt: Math.max(Date.now(), (tail?.created_at ?? 0) + 1), answerToMessageID: targetID };
1319
- db.query("INSERT INTO messages(id,room_id,sender_id,sender_session_id,text,created_at,is_question,answer_to) VALUES(?,?,?,?,?,?,0,?)").run(message.id, roomID, message.senderId, sessionID, text, message.createdAt, targetID);
1334
+ db.query("INSERT INTO messages(id,room_id,sender_id,sender_session_id,text,created_at,is_question,answer_to,client_msg_id) VALUES(?,?,?,?,?,?,0,?,?)").run(message.id, roomID, message.senderId, sessionID, text, message.createdAt, targetID, clientMessageID ?? null);
1320
1335
  noteMessageInsert(db, roomID);
1321
1336
  return { status: "ok", message };
1322
1337
  });
@@ -1654,11 +1669,11 @@ function acknowledgeQueued2(roomID, sessionID, ts) {
1654
1669
  async function answerQuestion2(roomID, questionID, sessionID, text) {
1655
1670
  return answerQuestion(databasePath(), roomID, questionID, sessionID, text);
1656
1671
  }
1657
- async function sendReply2(roomID, targetID, sessionID, text) {
1658
- return sendReply(databasePath(), roomID, targetID, sessionID, text);
1672
+ async function sendReply2(roomID, targetID, sessionID, text, clientMessageID) {
1673
+ return sendReply(databasePath(), roomID, targetID, sessionID, text, clientMessageID);
1659
1674
  }
1660
- function appendRoomMessage2(roomID, sessionID, text, isQuestion) {
1661
- return appendRoomMessage(databasePath(), roomID, sessionID, text, isQuestion);
1675
+ function appendRoomMessage2(roomID, sessionID, text, isQuestion, clientMessageID) {
1676
+ return appendRoomMessage(databasePath(), roomID, sessionID, text, isQuestion, clientMessageID);
1662
1677
  }
1663
1678
  async function readQuestionExcerpt2(roomID, questionID) {
1664
1679
  return readQuestionExcerpt(databasePath(), roomID, questionID);
@@ -3969,11 +3984,15 @@ var init_plugin_notifications = __esm(() => {
3969
3984
  });
3970
3985
 
3971
3986
  // src/agent/chatroom-skill.ts
3972
- import { readFileSync as readFileSync3 } from "node:fs";
3987
+ import { existsSync as existsSync2, readFileSync as readFileSync3 } from "node:fs";
3973
3988
  import { fileURLToPath } from "node:url";
3974
- var path8, source, metadata, content, description, chatroomSkill;
3989
+ var candidates, path8, source, metadata, content, description, chatroomSkill;
3975
3990
  var init_chatroom_skill = __esm(() => {
3976
- path8 = fileURLToPath(new URL("../../skills/chatroom/SKILL.md", import.meta.url));
3991
+ candidates = [
3992
+ new URL("../../skills/chatroom/SKILL.md", import.meta.url),
3993
+ new URL("../skills/chatroom/SKILL.md", import.meta.url)
3994
+ ].map((url) => fileURLToPath(url));
3995
+ path8 = candidates.find((candidate) => existsSync2(candidate)) ?? candidates[0];
3977
3996
  source = readFileSync3(path8, "utf8");
3978
3997
  [, metadata = "", content = source] = source.match(/^---\r?\n([\s\S]*?)\r?\n---\r?\n([\s\S]*)$/) ?? [];
3979
3998
  description = metadata.match(/^description:\s*(.+)$/m)?.[1]?.trim();
@@ -5496,7 +5515,7 @@ var init_http_server = __esm(() => {
5496
5515
  // src/runtime/watch.ts
5497
5516
  import { Buffer as Buffer3 } from "node:buffer";
5498
5517
  import { createHash as createHash6, randomBytes, timingSafeEqual } from "node:crypto";
5499
- import { realpathSync } from "node:fs";
5518
+ import { existsSync as existsSync3, realpathSync } from "node:fs";
5500
5519
  import { appendFile, chmod as chmod2, link, mkdir as mkdir2, readFile as readFile2, rename as rename2, unlink, writeFile as writeFile2 } from "node:fs/promises";
5501
5520
  import { spawn } from "node:child_process";
5502
5521
  import { fileURLToPath as fileURLToPath3 } from "node:url";
@@ -5715,6 +5734,23 @@ function sameController(value, record, status) {
5715
5734
  const body = value;
5716
5735
  return body.status === status && body.pid === record.pid && body.instanceID === record.instanceID && body.nonce === record.nonce;
5717
5736
  }
5737
+ function cliEntryPath() {
5738
+ const argv = process.argv[1];
5739
+ if (argv) {
5740
+ let resolved = path12.resolve(argv);
5741
+ try {
5742
+ resolved = realpathSync(resolved);
5743
+ } catch {}
5744
+ if (/^cli\.(?:ts|js)$/.test(path12.basename(resolved)))
5745
+ return resolved;
5746
+ }
5747
+ const candidates = [
5748
+ fileURLToPath3(new URL("../../dist/cli.js", import.meta.url)),
5749
+ fileURLToPath3(new URL("../../cli.ts", import.meta.url)),
5750
+ fileURLToPath3(new URL("../cli.js", import.meta.url))
5751
+ ];
5752
+ return candidates.find((candidate) => existsSync3(candidate)) ?? candidates[0];
5753
+ }
5718
5754
  async function watchStatus() {
5719
5755
  const record = await readRecord();
5720
5756
  if (!record) {
@@ -5751,9 +5787,9 @@ async function startWatcher(beforePublish) {
5751
5787
  }
5752
5788
  throw new Error("watcher state exists or is starting; no process was signaled");
5753
5789
  }
5754
- const cli = fileURLToPath3(new URL("../../cli.ts", import.meta.url));
5790
+ const cli = cliEntryPath();
5755
5791
  let childError;
5756
- const child = spawn(process.execPath, [path12.resolve(cli), "watch", "run"], {
5792
+ const child = spawn(process.execPath, [cli, "watch", "run"], {
5757
5793
  detached: true,
5758
5794
  stdio: "ignore",
5759
5795
  env: { ...process.env, CHAT_ROOM_WATCH_CONTROL_TOKEN: own.token, CHAT_ROOM_WATCH_START_NONCE: own.nonce, CHAT_ROOM_WATCH_INSTANCE_ID: own.instanceID }
@@ -5780,7 +5816,16 @@ async function startWatcher(beforePublish) {
5780
5816
  }
5781
5817
  await new Promise((resolve) => setTimeout(resolve, 100));
5782
5818
  }
5783
- throw new Error("watcher did not become ready; its process was not signaled");
5819
+ child.kill("SIGTERM");
5820
+ if (child.exitCode === null) {
5821
+ await Promise.race([
5822
+ new Promise((resolve) => child.once("exit", resolve)),
5823
+ new Promise((resolve) => setTimeout(resolve, 1000))
5824
+ ]);
5825
+ }
5826
+ await removeRecord(own.token, own.nonce);
5827
+ releaseWatcherClaim(profile(), own.instanceID);
5828
+ throw new Error("watcher did not become ready; its process was stopped");
5784
5829
  }
5785
5830
  async function stopWatcher() {
5786
5831
  const record = await readRecord();
@@ -6509,10 +6554,10 @@ function resourcePath(resource) {
6509
6554
  throw new ResourceError(404, "resource not found");
6510
6555
  return path13.join(roomDirectory(resource.roomID), resource.id);
6511
6556
  }
6512
- async function listRoomResources(roomID, limit = 500, offset = 0) {
6557
+ async function listRoomResources(roomID, limit = 500, offset = 0, beforeID) {
6513
6558
  if (!uuid2.test(roomID))
6514
6559
  throw new ResourceError(404, "room not found");
6515
- return listResources(databasePath(), roomID, limit, offset);
6560
+ return listResources(databasePath(), roomID, limit, offset, beforeID);
6516
6561
  }
6517
6562
  async function findResource(roomID, id) {
6518
6563
  if (!uuid2.test(id))
@@ -7122,7 +7167,8 @@ async function resourceRoutes(req, url) {
7122
7167
  const rawOffset = Number(url.searchParams.get("offset") ?? 0);
7123
7168
  const limit = Number.isSafeInteger(rawLimit) ? Math.min(1000, Math.max(1, rawLimit)) : 500;
7124
7169
  const offset = Number.isSafeInteger(rawOffset) ? Math.max(0, rawOffset) : 0;
7125
- const page = await listRoomResources(roomID, limit, offset);
7170
+ const before = url.searchParams.get("before");
7171
+ const page = await listRoomResources(roomID, limit, offset, before && uuid3.test(before) ? before : undefined);
7126
7172
  return json6({ resources: page.items, total: page.total, limit, offset }, 200);
7127
7173
  }
7128
7174
  if (upload) {
@@ -7750,7 +7796,7 @@ var init_room_reminders = __esm(() => {
7750
7796
  });
7751
7797
 
7752
7798
  // server/chat-server.ts
7753
- import { existsSync as existsSync2, promises as fs5 } from "node:fs";
7799
+ import { existsSync as existsSync4, promises as fs5 } from "node:fs";
7754
7800
  import path14 from "node:path";
7755
7801
  import { fileURLToPath as fileURLToPath4 } from "node:url";
7756
7802
  import { randomUUID as randomUUID14 } from "node:crypto";
@@ -8090,8 +8136,12 @@ async function handle(req) {
8090
8136
  const replyTo = body.replyToMessageID;
8091
8137
  if (replyTo !== undefined && (typeof replyTo !== "string" || !replyTo))
8092
8138
  return json10({ error: "replyToMessageID must be a non-empty message ID" }, 400);
8139
+ const clientMessageID = body.clientMessageID;
8140
+ if (clientMessageID !== undefined && (typeof clientMessageID !== "string" || !clientMessageID || clientMessageID.length > 100)) {
8141
+ return json10({ error: "clientMessageID must be a non-empty string (max 100)" }, 400);
8142
+ }
8093
8143
  if (replyTo !== undefined) {
8094
- const result = await sendReply2(roomId, replyTo, sessionID, text);
8144
+ const result = await sendReply2(roomId, replyTo, sessionID, text, clientMessageID);
8095
8145
  if (result.status !== "ok") {
8096
8146
  if (result.status === "missing")
8097
8147
  return json10({ error: "room not found" }, 404);
@@ -8103,10 +8153,11 @@ async function handle(req) {
8103
8153
  }
8104
8154
  touchActive(sessionID);
8105
8155
  const room = await read((svc) => svc.getRoom(roomId));
8106
- wakeMentionedSessions(serveWakeUrl2, roomId, room.name, text, sessionID, result.message);
8156
+ if (!result.duplicate)
8157
+ wakeMentionedSessions(serveWakeUrl2, roomId, room.name, text, sessionID, result.message);
8107
8158
  return json10(await roomPayload(room), 201);
8108
8159
  }
8109
- const result = await appendRoomMessage2(roomId, sessionID, text, isQuestion === true);
8160
+ const result = await appendRoomMessage2(roomId, sessionID, text, isQuestion === true, clientMessageID);
8110
8161
  if (result.status !== "ok") {
8111
8162
  if (result.status === "missing")
8112
8163
  return json10({ error: "room not found" }, 404);
@@ -8114,7 +8165,8 @@ async function handle(req) {
8114
8165
  }
8115
8166
  touchActive(sessionID);
8116
8167
  const room = await read((svc) => svc.getRoom(roomId));
8117
- wakeMentionedSessions(serveWakeUrl2, roomId, room.name, text, sessionID, result.message);
8168
+ if (!result.duplicate)
8169
+ wakeMentionedSessions(serveWakeUrl2, roomId, room.name, text, sessionID, result.message);
8118
8170
  return json10(await roomPayload(room), 201);
8119
8171
  }
8120
8172
  }
@@ -8219,7 +8271,7 @@ var init_chat_server = __esm(async () => {
8219
8271
  init_http_server();
8220
8272
  await init_admin_routes();
8221
8273
  moduleDir = path14.dirname(fileURLToPath4(import.meta.url));
8222
- here = existsSync2(path14.join(moduleDir, "chat.html")) ? moduleDir : path14.resolve(moduleDir, "../server");
8274
+ here = existsSync4(path14.join(moduleDir, "chat.html")) ? moduleDir : path14.resolve(moduleDir, "../server");
8223
8275
  settings = resolveServerSettings(loadRoomConfig());
8224
8276
  hostname = settings.host;
8225
8277
  displayHostname = hostname.includes(":") ? `[${hostname}]` : hostname;
@@ -8250,7 +8302,7 @@ var init_chat_server = __esm(async () => {
8250
8302
 
8251
8303
  // cli.ts
8252
8304
  import { spawnSync } from "node:child_process";
8253
- import { existsSync as existsSync3 } from "node:fs";
8305
+ import { existsSync as existsSync5 } from "node:fs";
8254
8306
  import { readFile as readFile3 } from "node:fs/promises";
8255
8307
  import { fileURLToPath as fileURLToPath5 } from "node:url";
8256
8308
  var usage = `Usage: opencode-chat-room [options]
@@ -8307,7 +8359,7 @@ if (args[0] === "cli") {
8307
8359
  relaunchTuiWithBun();
8308
8360
  const packaged = new URL("../src/tui/main.mjs", import.meta.url);
8309
8361
  const source = new URL("./src/tui/main.mjs", import.meta.url);
8310
- const entry = existsSync3(fileURLToPath5(packaged)) ? packaged : source;
8362
+ const entry = existsSync5(fileURLToPath5(packaged)) ? packaged : source;
8311
8363
  const { main } = await import(entry.href);
8312
8364
  process.exit(await main(args.slice(1)));
8313
8365
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alexsun-top/opencode-chat-room",
3
- "version": "0.7.7",
3
+ "version": "0.7.8",
4
4
  "description": "A chat-room server, web client, terminal client, and OpenCode/Codex/dsh plugins.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -67,7 +67,7 @@
67
67
  "server": "node cli.ts",
68
68
  "server:bun": "bun cli.ts",
69
69
  "server:deno": "deno run --allow-env --allow-read --allow-write --allow-net cli.ts",
70
- "test": "for file in src/tests/*.test.ts server/*.test.ts; do bun test \"$file\" || exit; done && bun test src/tui/test",
70
+ "test": "for file in src/tests/*.test.ts server/*.test.ts; do bun test \"$file\" || exit; done && bun test src/tui/test --isolate",
71
71
  "typecheck": "tsc --noEmit"
72
72
  },
73
73
  "engines": {
@@ -118,10 +118,12 @@ export function initAnnouncements(app) {
118
118
  });
119
119
  $("#btnNewAnnouncement").addEventListener("click", () => openEditor(null));
120
120
  $("#btnDeleteAnnouncement").addEventListener("click", async () => {
121
- const id = roomId(), name = selected;
122
- if (!id || !name || !(await app.confirmAction(app.t("announcementDeleteConfirm", { name })))) return;
121
+ const id = roomId(), name = selected, button = $("#btnDeleteAnnouncement");
122
+ if (!id || !name || button.disabled) return;
123
+ button.disabled = true;
123
124
  const context = roomGeneration, captured = editorSnapshot();
124
125
  try {
126
+ if (!(await app.confirmAction(app.t("announcementDeleteConfirm", { name })))) return;
125
127
  await app.api(`/rooms/${encodeURIComponent(id)}/announcements/${encodeURIComponent(name)}`, { method: "DELETE", body: JSON.stringify({ sessionID: LS.sessionID }) });
126
128
  if (currentRoom(id, context)) {
127
129
  generation++; items = items.filter((item) => item.name !== name); render();
@@ -129,6 +131,7 @@ export function initAnnouncements(app) {
129
131
  if (editorMatches(captured)) { select(null); status(app.t("announcementDeleted")); formStatus(""); dialog.close(); }
130
132
  }
131
133
  } catch (error) { if (currentRoom(id, context) && editorMatches(captured)) formStatus(error.message); }
134
+ finally { button.disabled = false; }
132
135
  });
133
136
  $("#btnRefreshAnnouncements").addEventListener("click", () => void load());
134
137
  $("#btnCloseAnnouncement").addEventListener("click", () => dialog.close());
@@ -0,0 +1,30 @@
1
+ // Clipboard writes with a legacy fallback for browsers or permissions that block
2
+ // the async Clipboard API. Mention copy keeps its marker HTML for later pastes.
3
+ export async function copyTextToClipboard(text, mentionSource = false) {
4
+ // The HTML marker lets a later paste rebuild mention chips; unmarked external text stays literal.
5
+ const html = mentionSource ? `<div data-chatroom-mentions>${String(text).replace(/[&<>"]/g, (char) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;" })[char])}</div>` : "";
6
+ try {
7
+ if (html && navigator.clipboard?.write && typeof ClipboardItem !== "undefined") {
8
+ await navigator.clipboard.write([new ClipboardItem({ "text/plain": new Blob([text], { type: "text/plain" }), "text/html": new Blob([html], { type: "text/html" }) })]);
9
+ return true;
10
+ }
11
+ if (navigator.clipboard?.writeText) {
12
+ await navigator.clipboard.writeText(text);
13
+ return true;
14
+ }
15
+ } catch { /* Use the legacy clipboard command when permission is unavailable. */ }
16
+ const field = document.createElement(html ? "div" : "textarea"), selection = getSelection(), active = document.activeElement;
17
+ const ranges = selection ? Array.from({ length: selection.rangeCount }, (_, index) => selection.getRangeAt(index).cloneRange()) : [];
18
+ if (html) { field.contentEditable = "true"; field.innerHTML = html; } else field.value = text;
19
+ field.setAttribute("readonly", "");
20
+ field.style.cssText = "position:fixed;left:-9999px;top:0";
21
+ document.body.append(field);
22
+ if (html && selection) { const range = document.createRange(); range.selectNodeContents(field); selection.removeAllRanges(); selection.addRange(range); }
23
+ else if (!html) field.select();
24
+ let copied = false;
25
+ try { copied = document.execCommand("copy"); } catch { /* Clipboard access may be disabled. */ }
26
+ field.remove();
27
+ if (selection) { selection.removeAllRanges(); ranges.forEach((range) => selection.addRange(range)); }
28
+ if (active instanceof HTMLElement) active.focus({ preventScroll: true });
29
+ return copied;
30
+ }
@@ -0,0 +1,48 @@
1
+ // Copy buttons for resource cards, the file list, and the preview header.
2
+ import { copyTextToClipboard } from "./clipboard.js";
3
+ import { iconNode } from "./icons.js";
4
+
5
+ export function createCopyButton(app, className = "") {
6
+ const button = document.createElement("button");
7
+ button.type = "button";
8
+ button.className = `copy-action ${className}`.trim();
9
+ button.dataset.i18nAriaLabel = "copyMessage";
10
+ button.dataset.i18nTitle = "copyMessage";
11
+ button.setAttribute("aria-label", app.t("copyMessage"));
12
+ button.title = app.t("copyMessage");
13
+ const feedback = document.createElement("span");
14
+ feedback.className = "copy-feedback";
15
+ feedback.setAttribute("role", "status");
16
+ feedback.setAttribute("aria-live", "polite");
17
+ button.append(iconNode("copy", "copy-action-icon copy-icon"), iconNode("checkmark", "copy-action-icon copy-check"), feedback);
18
+ return button;
19
+ }
20
+
21
+ export function setCopyFeedback(button, app, copied) {
22
+ clearTimeout(button._copyFeedbackTimer);
23
+ button.classList.toggle("is-copied", copied);
24
+ button.classList.toggle("is-copy-failed", !copied);
25
+ const key = copied ? "copied" : "copyMessageFailed";
26
+ const feedback = button.querySelector(".copy-feedback");
27
+ if (feedback) feedback.textContent = app.t(key);
28
+ button.setAttribute("aria-label", app.t(key));
29
+ button.title = app.t(key);
30
+ button._copyFeedbackTimer = setTimeout(() => {
31
+ button.classList.remove("is-copied", "is-copy-failed");
32
+ button.setAttribute("aria-label", app.t("copyMessage"));
33
+ button.title = app.t("copyMessage");
34
+ if (feedback) feedback.textContent = "";
35
+ }, 1600);
36
+ }
37
+
38
+ export async function copyResourceText(button, app, readText) {
39
+ let copied = false;
40
+ try {
41
+ const text = await readText();
42
+ copied = typeof text === "string" && text.length > 0 && await copyTextToClipboard(text);
43
+ } catch {
44
+ copied = false;
45
+ }
46
+ setCopyFeedback(button, app, copied);
47
+ return copied;
48
+ }