UNPKG

@code-yeongyu/senpi

Version:

Coding agent CLI with read, bash, edit, write tools and session management

44 lines • 1.67 kB
export const FAILURE_TRIP_THRESHOLD = 3; export const COOLDOWN_MS = 60_000; export function recordSuccess(state) { return { ...state, consecutiveFailures: 0, trippedAt: null }; } export function recordFailure(state, now, opts) { let working = state; if (working.trippedAt !== null && now >= working.trippedAt + COOLDOWN_MS) { working = { ...working, consecutiveFailures: 0, trippedAt: null }; } const next = { ...working, consecutiveFailures: working.consecutiveFailures + 1, }; if (next.consecutiveFailures >= FAILURE_TRIP_THRESHOLD && next.trippedAt === null) { next.trippedAt = now; opts?.onTrip?.({ tripped: true, failureCount: next.consecutiveFailures, trippedAt: now, reason: opts.route ?? "threshold", }); } return next; } export function isTripped(state, now) { return state.trippedAt !== null && now < state.trippedAt + COOLDOWN_MS; } /** * A tripped breaker halts *automatic* compaction only. An explicit `/compact` is the * user's escape hatch - and on an SDK-owned lane it is the documented recovery from a * rejected model downswitch - so refusing it during the cooldown would strand the very * session the recovery exists for. Manual failures are still recorded (see the * `ownsCompaction` failure-accounting site in `index.ts`), so they count toward the * trip that protects the automatic routes. */ export function shouldBypass(_state, opts) { if (opts?.manual === true) return true; if (opts?.reason === "manual") return true; return false; } //# sourceMappingURL=circuit-breaker.js.map