beads/cmd/bd
Steve Yegge 58fe00057c feat: Complete GH #353 follow-up phases (bd-9nw, bd-u3t, bd-e0o)
Implements all three follow-up phases for sandbox environment support:

**Phase 1 (bd-9nw): Documentation** ✅
- Comprehensive sandbox troubleshooting section in TROUBLESHOOTING.md
  - Detailed symptoms, root causes, and escape hatches
  - Step-by-step troubleshooting workflow
  - Comparison table for --sandbox, --force, and --allow-stale flags
- Global flags section added to CLI_REFERENCE.md
  - Documents --sandbox, --allow-stale, and --force flags
  - Usage examples and when to use each flag
- GitHub issue #353 comment with immediate workarounds

**Phase 2 (bd-u3t): Sandbox Auto-Detection** ✅
- Automatic sandbox detection using syscall.Kill permission checks
  - cmd/bd/sandbox_unix.go: Unix/Linux/macOS implementation
  - cmd/bd/sandbox_windows.go: Windows stub (conservative approach)
  - cmd/bd/sandbox_test.go: Comprehensive test coverage
- Auto-enables sandbox mode when detected
  - Shows: "ℹ️  Sandbox detected, using direct mode"
  - Respects explicit --sandbox or --no-daemon flags
- Updated documentation to reflect auto-detection (v0.21.1+)

**Phase 3 (bd-e0o): Enhanced Daemon Robustness** ✅
- Permission-aware process checks in cmd/bd/daemon_unix.go
  - Correctly handles EPERM (operation not permitted) from syscall.Kill
  - Treats EPERM as "process exists but not signable" = running
  - Prevents false negatives in sandboxed environments
- Metadata health check in cmd/bd/daemon_event_loop.go
  - Periodic verification that metadata is accessible
  - Helps detect external import operations (bd import --force)
  - Non-fatal logging for diagnostics
- Comprehensive test suite in cmd/bd/daemon_unix_test.go
  - Self-check, init process, nonexistent process, parent process tests

**Impact:**
- Codex users: No manual intervention needed, auto-detected
- Stuck states: Three escape hatches (--sandbox, --force, --allow-stale)
- Daemon robustness: Handles permission-restricted environments gracefully
- All three follow-up issues (bd-9nw, bd-u3t, bd-e0o) closed

**Files changed:**
- cmd/bd/main.go: Auto-detection logic in PersistentPreRun
- cmd/bd/sandbox_unix.go: Unix sandbox detection (new)
- cmd/bd/sandbox_windows.go: Windows sandbox detection stub (new)
- cmd/bd/sandbox_test.go: Sandbox detection tests (new)
- cmd/bd/daemon_unix.go: Permission-aware isProcessRunning()
- cmd/bd/daemon_unix_test.go: Process check tests (new)
- cmd/bd/daemon_event_loop.go: Metadata health check
- docs/TROUBLESHOOTING.md: Comprehensive sandbox section
- docs/CLI_REFERENCE.md: Global flags documentation

