@alexsun-top/opencode-chat-room 0.5.0 → 0.5.2

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 (54) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/README.md +23 -7
  3. package/README.zh-CN.md +23 -7
  4. package/docs/administrator-rooms.md +51 -0
  5. package/package.json +11 -2
  6. package/plugin.ts +29 -12
  7. package/server/admin-auth.ts +16 -0
  8. package/server/admin-plan-routes.ts +79 -0
  9. package/server/admin-routes.ts +154 -0
  10. package/server/admin-scheduler.ts +42 -0
  11. package/server/admin-state.ts +61 -0
  12. package/server/admin-task-routes.ts +182 -0
  13. package/server/assets/base.css +55 -43
  14. package/server/assets/chat/admin.js +223 -0
  15. package/server/assets/chat/attachments.js +240 -0
  16. package/server/assets/chat/editor.js +211 -0
  17. package/server/assets/chat/events.js +34 -10
  18. package/server/assets/chat/index.js +8 -0
  19. package/server/assets/chat/markdown.js +1 -12
  20. package/server/assets/chat/members.js +1 -1
  21. package/server/assets/chat/mentions.js +38 -28
  22. package/server/assets/chat/message-window.js +18 -0
  23. package/server/assets/chat/messages.js +64 -46
  24. package/server/assets/chat/questions.js +113 -41
  25. package/server/assets/chat/receipts.js +0 -1
  26. package/server/assets/chat/reminders.js +101 -0
  27. package/server/assets/chat/replies.js +149 -0
  28. package/server/assets/chat/rooms.js +30 -10
  29. package/server/assets/chat/state.js +68 -18
  30. package/server/assets/conversation.css +111 -45
  31. package/server/assets/responsive.css +83 -28
  32. package/server/chat-server.ts +23 -6
  33. package/server/chat.html +82 -31
  34. package/server/inbox.ts +5 -1
  35. package/server/newrooms.ts +27 -10
  36. package/server/resource-routes.ts +3 -0
  37. package/server/room-reminders.ts +212 -0
  38. package/server/wake.ts +11 -15
  39. package/skills/chatroom/SKILL.md +21 -1
  40. package/src/admin-client.ts +130 -0
  41. package/src/admin-credentials.ts +58 -0
  42. package/src/agent-receipts.ts +13 -18
  43. package/src/center-client.ts +1 -1
  44. package/src/center-inbox.ts +2 -0
  45. package/src/plugin-notifications.ts +4 -0
  46. package/src/queue.ts +7 -2
  47. package/src/reminder-client.ts +50 -0
  48. package/src/resource-read.ts +118 -0
  49. package/src/resources.ts +1 -1
  50. package/src/sqlite-state.ts +89 -21
  51. package/src/store.ts +22 -8
  52. package/src/supervision-inbox.ts +62 -0
  53. package/src/v1-plugin.ts +13 -3
  54. package/src/v2-plugin.ts +24 -7
