refactor(daemon): consolidate local-only sync functions to reduce duplication (bd-73u)

Extract performExport() and performAutoImport() shared implementations:
- createExportFunc() and createLocalExportFunc() now use performExport()
  with skipGit parameter
- createAutoImportFunc() and createLocalAutoImportFunc() now use performAutoImport()
  with skipGit parameter
- createLocalSyncFunc() kept as-is (different flow from createSyncFunc)

Reduces daemon_sync.go by 89 lines (1003 -> 914) while maintaining
identical behavior and test coverage.

All existing tests pass. New shared functions use conditional logic
to skip git operations when skipGit=true, eliminating the need for
separate implementations.
This commit is contained in:
Steve Yegge
2025-12-01 17:39:43 -08:00
parent f761ba1f3a
commit f84684e314
3 changed files with 73 additions and 157 deletions

View File

@@ -1 +0,0 @@

View File

@@ -8,11 +8,13 @@
{"id":"bd-2em","title":"Expand checkHooksQuick to verify all hook versions","description":"Currently checkHooksQuick only checks post-merge hook version. Should also check pre-commit, pre-push, and post-checkout for completeness. Keep it lightweight but catch more outdated hooks.","status":"closed","priority":2,"issue_type":"task","created_at":"2025-11-25T19:27:47.432243-08:00","updated_at":"2025-11-25T19:50:21.378464-08:00","closed_at":"2025-11-25T19:50:21.378464-08:00"}
{"id":"bd-39o","title":"Rename last_import_hash metadata key to jsonl_content_hash","description":"The metadata key 'last_import_hash' is misleading because it's updated on both import AND export (sync.go:614, import.go:320).\n\nBetter names:\n- jsonl_content_hash (more accurate)\n- last_sync_hash (clearer intent)\n\nThis is a breaking change requiring migration of existing metadata values.","status":"closed","priority":2,"issue_type":"task","created_at":"2025-11-20T21:31:07.568739-05:00","updated_at":"2025-11-29T22:06:06.329653-08:00","closed_at":"2025-11-28T23:13:46.885978-08:00"}
{"id":"bd-3gc","title":"Audit remaining cmd/bd files for error handling consistency","description":"Extend ERROR_HANDLING_AUDIT.md to cover: daemon_sync.go, update.go, list.go, show.go, close.go, reopen.go, dep.go, label.go, comments.go, delete.go, compact.go, config.go, validate.go and other high-usage command files","status":"closed","priority":3,"issue_type":"task","created_at":"2025-11-24T00:28:55.890991-08:00","updated_at":"2025-11-29T22:06:06.32994-08:00","closed_at":"2025-11-28T23:37:52.251887-08:00"}
{"id":"bd-3s8","title":"Imperator clone on beads-sync branch causes bd sync failures","description":"","status":"open","priority":1,"issue_type":"bug","created_at":"2025-11-30T22:53:51.056763-08:00","updated_at":"2025-11-30T22:53:51.056763-08:00"}
{"id":"bd-44e","title":"Ensure deletions.jsonl is tracked in git","description":"Parent: bd-imj\n\nEnsure deletions.jsonl is tracked in git (not ignored).\n\nUpdate bd init and gitignore upgrade logic to:\n1. NOT add deletions.jsonl to .gitignore\n2. Ensure it is committed alongside beads.jsonl\n\nThe file must be in git for cross-clone propagation to work.\n\nAcceptance criteria:\n- bd init does not ignore deletions.jsonl\n- Existing .gitignore files are not broken\n- File appears in git status when modified","status":"closed","priority":2,"issue_type":"task","created_at":"2025-11-25T09:57:21.663196-08:00","updated_at":"2025-11-25T14:55:43.225883-08:00","closed_at":"2025-11-25T14:55:43.225883-08:00"}
{"id":"bd-4aao","title":"Fix failing integration tests in beads-mcp","description":"The `beads-mcp` test suite has failures in `tests/test_bd_client_integration.py` (assertion error in `test_init_creates_beads_directory`) and errors in `tests/test_worktree_separate_dbs.py` (setup failures finding database). These need to be investigated and fixed to ensure a reliable CI baseline.","status":"closed","priority":2,"issue_type":"task","created_at":"2025-11-20T18:53:28.4803-05:00","updated_at":"2025-11-25T21:39:20.967106-08:00","closed_at":"2025-11-25T21:39:20.967106-08:00"}
{"id":"bd-4ew","title":"bd doctor should detect fresh clone and recommend 'bd init'","description":"When running `bd doctor` on a fresh clone (JSONL exists, no .db file), it should:\n\n1. Detect this is a fresh clone situation\n2. Recommend `bd init --prefix \u003cdetected-prefix\u003e` as the fix\n3. Show the prefix detected from the JSONL file\n\nCurrently it shows various warnings (git hooks, merge driver, etc.) but doesn't address the fundamental issue: the database needs to be hydrated.","status":"closed","priority":2,"issue_type":"feature","created_at":"2025-11-27T20:21:15.691764-08:00","updated_at":"2025-11-28T22:14:49.092112-08:00","closed_at":"2025-11-28T22:14:49.092112-08:00"}
{"id":"bd-4h3","title":"Add test coverage for internal/git package","description":"","status":"closed","priority":2,"issue_type":"task","created_at":"2025-11-20T21:21:23.497486-05:00","updated_at":"2025-11-28T22:17:12.606732-08:00","closed_at":"2025-11-28T21:55:45.2527-08:00","dependencies":[{"issue_id":"bd-4h3","depends_on_id":"bd-ge7","type":"blocks","created_at":"2025-11-20T21:21:31.277639-05:00","created_by":"daemon"}]}
{"id":"bd-4l5","title":"bd prime: Detect ephemeral branches and adjust workflow output","description":"When 'bd prime' runs on a branch with no upstream (ephemeral branch), it should output a different SESSION CLOSE PROTOCOL.\n\n**Current output (wrong for ephemeral branches):**\n```\n[ ] 1. git status\n[ ] 2. git add \u003cfiles\u003e\n[ ] 3. bd sync\n[ ] 4. git commit -m \"...\"\n[ ] 5. bd sync\n[ ] 6. git push\n```\n\n**Needed output for ephemeral branches:**\n```\n[ ] 1. git status\n[ ] 2. git add \u003cfiles\u003e\n[ ] 3. bd sync --from-main (pull updates from main)\n[ ] 4. git commit -m \"...\"\n[ ] 5. (no push - branch is ephemeral)\n```\n\n**Detection:** `git rev-parse --abbrev-ref --symbolic-full-name @{u}` returns error code 128 if no upstream.\n\nAlso update Sync \u0026 Collaboration section to mention `bd sync --from-main` for ephemeral branches.\n\n**Use case:** Gastown polecats work on ephemeral local branches that are never pushed. Their code gets merged to main via local merge, and beads changes stay local (communicated via gm mail to Overseer).","status":"closed","priority":1,"issue_type":"feature","created_at":"2025-11-25T16:55:24.984104-08:00","updated_at":"2025-11-25T17:12:46.604978-08:00","closed_at":"2025-11-25T17:12:46.604978-08:00"}
{"id":"bd-4pd","title":"Imperator lacks mail hooks for automatic notification","description":"","status":"open","priority":2,"issue_type":"bug","created_at":"2025-11-30T22:53:52.007971-08:00","updated_at":"2025-11-30T22:53:52.007971-08:00"}
{"id":"bd-4pv","title":"bd export only outputs 1 issue after auto-import corrupts database","description":"When auto-import runs and purges issues (due to git history backfill bug), subsequent 'bd export' only exports 1 issue even though the database should have many.\n\nReproduction:\n1. Have issues.jsonl with 55 issues\n2. Auto-import triggers and purges all issues via git history backfill\n3. Run 'bd export' - only exports 1 issue (the last one created before corruption)\n\nThe database gets into an inconsistent state where most issues are purged but export doesn't realize this.\n\nWorkaround: Rebuild database from scratch with 'rm .beads/beads.db \u0026\u0026 bd init --prefix bd'","status":"closed","priority":2,"issue_type":"bug","created_at":"2025-11-26T22:28:40.828866-08:00","updated_at":"2025-11-28T17:28:55.545056-08:00","closed_at":"2025-11-27T22:50:35.036227-08:00"}
{"id":"bd-4t7","title":"Auto-import runs during --no-auto-import operations via stats/ready commands","description":"Even when using --no-auto-import flag, certain commands like 'bd stats' and 'bd ready' still trigger auto-import internally, which can cause the git history backfill bug to corrupt data.\n\nExample:\n bd stats --no-auto-import\n # Still prints 'Purged bd-xxx (recovered from git history...)'\n\nThe flag should completely disable auto-import for the command, but it appears some code paths still trigger it.\n\nWorkaround: Use --allow-stale instead, or --sandbox mode.","status":"closed","priority":2,"issue_type":"bug","created_at":"2025-11-26T22:28:59.305898-08:00","updated_at":"2025-11-27T00:54:20.335013-08:00","closed_at":"2025-11-27T00:54:12.561872-08:00"}
{"id":"bd-53c","title":"bd sync corrupts issues.jsonl in multi-clone environments","description":"During parallel swarm operations on 2025-11-29, bd sync corrupted the issues database. Commit 93718056 purged all 80 issues from issues.jsonl.\n\nReproduction:\n1. Multiple clones of same repo (polecat swarm)\n2. Each clone runs bd sync in parallel\n3. One sync overwrites others, resulting in data loss\n\nEven in single-clone scenarios (~/src/beads), running bd sync after git pull seems to nuke the JSONL.\n\nWorkaround: Use bd import -i .beads/issues.jsonl --no-git-history instead of bd sync.\n\nRoot cause investigation needed. Options:\n1. Pessimistic locking (flock)\n2. Single point of merge (polecats on ephemeral branches)\n3. Beads-level locking (bd sync --lock)","status":"closed","priority":0,"issue_type":"bug","created_at":"2025-11-29T16:30:30.592507-08:00","updated_at":"2025-11-29T23:19:57.254217-08:00","closed_at":"2025-11-29T23:15:02.435084-08:00"}
@@ -20,6 +22,7 @@
{"id":"bd-63l","title":"bd hooks install fails in git worktrees","description":"When bd is used in a git worktree, bd hooks install fails with 'mkdir .git: not a directory' because .git is a file (gitdir pointer) not a directory. Beads should detect and follow the .git gitdir pointer to install hooks in the correct location. This blocks normal worktree workflows.\n\n## Symptoms of this bug:\n- Git hooks don't install automatically\n- Auto-sync doesn't run (5-second debounce)\n- Hash mismatch warnings in bd output\n- Daemon fails to start with 'auto_start_failed'\n\n## Workaround:\nUse `git rev-parse --git-dir` to find the actual hooks directory and copy hooks manually:\n```bash\nmkdir -p $(git rev-parse --git-dir)/hooks\ncp -r .beads-hooks/* $(git rev-parse --git-dir)/hooks/\n```","status":"closed","priority":1,"issue_type":"bug","created_at":"2025-11-29T00:27:59.111163003-07:00","updated_at":"2025-11-29T23:20:04.196608-08:00","closed_at":"2025-11-29T23:20:01.394894-08:00"}
{"id":"bd-6ic","title":"Second worktree test","description":"","status":"closed","priority":2,"issue_type":"task","created_at":"2025-11-30T00:40:28.768125-08:00","updated_at":"2025-11-30T00:40:58.06615-08:00","closed_at":"2025-11-30T00:40:58.06615-08:00"}
{"id":"bd-736d","title":"Refactor path canonicalization into helper function","description":"The path canonicalization logic (filepath.Abs + EvalSymlinks) is duplicated in 3 places:\n- beads.go:131-137 (BEADS_DIR handling)\n- cmd/bd/main.go:446-451 (--no-db cleanup)\n- cmd/bd/nodb.go:26-31 (--no-db initialization)\n\nRefactoring suggestion:\nExtract to a helper function like:\n func canonicalizePath(path string) string\n\nThis would:\n- Reduce code duplication\n- Make the logic easier to maintain\n- Ensure consistent behavior across all path handling\n\nRelated to bd-e16b implementation.","status":"closed","priority":3,"issue_type":"chore","created_at":"2025-11-02T18:33:47.727443-08:00","updated_at":"2025-11-25T22:27:33.738672-08:00","closed_at":"2025-11-25T22:27:33.738672-08:00"}
{"id":"bd-73u","title":"Refactor daemon local-only sync functions to reduce duplication","description":"PR #433 added three new local-only sync functions (createLocalSyncFunc, createLocalExportFunc, createLocalAutoImportFunc) that are largely copy-paste of existing ones with git operations removed. Refactor to use a single implementation with a skipGit bool parameter or extract shared logic into helper functions to reduce ~200 lines of duplication.","status":"in_progress","priority":3,"issue_type":"task","created_at":"2025-12-01T17:38:02.632264-08:00","updated_at":"2025-12-01T17:38:50.810193-08:00"}
{"id":"bd-81a","title":"Add programmatic tip injection API","description":"Allow tips to be programmatically injected at runtime based on detected conditions. This enables dynamic tips (not just pre-defined ones) to be shown with custom priority and frequency.","status":"closed","priority":2,"issue_type":"feature","created_at":"2025-11-11T23:29:46.645583-08:00","updated_at":"2025-11-25T17:52:35.096882-08:00","closed_at":"2025-11-25T17:52:35.096882-08:00","dependencies":[{"issue_id":"bd-81a","depends_on_id":"bd-d4i","type":"blocks","created_at":"2025-11-11T23:29:46.646327-08:00","created_by":"daemon"}]}
{"id":"bd-8a5","title":"Refactor: deduplicate FindJSONLInDir and FindJSONLPath","description":"## Background\n\nAfter fixing bd-tqo, we now have two nearly identical functions for finding the JSONL file:\n- `autoimport.FindJSONLInDir(dbDir string)` in internal/autoimport/autoimport.go\n- `beads.FindJSONLPath(dbPath string)` in internal/beads/beads.go\n\nBoth implement the same logic:\n1. Prefer issues.jsonl\n2. Fall back to beads.jsonl for legacy support\n3. Skip deletions.jsonl and merge artifacts\n4. Default to issues.jsonl if nothing found\n\n## Problem\n\nCode duplication means bug fixes need to be applied in multiple places (as we just experienced with bd-tqo).\n\n## Proposed Solution\n\nExtract shared logic to a utility package that both can import. Options:\n1. Create `internal/jsonlpath` package with the core logic\n2. Have `autoimport` import `beads` and call `FindJSONLPath` (but APIs differ slightly)\n3. Move to `internal/utils` if appropriate\n\nNeed to verify no import cycles would be created.\n\n## Affected Files\n- internal/autoimport/autoimport.go\n- internal/beads/beads.go","status":"closed","priority":4,"issue_type":"task","created_at":"2025-11-26T23:45:18.974339-08:00","updated_at":"2025-11-29T22:06:06.330185-08:00","closed_at":"2025-11-28T23:07:08.912247-08:00"}
{"id":"bd-8an","title":"bd import auto-detects wrong prefix from directory name instead of issue IDs","description":"When importing issues.jsonl into a fresh database, 'bd import' prints:\n\n ✓ Initialized database with prefix 'beads' (detected from issues)\n\nBut the issues all have prefix 'bd-' (e.g., bd-03r). It appears to be detecting the prefix from the directory name (.beads/) rather than from the actual issue IDs in the JSONL.\n\nThis causes import to fail with:\n validate ID prefix for bd-03r: issue ID 'bd-03r' does not match configured prefix 'beads'\n\nWorkaround: Run 'bd config set issue_prefix bd' before import, or use 'bd init --prefix bd'.","status":"closed","priority":2,"issue_type":"bug","created_at":"2025-11-26T22:28:01.582564-08:00","updated_at":"2025-11-28T22:17:12.607316-08:00","closed_at":"2025-11-27T22:38:48.971617-08:00"}
@@ -38,6 +41,7 @@
{"id":"bd-c4rq","title":"Refactor: Move staleness check inside daemon branch","description":"## Problem\n\nCurrently ensureDatabaseFresh() is called before the daemon mode check, but it checks daemonClient != nil internally and returns early. This is redundant.\n\n**Location:** All read commands (list.go:196, show.go:27, ready.go:102, status.go:80, etc.)\n\n## Current Pattern\n\nCall happens before daemon check, function checks daemonClient internally.\n\n## Better Pattern\n\nMove staleness check to direct mode branch only, after daemon check.\n\n## Impact\nLow - minor performance improvement (avoids one function call per command in daemon mode)\n\n## Effort\nMedium - requires refactoring 8 command files\n\n## Priority\nLow - can defer to future cleanup PR","status":"closed","priority":3,"issue_type":"chore","created_at":"2025-11-20T20:17:45.119583-05:00","updated_at":"2025-11-29T22:06:06.330716-08:00","closed_at":"2025-11-28T23:37:52.276192-08:00"}
{"id":"bd-c8x","title":"Don't search parent directories for .beads databases","description":"bd currently walks up the directory tree looking for .beads directories, which can find unrelated databases (e.g., ~/.beads). This causes confusing warnings and potential data pollution.\n\nShould either:\n1. Stop at git root (don't search above it)\n2. Only use explicit BEADS_DB env var or local .beads\n3. At minimum, don't search in home directory","status":"closed","priority":2,"issue_type":"bug","created_at":"2025-11-27T22:10:41.992686-08:00","updated_at":"2025-11-28T22:17:12.607956-08:00","closed_at":"2025-11-28T22:15:55.878353-08:00"}
{"id":"bd-clg","title":"bd jira sync command","description":"Add a built-in bd command for Jira synchronization.\n\n**Requires**: Both import and export scripts working\n\n**Features**:\n- `bd jira sync --pull` - Import from Jira to beads\n- `bd jira sync --push` - Export from beads to Jira\n- `bd jira sync` - Bidirectional (pull then push, with conflict resolution)\n- `bd jira status` - Show sync status and last sync time\n\n**Conflict resolution**:\n- Timestamp-based: newer update wins\n- Option for --prefer-local or --prefer-jira to override\n- Interactive mode for manual conflict resolution (optional)\n\n**Integration**:\n- Uses jira.* config settings from bd config\n- Stores last sync timestamp in config\n- Logs sync activity for audit\n\n**Stretch goals**:\n- Webhook integration for real-time sync\n- Selective sync by JQL filter","status":"closed","priority":3,"issue_type":"feature","created_at":"2025-11-30T12:56:27.716537-08:00","updated_at":"2025-11-30T15:25:37.896045-08:00","closed_at":"2025-11-30T15:25:37.896045-08:00","dependencies":[{"issue_id":"bd-clg","depends_on_id":"bd-qvj","type":"parent-child","created_at":"2025-11-30T12:56:49.796568-08:00","created_by":"stevey"},{"issue_id":"bd-clg","depends_on_id":"bd-tjn","type":"blocks","created_at":"2025-11-30T12:57:00.075288-08:00","created_by":"stevey"},{"issue_id":"bd-clg","depends_on_id":"bd-93d","type":"blocks","created_at":"2025-11-30T12:57:05.206431-08:00","created_by":"stevey"}]}
{"id":"bd-co0","title":"Imperator does not know its own mail identity","description":"","status":"open","priority":1,"issue_type":"bug","created_at":"2025-11-30T22:53:49.963803-08:00","updated_at":"2025-11-30T22:53:49.963803-08:00"}
{"id":"bd-d4i","title":"Create tip system infrastructure for contextual hints","description":"Implement a tip/hint system that shows helpful contextual messages after successful commands. This is different from the existing error-path \"Hint:\" messages - tips appear on success paths to educate users about features they might not know about.","status":"closed","priority":2,"issue_type":"feature","created_at":"2025-11-11T23:29:15.693956-08:00","updated_at":"2025-11-25T17:47:30.747566-08:00","closed_at":"2025-11-25T17:47:30.747566-08:00"}
{"id":"bd-dmb","title":"Fresh clone: bd should suggest 'bd init' when no database exists","description":"On a fresh clone of a repo using beads, running `bd stats` or `bd list` gives a cryptic error:\n\n```\nError: failed to open database: post-migration validation failed: migration invariants failed:\n - required_config_present: required config key missing: issue_prefix (database has 2 issues)\n```\n\n**Expected**: A helpful message like:\n```\nNo database found. This appears to be a fresh clone.\nRun 'bd init --prefix \u003cprefix\u003e' to hydrate from the committed JSONL file.\nFound: .beads/beads.jsonl (38 issues)\n```\n\n**Why this matters**: The current UX is confusing for new contributors or fresh clones. The happy path should be obvious.","status":"closed","priority":1,"issue_type":"feature","created_at":"2025-11-27T20:21:04.947959-08:00","updated_at":"2025-11-27T22:40:11.654051-08:00","closed_at":"2025-11-27T22:40:11.654051-08:00"}
{"id":"bd-e166","title":"Improve timestamp comparison readability in import","description":"The timestamp comparison logic uses double-negative which can be confusing:\n\nCurrent code:\nif !incoming.UpdatedAt.After(existing.UpdatedAt) {\n // skip update\n}\n\nMore readable:\nif incoming.UpdatedAt.After(existing.UpdatedAt) {\n // perform update\n} else {\n // skip (local is newer)\n}\n\nThis is a minor refactor for code clarity.\n\nRelated: bd-1022\nFiles: internal/importer/importer.go:411, 488","status":"closed","priority":4,"issue_type":"chore","created_at":"2025-11-02T15:32:12.27108-08:00","updated_at":"2025-11-26T22:25:27.124071-08:00","closed_at":"2025-11-26T22:25:27.124071-08:00"}
@@ -47,6 +51,7 @@
{"id":"bd-emg","title":"bd init should refuse when JSONL already has issues (safety guard)","description":"When running `bd init` in a directory with an existing JSONL containing issues, bd should refuse and suggest the correct action instead of proceeding.\n\n## The Problem\n\nCurrent behavior when database is missing but JSONL exists:\n```\n$ bd create \"test\"\nError: no beads database found\nHint: run 'bd init' to create a database...\n```\n\nThis leads users (and AI agents) to reflexively run `bd init`, which can cause:\n- Prefix mismatch if wrong prefix specified\n- Data corruption if JSONL is damaged\n- Confusion about what actually happened\n\n## Proposed Behavior\n\n```\n$ bd init --prefix bd\n\n⚠ Found existing .beads/issues.jsonl with 76 issues.\n\nThis appears to be a fresh clone, not a new project.\n\nTo hydrate the database from existing JSONL:\n bd doctor --fix\n\nTo force re-initialization (may cause data loss):\n bd init --prefix bd --force\n\nAborting.\n```\n\n## Trigger Conditions\n\n- `.beads/issues.jsonl` or `.beads/beads.jsonl` exists\n- File contains \u003e 0 valid issue lines\n- No `--force` flag provided\n\n## Edge Cases\n\n- Empty JSONL (0 issues) → allow init (new project)\n- Corrupted JSONL → warn but allow with confirmation\n- Existing `.db` file → definitely refuse (weird state)\n\n## Related\n\n- bd-dmb: Fresh clone should suggest hydration (better error messages)\n- bd-4ew: bd doctor should detect fresh clone\n\nThis issue is about the safety guard on `bd init` itself, not the error messages from other commands.","status":"closed","priority":2,"issue_type":"bug","created_at":"2025-11-28T18:21:41.149304-08:00","updated_at":"2025-11-28T22:17:18.849507-08:00","closed_at":"2025-11-28T22:17:18.849507-08:00"}
{"id":"bd-f0n","title":"Git history fallback missing timeout - could hang on large repos","description":"## Problem\n\nThe git commands in `checkGitHistoryForDeletions` have no timeout. On large repos with extensive history, `git log --all -S` or `git log --all -G` can take a very long time (minutes).\n\n## Location\n`internal/importer/importer.go:899` and `:930`\n\n## Impact\n- Import could hang indefinitely\n- User has no feedback that git search is running\n- No way to cancel except killing the process\n\n## Fix\nAdd context with timeout to git commands:\n\n```go\nctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)\ndefer cancel()\ncmd := exec.CommandContext(ctx, \"git\", ...)\n```\n\nAlso consider adding a `--since` flag to bound the git history search.","status":"closed","priority":2,"issue_type":"bug","created_at":"2025-11-25T12:48:24.388639-08:00","updated_at":"2025-11-25T15:04:53.669714-08:00","closed_at":"2025-11-25T15:04:53.669714-08:00"}
{"id":"bd-f2f","title":"CRITICAL: bd sync exports before pull, allowing stale DB to corrupt JSONL statuses","description":"## Root Cause\n\nThe fix in bd-53c (reverse ZFC check) only checks COUNTS, not content. The real corruption happens when:\n\n1. Polecat A has stale DB with old status values (e.g., status=closed for issues that are now open on remote)\n2. Polecat A runs bd sync:\n - **Export FIRST**: DB (status=closed) → JSONL (overwrites correct status=open)\n - Commit: Stale JSONL committed\n - Pull: 3-way merge with remote\n - Merge uses 'closed wins' rule → status stays closed\n3. Polecat A pushes → Remote now corrupted with status=closed\n\n## Why bd-53c didn't fix it\n\nThe reverse ZFC check compares COUNTS:\n```go\nif jsonlCount \u003e dbCount // Only catches count mismatch\n```\n\nBut in the corruption scenario:\n- JSONL count = 5, DB count = 5 (same count!)\n- Only the STATUS field differs\n\n## The Real Fix\n\n**PULL BEFORE EXPORT**. The sync order must be:\n1. Pull from remote (get latest state)\n2. Import merged JSONL to DB\n3. THEN export DB changes (if any)\n\nCurrent order is: Export → Commit → Pull → Import → Push\n\nThis is a fundamental architecture change to the sync flow.\n\n## Workaround\n\nUse --no-auto-flush and manually control the sync order, or disable daemon auto-export.\n\n## Evidence\n\nFrom user investigation:\n- At 595b7943 (13:20:30): 5 open issues\n- At 10239812 (13:28:39): 0 open issues\n- All 5 issues had their status changed from open to closed\n- Count stayed at 5 (not a deletion issue)","status":"closed","priority":0,"issue_type":"bug","created_at":"2025-11-29T17:33:26.744766-08:00","updated_at":"2025-11-29T19:24:31.010075-08:00","closed_at":"2025-11-29T19:24:31.010075-08:00"}
{"id":"bd-fl4","title":"Test sync branch setup","description":"","status":"closed","priority":2,"issue_type":"task","created_at":"2025-11-30T00:26:47.520507-08:00","updated_at":"2025-11-30T00:33:23.105998-08:00","closed_at":"2025-11-30T00:33:23.105998-08:00"}
{"id":"bd-ge7","title":"Improve Beads test coverage from 46% to 80%","description":"","status":"closed","priority":1,"issue_type":"epic","created_at":"2025-11-20T21:21:03.700271-05:00","updated_at":"2025-11-28T22:17:12.608871-08:00","closed_at":"2025-11-28T21:56:04.085939-08:00"}
{"id":"bd-ghb","title":"Add --yes flag to bd doctor --fix for non-interactive mode","description":"## Feature Request\n\nAdd a `--yes` or `-y` flag to `bd doctor --fix` that automatically confirms all prompts, enabling non-interactive usage in scripts and CI/CD pipelines.\n\n## Current Behavior\n`bd doctor --fix` prompts for confirmation before applying fixes, which blocks automated workflows.\n\n## Desired Behavior\n`bd doctor --fix --yes` should apply all fixes without prompting.\n\n## Use Cases\n- CI/CD pipelines that need to auto-fix issues\n- Scripts that automate repository setup\n- Pre-commit hooks that want to silently fix issues","status":"closed","priority":3,"issue_type":"feature","created_at":"2025-11-26T23:22:45.486584-08:00","updated_at":"2025-11-28T22:17:12.609134-08:00","closed_at":"2025-11-28T21:55:06.895066-08:00"}
{"id":"bd-gqo","title":"Implement health checks in daemon event loop","description":"Add health checks to checkDaemonHealth() function in daemon_event_loop.go:170:\n- Database integrity check\n- Disk space check\n- Memory usage check\n\nCurrently it's just a no-op placeholder.","status":"closed","priority":3,"issue_type":"feature","created_at":"2025-11-21T18:55:07.534304-05:00","updated_at":"2025-11-29T22:06:06.330972-08:00","closed_at":"2025-11-28T23:10:19.946063-08:00"}
@@ -57,6 +62,7 @@
{"id":"bd-io0","title":"sync.branch config lost on clone - should be in config.yaml","description":"## Problem\n\nThe sync.branch configuration is stored in the SQLite database, which is gitignored. When contributors clone a repo that uses beads:\n\n1. They get .beads/issues.jsonl (tracked)\n2. They don't get .beads/beads.db (gitignored)\n3. They lose the sync.branch config\n\nWhen they run 'bd init' or 'bd doctor --fix', sync.branch gets auto-set to the current branch (usually 'main'), but if the project uses a dedicated sync branch like 'beads-sync', they'll be committing to the wrong branch.\n\n## Root Cause\n\nsyncbranch.Get() only checks:\n1. BEADS_SYNC_BRANCH env var\n2. Database config (store.GetConfig)\n\nIt never reads from config.yaml, which IS tracked in git and persists across clones.\n\n## Proposed Solution\n\nAdd sync-branch support to config.yaml with this precedence:\n1. BEADS_SYNC_BRANCH env var (highest)\n2. config.yaml sync-branch setting\n3. Database config (legacy/local override)\n4. Auto-detect from current branch (lowest)\n\nChanges needed:\n1. Update syncbranch.Get() to check config.GetString('sync-branch') between env and database\n2. Update config.yaml template in init.go to include sync-branch\n3. Update docs to recommend setting sync-branch in config.yaml for team projects\n4. Consider: bd init --branch should also write to config.yaml, not just database","status":"closed","priority":1,"issue_type":"bug","created_at":"2025-11-30T10:51:29.594627-08:00","updated_at":"2025-11-30T10:54:14.198025-08:00","closed_at":"2025-11-30T10:54:14.198025-08:00"}
{"id":"bd-j3zt","title":"Fix mypy errors in beads-mcp","description":"Running `mypy .` in `integrations/beads-mcp` reports 287 errors. These should be addressed to improve type safety and code quality.","status":"closed","priority":3,"issue_type":"task","created_at":"2025-11-20T18:53:28.557708-05:00","updated_at":"2025-11-27T00:54:20.336256-08:00","closed_at":"2025-11-27T00:37:17.188443-08:00"}
{"id":"bd-k4b","title":"Enhance dep tree to show full dependency graph","description":"When running `bd dep tree \u003cissue-id\u003e`, the current output only shows the issue itself without its dependency relationships.\n\n## Current Behavior\n\n```\n$ bd dep tree gt-0iqq\n🌲 Dependency tree for gt-0iqq:\n\n→ gt-0iqq: Implement Boss (global overseer) [P2] (open)\n```\n\nThis doesn't show any of the dependency structure.\n\n## Desired Behavior\n\nShow the full dependency DAG rooted at the given issue. For example:\n\n```\n$ bd dep tree gt-0iqq\n🌲 Dependency tree for gt-0iqq:\n\ngt-0iqq: Implement Boss (global overseer) [P2] (open)\n├── gt-0xh4: Boss session management [P2] (open) [READY]\n│ ├── gt-le7c: Boss mail identity [P2] (open)\n│ │ ├── gt-r8fe: Boss human escalation queue [P2] (open)\n│ │ └── gt-vdak: Boss dispatch loop [P2] (open)\n│ │ └── gt-kgy6: Boss resource management [P2] (open)\n│ │ └── gt-93iv: Boss wake daemon [P2] (open)\n│ └── gt-vdak: (shown above)\n```\n\n## Suggested Options\n\n- `--direction=down|up|both` - Show dependents (what this blocks), dependencies (what blocks this), or both\n- `--status=open` - Filter to only show issues with a given status\n- `--depth=N` - Limit tree depth\n- Handle DAG cycles gracefully (show \"(shown above)\" or similar for already-displayed nodes)\n\n## Use Case\n\nWhen reorganizing a set of related issues (like I just did with the Boss implementation), being able to visualize the full dependency graph helps verify the structure is correct before syncing.","status":"closed","priority":2,"issue_type":"feature","created_at":"2025-11-25T19:18:18.750649-08:00","updated_at":"2025-11-25T19:50:46.863319-08:00","closed_at":"2025-11-25T19:31:55.312314-08:00"}
{"id":"bd-kig","title":"Test worktree sync branch commit","description":"","status":"closed","priority":2,"issue_type":"task","created_at":"2025-11-30T00:38:13.906936-08:00","updated_at":"2025-11-30T00:40:23.609537-08:00","closed_at":"2025-11-30T00:40:23.609537-08:00"}
{"id":"bd-l7u","title":"Duplicate DefaultRetentionDays constants","description":"## Problem\n\nThere are now two constants for the same value:\n\n1. `deletions.DefaultRetentionDays = 7` in `internal/deletions/deletions.go:184`\n2. `configfile.DefaultDeletionsRetentionDays = 7` in `internal/configfile/configfile.go:102`\n\n## Impact\n- DRY violation\n- Risk of values getting out of sync\n- Confusing which one to use\n\n## Fix\nRemove the constant from `deletions` package and have it import from `configfile`, or create a shared constants package.","status":"closed","priority":3,"issue_type":"task","created_at":"2025-11-25T12:49:38.356211-08:00","updated_at":"2025-11-25T15:15:21.964842-08:00","closed_at":"2025-11-25T15:15:21.964842-08:00"}
{"id":"bd-l954","title":"Performance Testing Framework","description":"Add comprehensive performance testing for beads focusing on optimization guidance and validating 10K+ database scale. Uses standard Go tooling, follows existing patterns, minimal complexity.\n\nComponents:\n- Benchmark suite for critical operations at 10K-20K scale\n- Fixture generator for realistic test data (epic hierarchies, cross-links)\n- User diagnostics via bd doctor --perf\n- Always-on profiling integration\n\nGoals:\n- Identify bottlenecks for optimization work\n- Validate performance at 10K+ issue scale\n- Enable users to collect diagnostics for bug reports\n- Support both SQLite and JSONL import paths","status":"closed","priority":2,"issue_type":"epic","created_at":"2025-11-13T22:22:11.203467-08:00","updated_at":"2025-11-29T22:06:06.331232-08:00","closed_at":"2025-11-28T23:07:57.285628-08:00"}
{"id":"bd-m0w","title":"Add test coverage for internal/validation package","description":"","status":"closed","priority":2,"issue_type":"task","created_at":"2025-11-20T21:21:24.129559-05:00","updated_at":"2025-11-28T22:17:12.609385-08:00","closed_at":"2025-11-28T21:52:34.198974-08:00","dependencies":[{"issue_id":"bd-m0w","depends_on_id":"bd-ge7","type":"blocks","created_at":"2025-11-20T21:21:31.350477-05:00","created_by":"daemon"}]}

