@alexsun-top/opencode-chat-room 0.7.4 → 0.7.6

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 (63) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/README.md +6 -6
  3. package/README.zh-CN.md +6 -6
  4. package/cli.ts +20 -0
  5. package/dist/cli.js +18 -0
  6. package/package.json +1 -1
  7. package/server/assets/FLUENT-ICONS-LICENSE +25 -0
  8. package/server/assets/NOTICE.txt +2 -1
  9. package/server/assets/attachments.css +1 -1
  10. package/server/assets/base.css +29 -7
  11. package/server/assets/chat/doc-preview.js +113 -0
  12. package/server/assets/chat/events.js +6 -0
  13. package/server/assets/chat/files.js +25 -16
  14. package/server/assets/chat/history-loader.js +36 -26
  15. package/server/assets/chat/icons.js +15 -0
  16. package/server/assets/chat/index.js +3 -1
  17. package/server/assets/chat/locales/de.js +6 -5
  18. package/server/assets/chat/locales/es.js +6 -5
  19. package/server/assets/chat/locales/fr.js +6 -5
  20. package/server/assets/chat/locales/it.js +6 -5
  21. package/server/assets/chat/locales/ja.js +6 -5
  22. package/server/assets/chat/locales/ko.js +6 -5
  23. package/server/assets/chat/markdown.js +17 -37
  24. package/server/assets/chat/messages.js +4 -9
  25. package/server/assets/chat/palette.js +50 -34
  26. package/server/assets/chat/pwa.js +67 -9
  27. package/server/assets/chat/recall.js +3 -2
  28. package/server/assets/chat/replies.js +2 -1
  29. package/server/assets/chat/rooms.js +12 -4
  30. package/server/assets/chat/shortcuts.js +1 -1
  31. package/server/assets/chat/state.js +12 -10
  32. package/server/assets/chat/system-messages.js +7 -1
  33. package/server/assets/code-highlight.css +0 -5
  34. package/server/assets/conversation.css +5 -4
  35. package/server/assets/doc-preview.css +158 -0
  36. package/server/assets/edit-room.css +8 -0
  37. package/server/assets/files.css +0 -15
  38. package/server/assets/fluent-icons.svg +42 -0
  39. package/server/assets/icons.css +9 -0
  40. package/server/assets/palette.css +1 -15
  41. package/server/assets/recall.css +2 -2
  42. package/server/assets/responsive.css +4 -4
  43. package/server/assets/room-create.css +1 -1
  44. package/server/assets/settings.css +13 -6
  45. package/server/chat.html +93 -57
  46. package/server/sw.js +10 -1
  47. package/src/tui/app.mjs +16 -1
  48. package/src/tui/http.mjs +109 -10
  49. package/src/tui/info-app.mjs +435 -0
  50. package/src/tui/info-content.mjs +198 -0
  51. package/src/tui/join-app.mjs +71 -0
  52. package/src/tui/main.mjs +23 -4
  53. package/src/tui/markdown.mjs +269 -0
  54. package/src/tui/message-app.mjs +177 -0
  55. package/src/tui/message-view.mjs +128 -0
  56. package/src/tui/palette-app.mjs +85 -9
  57. package/src/tui/palette.mjs +17 -2
  58. package/src/tui/reminder-app.mjs +189 -0
  59. package/src/tui/room-settings-app.mjs +249 -0
  60. package/src/tui/ui-content.mjs +136 -93
  61. package/src/tui/ui-overlay-view.mjs +255 -0
  62. package/src/tui/ui-view.mjs +2 -190
  63. package/src/tui/ui.mjs +103 -1
