Fix bd-161: Implement daemon JSONL import (fix NO-OP stub)
Replace the NO-OP importToJSONLWithStore() stub with full implementation: - Reads and parses JSONL file line by line using bufio.Scanner - Uses importIssuesCore() with auto-collision resolution enabled - Integrates with existing import infrastructure - Fixes PRIMARY root cause of bd-160 multi-clone sync failure The daemon now properly imports remote changes pulled from git instead of ignoring them, allowing databases to converge across clones. Amp-Thread-ID: https://ampcode.com/threads/T-9b92c2dc-e0e2-4d77-b562-136da8c3f64e Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
@@ -789,11 +790,53 @@ func exportToJSONLWithStore(ctx context.Context, store storage.Storage, jsonlPat
|
||||
// Note: This cannot use the import command approach since we're in the daemon
|
||||
// We need to implement direct import logic here
|
||||
func importToJSONLWithStore(ctx context.Context, store storage.Storage, jsonlPath string) error {
|
||||
// TODO Phase 4: Implement direct import for daemon
|
||||
// Currently a no-op - daemon doesn't import git changes into DB
|
||||
// This means git pulls won't update the database until this is implemented
|
||||
// For now, users must restart daemon after git pulls to see changes
|
||||
return nil
|
||||
// Read JSONL file
|
||||
file, err := os.Open(jsonlPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to open JSONL: %w", err)
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
// Parse all issues
|
||||
var issues []*types.Issue
|
||||
scanner := bufio.NewScanner(file)
|
||||
lineNum := 0
|
||||
|
||||
for scanner.Scan() {
|
||||
lineNum++
|
||||
line := scanner.Text()
|
||||
|
||||
// Skip empty lines
|
||||
if line == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
// Parse JSON
|
||||
var issue types.Issue
|
||||
if err := json.Unmarshal([]byte(line), &issue); err != nil {
|
||||
// Log error but continue - don't fail entire import
|
||||
fmt.Fprintf(os.Stderr, "Warning: failed to parse JSONL line %d: %v\n", lineNum, err)
|
||||
continue
|
||||
}
|
||||
|
||||
issues = append(issues, &issue)
|
||||
}
|
||||
|
||||
if err := scanner.Err(); err != nil {
|
||||
return fmt.Errorf("failed to read JSONL: %w", err)
|
||||
}
|
||||
|
||||
// Use existing import logic with auto-conflict resolution
|
||||
opts := ImportOptions{
|
||||
ResolveCollisions: true, // Auto-resolve ID conflicts
|
||||
DryRun: false,
|
||||
SkipUpdate: false,
|
||||
Strict: false,
|
||||
SkipPrefixValidation: true, // Skip prefix validation for auto-import
|
||||
}
|
||||
|
||||
_, err = importIssuesCore(ctx, "", store, issues, opts)
|
||||
return err
|
||||
}
|
||||
|
||||
type daemonLogger struct {
|
||||
|
||||
Reference in New Issue
Block a user