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:
@@ -0,0 +1,56 @@
|
||||
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"`
|
||||
}
|
||||
@@ -252,8 +252,13 @@ type Message struct {
|
||||
// ChatQueue is the session's server-held prompt queue: pushed as a
|
||||
// chat_queue frame when it changes and carried by the chat_subscribe and
|
||||
// chat_unqueue replies.
|
||||
ChatQueue *ChatQueueFrame `json:"chat_queue,omitempty"`
|
||||
ChatUnqueue *ChatUnqueueRequest `json:"chat_unqueue,omitempty"`
|
||||
ChatQueue *ChatQueueFrame `json:"chat_queue,omitempty"`
|
||||
// ChatTurnDiffList is the chat_turn_diffs push and the session's recent
|
||||
// turn summaries on a chat_messages reply; ChatTurnDiff is the
|
||||
// chat_turn_diff request and reply (see chat_turn_diff.go).
|
||||
ChatTurnDiffList *ChatTurnDiffList `json:"chat_turn_diffs,omitempty"`
|
||||
ChatTurnDiff *ChatTurnDiff `json:"chat_turn_diff,omitempty"`
|
||||
ChatUnqueue *ChatUnqueueRequest `json:"chat_unqueue,omitempty"`
|
||||
// ChatDirectories carries the operator's directory choices on a
|
||||
// chat_directories response (home first, then recent operator-session
|
||||
// directories, deduplicated and bounded). Additive/omitempty so older peers
|
||||
|
||||
Reference in New Issue
Block a user