@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
@@ -17,12 +17,12 @@
17
17
  .doc-preview::backdrop { background: rgb(9 22 18 / .52); backdrop-filter: blur(4px); }
18
18
  @keyframes doc-preview-in { from { opacity: 0; transform: translateY(8px); } }
19
19
 
20
- /* The pane is a third grid column inside the chat workspace, so the chat gets narrower
20
+ /* The pane is a grid column inside the chat workspace, so the chat gets narrower
21
21
  instead of being covered. Keep this query in sync with PANE_QUERY in doc-preview.js. */
22
22
  .doc-preview.is-pane {
23
23
  position: relative;
24
24
  inset: auto;
25
- grid-column: 3;
25
+ grid-column: 4;
26
26
  grid-row: 1 / -1;
27
27
  width: auto;
28
28
  height: auto;
@@ -36,9 +36,6 @@
36
36
  box-shadow: none;
37
37
  animation: none;
38
38
  }
39
- @media (min-width: 1100px) and (min-height: 560px) {
40
- #chatView.has-doc { grid-template-columns: 252px minmax(0, 1fr) clamp(380px, 30vw, 460px); }
41
- }
42
39
 
43
40
  .doc-preview-head {
44
41
  display: flex;
@@ -73,7 +70,18 @@
73
70
  /* The heading takes programmatic focus for screen readers; it does not need a ring. */
74
71
  .doc-preview-heading h2:focus { outline: none; }
75
72
  .doc-preview-meta { display: flex; flex-wrap: wrap; gap: 2px 10px; margin: 4px 0 0; color: var(--ink-3); font-size: 11.5px; line-height: 1.45; }
73
+ .doc-preview-language {
74
+ align-self: center;
75
+ padding: 0 6px;
76
+ border: 1px solid color-mix(in srgb, var(--accent) 26%, var(--line));
77
+ border-radius: 999px;
78
+ color: var(--accent);
79
+ font: 700 9.5px/1.6 var(--font-mono);
80
+ letter-spacing: .08em;
81
+ text-transform: uppercase;
82
+ }
76
83
  .doc-preview-actions { display: flex; flex: none; align-items: center; gap: 2px; }
84
+ .doc-preview-copy { width: 36px; height: 36px; }
77
85
  .doc-preview-download { min-height: 36px; padding: 6px 12px; }
78
86
  .doc-preview-actions .reader-close { width: 38px; height: 38px; }
79
87
 
@@ -108,6 +116,17 @@
108
116
  overflow-wrap: anywhere;
109
117
  }
110
118
  .doc-preview-body > :first-child { margin-top: 0; }
119
+
120
+ /* Plain text and code fill the reading width and wrap instead of scrolling sideways. */
121
+ .doc-code { margin: 0; }
122
+ pre.doc-code { padding: 0; border: 0; background: transparent; overflow-x: hidden; }
123
+ pre.doc-code code { padding: 0; font-family: var(--font-mono); font-size: 12.5px; line-height: 1.65; white-space: pre-wrap; overflow-wrap: anywhere; }
124
+
125
+ /* PDFs use the browser viewer and fill the reading surface edge to edge. */
126
+ .doc-preview.is-pdf .doc-preview-scroll { display: flex; padding: 0; overflow: hidden; }
127
+ .doc-preview.is-pdf .doc-preview-body { display: flex; flex: 1 1 auto; min-height: 0; }
128
+ .doc-preview.is-pdf .doc-preview-empty { display: none; }
129
+ .doc-pdf-frame { flex: 1 1 auto; width: 100%; height: 100%; min-height: 0; border: 0; background: var(--surface-2); }
111
130
  .doc-preview-body h1, .doc-preview-body h2, .doc-preview-body h3, .doc-preview-body h4 {
112
131
  margin: 1.4em 0 .45em;
113
132
  font-family: var(--font-display);
@@ -25,6 +25,8 @@
25
25
  /* Room workspace */
26
26
  #app { max-width: 1440px; }
27
27
  #chatView {
28
+ /* One width source for the document preview and the task board. */
29
+ --side-pane-width: clamp(380px, 30vw, 560px);
28
30
  display: grid;
29
31
  grid-template-columns: 252px minmax(0, 1fr);
30
32
  grid-template-rows: auto auto minmax(0, 1fr) auto;
@@ -37,6 +39,43 @@
37
39
  width: calc(100% - 36px);
38
40
  height: calc(100% - 36px);
39
41
  }
