@su-sws/synthetic-web-team 0.2.7 → 0.2.8
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/AGENTS.md +6 -0
- package/README.md +111 -9
- package/package.json +3 -2
- package/packages/cli/bin/sws.mjs +162 -14
- package/packages/cli/src/acknowledged.mjs +6 -1
- package/packages/cli/src/brief.mjs +393 -0
- package/packages/cli/src/preflight.mjs +1 -1
- package/packages/cli/src/prior-art.mjs +329 -0
- package/packages/cli/src/report.mjs +21 -2
- package/packages/wizard/bin/wizard.mjs +299 -12
- package/packages/wizard/src/detect.mjs +111 -1
- package/packages/wizard/src/emit.mjs +130 -9
- package/skills/role-backend-developer/SKILL.md +5 -2
- package/skills/role-compliance-officer/SKILL.md +1 -1
- package/skills/role-devops/SKILL.md +9 -6
- package/skills/role-fullstack-developer/SKILL.md +5 -3
- package/skills/role-information-architect/SKILL.md +1 -1
- package/skills/role-infrastructure-architect/SKILL.md +3 -3
- package/skills/role-qa-engineer/SKILL.md +5 -3
- package/skills/role-ux-designer/SKILL.md +1 -1
- package/skills/sws-compliance-check/SKILL.md +1 -1
- package/skills/sws-diverge/SKILL.md +2 -2
- package/skills/sws-github/SKILL.md +2 -0
- package/skills/sws-install/SKILL.md +1 -1
- package/skills/sws-netlify/SKILL.md +2 -0
- package/skills/sws-preflight/SKILL.md +5 -0
- package/skills/sws-vercel/SKILL.md +2 -0
- package/standards/hosting/github-pages.yml +1 -0
- package/standards/hosting/netlify.yml +1 -0
- package/standards/hosting/vercel.yml +1 -0
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
// `sws prior-art find <query>`: a keyword search over the curated catalog.
|
|
2
|
+
//
|
|
3
|
+
// What this is, and what it is not. The catalog's value is judgment: an era, a
|
|
4
|
+
// rating and a use_for / do_not_use_for split on every entry. This ranks those
|
|
5
|
+
// entries by how well they match the words in a query and prints the judgment
|
|
6
|
+
// beside each one. It does not read any repository, fetch any page, or decide
|
|
7
|
+
// what to borrow. A keyword match says an entry is about the same subject, and
|
|
8
|
+
// nothing more.
|
|
9
|
+
//
|
|
10
|
+
// Two things it does on purpose:
|
|
11
|
+
//
|
|
12
|
+
// - A CAUTIONARY ENTRY IS A RESULT. They are recorded so people stop copying
|
|
13
|
+
// them, which only works if a search that would have found the repo also
|
|
14
|
+
// finds the warning. They sort after better-rated entries on a tie, and are
|
|
15
|
+
// never filtered out.
|
|
16
|
+
// - NOTHING FOUND IS AN ANSWER. An entry must match at least half the query's
|
|
17
|
+
// words to be listed. Returning the best of a bad lot would send the reader
|
|
18
|
+
// down the wrong path with a straight face.
|
|
19
|
+
//
|
|
20
|
+
// Sources, in the lookup order standards/prior-art/README.md gives: the
|
|
21
|
+
// harvested patterns in patterns/INDEX.md, the inspected source repos in
|
|
22
|
+
// repos.yml, then the live exemplars and tools in catalog.yml. The local scan
|
|
23
|
+
// (.sws/prior-art.local.yml) and the live org search are not built, and the
|
|
24
|
+
// output says they were not searched.
|
|
25
|
+
|
|
26
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
27
|
+
import { join } from 'node:path';
|
|
28
|
+
import YAML from 'yaml';
|
|
29
|
+
|
|
30
|
+
const FILES = ['patterns/INDEX.md', 'repos.yml', 'catalog.yml'];
|
|
31
|
+
export const NOT_SEARCHED = ['.sws/prior-art.local.yml (local scan, not built yet)', 'live GitHub org search'];
|
|
32
|
+
|
|
33
|
+
/** The first directory among `candidates` that holds a prior-art catalog. */
|
|
34
|
+
export function findCatalog(candidates) {
|
|
35
|
+
for (const c of candidates) {
|
|
36
|
+
if (!c) continue;
|
|
37
|
+
const dir = join(c, 'prior-art');
|
|
38
|
+
if (existsSync(join(dir, 'repos.yml')) || existsSync(join(dir, 'catalog.yml'))) return dir;
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// --- loading -----------------------------------------------------------------
|
|
44
|
+
|
|
45
|
+
const KIND = { repos: 'source repo', live_exemplars: 'live site', tools: 'tool' };
|
|
46
|
+
const list = (v) => (v == null ? [] : [].concat(v)).map((x) => String(x).replace(/\s+/g, ' ').trim()).filter(Boolean);
|
|
47
|
+
const text = (v) => (v == null ? null : String(v).replace(/\s+/g, ' ').trim() || null);
|
|
48
|
+
|
|
49
|
+
// Every scalar under a value, for fields that are maps or mixed lists (`stack`).
|
|
50
|
+
function flatten(v) {
|
|
51
|
+
if (v == null) return [];
|
|
52
|
+
if (Array.isArray(v)) return v.flatMap(flatten);
|
|
53
|
+
if (typeof v === 'object') return Object.entries(v).flatMap(([k, x]) => [k, ...flatten(x)]);
|
|
54
|
+
return [String(v)];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// A YAML file: every top-level list of named entries is a section. Reading by
|
|
58
|
+
// shape rather than by a fixed list of keys means a new section in the catalog
|
|
59
|
+
// is searched the day it is added. An entry has to carry some of the judgment
|
|
60
|
+
// that makes it prior art (an era, a rating, or what it is for): the catalog's
|
|
61
|
+
// own `sources:` list is named entries too, and it is bookkeeping.
|
|
62
|
+
const JUDGMENT = ['era', 'rating', 'use_for', 'do_not_use_for'];
|
|
63
|
+
function loadYaml(dir, file) {
|
|
64
|
+
const doc = YAML.parse(readFileSync(join(dir, file), 'utf8')) || {};
|
|
65
|
+
const families = doc.families && typeof doc.families === 'object' ? doc.families : {};
|
|
66
|
+
const out = [];
|
|
67
|
+
for (const [section, items] of Object.entries(doc)) {
|
|
68
|
+
if (!Array.isArray(items)) continue;
|
|
69
|
+
for (const e of items) {
|
|
70
|
+
if (!e || typeof e !== 'object' || !e.name || !JUDGMENT.some((k) => e[k] != null)) continue;
|
|
71
|
+
const family = e.family ? families[e.family] : null;
|
|
72
|
+
const repo = typeof e.repo === 'string' && e.repo !== 'unknown' ? e.repo : null;
|
|
73
|
+
out.push({
|
|
74
|
+
name: String(e.name),
|
|
75
|
+
kind: KIND[section] ?? section,
|
|
76
|
+
source: `${file}#${section}`,
|
|
77
|
+
url: text(e.url),
|
|
78
|
+
repo,
|
|
79
|
+
ref: text(e.ref ?? e.repo_ref),
|
|
80
|
+
live: text(e.live),
|
|
81
|
+
era: text(e.era) ?? 'unrecorded',
|
|
82
|
+
rating: text(e.rating) ?? 'unrated',
|
|
83
|
+
family: text(e.family),
|
|
84
|
+
lineage: text(e.lineage),
|
|
85
|
+
what: text(e.what ?? e.why_exemplary ?? e.why),
|
|
86
|
+
use_for: list(e.use_for),
|
|
87
|
+
do_not_use_for: list(e.do_not_use_for),
|
|
88
|
+
priority: text(e.priority),
|
|
89
|
+
// Searched, not printed.
|
|
90
|
+
_fields: {
|
|
91
|
+
name: [e.name, ...[e.url, repo].filter(Boolean).map((u) => String(u).replace(/\/+$/, '').split('/').pop())],
|
|
92
|
+
use_for: list(e.use_for),
|
|
93
|
+
tags: [
|
|
94
|
+
...list(e.tags), e.family, e.kind, e.platform, e.era, e.hosting, e.provenance,
|
|
95
|
+
e.relationship, e.influences, ...flatten(e.stack),
|
|
96
|
+
].filter(Boolean).map(String),
|
|
97
|
+
description: [
|
|
98
|
+
e.what, e.why_exemplary, e.why, e.note, e.lineage, e.open_question,
|
|
99
|
+
...list(e.notable), family?.what,
|
|
100
|
+
].filter(Boolean).map(String),
|
|
101
|
+
do_not_use_for: list(e.do_not_use_for),
|
|
102
|
+
},
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return out;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// patterns/INDEX.md: `### <problem>` headings outside code fences, each with
|
|
110
|
+
// `- **field**: value` bullets. The file documents its own entry shape inside a
|
|
111
|
+
// fence, which is why fences are skipped: that example is not an entry.
|
|
112
|
+
function loadPatterns(dir, file) {
|
|
113
|
+
const out = [];
|
|
114
|
+
let fenced = false;
|
|
115
|
+
let cur = null;
|
|
116
|
+
const push = () => {
|
|
117
|
+
if (!cur || !cur.fields.era) return;
|
|
118
|
+
const f = cur.fields;
|
|
119
|
+
const split = (v) => list(v ? v.split(/;\s+/) : []);
|
|
120
|
+
out.push({
|
|
121
|
+
name: cur.name,
|
|
122
|
+
kind: 'harvested pattern',
|
|
123
|
+
source: `${file}`,
|
|
124
|
+
url: null, repo: null, ref: null, live: null,
|
|
125
|
+
era: f.era, rating: f.rating ?? 'unrated',
|
|
126
|
+
family: null, lineage: null,
|
|
127
|
+
what: text(cur.body.join(' ')) ?? (f.from ? `from ${f.from}` : null),
|
|
128
|
+
use_for: split(f.use_for),
|
|
129
|
+
do_not_use_for: split(f.do_not_use_for),
|
|
130
|
+
priority: null,
|
|
131
|
+
_fields: {
|
|
132
|
+
name: [cur.name],
|
|
133
|
+
use_for: split(f.use_for),
|
|
134
|
+
tags: [f.era, f.from].filter(Boolean),
|
|
135
|
+
description: cur.body,
|
|
136
|
+
do_not_use_for: split(f.do_not_use_for),
|
|
137
|
+
},
|
|
138
|
+
});
|
|
139
|
+
};
|
|
140
|
+
for (const line of readFileSync(join(dir, file), 'utf8').split('\n')) {
|
|
141
|
+
if (/^\s*```/.test(line)) { fenced = !fenced; continue; }
|
|
142
|
+
if (fenced) continue;
|
|
143
|
+
const h = /^(#{1,6})\s+(.*)$/.exec(line);
|
|
144
|
+
if (h) {
|
|
145
|
+
push();
|
|
146
|
+
cur = h[1].length === 3 ? { name: h[2].trim(), fields: {}, body: [] } : null;
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
if (!cur) continue;
|
|
150
|
+
const b = /^-\s+\*\*([a-z_]+)\*\*:\s*(.*)$/.exec(line);
|
|
151
|
+
if (b) cur.fields[b[1]] = b[2].trim();
|
|
152
|
+
else if (line.trim()) cur.body.push(line.trim());
|
|
153
|
+
}
|
|
154
|
+
push();
|
|
155
|
+
return out;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** Every entry in the catalog at `dir`, with the files that were read. */
|
|
159
|
+
export function loadCatalog(dir) {
|
|
160
|
+
const entries = [];
|
|
161
|
+
const sources = [];
|
|
162
|
+
for (const file of FILES) {
|
|
163
|
+
if (!existsSync(join(dir, file))) continue;
|
|
164
|
+
sources.push(file);
|
|
165
|
+
entries.push(...(file.endsWith('.md') ? loadPatterns(dir, file) : loadYaml(dir, file)));
|
|
166
|
+
}
|
|
167
|
+
return { entries, sources };
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// --- matching ----------------------------------------------------------------
|
|
171
|
+
|
|
172
|
+
// What each field is worth. The name and the curator's use_for say what an
|
|
173
|
+
// entry is for; a description mentions things in passing. A match in
|
|
174
|
+
// do_not_use_for counts for little and is always shown as such, because "we
|
|
175
|
+
// have this, and it is the wrong reference for that" is worth knowing.
|
|
176
|
+
const WEIGHT = { name: 5, use_for: 4, tags: 3, description: 2, do_not_use_for: 1 };
|
|
177
|
+
|
|
178
|
+
// Words that carry no subject. `stanford` and `sws` are here because every
|
|
179
|
+
// entry is Stanford's and SWS's.
|
|
180
|
+
const STOP = new Set(`a an and are as at be by do for from have how i in is it my of on or our that the
|
|
181
|
+
this to use used using we what when where which who why with you your stanford sws site sites
|
|
182
|
+
website page pages build building make making need want new`.split(/\s+/));
|
|
183
|
+
|
|
184
|
+
const words = (s) => String(s).toLowerCase().split(/[^a-z0-9]+/).filter(Boolean);
|
|
185
|
+
// Plural to singular, for words long enough that the result is still a word.
|
|
186
|
+
const stem = (w) => (w.length >= 5 && w.endsWith('s') && !w.endsWith('ss') ? w.slice(0, -1) : w);
|
|
187
|
+
|
|
188
|
+
/** The words of a query worth matching on, as typed, one per distinct stem. */
|
|
189
|
+
export function queryTerms(query) {
|
|
190
|
+
const seen = new Set();
|
|
191
|
+
return words(query)
|
|
192
|
+
// A lone digit stays: "decanter 8" and "decanter 7" are different questions.
|
|
193
|
+
.filter((w) => (w.length > 1 || /\d/.test(w)) && !STOP.has(w))
|
|
194
|
+
.filter((w) => !seen.has(stem(w)) && seen.add(stem(w)));
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// Equal after stemming, or a prefix when the term is long enough that a prefix
|
|
198
|
+
// is the same word ("search" in "searching"), not a different one ("form" in
|
|
199
|
+
// "format").
|
|
200
|
+
const hit = (term, word) => {
|
|
201
|
+
const t = stem(term);
|
|
202
|
+
return word === t || (t.length >= 5 && word.startsWith(t));
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
const RATING_ORDER = ['exemplary', 'sound', 'dated', 'cautionary'];
|
|
206
|
+
const rank = (r) => { const i = RATING_ORDER.indexOf(r); return i === -1 ? RATING_ORDER.length : i; };
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Rank `entries` against `query`. Returns `{ terms, results, total }`, where
|
|
210
|
+
* `results` is at most `limit` entries and `total` is how many matched.
|
|
211
|
+
*/
|
|
212
|
+
export function search(entries, query, { limit = 5 } = {}) {
|
|
213
|
+
const terms = queryTerms(query);
|
|
214
|
+
if (!terms.length) return { terms, results: [], total: 0 };
|
|
215
|
+
const need = Math.ceil(terms.length / 2);
|
|
216
|
+
const phrase = terms.map(stem).join(' ');
|
|
217
|
+
|
|
218
|
+
const scored = [];
|
|
219
|
+
for (const e of entries) {
|
|
220
|
+
const stems = Object.fromEntries(Object.entries(e._fields).map(([k, v]) => [k, v.flatMap(words).map(stem)]));
|
|
221
|
+
const matched = {};
|
|
222
|
+
let score = 0;
|
|
223
|
+
for (const t of terms) {
|
|
224
|
+
const fields = Object.keys(WEIGHT).filter((k) => stems[k].some((w) => hit(t, w)));
|
|
225
|
+
if (!fields.length) continue;
|
|
226
|
+
matched[t] = fields;
|
|
227
|
+
score += fields.reduce((n, k) => n + WEIGHT[k], 0);
|
|
228
|
+
}
|
|
229
|
+
const n = Object.keys(matched).length;
|
|
230
|
+
if (n < need) continue;
|
|
231
|
+
// The words in order, in the name or in what the curator says it is for.
|
|
232
|
+
if (terms.length > 1 && ['name', 'use_for'].some((k) => stems[k].join(' ').includes(phrase))) score += 5;
|
|
233
|
+
const { _fields, ...shown } = e;
|
|
234
|
+
scored.push({
|
|
235
|
+
...shown,
|
|
236
|
+
cautionary: e.rating === 'cautionary',
|
|
237
|
+
score,
|
|
238
|
+
matched,
|
|
239
|
+
terms_missing: terms.filter((t) => !matched[t]),
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
scored.sort((a, b) =>
|
|
244
|
+
Object.keys(b.matched).length - Object.keys(a.matched).length
|
|
245
|
+
|| b.score - a.score
|
|
246
|
+
|| rank(a.rating) - rank(b.rating)
|
|
247
|
+
|| a.name.localeCompare(b.name));
|
|
248
|
+
return { terms, results: scored.slice(0, limit), total: scored.length };
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// --- rendering ---------------------------------------------------------------
|
|
252
|
+
|
|
253
|
+
export const RULE = 'Prior art says how SWS solved a shape of problem. Standards say what to build it with, '
|
|
254
|
+
+ 'and win when the two disagree. Neither says why a choice was made or where the org is heading: ask a person.';
|
|
255
|
+
|
|
256
|
+
const NOTHING = 'No prior art found. That is a legitimate answer: build from the recipe rather than stretching a weak match.';
|
|
257
|
+
|
|
258
|
+
/** The machine-readable result. One JSON document. */
|
|
259
|
+
export function findJson({ query, dir, sources, entries, terms, results, total }) {
|
|
260
|
+
return JSON.stringify({
|
|
261
|
+
query,
|
|
262
|
+
terms,
|
|
263
|
+
catalog: { dir, sources, entries: entries.length, not_searched: NOT_SEARCHED },
|
|
264
|
+
count: total,
|
|
265
|
+
dropped: total - results.length,
|
|
266
|
+
results,
|
|
267
|
+
note: total ? RULE : NOTHING,
|
|
268
|
+
}, null, 2);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// `hang` indents every line after the first, so a wrapped bullet reads as one.
|
|
272
|
+
const wrap = (s, indent, { hang = '', width = 78 } = {}) => {
|
|
273
|
+
const out = [];
|
|
274
|
+
let line = '';
|
|
275
|
+
const lead = () => indent + (out.length ? hang : '');
|
|
276
|
+
for (const w of String(s).split(/\s+/)) {
|
|
277
|
+
if (line && lead().length + line.length + 1 + w.length > width) { out.push(lead() + line); line = w; }
|
|
278
|
+
else line = line ? `${line} ${w}` : w;
|
|
279
|
+
}
|
|
280
|
+
if (line) out.push(lead() + line);
|
|
281
|
+
return out;
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
/** The same result for a person, in the reporting shape the sws-prior-art skill asks for. */
|
|
285
|
+
export function findText({ query, dir, sources, entries, terms, results, total }) {
|
|
286
|
+
const L = [''];
|
|
287
|
+
if (!total) {
|
|
288
|
+
L.push(` No prior art found for "${query}".`);
|
|
289
|
+
L.push('');
|
|
290
|
+
L.push(` Searched ${entries.length} entries for: ${terms.join(', ')}`);
|
|
291
|
+
L.push(` in ${dir} (${sources.join(', ')})`);
|
|
292
|
+
L.push('');
|
|
293
|
+
L.push(...wrap('That is a legitimate answer. Build from the recipe rather than stretching a weak match.', ' '));
|
|
294
|
+
L.push(` Not searched: ${NOT_SEARCHED.join('; ')}.`);
|
|
295
|
+
L.push('');
|
|
296
|
+
return L.join('\n');
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
L.push(` Prior art for "${query}": ${total} of ${entries.length} entries match`);
|
|
300
|
+
L.push('');
|
|
301
|
+
for (const r of results) {
|
|
302
|
+
const rating = r.cautionary ? 'CAUTIONARY' : r.rating;
|
|
303
|
+
L.push(` ${r.name} ${r.kind}, era ${r.era}, rated ${rating}`);
|
|
304
|
+
if (r.cautionary) L.push(' Known problems. Recorded so people stop copying it.');
|
|
305
|
+
const where = [r.url, r.repo && r.repo !== r.url ? r.repo : null].filter(Boolean).join(' ');
|
|
306
|
+
if (where) L.push(` ${where}${r.ref ? ` (ref ${r.ref})` : ''}`);
|
|
307
|
+
if (r.what) L.push(...wrap(r.what, ' '));
|
|
308
|
+
if (r.lineage) L.push(...wrap(`Lineage: ${r.lineage}`, ' '));
|
|
309
|
+
L.push(' Use it for:');
|
|
310
|
+
if (r.use_for.length) for (const u of r.use_for) L.push(...wrap(`- ${u}`, ' ', { hang: ' ' }));
|
|
311
|
+
else L.push(' (nothing recorded)');
|
|
312
|
+
L.push(' Do not use it for:');
|
|
313
|
+
if (r.do_not_use_for.length) for (const u of r.do_not_use_for) L.push(...wrap(`- ${u}`, ' ', { hang: ' ' }));
|
|
314
|
+
else L.push(' (nothing recorded)');
|
|
315
|
+
const how = Object.entries(r.matched).map(([t, f]) => `${t} (${f.join(', ')})`).join('; ');
|
|
316
|
+
L.push(...wrap(`Matched: ${how}${r.terms_missing.length ? `. Not matched: ${r.terms_missing.join(', ')}` : ''}`, ' '));
|
|
317
|
+
L.push(` Source: ${r.source}`);
|
|
318
|
+
L.push('');
|
|
319
|
+
}
|
|
320
|
+
if (total > results.length) {
|
|
321
|
+
L.push(` ${total - results.length} more matched. --limit ${total} lists them all.`);
|
|
322
|
+
L.push('');
|
|
323
|
+
}
|
|
324
|
+
L.push(...wrap(RULE, ' '));
|
|
325
|
+
L.push(...wrap('A keyword match means the entry is about the same subject, nothing more. State the era of anything you borrow, and record what you reuse under prior_art in .sws/manifest.yml.', ' '));
|
|
326
|
+
L.push(` Not searched: ${NOT_SEARCHED.join('; ')}.`);
|
|
327
|
+
L.push('');
|
|
328
|
+
return L.join('\n');
|
|
329
|
+
}
|
|
@@ -16,6 +16,8 @@
|
|
|
16
16
|
// contract asks for. Only preferences can be diverged from.
|
|
17
17
|
// not_applicable excluded from the total entirely.
|
|
18
18
|
|
|
19
|
+
import { briefText } from './brief.mjs';
|
|
20
|
+
|
|
19
21
|
// Grouping is by what the reader can DO, not by policy chapter. Note every
|
|
20
22
|
// test requires a non-passing state: a blocking check that PASSES is not a
|
|
21
23
|
// blocking finding, and an earlier version of this listed `minweb.no-secrets`
|
|
@@ -149,15 +151,32 @@ export function renderMarkdown({ findings, sc, recipe, blocking }) {
|
|
|
149
151
|
return L.join('\n');
|
|
150
152
|
}
|
|
151
153
|
|
|
154
|
+
/** Findings counted by state, in the order every machine format prints them. */
|
|
155
|
+
export const countsByState = (findings) =>
|
|
156
|
+
['pass', 'fail', 'unknown', 'acknowledged', 'diverged', 'not_applicable']
|
|
157
|
+
.reduce((a, s) => ({ ...a, [s]: findings.filter((f) => f.state === s).length }), {});
|
|
158
|
+
|
|
152
159
|
export function renderJson({ findings, sc, recipe, blocking }) {
|
|
153
160
|
return JSON.stringify({
|
|
154
161
|
recipe, score: sc, blocking: blocking.map((b) => b.id),
|
|
155
|
-
counts:
|
|
156
|
-
.reduce((a, s) => ({ ...a, [s]: findings.filter((f) => f.state === s).length }), {}),
|
|
162
|
+
counts: countsByState(findings),
|
|
157
163
|
findings,
|
|
158
164
|
}, null, 2);
|
|
159
165
|
}
|
|
160
166
|
|
|
167
|
+
/**
|
|
168
|
+
* The brief format: one line of JSON, a few kilobytes at most, for a reader
|
|
169
|
+
* that has to act on the report rather than read all of it. Same findings,
|
|
170
|
+
* score and counts as renderJson; what it adds is selection and order. The
|
|
171
|
+
* shape and its size ceiling are in brief.mjs.
|
|
172
|
+
*
|
|
173
|
+
* Takes the payload the other renderers take, plus `command`, `criteria` (a
|
|
174
|
+
* Map of criterion by id) and `facts` about the project that are not findings.
|
|
175
|
+
*/
|
|
176
|
+
export function renderBrief(payload) {
|
|
177
|
+
return briefText({ ...payload, counts: countsByState(payload.findings) });
|
|
178
|
+
}
|
|
179
|
+
|
|
161
180
|
// ---------------------------------------------------------------------------
|
|
162
181
|
// Destinations. Rendering is separated from publishing (github.mjs) so every
|
|
163
182
|
// body below can be built and inspected without a network or a token.
|