Commit Graph

768 Commits

Author SHA1 Message Date
Steve Yegge
39909c1f80 feat: implement health checks in daemon event loop (bd-gqo)
Add health checks to checkDaemonHealth() function:
- Database integrity check using PRAGMA quick_check(1)
- Disk space check with 100MB warning threshold (platform-specific)
- Memory usage check with 500MB heap warning threshold

Platform-specific disk space implementations:
- Unix: uses unix.Statfs
- Windows: uses windows.GetDiskFreeSpaceEx
- WASM: returns unsupported (false)

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-28 23:10:44 -08:00
Steve Yegge
9efd31de5f bd-o2e: Add --squash flag to bd sync for batching commits
For solo developers who don't need real-time multi-agent coordination,
--squash accumulates changes in JSONL without committing. Run 'bd sync'
later (without --squash) to commit all accumulated changes in one commit.

This reduces git history noise while preserving the default behavior
needed for multi-agent orchestration.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-28 23:09:20 -08:00
Steve Yegge
40b07045c7 refactor: deduplicate FindJSONLInDir function (bd-8a5)
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>
2025-11-28 23:07:53 -08:00
Steve Yegge
6f9d8d3add bd-c8x: Stop searching parent directories at git root
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>
2025-11-28 22:16:11 -08:00
Steve Yegge
13b2ab6c95 feat(doctor): add fresh clone detection check (bd-4ew)
Add CheckFreshClone function that detects when JSONL contains issues
but no database exists. Recommends 'bd init --prefix <detected-prefix>'
to hydrate the database. This check appears early in doctor output
to guide users on fresh clones.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-28 22:15:34 -08:00
Steve Yegge
3a4840169d fix(init): add safety guard to prevent overwriting existing data
bd init now refuses when:
- JSONL file exists with >0 issues (fresh clone scenario)
- Database file already exists (already initialized)

Suggests `bd doctor --fix` for fresh clones and provides clear guidance.
Added --force flag to bypass the safety guard when needed.

Closes: bd-emg

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-28 22:15:13 -08:00
Steve Yegge
46862568f6 bd-4ew: Doctor detects fresh clone and recommends 'bd init'
When JSONL exists but no database (and not no-db mode), doctor now:
- Shows 'Fresh clone detected' warning
- Shows count of issues in JSONL
- Recommends 'bd init' with detected prefix

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-28 21:59:59 -08:00
Steve Yegge
9d896c3b28 bd-bok: Add --yes/-y flag to bd doctor --fix for non-interactive mode
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-28 21:56:33 -08:00
Steve Yegge
eeab5e55e3 test(doctor): add test for beads.base.jsonl merge artifacts (bd-ov1)
Verify that beads.base.jsonl and beads.left.jsonl patterns are correctly
excluded from the 'multiple JSONL files' warning, same as issues.base.jsonl.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-28 21:52:48 -08:00
Steve Yegge
40b86a15a7 fix(sync): cleanup snapshots after sync regardless of --no-pull (bd-0io)
Moved snapshot cleanup call to the end of successful sync, outside the
!noPull block. This ensures snapshot files (beads.base.jsonl, beads.left.jsonl)
are removed even when --no-pull is used.

