summaryrefslogtreecommitdiff
path: root/vrsite/model.go
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-08-02 12:36:54 -0300
committerGabriel Schneider <[email protected]>2026-08-02 17:37:58 -0300
commite16f78b255bcf46d8c6f9a4b9e76dd7a3817edeb (patch)
treede0db0c369522b5bf92ff32a8351de2224c5c9dc /vrsite/model.go
parent151ea12251ed876aa87bb486da1bc337e25369e9 (diff)
downloadnotevi-e16f78b255bcf46d8c6f9a4b9e76dd7a3817edeb.tar.gz
notevi-e16f78b255bcf46d8c6f9a4b9e76dd7a3817edeb.zip
Diffstat (limited to 'vrsite/model.go')
-rw-r--r--vrsite/model.go52
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 ──────────────────────────────────────────────────────────────────