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 +//