diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 09a23b3..1ca02a5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,7 +24,7 @@ jobs: - name: LAN discovery, pairing and admin tests run: cargo test --locked --test lan --test lan_messaging --test admin_messaging --test shell_daemon --test update --test remote --test spawn --test usage --test codex_wake - name: Store, page and phone tests - run: cargo test --locked --test attachments --test channel --test editing --test issues --test phone --test phone_plain --test requirements --test trace --test workflow --test working_on + run: cargo test --locked --test attachments --test channel --test editing --test issues --test phone --test phone_plain --test requirements --test trace --test workflow --test working_on --test codex_remote ui: # The admin page end to end (qa/, headless Chrome, a test bridge with # stand-in agents). Observe mode: it reports but does not block yet; the diff --git a/CHANGELOG.md b/CHANGELOG.md index 83bddc8..806cc75 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,8 +5,23 @@ User-facing changes to session-bridge. Newest first. Each version lists ## Unreleased +### Changes + +- Never kill root: the bridge no longer closes or restarts the session that + holds root, from the admin page, `session-bridge close`, or another session's + `close_session`; each says " holds root; the bridge does not close or + restart it". The Projects tab and the conversation header show no Close or + Restart for it, `list_sessions` marks it with `holds_root`, and the bridge's + instructions tell agents never to end its process. To end it, give the + session another role first, or close it in its own terminal. + ### Fixes +- A Codex session the bridge starts on your Codex app server is listed under + the name the start returned and acts in its role, root included, from its + first request. Two starts in one folder get their own names and roles. If + the app server cannot create the session's conversation, the start fails + with the reason in its window. - Starting a session on macOS no longer brings Terminal or iTerm2 to the front: the new window or tab opens while you keep working where you were, and in iTerm2 the tab you were looking at stays selected. One exception: diff --git a/README.md b/README.md index b721c6e..66d8732 100644 --- a/README.md +++ b/README.md @@ -411,7 +411,11 @@ not been read yet: from the bridge, or from a Codex session's own queue. A session's **Close session** button (local sessions only) ends its process after you confirm. A Codex session that runs inside a shared Codex app server -is not closed this way; close it in its terminal. From a shell: +is not closed this way; close it in its terminal. A session that holds root +has no Close button and is never closed by the bridge, on any path; the +answer is ` holds root; the bridge does not close or restart it`. End +it in its own terminal, or give root to another session and another role +(or none) to this one, and then close it. From a shell: `session-bridge spawn [--project ] [--model ] [--effort ]` and `session-bridge close `. @@ -423,8 +427,9 @@ Only you assign root or start a root session; you can edit root's instructions on the Roles tab but not rename or delete it. Root's own project is its directory, not just a folder of the same name elsewhere. Root acts only through the session you gave it (or the session started as root): another -session that takes the same name gets no root powers. Any program of your -account can still run `session-bridge spawn` and `close`, and the control +session that takes the same name gets no root powers and no protection from +a close. Any program of your account can still run `session-bridge spawn` +and `close` (a session that holds root is refused there too), and the control socket does not prove which session is calling (only a started session's claim is checked: it must come from its own launch process, on macOS and Linux), and whoever runs a launch chooses the `claude` or `codex` program it @@ -491,7 +496,9 @@ What a session was started with is kept in session started before restarts existed, or not by the bridge, says it has no launch record and cannot be restarted. Sessions sharing a process or running in the Codex app server, and a paired laptop's sessions, are restarted where -they run. Only the admin page restarts sessions. +they run. A session that holds root is not restarted by the bridge: it has +no Restart action, and a request answers ` holds root; the bridge does +not close or restart it`. Only the admin page restarts sessions. ## Issues @@ -692,6 +699,9 @@ The CLI derives sender identity from `CODEX_THREAD_ID`, `CLAUDE_CODE_SESSION_ID`, or its Claude ancestor. A human shell without an agent identity can list/status but cannot silently impersonate a sender. +Never end a root session's process (no kill, no closing its terminal); the +bridge refuses to close or restart it. + ### Command reference | Command | Purpose | @@ -706,7 +716,7 @@ identity can list/status but cannot silently impersonate a sender. | `session-bridge status` | Show the service state and recent messages | | `session-bridge send [--project ]` | Send from an agent's shell tool | | `session-bridge spawn [--project ] [--model ] [--effort ]` | Start a session with a role in a terminal | -| `session-bridge close ` | End a local session's process | +| `session-bridge close ` | End a local session's process (refused for a session that holds root) | | `session-bridge network on [--port ] [--name ]` / `network off` | Announce this laptop on the local network and accept paired bridges | | `session-bridge discover` | Bridges found on the network, paired or not | | `session-bridge pair ` | Pair with a discovered laptop; type the code it shows | diff --git a/docs/requirements.md b/docs/requirements.md index 2220b24..effebb4 100644 --- a/docs/requirements.md +++ b/docs/requirements.md @@ -41,7 +41,7 @@ - REQ-027: A bridge outside the local network is reached through SSH, not a public port: on the remote host the bridge runs with `network on --local-only` (listens on 127.0.0.1, no announcement); `session-bridge remote add [--port ]` (or the Peers tab) makes this bridge keep one `ssh -N` connection to that host with the user's own SSH configuration, keys or agent (BatchMode, no prompts), forwarding a local port to the remote bridge and a port on the remote's loopback back to this one, and reconnecting when it drops. `pair ` pairs through the tunnel with the remote's one-time code; afterwards both directions use the pinned Noise channel inside SSH. Remote hosts are listed with their tunnel state and removed with `remote remove`. -- REQ-028: The user starts a Claude or Codex session with a role (admin page channel, `session-bridge spawn`): it is named `{short}-{role}-{n}` (short project name set per project in `spawn.json`, default the folder name; lowest free n among live and starting sessions), starts in the project's directory with the role's instructions as its first prompt and the role assigned, and keeps the native approval checks, unless the user chose other approvals for sessions they start themselves (REQ-034); a session an agent starts always asks. A spawn service per system opens it: iTerm2 (a new tab in its front window; the default when it is installed and the user chose no terminal) or Terminal (macOS), `cmd` (Windows), tmux, screen or a detached `script` (Linux); the window runs only `session-bridge launch `, which claims its directory, name and prompt from the bridge and becomes the agent, so no user text enters a shell or AppleScript command. Codex sessions get their name through the launched process id (kept by session id in `names.json`). The user closes a local session (its process gets SIGTERM; a process that carries several sessions or a Codex app server is refused). The built-in role `root` cannot be renamed or deleted; root's authority belongs to the session the user gave it (by session id) or the session started as root (bound through its launch: only the launch process itself may claim it: the connecting process by the control socket's peer credentials, running exactly ` launch []` (not checked on Windows, which gives no peer process); the launched process itself takes the name whenever it appears, a session under it only within 2 minutes of the claim), not to whichever session has the name, and only a session that really holds root is protected from root's close; a session holding it may, through MCP, start sessions with any other role in its own project (its directory; below 16 live sessions) and close non-root sessions there; no session can start or close a root session. The admin page acts only as the user. The kickoff template fills a request for issue status and queued work in a direct conversation. +- REQ-028: The user starts a Claude or Codex session with a role (admin page channel, `session-bridge spawn`): it is named `{short}-{role}-{n}` (short project name set per project in `spawn.json`, default the folder name; lowest free n among live and starting sessions), starts in the project's directory with the role's instructions as its first prompt and the role assigned, and keeps the native approval checks, unless the user chose other approvals for sessions they start themselves (REQ-034); a session an agent starts always asks. A spawn service per system opens it: iTerm2 (a new tab in its front window; the default when it is installed and the user chose no terminal) or Terminal (macOS), `cmd` (Windows), tmux, screen or a detached `script` (Linux); the window runs only `session-bridge launch `, which claims its directory, name and prompt from the bridge and becomes the agent, so no user text enters a shell or AppleScript command. A Codex session on the Codex app server (REQ-041) gets its thread from the bridge at the launch's claim: the bridge starts the thread on the app server, names it with the session's name (which also writes it to disk), binds the thread to the name at once (`names.json`, by session id) and has the launch resume that thread with the first prompt (`codex resume --remote unix:// ... `); a start whose thread cannot be created fails with the reason in its window, binds nothing and frees its name, and a name bound at a claim stays taken until its session is listed. Other Codex sessions get their name through the launched process id (kept by session id in `names.json`). A started session is listed under the name its start returned and acts in its role, root included, from its first bridge request, with no second assignment. The user closes a local session (its process gets SIGTERM; a process that carries several sessions or a Codex app server is refused, and so is a session that holds root, REQ-057). The built-in role `root` cannot be renamed or deleted; root's authority belongs to the session the user gave it (by session id) or the session started as root (bound through its launch: only the launch process itself may claim it: the connecting process by the control socket's peer credentials, running exactly ` launch []` (not checked on Windows, which gives no peer process); the launched process itself takes the name whenever it appears, a session under it only within 2 minutes of the claim), not to whichever session has the name, and only a session that really holds root is protected from a close and a restart (REQ-057); a session holding it may, through MCP, start sessions with any other role in its own project (its directory; below 16 live sessions) and close non-root sessions there; no session can start a root session, and nothing closes or restarts a session that holds root (REQ-057). The admin page acts only as the user. The kickoff template fills a request for issue status and queued work in a direct conversation. - REQ-029: The admin page's Peers tab (and nowhere else on the page) shows usage, refreshed about every 5 seconds while it is visible: for this laptop and each paired bridge, CPU %, memory used and total, and disk used and total of the filesystem that holds the user's home; for each live session on this laptop, the CPU % and memory of its process tree (the process and its descendants). A process that carries several sessions (a shared Codex app server, `codex --remote`) is shown as shared with its own numbers only, never summed or split per session. Sizes are binary units named as such (GiB). Usage polls read the last discovered sessions and never run discovery; a local sample serves every reader for 2 seconds, and a paired bridge's answer for 30 seconds, with longer waits (up to 5 minutes) after failures. A peer's usage request that fails gets a fixed text; the detail stays in the local log. A bridge asks each paired bridge for its usage over the paired channel; a bridge that does not answer, or an older one that does not know the request, is shown as "usage unavailable", never as an error. @@ -65,7 +65,7 @@ - REQ-039: The installed bridge keeps its config and message history in `~/.session-bridge` (owner-only), and its runtime files (control socket, lock, logs, update and install backups) in `~/.local/state/session-bridge`; a bridge with `SESSION_BRIDGE_STATE` keeps everything in that folder (REQ-021). Config stays as JSON files (written atomically). The message history is `history.jsonl`: each save appends the message's whole state as one line and syncs it (and the folder when the save creates the file). On start the last line of each message is its state. Only the last line may be damaged: NUL bytes a power loss left at its end are dropped; when nothing remains, or JSON that ends early (cut short by a crash), it is skipped and the start cuts it off before any save; a whole last line without its newline is kept and ended. A save that fails is cut off through a handle opened for writing; when that cut fails, the bridge refuses further saves until it restarts. Any other line that cannot be read fails the start with `history.jsonl line N: `, so no message falls back to an older state and is resent. On start, under the daemon lock and before any save, a history with more than twice as many lines as messages is rewritten with each message's latest state in first-seen order (`history.jsonl.tmp`, owner-only, synced, renamed, folder synced). On the first start, when `~/.session-bridge` does not exist, the bridge copies an allowlist of config files and folders from the old folder and starts an empty history (the user's choice): no message is carried over, not even one still in flight, runtime files are not copied, links are not followed, and the old folder is not changed. The copy is built beside the data folder, every copied file and folder synced, and renamed into place (the parent synced), so an interrupted copy is made again on the next start. A bridge whose data folder is its state folder (`SESSION_BRIDGE_STATE`, a launch state) also starts an empty history beside an old `messages/` folder and leaves `messages/` as it is. Going back to an older release reads the old folder again, which may send the messages still waiting there. - REQ-040: The user stars projects on the admin page's Projects tab (`ProjectStar`, admin page only; a paired phone sees which projects are starred but cannot star). A star names a project by its absolute folder and is kept in the data folder as `stars.json` (a JSON list of absolute folders, written atomically), also for a folder that is not listed; a relative folder, or one with `..` parts, is refused, and a star keeps one spelling of its folder (no repeated or trailing separators, no `.` parts). The Projects tab lists starred projects first, then projects with live sessions, then by project name, then by folder. -- REQ-041: The admin page's Run tab has a Codex choice "Run on my Codex app server (--remote unix://)", kept in `spawn.json` as `codex.remote` and on by default, also for settings saved before it existed or saved without it. A Codex session the user starts gets `--remote unix://` only when the choice is on and the user's Codex app server is there (its control socket exists); otherwise it runs plain `codex`. Sessions an agent starts are unaffected: they get `--remote unix://` whenever the app server is there. The Run tab's replies carry `app_server` (whether the app server is there) next to the preview, and the preview follows the same rule. Importing the zsh aliases turns the choice on when the `codex` alias has `--remote` and otherwise leaves it as it is; `--remote` never becomes an extra flag and stays refused as one. +- REQ-041: The admin page's Run tab has a Codex choice "Run on my Codex app server (--remote unix://)", kept in `spawn.json` as `codex.remote` and on by default, also for settings saved before it existed or saved without it. A Codex session the user starts gets `--remote unix://` only when the choice is on and the user's Codex app server is there (its control socket exists); otherwise it runs plain `codex`. Sessions an agent starts are unaffected: they get `--remote unix://` whenever the app server is there. A Codex session that gets `--remote unix://` resumes a thread the bridge created for it at the claim (REQ-028); the bridge creates that thread with the directory, model and effort only, never an approval or sandbox setting, so approvals stay with the client's own flags (REQ-034), and the Run tab's preview keeps showing the flags, not the resume form. The Run tab's replies carry `app_server` (whether the app server is there) next to the preview, and the preview follows the same rule. Importing the zsh aliases turns the choice on when the `codex` alias has `--remote` and otherwise leaves it as it is; `--remote` never becomes an extra flag and stays refused as one. - REQ-042: A live session waiting for its user (a permission prompt, a question, a plan approval or an input request in Claude; an approval or an input request in Codex) carries `waiting_for` in the session list (`list_sessions`, the admin page, the phone, a paired laptop's sessions): a short label of what it waits for, absent when it does not wait or the bridge cannot tell. Whitespace (tabs and line breaks too) becomes a space, other control and format characters are removed, each run of spaces then becomes one space, and the label is trimmed, cut to 40 characters (not bytes, no ellipsis) and trimmed again; it is absent when empty, is applied again to a paired laptop's labels, and is shown as text only. Claude: the `waitingFor` of the session's record (`~/.claude/sessions/.json`) when its `status` is `waiting`, read with each discovery. Codex: in the 30-second queue sweep, over one connection to the user's Codex app server (its control socket), the bridge lists the loaded threads (`thread/loaded/list`) and reads (`thread/read`) only the live local threads among them: a thread whose status is active with `waitingOnApproval` waits for "approval", otherwise with `waitingOnUserInput` for "your input"; a thread that is idle, not loaded, not answered or without an app server has no label. These calls only read: the bridge never loads, resumes or starts a thread for them (REQ-015). A send to a waiting local session answers with `recipient_waiting` (the label at send time, not saved with the message), and the `send_message` result adds " is waiting for its user (