@@ -0,0 +1,154 @@
1
+ import { databasePath } from "../src/store";
2
+ import { readHistoryPage } from "../src/sqlite-state";
3
+ import { adminEnabled, hasAdminCapability, isOperator } from "./admin-auth";
4
+ import { adminPlanRoutes } from "./admin-plan-routes";
5
+ import { adminTaskRoutes } from "./admin-task-routes";
6
+ import { binding, digest, ensureAdminSchema, exec, isAgentMember, many, matchesHash, newSecret, one, publicRoom, tx, validCurrent, enroll } from "./admin-state";
7
+ import type { Binding } from "./admin-state";
8
+ import { startAdminScheduler } from "./admin-scheduler";
9
+
10
+ const json = (body: unknown, status = 200) => Response.json(body, { status, headers: { "Cache-Control": "no-store" } });
11
+ const object = (value: unknown): value is Record<string, unknown> => !!value && typeof value === "object" && !Array.isArray(value);
12
+ startAdminScheduler();
13
+
14
+ export async function adminRoutes(request: Request, url: URL): Promise<Response | undefined> {
15
+ if (!url.pathname.startsWith("/admin/") && !url.pathname.startsWith("/supervision/")) return undefined;
16
+ if (!adminEnabled) return json({ error: "admin API is disabled" }, 503);
17
+ try {
18
+ await ensureAdminSchema();
19
+ const task = await adminTaskRoutes(request, url);
20
+ if (task) return task;
21
+ const plan = await adminPlanRoutes(request, url);
22
+ if (plan) return plan;
23
+ return await rootRoutes(request, url);
24
+ } catch (error) {
25
+ if (error instanceof SyntaxError || error instanceof URIError) return json({ error: "invalid request" }, 400);
26
+ return json({ error: "admin request failed" }, 500);
27
+ }
28
+ }
29
+
30
+ async function rootRoutes(request: Request, url: URL): Promise<Response> {
31
+ const path = url.pathname;
32
+ if (request.method === "GET" && path === "/admin/rooms") return listRooms(request);
33
+ if (request.method === "POST" && path === "/admin/rooms") return createBinding(request);
34
+ const claim = path.match(/^\/admin\/rooms\/([^/]+)\/claim$/);
35
+ if (claim && request.method === "POST") return claimBinding(request, decodeURIComponent(claim[1]!));
36
+ const room = path.match(/^\/admin\/rooms\/([^/]+)(?:\/(overview|history))?$/);
37
+ if (!room) return json({ error: "not found" }, 404);
38
+ const roomID = decodeURIComponent(room[1]!);
39
+ if (request.method === "PUT" && !room[2]) return rotateBinding(request, roomID);
40
+ if (request.method === "DELETE" && !room[2]) return revokeBinding(request, roomID);
41
+ if (request.method === "GET" && room[2] === "overview") return overview(request, roomID);
42
+ if (request.method === "GET" && room[2] === "history") return history(request, url, roomID);
43
+ return json({ error: "method not allowed" }, 405);
44
+ }
45
+
46
+ async function listRooms(request: Request): Promise<Response> {
47
+ if (!isOperator(request)) return json({ error: "operator token required" }, 401);
48
+ return json({ rooms: await tx(db => many<Binding>(db, "SELECT * FROM admin_rooms ORDER BY created_at LIMIT 200").map(publicRoom)) });
49
+ }
50
+
51
+ async function createBinding(request: Request): Promise<Response> {
52
+ if (!isOperator(request)) return json({ error: "operator token required" }, 401);
53
+ const body: unknown = await request.json();
54
+ if (!object(body) || !bounded(body.roomId, 128) || !bounded(body.targetRoomId, 128) ||
55
+ !bounded(body.sessionID, 128) || typeof body.receiverOwnerID !== "string" || body.receiverOwnerID.length > 128 ||
56
+ !bounded(body.membershipID, 128)) return json({ error: "invalid admin binding" }, 400);
57
+ const { roomId, targetRoomId, sessionID, receiverOwnerID, membershipID } = body as {
58
+ roomId: string; targetRoomId: string; sessionID: string; receiverOwnerID: string; membershipID: string;
59
+ };
60
+ const result = await tx(db => {
61
+ const admin = one<{ kind: string }>(db, "SELECT kind FROM rooms WHERE id=?", roomId);
62
+ if (!admin) return { status: 404 as const, error: "admin room not found" };
63
+ if (admin.kind !== "group") return { status: 400 as const, error: "admin room must be a group room" };
64
+ if (one(db, "SELECT 1 FROM admin_rooms WHERE room_id=?", roomId)) return { status: 409 as const, error: "admin room already designated; use PUT to rotate" };
65
+ if (!one(db, "SELECT 1 FROM rooms WHERE id=?", targetRoomId)) return { status: 404 as const, error: "target room not found" };
66
+ if (!isAgentMember(db, targetRoomId, sessionID, receiverOwnerID, membershipID)) return { status: 409 as const, error: "target agent binding is not active" };
67
+ const issued = enroll(db, roomId, targetRoomId, sessionID, receiverOwnerID, membershipID, 1);
68
+ const adminBinding = binding(db, roomId);
69
+ return issued && adminBinding ? { status: 201 as const, issued, adminRoom: publicRoom(adminBinding) } : { status: 409 as const, error: "admin room cannot be designated" };
70
+ });
71
+ return "issued" in result ? json({ adminRoom: result.adminRoom, ...result.issued }, result.status) : json({ error: result.error }, result.status);
72
+ }
73
+
74
+ function bounded(value: unknown, max: number): value is string {
75
+ return typeof value === "string" && value.trim().length > 0 && value.length <= max;
76
+ }
77
+
78
+ async function claimBinding(request: Request, roomID: string): Promise<Response> {
79
+ const body: unknown = await request.json();
80
+ if (!object(body) || !bounded(body.sessionID, 128) || typeof body.receiverOwnerID !== "string" ||
81
+ body.receiverOwnerID.length > 128 || !bounded(body.enrollmentKey, 256)) return json({ error: "invalid claim" }, 400);
82
+ const { sessionID, receiverOwnerID, enrollmentKey } = body as { sessionID: string; receiverOwnerID: string; enrollmentKey: string };
83
+ const result = await tx(db => {
84
+ const b = binding(db, roomID);
85
+ if (!b || b.session_id !== sessionID || b.receiver_owner_id !== receiverOwnerID ||
86
+ b.enrollment_expires <= Date.now() || !matchesHash(enrollmentKey, b.enrollment_hash) ||
87
+ !isAgentMember(db, b.target_room_id, b.session_id, b.receiver_owner_id, b.membership_id)) return null;
88
+ const capability = newSecret();
89
+ const saved = exec(db, "UPDATE admin_rooms SET capability_hash=?,enrollment_hash='',enrollment_expires=0 WHERE room_id=? AND generation=? AND enrollment_hash=? AND enrollment_expires>?",
90
+ digest(capability), roomID, b.generation, b.enrollment_hash, Date.now());
91
+ return saved.changes === 1 ? { capability, adminRoom: publicRoom({ ...b, capability_hash: digest(capability) }) } : null;
92
+ });
93
+ return result ? json(result) : json({ error: "claim rejected" }, 409);
94
+ }
95
+
96
+ async function rotateBinding(request: Request, roomID: string): Promise<Response> {
97
+ if (!isOperator(request)) return json({ error: "operator token required" }, 401);
98
+ const body: unknown = await request.json();
99
+ if (!object(body) || !bounded(body.targetRoomId, 128) || !bounded(body.sessionID, 128) ||
100
+ typeof body.receiverOwnerID !== "string" || body.receiverOwnerID.length > 128 || !bounded(body.membershipID, 128)) return json({ error: "invalid binding" }, 400);
101
+ const { targetRoomId, sessionID, receiverOwnerID, membershipID } = body as {
102
+ targetRoomId: string; sessionID: string; receiverOwnerID: string; membershipID: string;
103
+ };
104
+ const result = await tx(db => {
105
+ const old = binding(db, roomID);
106
+ if (!old) return null;
107
+ if (!isAgentMember(db, targetRoomId, sessionID, receiverOwnerID, membershipID)) return null;
108
+ const issued = enroll(db, roomID, targetRoomId, sessionID, receiverOwnerID, membershipID, old.generation + 1);
109
+ const current = binding(db, roomID);
110
+ return issued && current ? { issued, adminRoom: publicRoom(current) } : null;
111
+ });
112
+ return result ? json({ adminRoom: result.adminRoom, ...result.issued }) : json({ error: "admin room or active agent binding not found" }, 409);
113
+ }
114
+
115
+ async function revokeBinding(request: Request, roomID: string): Promise<Response> {
116
+ if (!isOperator(request)) return json({ error: "operator token required" }, 401);
117
+ const deleted = await tx(db => exec(db, "DELETE FROM admin_rooms WHERE room_id=?", roomID).changes);
118
+ return deleted ? json({ ok: true }) : json({ error: "admin room not found" }, 404);
119
+ }
120
+
121
+ async function overview(request: Request, roomID: string): Promise<Response> {
122
+ const result = await tx(db => {
123
+ const b = binding(db, roomID);
124
+ if (!b) return { status: 404 as const };
125
+ if (!authorized(request, b)) return { status: 401 as const };
126
+ if (!isOperator(request) && !validCurrent(db, b)) return { status: 409 as const };
127
+ const rooms = many<{ id: string; name: string; createdAt: number }>(db, "SELECT id,name,created_at AS createdAt FROM rooms ORDER BY created_at DESC LIMIT 200")
128
+ .map(room => ({ ...room, members: many(db, "SELECT g.session_id AS sessionID,g.name,g.protocol,g.receiver_owner_id AS receiverOwnerID,g.work_state AS workState,g.last_seen_at AS lastSeenAt FROM registry g WHERE g.room_id=? ORDER BY g.name", room.id) }));
129
+ const tasks = many(db, "SELECT id,admin_room_id AS adminRoomId,admin_generation AS generation,target_room_id AS targetRoomId,target_session_id AS targetSessionID,text,status,progress,created_at AS createdAt,updated_at AS updatedAt FROM admin_tasks WHERE admin_room_id=? ORDER BY created_at DESC LIMIT 200", roomID);
130
+ const plans = many(db, "SELECT id,admin_room_id AS adminRoomId,name,interval_seconds AS intervalSeconds,text,paused,next_run_at AS nextRunAt,created_at AS createdAt FROM admin_plans WHERE admin_room_id=? ORDER BY created_at DESC LIMIT 200", roomID);
131
+ return { rooms, tasks, plans };
132
+ });
133
+ return "status" in result ? json({ error: result.status === 404 ? "admin room not found" : result.status === 401 ? "unauthorized" : "binding is no longer active" }, result.status) : json(result);
134
+ }
135
+
136
+ async function history(request: Request, url: URL, roomID: string): Promise<Response> {
137
+ const targetRoomID = url.searchParams.get("targetRoomId") ?? "";
138
+ const rawLimit = url.searchParams.get("limit");
139
+ const limit = rawLimit === null ? 20 : Number(rawLimit);
140
+ if (!bounded(targetRoomID, 128) || !Number.isSafeInteger(limit) || limit < 1 || limit > 50) return json({ error: "invalid history request" }, 400);
141
+ const allowed = await tx(db => {
142
+ const b = binding(db, roomID);
143
+ if (!b) return 404;
144
+ if (!authorized(request, b)) return 401;
145
+ if (!isOperator(request) && !validCurrent(db, b)) return 409;
146
+ return one(db, "SELECT 1 FROM rooms WHERE id=?", targetRoomID) ? 200 : 404;
147
+ });
148
+ if (allowed !== 200) return json({ error: allowed === 401 ? "unauthorized" : allowed === 404 ? "room not found" : "binding is no longer active" }, allowed);
149
+ return json(await readHistoryPage(databasePath(), targetRoomID, undefined, limit));
150
+ }
151
+
152
+ function authorized(request: Request, b: import("./admin-state").Binding): boolean {
153
+ return isOperator(request) || hasAdminCapability(request, b);
154
+ }
@@ -0,0 +1,42 @@
1
+ import { binding, exec, many, tx, validCurrent } from "./admin-state";
2
+ import { randomUUID } from "node:crypto";
3
+
4
+ type PlanRow = { id: string; admin_room_id: string; interval_seconds: number; next_run_at: number; text: string };
5
+ type OpenTask = { text: string; status: string; progress: string };
6
+ type Reminder = { id: string; acknowledged: number };
7
+
8
+ export async function tickAdminScheduler(now = Date.now()): Promise<void> {
9
+ await tx((db) => {
10
+ const due = many<PlanRow>(db, "SELECT * FROM admin_plans WHERE paused=0 AND next_run_at<=? ORDER BY next_run_at LIMIT 100", now);
11
+ for (const plan of due) {
12
+ const b = binding(db, plan.admin_room_id);
13
+ if (!b || !validCurrent(db, b)) {
14
+ exec(db, "UPDATE admin_plans SET next_run_at=? WHERE id=?", now + plan.interval_seconds * 1000, plan.id);
15
+ continue;
16
+ }
17
+ const tasks = many<OpenTask>(db, "SELECT text,status,progress FROM admin_tasks WHERE admin_room_id=? AND status IN ('pending','working','blocked') ORDER BY created_at DESC LIMIT 20", b.room_id);
18
+ const summary = tasks.length ? `\nOpen tasks:\n${tasks.map(t => `- ${t.status}: ${t.text}${t.progress ? ` (${t.progress})` : ""}`).join("\n")}` : "\nNo open tasks.";
19
+ const text = `${plan.text}${summary}`.slice(0, 5000);
20
+ const taskID = `plan:${plan.id}`;
21
+ const existing = db.query("SELECT id,acknowledged FROM admin_deliveries WHERE admin_room_id=? AND kind='supervision' AND task_id=?").get(b.room_id, taskID) as Reminder | null;
22
+ if (existing && !existing.acknowledged) {
23
+ exec(db, "UPDATE admin_deliveries SET text=?,created_at=?,generation=?,recipient_room_id=?,session_id=?,owner_id=?,membership_id=? WHERE id=?", text, now, b.generation, b.target_room_id, b.session_id, b.receiver_owner_id, b.membership_id, existing.id);
24
+ } else if (existing) {
25
+ const id = randomUUID();
26
+ exec(db, "UPDATE admin_deliveries SET id=?,admission_id=?,text=?,created_at=?,generation=?,recipient_room_id=?,session_id=?,owner_id=?,membership_id=?,acknowledged=0 WHERE id=?", id, `msg_${id}`, text, now, b.generation, b.target_room_id, b.session_id, b.receiver_owner_id, b.membership_id, existing.id);
27
+ } else {
28
+ const id = randomUUID();
29
+ exec(db, "INSERT INTO admin_deliveries(id,admin_room_id,generation,recipient_room_id,session_id,owner_id,membership_id,kind,text,task_id,admission_id,created_at) VALUES(?,?,?,?,?,?,?,'supervision',?,?,?,?)", id,b.room_id,b.generation,b.target_room_id,b.session_id,b.receiver_owner_id,b.membership_id,text,taskID,`msg_${id}`,now);
30
+ }
31
+ exec(db, "UPDATE admin_plans SET next_run_at=? WHERE id=?", now + plan.interval_seconds * 1000, plan.id);
32
+ }
33
+ });
34
+ }
35
+
36
+ let timer: ReturnType<typeof setInterval> | undefined;
37
+ export function startAdminScheduler(): void {
38
+ if (timer || !process.env.CHAT_ROOM_ADMIN_TOKEN || !process.env.CHAT_ROOM_SERVER_TOKEN || process.env.CHAT_ROOM_ADMIN_TOKEN === process.env.CHAT_ROOM_SERVER_TOKEN) return;
39
+ timer = setInterval(() => { void tickAdminScheduler().catch(() => {}); }, 5000);
40
+ timer.unref?.();
41
+ }
42
+ export function stopAdminScheduler(): void { if (timer) clearInterval(timer); timer = undefined; }
@@ -0,0 +1,61 @@
1
+ import { createHash, randomBytes, randomUUID, timingSafeEqual } from "node:crypto";
2
+ import type { Database, SQLQueryBindings } from "bun:sqlite";
3
+ import { databasePath } from "../src/store";
4
+ import { initializeAdminSchema, withStateTransaction } from "../src/sqlite-state";
5
+
6
+ const hash = (value: string) => createHash("sha256").update(value).digest("hex");
7
+ const secret = () => randomBytes(32).toString("base64url");
8
+ const row = <T>(db: Database, sql: string, ...args: SQLQueryBindings[]) => db.query(sql).get(...args) as T | null;
9
+ const all = <T>(db: Database, sql: string, ...args: SQLQueryBindings[]) => db.query(sql).all(...args) as T[];
10
+ const run = (db: Database, sql: string, ...args: SQLQueryBindings[]) => db.query(sql).run(...args);
11
+ export type AdminRoom = { roomId: string; targetRoomId: string; sessionID: string; receiverOwnerID: string; membershipID: string; generation: number; enrolled: boolean; createdAt: number };
12
+ export type Binding = { room_id: string; target_room_id: string; session_id: string; receiver_owner_id: string; membership_id: string; generation: number; enrollment_hash: string; enrollment_expires: number; capability_hash: string | null; created_at: number };
13
+ export const digest = hash;
14
+ export const newSecret = secret;
15
+ export function safeEqual(a: string, b: string): boolean {
16
+ const left = Buffer.from(hash(a), "hex"), right = Buffer.from(hash(b), "hex");
17
+ return timingSafeEqual(left, right);
18
+ }
19
+ export function matchesHash(value: string, stored: string): boolean {
20
+ const left = Buffer.from(hash(value), "hex"), right = Buffer.from(stored, "hex");
21
+ return right.length === 32 && timingSafeEqual(left, right);
22
+ }
23
+ export async function ensureAdminSchema() { await initializeAdminSchema(databasePath()); }
24
+ export async function tx<T>(fn: (db: Database) => T) { await ensureAdminSchema(); return withStateTransaction(databasePath(), fn); }
25
+ export function publicRoom(b: Binding): AdminRoom { return { roomId: b.room_id, targetRoomId: b.target_room_id, sessionID: b.session_id, receiverOwnerID: b.receiver_owner_id, membershipID: b.membership_id, generation: b.generation, enrolled: Boolean(b.capability_hash), createdAt: b.created_at }; }
26
+ export function binding(db: Database, roomID: string) { return row<Binding>(db, "SELECT * FROM admin_rooms WHERE room_id=?", roomID); }
27
+ export function currentMember(db: Database, b: Binding) {
28
+ return row(db, `SELECT g.membership_id,g.receiver_owner_id,g.protocol,g.host,p.id AS participant_id
29
+ FROM registry g JOIN participants p ON p.room_id=g.room_id AND p.id=CASE WHEN (SELECT kind FROM rooms WHERE id=g.room_id)='direct' THEN g.session_id ELSE g.name END
30
+ WHERE g.room_id=? AND g.session_id=?`, b.target_room_id, b.session_id) as { membership_id: string; receiver_owner_id: string | null; protocol: string | null; host: string | null; participant_id: string } | null;
31
+ }
32
+ export function validCurrent(db: Database, b: Binding): boolean {
33
+ const m = currentMember(db, b);
34
+ return !!m && m.membership_id === b.membership_id && (m.receiver_owner_id ?? "") === b.receiver_owner_id && (m.protocol === "v1" || m.protocol === "v2" || Boolean(m.host));
35
+ }
36
+ export function enroll(db: Database, roomID: string, targetRoomID: string, sessionID: string, ownerID: string, membershipID: string, generation: number, createdAt = Date.now()) {
37
+ if (!row(db, "SELECT 1 FROM rooms WHERE id=? AND kind='group'", roomID) || !row(db, "SELECT 1 FROM rooms WHERE id=?", targetRoomID)) return undefined;
38
+ const nextKey = secret(), expiresAt = Date.now() + 600_000;
39
+ run(db, `INSERT INTO admin_rooms(room_id,target_room_id,session_id,receiver_owner_id,membership_id,generation,enrollment_hash,enrollment_expires,capability_hash,created_at)
40
+ VALUES(?,?,?,?,?,?,?,?,NULL,?) ON CONFLICT(room_id) DO UPDATE SET target_room_id=excluded.target_room_id,session_id=excluded.session_id,receiver_owner_id=excluded.receiver_owner_id,membership_id=excluded.membership_id,generation=excluded.generation,enrollment_hash=excluded.enrollment_hash,enrollment_expires=excluded.enrollment_expires,capability_hash=NULL`,
41
+ roomID, targetRoomID, sessionID, ownerID, membershipID, generation, hash(nextKey), expiresAt, createdAt);
42
+ run(db, "UPDATE admin_tasks SET status='cancelled',delivery_token_hash='',updated_at=? WHERE admin_room_id=? AND status IN ('pending','working','blocked')", Date.now(), roomID);
43
+ run(db, "DELETE FROM admin_deliveries WHERE admin_room_id=?", roomID);
44
+ run(db, "UPDATE admin_plans SET paused=1 WHERE admin_room_id=?", roomID);
45
+ return { enrollmentKey: nextKey, expiresAt };
46
+ }
47
+ export function isAgentMember(db: Database, roomID: string, sessionID: string, ownerID: string, membershipID: string) {
48
+ const entry = row<{ membership_id: string; receiver_owner_id: string | null; protocol: string | null; host: string | null }>(db,
49
+ `SELECT g.membership_id,g.receiver_owner_id,g.protocol,g.host FROM registry g JOIN participants p ON p.room_id=g.room_id AND p.id=CASE WHEN (SELECT kind FROM rooms WHERE id=g.room_id)='direct' THEN g.session_id ELSE g.name END WHERE g.room_id=? AND g.session_id=?`, roomID, sessionID);
50
+ return !!entry && entry.membership_id === membershipID && (entry.receiver_owner_id ?? "") === ownerID && (entry.protocol === "v1" || entry.protocol === "v2" || Boolean(entry.host));
51
+ }
52
+ export type Recipient = { roomID: string; sessionID: string; ownerID: string; membershipID: string };
53
+ export function queue(db: Database, b: Binding, kind: string, text: string, taskID: string | null = null, taskToken: string | null = null, recipient: Recipient = { roomID: b.target_room_id, sessionID: b.session_id, ownerID: b.receiver_owner_id, membershipID: b.membership_id }) {
54
+ const id = randomUUID();
55
+ run(db, `INSERT INTO admin_deliveries(id,admin_room_id,generation,recipient_room_id,session_id,owner_id,membership_id,kind,text,task_id,task_token,admission_id,created_at)
56
+ VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?) ON CONFLICT(admin_room_id,kind,task_id) DO UPDATE SET text=excluded.text,task_token=excluded.task_token,generation=excluded.generation,recipient_room_id=excluded.recipient_room_id,session_id=excluded.session_id,owner_id=excluded.owner_id,membership_id=excluded.membership_id,created_at=excluded.created_at,acknowledged=0`,
57
+ id,b.room_id,b.generation,recipient.roomID,recipient.sessionID,recipient.ownerID,recipient.membershipID,kind,text,taskID,taskToken,`msg_${id}`,Date.now());
58
+ }
59
+ export function one<T>(db: Database, sql: string, ...args: SQLQueryBindings[]) { return row<T>(db, sql, ...args); }
60
+ export function many<T>(db: Database, sql: string, ...args: SQLQueryBindings[]) { return all<T>(db, sql, ...args); }
61
+ export { run as exec, randomUUID };
@@ -0,0 +1,182 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import type { Database } from "bun:sqlite";
3
+ import { hasAdminCapability, isOperator } from "./admin-auth";
4
+ import { binding, digest, exec, isAgentMember, many, matchesHash, newSecret, one, queue, tx, validCurrent } from "./admin-state";
5
+ import type { Binding } from "./admin-state";
6
+
7
+ const json = (body: unknown, status = 200) => Response.json(body, { status, headers: { "Cache-Control": "no-store" } });
8
+ const object = (value: unknown): value is Record<string, unknown> => !!value && typeof value === "object" && !Array.isArray(value);
9
+ const statuses = ["pending", "working", "blocked", "completed", "cancelled"] as const;
10
+ type TaskStatus = typeof statuses[number];
11
+ const auth = (request: Request, b: Binding) => isOperator(request) || hasAdminCapability(request, b);
12
+ type TaskRow = { id: string; admin_room_id: string; admin_generation: number; target_room_id: string; target_session_id: string; target_owner_id: string; target_membership_id: string; text: string; status: string; progress: string; delivery_token_hash: string; created_at: number; updated_at: number };
13
+ type DeliveryRow = { id: string; admissionID: string; adminRoomId: string; generation: number; recipientRoomId: string; membershipID: string; kind: string; text: string; taskId: string | null; taskToken: string | null; createdAt: number };
14
+ type TaskView = { id: string; adminRoomId: string; generation: number; targetRoomId: string; targetSessionID: string; text: string; status: string; progress: string; createdAt: number; updatedAt: number };
15
+ type AckDelivery = { id: string; admin_room_id: string; generation: number; recipient_room_id: string; session_id: string; owner_id: string; membership_id: string; kind: string };
16
+ const revokeTaskDelivery = (db: Database, roomID: string, taskID: string) => {
17
+ exec(db, "DELETE FROM admin_deliveries WHERE admin_room_id=? AND kind='task' AND task_id=? AND acknowledged=0", roomID, taskID);
18
+ // A delivered prompt cannot be recalled; revoke its token so it cannot report progress.
19
+ exec(db, "UPDATE admin_deliveries SET task_token=NULL WHERE admin_room_id=? AND kind='task' AND task_id=?", roomID, taskID);
20
+ };
21
+
22
+ export async function adminTaskRoutes(request: Request, url: URL): Promise<Response | undefined> {
23
+ const base = url.pathname.match(/^\/admin\/rooms\/([^/]+)\/tasks$/);
24
+ const update = url.pathname.match(/^\/admin\/rooms\/([^/]+)\/tasks\/([^/]+)$/);
25
+ if (base && request.method === "GET") return tx(db => {
26
+ const b = binding(db, decodeURIComponent(base[1]!));
27
+ if (!b) return { error: "admin room not found", status: 404 };
28
+ if (!auth(request, b)) return { error: "unauthorized", status: 401 };
29
+ if (!isOperator(request) && !validCurrent(db, b)) return { error: "binding is no longer active", status: 409 };
30
+ return { tasks: many<TaskView>(db, "SELECT id,admin_room_id AS adminRoomId,admin_generation AS generation,target_room_id AS targetRoomId,target_session_id AS targetSessionID,text,status,progress,created_at AS createdAt,updated_at AS updatedAt FROM admin_tasks WHERE admin_room_id=? ORDER BY created_at DESC LIMIT 200", b.room_id) };
31
+ }).then(result => "status" in result ? json({ error: result.error }, result.status) : json(result));
32
+ if (base && request.method === "POST") return createTask(request, decodeURIComponent(base[1]!));
33
+ if (update && request.method === "PATCH") return updateTask(request, decodeURIComponent(update[1]!), decodeURIComponent(update[2]!));
34
+ if (url.pathname === "/supervision/inbox" && request.method === "GET") return inbox(request, url);
35
+ if (url.pathname === "/supervision/ack" && request.method === "POST") return acknowledge(request);
36
+ const progress = url.pathname.match(/^\/supervision\/tasks\/([^/]+)\/progress$/);
37
+ if (progress && request.method === "POST") return reportProgress(request, decodeURIComponent(progress[1]!));
38
+ return undefined;
39
+ }
40
+
41
+ async function createTask(request: Request, roomID: string): Promise<Response> {
42
+ const body: unknown = await request.json();
43
+ if (!object(body) || typeof body.targetRoomId !== "string" || !body.targetRoomId || typeof body.targetSessionID !== "string" || !body.targetSessionID || typeof body.text !== "string" || !body.text.trim() || body.text.trim().length > 2000) return json({ error: "invalid task" }, 400);
44
+ const targetRoomID = body.targetRoomId, targetSessionID = body.targetSessionID, text = body.text.trim();
45
+ const result = await tx(db => {
46
+ const b = binding(db, roomID);
47
+ if (!b) return { status: 404 as const };
48
+ if (!auth(request, b)) return { status: 401 as const };
49
+ if (!validCurrent(db, b)) return { status: 409 as const };
50
+ const recipient = one<{ receiver_owner_id: string | null; membership_id: string }>(db, "SELECT receiver_owner_id,membership_id FROM registry WHERE room_id=? AND session_id=?", targetRoomID, targetSessionID);
51
+ if (!recipient || !isAgentMember(db, targetRoomID, targetSessionID, recipient.receiver_owner_id ?? "", recipient.membership_id)) return { status: 409 as const };
52
+ const id = randomUUID(), now = Date.now(), taskToken = newSecret();
53
+ exec(db, "INSERT INTO admin_tasks(id,admin_room_id,admin_generation,target_room_id,target_session_id,target_owner_id,target_membership_id,text,status,progress,delivery_token_hash,created_at,updated_at) VALUES(?,?,?,?,?,?,?,?,'pending','',?,?,?)",
54
+ id, roomID, b.generation, targetRoomID, targetSessionID, recipient.receiver_owner_id ?? "", recipient.membership_id, text, digest(taskToken), now, now);
55
+ queue(db, b, "task", text, id, taskToken, { roomID: targetRoomID, sessionID: targetSessionID, ownerID: recipient.receiver_owner_id ?? "", membershipID: recipient.membership_id });
56
+ return { task: { id, adminRoomId: roomID, generation: b.generation, targetRoomId: targetRoomID, targetSessionID, text, status: "pending", progress: "", createdAt: now, updatedAt: now } };
57
+ });
58
+ if ("status" in result) return json({ error: result.status === 404 ? "admin room not found" : result.status === 401 ? "unauthorized" : "active agent target not found" }, result.status);
59
+ return json(result, 201);
60
+ }
61
+
62
+ async function updateTask(request: Request, roomID: string, taskID: string): Promise<Response> {
63
+ const body: unknown = await request.json();
64
+ if (!object(body) || (body.status !== undefined && !statuses.includes(body.status as typeof statuses[number])) ||
65
+ (body.progress !== undefined && (typeof body.progress !== "string" || body.progress.length > 2000))) return json({ error: "invalid task update" }, 400);
66
+ const update = body as { status?: TaskStatus; progress?: string };
67
+ const result = await tx(db => {
68
+ const b = binding(db, roomID);
69
+ if (!b) return { status: 404 as const };
70
+ if (!auth(request, b)) return { status: 401 as const };
71
+ if (!validCurrent(db, b)) return { status: 409 as const };
72
+ const task = one<TaskRow>(db, "SELECT * FROM admin_tasks WHERE id=? AND admin_room_id=?", taskID, roomID);
73
+ if (!task || task.admin_generation !== b.generation) return { status: 404 as const };
74
+ const status = update.status ?? task.status;
75
+ if (task.status === "completed" || task.status === "cancelled") return { status: 409 as const };
76
+ const progress = update.progress === undefined ? task.progress : update.progress.trim();
77
+ const updatedAt = Date.now();
78
+ const terminal = status === "completed" || status === "cancelled";
79
+ exec(db, "UPDATE admin_tasks SET status=?,progress=?,delivery_token_hash=?,updated_at=? WHERE id=? AND admin_generation=?", status, progress, terminal ? "" : task.delivery_token_hash, updatedAt, taskID, b.generation);
80
+ if (terminal) revokeTaskDelivery(db, roomID, taskID);
81
+ return { task: { id: taskID, adminRoomId: roomID, generation: b.generation, targetRoomId: task.target_room_id,
82
+ targetSessionID: task.target_session_id, text: task.text, status, progress, createdAt: task.created_at, updatedAt } };
83
+ });
84
+ if ("status" in result) return json({ error: result.status === 401 ? "unauthorized" : result.status === 404 ? "task not found" : "binding is no longer active" }, result.status);
85
+ return json(result);
86
+ }
87
+
88
+ async function reportProgress(request: Request, taskID: string): Promise<Response> {
89
+ const body: unknown = await request.json();
90
+ const sessionID = request.headers.get("x-chat-agent-session") ?? "";
91
+ const ownerID = request.headers.get("x-chat-agent-owner") ?? "";
92
+ if (!object(body) || typeof body.taskToken !== "string" || typeof body.status !== "string" ||
93
+ !statuses.includes(body.status as TaskStatus) || typeof body.progress !== "string" || body.progress.length > 2000) return json({ error: "invalid task progress" }, 400);
94
+ const update = body as { taskToken: string; status: TaskStatus; progress: string };
95
+ const result = await tx(db => {
96
+ const task = one<TaskRow>(db, "SELECT * FROM admin_tasks WHERE id=?", taskID);
97
+ if (!task) return false;
98
+ const b = binding(db, task.admin_room_id);
99
+ if (!b || task.admin_generation !== b.generation || task.status === "completed" || task.status === "cancelled" || !validCurrent(db, b) ||
100
+ sessionID !== task.target_session_id || ownerID !== task.target_owner_id ||
101
+ !isAgentMember(db, task.target_room_id, task.target_session_id, task.target_owner_id, task.target_membership_id) ||
102
+ !task.delivery_token_hash || !matchesHash(update.taskToken, task.delivery_token_hash)) return null;
103
+ const terminal = update.status === "completed" || update.status === "cancelled";
104
+ exec(db, "UPDATE admin_tasks SET status=?,progress=?,delivery_token_hash=?,updated_at=? WHERE id=? AND admin_generation=?",
105
+ update.status, update.progress.trim(), terminal ? "" : task.delivery_token_hash, Date.now(), taskID, b.generation);
106
+ if (terminal) revokeTaskDelivery(db, b.room_id, taskID);
107
+ return true;
108
+ });
109
+ if (result === null) return json({ error: "task progress credential rejected" }, 401);
110
+ return result ? json({ ok: true }) : json({ error: "task not found" }, 404);
111
+ }
112
+
113
+ async function inbox(request: Request, url: URL): Promise<Response> {
114
+ const sessionID = url.searchParams.get("sessionID") ?? "";
115
+ const ownerID = url.searchParams.get("receiverOwnerID") ?? "";
116
+ const adminRoomID = url.searchParams.get("adminRoomId");
117
+ if (!sessionID || sessionID.length > 128 || ownerID.length > 128) return json({ error: "invalid agent identity" }, 400);
118
+ return adminRoomID ? protectedInbox(request, sessionID, ownerID, adminRoomID) : taskInbox(sessionID, ownerID);
119
+ }
120
+
121
+ function pruneStale(db: Database, sessionID: string, ownerID: string): void {
122
+ db.query(`DELETE FROM admin_deliveries AS d WHERE d.acknowledged=0 AND d.session_id=? AND d.owner_id=? AND (
123
+ NOT EXISTS(SELECT 1 FROM admin_rooms a WHERE a.room_id=d.admin_room_id AND a.generation=d.generation AND EXISTS(
124
+ SELECT 1 FROM registry g JOIN rooms r ON r.id=g.room_id JOIN participants p ON p.room_id=g.room_id AND p.id=CASE WHEN r.kind='direct' THEN g.session_id ELSE g.name END
125
+ WHERE g.room_id=a.target_room_id AND g.session_id=a.session_id AND g.membership_id=a.membership_id AND coalesce(g.receiver_owner_id,'')=a.receiver_owner_id AND (g.protocol IN ('v1','v2') OR coalesce(g.host,'')!='')))
126
+ OR NOT EXISTS(SELECT 1 FROM registry g JOIN rooms r ON r.id=g.room_id JOIN participants p ON p.room_id=g.room_id AND p.id=CASE WHEN r.kind='direct' THEN g.session_id ELSE g.name END
127
+ WHERE g.room_id=d.recipient_room_id AND g.session_id=d.session_id AND g.membership_id=d.membership_id AND coalesce(g.receiver_owner_id,'')=d.owner_id AND (g.protocol IN ('v1','v2') OR coalesce(g.host,'')!='')))`)
128
+ .run(sessionID, ownerID);
129
+ }
130
+
131
+ async function taskInbox(sessionID: string, ownerID: string): Promise<Response> {
132
+ const result = await tx(db => {
133
+ pruneStale(db, sessionID, ownerID);
134
+ const deliveries = many<DeliveryRow>(db, `SELECT d.id,d.admission_id AS admissionID,d.admin_room_id AS adminRoomId,d.generation,
135
+ d.recipient_room_id AS recipientRoomId,d.membership_id AS membershipID,d.kind,d.text,d.task_id AS taskId,d.task_token AS taskToken,d.created_at AS createdAt
136
+ FROM admin_deliveries d JOIN admin_tasks t ON t.id=d.task_id AND t.admin_room_id=d.admin_room_id AND t.admin_generation=d.generation
137
+ AND t.target_room_id=d.recipient_room_id AND t.target_session_id=d.session_id AND t.target_owner_id=d.owner_id AND t.target_membership_id=d.membership_id
138
+ WHERE d.session_id=? AND d.owner_id=? AND d.kind='task' AND d.acknowledged=0 ORDER BY d.created_at LIMIT 100`, sessionID, ownerID)
139
+ .map(({ taskToken, recipientRoomId, membershipID, ...delivery }) => ({ ...delivery, targetRoomId: recipientRoomId, ...(taskToken ? { taskToken } : {}) }));
140
+ const supervisionRoomIds = many<{ admin_room_id: string }>(db, `SELECT DISTINCT d.admin_room_id FROM admin_deliveries d JOIN admin_rooms a ON a.room_id=d.admin_room_id
141
+ WHERE d.session_id=a.session_id AND d.owner_id=a.receiver_owner_id AND d.membership_id=a.membership_id AND d.recipient_room_id=a.target_room_id
142
+ AND d.generation=a.generation AND d.session_id=? AND d.owner_id=? AND d.kind='supervision' AND d.acknowledged=0 ORDER BY d.admin_room_id LIMIT 100`, sessionID, ownerID).map(row => row.admin_room_id);
143
+ return { deliveries, supervisionRoomIds };
144
+ });
145
+ return json(result);
146
+ }
147
+
148
+ async function protectedInbox(request: Request, sessionID: string, ownerID: string, roomID: string): Promise<Response> {
149
+ const result = await tx(db => {
150
+ const b = binding(db, roomID);
151
+ if (!b) return { status: 404 as const };
152
+ const operator = isOperator(request);
153
+ if (!operator && (sessionID !== b.session_id || ownerID !== b.receiver_owner_id || !hasAdminCapability(request, b))) return { status: 401 as const };
154
+ if (!validCurrent(db, b)) return { status: 409 as const };
155
+ pruneStale(db, b.session_id, b.receiver_owner_id);
156
+ return { deliveries: many<DeliveryRow>(db, `SELECT id,admission_id AS admissionID,admin_room_id AS adminRoomId,generation,
157
+ recipient_room_id AS recipientRoomId,membership_id AS membershipID,kind,text,task_id AS taskId,task_token AS taskToken,created_at AS createdAt
158
+ FROM admin_deliveries WHERE admin_room_id=? AND generation=? AND recipient_room_id=? AND session_id=? AND owner_id=? AND membership_id=? AND kind='supervision' AND acknowledged=0 ORDER BY created_at LIMIT 100`,
159
+ roomID, b.generation, b.target_room_id, b.session_id, b.receiver_owner_id, b.membership_id).map(({ taskToken, membershipID, recipientRoomId, ...delivery }) => delivery) };
160
+ });
161
+ if ("status" in result) return json({ error: result.status === 401 ? "unauthorized" : result.status === 404 ? "admin room not found" : "binding is no longer active" }, result.status);
162
+ return json(result);
163
+ }
164
+
165
+ async function acknowledge(request: Request): Promise<Response> {
166
+ const body: unknown = await request.json();
167
+ if (!object(body) || typeof body.id !== "string" || typeof body.sessionID !== "string" || typeof body.receiverOwnerID !== "string") return json({ error: "invalid acknowledgement" }, 400);
168
+ const ack = body as { id: string; sessionID: string; receiverOwnerID: string };
169
+ const ok = await tx(db => {
170
+ const delivery = one<AckDelivery>(db, "SELECT * FROM admin_deliveries WHERE id=? AND acknowledged=0", ack.id);
171
+ if (!delivery || delivery.session_id !== ack.sessionID || delivery.owner_id !== ack.receiverOwnerID) return false;
172
+ const b = binding(db, delivery.admin_room_id);
173
+ if (!b || b.generation !== delivery.generation || !validCurrent(db, b) ||
174
+ !isAgentMember(db, delivery.recipient_room_id, delivery.session_id, delivery.owner_id, delivery.membership_id)) return false;
175
+ if (delivery.kind === "supervision" && (delivery.recipient_room_id !== b.target_room_id ||
176
+ delivery.session_id !== b.session_id || delivery.owner_id !== b.receiver_owner_id || delivery.membership_id !== b.membership_id ||
177
+ (!isOperator(request) && !hasAdminCapability(request, b)))) return false;
178
+ if (delivery.kind !== "task" && delivery.kind !== "supervision") return false;
179
+ return exec(db, "UPDATE admin_deliveries SET acknowledged=1 WHERE id=? AND acknowledged=0", ack.id).changes === 1;
180
+ });
181
+ return json({ ok });
182
+ }
@@ -3,40 +3,41 @@
3
3
  [hidden] { display: none !important; }
