Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
14 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 91 additions & 6 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ app/api/
stt/route.ts POST audio (+scope) → 202 { jobId } | GET ?scope= live jobs (lib/stt-jobs.ts)
stt/[jobId]/route.ts GET job state | POST retry with kept audio | DELETE ?claim= claim/discard
stt/[jobId]/audio/route.ts GET the kept recording (audio/* only) for playback
uploads/route.ts POST { id, host, name, size, type } start/resume a composer upload (SSE-mode path of the browser link's `up_start`) → { received, done }
uploads/[id]/route.ts PUT ?offset=N raw body ≤ 1 MiB, answered once the host acked it (409 `upload_offset` with { received }) | DELETE abort
worktrees/route.ts GET/POST/DELETE git worktrees

lib/
Expand All @@ -139,6 +141,7 @@ lib/
local-bootstrap.ts web server side of the local link: `localLinkUrl`, `ensureLocalHostLink` (the `local` record + `host.json`)
host-login.ts `host.json` (`loginHost`, `readHostLogin`) and `isLoopbackHost`, shared by the daemon and local-bootstrap
session-ops.ts file-reading half of the session/project routes, run on the owning host's daemon (this machine's too)
uploads.ts daemon side of composer uploads: `StagedUploads` (staging dir `<agent dir>/omp-web/uploads/`, offset writes, 24 h sweep, attach into the session's `local/uploads/`), `sanitizeUploadName`, `sessionLocalRoot`
link-protocol.ts link messages, codec, binary blob frames, close codes, size limits, `HOST_OP_NAMES`, `SeqWindow`/`Outbox`, `LinkSender`/`PartJoiner` (pieces, fair sending)
hub.ts main side: the link's upgrade and `websocket` handler (`handleLinkUpgrade`, `hostLinkSocket`), `RemoteHost`, `getHost`, `listHosts`, adoption of live children (`reattach`/`adopt`), orphans, `freezeHostLinks`, `hosts` change events
daemon.ts daemon side: `runHostDaemon` (reconnect, buffering, op dispatch, hello with each child's `{sessionId, cwd, pending}`; follows a `host.json` url or token change when a dial fails; loopback redials at most 3 s apart)
Expand Down Expand Up @@ -299,8 +302,8 @@ The table is static imports, not a runtime glob, so `bun build --compile` (`scri
`IDLE_DESTROY_MS` (10 min) and `DISCONNECT_DESTROY_MS`
(`OMP_WEB_DISCONNECT_DESTROY_MS`, 2 min, `0` disables). The shorter one only
fires once a session has been genuinely abandoned — no `onEvent` listener, no
run in flight, no startup handshake, no unanswered `send()`. The last
`onEvent` detach *starts* that window rather than exposing the last frame's,
run in flight, no startup handshake, no unanswered `send()` or command preparation.
The last `onEvent` detach *starts* that window rather than exposing the last frame's,
so a reload reattaching seconds later does not 409. Both are fed by
`resetIdleTimer()`, the single activity choke point for `send()` and every
child frame: adding a new call path must route activity through it.
Expand Down Expand Up @@ -347,7 +350,8 @@ The table is static imports, not a runtime glob, so `bun build --compile` (`scri
design `docs/specs/2026-10-31-websocket-link-design.md`). **Text frames**
carry the messages (hub → daemon one per frame; daemon → hub newline-separated
batches flushed every 16 ms or at one 256 KiB piece), **binary frames** carry large op
results (daemon → hub, before the `res` naming them). Every line except
results (daemon → hub, before the `res` naming them) and, from v6, upload bytes
(hub → daemon, `up:<id>`). Every line except
`hello`/`welcome`/`ack`/`ping`/`pong` has a per-direction `seq`; `ack {ack}`
is a message: the first line of every daemon frame, and the hub answers every
uplink frame (v5: binary ones too) with exactly one. **Pieces and fair sending
Expand Down Expand Up @@ -409,10 +413,13 @@ The table is static imports, not a runtime glob, so `bun build --compile` (`scri
field or a message type receivers skip is fine; a changed type or meaning, or
a newly required field, needs a new version. Receivers skip unknown message
types (acking their `seq`) and answer unknown ops 501 `unknown_op`, from v3 on.
v4 (the WebSocket link) dropped v3 before any release. v5 (pieces) keeps v4:
`MIN_LINK_PROTOCOL_VERSION` is 4 and `LINK_PROTOCOL_VERSION` 5 (literal
v4 (the WebSocket link) dropped v3 before any release. v5 (pieces) keeps v4;
v6 (uploads: hub → daemon binary frames, `upload_ack`, `uploadStart`/
`uploadAbort`/`uploadAttach`) keeps v4 and v5:
`MIN_LINK_PROTOCOL_VERSION` is 4 and `LINK_PROTOCOL_VERSION` 6 (literal
one-liners: the deploy script parses them with `sed`); a v4 daemon gets no
`part`, whole lines and no unacked window (`link.sender.parts`). Main keeps at least N-1, and
`part`, whole lines and no unacked window (`link.sender.parts`); a v4/v5
daemon gets 426 for uploads. Main keeps at least N-1, and
dropping one is an explicit decision (a hello
outside the range gets close 4426 with `{"serverVersion":N}`, a pre-WebSocket
daemon's POST gets 426). Once the WebSocket experiments end, the first version
Expand Down Expand Up @@ -1152,6 +1159,84 @@ during the wait.
`GhostMirror`), not ChatInput state: re-rendering the composer per ghost
change was the dominant per-keystroke cost.

### Composer file uploads (`docs/specs/2026-11-02-file-uploads-design.md`)
- Images and text files go inline while they fit the inline budgets
(`lib/image-attachments.ts`, `lib/chat-attachments.ts`); every other file,
an image switched to **As file**, and anything over a budget is uploaded
(2 GiB per file, 20 per message, `lib/upload-limits.ts`, browser-safe).
The composer re-checks the inline budget per chip on every render, so an
image's decoded size comes from `attachedImageBytes` (scanned once per
image object), never a fresh base64 scan.
- Uploads land in a staging dir on the **session's host** (the daemon), not on
main: a new chat has no session yet. The prompt command carries
`uploads: [id]`; `runAgentCommand` (`lib/agent-command.ts`) attaches each
through the host op `uploadAttach` (hard link into
`<session dir>/local/uploads/`, never overwriting; copy on EXDEV) and appends
the "Attached files" block with `local://` URL and absolute path. Ids stay
registered until the prompt reaches omp, so a retried send reuses the attach.
Attachment preparation uses the wrapper's pending-command protection too, so
disconnect and idle cleanup cannot dispose a submitted prompt's session while
a slow copy is still running. Later commands await the send fence before
selecting/replacing the wrapper, so Stop and an Advisor change cannot overtake it;
a command through any registry alias of the same wrapper (`getRpcSessionKeys`)
waits too. The Attached files block can push a prompt past the host link's
line cap: the transport then refuses it before queueing with 413
`request_too_large`, and the uploads stay registered for a shorter resend.
- Bytes are forwarded, never re-encoded: the browser sends binary frames
`[n][id][payload]` (≤ `pieceBytes`) as `LinkSender` blob units keyed
`up:<id>`; `lib/browser-link.ts` accepts them only for uploads that link
started and hands the same bytes to `forwardUploadFrame` (`lib/uploads.ts`) with
that link's sink; frames are forwarded only while it is the upload's current
sink, so a WS sender superseded by an HTTP resume or newer start is refused;
`forwardUploadFrame` queues them as blob units on the host link (link v6; `hostVersion < 6`
→ 426 `host_upgrade_required` on a remote host, `host_restart_required` on
`local`: an in-place upgrade keeps a running v4/v5 daemon, which is inside
`[MIN, LINK]`, so "This machine" needs `ompweb-host` restarted). Blob units
are outside both links' line windows; the worker's per-upload
`UPLOAD_WINDOW_BYTES` credit, refilled by the daemon's `upload_ack`, is the
flow control, and main enforces it: a frame putting `sent - received` over
`UPLOAD_WINDOW_BYTES + pieceBytes` stops the upload with 429
`upload_window_exceeded` (frames dropped until the next start; the socket
stays open). Binary frames are not resent: after a browser-link drop or a
web-server restart the worker re-sends `up_start {id, n, …}` (same id, `n` =
a worker-wide increasing sequence) and continues from the host's `received` in
the answer `up_ack {…, start: n}`. Each start has a fresh sink whose progress,
completion and errors retain `start: n`, including messages already queued
before a Retry. The worker ignores any mismatched generation before applying
an ack or error. On main the latest concurrent start wins; earlier starts
still answer their callers.
Each host `uploadStart` also carries a fresh UUIDv4 `attempt`; the daemon
echoes it on progress, completion and error `upload_ack`s. Main discards
superseded-attempt acks even if they arrive after the newer start's reply.
Receipt replay and a start of an already-attached upload both require a
regular-file target; a missing or directory target gets `upload_missing`.
Receipt publication is atomic, and start/attach/abort controls share one
per-id queue so an abort cannot be undone by an earlier attach's receipt.
A start that finds the upload aborted sends
`uploadAbort` to the host and answers 404 `upload_missing`. A host-link drop
fails each in-flight upload with 503 `host_offline`; the chip's Retry (same
id) resumes. No auto-retry.
- Limits on main: at most 32 unfinished uploads per owner (429
`too_many_uploads`); an unfinished entry idle 10 min (no start, frame or ack)
is dropped from the registry (a later `up_start` re-registers it). The worker
fails an upload no start answer or ack advances for `UPLOAD_STALL_MS` (120 s)
with 504 `upload_stalled` and forgets it without aborting it on the host, so
Retry resumes. Page navigation settles pending WebSocket-upload promises before
the worker's `bye`: a composer retained by bfcache shows Retry after restoration,
not a permanently uploading chip. This does not automatically resume navigation.
The daemon's `sweep` deletes staged files older than 24 h and aborts open uploads
idle (no start/write) over 24 h (`STAGED_MAX_AGE_MS`).
`uploadAttach` has a 10-minute op timeout (a 2 GiB EXDEV copy), not
`opTimeoutMs`.
- Error codes: composer uploads use `upload_id_conflict` (another upload has
this id); `upload_conflict` stays the file manager's.
- SSE mode uses the same registry over HTTP (`/api/uploads`). Upload owner =
`requestOwner(req)` (`lib/web-auth.ts`), the browser link's owner too; attach
requires the same owner and the session's host.
- The registry is in memory: a main restart loses finished-but-unsent uploads
("attach the file again"); unfinished ones resume. Switching chats aborts
in-flight uploads; drafts keep only finished ones (`sessionStorage`).

### Voice transcription jobs (`lib/stt-jobs.ts`, `/api/stt`, `hooks/useDictation.ts`)
- The browser never waits on the STT endpoint: `POST /api/stt` keeps the
recording in memory and starts a job; the hook polls `GET /api/stt/[jobId]`
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,16 @@ All notable changes to **omp-web** (`@kahme247/ompweb`) are documented in this f
- **ompweb as a single binary, with no Node or npm.** Each release now also carries `ompweb-linux-x64`, `ompweb-linux-arm64`, `ompweb-darwin-x64`, `ompweb-darwin-arm64` (`.tar.gz`) and `ompweb-windows-x64` (`.zip`): one `ompweb` program with the web files beside it. It takes the same options and environment variables as the npm `ompweb`, and runs the daemon too (`ompweb host`). It has no tray, service installers or in-app update: the README's "Single binary" section shows the service units, and Settings → System links the release page when an update is out. Build one with `npm run build:binary`.
- **Binary prereleases from `main`.** Each commit on `main` that passes CI is published as a GitHub prerelease titled with its build time in ISO 8601 UTC (for example `2026-11-01T10:30:00Z`; tag `20261101T103000Z-<short sha>`) with the five single-binary archives. Prereleases are never marked latest, publish no npm package and trigger no update notice.
- **Settings → Hosts shows link protocol versions.** Each host shows the link protocol version its daemon speaks, and the page shows the version this web app expects.
- **Attach any file to a message, up to 2 GiB each.** The composer no longer refuses archives, PDFs or other binary files, and images are no longer capped at 5 MB per message. A file that cannot go inline is uploaded to the session's `local://` directory (`local/uploads/`) on the machine the session runs on, and the message tells the agent its `local://` URL and absolute path. Each image has an **Inline / As file** switch: Inline sends it with the message as before (omp resizes it for the model), As file keeps the exact bytes. An image too large to go inline switches to As file by itself. Uploads stream in chunks over the browser connection (or over HTTP in SSE mode) and on to the host, and show progress on each chip; Send waits until they finish. Over the browser's WebSocket connection, an upload resumes by itself after that connection drops or the web server restarts; in SSE mode, when the server loses the host's link, or when an upload makes no progress for 2 minutes, the chip shows an error and its **Retry** continues from what the host already has. Update ompweb on the server first, then on its hosts: a host on an older build shows "Update ompweb on the session's host to attach files" when a file is attached. After an in-place upgrade, "This machine" takes uploads only once the ompweb host service (`ompweb-host`) is restarted, and the chip says so; restarting it ends the runs on this machine.
- **Keep a host running with the single binary.** The README's "Keep a host running as a service" section has a systemd user unit (Linux), a logon scheduled task (Windows) and, for macOS, a restart script to run in tmux: launchd jobs cannot use the login keychain and SSH agent that omp sessions need. In tmux, macOS Local Network privacy blocks the daemon from LAN addresses, so link it to a URL that does not resolve to one (the server's public URL, or a VPN or tailnet name).
- **Session search shows where each session matched.** While searching the sidebar, the arrow beside a session lists its matches one per line, best match first and newest first among equals, ten at a time with **Load more…**. Matches in the messages of the open conversation are highlighted, typos and partial words included (thinking, tool output and math are not searched; link addresses and image descriptions do not count), and clicking a match opens its session, scrolls to it and marks it as the current one, like the browser's find. Closing or clearing the search removes the highlights. Browsers without the CSS Custom Highlight API (before Chrome 105, Safari 17.2 or Firefox 140) still jump to the match but do not paint it.

### Fixes & Improvements

- **Uploads no longer leave submitted messages or restored pages stuck.** A slow attachment copy keeps its session alive even after you switch chats. Commands that change Advisor wait until that preparation is dispatched before they may replace the session's child. Returning through browser Back/Forward shows Retry for an interrupted upload instead of leaving Send permanently blocked.
- **Attachment retries no longer accept missing files or stale upload errors.** An attachment removed or replaced by a directory is reported as missing before it is marked complete. Failed receipt writes leave the staged file available to retry without creating a duplicate, and cancellation cannot be undone by an attachment still finishing. Replies from earlier upload attempts no longer fail a newer Retry. Retrying also waits for failed-write cleanup, so an old attempt cannot delete the new attempt's staged files.
- **A conflicting upload start no longer interrupts the original file.** Reusing an upload ID with another filename or MIME type is rejected before changing the active transfer, so the original upload continues normally.
- **PDFs stay file attachments when the browser omits their MIME type.** Filenames ending in `.pdf` (any case) no longer have their raw contents inserted into the prompt as text.
- **The dictation waveform no longer stays flat while you speak.** The meter's audio context was created only after the microphone opened; when that took longer than the click's activation window, the browser kept the context suspended and the bars showed silence even though the recording and transcription were fine. The context now starts inside the click.
- **Streaming replies use about a sixth of the bandwidth.** ompweb now asks omp (18.13.2 or later) for only what changed in a streaming reply instead of the whole reply several times a second, and the browser rebuilds the reply itself. In one measured reply the live stream fell from 232 KB to 91 KB, and the reply updates themselves from 178 KB to 30 KB, so replies keep up on slow mobile links. A tab opened mid-reply, a reconnect and a restarted server still show the whole reply. An older omp keeps sending whole replies and works as before.
- **The host link is now one WebSocket**, with fewer requests and large results sent in the same connection. A reverse proxy in front of ompweb must forward WebSocket upgrades on `/api/hosts/link` (see the README's hosts section). Update ompweb on the server first, then on its hosts: a host linked with an earlier build of this release shows **needs upgrade** until it is updated.
Expand Down
3 changes: 2 additions & 1 deletion app/api/agent/[id]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { getRpcSession, WebRpcError } from "@/lib/rpc-manager";
import { commandErrorResponse, runAgentCommand } from "@/lib/agent-command";
import { parseJsonWithinLimit } from "@/lib/bounded-form-data";
import { MAX_AGENT_COMMAND_REQUEST_BYTES } from "@/lib/image-attachments";
import { requestOwner } from "@/lib/web-auth";

/** Stamp when the handler had the request and when it answered, so the browser
* can split network time from server time. */
Expand All @@ -28,7 +29,7 @@ export async function POST(
// body, which is forwarded to omp verbatim) and only matters when this
// request spawns or replaces the session's omp process.
const advisor = new URL(req.url).searchParams.get("advisor") === "1";
return timed(receivedAt, await runAgentCommand(id, body, advisor));
return timed(receivedAt, await runAgentCommand(id, body, advisor, requestOwner(req)));
} catch (error) {
return timed(receivedAt ?? Date.now(), commandErrorResponse(error));
}
Expand Down
29 changes: 29 additions & 0 deletions app/api/uploads/[id]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { readBodyWithinLimit } from "@/lib/bounded-form-data";
import { abortUpload, putUploadChunk, uploadErrorResponse } from "@/lib/uploads";
import { requestOwner } from "@/lib/web-auth";

type Params = { params: Promise<{ id: string }> };

/** Largest PUT body: cut into pieceBytes frames and answered once the host acked its end (spec U4). */
const MAX_CHUNK_BYTES = 1024 * 1024;

/** PUT /api/uploads/<id>?offset=N → {received, done}: the next bytes of the upload, at the host's offset (else 409
* upload_offset with `received`). */
export async function PUT(req: Request, { params }: Params) {
try {
const { id } = await params;
const raw = new URL(req.url).searchParams.get("offset") ?? "";
const offset = Number(raw);
if (!/^\d+$/.test(raw) || !Number.isSafeInteger(offset)) return Response.json({ error: "offset must be a byte offset", code: "invalid_request" }, { status: 400 });
const body = await readBodyWithinLimit(req, MAX_CHUNK_BYTES);
return Response.json(await putUploadChunk(id, requestOwner(req), offset, body));
} catch (error) {
return uploadErrorResponse(error);
}
}

/** DELETE /api/uploads/<id>: cancel the upload and delete its staged file. */
export async function DELETE(req: Request, { params }: Params) {
await abortUpload((await params).id, requestOwner(req));
return new Response(null, { status: 204 });
}
Loading
Loading