@alexsun-top/opencode-chat-room 0.7.6 → 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 (78) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/README.md +5 -5
  3. package/README.zh-CN.md +5 -5
  4. package/dist/cli.js +815 -192
  5. package/package.json +3 -2
  6. package/plugin.ts +15 -3
  7. package/server/assets/base.css +0 -2
  8. package/server/assets/chat/announcements.js +5 -2
  9. package/server/assets/chat/clipboard.js +30 -0
  10. package/server/assets/chat/copy-action.js +48 -0
  11. package/server/assets/chat/diagram-viewer.js +253 -0
  12. package/server/assets/chat/doc-preview.js +160 -13
  13. package/server/assets/chat/editor.js +10 -7
  14. package/server/assets/chat/events.js +26 -5
  15. package/server/assets/chat/files.js +26 -5
  16. package/server/assets/chat/history-loader.js +3 -1
  17. package/server/assets/chat/index.js +11 -1
  18. package/server/assets/chat/join-requests.js +6 -3
  19. package/server/assets/chat/locales/de.js +20 -2
  20. package/server/assets/chat/locales/es.js +20 -2
  21. package/server/assets/chat/locales/fr.js +20 -2
  22. package/server/assets/chat/locales/it.js +20 -2
  23. package/server/assets/chat/locales/ja.js +20 -2
  24. package/server/assets/chat/locales/ko.js +20 -2
  25. package/server/assets/chat/markdown.js +75 -86
  26. package/server/assets/chat/messages.js +7 -3
  27. package/server/assets/chat/palette.js +40 -18
  28. package/server/assets/chat/pwa.js +2 -0
  29. package/server/assets/chat/questions.js +6 -0
  30. package/server/assets/chat/resource-format.js +74 -0
  31. package/server/assets/chat/rooms.js +9 -1
  32. package/server/assets/chat/shortcuts.js +14 -3
  33. package/server/assets/chat/side-pane.js +136 -0
  34. package/server/assets/chat/state.js +85 -8
  35. package/server/assets/chat/system-messages.js +3 -1
  36. package/server/assets/chat/task-form.js +197 -0
  37. package/server/assets/chat/task-row.js +170 -0
  38. package/server/assets/chat/tasks.js +521 -0
  39. package/server/assets/chat/viewport.js +5 -0
  40. package/server/assets/conversation.css +25 -1
  41. package/server/assets/diagram-viewer.css +141 -0
  42. package/server/assets/doc-preview.css +24 -5
  43. package/server/assets/responsive.css +108 -14
  44. package/server/assets/tasks.css +419 -0
  45. package/server/chat-server.ts +9 -4
  46. package/server/chat.html +120 -21
  47. package/server/member-routes.ts +3 -0
  48. package/server/resource-routes.ts +3 -1
  49. package/server/sw.js +247 -4
  50. package/server/task-routes.ts +53 -0
  51. package/skills/chatroom/SKILL.md +3 -1
  52. package/src/README.md +3 -3
  53. package/src/agent/chatroom-skill.ts +8 -2
  54. package/src/agent/task-tool.ts +155 -0
  55. package/src/center/center-client.ts +44 -0
  56. package/src/rooms/resources.ts +2 -2
  57. package/src/rooms/tasks.ts +246 -0
  58. package/src/runtime/v2-plugin.ts +11 -2
  59. package/src/runtime/watch.ts +38 -5
  60. package/src/state/sqlite-state.ts +93 -8
  61. package/src/state/store.ts +2 -2
  62. package/src/tui/app.mjs +14 -4
  63. package/src/tui/http.mjs +2 -2
  64. package/src/tui/info-app.mjs +24 -15
  65. package/src/tui/join-app.mjs +3 -3
  66. package/src/tui/main.mjs +4 -4
  67. package/src/tui/markdown.mjs +31 -5
  68. package/src/tui/mentions.mjs +218 -0
  69. package/src/tui/message-app.mjs +15 -11
  70. package/src/tui/palette-app.mjs +19 -9
  71. package/src/tui/reminder-app.mjs +14 -10
  72. package/src/tui/ui-content.mjs +12 -3
  73. package/src/tui/ui-mentions.mjs +44 -0
  74. package/src/tui/ui-suggest-view.mjs +63 -0
  75. package/src/tui/ui-suggest.mjs +197 -0
  76. package/src/tui/ui-theme.mjs +2 -1
  77. package/src/tui/ui-view.mjs +2 -0
  78. package/src/tui/ui.mjs +17 -9
