diff --git a/internal/sessions/agy.go b/internal/sessions/agy.go index 4bb2a934f..cc768a0cd 100644 --- a/internal/sessions/agy.go +++ b/internal/sessions/agy.go @@ -37,8 +37,11 @@ import ( // SYSTEM steps (notices, the errors of a failed request) are agy's own. // What agy calls the conversation, and the folder it was started in, are // its row of conversation_summaries.db beside brain/: title (written by a -// second, small model once the first reply is in, "" until then) and -// workspace_uris, a JSON list of file:// URIs. The steps name no model, so +// second, small model once the first reply is in, "" until then), +// preview (what the app lists the conversation as: the user's own words +// until it has a title, the title after) and workspace_uris, a JSON list +// of file:// URIs. The Antigravity app's language server is agy's, and +// keeps the same database in its own data folder (antigravity_app.go). The steps name no model, so // a conversation's tokens are counted under "agy", as its calls are left // with no model. `agy --conversation ` picks one up again, from any // folder; started on magpie's gateway, it needs the variables and --model @@ -50,18 +53,21 @@ var AgyStart func() string // agySummary is what conversation_summaries.db says of a conversation. type agySummary struct { - Title, Cwd string + Title, Preview, Cwd string // Last is last_modified_time: the time of a conversation that has // no transcript to read it from Last time.Time } -// agySummaries is conversation_summaries.db's rows, read again only when -// the database (or its write-ahead log) changed. A read that fails keeps -// the rows read before. +// agySummaries is each conversation_summaries.db's rows by its path (agy's +// and the Antigravity app's), read again only when the database (or its +// write-ahead log) changed. A read that fails keeps the rows read before. var agySummaries struct { sync.Mutex - path string + read map[string]agySummaryRead +} + +type agySummaryRead struct { rev string rows map[string]agySummary } @@ -79,17 +85,18 @@ func agySummariesOf(dir string) map[string]agySummary { } agySummaries.Lock() defer agySummaries.Unlock() - if agySummaries.path == path && agySummaries.rev == rev { - return agySummaries.rows + was, seen := agySummaries.read[path] + if seen && was.rev == rev { + return was.rows } rows, ok := readAgySummaries(path) if !ok { - if agySummaries.path == path { - return agySummaries.rows - } - return nil + return was.rows } - agySummaries.path, agySummaries.rev, agySummaries.rows = path, rev, rows + if agySummaries.read == nil { + agySummaries.read = map[string]agySummaryRead{} + } + agySummaries.read[path] = agySummaryRead{rev, rows} return rows } @@ -104,8 +111,13 @@ func readAgySummaries(path string) (map[string]agySummary, bool) { return agyRows(db) } +// agyRows reads the rows; a database made before preview was a column is +// read without it. func agyRows(db *sql.DB) (map[string]agySummary, bool) { - rows, err := db.Query("SELECT conversation_id, title, workspace_uris, last_modified_time FROM conversation_summaries") + rows, err := db.Query("SELECT conversation_id, title, preview, workspace_uris, last_modified_time FROM conversation_summaries") + if err != nil { + rows, err = db.Query("SELECT conversation_id, title, '', workspace_uris, last_modified_time FROM conversation_summaries") + } if err != nil { return nil, false } @@ -113,14 +125,14 @@ func agyRows(db *sql.DB) (map[string]agySummary, bool) { out := map[string]agySummary{} for rows.Next() { var id string - var t, ws sql.NullString + var t, p, ws sql.NullString var last any - if rows.Scan(&id, &t, &ws, &last) != nil || id == "" { + if rows.Scan(&id, &t, &p, &ws, &last) != nil || id == "" { continue } var uris []string json.Unmarshal([]byte(ws.String), &uris) - s := agySummary{Title: t.String, Last: agyTime(last)} + s := agySummary{Title: t.String, Preview: p.String, Last: agyTime(last)} for _, u := range uris { if s.Cwd = agyFolder(u, runtime.GOOS); s.Cwd != "" { break @@ -237,7 +249,7 @@ func agyFilesIn(dir string) []file { } func agyRev(r agySummary) string { - return r.Title + "\x00" + r.Cwd + "\x00" + r.Last.UTC().Format(time.RFC3339Nano) + return r.Title + "\x00" + r.Preview + "\x00" + r.Cwd + "\x00" + r.Last.UTC().Format(time.RFC3339Nano) } // agyRowOnly says the file is a conversation's own database, listed from @@ -286,6 +298,9 @@ func parseAgy(f file, old *state) *state { 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 + // no transcript to read the prompt from: what the row lists + // it as until it has a title + s.Title = title(f.m().agy.Preview) if !f.m().agy.Last.IsZero() { s.saw(f.m().agy.Last, true) } @@ -465,6 +480,6 @@ func agyParts(l agyLine) []Part { // forgetAgySummaries forgets the rows read of conversation_summaries.db. func forgetAgySummaries() { agySummaries.Lock() - agySummaries.path, agySummaries.rev, agySummaries.rows = "", "", nil + agySummaries.read = nil agySummaries.Unlock() } diff --git a/internal/sessions/agy_test.go b/internal/sessions/agy_test.go index 7e0471de2..c9103de79 100644 --- a/internal/sessions/agy_test.go +++ b/internal/sessions/agy_test.go @@ -243,3 +243,47 @@ func TestAgyRowOnly(t *testing.T) { t.Fatal("offers a conversation it can't read") } } + +// agy's real row before a title (11-07, agy 1.4.12): title "", preview +// "hi". A conversation listed from its row alone shows that, as there is +// no transcript to read the prompt from. +func TestAgyRowOnlyPreview(t *testing.T) { + dir := putAgy(t) + const id = "93668250-5f30-4171-86c1-8a3692824333" + db, err := sql.Open("sqlite", filepath.Join(dir, "conversation_summaries.db")) + if err != nil { + t.Fatal(err) + } + if _, err := db.Exec(`INSERT INTO conversation_summaries (conversation_id, title, preview, step_count, last_modified_time, workspace_uris, status, project_id, last_user_input_time, app_data_dir) VALUES (?, '', 'hi', 2, '2026-09-25 08:50:46.60116+00:00', '["file:///work/proj"]', 'CASCADE_RUN_STATUS_IDLE', 'default-cli-project', '2026-09-25 08:50:43.784481+00:00', 'antigravity-cli')`, id); err != nil { + t.Fatal(err) + } + db.Close() + os.MkdirAll(filepath.Join(dir, "conversations"), 0o755) + if err := os.WriteFile(filepath.Join(dir, "conversations", id+".db"), []byte("x"), 0o644); err != nil { + t.Fatal(err) + } + if s := find(t, List(0), "agy", id); s.Title != "hi" { + t.Fatalf("row only, no title yet: %q, want its preview", s.Title) + } +} + +// A conversation_summaries.db made before preview was a column is still +// read, its titles and folders with it. +func TestAgyRowsWithoutPreview(t *testing.T) { + path := filepath.Join(t.TempDir(), "conversation_summaries.db") + db, err := sql.Open("sqlite", path) + if err != nil { + t.Fatal(err) + } + defer db.Close() + if _, err := db.Exec("CREATE TABLE `conversation_summaries` (`conversation_id` text,`title` text NOT NULL DEFAULT \"\",`last_modified_time` datetime NOT NULL,`workspace_uris` text NOT NULL,PRIMARY KEY (`conversation_id`))"); err != nil { + t.Fatal(err) + } + if _, err := db.Exec(`INSERT INTO conversation_summaries VALUES ('a', 'Old one', '2026-10-12 04:00:00+00:00', '["file:///work/old"]')`); err != nil { + t.Fatal(err) + } + rows, ok := agyRows(db) + if !ok || rows["a"].Title != "Old one" || rows["a"].Cwd == "" { + t.Fatalf("rows %+v ok %v", rows, ok) + } +} diff --git a/internal/sessions/antigravity_app.go b/internal/sessions/antigravity_app.go index d5d5b9a8d..644496930 100644 --- a/internal/sessions/antigravity_app.go +++ b/internal/sessions/antigravity_app.go @@ -47,6 +47,14 @@ import ( // time as an agy step is (usage's agyGateway: the app sends no session // header). // +// What the app calls a conversation is its row of +// conversation_summaries.db beside conversations/, the database agy keeps +// (agy.go): the app's language server is agy's, and Antigravity 2.29.0's +// makes the same table in ~/.gemini/antigravity on its first start. title +// is the name the app gives it, preview what it lists the conversation as +// before that (the user's own words). Without the row, the steps' text +// being encrypted, a conversation has no name (xxooioo on Discord). +// // A session is listed read only: the app has no command to pick a // conversation up again from a terminal. @@ -67,12 +75,17 @@ func antigravityFiles() []file { return antigravityFilesIn(antigravityConversati // antigravityFilesIn are the conversation databases in dir. A file's size // and time are the database's and its write-ahead log's together, so a -// write that is in the log alone still reads the conversation again. +// write that is in the log alone still reads the conversation again; rev +// is its summary row, so a title the app gives it later does too. func antigravityFilesIn(dir string) []file { if !Reads("antigravity") { return nil } entries, _ := os.ReadDir(dir) + if len(entries) == 0 { + return nil + } + rows := agySummariesOf(filepath.Dir(dir)) var out []file for _, e := range entries { id, ok := strings.CutSuffix(e.Name(), ".db") @@ -89,6 +102,10 @@ func antigravityFilesIn(dir string) []file { f.mod = fi.ModTime() } } + if r, ok := rows[id]; ok { + m := f.w() + m.agy, m.rev = &r, agyRev(r) + } out = append(out, f) } return out @@ -333,7 +350,10 @@ func parseAntigravity(f file) *state { if err != nil { return &state{} } - s := &state{Size: f.size, Mod: f.mod.UnixNano()} + s := &state{Size: f.size, Mod: f.mod.UnixNano(), DBRevision: f.m().rev} + if r := f.m().agy; r != nil { + s.Named, s.Title = title(r.Title), title(r.Preview) + } for _, c := range calls { s.saw(c.at, true) s.use(dateOf(c.at), agAppModelOr(c.model), c.tokens) diff --git a/internal/sessions/antigravity_app_test.go b/internal/sessions/antigravity_app_test.go index f35362adc..3b32f12d5 100644 --- a/internal/sessions/antigravity_app_test.go +++ b/internal/sessions/antigravity_app_test.go @@ -215,3 +215,48 @@ func TestAntigravityAppDeploymentName(t *testing.T) { } } } + +// antigravitySummariesSchema is conversation_summaries.db as Antigravity +// 2.29.0's language_server makes it in ~/.gemini/antigravity on its first +// start (run in a sandbox HOME, 11-07): agy's table, in the app's folder. +const antigravitySummariesSchema = "CREATE TABLE `conversation_summaries` (`conversation_id` text,`title` text NOT NULL DEFAULT \"\",`preview` text NOT NULL DEFAULT \"\",`step_count` integer NOT NULL DEFAULT 0,`last_modified_time` datetime NOT NULL,`workspace_uris` text NOT NULL,`status` text NOT NULL DEFAULT \"\",`source` text NOT NULL DEFAULT \"\",`project_id` text NOT NULL DEFAULT \"\",`agent_name` text NOT NULL DEFAULT \"\",`parent_conversation_id` text NOT NULL DEFAULT \"\",`nesting_depth` integer NOT NULL DEFAULT 0,`battle_id` text NOT NULL DEFAULT \"\",`winning_conversation_id` text NOT NULL DEFAULT \"\",`not_fully_idle` numeric NOT NULL DEFAULT false,`killed` numeric NOT NULL DEFAULT false,`last_user_input_time` datetime NOT NULL,`last_user_input_step_index` integer NOT NULL DEFAULT -1,`app_data_dir` text NOT NULL DEFAULT \"\",`raw_summary` blob,`group_id` text NOT NULL DEFAULT \"\",PRIMARY KEY (`conversation_id`));\n" + + "CREATE INDEX `idx_conversation_summaries_last_user_input_time` ON `conversation_summaries`(`last_user_input_time`);\n" + + "CREATE INDEX `idx_conversation_summaries_last_modified_time` ON `conversation_summaries`(`last_modified_time`);" + +// xxooioo (Discord #help, 11-07): every Antigravity app session read "(no +// prompt)". The app's name for a conversation is its row of +// conversation_summaries.db: before a title, preview holds the user's own +// words (agy's real row: title "", preview "hi"), and once the app names +// it, title. A conversation with no row stays unnamed. +func TestAntigravityAppTitle(t *testing.T) { + claude, _ := setup(t) + home := filepath.Join(filepath.Dir(claude), "home") + const id, other = "37c3c786-9a11-44be-97df-b8fc1ccebc78", "b9eace9a-b15a-4dde-a440-b52e02016fa5" + antigravityFixture(t, home, id) + antigravityFixture(t, home, other) + db, err := sql.Open("sqlite", filepath.Join(home, ".gemini", "antigravity", "conversation_summaries.db")+"?_pragma=journal_mode(WAL)") + if err != nil { + t.Fatal(err) + } + defer db.Close() + if _, err := db.Exec(antigravitySummariesSchema); err != nil { + t.Fatal(err) + } + if _, err := db.Exec("INSERT INTO conversation_summaries (conversation_id, title, preview, step_count, last_modified_time, workspace_uris, status, project_id, last_user_input_time, app_data_dir) VALUES (?, '', '修一下登录页的跳转', 2, '2026-11-07 00:12:46.60116+00:00', '[\"file:///work/site\"]', 'CASCADE_RUN_STATUS_IDLE', 'default-project', '2026-11-07 00:12:43.784481+00:00', 'antigravity')", id); err != nil { + t.Fatal(err) + } + ss := List(0) + if s := find(t, ss, "antigravity", id); s.Title != "修一下登录页的跳转" { + t.Fatalf("before a title: %q, want the preview", s.Title) + } + if s := find(t, ss, "antigravity", other); s.Title != "" { + t.Fatalf("no row: %q", s.Title) + } + + if _, err := db.Exec("UPDATE conversation_summaries SET title = 'Login redirect fix', preview = 'Login redirect fix' WHERE conversation_id = ?", id); err != nil { + t.Fatal(err) + } + if s := find(t, List(0), "antigravity", id); s.Title != "Login redirect fix" { + t.Fatalf("after the app named it: %q", s.Title) + } +} diff --git a/internal/sessions/sessions.go b/internal/sessions/sessions.go index 449fd9d8d..c12152994 100644 --- a/internal/sessions/sessions.go +++ b/internal/sessions/sessions.go @@ -1364,7 +1364,7 @@ func refresh(want, all []file) { if f.cold { continue // in a stopped WSL distro: what was read of it stands } - if s := parsed(f.path); s == nil || s.Size != f.size || s.Mod != f.mod.UnixNano() || ccStale(f, s) || (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 s := parsed(f.path); s == nil || s.Size != f.size || s.Mod != f.mod.UnixNano() || ccStale(f, s) || (f.agent == "hermes" && (f.m().hermes == nil || f.m().rev == "" || s.DBRevision != f.m().rev)) || ((f.agent == "alma" || f.agent == "cursor" || f.agent == "agy" || f.agent == "antigravity") && 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