Closes bd-9nw, bd-u3t, bd-e0o
Related: GH #353

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-21 19:32:45 -05:00
..
doctor Merge branch 'main' of https://github.com/steveyegge/beads 2025-11-20 19:37:01 -05:00
setup feat: add context optimization features for AI agents (#297) 2025-11-12 10:48:36 -08:00
templates chore: Bump version to 0.24.0 2025-11-20 22:15:04 -05:00
testdata fix: Update dep_add test to match current show output format 2025-11-04 00:23:25 -08:00
autoflush.go Context propagation with graceful cancellation (bd-rtp, bd-yb8, bd-2o2) 2025-11-20 21:57:23 -05:00
autoimport.go Improve Windows git path normalization 2025-11-02 10:38:24 -08:00
autoimport_test.go Context propagation with graceful cancellation (bd-rtp, bd-yb8, bd-2o2) 2025-11-20 21:57:23 -05:00
autostart_test.go Fix failing tests 2025-10-27 20:08:50 -07:00
clean.go test: Add security and error handling tests for lint warnings 2025-11-21 19:30:48 -05:00
clean_security_test.go test: Add security and error handling tests for lint warnings 2025-11-21 19:30:48 -05:00
cleanup.go Context propagation with graceful cancellation (bd-rtp, bd-yb8, bd-2o2) 2025-11-20 21:57:23 -05:00
cli_fast_test.go test: Tag 16 slow integration tests with build tags 2025-11-21 14:40:22 -05:00
comments.go Context propagation with graceful cancellation (bd-rtp, bd-yb8, bd-2o2) 2025-11-20 21:57:23 -05:00
comments_test.go test: Refactor P1 test files to use shared DB pattern (bd-1rh) 2025-11-21 15:51:07 -05:00
compact.go Context propagation with graceful cancellation (bd-rtp, bd-yb8, bd-2o2) 2025-11-20 21:57:23 -05:00
compact_test.go test: Refactor compact_test.go to use shared DB pattern (bd-1rh) 2025-11-21 16:13:18 -05:00
config.go Context propagation with graceful cancellation (bd-rtp, bd-yb8, bd-2o2) 2025-11-20 21:57:23 -05:00
config_test.go Context propagation with graceful cancellation (bd-rtp, bd-yb8, bd-2o2) 2025-11-20 21:57:23 -05:00
count.go feat: Add 'bd count' command for counting and grouping issues 2025-11-21 19:21:05 -05:00
create.go Context propagation with graceful cancellation (bd-rtp, bd-yb8, bd-2o2) 2025-11-20 21:57:23 -05:00
create_test.go test: Refactor P1 test files to use shared DB pattern (bd-1rh) 2025-11-21 15:51:07 -05:00
daemon.go Context propagation with graceful cancellation (bd-rtp, bd-yb8, bd-2o2) 2025-11-20 21:57:23 -05:00
daemon_autoimport_test.go Optimize test suite: split integration tests, add -short support 2025-11-05 20:39:47 -08:00
daemon_autostart.go Centralize BD_DEBUG logging into internal/debug package 2025-11-06 20:14:34 -08:00
daemon_config.go Reorganize project structure: move Go files to internal/beads, docs to docs/ 2025-11-05 21:04:00 -08:00
daemon_crash_test.go bd-vcg5: Add daemon crash recovery with panic handler + socket cleanup 2025-11-07 21:17:24 -08:00
daemon_debouncer.go Fix FileWatcher robustness issues (bd-71) 2025-10-29 22:55:13 -07:00
daemon_debouncer_test.go Optimize test suite performance (15-18x speedup) 2025-11-05 10:26:58 -08:00
daemon_event_loop.go feat: Complete GH #353 follow-up phases (bd-9nw, bd-u3t, bd-e0o) 2025-11-21 19:32:45 -05:00
daemon_lifecycle.go Add RPC diagnostics with BD_RPC_DEBUG env var 2025-11-07 21:29:22 -08:00
daemon_lock.go Fix daemon orphaning: track parent PID and exit when parent dies 2025-11-07 18:57:43 -08:00
daemon_lock_test.go Optimize test suite: split integration tests, add -short support 2025-11-05 20:39:47 -08:00
daemon_lock_unix.go Fix bd-54: Prevent multiple daemon instances via file locking 2025-10-22 13:59:58 -07:00
daemon_lock_wasm.go WIP: WASM port - switch to ncruces/go-sqlite3, add WASM stubs 2025-11-02 22:17:08 -08:00
daemon_lock_windows.go Fix bd-54: Prevent multiple daemon instances via file locking 2025-10-22 13:59:58 -07:00
daemon_logger.go Refactor daemon.go for testability and maintainability (bd-2b34) 2025-11-01 19:20:01 -07:00
daemon_parent_test.go test: Tag 16 slow integration tests with build tags 2025-11-21 14:40:22 -05:00
daemon_rotation_test.go Add native Windows support (#91) 2025-10-20 21:08:49 -07:00
daemon_server.go Context propagation with graceful cancellation (bd-rtp, bd-yb8, bd-2o2) 2025-11-20 21:57:23 -05:00
daemon_sync.go Complete bd-ar2 P2 tasks: metadata, resurrection, and testing improvements 2025-11-21 11:40:37 -05:00
daemon_sync_branch.go Remove legacy issues.jsonl and update defaults to beads.jsonl 2025-11-20 19:00:36 -05:00
daemon_sync_branch_test.go Context propagation with graceful cancellation (bd-rtp, bd-yb8, bd-2o2) 2025-11-20 21:57:23 -05:00
daemon_sync_test.go Close bd-ar2.8: Add edge case tests for export metadata updates 2025-11-21 14:57:01 -05:00
daemon_test.go Context propagation with graceful cancellation (bd-rtp, bd-yb8, bd-2o2) 2025-11-20 21:57:23 -05:00
daemon_unix.go feat: Complete GH #353 follow-up phases (bd-9nw, bd-u3t, bd-e0o) 2025-11-21 19:32:45 -05:00
daemon_unix_test.go feat: Complete GH #353 follow-up phases (bd-9nw, bd-u3t, bd-e0o) 2025-11-21 19:32:45 -05:00
daemon_wasm.go WIP: WASM port - switch to ncruces/go-sqlite3, add WASM stubs 2025-11-02 22:17:08 -08:00
daemon_watcher.go fix: address critical resource leaks and error handling issues (#327) 2025-11-20 08:13:06 -08:00
daemon_watcher_platform_test.go Optimize test suite: split integration tests, add -short support 2025-11-05 20:39:47 -08:00
daemon_watcher_test.go Optimize test suite: split integration tests, add -short support 2025-11-05 20:39:47 -08:00
daemon_windows.go Add native Windows support (#91) 2025-10-20 21:08:49 -07:00
daemons.go fix: address critical resource leaks and error handling issues (#327) 2025-11-20 08:13:06 -08:00
daemons_test.go Improve test coverage for cmd/bd 2025-10-31 18:40:32 -07:00
delete.go Context propagation with graceful cancellation (bd-rtp, bd-yb8, bd-2o2) 2025-11-20 21:57:23 -05:00
delete_test.go test: Tag 16 slow integration tests with build tags 2025-11-21 14:40:22 -05:00
deletion_tracking.go Fix lint errors: handle error return values 2025-11-15 12:52:34 -08:00
deletion_tracking_test.go Context propagation with graceful cancellation (bd-rtp, bd-yb8, bd-2o2) 2025-11-20 21:57:23 -05:00
dep.go Context propagation with graceful cancellation (bd-rtp, bd-yb8, bd-2o2) 2025-11-20 21:57:23 -05:00
dep_test.go test: Refactor P1 test files to use shared DB pattern (bd-1rh) 2025-11-21 15:51:07 -05:00
detect_pollution.go Context propagation with graceful cancellation (bd-rtp, bd-yb8, bd-2o2) 2025-11-20 21:57:23 -05:00
direct_mode.go Context propagation with graceful cancellation (bd-rtp, bd-yb8, bd-2o2) 2025-11-20 21:57:23 -05:00
direct_mode_test.go Fix all test failures from bd-166 (missing issue_prefix) 2025-10-26 22:31:24 -07:00
doctor.go Merge branch 'main' of https://github.com/steveyegge/beads 2025-11-20 19:37:01 -05:00
doctor_test.go Fix doctor incorrectly diagnosing hash IDs as sequential (issue #322) 2025-11-18 05:20:11 -05:00
duplicates.go feat: Add issue IDs to TODO comments 2025-11-21 19:01:42 -05:00
duplicates_test.go feat: Add sandbox escape hatches for daemon lock issues (GH #353 Phase 1) 2025-11-21 18:53:34 -05:00
epic.go Context propagation with graceful cancellation (bd-rtp, bd-yb8, bd-2o2) 2025-11-20 21:57:23 -05:00
epic_test.go test: Refactor epic_test.go to use shared DB pattern (P2) 2025-11-21 16:14:30 -05:00
export.go Context propagation with graceful cancellation (bd-rtp, bd-yb8, bd-2o2) 2025-11-20 21:57:23 -05:00
export_import_test.go Optimize test suite performance (15-18x speedup) 2025-11-05 10:26:58 -08:00
export_integrity_integration_test.go Context propagation with graceful cancellation (bd-rtp, bd-yb8, bd-2o2) 2025-11-20 21:57:23 -05:00
export_mtime_test.go test: Tag 16 slow integration tests with build tags 2025-11-21 14:40:22 -05:00
export_staleness_test.go Fix bd-srwk: Add ID-based staleness detection to bd export 2025-11-07 20:07:59 -08:00
export_test.go Fix context propagation lifecycle bugs 2025-11-20 21:54:11 -05:00
flags.go Refactor: extract duplicated validation and flag logic (bd-g5p7) 2025-11-20 19:11:27 -05:00
flush_manager.go Improve FlushManager: constants, error logging, and functional tests 2025-11-20 21:38:31 -05:00
flush_manager_test.go test: Add security and error handling tests for lint warnings 2025-11-21 19:30:48 -05:00
git_sync_test.go Optimize test suite: split integration tests, add -short support 2025-11-05 20:39:47 -08:00
helpers_test.go bd sync: 2025-11-09 14:53:59 2025-11-09 14:53:59 -08:00
hooks.go Annotate gosec-safe file accesses 2025-11-17 10:12:46 -07:00
hooks_test.go Fix CI regressions and stabilize tests 2025-11-17 10:06:35 -07:00
import.go feat: Add sandbox escape hatches for daemon lock issues (GH #353 Phase 1) 2025-11-21 18:53:34 -05:00
import_bug_test.go Remove vestigial --resolve-collisions flag 2025-10-31 01:07:42 -07:00
import_cancellation_test.go Context propagation with graceful cancellation (bd-rtp, bd-yb8, bd-2o2) 2025-11-20 21:57:23 -05:00
import_idempotent_test.go Fix remaining test database initialization errors (bd-207) 2025-10-27 20:00:49 -07:00
import_mtime_test.go fix: Fix daemon export leaving JSONL newer than database (issues #301, #321) 2025-11-19 05:06:12 -05:00
import_multipart_id_test.go bd sync: 2025-11-09 14:53:59 2025-11-09 14:53:59 -08:00
import_profile_test.go test: Tag 16 slow integration tests with build tags 2025-11-21 14:40:22 -05:00
import_shared.go Add --clear-duplicate-external-refs flag to bd import 2025-11-06 13:01:44 -08:00
import_uncommitted_test.go test: Tag 16 slow integration tests with build tags 2025-11-21 14:40:22 -05:00
info.go Context propagation with graceful cancellation (bd-rtp, bd-yb8, bd-2o2) 2025-11-20 21:57:23 -05:00
info_test.go feat: Add bd info --whats-new for agent version awareness (bd-eiz9) 2025-11-08 02:28:54 -08:00
init.go Context propagation with graceful cancellation (bd-rtp, bd-yb8, bd-2o2) 2025-11-20 21:57:23 -05:00
init_contributor.go Annotate gosec-safe file accesses 2025-11-17 10:12:46 -07:00
init_hooks_test.go Fix CI regressions and stabilize tests 2025-11-17 10:06:35 -07:00
init_team.go feat: Add bd init --contributor and --team wizards 2025-11-05 19:04:14 -08:00
init_test.go bd sync: 2025-11-09 14:13:48 2025-11-09 14:13:48 -08:00
integrity.go Complete bd-ar2 P2 tasks: metadata, resurrection, and testing improvements 2025-11-21 11:40:37 -05:00
integrity_content_test.go test: Tag 16 slow integration tests with build tags 2025-11-21 14:40:22 -05:00
integrity_test.go test: Refactor integrity_test.go to use shared DB pattern (bd-1rh P2) 2025-11-21 16:11:56 -05:00
jsonl_integrity_test.go Context propagation with graceful cancellation (bd-rtp, bd-yb8, bd-2o2) 2025-11-20 21:57:23 -05:00
label.go Context propagation with graceful cancellation (bd-rtp, bd-yb8, bd-2o2) 2025-11-20 21:57:23 -05:00
label_test.go Fix all test failures from bd-166 (missing issue_prefix) 2025-10-26 22:31:24 -07:00
list.go Context propagation with graceful cancellation (bd-rtp, bd-yb8, bd-2o2) 2025-11-20 21:57:23 -05:00
list_test.go test: Refactor P1 test files to use shared DB pattern (bd-1rh) 2025-11-21 15:51:07 -05:00
main.go feat: Complete GH #353 follow-up phases (bd-9nw, bd-u3t, bd-e0o) 2025-11-21 19:32:45 -05:00
main_test.go test: Mark TestAutoFlushDebounce as obsolete 2025-11-21 19:00:44 -05:00
MAIN_TEST_REFACTOR_NOTES.md doc: Document main_test.go refactoring analysis (bd-1rh) 2025-11-21 18:00:23 -05:00
markdown.go Context propagation with graceful cancellation (bd-rtp, bd-yb8, bd-2o2) 2025-11-20 21:57:23 -05:00
markdown_test.go Add native Windows support (#91) 2025-10-20 21:08:49 -07:00
merge.go test: Add security and error handling tests for lint warnings 2025-11-21 19:30:48 -05:00
merge_security_test.go test: Add security and error handling tests for lint warnings 2025-11-21 19:30:48 -05:00
message.go Fix lint errors: handle error return values 2025-11-15 12:52:34 -08:00
migrate.go Context propagation with graceful cancellation (bd-rtp, bd-yb8, bd-2o2) 2025-11-20 21:57:23 -05:00
migrate_hash_ids.go Context propagation with graceful cancellation (bd-rtp, bd-yb8, bd-2o2) 2025-11-20 21:57:23 -05:00
migrate_hash_ids_test.go Context propagation with graceful cancellation (bd-rtp, bd-yb8, bd-2o2) 2025-11-20 21:57:23 -05:00
migrate_issues.go Context propagation with graceful cancellation (bd-rtp, bd-yb8, bd-2o2) 2025-11-20 21:57:23 -05:00
migrate_test.go Context propagation with graceful cancellation (bd-rtp, bd-yb8, bd-2o2) 2025-11-20 21:57:23 -05:00
nodb.go Context propagation with graceful cancellation (bd-rtp, bd-yb8, bd-2o2) 2025-11-20 21:57:23 -05:00
nodb_test.go bd sync: 2025-11-09 14:53:59 2025-11-09 14:53:59 -08:00
onboard.go Handle formatting errors in onboard renderer 2025-11-17 11:32:37 -07:00
onboard_test.go Handle formatting errors in onboard renderer 2025-11-17 11:32:37 -07:00
output_test.go Close bd-157: Complete auto-import refactoring 2025-10-18 18:21:17 -07:00
prime.go Annotate gosec-safe file accesses 2025-11-17 10:12:46 -07:00
quickstart.go Fix quickstart EXTENDING.md reference to use full URL (#12) 2025-10-14 01:10:18 -07:00
ready.go Context propagation with graceful cancellation (bd-rtp, bd-yb8, bd-2o2) 2025-11-20 21:57:23 -05:00
ready_test.go test: Refactor P1 test files to use shared DB pattern (bd-1rh) 2025-11-21 15:51:07 -05:00
reinit_test.go Context propagation with graceful cancellation (bd-rtp, bd-yb8, bd-2o2) 2025-11-20 21:57:23 -05:00
rename_prefix.go Context propagation with graceful cancellation (bd-rtp, bd-yb8, bd-2o2) 2025-11-20 21:57:23 -05:00
rename_prefix_repair_test.go Context propagation with graceful cancellation (bd-rtp, bd-yb8, bd-2o2) 2025-11-20 21:57:23 -05:00
rename_prefix_test.go Context propagation with graceful cancellation (bd-rtp, bd-yb8, bd-2o2) 2025-11-20 21:57:23 -05:00
reopen.go feat: Add issue IDs to TODO comments 2025-11-21 19:01:42 -05:00
reopen_test.go Fix all test failures from bd-166 (missing issue_prefix) 2025-10-26 22:31:24 -07:00
repair_deps.go Context propagation with graceful cancellation (bd-rtp, bd-yb8, bd-2o2) 2025-11-20 21:57:23 -05:00
repair_deps_test.go Context propagation with graceful cancellation (bd-rtp, bd-yb8, bd-2o2) 2025-11-20 21:57:23 -05:00
repo.go Context propagation with graceful cancellation (bd-rtp, bd-yb8, bd-2o2) 2025-11-20 21:57:23 -05:00
restore.go Context propagation with graceful cancellation (bd-rtp, bd-yb8, bd-2o2) 2025-11-20 21:57:23 -05:00
restore_test.go Improve cmd/bd test coverage from 21% to 23.1% (bd-27ea) 2025-10-31 19:44:43 -07:00
sandbox_test.go feat: Complete GH #353 follow-up phases (bd-9nw, bd-u3t, bd-e0o) 2025-11-21 19:32:45 -05:00
sandbox_unix.go feat: Complete GH #353 follow-up phases (bd-9nw, bd-u3t, bd-e0o) 2025-11-21 19:32:45 -05:00
sandbox_windows.go feat: Complete GH #353 follow-up phases (bd-9nw, bd-u3t, bd-e0o) 2025-11-21 19:32:45 -05:00
scripttest_test.go Optimize test suite performance - 45% reduction in integration tests 2025-11-04 11:25:36 -08:00
search.go test: Add security and error handling tests for lint warnings 2025-11-21 19:30:48 -05:00
search_test.go test: Add security and error handling tests for lint warnings 2025-11-21 19:30:48 -05:00
setup.go feat: add context optimization features for AI agents (#297) 2025-11-12 10:48:36 -08:00
show.go Context propagation with graceful cancellation (bd-rtp, bd-yb8, bd-2o2) 2025-11-20 21:57:23 -05:00
simple_helpers_test.go bd-211: Remove deprecated rename functions from import_shared.go 2025-10-27 20:38:13 -07:00
snapshot_manager.go Annotate gosec-safe file accesses 2025-11-17 10:12:46 -07:00
stale.go Context propagation with graceful cancellation (bd-rtp, bd-yb8, bd-2o2) 2025-11-20 21:57:23 -05:00
stale_test.go test: Refactor P1 test files to use shared DB pattern (bd-1rh) 2025-11-21 15:51:07 -05:00
staleness.go feat: Add sandbox escape hatches for daemon lock issues (GH #353 Phase 1) 2025-11-21 18:53:34 -05:00
status.go Context propagation with graceful cancellation (bd-rtp, bd-yb8, bd-2o2) 2025-11-20 21:57:23 -05:00
status_test.go Context propagation with graceful cancellation (bd-rtp, bd-yb8, bd-2o2) 2025-11-20 21:57:23 -05:00
sync.go Fix bd-ar2 code review issues: metadata tracking and multi-repo support 2025-11-21 11:28:25 -05:00
sync_local_only_test.go test: Tag 16 slow integration tests with build tags 2025-11-21 14:40:22 -05:00
sync_merge_test.go Context propagation with graceful cancellation (bd-rtp, bd-yb8, bd-2o2) 2025-11-20 21:57:23 -05:00
sync_test.go Add git hooks check to bd doctor 2025-11-02 17:09:39 -08:00
template.go fix: CI failures - performance thresholds, test eligibility, Nix hash, lint errors 2025-11-03 22:01:37 -08:00
template_security_test.go Add template support for issue creation (bd-164b) 2025-11-03 20:31:11 -08:00
template_test.go Add template support for issue creation (bd-164b) 2025-11-03 20:31:11 -08:00
test_helpers_test.go Context propagation with graceful cancellation (bd-rtp, bd-yb8, bd-2o2) 2025-11-20 21:57:23 -05:00
TEST_SUITE_AUDIT.md test: Refactor compact_test.go to use shared DB pattern (bd-1rh) 2025-11-21 16:13:18 -05:00
test_wait_helper.go test: add waitFor helper for event-driven testing 2025-11-04 01:10:18 -08:00
validate.go Context propagation with graceful cancellation (bd-rtp, bd-yb8, bd-2o2) 2025-11-20 21:57:23 -05:00
validate_test.go test: Refactor validate_test.go - remove ALL DB setup (P2) 2025-11-21 16:14:30 -05:00
version.go chore: Bump version to 0.24.0 2025-11-20 22:15:04 -05:00
version_test.go Add support for bd --version flag 2025-11-05 17:37:53 -08:00
worktree.go Reorganize project structure: move Go files to internal/beads, docs to docs/ 2025-11-05 21:04:00 -08:00
worktree_test.go Improve cmd/bd test coverage from 20.2% to 23.3% 2025-11-08 18:22:28 -08:00