@@ -0,0 +1,249 @@
1
+ // Room settings over the shared detail overlay. Reads the room payload and
2
+ // member list, shows owner/admin/successor/management-agent roles, and applies
3
+ // name, description and join-policy patches through api.updateRoom.
4
+ import { roomSettingsMarkdown } from "./info-content.mjs";
5
+ import { createInfoPalette } from "./info-app.mjs";
6
+
7
+ const errorText = (error) => (error instanceof Error ? error.message : String(error ?? "unknown error"));
8
+ const EDIT_HINT = "r rename · d desc · j policy · Esc close";
9
+
10
+ export function attachRoomSettings(Class) {
11
+ Object.assign(Class.prototype, {
12
+ async openRoomSettings() {
13
+ const current = this.state.current;
14
+ if (!current || !this.state.joined) {
15
+ this.state.palette = null;
16
+ this.setStatus("open a joined room first", "error");
17
+ return;
18
+ }
19
+ this.roomSettings = null;
20
+ const palette = {
21
+ ...createInfoPalette("room-settings", "Room settings", `#${current.name}`),
22
+ mode: "detail",
23
+ detail: { title: "Room settings", markdown: "Loading...", kind: "room-settings" },
24
+ hint: "Esc close",
25
+ };
26
+ this.state.palette = palette;
27
+ this.touch();
28
+ try {
29
+ const [room, members] = await Promise.all([
30
+ this.api.getRoom(current.id),
31
+ this.api.members(current.id).catch(() => []),
32
+ ]);
33
+ if (this.state.palette !== palette) return;
34
+ const owner = room.ownerId === this.participant;
35
+ const admin = owner || (room.adminIds ?? []).includes(this.participant);
36
+ const canEdit = Boolean(admin) && typeof this.api.updateRoom === "function";
37
+ const canDelete = owner && typeof this.api.deleteRoom === "function";
38
+ const agent = (members ?? []).find((member) => member.sessionID === room.adminSessionID);
39
+ this.roomSettings = { room, canEdit, canDelete };
40
+ palette.roomMeta = room;
41
+ palette.detail = {
42
+ title: "Room settings",
43
+ markdown: roomSettingsMarkdown(room, {
44
+ participant: this.participant,
45
+ sessionID: this.sessionID,
46
+ canEdit,
47
+ agentName: agent ? `${agent.name} (agent)` : "",
48
+ }),
49
+ kind: "room-settings",
50
+ };
51
+ palette.hint = canEdit ? EDIT_HINT : "Read-only · Esc close";
52
+ if (canDelete) {
53
+ palette.hint = canEdit
54
+ ? "r rename · d desc · j policy · x delete · Esc close"
55
+ : "x delete room · Esc close";
56
+ }
57
+ palette.error = "";
58
+ this.touch();
59
+ } catch (error) {
60
+ if (this.state.palette !== palette) return;
61
+ this.roomSettings = null;
62
+ palette.detail = { title: "Room settings", markdown: `**Unable to load room settings**\n\n${errorText(error)}`, kind: "room-settings" };
63
+ palette.error = errorText(error);
64
+ palette.hint = "Esc close";
65
+ this.touch();
66
+ }
67
+ },
68
+
69
+ roomSettingsGuard() {
70
+ const palette = this.state.palette;
71
+ const settings = this.roomSettings;
72
+ if (
73
+ palette?.kind !== "room-settings"
74
+ || !settings?.canEdit
75
+ || settings.room.id !== this.state.current?.id
76
+ ) {
77
+ if (palette) {
78
+ palette.error = "only the room owner or an admin can edit these settings";
79
+ this.touch();
80
+ }
81
+ return null;
82
+ }
83
+ return settings;
84
+ },
85
+
86
+ startRoomRename() {
87
+ const settings = this.roomSettingsGuard();
88
+ const palette = this.state.palette;
89
+ if (!settings || !palette) return;
90
+ palette.mode = "prompt";
91
+ palette.prompt = { label: "Room name", value: settings.room.name, action: "room-name", data: {} };
92
+ palette.error = "";
93
+ palette.hint = "Enter save · Esc cancel";
94
+ this.touch();
95
+ },
96
+
97
+ startRoomDescription() {
98
+ const settings = this.roomSettingsGuard();
99
+ const palette = this.state.palette;
100
+ if (!settings || !palette) return;
101
+ palette.mode = "prompt";
102
+ palette.prompt = {
103
+ label: "Room description",
104
+ value: settings.room.description ?? "",
105
+ action: "room-description",
106
+ data: {},
107
+ };
108
+ palette.error = "";
109
+ palette.hint = "Enter save · empty clears · Esc cancel";
110
+ this.touch();
111
+ },
112
+
113
+ askRoomJoinPolicy() {
114
+ const settings = this.roomSettingsGuard();
115
+ const palette = this.state.palette;
116
+ if (!settings || !palette) return;
117
+ const next = settings.room.joinPolicy === "approval" ? "open" : "approval";
118
+ palette.mode = "confirm";
119
+ palette.previous = { mode: "detail", hint: palette.hint };
120
+ palette.confirm = {
121
+ text: `Set join policy to ${next}?`,
122
+ action: "room-join-policy",
123
+ data: { joinPolicy: next },
124
+ };
125
+ palette.error = "";
126
+ palette.hint = "Enter or y applies · n or Esc cancels";
127
+ this.touch();
128
+ },
129
+
130
+ askDeleteRoom() {
131
+ const settings = this.roomSettings;
132
+ const palette = this.state.palette;
133
+ const current = this.state.current?.id;
134
+ if (
135
+ !settings?.canDelete
136
+ || !palette
137
+ || settings.room.id !== current
138
+ || palette.kind !== "room-settings"
139
+ ) {
140
+ if (palette) {
141
+ palette.error = "only the room owner can delete the room";
142
+ this.touch();
143
+ }
144
+ return;
145
+ }
146
+ palette.mode = "confirm";
147
+ palette.previous = { mode: "detail", hint: palette.hint };
148
+ palette.confirm = {
149
+ text: `Delete #${settings.room.name} and its messages? This cannot be undone.`,
150
+ action: "room-delete",
151
+ data: { id: settings.room.id, name: settings.room.name },
152
+ };
153
+ palette.error = "";
154
+ palette.hint = "Enter or y deletes · n or Esc cancels";
155
+ this.touch();
156
+ },
157
+
158
+ async submitRoomSettingsPrompt(prompt, value) {
159
+ const settings = this.roomSettingsGuard();
160
+ const palette = this.state.palette;
161
+ if (!settings || !palette) return;
162
+ if (prompt.action === "room-name") {
163
+ const name = String(value ?? "").trim();
164
+ if (!name || Array.from(name).length > 64) {
165
+ palette.error = "room name must contain 1 to 64 characters";
166
+ this.touch();
167
+ return;
168
+ }
169
+ await this.applyRoomPatch({ name }, `renamed to ${name}`);
170
+ return;
171
+ }
172
+ if (prompt.action === "room-description") {
173
+ const description = String(value ?? "").trim();
174
+ if (Array.from(description).length > 2000) {
175
+ palette.error = "description is limited to 2000 characters";
176
+ this.touch();
177
+ return;
178
+ }
179
+ await this.applyRoomPatch({ description }, "description updated");
180
+ }
181
+ },
182
+
183
+ async applyRoomPatch(patch, status) {
184
+ const settings = this.roomSettingsGuard();
185
+ const palette = this.state.palette;
186
+ if (!settings || !palette) return;
187
+ palette.searching = true;
188
+ palette.error = "";
189
+ this.touch();
190
+ try {
191
+ const result = await this.api.updateRoom(settings.room.id, this.sessionID, patch);
192
+ if (patch.name) {
193
+ const name = String(result?.name ?? patch.name);
194
+ this.state.current.name = name;
195
+ const summary = this.state.rooms.find((item) => item.id === settings.room.id);
196
+ if (summary) summary.name = name;
197
+ }
198
+ this.setStatus(status, "success");
199
+ await this.openRoomSettings();
200
+ } catch (error) {
201
+ if (this.state.palette === palette) {
202
+ palette.searching = false;
203
+ palette.error = errorText(error);
204
+ this.touch();
205
+ }
206
+ }
207
+ },
208
+
209
+ async runRoomSettingsConfirm(confirm) {
210
+ if (confirm.action === "room-delete") {
211
+ const palette = this.state.palette;
212
+ const settings = this.roomSettings;
213
+ if (
214
+ !palette
215
+ || !settings?.canDelete
216
+ || settings.room.id !== this.state.current?.id
217
+ || settings.room.id !== confirm.data.id
218
+ ) return;
219
+ palette.searching = true;
220
+ palette.error = "";
221
+ this.touch();
222
+ try {
223
+ await this.api.deleteRoom(confirm.data.id, this.sessionID);
224
+ this.stopPolling();
225
+ this.state.rooms = this.state.rooms.filter((room) => room.id !== confirm.data.id);
226
+ this.state.current = null;
227
+ this.state.joined = false;
228
+ this.state.messages = [];
229
+ this.state.pending = null;
230
+ this.state.selected = Math.min(this.state.selected, Math.max(0, this.state.rooms.length - 1));
231
+ this.closePalette();
232
+ this.setStatus(`deleted #${confirm.data.name}`, "success");
233
+ } catch (error) {
234
+ if (this.state.palette === palette) {
235
+ palette.searching = false;
236
+ palette.error = errorText(error);
237
+ this.touch();
238
+ }
239
+ }
240
+ return;
241
+ }
242
+ if (confirm.action !== "room-join-policy") return;
243
+ await this.applyRoomPatch(
244
+ { joinPolicy: confirm.data.joinPolicy },
245
+ `join policy set to ${confirm.data.joinPolicy}`,
246
+ );
247
+ },
248
+ });
249
+ }
@@ -1,19 +1,15 @@
1
1
  // State-to-renderable syncing for the OpenTUI view. These functions rebuild
