Commit Graph
16 Commits
Author SHA1 Message Date
yetone d2fa7d8d79 sessions: an Antigravity app conversation shows what was said, not only its title
@yansheng1003 on X: the Sessions page showed an Antigravity 2.0
conversation's title and preview only. HasTranscript left "antigravity"
out, since conversations/<id>.db's step text is encrypted at rest, so
the row had no Show conversation and /api/sessions/transcript said
"this agent's conversations can't be shown".

The app also writes every step in plain text beside the database:
brain/<id>/.system_generated/logs/transcript_full.jsonl in the same
store, in agy CLI's format (user input, planner responses with their
tool_calls, tool results). Antigravity 2.30's language server writes it
in the stable store and in Insiders' (both checked: run in a sandbox
HOME on Windows against a fake model that called read_file).

- transcript.go: antigravity has a transcript; readTranscriptOf reads
  it through agyTranscript (antigravityTranscriptOf), so the viewer,
  TranscriptAt, search, the said index and the Markdown export all get
  it. A conversation with no transcript file is ErrNoTranscript, as
  before.
- antigravity_app.go: antigravityTranscript derives the path from the
  database's (stable, Insiders, a WSL distro's); its size and time are
  folded into the session file's with the -wal's, so a step it adds
  reads the session and the said index again.
- search.go: linesFile is false for antigravity, so the encrypted .db is
  never pre-scanned for the words.
- testdata/antigravity-2.30-tools: that real conversation (db with the
  WAL checkpointed, summary row, brain/ logs).

Tests: TestAntigravityAppTranscript (stable, Insiders, WSL: parts, search
hit and miss, Markdown), TestAntigravityAppNoTranscript,
internal/gui TestSessionAntigravityConversation (/api/sessions marks it,
/api/sessions/transcript gives the five parts).

Run: on mica (mica-run) at base de5fc6700:
- gofmt -l internal/sessions internal/gui: clean.
- go vet ./internal/sessions ./internal/gui, GOOS=linux go vet -tags
  nogui and GOOS=windows go vet on the same, go build .: ok.
- go test -count=1 -timeout 45m ./internal/sessions: ok but for
  TestWSLAgentsGoneListingDrops (load ~48; fixed at its cause in the
  commit before this one); go test ./internal/gui: ok (299s).
- After that fix: go test -run 'WSL|Antigravity|Agy|Gone'
  ./internal/sessions ok; GUI files sessions-talk, -talk-sheet,
  -talk-model, -export, -said, -subagents, -reads, -search, -convert:
  168 of 168 in Chromium and WebKit.