42
+ @media (min-width: 1500px) and (min-height: 560px) {
43
+ #chatView { --side-pane-width: clamp(380px, 30vw, 640px); }
44
+ }
45
+ /* The separator owns one grid column of its own, so it never covers the chat. */
46
+ .side-pane-handle {
47
+ display: none;
48
+ grid-column: 3;
49
+ grid-row: 1 / -1;
50
+ align-items: center;
51
+ justify-content: center;
52
+ min-width: 0;
53
+ padding: 0;
54
+ border: 0;
55
+ background: transparent;
56
+ cursor: col-resize;
57
+ touch-action: none;
58
+ user-select: none;
59
+ }
60
+ .side-pane-handle::before {
61
+ content: "";
62
+ width: 2px;
63
+ height: 100%;
64
+ border-radius: 2px;
65
+ background: transparent;
66
+ transition: background .15s ease;
67
+ }
68
+ .side-pane-handle:hover::before,
69
+ .side-pane-handle.is-dragging::before { background: color-mix(in srgb, var(--accent) 60%, var(--line)); }
70
+ .side-pane-handle:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
71
+ .side-pane-handle:focus-visible::before { background: var(--accent); }
72
+ body.is-resizing-pane { cursor: col-resize; user-select: none; }
73
+ @media (min-width: 1100px) and (min-height: 560px) {
74
+ #chatView.has-doc,
75
+ #chatView.has-tasks { grid-template-columns: 252px minmax(0, 1fr) 8px var(--side-pane-width); }
76
+ #chatView.has-doc > .side-pane-handle,
77
+ #chatView.has-tasks > .side-pane-handle { display: flex; }
78
+ }
40
79
  .room-rail {
41
80
  position: relative;
42
81
  grid-column: 1;
@@ -245,10 +284,31 @@
245
284
 
246
285
  @media (max-width: 760px) {
247
286
  #chatView { width: 100%; height: 100%; margin: 0; border: 0; border-radius: 0; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto minmax(0, 1fr) auto; }
248
- .room-rail { display: none; position: fixed; inset: 0 auto 0 0; z-index: 50; width: min(300px, 88vw); height: 100dvh; min-height: 0; padding: 20px 14px 0; background: var(--surface); border-right: 1px solid var(--line); box-shadow: var(--shadow); }
249
- .room-rail.drawer-open { display: flex; }
287
+ /* Off-canvas rail: transform only, so opening never reflows the chat. */
288
+ .room-rail {
289
+ display: flex;
290
+ position: fixed;
291
+ inset: 0 auto 0 0;
292
+ z-index: 50;
293
+ width: min(300px, 88vw);
294
+ height: 100dvh;
295
+ min-height: 0;
296
+ padding: 20px 14px 0;
297
+ background: var(--surface);
298
+ border-right: 1px solid var(--line);
299
+ box-shadow: var(--shadow);
300
+ transform: translateX(-100%);
301
+ visibility: hidden;
302
+ transition: transform .2s cubic-bezier(.2, .7, .3, 1), visibility 0s linear .2s;
303
+ }
304
+ .room-rail.drawer-open {
305
+ transform: translateX(0);
306
+ visibility: visible;
307
+ transition: transform .2s cubic-bezier(.2, .7, .3, 1), visibility 0s;
308
+ }
309
+ .room-rail.no-drawer-animation { transition: none !important; }
250
310
  .rail-brand { display: flex; margin-bottom: 22px; }
251
- .rail-foot { display: flex; min-height: var(--composer-block, 93px); }
311
+ .rail-foot { display: flex; min-height: var(--composer-block, 88px); }
252
312
  .rail-install { display: grid; gap: 6px; padding: 8px 4px 10px; border-top: 1px solid color-mix(in srgb, var(--line) 80%, transparent); }
253
313
  .rail-install .rail-install-btn { width: 100%; min-height: 40px; }
254
314
  .rail-install svg { width: 16px; height: 16px; }
@@ -260,14 +320,14 @@
260
320
  #roomListChat .room-row { height: auto; padding: 10px 12px; }
261
321
  #roomListChat .r-meta { font-size: 12px; }
262
322
  #roomListChat .r-preview { display: block; }
263
- #chatView > .chat-head { grid-column: 1; grid-row: 1; flex-wrap: wrap; align-items: center; padding: calc(6px + env(safe-area-inset-top)) 10px 6px; gap: 4px 8px; }
323
+ #chatView > .chat-head { grid-column: 1; grid-row: 1; flex-wrap: nowrap; align-items: center; padding: calc(4px + env(safe-area-inset-top)) 8px 4px; gap: 2px 6px; }
264
324
  #chatView > .conn-bar { grid-column: 1; grid-row: 2; }
265
325
  #chatView > .msg-scroll { grid-column: 1; grid-row: 3; }
266
326
  #chatView > .composer { grid-column: 1; grid-row: 4; }
267
- .chat-head-actions { flex: none; flex-wrap: nowrap; justify-content: flex-end; gap: 4px; margin-left: auto; }
327
+ .chat-head-actions { flex: none; flex-wrap: nowrap; justify-content: flex-end; gap: 3px; margin-left: auto; }
268
328
  .chat-head-actions > .locale-control { display: none; }
269
- .chat-head-main { display: flex; flex: 1 1 200px; flex-wrap: wrap; align-items: center; gap: 2px 8px; min-width: 0; }
270
- .room-title-row { flex: 1 1 0; gap: 6px; min-width: 0; }
329
+ .chat-head-main { display: flex; flex: 1 1 0; flex-wrap: wrap; align-items: center; gap: 1px 6px; min-width: 0; }
330
+ .room-title-row { flex: 1 1 0; gap: 4px; min-width: 0; }
271
331
  .room-meta { flex: none; margin: 0; max-width: none; }
272
332
  .room-description { flex: 1 1 100%; margin: 0; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
273
333
  .chat-head-main h1 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 18px; }
@@ -279,20 +339,29 @@
279
339
  .room-options-panel { right: 0; left: auto; }
280
340
  .thread { padding: 14px 12px 6px; }
281
341
  .msg-text { max-width: 92%; font-size: 15px; }
282
- .composer { padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); }
283
- #msgInput { min-height: 0; padding: 9px 11px; line-height: 1.45; }
284
- #btnSend { padding: 12px 15px; }
342
+ .composer { gap: 8px; padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); }
343
+ .composer-row { gap: 8px; }
344
+ #msgInput { min-height: 0; padding: 10px 11px; line-height: 1.5; }
345
+ /* Beat the short-window compaction so the input still matches the buttons. */
346
+ #chatView #msgInput[data-empty="true"] { height: 46px !important; }
347
+ #chatView #msgInput[data-empty="true"]::before { inset: 12px 11px auto; }
348
+ #btnSend { height: 44px; min-height: 44px; padding: 0 18px; }
349
+ .composer-meta { gap: 6px; min-height: 18px; }
350
+ .composer-meta .chip.keys-entry { height: 18px; padding: 0 6px; font-size: 11px; }
351
+ .composer-meta .draft-count { display: block; font-size: 11px; line-height: 1.3; }
285
352
  }