4
4
 
5
5
  :root {
6
- --font-sans: system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI","PingFang SC","Hiragino Sans GB","Noto Sans SC","Noto Sans CJK SC","Source Han Sans SC","Microsoft YaHei",sans-serif;
6
+ --font-sans: "Avenir Next", "Segoe UI Variable", system-ui, -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", sans-serif;
7
+ --font-display: "Iowan Old Style", "Baskerville", "Songti SC", Georgia, serif;
7
8
  --font-mono: ui-monospace,"SF Mono","Cascadia Mono","JetBrains Mono",Consolas,monospace;
8
- --bg: #f2f4f6;
9
- --surface: #ffffff;
10
- --surface-2: #f3f5f7;
11
- --ink: #1c2631;
12
- --ink-2: #465462;
13
- --ink-3: #566574;
14
- --line: #d5dce3;
15
- --accent: #286783;
16
- --accent-ink: #ffffff;
17
- --accent-soft: #e2f0f5;
18
- --danger: #b23a2e;
19
- --danger-soft: #f9e7e2;
20
- --mention-blue: #2e6cc4;
21
- --shadow: 0 1px 2px rgb(48 38 25 / .05), 0 12px 32px rgb(48 38 25 / .08);
9
+ --bg: #f3f1ea;
10
+ --surface: #fffefa;
11
+ --surface-2: #f2f0e8;
12
+ --ink: #1e2c29;
13
+ --ink-2: #455651;
14
+ --ink-3: #63716b;
15
+ --line: #dcded4;
16
+ --accent: #22695c;
17
+ --accent-ink: #fffdf6;
18
+ --accent-soft: #e1eee6;
19
+ --danger: #a84437;
20
+ --danger-soft: #f7e8e1;
21
+ --mention-blue: #266c72;
22
+ --shadow: 0 2px 5px rgb(34 53 47 / .05), 0 18px 44px rgb(34 53 47 / .09);
22
23
  }
23
24
 
24
25
  @media (prefers-color-scheme: dark) {
25
26
  :root {
26
- --bg: #151a20;
27
- --surface: #1e252d;
28
- --surface-2: #28313a;
29
- --ink: #edf2f7;
30
- --ink-2: #cad3dc;
31
- --ink-3: #b3bfca;
32
- --line: #3a4652;
33
- --accent: #75b6cc;
34
- --accent-ink: #10242c;
35
- --accent-soft: #263f49;
36
- --danger: #e27a6c;
37
- --danger-soft: #3a201b;
38
- --mention-blue: #86a9ee;
39
- --shadow: 0 1px 2px rgb(0 0 0 / .4), 0 14px 36px rgb(0 0 0 / .45);
27
+ --bg: #111b19;
28
+ --surface: #182522;
29
+ --surface-2: #202f2b;
30
+ --ink: #edf2e9;
31
+ --ink-2: #c6d1c9;
32
+ --ink-3: #a6b3aa;
33
+ --line: #344640;
34
+ --accent: #8ac9aa;
35
+ --accent-ink: #14251e;
36
+ --accent-soft: #263d34;
37
+ --danger: #ef9580;
38
+ --danger-soft: #3a2924;
39
+ --mention-blue: #8bc8c2;
40
+ --shadow: 0 2px 6px rgb(0 0 0 / .22), 0 18px 44px rgb(0 0 0 / .32);
40
41
  }
41
42
  }
