Merge branch 'worktree-agent-a86b9c8a03da895c2'

This commit is contained in:
2026-11-22 18:24:30 +00:00
9 changed files with 698 additions and 199 deletions
@@ -59,7 +59,14 @@ class ChatRowKeys {
return keys;
}
static List<String> _messageIds(JsonMap row) {
/// A row's ids, held per row object: rows are values (see
/// `transcriptRows`), and an unchanged turn is the same row across builds.
static final Expando<List<String>> _idsOf = Expando('chat row ids');
static List<String> _messageIds(JsonMap row) =>
_idsOf[row] ??= _computeMessageIds(row);
static List<String> _computeMessageIds(JsonMap row) {
// A sent message is the same row before and after the server's copy
// replaces the local one, even if the copy carries another id.
final message = row['message'];
@@ -414,10 +414,7 @@ class ChatThreadController extends ChangeNotifier {
// A frame for a cached message is fresh state the next read must not drop.
final changed = body['message_id'];
if (changed != null) _untouchedCached?.remove(changed);
_messages = (next['messages'] as List? ?? const [])
.whereType<Map>()
.map((message) => Map<String, dynamic>.from(message))
.toList();
_messages = chatMessageList(next['messages']);
_running = next['running'] == true;
if (!_running) {
_liveAssistantMessageId = null;
@@ -234,6 +234,12 @@ class _ChatThreadViewState extends State<ChatThreadView> {
ChatShellRunsController(widget.gateway, widget.sessionId)
..addListener(_reportFinishedRuns);
late ChatRowKeys _rowKeys = ChatRowKeys();
// Keeps the rows of unchanged turns across builds; a streamed delta only
// re-derives the live turn.
ChatTranscriptRows _transcriptRows = ChatTranscriptRows();
// The last [_messageIds] and the message list it was read from.
List<JsonMap>? _idsSource;
List<String> _ids = const [];
final _sentEntrances = ChatSentEntrances();
final _rowWidgets = ChatRowWidgets();
@@ -711,6 +717,7 @@ class _ChatThreadViewState extends State<ChatThreadView> {
_controller = _attach();
_composer = _attachComposer();
_rowKeys = ChatRowKeys();
_transcriptRows = ChatTranscriptRows();
_rowWidgets.clear();
_chrome.clear();
_dismissals = ChatNoticeDismissals();
@@ -797,10 +804,21 @@ class _ChatThreadViewState extends State<ChatThreadView> {
/// The ids of the transcript's messages in view order. Cards are conversation
/// state, not messages, so a pending approval does not count as an arrival.
List<String> _messageIds() => [
for (final message in _visibleMessages())
if ('${message['id'] ?? ''}'.trim().isNotEmpty) '${message['id']}'.trim(),
];
///
/// The controller replaces its message list on every change, so the ids are
/// read once per list rather than on every call within a build.
List<String> _messageIds() {
final messages = _visibleMessages();
if (!identical(messages, _idsSource)) {
_idsSource = messages;
_ids = List.unmodifiable([
for (final message in messages)
if ('${message['id'] ?? ''}'.trim().isNotEmpty)
'${message['id']}'.trim(),
]);
}
return _ids;
}
String? _newestMessageId() {
final ids = _messageIds();
@@ -1119,7 +1137,7 @@ class _ChatThreadViewState extends State<ChatThreadView> {
groupSettledQuestions(
groupSettledPermissions(
withChatShownItems(
transcriptRows(
_transcriptRows.rows(
messages,
trailing: cards,
running: