trellis
Version:
Agentic State Engine — event-sourced causal graph with branching, decision traces, and realtime sync for AI-native applications
65 lines • 2.38 kB
TypeScript
/**
* Diff Engine
*
* File-level diff with unified text output (Tier 0 / P3).
* Compares two points in history by reconstructing file states from the
* op stream and producing file-level diffs with optional unified text diffs
* via the blob store.
*
* DESIGN.md §4.5 — "At Tier 0 (before AST parsing is available), the diff
* engine falls back to file-level comparison."
*/
import type { VcsOp } from './types.js';
import type { BlobResolver } from './blob-resolver.js';
export interface FileLevelDiff {
kind: 'fileAdded' | 'fileModified' | 'fileDeleted' | 'fileRenamed';
path: string;
oldPath?: string;
oldContentHash?: string;
newContentHash?: string;
/** Unified diff text (only for fileModified when blob content is available). */
unifiedDiff?: string;
}
export interface DiffResult {
diffs: FileLevelDiff[];
filesChanged: string[];
stats: {
added: number;
modified: number;
removed: number;
renamed: number;
};
}
export interface FileState {
contentHash?: string;
deleted?: boolean;
}
/**
* Compute file-level diffs between two file state snapshots.
* Optionally produces unified text diffs when a blob resolver is provided.
*/
export declare function diffFileStates(stateA: Map<string, FileState>, stateB: Map<string, FileState>, blobResolver?: BlobResolver | null): DiffResult;
/**
* Build cumulative file state from an array of ops up to (and including)
* the op with the given hash. If no hash given, uses all ops.
*/
export declare function buildFileStateAtOp(ops: VcsOp[], atOpHash?: string): Map<string, FileState>;
/**
* Diff two op hashes in the same op stream.
*/
export declare function diffOpRange(ops: VcsOp[], fromHash: string, toHash: string, blobResolver?: BlobResolver | null): DiffResult;
interface EditOp {
kind: 'equal' | 'insert' | 'delete';
line: string;
}
/**
* Generate a unified diff string from two text inputs.
*/
export declare function generateUnifiedDiff(filePath: string, oldText: string, newText: string, contextLines?: number): string;
/**
* Myers diff algorithm — computes the shortest edit script between two
* arrays of lines. Returns a sequence of equal/insert/delete operations.
*/
export declare function myersDiff(oldLines: string[], newLines: string[]): EditOp[];
export {};
//# sourceMappingURL=diff.d.ts.map