PEP-23: inAutonomyQuietHours (PEP-29 owns inQuietHours for user notification prefs)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
5465238d1a
commit
4c001ba5f6
@ -131,7 +131,7 @@ export async function setAutonomy(db: Db, projectId: number, patch: AutonomyPatc
|
||||
}
|
||||
|
||||
/** True inside the quiet hours (local time of the machine Peppa runs on). */
|
||||
export function inQuietHours(s: Pick<AutonomySettings, "quietFrom" | "quietTo">, now: Date): boolean {
|
||||
export function inAutonomyQuietHours(s: Pick<AutonomySettings, "quietFrom" | "quietTo">, now: Date): boolean {
|
||||
if (s.quietFrom == null || s.quietTo == null || s.quietFrom === s.quietTo) return false;
|
||||
const h = now.getHours();
|
||||
return s.quietFrom < s.quietTo ? h >= s.quietFrom && h < s.quietTo : h >= s.quietFrom || h < s.quietTo;
|
||||
|
||||
@ -11,7 +11,7 @@ import {
|
||||
getAutonomy,
|
||||
getSetting,
|
||||
giteaForBot,
|
||||
inQuietHours,
|
||||
inAutonomyQuietHours,
|
||||
listProjects,
|
||||
listSessions,
|
||||
listTasks,
|
||||
@ -269,7 +269,7 @@ async function dispatch(db: Db, project: Project, a: AutonomySettings, now: Date
|
||||
}
|
||||
|
||||
if (!a.idlePush || working.length > 0 || !backlog.length || limited || state.questionId) return;
|
||||
if (inQuietHours(a, now)) return;
|
||||
if (inAutonomyQuietHours(a, now)) return;
|
||||
if ((state.snoozeUntil ?? 0) > now.getTime()) return;
|
||||
if (state.at && now.getTime() - state.at < a.idlePushHours * 3_600_000) return;
|
||||
await offerStory(db, project, backlog[0]!, now);
|
||||
|
||||
@ -58,10 +58,10 @@ describe("autonomy settings", () => {
|
||||
|
||||
test("quiet hours wrap over midnight", () => {
|
||||
const q = { quietFrom: 22, quietTo: 9 };
|
||||
assert.equal(core.inQuietHours(q, new Date(2026, 10, 14, 23, 30)), true);
|
||||
assert.equal(core.inQuietHours(q, new Date(2026, 10, 14, 8, 59)), true);
|
||||
assert.equal(core.inQuietHours(q, new Date(2026, 10, 14, 12, 0)), false);
|
||||
assert.equal(core.inQuietHours({ quietFrom: null, quietTo: null }, new Date(2026, 10, 14, 23)), false);
|
||||
assert.equal(core.inAutonomyQuietHours(q, new Date(2026, 10, 14, 23, 30)), true);
|
||||
assert.equal(core.inAutonomyQuietHours(q, new Date(2026, 10, 14, 8, 59)), true);
|
||||
assert.equal(core.inAutonomyQuietHours(q, new Date(2026, 10, 14, 12, 0)), false);
|
||||
assert.equal(core.inAutonomyQuietHours({ quietFrom: null, quietTo: null }, new Date(2026, 10, 14, 23)), false);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user