Skip to content

Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.

sessions: Droid's sessions can be deleted from the Sessions page (zachzhao1984 on Discord)

yetone60fff9a7e52f
diff --git a/internal/sessions/droid_manage_test.go b/internal/sessions/droid_manage_test.go
new file mode 100644
index 000000000..262db78ca
--- /dev/null
+++ b/internal/sessions/droid_manage_test.go
@@ -0,0 +1,93 @@
+package sessions
+
+import (
+ "errors"
+ "os"
+ "path/filepath"
+ "testing"
+ "time"
+)
+
+func ageTree(root string) {
+ old := time.Now().Add(-24 * time.Hour)
+ filepath.WalkDir(root, func(p string, d os.DirEntry, err error) error {
+ if err == nil {
+ os.Chtimes(p, old, old)
+ }
+ return nil
+ })
+}
+
+// zachzhao1984 on Discord: some agents' sessions can't be deleted on the
+// Sessions page. Droid's are files of its own (a transcript and its
+// .settings.json, a subagent's beside them; the session index Droid keeps
+// is a cache it rebuilds from them), so one goes to the trash whole: its
+// transcript, its settings, its subagent's two, and nothing of another
+// session's. Restore puts them back.
+func TestDroidDeleteRestore(t *testing.T) {
+ manageSetup(t)
+ home := filepath.Join(t.TempDir(), "droid-home")
+ t.Setenv("FACTORY_HOME_OVERRIDE", home)
+ putDroid(t, home)
+ ageTree(home)
+ Reset()
+
+ if !Deletable("droid") {
+ t.Fatal("droid not deletable")
+ }
+ m, ok := findManaged(ListAgent("droid"), droidMain)
+ if !ok || !m.Deletable || m.Files != 2 {
+ t.Fatalf("listed as %+v", m)
+ }
+ dir := filepath.Join(home, ".factory", "sessions", "-work-droid")
+ mine := []string{
+ filepath.Join(dir, droidMain+".jsonl"), filepath.Join(dir, droidMain+".settings.json"),
+ filepath.Join(dir, droidSub+".jsonl"), filepath.Join(dir, droidSub+".settings.json"),
+ }
+ others := []string{
+ filepath.Join(dir, droidFork+".jsonl"), filepath.Join(dir, droidFork+".settings.json"),
+ filepath.Join(home, ".factory", "sessions", droidOld+".jsonl"), filepath.Join(home, ".factory", "settings.json"),
+ }
+
+ // one being written to is left alone
+ now := time.Now()
+ os.Chtimes(mine[3], now, now)
+ if _, err := Delete("droid", droidMain); !errors.Is(err, ErrActive) {
+ t.Fatalf("a session just written: %v", err)
+ }
+ ageTree(home)
+
+ tr, err := Delete("droid", droidMain)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if len(tr.Items) != 4 || tr.Cwd != "/work/droid" || tr.Title != "Login bug" {
+ t.Fatalf("trashed %+v, want its transcript and settings and its subagent's", tr)
+ }
+ for _, p := range mine {
+ if _, err := os.Lstat(p); err == nil {
+ t.Fatalf("%s is still there", p)
+ }
+ }
+ for _, p := range others {
+ if _, err := os.Stat(p); err != nil {
+ t.Fatalf("another's %s: %v", p, err)
+ }
+ }
+ if _, ok := findManaged(ListAgent("droid"), droidMain); ok {
+ t.Fatal("still listed after the delete")
+ }
+
+ if _, err := Restore(tr.Key); err != nil {
+ t.Fatal(err)
+ }
+ for _, p := range mine {
+ if _, err := os.Stat(p); err != nil {
+ t.Fatalf("%s isn't back: %v", p, err)
+ }
+ }
+ Reset()
+ if m, ok := findManaged(ListAgent("droid"), droidMain); !ok || m.Title != "Login bug" || m.Files != 2 {
+ t.Fatalf("the restored session: %+v", m)
+ }
+}
diff --git a/internal/sessions/manage.go b/internal/sessions/manage.go
index 4f5e54499..fdd9f6632 100644
--- a/internal/sessions/manage.go
+++ b/internal/sessions/manage.go
@@ -22,11 +22,19 @@ import (
//
// Only the agents whose sessions are files of their own can be deleted:
// Claude Code's (and Qoder's and WorkBuddy's, kept the same way), Codex's,
-// Pi's, omp's, Cursor CLI's (a chat's folder, its store and meta.json) and
-// DeepSeek Harness's (a session's folder, and its listing's cached row).
+// Pi's, omp's, Cursor CLI's (a chat's folder, its store and meta.json),
+// DeepSeek Harness's (a session's folder, and its listing's cached row) and
+// Droid's (a transcript and its .settings.json, and its subagents'; Droid's
+// own session index is a cache it rebuilds from those files, as it does
+// when it deletes an empty draft itself; zachzhao1984 on Discord).
// Hermes's and Alma's are rows in a database the agent keeps open and
-// writes, so they are only listed, and so are Cline's, whose sessions.db
-// lists a session whose files are gone. The agents' indexes are left as they are: Codex's
+// writes, so they are only listed, and so are OpenCode's and ZCode's, and
+// Cline's, whose sessions.db lists a session whose files are gone. Grok
+// Build's are folders, but it copies each session's text into
+// session_search.sqlite, which a delete would leave behind. Kimi Code's are
+// folders, but session_index.jsonl, which Kimi writes, names each one. A
+// Claude Desktop (Cowork) session is a Claude Code folder inside a session
+// Desktop keeps and lists itself. The agents' indexes are left as they are: Codex's
// session_index.jsonl (names by thread id) and its state database, and
// Claude Code's history.jsonl (the prompts typed, for the up arrow), are
// written by the agent while it runs, and a name or a prompt left for a
@@ -58,7 +66,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", "omp", "cursor", "dsh":
+ case "claude", "qoder", "qoder-cn", "workbuddy", "codebuddy", "codex", "pi", "omp", "cursor", "dsh", "droid":
return true
}
return false
@@ -438,6 +446,14 @@ func sessionPaths(agent, id string, fs []file) []string {
add(f.path)
}
}
+ if agent == "droid" {
+ // each transcript's settings beside it: what it spent, its model
+ for _, f := range fs {
+ if f.manifest != "" && !inside(f.manifest, out) {
+ add(f.manifest)
+ }
+ }
+ }
if agent == "claude" {
dir := ClaudeDir()
if fs[0].wsl != "" {