Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
444f21e
feat(open-file): resolve local:// session artifacts in open_file
andrebrait Nov 4, 2026
1bed381
fix(open-file): match omp's local:// parsing and report absent artifacts
andrebrait Nov 4, 2026
384c50a
fix(open-file): refuse dot-prefixed local:// names like omp, make the…
andrebrait Nov 4, 2026
f7ddda2
docs(open-file): state every way local:// parsing is stricter than omp
andrebrait Nov 4, 2026
85332ba
fix(open-file): address review of local:// file opening
andrebrait Nov 4, 2026
89fd0d5
test(files): cover lookup cleanup and in-root watched symlinks
andrebrait Nov 4, 2026
4960ceb
fix(open-file): share canonical credential policy before opening loca…
andrebrait Nov 5, 2026
c563101
fix(files): preserve session-local target priority and confinement
andrebrait Nov 5, 2026
264db80
fix(open-file): preserve live identity and current view during artifa…
andrebrait Nov 5, 2026
1ffe583
fix(open-file): cancel pending artifact lookups with their host request
andrebrait Nov 5, 2026
8982c5d
feat(open-file): resolve session artifacts through their owning daemon
andrebrait Nov 5, 2026
000770b
chore(graph): refresh artifact ownership graph after security restack
andrebrait Nov 5, 2026
c7b73e3
chore(graph): refresh artifact graph after request error fencing
andrebrait Nov 5, 2026
01ae6fd
fix(open-file): own resolved artifact tabs by their live session; wit…
andrebrait Nov 5, 2026
3f262d5
fix(files): compare Windows namespaced roots without the \\?\ prefix
andrebrait Nov 5, 2026
d16a576
fix(files): keep a tab's own session confinement after a later sessio…
andrebrait Nov 6, 2026
3792338
fix(open-file): refuse a local:// lookup when the session root cannot…
andrebrait Nov 6, 2026
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
22 changes: 18 additions & 4 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ goes through that host.
Shared foundations in `lib/omp/`:

- `paths.ts` — Node port of omp's directory resolution (`~/.omp/agent`,
XDG, session dir slugs).
XDG, session dir slugs) and `sessionLocalRoot`, omp's `local://` root rule.
- `omp-cli.ts` — locate/probe the installed `omp` binary (`resolveOmpBin`,
`getOmpVersion`).
- `rpc-process.ts` — process + NDJSON protocol layer (`RpcProcess`).
Expand Down Expand Up @@ -94,6 +94,7 @@ app/api/
sessions/[id]/context/route.ts GET ?leafId= — context for a specific leaf
sessions/[id]/matches/route.ts GET ?q=&limit= — best `limit` search hits in the active conversation (best match, then newest); Load more asks for a longer prefix
sessions/[id]/export/route.ts GET exported HTML for a session
sessions/[id]/local-file/route.ts GET ?uri=local://<file> → `{ path, sessionId }`: the absolute path of a file in the session's own local:// directory, resolved on the owning host's daemon, and the canonical session that owns it (a live alias resolves to its current id; the tab must store that, since the alias goes with its wrapper). The open_file host tool then reads it through /api/files with that `sessionId`; 400 `invalid_local_uri` / `not_a_file`, 404 `session_not_found` / `file_not_found`, 403 on a symlink out, 501 `workspace_unsupported` for a host daemon that predates `resolveLocalFile`
agent/new/route.ts POST { cwd, message, toolNames?, provider?, modelId? }
agent/[id]/route.ts GET state | POST any RPC command
events/route.ts GET multiplexed SSE | POST subscribe/unsubscribe channels
Expand Down Expand Up @@ -141,7 +142,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`
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`
upload-retention.ts daemon side of sent-upload retention: `UploadRetention` (op `setUploadRetention`, `<agent dir>/omp-web/upload-retention.json`, sweep at start and every 24 h), `sweepSentUploads`; `upload-retention-sync.ts` is main's side (`startUploadRetentionSync` on every hello, `pushUploadRetention` when the setting changes)
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
Expand All @@ -163,9 +164,11 @@ lib/
event-stream-hub.ts server connections + running/session/file channels for /api/events (SSE) and the browser link (`FrameSink`); `broadcastBrowserTransport`
event-stream-protocol.ts wire contract shared by hub, route, and facade
file-access.ts allowed file roots for /api/files and worktrees
file-authorization.ts single allow-list gate for /api/files and the file channel
file-authorization.ts single allow-list gate for /api/files and the file channel: allowed roots, the session's own `local://` directory (confined, symlinks included) or the session transcript's references
media-cache.ts tool-result images → /api/media URLs; media copies + thumbnails
file-paths.ts client/server path encoding helpers
file-paths.ts client/server path encoding helpers; `getFileApiUrl`, the one builder of a file tab's `/api/files` URLs
local-uri.ts `local://` parsing exactly as omp's local-protocol.ts reads it (pure; browser and server)
session-local-files.ts daemon side: a session's `local://` root (`sessionLocalRootFor`: verified live-file hint, else the daemon's session index, then `sessionLocalRoot`), a path resolved inside it, and the file gate's check
github-refs.ts remark plugin linking #N / owner/repo#N + GithubRepoContext
git-clone.ts pure clone helpers: URL→directory name (https/ssh only), \r-aware progress log
github-repo.ts server: pick the gh-default GitHub remote from git config
Expand Down Expand Up @@ -1510,6 +1513,17 @@ during the wait.
attachment. Switching chats aborts in-flight uploads; drafts keep only finished
ones and their proofs (`sessionStorage`).

