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
@@ -80,7 +80,7 @@ class ChatThreadView extends StatefulWidget {
this.scrollPositions,
this.transcripts,
this.initialNotice,
this.onCreatedSession,
this.onNewSession,
this.onSessionRenamed,
this.onSessionClosed,
this.fileBridge = const ArtifactFileBridge(),
@@ -99,10 +99,10 @@ class ChatThreadView extends StatefulWidget {
/// the `/new` notice for a session it just created and opened.
final String? initialNotice;
/// `/new` created this row; the destination lists it, opens it with the
/// notice and refreshes the list. Without a destination the notice shows
/// here instead, since the session already exists on the server.
final ChatCreatedSessionCallback? onCreatedSession;
/// `/new` moved this chat to a fresh native session; the destination swaps
/// the row in place, opens the new id with the notice and refreshes the
/// list. Without a destination the notice shows here instead.
final ChatNewSessionCallback? onNewSession;
/// `/rename` was accepted with this title, so the header can follow it.
final ValueChanged<String>? onSessionRenamed;
@@ -423,22 +423,21 @@ class _ChatThreadViewState extends State<ChatThreadView> {
}
/// The runner for this session's `/new`, `/close` and `/rename`, rebuilt per
/// build so an adopted row's directory and title are the current ones.
/// build so an adopted row's title is the current one.
ChatCommandActions _commandActions() {
final session =
widget.session ?? {'id': widget.sessionId, 'title': widget.title};
final onCreated = widget.onCreatedSession;
final onNewSession = widget.onNewSession;
return ChatCommandActions(
repository: ChatRepository(widget.gateway),
sessionId: widget.sessionId,
directory: '${session['directory'] ?? ''}'.trim(),
showNotice: _showCommandNotice,
confirmClose: () => confirmCloseChat(context, session),
openCreatedSession:
onCreated ?? (created, notice) => _showCommandNotice(notice),
startedNewSession:
onNewSession ??
(previousId, created, notice) => _showCommandNotice(notice),
onRenamed: widget.onSessionRenamed,
onClosed: _sessionClosed,
newOperationId: widget.newOperationId,
);
}