файл пакета→ .shtukbase/packages/alarms/checks/l01_alarm.ts
checks/l01_alarm.ts
36 строк, 2.2 КБ.
Файл как есть в пакете: код и комментарии в нём не переводятся.
- // ALR-R01. An alarm says what fired and how it ended: type Alarm, a watch name, a time it was found; a closed or
- // dismissed alarm names who or what closed it and when, not before it was found.
- import { main } from '../../collections/checks/lib/runner.ts';
- import { type Project, type Result, addr, has, pageExists, phase, recordsOf, target, text, time } from '../../agents/lib/factlib.ts';
- export const RULE = {
- id: 'ALR-R01', title: 'An alarm says what fired and how it ended',
- scope: 'all alarms',
- };
- export function check(p: Project, res: Result): void {
- const recs = recordsOf(p, 'ALARM');
- res.scope = recs.map((r) => addr(r.id));
- res.scopeText = `alarms ${p.coll('ALARM') || '—'} (${recs.length})`;
- if (!res.part('alarms', p.coll('ALARM') ? null : 'no alarms collection')) return;
- for (const r of recs) {
- const at = addr(r.id);
- if (text(r.fm.type) !== 'Alarm') res.hole(at, `type "${text(r.fm.type) || '—'}", not Alarm`, 'set type: Alarm', 'bad-type');
- if (!has(r, 'watch')) res.hole(at, 'no watcher named (watch)', 'write watch: a short name of the watcher, for example disk-low', 'no-watch');
- const found = time(r.fm.foundAt);
- if (found === null) res.hole(at, `time "${text(r.fm.foundAt) || '—'}" is not an ISO time`, 'write foundAt: 2026-11-28T03:00:00Z', 'no-found');
- if (has(r, 'foundBy')) {
- const t = target(r, r.fm.foundBy);
- if (!t || !pageExists(p, t)) res.hole(at, `foundBy points to ${t ?? text(r.fm.foundBy)}, but there is no such page`, 'fix the foundBy link', 'missing-finder');
- }
- const st = phase(r.fm.status);
- if (st === 'closed' || st === 'dismissed') {
- if (!has(r, 'closedBy')) res.hole(at, `the alarm is ${st === 'closed' ? 'closed' : 'dismissed'}, but by whom is not said`, 'write closedBy: who or what, and why', 'no-closer');
- const closed = time(r.fm.closedAt);
- if (closed === null) res.hole(at, `no closing time "${text(r.fm.closedAt) || '—'}"`, 'write closedAt: an ISO time', 'no-closed-at');
- else if (found !== null && closed < found) res.hole(at, `closed (${text(r.fm.closedAt)}) before it was found (${text(r.fm.foundAt)})`, 'fix foundAt or closedAt', 'closed-before-found');
- }
- }
- }
- if (import.meta.main) main({ RULE, check });