Previously, captureLeftSnapshot was called before the pull block, but
cleanup was only inside the pull block, leaving orphaned files when
--no-pull was used.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-28 21:51:08 -08:00
Steve Yegge
a7db382fda Merge conflict resolution: bd-0io cleanup comment wording 2025-11-28 21:50:46 -08:00
Steve Yegge
1cb855712f fix(sync): cleanup snapshot files at end of sync (bd-0io)
Add cleanup call at end of successful sync to ensure snapshot files
(beads.base.jsonl, beads.left.jsonl) are removed even when --no-pull
is used. Previously, captureLeftSnapshot was called before the pull
block, but cleanup was only inside the !noPull block, leaving orphaned
files.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-28 21:49:52 -08:00
Jimmy Stridh
bb16f247c6 fix(init): error on invalid JSON instead of overwriting settings (#404)
Previously, setupClaudeSettings would silently create an empty settings
map when json.Unmarshal failed, then write just a prompt field to the
file - destroying all existing user settings (permissions, hooks, etc).

Now returns a clear error asking the user to fix the JSON syntax
manually, preserving their original file contents.

Also properly handles permission errors when reading existing files.

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

Co-authored-by: Jimmy Stridh <jimmystridh@users.noreply.github.com>
Co-authored-by: Claude <noreply@anthropic.com>
2025-11-28 18:51:27 -08:00
Steve Yegge
95371ea116 Export and display close reasons for issues (beads-410)
- Add CloseReason field to Issue struct in types.go
- Add GetCloseReason() and batch GetCloseReasonsForIssues()
- Update issue loading to populate close reasons
- Update scanIssues() to include close_reason in JSONL export
- Update bd show to display close reason after status

Close reasons now survive sync between repos.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-28 18:39:07 -08:00
Steve Yegge
fe4f851d33 Fix validatePostImport false positive for legitimate deletions (bd-pg1)
The sync validation was incorrectly triggering 'data loss detected' when
issue count decreased after import, even for legitimate deletions recorded
in deletions.jsonl.

Changes:
- Modified validatePostImport to accept jsonlPath and check deletions manifest
- When issue count decreases, check if decrease is within recorded deletions
- Updated all call sites in sync.go and daemon_sync.go
- Added comprehensive tests for deletion-aware validation

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-28 17:43:25 -08:00
Steve Yegge
30197ee1ae bd-upd: Add snapshot cleanup to daemon sync function
After sync completion, orphan .base.jsonl and .left.jsonl files were
remaining in .beads/ directory. These are merge artifacts that should be
cleaned up after successful sync.

The fix adds SnapshotManager.Cleanup() call to createSyncFunc in
daemon_sync.go after successful import, matching the behavior of the CLI
sync command. Supports both single-repo and multi-repo modes.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-28 17:42:47 -08:00
Steve Yegge
86d6ffe57d fix(doctor): exclude merge artifacts from multiple JSONL warning
Add .base.jsonl, .left.jsonl, and .right.jsonl patterns to the skip list
in CheckLegacyJSONLFilename. These are legitimate git merge conflict
artifacts that should not trigger a warning about multiple JSONL files.

Fixes: bd-nsb

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-28 17:42:23 -08:00
Steve Yegge
03fa119e85 Add close reason display for closed issues
- 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>
2025-11-28 17:36:01 -08:00
Steve Yegge
774a57684c Fix auto-import git history backfill bug (bd-4pv)
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>
2025-11-27 22:51:39 -08:00
Steve Yegge
8b8a662acb Fix fresh clone UX with friendly error messages (bd-dmb)
When opening a database that exists but is missing issue_prefix config
(typical in fresh clone scenarios), show a helpful error message instead
of cryptic migration invariant errors.

The new message:
- Explains the database needs initialization
- Detects if a JSONL file exists and shows the issue count
- Suggests the exact command to run: bd import -i <path>
- Falls back to suggesting bd init --prefix if no JSONL exists

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-27 22:40:57 -08:00
Steve Yegge
1675275e1c Implement auto-merge functionality for duplicates command
When --auto-merge is used, performMerge now automatically:
1. Closes source issues with "Duplicate of <target>" reason
2. Links each source to target with a "related" dependency

Closes bd-hdt

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-27 22:39:13 -08:00
Steve Yegge
bc37afbb0e Fix bd sync staging gitignored files (bd-guc)
Changed gitCommitBeadsDir to explicitly stage only sync files
(issues.jsonl, deletions.jsonl, metadata.json) instead of the
entire .beads/ directory.

This prevents staging gitignored snapshot files (beads.*.jsonl,
*.meta.json) that may still be tracked from before they were
added to .gitignore, which could cause merge conflicts when
multiple polecats run bd sync concurrently.
2025-11-27 22:34:46 -08:00
Steve Yegge
2bcfcd1c9b Merge branch 'main' of https://github.com/steveyegge/beads 2025-11-27 13:23:19 -08:00
Steve Yegge
3f609267d4 fix: doctor deletions check and onboard docs improvements
- Fix doctor to treat empty deletions.jsonl as valid (0 entries OK status)
- Fix HydrateDeletionsManifest to create empty file when no deletions found
- Add --parent flag documentation to onboard command
- Add CLI --help tip throughout onboard documentation

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-27 13:23:14 -08:00
Steve Yegge
650dcd42f6 fix(tests): resolve short test performance regression (bd-0v4)
Short tests were timing out after 13+ minutes due to:

1. TestZFCSkipsExportAfterImport spawning subprocess that tried to
   auto-start daemon - now skipped in short mode

2. TestVersionFlag taking 5+ seconds because --version flag did not
   skip PersistentPreRun daemon startup - added early return

3. TestGetVersionsSince* had hardcoded version expectations that
   became stale - made tests dynamic using versionChanges array

Short tests now complete in ~8 seconds instead of timing out.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-27 01:36:57 -08:00
Steve Yegge
45c048ab96 chore: Bump version to 0.26.0
Release highlights:
- bd doctor --check-health for lightweight startup hook health checks
- --no-git-history flag to prevent spurious deletions
- gh2jsonl --id-mode hash for content-based ID generation
- Critical MCP protocol stdin fix (PR #400)
- Git worktree staleness fix (#399)
- Multi-part prefix support (#398)
- bd sync commit scope fix

Updated all component versions:
- bd CLI: 0.25.1 -> 0.26.0
- Plugin: 0.25.1 -> 0.26.0
- MCP server: 0.25.1 -> 0.26.0
- npm package: 0.25.1 -> 0.26.0

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-27 01:06:45 -08:00
Steve Yegge
99fff192eb fix(hooks): prevent rebase failures from deletions.jsonl writes
Two fixes to prevent git pull --rebase from failing:

1. Skip hook execution during rebase operations by detecting
   .git/rebase-merge or .git/rebase-apply directories

2. Use --no-git-history flag to prevent git-history-backfill
   from writing to deletions.jsonl during imports

The root cause was that post-checkout hooks were running during
rebase, triggering the git-history-backfill which appends to
deletions.jsonl. This created uncommitted changes that blocked
the rebase from continuing.

Bump hooks version to 0.26.0 (requires bd version bump to take effect).

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-27 00:55:30 -08:00
Steve Yegge
1c2aa6159b fix: Add defense-in-depth check for --no-auto-import flag (bd-4t7)
- autoImportIfNewer() now directly checks noAutoImport flag
- Ensures auto-import is blocked even if caller forgets to check autoImportEnabled
- Added TestAutoImportIfNewer_NoAutoImportFlag test to verify the fix

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-27 00:54:29 -08:00
Steve Yegge
cdc156428c fix(staleness): use RFC3339Nano precision for last_import_time (#399)
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>
2025-11-27 00:11:01 -08:00
Steve Yegge
5506486dc5 feat(import,sync): add --no-git-history flag to prevent spurious deletions
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>
2025-11-26 23:10:43 -08:00
Steve Yegge
6294ef0cc6 fix(init,import): preserve metadata.json and improve prefix detection
- bd init now preserves existing metadata.json settings instead of
  overwriting with defaults (bd-zai)
- bd init detects existing JSONL filename (beads.jsonl vs issues.jsonl)
  when creating new metadata.json
- bd import now correctly reports prefix source ("issues" vs "directory")
- bd import avoids using ".beads" as prefix when run from inside .beads/

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-26 22:57:17 -08:00
Steve Yegge
ff3352ab23 bd-6xd: Standardize on issues.jsonl as canonical filename
- 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>
2025-11-26 22:02:59 -08:00
matt wilkie
69d442be3a WIP: changes before push 2025-11-26 22:02:29 -08:00
Steve Yegge
fe6de0a73f fix: CI test failures on Windows
- 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>
2025-11-26 20:59:07 -08:00
Steve Yegge
ab330ea39d fix: bd sync now only commits .beads/ files, not other staged files (bd-red)
Previously, bd sync would commit ALL staged files when committing beads
changes. This could lead to unintended commits of work-in-progress code
that users had staged but weren't ready to commit.

Changed gitCommitBeadsDir to use pathspec (-- .beads/) to explicitly
limit the commit to only .beads/ files.

Also added in previous commit (bd-pbj):
- New Untracked Files check in bd doctor for untracked .beads/*.jsonl
- bd doctor --fix can now stage and commit untracked JSONL files

Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-26 20:46:47 -08:00
Steve Yegge
8ad0144142 bd sync: 2025-11-26 20:33:12 2025-11-26 20:33:12 -08:00
Steve Yegge
6a024fb4d9 fix: git hooks now stage deletions.jsonl for cross-clone propagation
The pre-commit and pre-push hooks were only staging beads.jsonl and
issues.jsonl, but not deletions.jsonl. This caused deletions.jsonl
to remain untracked after bd cleanup or bd delete operations.

Updated all hook locations:
- cmd/bd/templates/hooks/pre-commit
- cmd/bd/templates/hooks/pre-push
- examples/git-hooks/pre-commit
- examples/git-hooks/pre-push
- .beads-hooks/pre-commit
- .beads-hooks/pre-push

Users with existing hooks should run: bd hooks install

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-26 20:29:47 -08:00
Steve Yegge
340b3507b9 fix: expand tilde in global gitignore path from git config
git config --global core.excludesfile may return paths like ~/...
which Go does not expand. This caused setupGlobalGitIgnore to fail
when users had configured their gitignore with a tilde path.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-26 19:06:50 -08:00
Steve Yegge
d0bb0ad7d4 fix: staleness check fails after write in git worktrees (#399)
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>
2025-11-26 19:04:57 -08:00
matt wilkie
2d77e564a8 WIP: changes before push 2025-11-26 17:52:08 -08:00
Steve Yegge
c3b4243450 fix: bd doctor no longer warns about deletions.jsonl
The multiple JSONL files check was incorrectly flagging deletions.jsonl
as a problem, even though it is a valid system file for tracking deleted
issues. Added deletions.jsonl to the skip list alongside backups and
merge artifacts.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-26 17:48:16 -08:00
Kris Hansen
9931ac9bd9 fix: support multi-part prefixes in issue ID extraction (#398) 2025-11-26 17:42:14 -08:00
Steve Yegge
ce42ed43ff Merge remote-tracking branch 'origin/main' into improve-sync-jsonl-msg 2025-11-26 14:42:30 -08:00
Dane Bertram
81d23790dc refactor: remove global gitattributes setup from init --stealth mode (#391)
Removes global gitattributes setup from stealth mode, keeping only the global gitignore configuration. CI failures are pre-existing (TestZFCSkipsExportAfterImport timeout).
2025-11-26 14:31:23 -08:00
matt wilkie
eb69da3184 improve pre-push hook error message to clarify all uncommitted changes 2025-11-26 09:09:37 -07:00
Steve Yegge
3458956ecf refactor: consolidate check-health DB access and expand hook checks
- bd-b8h: Extract getCheckHealthDBPath() to DRY up path resolution
- bd-xyc: Open DB once in runCheckHealth, pass connection to check functions
- bd-2em: checkHooksQuick now verifies all 4 hooks (pre-commit, post-merge,
  pre-push, post-checkout) instead of just post-merge

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-25 19:50:46 -08:00
Steve Yegge
cd1cbbbfdd bd sync: 2025-11-25 19:32:04 2025-11-25 19:32:05 -08:00
Steve Yegge
3fe94f280f feat: add bd doctor --check-health for lightweight git hook health checks
- Add --check-health flag for quick, silent health checks (exit 0 on success)
- Check version mismatch (CLI vs database), sync.branch config, outdated hooks
- Add hints.doctor config option to suppress doctor hints globally
- Update post-merge/post-checkout hooks to call bd doctor --check-health
- Suggest running bd doctor in upgrade notification
- Modernize post-checkout hook (bash→sh, use bd sync instead of bd import)

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-25 19:28:13 -08:00
Steve Yegge
ddced40153 fix: add nosec annotations for gosec lint warnings 2025-11-25 18:22:05 -08:00
Steve Yegge
9fc0285987 chore: Bump version to 0.25.1 2025-11-25 18:16:49 -08:00