Record each chat turn's workspace changes for every harness

Snapshot the chat directory with internal/filediff when a turn starts and
compare it when the turn ends; store changed turns (newest 100 per chat),
push chat_turn_diffs summaries, attach them to chat_messages replies and
serve one turn's patches through chat_turn_diff.
This commit is contained in:
2026-11-09 16:08:35 +00:00
parent 57679d9591
commit 0696ab849a
12 changed files with 798 additions and 2 deletions
+6
View File
@@ -346,6 +346,8 @@ func (h *chatHub) releaseRoomLocked(room *chatRoom) {
h.rememberLiveLocked(room.sessionID)
h.clearCompactionLocked(room)
delete(h.rooms, room.sessionID)
// A turn whose end this room can no longer see keeps no stale baseline.
h.dropTurnDiffLocked(room.sessionID)
room.cancel()
// An unobserved session reports no turn and no background tasks.
h.noteActivityLocked(room.sessionID)
@@ -458,6 +460,7 @@ func (h *chatHub) emitRoom(source *chatRoom, frame protocol.ChatEventFrame) {
priorStep = h.turnLocked(frame.SessionID).step
}
h.applyLocked(frame)
h.noteTurnDiffLocked(room, frame)
h.noteFormAttentionLocked(frame)
h.noteReplyAttentionLocked(priorStep, frame)
buffered := false
@@ -834,6 +837,8 @@ func (h *chatHub) runTurn(room *chatRoom, p *chatQueuedPrompt, done chan struct{
h.endRoomTurn(room)
return
}
// The turn's baseline is read before its prompt can change anything.
h.startRoomTurnDiff(room.sessionID)
if first {
if err := h.ensureObserving(room, broker); err != nil {
h.failPrompt(room, p, err)
@@ -885,6 +890,7 @@ func (h *chatHub) runTurn(room *chatRoom, p *chatQueuedPrompt, done chan struct{
// comes.
func (h *chatHub) endRoomTurn(room *chatRoom) {
h.mu.Lock()
h.dropTurnDiffLocked(room.sessionID)
h.finishTurnLocked(room)
h.mu.Unlock()
}