@alexsun-top/opencode-chat-room 0.7.5 → 0.7.7

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 (68) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/README.md +5 -5
  3. package/README.zh-CN.md +5 -5
  4. package/cli.ts +20 -0
  5. package/dist/cli.js +753 -164
  6. package/package.json +2 -1
  7. package/plugin.ts +15 -3
  8. package/server/assets/base.css +0 -2
  9. package/server/assets/chat/doc-preview.js +122 -0
  10. package/server/assets/chat/editor.js +10 -7
  11. package/server/assets/chat/events.js +7 -1
  12. package/server/assets/chat/files.js +14 -6
  13. package/server/assets/chat/index.js +4 -0
  14. package/server/assets/chat/locales/de.js +21 -3
  15. package/server/assets/chat/locales/es.js +21 -3
  16. package/server/assets/chat/locales/fr.js +21 -3
  17. package/server/assets/chat/locales/it.js +21 -3
  18. package/server/assets/chat/locales/ja.js +21 -3
  19. package/server/assets/chat/locales/ko.js +21 -3
  20. package/server/assets/chat/markdown.js +39 -5
  21. package/server/assets/chat/messages.js +1 -0
  22. package/server/assets/chat/palette.js +18 -9
  23. package/server/assets/chat/questions.js +1 -0
  24. package/server/assets/chat/rooms.js +6 -1
  25. package/server/assets/chat/shortcuts.js +14 -3
  26. package/server/assets/chat/state.js +42 -6
  27. package/server/assets/chat/system-messages.js +9 -1
  28. package/server/assets/chat/task-form.js +197 -0
  29. package/server/assets/chat/task-row.js +169 -0
  30. package/server/assets/chat/tasks.js +494 -0
  31. package/server/assets/doc-preview.css +158 -0
  32. package/server/assets/edit-room.css +8 -0
  33. package/server/assets/responsive.css +26 -1
  34. package/server/assets/settings.css +9 -2
  35. package/server/assets/tasks.css +422 -0
  36. package/server/chat.html +129 -33
  37. package/server/member-routes.ts +3 -0
  38. package/server/sw.js +13 -2
  39. package/server/task-routes.ts +53 -0
  40. package/skills/chatroom/SKILL.md +3 -1
  41. package/src/README.md +3 -3
  42. package/src/agent/task-tool.ts +155 -0
  43. package/src/center/center-client.ts +44 -0
  44. package/src/rooms/tasks.ts +246 -0
  45. package/src/runtime/v2-plugin.ts +11 -2
  46. package/src/state/sqlite-state.ts +67 -0
  47. package/src/tui/app.mjs +21 -4
  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 +293 -0
  54. package/src/tui/mentions.mjs +218 -0
  55. package/src/tui/message-app.mjs +178 -0
  56. package/src/tui/message-view.mjs +128 -0
  57. package/src/tui/palette-app.mjs +91 -8
  58. package/src/tui/palette.mjs +17 -2
  59. package/src/tui/reminder-app.mjs +189 -0
  60. package/src/tui/room-settings-app.mjs +249 -0
  61. package/src/tui/ui-content.mjs +144 -94
  62. package/src/tui/ui-mentions.mjs +44 -0
  63. package/src/tui/ui-overlay-view.mjs +255 -0
  64. package/src/tui/ui-suggest-view.mjs +63 -0
  65. package/src/tui/ui-suggest.mjs +197 -0
  66. package/src/tui/ui-theme.mjs +2 -1
  67. package/src/tui/ui-view.mjs +4 -190
  68. package/src/tui/ui.mjs +111 -1
@@ -4,9 +4,10 @@
4
4
  const SEARCH_LIMIT = 50;
5
5
 
6
6
  export function filterCommands(commands, query) {
7
- const needle = String(query ?? "").trim().toLowerCase();
7
+ const normalize = (value) => String(value ?? "").trim().toLowerCase().replace(/[-_]+/g, " ");
8
+ const needle = normalize(query);
8
9
  if (!needle) return commands.slice();
9
- return commands.filter((command) => command.label.toLowerCase().includes(needle));
10
+ return commands.filter((command) => normalize(command.label).includes(needle));
10
11
  }
11
12
 
12
13
  /** Commands shown when the palette query is empty. */
@@ -25,6 +26,20 @@ export function buildCommands({ rooms = [], current = null, joined = false, help
25
26
  }
26
27
  commands.push({ id: "search-room", label: "Search this room" });
27
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" });
28
43
  return commands;
29
44
  }
30
45
 
