ac4af582301a4e8a29245dbba767eba31334ddf9
8
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
b8270850df |
sessions: a kept parse's rarely set fields live in a StateMore made only when one is set (#2278)
Each of the ~18k files the Sessions cache keeps had a 760-byte state, and ~330 bytes of it were fields almost no file sets: the Codex spawn and agent maps, Named/Custom/First, the dsh and Claude conversation lists, Root/Leaf, Compacts, and the six per-agent tails (Grok, Droid, Kimi, Agy, Dsh, Cline). On the owner's real cache (18,331 files) Root and Leaf are set in 150, Named in 117, Compacts in 78, First in 35. They move to an embedded *StateMore, nil unless something is in it: reads go through more() (a shared empty one when nil), writes through own(). The JSON is the same (embedded fields are inlined), so the cache version stays. - parseWith drops an extra that only had empty values written to it, and share() drops one the decode made empty. - clone() deep-copies the extra, so growing a clone leaves the kept state alone. Copies that never write (withoutRevisions, the Agent rename) share it, as they shared the maps before. Run on mote at this tree: - gofmt -l internal/sessions: clean. go vet ./internal/sessions/ on darwin, GOOS=linux and GOOS=windows: ok. - go test -count=1 ./internal/sessions/: ok (26s). - Every selector was checked by renaming the embedding to a named field and compiling with -gcflags=-e until only the struct literals were left, so no field is reached through a nil *StateMore. - New tests in state_more_test.go: zero() knows every field (reflect), a read makes no extra and a write never reaches the shared empty one, a clone owns its extra, and a cache round trip keeps no empty extra. Broken by hand: dropping Cline from zero() and sharing the extra in clone() each turn their test red; restored. - Real-account idle heap (copy of the owner's config and 24.6MB sessions cache, gateway idle 180s, heap after GC): decodeCache's retained heap 35.0MB -> 22.5MB, reflect.unsafe_New 20.0MB -> 10.5MB. The total (128.7MB -> 133.6MB) moves by more than that between runs of one binary (118-140MB), from late passes that happened to be live. Not tried: the full ./... suite (state is unexported; only internal/sessions uses it, and the whole binary builds). |
||
|
|
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
|
||
|
|
1dc20e73fc |
sessions: a live Cursor's state.vscdb is read in place, not copied (#1988)
Beside a running Cursor, every listing, count, transcript and search read the editor's state.vscdb from a copy in the temp folder, made again each time Cursor had written since the last. The store is often several GB, and on Windows, where no clone makes a copy free, Echo-Huang0010 measured ~10.6 GB written every few minutes. While the store has a non-empty -wal and a -shm beside it, Cursor's own processes share it as readers through the -shm, and magpie now opens it the same way, mode=ro with a 3s busy timeout: no copy. Nothing magpie shows comes from the store's file times (each chat carries lastUpdatedAt), so a reader's mark in -shm changes nothing it lists. With no -shm beside a live -wal, or if that open fails, it falls back to the copy as before. CLI chat stores keep the copy path. OpenUntouched's open is factored out as openSQLite. Thanks to Echo-Huang0010 for the report and the measurements; their patch capped the copy at 64 MiB, which would leave a larger history unread, so this takes the in-place read instead. The Cursor tests set TMPDIR only, which Windows' os.TempDir doesn't read (TMP, TEMP), so TestCursorLeftCopiesSwept's folder landed in the real temp folder and the next test counted it. cursorTempDir sets all three. Run at this head: - mote: go test -count=3 -run Cursor ./internal/sessions ok; go test -timeout 45m ./internal/sessions ./internal/agent ok; go vet ./internal/sessions for darwin, linux, windows ok; gofmt clean. - xiaomi-gpu (win-run): go test -count=3 -run Cursor ./internal/sessions ok (red before cursorTempDir, from the stray folder). - Broken by hand: in-place reads off, TestCursorEditorReadInPlaceWhileLive fails "a live state.vscdb was copied 3 times, want 0". - Windows, two processes: a writer holding a WAL store (~40 MB) with busy_timeout(0) wrote 200 times while a magpie process listed 40 times and read transcripts. 0 failed writes, every list saw the latest title (40 of 40), 0 copies in the temp folder. Not tried: a real Cursor install. Neither test machine has one, so the writer was a stand-in process, not Cursor itself. |
||
|
|
c26a418d23 |
agent: an import app's status magpie can't read is unknown, not "not added"
Agent.Added now returns (added, known). Cindy's reader turned any
failure (a locked, corrupt or unreadable cindy-local-v1.db) into "Not
added", which told a user who had added magpie that they hadn't. Now
an unreadable database is unknown: /api/agents leaves `added` out and
the row shows the "confirm it there" hint, as it does for Lody. A
stopped WSL distro's app is unknown too, not "not added".
Cindy's database is also read without writing beside it. A mode=ro
open of a WAL database while Cindy was closed made cindy-local-v1.db-wal
and -shm in Cindy's own folder. It now goes through
sessions.OpenUntouched, which is what the Cursor reader already did
(immutable with no log, from a copy with one), moved out of
openCursorStore so both share it.
The CLI's list still offers `magpie cindy add` when the status is
unknown; it never said magpie was missing.
Run: go test ./internal/agent ./internal/sessions ./internal/cli ok;
go test ./internal/gui -run 'Import|Lody|Cindy|Agents' ok.
Broken by hand: Cindy's reader put back on the mode=ro open made
TestCindyHasClosedWALAndUnreadable red ("Cindy's folder changed:
cindy-local-v1.db -> cindy-local-v1.db,cindy-local-v1.db-shm,
cindy-local-v1.db-wal"); api.go ignoring `known` made
TestImportStatusUnreadableIsUnknown red. Both restored, both green.
Not tried: a real Cindy install; the read is tested on fixture
databases only.
|
||
|
|
0e39c8e7e9 |
sessions: reading Cursor's history no longer writes its database to the temp folder again and again (#1988, kangxi94)
v0.1.1224 reads Cursor's editor chats from its global state.vscdb, which is often several GB. A store with a live -wal is read from a copy, and every listing, count, manage page, transcript, context read and each chat of a search made a fresh full copy in $TMPDIR/magpie-cursor-*. A visit to Sessions wrote the file out several times (28 in the test below): heavy disk writes with low CPU, and Time Machine's local snapshots can hold on to deleted copies' blocks, which would shrink free space (not reproduced on the reporter's machine). A magpie killed mid-read also left its copy behind for good. - A store of 16 MB or more is copied once and the copy is shared by every reader while the store and its -wal keep their size and time; a change makes one new copy, and a copy goes 30s after its last reader. - On macOS the copy is an APFS clone (clonefile), so it takes no space until Cursor writes; elsewhere, or when cloning fails, it is copied. - The first copy a process makes sweeps magpie-cursor-* folders older than an hour (a shared copy is touched on every reuse). Run: - TestCursorEditorCopiedOncePerChange: 6 editor chats, list + Agents + transcript + search of each, twice: 1 copy (28 with sharing turned off by hand), 2 after one change, none left. TestCursorLeftCopiesSwept goes red with the sweep turned off. - go test -race ./internal/sessions/ ok; -run TestCursor -race -count=10 ok. - gofmt -l clean; go vet -tags nogui for darwin, linux, windows. - Sandbox HOME with a 300 MB Cursor-shaped state.vscdb kept live by a writer every 5s: v0.1.1224 made 1-3 full copies per endpoint and 5 for one search (11s, searched 0 of 30); this build made 2 over sessions, stats, overview, manage, context, two searches and a second listing (search 30 of 30 in ms), and removed a planted day-old magpie-cursor-* folder. |
||
|
|
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. |
||
|
|
21702d01ff |
Add German translation; harden paths against unset env vars (#770)
* Add German translation and harden paths against unset env vars Add a German locale to the GUI, tray menu, usage alerts and website home page, and refuse to start when the home folder is unset or relative so nothing is written under the working folder; the pi plugin no longer adopts the user's PI_CODING_AGENT_DIR, and an inherited APPIMAGE no longer selects portable mode. Scripts refuse to run from the wrong folder or empty a shared out folder, and a new internal/testenv sandboxes every test package from the user's real files, which also fixes the Claude picker and Termux installer tests on Windows. * Makefile: know magpie's folder by its go.mod, so paths with spaces work The check compared $(CURDIR) with $(dir $(abspath …)), which make splits on spaces, so a checkout under 'My Projects' or 'John Doe' refused every target. It now reads go.mod relative to the working folder and wants magpie's module there: make -C and a symlinked Makefile work, make -f from another folder still stops before any recipe runs. * i18n: German for the strings main added since, with a parity test 75 strings main added (group order, patterns, slow-start wait, usage caps, RTK savings …) get their German, and two that main dropped go. gui-de.test.cjs checks, as gui-ja does, that de has every zh string with its placeholders and tags, and that the window reads in German when picked or on a German system. * appdir: ignore relative folder variables when reading, keep them for children CheckEnv no longer unsets anything. magpie reads the XDG folders, APPDATA/LOCALAPPDATA and every agent's folder variable through appdir.Getenv/LookupEnv, which pass over a relative value; the environment stays as it is, so the agents magpie starts get the variable as the user set it. That covers what proc.UserPath lends from the login shell too, which is set after main's check and reached the desktop app unchecked. On Windows a path rooted on the current drive (\Users\x, Git Bash's /c/x) counts as usable, and magpie version and help answer without a home, before run makes any folder. * Sandbox the tests main added since internal/wslrun gets testenv's TestMain, and four tests main added that set HOME alone set their home with testenv.SetHome, so on Windows they don't read the runner's profile through USERPROFILE. * agentenv: PI_CONFIG_DIR and OPENCODE_DB take relative names on purpose omp puts $PI_CONFIG_DIR under the home and OpenCode a relative $OPENCODE_DB in its data folder, so neither depends on the working folder: appdir no longer passes them over. * i18n: German for the Library's multi-select and System One's decision API The 19 strings main added since (#791's skill multi-select, the decision API snippets) get their German; the one main replaced (four APIs → five APIs) goes. * appdir: tidy the import into magpie's group; say what Go makes of /c/x The appdir import joins the group of magpie's own imports where a file has one. rooted's comment now says that Go takes a Git Bash path like /c/x as \c\x on the current drive, not C:\x. |
||
|
|
1e4174cada |
sessions: Cursor CLI's chats are on the Sessions page, each listed, opened, resumed and deleted to magpie's trash as another agent's sessions are (@ownsh1p on X: why doesn't the Sessions page show cursor-agent's sessions?) — magpie read the session files of Claude Code, Codex, OpenCode, Pi and the rest, and none of Cursor's. cursor-agent (2026.10.01) keeps a chat in its config folder ($CURSOR_CONFIG_DIR, else $XDG_CONFIG_HOME/cursor, else ~/.cursor) at chats/<md5 of the cwd>/<chat id>/store.db, a SQLite file of two tables as its run store (cursor-sdk-local-runtime's sqlite-blob-store) makes them: meta, whose row "0" is the chat's metadata as JSON in hex (agentId, name — "New Agent" until it has a title — createdAt, lastUsedModel, latestRootBlobId and, for a subagent's chat, subagentInfo with its parent's id), and blobs, content-addressed by the hex of their SHA-256. The root blob is a ConversationStateStructure (protobuf): field 1 the ids of the conversation's messages in order, field 13 the archives a compaction summed up (each one's field 1 the messages it summed up), field 26 when the conversation started. Each message is the AI SDK's JSON ({role, content: a string or parts — text, reasoning, tool-call, tool-result, image, file}). Newer builds also write meta.json beside store.db: title, createdAtMs, updatedAtMs, isSubagent and cwd, the one place the chat's folder is said in words (the folder's name is only its hash). This was read from the installed bundle and matches what other projects that read these stores found; no real chat was opened.
internal/sessions/cursor.go reads it: a chat is a session with the title meta.json or the store gives it (not "New Agent"), else its first typed prompt (the text in <user_query>, with Cursor's context tags — user_info, rules, system_reminder and the rest — left out, as Cursor's own transcript writer leaves them out); its cwd from meta.json; its start and last from meta.json and the store; prompts, replies and tool calls counted on the day it was last at work, since a message carries no time of its own. A subagent's chat, a sibling folder whose subagentInfo names its parent, is counted in its parent's session. Its resume line is cd '<cwd>' && cursor-agent --resume <id> — cursor-agent looks a chat up by the cwd's hash, so a chat whose cwd isn't known (no meta.json) gets none. There are no tokens or cost: Cursor counts and bills them on its servers and keeps none in the chat. A chat's WAL log and meta.json count in its size and time, so a chat Cursor is writing is read again and is never deleted mid-run. Reading writes nothing in Cursor's folder: SQLite opening a WAL store even read-only makes -wal and -shm files beside it and writes its read marks in -shm, which would also make every chat look written a moment ago and refuse its delete; a store with no log is opened immutable, and one with a log is read from a copy of store.db and its -wal in a temp folder that is removed after. Delete moves the chat's folder, its subagents' and its transcripts (~/.cursor/projects/<cwd slug>/agent-transcripts/<id>, .jsonl, .txt) to magpie's trash, and Restore puts them back. CURSOR_CONFIG_DIR and CURSOR_DATA_DIR join internal/agentenv's list, and the sessions tests' setup clears XDG_CONFIG_HOME, so no test reads a developer's own chats. Cursor's ACP sessions (acp-sessions/) and the editor's chats are not read. cursor_test.go builds stores as Cursor writes them in a temp folder — hex meta, SHA-256 blobs, a hand-encoded root with a compaction archive, a subagent's chat, one kept open by its writer so all of it is in -wal, one with its meta as plain JSON and no meta.json, one never spoken in — and checks the listing (two sessions, the subagent's in its parent's, the title from the typed prompt, cwd, start and last, no tokens, the resume line, none without a cwd), the counts and the tools, that reading leaves every file in Cursor's folder as it was (it made store.db-wal and store.db-shm before the immutable open and the copy), that a chat just written is refused, and Delete and Restore of the chat, its subagent's and its transcripts. go vet ./internal/..., go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui -count=1 ./... under a temp HOME pass. |