42
43
 
@@ -48,7 +49,8 @@
48
49
  line-height: 1.65;
49
50
  color: var(--ink);
50
51
  background:
51
- radial-gradient(1100px 520px at 50% -8%, color-mix(in srgb, var(--accent) 7%, transparent), transparent 65%),
52
+ radial-gradient(900px 540px at 6% 0%, color-mix(in srgb, var(--accent) 10%, transparent), transparent 68%),
53
+ radial-gradient(760px 420px at 100% 100%, color-mix(in srgb, #c6a775 7%, transparent), transparent 72%),
52
54
  var(--bg);
53
55
  -webkit-tap-highlight-color: transparent;
54
56
  }
@@ -87,10 +89,10 @@
87
89
  width: 100%;
88
90
  max-width: 424px;
89
91
  margin: auto;
90
- padding: 36px 32px 30px;
91
- background: var(--surface);
92
- border: 1px solid var(--line);
93
- border-radius: 18px;
92
+ padding: 38px 34px 32px;
93
+ background: linear-gradient(155deg, color-mix(in srgb, var(--accent-soft) 32%, var(--surface)), var(--surface) 42%);
94
+ border: 1px solid color-mix(in srgb, var(--accent) 18%, var(--line));
95
+ border-radius: 22px;
94
96
  box-shadow: var(--shadow);
95
97
  }
