feat(rpc): move_session op copy makes a writable session from a read-only one (#5889)

Merged
CO
17d ago
+316-74

Working...
Part of #5889 (part 2 of 2: the copy. Part 1, the typed refusal, is #5906).

What

move_session {op:"copy", sessionPath, sessionId, sessionDir?} (capability move_session_copy) copies a session file into a NEW session under a caller-chosen plain id, and answers { session_id, session_path }.

  • The copy's header carries the new id. The inherited ownership entries name the old session, so they no longer apply (core/session-move/ownership.ts), and the copy is writable. This lets work go on from a session that is read-only here: a revoked import (#4004) or a session that moved away.
  • The source is only read. No open session is rebound, unlike fork/clone, which keep the caller's session id while switching its file.
  • The copy lands in sessionDir, or in this host's session folder for the source's cwd.
  • Refusals, with nothing written:
    • an id a session file in that folder already carries: move_target_occupied;
    • the source's own id (the copy would stay read-only), or an id that is not plain: invalid_move_request.

The copy itself is the existing SessionManager.forkFrom(source, cwd, dir, { id }), the same path the CLI's cross-project fork uses. It is serialized per folder and id in this process.

Structure: session-move-commands.ts was over the 250-line ceiling, so its request parser moved unchanged to session-move-request.ts before the op was added (the commands file is now 219 lines).

Consumer: a desktop client. A sealed copy offers "Copy to a new thread"; the client mints the new thread id, copies under it, and binds the copy as a new thread.

Tests

  • test/suite/rpc-move-session-copy.test.ts uses two in-process hosts as two devices: a real import, then revoke, then copy. It checks:
    • the copy is writable, keeps the history and has the new header id;
    • the source is byte-identical and still refuses writes;
    • sessionDir is honoured;
    • the three refusals each write nothing.
  • RED (the test against main's source): 3 of 5 failed; the two refusal cases passed only because main refuses an unknown op with the same code.
  • GREEN: 5/5. The run also covered protocol-info (the capability list), move-session, revoke and steps: 52/52.
  • Mutation: idTaken always false fails the occupied case (see below).
  • bun check is clean; oxlint and oxfmt are clean on the changed files.

Summary by cubic

Adds the copy op to move_session, so a session that is read-only here (a moved-away session or a revoked import) can keep working from a new, writable copy under a caller-chosen id (#5889).

  • Copies the source into a new session with the chosen id under move_session_copy, keeping the history; the source is only read and no open session is rebound.
  • Refusals write nothing: move_target_occupied for an id a session file in the target folder already carries, invalid_move_request for the source's own id or a non-plain id.
  • The request parser moved unchanged to session-move-request.ts; the op is documented in docs/rpc.md, covered by in-process host tests across both devices, and announced in the changes/unreleased/5920.md changelog fragment.