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>
This commit is contained in:
Steve Yegge
2025-11-01 17:01:33 -07:00
parent cbe70aa2c3
commit b5839b656d
8 changed files with 390 additions and 40 deletions

View File

@@ -4,7 +4,6 @@ import (
"encoding/json"
"errors"
"fmt"
"io"
"os"
"path/filepath"
"time"
@@ -36,35 +35,6 @@ func (l *DaemonLock) Close() error {
return err
}
func (d *Daemon) setupLock() (io.Closer, error) {
lock, err := acquireDaemonLock(d.cfg.BeadsDir, d.cfg.DBPath, d.Version)
if err != nil {
if err == ErrDaemonLocked {
d.log.log("Daemon already running (lock held), exiting")
} else {
d.log.log("Error acquiring daemon lock: %v", err)
}
return nil, err
}
// Ensure PID file matches our PID
myPID := os.Getpid()
pidFile := d.cfg.PIDFile
// #nosec G304 - controlled path from config
if data, err := os.ReadFile(pidFile); err == nil {
var filePID int
if _, err := fmt.Sscanf(string(data), "%d", &filePID); err == nil && filePID != myPID {
d.log.log("PID file has wrong PID (expected %d, got %d), overwriting", myPID, filePID)
_ = os.WriteFile(pidFile, []byte(fmt.Sprintf("%d\n", myPID)), 0600)
}
} else {
d.log.log("PID file missing after lock acquisition, creating")
_ = os.WriteFile(pidFile, []byte(fmt.Sprintf("%d\n", myPID)), 0600)
}
return lock, nil
}
// acquireDaemonLock attempts to acquire an exclusive lock on daemon.lock
func acquireDaemonLock(beadsDir string, dbPath string, version string) (*DaemonLock, error) {
lockPath := filepath.Join(beadsDir, "daemon.lock")