96
98
  .locale-control { display: flex; align-items: center; justify-content: flex-end; gap: 8px; margin-bottom: 20px; color: var(--ink-2); font-size: 12.5px; }
@@ -99,8 +101,8 @@
99
101
  .chat-head-actions .locale-control { margin: 0; }
100
102
  .wordmark {
101
103
  margin: 0;
102
- font-family: var(--font-sans);
103
- font-size: 30px;
104
+ font-family: var(--font-display);
105
+ font-size: 34px;
104
106
  font-weight: 700;
105
107
  letter-spacing: -.03em;
106
108
  color: var(--ink);
@@ -124,9 +126,9 @@
124
126
  color: var(--ink);
125
127
  background: var(--surface);
126
128
  border: 1px solid var(--line);
127
- border-radius: 10px;
129
+ border-radius: 12px;
128
130
  padding: 11px 13px;
129
- transition: border-color .15s, box-shadow .15s;
131
+ transition: border-color .16s, box-shadow .16s, background-color .16s;
130
132
  }
131
133
  .input::placeholder { color: var(--ink-3); }
132
134
  .input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }
@@ -144,10 +146,10 @@
144
146
  }
145
147
  .btn:active { transform: translateY(1px); }
146
148
  .btn:disabled { opacity: .5; cursor: default; }