286
353
  @media (max-width: 480px) {
287
- .chat-head-main { flex-basis: 100%; }
288
- .chat-head-actions { flex-basis: 100%; margin-left: 0; }
289
- #msgInput[data-empty="true"] { min-height: calc(2.9em + 20px); }
354
+ /* One row for the menu, title, and actions: secondary room details move out. */
355
+ .room-meta, .room-description { display: none; }
290
356
  }
291
357
  @media (max-width: 420px) {
292
358
  #chatView > .chat-head { align-items: center; }
293
359
  .chat-head-actions { justify-content: flex-end; gap: 4px; }
294
360
  .chat-head-actions .panel { max-height: min(70dvh, 520px); overflow: auto; }
295
361
  }
362
+ @media (max-width: 380px) {
363
+ .chat-head-actions .chip { width: 40px; height: 40px; }
364
+ }
296
365
  @media (max-width: 300px) {
297
366
  #chatView > .chat-head { padding: 8px; gap: 0; }
298
367
  .chat-head-actions { gap: 0; }
@@ -24,7 +24,7 @@
24
24
  #tasksDialog.is-pane {
25
25
  position: relative;
26
26
  inset: auto;
27
- grid-column: 3;
27
+ grid-column: 4;
28
28
  grid-row: 1 / -1;
29
29
  width: auto;
30
30
  height: auto;
@@ -54,9 +54,6 @@
54
54
  #tasksDialog.is-pane .task-edit-form { grid-template-columns: minmax(0, 1fr); }
55
55
  #tasksDialog.is-pane .task-create-due, #tasksDialog.is-pane .task-create-assignee,
56
56
  #tasksDialog.is-pane .task-edit-due-field, #tasksDialog.is-pane .task-edit-assignee-field { grid-column: 1; }
57
- @media (min-width: 1100px) and (min-height: 560px) {
58
- #chatView.has-tasks { grid-template-columns: 252px minmax(0, 1fr) clamp(380px, 30vw, 460px); }
59
- }
60
57
 
61
58
  .tasks-head {
62
59
  display: flex;
@@ -445,8 +445,13 @@ async function handle(req: Request): Promise<Response> {
445
445
  }
446
446
  const replyTo = (body as Record<string, unknown>).replyToMessageID;
447
447
  if (replyTo !== undefined && (typeof replyTo !== "string" || !replyTo)) return json({ error: "replyToMessageID must be a non-empty message ID" }, 400);
448
+ // Optional retry key: a lost response may be retried without creating a twin.
449
+ const clientMessageID = (body as Record<string, unknown>).clientMessageID;
450
+ if (clientMessageID !== undefined && (typeof clientMessageID !== "string" || !clientMessageID || clientMessageID.length > 100)) {
451
+ return json({ error: "clientMessageID must be a non-empty string (max 100)" }, 400);
452
+ }
448
453
  if (replyTo !== undefined) {
449
- const result = await sendReply(roomId, replyTo, sessionID, text);
454
+ const result = await sendReply(roomId, replyTo, sessionID, text, clientMessageID);
450
455
  if (result.status !== "ok") {
451
456
  if (result.status === "missing") return json({ error: "room not found" }, 404);
452
457
  if (result.status === "target") return json({ error: "reply target not found in room" }, 404);
@@ -455,10 +460,10 @@ async function handle(req: Request): Promise<Response> {
455
460
  }
456
461
  touchActive(sessionID);
457
462
  const room = await read((svc) => svc.getRoom(roomId));
458
- void wakeMentionedSessions(serveWakeUrl, roomId, room.name, text, sessionID, result.message);
463
+ if (!result.duplicate) void wakeMentionedSessions(serveWakeUrl, roomId, room.name, text, sessionID, result.message);
459
464
  return json(await roomPayload(room), 201);
460
465
  }
461
- const result = await appendRoomMessage(roomId, sessionID, text, isQuestion === true);
466
+ const result = await appendRoomMessage(roomId, sessionID, text, isQuestion === true, clientMessageID);
462
467
  if (result.status !== "ok") {
463
468
  if (result.status === "missing") return json({ error: "room not found" }, 404);
464
469
  return json({ error: "session is not a room member" }, 409);
@@ -466,7 +471,7 @@ async function handle(req: Request): Promise<Response> {
466
471
  touchActive(sessionID); // 发送者活跃
467
472
  const room = await read((svc) => svc.getRoom(roomId));
468
473
  // ponytail: 即时唤起——仅 @ 点名成员时(核心需求)
469
- void wakeMentionedSessions(serveWakeUrl, roomId, room.name, text, sessionID, result.message);
474
+ if (!result.duplicate) void wakeMentionedSessions(serveWakeUrl, roomId, room.name, text, sessionID, result.message);
470
475
  return json(await roomPayload(room), 201);
471
476
  }
472
477
  }
package/server/chat.html CHANGED
@@ -33,6 +33,7 @@
33
33
  <link rel="stylesheet" href="/assets/files.css?v={{version}}">
34
34
  <link rel="stylesheet" href="/assets/tasks.css?v={{version}}">
35
35
  <link rel="stylesheet" href="/assets/doc-preview.css?v={{version}}">
36
+ <link rel="stylesheet" href="/assets/diagram-viewer.css?v={{version}}">
36
37
  </head>
37
38
  <body>
38
39
 
@@ -604,12 +605,14 @@
604
605
  <p id="draftCount" class="draft-count">0 / 5000</p>
605
606
  </div>
606
607
  </footer>
608
+ <!-- Drag or arrow-key resizes the preview/task pane; one separator serves both. -->
609
+ <div id="sidePaneHandle" class="side-pane-handle" role="separator" aria-orientation="vertical" aria-label="Resize side pane" data-i18n-aria-label="sidePaneResize" aria-valuemin="360" aria-valuemax="960" aria-valuenow="380" tabindex="0"></div>
607
610
  <dialog id="docPreview" class="doc-preview" aria-labelledby="docPreviewTitle">
608
611
  <header class="doc-preview-head">
609
612
  <div class="doc-preview-heading">
610
- <p class="doc-preview-eyebrow"><svg class="fluent-icon doc-preview-icon" aria-hidden="true" viewBox="0 0 24 24"><use href="/assets/fluent-icons.svg#fluent-document-24"></use></svg><span data-i18n="docPreviewEyebrow">Markdown preview</span></p>
613
+ <p class="doc-preview-eyebrow"><svg class="fluent-icon doc-preview-icon" aria-hidden="true" viewBox="0 0 24 24"><use href="/assets/fluent-icons.svg#fluent-document-24"></use></svg><span id="docPreviewEyebrow" data-i18n="docPreviewEyebrow">Markdown preview</span></p>
611
614
  <h2 id="docPreviewTitle" tabindex="-1"></h2>
612
- <p class="doc-preview-meta"><span id="docPreviewSize"></span><span id="docPreviewStatus" role="status" aria-live="polite"></span></p>
615
+ <p class="doc-preview-meta"><span id="docPreviewSize"></span><span id="docPreviewLanguage" class="doc-preview-language" hidden></span><span id="docPreviewStatus" role="status" aria-live="polite"></span></p>
613
616
  </div>
614
617
  <div class="doc-preview-actions">
615
618
  <button id="btnDocPreviewDownload" class="btn ghost small doc-preview-download" type="button" data-i18n="resourceDownload">Download</button>
@@ -618,6 +621,7 @@
618
621
  </header>
619
622
  <div class="doc-preview-scroll">
620
623
  <article id="docPreviewBody" class="doc-preview-body msg-text"></article>
624
+ <p id="docPreviewNotice" class="hint doc-preview-empty" role="status" hidden></p>
621
625
  <p id="docPreviewEmpty" class="hint doc-preview-empty" data-i18n="docPreviewEmpty" hidden>This document is empty.</p>
622
626
  </div>
623
627
  </dialog>
@@ -635,6 +639,23 @@
635
639
  <img id="imageDialogImage" alt="">
636
640
  </dialog>
637
641
 
642
+ <!-- A rendered Mermaid diagram opens large enough to read, with zoom and pan. -->
643
+ <dialog id="diagramViewer" class="diagram-viewer" aria-labelledby="diagramViewerTitle">
644
+ <header class="diagram-viewer-toolbar">
645
+ <h2 id="diagramViewerTitle" data-i18n="diagramViewerTitle">Diagram</h2>
646
+ <div class="diagram-viewer-tools" role="group" aria-label="Diagram zoom" data-i18n-aria-label="diagramZoomControls">
647
+ <button id="btnDiagramZoomOut" class="diagram-viewer-tool" type="button" aria-label="Zoom out" data-i18n-aria-label="zoomOut"></button>
648
+ <span id="diagramZoomLevel" class="diagram-viewer-level" aria-live="polite">100%</span>
649
+ <button id="btnDiagramZoomIn" class="diagram-viewer-tool" type="button" aria-label="Zoom in" data-i18n-aria-label="zoomIn"></button>
650
+ <button id="btnDiagramFit" class="diagram-viewer-tool diagram-viewer-fit" type="button" data-i18n="diagramFit">Fit</button>
651
+ </div>
652
+ <button id="btnCloseDiagram" class="reader-close" type="button" aria-label="Close" data-i18n-aria-label="close"><svg class="fluent-icon close-icon" aria-hidden="true" viewBox="0 0 24 24"><use href="/assets/fluent-icons.svg#fluent-dismiss-24"></use></svg></button>
653
+ </header>
654
+ <div id="diagramViewerBody" class="diagram-viewer-body">
655
+ <div id="diagramViewerStage" class="diagram-viewer-stage"></div>
656
+ </div>
657
+ </dialog>
658
+
638
659
  <!-- Shown when someone who is not the room owner reaches for the settings. -->
639
660
  <dialog id="ownerOnlyDialog" class="admin-dialog" aria-labelledby="ownerOnlyHeading">
640
661
  <header class="admin-dialog-head"><h2 id="ownerOnlyHeading" data-i18n="roomOwnerOnlyTitle">Owner or administrator only</h2><div class="admin-dialog-actions"><button id="btnCloseOwnerOnly" class="reader-close" type="button" aria-label="Close" data-i18n-aria-label="close"><svg class="fluent-icon close-icon" aria-hidden="true" viewBox="0 0 24 24"><use href="/assets/fluent-icons.svg#fluent-dismiss-24"></use></svg></button></div></header>
@@ -33,7 +33,9 @@ export async function resourceRoutes(req: Request, url: URL): Promise<Response |
33
33
  const rawOffset = Number(url.searchParams.get("offset") ?? 0);
34
34
  const limit = Number.isSafeInteger(rawLimit) ? Math.min(1000, Math.max(1, rawLimit)) : 500;
35
35
  const offset = Number.isSafeInteger(rawOffset) ? Math.max(0, rawOffset) : 0;
36
- const page = await listRoomResources(roomID, limit, offset);
36
+ // A cursor keeps paging stable when a new upload shifts the offset window.
37
+ const before = url.searchParams.get("before");
38
+ const page = await listRoomResources(roomID, limit, offset, before && uuid.test(before) ? before : undefined);
37
39
  return json({ resources: page.items, total: page.total, limit, offset }, 200);
38
40
  }
39
41
  if (upload) {
package/server/sw.js CHANGED
@@ -18,6 +18,7 @@ const STATIC = [
18
18
  "/assets/files.css",
19
19
  "/assets/tasks.css",
20
20
  "/assets/doc-preview.css",
21
+ "/assets/diagram-viewer.css",
21
22
  "/assets/highlight-10.7.3.min.js",
22
23
  "/assets/marked-18.0.4.js",
23
24
  "/assets/dompurify-3.4.7.js",
@@ -30,6 +31,28 @@ const STATIC = [
30
31
  const VERSIONED = new Set(STATIC.filter((path) => path.endsWith(".css") || /^\/assets\/(?:highlight|marked|dompurify|mermaid)-/.test(path)));
31
32
  const versioned = (path) => `${path}?v=${VERSION}`;
32
33
 
34
+ // Recently viewed images live in their own cache: a release upgrades CACHE, but a photo
35
+ // should survive until the person changes identity, it ages out, or the caps evict it.
36
+ const MEDIA_CACHE = "oc-chat-media";
37
+ const MEDIA_INDEX = "/__media-index__";
38
+ const MEDIA_IDENTITY = "/__media-identity__";
39
+ const MEDIA_PATH = /^\/rooms\/[^/]+\/resources\/[^/]+\/content$/;
40
+ const IDENTITY_PATTERN = /^[0-9a-f]{16}$/;
41
+ const REVALIDATE_MS = 10 * 60 * 1000;
42
+ const MEDIA_LIMITS = { entries: 80, bytes: 64 * 1024 * 1024, age: 30 * 24 * 60 * 60 * 1000 };
43
+ // Tests lower these numbers before seeding entries; production keeps the values above.
44
+ self.__MEDIA_LIMITS__ = MEDIA_LIMITS;
45
+
46
+ // The page owns the identity (a hash of its token and session ID); this worker only
47
+ // partitions the cache by it. Unknown identity means network-only.
48
+ let mediaIdentity;
49
+ let mediaQueue = Promise.resolve();
50
+ const queueMedia = (task) => {
51
+ const run = mediaQueue.then(task, task);
52
+ mediaQueue = run.catch(() => {});
53
+ return run;
54
+ };
55
+
33
56
  self.addEventListener("install", (event) => {
34
57
  event.waitUntil((async () => {
35
58
  const cache = await caches.open(CACHE);
@@ -59,14 +82,29 @@ self.addEventListener("install", (event) => {
59
82
  });
60
83
 
61
84
  self.addEventListener("message", (event) => {
62
- if (event.data?.type === "SKIP_WAITING") event.waitUntil(self.skipWaiting());
85
+ if (event.data?.type === "SKIP_WAITING") {
86
+ event.waitUntil(self.skipWaiting());
87
+ return;
88
+ }
89
+ // The first message is a cheap moment to enforce the age policy even if the worker
90
+ // was already active when this release first loaded.
91
+ if (!self.__mediaPruned) {
92
+ self.__mediaPruned = true;
93
+ event.waitUntil(pruneMedia().catch(() => {}));
94
+ }
95
+ if (event.data?.type === "SET_MEDIA_IDENTITY") event.waitUntil(setMediaIdentity(event.data.identity).catch(() => {}));
96
+ else if (event.data?.type === "CLEAR_MEDIA_CACHE") event.waitUntil(clearMedia().catch(() => {}));
63
97
  });
64
98
 
65
99
  self.addEventListener("activate", (event) => {
66
100
  event.waitUntil((async () => {
67
- for (const key of await caches.keys()) if (key !== CACHE) await caches.delete(key);
101
+ for (const key of await caches.keys()) {
102
+ if (key !== CACHE && key !== MEDIA_CACHE && key.startsWith("oc-chat-")) await caches.delete(key);
103
+ }
68
104
  await self.clients.claim();
69
105
  })());
106
+ // Housekeeping must never delay or fail activation.
107
+ event.waitUntil(pruneMedia().catch(() => {}));
70
108
  });
71
109
 
72
110
  self.addEventListener("fetch", (event) => {
@@ -74,6 +112,12 @@ self.addEventListener("fetch", (event) => {
74
112
  if (request.method !== "GET") return;
75
113
  const url = new URL(request.url);
76
114
  if (url.origin !== self.location.origin) return;
115
+ if (MEDIA_PATH.test(url.pathname)) {
116
+ // Partial responses do not belong in a whole-body cache; leave ranges to the browser.
117
+ if (request.headers.has("range")) return;
118
+ event.respondWith(mediaResponse(event));
119
+ return;
120
+ }
77
121
  // Chat data never comes from a cache: a stale answer would show a room that was deleted
78
122
  // and messages that were already read.
79
123
  if (url.pathname !== SHELL && !url.pathname.startsWith("/assets/")) return;
@@ -98,3 +142,192 @@ self.addEventListener("fetch", (event) => {
98
142
  return cached || network;
99
143
  })());
100
144
  });
145
+
146
+ // Cache Storage drops URL fragments, so the partition rides a reserved query parameter.
147
+ // The index keeps the readable `${url}#${identity}` form.
148
+ const mediaBodyKey = (url, identity) => `${url}${url.includes("?") ? "&" : "?"}__media_identity__=${identity}`;
149
+ const mediaIndexKey = (url, identity) => `${url}#${identity}`;
150
+
151
+ const isMediaEntry = (item) => Boolean(item)
152
+ && typeof item.url === "string" && typeof item.key === "string" && typeof item.identity === "string"
153
+ && Number.isFinite(item.size) && item.size >= 0
154
+ && Number.isFinite(item.usedAt) && Number.isFinite(item.revalidatedAt);
155
+
156
+ const isCacheable = (response) => response.status !== 206
157
+ && response.ok && response.type === "basic"
158
+ && (response.headers.get("content-type") || "").startsWith("image/");
159
+
160
+ const tagged = (response, state) => {
161
+ const headers = new Headers(response.headers);
162
+ headers.set("X-Media-Cache", state);
163
+ return new Response(response.body, { status: response.status, statusText: response.statusText, headers });
164
+ };
165
+
166
+ async function loadMediaIdentity() {
167
+ if (mediaIdentity !== undefined) return mediaIdentity;
168
+ mediaIdentity = null;
169
+ try {
170
+ const cache = await caches.open(MEDIA_CACHE);
171
+ const response = await cache.match(MEDIA_IDENTITY);
172
+ const value = response ? await response.json() : null;
173
+ if (typeof value?.identity === "string" && IDENTITY_PATTERN.test(value.identity)) mediaIdentity = value.identity;
174
+ } catch { /* No stored identity means network-only media. */ }
175
+ return mediaIdentity;
176
+ }
177
+
178
+ async function saveMediaIdentity(identity) {
179
+ const cache = await caches.open(MEDIA_CACHE);
180
+ await cache.put(MEDIA_IDENTITY, new Response(JSON.stringify({ identity }), { headers: { "Content-Type": "application/json" } }));
181
+ }
182
+
183
+ async function setMediaIdentity(identity) {
184
+ if (typeof identity !== "string" || !IDENTITY_PATTERN.test(identity)) return;
185
+ await queueMedia(async () => {
186
+ const previous = await loadMediaIdentity();
187
+ mediaIdentity = identity;
188
+ if (previous === identity) {
189
+ await saveMediaIdentity(identity);
190
+ return;
191
+ }
192
+ // A different browser identity must never read the previous one's cached images.
193
+ await caches.delete(MEDIA_CACHE);
194
+ await saveMediaIdentity(identity);
195
+ });
196
+ }
197
+
198
+ async function clearMedia() {
199
+ await queueMedia(async () => {
200
+ const identity = await loadMediaIdentity();
201
+ await caches.delete(MEDIA_CACHE);
202
+ if (identity) await saveMediaIdentity(identity);
203
+ });
204
+ }
205
+
206
+ async function readIndex(cache) {
207
+ const response = await cache.match(MEDIA_INDEX);
208
+ if (!response) return [];
209
+ try {
210
+ const value = await response.json();
211
+ if (!Array.isArray(value)) throw new Error("invalid index");
212
+ return value.filter(isMediaEntry);
213
+ } catch {
214
+ // A damaged index cannot account for bodies; drop them so the caps stay meaningful.
215
+ for (const request of await cache.keys()) {
216
+ const path = new URL(request.url).pathname;
217
+ if (path !== MEDIA_INDEX && path !== MEDIA_IDENTITY) await cache.delete(request);
218
+ }
219
+ await cache.delete(MEDIA_INDEX);
220
+ return [];
221
+ }
222
+ }
223
+
224
+ const writeIndex = (cache, items) => cache.put(MEDIA_INDEX, new Response(JSON.stringify(items), { headers: { "Content-Type": "application/json" } }));
225
+
226
+ async function applyLimits(cache, items) {
227
+ const kept = [...items].sort((a, b) => a.usedAt - b.usedAt);
228
+ let bytes = kept.reduce((sum, item) => sum + item.size, 0);
229
+ const evicted = [];
230
+ while (kept.length > MEDIA_LIMITS.entries || (bytes > MEDIA_LIMITS.bytes && kept.length)) {
231
+ const item = kept.shift();
232
+ bytes -= item.size;
233
+ evicted.push(item);
234
+ }
235
+ for (const item of evicted) await cache.delete(mediaBodyKey(item.url, item.identity));
236
+ await writeIndex(cache, kept);
237
+ }
238
+
239
+ async function storeMedia(url, identity, response) {
240
+ const blob = await response.blob();
241
+ await queueMedia(async () => {
242
+ // An identity switch queued between fetch and put must not resurrect old bytes.
243
+ if (mediaIdentity !== identity) return;
244
+ const cache = await caches.open(MEDIA_CACHE);
245
+ await cache.put(mediaBodyKey(url, identity), new Response(blob, {
246
+ status: response.status, statusText: response.statusText, headers: response.headers,
247
+ }));
248
+ const key = mediaIndexKey(url, identity), now = Date.now();
249
+ const items = (await readIndex(cache)).filter((item) => item.key !== key);
250
+ items.push({ key, url, identity, size: blob.size, usedAt: now, revalidatedAt: now });
251
+ await applyLimits(cache, items);
252
+ });
253
+ }
254
+
255
+ const touchMedia = (url, identity) => queueMedia(async () => {
256
+ const cache = await caches.open(MEDIA_CACHE);
257
+ const items = await readIndex(cache);
258
+ const item = items.find((entry) => entry.url === url && entry.identity === identity);
259
+ if (!item) return;
260
+ item.usedAt = Date.now();
261
+ await writeIndex(cache, items);
262
+ });
263
+
264
+ const revalidating = new Set();
265
+ function revalidateMedia(request, url, identity) {
266
+ const key = mediaIndexKey(url, identity);
267
+ if (revalidating.has(key)) return Promise.resolve();
268
+ revalidating.add(key);
269
+ return (async () => {
270
+ try {
271
+ const response = await fetch(request);
272
+ if (response.status === 401 || response.status === 403 || response.status === 404) {
273
+ await queueMedia(async () => {
274
+ const cache = await caches.open(MEDIA_CACHE);
275
+ const items = await readIndex(cache);
276
+ const kept = items.filter((item) => item.key !== key);
277
+ await cache.delete(mediaBodyKey(url, identity));
278
+ if (kept.length !== items.length) await writeIndex(cache, kept);
279
+ });
280
+ } else if (response.status === 200 && isCacheable(response)) {
281
+ await storeMedia(url, identity, response);
282
+ }
283
+ } catch { /* A failed revalidation must not remove a working entry. */ }
284
+ finally { revalidating.delete(key); }
285
+ })();
286
+ }
287
+
288
+ async function pruneMedia() {
289
+ await queueMedia(async () => {
290
+ const cache = await caches.open(MEDIA_CACHE);
291
+ const items = await readIndex(cache);
292
+ const cutoff = Date.now() - MEDIA_LIMITS.age;
293
+ const fresh = items.filter((item) => item.usedAt >= cutoff);
294
+ for (const item of items) if (item.usedAt < cutoff) await cache.delete(mediaBodyKey(item.url, item.identity));
295
+ await applyLimits(cache, fresh);
296
+ });
297
+ }
298
+
299
+ async function mediaResponse(event) {
300
+ try {
301
+ return await serveMedia(event);
302
+ } catch {
303
+ // Cache Storage can be unavailable (private modes, quota). Media then stays network-only.
304
+ try { return tagged(await fetch(event.request), "bypass"); }
305
+ catch { return Response.error(); }
306
+ }
307
+ }
308
+
309
+ async function serveMedia(event) {
310
+ const request = event.request;
311
+ const identity = await loadMediaIdentity();
312
+ if (!identity) {
313
+ try { return tagged(await fetch(request), "bypass"); }
314
+ catch { return Response.error(); }
315
+ }
316
+ const url = request.url;
317
+ const cache = await caches.open(MEDIA_CACHE);
318
+ const cached = await cache.match(mediaBodyKey(url, identity));
319
+ if (cached) {
320
+ event.waitUntil(touchMedia(url, identity).catch(() => {}));
321
+ const entry = (await readIndex(cache)).find((item) => item.key === mediaIndexKey(url, identity));
322
+ // Serving stale is fine; revalidation is background hygiene for revocation/deletion.
323
+ if (!entry || Date.now() - entry.revalidatedAt > REVALIDATE_MS) event.waitUntil(revalidateMedia(request, url, identity).catch(() => {}));
324
+ return tagged(cached, "hit");
325
+ }
326
+ try {
327
+ const response = await fetch(request);
328
+ if (isCacheable(response)) await storeMedia(url, identity, response.clone()).catch(() => {});
329
+ return tagged(response, "miss");
330
+ } catch {
331
+ return Response.error();
332
+ }
333
+ }
@@ -52,7 +52,7 @@ Discuss shared questions in the room rather than opening private dialogs. Consol
52
52
  - For `join`, `name` is your own participant display name, not the room name. Use `roomId` to identify the room. For example, to join room `project-alpha` as `reviewer`, pass `{"action":"join","roomId":"<project-alpha-room-id>","name":"reviewer"}`. For `create`, `name` is the new room's name instead.
53
53
  - To rename yourself in a room, `leave` it and `join` it again with the new `name`. Earlier messages keep their original author name; in an approval room, rejoining may return pending until an administrator approves it.
54
54
  - Use `send` for messages, `poll` for full messages when needed, and `leave` to exit. A truncated preview is not the full message.
55
- - Tasks: `task_list` takes `roomId`; `task_create` takes `title` plus optional `description`, `assignee`, `dueDate`, `participants`, `conclusion`, and `steps`; `task_update` and `task_delete` take `taskId`, and update also needs at least one changed field. Steps are strings or `{ text, done }`, and object steps must always send the boolean. The creator or a room administrator may edit or delete a task and its steps; the assignee may change `status` (todo, doing, done) or toggle matching step completion. Use `task_list` to read creator, assignee, due date, participants, progress, and conclusion.
55
+ - Tasks: `task_list` takes `roomId`; `task_create` takes `title` plus optional `description`, `assignee`, `dueDate`, `participants`, `conclusion`, and `steps`; `task_update` and `task_delete` take `taskId`, and update also needs at least one changed field. Steps are strings or `{ text, done }`, and object steps must always send the boolean. The creator or a room administrator may edit or delete a task and its steps; the assignee may change `status` (todo, doing, done) or toggle matching step completion. Use `task_list` to read creator, assignee, due date, participants, progress, and conclusion. Keep the room task list current yourself: create a task for multi-step work you take on, move it to `doing`, tick steps and add a conclusion as you finish them, and mark it `done` rather than leaving stale entries.
56
56
  - Address the intended participant in the message text; use room broadcasts only for genuinely shared work.
57
57
  - Shared room tokens grant room access and management. A direct conversation is not private from other token holders.
58
58
 
@@ -1,7 +1,13 @@
1
- import { readFileSync } from "node:fs";
1
+ import { existsSync, readFileSync } from "node:fs";
2
2
  import { fileURLToPath } from "node:url";
3
3
 
4
- const path = fileURLToPath(new URL("../../skills/chatroom/SKILL.md", import.meta.url));
4
+ // Bundled into dist/cli.js the module sits one level shallower than in src/agent,
5
+ // so try both layouts instead of hard-coding a single relative path.
6
+ const candidates = [
7
+ new URL("../../skills/chatroom/SKILL.md", import.meta.url),
8
+ new URL("../skills/chatroom/SKILL.md", import.meta.url),
9
+ ].map((url) => fileURLToPath(url));
10
+ const path = candidates.find((candidate) => existsSync(candidate)) ?? candidates[0]!;
5
11
  const source = readFileSync(path, "utf8");
6
12
  const [, metadata = "", content = source] = source.match(/^---\r?\n([\s\S]*?)\r?\n---\r?\n([\s\S]*)$/) ?? [];
7
13
  const description = metadata.match(/^description:\s*(.+)$/m)?.[1]?.trim();
@@ -134,9 +134,9 @@ export function resourcePath(resource: Pick<Resource, "id" | "roomID">): string
134
134
  if (!uuid.test(resource.roomID) || !uuid.test(resource.id)) throw new ResourceError(404, "resource not found");
135
135
  return path.join(roomDirectory(resource.roomID), resource.id);
136
136
  }
137
- export async function listRoomResources(roomID: string, limit = 500, offset = 0): Promise<{ items: Resource[]; total: number }> {
137
+ export async function listRoomResources(roomID: string, limit = 500, offset = 0, beforeID?: string): Promise<{ items: Resource[]; total: number }> {
138
138
  if (!uuid.test(roomID)) throw new ResourceError(404, "room not found");
139
- return listResources(databasePath(), roomID, limit, offset);
139
+ return listResources(databasePath(), roomID, limit, offset, beforeID);
140
140
  }
141
141
  export async function findResource(roomID: string, id: string): Promise<Resource | undefined> {
142
142
  if (!uuid.test(id)) return undefined;