sessions: Cindy's Pi sessions are read from its pi-agent-home (ldl123292 on X)
Cindy starts Pi with --session-dir <userData>/pi-agent-home/sessions
(resolvePiAgentHome in Cindy's app.asar), so its Pi sessions never
reached ~/.pi/agent and magpie showed none of them. They are read now from
the Cindy and CindyGlobal builds' folders and listed as Cindy's: list,
transcript, calls on Usage, Dirs, delete, and the gateway's own record of
a Cindy session merged with the file's.
Run (mote): go test ./internal/sessions ./internal/agent ./internal/usage
ok. go test ./internal/gui: two reds, both the same on origin/main
699ddf152: TestSettingsSaveKeepsWhatItDoesNotSend (#4514) and
TestMainWindowCorners (#3949). Linux (wsl-run): go test -run
'Cindy|Raft|TestPi' ./internal/sessions ok. gofmt clean.
Broken by hand: without cindyFiles() in the sessions list both Cindy tests
fail (0 Cindy sessions, want 4).
Not tried: a real Pi session run in Cindy (none on this Mac; the fixtures
are Pi 1.1.0's own files put where Cindy's Pi writes them), Windows, the
full suite. Cindy's Codex in <userData>/codex-home is not read yet: #4651.
This commit is contained in:
@@ -199,6 +199,7 @@ func Found() []string {
|
||||
add("opencode", OpenCodeDir())
|
||||
add("pi", PiDir())
|
||||
add("raft", filepath.Join(SlockDir(), "agents"))
|
||||
add("cindy", cindySessionDirs()...)
|
||||
add("zcode", zcodeDB())
|
||||
add("dsh", filepath.Join(DshDir(), "sessions"))
|
||||
add("cline", ClineSessionDir())
|
||||
|
||||
@@ -270,10 +270,11 @@ type lineCallReader struct {
|
||||
// lineCallReaders are the agents in callSources, beside callFiles' own,
|
||||
// whose calls are each one line of a file only appended to.
|
||||
var lineCallReaders = map[string]lineCallReader{
|
||||
"kimi": {kimiCallsBegin, kimiCallLine, nil}, // #1607
|
||||
"pi": {piCallsBegin, readPiCallLine, piCallsKept}, // #1951
|
||||
"raft": {piCallsBegin, readPiCallLine, piCallsKept},
|
||||
"omp": {piCallsBegin, readPiCallLine, piCallsKept},
|
||||
"kimi": {kimiCallsBegin, kimiCallLine, nil}, // #1607
|
||||
"pi": {piCallsBegin, readPiCallLine, piCallsKept}, // #1951
|
||||
"raft": {piCallsBegin, readPiCallLine, piCallsKept},
|
||||
"cindy": {piCallsBegin, readPiCallLine, piCallsKept},
|
||||
"omp": {piCallsBegin, readPiCallLine, piCallsKept},
|
||||
}
|
||||
|
||||
// callLock is the lock a file's calls are read under, so that two readers
|
||||
|
||||
@@ -42,6 +42,7 @@ import (
|
||||
// piCallFiles are Pi's and omp's session files, here and in WSL.
|
||||
func piCallFiles() []file {
|
||||
out := append(piFiles(), raftFiles()...)
|
||||
out = append(out, cindyFiles()...)
|
||||
out = append(out, ompFiles()...)
|
||||
return append(out, wslFiles("pi", "raft", "omp")...)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package sessions
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// Cindy (a desktop app that runs Claude Code, Codex and Pi) starts Pi with
|
||||
// --session-dir <its data>/pi-agent-home/sessions: Pi's SDK files,
|
||||
// <time>_<session id>.jsonl, all in one folder (Cindy 0.x's
|
||||
// resolvePiAgentHome, the userData folder Electron gives it). They are read
|
||||
// as Pi's, as agent "cindy", which is what the gateway counts their
|
||||
// requests as (Cindy's key). Before, Pi's own folder was read and Cindy's
|
||||
// never, so a user running Pi in Cindy saw no session of it at all
|
||||
// (ldl123292 on X). Cindy's Claude Code writes to ~/.claude, read as
|
||||
// Claude Code's already.
|
||||
|
||||
// CindyDirs are Cindy's data folders, Cindy and CindyGlobal (its global
|
||||
// build), under the user's config folder (~/Library/Application Support,
|
||||
// %APPDATA%, $XDG_CONFIG_HOME or ~/.config).
|
||||
func CindyDirs() []string {
|
||||
d, err := os.UserConfigDir()
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
return []string{filepath.Join(d, "Cindy"), filepath.Join(d, "CindyGlobal")}
|
||||
}
|
||||
|
||||
func cindySessionDirs() []string {
|
||||
var out []string
|
||||
for _, d := range CindyDirs() {
|
||||
out = append(out, filepath.Join(d, "pi-agent-home", "sessions"))
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func cindyFiles() []file { return cindyFilesIn(cindySessionDirs()) }
|
||||
|
||||
// cindyFilesIn are the Pi sessions in Cindy's session folders.
|
||||
func cindyFilesIn(dirs []string) []file {
|
||||
if !Reads("cindy") {
|
||||
return nil
|
||||
}
|
||||
var paths []string
|
||||
for _, d := range dirs {
|
||||
more, _ := filepath.Glob(filepath.Join(d, "*.jsonl"))
|
||||
paths = append(paths, more...)
|
||||
}
|
||||
return piNamed("cindy", paths)
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
package sessions
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Cindy starts Pi with --session-dir <userData>/pi-agent-home/sessions
|
||||
// (Cindy's resolvePiAgentHome, read in its app.asar), so Pi's SDK files,
|
||||
// <time>_<id>.jsonl, sit flat there and never in ~/.pi/agent. No Pi
|
||||
// session was run in Cindy here, so the files are Pi's own
|
||||
// (testdata/pi-calls, Pi 1.1.0's, and testdata/pi), put where Cindy's Pi
|
||||
// writes them: the global build's folder and the Chinese build's.
|
||||
func cindySetup(t *testing.T) (global, cn string) {
|
||||
t.Helper()
|
||||
manageSetup(t)
|
||||
dirs := CindyDirs()
|
||||
if len(dirs) != 2 {
|
||||
t.Fatalf("Cindy's folders: %v", dirs)
|
||||
}
|
||||
cn = filepath.Join(dirs[0], "pi-agent-home", "sessions")
|
||||
global = filepath.Join(dirs[1], "pi-agent-home", "sessions")
|
||||
put := func(from, dir string) {
|
||||
t.Helper()
|
||||
data, err := os.ReadFile(from)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
os.MkdirAll(dir, 0o755)
|
||||
p := filepath.Join(dir, filepath.Base(from))
|
||||
if err := os.WriteFile(p, data, 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
old := time.Now().Add(-24 * time.Hour)
|
||||
os.Chtimes(p, old, old)
|
||||
}
|
||||
calls, _ := filepath.Glob(filepath.Join("testdata", "pi-calls", "sessions", "*", "*.jsonl"))
|
||||
if len(calls) != 3 {
|
||||
t.Fatalf("pi-calls: %v", calls)
|
||||
}
|
||||
for _, f := range calls {
|
||||
put(f, global)
|
||||
}
|
||||
put(filepath.Join("testdata", "pi", "sessions", "--work-pi--", "2026-09-24T08-00-00-000Z_"+piFirst+".jsonl"), cn)
|
||||
// Pi's run folders beside them are not sessions
|
||||
os.MkdirAll(filepath.Join(filepath.Dir(global), "runtime", "pi-subagent-runs"), 0o755)
|
||||
Reset()
|
||||
return global, cn
|
||||
}
|
||||
|
||||
func TestCindyPiSessions(t *testing.T) {
|
||||
global, _ := cindySetup(t)
|
||||
ss := List(0)
|
||||
n := 0
|
||||
for _, s := range ss {
|
||||
if s.Agent == "pi" {
|
||||
t.Fatalf("a Cindy session listed as Pi's: %+v", s)
|
||||
}
|
||||
if s.Agent == "cindy" {
|
||||
n++
|
||||
}
|
||||
}
|
||||
if n != 4 {
|
||||
t.Fatalf("%d Cindy sessions, want 4", n)
|
||||
}
|
||||
p := find(t, ss, "cindy", raftParent)
|
||||
if p.Cwd != "/work/relay" || p.Title != "ping" {
|
||||
t.Fatalf("cindy: %+v", p)
|
||||
}
|
||||
if f := find(t, ss, "cindy", raftFork); f.Title != "ping" || f.Tokens != (Tokens{Input: 203, Output: 30, CacheRead: 1000}) {
|
||||
t.Fatalf("the fork: %+v", f)
|
||||
}
|
||||
if c := find(t, ss, "cindy", piFirst); c.Title != "Parser refactor" {
|
||||
t.Fatalf("the CN build's: %+v", c)
|
||||
}
|
||||
|
||||
if !HasTranscript("cindy") {
|
||||
t.Fatal("no transcript for Cindy")
|
||||
}
|
||||
tr, err := TranscriptOf(p)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var said []string
|
||||
for _, x := range tr.Parts {
|
||||
if x.Role == "user" && x.Kind == "text" {
|
||||
said = append(said, x.Text)
|
||||
}
|
||||
}
|
||||
if strings.Join(said, "|") != "ping|again" {
|
||||
t.Fatalf("prompts %q in %+v", said, tr.Parts)
|
||||
}
|
||||
|
||||
// its calls are Cindy's on the Usage page, those through magpie the
|
||||
// gateway's
|
||||
by, relay := map[string]int{}, 0
|
||||
for _, c := range Calls(time.Time{}) {
|
||||
by[c.Agent]++
|
||||
if c.Agent == "cindy" && (c.Upstream == "magpie" || c.Upstream == "dead") {
|
||||
t.Errorf("a call through magpie or one that failed: %+v", c)
|
||||
}
|
||||
if c.Agent == "cindy" && (c.Session == raftParent || c.Session == raftFork) && c.Upstream == "relay" {
|
||||
relay++
|
||||
}
|
||||
}
|
||||
if relay != 3 || by["pi"] != 0 {
|
||||
t.Fatalf("Cindy's relay calls %d, want 3 (as TestPiCalls); calls by agent %v", relay, by)
|
||||
}
|
||||
|
||||
found := false
|
||||
for _, d := range Dirs() {
|
||||
found = found || d == global
|
||||
}
|
||||
if !found {
|
||||
t.Fatalf("Cindy's session folder not among %v", Dirs())
|
||||
}
|
||||
if !Deletable("cindy") {
|
||||
t.Fatal("Cindy's sessions not deletable")
|
||||
}
|
||||
}
|
||||
|
||||
// The gateway counts Cindy's Pi requests as Cindy's: a session it recorded
|
||||
// under the same id is the one read from Cindy's file, listed once.
|
||||
func TestCindyGatewaySessionListedOnce(t *testing.T) {
|
||||
cindySetup(t)
|
||||
merged := MergeExternal(List(0), []ExternalSession{
|
||||
{Agent: "cindy", ID: raftViaUs, Title: "fail"},
|
||||
{Agent: "cindy", ID: "01a1343b-0000-7000-8000-000000000000", Title: "only the gateway's"},
|
||||
})
|
||||
ids := map[string]int{}
|
||||
for _, s := range merged {
|
||||
if s.Agent == "cindy" {
|
||||
ids[s.ID]++
|
||||
}
|
||||
}
|
||||
if ids[raftViaUs] != 1 || ids["01a1343b-0000-7000-8000-000000000000"] != 1 || len(ids) != 5 {
|
||||
t.Fatalf("Cindy's sessions: %v", ids)
|
||||
}
|
||||
if !NativeIDs(map[string]bool{"cindy": true})["cindy"][raftViaUs] {
|
||||
t.Fatal("Cindy's native ids leave its files out")
|
||||
}
|
||||
}
|
||||
@@ -75,7 +75,7 @@ type AgentCount struct {
|
||||
// those kept as files of their own, in a layout magpie knows whole.
|
||||
func Deletable(agent string) bool {
|
||||
switch agent {
|
||||
case "claude", "qoder", "qoder-cn", "workbuddy", "codebuddy", "codex", "pi", "raft", "omp", "cursor", "dsh", "droid", "agy":
|
||||
case "claude", "qoder", "qoder-cn", "workbuddy", "codebuddy", "codex", "pi", "raft", "cindy", "omp", "cursor", "dsh", "droid", "agy":
|
||||
return true
|
||||
}
|
||||
return false
|
||||
@@ -198,7 +198,7 @@ func readFor(want, all []file, quick bool) (pending map[string]bool, done func()
|
||||
// session's file, not taken from its name (as assemble does).
|
||||
func idInFile(agent string) bool {
|
||||
switch agent {
|
||||
case "codex", "pi", "raft", "omp", "dsh", "grok", "droid":
|
||||
case "codex", "pi", "raft", "cindy", "omp", "dsh", "grok", "droid":
|
||||
return true
|
||||
}
|
||||
return false
|
||||
@@ -532,7 +532,7 @@ func sessionPaths(agent, id string, fs []file) []string {
|
||||
}
|
||||
// the folder beside it: a Claude Code session's subagents and
|
||||
// tool results, an omp session's artifacts
|
||||
if agent != "codex" && agent != "pi" && agent != "raft" {
|
||||
if agent != "codex" && agent != "pi" && agent != "raft" && agent != "cindy" {
|
||||
if d := strings.TrimSuffix(f.path, ".jsonl"); d != f.path {
|
||||
if fi, err := os.Stat(d); err == nil && fi.IsDir() {
|
||||
add(d)
|
||||
|
||||
@@ -654,7 +654,7 @@ func allFiles() []file {
|
||||
}
|
||||
// each lister asked Reads already; a file listed under another
|
||||
// agent's name is held to that agent too
|
||||
return allowed(distinctOf(append(callFileLists(codexFiles()), openCodeFiles(), piFiles(), raftFiles(),
|
||||
return allowed(distinctOf(append(callFileLists(codexFiles()), openCodeFiles(), piFiles(), raftFiles(), cindyFiles(),
|
||||
wslFiles("pi", "raft", "omp", "kimi"), zcodeFiles(), dshFiles(), clineFiles(), ccFiles("qoder", QoderDir("qoder")), ccFiles("qoder-cn", QoderDir("qoder-cn")),
|
||||
grokFiles(), workbuddyFiles(), codebuddyFiles(), droidFiles(), ompFiles(), cursorFiles(), hermesFiles(), almaFiles(), kimiFiles(), agyFiles())...))
|
||||
}
|
||||
@@ -767,6 +767,13 @@ func Dirs() []string {
|
||||
}
|
||||
out = append(out, d.dir)
|
||||
}
|
||||
// Cindy's Pi sessions, by their own folder: Cindy's is the app's
|
||||
// whole data
|
||||
for _, d := range cindySessionDirs() {
|
||||
if _, err := os.Stat(d); err == nil {
|
||||
out = append(out, d)
|
||||
}
|
||||
}
|
||||
out = append(out, HermesDirs()...)
|
||||
out = append(out, wslDirs()...)
|
||||
return out
|
||||
@@ -1809,7 +1816,7 @@ func parserFor(agent string) sessionParser {
|
||||
return sessionParser{whole: parseCursor}
|
||||
case "codex":
|
||||
return sessionParser{line: codexBody}
|
||||
case "pi", "raft", "omp":
|
||||
case "pi", "raft", "cindy", "omp":
|
||||
return sessionParser{line: piParse}
|
||||
case "workbuddy", "codebuddy":
|
||||
return sessionParser{line: workbuddyLine}
|
||||
|
||||
@@ -31,6 +31,7 @@ var skillsCounted = map[string]struct {
|
||||
"codex": {test: "TestCodexSkillReads"},
|
||||
"pi": {test: "TestPiSkillRead"},
|
||||
"raft": {parser: "pi"},
|
||||
"cindy": {parser: "pi"},
|
||||
"omp": {parser: "pi"},
|
||||
"grok": {test: "TestGrokToolsAndSkills"},
|
||||
"alma": {test: "TestAlmaSessions"},
|
||||
|
||||
@@ -32,7 +32,7 @@ var ErrNoTranscript = errors.New("this agent's conversations can't be shown")
|
||||
// transcript.
|
||||
func HasTranscript(agent string) bool {
|
||||
switch agent {
|
||||
case "claude", "qoder", "qoder-cn", "codex", "pi", "raft", "omp", "cursor", "opencode", "kimi", "agy":
|
||||
case "claude", "qoder", "qoder-cn", "codex", "pi", "raft", "cindy", "omp", "cursor", "opencode", "kimi", "agy":
|
||||
return true
|
||||
}
|
||||
return false
|
||||
@@ -90,7 +90,7 @@ func readTranscriptOf(s Session, keep func([]byte) bool, add func(bool, Part) bo
|
||||
return cursorTranscript(s.Path, add)
|
||||
case "codex":
|
||||
return codexContentOf(whole, keep, add)
|
||||
case "pi", "raft", "omp":
|
||||
case "pi", "raft", "cindy", "omp":
|
||||
return piTranscript(s.Path, add)
|
||||
case "kimi":
|
||||
return kimiTranscript(s.Path, keep, add)
|
||||
|
||||
Reference in New Issue
Block a user