diff --git a/AGENTS.md b/AGENTS.md index 98ece8130..e93b95901 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -454,11 +454,13 @@ The table is static imports, not a runtime glob, so `bun build --compile` (`scri always before this machine, for `new_session` and `send_to_session` alike. - **Not yet remote:** Explorer, Git, Worktrees, the Skills/Plugins/Agents/MCP settings tabs and directory browsing show "Not available on remote hosts - yet". Sub-projects 2 and 3 of the spec add ops for them. + yet". Archive is refused for a remote session (501 `remote_unavailable`, the + menu item disabled): the Archived Sessions browser reads this machine's archive + only, so it could not be restored. Sub-projects 2 and 3 of the spec add ops for them. #### Local daemon (`docs/specs/2026-10-29-local-daemon-design.md`) - **Two services.** `ompweb` (web) and `ompweb-host` (`ompweb host`, the daemon) are installed together by `ompweb systemd install`, `ompweb launchd install` and the Windows tray install; uninstall removes both, `ompweb systemd restart` restarts the web unit only. The daemon owns this machine's omp children, so a web restart, update or redeploy leaves runs going; restarting the daemon ends them (auto-resume then resumes the sessions that were running). An upgrade restarts the daemon only when the running daemon's link version is outside the new release's `[MIN_LINK_PROTOCOL_VERSION, LINK_PROTOCOL_VERSION]` range (it would get 426 and exit); a daemon inside the range keeps running. -- **Local link bootstrap** (`lib/hosts/local-bootstrap.ts`, called from `instrumentation.node.ts`). `localLinkUrl()` builds the daemon's URL from `OMP_WEB_PORT`/`OMP_WEB_HOSTNAME` (set by the `ompweb` launcher; wildcard binds map to `127.0.0.1`, a non-loopback bind gets no link and a console warning). `ensureLocalHostLink()` makes sure the `local` record exists (`registry.ts`, `rotateLocalHostToken`) and writes `/omp-web/host.json` (`{url, token}`, 0600). A `host.json` whose token the registry still accepts and whose url matches is left alone, so a web restart does not make the daemon redial. It throws, and startup only logs, when `host.json` points to a non-loopback server (a remote-host login on this machine): it is never overwritten. The daemon re-reads `host.json` when its link gets 401 and exits only if the file still holds the rejected token. +- **Local link bootstrap** (`lib/hosts/local-bootstrap.ts`, called from `instrumentation.node.ts`). `localLinkUrl()` builds the daemon's URL from `OMP_WEB_PORT`/`OMP_WEB_HOSTNAME` (set by `startProduction` from its listen address, so the launcher, the binary and `npm start` all link; wildcard binds map to `127.0.0.1`, a non-loopback bind gets no link and a console warning). `ensureLocalHostLink()` makes sure the `local` record exists (`registry.ts`, `rotateLocalHostToken`) and writes `/omp-web/host.json` (`{url, token}`, 0600). A `host.json` whose token the registry still accepts and whose url matches is left alone, so a web restart does not make the daemon redial. It throws, and startup only logs, when `host.json` points to a non-loopback server (a remote-host login on this machine): it is never overwritten. The daemon re-reads `host.json` when its link gets 401 and exits only if the file still holds the rejected token. - **Dev mode does not take the daemon.** With `NODE_ENV=development` `ensureLocalHostLink` is skipped, so the daemon stays linked to production and the dev server shows "This machine" offline. The local row of `GET /api/hosts` carries `daemonManaged: false` there, which hides the install banner. - **`local` is a registry record like any host**, with three exceptions: it is listed first, `PATCH` takes `label` only (`allowAgentStart` is fixed), and it cannot be revoked. Renaming "This machine" is a `PATCH /api/hosts {id: "local", label}`; an empty label resets it (`registry.ts` stores `""`; `customLocalLabel()` / `DEFAULT_LOCAL_LABEL` map it). `getHost("local")` works without the record: it is the daemon link, offline while none is linked, and "needs upgrade" on a protocol mismatch (`hostVersion` in the row is the daemon's). - **Adoption on hello** (`reattach`/`adopt` in `hub.ts`, `adoptRpcSession` in `rpc-manager.ts`). Each listed `{ch, sessionId, cwd, pending}` channel that has no transport on this server is a child of a previous server and is taken over by a new `AgentSessionWrapper` (`adopted: true`, `RpcProcess` option `adopted`). There is no session-list lookup: the spawn `cwd` comes from the hello, and the session identity from the child's own `get_state` (`applyIdentity`), so a new session whose file is not written yet is adoptable. The daemon names each child's current session in the hello (`PendingRequests.sessionId`: the file's header id at spawn, then the last successful `get_state`). Re-sync (`AgentSessionWrapper.adopt`): `negotiate_protocol`, `set_subagent_subscription`, `set_ask_dialog`, `get_state`, `get_subagents`, `get_btw_history`, then `replay` of the `pending` lines and `release` of the frames held meanwhile. Every command is bounded by `GET_STATE_TIMEOUT_MS`. diff --git a/README.md b/README.md index ab720ac33..a13aa0fd5 100644 --- a/README.md +++ b/README.md @@ -488,9 +488,9 @@ Notes: whoever controls the ompweb server or the token. Keep the token private and revoke it when a machine is retired. - **Not available on remote hosts yet:** the file explorer, Git and worktree - panels, directory browsing, and the Skills, Plugins, Agents and MCP settings only - work on the machine ompweb runs on. Chat, session history, notifications and - starting sessions work on every host. + panels, directory browsing, archiving sessions, and the Skills, Plugins, Agents + and MCP settings only work on the machine ompweb runs on. Chat, session history, + notifications and starting sessions work on every host. - **Agent-started sessions:** with agent tools enabled, an agent can pass a `host` to `new_session` (it defaults to the agent's own host). A remote host asks for confirmation each time unless **Agents can start sessions here without asking** diff --git a/app/api/sessions/[id]/archive/route.ts b/app/api/sessions/[id]/archive/route.ts index 19d194d71..94cfd45e7 100644 --- a/app/api/sessions/[id]/archive/route.ts +++ b/app/api/sessions/[id]/archive/route.ts @@ -1,6 +1,7 @@ import { apiErrorResponse, hostOfflineResponse, opErrorResponse, resolveSessionHostOr404 } from "@/lib/api-utils"; import { HostOpError } from "@/lib/hosts/link-protocol"; import { invalidateHostSessionList } from "@/lib/hosts/session-index"; +import { LOCAL_HOST_ID } from "@/lib/hosts/registry"; import { clearExitedRpcSession, getRpcSession } from "@/lib/rpc-manager"; /** POST /api/sessions/[id]/archive — stop the live child, then archive the @@ -13,6 +14,11 @@ export async function POST( try { const resolved = await resolveSessionHostOr404(id); if ("response" in resolved) return resolved.response; + // The archive browser (/api/sessions/archive) reads this machine's archive only: a remote session archived on + // its host would vanish from the sidebar with no way to restore it. + if (resolved.host.id !== LOCAL_HOST_ID) { + return Response.json({ error: "Not available on remote hosts yet", code: "remote_unavailable" }, { status: 501 }); + } const { sessionOps } = resolved.host; // Parent-session paths are native branch metadata. Moving only a parent // would leave active children pointing at a path that no longer exists, diff --git a/components/SessionSidebar-rows.tsx b/components/SessionSidebar-rows.tsx index 2cc14788f..035261879 100644 --- a/components/SessionSidebar-rows.tsx +++ b/components/SessionSidebar-rows.tsx @@ -9,6 +9,7 @@ import { ConfirmDialog } from "./ui/field"; import { copyText } from "@/lib/clipboard"; import { transcriptToMarkdown } from "@/lib/transcript"; import { toast } from "./ui/toast"; +import { remoteHostId } from "@/lib/project-ordering"; import { MAX_PROJECT_SESSIONS, formatRelativeTime, @@ -719,6 +720,9 @@ const SessionItem = memo(function SessionItem({ toast.error(t("sessionSidebar.archiveFailed")); } }, [session.id, onDeleted, t]); + // The Archived Sessions browser lists this machine's archive only, so a remote archive could not be restored. + const archiveBlocked = hasChildren || remoteHostId(session.hostId) !== undefined; + const archiveTitle = hasChildren ? t("sessionSidebar.archiveLeafOnly") : archiveBlocked ? t("hosts.notAvailableRemote") : t("sessionSidebar.archive"); const handleDelete = useCallback(async () => { if (deleting) return; @@ -834,7 +838,7 @@ const SessionItem = memo(function SessionItem({