Skip to content

Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.

sessions: a listed file is 96 bytes, what only some agents' files have kept behind one pointer

yetone11dcc743f47b
diff --git a/internal/sessions/agy.go b/internal/sessions/agy.go
index 10a71e0ff..4fa395cc9 100644
--- a/internal/sessions/agy.go
+++ b/internal/sessions/agy.go
@@ -212,8 +212,8 @@ func agyFilesIn(dir string) []file {
id := strings.TrimPrefix(out[i].key, "agy:")
has[id] = true
if r, ok := rows[id]; ok {
- out[i].agy = &r
- out[i].rev = agyRev(r)
+ out[i].w().agy = &r
+ out[i].w().rev = agyRev(r)
}
}
for id, r := range rows {
@@ -222,7 +222,8 @@ func agyFilesIn(dir string) []file {
}
f := file{agent: "agy", key: "agy:" + id, path: filepath.Join(dir, "conversations", id+".db"), main: true}
if stat(&f) {
- f.agy, f.rev = &r, agyRev(r)
+ m := f.w()
+ m.agy, m.rev = &r, agyRev(r)
out = append(out, f)
}
}
@@ -276,11 +277,11 @@ const agyModel = "agy"
// the file has only grown (agy appends a step at a time).
func parseAgy(f file, old *state) *state {
if agyRowOnly(f.path) {
- s := &state{Size: f.size, Mod: f.mod.UnixNano(), DBRevision: f.rev}
- if f.agy != nil {
- s.Named, s.Cwd = title(f.agy.Title), f.agy.Cwd
- if !f.agy.Last.IsZero() {
- s.saw(f.agy.Last, true)
+ s := &state{Size: f.size, Mod: f.mod.UnixNano(), DBRevision: f.m().rev}
+ if f.m().agy != nil {
+ s.Named, s.Cwd = title(f.m().agy.Title), f.m().agy.Cwd
+ if !f.m().agy.Last.IsZero() {
+ s.saw(f.m().agy.Last, true)
}
}
return s
@@ -306,10 +307,10 @@ func parseAgy(f file, old *state) *state {
if err == nil {
c.Tail = markTail(f.path, end, 0, end)
}
- s.Size, s.Mod, s.DBRevision = f.size, f.mod.UnixNano(), f.rev
+ s.Size, s.Mod, s.DBRevision = f.size, f.mod.UnixNano(), f.m().rev
s.Named, s.Cwd = "", ""
- if f.agy != nil {
- s.Named, s.Cwd = title(f.agy.Title), f.agy.Cwd
+ if f.m().agy != nil {
+ s.Named, s.Cwd = title(f.m().agy.Title), f.m().agy.Cwd
}
s.Agy = &c
return s
diff --git a/internal/sessions/alma.go b/internal/sessions/alma.go
index a260fdbf1..f38375a7c 100644
--- a/internal/sessions/alma.go
+++ b/internal/sessions/alma.go
@@ -153,13 +153,15 @@ func almaFiles() []file {
agent: "alma",
key: "alma:" + id,
path: path + "#" + url.QueryEscape(id),
- sid: id,
main: true,
size: bytes,
mod: mod,
- alma: st,
- rev: strings.Join([]string{updated, strconv.FormatInt(n, 10), last, strconv.FormatInt(bytes, 10), strconv.FormatInt(usageN, 10), usageLast}, "|"),
readOnly: true,
+ more: &fileMore{
+ sid: id,
+ alma: st,
+ rev: strings.Join([]string{updated, strconv.FormatInt(n, 10), last, strconv.FormatInt(bytes, 10), strconv.FormatInt(usageN, 10), usageLast}, "|"),
+ },
})
}
return out
@@ -227,8 +229,8 @@ func almaModel(model, providerID string) string {
// parseAlma reads one chat in a read transaction, a snapshot while Alma
// writes on.
func parseAlma(f file) *state {
- s := &state{Size: f.size, Mod: f.mod.UnixNano(), DBRevision: f.rev}
- st := f.alma
+ s := &state{Size: f.size, Mod: f.mod.UnixNano(), DBRevision: f.m().rev}
+ st := f.m().alma
if st == nil {
return s
}
@@ -245,7 +247,7 @@ func parseAlma(f file) *state {
}
var named, created string
if err := tx.QueryRow("SELECT "+almaExpr(st.threads, "t", "title", "''")+", "+almaExpr(st.threads, "t", "created_at", "''")+", "+cwd+
- " FROM chat_threads t"+join+" WHERE t.id = ?", f.sid).Scan(&named, &created, &s.Cwd); err != nil {
+ " FROM chat_threads t"+join+" WHERE t.id = ?", f.m().sid).Scan(&named, &created, &s.Cwd); err != nil {
return &state{}
}
if named = title(named); named != "New Chat" {
@@ -259,7 +261,7 @@ func parseAlma(f file) *state {
}
order := almaColumn(st.messages, "timestamp", "created_at")
rows, err := tx.Query("SELECT message, "+hermesExpr(st.messages, "timestamp", "''")+", "+hermesExpr(st.messages, "metadata", "'{}'")+", "+sub+
- " FROM chat_messages WHERE thread_id = ? ORDER BY "+order+", rowid", f.sid)
+ " FROM chat_messages WHERE thread_id = ? ORDER BY "+order+", rowid", f.m().sid)
if err != nil {
return &state{}
}
@@ -342,7 +344,7 @@ func parseAlma(f file) *state {
q := "SELECT " + hermesSelect(table.cols, []string{"model", "provider_id", "timestamp"}, "''") + ", " +
hermesSelect(table.cols, []string{"input_tokens", "cached_input_tokens", "cache_write_input_tokens", "output_tokens"}, "0") +
" FROM " + table.name + " WHERE thread_id = ?"
- rows, err := tx.Query(q, f.sid)
+ rows, err := tx.Query(q, f.m().sid)
if err != nil {
return &state{}
}
diff --git a/internal/sessions/calls_opencode.go b/internal/sessions/calls_opencode.go
index 6e9e98d8f..3d80c4385 100644
--- a/internal/sessions/calls_opencode.go
+++ b/internal/sessions/calls_opencode.go
@@ -56,7 +56,7 @@ func openCodeCallFiles() []file {
out = openCodeDBFilesIn("opencode", path, db, "COUNT(m.id) + COALESCE(SUM(m.time_updated), 0)")
})
for i := range out {
- out[i].oc = nil // the handle is not kept; a read opens it again
+ out[i].w().oc = nil // the handle is not kept; a read opens it again
}
ocCallList.stamp, ocCallList.files = stamp, out
return append([]file(nil), out...)
diff --git a/internal/sessions/calls_zcode.go b/internal/sessions/calls_zcode.go
index b4ae9951d..550d16bf7 100644
--- a/internal/sessions/calls_zcode.go
+++ b/internal/sessions/calls_zcode.go
@@ -52,7 +52,7 @@ func zcodeCallFiles() []file {
out = openCodeDBFilesIn("zcode", path, db, "COUNT(m.id) + COALESCE(SUM(m.time_updated), 0)")
})
for i := range out {
- out[i].oc = nil // the handle is not kept; a read opens it again
+ out[i].w().oc = nil // the handle is not kept; a read opens it again
}
zcCallList.stamp, zcCallList.files = stamp, out
return append([]file(nil), out...)
diff --git a/internal/sessions/cline.go b/internal/sessions/cline.go
index 4b3d2d150..6d6189a7f 100644
--- a/internal/sessions/cline.go
+++ b/internal/sessions/cline.go
@@ -55,7 +55,7 @@ func clineFiles() []file {
// its title and its fork are in the manifest, beside it
m := file{path: filepath.Join(filepath.Dir(p), id+".json")}
if stat(&m) {
- f.manifest = m.path
+ f.w().manifest = m.path
f.size += m.size
if m.mod.After(f.mod) {
f.mod = m.mod
@@ -116,8 +116,8 @@ func parseCline(f file, old *state) *state {
var since, start time.Time
var m clineManifest
hasM := false
- if f.manifest != "" {
- if b, err := os.ReadFile(f.manifest); err == nil && json.Unmarshal(b, &m) == nil {
+ if f.m().manifest != "" {
+ if b, err := os.ReadFile(f.m().manifest); err == nil && json.Unmarshal(b, &m) == nil {
hasM = true
if m.Metadata.Fork != nil {
since, _ = time.Parse(time.RFC3339Nano, m.Metadata.Fork.ForkedAt)
diff --git a/internal/sessions/cursor_editor.go b/internal/sessions/cursor_editor.go
index 0c1746eb1..bad238d15 100644
--- a/internal/sessions/cursor_editor.go
+++ b/internal/sessions/cursor_editor.go
@@ -95,12 +95,12 @@ func cursorEditorFiles(cli []file) []file {
if !safeID.MatchString(id) || seen[id] {
continue
}
- f := file{agent: "cursor", key: "cursor:" + id, sid: id, path: path, main: true, readOnly: true, editor: metas[id]}
+ f := file{agent: "cursor", key: "cursor:" + id, path: path, main: true, readOnly: true, more: &fileMore{sid: id, editor: metas[id]}}
if !stat(&f) || !cursorEditorHasMessages(path) {
continue
}
- if f.editor != nil {
- f.rev = f.editor.revision
+ if f.m().editor != nil {
+ f.w().rev = f.m().editor.revision
}
out = append(out, f)
seen[id] = true
@@ -111,7 +111,7 @@ func cursorEditorFiles(cli []file) []file {
continue
}
b, _ := json.Marshal(m)
- out = append(out, file{agent: "cursor", key: "cursor:" + id, sid: id, path: p + "#" + id, main: true, readOnly: true, editor: m, rev: m.revision, size: int64(len(b)), mod: ms(max(m.Created, m.Updated))})
+ out = append(out, file{agent: "cursor", key: "cursor:" + id, path: p + "#" + id, main: true, readOnly: true, size: int64(len(b)), mod: ms(max(m.Created, m.Updated)), more: &fileMore{sid: id, editor: m, rev: m.revision}})
}
return out
}
@@ -131,8 +131,8 @@ func cursorEditorHasMessages(path string) bool {
}
func parseCursorEditor(f file) *state {
- s := &state{ID: f.sid, Size: f.size, Mod: f.mod.UnixNano(), DBRevision: f.rev}
- if m := f.editor; m != nil {
+ s := &state{ID: f.m().sid, Size: f.size, Mod: f.mod.UnixNano(), DBRevision: f.m().rev}
+ if m := f.m().editor; m != nil {
s.Named = cursorTitle(m.Name)
s.Cwd = m.Workspace.URI.Path
s.saw(ms(m.Created), false)
@@ -159,8 +159,8 @@ func parseCursorEditor(f file) *state {
}
return true
}
- if _, _, ok := cursorEditorDatabasePath(f.path); ok && f.editor != nil && f.editor.db != nil {
- _ = editorMessages(f.editor.db, f.sid, message)
+ if _, _, ok := cursorEditorDatabasePath(f.path); ok && f.m().editor != nil && f.m().editor.db != nil {
+ _ = editorMessages(f.m().editor.db, f.m().sid, message)
} else {
_ = readCursorEditor(f.path, message)
}
diff --git a/internal/sessions/droid.go b/internal/sessions/droid.go
index 3d9eb5602..30597d78d 100644
--- a/internal/sessions/droid.go
+++ b/internal/sessions/droid.go
@@ -93,7 +93,7 @@ func droidFiles() []file {
// what it spent and on which model are in its settings
m := file{path: strings.TrimSuffix(p, ".jsonl") + ".settings.json"}
if stat(&m) {
- f.manifest = m.path
+ f.w().manifest = m.path
f.size += m.size
if m.mod.After(f.mod) {
f.mod = m.mod
@@ -205,9 +205,9 @@ func parseDroid(f file, old *state) *state {
c.Tail = markTail(f.path, end, 0, end)
}
c.Date, c.Model, c.Tokens = "", "", Tokens{}
- if f.manifest != "" {
+ if f.m().manifest != "" {
var st droidSettings
- if b, err := os.ReadFile(f.manifest); err == nil && json.Unmarshal(b, &st) == nil && st.Usage != nil {
+ if b, err := os.ReadFile(f.m().manifest); err == nil && json.Unmarshal(b, &st) == nil && st.Usage != nil {
when := s.Last
if when.IsZero() {
when = time.Unix(0, s.Mod)
diff --git a/internal/sessions/dsh.go b/internal/sessions/dsh.go
index 41de7bc5d..d55501de0 100644
--- a/internal/sessions/dsh.go
+++ b/internal/sessions/dsh.go
@@ -106,7 +106,7 @@ func dshFiles() []file {
dshHeads[f.path] = h
}
seen[f.path] = true
- f.sid = h.ID
+ f.w().sid = h.ID
if h.DelegationDepth > 0 {
parent[h.ID] = h.ParentSession
}
@@ -118,12 +118,12 @@ func dshFiles() []file {
}
}
for i := range out {
- root := out[i].sid
+ root := out[i].m().sid
for n := 0; parent[root] != "" && n < 64; n++ {
root = parent[root]
}
out[i].key = "dsh:" + root
- out[i].main = parent[out[i].sid] == ""
+ out[i].main = parent[out[i].m().sid] == ""
}
return out
}
@@ -133,11 +133,11 @@ func dshFiles() []file {
// the session's generations and its session.lock. "" when the file isn't
// in the folder its id names, so a delete never takes another's.
func dshSessionDir(f file) string {
- if f.agent != "dsh" || f.sid == "" {
+ if f.agent != "dsh" || f.m().sid == "" {
return ""
}
d := filepath.Dir(f.path)
- if filepath.Base(d) != dshSegment(f.sid) || filepath.Dir(filepath.Dir(d)) != filepath.Join(DshDir(), "sessions") {
+ if filepath.Base(d) != dshSegment(f.m().sid) || filepath.Dir(filepath.Dir(d)) != filepath.Join(DshDir(), "sessions") {
return ""
}
return d
diff --git a/internal/sessions/grok.go b/internal/sessions/grok.go
index ea68115a5..fae817814 100644
--- a/internal/sessions/grok.go
+++ b/internal/sessions/grok.go
@@ -96,7 +96,7 @@ func grokFiles() []file {
// its title, its cwd and whose subagent it is are in its summary
m := file{path: filepath.Join(dir, "summary.json")}
if stat(&m) {
- f.manifest = m.path
+ f.w().manifest = m.path
f.size += m.size
if m.mod.After(f.mod) {
f.mod = m.mod
@@ -178,8 +178,8 @@ func parseGrok(f file, old *state) *state {
var c grokCarry
var m grokSummary
hasM := false
- if f.manifest != "" {
- if m, hasM = readGrokSummary(f.manifest); hasM {
+ if f.m().manifest != "" {
+ if m, hasM = readGrokSummary(f.m().manifest); hasM {
c.Model = m.CurrentModel
c.Created, _ = time.Parse(time.RFC3339Nano, m.CreatedAt)
if m.Parent != "" {
diff --git a/internal/sessions/hermes.go b/internal/sessions/hermes.go
index 16185443c..2725fa75b 100644
--- a/internal/sessions/hermes.go
+++ b/internal/sessions/hermes.go
@@ -342,12 +342,14 @@ func hermesFiles() []file {
agent: "hermes",
key: "hermes:" + id,
path: path + "#" + url.QueryEscape(sid),
- sid: sid,
main: true,
mod: mod,
- hermes: store,
- rev: prints[sid], // "" when unknown: parsed again
readOnly: true,
+ more: &fileMore{
+ sid: sid,
+ hermes: store,
+ rev: prints[sid], // "" when unknown: parsed again
+ },
})
}
rows.Close()
@@ -572,23 +574,23 @@ func (h *hermesDB) eachMessage(q hermesQuery, sid string, fn func(hermesMessage)
// the WAL: usage and titles can change without a DB-file mtime change.
func parseHermes(f file) *state {
s := &state{Size: f.size, Mod: f.mod.UnixNano()}
- if f.hermes == nil {
+ if f.m().hermes == nil {
return s
}
// The connection enforces mode=ro; the transaction needs only a snapshot.
- tx, err := f.hermes.db.BeginTx(context.Background(), nil)
+ tx, err := f.m().hermes.db.BeginTx(context.Background(), nil)
if err != nil {
return s
}
defer tx.Rollback()
- u, err := f.hermes.metadata(tx, f.sid, s)
+ u, err := f.m().hermes.metadata(tx, f.m().sid, s)
if err != nil {
return &state{}
}
// Activity comes from message gaps, not the entire duration of the session.
last := s.Last
s.Last = s.Start
- if err := f.hermes.eachMessage(tx, f.sid, func(m hermesMessage) {
+ if err := f.m().hermes.eachMessage(tx, f.m().sid, func(m hermesMessage) {
at := hermesTime(m.at)
s.saw(at, true)
d := s.day(dateOf(at))
@@ -610,7 +612,7 @@ func parseHermes(f file) *state {
if last.After(s.Last) {
s.Last = last
}
- usage, err := f.hermes.usages(tx, f.sid, u)
+ usage, err := f.m().hermes.usages(tx, f.m().sid, u)
if err != nil {
return &state{}
}
@@ -624,7 +626,7 @@ func parseHermes(f file) *state {
s.Last = at
}
}
- s.DBRevision = f.rev
+ s.DBRevision = f.m().rev
return s
}
diff --git a/internal/sessions/hermes_fingerprint_test.go b/internal/sessions/hermes_fingerprint_test.go
index 47922716a..729ce1b30 100644
--- a/internal/sessions/hermes_fingerprint_test.go
+++ b/internal/sessions/hermes_fingerprint_test.go
@@ -83,7 +83,7 @@ func TestHermesUnreadFingerprintsParseAgain(t *testing.T) {
}
// the same size and time as what was parsed: only the fingerprint can
// tell it changed, and it is unknown
- f := file{agent: "hermes", path: path + "#s", hermes: h, rev: "", mod: time.Unix(1790000000, 0)}
+ f := file{agent: "hermes", path: path + "#s", more: &fileMore{hermes: h}, mod: time.Unix(1790000000, 0)}
s := state{Mod: f.mod.UnixNano(), DBRevision: ""}
cache = map[string]*state{f.path: &s}
t.Cleanup(func() { cache = nil })
@@ -130,7 +130,7 @@ func TestHermesStoreResolvedOncePerListing(t *testing.T) {
if got := int(n.Load()); got >= len(files) {
t.Fatalf("the store's path was resolved %d times for %d sessions", got, len(files))
}
- if want := "hermes:" + hermesID(path, files[0].sid); files[0].key != want {
+ if want := "hermes:" + hermesID(path, files[0].m().sid); files[0].key != want {
t.Fatalf("key %q, want %q", files[0].key, want)
}
}
diff --git a/internal/sessions/hermes_test.go b/internal/sessions/hermes_test.go
index 16cfbf9b4..1de578b84 100644
--- a/internal/sessions/hermes_test.go
+++ b/internal/sessions/hermes_test.go
@@ -240,7 +240,7 @@ func TestHermesOlderSchemaAndNullFields(t *testing.T) {
defer closeDBs()
found := false
for _, f := range hermesFiles() {
- if f.sid == "old" {
+ if f.m().sid == "old" {
found = true
st := parseHermes(f)
if st == nil || st.Title != "hello" || !st.Start.IsZero() {
diff --git a/internal/sessions/manage.go b/internal/sessions/manage.go
index ab383f0dd..5bdb8677b 100644
--- a/internal/sessions/manage.go
+++ b/internal/sessions/manage.go
@@ -416,7 +416,7 @@ func sessionPaths(agent, id string, fs []file) []string {
}
for _, f := range fs {
add(dshSessionDir(f))
- add(dshCacheRecord(f.sid))
+ add(dshCacheRecord(f.m().sid))
}
return out
}
@@ -446,16 +446,16 @@ func sessionPaths(agent, id string, fs []file) []string {
if agent == "droid" {
// each transcript's settings beside it: what it spent, its model
for _, f := range fs {
- if f.manifest != "" && !inside(f.manifest, out) {
- add(f.manifest)
+ if f.m().manifest != "" && !inside(f.m().manifest, out) {
+ add(f.m().manifest)
}
}
}
if agent == "claude" {
dir := ClaudeDir()
- if fs[0].wsl != "" {
+ if fs[0].m().wsl != "" {
// the distro's own ~/.claude
- if dir = wslHomeOf(fs[0].wsl); dir == "" {
+ if dir = wslHomeOf(fs[0].m().wsl); dir == "" {
return out
}
dir = filepath.Join(dir, ".claude")
diff --git a/internal/sessions/opencode.go b/internal/sessions/opencode.go
index 60e1fff8c..7d437d3de 100644
--- a/internal/sessions/opencode.go
+++ b/internal/sessions/opencode.go
@@ -157,13 +157,13 @@ func fileExists(p string) bool {
// at the top: a subagent's subagent counts there too.
func ocRoots(out []file, parent map[string]string) []file {
for i := range out {
- root := out[i].sid
+ root := out[i].m().sid
for n := 0; parent[root] != "" && n < 64; n++ {
root = parent[root]
}
out[i].key = out[i].agent + ":" + root
- out[i].parent = parent[out[i].sid]
- out[i].main = out[i].parent == ""
+ out[i].w().parent = parent[out[i].m().sid]
+ out[i].main = out[i].m().parent == ""
}
return out
}
@@ -270,7 +270,7 @@ func ocDBRows(db *sql.DB, query, agent, path string, store ocStore, parent map[s
continue
}
parent[id] = par
- out = append(out, file{agent: agent, path: path + "#" + id, sid: id, oc: store, size: n, mod: ms(max(updated, last))})
+ out = append(out, file{agent: agent, path: path + "#" + id, size: n, mod: ms(max(updated, last)), more: &fileMore{sid: id, oc: store}})
}
return out
}
@@ -413,7 +413,7 @@ func openCodeJSONFiles(root string) []file {
if err != nil || json.Unmarshal(b, &i) != nil || i.ID == "" {
continue
}
- f := file{agent: "opencode", path: p, sid: i.ID, oc: store}
+ f := file{agent: "opencode", path: p, more: &fileMore{sid: i.ID, oc: store}}
if !stat(&f) {
continue
}
@@ -467,10 +467,10 @@ func (s ocFiles) parts(mid string) [][]byte { return s.docs(filepath.Join("pa
// place as its reply goes on, so there is no reading on from before.
func parseOpenCode(f file) *state {
s := &state{Size: f.size, Mod: f.mod.UnixNano()}
- if f.oc == nil {
+ if f.m().oc == nil {
return s
}
- info, ok := f.oc.info(f.sid)
+ info, ok := f.m().oc.info(f.m().sid)
if !ok {
return s
}
@@ -479,7 +479,7 @@ func parseOpenCode(f file) *state {
s.Named = t
}
var msgs []ocMessage
- for _, b := range f.oc.messages(f.sid) {
+ for _, b := range f.m().oc.messages(f.m().sid) {
var m ocMessage
if json.Unmarshal(b, &m) == nil {
msgs = append(msgs, m)
@@ -498,7 +498,7 @@ func parseOpenCode(f file) *state {
switch m.Role {
case "user":
if typed := m.Semantics == nil || m.Semantics.Origin == "" || m.Semantics.Origin == "real_user"; typed && f.main && s.Title == "" && s.First == "" {
- ocTitle(s, f.oc.parts(m.ID))
+ ocTitle(s, f.m().oc.parts(m.ID))
}
case "assistant":
if done := ms(m.Time.Completed); !done.IsZero() {
diff --git a/internal/sessions/sessions.go b/internal/sessions/sessions.go
index 652f7b2e1..ca9c1fb3c 100644
--- a/internal/sessions/sessions.go
+++ b/internal/sessions/sessions.go
@@ -361,14 +361,26 @@ func (s *state) clone() *state {
return &c
}
-// file is one session file found on disk.
+// file is one session file found on disk. What only some agents' files
+// have is in more, so a listing of every rollout copies 96 bytes a file,
+// not 232: a Sessions poll copied every agent's list of ~20k files five
+// or six times over, ~50 MB a poll.
type file struct {
- agent string
- key string // agent:session id — a session may span files
- path string
- main bool // the session's own file, not a subagent's
- size int64
- mod time.Time
+ agent string
+ key string // agent:session id — a session may span files
+ path string
+ size int64
+ mod time.Time
+ main bool // the session's own file, not a subagent's
+ readOnly bool
+ // cold: the WSL distro the file is in isn't running, and the file, as
+ // last listed, is not to be opened (that would start the distro)
+ cold bool
+ more *fileMore // nil for a file with none of it; shared by copies
+}
+
+// fileMore is what a file of some agents has besides.
+type fileMore struct {
// OpenCode and ZCode: the session, and where it is kept; parent is
// the session that started it, "" for one the user did
sid string
@@ -383,14 +395,25 @@ type file struct {
alma *almaStore
rev string
// agy: what conversation_summaries.db says of the conversation
- agy *agySummary
- readOnly bool
- editor *cursorEditorMeta
- // wsl: the WSL distro whose home it is in; cold: that distro isn't
- // running, and the file, as last listed, is not to be opened (that
- // would start the distro)
- wsl string
- cold bool
+ agy *agySummary
+ editor *cursorEditorMeta
+ // wsl: the WSL distro whose home it is in
+ wsl string
+}
+
+// m is what more holds, or none of it. It is a copy: a write goes through w.
+func (f file) m() fileMore {
+ if f.more == nil {
+ return fileMore{}
+ }
+ return *f.more
+}
+
+// w is f's own more to write: copies of f share it, so it is copied first.
+func (f *file) w() *fileMore {
+ m := f.m()
+ f.more = &m
+ return f.more
}
// byKey groups the files keep takes by session, each group in the files'
@@ -1068,7 +1091,7 @@ func refresh(want, all []file) {
if f.cold {
continue // in a stopped WSL distro: what was read of it stands
}
- if s := cache[f.path]; s == nil || s.Size != f.size || s.Mod != f.mod.UnixNano() || (f.agent == "hermes" && (f.hermes == nil || f.rev == "" || s.DBRevision != f.rev)) || ((f.agent == "alma" || f.agent == "cursor" || f.agent == "agy") && s.DBRevision != f.rev) {
+ if s := cache[f.path]; s == nil || s.Size != f.size || s.Mod != f.mod.UnixNano() || (f.agent == "hermes" && (f.m().hermes == nil || f.m().rev == "" || s.DBRevision != f.m().rev)) || ((f.agent == "alma" || f.agent == "cursor" || f.agent == "agy") && s.DBRevision != f.m().rev) {
if parsing[f.path] != nil {
// a refresh is reading it, another or this one (a path
// listed twice): its last parse stands until that one is
@@ -1467,7 +1490,7 @@ func assemble(fs []file, price func(string) *catalog.Price, codexTitle func(stri
// subagent's file again (3.5 GB of a live magpie's 6.3 GB of scans).
func assembleListed(fs []file, price func(string) *catalog.Price, codexTitle func(string) string) (Session, bool) {
sortSessionFiles(fs)
- s := Session{Agent: fs[0].agent, Path: fs[0].path, Models: []Model{}, WSL: fs[0].wsl}
+ s := Session{Agent: fs[0].agent, Path: fs[0].path, Models: []Model{}, WSL: fs[0].m().wsl}
for _, f := range fs {
s.ReadOnly = s.ReadOnly || f.readOnly
}
diff --git a/internal/sessions/subagents.go b/internal/sessions/subagents.go
index b520c5b97..73cec8928 100644
--- a/internal/sessions/subagents.go
+++ b/internal/sessions/subagents.go
@@ -62,16 +62,16 @@ func subagentsOf(s Session, fs []file) []Subagent {
sa.Title = ccTask(f.path)
}
case "opencode":
- sa.ID = f.sid
- if f.parent != s.ID {
- sa.Parent = f.parent
+ sa.ID = f.m().sid
+ if f.m().parent != s.ID {
+ sa.Parent = f.m().parent
}
sa.Title, sa.Kind = ocSubagentTitle(st.Named)
sa.Title = cmp.Or(sa.Title, st.Title, st.First)
// OpenCode 2 names the agent in the session's row, and its
// titles no longer do (#2290)
- if v2, ok := f.oc.(ocV2DB); ok {
- sa.Kind = cmp.Or(v2.agent(f.path, f.sid), sa.Kind)
+ if v2, ok := f.m().oc.(ocV2DB); ok {
+ sa.Kind = cmp.Or(v2.agent(f.path, f.m().sid), sa.Kind)
}
case "kimi":
sa.ID = filepath.Base(filepath.Dir(f.path))
diff --git a/internal/sessions/traces_opencode.go b/internal/sessions/traces_opencode.go
index 0de387929..c1aef883a 100644
--- a/internal/sessions/traces_opencode.go
+++ b/internal/sessions/traces_opencode.go
@@ -31,7 +31,7 @@ func traceOpenCodeWindow(files []file) []file {
func traceOCMessages(f file, budget *int64) [][]byte {
var out [][]byte
- for _, b := range f.oc.messages(f.sid) {
+ for _, b := range f.m().oc.messages(f.m().sid) {
if *budget <= 0 {
break
}
@@ -42,7 +42,7 @@ func traceOCMessages(f file, budget *int64) [][]byte {
}
func traceOCParts(f file, mid string, budget *int64) [][]byte {
var out [][]byte
- for _, b := range f.oc.parts(mid) {
+ for _, b := range f.m().oc.parts(mid) {
if *budget <= 0 {
break
}
@@ -83,8 +83,8 @@ func (r *TraceReader) pollOpenCode(bodies bool, budget *int64) []TraceSpan {
}
files := openCodeJSONFiles(filepath.Join(OpenCodeDir(), "storage"))
for i, f := range files {
- if store, ok := f.oc.(ocFiles); ok {
- for _, message := range readDirectory(filepath.Join(store.root, "message", f.sid)) {
+ if store, ok := f.m().oc.(ocFiles); ok {
+ for _, message := range readDirectory(filepath.Join(store.root, "message", f.m().sid)) {
mid := strings.TrimSuffix(message.Name(), ".json")
for _, part := range readDirectory(filepath.Join(store.root, "part", mid)) {
if info, err := part.Info(); err == nil && info.Mode().IsRegular() {
@@ -132,7 +132,7 @@ func (r *TraceReader) pollOpenCode(bodies bool, budget *int64) []TraceSpan {
m.ModelID = m.Model.ID
m.ProviderID = m.Model.ProviderID
}
- if _, ok := f.oc.(ocV2DB); !ok {
+ if _, ok := f.m().oc.(ocV2DB); !ok {
for _, p := range traceOCParts(f, m.ID, &localBudget) {
var part ocTracePart
if json.Unmarshal(p, &part) == nil {
@@ -148,7 +148,7 @@ func (r *TraceReader) pollOpenCode(bodies bool, budget *int64) []TraceSpan {
continue
}
*budget -= (32 << 20) - localBudget
- out = append(out, r.observations(s, traceOpenCode(f.sid, messages, bodies))...)
+ out = append(out, r.observations(s, traceOpenCode(f.m().sid, messages, bodies))...)
s.size, s.mod = f.size, f.mod
}
for path := range r.snapshots {
diff --git a/internal/sessions/traces_opencode_db.go b/internal/sessions/traces_opencode_db.go
index 74140ee54..fd93c9dcf 100644
--- a/internal/sessions/traces_opencode_db.go
+++ b/internal/sessions/traces_opencode_db.go
@@ -75,7 +75,7 @@ func (r *TraceReader) pollOpenCodeDB(path string, bodies bool, budget *int64) ([
}
snap := r.snapshot(key)
v2 := false
- if _, ok := f.oc.(ocV2DB); ok {
+ if _, ok := f.m().oc.(ocV2DB); ok {
v2 = true
}
if snap.oc == nil || snap.oc.v2 != v2 {
@@ -90,10 +90,10 @@ func (r *TraceReader) pollOpenCodeDB(path string, bodies bool, budget *int64) ([
}
// A row too large for the retained body window is read as metadata;
// body export is bounded independently from traversal progress.
- more, ok := state.readRows(db, table, kind, f.sid, false, bodies, budget, changed)
+ more, ok := state.readRows(db, table, kind, f.m().sid, false, bodies, budget, changed)
pending = pending || more || !ok
if !v2 && *budget > 0 {
- more, ok = state.readRows(db, "part", "''", f.sid, true, bodies, budget, changed)
+ more, ok = state.readRows(db, "part", "''", f.m().sid, true, bodies, budget, changed)
pending = pending || more || !ok
}
// Part-only updates may refer to messages evicted from the body window.
@@ -103,7 +103,7 @@ func (r *TraceReader) pollOpenCodeDB(path string, bodies bool, budget *int64) ([
continue
}
var raw []byte
- if db.QueryRow(`SELECT CASE WHEN length(data)>8388608 THEN json_remove(data,'$.text','$.content') ELSE data END FROM message WHERE id=? AND session_id=?`, mid, f.sid).Scan(&raw) == nil {
+ if db.QueryRow(`SELECT CASE WHEN length(data)>8388608 THEN json_remove(data,'$.text','$.content') ELSE data END FROM message WHERE id=? AND session_id=?`, mid, f.m().sid).Scan(&raw) == nil {
*budget -= int64(len(raw))
var doc ocTraceMessage
if json.Unmarshal(raw, &doc) == nil {
@@ -134,7 +134,7 @@ func (r *TraceReader) pollOpenCodeDB(path string, bodies bool, budget *int64) ([
continue
}
m.ParentID = user.ID
- spans := traceOpenCode(f.sid, []ocTraceMessage{user, m}, bodies)
+ spans := traceOpenCode(f.m().sid, []ocTraceMessage{user, m}, bodies)
for i, span := range spans {
if span.Parent != "" {
continue
diff --git a/internal/sessions/transcript_opencode.go b/internal/sessions/transcript_opencode.go
index 92b6d7fc4..d6998ca67 100644
--- a/internal/sessions/transcript_opencode.go
+++ b/internal/sessions/transcript_opencode.go
@@ -22,10 +22,10 @@ func openCodeTranscript(s Session, add func(bool, Part) bool) error {
mu.Unlock()
}()
for _, f := range files {
- if f.sid != s.ID {
+ if f.m().sid != s.ID {
continue
}
- if v, ok := f.oc.(ocV2DB); ok {
+ if v, ok := f.m().oc.(ocV2DB); ok {
rows, err := v.db.Query("SELECT type,data FROM session_message WHERE session_id=? AND type IN ('user','assistant') ORDER BY seq", s.ID)
if err != nil {
return err
@@ -62,7 +62,7 @@ func openCodeTranscript(s Session, add func(bool, Part) bool) error {
return rows.Err()
}
var messages []ocMessage
- for _, b := range f.oc.messages(f.sid) {
+ for _, b := range f.m().oc.messages(f.m().sid) {
var m ocMessage
if json.Unmarshal(b, &m) == nil {
messages = append(messages, m)
@@ -75,7 +75,7 @@ func openCodeTranscript(s Session, add func(bool, Part) bool) error {
return messages[i].ID < messages[j].ID
})
for _, m := range messages {
- for _, p := range f.oc.parts(m.ID) {
+ for _, p := range f.m().oc.parts(m.ID) {
if !openCodeTranscriptPart(m.Role, m.ModelID, p, add) {
return nil
}
diff --git a/internal/sessions/wsl.go b/internal/sessions/wsl.go
index 568403c85..e3fd2ee45 100644
--- a/internal/sessions/wsl.go
+++ b/internal/sessions/wsl.go
@@ -190,9 +190,10 @@ func wslFiles(agents ...string) []file {
for _, n := range names {
l := wslSess.lists[n]
cold := !l.Running || !up[n]
+ in := &fileMore{wsl: n} // the distro's files share it
for _, e := range l.Files {
if want[e.Agent] {
- out = append(out, file{agent: e.Agent, key: e.Key, path: e.Path, main: e.Main, size: e.Size, mod: e.Mod, wsl: n, cold: cold})
+ out = append(out, file{agent: e.Agent, key: e.Key, path: e.Path, main: e.Main, size: e.Size, mod: e.Mod, more: in, cold: cold})
}
}
}
@@ -329,7 +330,7 @@ func wslHomeOf(distro string) string {
func wslForget(fs []file) {
gone := map[string]bool{}
for _, f := range fs {
- if f.wsl != "" {
+ if f.m().wsl != "" {
gone[f.path] = true
}
}