@@ -0,0 +1,218 @@
1
+ // Mention helpers shared by the composer suggestions and outgoing messages.
2
+ // Display names stay visible while typing; the wire format is applied on send.
3
+ const escapeRegExp = (value) => String(value).replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
4
+
5
+ export function mentionNames(participants = []) {
6
+ const names = [];
7
+ const seen = new Set(["all"]);
8
+ for (const participant of Array.isArray(participants) ? participants : []) {
9
+ const name = String(participant?.name ?? participant?.id ?? "").trim();
10
+ if (!name || seen.has(name.toLowerCase())) continue;
11
+ seen.add(name.toLowerCase());
12
+ names.push(name);
13
+ }
14
+ return names;
15
+ }
16
+
17
+ export function mentionItems(participants, query = "") {
18
+ const needle = String(query ?? "").toLowerCase();
19
+ const items = mentionNames(participants).map((name) => ({
20
+ name,
21
+ insert: `@${name}`,
22
+ label: name,
23
+ }));
24
+ items.push({ name: "all", insert: "@all", label: "Everyone (@all)" });
25
+ return items.filter((item) => {
26
+ const haystack = `${item.label} ${item.name}`.toLowerCase();
27
+ return !needle || haystack.includes(needle);
28
+ });
29
+ }
30
+
31
+ /** Locate the @token at the end of the draft, outside email-like tokens. */
32
+ export function mentionTrigger(text) {
33
+ const source = String(text ?? "");
34
+ const match = source.match(/(^|[^\p{L}\p{N}_@])@([^\n@]{0,64})$/u);
35
+ if (!match) return null;
36
+ const query = match[2];
37
+ return { start: source.length - query.length - 1, query, cursor: source.length };
38
+ }
39
+
40
+ export function insertMention(draft, trigger, insert) {
41
+ const source = String(draft ?? "");
42
+ const at = trigger ?? mentionTrigger(source);
43
+ if (!at) return source;
44
+ const before = source.slice(0, at.start);
45
+ const after = source.slice(at.cursor ?? source.length);
46
+ return `${before}${insert} ${after}`;
47
+ }
48
+
49
+ /** Find a closing backtick run of exactly `length`, never a longer run. */
50
+ function closingBackticks(source, from, end, length) {
51
+ let i = from;
52
+ while (i < end) {
53
+ if (source[i] !== "`") {
54
+ i += 1;
55
+ continue;
56
+ }
57
+ let run = 0;
58
+ while (i + run < end && source[i + run] === "`") run += 1;
59
+ if (run === length) return i;
60
+ i += run;
61
+ }
62
+ return -1;
63
+ }
64
+
65
+ /** Split Markdown prose from fenced/indented code and inline code spans. */
66
+ function codeSegments(source) {
67
+ const segments = [];
68
+ let proseStart = 0;
69
+ let lineStart = 0;
70
+ const push = (start, end, code) => {
71
+ if (end > start) segments.push({ text: source.slice(start, end), code, start, end });
72
+ };
73
+ while (lineStart < source.length) {
74
+ const lineEnd = source.indexOf("\n", lineStart);
75
+ const end = lineEnd < 0 ? source.length : lineEnd;
76
+ const line = source.slice(lineStart, end).replace(/\r$/, "");
77
+ const opener = /^([ \t]*)(`{3,}|~{3,})/.exec(line);
78
+ if (opener) {
79
+ if (lineStart > proseStart) splitInlineCode(source, proseStart, lineStart, segments);
80
+ const fence = opener[2];
81
+ const indent = opener[1].length;
82
+ let scan = lineEnd < 0 ? source.length : lineEnd + 1;
83
+ let closed = source.length;
84
+ while (scan < source.length) {
85
+ const nextEnd = source.indexOf("\n", scan);
86
+ const stop = nextEnd < 0 ? source.length : nextEnd;
87
+ const close = /^([ \t]*)(`{3,}|~{3,})[ \t]*$/.exec(source.slice(scan, stop).replace(/\r$/, ""));
88
+ if (close && close[2][0] === fence[0] && close[2].length >= fence.length
89
+ && close[1].length <= indent + 3) {
90
+ closed = nextEnd < 0 ? source.length : nextEnd + 1;
91
+ break;
92
+ }
93
+ scan = nextEnd < 0 ? source.length : nextEnd + 1;
94
+ }
95
+ push(lineStart, closed, true);
96
+ proseStart = closed;
97
+ lineStart = closed;
98
+ continue;
99
+ }
100
+ // CommonMark indented code is also literal. Treat four spaces/tab as code
101
+ // rather than risking a mention rewrite inside it.
102
+ if (/^(?: {4,}|\t)/.test(line)) {
103
+ if (lineStart > proseStart) splitInlineCode(source, proseStart, lineStart, segments);
104
+ let scan = lineStart;
105
+ let closed = source.length;
106
+ while (scan < source.length) {
107
+ const nextEnd = source.indexOf("\n", scan);
108
+ const stop = nextEnd < 0 ? source.length : nextEnd;
109
+ const current = source.slice(scan, stop).replace(/\r$/, "");
110
+ if (current.trim() && !/^(?: {4,}|\t)/.test(current)) {
111
+ closed = scan;
112
+ break;
113
+ }
114
+ scan = nextEnd < 0 ? source.length : nextEnd + 1;
115
+ }
116
+ push(lineStart, closed, true);
117
+ proseStart = closed;
118
+ lineStart = closed;
119
+ continue;
120
+ }
121
+ lineStart = lineEnd < 0 ? source.length : lineEnd + 1;
122
+ }
123
+ splitInlineCode(source, proseStart, source.length, segments);
124
+ return segments;
125
+ }
126
+
127
+ function splitInlineCode(source, start, end, segments) {
128
+ let prose = start;
129
+ let i = start;
130
+ while (i < end) {
131
+ if (source[i] !== "`") {
132
+ i += 1;
133
+ continue;
134
+ }
135
+ let run = 1;
136
+ while (i + run < end && source[i + run] === "`") run += 1;
137
+ const close = closingBackticks(source, i + run, end, run);
138
+ if (close < 0) {
139
+ i += run;
140
+ continue;
141
+ }
142
+ if (i > prose) segments.push({ text: source.slice(prose, i), code: false, start: prose, end: i });
143
+ segments.push({ text: source.slice(i, close + run), code: true, start: i, end: close + run });
144
+ prose = close + run;
145
+ i = prose;
146
+ }
147
+ if (end > prose) segments.push({ text: source.slice(prose, end), code: false, start: prose, end });
148
+ }
149
+
150
+ function convertPlain(segment, names) {
151
+ if (!segment) return segment;
152
+ const candidates = ["all", ...names].sort((a, b) => b.length - a.length);
153
+ const pattern = new RegExp(
154
+ `(?<![\\p{L}\\p{N}_.@])@(${candidates.map(escapeRegExp).join("|")})(?![\\p{L}\\p{N}_])`,
155
+ "gu",
156
+ );
157
+ return segment.replace(pattern, (_match, name) => `<at>@${name}</at>`);
158
+ }
159
+
160
+ function convertProse(source, names) {
161
+ const tag = /<at>[\s\S]*?<\/at>/giu;
162
+ let output = "";
163
+ let last = 0;
164
+ for (const match of source.matchAll(tag)) {
165
+ output += convertPlain(source.slice(last, match.index), names);
166
+ output += match[0];
167
+ last = match.index + match[0].length;
168
+ }
169
+ return output + convertPlain(source.slice(last), names);
170
+ }
171
+
172
+ /** Convert known @names and @all to <at> tags, preserving code and existing tags. */
173
+ export function canonicalizeMentions(text, participants = []) {
174
+ const source = String(text ?? "");
175
+ const names = mentionNames(participants);
176
+ return codeSegments(source)
177
+ .map((segment) => (segment.code ? segment.text : convertProse(segment.text, names)))
178
+ .join("");
179
+ }
180
+
181
+ /** Character ranges for visible mention chips, excluding email-like tokens. */
182
+ export function mentionRanges(text, participants = []) {
183
+ const source = String(text ?? "");
184
+ const ranges = [];
185
+ const candidates = ["all", ...mentionNames(participants)].sort((a, b) => b.length - a.length);
186
+ const pattern = new RegExp(
187
+ `(?<![\\p{L}\\p{N}_.@])@(${candidates.map(escapeRegExp).join("|")})(?![\\p{L}\\p{N}_])`,
188
+ "gu",
189
+ );
190
+ for (const segment of codeSegments(source)) {
191
+ if (segment.code) continue;
192
+ const tag = /<at>([\s\S]*?)<\/at>/giu;
193
+ let last = 0;
194
+ const plain = [];
195
+ for (const match of segment.text.matchAll(tag)) {
196
+ const inner = match[1];
197
+ const trimmed = inner.trim();
198
+ const at = trimmed.indexOf("@");
199
+ if (at >= 0) {
200
+ const innerStart = segment.start + match.index + 4 + (inner.length - inner.trimStart().length);
201
+ ranges.push({ start: innerStart + at, end: innerStart + trimmed.length });
202
+ }
203
+ plain.push([last, match.index]);
204
+ last = match.index + match[0].length;
205
+ }
206
+ plain.push([last, segment.text.length]);
207
+ for (const [start, end] of plain) {
208
+ const piece = segment.text.slice(start, end);
209
+ for (const match of piece.matchAll(pattern)) {
210
+ ranges.push({
211
+ start: segment.start + start + match.index,
212
+ end: segment.start + start + match.index + match[0].length,
213
+ });
214
+ }
215
+ }
216
+ }
217
+ return ranges.sort((a, b) => a.start - b.start);
218
+ }
@@ -1,6 +1,7 @@
1
1
  // Message actions on top of the palette prompts: recall and reveal by id with
