When a clone gets reset (git reset --hard origin/main), the
git-history-backfill logic was incorrectly marking ALL issues as
deleted since they appeared in git history but not in the current
JSONL. This caused the entire database to be purged.
Fix:
- Add 50% threshold check: abort if git-history-backfill would delete
more than 50% of issues (likely a reset scenario, not deletions)
- Add warning when >10 issues would be deleted via backfill
- Print helpful message about manual deletion if needed
Test:
- Added TestMassDeletionSafetyGuard that simulates JSONL reset and
verifies the safety guard prevents mass deletion
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
When importing JSONL that contains issues in the deletions manifest,
import now:
- Filters out deleted issues before import
- Prints per-issue warning with deletion details (date, actor)
- Shows count of skipped issues in summary
- Suggests --ignore-deletions flag to force import
The new --ignore-deletions flag allows importing issues that are in the
deletions manifest, useful for recovering accidentally deleted issues.
Fixes bd-4zy
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
- Lower minimum hash length from 4 to 3 characters
- Update hash validation to support base36 (0-9, a-z) instead of just hex
- Require at least one digit to distinguish hashes from English words
- Fixes prefix extraction for hyphenated prefixes with 3-char hashes
e.g., 'document-intelligence-0sa' now correctly extracts 'document-intelligence'
- Add test cases for 3-char hashes with multi-part prefixes
- Resolves bd sync failures with 'prefix mismatch detected' errors
Adds a lightweight redirect mechanism that allows a stub .beads directory
to point to the actual beads location. This solves the workspace problem
where an AI agent runs in one directory but needs to operate on beads
stored elsewhere.
The redirect file is a simple text file containing a path (relative or
absolute) to the target .beads directory. Comments (lines starting with #)
are supported. Redirect chains are prevented - only one level is followed.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
SQLite WAL mode writes go to the -wal file, not the main database.
Without an explicit checkpoint before Close(), writes can be stranded
and lost between CLI invocations.
This was causing `bd migrate` to report success but not actually
persist the version update to the database.
Fixes#434🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
Extends the fix from PR #424 to also validate the BEADS_DIR environment
variable. Previously, only the directory tree search was validated, but
BEADS_DIR could still point to a daemon-only directory.
Changes:
- Add validation to BEADS_DIR path using hasBeadsProjectFiles()
- Add comprehensive test for BEADS_DIR validation
- Test verifies both rejection of daemon-only dirs and acceptance of valid dirs
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
FindBeadsDir() now checks for actual beads project files before returning
a .beads directory. This prevents false positives when ~/.beads/ exists
only for daemon registry (registry.json).
Changes:
- Add hasBeadsProjectFiles() helper that checks for:
- metadata.json or config.yaml (project config)
- *.db files (excluding backups and vc.db)
- *.jsonl files (JSONL-only mode)
- Update FindBeadsDir() to validate directories during tree search
- Add comprehensive tests for project file detection
- Update version_tracking_test.go to create project files
Fixes#420🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: Claude <noreply@anthropic.com>
Previously sync.branch was stored in the database via bd config set.
Now it is in config.yaml (version controlled, shared across clones):
sync-branch: "beads-sync"
Changes:
- Add sync-branch to .beads/config.yaml
- Update syncbranch.Get() to check config.yaml before database
- Add syncbranch.GetFromYAML() and IsConfigured() for fast checks
- Update hooks to read sync-branch from config.yaml directly
- Update bd doctor to check config.yaml instead of database
- Remove auto-fix (config.yaml changes should be committed)
Precedence: BEADS_SYNC_BRANCH env > config.yaml > database (legacy)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
sync.branch config was lost on clone because it was only stored in
the database (which is gitignored). Now syncbranch.Get() checks:
1. BEADS_SYNC_BRANCH env var (highest)
2. config.yaml sync-branch (tracked, persists across clones)
3. Database config (local override)
4. Empty (use current branch)
Changes:
- Update syncbranch.Get() to check config.yaml
- Update config.yaml template with sync-branch option
- Set sync-branch: beads-sync in this repo config.yaml
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
When sync.branch is configured, bd sync now commits beads changes
to that branch via git worktree, keeping the user's current branch
(e.g., main) clean of beads sync commits.
Changes:
- Add internal/syncbranch/worktree.go with CommitToSyncBranch and
PullFromSyncBranch functions for worktree-based operations
- Modify sync.go to check sync.branch config and use worktree
functions when configured
- Skip pre-commit hooks in worktree commits (--no-verify) since
bd's pre-commit hook would fail in worktree context
- Re-export after import also uses worktree when sync.branch set
This enables the orchestrator workflow where multiple workers stay
on main but all beads commits flow to a dedicated beads-sync branch.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Add -u/--unassigned flag to bd ready command to show only issues
with no assignee. This supports the SCAVENGE protocol where polecats
query the 'Salvage Yard' for unassigned ready work.
Changes:
- Add NoAssignee field to WorkFilter struct
- Update SQLite GetReadyWork to filter by empty/null assignee
- Add --unassigned/-u flag to ready command
- Update RPC protocol and daemon handler
- Add test for NoAssignee filter functionality
Fixes: gt-3rp
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Adds the ability to filter ready work for issues with no assignee,
which is useful for the SCAVENGE protocol in Gas Town where polecats
need to query the "Salvage Yard" for unclaimed work.
Changes:
- Add Unassigned bool field to types.WorkFilter
- Add --unassigned/-u flag to bd ready command
- Update SQL query in GetReadyWork to filter for NULL/empty assignee
- Add Unassigned field to RPC ReadyArgs for daemon support
- Add tests for the new functionality
Closes: gt-3rp
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* bd sync: 2025-11-29 00:08:58
* fix(multirepo): handle out-of-order dependencies during JSONL import
Fixes#413. When importing issues from multi-repo JSONL files, if issue A
(line 1) has a dependency on issue B (line 5), the import would fail with
FK constraint error because B doesn't exist yet.
Solution:
- Disable FK checks at start of importJSONLFile()
- Re-enable FK checks before commit
- Run PRAGMA foreign_key_check to validate data integrity
- Fail with clear error if orphaned dependencies are detected
This allows out-of-order dependencies while still catching corrupted data.
---------
Co-authored-by: Shaun Cutts <shauncutts@factfiber.com>
Fixed bug where issue IDs with multiple hyphens in the prefix and hash
suffixes were incorrectly parsed. For example, `web-app-a3f8e9` was
being parsed with prefix `web-` instead of `web-app`.
Root cause: ExtractIssuePrefix() only checked for numeric suffixes.
When it encountered a hash suffix, it fell back to using the first
hyphen instead of the last hyphen.
Changes:
- Added isLikelyHash() helper to detect hexadecimal hash suffixes (4-8 chars)
- Updated ExtractIssuePrefix() to handle both numeric and hash suffixes
- Added comprehensive test cases for various prefix patterns
Test coverage includes:
- web-app-123 (numeric suffix)
- web-app-a3f8e9 (hash suffix)
- my-cool-app-a3f8e9 (three-part prefix with hash)
- super-long-project-name-1a2b (four-part prefix)
- Various hash lengths and case variations
Co-authored-by: dubstylee <dubstylee@users.noreply.github.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Users can now define custom status states for multi-step pipelines using:
bd config set status.custom "awaiting_review,awaiting_testing,awaiting_docs"
Changes:
- Add Status.IsValidWithCustom() method for custom status validation
- Add Issue.ValidateWithCustomStatuses() method
- Add GetCustomStatuses() method to storage interface
- Update CreateIssue/UpdateIssue to support custom statuses
- Add comprehensive tests for custom status functionality
- Update config command help text with custom status documentation
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
The metadata key 'last_import_hash' was misleading because it's updated on
both import AND export. Renamed to 'jsonl_content_hash' which more accurately
describes its purpose - tracking the content hash of the JSONL file.
Added migration support: read operations try new key first, then fall back
to old key for backwards compatibility with existing databases.
Files modified:
- cmd/bd/integrity.go: Update key name with migration support
- cmd/bd/import.go: Update key name
- cmd/bd/sync.go: Update key name
- cmd/bd/autoflush.go: Update key name with migration support
- cmd/bd/daemon_sync.go: Update key name
- cmd/bd/daemon_event_loop.go: Update key name with migration support
- internal/autoimport/autoimport.go: Update key name with migration support
- Updated all related tests
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Extract shared JSONL file discovery logic to internal/utils/path.go.
Both autoimport and beads packages now use this shared implementation.
Changes:
- Add utils.FindJSONLInDir with common logic
- Update autoimport.go to use utils.FindJSONLInDir
- Update beads.go to delegate to utils.FindJSONLInDir
- Update server_export_import_auto.go to use utils.FindJSONLInDir
- Move FindJSONLInDir test to utils/path_test.go
- Fix pre-existing duplicate countIssuesInJSONLFile in init.go
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Directory discovery (FindBeadsDir, findDatabaseInTree, FindAllDatabases)
now stops at the git repository root to avoid finding unrelated databases
in parent directories (e.g., ~/.beads).
Added findGitRoot() helper that uses 'git rev-parse --show-toplevel'.
Also updated TestCheckDatabaseVersionJSONLMode to properly simulate
no-db mode by creating config.yaml with 'no-db: true'.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
- config: Add tests for GetStringSlice, GetMultiRepoConfig, and nil viper
behavior. Coverage improved from 65.3% to 84.0%.
- git: Add tests for error paths in RemoveBeadsWorktree, SyncJSONLToWorktree,
CheckWorktreeHealth, and sparse checkout functions. Coverage improved
from 72.9% to 82.7%.
Closes: bd-t3b, bd-4h3, bd-ge7
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
- Add CloseReason field to Issue struct
- Add GetCloseReason and GetCloseReasonsForIssues queries
- Batch-load close reasons in scanIssues for efficiency
- Display close reason in bd show output
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Auto-import was allowing git history backfill to run, which could
incorrectly purge issues. The fix adds NoGitHistory=true to all
auto-import code paths:
- autoimport.go (importFromGit)
- autoflush.go (autoImportIfNewer)
- daemon_sync.go (importToJSONLWithStore)
Git history backfill is designed to detect deletions that happened
after a local DB was created. During auto-import, there is no local
work to protect - we are importing from the authoritative JSONL source.
Also adds comprehensive tests for NoGitHistory behavior.
Generated with Claude Code
Co-Authored-By: Claude <noreply@anthropic.com>
When auto-importing issues from JSONL, issues with different prefixes
(e.g., gt-1 vs gastown-) would fail validation and cause an infinite
loop of failed migrations.
The fix adds SkipPrefixValidation option to CreateIssuesWithFullOptions
which propagates through EnsureIDs to skip prefix validation for issues
that already have IDs during import. This allows importing issues with
any prefix while still validating new issues created interactively.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
The global daemon registry (~/.beads/registry.json) could be corrupted
when multiple daemons from different workspaces wrote simultaneously.
Changes:
- Add file locking (flock) for cross-process synchronization
- Use atomic writes (temp file + rename) to prevent partial writes
- Keep entire read-modify-write cycle under single lock
- Add FlockExclusiveBlocking and FlockUnlock to lockfile package
This prevents race conditions that caused JSON corruption like `]]`.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
The staleness check compares last_import_time against JSONL file mtime.
File mtime has nanosecond precision, but last_import_time was stored with
only second precision (RFC3339). This caused a race condition where the
stored time could be slightly earlier than the file mtime, triggering
false "Database out of sync" errors - particularly in git worktrees.
Changed all 6 locations that set last_import_time to use RFC3339Nano.
The CheckStaleness parser already handles both formats, so this is
backward compatible.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Code review follow-up:
- Fix misleading docstring in FindJSONLInDir (does not return empty)
- Fix same bug in beads.FindJSONLPath (also fell back to matches[0])
- Add comprehensive tests for FindJSONLPath skipping deletions
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Add FindJSONLInDir helper that correctly prefers issues.jsonl over other
.jsonl files. Previously, glob patterns could return deletions.jsonl or
merge artifacts (beads.base.jsonl, etc.) first alphabetically, causing
issue data to be written to the wrong file.
This fixes the root cause of deletions.jsonl corruption where full issue
objects were written instead of deletion records, leading to all issues
being purged during sync.
Changes:
- Add FindJSONLInDir() in internal/autoimport with proper file selection
- Update AutoImportIfNewer() to use FindJSONLInDir
- Update CheckStaleness() to use FindJSONLInDir
- Update triggerExport() in RPC server to use FindJSONLInDir
- Add comprehensive tests for FindJSONLInDir
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Fixes bd-0b2: The git history backfill mechanism was causing data loss
during JSONL filename migrations (beads.jsonl → issues.jsonl). When issues
existed in the old filename's git history, the backfill incorrectly treated
them as "deleted" and purged them from the database.
Changes:
- Add NoGitHistory field to importer.Options and ImportOptions structs
- Modify purgeDeletedIssues() to skip git history check when flag is set
- Add --no-git-history flag to bd import command
- Add --no-git-history flag to bd sync command
- Update purge_test.go to pass Options argument
Usage:
bd import -i .beads/issues.jsonl --no-git-history
bd sync --no-git-history
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
- Change default JSONL filename from beads.jsonl to issues.jsonl
- Add bd doctor check and fix to auto-migrate legacy beads.jsonl configs
- Update FindJSONLPath to prefer issues.jsonl over beads.jsonl
- Add CheckLegacyJSONLConfig and CheckLegacyJSONLFilename checks
- Add LegacyJSONLConfig fix to rename files and update config
- Update .gitattributes to reference issues.jsonl
- Fix tests to expect new canonical filename
- Add bd-6xd to v0.25.1 release notes
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
- TestVersionChangesCoverage: Add missing 3rd changelog entry for v0.25.1
- TestDefaultPath: Use filepath.Join for cross-platform path handling
- TestDebouncer_CancelWithNoPendingAction: Increase sleep from 60ms to 100ms
to account for Windows timer imprecision
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
After write operations in git worktrees, subsequent reads failed with
"Database out of sync with JSONL" even though the hash check passed.
Root cause: flushToJSONLWithState() updated last_import_hash but not
last_import_time after export. CheckStaleness() compares last_import_time
against JSONL mtime, so after export the JSONL appeared "newer" than the
last import.
Additional issue: RFC3339 only has second precision but file mtimes have
nanosecond precision, causing false positives when times were within the
same second.
Fix:
- Update last_import_time after export in flushToJSONLWithState()
- Use RFC3339Nano format for nanosecond precision
- Update CheckStaleness() to parse both formats for backward compatibility
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
- Use utils.CanonicalizePath for BEADS_DB and findDatabaseInTree results
instead of inline filepath.Abs + filepath.EvalSymlinks (bd-736d)
- Extract findDatabaseInBeadsDir helper function that consolidates the
database search logic used by both FindDatabasePath and findDatabaseInTree,
with optional warnings for ambiguous/legacy states (bd-c362)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Completes the deletion propagation epic (bd-imj) with all 9 subtasks:
- Cross-clone deletion propagation via deletions.jsonl
- bd deleted command for audit trail
- Auto-compact during sync (opt-in)
- Git history fallback with timeout and regex escaping
- JSON output for pruning results
- Integration tests for deletion scenarios
- Documentation in AGENTS.md, README.md, and docs/DELETIONS.md
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
- Add Count function to deletions package for fast line counting
- Add maybeAutoCompactDeletions to sync (opt-in via deletions.auto_compact config)
- Fix regex escaping in batchCheckGitHistory (bd-bgs)
- Add 30s timeout to git history commands (bd-f0n)
- Use git rev-parse --show-toplevel for proper repo root detection (bd-bhd)
- Add tests for Count and auto-compact functionality
Closes: bd-qsm, bd-bgs, bd-f0n, bd-bhd
Implements two P1 tasks for the deletions manifest epic:
bd-v2x: Add deletions pruning to bd compact
- PruneDeletions function removes records older than retention period
- Default retention: 7 days (configurable via metadata.json)
- CLI --retention flag for override
- Atomic file rewrite prevents corruption
- Called automatically during all compact operations
bd-pnm: Add git history fallback for pruned deletions
- Catches deletions where manifest entry was pruned
- Uses git log -S to search for ID in JSONL history
- Batches multiple IDs for efficiency (git -G regex)
- Self-healing: backfills manifest on hit
- Conservative: keeps issue if git check fails (shallow clone)
Tests added for both features with edge cases covered.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
- Return LoadResult struct instead of multiple values, with Warnings slice
for testability (no more hardcoded stderr output)
- Add ID validation in AppendDeletion to prevent invalid records
- Add Sync() call in AppendDeletion for durability
- Document that timestamps may lose sub-second precision
- Document that empty slice in WriteDeletions clears all deletions
- Add test for empty ID validation
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
When JSONL mtime changes without content change (e.g., git pull, touch),
the staleness check would repeatedly trigger but auto-import would skip
due to hash match, creating an infinite loop of "Database out of sync"
errors.
Now we update last_import_time even when skipping import due to hash
match, breaking the staleness loop.
Fixes#378🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
ContentHash and SourceRepo were being exported to beads.jsonl even though
they are internal database fields. This caused JSONL pollution where every
issue got these extra fields, and re-exports would produce different output
than the original clean JSONL.
Changed JSON tags from `json:"...,omitempty"` to `json:"-"` for:
- ContentHash: Internal optimization field for content-based diffing
- SourceRepo: Internal metadata for multi-repo support
This fixes the ZFC resurrection bug where re-exports after import would
pollute the JSONL with internal fields.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Add Transaction type alias to both internal/beads and public beads packages.
This allows extensions like VC to use RunInTransaction() with the proper
Transaction interface type for atomic issue creation.
bd-m73k
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
- Add safe type assertions in applyUpdatesToIssue (bd-4gs)
- Add --sort and --reverse flags to bd search (bd-4f6)
- Add test cases for SearchIssues priority range, date range, IDs (bd-ew5)
- Handle errors from GetLabelsForIssues in search.go (bd-lce)
- Standardize error wrapping to fmt.Errorf pattern (bd-7kl)
- Extract shared scanIssueRow helper function (bd-ajf)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>