Fix compact command failing with 'SQLite DB needed' error when daemon is running by removing premature store check and using ensureDirectMode for analyze/apply modes (closes beads-vlo) (#294)

This commit is contained in:
dezer32
2025-11-12 20:37:54 +02:00
committed by GitHub
parent 9dff345e7a
commit d9904a8830

View File

@@ -101,27 +101,25 @@ Examples:
os.Exit(1) os.Exit(1)
} }
// Get SQLite store // Handle analyze mode (requires direct database access)
if compactAnalyze {
if err := ensureDirectMode("compact --analyze requires direct database access"); err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
}
sqliteStore, ok := store.(*sqlite.SQLiteStorage) sqliteStore, ok := store.(*sqlite.SQLiteStorage)
if !ok { if !ok {
fmt.Fprintf(os.Stderr, "Error: compact requires SQLite storage\n") fmt.Fprintf(os.Stderr, "Error: compact requires SQLite storage\n")
os.Exit(1) os.Exit(1)
} }
// Handle analyze mode
if compactAnalyze {
if daemonClient != nil {
fmt.Fprintf(os.Stderr, "Error: --analyze not yet supported in daemon mode, use --no-daemon\n")
os.Exit(1)
}
runCompactAnalyze(ctx, sqliteStore) runCompactAnalyze(ctx, sqliteStore)
return return
} }
// Handle apply mode // Handle apply mode (requires direct database access)
if compactApply { if compactApply {
if daemonClient != nil { if err := ensureDirectMode("compact --apply requires direct database access"); err != nil {
fmt.Fprintf(os.Stderr, "Error: --apply not yet supported in daemon mode, use --no-daemon\n") fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1) os.Exit(1)
} }
if compactID == "" { if compactID == "" {
@@ -132,31 +130,47 @@ Examples:
fmt.Fprintf(os.Stderr, "Error: --apply requires --summary\n") fmt.Fprintf(os.Stderr, "Error: --apply requires --summary\n")
os.Exit(1) os.Exit(1)
} }
sqliteStore, ok := store.(*sqlite.SQLiteStorage)
if !ok {
fmt.Fprintf(os.Stderr, "Error: compact requires SQLite storage\n")
os.Exit(1)
}
runCompactApply(ctx, sqliteStore) runCompactApply(ctx, sqliteStore)
return return
} }
// Handle auto mode (legacy) // Handle auto mode (legacy)
if compactAuto { if compactAuto {
// API key check only for auto mode // Validation checks
if compactID != "" && compactAll {
fmt.Fprintf(os.Stderr, "Error: cannot use --id and --all together\n")
os.Exit(1)
}
if compactForce && compactID == "" {
fmt.Fprintf(os.Stderr, "Error: --force requires --id\n")
os.Exit(1)
}
if compactID == "" && !compactAll && !compactDryRun {
fmt.Fprintf(os.Stderr, "Error: must specify --all, --id, or --dry-run\n")
os.Exit(1)
}
// Use RPC if daemon available, otherwise direct mode
if daemonClient != nil {
runCompactRPC(ctx)
return
}
// Fallback to direct mode
apiKey := os.Getenv("ANTHROPIC_API_KEY") apiKey := os.Getenv("ANTHROPIC_API_KEY")
if apiKey == "" && !compactDryRun { if apiKey == "" && !compactDryRun {
fmt.Fprintf(os.Stderr, "Error: --auto mode requires ANTHROPIC_API_KEY environment variable\n") fmt.Fprintf(os.Stderr, "Error: --auto mode requires ANTHROPIC_API_KEY environment variable\n")
os.Exit(1) os.Exit(1)
} }
if compactID != "" && compactAll { sqliteStore, ok := store.(*sqlite.SQLiteStorage)
fmt.Fprintf(os.Stderr, "Error: cannot use --id and --all together\n") if !ok {
os.Exit(1) fmt.Fprintf(os.Stderr, "Error: compact requires SQLite storage\n")
}
if compactForce && compactID == "" {
fmt.Fprintf(os.Stderr, "Error: --force requires --id\n")
os.Exit(1)
}
if compactID == "" && !compactAll && !compactDryRun {
fmt.Fprintf(os.Stderr, "Error: must specify --all, --id, or --dry-run\n")
os.Exit(1) os.Exit(1)
} }