2
2
  // message and room rows only when their signature changes.
3
- import {
4
- BoxRenderable,
5
- StyledText,
6
- TextRenderable,
7
- bold,
8
- dim,
9
- fg,
10
- italic,
11
- } from "@opentui/core";
3
+ import { BoxRenderable, StyledText, TextRenderable, bold, fg } from "@opentui/core";
12
4
  import { formatMessage, messageStamp, sanitizeText } from "./messages.mjs";
5
+ import { addNotice, buildMessageBlock, hashText, markdownStyle } from "./message-view.mjs";
13
6
  import { connectionStyle } from "./ui-theme.mjs";
14
7
 
15
8
  const clear = (container) => {
16
- for (const child of container.getChildren()) container.remove(child.id);
9
+ for (const child of container.getChildren()) {
10
+ container.remove(child.id);
11
+ child.destroyRecursively?.();
12
+ }
17
13
  };
18
14
 
19
15
  const plural = (count, word) => `${count} ${word}${count === 1 ? "" : "s"}`;
@@ -163,23 +159,6 @@ export function syncRooms(ui, state) {
163
159
  updateRoomStyles(ui, state);
164
160
  }
165
161
 
166
- function messageChunks(ui, message, info) {
167
- const { theme } = ui;
168
- const chunks = [];
169
- const highlighted = message.id === ui.app.state.highlight;
170
- if (highlighted) chunks.push(bold(fg(theme.accent)("▸ ")));
171
- if (info.question) chunks.push(bold(fg(theme.warning)("? ")));
172
- chunks.push(dim(`${info.time} `));
173
- const own = message.senderId === ui.app.state.participant;
174
- chunks.push(bold(fg(own ? theme.accent : theme.text)(info.sender)));
175
- return chunks;
176
- }
177
-
178
- function messageBody(ui, info) {
179
- if (info.recalled) return new StyledText([dim(italic(info.body))]);
180
- return new StyledText([fg(ui.theme.text)(info.body)]);
181
- }
182
-
183
162
  export function syncMessages(ui, state) {
184
163
  const { current, pending, joined, messages, highlight } = state;
185
164
  const messageKey = messages
@@ -201,20 +180,29 @@ export function syncMessages(ui, state) {
201
180
  const wasAtBottom = ui.scrollBox.scrollHeight - ui.scrollBox.scrollTop - ui.scrollBox.viewport.height < 2;
202
181
  ui.messageSignature = signature;
203
182
 
204
- clear(ui.messageContent);
205
183
  ui.pendingScrollTo = null;
206
184
  ui.pendingBottom = false;
207
185
 
208
186
  if (pending && pending.roomId === current?.id) {
187
+ clear(ui.messageContent);
188
+ ui.messageBlocks = [];
209
189
  addNotice(ui, "pending", sanitizeText(pending.message), ui.theme.warning);
210
190
  addNotice(ui, "pending-wait", "Waiting for approval...", ui.theme.muted);
211
191
  } else if (!current) {
192
+ clear(ui.messageContent);
193
+ ui.messageBlocks = [];
212
194
  addNotice(ui, "empty", "Select a room and press Enter.", ui.theme.muted);
213
195
  } else if (!joined) {
196
+ clear(ui.messageContent);
197
+ ui.messageBlocks = [];
214
198
  addNotice(ui, "empty", "Not joined · press Enter to join again.", ui.theme.muted);
215
199
  } else if (!messages.length) {
200
+ clear(ui.messageContent);
201
+ ui.messageBlocks = [];
216
202
  addNotice(ui, "empty", "No messages yet. Say hello.", ui.theme.muted);
217
203
  } else {
204
+ if (!ui.messageBlocks.length && ui.messageContent.getChildren().length) clear(ui.messageContent);
205
+ const nextBlocks = [];
218
206
  messages.forEach((message, index) => {
219
207
  const info = formatMessage(message, current);
220
208
  const previous = messages[index - 1];
@@ -222,33 +210,37 @@ export function syncMessages(ui, state) {
222
210
  ? previous.senderId !== message.senderId || messageStamp(message) - messageStamp(previous) > 300000
223
211
  : false;
224
212
  const highlighted = message.id === highlight;
225
- const block = new BoxRenderable(ui.renderer, {
226
- id: `message-${message.id}`,
227
- width: "100%",
228
- flexDirection: "column",
229
- flexShrink: 0,
230
- marginTop: index === 0 || gap ? 1 : 0,
231
- });
232
- block.add(new TextRenderable(ui.renderer, {
233
- id: `message-head-${message.id}`,
234
- width: "100%",
235
- height: 1,
236
- wrapMode: "none",
237
- truncate: true,
238
- content: new StyledText(messageChunks(ui, message, info)),
239
- }));
240
- block.add(new TextRenderable(ui.renderer, {
241
- id: `message-body-${message.id}`,
242
- width: "100%",
243
- flexShrink: 0,
244
- wrapMode: "word",
245
- marginLeft: 2,
246
- paddingRight: 1,
247
- bg: highlighted ? ui.theme.raised : undefined,
248
- content: messageBody(ui, info),
249
- }));
250
- ui.messageContent.add(block);
213
+ const key = [
214
+ ui.theme.mode,
215
+ current.id,
216
+ message.id,
217
+ message.recalledAt ? 1 : 0,
218
+ message.isQuestion ? 1 : 0,
219
+ message.senderId,
220
+ message.createdAt,
221
+ highlighted ? 1 : 0,
222
+ hashText(info.body),
223
+ ].join("|");
224
+ const existing = ui.messageBlocks[index];
225
+ let block;
226
+ if (existing?.key === key) {
227
+ block = existing.block;
228
+ block.marginTop = index === 0 || gap ? 1 : 0;
229
+ } else {
230
+ if (existing) {
231
+ ui.messageContent.remove(existing.block.id);
232
+ existing.block.destroyRecursively();
233
+ }
234
+ block = buildMessageBlock(ui, message, info, highlighted, index === 0 || gap ? 1 : 0);
235
+ ui.messageContent.add(block, index);
236
+ }
237
+ nextBlocks.push({ key, block });
251
238
  });
239
+ for (const stale of ui.messageBlocks.slice(messages.length)) {
240
+ ui.messageContent.remove(stale.block.id);
241
+ stale.block.destroyRecursively();
242
+ }
243
+ ui.messageBlocks = nextBlocks;
252
244
  if (highlight) ui.pendingScrollTo = `message-${highlight}`;
253
245
  else if (wasAtBottom) ui.pendingBottom = true;
254
246
  }
@@ -258,16 +250,6 @@ export function syncMessages(ui, state) {
258
250
  }
259
251
  }
260
252
 
261
- function addNotice(ui, id, text, color) {
262
- ui.messageContent.add(new TextRenderable(ui.renderer, {
263
- id: `message-${id}`,
264
- width: "100%",
265
- flexShrink: 0,
266
- wrapMode: "char",
267
- content: new StyledText([fg(color)(sanitizeText(text))]),
268
- }));
269
- }
270
-
271
253
  export function syncComposer(ui, state) {
272
254
  const draft = String(state.draft ?? "");
273
255
  ui.textarea.placeholderColor = ui.theme.faint;
@@ -304,13 +286,19 @@ export function syncStatus(ui, state) {
304
286
 
305
287
  export function syncFocus(ui, state) {
306
288
  const target = state.palette ? "palette" : state.help ? "help" : state.focus === "composer" ? "composer" : "rooms";
289
+ const paletteInput = Boolean(state.palette) && ["commands", "search", "prompt"].includes(state.palette.mode);
307
290
  if (target !== ui.focusKey) {
308
291
  if (ui.focusKey === "composer") ui.textarea.blur();
309
292
  if (ui.focusKey === "palette") ui.paletteInput.blur();
310
293
  if (target === "composer") ui.textarea.focus();
311
- if (target === "palette") ui.paletteInput.focus();
294
+ if (target === "palette" && paletteInput) ui.paletteInput.focus();
312
295
  ui.focusKey = target;
313
296
  }
297
+ if (ui.paletteInputMode !== paletteInput) {
298
+ if (paletteInput) ui.paletteInput.focus();
299
+ else ui.paletteInput.blur();
300
+ ui.paletteInputMode = paletteInput;
301
+ }
314
302
  const accent = target === "composer";
315
303
  ui.composer.borderColor = accent ? ui.theme.accent : ui.theme.border;
316
304
  ui.prompt.fg = accent ? ui.theme.accent : ui.theme.muted;
@@ -320,7 +308,16 @@ export function syncPalette(ui, state) {
320
308
  const { theme, paletteBox } = ui;
321
309
  const palette = state.palette;
322
310
  paletteBox.visible = Boolean(palette);
323
- if (!palette) return;
311
+ if (!palette) {
312
+ ui.detailSignature = "";
313
+ return;
314
+ }
315
+
316
+ const mode = palette.mode;
317
+ const isInput = mode === "commands" || mode === "search" || mode === "prompt";
318
+ const isList = mode === "commands" || mode === "search" || mode === "info";
319
+ const isDetail = mode === "detail";
320
+ const isConfirm = mode === "confirm";
324
321
 
325
322
  paletteBox.backgroundColor = theme.surface;
326
323
  paletteBox.borderColor = theme.accent;
@@ -328,6 +325,10 @@ export function syncPalette(ui, state) {
328
325
  ui.paletteTitle.fg = theme.text;
329
326
  ui.paletteScope.fg = theme.muted;
330
327
  ui.palettePrompt.fg = theme.accent;
328
+ ui.paletteInputRow.visible = isInput;
329
+ ui.paletteList.visible = isList;
330
+ ui.paletteDetailScroll.visible = isDetail;
331
+ ui.paletteConfirm.visible = isConfirm;
331
332
  ui.paletteInput.placeholderColor = theme.faint;
332
333
  ui.paletteInput.textColor = theme.text;
333
334
  ui.paletteInput.focusedTextColor = theme.text;
@@ -337,15 +338,21 @@ export function syncPalette(ui, state) {
337
338
  ui.paletteList.selectedTextColor = theme.selectedFg;
338
339
 
339
340
  const scope = palette.scope === "all" ? "all joined rooms" : "this room";
340
- ui.paletteTitle.content = palette.mode === "prompt" ? "New room" : palette.mode === "search" ? "Search messages" : "Palette";
341
- ui.paletteScope.content = palette.mode === "prompt" ? "create" : palette.mode === "search" ? scope : "commands";
342
- ui.paletteInput.placeholder = palette.mode === "prompt"
343
- ? "Room name"
344
- : palette.mode === "search"
341
+ const defaultTitle = mode === "prompt"
342
+ ? "New room"
343
+ : mode === "search"
344
+ ? "Search messages"
345
+ : "Palette";
346
+ ui.paletteTitle.content = palette.title || defaultTitle;
347
+ ui.paletteScope.content = palette.subtitle
348
+ || (mode === "prompt" ? "create" : mode === "search" ? scope : "commands");
349
+ ui.paletteInput.placeholder = mode === "prompt"
350
+ ? palette.prompt?.label || "Enter a value"
351
+ : mode === "search"
345
352
  ? "Type to search messages"
346
353
  : "Type to search or run a command";
347
354
 
348
- const value = palette.mode === "prompt" ? palette.prompt?.value ?? "" : palette.query;
355
+ const value = mode === "prompt" ? palette.prompt?.value ?? "" : palette.query ?? "";
349
356
  if (ui.paletteInput.value !== value) {
350
357
  ui.syncingPalette = true;
351
358
  try {
@@ -355,33 +362,68 @@ export function syncPalette(ui, state) {
355
362
  }
356
363
  }
357
364
 
358
- let options;
359
- if (palette.mode === "commands") {
365
+ let options = [];
366
+ if (mode === "commands") {
360
367
  options = ui.app.paletteCommands().map((command) => ({ name: command.label, description: "", value: command.id }));
361
- } else if (palette.mode === "prompt") {
362
- options = [{ name: "Enter creates the room", description: "", value: "" }];
363
- } else if (!palette.results.length) {
364
- options = [{ name: palette.searching ? "Searching..." : "No matches", description: "", value: "" }];
365
- } else {
366
- options = palette.results.map((result) => {
367
- const info = formatMessage(result.message, null);
368
- return {
369
- name: `${sanitizeText(result.roomName)} ${info.time} ${info.sender} ${sanitizeText(result.snippet)}`,
370
- description: "",
371
- value: result.message.id,
372
- };
373
- });
368
+ } else if (mode === "search") {
369
+ options = !palette.results.length
370
+ ? [{ name: palette.searching ? "Searching..." : "No matches", description: "", value: "" }]
371
+ : palette.results.map((result) => {
372
+ const info = formatMessage(result.message, null);
373
+ return {
374
+ name: `${sanitizeText(result.roomName)} ${info.time} ${info.sender} ${sanitizeText(result.snippet)}`,
375
+ description: "",
376
+ value: result.message.id,
377
+ };
378
+ });
379
+ } else if (mode === "info") {
380
+ options = palette.loading
381
+ ? [{ name: "Loading...", description: "", value: "" }]
382
+ : palette.items.length
383
+ ? palette.items.map((item) => ({ name: item.name, description: "", value: item.value }))
384
+ : [{ name: palette.error ? "Unavailable" : "Nothing here", description: "", value: "" }];
374
385
  }
375
386
  ui.paletteList.options = options;
376
- ui.paletteList.setSelectedIndex(Math.min(palette.selected, Math.max(0, options.length - 1)));
387
+ if (isList) ui.paletteList.setSelectedIndex(Math.min(palette.selected ?? 0, Math.max(0, options.length - 1)));
388
+
389
+ let desiredHeight;
390
+ if (mode === "commands" || mode === "info") {
391
+ desiredHeight = Math.min(ui.renderer.height - 2, Math.max(9, options.length + 5));
392
+ } else if (isDetail) {
393
+ desiredHeight = Math.min(ui.renderer.height - 2, Math.max(12, Math.floor(ui.renderer.height * 0.8)));
394
+ } else if (isConfirm) {
395
+ desiredHeight = Math.min(9, Math.max(6, ui.renderer.height - 4));
396
+ } else {
397
+ desiredHeight = Math.min(16, Math.max(9, Math.floor(ui.renderer.height / 2) + 1));
398
+ }
399
+ if (paletteBox.height !== desiredHeight) paletteBox.height = desiredHeight;
400
+
401
+ ui.paletteDetailMarkdown.syntaxStyle = markdownStyle(ui);
402
+ ui.paletteDetailMarkdown.fg = theme.text;
403
+ if (isDetail) {
404
+ const signature = `${theme.mode}:${palette.detail?.title}:${palette.detail?.markdown}`;
405
+ if (signature !== ui.detailSignature) {
406
+ ui.detailSignature = signature;
407
+ ui.paletteDetailMarkdown.content = palette.detail?.markdown ?? "";
408
+ ui.paletteDetailScroll.scrollTop = 0;
409
+ }
410
+ }
411
+ if (isConfirm) {
412
+ ui.paletteConfirm.content = ` ${palette.confirm?.text ?? ""}`;
413
+ ui.paletteConfirm.fg = theme.warning;
414
+ }
377
415
 
378
416
  const footer = palette.error
379
- || (palette.mode === "prompt"
380
- ? "Enter create · Esc close"
381
- : palette.mode === "search"
417
+ || (mode === "prompt"
418
+ ? palette.hint || "Enter confirm · Esc cancel"
419
+ : mode === "search"
382
420
  ? `↑↓ select · Enter open · Tab: ${palette.scope === "all" ? "this room" : "all rooms"} · Esc close${palette.searching ? " · searching..." : ""}`
383
- : "↑↓ select · Enter run · Esc close");
384
- ui.paletteHint.content = ` ${sanitizeText(footer)}`;
421
+ : mode === "detail"
422
+ ? palette.hint || "↑↓ scroll · Esc back"
423
+ : mode === "confirm"
424
+ ? palette.hint || "Enter or y confirms · n or Esc cancels"
425
+ : palette.hint || (mode === "info" ? "↑↓ select · Enter open · Esc close" : "↑↓ select · Enter run · Esc close"));
426
+ ui.paletteHint.content = ` ${sanitizeText(footer)}${palette.searching && mode !== "search" ? " · working..." : ""}`;
385
427
  ui.paletteHint.fg = palette.error ? theme.error : theme.muted;
386
428
  }
387
429
 
@@ -419,6 +461,7 @@ export function syncHelp(ui, state) {
419
461
  ["Enter", "send message"],
420
462
  ["Ctrl+J", "insert newline"],
421
463
  ["Esc", "clear / blur"],
464
+ ["/", "commands (empty composer)"],
422
465
  ["Alt+Space", "palette / search"],
423
466
  ["Ctrl+R", "refresh rooms"],
424
467
  ["Ctrl+C", "quit"],