Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions internal/session/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ func LoadCachedSessions(claudeDir string) []Session {
sessions := make([]Session, 0, len(sc.entries))
for _, cached := range sc.entries {
if cached.Sess.MsgCount > 0 {
refreshSessionDerivedState(&cached.Sess, filepath.Dir(claudeDir))
sessions = append(sessions, cached.Sess)
}
}
Expand Down
16 changes: 16 additions & 0 deletions internal/session/memory_import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,22 @@ func TestResolveMainProjectPath(t *testing.T) {
}
}

func TestHasProjectMemoryFallsBackToMainRepoForWorktree(t *testing.T) {
home := t.TempDir()
mainProject := "/Users/gavin.jeong/src/keyolk/ccproxy"
worktreeProject := "/Users/gavin.jeong/src/keyolk/ccproxy/.worktree/rebuild"
memDir := filepath.Join(home, ".claude", "projects", EncodeProjectPath(mainProject), "memory")
if err := os.MkdirAll(memDir, 0o755); err != nil {
t.Fatalf("mkdir memory dir: %v", err)
}
if err := os.WriteFile(filepath.Join(memDir, "state.md"), []byte("memory"), 0o644); err != nil {
t.Fatalf("write memory file: %v", err)
}
if !hasProjectMemory(worktreeProject, home) {
t.Fatalf("expected worktree project to inherit memory from main repo")
}
}

func TestListMemoryDir(t *testing.T) {
dir := t.TempDir()

Expand Down
1 change: 1 addition & 0 deletions internal/session/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func ScanSessions(claudeDir string) ([]Session, error) {
for _, f := range files {
validPaths[f.path] = true
if cached, ok := cache.lookup(f.path, f.modTime); ok {
refreshSessionDerivedState(&cached, home)
if cached.MsgCount > 0 {
// Load custom badges for cached sessions
cached.CustomBadges = badgeStore.Get(cached.ID)
Expand Down
45 changes: 41 additions & 4 deletions internal/session/scanner_path.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,47 @@ func ResolveBaseRepo(projectPath string, worktreeDirs ...string) string {
}

func hasProjectMemory(projectPath, home string) bool {
encoded := EncodeProjectPath(projectPath)
memDir := filepath.Join(home, ".claude", "projects", encoded, "memory")
entries, err := os.ReadDir(memDir)
return err == nil && len(entries) > 0
paths := []string{projectPath}
if base := ResolveBaseRepo(projectPath); base != "" && base != projectPath {
paths = append(paths, base)
}
if main := ResolveMainProjectPath(projectPath); main != "" && main != projectPath {
paths = append(paths, main)
}
seen := make(map[string]bool, len(paths))
for _, p := range paths {
if p == "" || seen[p] {
continue
}
seen[p] = true
encoded := EncodeProjectPath(p)
memDir := filepath.Join(home, ".claude", "projects", encoded, "memory")
entries, err := os.ReadDir(memDir)
if err == nil && len(entries) > 0 {
return true
}
}
return false
}

func refreshSessionDerivedState(sess *Session, home string) {
if sess == nil {
return
}
if len(sess.PlanSlugs) == 0 && sess.PlanSlug != "" {
sess.PlanSlugs = []string{sess.PlanSlug}
}
if sess.ProjectPath != "" {
sess.IsWorktree = isGitWorktree(sess.ProjectPath)
sess.HasMemory = hasProjectMemory(sess.ProjectPath, home)
}
sess.HasPlan = false
for _, slug := range sess.PlanSlugs {
if planFileExists(slug, home) {
sess.HasPlan = true
break
}
}
}

func hasSubagents(sessionFilePath string) bool {
Expand Down
4 changes: 1 addition & 3 deletions internal/session/scanner_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ func scanSessionStream(path string, modTime time.Time, home string, badgeStore *
if branch != "" {
sess.GitBranch = branch
}
continue
}

if bytes.Contains(line, bRoleUser) || bytes.Contains(line, bRoleUserS) {
Expand Down Expand Up @@ -170,8 +169,7 @@ func scanSessionStream(path string, modTime time.Time, home string, badgeStore *
}
}
if sess.ProjectPath != "" {
sess.IsWorktree = isGitWorktree(sess.ProjectPath)
sess.HasMemory = hasProjectMemory(sess.ProjectPath, home)
refreshSessionDerivedState(&sess, home)
}

// Load richer todos from ~/.claude/todos/ files if JSONL had none
Expand Down
Loading
Loading