diff --git a/AGENTS.md b/AGENTS.md index 7ea44cfe6..f7c78d4f2 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -103,6 +103,7 @@ app/api/ hosts/route.ts GET hosts (this machine first) | POST { label } → token once + login command | PATCH { id, label?, allowAgentStart? } (`local`: label only, empty resets to "This machine") | DELETE ?id= revoke (registry first, then close the link); 503 if hosts.json is unreadable hosts/link/route.ts GET WebSocket upgrade (the `ompweb host` daemon; bearer checked before the upgrade, skipped by the `proxy.ts` gate) | POST 426 for pre-WebSocket daemons notifications/devices/route.ts GET VAPID key + subscribed | PUT { deviceId, prefs, subscription? } + notifications/answer/route.ts POST { sessionId, requestId, response } answer a pending dialog from a notification (never spawns omp) notifications/presence/route.ts POST { clientId, deviceId, visible, sessionId, seq } notifications/test/route.ts POST { deviceId } send a test push (502 on push-service refusal) notifications/history/route.ts GET entries | PATCH { ids } mark read | DELETE ?id= remove one, ?all=1 clear @@ -1808,8 +1809,14 @@ during the wait. leak it); else if a visible tab with an open stream exists, `whenActive: "toast"` devices get a toast on their active tabs only; else push (subscribed devices) or in-page `showNotification` (tabs with an open stream). -- The server decides before pushing: iOS revokes push permission for pushes - that display nothing, so `public/sw.js` always shows what it receives. +- The server decides before pushing: a push that displays nothing is a silent + push, and iOS revokes the permission for one while Chromium and Firefox + substitute a generic card and eventually mute the origin. `public/sw.js` + therefore always shows what it receives, and a settled dialog is retracted on + the tab streams only (`{type: "notification-dismiss", tag, sessionId, + requestId}`) — never by a push. A device that is not reachable keeps the + stale card until the next `input` push replaces it by tag; only a reachable + tab closes it, through the stream. - Notifications have their own `notifications` channel (`clientId` = the tab's notification client id), opened by `useNotifications` in `AppShell`, so a tab stays reachable on every view, Settings included. A tab on @@ -1824,6 +1831,18 @@ during the wait. rendered server-side in the device's locale. Browsers with saved settings (enabled or not) sync on load; never-configured browsers do not. - A crash notifies "Run failed" while a run is live or while background work started by it has not settled yet (`unsettled`, cleared by `session_settled`). +- An unanswered `input` notification repeats while its dialog stays pending: + `INPUT_REMINDER_MS` (2 h) apart, at most `MAX_INPUT_REMINDERS` (12) times, + then it stays quiet until it settles. `OMP_WEB_INPUT_REMINDER_MS` overrides + the spacing for this process (`0` disables reminders; unset, negative, + non-numeric or above `2^31-1` keep the default — a larger value overflows + `setTimeout` and would fire immediately). Each device can turn the repeats + off with `prefs.inputReminder`; the first notification is unaffected. The + schedule is per request id and survives a host replay of the same id, so a + reconnecting host neither restarts the budget nor resets the "waiting for" + duration; only a real settlement drops it. The history entry is shared, so a + device that turned repeats off still sees the reminder rows another device + wanted. - The Settings test button pushes through the server for subscribed devices (502 with the push service's answer on failure) and shows a local notification otherwise, or a toast where none are allowed. diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a747ff97..a385bc5fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,19 @@ All notable changes to **omp-web** (`@kahme247/ompweb`) are documented in this f - **Updates belong to each host.** Settings → Hosts now shows the ompweb daemon and OMP runtime versions, available updates, and update actions for every machine, including This machine. Checks and installations run on that host. An incompatible or unverifiable daemon update stays visible but blocked, with a reason to update the web server first; OMP updates are independent of the link protocol. A daemon update is refused while session processes or subagents run on that host (close them, then start it again), and the host refuses new sessions while it installs. The host update retains a backup and reports progress after reconnect. **System & Updates** is now **System**, containing only the web server's controls; it no longer updates or restarts a host's OMP sessions globally. - **Messages wait safely until omp has them.** In an existing chat, the composer clears once IndexedDB has stored the message, and a dimmed bubble names the delivery leg: **Sending**, **Waiting for **, **Delivering**, or **Not sent** with the reason. Browser-held messages survive reloads and closed tabs; server-held messages survive web-server restarts and host outages, and appear on every device viewing the chat. Chromium's Background Sync can deliver after the last tab closes; other browsers retry when an ompweb page reopens. Duplicate submissions share one message id. If a lost host reply leaves delivery uncertain, the message is marked **Not sent** and never retried automatically. A prompt that omp stops (Stop, or a failure) before it reaches the transcript is marked **Not sent** at once, so the messages behind it go on without waiting. Held messages offer **Delete** until dispatched. Follow-ups and steers become omp's own queue chips when accepted. New chats keep their existing first-message path; a browser unable to store the message keeps the composer draft instead. +- **Answer a waiting question from the notification itself.** A notification for a blocking dialog (confirm, select, input, editor, or the ask tool's question panel) now carries the dialog, so a phone or a native client can answer it without opening the session: `POST /api/notifications/answer` takes the session id, the dialog's request id and one response (`confirmed`, `value`, `cancelled`, or `answers` for an ask). The answer goes through the same command the desktop dialog sends, so a server-owned confirmation resolves, an offline host or a restarting session is reported instead of silently dropping it, and no omp process is started for a session that is not running. An answer the pending dialog cannot take is refused with 400 before anything settles: a select accepts only one of its own labels, and an ask's answers are checked against that dialog's questions the way omp checks them (one answer per question in order, each naming its own question, only offered labels, no label twice, and a single-select question takes either one label or free text, never both), so a payload omp would reject never consumes the question. When the dialog settles anywhere, every other open tab is told to close its notification of exactly that request, and a push retry that wakes up afterwards delivers nothing. A settled dialog is never retracted by a push: a push that displays nothing is a silent push, which iOS punishes by revoking the permission and Chromium and Firefox by substituting a generic card and muting the site, so a device that is not reachable keeps the stale card until the next question of that session replaces it. A request that is not a dialog (open_url) takes no answer at all. + +- **A waiting question is repeated until you answer it.** A notification for a + blocking dialog now repeats every two hours while the dialog stays pending, + at most twelve times, then stays quiet until it settles. Each repeat says how + long the question has been open in the reader's language ("Waiting for 2 + hours: Deploy?"), not a clock time in the server's timezone. Repeats stop the + moment the dialog is answered, cancelled, expires, or its session ends, and + each device can turn them off in Settings → Notifications without losing the + first notification. `OMP_WEB_INPUT_REMINDER_MS` overrides the spacing (`0` + disables reminders). A host that replays its pending requests after a + reconnect does not restart the count or the elapsed label: the same question + keeps its own schedule until it is really settled. ### Fixes & Improvements diff --git a/app/api/notifications/answer/route.ts b/app/api/notifications/answer/route.ts new file mode 100644 index 000000000..104b0dd99 --- /dev/null +++ b/app/api/notifications/answer/route.ts @@ -0,0 +1,75 @@ +import { commandErrorResponse } from "@/lib/agent-command"; +import { parseJsonWithinLimit, RequestBodyTooLargeError } from "@/lib/bounded-form-data"; +import type { ExtensionUiResponse, RpcAskDialogAnswer } from "@/lib/pi-types"; +import { getRpcSession, isAskAnswers } from "@/lib/rpc-manager"; +import { isRecord } from "@/lib/type-guards"; + +/** Answers are text; 64 KB leaves room for a long ask customInput without becoming a payload channel. */ +const MAX_BODY_BYTES = 64 * 1024; +const MAX_ID_CHARS = 256; + +const invalid = (error: string) => Response.json({ error, code: "invalid_answer_request" }, { status: 400 }); + +function isId(value: unknown): value is string { + return typeof value === "string" && value.length > 0 && value.length <= MAX_ID_CHARS; +} + +/** + * Exactly one response variant, and nothing else. Shapes come from + * ExtensionDialog; the ask payload reuses the agent route's validation. + */ +function parseResponse(value: unknown): ExtensionUiResponse | null { + if (!isRecord(value)) return null; + const keys = Object.keys(value); + if (keys.length !== 1) return null; + switch (keys[0]) { + case "value": + return typeof value.value === "string" ? { value: value.value } : null; + case "confirmed": + return typeof value.confirmed === "boolean" ? { confirmed: value.confirmed } : null; + case "cancelled": + return value.cancelled === true ? { cancelled: true } : null; + case "answers": + return isAskAnswers(value.answers) ? { answers: value.answers as RpcAskDialogAnswer[] } : null; + default: + return null; + } +} + +/** + * POST /api/notifications/answer — answer a pending blocking extension dialog + * from a notification action. Looks up the live wrapper (also through moved- + * session aliases) and never spawns omp. Behind the normal auth gate. + * + * 200 {status:"answered"} routed through the shared extension_ui_response command + * 200 {status:"alreadySettled"} the request id is not pending + * 200 {status:"sessionGone"} no live wrapper for the session + * 400 on an invalid body, an answer the pending dialog does not take, or a + * request that is not a dialog at all (`open_url` takes no answer) + * 400 session_restarting / 503 {hostOffline: true} when it cannot be delivered + */ +export async function POST(req: Request) { + let body: unknown; + try { + body = await parseJsonWithinLimit(req, MAX_BODY_BYTES); + } catch (error) { + if (error instanceof RequestBodyTooLargeError) { + return Response.json({ error: "Answer is too large", code: "request_too_large" }, { status: 413 }); + } + return invalid("Invalid JSON request body"); + } + if (!isRecord(body) || !isId(body.sessionId) || !isId(body.requestId)) { + return invalid("sessionId, requestId and response are required"); + } + const response = parseResponse(body.response); + if (!response) return invalid("response must be exactly one of value, confirmed, cancelled or answers"); + + const session = getRpcSession(body.sessionId); + if (!session || !session.isAlive()) return Response.json({ status: "sessionGone" }); + + try { + return Response.json({ status: await session.answerExtensionUiRequest(body.requestId, response) }); + } catch (error) { + return commandErrorResponse(error); + } +} diff --git a/components/NotificationList.tsx b/components/NotificationList.tsx index e18f9aaee..9795392e4 100644 --- a/components/NotificationList.tsx +++ b/components/NotificationList.tsx @@ -80,7 +80,8 @@ export function NotificationList() { */ function NotificationRow({ entry }: { entry: NotificationHistoryEntry }) { const { t, locale } = useI18n(); - const { title, body } = renderNotification(entry.event, t); + // The locale makes a reminder's elapsed duration read in the same language. + const { title, body } = renderNotification(entry.event, t, locale); const { sessionId } = entry.event; // Following a notification is reading it. const open = sessionId ? () => { diff --git a/components/SettingsConfig.tsx b/components/SettingsConfig.tsx index 7178468ef..3a2a25161 100644 --- a/components/SettingsConfig.tsx +++ b/components/SettingsConfig.tsx @@ -228,6 +228,7 @@ const SETTING_INDEX: SettingIndexEntry[] = [ { id: "notifications-enable", tab: "notifications", sectionKey: "notifications.title", labelKey: "notifications.enable", descKey: "notifications.enableDesc", fallbackSection: "Notifications", fallbackLabel: "Enable notifications", fallbackDesc: "Asks the browser for permission to show notifications.", scope: "UI" }, { id: "notifications-completed", tab: "notifications", sectionKey: "notifications.title", labelKey: "notifications.typeCompleted", descKey: "notifications.typeCompletedDesc", fallbackSection: "Notifications", fallbackLabel: "Task finished", fallbackDesc: "A prompt and the background work it started are done. Subagents never notify.", scope: "UI" }, { id: "notifications-input", tab: "notifications", sectionKey: "notifications.title", labelKey: "notifications.typeInput", descKey: "notifications.typeInputDesc", fallbackSection: "Notifications", fallbackLabel: "Waiting for input", fallbackDesc: "The agent asks a question or needs an approval.", scope: "UI" }, + { id: "notifications-input-reminder", tab: "notifications", sectionKey: "notifications.title", labelKey: "notifications.inputReminder", descKey: "notifications.inputReminderDesc", fallbackSection: "Notifications", fallbackLabel: "Remind me about unanswered questions", fallbackDesc: "The notification repeats while a question stays unanswered, until it is answered or cancelled.", scope: "UI" }, { id: "notifications-error", tab: "notifications", sectionKey: "notifications.title", labelKey: "notifications.typeError", descKey: "notifications.typeErrorDesc", fallbackSection: "Notifications", fallbackLabel: "Run failed", fallbackDesc: "A run stops with an error after retries and fallbacks, or the omp process exits.", scope: "UI" }, { id: "notifications-modelSwitch", tab: "notifications", sectionKey: "notifications.title", labelKey: "notifications.typeModelSwitch", descKey: "notifications.typeModelSwitchDesc", fallbackSection: "Notifications", fallbackLabel: "Model switched automatically", fallbackDesc: "omp switches models on its own: a fallback after a refusal, rate limit, or usage limit, or a prewalk / plan hand-off.", scope: "UI" }, { id: "notifications-when-active", tab: "notifications", sectionKey: "notifications.title", labelKey: "notifications.whenActive", descKey: "notifications.whenActiveDesc", fallbackSection: "Notifications", fallbackLabel: "When I'm using omp-web in another tab", fallbackDesc: "Nothing is shown for the session you are viewing.", scope: "UI" }, @@ -699,6 +700,9 @@ function NotificationSettingsPanel() { save({ types: { ...prefs.types, [type]: next } })} /> ))} + + save({ inputReminder: next })} /> +