/** * [WHO]: SchedulerLockOptions, tryAcquireSchedulerLock, releaseSchedulerLock * [FROM]: Depends on node:fs/promises, node:path * [TO]: Consumed by ./cron-scheduler, ./index * [HERE]: extensions/builtin/loop/cron/cron-tasks-lock.ts - scheduler lease lock for scheduled_tasks.json * * Scheduler lease lock for /cron/scheduled_tasks.lock. * * Modeled on Claude Code's src/utils/cronTasksLock.ts. When multiple Catui * sessions share the same agent dir, only one should drive the cron * scheduler. The first session to acquire this lock becomes the scheduler; * others stay passive and periodically probe the lock. If the owner dies * (PID no longer running), a passive session takes over. * * Pattern mirrors computerUseLock.ts: O_EXCL atomic create, PID liveness * probe, stale-lock recovery, cleanup-on-exit. */ /** * Options for callers that don't have bootstrap state. * lockIdentity should be stable for the lifetime of one process. */ export type SchedulerLockOptions = { dir?: string; lockIdentity?: string; }; /** * Try to acquire the scheduler lock for the current session. * Returns true on success, false if another live session holds it. * * Uses O_EXCL ('wx') for atomic test-and-set. If the file exists: * - Already ours → true (idempotent re-acquire) * - Another live PID → false * - Stale (PID dead / corrupt) → unlink and retry exclusive create once * * If two sessions race to recover a stale lock, only one create succeeds. */ export declare function tryAcquireSchedulerLock(opts: SchedulerLockOptions, sessionId: string): Promise; /** * Release the scheduler lock if the current session owns it. */ export declare function releaseSchedulerLock(opts: SchedulerLockOptions, sessionId: string): Promise;