32
*/
33
export function resolveForkBoundary(sourceTurnIds: readonly string[], codexTurnId: string, fallbackTurnIndex: number): ForkBoundaryResolution {
35
>
let keepThroughIndex = sourceTurnIds.findIndex(id => id === codexTurnId);
36
>
if (keepThroughIndex === -1) {
37
keepThroughIndex = fallbackTurnIndex;
38
}
39
>
// An empty source thread is a valid (empty) fork; otherwise the boundary
codexForkPlan.ts
40
>
// must land inside the source turns.
41
>
if (total > 0 && (keepThroughIndex < 0 || keepThroughIndex >= total)) {
42
return { resolved: false };
43
}
44
>
const numTurnsToDrop = total > 0 ? Math.max(0, total - (keepThroughIndex + 1)) : 0;
codexForkPlan.ts
45
>
return { resolved: true, keepThroughIndex, numTurnsToDrop };
46
>
}
47
48
/** A `[hostTurnId, codexTurnId]` pair to seed into a forked session's map. */