/**
 * Live-session metadata publisher as a supervised periodic service.
 *
 * This is the single daemon-owned writer behind `sessions watch`: consumers
 * announce reader presence, and the service publishes an incremental journal
 * snapshot immediately on the idle->active edge and every 15 seconds while a
 * reader remains. Callers consume the row; they do not run their own gather.
 */
import { runActiveSessionsWarmTick } from '../daemon-ticks.js';
import { watchActiveSessionsReaderPresence } from '../session/session-cache.js';
import { BasePeriodicService } from './service.js';
const SESSION_STATE_TICK_MS = 15_000;
const SESSION_STATE_DEADLINE_MS = 30_000;
export class SessionStateService extends BasePeriodicService {
    wake;
    id = 'session-state';
    intervalMs = SESSION_STATE_TICK_MS;
    deadlineMs = SESSION_STATE_DEADLINE_MS;
    stopReaderWatch = null;
    constructor(wake) {
        super();
        this.wake = wake;
    }
    async onStart(_ctx) {
        this.stopReaderWatch = watchActiveSessionsReaderPresence(this.wake);
    }
    async onStop() {
        this.stopReaderWatch?.();
        this.stopReaderWatch = null;
    }
    async onTick(_ctx) {
        await runActiveSessionsWarmTick();
    }
}
