Commit Graph

5450 Commits

Author SHA1 Message Date
mayor
1a0e5a8d52 bd daemon sync: 2026-01-07 21:30:29 2026-01-07 21:30:29 -08:00
Peter Chanthamynavong
1561374c04 feat(sync): pull-first sync with 3-way merge (#918)
* feat(sync): implement pull-first synchronization strategy

- Add --pull-first flag and logic to sync command
- Introduce 3-way merge stub for issue synchronization
- Add concurrent edit tests for the pull-first flow

Ensures local changes are reconciled with remote updates before pushing to prevent data loss.

* feat(sync): implement 3-way merge and state tracking

- Implement 3-way merge algorithm for issue synchronization
- Add base state storage to track changes between syncs
- Add comprehensive tests for merge logic and persistence

Ensures data consistency and prevents data loss during concurrent
issue updates.

* feat(sync): implement field-level conflict merging

- Implement field-level merge logic for issue conflicts
- Add unit tests for field-level merge strategies

Reduces manual intervention by automatically resolving overlapping updates at the field level.

* refactor(sync): simplify sync flow by removing ZFC checks

The previous sync implementation relied on Zero-False-Convergence (ZFC)
staleness checks which are redundant following the transition to
structural 3-way merging. This legacy logic added complexity and
maintenance overhead without providing additional safety.

This commit introduces a streamlined sync pipeline:
- Remove ZFC staleness validation from primary sync flow
- Update safety documentation to reflect current merge strategy
- Eliminate deprecated unit tests associated with ZFC logic

These changes reduce codebase complexity while maintaining data
integrity through the robust structural 3-way merge implementation.

* feat(sync): default to pull-first sync workflow

- Set pull-first as the primary synchronization workflow
- Refactor core sync logic for better maintainability
- Update concurrent edit tests to validate 3-way merge logic

Reduces merge conflicts by ensuring local state is current before pushing changes.

* refactor(sync): clean up lint issues in merge code

- Remove unused error return from MergeIssues (never returned error)
- Use _ prefix for unused _base parameter in mergeFieldLevel
- Update callers to not expect error from MergeIssues
- Keep nolint:gosec for trusted internal file path

* test(sync): add mode compatibility and upgrade safety tests

Add tests addressing Steve's PR #918 review concerns:

- TestSyncBranchModeWithPullFirst: Verifies sync-branch config
  storage and git branch creation work with pull-first
- TestExternalBeadsDirWithPullFirst: Verifies external BEADS_DIR
  detection and pullFromExternalBeadsRepo
- TestUpgradeFromOldSync: Validates upgrade safety when
  sync_base.jsonl doesn't exist (first sync after upgrade)
- TestMergeIssuesWithBaseState: Comprehensive 3-way merge cases
- TestLabelUnionMerge: Verifies labels use union (no data loss)

Key upgrade behavior validated:
- base=nil (no sync_base.jsonl) safely handles all cases
- Local-only issues kept (StrategyLocal)
- Remote-only issues kept (StrategyRemote)
- Overlapping issues merged (LWW scalars, union labels)

* fix(sync): report line numbers for malformed JSON

Problem:
- JSON decoding errors when loading sync base state lacked line numbers
- Difficult to identify location of syntax errors in large state files

Solution:
- Include line number reporting in JSON decoder errors during state loading
- Add regression tests for malformed sync base file scenarios

Impact:
- Users receive actionable feedback for corrupted state files
- Faster troubleshooting of manual configuration errors

* fix(sync): warn on large clock skew during sync

Problem:
- Unsynchronized clocks between systems could lead to silent merge errors
- No mechanism existed to alert users of significant timestamp drift

Solution:
- Implement clock skew detection during sync merge
- Log a warning when large timestamp differences are found
- Add comprehensive unit tests for skew reporting

Impact:
- Users are alerted to potential synchronization risks
- Easier debugging of time-related merge issues

* fix(sync): defer state update until remote push succeeds

Problem:
- Base state updated before confirming remote push completion
- Failed pushes resulted in inconsistent local state tracking

Solution:
- Defer base state update until after the remote push succeeds

Impact:
- Ensures local state accurately reflects remote repository status
- Prevents state desynchronization during network or push failures

* fix(sync): prevent concurrent sync operations

Problem:
- Multiple sync processes could run simultaneously
- Overlapping operations risk data corruption and race conditions

Solution:
- Implement file-based locking using gofrs/flock
- Add integration tests to verify locking behavior

Impact:
- Guarantees execution of a single sync process at a time
- Eliminates potential for data inconsistency during sync

* docs: document sync architecture and merge model

- Detail the 3-way merge model logic
- Describe the core synchronization architecture principles

* fix(lint): explicitly ignore lock.Unlock return value

errcheck linter flagged bare defer lock.Unlock() calls. Wrap in
anonymous function with explicit _ assignment to acknowledge
intentional ignore of unlock errors during cleanup.

* fix(lint): add sync_merge.go to G304 exclusions

The loadBaseState and saveBaseState functions use file paths derived
from trusted internal sources (beadsDir parameter from config). Add
to existing G304 exclusion list for safe JSONL file operations.

* feat(sync): integrate sync-branch into pull-first flow

When sync.branch is configured, doPullFirstSync now:
- Calls PullFromSyncBranch before merge
- Calls CommitToSyncBranch after export

This ensures sync-branch mode uses the correct branch for
pull/push operations.

* test(sync): add E2E tests for sync-branch and external BEADS_DIR

Adds comprehensive end-to-end tests:
- TestSyncBranchE2E: verifies pull→merge→commit flow with remote changes
- TestExternalBeadsDirE2E: verifies sync with separate beads repository
- TestExternalBeadsDirDetection: edge cases for repo detection
- TestCommitToExternalBeadsRepo: commit handling

* refactor(sync): remove unused rollbackJSONLFromGit

Function was defined but never called. Pull-first flow saves base
state after successful push, making this safety net unnecessary.

* test(sync): add export-only mode E2E test

Add TestExportOnlySync to cover --no-pull flag which was the only
untested sync mode. This completes full mode coverage:

- Normal (pull-first): sync_test.go, sync_merge_test.go
- Sync-branch: sync_modes_test.go:TestSyncBranchE2E (PR#918)
- External BEADS_DIR: sync_external_test.go (PR#918)
- From-main: sync_branch_priority_test.go
- Local-only: sync_local_only_test.go
- Export-only: sync_modes_test.go:TestExportOnlySync (this commit)

Refs: #911

* docs(sync): add sync modes reference section

Document all 6 sync modes with triggers, flows, and use cases.
Include mode selection decision tree and test coverage matrix.

Co-authored-by: Claude <noreply@anthropic.com>

* test(sync): upgrade sync-branch E2E tests to bare repo

- Replace mocked repository with real bare repo setup
- Implement multi-machine simulation in sync tests
- Refactor test logic to handle distributed states

Coverage: sync-branch end-to-end scenarios

* test(sync): add daemon sync-branch E2E tests

- Implement E2E tests for daemon sync-branch flow
- Add test cases for force-overwrite scenarios

Coverage: daemon sync-branch workflow in cmd/bd

* docs(sync): document sync-branch paths and E2E architecture

- Describe sync-branch CLI and Daemon execution flow
- Document the end-to-end test architecture

* build(nix): update vendorHash for gofrs/flock dependency

New dependency added for file-based sync locking changes the
Go module checksum.

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-01-07 21:27:20 -08:00
mayor
50a0142a1d bd daemon sync: 2026-01-07 20:59:09 2026-01-07 20:59:09 -08:00
mayor
55fd5ba2db bd daemon sync: 2026-01-07 20:56:53 2026-01-07 20:56:53 -08:00
mayor
a97bb3303d bd daemon sync: 2026-01-07 20:46:57 2026-01-07 20:46:57 -08:00
Andrey Taranov
e0b613d5b1 fix(sync): validate custom types in batch issue creation (#943)
Fix validation in batch issue creation to check custom types

Previously only validated custom statuses, causing sync to fail when JSONL
contained issues with types removed from core (agent, role, rig, convoy, slot).

Fixes: validation failed for issue: invalid issue type: agent
2026-01-07 20:45:58 -08:00
kustrun
7aa3e79649 fix(prime): use flush-only workflow when no git remote configured (#940)
Use flush-only workflow when no git remote is configured

Detects local-only repos (no git remote) and provides appropriate instructions:
- bd sync --flush-only instead of full git workflow
- Clear note about local-only storage
- Prevents confusing git errors for non-git users
2026-01-07 20:45:40 -08:00
Peter Chanthamynavong
bec44d85a1 fix(install): stop existing daemons before binary replacement (#945)
Stop existing daemons before binary replacement during install

Prevents file lock race condition by gracefully stopping bd daemons
before replacing the binary. Safe for fresh installs (skips if bd not found).
2026-01-07 20:45:37 -08:00
Andrey Taranov
88f106fe17 fix(hooks): add --no-daemon to git hook sync commands (bd-tyyn) (#948)
Fix git hooks failing when daemon is running

Git hooks were calling bd sync without --no-daemon, causing inline import to fail
with 'no database store available' because daemon mode only initializes daemonClient.

Fix: Add --no-daemon to all bd sync calls in git hooks to ensure direct mode.
2026-01-07 20:45:33 -08:00
Paddo
5254ade346 feat(linear): add project_id filter for sync (#938)
Add project_id filter for Linear sync

When linear.project_id is configured, bd linear sync will only fetch issues
belonging to that project instead of all team issues.

Closes #937
2026-01-07 20:45:00 -08:00
Jeremy Saenz
3c9ceaa74d docs: add lazybeads to community tools (#951)
Add lazybeads (Bubble Tea TUI by @codegangsta) to community tools
2026-01-07 20:44:34 -08:00
Patt O'Brien
78d51ea346 Fix bd quickstart link to database extension documentation (#939)
Fix broken link to database extension documentation

- Path changed from EXTENDING.md to docs/EXTENDING.md
2026-01-07 20:44:16 -08:00
mayor
4ee0015955 bd daemon sync: 2026-01-07 20:41:34 2026-01-07 20:41:34 -08:00
mayor
b796cb9a05 bd daemon sync: 2026-01-07 19:20:08 2026-01-07 19:20:08 -08:00
mayor
91345e8363 bd daemon sync: 2026-01-07 19:20:05 2026-01-07 19:20:05 -08:00
mayor
2eef55eaed bd daemon sync: 2026-01-07 19:20:03 2026-01-07 19:20:04 -08:00
mayor
10ca941047 bd daemon sync: 2026-01-07 19:01:32 2026-01-07 19:01:32 -08:00
mayor
c4d0e17bbc bd daemon sync: 2026-01-07 17:42:17 2026-01-07 17:42:17 -08:00
mayor
7b0788c062 bd daemon sync: 2026-01-07 17:42:09 2026-01-07 17:42:09 -08:00
mayor
9abc13b9cb bd daemon sync: 2026-01-07 17:42:03 2026-01-07 17:42:03 -08:00
mayor
b4627e651f bd daemon sync: 2026-01-07 17:42:01 2026-01-07 17:42:01 -08:00
mayor
00f8ebd90a bd daemon sync: 2026-01-07 17:40:21 2026-01-07 17:40:21 -08:00
Andrey Taranov
1a64654c48 fix(sync): force-add .beads in worktree for contributor mode (#947)
In contributor mode (bd init --contributor), .beads/ is excluded in
.git/info/exclude to prevent committing upstream issue databases.
However, this exclusion applies to ALL worktrees, including the sync
worktree where .beads/ must be committed.

The fix adds -f flag to git add in commitInWorktree() to force-add
files even when gitignored. This follows the existing pattern in
beads where -f is used for worktree operations (git worktree add -f).

Fixes: bd sync failing with "git add failed in worktree: exit status 1"

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-07 17:40:09 -08:00
mayor
00cb8104d2 bd daemon sync: 2026-01-07 17:39:22 2026-01-07 17:39:22 -08:00
mayor
7e9e43a6d4 bd daemon sync: 2026-01-07 17:36:53 2026-01-07 17:36:53 -08:00
mayor
64ee653336 bd daemon sync: 2026-01-07 17:34:15 2026-01-07 17:34:15 -08:00
dave
fde464172d bd daemon sync: 2026-01-07 17:31:49 2026-01-07 17:31:49 -08:00
dave
9bfb6e8e71 bd daemon sync: 2026-01-07 17:31:29 2026-01-07 17:31:29 -08:00
dave
15eea05edb bd daemon sync: 2026-01-07 17:31:24 2026-01-07 17:31:24 -08:00
beads/crew/emma
7dd227aa2a bd daemon sync: 2026-01-07 01:18:49 2026-01-07 01:18:49 -08:00
beads/crew/emma
c08dddce0e bd daemon sync: 2026-01-07 01:18:15 2026-01-07 01:18:15 -08:00
beads/crew/emma
d733e88c8f bd daemon sync: 2026-01-07 01:18:14 2026-01-07 01:18:14 -08:00
beads/crew/emma
d8fb73f8f9 bd daemon sync: 2026-01-07 01:18:12 2026-01-07 01:18:12 -08:00
beads/crew/emma
463bfa57f2 bd daemon sync: 2026-01-07 01:18:08 2026-01-07 01:18:08 -08:00
gastown/crew/george
de7ed3c08a bd daemon sync: 2026-01-07 01:08:45 2026-01-07 01:08:45 -08:00
beads/crew/emma
744d2a7d22 feat(create): add --dry-run flag to preview issue creation (bd-0hi7)
Adds --dry-run flag that shows what would be created without actually
creating the issue. Useful for scripting and validation.

- Shows preview in human-readable format by default
- Outputs full issue JSON with --json flag (empty ID, not placeholder string)
- Skips all side effects (hooks, labels, dependencies)
- Works with --rig/--prefix flags (shows target rig)
- Errors gracefully with --file flag (not supported)
- Includes event fields when --type=event
2026-01-07 01:08:28 -08:00
beads/crew/emma
181fd58651 bd daemon sync: 2026-01-07 01:06:02 2026-01-07 01:06:02 -08:00
beads/crew/emma
c58ca6c261 bd daemon sync: 2026-01-07 01:05:25 2026-01-07 01:05:25 -08:00
beads/crew/emma
ecb5a28191 bd daemon sync: 2026-01-07 01:05:06 2026-01-07 01:05:06 -08:00
beads/crew/emma
74fba8cab8 bd daemon sync: 2026-01-07 01:03:23 2026-01-07 01:03:23 -08:00
deacon
352ea6707e bd daemon sync: 2026-01-07 01:01:26 2026-01-07 01:01:26 -08:00
beads/crew/emma
f45a06da91 bd sync: 2026-01-07 00:49:43 2026-01-07 00:49:43 -08:00
beads/crew/emma
81a2af9598 Revert "fix(formula): add dev path to local-install and clarify bump-version.sh (bd-z8xz)"
This reverts commit fd3e78461231301193c08f960b73e8d0ec1d531a.
2026-01-07 00:46:48 -08:00
beads/crew/emma
b391a96465 fix(formula): add dev path to local-install and clarify bump-version.sh (bd-z8xz)
- Add Option 3 to local-install step: build from source with macOS codesigning
- Clarify run-bump-script step: bump-version.sh is the authority for release mechanics
- Document --all flag includes --install --mcp-local --restart-daemons
- Add reference to ./scripts/bump-version.sh --help
2026-01-07 00:46:48 -08:00
beads/crew/emma
9da807863b bd sync: 2026-01-07 00:46:20 2026-01-07 00:46:20 -08:00
beads/crew/emma
a7a1d499d7 bd sync: 2026-01-07 00:39:50 2026-01-07 00:39:50 -08:00
beads/crew/emma
c0891cff3f bd sync: 2026-01-07 00:37:14 2026-01-07 00:37:14 -08:00
beads/crew/emma
ee5bc5931a feat(gate): auto-discover workflow run ID in gate check (bd-fbkd)
When bd gate check encounters a gh:run gate with a non-numeric await_id
(workflow name hint like release.yml), it now auto-discovers the run ID:

- Queries GitHub directly with gh run list --workflow=X
- Takes the most recent run (deterministic: newest-first from API)
- Updates the gates await_id and proceeds with status check

This is ZFC-compliant: most recent run of workflow X is purely mechanical,
no heuristic scoring. Agents no longer need to run bd gate discover manually.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-07 00:36:51 -08:00
emma
e049b30fe0 bd sync: 2026-01-07 00:23:22 2026-01-07 00:23:22 -08:00
emma
f9b7af767b bd sync: 2026-01-07 00:23:18 2026-01-07 00:23:18 -08:00