33
};
34
}
36
>
/**
37
>
* Represents a file's identity across renames, tracking its first and last
38
>
* snapshots in the session for diff computation.
39
>
*/
40
>
interface IFileIdentity {
41
>
/** The last known URI for this file. */
42
>
terminalPath: string;
43
>
/** Tool call ID of the first edit (for fetching "before" content). */
44
>
firstToolCallId: string;
45
>
/** File path used in the first edit's database record. */
46
>
firstFilePath: string;
47
>
/** The kind of the first edit (Create means no "before" content). */
48
>
firstKind: FileEditKind;
49
>
/** Index into the sources array of the DB that owns the first edit. */
50
>
firstSourceIdx: number;
51
>
/** Tool call ID of the last edit (for fetching "after" content). */
52
>
lastToolCallId: string;
53
>
/** File path used in the last edit's database record. */
54
>
lastFilePath: string;
55
>
/** The kind of the last edit (Delete means no "after" content). */
56
>
lastKind: FileEditKind;
57
>
/** Index into the sources array of the DB that owns the last edit. */
58
>
lastSourceIdx: number;
59
>
}
60
>
61
>
/**
62
>
* A single database whose file edits contribute to a session's aggregated
63
>
* diff. For single-chat sessions there is one source (the session DB); for
64
>
* multi-chat sessions each peer chat records edits into its own DB, so the
65
>
* session changeset unions the session DB with every peer chat DB.
66
>
*/
67
>
export interface ISessionDiffSource {
68
>
/**
69
>
* The session / peer-chat URI that owns {@link db}. Encoded into the
70
>
* `session-db:` content URIs so the resource resolver opens the correct
71
>
* database when fetching before/after blobs.
72
>
*/
73
>
sessionUri: string;
74
>
/** The database holding this source's file edits. */
75
>
db: ISessionDatabase;
76
>
}
77
>
78
>
/**
79
>
* Options for incremental diff computation. When provided,
80
>
* {@link computeSessionDiffs} reuses previous diff results for file
81
>
* identities that were not touched in the given turn.
82
>
*/
83
>
export interface IIncrementalDiffOptions {
84
>
/** The turn ID that just completed — only identities touched by edits
85
>
* in this turn will be recomputed. */
86
>
changedTurnId: string;
87
>
/** Previously computed diffs (from the last dispatch). Entries for
88
>
* untouched identities are carried over without recomputation. */
89
>
previousDiffs: ISessionFileDiff[];
90
>
}
91
>
92
>
/**
93
>
* Computes aggregated diff statistics for a session by comparing each file's
94
>
* first snapshot to its last snapshot, tracking renames across the chain.
95
>
*
96
>
* When {@link incremental} is provided, only identities that were touched
97
>
* by edits in the given turn are recomputed; all other identities reuse
98
>
* the previous diff results. This avoids expensive content fetches and
99
>
* diff computations for unchanged files.
100
>
*
101
>
* Returns an {@link ISessionFileDiff} array with the "last known URI" for each
102
>
* file and the total lines added/removed across the session.
103
>
*/
104
export async function computeSessionDiffs(
105
sessionUri: string,