Files
alan 0696ab849a 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.
2026-11-09 16:08:35 +00:00

57 lines
2.5 KiB
Go

package protocol
// Per-turn workspace changes of a chat. At each chat turn the server captures
// the session directory before the turn and compares it afterwards (the same
// bounded internal/filediff capture a pipeline stage visit records). A turn
// that changed files gets one ChatTurnDiffSummary: the transcript shows it as a
// compact chip, and chat_turn_diff fetches that turn's per-file patches. The
// evidence is observed workspace change during the turn, not a claim that the
// agent authored it.
const (
// ChatTurnDiffs is both the push (one new summary for a watched session)
// and the chat_messages companion field: a session's recent summaries.
ChatTurnDiffs = "chat_turn_diffs"
// ChatTurnDiffRequest asks for one turn's recorded file changes.
ChatTurnDiffRequest = "chat_turn_diff"
)
// ChatTurnDiffLimit bounds the summaries kept (and listed) per session.
const ChatTurnDiffLimit = 100
// ChatTurnDiffMessageIDs bounds the assistant message ids one summary names.
const ChatTurnDiffMessageIDs = 16
// ChatTurnDiffSummary is the chip's data for one turn that changed files.
// MessageIDs are the assistant message ids the turn streamed (bounded), so a
// client attaches the chip to the transcript row holding any of them;
// StartedAt/EndedAt (epoch ms) bound the turn for a client that cannot match
// an id. Truncated says the capture was partial or a patch was cut or omitted.
type ChatTurnDiffSummary struct {
TurnID string `json:"turn_id"`
MessageIDs []string `json:"message_ids,omitempty"`
StartedAt int64 `json:"started_at"`
EndedAt int64 `json:"ended_at"`
Files int `json:"files"`
Additions int `json:"additions"`
Deletions int `json:"deletions"`
Truncated bool `json:"truncated,omitempty"`
Status string `json:"status"` // complete | partial
Diagnostic string `json:"diagnostic,omitempty"`
}
// ChatTurnDiffList carries a session's turn summaries, oldest first. It names
// the session so a multi-machine client can re-key it like other chat bodies.
type ChatTurnDiffList struct {
SessionID string `json:"session_id"`
TurnDiffs []ChatTurnDiffSummary `json:"turn_diffs"`
}
// ChatTurnDiff is the chat_turn_diff request (SessionID and TurnID) and its
// reply, which adds the summary and the recorded per-file changes.
type ChatTurnDiff struct {
SessionID string `json:"session_id"`
TurnID string `json:"turn_id"`
Summary *ChatTurnDiffSummary `json:"summary,omitempty"`
Changes *StageFileChanges `json:"changes,omitempty"`
}