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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (161) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/LICENSE +2 -2
  3. package/README.md +38 -6
  4. package/README.zh-CN.md +38 -6
  5. package/cli.ts +27 -1
  6. package/dist/cli.js +5074 -3212
  7. package/package.json +23 -3
  8. package/packages/chat-room-channeld/README.md +98 -25
  9. package/packages/chat-room-channeld/dist/feishu-adapter.js +912 -149
  10. package/packages/chat-room-channeld/src/adapter.ts +36 -2
  11. package/packages/chat-room-channeld/src/config.ts +63 -1
  12. package/packages/chat-room-channeld/src/delivery.ts +6 -1
  13. package/packages/chat-room-channeld/src/feishu-adapter.ts +122 -292
  14. package/packages/chat-room-channeld/src/feishu-card.ts +27 -0
  15. package/packages/chat-room-channeld/src/feishu-inbound.ts +158 -0
  16. package/packages/chat-room-channeld/src/feishu-live.ts +355 -0
  17. package/packages/chat-room-channeld/src/feishu-send.ts +342 -0
  18. package/packages/chat-room-channeld/src/feishu-ws-frames.ts +173 -0
  19. package/packages/chat-room-channeld/src/host-helpers.ts +11 -0
  20. package/packages/chat-room-channeld/src/host.ts +120 -2
  21. package/packages/chat-room-channeld/src/inbound.ts +26 -0
  22. package/packages/chat-room-channeld/src/state.ts +17 -0
  23. package/packages/chat-room-channeld/src/stats.ts +43 -1
  24. package/server/admin-state.ts +13 -13
  25. package/server/app.ts +95 -0
  26. package/server/assets/NOTICE.txt +2 -1
  27. package/server/assets/base.css +15 -9
  28. package/server/assets/chat/announcements.js +70 -7
  29. package/server/assets/chat/doc-preview.js +184 -35
  30. package/server/assets/chat/events.js +3 -0
  31. package/server/assets/chat/files.js +46 -4
  32. package/server/assets/chat/index.js +2 -0
  33. package/server/assets/chat/integration-editor.js +163 -0
  34. package/server/assets/chat/integration-values.js +124 -0
  35. package/server/assets/chat/integrations.js +498 -0
  36. package/server/assets/chat/locales/de.js +40 -4
  37. package/server/assets/chat/locales/es.js +40 -4
  38. package/server/assets/chat/locales/fr.js +40 -4
  39. package/server/assets/chat/locales/it.js +40 -4
  40. package/server/assets/chat/locales/ja.js +40 -4
  41. package/server/assets/chat/locales/ko.js +40 -4
  42. package/server/assets/chat/markdown.js +22 -8
  43. package/server/assets/chat/messages.js +5 -5
  44. package/server/assets/chat/office-preview.js +69 -0
  45. package/server/assets/chat/panels.js +36 -0
  46. package/server/assets/chat/recall.js +58 -7
  47. package/server/assets/chat/receipts.js +15 -3
  48. package/server/assets/chat/reminders.js +69 -8
  49. package/server/assets/chat/resource-format.js +11 -0
  50. package/server/assets/chat/settings.js +30 -2
  51. package/server/assets/chat/side-pane.js +1 -2
  52. package/server/assets/chat/state.js +93 -10
  53. package/server/assets/chat/system-events.js +32 -0
  54. package/server/assets/chat/system-messages.js +23 -14
  55. package/server/assets/chat/task-row.js +0 -6
  56. package/server/assets/chat/tasks.js +121 -33
  57. package/server/assets/code-highlight.css +55 -32
  58. package/server/assets/conversation.css +123 -23
  59. package/server/assets/doc-preview.css +35 -3
  60. package/server/assets/files.css +5 -0
  61. package/server/assets/fluent-icons.svg +2 -0
  62. package/server/assets/monaco/LICENSE +21 -0
  63. package/server/assets/monaco/ThirdPartyNotices.txt +448 -0
  64. package/server/assets/monaco/codicon-jdswhhtn.ttf +0 -0
  65. package/server/assets/monaco/editor.worker.js +45 -0
  66. package/server/assets/monaco/integration-rules.css +1 -0
  67. package/server/assets/monaco/integration-rules.js +1297 -0
  68. package/server/assets/monaco/json.worker.js +77 -0
  69. package/server/assets/office/THIRD-PARTY-NOTICES.txt +11 -0
  70. package/server/assets/office/docx.bundle.js +33 -0
  71. package/server/assets/office/licenses/docx-preview-LICENSE.txt +201 -0
  72. package/server/assets/office/licenses/echarts-LICENSE.txt +222 -0
  73. package/server/assets/office/licenses/jszip-LICENSE.txt +651 -0
  74. package/server/assets/office/licenses/lodash-LICENSE.txt +47 -0
  75. package/server/assets/office/licenses/pptx-preview-LICENSE.txt +8 -0
  76. package/server/assets/office/licenses/tslib-LICENSE.txt +12 -0
  77. package/server/assets/office/licenses/uuid-LICENSE.txt +9 -0
  78. package/server/assets/office/licenses/xlsx-LICENSE.txt +201 -0
  79. package/server/assets/office/licenses/zrender-LICENSE.txt +29 -0
  80. package/server/assets/office/pptx.bundle.js +104 -0
  81. package/server/assets/office/xlsx.bundle.js +141 -0
  82. package/server/assets/recall.css +5 -4
  83. package/server/assets/responsive.css +50 -11
  84. package/server/assets/settings.css +73 -1
  85. package/server/assets/tasks.css +57 -7
  86. package/server/channel-integration.ts +519 -0
  87. package/server/channel-settings.ts +77 -0
  88. package/server/channels.ts +261 -18
  89. package/server/chat-server.ts +32 -580
  90. package/server/chat.html +187 -21
  91. package/server/http-server.ts +3 -182
  92. package/server/resource-routes.ts +16 -16
  93. package/server/routes/inbox.ts +100 -0
  94. package/server/routes/pages.ts +83 -0
  95. package/server/routes/questions.ts +39 -0
  96. package/server/routes/room-actions.ts +162 -0
  97. package/server/routes/rooms.ts +160 -0
  98. package/server/startup.ts +84 -0
  99. package/server/sw.js +4 -0
  100. package/server/task-routes.ts +1 -1
  101. package/src/center/center-client.ts +2 -10
  102. package/src/config/file-config.ts +7 -54
  103. package/src/platform/http-server.ts +182 -0
  104. package/src/protocol/addressing.ts +21 -0
  105. package/src/protocol/config.ts +58 -0
  106. package/src/protocol/room.ts +51 -0
  107. package/src/rooms/resources.ts +26 -16
  108. package/src/rooms/room-service.ts +2 -48
  109. package/src/rooms/storage.ts +329 -0
  110. package/src/rooms/tasks.ts +21 -5
  111. package/src/runtime/watch.ts +1 -1
  112. package/src/state/pg-database.ts +183 -0
  113. package/src/state/pg-migrate.ts +175 -0
  114. package/src/state/pg-sql.mjs +175 -0
  115. package/src/state/pg-worker.mjs +148 -0
  116. package/src/state/sqlite-announcements.ts +25 -0
  117. package/src/state/sqlite-database.ts +121 -0
  118. package/src/state/sqlite-legacy.ts +90 -0
  119. package/src/state/sqlite-members.ts +155 -0
  120. package/src/state/sqlite-messages.ts +288 -0
  121. package/src/state/sqlite-resources.ts +39 -0
  122. package/src/state/sqlite-rooms.ts +87 -0
  123. package/src/state/sqlite-schema.ts +80 -0
  124. package/src/state/sqlite-state-store.ts +33 -0
  125. package/src/state/sqlite-state.ts +15 -897
  126. package/src/state/sqlite-tasks.ts +65 -0
  127. package/src/state/sqlite-transaction.ts +13 -0
  128. package/src/state/sqlite.ts +21 -1
  129. package/src/state/store.ts +5 -1
  130. package/src/tui/app.mjs +32 -19
  131. package/src/tui/config.mjs +12 -4
  132. package/src/tui/i18n.mjs +38 -0
  133. package/src/tui/info-app.mjs +50 -51
  134. package/src/tui/info-content.mjs +79 -44
  135. package/src/tui/join-app.mjs +9 -9
  136. package/src/tui/locales/en.mjs +349 -0
  137. package/src/tui/locales/zh-CN.mjs +349 -0
  138. package/src/tui/main.mjs +85 -37
  139. package/src/tui/markdown.mjs +3 -2
  140. package/src/tui/mentions.mjs +3 -1
  141. package/src/tui/message-app.mjs +22 -21
  142. package/src/tui/message-view.mjs +2 -1
  143. package/src/tui/palette-app.mjs +9 -8
  144. package/src/tui/palette.mjs +30 -24
  145. package/src/tui/prefs.mjs +92 -0
  146. package/src/tui/reminder-app.mjs +18 -17
  147. package/src/tui/room-settings-app.mjs +30 -28
  148. package/src/tui/settings-app.mjs +153 -0
  149. package/src/tui/ui-content.mjs +65 -86
  150. package/src/tui/ui-help.mjs +73 -0
  151. package/src/tui/ui-overlay-view.mjs +23 -7
  152. package/src/tui/ui-suggest.mjs +6 -5
  153. package/src/tui/ui-theme.mjs +37 -33
  154. package/src/tui/ui-view.mjs +22 -7
  155. package/src/tui/ui.mjs +15 -3
  156. package/src/web/editor.worker.ts +1 -0
  157. package/src/web/integration-rules-editor.ts +439 -0
  158. package/src/web/integration-rules.ts +22 -0
  159. package/src/web/integration-schema.ts +228 -0
  160. package/src/web/json.worker.ts +1 -0
  161. package/src/web/office-viewer.ts +221 -0
@@ -2,6 +2,7 @@
2
2
  // confirmation, and a prompt-based reply flow that uses api.send's replyTo.
3
3
  import { mergeMessages } from "./messages.mjs";
4
4
  import { canonicalizeMentions } from "./mentions.mjs";
5
+ import { t } from "./i18n.mjs";
5
6
 
6
7
  const errorText = (error) => (error instanceof Error ? error.message : String(error ?? "unknown error"));
7
8
 
@@ -11,7 +12,7 @@ export function attachMessageActions(Class) {
11
12
  const palette = this.state.palette;
12
13
  if (!palette || !this.state.current || !this.state.joined) {
13
14
  this.state.palette = null;
14
- this.setStatus("open a joined room first", "error");
15
+ this.setStatus(t("info.joinFirst"), "error");
15
16
  return null;
16
17
  }
17
18
  palette.mode = "prompt";
@@ -21,25 +22,25 @@ export function attachMessageActions(Class) {
21
22
  palette.subtitle = `#${this.state.current.name}`;
22
23
  palette.error = "";
23
24
  palette.prompt = { label, value: "", action, data };
24
- palette.hint = "Enter next · Esc cancel";
25
+ palette.hint = t("palette.enterNextHint");
25
26
  this.touch();
26
27
  return palette;
27
28
  },
28
29
 
29
30
  startMessageRecall() {
30
- return this.messageActionPalette("Recall message", "Message ID to recall", "message-recall-id");
31
+ return this.messageActionPalette(t("message.recallTitle"), t("message.recallPrompt"), "message-recall-id");
31
32
  },
32
33
 
33
34
  startMessageReveal() {
34
- return this.messageActionPalette("Reveal message", "Message ID to reveal", "message-reveal-id");
35
+ return this.messageActionPalette(t("message.revealTitle"), t("message.revealPrompt"), "message-reveal-id");
35
36
  },
36
37
 
37
38
  startMessageReply() {
38
- return this.messageActionPalette("Reply", "Message ID to reply to", "message-reply-id");
39
+ return this.messageActionPalette(t("message.replyTitle"), t("message.replyPrompt"), "message-reply-id");
39
40
  },
40
41
 
41
42
  startAskQuestion() {
42
- return this.messageActionPalette("Ask question", "Question text", "message-ask");
43
+ return this.messageActionPalette(t("message.askTitle"), t("message.askPrompt"), "message-ask");
43
44
  },
44
45
 
45
46
  async submitMessagePrompt(prompt, value) {
@@ -48,14 +49,14 @@ export function attachMessageActions(Class) {
48
49
  const participants = palette?.roomParticipants || this.state.current?.participants;
49
50
  if (!palette || palette.mode !== "prompt") return;
50
51
  if (!roomId) {
51
- palette.error = "open a joined room first";
52
+ palette.error = t("info.joinFirst");
52
53
  this.touch();
53
54
  return;
54
55
  }
55
56
  if (prompt.action === "message-ask") {
56
57
  const question = canonicalizeMentions(String(value ?? "").trim(), participants);
57
58
  if (!question) {
58
- palette.error = "question text is required";
59
+ palette.error = t("message.questionRequired");
59
60
  this.touch();
60
61
  return;
61
62
  }
@@ -68,7 +69,7 @@ export function attachMessageActions(Class) {
68
69
  else if (result?.id) mergeMessages(this.state.messages, [result]);
69
70
  this.state.connection = "online";
70
71
  this.closePalette();
71
- this.setStatus("question sent", "success");
72
+ this.setStatus(t("message.questionSent"), "success");
72
73
  this.markRead();
73
74
  } catch (error) {
74
75
  if (this.state.palette === palette) {
@@ -81,7 +82,7 @@ export function attachMessageActions(Class) {
81
82
  }
82
83
  const id = String(value ?? "").trim();
83
84
  if (!id) {
84
- palette.error = "message ID is required";
85
+ palette.error = t("message.idRequired");
85
86
  this.touch();
86
87
  return;
87
88
  }
@@ -90,23 +91,23 @@ export function attachMessageActions(Class) {
90
91
  palette.mode = "confirm";
91
92
  palette.previous = { mode: "prompt", hint: palette.hint };
92
93
  palette.confirm = {
93
- text: recall ? `Recall message "${id}"?` : `Reveal the original text of "${id}"?`,
94
+ text: recall ? t("message.recallConfirm", { id }) : t("message.revealConfirm", { id }),
94
95
  action: recall ? "message-recall" : "message-reveal",
95
96
  data: { id },
96
97
  };
97
- palette.hint = "Enter or y confirms · n or Esc cancels";
98
+ palette.hint = t("palette.confirmHint");
98
99
  palette.error = "";
99
100
  this.touch();
100
101
  return;
101
102
  }
102
103
  if (prompt.action === "message-reply-id") {
103
104
  palette.prompt = {
104
- label: `Reply to ${id}`,
105
+ label: t("message.replyLabel", { id }),
105
106
  value: "",
106
107
  action: "message-reply-text",
107
108
  data: { id },
108
109
  };
109
- palette.hint = "Enter send · Esc cancel";
110
+ palette.hint = t("message.replyHint");
110
111
  palette.error = "";
111
112
  this.touch();
112
113
  return;
@@ -114,7 +115,7 @@ export function attachMessageActions(Class) {
114
115
  if (prompt.action === "message-reply-text") {
115
116
  const text = canonicalizeMentions(String(value ?? "").trim(), participants);
116
117
  if (!text) {
117
- palette.error = "reply text is required";
118
+ palette.error = t("message.replyRequired");
118
119
  this.touch();
119
120
  return;
120
121
  }
@@ -128,7 +129,7 @@ export function attachMessageActions(Class) {
128
129
  else if (result?.id) mergeMessages(this.state.messages, [result]);
129
130
  this.state.connection = "online";
130
131
  this.closePalette();
131
- this.setStatus("reply sent", "success");
132
+ this.setStatus(t("message.replySent"), "success");
132
133
  this.markRead();
133
134
  } catch (error) {
134
135
  if (this.state.palette === palette) {
@@ -154,19 +155,19 @@ export function attachMessageActions(Class) {
154
155
  const target = this.state.messages.find((message) => message.id === id);
155
156
  if (target) target.recalledAt = Date.now();
156
157
  this.closePalette();
157
- this.setStatus(`recalled ${id}`, "success");
158
+ this.setStatus(t("message.recalledStatus", { id }), "success");
158
159
  return;
159
160
  }
160
161
  const revealed = await this.api.reveal(roomId, id, this.sessionID);
161
162
  palette.mode = "detail";
162
- palette.title = "Revealed message";
163
+ palette.title = t("message.revealed");
163
164
  palette.confirm = null;
164
165
  palette.detail = {
165
- title: "Revealed message",
166
- markdown: String(revealed?.text ?? "(empty)"),
166
+ title: t("message.revealed"),
167
+ markdown: String(revealed?.text ?? t("message.empty")),
167
168
  kind: "revealed-message",
168
169
  };
169
- palette.hint = "Esc close";
170
+ palette.hint = t("palette.closeHint");
170
171
  palette.searching = false;
171
172
  this.touch();
172
173
  } catch (error) {
@@ -18,6 +18,7 @@ import {
18
18
  formatAttachments,
19
19
  prepareMarkdown,
20
20
  } from "./markdown.mjs";
21
+ import { t } from "./i18n.mjs";
21
22
 
22
23
  let treeSitter;
23
24
  const treeClient = () => (treeSitter ??= getTreeSitterClient());
@@ -67,7 +68,7 @@ function messageBody(ui, message, info, highlighted) {
67
68
  id: `message-recalled-${message.id}`,
68
69
  width: "100%",
69
70
  wrapMode: "word",
70
- content: new StyledText([dim(italic("[recalled]"))]),
71
+ content: new StyledText([dim(italic(t("chat.recalled")))]),
71
72
  }));
72
73
  return body;
73
74
  }
@@ -2,6 +2,7 @@
2
2
  // terminal core stays under the project line budget.
3
3
  import { buildCommands, filterCommands, nextScope, scopeSources, searchMessages } from "./palette.mjs";
4
4
  import { mergeMessages, oldestSeq } from "./messages.mjs";
5
+ import { t } from "./i18n.mjs";
5
6
 
6
7
  const SEARCH_PAGES = 2;
7
8
 
@@ -93,7 +94,7 @@ export function attachPalette(Class) {
93
94
  // A failed page must not consume the room's search budget.
94
95
  this.historyPages.set(room.id, (this.historyPages.get(room.id) ?? 0) + 1);
95
96
  } catch (error) {
96
- if (this.state.palette === palette) palette.error = `history: ${error.message ?? error}`;
97
+ if (this.state.palette === palette) palette.error = t("palette.historyError", { error: error.message ?? error });
97
98
  } finally {
98
99
  this.historyInflight.delete(room.id);
99
100
  }
@@ -168,7 +169,7 @@ export function attachPalette(Class) {
168
169
  return;
169
170
  case "new-room":
170
171
  palette.mode = "prompt";
171
- palette.prompt = { label: "New room name", value: "", action: "new-room", data: {} };
172
+ palette.prompt = { label: t("palette.newRoomPrompt"), value: "", action: "new-room", data: {} };
172
173
  palette.selected = 0;
173
174
  palette.error = "";
174
175
  this.touch();
@@ -213,7 +214,7 @@ export function attachPalette(Class) {
213
214
  await this.openReminders();
214
215
  return;
215
216
  case "settings":
216
- this.openSettings();
217
+ this.openSettingsEditor();
217
218
  return;
218
219
  case "room-settings":
219
220
  await this.openRoomSettings();
@@ -260,7 +261,7 @@ export function attachPalette(Class) {
260
261
  const palette = this.state.palette;
261
262
  const name = String(palette?.prompt?.value ?? "").trim();
262
263
  if (!name) {
263
- palette.error = "enter a room name";
264
+ palette.error = t("palette.enterRoomName");
264
265
  this.touch();
265
266
  return;
266
267
  }
@@ -274,7 +275,7 @@ export function attachPalette(Class) {
274
275
  const index = this.state.rooms.findIndex((room) => room.id === roomID);
275
276
  this.closePalette();
276
277
  if (index >= 0) await this.openRoom(index);
277
- else this.setStatus(`created #${name}`, "success");
278
+ else this.setStatus(t("palette.created", { name }), "success");
278
279
  } catch (error) {
279
280
  if (this.state.palette) {
280
281
  this.state.palette.searching = false;
@@ -287,7 +288,7 @@ export function attachPalette(Class) {
287
288
  async leaveCurrent() {
288
289
  const room = this.state.current;
289
290
  if (!room || !this.state.joined) {
290
- this.setStatus("not joined to a room", "error");
291
+ this.setStatus(t("palette.notJoined"), "error");
291
292
  return;
292
293
  }
293
294
  try {
@@ -297,9 +298,9 @@ export function attachPalette(Class) {
297
298
  const summary = this.state.rooms.find((item) => item.id === room.id);
298
299
  if (summary) summary.joined = false;
299
300
  await this.refreshRooms(true);
300
- this.setStatus(`left #${room.name}`, "success");
301
+ this.setStatus(t("palette.left", { name: room.name }), "success");
301
302
  } catch (error) {
302
- this.setStatus(`could not leave: ${error.message ?? error}`, "error");
303
+ this.setStatus(t("palette.leaveFailed", { error: error.message ?? error }), "error");
303
304
  }
304
305
  },
305
306
 
@@ -1,45 +1,51 @@
1
1
  // Pure command palette logic: command lists, scoped client-side search,
2
2
  // ranking and snippets. No I/O lives here so it is easy to test.
3
+ import { t } from "./i18n.mjs";
3
4
 
4
5
  const SEARCH_LIMIT = 50;
5
6
 
7
+ /** Match the visible label plus optional search aliases such as exit/quit. */
6
8
  export function filterCommands(commands, query) {
7
- const normalize = (value) => String(value ?? "").trim().toLowerCase().replace(/[-_]+/g, " ");
9
+ const normalize = (value) => String(value ?? "").trim().toLowerCase()
10
+ .replace(/^[/\\]+/, "").replace(/[-_]+/g, " ");
8
11
  const needle = normalize(query);
9
12
  if (!needle) return commands.slice();
10
- return commands.filter((command) => normalize(command.label).includes(needle));
13
+ return commands.filter((command) => {
14
+ const haystack = normalize([command.label, ...(command.keywords ?? [])].join(" "));
15
+ return haystack.includes(needle);
16
+ });
11
17
  }
12
18
 
13
19
  /** Commands shown when the palette query is empty. */
14
20
  export function buildCommands({ rooms = [], current = null, joined = false, help = false } = {}) {
15
21
  const commands = [
16
- { id: "refresh", label: "Refresh rooms" },
17
- { id: "new-room", label: "New room..." },
22
+ { id: "refresh", label: t("command.refresh") },
23
+ { id: "new-room", label: t("command.newRoom") },
18
24
  ];
19
25
  for (const room of rooms) {
20
- if (!room.joined) commands.push({ id: `join:${room.id}`, label: `Join #${room.name}`, roomId: room.id });
26
+ if (!room.joined) commands.push({ id: `join:${room.id}`, label: t("command.join", { name: room.name }), roomId: room.id });
21
27
  }
22
- if (current && joined) commands.push({ id: "leave-room", label: `Leave #${current.name}` });
23
- commands.push({ id: "toggle-help", label: help ? "Hide keyboard help" : "Show keyboard help" });
28
+ if (current && joined) commands.push({ id: "leave-room", label: t("command.leave", { name: current.name }) });
29
+ commands.push({ id: "toggle-help", label: help ? t("command.hideHelp") : t("command.showHelp") });
24
30
  for (const room of rooms) {
25
- if (room.joined) commands.push({ id: `switch:${room.id}`, label: `Switch to #${room.name}`, roomId: room.id });
31
+ if (room.joined) commands.push({ id: `switch:${room.id}`, label: t("command.switch", { name: room.name }), roomId: room.id });
26
32
  }
27
- commands.push({ id: "search-room", label: "Search this room" });
28
- commands.push({ id: "search-all", label: "Search all joined rooms" });
29
- commands.push({ id: "members", label: "Members" });
30
- commands.push({ id: "join-requests", label: "Join requests" });
31
- commands.push({ id: "announcements", label: "Announcements" });
32
- commands.push({ id: "questions", label: "Questions" });
33
- commands.push({ id: "files", label: "Files" });
34
- commands.push({ id: "reminders", label: "Reminders" });
35
- commands.push({ id: "settings", label: "Settings" });
36
- commands.push({ id: "room-settings", label: "Room settings" });
37
- commands.push({ id: "delete-room", label: "Delete room..." });
38
- commands.push({ id: "recall-message", label: "Recall message..." });
39
- commands.push({ id: "reveal-message", label: "Reveal message..." });
40
- commands.push({ id: "reply-message", label: "Reply to message..." });
41
- commands.push({ id: "ask-question", label: "Ask question..." });
42
- commands.push({ id: "quit", label: "Quit" });
33
+ commands.push({ id: "search-room", label: t("command.searchRoom") });
34
+ commands.push({ id: "search-all", label: t("command.searchAll") });
35
+ commands.push({ id: "members", label: t("command.members") });
36
+ commands.push({ id: "join-requests", label: t("command.joinRequests") });
37
+ commands.push({ id: "announcements", label: t("command.announcements") });
38
+ commands.push({ id: "questions", label: t("command.questions") });
39
+ commands.push({ id: "files", label: t("command.files") });
40
+ commands.push({ id: "reminders", label: t("command.reminders") });
41
+ commands.push({ id: "settings", label: t("command.settings") });
42
+ commands.push({ id: "room-settings", label: t("command.roomSettings") });
43
+ commands.push({ id: "delete-room", label: t("command.deleteRoom") });
44
+ commands.push({ id: "recall-message", label: t("command.recall") });
45
+ commands.push({ id: "reveal-message", label: t("command.reveal") });
46
+ commands.push({ id: "reply-message", label: t("command.reply") });
47
+ commands.push({ id: "ask-question", label: t("command.ask") });
48
+ commands.push({ id: "quit", label: t("command.quit"), keywords: ["exit", "quit", "q"] });
43
49
  return commands;
44
50
  }
45
51
 
@@ -0,0 +1,92 @@
1
+ // Persistent TUI preferences in $XDG_CONFIG_HOME/chatroom/tui.json. The file
2
+ // only stores language, theme, participant and url; a server token is never
3
+ // written or accepted from this layer.
4
+ import { randomUUID } from "node:crypto";
5
+ import { mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
6
+ import os from "node:os";
7
+ import path from "node:path";
8
+ import { loadTuiConfig } from "./config.mjs";
9
+ import { DEFAULT_LANGUAGE, normalizeLanguage } from "./i18n.mjs";
10
+
11
+ export const PREFS_FILE_NAME = "tui.json";
12
+ export const DEFAULT_THEME = "dark";
13
+ export const THEMES = ["dark", "light"];
14
+ const LANGUAGE_VALUES = ["en", "zh", "zh-cn", "zh_cn"];
15
+
16
+ export function normalizeTheme(value) {
17
+ return String(value ?? "").trim().toLowerCase() === "light" ? "light" : "dark";
18
+ }
19
+
20
+ export function tuiPrefsFile(env = process.env) {
21
+ const home = env.HOME || os.homedir();
22
+ const configHome = env.XDG_CONFIG_HOME || path.join(home, ".config");
23
+ return path.join(configHome, "chatroom", PREFS_FILE_NAME);
24
+ }
25
+
26
+ /** Keep only known, valid fields; unknown or malformed values are dropped. */
27
+ function cleanPrefs(value) {
28
+ if (!value || typeof value !== "object" || Array.isArray(value)) return {};
29
+ const prefs = {};
30
+ const language = typeof value.language === "string" ? value.language.trim().toLowerCase() : "";
31
+ if (LANGUAGE_VALUES.includes(language)) prefs.language = normalizeLanguage(language);
32
+ const theme = typeof value.theme === "string" ? value.theme.trim().toLowerCase() : "";
33
+ if (THEMES.includes(theme)) prefs.theme = theme;
34
+ if (typeof value.participant === "string" && value.participant.trim()) {
35
+ prefs.participant = value.participant.trim().slice(0, 64);
36
+ }
37
+ if (typeof value.url === "string" && /^https?:\/\/[^/]+/i.test(value.url.trim())) {
38
+ prefs.url = value.url.trim().replace(/\/+$/, "");
39
+ }
40
+ return prefs;
41
+ }
42
+
43
+ /** A missing or malformed file is not an error: it means "no preferences". */
44
+ export function loadTuiPrefs(env = process.env) {
45
+ try {
46
+ const data = JSON.parse(readFileSync(tuiPrefsFile(env), "utf8"));
47
+ return cleanPrefs(data);
48
+ } catch {
49
+ return {};
50
+ }
51
+ }
52
+
53
+ export function saveTuiPrefs(env = process.env, patch = {}) {
54
+ const prefs = cleanPrefs({ ...loadTuiPrefs(env), ...cleanPrefs(patch) });
55
+ const file = tuiPrefsFile(env);
56
+ mkdirSync(path.dirname(file), { recursive: true });
57
+ const temp = `${file}.${process.pid}.${randomUUID()}.tmp`;
58
+ writeFileSync(temp, `${JSON.stringify(prefs, null, 2)}\n`, { mode: 0o600 });
59
+ renameSync(temp, file);
60
+ return prefs;
61
+ }
62
+
63
+ function envValue(env, key) {
64
+ const value = env[key];
65
+ return value === undefined || value === "" ? undefined : value;
66
+ }
67
+
68
+ /** Resolve language and theme: flags > env > tui.json > project config > defaults. */
69
+ export function resolveTuiPreferences(env = process.env, cwd = process.cwd(), flags = {}, sources = {}) {
70
+ const prefs = sources.prefs ?? loadTuiPrefs(env);
71
+ const project = sources.project === undefined ? loadTuiConfig(env, cwd) : sources.project;
72
+ return {
73
+ language: normalizeLanguage(
74
+ flags.language
75
+ ?? envValue(env, "CHAT_ROOM_TUI_LANGUAGE")
76
+ ?? prefs.language
77
+ ?? project?.client?.language
78
+ ?? project?.language
79
+ ?? DEFAULT_LANGUAGE,
80
+ ),
81
+ theme: normalizeTheme(
82
+ flags.theme
83
+ ?? envValue(env, "CHAT_ROOM_TUI_THEME")
84
+ ?? prefs.theme
85
+ ?? project?.client?.theme
86
+ ?? project?.theme
87
+ ?? DEFAULT_THEME,
88
+ ),
89
+ prefs,
90
+ prefsFile: tuiPrefsFile(env),
91
+ };
92
+ }
@@ -3,18 +3,19 @@
3
3
  // info-content.mjs so errors can be tested without a renderer.
4
4
  import { parseReminderSchedule, reminderRows } from "./info-content.mjs";
5
5
  import { sanitizeText } from "./messages.mjs";
6
+ import { t } from "./i18n.mjs";
6
7
 
7
8
  const errorText = (error) => (error instanceof Error ? error.message : String(error ?? "unknown error"));
8
- export const REMINDER_HINT = "n new · p pause/resume · e edit · d delete · Esc close";
9
+ const reminderHint = () => t("reminder.hint");
9
10
 
10
11
  function promptScheduleLabel() {
11
- return 'Schedule: once 2026-11-23T09:00 or cron 0 9 * * *';
12
+ return t("reminder.schedulePrompt");
12
13
  }
13
14
 
14
15
  export function attachReminders(Class) {
15
16
  Object.assign(Class.prototype, {
16
17
  openReminders() {
17
- return this.openInfo("reminders", "Reminders", REMINDER_HINT, async (room) =>
18
+ return this.openInfo("reminders", t("reminder.title"), reminderHint(), async (room) =>
18
19
  reminderRows(await this.api.reminders(room.id, this.sessionID)));
19
20
  },
20
21
 
@@ -37,8 +38,8 @@ export function attachReminders(Class) {
37
38
  if (!palette) return;
38
39
  palette.mode = "prompt";
39
40
  palette.error = "";
40
- palette.prompt = { label: "Reminder text", value: "", action: "reminder-text", data: {} };
41
- palette.hint = "Enter next · Esc cancel";
41
+ palette.prompt = { label: t("reminder.textPrompt"), value: "", action: "reminder-text", data: {} };
42
+ palette.hint = t("palette.enterNextHint");
42
43
  this.touch();
43
44
  },
44
45
 
@@ -49,12 +50,12 @@ export function attachReminders(Class) {
49
50
  palette.mode = "prompt";
50
51
  palette.error = "";
51
52
  palette.prompt = {
52
- label: "Reminder text",
53
+ label: t("reminder.textPrompt"),
53
54
  value: reminder.text,
54
55
  action: "reminder-edit-text",
55
56
  data: { id: reminder.value },
56
57
  };
57
- palette.hint = "Enter save · Esc cancel";
58
+ palette.hint = t("palette.enterSaveHint");
58
59
  this.touch();
59
60
  },
60
61
 
@@ -68,7 +69,7 @@ export function attachReminders(Class) {
68
69
  this.touch();
69
70
  try {
70
71
  await this.api.updateReminder(roomId, reminder.value, this.sessionID, { paused: !reminder.paused });
71
- this.setStatus(`${reminder.paused ? "resumed" : "paused"} reminder`, "success");
72
+ this.setStatus(t(reminder.paused ? "reminder.resumed" : "reminder.paused"), "success");
72
73
  await this.openReminders();
73
74
  } catch (error) {
74
75
  if (this.state.palette === palette) {
@@ -87,11 +88,11 @@ export function attachReminders(Class) {
87
88
  palette.error = "";
88
89
  palette.previous = { mode: "info", hint: palette.hint };
89
90
  palette.confirm = {
90
- text: `Delete reminder "${sanitizeText(reminder.text).slice(0, 50)}"?`,
91
+ text: t("reminder.deleteConfirm", { text: sanitizeText(reminder.text).slice(0, 50) }),
91
92
  action: "reminder-delete",
92
93
  data: { id: reminder.value },
93
94
  };
94
- palette.hint = "Enter or y deletes · n or Esc cancels";
95
+ palette.hint = t("palette.deleteHint");
95
96
  this.touch();
96
97
  },
97
98
 
@@ -100,14 +101,14 @@ export function attachReminders(Class) {
100
101
  const roomId = this.reminderRoomId(palette);
101
102
  if (!palette || palette.mode !== "prompt") return;
102
103
  if (!roomId) {
103
- palette.error = "open a joined room first";
104
+ palette.error = t("info.joinFirst");
104
105
  this.touch();
105
106
  return;
106
107
  }
107
108
  if (prompt.action === "reminder-text") {
108
109
  const text = String(value ?? "").trim();
109
110
  if (!text) {
110
- palette.error = "reminder text is required";
111
+ palette.error = t("reminder.textRequired");
111
112
  this.touch();
112
113
  return;
113
114
  }
@@ -117,7 +118,7 @@ export function attachReminders(Class) {
117
118
  action: "reminder-schedule",
118
119
  data: { text },
119
120
  };
120
- palette.hint = "once ISO datetime or cron 5 fields · Enter create";
121
+ palette.hint = t("reminder.scheduleHint");
121
122
  palette.error = "";
122
123
  this.touch();
123
124
  return;
@@ -136,7 +137,7 @@ export function attachReminders(Class) {
136
137
  this.touch();
137
138
  try {
138
139
  await this.api.createReminder(roomId, this.sessionID, prompt.data.text, schedule);
139
- this.setStatus("reminder created", "success");
140
+ this.setStatus(t("reminder.created"), "success");
140
141
  await this.openReminders();
141
142
  } catch (error) {
142
143
  if (this.state.palette === palette) {
@@ -150,7 +151,7 @@ export function attachReminders(Class) {
150
151
  if (prompt.action === "reminder-edit-text") {
151
152
  const text = String(value ?? "").trim();
152
153
  if (!text) {
153
- palette.error = "reminder text is required";
154
+ palette.error = t("reminder.textRequired");
154
155
  this.touch();
155
156
  return;
156
157
  }
@@ -159,7 +160,7 @@ export function attachReminders(Class) {
159
160
  this.touch();
160
161
  try {
161
162
  await this.api.updateReminder(roomId, prompt.data.id, this.sessionID, { text });
162
- this.setStatus("reminder updated", "success");
163
+ this.setStatus(t("reminder.updated"), "success");
163
164
  await this.openReminders();
164
165
  } catch (error) {
165
166
  if (this.state.palette === palette) {
@@ -179,7 +180,7 @@ export function attachReminders(Class) {
179
180
  this.touch();
180
181
  try {
181
182
  await this.api.deleteReminder(roomId, confirm.data.id, this.sessionID);
182
- this.setStatus("reminder deleted", "success");
183
+ this.setStatus(t("reminder.deleted"), "success");
183
184
  await this.openReminders();
184
185
  } catch (error) {
185
186
  if (this.state.palette === palette) {