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

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 (67) hide show
  1. package/CHANGELOG.md +14 -1
  2. package/LICENSE +21 -0
  3. package/README.md +45 -36
  4. package/README.zh-CN.md +50 -41
  5. package/dist/cli.js +2629 -350
  6. package/package.json +13 -3
  7. package/packages/chat-room-channeld/README.md +242 -0
  8. package/packages/chat-room-channeld/dist/feishu-adapter.js +499 -0
  9. package/packages/chat-room-channeld/dist/mock-adapter.js +295 -0
  10. package/packages/chat-room-channeld/src/adapter.ts +475 -0
  11. package/packages/chat-room-channeld/src/cli.ts +124 -0
  12. package/packages/chat-room-channeld/src/config.ts +207 -0
  13. package/packages/chat-room-channeld/src/delivery.ts +158 -0
  14. package/packages/chat-room-channeld/src/feishu-adapter.ts +473 -0
  15. package/packages/chat-room-channeld/src/framing.ts +128 -0
  16. package/packages/chat-room-channeld/src/host-helpers.ts +41 -0
  17. package/packages/chat-room-channeld/src/host.ts +509 -0
  18. package/packages/chat-room-channeld/src/ingest-gate.ts +108 -0
  19. package/packages/chat-room-channeld/src/log.ts +26 -0
  20. package/packages/chat-room-channeld/src/mock-adapter.ts +206 -0
  21. package/packages/chat-room-channeld/src/protocol.ts +75 -0
  22. package/packages/chat-room-channeld/src/published.ts +37 -0
  23. package/packages/chat-room-channeld/src/rules.ts +127 -0
  24. package/packages/chat-room-channeld/src/state.ts +485 -0
  25. package/packages/chat-room-channeld/src/stats.ts +167 -0
  26. package/plugin.ts +22 -5
  27. package/server/addressing-routes.ts +130 -0
  28. package/server/assets/NOTICE.txt +2 -2
  29. package/server/assets/SHIKI-LICENSE +22 -0
  30. package/server/assets/base.css +9 -1
  31. package/server/assets/chat/doc-preview.js +3 -4
  32. package/server/assets/chat/forward.js +69 -0
  33. package/server/assets/chat/index.js +2 -0
  34. package/server/assets/chat/locales/de.js +5 -0
  35. package/server/assets/chat/locales/es.js +5 -0
  36. package/server/assets/chat/locales/fr.js +5 -0
  37. package/server/assets/chat/locales/it.js +5 -0
  38. package/server/assets/chat/locales/ja.js +5 -0
  39. package/server/assets/chat/locales/ko.js +5 -0
  40. package/server/assets/chat/markdown-footnotes.js +115 -0
  41. package/server/assets/chat/markdown.js +24 -35
  42. package/server/assets/chat/palette.js +1 -1
  43. package/server/assets/chat/replies.js +7 -1
  44. package/server/assets/chat/shiki.js +87 -0
  45. package/server/assets/chat/side-pane.js +8 -1
  46. package/server/assets/chat/state.js +14 -1
  47. package/server/assets/chat/system-messages.js +2 -0
  48. package/server/assets/code-highlight.css +20 -31
  49. package/server/assets/conversation.css +3 -2
  50. package/server/assets/doc-preview.css +2 -1
  51. package/server/assets/responsive.css +5 -0
  52. package/server/assets/shiki.bundle.js +152 -0
  53. package/server/channels.ts +314 -0
  54. package/server/chat-server.ts +27 -4
  55. package/server/chat.html +10 -3
  56. package/server/sw.js +1 -2
  57. package/skills/chatroom/SKILL.md +1 -1
  58. package/src/center/center-client.ts +79 -1
  59. package/src/config/file-config.ts +34 -0
  60. package/src/runtime/v2-plugin.ts +8 -2
  61. package/src/runtime/watch.ts +3 -2
  62. package/src/state/sqlite-state.ts +42 -11
  63. package/src/state/store.ts +9 -3
  64. package/src/tui/http.mjs +16 -2
  65. package/src/tui/main.mjs +1 -1
  66. package/server/assets/HIGHLIGHT-LICENSE +0 -29
  67. package/server/assets/highlight-10.7.3.min.js +0 -1358
