4794de398ea8337d223a91e207181c56fcf4ad76
95
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
81f587d7be |
sessions: omp's sessions in a WSL distro are listed on Windows, on the Sessions page and in Usage's Sessions tab, as Claude Code's, Codex's and Pi's there already are (#1150, #1138)
omp keeps its sessions under ~/.omp/agent in the distro's home, and in
a profile's own folder for omp --profile. wslAgents now names omp, and
allFiles reads wslFiles("pi", "omp"), so a distro's omp sessions show on
Windows marked with their distro and resume through wsl.exe. A session
under a profile resumes with omp --profile <name> --resume <id>; a
profile name that isn't plain ([a-z0-9][a-z0-9._-]{0,63}) gets no resume
command rather than one built from it (resumeCommand takes the session's
path for this).
Squashed from yetone/magpie#1150 at d7968f11b2ef419e30e1a6a169554b12e58c885a
onto main; docs/subsystems/gui-shell.md conflicted and keeps main's
"Streamed output speed" section and the PR's "Stored agent sessions in
WSL" section.
Run at this tree: gofmt; go vet darwin, GOOS=linux -tags nogui,
GOOS=windows; builds for all three; go test -tags nogui on
internal/sessions, internal/gui and internal/agent (agent with
-timeout 45m, it took 17 min on a loaded machine) green.
Broken by hand: with omp taken out of wslAgents, TestWSLSessionsListed,
TestWSLOmpSessionDeleted, TestWSLOmpProfiles, TestWSLStoppedDistroKept
and TestWSLStoppedSinceNotOpened go red.
Not tried: a real WSL distro with omp on the Windows box.
|
||
|
|
c984adfbc7 |
sessions: a renamed or moved Claude Code project folder is relocated with its sessions, from the Sessions page or the CLI (#1131)
Renaming or moving a project folder left Claude Code's transcripts under the old encoded project path: magpie listed them with a resume command for a folder that no longer exists, and Claude Code in the new folder didn't find them. A Claude Code folder row on the Sessions page now has Relocate project, which opens magpie's own dialog with the new absolute path, a read-only preview and a confirm that carries the preview's token; `magpie sessions relocate-claude --from --to [--confirm <token>]` does the same in a terminal (inside WSL too). The whole project store moves, session ids, subagents, tool results and memory with it; the transcripts' top-level cwd and the sessions index are rewritten, message text is not. The originals and a recovery manifest are kept outside Claude's project list, writes are staged before the originals are renamed, a change since the preview is refused, and a failed publish rolls back. An existing target store, recently written files, a malformed transcript, a symlink, an ambiguous encoded path or a long hashed name are refused. Desktop's stores are left alone. Recovery is in docs/session-relocation.md. Jianyu's PR head e8263cde, which conflicted with main: the button moved into main's folder() row, the CLI test into internal/cli beside sessions_cli.go, and both sides of sessions_manage.go and i18n.js kept. Run: see the next commit, which adds the zh-TW/ja/de strings and the GUI test. |
||
|
|
ab1cefeed8 |
sessions, gui: Usage's Sessions list shows the sessions the range counted (#1251, wizzy-yang)
The Sessions tab listed every session whose last line fell in the range, and
counted only those stats found at work there. A session whose file goes on
being written after its last call (a setting, a fork's seed) was listed but
not counted, so the note beside the list said more than the KPI above it.
statsAt now returns keys (agent:id) for the sessions it counted, in the
list's order. app.js filters the list by them in every range and falls back
to the old last-line guess only when keys are missing.
The PR also made days with prompts or replies count as at work, so a
session that spoke but spent nothing (one user line, a Cursor chat) is not
dropped. Main's
|
||
|
|
5e89b7f83d |
sessions tests: every agent's resume line is asserted on Windows too, not skipped there (#1069)
Ten of resumeCommand's agents (cline, qoder, qoder-cn, droid, grok, omp, opencode files/db/v2, pi, codex, claude) had their resume check wrapped in runtime.GOOS != "windows", so on Windows nothing checked the Set-Location -LiteralPath line resumeCommand builds there, its doubled single quote included. Each now asserts its own platform's line. This is the sessions half of TryWorld2026's #1069. Its internal/agent half (aside refusals, the Codex stale skip) was already done on main by |
||
|
|
067f39f406 |
sessions: Desktop titles read once per second, from every handle Desktop keeps, and reach stats and Context (#1675)
Follow-up to Koohoko's 3d6f8b8e, after review. - Cost: assemble asks DesktopTitles once per native Claude Desktop session, and each call globbed and stat'ed every local_*.json, so a list of N Cowork sessions looked at the metadata N times. The names are now one index, rebuilt at most once a second (desktopTitlesHeld); a rename in Desktop shows within that second. Files are read through filememo, the shared reader the usage resolver already uses for these same files, which also catches a same-size rewrite inside one mtime tick (the patch's own size+mtime cache didn't). - A record that is there but doesn't parse (Desktop midway through a write) keeps its last parse instead of dropping to the bare id; a record gone still takes its names with it. - Handles: Claude.app 2.7032's LocalSessionManager (app.asar, read-only) counts unarchivedCliSessionId as a live handle beside cliSessionId and preClearCliSessionId as lineage beside priorCliSessionIds, and runs a record with no cliSessionId under its sessionId without "local_". All are named now; the raw "local_..." id no longer is (no usage record carries it). - Siblings: MergeExternalStats (the Sessions page's stats summaries) and the Context page named gateway-only Desktop sessions by the recorded prompt or nothing; both use the Desktop name now. - docs/subsystems/gateway-sessions.md says all of the above. Real layout: no Desktop session records exist on this Mac or the Windows box (only claude_desktop_config.json), so field names and types were checked against Claude.app 2.7032's own reader/writer code: a string title, string cliSessionId/unarchivedCliSessionId/ preClearCliSessionId, an array priorCliSessionIds, files <account>/<org>/local_*.json under claude-code-sessions and local-agent-mode-sessions. Dirs come from desktopdir.Everywhere, the resolver the other Desktop session readers use (Windows %APPDATA% and MSIX LocalCache, Linux ~/.config); Windows/Linux not run. Run: new tests TestDesktopSessionTitleHandles, TestDesktopSessionTitleInStats, TestDesktopTitlesReadOncePerList, and context checks in TestDesktopSessionTitlesOnPages. Each broken by hand went red: rescan per call -> "metadata looked at 12 times, want once"; no last-good -> "a half-written file lost its names"; no unarchived/stem -> missing ids; stats without the name -> "stats titles map[cli-s:Recorded prompt ...]"; Context without it -> "context titles map[...: ...]". go test -race -count=20 -run TestDesktop ./internal/sessions; go test -tags nogui ./... (sandbox HOME, pinned caches): all ok but internal/plugin's TestPiPackage (pi-codemode export missing; passes alone, doesn't import sessions or gui), filed as #1879; gofmt -l; go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./...; go build, GOOS=linux go build -tags nogui, GOOS=windows go build. GUI: routing-sessions, session-identity, sessions-overview, sessions-bar-names, sessions-gateway-delete, sessions-manage, context-window in Chromium and WebKit (84/84 each). Real binary: magpie web under a sandbox HOME with Claude-3p Code and Claude Cowork fixture records and five claude-desktop usage records; the Sessions page (Chromium, WebKit) showed both titles on current, prior and unarchived ids and the bare id on the unmatched one; /api/gateway/session-titles named them; a rename showed after 1.3s; a half-written file kept the name; deleting the record went back to the id. Co-authored-by: Koohoko <koohoko@gmail.com> |
||
|
|
d46a5635c0 |
sessions: Claude Desktop uses its saved conversation titles (#1675)
Read Code and Cowork metadata when native CLI transcripts are absent, including current/prior CLI IDs and renames. Keep gateway identity, accounting and capabilities. Desktop titles take precedence over the recorded first-prompt fallback added upstream; unknown names keep it. Rebased onto |
||
|
|
d3d1605c2c |
sessions: Kimi Code's own calls reach Usage, read from its wire files (#1607, infinitr0us)
Usage counts the gateway's calls and the calls the agents' own session files record (sessions.Calls). Kimi Code had no reader, so its calls straight to api.kimi.com on Kimi's own sign-in never showed (the reporter's 47 k3 calls of one session on 2026-10-11). The reader (calls_kimi.go) is built from the redacted real wire files infinitr0us shared from two machines (protocols 1.0, 1.4, 1.5; text replaced, every id, model and number kept) and their notes from Kimi Code's source. It reads every agents/*/wire.jsonl under $KIMI_CODE_HOME/sessions, else ~/.kimi-code/sessions (as agent.KimiDir finds the new Kimi Code), main and subagents, ses_* folders included. One call per usage.record: inputOther, inputCacheRead and inputCacheCreation go to Input, CacheRead and CacheWrite, output as is, the record's own model and time. Nothing is paired with step.end, since 1.4 and 1.5 write them in opposite orders and the June 1.4 build has no messageId or llm.request. A model beginning "magpie/" (magpie's own entry in Kimi's config) is skipped: the gateway counted it. kimi fork copies the parent's records unchanged, so a call is keyed by agent (agentId, else its agents/<id> folder), time, model and usage, and Calls counts a key once. It is a whole-file call source (callSources, wholeCallReaders) and the folder is watched (Dirs). The subsystem page gets the list of call readers. Fixtures (testdata/kimi-code) are the reporter's files cut to the lines a call is read from, each line verbatim (50 KB; one of the July session's eight agents kept). Run: the reader over the reporter's whole, untrimmed files gives exactly their README's totals (32/2,841,972/12,283; 151/7,025,587/122,782; 6/147,822/2,009; 10/338,328/2,176; 0 for the four others). TestKimiCodeCalls (both homes), TestKimiCodeSkipsCallsThroughMagpie, TestKimiCodeForkCountsOnce, TestKimiCodeBrokenFiles (cut mid-record, empty, junk, null/negative/timeless usage) pass. Broken by hand, each goes red: no magpie skip, no key, key without agent, no negative or time guard, main only, KIMI_CODE_HOME ignored, cache read dropped. go test -tags nogui ./internal/sessions ./internal/usage ./internal/cli ./internal/gui under a sandbox HOME, gofmt -l, go vet (darwin), GOOS=linux go vet -tags nogui, GOOS=windows go vet. Not tried: a live Kimi Code run (fixtures are the reporter's real files, not a sandbox capture), a successful call through magpie (the magpie-routed record in the test is the reporter's quoted 1.5 line with a magpie/ model), a compaction record (usageScope "session", none in the files), Kimi Code in WSL (not read), Windows paths at runtime. A subagent's calls carry the session but no Subagent field. Thanks to infinitr0us for the write-up from Kimi's source and the redacted wire files. Reported-by: infinitr0us |
||
|
|
9935119f1d |
sessions: search finds Cursor and OpenCode sessions read from their stores, and a Cursor chat's system prompt isn't shown as said (#1743)
Follow-up to liubing's #1743 patch, which put cursor and opencode in HasTranscript. That moved their search from magpie's recorded transcript to SearchSession, whose byte prefilter (mayHold) reads s.Path. For these agents s.Path isn't the conversation: - OpenCode's JSON storage: the session info file, without messages, so every word missed; - OpenCode's and Cursor's SQLite stores: the newest pages are in the -wal, so a live chat's latest turns missed. linesFile now skips the prefilter for them (a Cursor .jsonl still gets it). cursorTranscript also handed the CLI store's system message ("You are a coding agent.") to the transcript as a said part; system messages are skipped, as the listing already does. The patch's tests commit left TestSearchSessionWithoutATranscript red (it used cursor as the agent without a transcript; now gemini). sessions-empty-range.test.cjs runs in every language, de at 420px. Run: go test -tags nogui -count=1 ./internal/sessions/ ok, and -race ok; sessions-empty-range 10/10 (Chromium+WebKit, en zh zh-TW ja de); sessions-today/overview/toolbar/search/manage/calendar-fill/paging GUI tests pass. Broken by hand: prefilter always on -> TestSearchOpenCodeFiles and TestSearchCursorLiveChat red; system skip removed -> TestSearchCursorLiveChat red. Also broke the patch itself: editor files not appended, readOnly Delete guard, stats message dates, CLI dedupe, HasTranscript entries, parseCursor readOnly dispatch, and the "All sessions" button (via MAGPIE_TEST_APP_JS); each went red. Co-authored-by: liubing <lb0806@foxmail.com> |
||
|
|
5d3d494431 |
sessions: reproduce missing editor histories and unreadable conversations (#1743)
The new Go tests fail on upstream
|
||
|
|
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. |
||
|
|
e08902e79d |
agent, library: Hermes Agent's folder is %LOCALAPPDATA%\hermes on Windows, and rtk's installer is told it (新v学员 on Discord)
新v学员 runs magpie on native Windows. Library -> RTK -> Hermes Agent
failed with "rtk's installer didn't add its hook to Hermes Agent:
Config: C:\Users\admin\AppData\Local\hermes\config.yaml ...". magpie
hard-coded ~/.hermes. Hermes' own default
(hermes_constants._get_platform_default_hermes_home) is
$LOCALAPPDATA\hermes on win32 (~/AppData/Local/hermes when LOCALAPPDATA
is empty) and ~/.hermes elsewhere, with $HERMES_HOME overriding it.
rtk 0.51's resolve_hermes_home knows only $HERMES_HOME and ~/.hermes,
on every OS.
What changed:
- appdir.HermesHome / HermesHomeIn / HermesDefaultIn: $HERMES_HOME,
else Hermes' per-OS default. This is the one place that resolves it.
- agent: hermesIn (Agents-page model wiring) and hermesProfiles use it
through place.hermesHome / hermesDefault. A WSL distro keeps
~/.hermes (Linux paths, Windows env not read). The Agents-page wiring
was wrong on native Windows too: without HERMES_HOME it wrote
%USERPROFILE%\.hermes\config.yaml, which Hermes never reads.
- sessions.HermesDir uses it, so Windows sessions are found.
- library/rtk: the hermes spec reads and writes the agent's own folder
(a.Dir), and rtkSpec.env passes HERMES_HOME=<that folder> to
`rtk init -g --agent hermes --auto-patch`.
- Tests resolve the folder through appdir instead of home/.hermes. New
TestHermesDefault/TestHermesHome (appdir), TestHermesFolder (agent:
Windows default, profiles under it, WSL unchanged), and
TestRTKHermesHome (library, a fake rtk that behaves like 0.51).
- docs/reference.md and docs/subsystems/library.md describe the
Windows folder and the env.
Run:
- gofmt -l clean. go vet ./... on darwin, GOOS=linux -tags nogui and
GOOS=windows.
- darwin: go test ./internal/appdir ./internal/library
./internal/sessions ./internal/agent ./internal/tui.
- TestRTKHermesHome against the old rtk.go fails with the reporter's
exact message ("didn't add its hook ... AppData/Local/hermes/
config.yaml"), and its default subtest fails with HERMES_HOME="".
- Windows box (cross-compiled test binaries, testenv sandbox
USERPROFILE/LOCALAPPDATA): appdir Hermes tests, agent
Hermes|Reseat|Effort (incl. TestHermesFolder) and library Hermes|RTK
pass. TestRTKHermesHome skips there (shell fake). The sessions binary
failed only TestHermesMessageVisibility, because its testdata wasn't
copied to the box.
- Real rtk.exe 0.51.0 on the Windows box: with
HERMES_HOME=<sandbox>\AppData\Local\hermes it wrote the plugin there
and patched that config.yaml. Without HERMES_HOME it wrote
C:\Users\<user>\.hermes, ignoring a sandbox USERPROFILE (rtk asks
Windows for the home folder). That confirms the cause and the fix.
The stray folder it made on the test box was removed.
Not run: real Hermes on Windows (no install, and running hermes under
a temp HERMES_HOME rewrites the live launcher); the GUI suite; the full
go test ./... ; the reporter's own machine.
|
||
|
|
a3f2097ede |
sessions: CodeBuddy Code's own calls reach Usage, read from its session files as WorkBuddy's are, and its calls through magpie's gateway are left to the gateway (#1779)
CodeBuddy Code was wired on the Agents page, but nothing read its session files, so a call it made straight to its vendor never reached the usage ledger. Only the calls it made through magpie's gateway showed, logged by the gateway. CodeBuddy Code writes its sessions the way WorkBuddy does: projects/<cwd>/<id>.jsonl under $CODEBUDDY_CONFIG_DIR, else ~/.codebuddy. A reply's usage sits in providerData.usage on its function_call or assistant message line, keyed by providerData.messageId, and models.json has the same format. So WorkBuddy's reader is now parameterized by agent: - buddyFiles(agent, dir) lists the files. - buddyGateway(dir, id) reads that agent's own models.json. Its stamp cache is kept per path. - readWorkBuddyCalls takes the agent from the file. "codebuddy" is registered in callSources and wholeCallReaders. A model CodeBuddy asks for as custom-local:<id>, where models.json names <id> with vendor "magpie", went to the gateway, and is skipped as WorkBuddy's are. The fixtures in testdata/codebuddy are CodeBuddy Code 2.164.0's own files (npm @tencent-ai/codebuddy-code), with only the cwd path shortened. They come from two `codebuddy -p` runs in a sandbox HOME against a local OpenAI fake: one on a model the user added for another vendor (counted: two replies, 521 in + 26496 cache read, 115 out), and one on a vendor "magpie" entry (skipped). Run: - TestCodeBuddyCalls goes red (0 calls) with codebuddyCallFiles taken out of callSources, and green with it in. - TestCodeBuddyGatewayIsItsOwn checks that each agent's models.json is its own. - go test ./internal/sessions passes. - gofmt, go vet, Linux nogui vet and Windows vet are clean. - Sandboxed go test ./... at the rebased head. Not done: - The Sessions page still doesn't list CodeBuddy Code's sessions. This commit is the Usage side only. - Reasoning tokens (outputTokensDetails) aren't recorded, as for WorkBuddy. - Not run against the reporter's China-edition session (47 calls). The line shapes match those in the issue. |
||
|
|
8bfe33f1f4 |
agent, proc: where each command is on PATH is looked up once while its folders are unchanged, so a Windows page doesn't stat PATH per agent and per session (#1771)
oxyuan profiled every page's first load on Windows at seconds (4-7s), and Sessions, Usage → Sessions and Context at 26-45s: 96-98% of the samples were os.Stat under exec.LookPath and proc.FindTool. A failed lookup stats every PATHEXT candidate in every PATH folder (111ms there), and the pages asked once per known agent (Detected → binAt) and once per Pi session (sessions.carries → ompThere) on every request. proc.Look (new, look.go) is exec.LookPath with its answers kept. The proc.LookPath that |
||
|
|
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. |
||
|
|
e044ea862f |
sessions: the warm-up at start reads with a quarter of the cores unless a page waits, and a long first read keeps what it read (#1665, laowangba233)
#1665: magpie pegs the CPU on every start (Windows Task Manager showed 95.8%). Three seconds after start, warmSessions indexes every Claude/Codex session file and reads every file's calls for usage. refresh() ran min(max(8, 2*NumCPU), 32) parsers at once and usage's prefetch 8 more, so the background warm-up took every core while nobody was looking at the result. Two goals, in one commit because they touch the same loop in refresh(): 1. Quiet warm-up (quiet.go). gui's warmSessions runs inside sessions.Warm. While a warm-up runs and no request waits, every parse in refresh() and every readCalls takes one of max(1, NumCPU/4) slots. A request to /api/sessions* or /api/usage* (gui's held middleware) calls sessions.Ask(), which lifts the limit for as long as it runs, so a page the user opened isn't slowed down. A waiting reader re-checks every 50ms, so Ask takes effect mid-read. 2. Checkpoints. refresh() saved sessions.json only once all files were parsed. Quitting magpie before that (a slow machine, or the user closing it because the CPU is pegged) kept nothing, and the next start parsed every file again. Now every 5s (checkpointEvery) the files done so far are published and saved, if the cache generation still matches. Measured on a Mac (14 cores) with a sandbox HOME holding 8.9 GB of real sessions (copied read-only), sessions.json and calls-v11 removed, sampling ps every 2s: - cold start before: 41.2 CPU-s, peak 580-600%, done ~14s - cold start after: 34.7 CPU-s, peak ~300-360%, done ~16s - quit mid-index, before: quit at 6s (13.5 CPU-s spent) left no sessions.json and no calls files; the next start spent 41 CPU-s again. - quit mid-index, after: quit at 12s left a 1.3 MB sessions.json (of 3.0 MB); the next start spent 26.6 CPU-s instead of 34.7. Tests (each red with its part undone, script-checked: refresh's slot replaced by a no-op, readCalls' slot removed, the checkpoint block removed): - TestWarmReadsOnlyInItsSlots: with every slot held, neither the index nor the calls read anything for 300ms; Ask() lets both finish. - TestReadSlotOnlyWhileWarming: outside Warm, or while asked, reads don't wait. - TestLongReadKeepsWhatItRead: a read held after its 3rd file has saved sessions.json with fewer files than it has to do. Run: go test -tags nogui ./internal/sessions ./internal/gui ./internal/library ./internal/usage; gofmt -l; GOOS=linux and GOOS=windows go vet of sessions, gui, library; full go test ./... before push. Not tried: the reporter's machine or data volume; a Windows re-measure. |
||
|
|
ddb3cef517 |
sessions: a visit to Sessions no longer parses Codex's config.toml again when it hasn't changed (#1665, laowangba233)
Profiled for laowangba233's report of CPU jumping on page switches: in a sandbox HOME with a copy of a real Codex config.toml (10,927 [projects."<dir>"] tables), 67% of GET /api/sessions/manage's CPU was go-toml parsing config.toml in readCodexConfig, for the provider Codex uses now (codexProviders -> CodexProviderIn). go-toml checks each table name against every sibling before it, so a file with that many projects takes ~0.2 s to parse, and it was parsed on every visit. readCodexConfig now keeps the parse through filememo, keyed by the file's size and time (and its bytes while it is less than two seconds old). Its callers only read the struct. Measured (sandbox HOME, 8.9 GB of copied sessions, macOS, 10 warm GET /api/sessions/manage after start): 3.00 s of CPU before, 0.94 s after (~0.30 s -> ~0.09 s a visit). TestCodexConfigParsedOncePerChange rewrites config.toml with the same size and time and expects the first parse; a real change is read. It fails with the memo undone. go test -tags nogui ./internal/sessions passes. |
||
|
|
5c9221899f |
sessions, agent: MiniMax Code's own calls reach Usage's split by agent, and its 0.6.8 User-Agent names it (#1605, LukeZ1988)
Usage's split by agent counts the gateway's calls and the calls the agents' session files record (sessions.Calls). MiniMax Code had no session reader at all, so a MiniMax Code on its own MiniMax sign-in or a relay of the user's never showed in it. What @minimax-ai/code 0.6.8 really writes, run in a sandbox HOME and MINIMAX_DATA_DIR against a fake Anthropic upstream: each session is a folder under <data dir>/v2/sessions/<yyyy>/<mm>/<dd>/, named <time>-session_<base64 of its mvs_ id>, its messages in messages.jsonl. An assistant line names the provider and model that answered, its usage (input without the cache, output, cacheRead, cacheWrite, as pi's ai package counts them) and the time in ms. The new reader (calls_minimax.go) is a whole-file call source (callSources, wholeCallReaders), and the folder is watched (Dirs). A call through magpie's own entry (custom_provider:magpie) is skipped; the gateway already counted it, with the account that answered. A reply is keyed by its message_id, so one copied into another generation of the history counts once. Gateway side: magpie's entry sets User-Agent minimax-code, and the sandbox run showed it reaching the upstream on /v1/messages and count_tokens. 0.6.8 without that header (a provider pointed at magpie by hand) sends "MiniMaxCode", which now names minimax-code too. The class check: StepCode, jcode, Prime Agent, Snow and every other built-in agent are named by their own gateway key (TokenFor); TestEveryAgentNamedByItsKey guards that for all of Clients(). Their direct, non-gateway calls are not read yet, and neither are those of pi, Cline, Qoder, Grok, Droid, omp, Cursor, Hermes and Alma, which the Sessions page reads (filed as #1607). Run: TestMiniMaxCodeCalls (the two real messages.jsonl files, verbatim: three calls through magpie's entry and one on a relay; under ~/.minimax and under MINIMAX_DATA_DIR) passes; dropping the gateway skip by hand turns it red (4 calls). TestAgentOf (MiniMaxCode, minimax-code), TestEveryAgentNamedByItsKey. go test ./internal/sessions ./internal/usage, the agent tests named above, gofmt -l, GOOS=linux and GOOS=windows go vet. Not tried: MiniMax Code on Windows or in WSL (WSL distros' MiniMax sessions are not read), a call on the MiniMax sign-in itself (provider name taken from the file whatever it is), or a session after compaction. |
||
|
|
5d1d2f66dd |
sessions: a Codex call in a turn of several is timed from what asked for it to its last output, not from its own tool's output (Fallmonkey on Discord)
An older Codex rollout (no token_usage_record) writes a call's token_count after the output of the tool that call ran. The call was timed from the last thing the model was given, which by then was its own tool's output, so its window was a millisecond or two: on 517 stripped copies of the owner's Aug/Sep rollouts gpt-5.6-sol's multi-call calls read p50 65,500 and up to 1,844,000 tok/s. A count written seconds after its tool's output gives the mid-range outliers (sol 972) Fallmonkey reported. Now a call begins to answer at its first output item (reasoning, a tool call, an assistant message). It is timed from what the model had last been given at that moment, and, when its own tool's output came before its usage line, it ends at its last output item rather than after the tool ran. Newer rollouts, whose token_usage_record comes before the tool's output, are timed as before: on 622 stripped recent rollouts every call reads the same (sol p50 44, max 82). On the older ones sol now reads p50 34, p99 53, max 54. A long output line (a large patch) is read by its head. The call cache goes to calls-v11 so cached calls are re-read. TestCallsCodexTimedFromTheAsk is built on a real 2026-09-06 rollout's shape with content stripped; on the old code it reads [15000 0 0 0] instead of [15000 29000 8000 9000], and with the long-line branch taken out it fails too. Ran: go test ./internal/sessions, gofmt -l, GOOS=linux/windows go vet. |
||
|
|
36839d503a |
agent: Claude Code kept in CLAUDE_CONFIG_DIR is listed on the Agents page, and a model picked for it goes to the settings.json it reads (#1482, edussss)
The Agents page looked for ~/.claude/settings.json alone, while the
sessions, the Library, the sign-in, the account import and the gateway's
Claude subscription all read $CLAUDE_CONFIG_DIR. A Claude Code whose
folder is elsewhere (CLAUDE_CONFIG_DIR set) wasn't listed when its CLI
wasn't on magpie's PATH either, and a pick, a tune and the gateway's
stand-in went to a ~/.claude it never reads. The sibling of CODEX_HOME
(
|
||
|
|
814a5ed73c |
agent: dsh asks each of magpie's models on its own API, a route per protocol (01huadalang on Discord)
dsh's llm-pi-ai sets one api for a whole route, so magpie's single "magpie" route asked every model over Chat Completions. A GPT served on Responses, or a Claude served on Messages, was translated from Chat, and its sealed reasoning was lost between tool calls. 01huadalang asked for a group per protocol. What changed: - dshPutRoute writes up to three routes from each model's catalog APIs (dshRouteOf): magpie (openai-completions, as before, for Chat models, Gemini-native ones, groups and agent-bridged sign-ins), magpie-responses (openai-responses, gateway /v1) and magpie-anthropic (anthropic-messages, the gateway root, forceAdaptiveThinking where gateway.AdaptiveThinking). A route left with no models is taken out. An api the user picked for a route in dsh's Models page is kept, and so are keys they added to it. - The start (agent-default-model) names its model's route on a pick, an effort change, and the home layer's mirror. Sync moves a start on one of magpie's routes to the route its model is now on (dshStartOnItsRoute), keeping its mark, effort and other keys. A start on the user's own route stays. - dshCheck checks each route's baseURL against its own api, and asks the route the start names to list its model. - Disconnect, dshOurs, dshKeepPick and dshFillNewProfiles know all three routes. sessions' dshGatewayProvider counts dsh sessions on any of them as magpie's. - docs/subsystems/agent-wiring.md: a line on the routes. Known limit: a dsh session resumed on a model that has since moved routes asks for the model to be picked again once, since dsh finds a model by route and id. Run: - go test -tags nogui ./internal/agent (whole package, default order) and ./internal/sessions -run TestDsh: pass. New tests TestDshRoutesAModelOnItsNativeAPI, TestDshSyncMovesAStartToItsModelsRoute, TestDshCheckSaysAStartOnAnotherRoutesModel and TestDshGatewayProviderTakesEveryRouteOfMagpies. With dshRouteOf forced back to the single route, the three agent tests go red. - Real dsh (headless, sandbox HOME and DSH_HOME) on patches magpie wrote, pointed at a fake gateway: the start on magpie answered from /v1/chat/completions, the one on magpie-responses from /v1/responses (reasoning.effort high), and the one on magpie-anthropic sent /v1/messages with thinking adaptive and output_config.effort high. dsh accepted all three routes. Its Anthropic turn then ended on my fake's SSE, not on the wiring. - gofmt -l clean. go vet -tags nogui for darwin, GOOS=linux and GOOS=windows on internal/agent and internal/sessions. |
||
|
|
f0834b6f0d |
gui, sessions: a session magpie's gateway recorded downloads as Markdown instead of a 400 (akic404 on Discord)
akic404's public magpie serves other magpies as a remote magpie and records
their agents' conversations. The Sessions page showed them, but Download as
Markdown in magpie web answered 400 {"error":"no such session"}: the export
(GET /api/sessions/markdown, and the app's POST /api/sessions/export) only
looked for the agent's own session file, and an agent that ran on another
machine has none here. The transcript endpoint already fell back to the
gateway's record; the export didn't.
sessionMarkdown now takes the same fallback: no native session, but a known
gateway session for that agent and id, is written from GatewayTranscript by
the new sessions.WriteGatewayMarkdown. It shares WriteMarkdown's layout
(writeMarkdown), says "Recorded by: magpie's gateway" in place of the file,
and notes when older turns or the end of a long part weren't kept. It is not
the Host check or CSRF: the GET with the web cookie reached the handler.
Run:
- Sandbox upstream (magpie web --gateway, MAGPIE_WEB_KEY) with recorded pi
and omp sessions reached through a downstream remote magpie: the old
binary's /api/sessions/markdown gave 400 "no such session"; the new one
gives 200 with the text, Content-Disposition
magpie-session-pi-01a126b7-2a4.md; without the cookie still 401.
- TestGatewaySessionExportsMarkdown fails on the old sessionMarkdown with
that 400 and passes now; TestSessionExportMarkdown, TestGatewayConversationAPI.
- go test ./internal/gui ./internal/sessions, gofmt -l, go vet for darwin,
GOOS=linux and GOOS=windows on internal/gui and internal/sessions.
|
||
|
|
89271cd4e8 |
provider, plugin, settings: accounts left all zero by a crash are read from their last good copy, and every state file is flushed before it is renamed in (#1505, Zhangwier)
Zhangwier's Windows machine went down hard, and logins.json (10783 bytes)
and plugin-auth.json (29926 bytes) came back at full length with every byte
0x00. Every account was gone. The rename had reached the disk before the
data. magpie then read "no accounts", and its next write would have made
that final.
What changed:
- Flushed before rename: steady.WriteFile writes a temp file, fsyncs it,
then renames it in. A failed write or flush removes the temp file and
leaves the old file as it was. edit.WriteAtomic, Kiro's writer, the
Codex session rewrite and the plugin host's writeDurable (host.js)
flush the same way. So do writePrivate (providers, logins, migrations),
settings, profiles, plugins.json, plugin-auth.json and mcp-signins.json.
- A last good generation: before each write, lastgood.Keep keeps the
valid file there as <file>.bak. A file that isn't valid is copied aside
as <file>.bad-<time>, with -2, -3 when two land in one second (O_EXCL),
and is never overwritten before that copy exists. The .bak lags one
write behind on purpose, since a crash zeroes the latest write.
- A failed read is unknown, never empty. On a cold start, logins.json,
providers.json, migrations.json, settings.json, profiles.json,
plugins.json, plugin-auth.json (Go and the host) and mcp-signins.json
are read from their .bak when they don't read. The recovery is logged
and listed in /api/state's recovered, and the window says it once in
every language. With no good .bak, a sign-out leaves plugin-auth.json
and mcp-signins.json as they are (the host's changeAuth no longer
writes {} over them). magpie's own sign-out returns the error, and a
sign-in copies the bad file aside before writing.
- caller-keys.json is flushed but never read from a .bak. A key revoked
in the last write would come back, so a store that doesn't read still
refuses every key, as its tests require.
ggbdpq's patch (f230bcae) is where the fsync-before-rename in
writePrivate, writeWhole and writeAuth came from. This change puts it in
one shared helper and reaches every other writer of magpie's state. The
JS write cleans up its temp file. The .bak recovery, the .bad copies and
the GUI notice are added here.
What was run:
- New tests, built from the literal case (10783 and 29926 zero bytes):
- internal/lastgood
- provider: TestZeroedLogins*, TestZeroedMigrations*,
TestZeroedProviders*, TestWritePrivateSyncsBeforeRename
- plugin: TestZeroedPluginAuth* against the real bun host,
TestPluginAuthSyncedBeforeRename with a plugin that makes fsync fail,
TestZeroedPluginList*
- TestZeroedSettings*, TestZeroedProfiles*, TestZeroedMCPSignIns*
- steady TestWriteFileSyncsBeforeRename, edit
TestWriteAtomicSyncsBeforeRename
- gui recovered-file.test.cjs (en/zh/zh-TW/ja/de, Chromium and WebKit)
- Broken by hand, each going red:
- Without the sync: the steady, edit, writePrivate and host fsync tests.
- Without the .bak fallback: every TestZeroed* test.
- The old changeAuth writes "{}\n" over the zeros.
- The old readLogins default.
- KeepBad without suffixes fails the one-second test.
- Without recoveredOnce, the GUI test fails 5/5.
- macOS: go test -tags nogui ./... in a sandbox HOME. The only failures
were the two access tests (then fixed by not recovering caller keys) and
TestProvidersCmdSaysUnreadable, which now removes the .bak to test the
no-backup case. Both packages were rerun and pass. gofmt -l prints
nothing. go vet, and GOOS=linux and GOOS=windows go vet -tags nogui, are
clean on the touched packages.
- GUI: recovered-file, whats-new, click-scroll, gui-de, gui-ja,
gui-zh-tw and i18n-keys pass.
- Windows box (cross-compiled test exes, sandboxed USERPROFILE/APPDATA):
lastgood, steady, provider, plugin (real bun host), settings, mcpauth,
edit and access pass. In profile, TestProfileSwitchesModelList and
TestOldProfileKeepsModelList fail the same on origin/main (filed as
#1517).
Reported-by: Zhangwier
Co-authored-by: ggbdpq <ggbdpq@gmail.com>
|
||
|
|
d47c0fea0b |
agent, provider: with CODEX_HOME set, a model picked for Codex goes to $CODEX_HOME/config.toml, the file Codex reads, and its sign-in is read and switched there (#1513, Wakkana, sunxwei)
Wakkana on Discord (macOS, Codex CLI 0.162.1) keeps Codex in a CODEX_HOME
of their own. Picking a model in magpie wrote ~/.codex/config.toml and
~/.codex/magpie-models.json, which Codex never reads, while magpie read the
pick back from the same file and showed it applied.
Checked each claim in the source: codexIn built its folder from
filepath.Join(at.home, ".codex"); so did StandIn, the compact-window tune
and KeepCodexDaemonCurrent; codexAuthPath (logins.go), codexAccount
(account.go) and the Usage card's auth.json (subscription_usage.go) read a
hardcoded ~/.codex, and since the app-server restart takes its home from
codexAuthPath, it restarted ~/.codex's daemon too. sessions.CodexDir,
catalog.CodexHome, library's codexDir and import_codex's config path
already read CODEX_HOME, each with its own copy of the rule.
Now there is one rule, appdir.CodexHome / CodexHomeIn: $CODEX_HOME through
appdir.LookupEnv (so the value proc.UserPath lends the desktop app from the
login shell counts, and a relative one reads as unset), else ~/.codex.
Every place that reads or writes Codex's files goes through it:
config.toml and the catalog (codexIn, so detection, Dir, models_cache,
history, logs, threads too), StandIn, tune, the daemon check, auth.json
read/switch/sign-in/sign-out, the import's own-catalog check, sessions,
the models cache, library targets (AGENTS.md, skills, MCP, rtk). A WSL
distro's Codex keeps ~/.codex (place.codexHome), since magpie can't read
a distro's variables. Left as they are, on purpose: library's project-level
.codex/config.toml (Codex reads that in the project whatever CODEX_HOME
is), sessions/wsl.go and wsl.go's distro probes, cliupdate's standalone
install path, and gateway/prompt.go's "/.codex/" path heuristic for a
Claude Code memory file. Codex itself doesn't expand "~" in CODEX_HOME
(0.162.0: 'CODEX_HOME points to "~/x", but that path does not exist').
Tests:
- TestCodexHomeEnvTakesThePick (agent): CODEX_HOME set, pick fakeup/m1:
config.toml and magpie-models.json land in CODEX_HOME, Get reads it back,
StandIn and tune use it, nothing exists under ~/.codex. Old codexIn:
FAIL "Codex's files at …/001/.codex/config.toml, want under
…/codex-home"; old tune.go: FAIL "tune didn't write
$CODEX_HOME/config.toml"; old StandIn: FAIL "stand-in … is """.
- TestCodexHomeEnvSignIn (provider): auth.json, config import path and
daemon home are CODEX_HOME's; two accounts listed from it; SwitchLogin
writes it; ~/.codex never created. Old account.go: FAIL "sign-in in
$CODEX_HOME not read"; old codexAuthPath: FAIL "auth.json at
…/.codex/auth.json".
- TestRestartCodexDaemon and gui's TestCodexDaemonRestartRoute asserted the
old ~/.codex daemon under CODEX_HOME=/somewhere/else; they now want
/somewhere/else. TestFolderVarsAreListed scans appdir/codex.go too, so
its CODEX_HOME canary still finds the read.
Real use, sandbox HOME + CODEX_HOME=<sb>/custom-codex, MAGPIE_ADDR on a
free port with a stand-in listener: `magpie codex fakeup/m1` (this build)
wrote custom-codex/config.toml + magpie-models.json, no <sb>/home/.codex;
real codex 0.162.0 with that CODEX_HOME: `codex debug models` listed
fakeup/m1, `codex exec` sent POST /v1/responses model=fakeup/m1 to magpie's
address. The origin/main build in the same sandbox wrote
<sb>/home/.codex/{config.toml,magpie-models.json} and left
custom-codex/config.toml at model = "gpt-5.5" (the report). The GUI app
was not run.
#1513 (sunxwei, native Windows 0.1.1157, CODEX_HOME=F:\codex-home) is the
same bug. Windows has no shell to borrow from: a user-level variable is in
the environment Explorer hands the Start-menu app, which is what
appdir.LookupEnv reads, and a drive-letter path is rooted. On the Windows
box: the agent, provider and appdir test binaries (GOOS=windows) pass
TestCodexHomeEnvTakesThePick and TestCodexHomeEnvSignIn with CODEX_HOME a
C:\ temp folder; this build's magpie.exe codex fakeup/m1 in a sandbox
USERPROFILE with CODEX_HOME=D:\codexhome-sb\custom-codex wrote config.toml
(model, magpie provider, catalog) and magpie-models.json there and created
no %USERPROFILE%\.codex. Codex itself isn't installed there, so it was
not run on Windows.
Run: go test -tags nogui ./... in a temp HOME (all ok after the three test
updates above; re-ran agent, provider, gui, catalog, sessions, library,
appdir, usage, codexcat after rebase; gateway after rebase hit the 10m
default timeout at load ~150 and passed with -timeout 25m in 656s),
gofmt -l clean, go vet +
GOOS=linux + GOOS=windows go vet -tags nogui on the touched packages.
|
||
|
|
b6a263b9fd |
gateway, usage: the Usage page's numbers are read over the gateway, and a Claude Code subagent's call says which subagent and which started it (HoGee_xxl on X)
HoGee_xxl wants their own usage app to read magpie over the gateway, which had no /api/usage counterpart, and asked for subagents' parent ids. - GET /v1/magpie/usage (the /api/usage summary, ?period=) and GET /v1/magpie/usage/requests (the /api/usage/requests ledger page, same filters, offset/limit) on the gateway. The builders moved out of gui into internal/usageapi so both serve the same JSON; gui keeps aliases and sets usageapi.Clients for agent names (gateway can't import agent). Guard as /v1/magpie/quotas: this machine, or another with an enabled gateway key, behind the same Host check. A key held to a budget, models or accounts is refused the summary (403) and gets the ledger filtered to its own CallerKey, with callerKeys/agents/providers/accounts cut to its own rows (usageapi.OwnPage): those facets are drawn from every call in the period. `path` is left out for another machine. - usage.Record gains subagent and parent_agent; session stays the parent conversation. Gateway rows take them from x-claude-code-agent-id and x-claude-code-parent-agent-id; session-file rows from the file name (<session>/subagents[/workflows/<run>]/agent-<id>.jsonl, no cache version bump) and the parentAgentId of the agent-<id>.meta.json beside it. Both packed into the request page's text columns (now 29, msg at 29). Codex sub-threads: only kind, as before; no spawned thread on disk to take a parent shape from. Run: real Claude Code 2.1.296 under a sandbox CLAUDE_CONFIG_DIR against a local fake Anthropic endpoint that made it spawn a subagent from a subagent: the nested request carried X-Claude-Code-Agent-Id=a143287ac46b82a96 and X-Claude-Code-Parent-Agent-Id=a99ca20c03d1813d8, the first-level one the agent id only, Session-Id the parent's throughout; the nested meta.json had parentAgentId. Tests use those bytes. TestUsageOverGateway goes red with OwnPage, the CallerKey pin, or the header read removed (each tried). gofmt -l clean; go vet ./...; GOOS=linux go vet -tags nogui ./...; GOOS=windows go vet ./...; set -o pipefail; go test ./... green. |
||
|
|
82990126db |
sessions: a gateway turn cut off mid-write no longer makes every later turn of its session fail on Windows (#1468)
turns.jsonl was opened with O_APPEND. On Windows Go opens such a file
with FILE_APPEND_DATA and without write access, so the Truncate that
drops a cut-off last line was refused ("Access is denied"), and
SaveGatewayTurn failed for every later turn of that session. The file
is now opened read-write without O_APPEND and the line is written with
WriteAt at the end found (gatewayMu already keeps another save from
writing in between). No other file in the repo is both opened with
O_APPEND and truncated.
Run:
- Windows box (xiaomi-gpu), GOOS=windows test binaries of
internal/sessions under a scratch USERPROFILE/APPDATA/TEMP:
origin/main (
|
||
|
|
282c9feb23 |
agent: a packaged Claude Desktop gets magpie's gateway in the real %LOCALAPPDATA%\Claude-3p too, which 2.31226 reads, not only the package's (bg5eau on X)
bg5eau on X: Claude Desktop 2.31226.1, installed as an MSIX package on
Windows, never reached magpie. magpie wrote deploymentMode and its
configLibrary profile only into the package's
LocalCache\Local\Claude-3p, and that build reads the real
%LOCALAPPDATA%\Claude-3p. Copying configLibrary there and setting
deploymentMode 3p fixed it for them.
What the build does: 2.31226.1's asar (index.chunk-Cyt2WTko.js) resolves
the 3p userData with Ou() = path.join(LOCALAPPDATA, "Claude-3p"). 2.7032.0
has the same code (GY()). It reads deploymentMode from
Ou()/claude_desktop_config.json and the gateway from Ou()/configLibrary.
The path didn't change; the package stopped redirecting it into
LocalCache. An install's folders don't say which build it is, so:
- desktopdir.Sets returns every set of folders: Find's choice first, then
the other one for an MSIX install. Everywhere lists every set's folders.
- Claude Desktop's switch writes and removes deploymentMode, the profile
and _meta.json in each set. The package's set keeps its own stash keys
(".package"). A stash that an older magpie wrote for the package's
folders moves onto those keys, so turning it off still restores them.
- The check runs on each set, names the folder when there are two, and
checks Claude-3p's deploymentMode as well.
- The siblings: the library's MCP servers go into every Claude-3p file
that exists, and Cowork skills and Desktop sessions are read from every
set.
Run:
- go test ./internal/{desktopdir,agent,library,sessions,usage}: green.
- The new tests (TestClaudeDesktopMSIX, TestClaudeDesktopMSIXStashBefore,
TestClaudeDesktopMSIXBoth3p) and TestCallsCoworkMSIX are red against
the old code. StashBefore also goes red with desktopAdoptStash disabled.
- gofmt; go vet for darwin, linux and windows.
- On the Windows box, Windows test binaries for the four packages:
- desktopdir and library pass.
- agent and sessions fail exactly the set that main's binaries fail
there (#1388, and newly filed #1468).
- Every Desktop test passes.
|
||
|
|
eb035e29e1 |
sessions: a session seen only through the gateway can be deleted: its row and recorded conversation go to magpie's trash, and Restore brings them back (lc on Discord)
lc ("只可列出?不可删除?agent claude code") saw Claude Code sessions named by
uuid under "No folder" at "0 B", with "These Claude Code sessions are read
only; magpie can list them, but cannot resume or delete them." Those rows are
gateway projections from the usage ledger: Claude Code ran with its own files
somewhere magpie can't see (another computer, a container, another config
folder), so nothing native won on the same agent+id. An agent with only such
rows was sent as not deletable, and every row was read_only, so the page had
no Delete at all.
What changed:
- sessions.DeleteGateway moves the session's recorded text folders
(gateway-conversations/<date>/<identity hash>) into
trash/sessions/gateway/<ts>-<hash>/files/<date> with a note marked gateway,
and records {agent, id, last} in gateway-sessions-hidden.json.
/api/sessions and /api/sessions/manage leave it out up to that last
request; a newer request lists it again. The usage ledger is untouched, so
Usage, /api/sessions/one and stats keep what it spent. A session with a
request in the last minute is refused as active.
- Restore moves the text back (skipping what expired or was cleared, refusing
rather than overwriting a same-day re-recording), checks each item is this
session's identity folder inside the store, and unhides it. Delete forever
keeps it hidden.
- The recording's promises hold in the trash: the hourly prune erases
trashed gateway text past 7 days, "Delete saved conversations…" erases it
too, and HasGatewayConversations counts it.
- The manage route marks an agent with gateway rows deletable and sends
those rows deletable, with gateway: true and the size of their recorded
text; the delete route sends gateway ids to DeleteGateway and native ones
to Delete as before.
- Sessions page: gateway rows group under "Seen through the gateway"
instead of "No folder", show "{size} recorded" only when something was
recorded (no "0 B"), and the note says why they can't be resumed and what
Delete takes and keeps. The delete dialog says the same for gateway rows
instead of "Their files are moved…"; the Trash marks them and notes the
7-day expiry. New strings in zh, zh-TW, ja and de.
- docs/subsystems/gateway-sessions.md describes the delete, hidden list,
restore, expiry and clear.
Verified:
- go test -tags nogui ./... (sandbox HOME) green; gofmt -l clean; go vet
./...; GOOS=linux and GOOS=windows go vet -tags nogui ./internal/sessions
./internal/gui; go build, GOOS=linux -tags nogui and GOOS=windows builds.
- TestSessionsDeleteGatewaySession fails on the old code with "Claude Code
with only gateway sessions isn't deletable: [{Agent:claude
Deletable:false}]"; sessions-gateway-delete.test.cjs fails there too.
TestGatewayDeleteTrashExpires, TestGatewayPurgeKeepsItHidden,
TestGatewayDeleteNothingRecorded and TestGatewayRestoreRefusesForeignItems
cover expiry, purge, an unrecorded session and a forged note.
- GUI: sessions-gateway-delete.test.cjs in Chromium and WebKit, en, zh,
zh-TW, ja, de, at 1000 and 390px (in-app dialog, Cancel sends nothing,
click doesn't scroll, no left-border accents, no page overflow); all
sessions-*, gateway-conversations, checkbox-look, old-webkit,
sess-agent-strip, i18n-keys, gui-ja, gui-de and gui-zh-tw tests pass.
- Real try: magpie web from this tree on a sandbox HOME seeded with three
gateway-only Claude Code sessions (two recorded): deleted a recorded and an
unrecorded one, checked the store, trash and hidden list on disk, restored
the recorded one (its transcript reads again), purged the other (stays
hidden). That try found the Trash page breaking on an unrecorded session's
null items; DeleteGateway now writes [] (TestGatewayDeleteNothingRecorded
fails without it) and the page reads a missing list as empty.
|
||
|
|
62d7cd7be3 |
sessions: recording gateway conversations is a setting card over the list, with what it keeps and where, and a labelled delete that shows only when text is kept (lee on Discord)
What changed:
|
||
|
|
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. |
||
|
|
9fbdd584ed |
codex: a thread started on a provider config.toml no longer has opens again, through magpie (#1372, obstrux: "ChatGPT 无法加载 config.toml … Model provider custom not found")
The Codex app resumes a thread on the provider it was started on, kept in
Codex's state database (app-server thread_processor.rs:
merge_persisted_resume_metadata), whatever config.toml's model_provider is
now, and loads no config for it when config.toml has no table of that id
(core config: "Model provider `{id}` not found"). CC Switch puts every
third-party thread on "custom" and rewrites config.toml whole when it
switches, so a switch to its official provider leaves those threads with no
table, and the app can't open them. magpie never removes [model_providers.custom],
but nothing put it back either.
While magpie is wired into Codex (takeTables: set, Join and Sync), each
provider a thread in state_*.sqlite names that config.toml has none of
(table, inline or dotted) gets a table pointed at magpie's gateway, as
CC Switch's own tables already are. Codex's built-in providers (openai,
ollama, lmstudio, amazon-bedrock[-runtime], ollama-chat) and magpie's own
are left out, and a provider the user has stays as it is. The table stays
when Codex steps off magpie, as magpie's own does, for the threads that
name it. Not wired, nothing is written. sessions.CodexThreadProviders reads
the distinct model_provider of the threads table, read-only.
Run:
- Real Codex 0.161 in a sandbox HOME: `codex exec` recorded a thread under
a [model_providers.custom] pointed at a fake Responses server, the table
was removed, and the app-server's thread/resume answered "failed to load
configuration: Model provider `custom` not found" (the reporter's error).
With this build's `magpie codex fakerelay/m1` (sandbox HOME, gateway on
127.0.0.1:3546), [model_providers.custom] was written to the gateway, the
same thread/resume succeeded, and a turn on it completed through magpie to
the provider (its request reached the fake). The thread kept "custom".
- TestCodexWritesTablesThreadsName (signed in and not) fails without the
call ("custom not written through magpie"), and its inline case fails
without the parsed check ("edited TOML is invalid: key inl should be a
table"); TestCodexThreadTablesOnlyWired.
- gofmt -l, go vet, GOOS=linux/windows go vet -tags nogui on agent and
sessions, GOOS=linux go build -tags nogui, GOOS=windows go build, and
go test -tags nogui ./... under a temp HOME. One full run failed
TestSetAnswersWhileDevinAndProvidersHang (internal/gui, set took 1.6s
against its 1.5s wall-clock bound; Claude only, Codex not wired, so this
code isn't on its path); it passes alone 5/5 (0.19-0.42s) and in a rerun
of gui, agent and sessions together.
|
||
|
|
8df15fd437 |
sessions: the page's limit counts nonempty sessions only (#1324)
List sorted the session keys by file mtime and truncated them to the limit before assemble dropped empty sessions, so a newest empty file ate the page: List(1) answered no session at all though List(0) found two, and on an mtime tie an empty one could win the key tie-break. The limit now falls on the assembled sessions: keys are walked newest first and a nonempty one takes an empty one's place until limit are collected; the most-recently-active-first order is kept. Reproducer by @Ethereal49 in #1320, red before (limit=1 returned 0 nonempty sessions, want 1) and green after; the TestList flake they saw under -race -count=20 does not repeat with it. Fixes #1320. Signed-off-by: Charan Rathore <180254320+charan-rathore@users.noreply.github.com> |
||
|
|
79f9b3752b |
sessions: a Codex archived copy rewritten at the same size in the clock tick of its last comparison is compared again, not taken from the cache, on Windows too (#1299, wizzy-yang)
The copy cache trusted a change time it had seen as proof the file had not changed. NTFS stamps ChangeTime from Windows' clock tick, not the precise clock: on the Windows box, 300 ms of back-to-back same-size writes got a new ChangeTime only every ~0.5 ms (2147 of 2691 writes kept the previous stamp; diffs 0.5/1.0/1.5 ms). A rewrite in the tick of the comparison kept the stamp the cache saw, so the cached relation was reused. That, not write merging, is why TestCodexArchivedSameSizeRewriteInvalidatesDiscovery failed 19 of 300 runs on Windows, alone as well as in the full package. A comparison is now cached only when both files' change times are more than a second older than the moment it started (codexStampSettle); a file changed more recently is compared again next time. A later rewrite then lands in a later tick and changes the stamp. Change times are compared as times (Windows FILETIME converted). TestCodexSameTickRewriteIsNotCached gives every write one change time and a clock 10 ms into that tick. With the settle rule taken out (cacheable = both stamps present), it fails: "a rewrite in the tick of the comparison reused its stale relation". With it, it passes, and the second half checks settled copies are still compared once, not every time. TestCodexArchivedDiscoveryCacheAndAppend moves its clock a minute on so the just-written copies count as settled. The Windows CI step now runs the Codex copy tests (CodexArchived, CodexSameTick, CodexPlainTwin), which it had never run. Run: Windows 11 box (cross-built sessions.test.exe, sandbox USERPROFILE/ APPDATA/TEMP): old binary 19/300 failures of the reported test; new binary 0/1000 for the three Codex copy tests, and the Windows CI regex x5 with testdata passes. macOS: go test -race ./internal/sessions, -race -count=30 of the Codex copy tests, go vet (darwin, GOOS=linux, GOOS=windows), gofmt -l. Not run: Linux with a coarse ctime clock (kernels before 6.13); the rule covers it the same way. |
||
|
|
4b8bfd4676 |
gui: Routing's By session heads a Claude Code (and every other agent's) session with its own name, not its UUID (#1293, luzhuang)
Only Codex sessions were named (from Codex's index). The page now also asks POST /api/gateway/session-titles for the other agents' sessions it lists, as agent:id keys, and sessions.Titles reads each from the agent's own files the way the Sessions page does: the name given in magpie, else the agent's own title (Claude Code's ai-title / custom-title), else the first prompt. Each key is asked once; the names are kept on the page, so a live update that replaces the rows keeps them. A session with no file here keeps its id. TestSessionTitlesNameOtherAgents fails without the change (titles = map[]), and routing-sessions' "other agents' sessions show their own names" times out waiting for the name without the routing.js change. Run: HOME=<temp> go test -tags nogui ./internal/gui ./internal/sessions; go vet for darwin, linux and windows; the 72 routing GUI test files in Chromium and WebKit (491 pass, 0 fail). No new t() strings. |
||
|
|
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. |
||
|
|
1b29cb81a2 |
agent, wslrun, sessions, gui: Settings → General has Detect agents in WSL; off, magpie asks wsl.exe nothing and shows no WSL agents or sessions (#1264)
On Windows magpie lists the running distros and probes each one for agents, their sessions and Claude Code. Etsuya233 asked for a way to turn that off. settings.NoWSLAgents (per machine, kept by KeepOwn) now gates every auto-discovery path: agent.wslAgents/wslHomes/WSLRunning, sessions' wslFiles/wslDirs (via the new sessions.WSLOff hook), and wslrun.Find, which the Claude subscription uses to run Claude Code in WSL. The toggle is shown on Windows only and is on by default. Verified: - red without the change: TestWSLDetectionOff (1 WSL agent with detection off; with only sessions reverted, a distro's session is listed), TestFindWithDetectionOff (Find returned Ubuntu after asking wsl.exe). - go test -tags nogui ./... in a sandbox HOME: every package ok except TestPluginLoginTakesTheLapseOff, which timed out at 63.7s under the full run and passes alone (-count=3) and with its package (-count=1); it doesn't reach WSL. - go vet -tags nogui on agent, wslrun, sessions, settings and gui for darwin, linux and windows. - GUI: wsl-agents-setting (en/zh/zh-TW/ja/de, 900 and 440px) 30/30; gui-ja, gui-de, gui-zh-tw, i18n-keys, keep-awake, lightweight, settings-sections, settings-groups 44/44 in Chromium and 44/44 in WebKit. - Windows box (10.0.0.132), nogui magpie.exe in a sandbox profile with a logging wsl.exe first on PATH: on, `magpie agents` listed Claude Code · WSL magpie-desktop after 3 wsl.exe calls; off, `agents`, `ls` and `sessions` made no wsl.exe call and wrote no wsl.json. Not tried: the toggle in the real Windows GUI window, and Claude Code in WSL through the Claude subscription with the setting off (unit-tested only). |
||
|
|
6a8095421e |
sessions tests: TestCursor expects the resume command Windows gives it (red on Windows in main since 585f7f7d) (#1248)
|
||
|
|
5d0c1dcad7 |
agent, library, sessions: a Claude Desktop installed as an MSIX package on Windows is found, wired, given MCP servers and skills, and its Cowork calls read, in the package's folders (Kilig on Discord, Windows 10 LTSC 21H2)
Desktop from its setup.exe there runs packaged, so Windows keeps what it
writes under %APPDATA% and %LOCALAPPDATA% in
%LOCALAPPDATA%\Packages\Claude_<publisher>\LocalCache\{Roaming,Local}.
Nothing was in %APPDATA%\Claude or %LOCALAPPDATA%\Claude*, so magpie didn't
recognise Desktop at all. The packaged app reads its own copy before the
real folder's, so writing the usual folders wouldn't reach it either.
New internal/desktopdir is the one resolver for Desktop's folders: Data
(its own userData: %APPDATA%\Claude, the package's LocalCache\Roaming\Claude),
Mode (the Claude folder deploymentMode goes into, %LOCALAPPDATA%\Claude as
before) and ThreeP (Claude-3p). The package is found by globbing
Packages\Claude_* (the publisher id isn't assumed) and used unless Desktop
runs in the usual folders: it has run there (Chromium's "Local State"; an
%APPDATA%\Claude holding only another tool's claude_desktop_config.json
doesn't count) and not later in the package's. Every place that built
these paths goes through it:
- agent: desktopDirs (its 3p switch's writes, DesktopConfig3p, Claude
Code's desktop check in claude.go) and detection, which also looks at
Data (replacing the separate %APPDATA%\Claude check). windowsDesktopDir
moved into desktopdir unchanged.
- library: apps() (Desktop's MCP file, was os.UserConfigDir) and
desktopSkillRoots (Cowork's skills-plugin).
- sessions: desktopDataDirs, a copy of agent's resolver, now desktopdir's
All(); it also adds %APPDATA%\Claude on a usual Windows install, where
Desktop keeps 1p Cowork sessions (only %LOCALAPPDATA%'s were read). usage's
request_page and session_provider read it through sessions.DesktopDataDirs.
Tests: TestFindMSIX/TestFindWindowsClassic/TestFindOthers (desktopdir),
TestClaudeDesktopMSIX (agent: detected, switch writes LocalCache\Local\Claude
and Claude-3p, nothing in the usual folders), TestClaudeDesktopMSIXLibrary
(MCP file and skills-plugin in LocalCache\Roaming\Claude),
TestCallsCoworkMSIX (sessions). With the call sites put back to origin/main
the last three fail: "an MSIX Claude Desktop isn't detected", "no Claude
Desktop target: <nil>", "dirs: [.../Claude .../Claude-3p]".
Run: go test -tags nogui ./... under a temp HOME with pinned caches (all
ok); GOOS=darwin|linux|windows go vet -tags nogui on desktopdir, agent,
library, sessions, usage; GOOS=windows go build, GOOS=linux go build -tags
nogui. On the Windows 11 box (Squirrel install, no MSIX package): the
windows test binaries pass every Desktop/MSIX/Cowork test; the full agent
and sessions binaries fail the same 16 and 76 tests (run outside their
testdata) as origin/main's; a read-only probe of desktopdir.Here() gives
the usual %APPDATA%\Claude, %LOCALAPPDATA%\Claude and Claude-3p, Package "".
Not tried against a real MSIX Desktop: none on the box, and Claude-3p's
place in the package (LocalCache\Local, as Local\Claude is in Kilig's
listing) is inferred, not seen.
|
||
|
|
e95852e301 |
usage, gui: 用量页补上各 agent 会话文件里的用量,请求页按「经过 / 不经过 magpie」拆开 (#948)
* sessions: dsh、ZCode、WorkBuddy 的会话文件里有各自花掉的 token,用量台账从来不读
Sessions 页面一直都在读这些 agent 自己的会话文件,用量台账没有:用量页只显示网关本
身应答过的调用——也就是装上 magpie 之前的什么都没有,而一个直接指向厂商的 dsh 更
是什么都没有。本机上装 magpie 之前就已经在用这些 agent(用它们自带的模型),那段
用量一直对不上账。
* 新增三类"整文件读取"的调用来源,走 wholeCallReaders(它们的调用不是一行一条,
或者文件不能从中间接着读):dsh 的会话是 zstd 分帧追加的;ZCode 用的是 OpenCode
那几张表;WorkBuddy 的同一句回复会在多行里重复同一个 messageId。三者的 token
语义各自换算成 Call 的 Input/Output/CacheRead/CacheWrite,调用缓存跟着记一份(v9)。
* 每个来源都跳过经由 magpie 网关发出的调用:网关自己记过那一本账,还带着真正应答
的供应商和账号;dsh 发往网关的请求不带会话头,两边事后对不上(token 数每次不同、
又没有可配对的 id),硬读就是同一通调用记两次。dsh 认它被配置去的那个 provider
(dshGatewayProvider:magpie / dial),ZCode 和 OpenCode 认路由里写的 provider
(ocGatewayProvider)。WorkBuddy 那部分见下一个提交。
* WorkBuddy 的调用里,同一句回复的多行只记最后一次(它带这个回复的总量);而它从
旧历史搬过来的回复一条 messageId 都没有,每一条都是独立的一通调用——会话汇总的
读法(workbuddyLine)就是这么数的,这里照它来,否则台账会比 Sessions 页面少算,
正是本次要消灭的那类"两页对不上",只是方向相反。
* dsh 的一通调用保留它文件里记的两样东西:被配置去的供应商(Upstream,作为历史,
从来不当成路由的证据),以及厂商真正应答的模型——回复的 replayState 里那个和
请求模型不一致时,Model 记应答的、Requested 记被请求的,和 Claude Code 的文件
一样的读法,好让请求表的若干列有东西可填。
* 会话的 fork:dsh 的会话从另一个会话续起来时会带上对方已写入的事件(isSeeded /
seedLength,session/end-seed 标记之后的不算),parser 跳过的这里同样跳过,否则
同一通调用会在每个 fork 上再花一次。
* WorkBuddy 的 subagents/ 子目录是父会话自己的调用来源(它带自己的消息 id,会话
归到父会话名下);调用这条路不读 file.main,那个标记是 Sessions 页面给"会话自己的
文件、不是子代理的"用的。
夹具:dsh 的三个会话(普通、带供应商与应答模型、以及一通经网关的),ZCode 的两条
(其中 ses_zcA 那条的 providerID 是 magpie,应被跳过),WorkBuddy 的既有会话(m1 的
usage 同时落在 assistant message 和它最后一个 function_call 上,只能记一次;旧历史
三条无 messageId 的回复各记一次)和一通经网关、一通走用户自建端点的会话。
调用缓存升到 v9:v8 里既没有 dsh 的供应商和应答模型,也没有"跳过网关调用"这件事,
旧缓存会继续把旧账 Serve 出来。
TestDshCalls、TestZCodeCalls、TestWorkBuddyCalls 是新的;把跳过网关调用那几行、以及
WorkBuddy 旧历史那条判据去掉,它们必挂、加上必过(都实际跑过反向验证)。
验证:go vet;go test ./internal/sessions(只余 TestCursor,Windows 路径前缀问题,
改动前同样失败);go build(windows)。
* usage: 请求页把"magpie 转的"和"它只读到的"分成两个数,GUI 跟着拆成两栏
用量页一直只显示网关自己应答过的调用,而现在它还要读 agent 自己会话文件里的调用:
两本账混在一行里,读者分不清哪一段是 magpie 转的、哪一段只是它从文件里读到的,
而总数事实上几乎全部来自后者(本机 30 天 847M token 里,网关只转了 2.4%)。Summary
里的两个来源卡片也加不出这个数来:它们只算 input 和 output,上面的 KPI 把缓存的
token 也算在内,于是"全部请求"读作 13.6M,而"Tokens"是 847M。
* usage.RequestPage 和 usage.Filter 各多一样东西:前者在 Sum 之外带上 Through 和
Direct(网关应答的,和从会话文件读到的),后者多一个 Through 维度。两种建页路径
(流式的 queryPage 和治疗桌用的 pageFromLedger)都做同一个拆分,两边一致——
TestCompactPageMatchesLedger 现在也覆盖两个来源筛选。
* 每一行本来就是按 Source 区分这两类的("log" 是会话文件里的调用,其余走的网关),
拆分就落在它上面;网关自己拒掉的调用两边都不算(页面在总数下面也这么说),所以
SourceOf 对它返回 "",点哪一栏都同样把它排除,两栏自己的计数本来也不含它。
* 两栏自己的数字是在"来源"这个挑选被清空的情况下数的,和各维度分组一样:三栏是读者
来回切换的地方,各自得一直报着自己的数,否则点了其中一栏另一栏读作 0,且没有回
到全部的路。
* /api/usage/requests 支持 via=through|direct;GUI 那一侧的三个格子、计数单位、
方块样式在下一个提交里。
* Filter.Via 这个名字和 Record.Via(转发调用的那台电脑,#542)重了,改叫 Filter.Through。
Sessions 页列表长度那件事(sessionListLimit)拆到单独的 PR 里,不在这里。
验证:go vet;go test ./internal/usage(只余 TestOTelRetryAfterBound,计时的 ±30ms,
origin/main 同样失败);go build(windows)。
* gui: 请求页把来源拆成三栏,汇总那一排也改成方块
用途页的请求栏一直只有一本账(Sum),而现在它既显示网关应答的调用,也显示从各 agent
自己会话文件里读到的调用。三个格子画在上方汇总那一排方块里,样式一致:三张各自带
边框、彼此留缝的卡片,窄屏(≤620px)下竖排。
* 每栏是一个 button:点一下就只列这一来源的请求,再点一下、或点"全部请求"回到
全部;被选中的那一栏底下有一道本主题色的线。aria-pressed 标出当前选中的是哪一栏。
* 计数后面跟单位("147 请求"),免得一个光秃秃的数字被读成下面的 token;token 是
四项合计,和上面 KPI 的算法一致。
* 三个格子在重绘之间是同一批元素、原地改(class / aria / 文本 / onclick),不是每次
replaceChildren 重建——同一份 app.js 里 5810 行的规定就是这么写的("The switch is
the same element across redraws, changed in place, so one being pressed or focused is
never swapped out"),正在点的那个不该被换掉。
* 汇总那一排本身(五张 KPI 卡)改成同样的方块:各自一张卡、有缝,边框写成
var(--line) 而不是 --card-edge(那是面板用的变量,这些卡在独立窗口里也有)。
≤860px 两列排布时卡片之间的那几条线照旧:奇数位去掉左边框、第三张起加上边框,
是 e0eaf5b4 带 #799 的老规则,这里只是跟着搬了位置,没有删。三张来源格是 button,
不参与这套分隔线。
* 供应商·账号 一栏:来自会话文件的行显示它文件里记的那个供应商 id(Codex 一向
如此),有账号时仍是账号优先,什么都没有才说"本地会话"。"本地会话"角标的条件
跟着放宽到账号或供应商任一存在,提示分两种说法:文件记了供应商的,说明这是它
被配置去调用的那个记录、不是 magpie 看到的路由(不等于官方供应商);只认得出
账号的,沿用原来那句"仅当本地元数据能明确识别时显示账号"。
* 窗口参数支持 via,用后从地址栏清掉,和 tab/provider/agent 等一致。
* 新增的串子在 en/zh/ja/de 四种语言里都有("{n} tokens" 上游已有,不重复加,
i18n-keys 绿)。
验证:node --check(app.js、i18n.js);go vet;go build(windows)。
界面效果在本机用改动后的源码构建的二进制上过目:三栏的切换与计数、方块样式、
窄屏竖排、请求表新增的会话文件行(含供应商 id)。
浏览器套件(chromium 与 webkit、en/zh):session-identity、usage-ledger、
ledger-protocol、number-units、usage-ledger-chart、usage-ttft-rounding、
usage-chart-axis、usage-fold、web-page、usage-accounts、i18n-keys 全绿;
ledger-hscroll、usage-speed、click-scroll 全绿;gui-ja、gui-de 各一条失败、
usage-ledger-detail 六条失败,均在本机 origin/main 上同样失败,与本次改动无关。
usage-ledger-chart 新钉了 ≤620px 下 KPI 卡与来源格的分隔线(把 app.css 换回上游版本
它必挂,实测过)。
---------
Co-authored-by: wizzy-yang <wizzy-yang@users.noreply.github.com>
|
||
|
|
395c4bc51e |
tests: a test that sets time.Local does it through testenv.Zone, which first waits out the stand-ins' first runs — their os.Stat reads time.Local, and TestDsh -race alone raced it every run
testenv.StandIns (
|
||
|
|
2c2137beb7 |
sessions: a DeepSeek Harness session can be deleted — its folder, its subagents' and their cached listing rows go to magpie's trash, and Restore puts them back (lc on Discord: deepseek harness无法删除会话)
Deletable left dsh out, so the Sessions page said magpie could list dsh's
sessions but not delete them. dsh keeps each session as files of its own
(dsh-session-persistence-jsonl, root $DSH_HOME/sessions from dsh-base's
cordis.patch.yml): <sessions>/--<cwd>--/<id escaped by encodeSegment>/ with
every format generation and session.lock; a subagent's session is a folder
of its own whose header names its parent. dsh's listing caches a row per
session at storages/session_projcache/sessions/<id>.json (per-record
dsh-storage-json); dsh itself deletes nothing ("Nothing deletes session
files"), so there is no index to keep in step.
The delete moves each of the group's session folders and its cached row.
A folder is taken only when its name is the session id as dsh escapes it
and it sits two levels under the sessions root; when any file of the
group isn't in such a folder nothing is moved, so another session's files
never go with it.
Tested: TestDshDeleteRestore on dsh 0.2.0-rc.2's real layout (zstd frames,
session.v4 plus a v3 left behind, session.lock, a subagent, a second
session in the same project folder that stays untouched, ErrActive while
written), TestDshDeleteOnlyItsOwnFolder, TestDshSegment (checked against
dsh's own encodeSegment run in node). Fails with dsh out of Deletable.
With the real dsh 0.2.0-rc.2 in a sandbox DSH_HOME: two `dsh headless`
sessions, magpie deleted one (folder + cached row), restore gave a tree
identical to the original (diff -r), deleted again: `dsh headless
--session-id` on the other still resumes it, and on the deleted one says
it does not exist. go test -race -count=5 of the delete tests, go vet,
gofmt, go test -tags nogui ./... pass. No GUI change: the page already
offers delete when the API says deletable.
Siblings checked: Cline keeps sessions.db as its session list (its own
deleteSession removes the rows, checkpoint refs and files), so moving files
alone would leave it listing them; Grok Build keeps session_search.sqlite;
Droid's layout is only known from a closed binary. They stay list-only.
|
||
|
|
764bbfdad5 |
sessions, gui, tui, cli: the Sessions list is as long as the count beside it, and drawn in pages (#1019)
The Sessions page's list and its session count came from two different
lengths: the count is over every session (statsFor's Overview), while
GET /api/sessions fell back to sessions.Limit (200) when the page asked for
no number — and the page never asks for one. So the page said "238 sessions"
over a list of 200, and each agent whose sessions were oldest lost them
whole: Codex had 121 sessions here and the list showed 7, OpenCode 33 showed
2, ZCode 20 showed 3.
* sessions.All (5000) is what a listing that means every session asks for,
and the endpoint reads it when no number is asked of it; a caller that
asks for one still gets it. It lives in internal/sessions so the page, the
TUI and the CLI ask for the same number.
* sessions.Limit stays 200 and is not raised: traceRecentFiles sizes the
window gateway attribution is judged over by it (TraceSessionVisible
decides whether a session has a readable local transcript), so raising it
would change which calls count as magpie's.
* The page draws that list in pages: SESS_PAGE (200) rows, and "Show N
more" appends the next. A filter click or a keystroke in Search draws the
first page and no more, so the cost does not grow with the history. The
data stays complete, so the count and the list still agree. A list served
4000 sessions long rebuilt every row on every keystroke — 275–320 ms a
keystroke on a fast Mac with very small rows, worse on Windows — and now
draws 200.
* The note under the list counts the list the filters kept, not every
session on the computer: it says "showing {drawn} of {n}" while pages are
left and "{n} session"/"{n} sessions" once the whole list is drawn. Before
it counted the whole history beside the drawn rows, so a search matching
one session read "the list holds all 2600, 1 drawn" — as if 2599 were
behind a "Show more" that isn't there. It also no longer says "drawn",
which is how the page is built, not what a reader sees.
* The CLI read sessions.List(0) — 200 — and then cut to its own --limit, so
--limit 500 could never show more than 200 and the "%d more with --limit"
foot was counted off the truncated list. It reads the whole set now; only
o.limit rows are printed, so that costs a parse, not output.
* The TUI read List(0) beside a head that says how many sessions there are,
and then List(sessions.Limit+1) — 201, still not the whole set. It reads
sessions.All now.
What the wider list costs is unchanged: every session file is read either way
to sort by last activity. Measured here with 384 sessions and 84.5k calls:
cold List(200) 10.3 s, List(5000) 10.5 s. What it adds is per-row work while
List holds the lock — a Codex session's titles stat, a pi session's omp
look-up, 25× the rows of JSON — hundreds of milliseconds, not seconds.
Tests, each failing without its change:
* TestSessionsListIsAsLongAsTheCount (internal/gui): 205 Claude Code
sessions as Claude Code keeps them; all 205 with no number asked, 5 with
?limit=5, 201 with ?limit=201. Fails with the list holding 200.
* TestSessionsListIsNotCutAtTheLimit (internal/tui): 210 sessions, of which
the ten past sessions.Limit are all in the list. Fails at 201.
* TestSessionsMoreCountsTheWholeSet (root): the default --limit 20 over 212
sessions says "192 more with --limit", and --limit 205 prints 205 rows.
Fails saying 180 (counted off the truncated list).
* sessions-paging.test.cjs (Chromium and WebKit, en and zh): 2600 sessions;
the first page is 200 rows with "Show 200 more", the button appends to
600 with the rows above left in place, a keystroke in Search draws a page
in under 250 ms and starts the pages again, a search matching one session
reads "1 session" and never the 2600 on the computer, and the note follows
the list the filters kept (200 of 1111 after that search). Fails on
origin/main (200 rows are not a page there) and with the pages taken out;
counting every session again, or writing "1 sessions", fails it too.
Verified: go vet; go build (windows); go test ./internal/sessions
./internal/tui ./internal/gui . — only what origin/main fails (TestCursor,
TestGatewayFixQuitsOnlyAMagpie, TestPurposeAssetMatchesUsage,
TestUpdateThatWontStart, TestPluginListSaysMiddleware,
TestPluginOnOffRmShortName); node --check app.js and i18n.js; the browser
suites above plus sessions-overview, sessions-today, sessions-usage-open,
sessions-toolbar, sessions-calendar-fill, usage-sessions-agents-fit,
i18n-keys, usage-ledger and click-scroll.
Co-authored-by: wizzy-yang <wizzy-yang@users.noreply.github.com>
|
||
|
|
dd027bc433 | sessions: a Claude Code workflow's agents are read as their session's calls (ksinverse on X: 发现Claude的用量和会话不太准,codex就非常好。是不是sub-agents没有被统计进去?默认开ultracode) — Claude Code writes a workflow's (ultracode) agents a folder deeper than other subagents, <session>/subagents/workflows/<run>/agent-*.jsonl beside the run's journal.jsonl, and ccFiles read only <session>/subagents/*.jsonl, so with ultracode on every workflow agent's calls and tokens were missing from Usage, the Requests page and the session's totals. ccFiles now reads each run's agent-*.jsonl too (the journal isn't a transcript and stays out), and sessionOfPath gives them their session, so they count as the session's like any subagent's; Claude Desktop's and Qoder's readers, which share ccFiles, follow. TestCallsWorkflowAgents (a session, a workflow agent's file and a journal with a line that reads as a call) fails without the change (1 call, the agent's missing) and passes. On this machine's real ~/.claude (read only), 34 workflow-agent calls of one session were unread and are now that session's. go test ./internal/sessions, -race -count=10 on TestCalls*/Subagent*/Trace*, go vet (darwin, windows), gofmt -l, linux and windows (nogui) builds pass. Not tried against the reporter's own transcripts. docs/reference.md says it. | ||
|
|
da5f7a8115 |
wsl: background work never touches a WSL distro that has stopped since it was last seen running — it booted it again (TJHHHH on Discord: while they were repairing WSL, magpie kept starting it). Detection already listed only running distros, but the running set was kept for a minute (wslListAge), agents built while a distro ran kept its home and read its files from their Get/Sync/Check/Reached/Routed closures later, the sessions listing kept a distro's Running for 30s+ and read its \\wsl.localhost files, and wslrun.Find reused a tool it had found in a distro for a minute and ran wsl.exe -d on it. Any wsl.exe -d or \\wsl.localhost read boots a stopped distro, so a wsl --shutdown was undone within a minute, and the distro, running again, kept it going. Now wsl.exe -l --running -q (it starts nothing; UTF-16 with or without BOM, or UTF-8 under WSL_UTF8) is asked again after 3s, and a distro not in it is not touched: a WSL agent's Get gives the last values seen, Sync/Check/Reached do nothing and Routed/Joined/Beside/Added say no; sessions aren't listed or read from it (wslCold says cold); wslrun.Find (Claude subscription sign-in and usage) doesn't reuse or run a tool there; the Library gives skills to no target in it and its MCP probe says it isn't running. An explicit action still starts it: setting a WSL agent's field, a Set on a running agent, resuming a WSL session. TestWSLStoppedSinceNotOpened (agent, sessions), TestWSLStoppedSinceNoTarget (library) and TestFindStoppedSince (wslrun) fail without the change and pass; TestUp covers the -l --running parse. On the Windows box (10.0.0.132) a test binary that had seen magpie-fedora running ran Values/Check/Reached/wslDistros/wslAgents/sessions.List/wslrun.Find against it for 4 rounds while it was stopped: it stayed Stopped and wsl -l -v was unchanged; wslrun and agent WSL tests pass there. No distro was terminated for the check (magpie-desktop is in use, the stopped ones aren't ours). go test ./... (nogui), -race on the WSL tests, go vet, windows and linux (nogui) builds pass.
|
||
|
|
9abfbff607 | cleanup: gofmt the 15 Go files main had unformatted — whitespace, comment alignment and three one-line funcs gofmt opens up; nothing else. go build and vet -tags nogui pass. | ||
|
|
3ab27186c9 | cleanup: drop eight functions nothing calls — catalog.ProviderEnv/ProviderAvailable, subscriptionRun.attached, hasTool, kiroSignedIn, SetModelSame (SetModelPrefs calls setModelSame itself; the comments name it), sessions.claudeFiles and plugin.SetConfig. Found with deadcode -test -tags nogui and checked by git grep across .go and .js; the ones only the GUI build or one platform calls stay. vet on darwin, linux, windows; catalog, gateway, provider, sessions and plugin tests pass. | ||
|
|
3a30ac87c2 |
catalog, gui: a 1-hour cache write is 2× input for a Claude model only, any other's unset is its 5-minute price and isn't shown (PAMI on Discord)
v0.1.1032 counted a 1-hour cache write left out at 2× input for every model, so gpt-6-astra priced 10,50,1,12.5 showed "$20 (1 hour) at 2× input", a write OpenAI has no price for. OneHourFor gives a Claude model's price, listed or given by the user, its 2× input; any other model's 1-hour writes count at the 5-minute price, magpie model price shows only its cache write, and the app shows the 1-hour box only for a Claude model or one priced with one. |
||
|
|
2086884bef | sessions: a session goes by the name its agent shows for it — Codex's thread name (session_index.jsonl), the one a Claude Code session was renamed to (/rename), else the title the agent made — and by its first prompt only when it has none (TJHHHH on Discord) | ||
|
|
71d2da1f42 |
catalog, usage, gateway, gui: a price can have a long-context tier and a 1-hour cache write, and the price boxes take decimals (PAMI on Discord)
OpenAI bills gpt-6-astra, gpt-6.1-sol and gpt-6-luna over 272K input at 2× input and cache and 1.5× output, for the whole request. A price now has tiers: `magpie model price <m> 10,50,1,12.5 --tier 272k 20,75,2,25` (--tier can repeat). A tier applies when input + cache reads + cache writes is over its size, so 272,000 is not over and 272,001 is. The built-in prices take tiers only where models.dev lists one (cost.tiers of type "context"), and it does list one for those three. The ledger, each request and OTLP are costed at the tier the call reached. Session and day totals sum many calls, so they stay at the base price.
Anthropic bills a cache write kept for an hour at 2× input and one kept for 5 minutes at 1.25×. Its usage reports which is which in cache_creation.ephemeral_5m/1h_input_tokens. The gateway (API and Claude subscription) and Claude Code's transcripts now keep that split. A price's fifth part is the 1-hour write. When it isn't given, it is 2× input: that is Anthropic's rule, and only Anthropic reports 1-hour writes. Claude list prices carry the 2× too. cache_write_tokens is still the total, and the usage CSV adds cache_write_5m_tokens and cache_write_1h_tokens at the end. The app shows the split on a request's Cache and on the usage tooltips. Old prices and old records, which have no 1-hour part, read as before. The sessions cache (18) and the call cache (calls-v8) are re-read once.
In the GUI, the price boxes were number inputs and dropped what they didn't parse ("0,25"). They are now decimal text boxes that take both "0.25" and "0,25". A model's price row has a 1-hour box (empty means 2× input) and a quiet Long-context price row. That row shows the list's tier greyed in, or sits behind a link when the list has none. A bad size is refused by name. en/zh/ja/de.
Tests:
- New: TestPriceTiers, TestCostSplit, TestPriceJSON, TestModelPriceTiers, TestModelPriceTierCmd, TestAnthropicCacheWriteSplit and TestClaudeCacheWriteSplit. The ledger CSV test expects the new columns.
- model-price-tiers.test.cjs is new; model-price-edit and provider-price-rate are updated. All of them fail against the old assets and pass in WebKit. Chromium couldn't be launched here.
- go vet, go build (darwin, GOOS=linux nogui, GOOS=windows) and go test -tags nogui ./... under a temp HOME pass.
|
||
|
|
585f7f7dfa | sessions, gui: Codex sessions made with another provider are moved to Codex's own from the Sessions page, and back (#887, cjyrainbow) — Codex's history lists only the sessions of the provider it uses now, so sessions made through CC Switch (model_provider "custom") vanished from it once Codex used magpie, though their files were still there and the Sessions page listed them. The Codex tab now reads each session's provider from its session_meta (cached with the rest) and the one Codex in that session's home uses (config.toml's model_provider, or its profile's; "openai" when none), says how many were made with another and which, and tags each. "Move to <provider>…" opens magpie's own dialog listing them, each ticked; Move rewrites only the model_provider string in each session's files (.jsonl and .jsonl.zst, in its own Codex home, so WSL's too, mtime kept) and in Codex's state_*.sqlite threads row: messages, id, title and archive are left as they are. A copy of the files goes to magpie's trash folder (trash/codex-provider, with a move.json) first, a failed rewrite is put back from it, and a session written to in the last minute is left alone and said so. Undo moves each back to the provider it had, byte for byte. Nothing is moved by itself. POST /api/sessions/codex-provider; en/zh/ja/de. TestMoveCodexProvider (listing, bytes, mtime, the DB row and nothing else, backup, byte-identical undo, an active session, a bad id), TestMoveCodexProviderPacked and TestCodexProviderIn fail without the change, as does sessions-codex-provider.test.cjs (WebKit, en and zh: magpie's dialog, Cancel posts nothing, an unticked one stays, Undo, no click moves the page, no left border, translations); sessions-manage, -toolbar, -purge, -folder-delete, -wsl-delete and click-scroll pass. Not tried against a real CC Switch history. go vet, go build (darwin, GOOS=linux nogui, GOOS=windows) and go test -tags nogui ./... under a temp HOME pass. | ||
|
|
653cb8ee30 | gui, sessions: a moved subscription's other sign-in ways are a link away, ZCode's app's own account among them (Jinyu), and a session in a WSL distro is deleted as this computer's are (TJHHHH) — Jinyu asked to add a ZCode account from the one the ZCode app is signed in to rather than signing in again. The ZCode plugin (0.1.8) already does that (its "ZCode app's sign-in" reads ~/.zcode/v2/credentials.json), but a moved subscription's Add went straight to the plugin's first way (#777: one click), so it couldn't be reached. Now ZCode's site step shows its other ways beside the sites (the app's account, the GLM Coding Plan API key), and while a moved subscription's sign-in waits, Other ways to sign in… (when it has ways other than the one under way and Use an API key instead) cancels it and shows the plugin's ways; the owner's suggestion on #777 (suyu-ops). Factory, whose two ways are its device code and its key, still goes straight through with no extra link. No plugin release or mover change. With a sandbox copy of the owner's real ~/.zcode the plugin's way signed in (account, key, site zai). TJHHHH asked to delete sessions listed from WSL: they were resumable only, the page saying to delete them in WSL. Now they have their box and are deleted the same way: moved to magpie's trash over \\wsl.localhost (copied and removed across the device boundary), Claude Code's file history from the distro's ~/.claude, never this computer's; dropped from the distro's listing at once, which is listed again next; Restore puts the files back in the distro and lists it again. zh, ja, de strings; the WSL note's strings are gone. TestWSLSessionDeleted fails on the old code. On the Windows box against a sandbox folder in a running WSL2 distro (magpie-desktop), Delete moved the session, its subagents and its file history out of the distro into a %APPDATA% trash, and Restore put them back and listed it again (removed afterwards). plugin-other-ways.test.cjs (ZCode's ways at the site step and from the waiting box, Factory's one click) and sessions-wsl-delete.test.cjs (the WSL row's box, Delete in magpie's dialog posts its id, no note) fail on the old code and pass on WebKit in en and zh. sessions-folder-delete, sessions-manage, checkbox-look, plugin-moved-signin, gui-ja, gui-de and click-scroll pass on WebKit. go vet, builds (darwin, GOOS=linux nogui, GOOS=windows) and go test -tags nogui -count=1 ./... under a temp HOME pass. |