Chat: /new continues the same chat on a fresh session

The composer's /new used to create a separate chat. It now sends
chat_new_session. The server starts a fresh native session on the chat's
own harness (OpenCode, Codex or Claude Code) and re-keys the
operator_sessions row in one transaction. The chat keeps its title,
directory, backend, colour, star, model and mode. The old row is kept
unlisted with replaced_by, and its native session stays resumable.

The reply and the chat_session_changed push carry previous_id, so every
client swaps the row in place and an open conversation follows it to the
fresh, empty transcript with a notice.
This commit is contained in:
2026-11-03 14:06:44 +00:00
parent 251cc4f274
commit ad4233f7b8
21 changed files with 910 additions and 131 deletions
+24
View File
@@ -71,6 +71,30 @@ command noise are excluded, and paging is bounded. A session file larger than
The live user turn keeps the client's optimistic id when it can be matched to the
recorded prompt.
## Fresh context (`/new`)
The composer's `/new` sends `chat_new_session`. It keeps the chat and clears the
agent's context, like `/new` or `/clear` in the harness's own TUI. The server
creates a fresh native session on the chat's own harness, in the same directory
and with the same title. OpenCode makes a new `ses_` session, Codex a new thread
and Claude Code a new session UUID. The server then re-keys the
`operator_sessions` row in one transaction. The new row keeps the title,
directory, tag, backend, colour, star, creation time, model override and mode.
The old row is not deleted: it records `replaced_by`, is no longer listed, and
its native session can still be resumed in a terminal.
The row is re-keyed rather than mapped from a stable id because every other
layer is keyed by the native id: rooms, queues, transcripts, shells, exports and
resume commands. The reply, and the `chat_session_changed` push to other
connections, carry the new row with `previous_id`. Each client swaps that row in
place, and an open conversation follows it to the fresh, empty transcript. A
running turn is refused, so stop it first. A second `/new` from an id that has
already been replaced is refused too.
Claude Code also accepts `/clear` in `-p --input-format stream-json` mode, but
the CLI then picks the new session id itself. Re-keying keeps one path for all
three harnesses and lets the server choose the id.
## Web interaction contract
All advertised chat adapters (OpenCode V2, Codex and Claude Code) implement the