@@ -0,0 +1,115 @@
1
+ // Code masking keeps footnote syntax literal inside fences and inline spans.
2
+ function maskCode(value, nonce) {
3
+ const blocks = [];
4
+ const token = () => `CHATCODETOKEN${nonce}${blocks.length}END`;
5
+ let masked = String(value).replace(/^(```|~~~)[^\n]*\n[\s\S]*?\n\1[ \t]*$/gm, (block) => {
6
+ const key = token(); blocks.push(block); return key;
7
+ });
8
+ masked = masked.replace(/(`+)([^`\n]*?)\1/g, (span) => {
9
+ const key = token(); blocks.push(span); return key;
10
+ });
11
+ return {
12
+ masked,
13
+ maskIndented: (text) => text.replace(/^(?: {4}|\t).*$/gm, (line) => {
14
+ const key = token(); blocks.push(line); return key;
15
+ }),
16
+ restore: (text) => text.replace(new RegExp(`CHATCODETOKEN${nonce}(\\d+)END`, "g"), (_, index) => blocks[Number(index)]),
17
+ };
18
+ }
19
+
20
+ export function prepareFootnotes(value, nonce) {
21
+ const code = maskCode(value, nonce);
22
+ const lines = code.masked.split("\n"), definitions = new Map(), kept = [];
23
+ for (let index = 0; index < lines.length; index++) {
24
+ const match = /^ {0,3}\[\^([^\]\s]+)\]:[ \t]*(.*)$/.exec(lines[index]);
25
+ if (!match) { kept.push(lines[index]); continue; }
26
+ let body = match[2].trim();
27
+ while (index + 1 < lines.length && /^(?: {2,}|\t)/.test(lines[index + 1])) {
28
+ index++;
29
+ body += `\n${lines[index].replace(/^(?: {2,4}|\t)/, "")}`;
30
+ }
31
+ definitions.set(match[1], code.restore(body));
32
+ kept.push("");
33
+ }
34
+ const references = new Map(), tokens = [], tokenLabels = [];
35
+ let source = code.maskIndented(kept.join("\n")).replace(/\[\^([^\]\s]+)\]/g, (literal, label) => {
36
+ if (!definitions.has(label)) return literal;
37
+ if (!references.has(label)) references.set(label, references.size + 1);
38
+ const token = `CHATFOOTNOTE${nonce}${tokens.length}END`;
39
+ tokens.push(token); tokenLabels.push(label);
40
+ return token;
41
+ });
42
+ source = code.restore(source);
43
+ // Footnote anchors live in the same document as messages and the preview, so
44
+ // each render needs its own prefix or id="fn-1" would collide across them.
45
+ return { source, definitions, references, tokens, tokenLabels, refIds: new Map(), idPrefix: `fn-${nonce}` };
46
+ }
47
+
48
+ export function replaceFootnoteTokens(fragment, notes) {
49
+ if (!notes.tokens.length) return;
50
+ const labels = new Map(notes.tokens.map((token, index) => [token, notes.tokenLabels[index]]));
51
+ const pattern = new RegExp(`(${notes.tokens.join("|")})`, "g");
52
+ const walker = document.createTreeWalker(fragment, NodeFilter.SHOW_TEXT), nodes = [];
53
+ while (walker.nextNode()) nodes.push(walker.currentNode);
54
+ for (const node of nodes) {
55
+ if (node.parentElement?.closest("code, pre, a")) continue;
56
+ const pieces = (node.nodeValue || "").split(pattern);
57
+ if (pieces.length === 1) continue;
58
+ const replacement = document.createDocumentFragment();
59
+ for (const piece of pieces) {
60
+ const label = labels.get(piece);
61
+ if (!label) { replacement.append(document.createTextNode(piece)); continue; }
62
+ const number = notes.references.get(label), ids = notes.refIds.get(label) || [];
63
+ const id = ids.length ? `${notes.idPrefix}-ref-${number}-${ids.length}` : `${notes.idPrefix}-ref-${number}`;
64
+ ids.push(id); notes.refIds.set(label, ids);
65
+ const sup = document.createElement("sup"), link = document.createElement("a");
66
+ sup.className = "footnote-ref";
67
+ link.id = id; link.href = `#${notes.idPrefix}-${number}`; link.textContent = String(number);
68
+ link.setAttribute("role", "doc-noteref");
69
+ sup.append(link); replacement.append(sup);
70
+ }
71
+ node.replaceWith(replacement);
72
+ }
73
+ }
74
+
75
+ export function appendFootnotes(fragment, notes) {
76
+ if (!notes.references.size) return;
77
+ const section = document.createElement("section"), list = document.createElement("ol");
78
+ section.className = "footnotes"; section.setAttribute("role", "doc-endnotes");
79
+ for (const [label, number] of notes.references) {
80
+ const item = document.createElement("li"), body = document.createElement("span");
81
+ item.id = `${notes.idPrefix}-${number}`; item.setAttribute("role", "doc-endnote");
82
+ body.className = "footnote-body";
83
+ const parsed = window.marked.parseInline(notes.definitions.get(label) || "", { gfm: true, breaks: true });
84
+ body.innerHTML = window.DOMPurify.sanitize(parsed);
85
+ item.append(body);
86
+ for (const id of notes.refIds.get(label) || []) {
87
+ const back = document.createElement("a");
88
+ back.href = `#${id}`; back.className = "footnote-backref"; back.textContent = "↩";
89
+ back.setAttribute("aria-label", "Back to reference");
90
+ item.append(document.createTextNode(" "), back);
91
+ }
92
+ list.append(item);
93
+ }
94
+ section.append(list); fragment.append(section);
95
+ }
96
+
97
+ export function decorateLinks(fragment) {
98
+ fragment.querySelectorAll("a").forEach((link) => {
99
+ const href = link.getAttribute("href") || "";
100
+ if (href.startsWith("#")) return;
101
+ let external = /^(?:mailto|tel):/i.test(href);
102
+ if (!external && /^(?:https?:)?\/\//i.test(href)) {
103
+ try { external = new URL(href, location.href).origin !== location.origin; } catch { external = false; }
104
+ }
105
+ if (external) {
106
+ link.target = "_blank";
107
+ link.rel = "noopener noreferrer";
108
+ } else {
109
+ // A relative or same-origin API URL would lose the bearer token in a top-level
110
+ // navigation; keep the reader in place instead of opening a 401 page.
111
+ link.removeAttribute("target");
112
+ link.addEventListener("click", (event) => event.preventDefault());
113
+ }
114
+ });
115
+ }
@@ -2,9 +2,10 @@ import { createRandomId, LS } from "./state.js";
2
2
  import { isRoomAdmin } from "./admin-badge.js";
3
3
  import { iconNode } from "./icons.js";
4
4
  import { isUnsafeDiagram, rememberDiagramSource, renderDiagram, showDiagramFallback } from "./diagram-viewer.js";
5
- import { docPreviewFormat, TEXT_PREVIEW_LIMIT } from "./resource-format.js";
5
+ import { docPreviewFormat } from "./resource-format.js";
6
6
  import { copyTextToClipboard } from "./clipboard.js";
7
- import { createCopyButton, copyResourceText } from "./copy-action.js";
7
+ import { enhanceCodeElement } from "./shiki.js";
8
+ import { appendFootnotes, decorateLinks, prepareFootnotes, replaceFootnoteTokens } from "./markdown-footnotes.js";
8
9
 
9
10
  export { copyTextToClipboard };
10
11
 
@@ -44,7 +45,8 @@ function escapeHtmlText(value) {
44
45
  export function renderMarkdown(root, text, app) {
45
46
  const mentions = [], diagrams = new Map();
46
47
  const nonce = createRandomId();
47
- const source = String(text).replace(mentionPattern, (_, name) => {
48
+ const notes = prepareFootnotes(text, nonce);
49
+ const source = notes.source.replace(mentionPattern, (_, name) => {
48
50
  const token = `CHATMENTION${nonce}${mentions.length}END`;
49
51
  mentions.push({ token, name, literal: `<at>@${name}</at>` });
50
52
  return token;
@@ -61,6 +63,8 @@ export function renderMarkdown(root, text, app) {
61
63
  const parsed = window.marked.parse(source, { gfm: true, breaks: true, async: false, renderer });
62
64
  const fragment = window.DOMPurify.sanitize(parsed, { RETURN_DOM_FRAGMENT: true });
63
65
  replaceMentionTokens(fragment, mentions, app);
66
+ replaceFootnoteTokens(fragment, notes);
67
+ appendFootnotes(fragment, notes);
64
68
  const resources = replaceResourceMarkers(fragment, app);
65
69
  const diagramNodes = [...fragment.querySelectorAll("[data-chat-mermaid]")];
66
70
  for (const node of diagramNodes) {
@@ -72,13 +76,13 @@ export function renderMarkdown(root, text, app) {
72
76
  if (!unsafe) activateDiagram(node, source, app);
73
77
  }
74
78
  }
75
- fragment.querySelectorAll("a").forEach((link) => {
76
- link.target = "_blank";
77
- link.rel = "noopener noreferrer";
78
- });
79
+ decorateLinks(fragment);
79
80
  fragment.querySelectorAll('input[type="checkbox"]').forEach((input) => { input.disabled = true; });
80
- for (const code of fragment.querySelectorAll("pre > code")) decorateCodeBlock(code, app);
81
+ const codeBlocks = [...fragment.querySelectorAll("pre > code")];
82
+ for (const code of codeBlocks) decorateCodeBlock(code, app);
81
83
  root.appendChild(fragment);
84
+ // Highlight after insertion: the escaped text is readable while the bundle loads.
85
+ for (const code of codeBlocks) void enhanceCodeElement(code);
82
86
  for (let i = 0; i < diagramNodes.length; i++) {
83
87
  const source = diagrams.get(`CHATDIAGRAM${nonce}${i}END`);
84
88
  if (!isUnsafeDiagram(source)) void renderDiagram(diagramNodes[i], source, app);
@@ -89,7 +93,6 @@ export function renderMarkdown(root, text, app) {
89
93
  function decorateCodeBlock(code, app) {
90
94
  const pre = code.parentElement;
91
95
  if (!pre || pre.closest(".mermaid-diagram") || pre.parentElement?.classList.contains("code-block")) return;
92
- highlightCode(code);
93
96
  const block = document.createElement("div");
94
97
  block.className = "code-block";
95
98
  pre.replaceWith(block);
@@ -103,17 +106,6 @@ function decorateCodeBlock(code, app) {
103
106
  }
104
107
  }
105
108
 
106
- function highlightCode(code) {
107
- const language = (/language-(\S+)/.exec(code.className) || [])[1]?.toLowerCase();
108
- if (!language || language === "mermaid" || !window.hljs?.getLanguage?.(language)) return;
109
- try {
110
- const markup = window.hljs.highlight(code.textContent, { language }).value;
111
- const fragment = window.DOMPurify.sanitize(markup, { RETURN_DOM_FRAGMENT: true, ALLOWED_TAGS: ["span"], ALLOWED_ATTR: ["class"] });
112
- code.replaceChildren(fragment);
113
- code.classList.add("hljs");
114
- } catch { /* Keep the escaped text when a grammar rejects its input. */ }
115
- }
116
-
117
109
  function codeToolbar(code, pre, block, app) {
118
110
  const toolbar = document.createElement("div");
119
111
  toolbar.className = "code-toolbar";
@@ -232,18 +224,6 @@ async function loadResourceCard(card, roomId, app) {
232
224
  actions.append(resourceSplit(app, resource, download, remove));
233
225
  } else actions.append(download);
234
226
  const docFormat = docPreviewFormat(resource);
235
- if (docFormat && docFormat.kind !== "pdf") {
236
- const copy = createCopyButton(app, "resource-copy");
237
- copy.dataset.copyAction = "card";
238
- copy.addEventListener("click", () => {
239
- void copyResourceText(copy, app, async () => {
240
- if (Number(resource.size) > TEXT_PREVIEW_LIMIT) return "";
241
- const data = await app.apiBlob(`/rooms/${encodeURIComponent(roomId)}/resources/${encodeURIComponent(id)}/content`);
242
- return data.text();
243
- });
244
- });
245
- actions.append(copy);
246
- }
247
227
  if (previewKind(type) || docFormat) {
248
228
  const preview = resourceButton("resourcePreview", resource.name, () => docFormat
249
229
  ? app.openDocPreview(roomId, resource, preview)
@@ -255,19 +235,28 @@ async function loadResourceCard(card, roomId, app) {
255
235
  } catch (error) { if (card.isConnected) setResourceError(card, app, error?.status === 404 ? "resourceDeleted" : "resourceFailed"); }
256
236
  }
257
237
  function setResourceButton(button, key, name, app) {
258
- button.dataset.i18n = key; button.textContent = app.t(key);
238
+ button.dataset.i18n = key;
239
+ const label = button.querySelector(".i18n-label");
240
+ if (label) label.textContent = app.t(key); else button.textContent = app.t(key);
259
241
  button.setAttribute("aria-label", `${app.t(key)}: ${name}`);
260
242
  }
261
243
  function resourceButton(key, name, action, app) {
262
244
  const button = document.createElement("button");
263
245
  button.type = "button"; button.className = "btn ghost small resource-button";
246
+ const label = document.createElement("span");
247
+ label.className = "i18n-label"; label.textContent = app.t(key);
248
+ button.append(iconNode(key === "resourceDownload" ? "arrow_download" : "eye"), label);
249
+ button.addEventListener("click", action);
264
250
  setResourceButton(button, key, name, app);
265
- button.addEventListener("click", action); return button;
251
+ return button;
266
252
  }
267
253
  function resourceMenuItem(key, action, app) {
268
254
  const button = document.createElement("button");
269
255
  button.type = "button"; button.className = "menu-action danger-text"; button.setAttribute("role", "menuitem");
270
- button.dataset.i18n = key; button.textContent = app.t(key);
256
+ button.dataset.i18n = key;
257
+ const label = document.createElement("span");
258
+ label.className = "i18n-label"; label.textContent = app.t(key);
259
+ button.append(iconNode("delete"), label);
271
260
  button.addEventListener("click", action); return button;
272
261
  }
273
262
  function resourceSplit(app, resource, download, item) {
@@ -2,7 +2,7 @@ import { icon } from "./icons.js";
2
2
 
3
3
  // Alt+Space or Ctrl+P opens one keyboard-first surface: message search plus common room commands.
4
4
 
5
- const SEARCH_DEBOUNCE_MS = 220;
5
+ const SEARCH_DEBOUNCE_MS = 120;
6
6
 
7
7
  export function initPalette(app) {
8
8
  const dialog = app.$("#paletteDialog");
@@ -33,7 +33,7 @@ function bindMessageActions(app) {
33
33
  const render = app.renderMessage;
34
34
  app.renderMessage = (message, live) => {
35
35
  const row = render(message, live);
36
- if (message.senderId === "system" || message.pending) return row;
36
+ if (message.senderId === "system" || message.pending || message.recalledAt) return row;
37
37
  if (message.answerToMessageID) row.querySelector(".msg-meta")?.after(quoteButton(message, app));
38
38
  const copy = row.querySelector("[data-copy-message]");
39
39
  if (copy) {
@@ -42,6 +42,12 @@ function bindMessageActions(app) {
42
42
  reply.type = "button"; reply.className = "message-reply"; reply.innerHTML = icon("arrow_reply", "message-reply-icon");
43
43
  reply.setAttribute("aria-label", app.t("replyMessage")); reply.dataset.i18nAriaLabel = "replyMessage"; reply.dataset.replyMessage = message.id;
44
44
  copy.before(actions); actions.append(copy, reply);
45
+ if (document.body.dataset.channeld === "on") {
46
+ const forward = document.createElement("button");
47
+ forward.type = "button"; forward.className = "message-reply message-forward"; forward.innerHTML = icon("arrow_right", "message-reply-icon");
48
+ forward.setAttribute("aria-label", app.t("forwardMessage")); forward.dataset.i18nAriaLabel = "forwardMessage"; forward.dataset.forwardMessage = message.id;
49
+ actions.append(forward);
50
+ }
45
51
  }
46
52
  return row;
47
53
  };
@@ -0,0 +1,87 @@
1
+ // Lazy Shiki highlighting. The bundle is fetched on the first fenced code block,
2
+ // so a conversation without code never downloads or parses it.
3
+
4
+ const LANGUAGE_ALIASES = new Map([
5
+ ["ts", "typescript"], ["typescript", "typescript"],
6
+ ["tsx", "tsx"],
7
+ ["js", "javascript"], ["javascript", "javascript"], ["mjs", "javascript"], ["cjs", "javascript"], ["node", "javascript"],
8
+ ["jsx", "jsx"],
9
+ ["json", "json"], ["jsonc", "json"],
10
+ ["bash", "shellscript"], ["sh", "shellscript"], ["zsh", "shellscript"],
11
+ ["shell", "shellscript"], ["shellscript", "shellscript"], ["console", "shellscript"],
12
+ ["yml", "yaml"], ["yaml", "yaml"],
13
+ ["md", "markdown"], ["markdown", "markdown"],
14
+ ["py", "python"], ["python", "python"],
15
+ ["rs", "rust"], ["rust", "rust"],
16
+ ["go", "go"], ["golang", "go"],
17
+ ["java", "java"],
18
+ ["sql", "sql"],
19
+ ["html", "html"], ["htm", "html"],
20
+ ["xml", "xml"], ["svg", "xml"], ["xsl", "xml"],
21
+ ["css", "css"],
22
+ ]);
23
+
24
+ const pending = new Set();
25
+ let highlighterPromise;
26
+ let failed = false;
27
+ let warned = false;
28
+
29
+ function warnOnce(error) {
30
+ if (warned) return;
31
+ warned = true;
32
+ console.warn("Syntax highlighting unavailable; showing plain code.", error);
33
+ }
34
+
35
+ function getHighlighter() {
36
+ if (failed) return null;
37
+ highlighterPromise ??= import("/assets/shiki.bundle.js")
38
+ .then((module) => module.createHighlighter())
39
+ .catch((error) => {
40
+ failed = true;
41
+ warnOnce(error);
42
+ return null;
43
+ });
44
+ return highlighterPromise;
45
+ }
46
+
47
+ function languageOf(code) {
48
+ return (/language-(\S+)/.exec(code.className) || [])[1]?.toLowerCase() || "";
49
+ }
50
+
51
+ // Returns Shiki's HTML (it escapes the code text) or null for an unknown or failed language.
52
+ export async function highlightToHtml(code, lang) {
53
+ const language = LANGUAGE_ALIASES.get(String(lang || "").toLowerCase());
54
+ if (!language) return null;
55
+ try {
56
+ const highlighter = await getHighlighter();
57
+ if (!highlighter) return null;
58
+ return highlighter.codeToHtml(code, { lang: language, theme: "chatroom" });
59
+ } catch (error) {
60
+ warnOnce(error);
61
+ return null;
62
+ }
63
+ }
64
+
65
+ export function whenShikiIdle() {
66
+ return Promise.allSettled([...pending]);
67
+ }
68
+
69
+ // Replaces the escaped text inside one code element, leaving the surrounding
70
+ // pre, toolbar, wrap state, and copy button alone.
71
+ export function enhanceCodeElement(code) {
72
+ const task = embed(code).catch(() => {}).finally(() => pending.delete(task));
73
+ pending.add(task);
74
+ return task;
75
+ }
76
+
77
+ async function embed(code) {
78
+ if (!LANGUAGE_ALIASES.has(languageOf(code))) return;
79
+ const markup = await highlightToHtml(code.textContent || "", languageOf(code));
80
+ if (!markup || !code.isConnected) return;
81
+ const template = document.createElement("template");
82
+ template.innerHTML = markup;
83
+ const rendered = template.content.querySelector("code");
84
+ if (!rendered) return;
85
+ code.replaceChildren(...rendered.childNodes);
86
+ code.classList.add("shiki");
87
+ }
@@ -4,6 +4,7 @@
4
4
  const STORAGE_KEY = "chat.sidePaneWidth";
5
5
  const MIN_WIDTH = 360;
6
6
  const MIN_CHAT = 420;
7
+ const WIDE_TASKS_MIN_CHAT = 700;
7
8
  const RAIL_WIDTH = 252;
8
9
  const GUTTER = 8;
9
10
  const MAX_WIDTH = 960;
@@ -24,8 +25,14 @@ export function initSidePaneSplitter(app) {
24
25
  const activePane = () => view.classList.contains("has-doc") ? preview
25
26
  : view.classList.contains("has-tasks") ? tasks : null;
26
27
 
28
+ // A wide task board must leave the conversation a full working column; the
29
+ // Markdown preview keeps the normal minimum.
30
+ const wideTasks = () => view.classList.contains("has-tasks") && !view.classList.contains("has-doc")
31
+ && window.matchMedia("(min-width: 1500px) and (min-height: 900px)").matches;
32
+ const minChat = () => wideTasks() ? WIDE_TASKS_MIN_CHAT : MIN_CHAT;
33
+
27
34
  const maxWidth = () => {
28
- const available = view.clientWidth - RAIL_WIDTH - GUTTER - MIN_CHAT;
35
+ const available = view.clientWidth - RAIL_WIDTH - GUTTER - minChat();
29
36
  return Math.max(MIN_WIDTH, Math.min(window.innerWidth * 0.7, MAX_WIDTH, available));
30
37
  };
31
38
  const clamp = (width) => Math.max(MIN_WIDTH, Math.min(width, maxWidth()));
@@ -353,6 +353,10 @@ export const messages = {
353
353
  savedMemory: "Saved for this tab only", copyFailed: ({ id }) => `Copy failed. Copy manually: ${id}`,
354
354
  copyMessage: "Copy", copiedMessage: "Copied", copyMessageFailed: "Could not copy. Select and copy the message manually.", wrapCode: "Wrap code",
355
355
  replyMessage: "Reply", replyingTo: "Replying to", cancelReply: "Cancel reply", replyOpenOriginal: "View original message", replyOriginalUnavailable: "Original message is unavailable.", replyOriginalRecalled: "Original message was recalled.",
356
+ forwardMessage: "Forward", forwardTitle: "Forward message", forwardHint: "Choose where to forward this message.",
357
+ forwardConfirm: ({ target }) => `Forward this message to ${target}?`, forwardNoTargets: "No forward targets are configured for this room.",
358
+ forwardUnavailable: "Forwarding is not available on this server.", forwardLoadFailed: "Could not load forward targets.",
359
+ forwardFailed: ({ message }) => `Forward failed: ${message}`,
356
360
  recallMessage: "Recall", recallSystemMessage: "Recall this room notice", recallSystemConfirm: "Recall this room notice? Everyone will see it as recalled.", recallConfirm: "Recall this message? Everyone will see it as recalled.", recallAdminConfirm: ({ name }) => `Recall ${name}'s message? Everyone will see it as recalled.`, recallFailed: "Could not recall this message.", messageRecalled: "Message recalled", recalledBy: ({ name }) => `Recalled by ${name}`, showRecalled: "View original", hideRecalled: "Hide original", revealFailed: "Load failed. Retry",
357
361
  identityChanged: "This browser identity changed in another tab. Reload this tab before continuing.",
358
362
  networkError: "Network connection failed", requestFailed: ({ status }) => `Request failed (HTTP ${status})`,
@@ -379,6 +383,7 @@ export const messages = {
379
383
  resourceDelete: "Delete file", resourceDeleting: "Deleting…", resourceDeleteConfirm: ({ name }) => `Delete “${name}”? This cannot be undone.`, resourceDeleted: "File deleted.", resourceDeleteFailed: "Could not delete this file.",
380
384
  systemJoined: ({ name }) => `${name} joined the room`, systemLeft: ({ name }) => `${name} left the room`, systemRemoved: ({ name }) => `${name} was removed from the room`,
381
385
  systemDesignated: ({ actor, name }) => `${actor} designated ${name} as administrator`, systemRevoked: ({ actor }) => `${actor} revoked the administrator designation`, systemRenamed: ({ actor, from, to }) => `${actor} renamed the room from "${from}" to "${to}"`, systemDescribed: ({ actor }) => `${actor} updated the room description`, systemHanded: ({ actor, name }) => `${actor} handed the room to ${name}`, systemAdminsUpdated: ({ actor }) => `${actor} updated the room administrators`, systemSuccessorNamed: ({ actor, name }) => `${actor} named ${name} as the room successor`, systemSuccessorCleared: ({ actor }) => `${actor} cleared the room successor`, systemJoinPolicy: ({ actor, policy }) => policy === "approval" ? `${actor} now requires approval to join this room` : `${actor} opened this room to join without approval`,
386
+ systemForwarded: ({ target }) => `Forwarded to ${target}`, systemForwardFailed: ({ target, reason }) => `Forward to ${target} failed: ${reason}`,
382
387
  activity_working: "Working", activity_idle: "Foreground idle", activity_waiting: "Waiting", activity_unknown: "Status unknown", activity_offline: "Status stale",
383
388
  activityHint_working: "The agent reports active work.", activityHint_idle: "Foreground is idle; background work may continue.", activityHint_waiting: "The agent reports that it is waiting.", activityHint_unknown: "No activity report is available.", activityHint_offline: "The last status is stale; this does not prove the agent is offline.",
384
389
  receiptCount: ({ count }) => `Read by ${count}`, receiptNone: "No readers yet", receiptNotLoaded: "Read status not loaded", readerPanelTitle: "Message readers", close: "Close", departedMember: "left",
@@ -502,6 +507,10 @@ export const messages = {
502
507
  savedMemory: "仅保存于当前标签页", copyFailed: ({ id }) => `复制失败,请手动复制:${id}`,
503
508
  copyMessage: "复制", copiedMessage: "已复制", copyMessageFailed: "复制失败,请手动选择并复制消息。", wrapCode: "自动换行",
504
509
  replyMessage: "回复", replyingTo: "回复给", cancelReply: "取消回复", replyOpenOriginal: "查看原始消息", replyOriginalUnavailable: "原始消息不可用。", replyOriginalRecalled: "原消息已撤回。",
510
+ forwardMessage: "转发", forwardTitle: "转发消息", forwardHint: "选择把这条消息转发到哪里。",
511
+ forwardConfirm: ({ target }) => `把这条消息转发到 ${target}?`, forwardNoTargets: "这个房间没有配置转发目标。",
512
+ forwardUnavailable: "此服务器未开启转发功能。", forwardLoadFailed: "无法加载转发目标。",
513
+ forwardFailed: ({ message }) => `转发失败:${message}`,
505
514
  recallMessage: "撤回", recallSystemMessage: "撤回这条房间通知", recallSystemConfirm: "撤回这条房间通知?所有人都会看到“消息已撤回”。", recallConfirm: "撤回这条消息?所有人都会看到“消息已撤回”。", recallAdminConfirm: ({ name }) => `撤回 ${name} 的消息?所有人都会看到“消息已撤回”。`, recallFailed: "撤回失败,请重试。", messageRecalled: "消息已撤回", recalledBy: ({ name }) => `${name} 撤回`, showRecalled: "查看原文", hideRecalled: "收起原文", revealFailed: "加载失败,重试",
506
515
  identityChanged: "此浏览器身份已在另一个标签页中更改,请重新加载此标签页后继续。",
507
516
  networkError: "网络连接失败", requestFailed: ({ status }) => `请求失败(HTTP ${status})`,
@@ -523,6 +532,7 @@ export const messages = {
523
532
  privacyNote: "持有共享令牌的人都可以读取私聊内容和管理房间;服务器也可以读取私聊内容。", resourceDelete: "删除文件", resourceDeleting: "正在删除…", resourceDeleteConfirm: ({ name }) => `确定删除“${name}”?此操作无法撤销。`, resourceDeleted: "文件已删除。", resourceDeleteFailed: "无法删除此文件。",
524
533
  systemJoined: ({ name }) => `${name} 加入了房间`, systemLeft: ({ name }) => `${name} 离开了房间`, systemRemoved: ({ name }) => `${name} 被移出了房间`,
525
534
  systemDesignated: ({ actor, name }) => `${actor} 指定 ${name} 为管理员`, systemRevoked: ({ actor }) => `${actor} 撤销了管理员指定`, systemRenamed: ({ actor, from, to }) => `${actor} 将房间名称从“${from}”改为“${to}”`, systemDescribed: ({ actor }) => `${actor} 更新了房间描述`, systemHanded: ({ actor, name }) => `${actor} 将房间移交给了 ${name}`, systemAdminsUpdated: ({ actor }) => `${actor} 更新了房间管理员`, systemSuccessorNamed: ({ actor, name }) => `${actor} 指定 ${name} 为房间继任者`, systemSuccessorCleared: ({ actor }) => `${actor} 清除了房间继任者`, systemJoinPolicy: ({ actor, policy }) => policy === "approval" ? `${actor} 开启了加入审核,新成员需要管理员批准` : `${actor} 关闭了加入审核,新成员可以直接加入`,
535
+ systemForwarded: ({ target }) => `已转发到 ${target}`, systemForwardFailed: ({ target, reason }) => `转发到 ${target} 失败:${reason}`,
526
536
  activity_working: "工作中", activity_idle: "前台空闲", activity_waiting: "等待中", activity_unknown: "状态未知", activity_offline: "状态已过期",
527
537
  activityHint_working: "Agent 正在报告工作状态。", activityHint_idle: "前台空闲;后台任务仍可能继续。", activityHint_waiting: "Agent 正在报告等待状态。", activityHint_unknown: "暂无活动状态报告。", activityHint_offline: "最近的状态已过期;这不能证明 Agent 已离线。",
528
538
  receiptCount: ({ count }) => `已读 ${count} 人`, receiptNone: "尚无人已读", receiptNotLoaded: "尚未加载已读状态", readerPanelTitle: "消息已读情况", close: "关闭", departedMember: "已离开",
@@ -601,9 +611,12 @@ app.setText = (element, key, values = {}) => {
601
611
  app.applyLocale = () => {
602
612
  document.documentElement.lang = app.locale;
603
613
  document.querySelectorAll("[data-i18n]").forEach((element) => {
604
- element.textContent = element._flashKey
614
+ const text = element._flashKey
605
615
  ? app.t(element._flashKey)
606
616
  : app.t(element.dataset.i18n, element._i18nValues || {});
617
+ // Controls with icons keep the graphic and swap only the text label.
618
+ const label = element.querySelector(":scope > .i18n-label");
619
+ if (label) label.textContent = text; else element.textContent = text;
607
620
  });
608
621
  for (const attribute of ["aria-label", "aria-placeholder", "title", "placeholder"]) {
609
622
  document.querySelectorAll(`[data-i18n-${attribute}]`).forEach((element) => {
@@ -11,6 +11,8 @@ const patterns = [
11
11
  [/^(.*?) updated the room description$/, "systemDescribed", (m) => ({ actor: m[1] })],
12
12
  [/^(.*?) set join approval to (open|approval)$/, "systemJoinPolicy", (m) => ({ actor: m[1], policy: m[2] })],
13
13
  [/^(.*?) handed the room to (.*)$/, "systemHanded", (m) => ({ actor: m[1], name: m[2] })],
14
+ [/^Forwarded to (.*)$/, "systemForwarded", (m) => ({ target: m[1] })],
15
+ [/^Forward to (.*?) failed: (.*)$/, "systemForwardFailed", (m) => ({ target: m[1], reason: m[2] })],
14
16
  ];
15
17
 
16
18
  function formatLine(line, app) {
@@ -7,6 +7,22 @@
7
7
  --code-number: color-mix(in srgb, var(--warning) 68%, var(--ink));
8
8
  --code-title: color-mix(in srgb, var(--accent) 72%, var(--ink));
9
9
  --code-comment: color-mix(in srgb, var(--ink-3) 78%, var(--ink));
10
+ /* Shiki renders token colors as var(--shiki-token-*) inline styles. Mapping them
11
+ to the palette tokens lets every theme (light, dark, forest, sand) switch live. */
12
+ --shiki-foreground: var(--ink);
13
+ --shiki-background: var(--code-bg);
14
+ --shiki-token-comment: var(--code-comment);
15
+ --shiki-token-constant: var(--code-number);
16
+ --shiki-token-keyword: var(--code-keyword);
17
+ --shiki-token-parameter: var(--ink-2);
18
+ --shiki-token-function: var(--code-title);
19
+ --shiki-token-string: var(--code-string);
20
+ --shiki-token-string-expression: var(--code-string);
21
+ --shiki-token-punctuation: var(--ink-2);
22
+ --shiki-token-link: var(--mention-blue);
23
+ --shiki-token-inserted: var(--accent);
24
+ --shiki-token-deleted: var(--danger);
25
+ --shiki-token-changed: var(--warning);
10
26
  }
11
27
 
12
28
  .code-block { position: relative; min-width: 0; }
@@ -18,7 +34,7 @@
18
34
  padding: 10px 12px;
19
35
  border: 1px solid var(--line);
20
36
  border-radius: 10px;
21
- background: var(--code-bg);
37
+ background: var(--shiki-background);
22
38
  overflow-x: auto;
23
39
  }
24
40
 
@@ -84,33 +100,6 @@
84
100
  .code-tool-button.is-copied .code-copy-icon { display: none; }
85
101
  .code-tool-button.is-copied .code-check-icon { display: block; }
86
102
 
87
- /* highlight.js tokens use palette tokens, so dark, forest, and sand stay legible. */
88
- .code-block .hljs { color: var(--ink); }
89
- .code-block .hljs-comment,
90
- .code-block .hljs-quote { color: var(--code-comment); font-style: italic; }
91
- .code-block .hljs-keyword,
92
- .code-block .hljs-selector-tag,
93
- .code-block .hljs-literal,
94
- .code-block .hljs-section,
95
- .code-block .hljs-doctag { color: var(--code-keyword); font-weight: 650; }
96
- .code-block .hljs-string,
97
- .code-block .hljs-regexp,
98
- .code-block .hljs-addition,
99
- .code-block .hljs-template-tag,
100
- .code-block .hljs-template-variable { color: var(--code-string); }
101
- .code-block .hljs-number,
102
- .code-block .hljs-symbol,
103
- .code-block .hljs-bullet,
104
- .code-block .hljs-built_in,
105
- .code-block .hljs-type { color: var(--code-number); }
106
- .code-block .hljs-title,
107
- .code-block .hljs-title.function_,
108
- .code-block .hljs-title.class_,
109
- .code-block .hljs-attr,
110
- .code-block .hljs-attribute,
111
- .code-block .hljs-property,
112
- .code-block .hljs-selector-class,
113
- .code-block .hljs-selector-id { color: var(--code-title); }
114
- .code-block .hljs-deletion { color: var(--danger); }
115
- .code-block .hljs-emphasis { font-style: italic; }
116
- .code-block .hljs-strong { font-weight: 700; }
103
+ /* Shiki tokens use palette variables, so dark, forest, and sand stay legible. */
104
+ .code-block .shiki { color: var(--shiki-foreground); }
105
+ .code-block .shiki [style*="--shiki-token-comment"] { font-style: italic; }
@@ -282,6 +282,7 @@
282
282
  .message-copy:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
283
283
  .message-copy-feedback { position: absolute; z-index: 25; left: 0; bottom: calc(100% + 5px); width: max-content; max-width: min(260px, calc(100vw - 32px)); padding: 6px 9px; border: 1px solid var(--line); border-radius: 8px; color: var(--ink); background: var(--surface); box-shadow: var(--shadow); font-size: 11px; font-weight: 500; line-height: 1.4; text-align: left; white-space: normal; overflow-wrap: anywhere; }
284
284
  .message-actions { display: flex; align-items: center; gap: 2px; }
285
+ .forward-targets { display: grid; gap: 8px; }
285
286
  .message-reply { display: grid; place-items: center; width: 32px; height: 32px; padding: 0; border: 1px solid transparent; border-radius: 8px; color: var(--ink-3); background: transparent; cursor: pointer; }
286
287
  .message-reply-icon { display: block; width: 16px; height: 16px; }
287
288
  .message-reply:hover, .message-reply:focus-visible { border-color: var(--line); color: var(--accent); background: var(--accent-soft); }
@@ -326,7 +327,8 @@
326
327
  .resource-name { min-width: 0; overflow-wrap: anywhere; font-weight: 600; }
327
328
  .resource-size, .resource-status { color: var(--ink-3); font-size: 12px; }
328
329
  .resource-status { margin: 0; }
329
- .resource-button { min-height: 34px; }
330
+ .resource-button { display: inline-flex; align-items: center; gap: 6px; min-height: 34px; white-space: nowrap; }
331
+ .resource-button .fluent-icon { width: 16px; height: 16px; }
330
332
  .copy-action { position: relative; display: grid; place-items: center; width: 34px; height: 34px; padding: 0; border: 1px solid transparent; border-radius: 8px; color: var(--ink-3); background: transparent; cursor: pointer; transition: color .12s, border-color .12s, background .12s; }
331
333
  .copy-action svg { width: 16px; height: 16px; }
332
334
  .copy-action:hover { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 24%, transparent); background: var(--accent-soft); }
@@ -336,7 +338,6 @@
336
338
  .copy-action .copy-check { display: none; }
337
339
  .copy-action.is-copied .copy-icon { display: none; }
338
340
  .copy-action.is-copied .copy-check { display: block; }
339
- .resource-copy { border-color: var(--line); background: var(--surface); }
340
341
  .copy-feedback { position: absolute; top: calc(100% + 6px); right: 0; z-index: 6; width: max-content; max-width: 200px; padding: 3px 7px; border-radius: 6px; background: var(--ink); color: var(--surface); font: 600 10.5px/1.35 var(--font-sans); text-align: center; opacity: 0; transform: translateY(-2px); pointer-events: none; transition: opacity .12s ease, transform .12s ease; }
341
342
  .copy-action.is-copied .copy-feedback, .copy-action.is-copy-failed .copy-feedback { opacity: 1; transform: none; }
342
343
  .chat-resource img, .chat-resource video { display: block; max-width: 100%; max-height: 420px; border-radius: 7px; }
@@ -82,7 +82,8 @@
82
82
  }
83
83
  .doc-preview-actions { display: flex; flex: none; align-items: center; gap: 2px; }
84
84
  .doc-preview-copy { width: 36px; height: 36px; }
85
- .doc-preview-download { min-height: 36px; padding: 6px 12px; }
85
+ .doc-preview-download { display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 6px 12px; white-space: nowrap; }
86
+ .doc-preview-download .fluent-icon { width: 16px; height: 16px; }
86
87
  .doc-preview-actions .reader-close { width: 38px; height: 38px; }
87
88
 
88
89
  .doc-preview-scroll {
@@ -42,6 +42,11 @@
42
42
  @media (min-width: 1500px) and (min-height: 560px) {
43
43
  #chatView { --side-pane-width: clamp(380px, 30vw, 640px); }
44
44
  }
45
+ /* Wide task boards use the extra desktop width and leave the chat a 700px column. */
46
+ @media (min-width: 1500px) and (min-height: 900px) {
47
+ #app:has(#chatView.has-tasks) { max-width: 1600px; }
48
+ #chatView.has-tasks { --side-pane-width: min(560px, calc(100% - 960px)); }
49
+ }
45
50
  /* The separator owns one grid column of its own, so it never covers the chat. */
46
51
  .side-pane-handle {
47
52
  display: none;