Navigate to snapshots from the transcript

This commit is contained in:
Ian Gulliver
2026-10-15 00:08:32 -07:00
parent 75c76eff0a
commit c778741a4a
23 changed files with 763 additions and 202 deletions
+49
View File
@@ -29,6 +29,20 @@ func (s *Server) GetTaskChanges(w http.ResponseWriter, r *http.Request, taskID s
return
}
step := params.Step != nil && *params.Step
if params.Snapshot != nil {
if params.Since != nil {
writeError(w, http.StatusBadRequest, errors.New("since and snapshot can't be used together"))
return
}
s.snapshotChanges(w, r, t, p, *params.Snapshot, step)
return
}
if step {
writeError(w, http.StatusBadRequest, errors.New("step needs snapshot"))
return
}
since := ""
if params.Since != nil {
since = *params.Since
@@ -46,6 +60,41 @@ func (s *Server) GetTaskChanges(w http.ResponseWriter, r *http.Request, taskID s
writeJSON(w, http.StatusOK, changes)
}
func (s *Server) snapshotChanges(w http.ResponseWriter, r *http.Request, t api.Task, p api.Project, n int, step bool) {
snap, err := s.store.GetSnapshot(r.Context(), t.Id, n)
if err != nil {
writeStoreError(w, err)
return
}
since := ""
if step {
since, err = s.stepBase(r, t, snap)
if err != nil {
writeStoreError(w, err)
return
}
}
changes, err := git.Compare(t.WorktreePath, p.DefaultBranch, snap.CommitSha, snap.TreeSha, since)
if err != nil {
writeError(w, http.StatusInternalServerError, err)
return
}
writeJSON(w, http.StatusOK, changes)
}
func (s *Server) stepBase(r *http.Request, t api.Task, snap api.Snapshot) (string, error) {
if snap.N == 1 {
return git.Parent(t.WorktreePath, snap.CommitSha)
}
prev, err := s.store.GetSnapshot(r.Context(), t.Id, snap.N-1)
if err != nil {
return "", err
}
return prev.TreeSha, nil
}
func (s *Server) GetTaskDiff(w http.ResponseWriter, r *http.Request, taskID string, params api.GetTaskDiffParams) {
t, err := s.store.GetTask(r.Context(), taskID)
if err != nil {