Fix bd-73: Add git worktree detection and warnings

- Implement robust worktree detection using git-dir vs git-common-dir comparison
- Add prominent warning when daemon mode is active in a worktree
- Warn in 3 places: initial connection, auto-start, and daemon start command
- Show shared database path and clarify BEADS_AUTO_START_DAEMON behavior
- Document limitations and solutions in README.md and AGENTS.md
- Add comprehensive tests for detection and path truncation

Fixes #55

Amp-Thread-ID: https://ampcode.com/threads/T-254eb9e3-1a42-42d7-afdf-b7ca2d2dcb8b
Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
Steve Yegge
2025-10-22 23:05:00 -07:00
parent 3fae41cb35
commit 5a6177b4bc
7 changed files with 302 additions and 0 deletions

View File

@@ -646,10 +646,44 @@ bd --db ~/otherproject/.beads/other.db list
- `BEADS_DB` - Override database path
- `BEADS_AUTO_START_DAEMON` - Enable/disable automatic daemon start (default: `true`). Set to `false` or `0` to disable.
- `BEADS_NO_DAEMON` - Disable daemon mode entirely (same as `--no-daemon` flag). Set to `1` or `true` to disable.
- `BD_ACTOR` - Set actor name for change tracking (defaults to `$USER`)
- `BD_DEBUG` - Enable debug logging (connection attempts, auto-start timing, health checks)
- `BD_VERBOSE` - Show warnings when falling back from daemon to direct mode
### Git Worktrees
**⚠️ Important:** Git worktrees share the same `.beads` directory, which creates issues with daemon mode.
**The Problem:**
When using `git worktree`, multiple working directories share a single `.git` directory and thus share the same `.beads` database. The daemon doesn't know which branch each worktree has checked out, which can cause it to commit/push to the wrong branch.
**What you lose without daemon mode:**
- **Auto-sync** - No automatic commit/push of changes (use `bd sync` manually)
- **MCP server** - The beads-mcp server requires daemon mode for multi-repo support
- **Background watching** - No automatic detection of remote changes
**Solutions:**
1. **Use `--no-daemon` flag** (recommended):
```bash
bd --no-daemon ready
bd --no-daemon create "Fix bug" -p 1
```
2. **Disable daemon via environment variable**:
```bash
export BEADS_NO_DAEMON=1
bd ready # Will use direct mode
```
3. **Disable auto-start** (for this worktree only):
```bash
export BEADS_AUTO_START_DAEMON=false
```
bd will automatically detect when you're in a worktree and show a warning if daemon mode is active. The `--no-daemon` mode works correctly with worktrees since it operates directly on the database without shared state.
### Version Compatibility
The daemon and CLI check version compatibility automatically: