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
+16 -16
View File
@@ -29,7 +29,7 @@ const String chatCommandHelp = 'help';
const List<ChatCommand> chatCommands = <ChatCommand>[
ChatCommand(
name: chatCommandNew,
summary: 'Start a fresh session in this directory',
summary: 'Clear the context: continue this chat in a fresh session',
usage: '/new',
),
ChatCommand(
@@ -131,8 +131,8 @@ String chatUnknownCommandReport(String word) =>
String chatCommandUnavailableReport(String word) =>
'“$word” is not available yet, so nothing was sent to the agent.';
/// The behaviour brief a `/new` session is created with, verbatim from the web
/// client's `DEFAULT_CHAT_INSTRUCTIONS`.
/// The behaviour brief a new chat, and a `/new` fresh session, starts with,
/// verbatim from the web client's `DEFAULT_CHAT_INSTRUCTIONS`.
const String chatDefaultSessionInstructions =
"Act as a careful coding agent. Read the repository's AGENTS.md and the "
'relevant skills before acting. Inspect the current state, keep changes '
@@ -140,9 +140,6 @@ const String chatDefaultSessionInstructions =
'changed and what was not verified. Ask only about real ambiguity, '
'destructive actions or changes outside the request.';
/// The title every `/new` session is created with, as the web client sends it.
const String chatNewSessionTitle = 'New chat';
/// `/new` and `/close` act on the open session alone, so an argument is a
/// usage error the web reports in these exact words.
String chatCommandArgumentReport(ChatCommand command) =>
@@ -152,18 +149,21 @@ String chatCommandArgumentReport(ChatCommand command) =>
const String chatRenameUsageReport =
'Usage: /rename <title> — renames this session.';
/// `/new` needs the open session's directory; without one nothing is sent.
const String chatNoDirectoryReport =
"Can't start a new session here: the server reported no directory for "
'this chat.';
/// The line the fresh conversation opens on after `/new`: the chat is the
/// same, the agent's context is empty.
const String chatNewSessionNotice =
'New session started. The agent no longer sees the earlier conversation; '
'the previous session can still be resumed in a terminal.';
/// The notice the created session opens with.
String chatSessionStartedNotice(String title, String directory) =>
'Started a new session “$title” in $directory.';
/// The line a conversation opens on when another device started its new
/// session.
const String chatNewSessionElsewhereNotice =
'Another device started a new session in this chat. The agent no longer '
'sees the earlier conversation.';
/// The failed notice the current session shows when the create is refused.
String chatSessionStartFailedNotice(String directory, String reason) =>
"Couldn't start a new session in $directory: $reason";
/// The failed notice the current session shows when `/new` is refused.
String chatNewSessionFailedNotice(String reason) =>
"Couldn't start a new session: $reason";
/// The notice after the server accepted the shared rename.
String chatSessionRenamedNotice(String title) =>