From 81f587d7be696a26dcb0040c4b42313c751ef226 Mon Sep 17 00:00:00 2001 From: Rupert-WLLP-Bai Date: Tue, 13 Oct 2026 13:45:21 +0800 Subject: [PATCH] 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 --resume ; 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. --- docs/subsystems/gui-shell.md | 21 +++++ internal/sessions/manage.go | 2 +- internal/sessions/omp.go | 120 ++++++++++++++++-------- internal/sessions/omp_test.go | 6 +- internal/sessions/sessions.go | 15 ++- internal/sessions/wsl.go | 9 +- internal/sessions/wsl_test.go | 169 +++++++++++++++++++++++++++++++--- 7 files changed, 280 insertions(+), 62 deletions(-) diff --git a/docs/subsystems/gui-shell.md b/docs/subsystems/gui-shell.md index 499694aeb..052b18fdb 100644 --- a/docs/subsystems/gui-shell.md +++ b/docs/subsystems/gui-shell.md @@ -164,6 +164,27 @@ under its id (`render`, #1835). The row itself keeps one line: the fullest window while idle, what it is doing while it answers. See `routing-seat-windows.test.cjs`. +### Stored agent sessions in WSL + +The Sessions page uses `sessions.ListAgent`; Usage → Sessions uses +`sessions.List` and `StatsFor` through the handlers in +[`sessions.go`](../../internal/gui/sessions.go) and +[`sessions_manage.go`](../../internal/gui/sessions_manage.go). +On Windows, [`internal/sessions/wsl.go`](../../internal/sessions/wsl.go) +reads running distros through their WSL shared paths. A stopped distro keeps +its cached listing and is not opened; running distros are relisted at most +every 30 seconds. + +For omp, [`ompRootsIn`](../../internal/sessions/omp.go) includes both +`~/.omp/agent/sessions` and +`~/.omp/profiles//agent/sessions`. Subagents and advisor files count +in their parent session. A profile session's Resume command selects its +own profile with `omp --profile --resume `, including when +resumed through `wsl.exe`. Delete and Restore preserve its original +profile path and artifacts. Windows does not discover arbitrary stores +selected by a distro's `PI_CODING_AGENT_DIR`, XDG variables or +`--session-dir`. + ### Desktop fonts Settings → General offers independent interface and code fonts, each with diff --git a/internal/sessions/manage.go b/internal/sessions/manage.go index cf7ec34e7..625b8dfea 100644 --- a/internal/sessions/manage.go +++ b/internal/sessions/manage.go @@ -122,7 +122,7 @@ func ListAgent(agent string) []Managed { for _, fs := range groups { s, _ := assemble(fs, price) if s.Resume == "" && !s.ReadOnly { - s.Resume = resumeCommand(s.WSL, s.Agent, s.ID, s.Cwd) + s.Resume = resumeCommand(s.WSL, s.Agent, s.ID, s.Cwd, s.Path) } if s.Carry == nil { s.Carry = carries(s) diff --git a/internal/sessions/omp.go b/internal/sessions/omp.go index b80ce509f..270d83ea8 100644 --- a/internal/sessions/omp.go +++ b/internal/sessions/omp.go @@ -31,58 +31,100 @@ func OmpDir() string { // sessions/, each profile's, and $XDG_DATA_HOME/omp/sessions once omp has // moved its data there (Linux and macOS). func ompSessionRoots() []string { - roots := []string{filepath.Join(OmpDir(), "sessions")} - profiles, _ := filepath.Glob(filepath.Join(filepath.Dir(OmpDir()), "profiles", "*", "agent", "sessions")) - roots = append(roots, profiles...) + roots := ompRootsIn(OmpDir()) if d := appdir.Getenv("XDG_DATA_HOME"); d != "" && runtime.GOOS != "windows" { roots = append(roots, filepath.Join(d, "omp", "sessions")) } return roots } +// ompRootsIn are the sessions folders of an omp agent folder (~/.omp/agent): +// its own, and each profile's beside it (~/.omp/profiles//agent). +func ompRootsIn(dir string) []string { + roots := []string{filepath.Join(dir, "sessions")} + profiles, _ := filepath.Glob(filepath.Join(filepath.Dir(dir), "profiles", "*", "agent", "sessions")) + return append(roots, profiles...) +} + func ompFiles() []file { var out []file seen := map[string]bool{} for _, root := range ompSessionRoots() { - paths, _ := filepath.Glob(filepath.Join(root, "*", "*.jsonl")) - for _, p := range paths { - if seen[p] { - continue + out = ompFilesUnder(out, seen, root) + } + return out +} + +// ompFilesIn are the sessions in a distro's omp folder (~/.omp/agent) and +// its profiles': the variables that move them (PI_CODING_AGENT_DIR, +// $XDG_DATA_HOME) are the distro's and aren't read from Windows. +func ompFilesIn(dir string) []file { + var out []file + seen := map[string]bool{} + for _, root := range ompRootsIn(dir) { + out = ompFilesUnder(out, seen, root) + } + return out +} + +// ompProfile identifies the profile owning a main session file. Default +// and XDG stores have no profile component in their paths. +func ompProfile(path string) string { + if path == "" { + return "" + } + sessions := filepath.Dir(filepath.Dir(path)) + agent := filepath.Dir(sessions) + profile := filepath.Dir(agent) + profiles := filepath.Dir(profile) + if filepath.Base(sessions) != "sessions" || filepath.Base(agent) != "agent" || + filepath.Base(profiles) != "profiles" || filepath.Base(filepath.Dir(profiles)) != ".omp" { + return "" + } + return filepath.Base(profile) +} + +// ompFilesUnder adds the sessions under one sessions folder: each +//