UNPKG

@code-yeongyu/senpi

Version:

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

34 lines • 1.4 kB
export class SessionReapScheduler { constructor(deps) { this.scheduled = new Map(); this.deps = deps; } arm(senpiSessionId, generation, delayMs = this.deps.idleTtlMs) { const token = Symbol("session-reap"); const handle = this.deps.scheduleTimer(() => this.fire(senpiSessionId, generation, token), delayMs); this.scheduled.set(senpiSessionId, { generation, token, handle }); handle.unref(); } cancel(senpiSessionId, generation) { const scheduled = this.scheduled.get(senpiSessionId); if (!scheduled || scheduled.generation !== generation) return; scheduled.handle.cancel(); this.scheduled.delete(senpiSessionId); } fire(senpiSessionId, generation, token) { const scheduled = this.scheduled.get(senpiSessionId); if (!scheduled || scheduled.generation !== generation || scheduled.token !== token) return; this.scheduled.delete(senpiSessionId); const candidate = this.deps.candidate(senpiSessionId, generation); if (!candidate) return; const remaining = candidate.lastUsedAt + this.deps.idleTtlMs - this.deps.now(); if (remaining <= 0) this.deps.expire(senpiSessionId); else this.arm(senpiSessionId, generation, remaining); } } //# sourceMappingURL=session-reaper.js.map