Files
oh-my-opencode/src/hooks/todo-continuation-enforcer/compaction-guard.ts
T
2026-03-24 20:36:22 +09:00

40 lines
1022 B
TypeScript

import { COMPACTION_GUARD_MS } from "./constants"
import type { SessionState } from "./types"
export function armCompactionGuard(state: SessionState, now: number): number {
const nextEpoch = (state.recentCompactionEpoch ?? 0) + 1
state.recentCompactionAt = now
state.recentCompactionEpoch = nextEpoch
return nextEpoch
}
export function acknowledgeCompactionGuard(
state: SessionState,
compactionEpoch: number | undefined
): boolean {
if (compactionEpoch === undefined) {
return false
}
if (state.recentCompactionEpoch !== compactionEpoch) {
return false
}
state.acknowledgedCompactionEpoch = compactionEpoch
return true
}
export function isCompactionGuardActive(state: SessionState, now: number): boolean {
if (state.recentCompactionAt === undefined || state.recentCompactionEpoch === undefined) {
return false
}
if (state.acknowledgedCompactionEpoch === state.recentCompactionEpoch) {
return false
}
return now - state.recentCompactionAt < COMPACTION_GUARD_MS
}