View File

@@ -375,11 +375,27 @@ Solutions:
// createExportFunc creates a function that only exports database to JSONL
// and optionally commits/pushes (no git pull or import). Used for mutation events.
func createExportFunc(ctx context.Context, store storage.Storage, autoCommit, autoPush bool, log daemonLogger) func() {
return performExport(ctx, store, autoCommit, autoPush, false, log)
}
// createLocalExportFunc creates a function that only exports database to JSONL
// without any git operations. Used for local-only mode with mutation events.
func createLocalExportFunc(ctx context.Context, store storage.Storage, log daemonLogger) func() {
return performExport(ctx, store, false, false, true, log)
}
// performExport is the shared implementation for export-only functions.
// skipGit: if true, skips all git operations (commits, pushes).
func performExport(ctx context.Context, store storage.Storage, autoCommit, autoPush, skipGit bool, log daemonLogger) func() {
return func() {
exportCtx, exportCancel := context.WithTimeout(ctx, 30*time.Second)
defer exportCancel()
log.log("Starting export...")
mode := "export"
if skipGit {
mode = "local export"
}
log.log("Starting %s...", mode)
jsonlPath := findJSONLPath()
if jsonlPath == "" {
@@ -392,9 +408,9 @@ func createExportFunc(ctx context.Context, store storage.Storage, autoCommit, au
skip, holder, err := types.ShouldSkipDatabase(beadsDir)
if skip {
if err != nil {
log.log("Skipping export (lock check failed: %v)", err)
log.log("Skipping %s (lock check failed: %v)", mode, err)
} else {
log.log("Skipping export (locked by %s)", holder)
log.log("Skipping %s (locked by %s)", mode, holder)
}
return
}
@@ -436,8 +452,8 @@ func createExportFunc(ctx context.Context, store storage.Storage, autoCommit, au
log.log("Warning: failed to update database mtime: %v", err)
}
// Auto-commit if enabled
if autoCommit {
// Auto-commit if enabled (skip in git-free mode)
if autoCommit && !skipGit {
// Try sync branch commit first
committed, err := syncBranchCommitAndPush(exportCtx, store, autoPush, log)
if err != nil {
@@ -473,18 +489,38 @@ func createExportFunc(ctx context.Context, store storage.Storage, autoCommit, au
}
}
log.log("Export complete")
if skipGit {
log.log("Local export complete")
} else {
log.log("Export complete")
}
}
}
// createAutoImportFunc creates a function that pulls from git and imports JSONL
// to database (no export). Used for file system change events.
func createAutoImportFunc(ctx context.Context, store storage.Storage, log daemonLogger) func() {
return performAutoImport(ctx, store, false, log)
}
// createLocalAutoImportFunc creates a function that imports from JSONL to database
// without any git operations. Used for local-only mode with file system change events.
func createLocalAutoImportFunc(ctx context.Context, store storage.Storage, log daemonLogger) func() {
return performAutoImport(ctx, store, true, log)
}
// performAutoImport is the shared implementation for import-only functions.
// skipGit: if true, skips git pull operations.
func performAutoImport(ctx context.Context, store storage.Storage, skipGit bool, log daemonLogger) func() {
return func() {
importCtx, importCancel := context.WithTimeout(ctx, 1*time.Minute)
defer importCancel()
log.log("Starting auto-import...")
mode := "auto-import"
if skipGit {
mode = "local auto-import"
}
log.log("Starting %s...", mode)
jsonlPath := findJSONLPath()
if jsonlPath == "" {
@@ -497,9 +533,9 @@ func createAutoImportFunc(ctx context.Context, store storage.Storage, log daemon
skip, holder, err := types.ShouldSkipDatabase(beadsDir)
if skip {
if err != nil {
log.log("Skipping import (lock check failed: %v)", err)
log.log("Skipping %s (lock check failed: %v)", mode, err)
} else {
log.log("Skipping import (locked by %s)", holder)
log.log("Skipping %s (locked by %s)", mode, holder)
}
return
}
@@ -512,25 +548,28 @@ func createAutoImportFunc(ctx context.Context, store storage.Storage, log daemon
// Use getRepoKeyForPath for multi-repo support (bd-ar2.10, bd-ar2.11)
repoKey := getRepoKeyForPath(jsonlPath)
if !hasJSONLChanged(importCtx, store, jsonlPath, repoKey) {
log.log("Skipping import: JSONL content unchanged")
log.log("Skipping %s: JSONL content unchanged", mode)
return
}
log.log("JSONL content changed, proceeding with import...")
log.log("JSONL content changed, proceeding with %s...", mode)
// Pull from git (try sync branch first)
pulled, err := syncBranchPull(importCtx, store, log)
if err != nil {
log.log("Sync branch pull failed: %v", err)
return
}
// If sync branch not configured, use regular pull
if !pulled {
if err := gitPull(importCtx); err != nil {
log.log("Pull failed: %v", err)
// Pull from git if not in git-free mode
if !skipGit {
// Try sync branch first
pulled, err := syncBranchPull(importCtx, store, log)
if err != nil {
log.log("Sync branch pull failed: %v", err)
return
}
log.log("Pulled from remote")
// If sync branch not configured, use regular pull
if !pulled {
if err := gitPull(importCtx); err != nil {
log.log("Pull failed: %v", err)
return
}
log.log("Pulled from remote")
}
}
// Count issues before import
@@ -559,7 +598,11 @@ func createAutoImportFunc(ctx context.Context, store storage.Storage, log daemon
return
}
log.log("Auto-import complete")
if skipGit {
log.log("Local auto-import complete")
} else {
log.log("Auto-import complete")
}
}
}
@@ -869,135 +912,3 @@ func createLocalSyncFunc(ctx context.Context, store storage.Storage, log daemonL
log.log("Local sync cycle complete")
}
}
// createLocalExportFunc creates a function that only exports database to JSONL
// without any git operations. Used for local-only mode with mutation events.
func createLocalExportFunc(ctx context.Context, store storage.Storage, log daemonLogger) func() {
return func() {
exportCtx, exportCancel := context.WithTimeout(ctx, 30*time.Second)
defer exportCancel()
log.log("Starting local export...")
jsonlPath := findJSONLPath()
if jsonlPath == "" {
log.log("Error: JSONL path not found")
return
}
// Check for exclusive lock
beadsDir := filepath.Dir(jsonlPath)
skip, holder, err := types.ShouldSkipDatabase(beadsDir)
if skip {
if err != nil {
log.log("Skipping export (lock check failed: %v)", err)
} else {
log.log("Skipping export (locked by %s)", holder)
}
return
}
if holder != "" {
log.log("Removed stale lock (%s), proceeding", holder)
}
// Pre-export validation
if err := validatePreExport(exportCtx, store, jsonlPath); err != nil {
log.log("Pre-export validation failed: %v", err)
return
}
// Export to JSONL
if err := exportToJSONLWithStore(exportCtx, store, jsonlPath); err != nil {
log.log("Export failed: %v", err)
return
}
log.log("Exported to JSONL")
// Update export metadata
multiRepoPaths := getMultiRepoJSONLPaths()
if multiRepoPaths != nil {
for _, path := range multiRepoPaths {
repoKey := getRepoKeyForPath(path)
updateExportMetadata(exportCtx, store, path, log, repoKey)
}
} else {
updateExportMetadata(exportCtx, store, jsonlPath, log, "")
}
// Update database mtime to be >= JSONL mtime
dbPath := filepath.Join(beadsDir, "beads.db")
if err := TouchDatabaseFile(dbPath, jsonlPath); err != nil {
log.log("Warning: failed to update database mtime: %v", err)
}
log.log("Local export complete")
}
}
// createLocalAutoImportFunc creates a function that imports from JSONL to database
// without any git operations. Used for local-only mode with file system change events.
func createLocalAutoImportFunc(ctx context.Context, store storage.Storage, log daemonLogger) func() {
return func() {
importCtx, importCancel := context.WithTimeout(ctx, 1*time.Minute)
defer importCancel()
log.log("Starting local auto-import...")
jsonlPath := findJSONLPath()
if jsonlPath == "" {
log.log("Error: JSONL path not found")
return
}
// Check for exclusive lock
beadsDir := filepath.Dir(jsonlPath)
skip, holder, err := types.ShouldSkipDatabase(beadsDir)
if skip {
if err != nil {
log.log("Skipping import (lock check failed: %v)", err)
} else {
log.log("Skipping import (locked by %s)", holder)
}
return
}
if holder != "" {
log.log("Removed stale lock (%s), proceeding", holder)
}
// Check JSONL content hash to avoid redundant imports
repoKey := getRepoKeyForPath(jsonlPath)
if !hasJSONLChanged(importCtx, store, jsonlPath, repoKey) {
log.log("Skipping import: JSONL content unchanged")
return
}
log.log("JSONL content changed, proceeding with import...")
// Count issues before import
beforeCount, err := countDBIssues(importCtx, store)
if err != nil {
log.log("Failed to count issues before import: %v", err)
return
}
// Import from JSONL (no git pull in local mode)
if err := importToJSONLWithStore(importCtx, store, jsonlPath); err != nil {
log.log("Import failed: %v", err)
return
}
log.log("Imported from JSONL")
// Validate import
afterCount, err := countDBIssues(importCtx, store)
if err != nil {
log.log("Failed to count issues after import: %v", err)
return
}
if err := validatePostImport(beforeCount, afterCount, jsonlPath); err != nil {
log.log("Post-import validation failed: %v", err)
return
}
log.log("Local auto-import complete")
}
}