147
- .btn.primary { background: var(--accent); color: var(--accent-ink); }
148
- .btn.primary:not(:disabled):hover { filter: brightness(1.07); }
149
- .btn.ghost { background: transparent; color: var(--ink-2); border: 1px solid var(--line); }
150
- .btn.ghost:not(:disabled):hover { color: var(--ink); border-color: var(--ink-3); }
149
+ .btn.primary { background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 86%, #152d28), var(--accent)); color: var(--accent-ink); box-shadow: 0 3px 8px color-mix(in srgb, var(--accent) 18%, transparent); }
150
+ .btn.primary:not(:disabled):hover { filter: brightness(1.07); box-shadow: 0 5px 14px color-mix(in srgb, var(--accent) 22%, transparent); }
151
+ .btn.ghost { background: color-mix(in srgb, var(--surface) 78%, transparent); color: var(--ink-2); border: 1px solid var(--line); }
152
+ .btn.ghost:not(:disabled):hover { color: var(--ink); border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); background: var(--accent-soft); }
151
153
  .btn.small { padding: 8px 14px; font-size: 13.5px; }
152
154
  .btn:focus-visible, .chip:focus-visible, .room-row:focus-visible, .input:focus-visible,
153
155
  .jump:focus-visible, .copy-id:focus-visible, .locale-select:focus-visible {
@@ -163,7 +165,7 @@
163
165
  .alert {
164
166
  margin-top: 16px;
165
167
  padding: 10px 13px;
166
- border-radius: 10px;
168
+ border-radius: 12px;
167
169
  background: var(--danger-soft);
168
170
  color: var(--danger);
169
171
  font-size: 13.5px;
@@ -187,6 +189,16 @@
187
189
  .danger-text { color: var(--danger) !important; }
188
190
  .announcement-content { white-space: pre-wrap; overflow-wrap: anywhere; }
189
191
 
192
+ .panel.reminder-panel { width: min(410px, calc(100vw - 32px)); max-height: min(72dvh, 640px); overflow: auto; }
193
+ .reminder-form { border-top: 1px solid var(--line); padding-top: 10px; }
194
+ .reminder-form .field { margin: 0 0 9px; }
195
+ .reminder-form textarea { resize: vertical; }
196
+ .reminder-list { list-style: none; padding: 0; margin: 10px 0; display: grid; gap: 8px; }
197
+ .reminder-list li { padding: 9px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
198
+ .reminder-list p { margin: 0 0 6px; overflow-wrap: anywhere; }
199
+ .reminder-list .hint { margin: 2px 0 7px; }
200
+ .reminder-list .btn { margin: 0 6px 0 0; }
201
+
190
202
  .token-box { margin-top: 18px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
191
203
  .token-box summary {
192
204
  cursor: pointer;