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
+22
View File
@@ -43,6 +43,15 @@ const (
// ChatRename records the operator's shared chat title on the server. Unlike
// a local override, every browser and device then lists the same name.
ChatRename = "chat_rename"
// ChatNewSession is the composer's /new: the same chat (list row, title,
// colour, star, directory, model and mode) continues on a fresh native
// harness session with an empty context, as /new or /clear do inside the
// harness's own TUI. The body is ChatNewSessionRequest. The registry row is
// re-keyed to the new native id; the reply and the chat_session_changed push
// carry the new row with PreviousID naming the id it replaced, so every
// client swaps the row in place and an open conversation follows it. The
// previous native session is untouched and stays resumable in a terminal.
ChatNewSession = "chat_new_session"
// ChatExport returns one operator chat as a file the client saves or
// shares. The body is ChatExportRequest and the reply carries
// ChatExportFile: a Markdown or JSON transcript built from the same history
@@ -306,6 +315,11 @@ type ChatSession struct {
// Color is the operator's shared highlight, a ChatColors name; omitted when
// none is set. Clients map the name to their own theme-tuned shade.
Color string `json:"color,omitempty"`
// PreviousID is set only on a chat_new_session reply and its
// chat_session_changed push: the native session id this chat ran on until
// the operator started a fresh session. Clients replace the row with that
// id by this one; it is never part of a listed row.
PreviousID string `json:"previous_id,omitempty"`
}
// Chat export formats accepted by chat_export.
@@ -776,6 +790,14 @@ type ChatRenameRequest struct {
Title string `json:"title"`
}
// ChatNewSessionRequest is the chat_new_session body: the chat whose context
// is replaced, and an optional behaviour instruction preloaded on the fresh
// session where the harness supports one (like chat_create's Instructions).
type ChatNewSessionRequest struct {
SessionID string `json:"session_id"`
Instructions string `json:"instructions,omitempty"`
}
// ChatAnswerRequest is the chat_answer body: the form id and a field-keyed
// answer object. It is deliberately separate from ChatQuery because its payload
// is structured answers, not a session-scoped read.
+3
View File
@@ -203,6 +203,9 @@ type Message struct {
ChatAnswer *ChatAnswerRequest `json:"chat_answer,omitempty"`
// ChatRename is the chat_rename body; the reply echoes the updated session.
ChatRename *ChatRenameRequest `json:"chat_rename,omitempty"`
// ChatNewSession is the chat_new_session body; the reply carries the
// re-keyed session in ChatSession with PreviousID set.
ChatNewSession *ChatNewSessionRequest `json:"chat_new_session,omitempty"`
// ChatExport is the chat_export body and ChatExportFile its reply.
ChatExport *ChatExportRequest `json:"chat_export,omitempty"`
ChatExportFile *ChatExportFile `json:"chat_export_file,omitempty"`