- Old code (de5fc6700 with only the new tests and testdata):
  TestAntigravityAppTranscript red in stable, insiders and wsl ("the
  session isn't marked readable"), TestSessionAntigravityConversation
  red ("listed with no conversation to show ... Transcript:false").
- Windows (win-run on xiaomi-gpu): TestAntigravityAppTranscript (3
  subtests) and TestAntigravityAppNoTranscript pass.
  TestAntigravityAppFolder is red there at the base as well (#5957).
Rebased onto bfddc9cfb, on mote (mote-run) at this tree: gofmt clean,
the three vets and go build ok, go test -count=1 ./internal/sessions
./internal/gui ok (56s, 157s).
Not tried: the real GUI window opening this conversation; the API and
page are covered by the tests above.
2026-11-18 18:55:46 +08:00
yetone 8e1534f5f9 sessions: read LiveAgent's sessions (#6741)
Usage › Sessions and the Sessions page now list LiveAgent's sessions
with their title, time, model, tokens and cost, and show their
conversation.

- Where: K-brain keeps each session at
  <root>/sessions/<project>/<id>/session.jsonl (older ones right under
  sessions/). sessions/.runs and sessions/.deleted-history are skipped.
- Root: $LIVEAGENT_HOME, then $K_BRAIN_HOME, then
  ~/.liveagent/data-dir.json, then ~/.liveagent. The rule now lives in
  sessions.LiveAgentDirIn, and agent.liveAgentDir calls it, so it has
  one owner.
- Reading: K-brain rewrites the file whole, so it is parsed whole. The
  first line is session_meta (id, title, cwd, running totals).
- Tokens:
  - Each reply's own usage counts on the day it came back.
  - What the totals (model_usage, else usage_in/usage_cached/usage_out)
    hold beyond those replies, such as a compaction's call or a rewound
    reply, counts on the last message's day, together with sub_usage.
  - Cache reads and writes are taken out of prompt_tokens.
- Forks: a fork's copies of its source's messages (seq <= fork_seq) are
  the source's, and count in neither the fork's messages nor its totals.
- Subagents: a subagent's own session (task-<parent>-<task>, task_id
  set) is filed under its parent with its activity, but no tokens,
  because its spend is the parent's sub_usage already.
- Not added:
  - a Calls reader: the gateway's own record of LiveAgent's calls
    carries no session id, so it would count them twice;
  - resume and delete: LiveAgent has no resume command.
- Skills: SkillsManager read (skill://<name>/SKILL.md) and Read of a
  skill path are counted.

Run (mote, mote-run, at d67ccbd3c plus this change before the rebase):
- go test -count=1 -timeout 45m ./internal/sessions ./internal/agent
  ./internal/library ./internal/agentenv ./internal/gui: all ok.
- go vet ./..., GOOS=linux go vet -tags nogui ./... and
  GOOS=windows go vet ./...: clean. gofmt -l: clean.
- TestEveryAgentSaysItsSkills has liveagent →
  TestLiveAgentSessions.

Again after the rebase on 3be322fe4 (mote): ./internal/sessions,
./internal/agent, ./internal/library ok; GOOS=linux -tags nogui and
GOOS=windows go vet ./... clean.

Broken by hand (mote), each red:
- Without parserFor's liveagent case: TestLiveAgentSessions (0 listed)
  and TestLiveAgentTranscript.
- Without subtracting a fork's copies: fork1 tokens 600/140/1000 for
  want 400/40.
- Without subtracting the replies already counted: abc123
  3500/550/2000 for want 2500/350/1000.

Fixtures: the issue's literal session_meta, with its placeholders
filled in (12786068 in, 12455808 cached, 103572 out →
330260/103572/12455808). The message, snapshot and compaction lines
follow K-brain's record types as its source writes them.

Not tried: no real LiveAgent install. The files were not written by
LiveAgent itself, and no real session was read. Imported sessions
(ImportHistory) are listed as they are. No GUI file changed, so no
GUI tests were run.
2026-11-17 20:56:30 +08:00
yetone 64c4261582 sessions: search what was said in every agent's sessions, from the page and an MCP server
cryingLiu on X asked to search the chat history of every agent magpie
reads sessions from: prompts and replies, from one place.

What the user gets:
- The Sessions page's search also lists, under the agent's own list,
  the other agents' sessions whose conversation says the words, each
  with a snippet. A hit opens the conversation in the sheet at the
  message that said it (transcript?find=), with "N earlier messages
  not shown"; the page itself never scrolls. While the index is still
  being built the head says "Indexing sessions…" or "Indexing N of M
  sessions…", and the page asks again every 3s until it is done.
- Magpie Sessions, a built-in MCP server in Library → MCP (Discover),
  opt in per agent like the other magpie servers. Its tools are
  search_sessions(query, agent?, limit) and read_session(id, around?),
  both returning text. It runs as `magpie mcp sessions` over stdio and
  reaches the gateway's /mcp/magpie/sessions, which serves only local
  callers that are not browsers.

How it works:
- internal/sessions/said_index.go keeps said-v1.db beside sessions.json:
  a contentless SQLite FTS5 index (detail=none) of the words each
  session says. It is built from the sessions list sessions already
  caches and refreshed at most every 10s: a new or rewritten file is
  read once, a grown Claude Code or Codex file only from where it ended,
  and a gone one is forgotten. A query asks the index which sessions
  have every word, then reads only those files for the snippet, for at
  most 6s. A search waits up to 2s for a refresh. While the first
  listing is still running the answer says `listing`, so an empty first
  answer is not read as "no session says it".
- Privacy: only agents sessions.Reads allows are indexed or searched;
  nothing is read until the user has answered the sessions question,
  and in gateway mode no agent's own files are read (the page doesn't
  ask). Reset forgets the index.
- /api/sessions/said for the page; the CLI parity list names it.

Run, at this tree (rebased on origin/main 256910f17):
- gofmt -l clean; go vet on mote for darwin, GOOS=linux -tags nogui
  and GOOS=windows: ok.
- go test -tags nogui ./... -timeout 45m on the WSL Linux box:
  every package ok at c8e445c4b (the tree before the one-hit wording,
  whose gateway tests ran again on mote: ok).
- GUI: the whole suite on mica at this head was still running when
  this was pushed (owner: never hold a verified change behind a full
  suite). Under mica's load, beside another session's full suite, 90
  tests had failed so far, all in files this change doesn't touch
  (accounts, Details, keys, plugins, providers); none in sessions,
  library or i18n. The files this change reaches passed on their own
  (below).
- Focused, green: internal/sessions (Said*, TranscriptAt),
  internal/gateway (SessionsMCP*, own MCP, read-only, key slots),
  internal/library (market, opt in), internal/gui (Said, Sessions,
  gateway mode); GUI sessions-said, sessions-search, library-sessions-mcp,
  vision-mcp-library, library-browser-setup and i18n-keys in chromium
  and webkit, every language, wide and narrow.
- Broken by hand, one at a time, each red and green restored: the
  index's Listing left out (TestSearchSaidWhileTheSessionsAreFound red
  in 2.5s); the page ignoring `listing` (sessions-said 6 of 7 red); the
  MCP's local/browser guard (TestSessionsMCPOnlyForAgentsHere red); the
  server's opt in (TestSessionsServerInDiscover red); every Reads check
  on the search path, the index's and SearchSession's together
  (TestSearchSaidLeavesOutAgentsNotRead red). With those gone the
  gateway-mode GUI test stays green, because the sessions listing
  leaves an unread agent out before the index sees it.
- Real use, in a sandbox HOME with GOPATH, GOMODCACHE and GOCACHE
  pinned, over the real history through symlinks (29 GB Claude Code,
  60 GB Codex, 14,102 sessions), sessions reads set to all in the
  sandbox: first listing ~60s cold (answers say still being found),
  whole index built in 9m50s while queries answered in ~6s each, index
  38 MB, a common word 4.9s and a rare word 1.0s warm, read_session at
  the words of a huge session 1.8s, peak footprint 442 MB for the whole
  process with the sessions cache. Nothing was written under the real
  ~/.claude or ~/.codex.
- The real binary end to end on mote, in a sandbox HOME: `magpie serve`
  on a free port and `magpie mcp sessions` over stdio with
  MAGPIE_GATEWAY, against a Claude Code session written there:
  initialize, tools/list, search_sessions found it with its snippet,
  read_session at the words started 3 messages before them, a word
  nowhere said "No session says", and a POST with a web page's Origin
  was refused 403. That run is how "1 sessions say" was found and
  made "1 session says" (TestSessionsMCPSearch red before, green after).

Not tried: a real agent (Claude Code, Codex) calling the server it was
given from the Library, and the page against a real backend (the GUI
tests fake the API). The index on Windows and Linux ran only through
the Go suite.
2026-11-16 07:19:18 +08:00
yetone c41fa8e478 sessions: an OpenMausBot conversation can be shown (@qingqingdilaiP on X)
@qingqingdilaiP's OpenMausBot rows in Usage → Sessions (b507b5f69,
v0.1.4146) had a time, an id and ~\.openmausbot\messages.db#<id>, but no
Show conversation: HasTranscript left openmausbot out, so the row had no
transcript flag and /api/sessions/transcript, the Markdown export and the
Sessions filter refused it.