### open_file and `local://`
- The `open_file` host tool takes an absolute path, a workspace-relative path or a `local://` URL. `runHostTool` (`hooks/useAgentSession-stream.ts`) resolves a `local://` URL **before** a tab exists, with the id of the session that called (`useAgentSession` for the viewed session, `AppShell` for a call from another one), through `GET /api/sessions/[id]/local-file`: the tab, its de-duplication and the cross-session confirmation all see the absolute path and `sourceSessionId`, so two sessions' `local://note.md` are two files.
- `lib/session-local-files.ts` resolves on the **owning Node daemon**, without consulting main's live-session or host state. Main's `GET /api/sessions/[id]/local-file` checks shared URI syntax (early 400), uses `resolveWorkspaceHost(undefined, id, { followAlias: true })` to canonicalize a live alias to its current ID and file, and calls the additive `resolveLocalFile(id, uri, sessionFile)` workspace op. An older daemon answers 501 `workspace_unsupported`; there is no main-disk fallback. The daemon applies its native URI rules and uses a live-file hint only after checking realpath containment in its sessions directory and the header's session ID; otherwise its own `resolveSessionPath` decides, including any custom file its index knows. `sessionLocalRoot` (`lib/omp/paths.ts`) retains omp's Windows temp fallback. File GET and watch carry the tab's own ID (and the live file hint only while the wrapper still reports that ID) to `authorizeFileAccess` and `sessionLocalRootContaining`. Never derive the root from cwd or the viewed session, and never read artifact contents in the resolver. The response path must be absolute, and confinement compares native paths without rewriting literal POSIX backslashes.
- `lib/local-uri.ts` reads the URL as omp 18.3.1+'s `extractRelativePath`/`validateRelativePath` do: the authority is the first path segment and is decoded once, with the rest (`local://100%25.md` is `100%.md`; a second decode would open another file); query and fragment are dropped; a segment that is `..` or starts with `..` (`..hidden.md`, `a/..b`), and an absolute suffix (`/x`, `\x`; on Windows also `C:x`), are refused. A colon is an ordinary character off Windows. The resolver answers in this order, so the agent hears it before any tab opens: 503 `local_root_unavailable` when the session's existing local root cannot be canonicalized (only a missing root counts as having nothing to escape), 403 for a path that leaves the root through a symlink (or a link loop), 404 `file_not_found` for a file that is not there, 400 `not_a_file` for a directory (`local://.`, `local://dir/`) or other non-file.
- `runHostTool` bounds the lookup with `LOCAL_FILE_LOOKUP_TIMEOUT_MS` (an `AbortController` and timer, not `AbortSignal.timeout`): a stalled lookup reports an error to the agent. Viewed-chat and global handlers own request-scoped controllers; native `host_tool_cancel`, request withdrawal and unmount abort pending lookups and suppress late open/confirmation and result callbacks. Cross-session cancellation uses the privately captured original source alias, keyed with the request ID, so another session's identical ID is unaffected. Confirmed identity moves keep the mounted request valid. The shell rechecks the committed session and Settings view at completion before using its existing confirmation. A thrown opener becomes `isError`, never a false “Opened” result.
A resolved `local://` tab stores the route's returned `sessionId` (the canonical owner) as `sourceSessionId`; the `host_tool_result` still goes to the calling id. A subscription error (the viewed chat's `session` stream or AppShell's `host-tools` stream) also aborts pending lookups: the server already rejected those calls when the subscription left, and the `host_tool_cancel` it emitted had no listener.
File reads, downloads and watches (`/api/files`, the `file` channel) keep the tab's own `sessionId` and never follow an alias: a tab opened for A stays confined to A's root after omp later moves A to B, and the live wrapper's file is passed as a hint only while it still reports that id. Only the `local://` lookup uses `resolveWorkspaceHost(..., { followAlias: true })`.
- Every file-tab URL uses `getFileApiUrl` with that tab's host ID and source session ID, including both Download controls. `authorizeFileAccess` grants session-local access only for reads, downloads and file watch, never listing. It confines realpaths even when the transcript names the path. Both it and the resolver apply `isOmpSecretFile`: owned credentials and symlink/hard-link aliases stay private, while independent `agent.db` or `models.yml` artifacts remain usable.
- The daemon file watch re-authorizes its target and rejects a pathname swapped for an outside symlink without reporting the outside file's metadata. Its error ends the subscription; a fresh subscription performs authorization again.
- A session-local absolute target takes precedence over workspace-relative fallback, even if a workspace contains a file mirroring its entire pathname or the artifact is missing. Apply its local-root realpath restriction even when a broader config/workspace root also admits the path.

