Skip to content

The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu

fix(pi): resolve the session workspace on the ref instead of an undefined helper

Claude96795b2c549e
diff --git a/cli/beacon/cmd/endpoint_pi.go b/cli/beacon/cmd/endpoint_pi.go
index 85e289e1..d30eb0b5 100644
--- a/cli/beacon/cmd/endpoint_pi.go
+++ b/cli/beacon/cmd/endpoint_pi.go
@@ -172,7 +172,7 @@ func runEndpointPiStatus(cmd *cobra.Command, args []string) error {
status := piSessionStatus{
SessionID: ref.ID,
SourcePath: ref.Path,
- Workspace: stringFromMap(ref.Header, "cwd"),
+ Workspace: strings.TrimSpace(ref.Workspace),
SizeBytes: ref.SizeBytes,
}
if ref.ModTimeMS > 0 {
diff --git a/cli/beacon/internal/pisession/store.go b/cli/beacon/internal/pisession/store.go
index aa7feb9c..539cb3e1 100644
--- a/cli/beacon/internal/pisession/store.go
+++ b/cli/beacon/internal/pisession/store.go
@@ -31,6 +31,7 @@ type SessionRef struct {
Path string
ModTimeMS int64
SizeBytes int64
+ Workspace string
Header map[string]interface{}
}
@@ -115,6 +116,7 @@ func (s *Store) List() ([]SessionRef, error) {
Path: path,
ModTimeMS: info.ModTime().UnixMilli(),
SizeBytes: info.Size(),
+ Workspace: stringValue(header["cwd"]),
Header: header,
})
}
diff --git a/cli/beacon/internal/pisession/store_test.go b/cli/beacon/internal/pisession/store_test.go
new file mode 100644
index 00000000..5e38ac5b
--- /dev/null
+++ b/cli/beacon/internal/pisession/store_test.go
@@ -0,0 +1,77 @@
+package pisession
+
+import (
+ "os"
+ "path/filepath"
+ "testing"
+)
+
+// List resolves the fields `beacon endpoint pi status` reports, and Workspace is
+// the one it cannot recompute: the status command has no access to the header map.
+func TestListResolvesSessionIdentityAndWorkspace(t *testing.T) {
+ sessions := t.TempDir()
+ writePiJSONL(t, filepath.Join(sessions, "session-1.jsonl"), []string{
+ `{"type":"session","id":"session-1","cwd":"/work/project"}`,
+ `{"type":"message","message":{"role":"user","content":[{"text":"hello"}]}}`,
+ })
+ // No session header: the id falls back to the filename and the workspace is unknown
+ // rather than wrong.
+ writePiJSONL(t, filepath.Join(sessions, "session-2.jsonl"), []string{
+ `{"type":"message","message":{"role":"user","content":[{"text":"hi"}]}}`,
+ })
+
+ store, err := NewStore(sessions)
+ if err != nil {
+ t.Fatal(err)
+ }
+ refs, err := store.List()
+ if err != nil {
+ t.Fatal(err)
+ }
+ if len(refs) != 2 {
+ t.Fatalf("len(refs) = %d, want 2", len(refs))
+ }
+
+ byID := map[string]SessionRef{}
+ for _, ref := range refs {
+ byID[ref.ID] = ref
+ }
+ first, ok := byID["session-1"]
+ if !ok {
+ t.Fatalf("no ref with id session-1: %#v", refs)
+ }
+ if first.Workspace != "/work/project" {
+ t.Fatalf("Workspace = %q, want /work/project", first.Workspace)
+ }
+ if first.SizeBytes == 0 || first.ModTimeMS == 0 {
+ t.Fatalf("stat fields not populated: %#v", first)
+ }
+ second, ok := byID["session-2"]
+ if !ok {
+ t.Fatalf("no ref with id session-2: %#v", refs)
+ }
+ if second.Workspace != "" {
+ t.Fatalf("Workspace = %q, want empty for a transcript with no session header", second.Workspace)
+ }
+}
+
+func TestListReturnsNothingForAMissingSessionsDir(t *testing.T) {
+ missing := filepath.Join(t.TempDir(), "absent")
+ store, err := NewStore(missing)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if store.Exists() {
+ t.Fatalf("Exists() = true for %s", missing)
+ }
+ refs, err := store.List()
+ if err != nil {
+ t.Fatalf("List() on a missing dir returned an error: %v", err)
+ }
+ if len(refs) != 0 {
+ t.Fatalf("len(refs) = %d, want 0", len(refs))
+ }
+ if _, err := os.Stat(missing); !os.IsNotExist(err) {
+ t.Fatalf("List() created %s", missing)
+ }
+}