Commit Graph

8 Commits

Author SHA1 Message Date
Steve Yegge
15affbe11e fix: Suppress gosec warnings with nolint comments
- Add nolint:gosec comments for safe file operations
- G304: File reads from validated/secure paths
- G306/G302: JSONL/error files need 0644 for sharing/debugging
- G204: Subprocess launches with validated arguments
- G104: Deferred file close errors are non-critical
- G115: Safe integer conversions in backoff
- G201: SQL placeholders for IN clause expansion

All warnings are for intentional behavior that is safe in context.

Amp-Thread-ID: https://ampcode.com/threads/T-d78f2780-4709-497f-97b0-035ca8c809e1
Co-authored-by: Amp <amp@ampcode.com>
2025-11-02 08:09:58 -08:00
Steve Yegge
7032d7d8ec Refactor: separate process/lock/PID concerns into process.go (bd-d33c) 2025-11-01 23:46:01 -07:00
Steve Yegge
88fd7b2bc2 Improve git operations: use --ff-only for pull, make commit idempotent 2025-11-01 23:00:25 -07:00
Steve Yegge
cfce2b1e70 Add GitClient interface to daemonrunner/git.go for testability
Amp-Thread-ID: https://ampcode.com/threads/T-3e38fcda-411e-41db-bfe4-eba7a7771b67
Co-authored-by: Amp <amp@ampcode.com>
2025-11-01 22:56:08 -07:00
Steve Yegge
6e8907335f Add test coverage for daemon lifecycle and config modules
- Add config_test.go: tests for daemon configuration (local/global, sync behavior)
- Add daemon_test.go: tests for daemon lifecycle (creation, shutdown, database path resolution)
- Add process_test.go: tests for daemon lock acquisition and release
- Closes bd-2b34.6, bd-2b34.7

Amp-Thread-ID: https://ampcode.com/threads/T-4419d1ab-4105-4e75-bea8-1837ee80e2c2
Co-authored-by: Amp <amp@ampcode.com>
2025-11-01 21:27:09 -07:00
Steve Yegge
3fc8922c86 Refactor daemon runtime into internal/daemonrunner package
- Extract Daemon struct with Start/Stop methods
- Create focused modules: config, daemon, rpc, sync, git, process, logger
- Move platform-specific code to separate files (signals_*.go, flock_*.go)
- Add database fingerprint validation
- Keep import logic in cmd/bd for now (TODO: extract later)
- All builds pass, most daemon tests pass

Closes bd-b5a3
2025-11-01 20:02:30 -07:00
Steve Yegge
b5839b656d Fix compilation errors in internal/daemonrunner package
Created missing files:
- logger.go: Logger type, setupLogger method, and env helpers
- signals_unix.go: Unix signal definitions (SIGTERM, SIGINT, SIGHUP)
- signals_windows.go: Windows signal definitions
- sync.go: Sync loop implementation with export/import/validation helpers

Fixed errors:
- Added missing 'version' parameter to acquireDaemonLock call
- Removed duplicate setupLock method from process.go (kept in daemon.go)
- Removed duplicate startRPCServer from daemon.go (kept in rpc.go)
- Fixed LogPath -> LogFile config field reference
- Removed unused 'io' import from process.go

Implementation notes:
- exportToJSONL: Full implementation with dependencies, labels, comments
- importFromJSONL: Placeholder (TODO: extract from cmd/bd/import.go)
- countDBIssues: Uses SQL COUNT(*) optimization with fallback
- validatePostImport: Checks for data loss
- runSyncLoop/runEventLoop: Main daemon event loops with signal handling

All packages now compile successfully with 'go build ./...'

Amp-Thread-ID: https://ampcode.com/threads/T-36a7f730-3420-426f-9e23-f13d5fa089c4
Co-authored-by: Amp <amp@ampcode.com>
2025-11-01 19:10:27 -07:00
Steve Yegge
94f2dc1198 WIP: Extract daemon runtime into internal/daemonrunner
- Created config.go with Config struct
- Created daemon.go with Daemon struct and Start/Stop methods
- Created logger.go for logging setup
- Created process.go for lock/PID management
- Created fingerprint.go for database validation
- Created flock_unix.go/flock_windows.go for platform-specific locking
- Created git.go for git operations

Still TODO:
- Implement runGlobalDaemon, startRPCServer, runSyncLoop
- Create sync.go, rpc.go, jsonl.go, validation.go
- Update cmd/bd/daemon.go to use daemonrunner

Part of bd-5f26
2025-11-01 11:47:41 -07:00