diff options
Diffstat (limited to 'vrsite/model.go')
| -rw-r--r-- | vrsite/model.go | 52 |
1 files changed, 22 insertions, 30 deletions
diff --git a/vrsite/model.go b/vrsite/model.go index b580b49..10f3f1d 100644 --- a/vrsite/model.go +++ b/vrsite/model.go @@ -2,14 +2,13 @@ // // Everything the site shows is derived here from the vr log alone: agents and // their colors, per-file coverage bitmasks, notes, and live session activity. -// The repo is never written to; the log is the only state. +// The private jj sidecar is the only state. package main import ( "encoding/json" "fmt" "html/template" - "os" "sort" "strings" "time" @@ -29,6 +28,7 @@ type Entry struct { Dir string `json:"dir,omitempty"` Rev string `json:"rev,omitempty"` Change string `json:"change,omitempty"` + Commit string `json:"commit,omitempty"` File string `json:"file,omitempty"` Start int `json:"start,omitempty"` End int `json:"end,omitempty"` @@ -47,16 +47,16 @@ type Agent struct { } type Note struct { - ID int // position in the log, for anchors - NoteID int // the agent's own per-session number - Agent *Agent - Session, Model, Reason string - File, Kind, Text, Change, Rev string - Start, End int - ReplyTo int - Replies, Mentions []*Note // notes that point back to this one - At time.Time - When, Ago string + ID int // position in the log, for anchors + NoteID int // the agent's own per-session number + Agent *Agent + Session, Model, Reason string + File, Kind, Text, Change, Commit, Rev string + Start, End int + ReplyTo int + Replies, Mentions []*Note // notes that point back to this one + At time.Time + When, Ago string } // ThreadNode is the tree-shaped rendering of the note DAG. A note reached by @@ -164,7 +164,7 @@ func buildModel(title string, entries []Entry, only string) *Site { at := parseTime(e.Time) n := &Note{ID: noteN, NoteID: e.NoteID, Agent: a, Session: e.Session, Model: e.Model, Reason: e.Reason, File: e.File, Change: e.Change, - Rev: e.Rev, Start: e.Start, End: e.End, ReplyTo: e.ReplyTo, + Commit: e.Commit, Rev: e.Rev, Start: e.Start, End: e.End, ReplyTo: e.ReplyTo, Kind: e.Type, Text: e.Text, At: at, When: stamp(at), Ago: ago(at)} s.Notes = append(s.Notes, n) @@ -547,7 +547,7 @@ func describe(e Entry) string { return e.Op } -// ── log file ────────────────────────────────────────────────────────────── +// ── sidecar JSONL ───────────────────────────────────────────────────────── func parseLog(b []byte) []Entry { var entries []Entry @@ -563,28 +563,20 @@ func parseLog(b []byte) []Entry { return entries } -func readLog(path string) []Entry { - b, err := os.ReadFile(path) +func readLog(log logStore) []Entry { + b, err := log.Read() if err != nil { fatal("%v", err) } return parseLog(b) } -// appendEntry adds one line to the log. O_APPEND plus a single write keeps it -// interleaving safely with vr processes writing the same file. -func appendEntry(path string, e Entry) error { - b, err := json.Marshal(e) - if err != nil { - return err - } - f, err := os.OpenFile(path, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0o644) - if err != nil { - return err - } - defer f.Close() - _, err = f.Write(append(b, '\n')) - return err +func appendEntry(log logStore, e *Entry) error { + return log.Append(func(current []byte) ([]byte, error) { + e.NoteID = nextNoteID(parseLog(current), e.Session) + b, err := json.Marshal(e) + return append(b, '\n'), err + }) } // ── time ────────────────────────────────────────────────────────────────── |
