diff --git a/docs/subsystems/gateway-sessions.md b/docs/subsystems/gateway-sessions.md index c09ae57b6..8f99a22a5 100644 --- a/docs/subsystems/gateway-sessions.md +++ b/docs/subsystems/gateway-sessions.md @@ -1019,10 +1019,22 @@ including response folding and gateway matching. Insiders session ids have an `insiders-` prefix in magpie, leaving stable ids unchanged and keeping equal UUIDs in the two stores from sharing a session or call id. The files themselves are not renamed. Sessions stay read-only with no -terminal resume command; encrypted conversation text is not read. +terminal resume command. The database's step text is encrypted and not +read; what was said is read from the plain-text transcript the app writes +beside it, `brain//.system_generated/logs/transcript_full.jsonl` in the +same store (`antigravityTranscript`), in agy's format and through agy's +reader (`agyTranscript`): the user's turns, the replies, each tool call and +its result, on the session viewer, search and the Markdown export +(@yansheng1003 on X: only the title and preview showed). Its size and time +are counted into the session file's with the `-wal`'s, so a step it adds +reads the session again. A conversation with no transcript is +`ErrNoTranscript`, as before. Verification: `TestAntigravityInsidersSessions` covers Insiders alone, both stores with the same UUID, per-model tokens, call ids, summary refresh and turning the existing reading choice off, using #2190's real step bytes. +`TestAntigravityAppTranscript` reads a conversation the app's 2.30 language +server had with a read_file call (testdata/antigravity-2.30-tools) from +stable, Insiders and a WSL distro's store; `TestAntigravityAppNoTranscript`. A read of every call decodes each file's cached shard, and over a long history that is tens of thousands of files (#2278: 68k shards, 415 MB). diff --git a/internal/gui/sessions_antigravity_test.go b/internal/gui/sessions_antigravity_test.go new file mode 100644 index 000000000..851141ffa --- /dev/null +++ b/internal/gui/sessions_antigravity_test.go @@ -0,0 +1,82 @@ +package gui + +import ( + "encoding/json" + "net/http" + "net/http/httptest" + "path/filepath" + "strings" + "testing" + + "github.com/yetone/magpie/internal/sessions" + "github.com/yetone/magpie/internal/settings" +) + +// @yansheng1003 on X: an Antigravity 2.0 conversation showed only its +// title and preview. The Sessions list marks it as one whose conversation +// can be shown, and /api/sessions/transcript, which Show conversation +// asks, gives what was said: the user's turn, the replies, the tool call +// and its result, read from the transcript the app's 2.30 language server +// wrote (sessions' testdata/antigravity-2.30-tools). +func TestSessionAntigravityConversation(t *testing.T) { + h := sandboxHome(t) + copyTree(t, "../sessions/testdata/antigravity-2.30-tools", filepath.Join(h, ".gemini", "antigravity")) + if err := settings.SetSessionReads(func(*settings.SessionReads) *settings.SessionReads { + return &settings.SessionReads{Asked: true, All: true} + }); err != nil { + t.Fatal(err) + } + sessions.Reset() + t.Cleanup(sessions.Reset) + const id = "a9b3e500-3594-49ed-b821-3418225e1990" + mux := http.NewServeMux() + sessionRoutes(mux, folderOnly{}) + get := func(path string) []byte { + t.Helper() + w := httptest.NewRecorder() + mux.ServeHTTP(w, httptest.NewRequest("GET", path, nil)) + if w.Code != 200 { + t.Fatalf("%s: %d %s", path, w.Code, w.Body) + } + return w.Body.Bytes() + } + var list struct { + Sessions []struct { + Agent, ID string + Transcript bool + } + } + if err := json.Unmarshal(get("/api/sessions"), &list); err != nil { + t.Fatal(err) + } + listed := false + for _, s := range list.Sessions { + if s.Agent == "antigravity" && s.ID == id { + listed = true + if !s.Transcript { + t.Fatalf("listed with no conversation to show: %+v", s) + } + } + } + if !listed { + t.Fatalf("not listed: %+v", list.Sessions) + } + var tr sessions.Transcript + if err := json.Unmarshal(get("/api/sessions/transcript?agent=antigravity&id="+id), &tr); err != nil { + t.Fatal(err) + } + var said []string + for _, p := range tr.Parts { + said = append(said, p.Role+"/"+p.Kind+"/"+p.Name+": "+p.Text) + } + want := []string{ + "user/text/: read a.txt", + "assistant/text/: Let me read it.", + `assistant/tool_use/read_file: {"Path":"C:\\Users\\yeton\\agyss\\e2e4\\home\\proj\\a.txt"}`, + "tool/tool_result/: Showing lines 1-1 of 1\n1: hi", + "assistant/text/: a.txt says hi.", + } + if strings.Join(said, "\n|") != strings.Join(want, "\n|") { + t.Fatalf("transcript\n%s\nwant\n%s", strings.Join(said, "\n|"), strings.Join(want, "\n|")) + } +} diff --git a/internal/sessions/antigravity_app.go b/internal/sessions/antigravity_app.go index 3be9502c0..dae9b1074 100644 --- a/internal/sessions/antigravity_app.go +++ b/internal/sessions/antigravity_app.go @@ -23,7 +23,11 @@ import ( // ~/.gemini/antigravity/conversations/.db (Insiders uses // ~/.gemini/antigravity-insiders/conversations), written in WAL // mode while it runs. Its messages are encrypted at rest; the figures read -// here are not. As Antigravity 2.23.0 on macOS writes them (yygutn's real +// here are not. What was said is also written in plain text beside it, +// brain//.system_generated/logs/transcript_full.jsonl +// (antigravityTranscript): the steps as agy CLI writes them, user turns, +// replies, tool calls and their results, which the session viewer reads +// (@yansheng1003 on X: it showed only the title and preview). As Antigravity 2.23.0 on macOS writes them (yygutn's real // rows on #2190; the app isn't installed on any machine magpie is tried on): // // steps idx, metadata BLOB, …: one row a step @@ -130,10 +134,12 @@ func antigravityFilesIn(dir, goos string) []file { if !stat(&f) { continue } - if fi, err := os.Stat(f.path + "-wal"); err == nil { - f.size += fi.Size() - if fi.ModTime().After(f.mod.Time()) { - f.mod = modOf(fi.ModTime()) + for _, p := range []string{f.path + "-wal", antigravityTranscript(f.path)} { + if fi, err := os.Stat(p); err == nil { + f.size += fi.Size() + if fi.ModTime().After(f.mod.Time()) { + f.mod = modOf(fi.ModTime()) + } } } if r, ok := rows[id]; ok { @@ -145,6 +151,26 @@ func antigravityFilesIn(dir, goos string) []file { return out } +// antigravityTranscript is the plain-text transcript of the conversation +// whose database is db: brain//.system_generated/logs/transcript_full.jsonl +// in the same data folder (stable's, Insiders' or a WSL distro's), as +// Antigravity 2.30 writes it. Its size and time are the session file's +// too (antigravityFilesIn), so a step it adds reads the session again. +func antigravityTranscript(db string) string { + id := strings.TrimSuffix(filepath.Base(db), ".db") + return filepath.Join(filepath.Dir(filepath.Dir(db)), "brain", id, ".system_generated", "logs", "transcript_full.jsonl") +} + +// antigravityTranscriptOf reads the conversation whose database is db from +// its transcript, as agy's; ErrNoTranscript when the app wrote none. +func antigravityTranscriptOf(db string, keep func([]byte) bool, add func(bool, Part) bool) error { + p := antigravityTranscript(db) + if _, err := os.Stat(p); errors.Is(err, os.ErrNotExist) { + return ErrNoTranscript + } + return agyTranscript(p, keep, add) +} + // antigravityCallFiles are the same databases as call sources. func antigravityCallFiles() []file { return antigravityFiles() } diff --git a/internal/sessions/antigravity_transcript_test.go b/internal/sessions/antigravity_transcript_test.go new file mode 100644 index 000000000..00f69b8c8 --- /dev/null +++ b/internal/sessions/antigravity_transcript_test.go @@ -0,0 +1,108 @@ +package sessions + +import ( + "context" + "errors" + "path/filepath" + "strings" + "testing" +) + +// testdata/antigravity-2.30-tools is the Antigravity app's data folder +// after one conversation its 2.30 language server had in a sandbox HOME on +// Windows, against a fake model that called read_file once: the +// conversation's database (its steps' text encrypted), its summary row, and +// brain//.system_generated/logs/transcript_full.jsonl, the steps in +// plain text. +const agAppTools = "a9b3e500-3594-49ed-b821-3418225e1990" + +// agAppToolsParts are what that conversation said. +var agAppToolsParts = []Part{ + {Role: "user", Kind: "text", Text: "read a.txt"}, + {Role: "assistant", Kind: "text", Text: "Let me read it."}, + {Role: "assistant", Kind: "tool_use", Name: "read_file", Text: `{"Path":"C:\\Users\\yeton\\agyss\\e2e4\\home\\proj\\a.txt"}`}, + {Role: "tool", Kind: "tool_result", Text: "Showing lines 1-1 of 1\n1: hi"}, + {Role: "assistant", Kind: "text", Text: "a.txt says hi."}, +} + +func wantAgAppTools(t *testing.T, s Session) { + t.Helper() + if !s.Transcript { + t.Fatalf("the session isn't marked readable: %+v", s) + } + tr, err := TranscriptOf(s) + if err != nil { + t.Fatal(err) + } + if len(tr.Parts) != len(agAppToolsParts) { + t.Fatalf("parts %+v", tr.Parts) + } + for i, p := range agAppToolsParts { + if tr.Parts[i] != p { + t.Errorf("part %d %+v, want %+v", i, tr.Parts[i], p) + } + } +} + +// @yansheng1003 on X: an Antigravity 2.0 conversation showed only its +// title and preview on the Sessions page, not what was said. The app's +// transcript beside the database is read as agy's is: the user's turn, +// the replies, the tool call and its result; found by search, and in the +// Markdown export. Stable's, Insiders' and a WSL distro's. +func TestAntigravityAppTranscript(t *testing.T) { + t.Run("stable", func(t *testing.T) { + claude, _ := setup(t) + home := filepath.Join(filepath.Dir(claude), "home") + copyTree(t, "testdata/antigravity-2.30-tools", filepath.Join(home, ".gemini", "antigravity")) + Reset() + s := find(t, List(0), "antigravity", agAppTools) + if s.Title != "a.txt says hi." { + t.Errorf("title %q", s.Title) + } + wantAgAppTools(t, s) + if _, found, err := SearchSession(context.Background(), s, NeedleOf("says hi")); err != nil || !found { + t.Errorf("search: found %v, %v", found, err) + } + if _, found, _ := SearchSession(context.Background(), s, NeedleOf("never said")); found { + t.Error("search found words never said") + } + var b strings.Builder + if err := WriteMarkdown(&b, s, "Antigravity"); err != nil { + t.Fatal(err) + } + for _, w := range []string{"read a.txt", "read_file", "a.txt says hi."} { + if !strings.Contains(b.String(), w) { + t.Errorf("markdown has no %q:\n%s", w, b.String()) + } + } + }) + t.Run("insiders", func(t *testing.T) { + claude, _ := setup(t) + home := filepath.Join(filepath.Dir(claude), "home") + copyTree(t, "testdata/antigravity-2.30-tools", filepath.Join(home, ".gemini", "antigravity-insiders")) + Reset() + wantAgAppTools(t, find(t, List(0), "antigravity", "insiders-"+agAppTools)) + }) + t.Run("wsl", func(t *testing.T) { + home, _ := wslDistro(t) + copyTree(t, "testdata/antigravity-2.30-tools", filepath.Join(home, ".gemini", "antigravity")) + s := find(t, List(0), "antigravity", agAppTools) + if s.WSL == "" { + t.Fatalf("not the distro's: %+v", s) + } + wantAgAppTools(t, s) + }) +} + +// A conversation the app wrote no transcript for (antigravityFixture's, +// from #2190's rows) can't be shown, as before. +func TestAntigravityAppNoTranscript(t *testing.T) { + claude, _ := setup(t) + home := filepath.Join(filepath.Dir(claude), "home") + const id = "37c3c786-9a11-44be-97df-b8fc1ccebc78" + antigravityFixture(t, home, id) + Reset() + if _, err := TranscriptOf(find(t, List(0), "antigravity", id)); !errors.Is(err, ErrNoTranscript) { + t.Fatalf("err %v, want ErrNoTranscript", err) + } +} diff --git a/internal/sessions/search.go b/internal/sessions/search.go index 707da46a9..38b63074f 100644 --- a/internal/sessions/search.go +++ b/internal/sessions/search.go @@ -264,9 +264,11 @@ func SearchSession(ctx context.Context, s Session, needle string) (Hit, bool, er // so that one without the needle's bytes can be passed over unread. An // OpenCode session's is its info (the messages are elsewhere) or a database, // and a Cursor chat's a database too, whose newest pages are in its -wal. +// An Antigravity app conversation's is its database, the transcript beside +// it. func linesFile(s Session) bool { switch s.Agent { - case "opencode": + case "opencode", "antigravity": return false case "cursor": return strings.HasSuffix(s.Path, ".jsonl") diff --git a/internal/sessions/testdata/antigravity-2.30-tools/brain/a9b3e500-3594-49ed-b821-3418225e1990/.system_generated/logs/chunks/transcript/00000000.jsonl b/internal/sessions/testdata/antigravity-2.30-tools/brain/a9b3e500-3594-49ed-b821-3418225e1990/.system_generated/logs/chunks/transcript/00000000.jsonl new file mode 100644 index 000000000..de6757385 --- /dev/null +++ b/internal/sessions/testdata/antigravity-2.30-tools/brain/a9b3e500-3594-49ed-b821-3418225e1990/.system_generated/logs/chunks/transcript/00000000.jsonl @@ -0,0 +1,4 @@ +{"step_index":0,"source":"USER_EXPLICIT","type":"USER_INPUT","status":"DONE","created_at":"2026-11-18T08:25:49Z","content":"\nread a.txt\n\n\nThe current local time is: 2026-11-18T16:25:49+08:00.\n\n\nThe user changed setting `Model Selection` from None to g3. No need to comment on this change if the user doesn't ask about it. If reporting what model you are, please use a human readable name instead of the exact string.\n"} +{"step_index":1,"source":"MODEL","type":"PLANNER_RESPONSE","status":"DONE","created_at":"2026-11-18T08:25:50Z","input_tokens":1000,"cache_read_tokens":200,"output_tokens":7,"content":"Let me read it.","tool_calls":[{"name":"read_file","args":{"Path":"\"C:\\\\Users\\\\yeton\\\\agyss\\\\e2e4\\\\home\\\\proj\\\\a.txt\""}}]} +{"step_index":2,"source":"MODEL","type":"GENERIC","status":"DONE","created_at":"2026-11-18T08:25:50Z","content":"Created At: 2026-11-18T16:25:50+08:00\nCompleted At: 2026-11-18T16:25:50+08:00\nShowing lines 1-1 of 1\n1: hi\r"} +{"step_index":3,"source":"MODEL","type":"PLANNER_RESPONSE","status":"DONE","created_at":"2026-11-18T08:25:50Z","input_tokens":1000,"cache_read_tokens":200,"output_tokens":7,"content":"a.txt says hi."} diff --git a/internal/sessions/testdata/antigravity-2.30-tools/brain/a9b3e500-3594-49ed-b821-3418225e1990/.system_generated/logs/chunks/transcript_full/00000000.jsonl b/internal/sessions/testdata/antigravity-2.30-tools/brain/a9b3e500-3594-49ed-b821-3418225e1990/.system_generated/logs/chunks/transcript_full/00000000.jsonl new file mode 100644 index 000000000..78f1bddce --- /dev/null +++ b/internal/sessions/testdata/antigravity-2.30-tools/brain/a9b3e500-3594-49ed-b821-3418225e1990/.system_generated/logs/chunks/transcript_full/00000000.jsonl @@ -0,0 +1,4 @@ +{"step_index":0,"source":"USER_EXPLICIT","type":"USER_INPUT","status":"DONE","created_at":"2026-11-18T08:25:49Z","content":"\nread a.txt\n\n\nThe current local time is: 2026-11-18T16:25:49+08:00.\n\n\nThe user changed setting `Model Selection` from None to g3. No need to comment on this change if the user doesn't ask about it. If reporting what model you are, please use a human readable name instead of the exact string.\n"} +{"step_index":1,"source":"MODEL","type":"PLANNER_RESPONSE","status":"DONE","created_at":"2026-11-18T08:25:50Z","input_tokens":1000,"cache_read_tokens":200,"output_tokens":7,"content":"Let me read it.","tool_calls":[{"name":"read_file","args":{"Path":"C:\\Users\\yeton\\agyss\\e2e4\\home\\proj\\a.txt"}}]} +{"step_index":2,"source":"MODEL","type":"GENERIC","status":"DONE","created_at":"2026-11-18T08:25:50Z","content":"Created At: 2026-11-18T16:25:50+08:00\nCompleted At: 2026-11-18T16:25:50+08:00\nShowing lines 1-1 of 1\n1: hi\r"} +{"step_index":3,"source":"MODEL","type":"PLANNER_RESPONSE","status":"DONE","created_at":"2026-11-18T08:25:50Z","input_tokens":1000,"cache_read_tokens":200,"output_tokens":7,"content":"a.txt says hi."} diff --git a/internal/sessions/testdata/antigravity-2.30-tools/brain/a9b3e500-3594-49ed-b821-3418225e1990/.system_generated/logs/transcript.jsonl b/internal/sessions/testdata/antigravity-2.30-tools/brain/a9b3e500-3594-49ed-b821-3418225e1990/.system_generated/logs/transcript.jsonl new file mode 100644 index 000000000..de6757385 --- /dev/null +++ b/internal/sessions/testdata/antigravity-2.30-tools/brain/a9b3e500-3594-49ed-b821-3418225e1990/.system_generated/logs/transcript.jsonl @@ -0,0 +1,4 @@ +{"step_index":0,"source":"USER_EXPLICIT","type":"USER_INPUT","status":"DONE","created_at":"2026-11-18T08:25:49Z","content":"\nread a.txt\n\n\nThe current local time is: 2026-11-18T16:25:49+08:00.\n\n\nThe user changed setting `Model Selection` from None to g3. No need to comment on this change if the user doesn't ask about it. If reporting what model you are, please use a human readable name instead of the exact string.\n"} +{"step_index":1,"source":"MODEL","type":"PLANNER_RESPONSE","status":"DONE","created_at":"2026-11-18T08:25:50Z","input_tokens":1000,"cache_read_tokens":200,"output_tokens":7,"content":"Let me read it.","tool_calls":[{"name":"read_file","args":{"Path":"\"C:\\\\Users\\\\yeton\\\\agyss\\\\e2e4\\\\home\\\\proj\\\\a.txt\""}}]} +{"step_index":2,"source":"MODEL","type":"GENERIC","status":"DONE","created_at":"2026-11-18T08:25:50Z","content":"Created At: 2026-11-18T16:25:50+08:00\nCompleted At: 2026-11-18T16:25:50+08:00\nShowing lines 1-1 of 1\n1: hi\r"} +{"step_index":3,"source":"MODEL","type":"PLANNER_RESPONSE","status":"DONE","created_at":"2026-11-18T08:25:50Z","input_tokens":1000,"cache_read_tokens":200,"output_tokens":7,"content":"a.txt says hi."} diff --git a/internal/sessions/testdata/antigravity-2.30-tools/brain/a9b3e500-3594-49ed-b821-3418225e1990/.system_generated/logs/transcript_full.jsonl b/internal/sessions/testdata/antigravity-2.30-tools/brain/a9b3e500-3594-49ed-b821-3418225e1990/.system_generated/logs/transcript_full.jsonl new file mode 100644 index 000000000..78f1bddce --- /dev/null +++ b/internal/sessions/testdata/antigravity-2.30-tools/brain/a9b3e500-3594-49ed-b821-3418225e1990/.system_generated/logs/transcript_full.jsonl @@ -0,0 +1,4 @@ +{"step_index":0,"source":"USER_EXPLICIT","type":"USER_INPUT","status":"DONE","created_at":"2026-11-18T08:25:49Z","content":"\nread a.txt\n\n\nThe current local time is: 2026-11-18T16:25:49+08:00.\n\n\nThe user changed setting `Model Selection` from None to g3. No need to comment on this change if the user doesn't ask about it. If reporting what model you are, please use a human readable name instead of the exact string.\n"} +{"step_index":1,"source":"MODEL","type":"PLANNER_RESPONSE","status":"DONE","created_at":"2026-11-18T08:25:50Z","input_tokens":1000,"cache_read_tokens":200,"output_tokens":7,"content":"Let me read it.","tool_calls":[{"name":"read_file","args":{"Path":"C:\\Users\\yeton\\agyss\\e2e4\\home\\proj\\a.txt"}}]} +{"step_index":2,"source":"MODEL","type":"GENERIC","status":"DONE","created_at":"2026-11-18T08:25:50Z","content":"Created At: 2026-11-18T16:25:50+08:00\nCompleted At: 2026-11-18T16:25:50+08:00\nShowing lines 1-1 of 1\n1: hi\r"} +{"step_index":3,"source":"MODEL","type":"PLANNER_RESPONSE","status":"DONE","created_at":"2026-11-18T08:25:50Z","input_tokens":1000,"cache_read_tokens":200,"output_tokens":7,"content":"a.txt says hi."} diff --git a/internal/sessions/testdata/antigravity-2.30-tools/conversation_summaries.db b/internal/sessions/testdata/antigravity-2.30-tools/conversation_summaries.db new file mode 100644 index 000000000..4846dc85c Binary files /dev/null and b/internal/sessions/testdata/antigravity-2.30-tools/conversation_summaries.db differ diff --git a/internal/sessions/testdata/antigravity-2.30-tools/conversations/a9b3e500-3594-49ed-b821-3418225e1990.db b/internal/sessions/testdata/antigravity-2.30-tools/conversations/a9b3e500-3594-49ed-b821-3418225e1990.db new file mode 100644 index 000000000..1fc393ffa Binary files /dev/null and b/internal/sessions/testdata/antigravity-2.30-tools/conversations/a9b3e500-3594-49ed-b821-3418225e1990.db differ diff --git a/internal/sessions/transcript.go b/internal/sessions/transcript.go index c643f4c4b..1c5bb0fdc 100644 --- a/internal/sessions/transcript.go +++ b/internal/sessions/transcript.go @@ -35,7 +35,7 @@ var ErrNoTranscript = errors.New("this agent's conversations can't be shown") // transcript. func HasTranscript(agent string) bool { switch agent { - case "claude", "qoder", "qoder-cn", "codex", "pi", "raft", "cindy", "omp", "cursor", "opencode", "kimi", "agy", "openmausbot", "liveagent": + case "claude", "qoder", "qoder-cn", "codex", "pi", "raft", "cindy", "omp", "cursor", "opencode", "kimi", "agy", "antigravity", "openmausbot", "liveagent": return true } return false @@ -162,6 +162,8 @@ func readTranscriptOf(s Session, keep func([]byte) bool, add func(bool, Part) bo return kimiTranscript(s.Path, keep, add) case "agy": return agyTranscript(s.Path, keep, add) + case "antigravity": + return antigravityTranscriptOf(s.Path, keep, add) case "openmausbot": return ombTranscript(s, add) case "liveagent":