From ea7b39e40b902cb90b18cbe5f26169adb55023e1 Mon Sep 17 00:00:00 2001 From: "Charles P. Cross" <8572939+cpdata@users.noreply.github.com> Date: Sat, 22 Nov 2025 19:57:39 -0500 Subject: [PATCH] Fix: Use dynamic JSONL path in daemon sync branch operations (#361) Fixes #359 The daemon's sync branch logic was hardcoding the JSONL path to .beads/beads.jsonl, ignoring the dynamic discovery logic used elsewhere. This caused sync failures in repositories where the JSONL file has a different name (e.g., beads.base.jsonl, issues.jsonl). Changes: - Updated cmd/bd/daemon_sync_branch.go to use findJSONLPath() instead of hardcoded path - Implemented relative path calculation for correct worktree placement - Applied fix to both push (sync to worktree) and pull (sync from worktree) operations This works together with PR #360 to fix team/protected branch sync issues. Co-authored-by: Charles P. Cross --- cmd/bd/daemon_sync_branch.go | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/cmd/bd/daemon_sync_branch.go b/cmd/bd/daemon_sync_branch.go index a0b66d9d..aa9f4805 100644 --- a/cmd/bd/daemon_sync_branch.go +++ b/cmd/bd/daemon_sync_branch.go @@ -64,14 +64,24 @@ func syncBranchCommitAndPush(ctx context.Context, store storage.Storage, autoPus } // Sync JSONL file to worktree - // Use hardcoded relative path since JSONL is always at .beads/beads.jsonl - jsonlRelPath := filepath.Join(".beads", "beads.jsonl") + // Get the actual JSONL path (could be issues.jsonl, beads.base.jsonl, etc.) + jsonlPath := findJSONLPath() + if jsonlPath == "" { + return false, fmt.Errorf("JSONL path not found") + } + + // Convert absolute path to relative path from repo root + jsonlRelPath, err := filepath.Rel(repoRoot, jsonlPath) + if err != nil { + return false, fmt.Errorf("failed to get relative JSONL path: %w", err) + } + if err := wtMgr.SyncJSONLToWorktree(worktreePath, jsonlRelPath); err != nil { return false, fmt.Errorf("failed to sync JSONL to worktree: %w", err) } // Check for changes in worktree - worktreeJSONLPath := filepath.Join(worktreePath, ".beads", "beads.jsonl") + worktreeJSONLPath := filepath.Join(worktreePath, jsonlRelPath) hasChanges, err := gitHasChangesInWorktree(ctx, worktreePath, worktreeJSONLPath) if err != nil { return false, fmt.Errorf("failed to check for changes in worktree: %w", err) @@ -225,9 +235,21 @@ func syncBranchPull(ctx context.Context, store storage.Storage, log daemonLogger log.log("Pulled sync branch %s", syncBranch) + // Get the actual JSONL path + jsonlPath := findJSONLPath() + if jsonlPath == "" { + return false, fmt.Errorf("JSONL path not found") + } + + // Convert to relative path + jsonlRelPath, err := filepath.Rel(repoRoot, jsonlPath) + if err != nil { + return false, fmt.Errorf("failed to get relative JSONL path: %w", err) + } + // Copy JSONL back to main repo - worktreeJSONLPath := filepath.Join(worktreePath, ".beads", "beads.jsonl") - mainJSONLPath := filepath.Join(repoRoot, ".beads", "beads.jsonl") + worktreeJSONLPath := filepath.Join(worktreePath, jsonlRelPath) + mainJSONLPath := jsonlPath // Check if worktree JSONL exists if _, err := os.Stat(worktreeJSONLPath); os.IsNotExist(err) {