feat(daemon): unify auto-sync config for simpler agent workflows (#904)
* feat(daemon): unify auto-sync config for simpler agent workflows ## Problem Agents running `bd sync` at session end caused delays in the Claude Code "event loop", slowing development. The daemon was already auto-exporting DB→JSONL instantly, but auto-commit and auto-push weren't enabled by default when sync-branch was configured - requiring manual `bd sync`. Additionally, having three separate config options (auto-commit, auto-push, auto-pull) was confusing and could get out of sync. ## Solution Simplify to two intuitive sync modes: 1. **Read/Write Mode** (`daemon.auto-sync: true` or `BEADS_AUTO_SYNC=true`) - Enables auto-commit + auto-push + auto-pull - Full bidirectional sync - eliminates need for manual `bd sync` - Default when sync-branch is configured 2. **Read-Only Mode** (`daemon.auto-pull: true` or `BEADS_AUTO_PULL=true`) - Only receives updates from team - Does NOT auto-publish changes - Useful for experimental work or manual review before sharing ## Benefits - **Faster agent workflows**: No more `bd sync` delays at session end - **Simpler config**: Two modes instead of three separate toggles - **Backward compatible**: Legacy auto_commit/auto_push settings still work (treated as auto-sync=true) - **Adaptive `bd prime`**: Session close protocol adapts when daemon is auto-syncing (shows simplified 4-step git workflow, no `bd sync`) - **Doctor warnings**: `bd doctor` warns about deprecated legacy config ## Changes - cmd/bd/daemon.go: Add loadDaemonAutoSettings() with unified config logic - cmd/bd/doctor.go: Add CheckLegacyDaemonConfig call - cmd/bd/doctor/daemon.go: Add CheckDaemonAutoSync, CheckLegacyDaemonConfig - cmd/bd/init_team.go: Use daemon.auto-sync in team wizard - cmd/bd/prime.go: Detect daemon auto-sync, adapt session close protocol - cmd/bd/prime_test.go: Add stubIsDaemonAutoSyncing for testing * docs: add comprehensive daemon technical analysis Add daemon-summary.md documenting the beads daemon architecture, memory analysis (explaining the 30-35MB footprint), platform support comparison, historical problems and fixes, and architectural guidance for other projects implementing similar daemon patterns. Key sections: - Architecture deep dive with component diagrams - Memory breakdown (SQLite WASM runtime is the main contributor) - Platform support matrix (macOS/Linux full, Windows partial) - Historical bugs and their fixes with reusable patterns - Analysis of daemon usefulness without database (verdict: low value) - Expert-reviewed improvement proposals (3 recommended, 3 skipped) - Technical design patterns for other implementations * feat: add cross-platform CI matrix and dual-mode test framework Cross-Platform CI: - Add Windows, macOS, Linux matrix to catch platform-specific bugs - Linux: full tests with race detector and coverage - macOS: full tests with race detector - Windows: full tests without race detector (performance) - Catches bugs like GH#880 (macOS path casing) and GH#387 (Windows daemon) Dual-Mode Test Framework (cmd/bd/dual_mode_test.go): - Runs tests in both direct mode and daemon mode - Prevents recurring bug pattern (GH#719, GH#751, bd-fu83) - Provides DualModeTestEnv with helper methods for common operations - Includes 5 example tests demonstrating the pattern Documentation: - Add dual-mode testing section to CONTRIBUTING.md - Document RunDualModeTest API and available helpers Test Fixes: - Fix sync_local_only_test.go gitPull/gitPush calls - Add gate_no_daemon_test.go for beads-70c4 investigation * fix(test): isolate TestFindBeadsDir tests with BEADS_DIR env var The tests were finding the real project's .beads directory instead of the temp directory because FindBeadsDir() walks up the directory tree. Using BEADS_DIR env var provides proper test isolation. * fix(test): stop daemon before running test suite guard The test suite guard checks that tests don't modify the real repo's .beads directory. However, a background daemon running auto-sync would touch issues.jsonl during test execution, causing false positives. Changes: - Set BEADS_NO_DAEMON=1 to prevent daemon auto-start from tests - Stop any running daemon for the repo before taking the "before" snapshot - Uses exec to call `bd daemon --stop` to avoid import cycle issues * chore: revert .beads/issues.jsonl to upstream/main Per CONTRIBUTING.md, .beads/issues.jsonl should not be modified in PRs.
This commit is contained in:
@@ -12,8 +12,34 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/steveyegge/beads"
|
||||
"github.com/steveyegge/beads/internal/config"
|
||||
"github.com/steveyegge/beads/internal/rpc"
|
||||
)
|
||||
|
||||
// isDaemonAutoSyncing checks if daemon is running with auto-commit and auto-push enabled.
|
||||
// Returns false if daemon is not running or check fails (fail-safe to show full protocol).
|
||||
// This is a variable to allow stubbing in tests.
|
||||
var isDaemonAutoSyncing = func() bool {
|
||||
beadsDir := beads.FindBeadsDir()
|
||||
if beadsDir == "" {
|
||||
return false
|
||||
}
|
||||
|
||||
socketPath := filepath.Join(beadsDir, "bd.sock")
|
||||
client, err := rpc.TryConnect(socketPath)
|
||||
if err != nil || client == nil {
|
||||
return false
|
||||
}
|
||||
defer func() { _ = client.Close() }()
|
||||
|
||||
status, err := client.Status()
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
// Only check auto-commit and auto-push (auto-pull is separate)
|
||||
return status.AutoCommit && status.AutoPush
|
||||
}
|
||||
|
||||
var (
|
||||
primeFullMode bool
|
||||
primeMCPMode bool
|
||||
@@ -181,11 +207,15 @@ func outputPrimeContext(w io.Writer, mcpMode bool, stealthMode bool) error {
|
||||
func outputMCPContext(w io.Writer, stealthMode bool) error {
|
||||
ephemeral := isEphemeralBranch()
|
||||
noPush := config.GetBool("no-push")
|
||||
autoSync := isDaemonAutoSyncing()
|
||||
|
||||
var closeProtocol string
|
||||
if stealthMode {
|
||||
// Stealth mode: only flush to JSONL as there's nothing to commit.
|
||||
closeProtocol = "Before saying \"done\": bd sync --flush-only"
|
||||
} else if autoSync && !ephemeral && !noPush {
|
||||
// Daemon is auto-syncing - no bd sync needed
|
||||
closeProtocol = "Before saying \"done\": git status → git add → git commit → git push (beads auto-synced by daemon)"
|
||||
} else if ephemeral {
|
||||
closeProtocol = "Before saying \"done\": git status → git add → bd sync --from-main → git commit (no push - ephemeral branch)"
|
||||
} else if noPush {
|
||||
@@ -217,11 +247,13 @@ Start: Check ` + "`ready`" + ` tool for available work.
|
||||
func outputCLIContext(w io.Writer, stealthMode bool) error {
|
||||
ephemeral := isEphemeralBranch()
|
||||
noPush := config.GetBool("no-push")
|
||||
autoSync := isDaemonAutoSyncing()
|
||||
|
||||
var closeProtocol string
|
||||
var closeNote string
|
||||
var syncSection string
|
||||
var completingWorkflow string
|
||||
var gitWorkflowRule string
|
||||
|
||||
if stealthMode {
|
||||
// Stealth mode: only flush to JSONL, no git operations
|
||||
@@ -233,6 +265,23 @@ func outputCLIContext(w io.Writer, stealthMode bool) error {
|
||||
bd close <id1> <id2> ... # Close all completed issues at once
|
||||
bd sync --flush-only # Export to JSONL
|
||||
` + "```"
|
||||
gitWorkflowRule = "Git workflow: stealth mode (no git ops)"
|
||||
} else if autoSync && !ephemeral && !noPush {
|
||||
// Daemon is auto-syncing - simplified protocol (no bd sync needed)
|
||||
closeProtocol = `[ ] 1. git status (check what changed)
|
||||
[ ] 2. git add <files> (stage code changes)
|
||||
[ ] 3. git commit -m "..." (commit code)
|
||||
[ ] 4. git push (push to remote)`
|
||||
closeNote = "**Note:** Daemon is auto-syncing beads changes. No manual `bd sync` needed."
|
||||
syncSection = `### Sync & Collaboration
|
||||
- Daemon handles beads sync automatically (auto-commit + auto-push + auto-pull enabled)
|
||||
- ` + "`bd sync --status`" + ` - Check sync status`
|
||||
completingWorkflow = `**Completing work:**
|
||||
` + "```bash" + `
|
||||
bd close <id1> <id2> ... # Close all completed issues at once
|
||||
git push # Push to remote (beads auto-synced by daemon)
|
||||
` + "```"
|
||||
gitWorkflowRule = "Git workflow: daemon auto-syncs beads changes"
|
||||
} else if ephemeral {
|
||||
closeProtocol = `[ ] 1. git status (check what changed)
|
||||
[ ] 2. git add <files> (stage code changes)
|
||||
@@ -249,6 +298,7 @@ bd sync --from-main # Pull latest beads from main
|
||||
git add . && git commit -m "..." # Commit your changes
|
||||
# Merge to main when ready (local merge, not push)
|
||||
` + "```"
|
||||
gitWorkflowRule = "Git workflow: run `bd sync --from-main` at session end"
|
||||
} else if noPush {
|
||||
closeProtocol = `[ ] 1. git status (check what changed)
|
||||
[ ] 2. git add <files> (stage code changes)
|
||||
@@ -265,6 +315,7 @@ bd close <id1> <id2> ... # Close all completed issues at once
|
||||
bd sync # Sync beads (push disabled)
|
||||
# git push # Run manually when ready
|
||||
` + "```"
|
||||
gitWorkflowRule = "Git workflow: run `bd sync` at session end (push disabled)"
|
||||
} else {
|
||||
closeProtocol = `[ ] 1. git status (check what changed)
|
||||
[ ] 2. git add <files> (stage code changes)
|
||||
@@ -281,6 +332,7 @@ bd sync # Sync beads (push disabled)
|
||||
bd close <id1> <id2> ... # Close all completed issues at once
|
||||
bd sync # Push to remote
|
||||
` + "```"
|
||||
gitWorkflowRule = "Git workflow: hooks auto-sync, run `bd sync` at session end"
|
||||
}
|
||||
|
||||
redirectNotice := getRedirectNotice(true)
|
||||
@@ -304,7 +356,7 @@ bd sync # Push to remote
|
||||
- Track strategic work in beads (multi-session, dependencies, discovered work)
|
||||
- Use ` + "`bd create`" + ` for issues, TodoWrite for simple single-session execution
|
||||
- When in doubt, prefer bd—persistence you don't need beats lost context
|
||||
- Git workflow: hooks auto-sync, run ` + "`bd sync`" + ` at session end
|
||||
- ` + gitWorkflowRule + `
|
||||
- Session management: check ` + "`bd ready`" + ` for available work
|
||||
|
||||
## Essential Commands
|
||||
|
||||
Reference in New Issue
Block a user