2
2
  // confirmation, and a prompt-based reply flow that uses api.send's replyTo.
3
3
  import { mergeMessages } from "./messages.mjs";
4
+ import { canonicalizeMentions } from "./mentions.mjs";
4
5
 
5
6
  const errorText = (error) => (error instanceof Error ? error.message : String(error ?? "unknown error"));
6
7
 
@@ -14,6 +15,8 @@ export function attachMessageActions(Class) {
14
15
  return null;
15
16
  }
16
17
  palette.mode = "prompt";
18
+ palette.roomId = this.state.current.id;
19
+ palette.roomParticipants = [...(this.state.current.participants || [])];
17
20
  palette.title = title;
18
21
  palette.subtitle = `#${this.state.current.name}`;
19
22
  palette.error = "";
@@ -41,15 +44,16 @@ export function attachMessageActions(Class) {
41
44
 
42
45
  async submitMessagePrompt(prompt, value) {
43
46
  const palette = this.state.palette;
44
- const room = this.state.current;
47
+ const roomId = palette?.roomId || this.state.current?.id;
48
+ const participants = palette?.roomParticipants || this.state.current?.participants;
45
49
  if (!palette || palette.mode !== "prompt") return;
46
- if (!room) {
50
+ if (!roomId) {
47
51
  palette.error = "open a joined room first";
48
52
  this.touch();
49
53
  return;
50
54
  }
51
55
  if (prompt.action === "message-ask") {
52
- const question = String(value ?? "").trim();
56
+ const question = canonicalizeMentions(String(value ?? "").trim(), participants);
53
57
  if (!question) {
54
58
  palette.error = "question text is required";
55
59
  this.touch();
@@ -59,7 +63,7 @@ export function attachMessageActions(Class) {
59
63
  palette.error = "";
60
64
  this.touch();
61
65
  try {
62
- const result = await this.api.send(room.id, this.sessionID, question, { isQuestion: true });
66
+ const result = await this.api.send(roomId, this.sessionID, question, { isQuestion: true });
63
67
  if (Array.isArray(result?.messages)) mergeMessages(this.state.messages, result.messages);
64
68
  else if (result?.id) mergeMessages(this.state.messages, [result]);
65
69
  this.state.connection = "online";
@@ -108,7 +112,7 @@ export function attachMessageActions(Class) {
108
112
  return;
109
113
  }
110
114
  if (prompt.action === "message-reply-text") {
111
- const text = String(value ?? "").trim();
115
+ const text = canonicalizeMentions(String(value ?? "").trim(), participants);
112
116
  if (!text) {
113
117
  palette.error = "reply text is required";
114
118
  this.touch();
@@ -118,8 +122,8 @@ export function attachMessageActions(Class) {
118
122
  palette.error = "";
119
123
  this.touch();
120
124
  try {
121
- const result = await this.api.send(room.id, this.sessionID, text, { replyToMessageID: prompt.data.id });
122
- if (!this.isCurrent(room.id)) return;
125
+ const result = await this.api.send(roomId, this.sessionID, text, { replyToMessageID: prompt.data.id });
126
+ if (!this.isCurrent(roomId)) return;
123
127
  if (Array.isArray(result?.messages)) mergeMessages(this.state.messages, result.messages);
124
128
  else if (result?.id) mergeMessages(this.state.messages, [result]);
125
129
  this.state.connection = "online";
@@ -138,22 +142,22 @@ export function attachMessageActions(Class) {
138
142
 
139
143
  async runMessageConfirm(confirm) {
140
144
  const palette = this.state.palette;
141
- const room = this.state.current;
142
- if (!palette || !room) return;
145
+ const roomId = palette?.roomId || this.state.current?.id;
146
+ if (!palette || !roomId) return;
143
147
  const id = confirm.data.id;
144
148
  palette.searching = true;
145
149
  palette.error = "";
146
150
  this.touch();
147
151
  try {
148
152
  if (confirm.action === "message-recall") {
149
- await this.api.recall(room.id, id, this.sessionID);
153
+ await this.api.recall(roomId, id, this.sessionID);
150
154
  const target = this.state.messages.find((message) => message.id === id);
151
155
  if (target) target.recalledAt = Date.now();
152
156
  this.closePalette();
153
157
  this.setStatus(`recalled ${id}`, "success");
154
158
  return;
155
159
  }
156
- const revealed = await this.api.reveal(room.id, id, this.sessionID);
160
+ const revealed = await this.api.reveal(roomId, id, this.sessionID);
157
161
  palette.mode = "detail";
158
162
  palette.title = "Revealed message";
159
163
  palette.confirm = null;
@@ -10,8 +10,10 @@ export function attachPalette(Class) {
10
10
  openPalette({ slash = false } = {}) {
11
11
  this.historyPages.clear();
12
12
  this.state.help = false;
13
+ // Same rule as the web palette: only "/" means commands; empty input
14
+ // waits for a search query instead of showing a command wall.
13
15
  this.state.palette = {
14
- mode: "commands",
16
+ mode: slash ? "commands" : "search",
15
17
  query: slash ? "/" : "",
16
18
  scope: "room",
17
19
  selected: 0,
@@ -19,6 +21,12 @@ export function attachPalette(Class) {
19
21
  prompt: null,
20
22
  searching: false,
21
23
  error: "",
24
+ commands: buildCommands({
25
+ rooms: this.state.rooms,
26
+ current: this.state.current,
27
+ joined: this.state.joined,
28
+ help: this.state.help,
29
+ }),
22
30
  };
23
31
  this.touch();
24
32
  },
@@ -32,12 +40,13 @@ export function attachPalette(Class) {
32
40
  paletteCommands() {
33
41
  const palette = this.state.palette;
34
42
  const query = palette?.mode === "commands" ? String(palette.query ?? "").replace(/^\s*\//, "") : "";
35
- return filterCommands(buildCommands({
43
+ const commands = palette?.commands ?? buildCommands({
36
44
  rooms: this.state.rooms,
37
45
  current: this.state.current,
38
46
  joined: this.state.joined,
39
47
  help: this.state.help,
40
- }), query);
48
+ });
49
+ return filterCommands(commands, query);
41
50
  },
42
51
 
43
52
  paletteItems() {
@@ -81,16 +90,17 @@ export function attachPalette(Class) {
81
90
  this.historyInflight.add(room.id);
82
91
  try {
83
92
  await this.fetchHistoryPage(room.id);
93
+ // A failed page must not consume the room's search budget.
94
+ this.historyPages.set(room.id, (this.historyPages.get(room.id) ?? 0) + 1);
84
95
  } catch (error) {
85
- if (this.state.palette) this.state.palette.error = `history: ${error.message ?? error}`;
96
+ if (this.state.palette === palette) palette.error = `history: ${error.message ?? error}`;
86
97
  } finally {
87
98
  this.historyInflight.delete(room.id);
88
- this.historyPages.set(room.id, (this.historyPages.get(room.id) ?? 0) + 1);
89
99
  }
90
- if (this.state.palette) this.refreshPaletteResults();
100
+ if (this.state.palette === palette) this.refreshPaletteResults();
91
101
  }
92
- if (this.state.palette) {
93
- this.state.palette.searching = this.historyInflight.size > 0;
102
+ if (this.state.palette === palette) {
103
+ palette.searching = this.historyInflight.size > 0;
94
104
  this.refreshPaletteResults();
95
105
  }
96
106
  },
@@ -299,7 +309,7 @@ export function attachPalette(Class) {
299
309
  const query = String(value ?? "");
300
310
  palette.error = "";
301
311
  if (!query.trim()) {
302
- palette.mode = "commands";
312
+ palette.mode = "search";
303
313
  palette.query = "";
304
314
  palette.results = [];
305
315
  palette.selected = 0;
@@ -23,6 +23,10 @@ export function attachReminders(Class) {
23
23
  return palette?.mode === "info" && palette.kind === "reminders" ? palette : null;
24
24
  },
25
25
 
26
+ reminderRoomId(palette) {
27
+ return palette?.roomId || this.state.current?.id;
28
+ },
29
+
26
30
  selectedReminder() {
27
31
  const palette = this.reminderPalette();
28
32
  return palette ? this.paletteItems()[palette.selected] : null;
@@ -57,13 +61,13 @@ export function attachReminders(Class) {
57
61
  async toggleReminder() {
58
62
  const palette = this.reminderPalette();
59
63
  const reminder = this.selectedReminder();
60
- const room = this.state.current;
61
- if (!palette || !reminder || !room) return;
64
+ const roomId = this.reminderRoomId(palette);
65
+ if (!palette || !reminder || !roomId) return;
62
66
  palette.searching = true;
63
67
  palette.error = "";
64
68
  this.touch();
65
69
  try {
66
- await this.api.updateReminder(room.id, reminder.value, this.sessionID, { paused: !reminder.paused });
70
+ await this.api.updateReminder(roomId, reminder.value, this.sessionID, { paused: !reminder.paused });
67
71
  this.setStatus(`${reminder.paused ? "resumed" : "paused"} reminder`, "success");
68
72
  await this.openReminders();
69
73
  } catch (error) {
@@ -93,9 +97,9 @@ export function attachReminders(Class) {
93
97
 
94
98
  async submitReminderPrompt(prompt, value) {
95
99
  const palette = this.state.palette;
96
- const room = this.state.current;
100
+ const roomId = this.reminderRoomId(palette);
97
101
  if (!palette || palette.mode !== "prompt") return;
98
- if (!room) {
102
+ if (!roomId) {
99
103
  palette.error = "open a joined room first";
100
104
  this.touch();
101
105
  return;
@@ -131,7 +135,7 @@ export function attachReminders(Class) {
131
135
  palette.error = "";
132
136
  this.touch();
133
137
  try {
134
- await this.api.createReminder(room.id, this.sessionID, prompt.data.text, schedule);
138
+ await this.api.createReminder(roomId, this.sessionID, prompt.data.text, schedule);
135
139
  this.setStatus("reminder created", "success");
136
140
  await this.openReminders();
137
141
  } catch (error) {
@@ -154,7 +158,7 @@ export function attachReminders(Class) {
154
158
  palette.error = "";
155
159
  this.touch();
156
160
  try {
157
- await this.api.updateReminder(room.id, prompt.data.id, this.sessionID, { text });
161
+ await this.api.updateReminder(roomId, prompt.data.id, this.sessionID, { text });
158
162
  this.setStatus("reminder updated", "success");
159
163
  await this.openReminders();
160
164
  } catch (error) {
@@ -169,12 +173,12 @@ export function attachReminders(Class) {
169
173
 
170
174
  async runReminderConfirm(confirm) {
171
175
  const palette = this.state.palette;
172
- const room = this.state.current;
173
- if (!palette || !room) return;
176
+ const roomId = this.reminderRoomId(palette);
177
+ if (!palette || !roomId) return;
174
178
  palette.searching = true;
175
179
  this.touch();
176
180
  try {
177
- await this.api.deleteReminder(room.id, confirm.data.id, this.sessionID);
181
+ await this.api.deleteReminder(roomId, confirm.data.id, this.sessionID);
178
182
  this.setStatus("reminder deleted", "success");
179
183
  await this.openReminders();
180
184
  } catch (error) {
@@ -3,6 +3,7 @@
3
3
  import { BoxRenderable, StyledText, TextRenderable, bold, fg } from "@opentui/core";
4
4
  import { formatMessage, messageStamp, sanitizeText } from "./messages.mjs";
5
5
  import { addNotice, buildMessageBlock, hashText, markdownStyle } from "./message-view.mjs";
6
+ import { syncMentionHighlights } from "./ui-mentions.mjs";
6
7
  import { connectionStyle } from "./ui-theme.mjs";
7
8
 
8
9
  const clear = (container) => {
@@ -256,7 +257,10 @@ export function syncComposer(ui, state) {
256
257
  ui.textarea.textColor = ui.theme.text;
257
258
  ui.textarea.focusedTextColor = ui.theme.text;
258
259
  ui.prompt.fg = ui.theme.accent;
259
- if (ui.textarea.plainText === draft) return;
260
+ if (ui.textarea.plainText === draft) {
261
+ syncMentionHighlights(ui, state);
262
+ return;
263
+ }
260
264
  ui.syncingComposer = true;
261
265
  try {
262
266
  ui.textarea.setText(draft);
@@ -266,6 +270,8 @@ export function syncComposer(ui, state) {
266
270
  } finally {
267
271
  ui.syncingComposer = false;
268
272
  }
273
+ ui.mentionSignature = "";
274
+ syncMentionHighlights(ui, state);
269
275
  }
270
276
 
271
277
  export function syncStatus(ui, state) {
@@ -366,7 +372,9 @@ export function syncPalette(ui, state) {
366
372
  if (mode === "commands") {
367
373
  options = ui.app.paletteCommands().map((command) => ({ name: command.label, description: "", value: command.id }));
368
374
  } else if (mode === "search") {
369
- options = !palette.results.length
375
+ options = !String(palette.query ?? "").trim()
376
+ ? [{ name: "Type to search messages", description: "", value: "" }]
377
+ : !palette.results.length
370
378
  ? [{ name: palette.searching ? "Searching..." : "No matches", description: "", value: "" }]
371
379
  : palette.results.map((result) => {
372
380
  const info = formatMessage(result.message, null);
@@ -461,7 +469,8 @@ export function syncHelp(ui, state) {
461
469
  ["Enter", "send message"],
462
470
  ["Ctrl+J", "insert newline"],
463
471
  ["Esc", "clear / blur"],
464
- ["/", "commands (empty composer)"],
472
+ ["/", "inline commands"],
473
+ ["@", "mention members"],
465
474
  ["Alt+Space", "palette / search"],
466
475
  ["Ctrl+R", "refresh rooms"],
467
476
  ["Ctrl+C", "quit"],
@@ -0,0 +1,44 @@
1
+ // Accent-colored mention chips inside the composer. Extmarks keep ranges tied
2
+ // to the text; we rebuild them only when the visible ranges or theme change.
3
+ import { SyntaxStyle } from "@opentui/core";
4
+ import { mentionNames, mentionRanges } from "./mentions.mjs";
5
+
6
+ function styleFor(ui) {
7
+ let style = ui.mentionStyles.get(ui.theme.mode);
8
+ if (!style) {
9
+ style = SyntaxStyle.fromStyles({
10
+ mention: { fg: ui.theme.accent, bold: true },
11
+ });
12
+ ui.mentionStyles.set(ui.theme.mode, style);
13
+ }
14
+ return style;
15
+ }
16
+
17
+ export function syncMentionHighlights(ui, state) {
18
+ const textarea = ui.textarea;
19
+ const text = textarea.plainText;
20
+ const ranges = mentionRanges(text, state.current?.participants);
21
+ const names = mentionNames(state.current?.participants).join(",");
22
+ const signature = `${ui.theme.mode}:${names}:${ranges.map((range) => `${range.start}-${range.end}`).join(",")}`;
23
+ if (signature === ui.mentionSignature) return;
24
+ if (!ranges.length) {
25
+ textarea.extmarks.clear();
26
+ ui.mentionSignature = signature;
27
+ return;
28
+ }
29
+
30
+ const style = styleFor(ui);
31
+ const styleId = style.getStyleId("mention") ?? style.registerStyle("mention", {
32
+ fg: ui.theme.accent,
33
+ bold: true,
34
+ });
35
+ textarea.syntaxStyle = style;
36
+ const extmarks = textarea.extmarks;
37
+ const typeId = ui.mentionTypeId ??= extmarks.registerType("mention");
38
+ extmarks.clear();
39
+ for (const range of ranges) {
40
+ extmarks.create({ start: range.start, end: range.end, styleId, typeId });
41
+ }
42
+ ui.mentionSignature = signature;
43
+ ui.renderer.requestRender();
44
+ }
@@ -0,0 +1,63 @@
1
+ // Compact command/mention suggestions floating just above the composer.
2
+ // Rows are plain renderables so the popup never owns keyboard focus.
3
+ import { BoxRenderable, TextRenderable } from "@opentui/core";
4
+
5
+ export const SUGGEST_LIMIT = 6;
6
+
7
+ export function createSuggestView(renderer, theme, view) {
8
+ view.suggestBox = new BoxRenderable(renderer, {
9
+ id: "suggest",
10
+ position: "absolute",
11
+ left: 1,
12
+ right: 1,
13
+ bottom: 7,
14
+ height: 5,
15
+ zIndex: 80,
16
+ visible: false,
17
+ focusable: false,
18
+ border: true,
19
+ borderStyle: "rounded",
20
+ borderColor: theme.border,
21
+ backgroundColor: theme.surface,
22
+ title: " commands ",
23
+ titleAlignment: "left",
24
+ flexDirection: "column",
25
+ });
26
+ renderer.root.add(view.suggestBox);
27
+
28
+ view.suggestRows = [];
29
+ for (let index = 0; index < SUGGEST_LIMIT; index += 1) {
30
+ const row = new BoxRenderable(renderer, {
31
+ id: `suggest-row-${index}`,
32
+ height: 1,
33
+ flexShrink: 0,
34
+ flexDirection: "row",
35
+ paddingX: 1,
36
+ visible: false,
37
+ });
38
+ const label = new TextRenderable(renderer, {
39
+ id: `suggest-label-${index}`,
40
+ flexGrow: 1,
41
+ height: 1,
42
+ wrapMode: "none",
43
+ truncate: true,
44
+ fg: theme.text,
45
+ content: "",
46
+ });
47
+ row.add(label);
48
+ view.suggestBox.add(row);
49
+ view.suggestRows.push({ row, label });
50
+ }
51
+
52
+ view.suggestHint = new TextRenderable(renderer, {
53
+ id: "suggest-hint",
54
+ height: 1,
55
+ flexShrink: 0,
56
+ truncate: true,
57
+ wrapMode: "none",
58
+ paddingX: 1,
59
+ fg: theme.muted,
60
+ content: "",
61
+ });
62
+ view.suggestBox.add(view.suggestHint);
63
+ }