sessions: a Claude Code, Qoder or Cowork project folder, a session's folder or a Hermes profile behind a junction is read, not skipped (#2268, JasonBuildAI)
On Windows os.ReadDir lists a junction as ModeIrregular, neither IsDir nor ModeSymlink, so a reader that goes into only IsDir() entries, or IsDir() and ModeSymlink ones, walked past a folder kept on another drive with a junction left in its place. ccFiles (Claude Code's own store, Qoder's, Qoder CN's and Cowork's) skipped such a project folder whole, a session's own folder (its subagents) and a workflow run's; HermesDirs skipped such a profile. Sessions and Usage lost all of them, silently. #2233/#2250 fixed walk roots (walkLinked); this is the entry check one level in. dirent.IsFolder is the one check now: an entry is a folder to read into when it is one, or when it is a symlink or irregular entry that os.Stat follows to a folder. A link to a file, a broken link and other irregular entries are none. It follows only the entry asked about; none of its callers recurses through one, so no visited set is needed. Used at every reader of an agent's folder that picks entries this way: - sessions: ccFiles' project, session-folder and workflow-run checks, HermesDirs' profile check, agyCallFiles' conversation check (IsDir only before, so even a symlink was skipped); - agent: hermesProfiles and ompProfiles (IsDir only), so a linked profile still gets magpie's provider and its own row; - library: desktopSkillRoots' org and account folders (IsDir only). Left as they are, on purpose: WalkDir copies, hashes and deletes in library and sessions/manage.go (they must not follow links), the relocate code (it tells a link from a folder on purpose), library's linkEntry (asks "is this a link", not "is this a folder"), magpie's own folders (calls cache, gateway logs, OthersDir, backups, Bun, Devin homes), and install/version detection (claudecode versions, VS Code extensions, Desktop's folder name, Hanako's agents). The issue's patch had sessions' own copy of library's linkEntry without a Stat; this is a shared package and Stat-checked, so an irregular entry that isn't a folder (a dedup or cloud placeholder file) isn't read as one. docs/subsystems/gateway-sessions.md says how the readers treat links. Run: - New tests make real links, a junction (mklink /J) on Windows and a symlink elsewhere: TestIsFolder; TestClaudeProjectFolderBehindALink, TestClaudeSessionFolderBehindALink and TestHermesProfileBehindALink (the issue's), TestClaudeWorkflowRunBehindALink, TestAgyConversationBehindALink; agent's TestHermesProfileBehindALink and TestOmpProfileBehindALink; library's TestClaudeDesktopSkillRootsBehindALink. - Broken by hand on macOS (IsFolder = e.IsDir()): all nine fail. Broken as before on the Windows box (IsDir() || ModeSymlink, no Stat): TestIsFolder and all eight reader tests fail there (e.g. "Claude session files behind a link: [], want [...]", "Hermes sessions behind a link: 1, want 2", "agy calls behind a link: 3, want 5"); with the fix all pass. Windows test binaries cross-built with go1.26.8 (windows/amd64, nogui) and run on the box with a fresh sandbox USERPROFILE/HOME/APPDATA/LOCALAPPDATA/TEMP per run. - Whole packages on the Windows box: dirent and sessions pass. usage, agent and library each have reds that fail the same with binaries built from origin/main69d7ee33a: usage's TestDesktopSessionAccountMetadata (#1356/#1827), agent's TestFolderVarsAreListed (reads ..\gateway source the copied layout lacks), library's TestAgentsSkillsFolders, TestHooksCodexTrustMovesWithTheGroups and TestTargetsLeaveGoneAgentsOut (filed as #2275). - gofmt -l: nothing. go vet ./... (darwin), GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./... and -tags nogui: clean. - macOS: set -o pipefail; go test -p 4 -timeout 40m ./... onbc470c6b6plus this change: 56 packages ok, none failed. After rebasing onto origin/main3a0b61275(#2261's subagents, which touch sessions.go and the same doc): go test ./internal/sessions/ ./internal/dirent/ again.
This commit is contained in:
@@ -371,6 +371,16 @@ writes for a subagent a subagent started (`sessions.SubagentParent`, through
|
||||
to a file row keeps the gateway's own. Both were checked against Claude Code
|
||||
2.1.296 spawning a subagent from a subagent.
|
||||
|
||||
A folder these readers go into may be a link: a symlink, or on Windows a
|
||||
junction, which Go lists as irregular rather than as a folder or a symlink.
|
||||
Each reader that picks the entries it goes into (a Claude Code, Qoder or
|
||||
Cowork project folder, a session's own folder and a workflow run's, a Hermes
|
||||
profile, an Antigravity CLI conversation) asks `dirent.IsFolder`, which
|
||||
follows such an entry with `os.Stat`; none of them recurses through one. A
|
||||
walk root that is a link is walked where it leads, its files still named
|
||||
under the agent's folder (`walkLinked`, #2233). `TestIsFolder` and the
|
||||
`*BehindALink` tests make real links, junctions on Windows (#2268).
|
||||
|
||||
Codex session identity is read from native thread metadata, rather than inferred
|
||||
from a shared session header or `Kind` (`x-openai-subagent`). The sessions API
|
||||
adds `role` (`main`, `subagent` or `unknown`), and when native metadata
|
||||
|
||||
@@ -29,6 +29,7 @@ import (
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/yetone/magpie/internal/dirent"
|
||||
"github.com/yetone/magpie/internal/edit"
|
||||
)
|
||||
|
||||
@@ -209,7 +210,7 @@ func hermesProfiles(at place) []string {
|
||||
es, _ := os.ReadDir(ps)
|
||||
for _, e := range es {
|
||||
name := e.Name()
|
||||
if !e.IsDir() || name == "default" || !hermesProfileID.MatchString(name) {
|
||||
if !dirent.IsFolder(ps, e) || name == "default" || !hermesProfileID.MatchString(name) {
|
||||
continue
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(ps, ".deleted", name)); err == nil {
|
||||
|
||||
@@ -20,6 +20,7 @@ import (
|
||||
|
||||
"github.com/yetone/magpie/internal/appdir"
|
||||
"github.com/yetone/magpie/internal/catalog"
|
||||
"github.com/yetone/magpie/internal/dirent"
|
||||
"github.com/yetone/magpie/internal/edit"
|
||||
"github.com/yetone/magpie/internal/gateway"
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
@@ -163,7 +164,7 @@ func ompProfiles(home string) []*Agent {
|
||||
var names []string
|
||||
for _, e := range entries {
|
||||
name := e.Name()
|
||||
if !e.IsDir() || !ompProfileOK(name) {
|
||||
if !dirent.IsFolder(filepath.Join(root, "profiles"), e) || !ompProfileOK(name) {
|
||||
continue
|
||||
}
|
||||
if filepath.Join(root, "profiles", name, "agent") == cur {
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// moveBehindLink moves the folder at live elsewhere and leaves a link to it
|
||||
// in its place: a junction on Windows, which Go lists as irregular rather
|
||||
// than as a folder or a symlink, and a symlink elsewhere.
|
||||
func moveBehindLink(t *testing.T, live string) {
|
||||
t.Helper()
|
||||
elsewhere := filepath.Join(t.TempDir(), filepath.Base(live))
|
||||
if err := os.Rename(live, elsewhere); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if runtime.GOOS == "windows" {
|
||||
if out, err := exec.Command("cmd", "/c", "mklink", "/J", live, elsewhere).CombinedOutput(); err != nil {
|
||||
t.Fatalf("mklink /J: %v %s", err, out)
|
||||
}
|
||||
return
|
||||
}
|
||||
if err := os.Symlink(elsewhere, live); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// A Hermes profile folder that is a link is still a profile whose config
|
||||
// magpie writes (#2268).
|
||||
func TestHermesProfileBehindALink(t *testing.T) {
|
||||
home := syncHome(t)
|
||||
root := filepath.Join(home, ".hermes")
|
||||
for _, p := range []string{"config.yaml", "profiles/work/config.yaml"} {
|
||||
writeFile(t, filepath.Join(root, p), "model:\n default: x\n")
|
||||
}
|
||||
t.Setenv("HERMES_HOME", root)
|
||||
if got := hermesProfiles(here(home)); len(got) != 2 {
|
||||
t.Fatalf("profiles: %v", got)
|
||||
}
|
||||
moveBehindLink(t, filepath.Join(root, "profiles", "work"))
|
||||
if got := hermesProfiles(here(home)); len(got) != 2 || got[1] != filepath.Join(root, "profiles", "work", "config.yaml") {
|
||||
t.Fatalf("profiles behind a link: %v", got)
|
||||
}
|
||||
}
|
||||
|
||||
// An omp profile folder that is a link is still a profile row (#2268).
|
||||
func TestOmpProfileBehindALink(t *testing.T) {
|
||||
home := syncHome(t)
|
||||
ompProfileAt(t, home, "work", "b/model-b")
|
||||
ids := func() map[string]bool {
|
||||
got := map[string]bool{}
|
||||
for _, a := range ompProfiles(home) {
|
||||
got[a.ID] = true
|
||||
}
|
||||
return got
|
||||
}
|
||||
if got := ids(); !got["omp#work"] {
|
||||
t.Fatalf("profiles %v", got)
|
||||
}
|
||||
moveBehindLink(t, filepath.Join(home, ".omp", "profiles", "work"))
|
||||
if got := ids(); len(got) != 1 || !got["omp#work"] {
|
||||
t.Fatalf("profiles behind a link %v", got)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
// Package dirent decides whether an entry a reader lists is a folder to go
|
||||
// into, links included.
|
||||
package dirent
|
||||
|
||||
import (
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// IsFolder is whether e, an entry listed in dir, is a folder to read into:
|
||||
// a folder of its own, or a link that leads to one. os.ReadDir reports a
|
||||
// symlink as ModeSymlink and, on Windows, a junction as ModeIrregular (Go
|
||||
// 1.23 and later), and neither as IsDir, so a reader that goes into only
|
||||
// IsDir() entries, or IsDir() and ModeSymlink ones, walks past a folder
|
||||
// kept on another drive with a junction left where it was (#2268). Such an
|
||||
// entry is followed with os.Stat. A link to a file, a broken link and
|
||||
// anything else irregular are no folder.
|
||||
//
|
||||
// It follows only the entry it is asked about. A reader that recurses on
|
||||
// it must keep its own record of the folders it has been in.
|
||||
func IsFolder(dir string, e fs.DirEntry) bool {
|
||||
if e.IsDir() {
|
||||
return true
|
||||
}
|
||||
if e.Type()&(fs.ModeSymlink|fs.ModeIrregular) == 0 {
|
||||
return false
|
||||
}
|
||||
fi, err := os.Stat(filepath.Join(dir, e.Name()))
|
||||
return err == nil && fi.IsDir()
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package dirent
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// link makes path a link to the folder target: a junction on Windows, the
|
||||
// link an agent's folder kept on another drive has there, and a symlink
|
||||
// elsewhere.
|
||||
func link(t *testing.T, target, path string) {
|
||||
t.Helper()
|
||||
if runtime.GOOS == "windows" {
|
||||
if out, err := exec.Command("cmd", "/c", "mklink", "/J", path, target).CombinedOutput(); err != nil {
|
||||
t.Fatalf("mklink /J: %v %s", err, out)
|
||||
}
|
||||
return
|
||||
}
|
||||
if err := os.Symlink(target, path); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// A folder, and a link (a junction on Windows) to a folder, are folders to
|
||||
// read into; a file, a link to a file and a broken link are not.
|
||||
func TestIsFolder(t *testing.T) {
|
||||
dir, elsewhere := t.TempDir(), t.TempDir()
|
||||
if err := os.Mkdir(filepath.Join(dir, "own"), 0o755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(dir, "file"), []byte("x"), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.Mkdir(filepath.Join(elsewhere, "kept"), 0o755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
link(t, filepath.Join(elsewhere, "kept"), filepath.Join(dir, "linked"))
|
||||
if err := os.Mkdir(filepath.Join(elsewhere, "gone"), 0o755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
link(t, filepath.Join(elsewhere, "gone"), filepath.Join(dir, "broken"))
|
||||
if err := os.Remove(filepath.Join(elsewhere, "gone")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
want := map[string]bool{"own": true, "linked": true, "file": false, "broken": false}
|
||||
if runtime.GOOS != "windows" {
|
||||
if err := os.WriteFile(filepath.Join(elsewhere, "f"), []byte("x"), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.Symlink(filepath.Join(elsewhere, "f"), filepath.Join(dir, "tofile")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
want["tofile"] = false
|
||||
}
|
||||
es, err := os.ReadDir(dir)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got := map[string]bool{}
|
||||
for _, e := range es {
|
||||
got[e.Name()] = IsFolder(dir, e)
|
||||
}
|
||||
for name, w := range want {
|
||||
if g, ok := got[name]; !ok || g != w {
|
||||
t.Errorf("IsFolder(%s) = %v (listed %v), want %v", name, g, ok, w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package dirent
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/yetone/magpie/internal/testenv"
|
||||
)
|
||||
|
||||
// The tests run in a home of their own, never the user's real files.
|
||||
func TestMain(m *testing.M) { testenv.Main(m) }
|
||||
@@ -0,0 +1,52 @@
|
||||
package library
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"slices"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// cmdExe is found before a test's sandbox takes PATH away.
|
||||
var cmdExe, _ = exec.LookPath("cmd")
|
||||
|
||||
// folderLink makes path a link to the folder target: a junction on
|
||||
// Windows, which Go lists as irregular rather than as a folder or a
|
||||
// symlink, and a symlink elsewhere.
|
||||
func folderLink(t *testing.T, target, path string) {
|
||||
t.Helper()
|
||||
if runtime.GOOS == "windows" {
|
||||
if out, err := exec.Command(cmdExe, "/c", "mklink", "/J", path, target).CombinedOutput(); err != nil {
|
||||
t.Fatalf("mklink /J: %v %s", err, out)
|
||||
}
|
||||
return
|
||||
}
|
||||
if err := os.Symlink(target, path); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// A Claude Desktop org's or account's skills-plugin folder that is a link
|
||||
// (a junction on Windows) is still one of Desktop's skill roots (#2268).
|
||||
func TestClaudeDesktopSkillRootsBehindALink(t *testing.T) {
|
||||
sandbox(t)
|
||||
dir := t.TempDir()
|
||||
base := filepath.Join(dir, "local-agent-mode-sessions", "skills-plugin")
|
||||
org := desktopAccount(t, dir, "org1", "acct1", `{"skills": []}`)
|
||||
acct := desktopAccount(t, dir, "org2", "acct2", `{"skills": []}`)
|
||||
if got := desktopSkillRoots(dir); !slices.Contains(got, org) || !slices.Contains(got, acct) {
|
||||
t.Fatalf("roots %v, want %s and %s", got, org, acct)
|
||||
}
|
||||
for _, live := range []string{filepath.Join(base, "org1"), acct} {
|
||||
elsewhere := filepath.Join(t.TempDir(), filepath.Base(live))
|
||||
if err := os.Rename(live, elsewhere); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
folderLink(t, elsewhere, live)
|
||||
}
|
||||
if got := desktopSkillRoots(dir); !slices.Contains(got, org) || !slices.Contains(got, acct) {
|
||||
t.Fatalf("roots behind links %v, want %s and %s", got, org, acct)
|
||||
}
|
||||
}
|
||||
@@ -31,6 +31,7 @@ import (
|
||||
"github.com/tidwall/gjson"
|
||||
|
||||
"github.com/yetone/magpie/internal/desktopdir"
|
||||
"github.com/yetone/magpie/internal/dirent"
|
||||
"github.com/yetone/magpie/internal/edit"
|
||||
)
|
||||
|
||||
@@ -51,13 +52,13 @@ func desktopSkillRoots(desktopDir string) []string {
|
||||
base := filepath.Join(d, "local-agent-mode-sessions", "skills-plugin")
|
||||
orgs, _ := os.ReadDir(base)
|
||||
for _, o := range orgs {
|
||||
if !o.IsDir() {
|
||||
if !dirent.IsFolder(base, o) {
|
||||
continue
|
||||
}
|
||||
accts, _ := os.ReadDir(filepath.Join(base, o.Name()))
|
||||
for _, a := range accts {
|
||||
p := filepath.Join(base, o.Name(), a.Name())
|
||||
if a.IsDir() && (isFile(filepath.Join(p, desktopManifest)) || isFile(filepath.Join(p, ".claude-plugin", "plugin.json"))) {
|
||||
if dirent.IsFolder(filepath.Join(base, o.Name()), a) && (isFile(filepath.Join(p, desktopManifest)) || isFile(filepath.Join(p, ".claude-plugin", "plugin.json"))) {
|
||||
out = append(out, p)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,8 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/yetone/magpie/internal/dirent"
|
||||
)
|
||||
|
||||
// Antigravity CLI's (agy's) calls (#2097, parkavenue9639: a call agy made
|
||||
@@ -47,7 +49,7 @@ func agyCallFiles() []file {
|
||||
dirs, _ := os.ReadDir(filepath.Join(AgyDir(), "brain"))
|
||||
var out []file
|
||||
for _, d := range dirs {
|
||||
if !d.IsDir() {
|
||||
if !dirent.IsFolder(filepath.Join(AgyDir(), "brain"), d) {
|
||||
continue
|
||||
}
|
||||
p := filepath.Join(AgyDir(), "brain", d.Name(), ".system_generated", "logs", "transcript_full.jsonl")
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/yetone/magpie/internal/appdir"
|
||||
"github.com/yetone/magpie/internal/dirent"
|
||||
)
|
||||
|
||||
// Hermes stores canonical, non-overlapping input/cache buckets. Reasoning is
|
||||
@@ -34,7 +35,7 @@ func HermesDirs() []string {
|
||||
}
|
||||
dirs := []string{root}
|
||||
for _, e := range readDirectory(filepath.Join(root, "profiles")) {
|
||||
if !strings.HasPrefix(e.Name(), ".") && (e.IsDir() || e.Type()&os.ModeSymlink != 0) {
|
||||
if !strings.HasPrefix(e.Name(), ".") && dirent.IsFolder(filepath.Join(root, "profiles"), e) {
|
||||
dirs = append(dirs, filepath.Join(root, "profiles", e.Name()))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,151 @@
|
||||
package sessions
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"slices"
|
||||
"sort"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
// The tests below move a folder a reader goes into elsewhere and leave a
|
||||
// link where it was: a junction on Windows, where Go lists one as
|
||||
// irregular rather than as a folder or a symlink, and a symlink elsewhere
|
||||
// (#2268, JasonBuildAI; its first three tests are the issue's).
|
||||
|
||||
// ccFilePaths is every session file ccFiles found, by path: one that stops
|
||||
// being listed, or is listed from somewhere else, stands out.
|
||||
func ccFilePaths(fs []file) []string {
|
||||
out := make([]string, 0, len(fs))
|
||||
for _, f := range fs {
|
||||
out = append(out, f.path)
|
||||
}
|
||||
sort.Strings(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// moveBehindLink moves the folder at live elsewhere and leaves a link to it
|
||||
// in its place.
|
||||
func moveBehindLink(t *testing.T, live string) {
|
||||
t.Helper()
|
||||
elsewhere := filepath.Join(t.TempDir(), filepath.Base(live))
|
||||
if err := os.Rename(live, elsewhere); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
linkFolder(t, elsewhere, live)
|
||||
}
|
||||
|
||||
// A Claude Code project folder inside projects/ that is a link is read all
|
||||
// the same: Sessions listed none of its sessions and Usage none of its
|
||||
// calls. ccFiles reads Qoder's, Qoder CN's and Cowork's stores too.
|
||||
func TestClaudeProjectFolderBehindALink(t *testing.T) {
|
||||
claude, _ := setup(t)
|
||||
before := ccFiles("claude", claude)
|
||||
if len(before) == 0 {
|
||||
t.Fatal("the fixture has no Claude session files")
|
||||
}
|
||||
listed := len(ListAgent("claude"))
|
||||
moveBehindLink(t, filepath.Join(claude, "projects", "-work-app"))
|
||||
|
||||
after := ccFiles("claude", claude)
|
||||
if !reflect.DeepEqual(ccFilePaths(after), ccFilePaths(before)) {
|
||||
t.Fatalf("Claude session files behind a link: %v, want %v", ccFilePaths(after), ccFilePaths(before))
|
||||
}
|
||||
if got := len(ListAgent("claude")); got != listed {
|
||||
t.Fatalf("Claude sessions behind a link: %d, want %d", got, listed)
|
||||
}
|
||||
}
|
||||
|
||||
// A session's own folder, where its subagents live, being a link is read
|
||||
// too.
|
||||
func TestClaudeSessionFolderBehindALink(t *testing.T) {
|
||||
claude, _ := setup(t)
|
||||
before := ccFiles("claude", claude)
|
||||
if len(before) == 0 {
|
||||
t.Fatal("the fixture has no Claude session files")
|
||||
}
|
||||
moveBehindLink(t, filepath.Join(claude, "projects", "-work-app", "11111111-2222-3333-4444-555555555555"))
|
||||
|
||||
after := ccFiles("claude", claude)
|
||||
if !reflect.DeepEqual(ccFilePaths(after), ccFilePaths(before)) {
|
||||
t.Fatalf("a Claude session folder behind a link: %v, want %v", ccFilePaths(after), ccFilePaths(before))
|
||||
}
|
||||
}
|
||||
|
||||
// A workflow run's folder (ultracode's agents) being a link is read too.
|
||||
func TestClaudeWorkflowRunBehindALink(t *testing.T) {
|
||||
claude, _ := setup(t)
|
||||
subs := filepath.Join(claude, "projects", "-work-app", "11111111-2222-3333-4444-555555555555", "subagents")
|
||||
b, err := os.ReadFile(filepath.Join(subs, "agent-a1.jsonl"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
run := filepath.Join(subs, "workflows", "run-1")
|
||||
if err := os.MkdirAll(run, 0o755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(run, "agent-w1.jsonl"), b, 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
before := ccFilePaths(ccFiles("claude", claude))
|
||||
if !slices.Contains(before, filepath.Join(run, "agent-w1.jsonl")) {
|
||||
t.Fatalf("the workflow's agent isn't read: %v", before)
|
||||
}
|
||||
moveBehindLink(t, run)
|
||||
if after := ccFilePaths(ccFiles("claude", claude)); !reflect.DeepEqual(after, before) {
|
||||
t.Fatalf("a workflow run behind a link: %v, want %v", after, before)
|
||||
}
|
||||
}
|
||||
|
||||
// A Hermes profile folder that is a link is read too: HermesDirs skipped it
|
||||
// and the profile's sessions were gone from Sessions and Usage.
|
||||
func TestHermesProfileBehindALink(t *testing.T) {
|
||||
setup(t)
|
||||
root := filepath.Join(t.TempDir(), "hermes")
|
||||
t.Setenv("HERMES_HOME", root)
|
||||
hermesFixture(t, root, "", "link-default", true)
|
||||
hermesFixture(t, root, "work", "link-work", true)
|
||||
if got := hermesSessions(); got != 2 {
|
||||
t.Fatalf("Hermes sessions: %d, want 2", got)
|
||||
}
|
||||
moveBehindLink(t, filepath.Join(root, "profiles", "work"))
|
||||
if got := hermesSessions(); got != 2 {
|
||||
t.Fatalf("Hermes sessions behind a link: %d, want 2", got)
|
||||
}
|
||||
}
|
||||
|
||||
func hermesSessions() int {
|
||||
n := 0
|
||||
for _, s := range List(0) {
|
||||
if s.Agent == "hermes" {
|
||||
n++
|
||||
}
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
// An Antigravity CLI conversation folder that is a link keeps its calls.
|
||||
func TestAgyConversationBehindALink(t *testing.T) {
|
||||
claude, _ := setup(t)
|
||||
agy := filepath.Join(filepath.Dir(claude), "home", ".gemini", "antigravity-cli")
|
||||
copyTree(t, "testdata/agy", agy)
|
||||
calls := func() int {
|
||||
n := 0
|
||||
for _, c := range Calls(time.Time{}) {
|
||||
if c.Agent == "agy" {
|
||||
n++
|
||||
}
|
||||
}
|
||||
return n
|
||||
}
|
||||
before := calls()
|
||||
if before == 0 {
|
||||
t.Fatal("the fixture has no agy calls")
|
||||
}
|
||||
moveBehindLink(t, filepath.Join(agy, "brain", "2b0e6c1a-1d3e-4f6a-9a51-0f1c2d3e4f5a"))
|
||||
if got := calls(); got != before {
|
||||
t.Fatalf("agy calls behind a link: %d, want %d", got, before)
|
||||
}
|
||||
}
|
||||
@@ -34,6 +34,7 @@ import (
|
||||
"github.com/klauspost/compress/zstd"
|
||||
"github.com/yetone/magpie/internal/appdir"
|
||||
"github.com/yetone/magpie/internal/catalog"
|
||||
"github.com/yetone/magpie/internal/dirent"
|
||||
"github.com/yetone/magpie/internal/proc"
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
"github.com/yetone/magpie/internal/settings"
|
||||
@@ -424,7 +425,7 @@ func ccFiles(agent, dir string) []file {
|
||||
projects := filepath.Join(dir, "projects")
|
||||
var out []file
|
||||
for _, project := range readDirectory(projects) {
|
||||
if !project.IsDir() && project.Type()&os.ModeSymlink == 0 {
|
||||
if !dirent.IsFolder(projects, project) {
|
||||
continue
|
||||
}
|
||||
root := filepath.Join(projects, project.Name())
|
||||
@@ -435,7 +436,7 @@ func ccFiles(agent, dir string) []file {
|
||||
if stat(&f) {
|
||||
out = append(out, f)
|
||||
}
|
||||
} else if e.IsDir() || e.Type()&os.ModeSymlink != 0 {
|
||||
} else if dirent.IsFolder(root, e) {
|
||||
subs := filepath.Join(path, "subagents")
|
||||
for _, sub := range readDirectory(subs) {
|
||||
if sub.IsDir() || !strings.HasSuffix(sub.Name(), ".jsonl") {
|
||||
@@ -447,7 +448,7 @@ func ccFiles(agent, dir string) []file {
|
||||
}
|
||||
}
|
||||
for _, run := range readDirectory(filepath.Join(subs, "workflows")) {
|
||||
if !run.IsDir() {
|
||||
if !dirent.IsFolder(filepath.Join(subs, "workflows"), run) {
|
||||
continue
|
||||
}
|
||||
dir := filepath.Join(subs, "workflows", run.Name())
|
||||
|
||||
Reference in New Issue
Block a user