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.
This commit is contained in:
Rupert-WLLP-Bai
2026-10-13 13:49:16 +08:00
committed by yetone
parent 26465bc017
commit 81f587d7be
7 changed files with 280 additions and 62 deletions
+21
View File
@@ -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/<name>/agent/sessions`. Subagents and advisor files count
in their parent session. A profile session's Resume command selects its
own profile with `omp --profile <name> --resume <id>`, 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
+1 -1
View File
@@ -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)
+81 -39
View File
@@ -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/<name>/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
// <time>_<id>.jsonl, and its subagents' and advisor's beside it.
func ompFilesUnder(out []file, seen map[string]bool, root string) []file {
paths, _ := filepath.Glob(filepath.Join(root, "*", "*.jsonl"))
for _, p := range paths {
if seen[p] {
continue
}
seen[p] = true
name := strings.TrimSuffix(filepath.Base(p), ".jsonl")
_, id, ok := strings.Cut(name, "_")
if !ok || id == "" {
continue
}
key := "omp:" + id
f := file{agent: "omp", key: key, path: p, main: true}
if !stat(&f) {
continue
}
out = append(out, f)
// its subagents and advisor, at any depth
filepath.WalkDir(strings.TrimSuffix(p, ".jsonl"), func(q string, d fs.DirEntry, err error) error {
if err != nil {
return nil
}
if d.IsDir() {
// side questions (/btw) are kept apart, as .json
if d.Name() == "btw-history" {
return filepath.SkipDir
}
return nil
}
seen[p] = true
name := strings.TrimSuffix(filepath.Base(p), ".jsonl")
_, id, ok := strings.Cut(name, "_")
if !ok || id == "" {
continue
if !strings.HasSuffix(q, ".jsonl") {
return nil
}
key := "omp:" + id
f := file{agent: "omp", key: key, path: p, main: true}
if !stat(&f) {
continue
sub := file{agent: "omp", key: key, path: q}
if stat(&sub) {
out = append(out, sub)
}
out = append(out, f)
// its subagents and advisor, at any depth
filepath.WalkDir(strings.TrimSuffix(p, ".jsonl"), func(q string, d fs.DirEntry, err error) error {
if err != nil {
return nil
}
if d.IsDir() {
// side questions (/btw) are kept apart, as .json
if d.Name() == "btw-history" {
return filepath.SkipDir
}
return nil
}
if !strings.HasSuffix(q, ".jsonl") {
return nil
}
sub := file{agent: "omp", key: key, path: q}
if stat(&sub) {
out = append(out, sub)
}
return nil
})
}
return nil
})
}
return out
}
+5 -1
View File
@@ -4,6 +4,7 @@ import (
"os"
"path/filepath"
"runtime"
"strings"
"testing"
)
@@ -87,6 +88,9 @@ func TestOmp(t *testing.T) {
Reset()
ss = List(0)
for id := range moves {
find(t, ss, "omp", id)
m := find(t, ss, "omp", id)
if id == ompNamed && !strings.Contains(m.Resume, "omp --profile work --resume "+id) {
t.Fatalf("profile resume %q", m.Resume)
}
}
}
+11 -4
View File
@@ -430,7 +430,7 @@ func ccFiles(agent, dir string) []file {
func allFiles() []file {
var out []file
for _, fs := range [][]file{callFiles(), openCodeFiles(), piFiles(),
wslFiles("pi"), zcodeFiles(), dshFiles(), clineFiles(), ccFiles("qoder", QoderDir("qoder")), ccFiles("qoder-cn", QoderDir("qoder-cn")),
wslFiles("pi", "omp"), zcodeFiles(), dshFiles(), clineFiles(), ccFiles("qoder", QoderDir("qoder")), ccFiles("qoder-cn", QoderDir("qoder-cn")),
grokFiles(), workbuddyFiles(), droidFiles(), ompFiles(), cursorFiles(), hermesFiles(), almaFiles()} {
out = append(out, fs...)
}
@@ -1056,7 +1056,7 @@ func assemble(fs []file, price func(string) *catalog.Price) (Session, bool) {
return s, false // nothing was said in it
}
if !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)
}
s.Carry, s.Transcript = carries(s), HasTranscript(s.Agent)
return s, true
@@ -1356,14 +1356,15 @@ func makers(id string) []string {
// ---- resuming ---------------------------------------------------------------
var safeID = regexp.MustCompile(`^[0-9A-Za-z_-]+$`)
var safeOmpProfile = regexp.MustCompile(`^[a-z0-9][a-z0-9._-]{0,63}$`)
// ResumeCommand is the shell line that picks a session up again in its
// folder, or "" for an id that isn't plain.
func ResumeCommand(agent, id, cwd string) string { return resumeCommand("", agent, id, cwd) }
func ResumeCommand(agent, id, cwd string) string { return resumeCommand("", agent, id, cwd, "") }
// resumeCommand is ResumeCommand for a session in a WSL distro too, when
// distro is set: see wslResume.
func resumeCommand(distro, agent, id, cwd string) string {
func resumeCommand(distro, agent, id, cwd, path string) string {
if !safeID.MatchString(id) {
return ""
}
@@ -1387,6 +1388,12 @@ func resumeCommand(distro, agent, id, cwd string) string {
run = "grok --resume " + id
case "omp":
run = "omp --resume " + id
if profile := ompProfile(path); profile != "" {
if !safeOmpProfile.MatchString(profile) {
return ""
}
run = "omp --profile " + profile + " --resume " + id
}
case "droid":
run = "droid --resume " + id
case "cursor":
+6 -3
View File
@@ -15,9 +15,9 @@ import (
// sessions in the distro's home, which magpie opens through
// \\wsl.localhost\<distro> — the distros internal/agent's wsl.go already
// finds and probes for the agents it sets up (WSLHomes, which that package
// sets; this one can't import it). Claude Code's, Codex's and Pi's session
// files there are read as this computer's are, each session marked with its
// distro (Session.WSL) and resumed through wsl.exe (wslResume).
// sets; this one can't import it). Claude Code's, Codex's, Pi's and omp's
// session files there are read as this computer's are, each session marked
// with its distro (Session.WSL) and resumed through wsl.exe (wslResume).
//
// Reading over \\wsl.localhost is slow, and looking at a stopped distro's
// files starts it. So the distros' files are listed behind, at most every
@@ -64,6 +64,7 @@ var wslAgents = []struct{ agent, dir string }{
{"claude", ".claude"},
{"codex", ".codex"},
{"pi", filepath.Join(".pi", "agent")},
{"omp", filepath.Join(".omp", "agent")},
}
// wslScan lists the session files under a distro's home.
@@ -78,6 +79,8 @@ func wslScan(home string) []file {
out = append(out, codexFilesIn(dir)...)
case "pi":
out = append(out, piFilesIn(dir, "")...)
case "omp":
out = append(out, ompFilesIn(dir)...)
}
}
return out
+155 -14
View File
@@ -19,8 +19,8 @@ func wslSettle() {
}
// wslDistro is a distro's home in a temp dir with Claude Code's, Codex's
// and Pi's sessions in it, and this computer's own folders empty; WSLHomes
// says it runs while *running is true.
// Pi's and omp's sessions in it, and this computer's own folders empty;
// WSLHomes says it runs while *running is true.
func wslDistro(t *testing.T) (home string, running *bool) {
setup(t)
dir := t.TempDir()
@@ -30,6 +30,7 @@ func wslDistro(t *testing.T) (home string, running *bool) {
copyTree(t, "testdata/claude", filepath.Join(home, ".claude"))
copyTree(t, "testdata/codex", filepath.Join(home, ".codex"))
copyTree(t, "testdata/pi", filepath.Join(home, ".pi", "agent"))
copyTree(t, "testdata/omp/agent", filepath.Join(home, ".omp", "agent"))
on := true
WSLHomes = func() []WSLHome { return []WSLHome{{Distro: "Ubuntu", Home: home, Running: on}} }
t.Cleanup(func() { wslSettle(); WSLHomes = nil; Reset() })
@@ -37,8 +38,8 @@ func wslDistro(t *testing.T) (home string, running *bool) {
return home, &on
}
// The sessions of Claude Code, Codex and Pi in a WSL distro are listed with
// the distro, resumed there through wsl.exe; their calls count in usage.
// The sessions of Claude Code, Codex, Pi and omp in a WSL distro are listed
// with the distro, resumed there through wsl.exe; their calls count in usage.
func TestWSLSessionsListed(t *testing.T) {
home, _ := wslDistro(t)
ss := List(0)
@@ -49,7 +50,7 @@ func TestWSLSessionsListed(t *testing.T) {
}
got[s.Agent] = s
}
for _, a := range []string{"claude", "codex", "pi"} {
for _, a := range []string{"claude", "codex", "pi", "omp"} {
if _, ok := got[a]; !ok {
t.Fatalf("no %s session from WSL in %+v", a, ss)
}
@@ -65,6 +66,17 @@ func TestWSLSessionsListed(t *testing.T) {
if r := got["codex"].Resume; !strings.HasPrefix(r, "wsl.exe -d 'Ubuntu' ") || !strings.Contains(r, "''codex resume ") {
t.Fatalf("codex resume %q", r)
}
omp := got["omp"]
if omp.ID != "019a0000-0000-7000-8000-00000000000a" || omp.Cwd != "/work/omp" || omp.Title != "Port the parser to omp" || omp.Tokens.zero() {
t.Fatalf("omp: %+v", omp)
}
wantOmp := `wsl.exe -d 'Ubuntu' --cd '/work/omp' -e sh -lc 'exec ${SHELL:-sh} -lic ''omp --resume 019a0000-0000-7000-8000-00000000000a'''`
if omp.Resume != wantOmp {
t.Fatalf("omp resume\n got %s\nwant %s", omp.Resume, wantOmp)
}
if len(omp.Models) != 4 {
t.Fatalf("the subagent and advisor weren't read: %+v", omp.Models)
}
var calls int
for _, c := range Calls(time.Time{}) {
if c.Agent == "claude" || c.Agent == "codex" {
@@ -78,6 +90,23 @@ func TestWSLSessionsListed(t *testing.T) {
if !strings.Contains(dirs, filepath.Join(home, ".claude")) || !strings.Contains(dirs, filepath.Join(home, ".codex")) {
t.Fatalf("dirs %s", dirs)
}
if !strings.Contains(dirs, filepath.Join(home, ".omp", "agent")) {
t.Fatalf("omp's folder isn't listed: %s", dirs)
}
// the Usage page's sessions (/api/sessions/stats and overview) count it
st := StatsFor(0)
var inStats, inDays bool
for _, s := range st.Sessions {
inStats = inStats || (s.Key == "omp:"+omp.ID && !s.Tokens.zero())
}
for _, d := range st.Days {
for _, u := range d.Usage {
inDays = inDays || u.Agent == "omp"
}
}
if !inStats || !inDays {
t.Fatalf("the WSL omp session isn't in the usage stats: sessions %v, days %v", inStats, inDays)
}
}
// A session in a WSL distro is deleted as this computer's are (TJHHHH: 请问
@@ -132,12 +161,124 @@ func TestWSLSessionDeleted(t *testing.T) {
}
}
// An omp session in a WSL distro is deleted and restored as this computer's
// are: its file and the artifacts beside it leave the distro together, and
// come back there.
func TestWSLOmpSessionDeleted(t *testing.T) {
home, _ := wslDistro(t)
const id = "019a0000-0000-7000-8000-00000000000a"
old := time.Now().Add(-time.Hour)
filepath.WalkDir(home, func(p string, _ os.DirEntry, _ error) error { return os.Chtimes(p, old, old) })
List(0)
wslSettle()
m, ok := findManaged(ListAgent("omp"), id)
if !ok || m.WSL != "Ubuntu" || !m.Deletable || m.Files < 2 {
t.Fatalf("the WSL omp session listed as %+v, %v", m, ok)
}
artifacts := strings.TrimSuffix(m.Path, ".jsonl")
if fi, err := os.Stat(artifacts); err != nil || !fi.IsDir() {
t.Fatalf("artifacts %s: %v", artifacts, err)
}
tr, err := Delete("omp", id)
if err != nil {
t.Fatal(err)
}
for _, p := range []string{m.Path, artifacts} {
if _, err := os.Lstat(p); err == nil {
t.Fatalf("%s is still there", p)
}
}
if _, ok := findManaged(ListAgent("omp"), id); ok {
t.Fatal("still listed")
}
if _, err := Restore(tr.Key); err != nil {
t.Fatal(err)
}
for _, p := range []string{m.Path, filepath.Join(artifacts, "__advisor.jsonl")} {
if _, err := os.Lstat(p); err != nil {
t.Fatalf("%s wasn't restored", p)
}
}
if m, ok := findManaged(ListAgent("omp"), id); !ok || m.WSL != "Ubuntu" || len(m.Models) != 4 {
t.Fatalf("restored session listed as %+v, %v", m, ok)
}
}
// A distro's named profiles are read as its default folder is: one
// session's file and its artifacts move to a profile, and both stay
// listed, only the profile's resumed through it.
func TestWSLOmpProfiles(t *testing.T) {
for _, profile := range []string{"work", "client-a.v2"} {
t.Run(profile, func(t *testing.T) {
home, _ := wslDistro(t)
from := filepath.Join(home, ".omp", "agent", "sessions", "--work-omp--")
to := filepath.Join(home, ".omp", "profiles", profile, "agent", "sessions", "--work-omp--")
if err := os.MkdirAll(to, 0o755); err != nil {
t.Fatal(err)
}
// the session's file and the folder beside it (its subagents
// and advisor), leaving the default folder's other sessions
for _, p := range []string{
filepath.Join(from, "2026-09-28T08-00-00-000Z_"+ompMain+".jsonl"),
filepath.Join(from, "2026-09-28T08-00-00-000Z_"+ompMain),
} {
if err := os.Rename(p, filepath.Join(to, filepath.Base(p))); err != nil {
t.Fatal(err)
}
}
ss := List(0)
wslSettle()
m := find(t, ss, "omp", ompMain)
if m.WSL != "Ubuntu" || !strings.HasPrefix(m.Path, to) || len(m.Models) != 4 {
t.Fatalf("profile session: %+v", m)
}
want := "omp --profile " + profile + " --resume " + ompMain
if !strings.Contains(m.Resume, want) {
t.Fatalf("resume doesn't select %s: %s", profile, m.Resume)
}
// the default folder's own sessions are untouched by it
for _, id := range []string{ompFork, ompNamed} {
d := find(t, ss, "omp", id)
if strings.Contains(d.Resume, "--profile") {
t.Fatalf("%s resumed through a profile: %s", id, d.Resume)
}
}
st := StatsFor(0)
var usage Tokens
for _, s := range st.Sessions {
if s.Key == "omp:"+ompMain {
usage = s.Tokens
}
}
if usage != m.Tokens {
t.Fatalf("usage tokens %+v, want %+v", usage, m.Tokens)
}
old := time.Now().Add(-time.Hour)
filepath.WalkDir(to, func(p string, _ os.DirEntry, _ error) error { return os.Chtimes(p, old, old) })
tr, err := Delete("omp", ompMain)
if err != nil {
t.Fatal(err)
}
if _, err := os.Stat(m.Path); !os.IsNotExist(err) {
t.Fatalf("profile session wasn't deleted: %v", err)
}
if _, err := Restore(tr.Key); err != nil {
t.Fatal(err)
}
back, ok := findManaged(ListAgent("omp"), ompMain)
if !ok || back.Path != m.Path || !strings.Contains(back.Resume, want) || len(back.Models) != 4 {
t.Fatalf("restored profile session: %+v, %v", back, ok)
}
})
}
}
// A stopped distro's sessions are listed as last read, and nothing in it is
// opened: that would start it.
func TestWSLStoppedDistroKept(t *testing.T) {
home, running := wslDistro(t)
if n := len(List(0)); n != 4 {
t.Fatalf("want the 4 sessions, got %d", n)
if n := len(List(0)); n != 7 {
t.Fatalf("want the 7 sessions, got %d", n)
}
wslSettle()
Saved()
@@ -150,8 +291,8 @@ func TestWSLStoppedDistroKept(t *testing.T) {
}
for i := 0; i < 2; i++ {
ss := List(0)
if len(ss) != 4 {
t.Fatalf("pass %d: want the 4 sessions as last read, got %+v", i, ss)
if len(ss) != 7 {
t.Fatalf("pass %d: want the 7 sessions as last read, got %+v", i, ss)
}
for _, s := range ss {
if s.WSL != "Ubuntu" || s.Tokens.zero() || s.Resume == "" {
@@ -172,8 +313,8 @@ func TestWSLStoppedSinceNotOpened(t *testing.T) {
up := true
WSLRunning = func(d string) bool { return d == "Ubuntu" && up }
t.Cleanup(func() { WSLRunning = nil })
if n := len(List(0)); n != 4 {
t.Fatalf("want the 4 sessions, got %d", n)
if n := len(List(0)); n != 7 {
t.Fatalf("want the 7 sessions, got %d", n)
}
wslSettle()
project := filepath.Join(home, ".claude", "projects", "-work-app")
@@ -209,7 +350,7 @@ func TestWSLStoppedSinceNotOpened(t *testing.T) {
wslSess.Unlock()
ss := List(0)
wslSettle()
if len(ss) != 4 {
if len(ss) != 7 {
t.Fatalf("pass %d: the stopped distro was listed again: %d sessions", i, len(ss))
}
for _, s := range ss {
@@ -226,8 +367,8 @@ func TestWSLStoppedSinceNotOpened(t *testing.T) {
List(0)
wslSettle()
ss := List(0)
if len(ss) != 5 {
t.Fatalf("running again: want 5 sessions, got %d", len(ss))
if len(ss) != 8 {
t.Fatalf("running again: want 8 sessions, got %d", len(ss))
}
}