@@ -0,0 +1,189 @@
1
+ // Reminder management on top of the shared palette overlay: list, create,
2
+ // pause/resume, edit text and delete. Schedule parsing stays pure in
3
+ // info-content.mjs so errors can be tested without a renderer.
4
+ import { parseReminderSchedule, reminderRows } from "./info-content.mjs";
5
+ import { sanitizeText } from "./messages.mjs";
6
+
7
+ 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
+
10
+ function promptScheduleLabel() {
11
+ return 'Schedule: once 2026-11-23T09:00 or cron 0 9 * * *';
12
+ }
13
+
14
+ export function attachReminders(Class) {
15
+ Object.assign(Class.prototype, {
16
+ openReminders() {
17
+ return this.openInfo("reminders", "Reminders", REMINDER_HINT, async (room) =>
18
+ reminderRows(await this.api.reminders(room.id, this.sessionID)));
19
+ },
20
+
21
+ reminderPalette() {
22
+ const palette = this.state.palette;
23
+ return palette?.mode === "info" && palette.kind === "reminders" ? palette : null;
24
+ },
25
+
26
+ selectedReminder() {
27
+ const palette = this.reminderPalette();
28
+ return palette ? this.paletteItems()[palette.selected] : null;
29
+ },
30
+
31
+ startReminderCreate() {
32
+ const palette = this.reminderPalette();
33
+ if (!palette) return;
34
+ palette.mode = "prompt";
35
+ palette.error = "";
36
+ palette.prompt = { label: "Reminder text", value: "", action: "reminder-text", data: {} };
37
+ palette.hint = "Enter next · Esc cancel";
38
+ this.touch();
39
+ },
40
+
41
+ startReminderEdit() {
42
+ const palette = this.reminderPalette();
43
+ const reminder = this.selectedReminder();
44
+ if (!palette || !reminder) return;
45
+ palette.mode = "prompt";
46
+ palette.error = "";
47
+ palette.prompt = {
48
+ label: "Reminder text",
49
+ value: reminder.text,
50
+ action: "reminder-edit-text",
51
+ data: { id: reminder.value },
52
+ };
53
+ palette.hint = "Enter save · Esc cancel";
54
+ this.touch();
55
+ },
56
+
57
+ async toggleReminder() {
58
+ const palette = this.reminderPalette();
59
+ const reminder = this.selectedReminder();
60
+ const room = this.state.current;
61
+ if (!palette || !reminder || !room) return;
62
+ palette.searching = true;
63
+ palette.error = "";
64
+ this.touch();
65
+ try {
66
+ await this.api.updateReminder(room.id, reminder.value, this.sessionID, { paused: !reminder.paused });
67
+ this.setStatus(`${reminder.paused ? "resumed" : "paused"} reminder`, "success");
68
+ await this.openReminders();
69
+ } catch (error) {
70
+ if (this.state.palette === palette) {
71
+ palette.searching = false;
72
+ palette.error = errorText(error);
73
+ this.touch();
74
+ }
75
+ }
76
+ },
77
+
78
+ askDeleteReminder() {
79
+ const palette = this.reminderPalette();
80
+ const reminder = this.selectedReminder();
81
+ if (!palette || !reminder) return;
82
+ palette.mode = "confirm";
83
+ palette.error = "";
84
+ palette.previous = { mode: "info", hint: palette.hint };
85
+ palette.confirm = {
86
+ text: `Delete reminder "${sanitizeText(reminder.text).slice(0, 50)}"?`,
87
+ action: "reminder-delete",
88
+ data: { id: reminder.value },
89
+ };
90
+ palette.hint = "Enter or y deletes · n or Esc cancels";
91
+ this.touch();
92
+ },
93
+
94
+ async submitReminderPrompt(prompt, value) {
95
+ const palette = this.state.palette;
96
+ const room = this.state.current;
97
+ if (!palette || palette.mode !== "prompt") return;
98
+ if (!room) {
99
+ palette.error = "open a joined room first";
100
+ this.touch();
101
+ return;
102
+ }
103
+ if (prompt.action === "reminder-text") {
104
+ const text = String(value ?? "").trim();
105
+ if (!text) {
106
+ palette.error = "reminder text is required";
107
+ this.touch();
108
+ return;
109
+ }
110
+ palette.prompt = {
111
+ label: promptScheduleLabel(),
112
+ value: "",
113
+ action: "reminder-schedule",
114
+ data: { text },
115
+ };
116
+ palette.hint = "once ISO datetime or cron 5 fields · Enter create";
117
+ palette.error = "";
118
+ this.touch();
119
+ return;
120
+ }
121
+ if (prompt.action === "reminder-schedule") {
122
+ let schedule;
123
+ try {
124
+ schedule = parseReminderSchedule(value);
125
+ } catch (error) {
126
+ palette.error = errorText(error);
127
+ this.touch();
128
+ return;
129
+ }
130
+ palette.searching = true;
131
+ palette.error = "";
132
+ this.touch();
133
+ try {
134
+ await this.api.createReminder(room.id, this.sessionID, prompt.data.text, schedule);
135
+ this.setStatus("reminder created", "success");
136
+ await this.openReminders();
137
+ } catch (error) {
138
+ if (this.state.palette === palette) {
139
+ palette.searching = false;
140
+ palette.error = errorText(error);
141
+ this.touch();
142
+ }
143
+ }
144
+ return;
145
+ }
146
+ if (prompt.action === "reminder-edit-text") {
147
+ const text = String(value ?? "").trim();
148
+ if (!text) {
149
+ palette.error = "reminder text is required";
150
+ this.touch();
151
+ return;
152
+ }
153
+ palette.searching = true;
154
+ palette.error = "";
155
+ this.touch();
156
+ try {
157
+ await this.api.updateReminder(room.id, prompt.data.id, this.sessionID, { text });
158
+ this.setStatus("reminder updated", "success");
159
+ await this.openReminders();
160
+ } catch (error) {
161
+ if (this.state.palette === palette) {
162
+ palette.searching = false;
163
+ palette.error = errorText(error);
164
+ this.touch();
165
+ }
166
+ }
167
+ }
168
+ },
169
+
170
+ async runReminderConfirm(confirm) {
171
+ const palette = this.state.palette;
172
+ const room = this.state.current;
173
+ if (!palette || !room) return;
174
+ palette.searching = true;
175
+ this.touch();
176
+ try {
177
+ await this.api.deleteReminder(room.id, confirm.data.id, this.sessionID);
178
+ this.setStatus("reminder deleted", "success");
179
+ await this.openReminders();
180
+ } catch (error) {
181
+ if (this.state.palette === palette) {
182
+ palette.searching = false;
183
+ palette.error = errorText(error);
184
+ this.touch();
185
+ }
186
+ }
187
+ },
188
+ });
189
+ }
@@ -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
+ }