feat: usage-alignment hold (04-08 KST daily + one-off hold until a set time)

Bring back the dawn gap that keeps Claude's 5h windows on the primer
slots (08-13, 13-18, 18-23, 23-04): it was dropped by the 2026-06-08
upstream merge (1dd948a).

- usage-alignment-hold.ts: hold during 04:00-08:00 KST, or until the ISO
  time in router_state `usage_alignment_hold_until` (ignored once past,
  so only the daily gap remains). A one-off end inside the gap runs on to
  08:00.
- Claude turns during a hold pause through the existing usage-pause path
  (messages kept, room resumed at the hold end) with an alignment notice.
  The stored pause is marked alignmentOnly so it does not act as an
  account-wide usage limit.
- Due Claude scheduled tasks stay due until the hold ends (Codex and
  GitHub CI watchers are not held).
- Urgent bypass like the old gate: a human @-mention lets that room run
  until the hold ends.
- Tests stub the wall-clock hold in test/vitest-env.ts so the suite does
  not pause when run between 04 and 08 KST.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Codex
2026-10-16 05:54:39 +09:00
parent 9dc5d9ea70
commit f944f97e54
13 changed files with 547 additions and 21 deletions

View File

@@ -29,6 +29,12 @@ interface ClaudeUsagePauseState {
resetKnown: boolean;
/** chatJid -> ISO time the room was paused. */
rooms: Record<string, string>;
/**
* Set while every room was paused only by the usage-alignment hold
* (usage-alignment-hold.ts), not by a real limit. Such a pause does not
* block other rooms; the hold itself is re-checked on every run.
*/
alignmentOnly?: boolean;
}
export interface ActiveClaudeUsagePause {
@@ -61,6 +67,8 @@ export function pauseRoomForClaudeUsage(args: {
chatJid: string;
resumeAt: Date;
resetKnown: boolean;
/** Paused by the usage-alignment hold, not by a usage limit. */
alignment?: boolean;
now?: Date;
}): ActiveClaudeUsagePause {
const now = args.now ?? new Date();
@@ -71,6 +79,9 @@ export function pauseRoomForClaudeUsage(args: {
until: keepExisting ? state.until : args.resumeAt.toISOString(),
resetKnown: keepExisting ? state.resetKnown : args.resetKnown,
rooms: { ...(state?.rooms ?? {}) },
alignmentOnly:
args.alignment === true &&
(state === null || state.alignmentOnly === true),
};
next.rooms[args.chatJid] ??= now.toISOString();
writeState(next);
@@ -86,7 +97,7 @@ export function getActiveClaudeUsagePause(
nowMs: number = Date.now(),
): ActiveClaudeUsagePause | null {
const state = readState();
if (!state) return null;
if (!state || state.alignmentOnly) return null;
const until = new Date(state.until);
return until.getTime() > nowMs
? { until, resetKnown: state.resetKnown }
@@ -97,6 +108,12 @@ export function isRoomPausedForClaudeUsage(chatJid: string): boolean {
return Boolean(readState()?.rooms[chatJid]);
}
/** True when the room is paused and no usage limit is involved. */
export function isRoomPausedOnlyForAlignment(chatJid: string): boolean {
const state = readState();
return Boolean(state?.alignmentOnly && state.rooms[chatJid]);
}
/** Drop a room from the pause (the user stopped its work). */
export function releaseRoomFromClaudeUsagePause(chatJid: string): boolean {
const state = readState();