### 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 @@ -57,6 +57,11 @@ All notable changes to **omp-web** (`@kahme247/ompweb`) are documented in this f
- **Pending messages follow native ownership moves immediately.** The confirmed identity change durably retargets held and failed entries before another outbox action, retaining original-ID replay receipts across server restarts. Ordinary branches and session switches stay separate.
- **Deleting a held message cannot be undone by late preparation errors.** A refused or retryable startup result cannot revive the retired entry or send its emptied tombstone.
- **Offline remote chats remain discoverable after a web-server restart.** An empty host cache or failed session-list refresh no longer turns a valid remote chat into a permanent “Session not found” error just because the local daemon is online. Pending messages stay held and reach their owning host once it returns; confirmed missing sessions still fail normally.
- **An agent's `open_file` now opens `local://` files.** `open_file` with `local://note.md` (or `local://nested/name with spaces.md`) opens the file from that session's own `local://` directory in the file viewer, where it used to open a tab that failed with a 403. The URL is read as omp reads it, so a name with a percent such as `local://100%25.md` opens `100%.md`. The file is looked up for the session that asked, even when you are viewing another one, and is read, downloaded (from the file panel's header button too) and live-watched like any other file; a path swapped for a link out of the directory after the file was opened reports nothing of the other file. A file that does not exist, a directory, a URL that leaves the directory (`..`, an absolute path, a symlink out) and one that names a session that does not exist are refused with a message to the agent instead of opening an empty tab, and a lookup the server never answers ends the call with an error after 30 s instead of leaving the agent waiting. A session on a linked host works the same way: that host's daemon resolves and confines the path on its own machine. A host daemon that predates this lookup answers "update or restart the ompweb host daemon" instead of opening an empty tab.
- **Opening a `local://` link refuses omp's own secret files before creating a tab.** The lookup uses the same credential policy as the file viewer, including symlinked agent directories and credential files, so the agent receives an access error instead of a successful “Opened” result followed by a failed tab. Unrelated session artifacts with credential-like names still open.
- **Session-local tabs keep reading the owning artifact.** A workspace file mirroring the artifact's absolute pathname no longer shadows it, and a completed symlink replacement outside the session's local directory is refused even when a broader agent-directory root is browsable.
- **Delayed artifact lookups respect the current conversation.** A file request that finishes after its chat was left no longer opens over the new view; cross-session requests ask for confirmation, including while Settings is open. A live session addressed through an old ID uses its current temporary artifact root on Windows.
Canceling an outstanding file request aborts its lookup and prevents a late tab or confirmation from appearing. Cancellation stays scoped to that request and its original session, including after a confirmed session-ID move.
- **Removing an upload while offline still deletes it from the host.** A file you remove (or a finished upload you discard) is now deleted from the host's staging area once the browser, the server and the host can reach each other again, even if the browser connection dropped or the host was offline when you removed it. As a backstop, a running host now deletes staged files older than a day every hour, not only when it starts or receives a new upload, which also covers a removal that ompweb lost because it restarted while the host was offline.
- **Sent-upload retention reaches hosts already linked at server startup and retries live-link failures.** An attachment whose timestamp cannot be updated is copied so it does not expire before its selected retention period; unreadable cleanup folders are reported in host logs.
- **`!` commands you run have their own look.** A shell command you ran with `!` now shows as a terminal-style card with a `$ command` prompt line, instead of the same row as the agent's tool calls. A failed run shows its exit code (`exit 1`) or `cancelled`, and a `!!` run is tagged `local`. Click the card to show its output. Long pending commands wrap even on narrow screens, switching to a different run resets its expansion, and screen readers can identify successful runs.
Expand Down
4 changes: 2 additions & 2 deletions app/api/files/[...path]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,10 @@ export async function GET(
const { searchParams } = new URL(request.url);
const type = parseFileRequestType(searchParams.get("type") ?? "list");
if (!type) return Response.json({ error: "Invalid file request type", code: "invalid_request_type" }, { status: 400 });
const input = { segments, sessionId: searchParams.get("sessionId") };
const resolved = await resolveWorkspaceHost(searchParams.get("hostId") ?? undefined, input.sessionId);
const resolved = await resolveWorkspaceHost(searchParams.get("hostId") ?? undefined, searchParams.get("sessionId"));
if ("response" in resolved) return resolved.response;
const { host } = resolved;
const input = { segments, sessionId: resolved.sessionId, sessionFile: resolved.sessionFile };
if (type === "list") {
const result = await host.workspaceOps.listFilesInRoot(input, searchParams.get("root"));
return result.ok ? Response.json(result.value) : opErrorResponse(result);
Expand Down
25 changes: 25 additions & 0 deletions app/api/sessions/[id]/local-file/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { apiErrorResponse, opErrorResponse, resolveWorkspaceHost } from "@/lib/api-utils";
import { parseLocalUri } from "@/lib/local-uri";

/** GET ?uri=local://<file> — the absolute path of a file in the session's own `local://` directory, for the file
* viewer (open_file). The owning host's daemon resolves and confines it (its machine, its platform rules); the file
* is stat'ed, not read: 404 `file_not_found` when it is not there, so the agent hears it. */
export async function GET(request: Request, { params }: { params: Promise<{ id: string }> }) {
const { id } = await params;
const uri = new URL(request.url).searchParams.get("uri") ?? "";
// Main checks only shared URI syntax; the owning daemon applies its platform's filename rules.
const parsed = parseLocalUri(uri, null);
if (!parsed.ok) return Response.json({ error: parsed.error, code: "invalid_local_uri" }, { status: 400 });
try {
const resolved = await resolveWorkspaceHost(undefined, id, { followAlias: true });
if ("response" in resolved) return resolved.response;
const owner = resolved.sessionId ?? id;
const result = await resolved.host.workspaceOps.resolveLocalFile(owner, uri, resolved.sessionFile);
if (!result.ok) return opErrorResponse(result);
// The live conversation owns the file: a tab authorized through the alias the request named would lose access once
// that alias is dropped with its wrapper.
return Response.json({ path: result.value.path, sessionId: owner }, { headers: { "Cache-Control": "no-store" } });
} catch (error) {
return apiErrorResponse(error);
}
}
Loading
Loading