ombTranscript reads the conversation from messages.db (the listing's
path up to its last "#", the session's id as thread_id), on its own
read-only connection, in one read transaction, ordered by at and rowid
as the listing reads it:
- a user text is the person's message;
- a bot text, and an options card's words (MausBot's first message is
  one), are the bot's;
- an activity of a turn's item (tool.itemId, as server/index.js writes
  on item.started) is a tool_use with its input (else its summary, else
  its name: the sample's agents_list_bots kept no input), and its output
  a tool_result;
- an activity with no item (a notice, a queue or engine move, which
  OpenMausBot adds itself) and a turn's digest, which repeats the reply,
  aren't said.

Sibling check: Hermes and Alma, listed the same way (read-only database
rows, 5a4104632, dc3deaf09), have no Show conversation either, nor do
zcode, dsh, cline, grok, droid, workbuddy, workbuddy-ai, codebuddy and
antigravity. Filed as #6633; not changed here.

Tests (testdata/openmausbot, OpenMausBot 0.1.155's own data folder as
b507b5f69 recorded it):
- TestOpenMausBotTranscript: both conversations flagged in List and on
  the Sessions page; Find + TranscriptOf as the GUI route does gives the
  team thread's prompt, "Checking the team.", agents_list_bots, its
  result, the reply, and the fruits thread's 4 texts with no digest;
  WriteMarkdown and SearchSession read the same rows; messages.db's bytes
  unchanged.
- TestOpenMausBotTranscriptToolsAndNotices: rows inserted in the shapes
  OpenMausBot writes (item.started/completed with input and output, a
  cloud-credit-moves notice): the tool shown with its arguments and
  result, the notice not said.
Broken by hand, each red: openmausbot out of HasTranscript (no flag,
"can't be shown"); the itemId check removed (the notice said as a tool).

Run on mote: gofmt -l clean; go vet ./internal/sessions ./internal/gui,
GOOS=windows go vet ./internal/sessions, GOOS=linux go vet -tags nogui
./internal/sessions; go test -count=1 ./internal/sessions ./internal/gui
ok; node --test sessions-talk, sessions-talk-sheet, sessions-talk-model,
sessions-export, sessions-search (Chromium and WebKit, their languages
and widths): 54 of 54 pass (the GUI is unchanged: it shows the button
from the row's transcript flag). On Windows (xiaomi-gpu): go test -run
'OpenMausBot|Alma|Hermes' ./internal/sessions ok.

After a rebase onto 80a315a70 (no internal/sessions change; internal/gui's
cache change): on mica (mote over its cores), go vet and go test -count=1
./internal/sessions ./internal/gui ok, at the pushed tree.

Not tried: the live GUI against a real OpenMausBot on Windows (the
reporter's case); a conversation with images or cards other than options
(secret, signin, connector are left out); not the full ./... suite (the
change is inside internal/sessions, whose only callers here are
internal/gui's routes, both run).
2026-11-14 17:04:45 +08:00
yetone 7da5b34aa4 sessions: Cindy's Pi sessions are read from its pi-agent-home (ldl123292 on X)
Cindy starts Pi with --session-dir <userData>/pi-agent-home/sessions
(resolvePiAgentHome in Cindy's app.asar), so its Pi sessions never
reached ~/.pi/agent and magpie showed none of them. They are read now from
the Cindy and CindyGlobal builds' folders and listed as Cindy's: list,
transcript, calls on Usage, Dirs, delete, and the gateway's own record of
a Cindy session merged with the file's.

Run (mote): go test ./internal/sessions ./internal/agent ./internal/usage
ok. go test ./internal/gui: two reds, both the same on origin/main
699ddf152: TestSettingsSaveKeepsWhatItDoesNotSend (#4514) and
TestMainWindowCorners (#3949). Linux (wsl-run): go test -run
'Cindy|Raft|TestPi' ./internal/sessions ok. gofmt clean.
Broken by hand: without cindyFiles() in the sessions list both Cindy tests
fail (0 Cindy sessions, want 4).
Not tried: a real Pi session run in Cindy (none on this Mac; the fixtures
are Pi 1.1.0's own files put where Cindy's Pi writes them), Windows, the
full suite. Cindy's Codex in <userData>/codex-home is not read yet: #4651.
2026-11-01 09:12:11 +08:00
yetone af8f3a9399 sessions: a new install reads no agent's session history until the user allows it (RustCats on X)
RustCats on X: a fresh magpie showed every agent's session history on
the Sessions page before anyone agreed to it, and asked for a per-agent
choice instead.

- sessions.Reads(agent) (internal/sessions/access.go) is the one gate,
  from settings.SessionReads {Asked, All, Agents}. Every lister asks it,
  the aggregators (allFiles, callFilesWith, callSourcesWith,
  traceLineFiles, wslFiles, DesktopDataDirs) filter by it again, and
  readers of an already-listed session (TranscriptOf, ContentOf,
  SearchSession, SubagentTranscript, CarryOver, ReadCallSource) return
  ErrNotRead, so a cache from before a switch was turned off goes no
  further. The Sessions list, stats, /api/sessions/overview, the call and
  trace indexes, Usage's agent-file calls and the Codex/Pi title readers
  all pass it.
- SettleReads decides once and saves: an install with sessions.json or
  a calls-v* cache read sessions before and keeps all on; a fresh one
  reads none, not asked. A saved value is never replaced; save, sync and
  restore keep it (KeepOwn); only SetSessionReads writes it. An
  unwritable settings.json reads nothing this run.
- GUI: GET/POST /api/sessions/reads. While not asked, the Sessions page
  shows a consent card: each agent found (by a stat of its folder only)
  with a switch, Allow selected and Allow all. Settings > Privacy >
  Agents' session history has "Agents found later" and a row per agent.
  Strings in en, zh, zh-TW, ja, de.
- CLI: magpie sessions read [on|off all|<agent>...]; magpie sessions
  says on stderr when nothing is allowed yet; the TUI's empty Sessions
  page says how.

Read either way, because none of it lists or shows a session: the
gateway's own usage ledger, its projections and the conversations it
recorded (magpie's own records, so usage and cost keep working); the
agents' config and sign-in files; Claude Code's and Codex's
history.jsonl last-used time and a session file's mtime for a quota's
first use; Codex's newest rollout's last line before magpie restarts
Codex (codexTurnOpen).

Tests: TestFreshInstallReadsNoAgentUntilAllowed,
TestSettleReadsKeepsWhatWasThere, TestSessionReadsRoutes,
TestSessionsRead, TestSessionsNotAskedSaysHow, sessions-reads.test.cjs
(26 cases: consent and Settings in 5 languages, Chromium and WebKit,
390 to 900 wide).

Run on mote:
- full Go suite (gofmt -l, go vet ./..., GOOS=linux go vet -tags nogui,
  GOOS=windows go vet, go build, go test -timeout 45m ./...) at this
  change on 8c63c5b78: 79 packages ok; internal/gui red on
  TestSettingsSaveKeepsWhatItDoesNotSend (mine: SessionReads is written
  by SetSessionReads only, the test now sets it so; green after) and
  TestMainWindowCorners (the same on origin/main c1da9ccda, #3949).
- whole GUI suite (make test-ui, concurrency 2) at this change on
  8c63c5b78: 14985 tests, 276 failed in 44 files. Mine: i18n-keys
  (comments named "Allow all"/"Allow selected"; lowercased) and
  account-discovery (read the last Privacy heading; now the one above
  its list); both green after. The 44 files again on origin/main
  c1da9ccda: 36 red there too (#4304, with #3218, #3412, #3414, #3795,
  #4120, #4125). stays-strict green alone; gateway-key-models webkit red
  1 of 3 alone on main too; plugin-github de 440 red on main (#3218).
- at the pushed head (rebased on cd10dfbe6): go build ./...; go test
  internal/sessions, settings, cli, tui ok; internal/gui
  TestSettingsSave*, TestSessionReads*, TestSessions* ok; i18n-keys,
  account-discovery, sessions-reads: 62 pass, 0 fail.

Broken by hand:
- the aggregator filter off with the leaf gates on: green (the leaf
  gates hold); both off: TestFreshInstall red on List, Agents, Calls,
  CallSources, traces, stats, TranscriptOf and Search.
- consentApplies=false and Settings' old save({all}) without the rows:
  all 13 Chromium cases of sessions-reads red.
- sessNothing's hint removed: TestSessionsNotAskedSaysHow red.

Real binary in a sandbox HOME on mote (removed after): a fresh
`magpie sessions` is empty with the hint on stderr; `sessions read`
says not asked, claude off; `read --help` prints usage and saves
nothing; `read on claude` lists the one session; `read off all`
empties it again.

Not tried: the GUI and real app on Windows and Linux; WSL agents in the
consent list (WSL distros are not looked into; Allow all covers them);
a fresh install of a signed release build.
2026-10-29 23:56:05 +08:00
yetone 9474eaf9cb sessions: Raft's Pi agents' sessions are listed as Raft's, with their prompts, calls and delete
Raft (slock's raft-computer) runs its agents on Pi and keeps each one's
Pi SDK session files in that agent's folder: <slock>/agents/<id>/
.pi-sessions/<ts>_<id>.jsonl, or .builtin-sessions/ for its built-in
runtime. <slock> is $SLOCK_HOME or ~/.slock (%USERPROFILE%\.slock on
Windows, the distro's ~/.slock under WSL). Read from raft-computer
1.0.14's PiDriver (buildPiSessionDir), BuiltInDriver and
resolveSlockHome, and a read-only listing of ~/.slock here.
runtime-sessions/ holds handoff notes, no sessions, and is not read.

- The Sessions page lists them as Raft's (agent "raft", in agent.Clients'
  others), titled and opened with their prompts as Pi's are.
- Their calls count on the Usage page as Raft's; calls through magpie
  stay the gateway's, as Pi's do.
- Raft's Pi uses the user's own ~/.pi/agent, so a request it sends
  through magpie reaches the gateway as Pi's under the same session id.
  sessions.GatewayKeys gives a Raft session both "raft|ID" and "pi|ID",
  so the gateway's copy is not listed twice nor counted twice (Merge,
  stats, NativeIDs, the GUI's Via).
- Delete and restore work as Pi's: the one file goes to the trash, and a
  folder beside it is left (the agent's workspace is not the session's).
  A session written in the last minutes is refused as active.
- No resume command, no carry and no trace export: Raft starts its own
  agents, and nothing outside it can resume one.
- SLOCK_HOME is passed through agentenv like the other agents' homes.

Run (at 958ad9f10 on e61e10535):
- mote (macOS): -run 'Raft|TestPi|TestDirs|TestVars|TestFolderVars' in
  sessions and agentenv: ok, and red for each break below. A full
  go test ./... was started there; at load ~300 from other sessions'
  suites it printed only magpie and internal/access (ok) before mote
  stopped answering (host down), so no full macOS record exists.
- mote (macOS), rebased on 5d24bc6cc: go test -count=1 ./internal/sessions/
  ./internal/agentenv/: ok (sessions 495s, agentenv 1.1s). agent and gui
  were not run in full on macOS.
- mote: GOOS=windows go vet of sessions, agent, agentenv, gui; GOOS=linux
  go vet of sessions, agent, agentenv: ok.
- Windows (win-run): agentenv ok; -run 'Raft|TestPi|TestDirs' in
  sessions ok. The full sessions package hit its 30m timeout after
  TestOneListing's red (#4114) and the Agy reds (#4115, #4177). agent
  and gui reds (Hermes, WorkBuddy, Lody, Qoder/Copilot plugin folders,
  Codex keychain, ClaudeDesktop language, Aside, InstallWithoutNode,
  DesktopExec, AionUi, ImportStatus, UpdateThatWontStart,
  GatewayHeldByAContainer, GatewaySessionHistoryAndCalendar): each run
  again at origin/main c1660481c on Windows and red there too, except
  TestHermesProfilesFollowMagpieModel which passed there alone; it is
  #1388's Hermes model rewrite, which this change does not reach.
- Linux (wsl-run): sessions ok, agentenv ok. agent's TestInstalledVersion,
  TestGrokInstalled, TestCursorFolderFromTheEditorIsNotTheCLI and
  TestOmpDetectedWithPiDir are red at origin/main c1660481c too (#4033,
  #3548). gui does not build there (no gtk4/webkitgtk-6.0 in the distro).

Broken by hand, each red, then restored: Raft's listing removed; the
"pi|ID" key dropped from GatewayKeys; the folder-beside check reverted to
Pi's absence; $SLOCK_HOME ignored; Raft's calls left out of piCallFiles;
NativeIDs without Raft; stats' native keys without "pi|ID".

Not tried: with real Raft. No agent on this machine has run on Pi, so
the fixtures are Pi 1.1.0's own files (testdata/pi-calls, testdata/pi)
placed in Raft's folders. The GUI was not run in a browser: no JS
changed, Raft's name and icon come from agent.Clients. Raft's icon is the
generic one.
2026-10-29 15:29:30 +08:00
yetone f594b452e3 sessions: a Claude fork after a compaction is a branch under its session, read from the start
neo_o11 (Discord, after v0.1.1809): one conversation still showed as ~9
rows with the same title, and opening one showed "Session start" and a
single turn.

Cause, reproduced with real Claude Code 2.1.312 in a sandbox
CLAUDE_CONFIG_DIR: the reporter's session was compacted, then forked
several times (headless --fork-session per task, or /branch). Each fork
starts at the compact boundary and summary, and copies the session's
last reply under the same uuid. So every fork holds the original's
Leaf, and ccCopies hid the original as a fork's copy, though it alone
holds the conversation before the compaction. Each fork had a Leaf of
its own and stayed a row, with the copied title. Opening a fork read
its own file: the summary and one turn.

Fix:
- cc_copies.go: ccFamily returns copies and branches. A file is a
  copy of another only when that one holds its Leaf and its Root too,
  so a file with what came before the other's start is never hidden.
  The members of a family left visible pick a head (holds the other's
  Root, then named in the other's forkedFrom, then the earlier start,
  then the lower key); the rest are branches of it.
- sessions.go, manage.go: a branch has role "branch" and
  parent_session = its head, in List, Find/get and ListAgent.
- transcript.go: a branch's transcript is its head up to the fork
  point (the last line of the head holding one of the branch's
  uuids), then the branch's own lines. Search still reads its file.
- stats.go: a branch counts only its own lines, so tokens are not
  counted twice.
- GUI sessions plugin: the fold under a session names branches apart
  ("2 branches · 1 subagent"), in en/zh/zh-TW/ja/de.
- Fixtures in testdata/claude-forks/tasks*.jsonl are trimmed from real
  2.1.312 output: a session compacted once, two --fork-session task
  forks and a /branch copy with forkedFrom.
- docs/subsystems/gateway-sessions.md: copies and branches.

Run:
- go test ./internal/sessions -run 'TestClaude|TestQoder|TestMergeExternal'
  on mote, at e15b2277c before the rebase: ok. Red on the old code (cc_copies/sessions/transcript/stats
  restored from HEAD~): 5 tests failed (the original hidden, only forks
  as rows; a branch's prompts starting at the summary).
- Broken by hand, each red: dropping the Root rule (3 compacted-fork
  tests), ignoring forkedFrom (TestClaudeBranchNamesItsSession),
  turning branchTranscript off (3 tests), counting a branch whole in
  stats (90 tokens, not 80).
- GOOS=linux (-tags nogui), windows and darwin go vet, at e15b2277c: ok.
- Full go test ./... -timeout 45m at this head (71124a2d7 on c1660481c),
  on the Linux box (mote was at load 300 with six suites): every
  package ok, sessions 144s, gateway 987s, except: ., internal/cli and
  internal/gui didn't build (no gtk4 there), ok again with -tags nogui;
  internal/agent's TestInstalledVersion, TestGrokInstalled,
  TestOmpDetectedWithPiDir and TestCursorFolderFromTheEditorIsNotTheCLI,
  the first three red the same at origin/main c1660481c there, all four
  in #4033 (#3548, #3141). Nothing here touches internal/agent.
- GUI on the Windows box, both engines, every language:
  sessions-subagents + i18n-keys 40/44, the 4 reds 5s nav-click and
  goto timeouts in WebKit; WebKit alone again 20/20. Every
  session*.test.cjs file (32): 381/399. Its six red files run again at
  origin/main c1660481c and here, one at a time: calendar-fill zh red
  on both (#1314), sessions-today WebKit zh red here only, the
  reads.n race of #1315; the rest green on both.

Not tried: get()'s path for a session beyond the listing's 200 has no
test of its own; the TUI and CLI lists show a branch as a row of its
own, not nested; an uncompacted fork that went on has no real
forkedFrom fixture (TestClaudeBranchNamesItsSession injects one).
2026-10-29 15:03:18 +08:00
yetone b30734f964 sessions: Antigravity CLI (agy) conversations are listed, with title, folder, tokens and resume (RickyWei, #1718)
agy's conversations were on no Sessions page: internal/sessions had no
lister for them, only the calls reader of #2097. Now each
~/.gemini/antigravity-cli/brain/<id>/.system_generated/logs/transcript_full.jsonl
is a session (agy.go). Its steps give the start and last times, the first
prompt (taken out of agy's <USER_REQUEST> wrapper), prompts, replies, tool
calls, and tokens under the model "agy", since no step names one. A step
written again replaces its tokens, read on or read whole. The title and
folder come from the conversation's conversation_summaries.db row:
title, and workspace_uris through agyFolder, which turns file:///C:/... and
file:///c%3A/... into C:\... and a host into \\host\share on Windows. agy
writes the title after the transcript, so the row is the file's rev. The
database is read again only when it or its -wal changed, and a failed read
keeps the rows read before. A row with conversations/<id>.db and no
transcript (#1718's case) is listed from the row alone, with no tokens and
no conversation to open. Resume is "agy --conversation <id>". When agy is
set to use magpie, it is the agent's launch command (gateway variables and
--model, the PowerShell form on Windows) with --conversation after it,
through sessions.AgyStart, which package agent sets. The transcript (user
text, thinking, text, tool calls, tool results) can be opened and searched.

Format read from real files: agy 1.3.5 and 1.4.7 in a sandbox HOME
against a fake Gemini endpoint, with plain replies, a read_file tool call
with thinking, invalid tool calls, and a conversation picked up again with
--conversation from another folder. testdata/agy-sessions is three of
those conversations with paths rewritten to /work.

Resume tried for real in the sandbox: `agy --conversation <id> -p again`
from another folder appended steps 2-4 to the same transcript and kept the
row's folder. Interactive `agy --conversation <id>` (in tmux) showed the
earlier turns.

Run at this tree, rebased on origin/main:
- gofmt -l internal clean
- go vet: darwin; GOOS=linux -tags nogui; GOOS=windows
- GOOS=windows go build ./...; GOOS=linux go build -tags nogui ./...
- go test -count=1 ./internal/sessions ./internal/gui ./internal/agent: ok
  before the row-only change. After it, sessions ok, and gui had one red,
  TestMainWindowCorners killed at its 40s deadline at load ~300 (#1936).
  It passes alone (47s).
- GUI (playwright 1.62.0, chromium and webkit, en and zh): i18n-keys,
  gui-de, gui-ja, gui-zh-tw, session-terminal, sessions-bar-names,
  sessions-manage, sessions-talk, sessions-toolbar: 49 of 49. No GUI asset
  changed. Tab names come from the agent registry.

Fails without the change (broken by hand, each one red):
- agyFiles out of allFiles: TestAgySessions, TestAgyTitleLater, TestAgyTranscript
- agy out of refresh's DBRevision check: TestAgyTitleLater
- no dropUse of a rewritten step: TestAgyGrows (4510 input, want 3010)
- AgyStart ignored: TestAgySessions (wired resume)
- drive letter not handled: TestAgyFolder
- agy out of HasTranscript: TestAgySessions, TestAgyTranscript
- the row-only listing off: TestAgyRowOnly; readable() off: TestAgyRowOnly

Not tried: agy on Windows. The Windows box (10.0.0.132) didn't answer
ssh, so the Windows paths are covered by unit tests only (agyFolder,
the Set-Location resume form). A wired resume through magpie's real
gateway was not tried. Not done: subagents (parent_conversation_id),
which I never saw agy write. The model name, which is only in
conversations/<id>.db's protobuf (#3147). Deleting an agy session from magpie. agy in WSL: #3595.

Side effect: agy's self-updater ran in the sandbox and replaced the
live ~/.local/bin/agy, 1.3.5 -> 1.4.7.
2026-10-25 18:24:20 +08:00
yetone 5618ade1e6 sessions: each reply in a session's conversation names the model its own line in the agent's file names (#2253, cnlove7777777-art)
Usage -> Sessions' conversation said only "Assistant", so which model
wrote a reply couldn't be told, though the agents' files name it.

- sessions.Part gains model (omitempty), set on assistant parts only,
  from the part's own line: Claude Code's message.model (the model that
  answered; none for its "<synthetic>" lines), Codex's
  turn_context.model (the model the turn was sent to; a /model between
  turns moves the next turn), Pi's and omp's message.model, OpenCode's
  modelID and OpenCode 2's model.id.
- Kimi Code (its model is only on a usage.record written after the
  reply), Cursor (no model in the transcript) and gateway transcripts
  (GatewayTurn.Model is the model asked for, not the one that answered)
  name none. Nothing is guessed from nearby requests.
- The reader (sessions client.js) says it muted after the role, once a
  reply at its first part and again only where it changes inside the
  reply; the tooltip is "Model: <id>" (an existing string, translated).
  ledSaid takes the model as an argument, so the Usage page's
  per-request content, whose row already names its model, is unchanged.
  No layout change: one muted span in the existing header line,
  ellipsized at narrow widths.

Run:
- TestTranscriptModelClaude/Codex/Pi/OpenCodeV2/OpenCodeFiles: all five
  fail on the old content.go/transcript*.go, pass on the new.
- sessions-talk-model.test.cjs: 20/20 (chromium+webkit, en/zh/zh-TW/
  ja/de, 1100 and 420). Fails on the old app.js/client.js, and with the
  once-a-reply rule removed by hand (label every assistant part).
- sessions-talk, sessions-export, gateway-conversations,
  usage-ledger-content, usage-ledger-detail GUI tests: all pass.
- go test -tags nogui ./internal/sessions ./internal/gui
  ./internal/gateway: ok. gofmt -l clean; go vet -tags nogui darwin/
  linux/windows clean.

Full suite for this push (#2257, #2251, #2254, #2253) at 53677ed8d:
go test -tags nogui -p 4 -timeout 40m ./... with pipefail: every
package ok. (An earlier full run caught davsync's TestSyncLibrary and
profile's TestOldProfiles/TestProfileCarriesLibrary relying on a gone
CLI after #2254; their sandboxes now have the CLIs, in #2254's commit.)

Not tried: the real app against a live Codex rollout (fixtures follow
the lines the readers already parse for usage).
2026-10-15 06:07:43 +08:00
yetone 2d8f2a86a5 sessions: Kimi Code sessions open as a transcript (#2056)
infinitr0us: a Kimi Code session on the Sessions page had no transcript
to open. HasTranscript now lists kimi, and kimiTranscript reads the
session's main wire.jsonl:
- protocol 1.4/1.5: turn.prompt and turn.steer (a prompt not from the
  user, a skill's activation or a background task's news, is folded as
  context), and the loop events content.part (text, think), tool.call
  and tool.result, a result named for its call. These are there for
  every session, finished or running; agent.message.appended (1.5, only
  at a turn's end) and the timed context.append_message records say the
  same again and are passed over.
- kimi-cli imports (1.0, and the head of a ses_* session Kimi Code
  reopened): the untimed context.append_message records, with an
  assistant's toolCalls in both shapes (name/arguments and OpenAI's
  function.{name,arguments}).
Search and markdown export read the same parts.

Run:
- TestKimiCodeTranscript on the #1607 reporter's wire files in testdata
  (1.4, a cancelled 1.4, an early 1.5 started by a skill, a failed 1.5,
  a kimi-cli import), and TestKimiCodeTranscriptOrder on a synthetic
  file in the same record shapes, exact part order plus SearchSession.
- Broken by hand: kimi out of HasTranscript fails both tests; reading
  the timed context.append_message records fails both (user/text 9,
  not 3).
- A nogui build's `magpie web` under a sandbox HOME, KIMI_CODE_HOME on
  the reporter's whole zip (8 sessions, the July subagent session and
  a reopened ses_* among them): all 8 listed with a transcript;
  /api/sessions/transcript gave 105, 13 and 205 parts for June, the
  reopened ses_* and July; the markdown export worked.
- gofmt -l clean; go vet darwin, linux -tags nogui, windows;
  go test -tags nogui ./internal/sessions/ ./internal/gui/.

Not tried: a live Kimi Code session on this machine (none here; the kimi
installed is kimi-cli 1.52.0), the GUI's look of the transcript, WSL.
A subagent's own wire file isn't shown; the main agent's is.
2026-10-14 08:28:52 +08:00
liubing 1cd8140047 sessions: read Cursor editor history and Cursor/OpenCode conversations (#1743)
Discover editor project transcripts and cursorDiskKV histories without modifying the source. Share one SQLite/WAL snapshot across a scan, refresh metadata changes, deduplicate CLI histories, and reject deletion of read-only sessions.

Count message-only sessions and expose an all-dates action when a filter hides existing history. Read Cursor CLI text, reasoning and tool parts, and OpenCode v1/v2 transcripts through the existing transcript API.
2026-10-13 06:43:50 +08:00
yetone 260ded9af4 sessions: the Sessions page's search finds a session by what was said in it, and a gateway session is titled by what it was first asked (YOU on Discord)
Why: the filter matched only titles, folders, ids and models, and a
session the gateway recorded was listed under its bare ses_… id, so one
couldn't be found by anything a person remembers about it.

What changed:
- sessions.GatewayTitle: the first user text of a recorded session (not
  a <…> context tag, # AGENTS.md or an image), made one line. It reads at
  most 8 complete turns of the oldest file of it, caches a finished
  file's answer by path, and costs one stat when nothing is recorded.
  gatewayListed applies it in every list (/api/sessions, /manage, /one,
  the stats summaries); ExternalSession gained Title.
- GET /api/sessions/search?agent=&q= (searchSessions): an agent's
  sessions, newest first, read by up to 4 workers, each only to its
  first match. Native files go through a byte prefilter (mayHold: the
  query's longest word, ASCII case folded without a copy, 1 MiB chunks,
  skipped for zstd and for queries JSON may escape), and of a Claude or
  Codex file only the lines holding every word are decoded
  (readTranscriptOf; claudeContentOf/codexContentOf take an optional
  line test, nil for every other caller); gateway sessions, and an
  unreadable agent's sessions (unread: true), through their recorded
  transcript. System prompts, tool definitions and images never match.
  It stops at 200 hits or 8s (cut, searched of total) and when the
  request's context ends. Each hit carries the match with 36 runes
  before and 120 after.
- sessions.js: the field says "Search sessions"; title/folder/id/model
  matches show at once, the server is asked 300ms after the last
  keystroke, a new query aborts the request in flight and its answer is
  dropped, under 2 letters asks nothing. A session found shows a line of
  the words round its match with the match in <mark> (text nodes, no
  innerHTML). A note says when it is searching, cut short, failed, or
  limited to recorded text. New strings in zh, zh-TW, ja and de.
- docs/subsystems/gateway-sessions.md describes both.

Run:
- Go: TestSearchSession* (snippet, case and line breaks, said text
  preferred over a tool call, cut ends, cancelled context, a Codex file,
  only matching lines decoded: 1 part of 3), TestContainsFold,
  TestMayHoldSkipsAFileWithoutTheWords (incl. a match across chunks),
  TestGatewayTitleAndSearch (context tag and system prompt skipped),
  TestSessionsSearchFindsGatewaySessionsByWhatWasSaid (endpoint + manage
  titles), TestSessionsSearchStopsWhenItsRequestEnds. Without the
  endpoint/title they fail (404, id as title).
- GUI: new sessions-search.test.cjs in chromium and webkit, en/zh at
  1100, zh-TW/ja at 560, de at 420: title shown, one letter no request,
  one debounced request, snippet mark, cancelled earlier request never
  shown, cut note, empty state, Escape, every language's strings, no
  overflow; 12/12, and 0/12 with the old sessions.js. The sessions-*,
  sess-*, session-* and i18n-keys tests pass in both engines
  (sessions-manage's placeholder updated to "Search sessions").
- gofmt -l, go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./..., the builds: clean. go test -tags nogui
  ./... at load ~25-60 (other sessions' runs): every package passed but
  internal/agent and internal/gateway, which hit the 30m timeout; run
  again alone, agent passed and gateway's only red was
  TestOTelWaterfallIncludesUnbilledFallback, filed as #1794 (passes
  alone, -count=3).
- Real data, read-only (a temporary probe, not committed, pointed at
  the owner's ~/.claude and ~/.codex; one worker, 8s, load ~50):
  Claude, 58 sessions / 3 GB: before the line filter one 1.3 GB session
  took the whole 8s ("redis": 1 of 58); after, all 58 in 4.7s ("redis",
  13 hits), 7.4s ("gateway session"), 2.8s (no match). Codex, 11534
  sessions / 65 GB: 245-656 sessions in 8s either way, which is what
  the cut note ("latest n of total") is for.

Not verified: the endpoint and page against a real recorded gateway
store (only fixtures and temp homes); the timings above were taken on
a machine at load ~50 and vary run to run.
2026-10-12 22:29:46 +08:00
木子不是木子狸 c9b8263378 sessions, gateway: Sessions lists gateway sessions, and can keep their text on this computer when turned on (#1355, mu-zi-lee)
What changed: the Sessions page lists sessions seen only through the
gateway (from the usage ledger, read-only, a native session of the same id
wins), and shows in gateway mode. A Sessions switch, off by default and
confirmed before it turns on, records each gateway exchange's text under
the config dir (scrubbed, at most 7 days and 256 MiB, cleaned hourly).
Settings sync and restore can't turn it on; POST /api/sessions/recording
turns it on or off and can clear what was kept.

Why: users of magpie as a gateway (gateway mode, LAN clients) had no way
to see their conversations; the owner chose this design on the PR.

Squashed from PR head 6a343ba1 onto origin/main. Conflicts: gui-shell.md
(kept main's placeMenu text, took the PR's Sessions in gateway mode) and
settings_keep_test.go (main's fields plus GatewayConversations).

Run: go build ./..., go vet on gateway, gui, sessions, settings, usage;
go test -race -timeout 900s on those five packages: all ok.
2026-10-10 04:24:18 +08:00
yetone 67329b8d9c sessions, gui: a session's conversation is exported as Markdown from its details on the Sessions page (#1276)
Beside Show conversation, Export Markdown saves the whole conversation
(Claude Code, Qoder, Codex, Pi, oh-my-pi: every agent whose transcript the
page can show) as a Markdown file: a heading with the session's agent, id,
folder, times, models and file, then each turn under User / Assistant, a
tool's call by its name and arguments, its result, thinking and the agent's
own notes folded in <details>. Parts are kept whole (the page's 8000-char
cut doesn't apply), fences grow past any backticks in the text. In the app
it goes to Downloads (never over an earlier export) and the status says
where; in magpie web the browser downloads /api/sessions/markdown. The
session is found as listed, never a path from the page; the file is only
read.

Verified: TestMarkdownClaude, TestMarkdownCodexAndPi, TestMarkdownUnsupported
(sessions) and TestSessionExportMarkdown (gui) under a temp HOME. Without the
routes TestSessionExportMarkdown fails "export: 404 404 page not found";
with the page's per-part cut TestMarkdownClaude fails on the long part.
sessions-export.test.cjs (Chromium+WebKit, en/zh, app and web, 560px) fails
on origin/main's sessions.js waiting for .sess-export; passes with it, as do
sessions-talk, gui-ja, gui-de, gui-zh-tw and i18n-keys. Exported real
Claude Code, Codex and Pi session copies: fences balanced, turns in order.
go vet (darwin, GOOS=linux, GOOS=windows) -tags nogui on both packages.
2026-10-08 17:38:03 +08:00
yetone b96d55fc99 sessions: a session's conversation can be read in magpie, and a Pi session carried on in oh-my-pi (sxwedo, #845) — the Sessions page could resume a session only in the agent that wrote it, and showed nothing of what was said. A session's details now have Show conversation: magpie reads the agent's own session file (Claude Code, Qoder, Qoder CN, Codex, Pi, oh-my-pi; found by agent and id, never a path from the page; read only, no copy kept, 400 KB at most with "There was more than is shown here") and lists the user's words, the model's, each tool call by name and its result, thinking and summaries folded. For Pi and oh-my-pi it follows the branch the session is on (parentId from the last entry), not the turns left on an abandoned one. A Pi session also has Continue in, the app's menu (no <select>): oh-my-pi's omp --fork <file> in the session's folder, copied or opened in the session terminal (the server makes the command from the session it finds; the page sends agent, id, in), and the details say it. omp --fork loads the Pi file, migrates it and writes a new oh-my-pi session, leaving Pi's untouched; with the owner's Pi sessions copied into a sandbox HOME, oh-my-pi's own SessionManager forked them whole (4→5 and 46→47 messages, its system line added; text, thinking and tool calls kept) and the source files' sha256 didn't change. Only that pair is offered: Pi can't read an oh-my-pi file (it wants the session header first, oh-my-pi writes a title line first), oh-my-pi takes Claude Code and Codex only from its own import picker, not a given session, and the other agents' formats differ, so carrying them on would mean converting them, which isn't done. zh, ja, de strings. TestTranscriptClaude, TestTranscriptCodex, TestTranscriptPiBranch, TestTranscriptOmp, TestTranscriptUnsupported, TestTranscriptCut, TestCarryPiToOmp; sessions-talk.test.cjs (WebKit, en and zh) fails on the old code. sessions-*, click-scroll, gui-ja and gui-de pass on WebKit; session-terminal and session-identity fail the same on origin/main. go vet, builds (darwin, GOOS=linux nogui, GOOS=windows) and go test -tags nogui -count=1 ./... under a temp HOME pass. 2026-10-05 10:08:35 +08:00