@dreamforgestudiollc/emet 0.2.6 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +10 -0
- package/CHANGELOG.md +26 -1
- package/README.md +34 -8
- package/areas/emet.md +18 -0
- package/areas/garden.md +18 -0
- package/areas/health.md +18 -0
- package/areas/home.md +18 -0
- package/areas/learning.md +18 -0
- package/areas/state.md +18 -0
- package/docs/DEPLOY.md +32 -1
- package/docs/DEVELOPMENT-PRACTICES.md +26 -0
- package/docs/ERROR-CODES-SPEC.md +43 -0
- package/docs/ERROR-CODES.md +332 -0
- package/docs/GUIDED-SETUP.md +16 -0
- package/docs/PERMISSIONS.md +8 -5
- package/docs/ROADMAP.md +10 -10
- package/docs/SETUP.md +115 -12
- package/package.json +4 -2
- package/server.json +7 -3
- package/src/aleph.js +16 -10
- package/src/annotations.js +8 -3
- package/src/atlas-role.js +8 -3
- package/src/attribution.js +12 -12
- package/src/conformance.js +6 -4
- package/src/database.js +28 -12
- package/src/dispatch.js +33 -16
- package/src/error-codes.js +394 -0
- package/src/error-log.js +273 -0
- package/src/error-report.js +245 -0
- package/src/floor.js +6 -4
- package/src/gaps.js +2 -2
- package/src/gem-check.js +27 -26
- package/src/http-remote.js +2 -1
- package/src/index.js +1 -0
- package/src/invites.js +6 -5
- package/src/layers.js +8 -7
- package/src/mongo-connect.js +5 -0
- package/src/oauth-provider.js +28 -27
- package/src/pages.js +806 -0
- package/src/persons.js +2 -1
- package/src/provenance.js +10 -10
- package/src/rune-dispatch.js +10 -10
- package/src/session-graph.js +16 -15
- package/src/session.js +1 -1
- package/src/setup.js +21 -17
- package/src/startup-pages.js +3 -2
- package/src/startup-payload.js +3 -2
- package/src/subkey-store.js +3 -2
- package/src/tools.js +254 -177
- package/src/validation.js +61 -52
- package/src/version.js +1 -1
- package/templates/AREA.md +35 -0
- package/templates/INDEX.md +7 -6
- package/templates/PROCEDURE.md +1 -1
- package/templates/SEED.md +2 -2
- package/templates/STAGING.md +1 -1
- package/templates/THREAD.md +1 -1
package/src/pages.js
ADDED
|
@@ -0,0 +1,806 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EMET - Enduring Memory & Epistemic Tiers
|
|
3
|
+
* Copyright (c) 2026 Dreamforge Studio LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the MIT License - see LICENSE
|
|
6
|
+
*
|
|
7
|
+
* Topic pages. A page is a view computed from current records. It is not a
|
|
8
|
+
* record: nothing in this module writes, the result is never stored, and it
|
|
9
|
+
* is never something recall can return. The area document (areas/<slug>.md)
|
|
10
|
+
* is the selector. It names what to look at. It does not state what is true.
|
|
11
|
+
*
|
|
12
|
+
* Read-only. The write-path invariant covers this file: no write verb here.
|
|
13
|
+
* Lint flags. It does not revise, retire, or accept anything.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { connectMongo } from './mongo-connect.js';
|
|
17
|
+
import { MONGODB_URI, MONGODB_DB, COLLECTION_PREFIX, DatabaseError } from './database.js';
|
|
18
|
+
import { LAYERS } from './layers.js';
|
|
19
|
+
import { classifyRow } from './gaps.js';
|
|
20
|
+
import { parseMetadata } from './metadata.js';
|
|
21
|
+
import { ValidationError } from './validation.js';
|
|
22
|
+
import { currentActor, getPerson } from './persons.js';
|
|
23
|
+
import { setting } from './env.js';
|
|
24
|
+
|
|
25
|
+
export const DEFAULT_STALENESS_DAYS = 30;
|
|
26
|
+
export const DEFAULT_ITEM_CAP = 40;
|
|
27
|
+
export const PAGE_LINT_CLASSES = Object.freeze([
|
|
28
|
+
'contradictions',
|
|
29
|
+
'superseded_but_current',
|
|
30
|
+
'unsourced',
|
|
31
|
+
'duplicates',
|
|
32
|
+
'broken_links',
|
|
33
|
+
'long_unconfirmed'
|
|
34
|
+
]);
|
|
35
|
+
|
|
36
|
+
const GROUPS = Object.freeze([
|
|
37
|
+
['status', 'Status'],
|
|
38
|
+
['open', 'Open'],
|
|
39
|
+
['decisions', 'Decisions'],
|
|
40
|
+
['recent', 'Recent']
|
|
41
|
+
]);
|
|
42
|
+
|
|
43
|
+
const SEP = ' · ';
|
|
44
|
+
|
|
45
|
+
function meta(row) {
|
|
46
|
+
return parseMetadata(row && row.metadata) || {};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function registry() {
|
|
50
|
+
return String(setting('SOURCE_TAGS') ?? '').split(',').map((s) => s.trim()).filter(Boolean);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Unix seconds. Milliseconds and ISO dates are accepted. Null when absent. */
|
|
54
|
+
export function toSec(value) {
|
|
55
|
+
if (value == null || value === '') return null;
|
|
56
|
+
if (value instanceof Date) return value.getTime() / 1000;
|
|
57
|
+
if (typeof value === 'number' && Number.isFinite(value)) return value > 1e12 ? value / 1000 : value;
|
|
58
|
+
const s = String(value).trim();
|
|
59
|
+
if (/^\d{9,12}(\.\d+)?$/.test(s)) {
|
|
60
|
+
const n = Number(s);
|
|
61
|
+
return n > 1e12 ? n / 1000 : n;
|
|
62
|
+
}
|
|
63
|
+
const ms = Date.parse(s);
|
|
64
|
+
return Number.isNaN(ms) ? null : ms / 1000;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function parseAsOf(raw) {
|
|
68
|
+
if (raw == null || raw === '') return null;
|
|
69
|
+
const sec = toSec(raw);
|
|
70
|
+
if (sec == null) throw new ValidationError('as_of', 'emet_page: as_of must be an ISO date or unix seconds.', { code: 'EMET-PAGE-001' });
|
|
71
|
+
return sec;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function ymd(sec) {
|
|
75
|
+
return new Date(sec * 1000).toISOString().slice(0, 10);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function isoWeek(date) {
|
|
79
|
+
const d = new Date(Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate()));
|
|
80
|
+
const day = d.getUTCDay() || 7;
|
|
81
|
+
d.setUTCDate(d.getUTCDate() + 4 - day);
|
|
82
|
+
const yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
|
|
83
|
+
const week = Math.ceil((((d - yearStart) / 86400000) + 1) / 7);
|
|
84
|
+
return `${d.getUTCFullYear()}-W${String(week).padStart(2, '0')}`;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function isAreaDoc(doc_id) {
|
|
88
|
+
return typeof doc_id === 'string' && doc_id.startsWith('areas/');
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function areaSlug(doc_id) {
|
|
92
|
+
const m = /^areas\/([a-z0-9]+(?:-[a-z0-9]+)*)\.md$/.exec(String(doc_id || ''));
|
|
93
|
+
return m ? m[1] : null;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function localOwner(actor) {
|
|
97
|
+
return actor.transport === 'stdio' || (actor.transport !== 'http' && !actor.personId);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Area documents are owner-only writes. Stdio, and an in-process actor with
|
|
102
|
+
* no person id, is the owner. An HTTP login must be the person whose role
|
|
103
|
+
* is owner.
|
|
104
|
+
*/
|
|
105
|
+
export async function assertAreaOwner(db, tool) {
|
|
106
|
+
const actor = currentActor();
|
|
107
|
+
if (localOwner(actor)) return;
|
|
108
|
+
const person = actor.personId ? await getPerson(db, actor.personId) : null;
|
|
109
|
+
if (!person || person.role !== 'owner') {
|
|
110
|
+
throw new ValidationError(`${tool}: only the owner can create or edit an area document. Nothing was written.`, { code: 'EMET-PAGE-002' });
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
async function assertPageOwner(db, tool) {
|
|
115
|
+
const actor = currentActor();
|
|
116
|
+
if (localOwner(actor)) return;
|
|
117
|
+
const person = actor.personId ? await getPerson(db, actor.personId) : null;
|
|
118
|
+
if (!person || person.role !== 'owner') {
|
|
119
|
+
throw new ValidationError(`${tool}: only the owner can read topic pages.`, { code: 'EMET-PAGE-003' });
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function uri() {
|
|
124
|
+
return process.env.MONGODB_URI || MONGODB_URI;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
async function withDb(fn) {
|
|
128
|
+
const u = uri();
|
|
129
|
+
if (!u) throw new DatabaseError('MONGODB_URI is not set; cannot read topic pages.', 'emet_page', { code: 'EMET-DB-001' });
|
|
130
|
+
const client = await connectMongo(u, { serverSelectionTimeoutMS: 15000 });
|
|
131
|
+
try {
|
|
132
|
+
return await fn(client.db(process.env.MONGODB_DB || MONGODB_DB));
|
|
133
|
+
} finally {
|
|
134
|
+
await client.close();
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function sectionBody(text, num) {
|
|
139
|
+
const re = new RegExp(`^##[ \\t]*§${num}\\b.*$`, 'm');
|
|
140
|
+
const m = re.exec(String(text || ''));
|
|
141
|
+
if (!m) return String(text || '');
|
|
142
|
+
const rest = text.slice(m.index + m[0].length);
|
|
143
|
+
const next = rest.search(/^##[ \t]/m);
|
|
144
|
+
return next === -1 ? rest : rest.slice(0, next);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function boldField(text, label) {
|
|
148
|
+
const re = new RegExp(`^\\s*[-*]?\\s*\\*\\*${label}:\\*\\*\\s*(.*)$`, 'im');
|
|
149
|
+
const m = re.exec(String(text || ''));
|
|
150
|
+
return m ? m[1].trim() : '';
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function lineValue(text, label) {
|
|
154
|
+
const re = new RegExp(`^\\s*[-*]?\\s*${label}\\s*:\\s*(.+)$`, 'im');
|
|
155
|
+
const m = re.exec(String(text || ''));
|
|
156
|
+
return m ? m[1].replace(/`/g, '').trim() : '';
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function listField(raw) {
|
|
160
|
+
if (raw == null) return [];
|
|
161
|
+
const s = String(raw).trim();
|
|
162
|
+
if (!s || /^(any|none|n\/a)$/i.test(s)) return [];
|
|
163
|
+
return s.split(',').map((x) => x.trim()).filter(Boolean);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* The selector an area document holds. The page body is not in here.
|
|
168
|
+
* A missing staleness window is 30 days. A missing cap is 40.
|
|
169
|
+
*/
|
|
170
|
+
export function parseArea(content, doc_id) {
|
|
171
|
+
const text = String(content || '');
|
|
172
|
+
const slug = areaSlug(doc_id) || lineValue(sectionBody(text, '0'), 'Slug');
|
|
173
|
+
const title = lineValue(sectionBody(text, '0'), 'Title') || slug;
|
|
174
|
+
const body = sectionBody(text, '1');
|
|
175
|
+
const layers = listField(boldField(body, 'Layers')).map((s) => s.toLowerCase()).filter((l) => LAYERS.includes(l));
|
|
176
|
+
const stalenessRaw = Number(String(boldField(body, 'Staleness days') || '').trim());
|
|
177
|
+
const capRaw = Number(String(boldField(body, 'Item cap') || '').trim());
|
|
178
|
+
return {
|
|
179
|
+
slug,
|
|
180
|
+
title,
|
|
181
|
+
doc_id,
|
|
182
|
+
layers,
|
|
183
|
+
tags: listField(boldField(body, 'Tags')).map((t) => t.toLowerCase()),
|
|
184
|
+
keywords: listField(boldField(body, 'Keywords')),
|
|
185
|
+
prefixes: listField(boldField(body, 'Doc id prefixes')),
|
|
186
|
+
clients: listField(boldField(body, 'Source clients')).map((c) => c.toLowerCase()),
|
|
187
|
+
staleness_days: Number.isFinite(stalenessRaw) && stalenessRaw >= 1 ? Math.min(3650, Math.floor(stalenessRaw)) : DEFAULT_STALENESS_DAYS,
|
|
188
|
+
item_cap: Number.isFinite(capRaw) && capRaw >= 1 ? Math.min(200, Math.floor(capRaw)) : DEFAULT_ITEM_CAP
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export function clientOf(row) {
|
|
193
|
+
const md = meta(row);
|
|
194
|
+
const raw = md.source ?? md.client ?? row.client ?? row.updated_by ?? '';
|
|
195
|
+
const client = String(raw).trim().replace(/[·\]]/g, ' ').replace(/\s+/g, ' ').trim();
|
|
196
|
+
return client || null;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export function citeMemory(row) {
|
|
200
|
+
if (!row || row.id == null || row.id === '') return null;
|
|
201
|
+
if (!row.layer || !LAYERS.includes(row.layer)) return null;
|
|
202
|
+
const client = clientOf(row);
|
|
203
|
+
if (!client) return null;
|
|
204
|
+
const sec = toSec(row.timestamp);
|
|
205
|
+
if (sec == null) return null;
|
|
206
|
+
return `[mem:${row.id}${SEP}${row.layer}${SEP}${client}${SEP}${ymd(sec)}]`;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export function citeDoc(doc) {
|
|
210
|
+
if (!doc || !doc.doc_id) return null;
|
|
211
|
+
const version = Number(doc.version);
|
|
212
|
+
if (!Number.isFinite(version)) return null;
|
|
213
|
+
return `[doc:${doc.doc_id}@v${version}]`;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function tagsOf(row) {
|
|
217
|
+
const md = meta(row);
|
|
218
|
+
const raw = Array.isArray(md.tags) ? md.tags : (Array.isArray(row.tags) ? row.tags : []);
|
|
219
|
+
return raw.map((t) => String(t).trim().toLowerCase()).filter(Boolean);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function endMarks(row) {
|
|
223
|
+
const md = meta(row);
|
|
224
|
+
const superseded = (row.superseded_by != null && row.superseded_by !== '') || (md.superseded_by != null && md.superseded_by !== '');
|
|
225
|
+
const retired = row.retired === true || row.is_live === false || row.retired_at != null || md.retired_at != null;
|
|
226
|
+
return {
|
|
227
|
+
superseded,
|
|
228
|
+
supersededAt: toSec(row.superseded_at ?? md.superseded_at),
|
|
229
|
+
retired,
|
|
230
|
+
retiredAt: toSec(row.retired_at ?? md.retired_at)
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function timeOf(row) {
|
|
235
|
+
return toSec(row.timestamp ?? row.updated_at);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Ended, for the view at `at`. A missing end date means the record is not
|
|
240
|
+
* current now, and a past view cannot treat it as already ended.
|
|
241
|
+
*/
|
|
242
|
+
function endedBefore(ended, endedAt, asOf, at) {
|
|
243
|
+
if (!ended) return false;
|
|
244
|
+
if (endedAt == null) return asOf == null;
|
|
245
|
+
return endedAt <= at;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/** Current at `asOf` (unix seconds). Null asOf means now. */
|
|
249
|
+
export function currentAt(row, asOf, nowSec = Date.now() / 1000) {
|
|
250
|
+
const sec = timeOf(row);
|
|
251
|
+
if (asOf != null && (sec == null || sec > asOf)) return false;
|
|
252
|
+
const at = asOf == null ? nowSec : asOf;
|
|
253
|
+
const end = endMarks(row);
|
|
254
|
+
if (endedBefore(end.superseded, end.supersededAt, asOf, at)) return false;
|
|
255
|
+
if (endedBefore(end.retired, end.retiredAt, asOf, at)) return false;
|
|
256
|
+
return true;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* The document revision in force at `asOf`. Candidates are the current row
|
|
261
|
+
* and documents_history rows for the same id that had been written by then.
|
|
262
|
+
* The newest of those is the one in force: latest updated_at, then the
|
|
263
|
+
* highest version, so an older row with no archive date does not stay
|
|
264
|
+
* current once a later revision exists. If that newest revision was
|
|
265
|
+
* archived at or before asOf, the document is absent. The area selector
|
|
266
|
+
* stays the current area document.
|
|
267
|
+
*/
|
|
268
|
+
function revisionAt(doc, history, asOf) {
|
|
269
|
+
if (!doc || asOf == null) return doc;
|
|
270
|
+
const candidates = [doc, ...(history || []).filter((row) => row && row.doc_id === doc.doc_id)];
|
|
271
|
+
const writtenByThen = candidates.filter((row) => {
|
|
272
|
+
const written = toSec(row.updated_at ?? row.timestamp);
|
|
273
|
+
return written != null && written <= asOf;
|
|
274
|
+
});
|
|
275
|
+
if (!writtenByThen.length) return null;
|
|
276
|
+
writtenByThen.sort((a, b) => {
|
|
277
|
+
const byTime = (toSec(b.updated_at ?? b.timestamp) || 0) - (toSec(a.updated_at ?? a.timestamp) || 0);
|
|
278
|
+
if (byTime) return byTime;
|
|
279
|
+
return (Number(b.version) || 0) - (Number(a.version) || 0);
|
|
280
|
+
});
|
|
281
|
+
const newest = writtenByThen[0];
|
|
282
|
+
const archived = toSec(newest.archived_at);
|
|
283
|
+
if (archived != null && archived <= asOf) return null;
|
|
284
|
+
return newest;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function confirmedSec(row) {
|
|
288
|
+
const md = meta(row);
|
|
289
|
+
return toSec(md.confirmed_at) ?? toSec(md.revised_at) ?? toSec(row.timestamp);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
export function staleAt(row, days, asOf, nowSec) {
|
|
293
|
+
const confirmed = confirmedSec(row);
|
|
294
|
+
if (confirmed == null) return true;
|
|
295
|
+
const at = asOf == null ? nowSec : asOf;
|
|
296
|
+
return confirmed < at - days * 86400;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
export function groupOf(row) {
|
|
300
|
+
const md = meta(row);
|
|
301
|
+
const explicit = String(md.page_group || '').toLowerCase();
|
|
302
|
+
if (explicit === 'status' || explicit === 'open' || explicit === 'decisions' || explicit === 'recent') return explicit;
|
|
303
|
+
const tags = tagsOf(row);
|
|
304
|
+
const status = String(md.status || '').toLowerCase();
|
|
305
|
+
if (tags.includes('decision') || tags.includes('decisions') || md.kind === 'decision') return 'decisions';
|
|
306
|
+
if (tags.includes('open') || status === 'open' || status === 'waiting' || status === 'parked') return 'open';
|
|
307
|
+
if (row.layer === 'procedural') return 'decisions';
|
|
308
|
+
if (row.layer === 'episodic') return 'recent';
|
|
309
|
+
if (row.layer === 'working') return 'open';
|
|
310
|
+
return 'status';
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
function memoryMatches(row, selector) {
|
|
314
|
+
if (!selector.layers.length || !selector.layers.includes(row.layer)) return false;
|
|
315
|
+
const client = clientOf(row);
|
|
316
|
+
if (selector.clients.length && (!client || !selector.clients.includes(client.toLowerCase()))) return false;
|
|
317
|
+
if (!selector.tags.length && !selector.keywords.length) return true;
|
|
318
|
+
const tags = tagsOf(row);
|
|
319
|
+
if (selector.tags.some((t) => tags.includes(t))) return true;
|
|
320
|
+
const hay = `${row.content || ''} ${row.context || ''}`.toLowerCase();
|
|
321
|
+
return selector.keywords.some((k) => hay.includes(String(k).toLowerCase()));
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
function docMatches(doc, selector) {
|
|
325
|
+
if (!doc || !doc.doc_id || isAreaDoc(doc.doc_id)) return false;
|
|
326
|
+
if (!selector.prefixes.length) return false;
|
|
327
|
+
if (!selector.prefixes.some((p) => doc.doc_id.startsWith(p))) return false;
|
|
328
|
+
if (selector.clients.length) {
|
|
329
|
+
const client = String(doc.updated_by || doc.client || '').toLowerCase();
|
|
330
|
+
if (!selector.clients.includes(client)) return false;
|
|
331
|
+
}
|
|
332
|
+
return true;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
function oneLine(text) {
|
|
336
|
+
return String(text || '').replace(/\s+/g, ' ').trim();
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
function docClaims(content) {
|
|
340
|
+
const out = [];
|
|
341
|
+
for (const raw of String(content || '').split(/\r?\n/)) {
|
|
342
|
+
const line = raw.trim();
|
|
343
|
+
if (!line || line.startsWith('#')) continue;
|
|
344
|
+
if (/^\*\*(?:Template|Record) control:\*\*/.test(line)) continue;
|
|
345
|
+
if (line.startsWith('|') || /^[-|: ]+$/.test(line)) continue;
|
|
346
|
+
const text = oneLine(line.replace(/^[-*]\s+/, '').replace(/\*\*/g, ''));
|
|
347
|
+
if (text.length < 3) continue;
|
|
348
|
+
out.push(text);
|
|
349
|
+
if (out.length >= 12) break;
|
|
350
|
+
}
|
|
351
|
+
return out;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
function importanceOf(row) {
|
|
355
|
+
const n = Number(row.importance ?? meta(row).importance);
|
|
356
|
+
return Number.isFinite(n) ? n : 0.5;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
function byRank(a, b) {
|
|
360
|
+
const ia = importanceOf(a.row);
|
|
361
|
+
const ib = importanceOf(b.row);
|
|
362
|
+
if (ia !== ib) return ib - ia;
|
|
363
|
+
const ta = timeOf(a.row) ?? 0;
|
|
364
|
+
const tb = timeOf(b.row) ?? 0;
|
|
365
|
+
if (ta !== tb) return tb - ta;
|
|
366
|
+
return String(a.ref).localeCompare(String(b.ref));
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
function watermark(rows) {
|
|
370
|
+
let best = null;
|
|
371
|
+
for (const row of rows) {
|
|
372
|
+
const sec = timeOf(row);
|
|
373
|
+
if (sec == null) continue;
|
|
374
|
+
if (best == null || sec > best) best = sec;
|
|
375
|
+
}
|
|
376
|
+
return best == null ? null : new Date(best * 1000).toISOString();
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
function unknownEnd(row, asOf) {
|
|
380
|
+
if (asOf == null) return false;
|
|
381
|
+
const end = endMarks(row);
|
|
382
|
+
return (end.superseded && end.supersededAt == null) || (end.retired && end.retiredAt == null);
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
function renderMarkdown(selector, lines, history, computedAt, includeHistory, unknownEnds) {
|
|
386
|
+
const grouped = { status: [], open: [], decisions: [], recent: [] };
|
|
387
|
+
for (const line of lines) grouped[line.group].push(line);
|
|
388
|
+
const parts = [
|
|
389
|
+
`# ${selector.title}`,
|
|
390
|
+
'',
|
|
391
|
+
`Area \`${selector.slug}\`. Computed ${computedAt}. cache_hit: false.`,
|
|
392
|
+
''
|
|
393
|
+
];
|
|
394
|
+
for (const [key, heading] of GROUPS) {
|
|
395
|
+
parts.push(`## ${heading}`, '');
|
|
396
|
+
if (!grouped[key].length) parts.push('None.', '');
|
|
397
|
+
else {
|
|
398
|
+
for (const line of grouped[key]) {
|
|
399
|
+
parts.push(`- ${line.text}${line.stale ? ' (stale)' : ''} ${line.cite}`);
|
|
400
|
+
}
|
|
401
|
+
parts.push('');
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
if (unknownEnds.length) {
|
|
405
|
+
parts.push('## End date unknown', '', 'Superseded or retired, and the date they ended was not recorded. Not current.', '');
|
|
406
|
+
for (const line of unknownEnds) parts.push(`- ${line.text} (end date unknown) ${line.cite}`);
|
|
407
|
+
parts.push('');
|
|
408
|
+
}
|
|
409
|
+
if (includeHistory) {
|
|
410
|
+
parts.push('## History', '', 'Superseded and retired records. Not current.', '');
|
|
411
|
+
if (!history.length) parts.push('None.', '');
|
|
412
|
+
else {
|
|
413
|
+
for (const line of history) parts.push(`- ${line.text} (${line.ended}) ${line.cite}`);
|
|
414
|
+
parts.push('');
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
return parts.join('\n').replace(/\n+$/, '\n');
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* Pure page compiler. `memories` carry `layer`. `documents` are store rows.
|
|
422
|
+
* Nothing here is written back.
|
|
423
|
+
*/
|
|
424
|
+
export function compilePage(selector, memories, documents, { asOf = null, includeHistory = false, now = new Date(), revisions = [] } = {}) {
|
|
425
|
+
const nowSec = now.getTime() / 1000;
|
|
426
|
+
const matchedMem = memories.filter((row) => memoryMatches(row, selector));
|
|
427
|
+
const docsAt = asOf == null ? documents : documents.map((doc) => revisionAt(doc, revisions, asOf)).filter(Boolean);
|
|
428
|
+
const matchedDocs = docsAt.filter((doc) => docMatches(doc, selector));
|
|
429
|
+
const read = [...matchedMem, ...matchedDocs].filter((row) => {
|
|
430
|
+
if (asOf == null) return true;
|
|
431
|
+
const sec = timeOf(row);
|
|
432
|
+
return sec != null && sec <= asOf;
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
const dropped = [];
|
|
436
|
+
const current = [];
|
|
437
|
+
const history = [];
|
|
438
|
+
const unknownEnds = [];
|
|
439
|
+
|
|
440
|
+
for (const row of matchedMem) {
|
|
441
|
+
if (asOf != null) {
|
|
442
|
+
const sec = timeOf(row);
|
|
443
|
+
if (sec == null || sec > asOf) continue;
|
|
444
|
+
}
|
|
445
|
+
const cite = citeMemory(row);
|
|
446
|
+
const text = oneLine(row.content);
|
|
447
|
+
const ref = `${row.layer}#${row.id}`;
|
|
448
|
+
if (!cite || !text) {
|
|
449
|
+
dropped.push({ ref, text, reason: 'unsourced' });
|
|
450
|
+
continue;
|
|
451
|
+
}
|
|
452
|
+
const item = {
|
|
453
|
+
text,
|
|
454
|
+
cite,
|
|
455
|
+
stale: staleAt(row, selector.staleness_days, asOf, nowSec),
|
|
456
|
+
group: groupOf(row),
|
|
457
|
+
row,
|
|
458
|
+
ref
|
|
459
|
+
};
|
|
460
|
+
if (unknownEnd(row, asOf)) unknownEnds.push({ ...item, label: 'end date unknown' });
|
|
461
|
+
else if (currentAt(row, asOf, nowSec)) current.push(item);
|
|
462
|
+
else if (includeHistory) {
|
|
463
|
+
const end = endMarks(row);
|
|
464
|
+
history.push({ ...item, ended: end.retired && !end.superseded ? 'retired' : 'superseded', stale: false });
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
for (const doc of matchedDocs) {
|
|
469
|
+
if (asOf != null) {
|
|
470
|
+
const sec = timeOf(doc);
|
|
471
|
+
if (sec == null || sec > asOf) continue;
|
|
472
|
+
}
|
|
473
|
+
const cite = citeDoc(doc);
|
|
474
|
+
const claims = docClaims(doc.content);
|
|
475
|
+
if (!cite || !claims.length) {
|
|
476
|
+
dropped.push({ ref: `doc:${doc.doc_id}`, text: '', reason: 'unsourced' });
|
|
477
|
+
continue;
|
|
478
|
+
}
|
|
479
|
+
const stale = staleAt(doc, selector.staleness_days, asOf, nowSec);
|
|
480
|
+
const isCurrent = currentAt(doc, asOf, nowSec);
|
|
481
|
+
claims.forEach((text, i) => {
|
|
482
|
+
const item = { text, cite, stale, group: 'status', row: doc, ref: `doc:${doc.doc_id}@v${doc.version}#${i}` };
|
|
483
|
+
if (unknownEnd(doc, asOf)) unknownEnds.push({ ...item, label: 'end date unknown' });
|
|
484
|
+
else if (isCurrent) current.push(item);
|
|
485
|
+
else if (includeHistory) {
|
|
486
|
+
const end = endMarks(doc);
|
|
487
|
+
history.push({ ...item, ended: end.retired ? 'retired' : 'superseded', stale: false });
|
|
488
|
+
}
|
|
489
|
+
});
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
current.sort(byRank);
|
|
493
|
+
history.sort(byRank);
|
|
494
|
+
unknownEnds.sort(byRank);
|
|
495
|
+
const lines = current.slice(0, selector.item_cap).map(({ text, cite, stale, group, ref }) => ({ text, cite, stale, group, ref }));
|
|
496
|
+
const historyLines = history.slice(0, selector.item_cap).map(({ text, cite, ended, ref }) => ({ text, cite, ended, ref }));
|
|
497
|
+
const unknownLines = unknownEnds.slice(0, selector.item_cap).map(({ text, cite, label, ref }) => ({ text, cite, label, ref }));
|
|
498
|
+
const computed_at = now.toISOString();
|
|
499
|
+
return {
|
|
500
|
+
slug: selector.slug,
|
|
501
|
+
title: selector.title,
|
|
502
|
+
lines,
|
|
503
|
+
history: historyLines,
|
|
504
|
+
end_date_unknown: unknownLines,
|
|
505
|
+
dropped,
|
|
506
|
+
computed_at,
|
|
507
|
+
source_watermark: watermark(read),
|
|
508
|
+
cache_hit: false,
|
|
509
|
+
markdown: renderMarkdown(selector, lines, historyLines, computed_at, includeHistory, unknownLines)
|
|
510
|
+
};
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
async function loadCorpus(db) {
|
|
514
|
+
const memories = [];
|
|
515
|
+
for (const layer of LAYERS) {
|
|
516
|
+
const col = db.collection(`${COLLECTION_PREFIX}${layer}`);
|
|
517
|
+
for await (const row of col.find({})) memories.push({ ...row, layer });
|
|
518
|
+
}
|
|
519
|
+
const documents = [];
|
|
520
|
+
for await (const doc of db.collection('documents').find({})) documents.push(doc);
|
|
521
|
+
const history = [];
|
|
522
|
+
for await (const doc of db.collection('documents_history').find({})) history.push(doc);
|
|
523
|
+
return { memories, documents, history };
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
function liveAreas(documents) {
|
|
527
|
+
return documents.filter((doc) => areaSlug(doc.doc_id) && currentAt(doc, null));
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
function selectorFor(doc) {
|
|
531
|
+
return parseArea(doc.content, doc.doc_id);
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
function requireSlug(area, tool) {
|
|
535
|
+
const slug = String(area || '').trim();
|
|
536
|
+
if (!areaSlug(`areas/${slug}.md`)) {
|
|
537
|
+
throw new ValidationError('area', `${tool}: area must be a slug like "health".`, { code: 'EMET-PAGE-004' });
|
|
538
|
+
}
|
|
539
|
+
return slug;
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
export async function readPage({ area, as_of = null, include_history = false } = {}, now = new Date()) {
|
|
543
|
+
const slug = requireSlug(area, 'emet_page');
|
|
544
|
+
const asOf = parseAsOf(as_of);
|
|
545
|
+
return withDb(async (db) => {
|
|
546
|
+
await assertPageOwner(db, 'emet_page');
|
|
547
|
+
const { memories, documents, history } = await loadCorpus(db);
|
|
548
|
+
const doc = liveAreas(documents).find((d) => areaSlug(d.doc_id) === slug);
|
|
549
|
+
if (!doc) throw new ValidationError('area', `emet_page: no current area document areas/${slug}.md. The owner writes it with write_doc.`, { code: 'EMET-PAGE-005' });
|
|
550
|
+
const page = compilePage(selectorFor(doc), memories, documents, { asOf, includeHistory: include_history === true, now, revisions: history });
|
|
551
|
+
return {
|
|
552
|
+
area: slug,
|
|
553
|
+
title: page.title,
|
|
554
|
+
markdown: page.markdown,
|
|
555
|
+
lines: page.lines.map(({ text, cite, stale }) => ({ text, cite, stale })),
|
|
556
|
+
end_date_unknown: page.end_date_unknown.map(({ text, cite, label }) => ({ text, cite, label })),
|
|
557
|
+
...(include_history === true ? { history: page.history } : {}),
|
|
558
|
+
computed_at: page.computed_at,
|
|
559
|
+
source_watermark: page.source_watermark,
|
|
560
|
+
cache_hit: false
|
|
561
|
+
};
|
|
562
|
+
});
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
export async function listPages(now = new Date()) {
|
|
566
|
+
return withDb(async (db) => {
|
|
567
|
+
await assertPageOwner(db, 'emet_pages');
|
|
568
|
+
const { memories, documents } = await loadCorpus(db);
|
|
569
|
+
const areas = liveAreas(documents).map((doc) => {
|
|
570
|
+
const selector = selectorFor(doc);
|
|
571
|
+
const page = compilePage(selector, memories, documents, { now });
|
|
572
|
+
return {
|
|
573
|
+
area: selector.slug,
|
|
574
|
+
title: selector.title,
|
|
575
|
+
doc_id: doc.doc_id,
|
|
576
|
+
version: doc.version ?? null,
|
|
577
|
+
lines: page.lines.length,
|
|
578
|
+
stale: page.lines.filter((line) => line.stale).length,
|
|
579
|
+
last_source_change: page.source_watermark
|
|
580
|
+
};
|
|
581
|
+
}).sort((a, b) => a.area.localeCompare(b.area));
|
|
582
|
+
return { areas };
|
|
583
|
+
});
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
function pushFinding(findings, seen, finding) {
|
|
587
|
+
const key = `${finding.class}|${finding.area}|${[...finding.ids].sort().join(',')}`;
|
|
588
|
+
if (seen.has(key)) return;
|
|
589
|
+
seen.add(key);
|
|
590
|
+
findings.push(finding);
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
function normText(text) {
|
|
594
|
+
return oneLine(text).toLowerCase();
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
/**
|
|
598
|
+
* Flag only. `area` omitted lints every current area. Builds on classifyRow
|
|
599
|
+
* from gaps.js for unsourced assertions. Writes nothing.
|
|
600
|
+
*/
|
|
601
|
+
export async function lintPages({ area = null } = {}, now = new Date()) {
|
|
602
|
+
const only = area == null || area === '' ? null : requireSlug(area, 'emet_page_lint');
|
|
603
|
+
const nowSec = now.getTime() / 1000;
|
|
604
|
+
return withDb(async (db) => {
|
|
605
|
+
await assertPageOwner(db, 'emet_page_lint');
|
|
606
|
+
const { memories, documents } = await loadCorpus(db);
|
|
607
|
+
let areas = liveAreas(documents);
|
|
608
|
+
if (only) {
|
|
609
|
+
areas = areas.filter((doc) => areaSlug(doc.doc_id) === only);
|
|
610
|
+
if (!areas.length) throw new ValidationError('area', `emet_page_lint: no current area document areas/${only}.md.`, { code: 'EMET-PAGE-006' });
|
|
611
|
+
}
|
|
612
|
+
const memById = new Map();
|
|
613
|
+
for (const row of memories) {
|
|
614
|
+
const id = String(row.id);
|
|
615
|
+
if (!memById.has(id)) memById.set(id, []);
|
|
616
|
+
memById.get(id).push(row);
|
|
617
|
+
}
|
|
618
|
+
const docById = new Map(documents.map((doc) => [doc.doc_id, doc]));
|
|
619
|
+
const findings = [];
|
|
620
|
+
const seen = new Set();
|
|
621
|
+
const slugs = [];
|
|
622
|
+
|
|
623
|
+
for (const areaDoc of areas) {
|
|
624
|
+
const selector = selectorFor(areaDoc);
|
|
625
|
+
slugs.push(selector.slug);
|
|
626
|
+
const page = compilePage(selector, memories, documents, { now });
|
|
627
|
+
const matched = memories.filter((row) => memoryMatches(row, selector) && currentAt(row, null, nowSec));
|
|
628
|
+
|
|
629
|
+
for (const drop of page.dropped) {
|
|
630
|
+
pushFinding(findings, seen, {
|
|
631
|
+
class: 'unsourced',
|
|
632
|
+
ids: drop.ref ? [drop.ref] : [],
|
|
633
|
+
area: selector.slug,
|
|
634
|
+
detail: 'A page line had no source citation and was dropped.'
|
|
635
|
+
});
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
for (const row of matched) {
|
|
639
|
+
const ref = `${row.layer}#${row.id}`;
|
|
640
|
+
const gaps = classifyRow(row.layer, row, { registry: registry(), nowSec });
|
|
641
|
+
if (gaps.includes('unsourced_assertions') && citeMemory(row)) {
|
|
642
|
+
pushFinding(findings, seen, {
|
|
643
|
+
class: 'unsourced',
|
|
644
|
+
ids: [ref],
|
|
645
|
+
area: selector.slug,
|
|
646
|
+
detail: 'A current record in this area has no provenance pointer (emet_gaps unsourced_assertions).'
|
|
647
|
+
});
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
const MEM_REF = /mem:(\d+)/g;
|
|
652
|
+
const DOC_REF = /doc:([A-Za-z0-9_./-]+\.md)(?:@v(\d+))?/g;
|
|
653
|
+
for (const row of matched) {
|
|
654
|
+
const ref = `${row.layer}#${row.id}`;
|
|
655
|
+
const text = String(row.content || '');
|
|
656
|
+
for (const m of text.matchAll(MEM_REF)) {
|
|
657
|
+
const hits = memById.get(m[1]) || [];
|
|
658
|
+
if (!hits.length) {
|
|
659
|
+
pushFinding(findings, seen, {
|
|
660
|
+
class: 'broken_links',
|
|
661
|
+
ids: [ref, `mem:${m[1]}`],
|
|
662
|
+
area: selector.slug,
|
|
663
|
+
detail: `mem:${m[1]} does not resolve.`
|
|
664
|
+
});
|
|
665
|
+
} else if (hits.every((hit) => !currentAt(hit, null, nowSec))) {
|
|
666
|
+
pushFinding(findings, seen, {
|
|
667
|
+
class: 'superseded_but_current',
|
|
668
|
+
ids: [ref, ...hits.map((hit) => `${hit.layer}#${hit.id}`)],
|
|
669
|
+
area: selector.slug,
|
|
670
|
+
detail: `A current record claims mem:${m[1]}, which is superseded or retired.`
|
|
671
|
+
});
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
for (const m of text.matchAll(DOC_REF)) {
|
|
675
|
+
const target = docById.get(m[1]);
|
|
676
|
+
const version = m[2] != null ? Number(m[2]) : null;
|
|
677
|
+
if (!target || !currentAt(target, null, nowSec) && target.retired !== true && !target.retired_at) {
|
|
678
|
+
if (!target) {
|
|
679
|
+
pushFinding(findings, seen, {
|
|
680
|
+
class: 'broken_links',
|
|
681
|
+
ids: [ref, `doc:${m[1]}`],
|
|
682
|
+
area: selector.slug,
|
|
683
|
+
detail: `doc:${m[1]} does not resolve.`
|
|
684
|
+
});
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
if (target && !currentAt(target, null, nowSec)) {
|
|
688
|
+
pushFinding(findings, seen, {
|
|
689
|
+
class: 'superseded_but_current',
|
|
690
|
+
ids: [ref, `doc:${target.doc_id}@v${target.version}`],
|
|
691
|
+
area: selector.slug,
|
|
692
|
+
detail: `A current record claims ${m[1]}, which is retired.`
|
|
693
|
+
});
|
|
694
|
+
} else if (target && version != null && version !== Number(target.version)) {
|
|
695
|
+
pushFinding(findings, seen, {
|
|
696
|
+
class: 'broken_links',
|
|
697
|
+
ids: [ref, `doc:${m[1]}@v${version}`],
|
|
698
|
+
area: selector.slug,
|
|
699
|
+
detail: `doc:${m[1]}@v${version} does not resolve. The current version is v${target.version}.`
|
|
700
|
+
});
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
const bySubject = new Map();
|
|
706
|
+
for (const row of matched) {
|
|
707
|
+
const subject = String(meta(row).subject || '').trim().toLowerCase();
|
|
708
|
+
if (!subject) continue;
|
|
709
|
+
const claim = oneLine(meta(row).claim != null ? meta(row).claim : row.content);
|
|
710
|
+
if (!bySubject.has(subject)) bySubject.set(subject, []);
|
|
711
|
+
bySubject.get(subject).push({ ref: `${row.layer}#${row.id}`, claim });
|
|
712
|
+
}
|
|
713
|
+
for (const [subject, group] of bySubject) {
|
|
714
|
+
const claims = new Set(group.map((g) => g.claim));
|
|
715
|
+
if (claims.size > 1) {
|
|
716
|
+
pushFinding(findings, seen, {
|
|
717
|
+
class: 'contradictions',
|
|
718
|
+
ids: group.map((g) => g.ref),
|
|
719
|
+
area: selector.slug,
|
|
720
|
+
detail: `Current records disagree on "${subject}".`
|
|
721
|
+
});
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
const byText = new Map();
|
|
726
|
+
const currentItems = [
|
|
727
|
+
...matched.map((row) => ({ text: oneLine(row.content), ref: `${row.layer}#${row.id}` })),
|
|
728
|
+
...page.lines.filter((line) => line.ref.startsWith('doc:')).map((line) => ({ text: line.text, ref: line.ref }))
|
|
729
|
+
];
|
|
730
|
+
for (const item of currentItems) {
|
|
731
|
+
const key = normText(item.text);
|
|
732
|
+
if (!key) continue;
|
|
733
|
+
if (!byText.has(key)) byText.set(key, []);
|
|
734
|
+
const list = byText.get(key);
|
|
735
|
+
if (!list.includes(item.ref)) list.push(item.ref);
|
|
736
|
+
}
|
|
737
|
+
for (const [text, ids] of byText) {
|
|
738
|
+
if (ids.length < 2) continue;
|
|
739
|
+
pushFinding(findings, seen, {
|
|
740
|
+
class: 'duplicates',
|
|
741
|
+
ids,
|
|
742
|
+
area: selector.slug,
|
|
743
|
+
detail: `The same current line appears ${ids.length} times: ${text.slice(0, 80)}`
|
|
744
|
+
});
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
for (const row of matched) {
|
|
748
|
+
const status = meta(row).status;
|
|
749
|
+
const group = groupOf(row);
|
|
750
|
+
if (group !== 'status' && (status == null || status === '')) continue;
|
|
751
|
+
if (!staleAt(row, selector.staleness_days, null, nowSec)) continue;
|
|
752
|
+
if (!citeMemory(row)) continue;
|
|
753
|
+
pushFinding(findings, seen, {
|
|
754
|
+
class: 'long_unconfirmed',
|
|
755
|
+
ids: [`${row.layer}#${row.id}`],
|
|
756
|
+
area: selector.slug,
|
|
757
|
+
detail: `A status has not been confirmed or revised within ${selector.staleness_days} days.`
|
|
758
|
+
});
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
return { findings, areas: slugs, read_only: true };
|
|
763
|
+
});
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
/**
|
|
767
|
+
* The weekly summary for emet_initialize. Monday (UTC) carries counts.
|
|
768
|
+
* Other days name the cadence. Non-owners receive no findings. Nothing is stored.
|
|
769
|
+
*/
|
|
770
|
+
export async function pageLintDigest(now = new Date()) {
|
|
771
|
+
try {
|
|
772
|
+
const actor = currentActor();
|
|
773
|
+
if (!localOwner(actor)) {
|
|
774
|
+
const allowed = await withDb(async (db) => {
|
|
775
|
+
const person = actor.personId ? await getPerson(db, actor.personId) : null;
|
|
776
|
+
return !!(person && person.role === 'owner');
|
|
777
|
+
});
|
|
778
|
+
if (!allowed) return { cadence: 'weekly', included: false, owner_only: true };
|
|
779
|
+
}
|
|
780
|
+
const week = isoWeek(now);
|
|
781
|
+
if (now.getUTCDay() !== 1) {
|
|
782
|
+
return {
|
|
783
|
+
cadence: 'weekly',
|
|
784
|
+
week,
|
|
785
|
+
included: false,
|
|
786
|
+
note: 'The weekly page-lint summary is included on Monday (UTC). emet_page_lint reads the same checks on demand.'
|
|
787
|
+
};
|
|
788
|
+
}
|
|
789
|
+
const lint = await lintPages({}, now);
|
|
790
|
+
const counts = {};
|
|
791
|
+
for (const name of PAGE_LINT_CLASSES) counts[name] = 0;
|
|
792
|
+
for (const finding of lint.findings) counts[finding.class] = (counts[finding.class] || 0) + 1;
|
|
793
|
+
return {
|
|
794
|
+
cadence: 'weekly',
|
|
795
|
+
week,
|
|
796
|
+
included: true,
|
|
797
|
+
assessed: true,
|
|
798
|
+
areas: lint.areas,
|
|
799
|
+
findings: lint.findings.length,
|
|
800
|
+
counts,
|
|
801
|
+
note: 'Computed for this initialize. emet_page_lint returns the findings. A fix goes through revise_memory, retire_doc, or accept_nonconformance.'
|
|
802
|
+
};
|
|
803
|
+
} catch (e) {
|
|
804
|
+
return { cadence: 'weekly', included: false, assessed: false, error: e && e.message ? e.message : String(e) };
|
|
805
|
+
}
|
|
806
|
+
}
|