@sudocode-ai/cli
Version:
Git-native spec and issue management CLI for AI-assisted software development
118 lines • 3.53 kB
TypeScript
/**
* Import JSONL data to SQLite with collision resolution
*/
import type Database from "better-sqlite3";
import type { SpecJSONL, IssueJSONL } from "@sudocode-ai/types";
export interface ImportOptions {
/**
* Input directory for JSONL files
*/
inputDir?: string;
/**
* Custom file names
*/
specsFile?: string;
issuesFile?: string;
/**
* Dry run - detect changes but don't apply
*/
dryRun?: boolean;
/**
* Automatically resolve collisions
*/
resolveCollisions?: boolean;
/**
* Path to meta.json for collision logging
*/
metaPath?: string;
}
export interface ImportResult {
specs: {
added: number;
updated: number;
deleted: number;
};
issues: {
added: number;
updated: number;
deleted: number;
};
collisions: CollisionInfo[];
}
export interface CollisionInfo {
id: string;
uuid: string;
type: "spec" | "issue";
reason: string;
localContent: string;
incomingContent: string;
localCreatedAt?: string;
incomingCreatedAt: string;
resolution?: "keep-local" | "use-incoming" | "renumber";
newId?: string;
}
export interface ChangeDetection {
added: string[];
updated: string[];
deleted: string[];
unchanged: string[];
}
/**
* Detect changes between existing and incoming entities
* Uses UUID as the source of truth for entity identity
*/
export declare function detectChanges<T extends {
id: string;
uuid: string;
updated_at: string;
}>(existing: T[], incoming: T[]): ChangeDetection;
/**
* Detect ID collisions (same ID, different UUID)
* UUIDs are the source of truth for entity identity
*/
export declare function detectCollisions<T extends {
id: string;
uuid: string;
title: string;
created_at: string;
}>(existing: T[], incoming: T[]): CollisionInfo[];
/**
* Count references to an entity ID in content fields
*/
export declare function countReferences(db: Database.Database, entityId: string, entityType: "spec" | "issue"): number;
/**
* Resolve collisions using timestamp-based deterministic strategy
*
* The entity with the NEWER (more recent) created_at timestamp logically
* should be renumbered, while the OLDER entity keeps the original ID.
*
* For practical reasons (entities already in DB can't be easily renamed),
* incoming entities are always the ones that get new IDs. However, we
* deterministically decide which UUID gets which new ID based on timestamps.
*/
export declare function resolveCollisions(db: Database.Database, collisions: CollisionInfo[]): CollisionInfo[];
/**
* Update text references when an ID is renumbered
*/
export declare function updateTextReferences(db: Database.Database, oldId: string, newId: string): number;
/**
* Import specs from JSONL
*/
export declare function importSpecs(db: Database.Database, specs: SpecJSONL[], changes: ChangeDetection, dryRun?: boolean, skipRelationships?: boolean): {
added: number;
updated: number;
deleted: number;
};
/**
* Import issues from JSONL
*/
export declare function importIssues(db: Database.Database, issues: IssueJSONL[], changes: ChangeDetection, dryRun?: boolean, skipRelationships?: boolean): {
added: number;
updated: number;
deleted: number;
};
/**
* Import both specs and issues from JSONL files
*/
export declare function importFromJSONL(db: Database.Database, options?: ImportOptions): Promise<ImportResult>;
//# sourceMappingURL=import.d.ts.map