@popcorn245/cornfield 0.58.0 → 0.60.0

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/core/config.js CHANGED
@@ -33,6 +33,7 @@
33
33
  * embed: { origins: [] }, // exact origins of sibling apps that may read, and decide a review, as the signed-in maintainer (docs/embedding.md)
34
34
  * proxy: {}, // { '/api/': 'http://127.0.0.1:3245' }: same-origin paths for a live source
35
35
  * importMap: {}, // bare imports a repo-local browser module needs: { name: '/repo/path.js' }
36
+ * history: false, // true: read the repo's git history for the History layer, a node's commits and Replay (docs/config.md#history; spec 0014)
36
37
  * dataDir: null, // where cornfield keeps its own state (reviews; the SQLite file in v1)
37
38
  * }
38
39
  *
@@ -182,6 +183,7 @@ export const DEFAULTS = Object.freeze({
182
183
  embed: { origins: [] },
183
184
  proxy: {},
184
185
  importMap: {},
186
+ history: false,
185
187
  dataDir: null,
186
188
  });
187
189
 
@@ -393,6 +395,7 @@ export function configProblems(c) {
393
395
  if (l !== undefined && (!isText(l) || l.includes(',') || l.trim() !== l || l.length > MAX_LABEL)) out.push(`threads.label is the name of the label that makes an issue an idea, like "idea": text of at most ${MAX_LABEL} characters, no comma, no space at either end.`);
394
396
  }
395
397
  }
398
+ if (c.history !== undefined && typeof c.history !== 'boolean') out.push('"history" is true or false: true reads the repo\'s git history (docs/config.md#history).');
396
399
  if (c.releaseNotes !== undefined) {
397
400
  if (!isObject(c.releaseNotes)) out.push('"releaseNotes" is { breakingLabel }.');
398
401
  else if (c.releaseNotes.breakingLabel !== undefined && (!isText(c.releaseNotes.breakingLabel) || c.releaseNotes.breakingLabel.includes(','))) out.push('releaseNotes.breakingLabel is a label\'s name, like "breaking".');
@@ -0,0 +1,222 @@
1
+ /**
2
+ * @module core/history
3
+ *
4
+ * The map's own history (spec 0014 D4): which commits changed each node, when each node was born, and, for each commit,
5
+ * the trail it names from spec to issue to pull request. Read from `git log` when the config says `history: true`.
6
+ *
7
+ * Two halves:
8
+ * - pure: `parseLog` reads the fixed format `readLog` asks git for, `traceOf` reads a commit's trail from its message
9
+ * and files, and `historyOf` ties the commits to a map's nodes. No I/O; tested in Node.
10
+ * - `readLog` and `createHistory`: run git, read-only, and keep the answer per HEAD.
11
+ *
12
+ * Running git is the one program cornfield runs, so it is held tight (spec 0014, question 1):
13
+ * - a fixed list of arguments, `execFile` with no shell, the repo's path as `-C`, nothing from a request in it;
14
+ * - nothing from the repo's own config may run a program: no pager, external diff, text conversion, signature check
15
+ * or fsmonitor, and no terminal prompt;
16
+ * - a time and size ceiling, and at most MAX_COMMITS commits.
17
+ */
18
+
19
+ import { execFile } from 'node:child_process';
20
+
21
+ /** The most commits read, newest first: a long history is cut at its newest MAX_COMMITS */
22
+ export const MAX_COMMITS = 5000;
23
+ /** How long `git log` may take, and how much it may say, before it is given up on */
24
+ export const GIT_TIMEOUT_MS = 15_000;
25
+ export const GIT_MAX_BYTES = 64 * 1024 * 1024;
26
+
27
+ const RS = '\x1e';
28
+ const US = '\x1f';
29
+ /** The format each commit is written in: record separator, hash, author date (ISO), subject, body, then its files */
30
+ export const LOG_FORMAT = `${RS}%H${US}%aI${US}%s${US}%b${US}`;
31
+
32
+ /**
33
+ * The arguments `readLog` runs git with: settings that keep the repo's own config from running anything, then the log
34
+ * of the checked-out branch, first parent only (a merged branch's own commits are its pull request's), with renames.
35
+ * @param {string} root the repo's folder
36
+ */
37
+ export function gitArgs(root) {
38
+ return [
39
+ '-C', root,
40
+ '-c', 'core.pager=cat', '-c', 'core.fsmonitor=false', '-c', 'log.showSignature=false', '-c', 'diff.external=',
41
+ '--no-pager', 'log', '--first-parent', `--max-count=${MAX_COMMITS}`, `--format=${LOG_FORMAT}`,
42
+ '--name-status', '-M', '--no-ext-diff', '--no-textconv', '--no-color', 'HEAD', '--',
43
+ ];
44
+ }
45
+
46
+ /** The environment git runs in: no prompt, no system config, the user's own config kept (it is theirs, not the repo's) */
47
+ export const gitEnv = (env = process.env) => ({ ...env, GIT_TERMINAL_PROMPT: '0', GIT_CONFIG_NOSYSTEM: '1', GIT_PAGER: 'cat', GIT_EXTERNAL_DIFF: '', LC_ALL: 'C' });
48
+
49
+ /**
50
+ * @typedef {object} RawCommit
51
+ * @property {string} sha
52
+ * @property {string} date the author date, ISO 8601
53
+ * @property {string} subject
54
+ * @property {string} body
55
+ * @property {{ status: string, path: string, from?: string }[]} files A, M, D, R (with `from`), C, T
56
+ */
57
+
58
+ /**
59
+ * The commits in `readLog`'s output, oldest first. A malformed record is left out.
60
+ * @param {string} text
61
+ * @returns {RawCommit[]}
62
+ */
63
+ export function parseLog(text) {
64
+ const out = [];
65
+ for (const rec of String(text).split(RS).slice(1)) {
66
+ const parts = rec.split(US);
67
+ if (parts.length < 5) continue;
68
+ const [sha, date, subject, body] = parts;
69
+ if (!/^[0-9a-f]{40}$/.test(sha) || Number.isNaN(Date.parse(date))) continue;
70
+ const files = [];
71
+ for (const line of parts.slice(4).join(US).split('\n')) {
72
+ const cols = line.split('\t');
73
+ if (cols.length < 2 || !/^[AMDRCT]\d*$/.test(cols[0])) continue;
74
+ const status = cols[0][0];
75
+ if ((status === 'R' || status === 'C') && cols.length >= 3) files.push({ status, from: cols[1], path: cols[2] });
76
+ else files.push({ status, path: cols[1] });
77
+ }
78
+ out.push({ sha, date, subject: subject.trim(), body: body.trim(), files });
79
+ }
80
+ return out.reverse();
81
+ }
82
+
83
+ /** The words that say a commit closes an issue (GitHub's and Forgejo's) */
84
+ const CLOSES = /\b(?:close[sd]?|fix(?:e[sd])?|resolve[sd]?)\s+#(\d+)\b/gi;
85
+ const KEY = /\[([A-Z][A-Z0-9]*-\d+)\]/g;
86
+ const SPEC_WORD = /\bspecs?\s+(\d{4})\b/gi;
87
+ const SPEC_FILE = /^docs\/specs\/(\d{4})-[^/]+\.md$/;
88
+
89
+ /**
90
+ * The trail a commit names (spec 0014 D2, question 3): its pull request (the last `(#N)` in its subject, as a squash
91
+ * merge writes it), its issues (an earlier `(#N)`, a `Closes #N`), the issue keys it carries (`[CF-45]`), and its specs
92
+ * (`spec 0012` in its message, or a spec file it changed). What it does not name is not guessed.
93
+ * @param {{ subject: string, body?: string, files?: { path: string }[] }} commit
94
+ * @returns {{ pr: number | null, issues: number[], keys: string[], specs: string[] }}
95
+ */
96
+ export function traceOf({ subject, body = '', files = [] }) {
97
+ const refs = [...String(subject).matchAll(/\(#(\d+)\)/g)].map((m) => Number(m[1]));
98
+ const pr = refs.length ? refs[refs.length - 1] : null;
99
+ const issues = [];
100
+ const add = (n) => { if (n !== pr && !issues.includes(n)) issues.push(n); };
101
+ refs.slice(0, -1).forEach(add);
102
+ for (const m of `${subject}\n${body}`.matchAll(CLOSES)) add(Number(m[1]));
103
+ const keys = [...new Set([...`${subject}\n${body}`.matchAll(KEY)].map((m) => m[1]))];
104
+ const specs = [];
105
+ for (const m of `${subject}\n${body}`.matchAll(SPEC_WORD)) if (!specs.includes(m[1])) specs.push(m[1]);
106
+ for (const f of files) { const m = SPEC_FILE.exec(f.path); if (m && !specs.includes(m[1])) specs.push(m[1]); }
107
+ return { pr, issues, keys, specs };
108
+ }
109
+
110
+ /** A commit's subject without the `(#N)` its pull request left on it */
111
+ export const cleanSubject = (subject) => String(subject).replace(/\s*\(#\d+\)/g, '').trim();
112
+
113
+ /**
114
+ * @typedef {object} History
115
+ * @property {{ sha: string, date: string, subject: string, pr: number | null, issues: number[], keys: string[], specs: string[], files: number, nodes: string[] }[]} commits oldest first
116
+ * @property {Record<string, { born: number, commits: number[] }>} nodes by node id: the index of the commit it was born in, and of every commit that changed it
117
+ * @property {boolean} cut whether the history was cut at MAX_COMMITS
118
+ */
119
+
120
+ /**
121
+ * Ties commits to a map's nodes. A node owns its `file`, and everything under it when that is a folder. Renames are
122
+ * followed back (question 4): a file renamed into a node's path brings its older history with it. A node is born at the
123
+ * first commit that changed what it owns; one that nothing in the history touches is born with the first commit.
124
+ * A child is never born before its parent: its parent is born with it.
125
+ * @param {RawCommit[]} raw oldest first (parseLog)
126
+ * @param {{ nodes: { id: string, file?: string }[], edges?: { from: string, to: string, dashed?: boolean, kind?: string }[] }} topology
127
+ * @param {{ cut?: boolean }} [opts]
128
+ * @returns {History}
129
+ */
130
+ export function historyOf(raw, topology, { cut = false } = {}) {
131
+ const nodes = (topology && Array.isArray(topology.nodes) ? topology.nodes : []).filter((n) => n && typeof n.id === 'string');
132
+ // Each node's paths, newest name first; walked newest to oldest so a rename adds the older name before it is met
133
+ const owns = new Map(nodes.filter((n) => typeof n.file === 'string' && n.file.trim()).map((n) => [n.id, new Set([n.file.replace(/\/+$/, '')])]));
134
+ const covers = (p, f) => f === p || f.startsWith(`${p}/`);
135
+ const touched = raw.map(() => new Set());
136
+ for (let i = raw.length - 1; i >= 0; i--) {
137
+ for (const f of raw[i].files) {
138
+ for (const [id, paths] of owns) {
139
+ for (const p of [...paths]) {
140
+ if (!covers(p, f.path)) continue;
141
+ if (f.status !== 'D') touched[i].add(id);
142
+ // The node's own file came from another name: follow it back. A rename inside a folder node needs nothing, the folder covers both
143
+ if (f.status === 'R' && f.from && f.path === p) paths.add(f.from);
144
+ }
145
+ }
146
+ }
147
+ }
148
+ const out = {};
149
+ nodes.forEach((n) => { out[n.id] = { born: 0, commits: [] }; });
150
+ touched.forEach((ids, i) => ids.forEach((id) => out[id].commits.push(i)));
151
+ for (const n of nodes) out[n.id].born = out[n.id].commits.length ? out[n.id].commits[0] : 0;
152
+ // Parents first: ownership edges (no kind, not dashed), a parent born no later than its child
153
+ const parent = new Map();
154
+ for (const e of topology?.edges || []) if (e && !e.dashed && !e.kind && out[e.from] && out[e.to] && !parent.has(e.to) && e.from !== e.to) parent.set(e.to, e.from);
155
+ for (const n of nodes) {
156
+ const seen = new Set([n.id]);
157
+ for (let c = n.id, p = parent.get(c); p && !seen.has(p); c = p, p = parent.get(p)) {
158
+ seen.add(p);
159
+ if (out[p].born > out[c].born) out[p].born = out[c].born;
160
+ }
161
+ }
162
+ const commits = raw.map((c, i) => ({ sha: c.sha, date: c.date, subject: cleanSubject(c.subject), ...traceOf(c), files: c.files.length, nodes: [...touched[i]].sort() }));
163
+ return { commits, nodes: out, cut };
164
+ }
165
+
166
+ /**
167
+ * Runs git and reads the log of the checked-out branch. Rejects with a plain message when git is not there, the folder
168
+ * is not a repo, or git gives up.
169
+ * @param {string} root
170
+ * @param {{ env?: NodeJS.ProcessEnv, run?: typeof execFile }} [opts] `run` is the tests' fake
171
+ * @returns {Promise<{ raw: RawCommit[], cut: boolean }>}
172
+ */
173
+ export function readLog(root, { env = process.env, run = execFile } = {}) {
174
+ return new Promise((resolve, reject) => {
175
+ run('git', gitArgs(root), { env: gitEnv(env), timeout: GIT_TIMEOUT_MS, maxBuffer: GIT_MAX_BYTES, windowsHide: true, encoding: 'utf8' }, (err, stdout) => {
176
+ if (err) {
177
+ const why = err.code === 'ENOENT' ? 'git is not installed where cornfield runs' : err.killed ? `git log took longer than ${GIT_TIMEOUT_MS / 1000}s` : 'the repo has no history git can read (is it a git checkout with a commit?)';
178
+ return reject(Object.assign(new Error(`The history could not be read: ${why}.`), { code: 'ENOHISTORY' }));
179
+ }
180
+ const raw = parseLog(stdout);
181
+ resolve({ raw, cut: raw.length >= MAX_COMMITS });
182
+ });
183
+ });
184
+ }
185
+
186
+ /** The commit HEAD points at, by asking git with the same guards; null when there is none */
187
+ export function readHead(root, { env = process.env, run = execFile } = {}) {
188
+ return new Promise((resolve) => {
189
+ run('git', ['-C', root, '-c', 'core.fsmonitor=false', 'rev-parse', '--verify', '--quiet', 'HEAD'], { env: gitEnv(env), timeout: GIT_TIMEOUT_MS, windowsHide: true, encoding: 'utf8' }, (err, stdout) => {
190
+ const sha = String(stdout || '').trim();
191
+ resolve(!err && /^[0-9a-f]{40}$/.test(sha) ? sha : null);
192
+ });
193
+ });
194
+ }
195
+
196
+ /**
197
+ * The history of one repo, kept per HEAD and map: read again only when either changes. One read at a time; callers
198
+ * that ask while it runs share it.
199
+ * @param {string} root
200
+ * @param {{ env?: NodeJS.ProcessEnv, run?: typeof execFile }} [opts]
201
+ * @returns {{ get(topology: object, topologyKey: string): Promise<History & { head: string }> }}
202
+ */
203
+ export function createHistory(root, opts = {}) {
204
+ let kept = null; // { key, value }
205
+ let pending = null; // { key, promise }
206
+ return {
207
+ async get(topology, topologyKey) {
208
+ const head = await readHead(root, opts);
209
+ if (!head) throw Object.assign(new Error('The history could not be read: the repo has no commit yet, or is not a git checkout.'), { code: 'ENOHISTORY' });
210
+ const key = `${head}|${topologyKey}`;
211
+ if (kept && kept.key === key) return kept.value;
212
+ if (pending && pending.key === key) return pending.promise;
213
+ const promise = readLog(root, opts).then(({ raw, cut }) => {
214
+ const value = { head, ...historyOf(raw, topology, { cut }) };
215
+ kept = { key, value };
216
+ return value;
217
+ }).finally(() => { if (pending && pending.key === key) pending = null; });
218
+ pending = { key, promise };
219
+ return promise;
220
+ },
221
+ };
222
+ }
@@ -188,3 +188,16 @@
188
188
  /* The head never shrinks: the body is a flex column that scrolls, and a short box (a panel in a host's 200px place, a short window) would squash the head to its
189
189
  min-height, laying a title that wraps, or a kicker that does ("Added by" a proposal), over the line under it */
190
190
  .hx-drawer-head { min-height: var(--corn-panel-head-height); flex-shrink: 0; }
191
+
192
+ /* History (spec 0014 D2): a node's commits, each with its trail from spec to issue to pull request to commit; a gap is dashed */
193
+ .hx-history-stats { margin: 0; color: var(--corn-text-2); font-size: var(--corn-text-sm); }
194
+ .hx-history-k { margin: var(--corn-space-3) 0 var(--corn-space-1); font-size: var(--corn-text-xs); font-weight: 600; color: var(--corn-text-3); text-transform: uppercase; letter-spacing: 0.04em; }
195
+ .hx-history-issues { margin: var(--corn-space-2) 0 0; font-size: var(--corn-text-sm); color: var(--corn-text-2); }
196
+ .hx-history-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--corn-space-2); }
197
+ .hx-history-commit { display: flex; flex-direction: column; gap: var(--corn-space-1); padding: var(--corn-space-3) var(--corn-space-4); border: var(--corn-border) solid var(--corn-line-soft); border-radius: var(--corn-radius-sm); background: var(--corn-surface-2); }
198
+ .hx-history-subject { color: var(--corn-text); overflow-wrap: anywhere; }
199
+ .hx-trail { display: flex; flex-wrap: wrap; align-items: center; gap: var(--corn-space-1); }
200
+ .hx-trail-arrow { color: var(--corn-text-3); font-size: var(--corn-text-xs); }
201
+ .hx-trail-chip { display: inline-flex; align-items: center; padding: 0 var(--corn-space-2); min-height: 22px; border: var(--corn-border) solid var(--corn-line); border-radius: var(--corn-radius-pill); color: var(--corn-text-2); font-size: var(--corn-text-xs); text-decoration: none; white-space: nowrap; }
202
+ a.hx-trail-chip:hover { border-color: var(--corn-accent-hover); color: var(--corn-text); }
203
+ .hx-trail-chip[data-trail="gap"] { border-style: dashed; color: var(--corn-text-3); }
@@ -0,0 +1,178 @@
1
+ /**
2
+ * @module explorer/history-model
3
+ *
4
+ * The pure half of a node's history (spec 0014 D2): the links of a commit's trail on the forge, and the node panel's History section.
5
+ * No DOM, no state, no fetch; explorer/history.js holds the answer of `GET /api/history` (core/history.js) and asks these.
6
+ *
7
+ * forgeLinks(forge) { commit(sha), pull(n), issue(n) }: where each is on the forge's site, or null (only https; GitHub and Forgejo)
8
+ * specFiles(nodes) spec number -> its file (`docs/specs/0012-work-as-a-view.md`), from the map's doc pages
9
+ * nodeTrail(history, nodeId) a node's commits, newest first, with what the History section counts
10
+ * trailHtml(commit, ctx) a commit's trail: `Spec 0012 → Issue #283 → PR #284 → 0281cba`, a gap dashed (`no spec`, `no issue`)
11
+ * historySectionHtml(node, ctx) the node panel's History section
12
+ * specReach(history, spec) the nodes a spec's commits touched, and how many commits named it
13
+ */
14
+
15
+ import { escapeHtml as esc } from '../core/text.js';
16
+ import { fileUrl } from './file-url.js';
17
+
18
+ /** The most commits the section lists before "Show all N" */
19
+ export const HISTORY_CAP = 12;
20
+
21
+ /** Where a commit, a pull request and an issue are on each forge's site */
22
+ const SHAPES = {
23
+ github: { commit: 'commit', pull: 'pull', issue: 'issues' },
24
+ forgejo: { commit: 'commit', pull: 'pulls', issue: 'issues' },
25
+ };
26
+
27
+ /**
28
+ * The links of a trail on the forge, or null when there is no forge cornfield can link to. Built like file-url.js: `URL`, each segment encoded,
29
+ * only `https:`, no user name and no backslash in `forge.url`.
30
+ * @param {{ type: string, url: string, repo: string, baseBranch?: string } | null} forge the client config's
31
+ */
32
+ export function forgeLinks(forge) {
33
+ const shape = forge && Object.hasOwn(SHAPES, forge.type) ? SHAPES[forge.type] : null;
34
+ const repo = forge && typeof forge.repo === 'string' ? forge.repo.split('/') : [];
35
+ if (!shape || repo.length !== 2 || !repo.every((s) => /^[A-Za-z0-9_.-]+$/.test(s) && s !== '.' && s !== '..')) return null;
36
+ let base;
37
+ try {
38
+ base = new URL(forge.url);
39
+ if (base.protocol !== 'https:' || base.username || base.password || String(forge.url).includes('\\')) return null;
40
+ } catch {
41
+ return null;
42
+ }
43
+ const at = (...segs) => {
44
+ const u = new URL(base.href);
45
+ u.pathname = `${u.pathname.replace(/\/+$/, '')}/${[...repo, ...segs].map(encodeURIComponent).join('/')}`;
46
+ u.search = '';
47
+ u.hash = '';
48
+ return u.href;
49
+ };
50
+ const num = (n) => Number.isInteger(n) && n > 0;
51
+ return {
52
+ commit: (sha) => (typeof sha === 'string' && /^[0-9a-f]{7,40}$/.test(sha) ? at(shape.commit, sha) : null),
53
+ pull: (n) => (num(n) ? at(shape.pull, String(n)) : null),
54
+ issue: (n) => (num(n) ? at(shape.issue, String(n)) : null),
55
+ file: (path) => fileUrl(forge, path, forge.baseBranch),
56
+ };
57
+ }
58
+
59
+ /** A spec's short title from its doc page: "Work as a view" from "Spec 0012: Work as a view (issues, …)"; else its number */
60
+ const titleOf = (n, num) => {
61
+ const m = typeof n.desc === 'string' && /^Spec \d{4}:\s*([^(]+?)\s*(?:\(|$)/.exec(n.desc);
62
+ return m ? m[1] : `Spec ${num}`;
63
+ };
64
+
65
+ /** Spec number -> its file, from the map's pages of `docs/specs/NNNN-*.md` (the docs deriver puts each doc on the map) */
66
+ export function specFiles(nodes) {
67
+ const out = new Map();
68
+ for (const n of nodes || []) {
69
+ const m = n && typeof n.file === 'string' && /^docs\/specs\/(\d{4})-[^/]+\.md$/.exec(n.file);
70
+ if (m && !out.has(m[1])) out.set(m[1], { file: n.file, label: titleOf(n, m[1]), id: n.id });
71
+ }
72
+ return out;
73
+ }
74
+
75
+ /**
76
+ * A node's commits, newest first, and what the section counts of them: pull requests, the specs and issues they name, and how many name a spec or an issue.
77
+ * @param {{ commits: object[], nodes: Record<string, { born: number, commits: number[] }> } | null} history
78
+ * @param {string} nodeId
79
+ */
80
+ export function nodeTrail(history, nodeId) {
81
+ const entry = history && history.nodes && Object.hasOwn(history.nodes, nodeId) ? history.nodes[nodeId] : null;
82
+ if (!entry) return null;
83
+ const commits = entry.commits.map((i) => ({ ...history.commits[i], index: i })).filter((c) => c.sha).reverse();
84
+ const uniq = (xs) => [...new Set(xs)];
85
+ return {
86
+ commits,
87
+ born: history.commits[entry.born] ? { ...history.commits[entry.born], index: entry.born } : null,
88
+ pulls: uniq(commits.map((c) => c.pr).filter((n) => n != null)),
89
+ specs: uniq(commits.flatMap((c) => c.specs || [])),
90
+ issues: uniq(commits.flatMap((c) => c.issues || [])),
91
+ traced: commits.filter((c) => (c.specs && c.specs.length) || (c.issues && c.issues.length) || (c.keys && c.keys.length)).length,
92
+ };
93
+ }
94
+
95
+ const chip = (kind, href, words, title) => (href
96
+ ? `<a class="hx-trail-chip" data-corn="text-link" data-trail="${kind}" href="${esc(href)}" target="_blank" rel="noreferrer"${title ? ` title="${esc(title)}"` : ''}>${words}</a>`
97
+ : `<span class="hx-trail-chip" data-trail="${kind}"${title ? ` title="${esc(title)}"` : ''}>${words}</span>`);
98
+ const gap = (what) => `<span class="hx-trail-chip" data-trail="gap">no ${what}</span>`;
99
+ const ARROW = '<span class="hx-trail-arrow" aria-hidden="true">→</span>';
100
+
101
+ /**
102
+ * A commit's trail, from spec to issue to pull request to commit. Each a link on the forge when there is one (a spec to its file); what the commit does not name is a dashed gap.
103
+ * @param {{ sha: string, pr: number | null, issues: number[], specs: string[], keys?: string[] }} c
104
+ * @param {{ links: ReturnType<typeof forgeLinks>, specs: ReturnType<typeof specFiles> }} ctx
105
+ */
106
+ export function trailHtml(c, { links, specs }) {
107
+ const parts = [];
108
+ if (c.specs && c.specs.length) {
109
+ for (const s of c.specs) {
110
+ const spec = specs.get(s);
111
+ parts.push(chip('spec', spec && links ? links.file(spec.file) : null, `Spec ${esc(s)}`, spec ? spec.label : ''));
112
+ }
113
+ } else parts.push(gap('spec'));
114
+ if (c.issues && c.issues.length) for (const n of c.issues) parts.push(chip('issue', links && links.issue(n), `Issue #${esc(n)}`));
115
+ else if (c.keys && c.keys.length) for (const k of c.keys) parts.push(chip('issue', null, esc(k)));
116
+ else parts.push(gap('issue'));
117
+ if (c.pr != null) parts.push(chip('pull', links && links.pull(c.pr), `PR #${esc(c.pr)}`));
118
+ else parts.push(gap('pull request'));
119
+ parts.push(chip('commit', links && links.commit(c.sha), `<span class="hx-mono">${esc(String(c.sha).slice(0, 7))}</span>`, 'The commit on the forge'));
120
+ return `<span class="hx-trail" role="group" aria-label="Spec, issue, pull request and commit">${parts.join(ARROW)}</span>`;
121
+ }
122
+
123
+ /** "26 Nov 2026": a commit's day, in the viewer's own words for it */
124
+ export const dayOf = (iso, locale) => {
125
+ const d = new Date(iso);
126
+ return Number.isNaN(d.getTime()) ? '' : d.toLocaleDateString(locale, { day: 'numeric', month: 'short', year: 'numeric' });
127
+ };
128
+
129
+ /**
130
+ * The node panel's History section (spec 0014 D2): counts, the specs behind the node (each picks what the spec reached on the map), the issues, and its commits newest first
131
+ * with their trails. Every word from git and the forge is escaped; only https links are made.
132
+ * @param {{ id: string }} node
133
+ * @param {{ history: object | null, status: 'off' | 'loading' | 'ready' | 'error', error?: string, links: ReturnType<typeof forgeLinks>, specs: ReturnType<typeof specFiles>, picked?: string | null, all?: boolean, locale?: string }} ctx
134
+ */
135
+ export function historySectionHtml(node, ctx) {
136
+ const head = '<h3 class="hx-sec-title">History</h3>';
137
+ const wrap = (body) => `<div class="hx-sec-block hx-history" data-corn="section" data-history>${head}${body}</div>`;
138
+ if (ctx.status === 'off') return '';
139
+ if (ctx.status === 'loading') return wrap('<p class="hx-faint" data-corn="loading">Reading the history…</p>');
140
+ if (ctx.status === 'error') return wrap(`<p class="hx-faint" data-corn="error">${esc(ctx.error || 'The history could not be read.')}</p>`);
141
+ const t = nodeTrail(ctx.history, node.id);
142
+ if (!t) return wrap('<p class="hx-faint">This node is not in the history yet: run <code class="hx-code">cornfield sync</code> and commit the map.</p>');
143
+ if (!t.commits.length) return wrap('<p class="hx-faint">No commit has changed this node\'s file yet.</p>');
144
+ const n = t.commits.length;
145
+ const share = Math.round((t.traced / n) * 100);
146
+ const stats = `<p class="hx-history-stats"><span><b class="hx-ms">${n}</b> ${n === 1 ? 'commit' : 'commits'}</span> · <span><b class="hx-ms">${t.pulls.length}</b> ${t.pulls.length === 1 ? 'pull request' : 'pull requests'}</span> · <span><b class="hx-ms">${share}%</b> traced to a spec or issue</span></p>`;
147
+ const specChips = t.specs.map((s) => {
148
+ const spec = ctx.specs.get(s);
149
+ const on = ctx.picked === s;
150
+ return `<button type="button" class="hx-lines-kind" data-corn-kind="quiet" data-history-spec="${esc(s)}" aria-pressed="${on}" title="Light every node spec ${esc(s)} reached">Spec ${esc(s)}${spec ? ` <span class="hx-faint">${esc(spec.label)}</span>` : ''}</button>`;
151
+ });
152
+ const specs = specChips.length ? `<div class="hx-chips" role="group" aria-label="Specs behind it">${specChips.join('')}</div>` : '<p class="hx-faint">No commit to this node names a spec.</p>';
153
+ const issues = t.issues.length ? `<p class="hx-history-issues">Issues: ${t.issues.map((i) => { const href = ctx.links && ctx.links.issue(i); return href ? `<a class="hx-link" data-corn="text-link" href="${esc(href)}" target="_blank" rel="noreferrer">#${esc(i)}</a>` : `#${esc(i)}`; }).join(', ')}</p>` : '';
154
+ const shown = ctx.all ? t.commits : t.commits.slice(0, HISTORY_CAP);
155
+ const rows = shown.map((c) => `<li class="hx-history-commit" data-corn="row">`
156
+ + `<div class="hx-row-meta">${esc(dayOf(c.date, ctx.locale))} · ${c.nodes.length} ${c.nodes.length === 1 ? 'node' : 'nodes'}${t.born && c.index === t.born.index ? ' · <span class="hx-history-born">born here</span>' : ''}</div>`
157
+ + `<div class="hx-history-subject">${esc(c.subject)}</div>`
158
+ + trailHtml(c, ctx)
159
+ + '</li>');
160
+ const more = shown.length < n ? `<button type="button" class="hx-btn hx-btn--quiet hx-textact" data-corn="more" data-corn-kind="quiet" data-history-all>Show all ${n}</button>` : '';
161
+ return wrap(`${stats}<h4 class="hx-history-k">Specs behind it</h4>${specs}${issues}<h4 class="hx-history-k">Commits, newest first</h4><ol class="hx-history-list">${rows.join('')}</ol>${more}`);
162
+ }
163
+
164
+ /**
165
+ * What a spec reached: the nodes its commits touched, and how many commits named it (spec 0014 D3: picking a spec lights them).
166
+ * @param {{ commits: { specs: string[], nodes: string[] }[] } | null} history
167
+ * @param {string} spec
168
+ */
169
+ export function specReach(history, spec) {
170
+ const nodes = new Set();
171
+ let commits = 0;
172
+ for (const c of (history && history.commits) || []) {
173
+ if (!c.specs || !c.specs.includes(spec)) continue;
174
+ commits++;
175
+ for (const id of c.nodes) nodes.add(id);
176
+ }
177
+ return { nodes, commits };
178
+ }
@@ -0,0 +1,78 @@
1
+ /**
2
+ * @module explorer/history
3
+ *
4
+ * A node's history on an instance (spec 0014 D2): reads `GET /api/history` (core/history.js) once, the first time the node panel asks, and
5
+ * answers the panel's History section; picking a spec lights every node its commits touched (`state.historyPick`, which scene.js dims around).
6
+ * Nothing is fetched while the config says `history: false`, and the panel then has no History section.
7
+ *
8
+ * initHistory(inst, config) once, with the client config (`history`, `forge`); returns how to stop
9
+ *
10
+ * What it answers and hears (instance.js lists them):
11
+ * history:section node -> HTML | undefined the node panel's History section; asking starts the one read
12
+ * history:pick spec | null (emit) light what that spec reached, or nothing; picking the lit spec again ends it
13
+ * history:all (none) (emit) the section lists every commit, not only the newest
14
+ * history:changed (none) (emitted) the read ended, or a pick changed: the open panel draws its History section again
15
+ */
16
+
17
+ import { credentialed } from './engine/connection.js';
18
+ import { announce } from './engine/keyboard.js';
19
+ import { forgeLinks, historySectionHtml, specFiles, specReach } from './history-model.js';
20
+
21
+ /** Where the server answers the history (server/server.js) */
22
+ export const HISTORY_PATH = '/api/history';
23
+
24
+ /**
25
+ * @param {ReturnType<typeof import('./instance.js').createInstance>} inst
26
+ * @param {{ history?: boolean, forge?: object | null }} config the client config (/cornfield/config.json)
27
+ * @returns {() => void}
28
+ */
29
+ export function initHistory(inst, config) {
30
+ const { state } = inst;
31
+ const on = !!(config && config.history === true);
32
+ const mem = { status: on ? 'idle' : 'off', history: null, error: '', all: false, node: null, links: forgeLinks(config && config.forge), specs: null };
33
+ const stops = [];
34
+
35
+ async function load() {
36
+ if (mem.status !== 'idle') return;
37
+ mem.status = 'loading';
38
+ try {
39
+ const res = await credentialed(inst)(HISTORY_PATH);
40
+ const body = await res.json().catch(() => null);
41
+ if (!res.ok || !body || body.ok !== true) throw new Error(body && typeof body.error === 'string' ? body.error : `The history could not be read (${res.status}).`);
42
+ mem.history = body;
43
+ mem.status = 'ready';
44
+ } catch (err) {
45
+ mem.status = 'error';
46
+ mem.error = inst.offline() ? 'You are offline, so the history could not be read.' : String(err && err.message ? err.message : err);
47
+ }
48
+ inst.emit('history:changed');
49
+ }
50
+
51
+ function pick(spec) {
52
+ if (!spec || (state.historyPick && state.historyPick.spec === spec) || mem.status !== 'ready') {
53
+ if (!state.historyPick) return;
54
+ state.historyPick = null;
55
+ announce(inst, 'Showing the whole map again');
56
+ } else {
57
+ const { nodes, commits } = specReach(mem.history, spec);
58
+ state.historyPick = { spec, nodes };
59
+ announce(inst, `Spec ${spec}: ${commits} ${commits === 1 ? 'commit' : 'commits'} reached ${nodes.size} ${nodes.size === 1 ? 'node' : 'nodes'}; the rest is dimmed`);
60
+ }
61
+ inst.touchScene();
62
+ if (inst.map) inst.map.render();
63
+ inst.emit('history:changed');
64
+ }
65
+
66
+ stops.push(inst.on('history:section', (node) => {
67
+ if (mem.status === 'off' || !node || typeof node.id !== 'string') return undefined;
68
+ if (mem.node !== node.id) { mem.node = node.id; mem.all = false; } // "Show all" is for the node it was pressed on
69
+ if (mem.status === 'idle') load();
70
+ if (!mem.specs) mem.specs = specFiles(state.nodes);
71
+ return historySectionHtml(node, { history: mem.history, status: mem.status === 'idle' ? 'loading' : mem.status, error: mem.error, links: mem.links, specs: mem.specs, picked: state.historyPick ? state.historyPick.spec : null, all: mem.all });
72
+ }));
73
+ stops.push(inst.on('history:pick', (spec) => pick(typeof spec === 'string' ? spec : null)));
74
+ // A selection cleared (the bare map, Escape, Close) ends a pick too: nothing on screen would say why the map is dim
75
+ stops.push(inst.on('selection', () => { if (!state.selectedNode && state.historyPick) pick(null); }));
76
+ stops.push(inst.on('history:all', () => { mem.all = true; inst.emit('history:changed'); }));
77
+ return () => { stops.forEach((s) => s()); if (state.historyPick) { state.historyPick = null; inst.touchScene(); } };
78
+ }
@@ -43,6 +43,8 @@ export function createState() {
43
43
  /** The config's `forge` (`{ type, url, repo, baseBranch? }`), or null: where a node's file is opened (file-url.js) */
44
44
  forge: null,
45
45
  searchQuery: '',
46
+ /** The spec picked in a node's History (history.js, spec 0014 D3): `{ spec, nodes }`, the nodes its commits touched, lit while the rest dims; or null */
47
+ historyPick: null,
46
48
  /** The id of the search match the stepping is on (search.js), or null: the map draws its halo and places its label first of the matches */
47
49
  searchCurrent: null,
48
50
  /** The id of the node the pointer is on (input.js): a node with no label is named by a chip while it is */
@@ -99,6 +99,8 @@
99
99
  * player:seat bar -> true the dock's owner (engine/sheets.js) seats the scenario player's bar as a sheet above the node panel's
100
100
  * threads:index nodeId -> { threads: thread[] | null, forge: string, start: true } | undefined the Work list's list of the threads that mention a node, for the node panel's "Threads"; `threads` is null until the list was read; no answer: no Threads section
101
101
  * threads:ensure (none) (emit) the node panel was filled: the Work list reads the threads list once; threads:changed: it was read, or the map changed, so the node panel draws "Threads" again
102
+ * history:section node -> HTML | undefined (ask, answered by history.js when the config says `history: true`) the node panel's History section (spec 0014 D2); history:pick spec | null
103
+ * (emit): light what a spec's commits reached; history:all (emit): list every commit; history:changed (emit): the panel draws History again
102
104
  * work:list { open } the Work list opened or closed (pieces/work-list.js)
103
105
  * work:pick { kind, key } -> true (ask, answered by the Work view: explorer/work-view.js) select the node of that piece of work (`pull`, `issue`, `thread`, `run`, `deploy`, `proposal`, and its number, id or slug) on the map; no answer: the Work piece shows it in the node panel alone, as it shows work older than the graph's 14 days
104
106
  * work:panel node -> { replace, badge, title, html } | undefined (ask, answered by the Work view) what the node panel shows for a piece of work or, in the Work view, a node of code; the html holds `forge-detail`, where the Work piece draws the actions
package/explorer/page.js CHANGED
@@ -62,6 +62,7 @@ import { initTheme, setThemeChoice } from './theme.js';
62
62
  import { initAccountMenu } from './account-menu.js';
63
63
  import { watchHeaderFit } from './header-fit.js';
64
64
  import { watchHint } from './hint.js';
65
+ import { initHistory } from './history.js';
65
66
 
66
67
  /** The instance and its map: made by `startPage`, the one of this document */
67
68
  let inst;
@@ -203,6 +204,7 @@ export function startPage() {
203
204
  initWhatIf(); // before a proposal can open, so its edits come with it
204
205
  initReview(); // the decision follows the what-if editor's edits
205
206
  initMockups(); // a proposal's screens open from the node they name
207
+ initHistory(inst, config); // a node's commits and their trails in the node panel, read when first shown (history.js; only with `history: true`)
206
208
  // /?proposal=<slug> (&source=, &proposalView=) opens a proposal, as a host would ask for one (page-address.js)
207
209
  const proposalOpened = await openFromAddress(inst, window.location.search);
208
210
  // The live layer (live.js): loads only once a live layer goes on in the Layers menu; with no source it stays off
@@ -370,7 +370,7 @@ export function mount(root, inst, options = {}) {
370
370
  }
371
371
 
372
372
  const metaList = own('drawer-meta-list');
373
- scope.listen(metaList, 'click', (e) => { if (!onLinesClick(e)) toggleCapped(e.target); });
373
+ scope.listen(metaList, 'click', (e) => { if (!onLinesClick(e) && !onHistoryClick(e)) toggleCapped(e.target); });
374
374
  scope.listen(metaList, 'change', onLinesChange);
375
375
 
376
376
  /** Keeps "9 connected · 3 off screen" true as the camera moves (after every draw, while a node is selected and its panel is open) */
@@ -391,6 +391,26 @@ export function mount(root, inst, options = {}) {
391
391
  addParts(box);
392
392
  }
393
393
 
394
+ /** Draws "History" again in the open panel (spec 0014 D2: the history was read, a spec was picked, or Show all); nothing else in the panel moves */
395
+ function repaintHistory() {
396
+ const box = own('drawer-history');
397
+ const node = state.selectedNode;
398
+ if (!box || !node || gone) return;
399
+ const active = inst.active();
400
+ const key = active && box.contains(active) ? (active.dataset.historySpec ? `spec:${active.dataset.historySpec}` : active.hasAttribute('data-history-all') ? 'all' : '') : '';
401
+ box.innerHTML = inst.ask('history:section', node) || '';
402
+ addParts(box);
403
+ if (key.startsWith('spec:')) { const el = [...box.querySelectorAll('[data-history-spec]')].find((x) => `spec:${x.dataset.historySpec}` === key); if (el) el.focus(); }
404
+ else if (key === 'all') { const first = box.querySelector('.hx-history-commit a'); if (first) first.focus(); }
405
+ }
406
+ /** A spec's chip in "History" picks it (or ends the pick); "Show all" lists every commit */
407
+ function onHistoryClick(e) {
408
+ const spec = e.target.closest && e.target.closest('[data-history-spec]');
409
+ if (spec) { inst.emit('history:pick', spec.dataset.historySpec); return true; }
410
+ if (e.target.closest && e.target.closest('[data-history-all]')) { inst.emit('history:all'); return true; }
411
+ return false;
412
+ }
413
+
394
414
  /** What the Work view put first in the panel for a node of code (the Work layer's "Open work", or the work touching it in the Work view): its elements and its markup */
395
415
  let workShown = { node: null, html: '', els: [] };
396
416
  function putWork(node, html) {
@@ -437,6 +457,7 @@ export function mount(root, inst, options = {}) {
437
457
  <div id="drawer-live">${live}</div>
438
458
  ${nodeMockupsHtml(state, node.id)}
439
459
  <div id="drawer-threads">${sections.threadsSection(node)}</div>
460
+ <div id="drawer-history">${inst.ask('history:section', node) || ''}</div>
440
461
  ${sections.diffSection(node)}`;
441
462
  addParts(metaList);
442
463
  inst.emit('threads:ensure'); // the Work list reads the threads once, for "Mentioned in"
@@ -573,6 +594,7 @@ export function mount(root, inst, options = {}) {
573
594
  });
574
595
  // The threads that mention nodes changed (the list was read, or the map changed): the section is drawn again
575
596
  scope.on('threads:changed', () => repaintThreads());
597
+ scope.on('history:changed', () => repaintHistory());
576
598
  scope.on('work:changed', () => repaintWork());
577
599
  // The dim layer behind the panel: on a phone a tap there folds the panel to its peek; elsewhere it closes it
578
600
  if (!inline) {
package/explorer/scene.js CHANGED
@@ -589,9 +589,11 @@ function buildNodes(state, subgraph) {
589
589
  // deep dimming for what is not connected; a proposal's Diff view fades what it does not touch, less deeply, and a removed node is faded too
590
590
  // A search's matches are what the reader asked for: a selection's focus does not dim them, so each keeps its label (spec 0008 D4)
591
591
  const dimmed = state.view === 'work' ? PROPOSAL_DIM_ALPHA : DIM_ALPHA; // the Work view dims to what the mock shows: the rest is still readable
592
- let alpha = subgraph && !connected && !(searching && match) ? dimmed : 1;
592
+ const picked = !!state.historyPick && state.historyPick.nodes.has(node.id); // a picked spec's nodes are what the reader asked for, as a search's matches are
593
+ let alpha = subgraph && !connected && !(searching && match) && !picked ? dimmed : 1;
593
594
  if (searching && !match && !selected && !(subgraph && connected)) alpha = dimmed; // a search dims what it did not find, as a focus does
594
595
  if (node.dim === true) alpha = Math.min(alpha, dimmed); // "Waiting on you" (work-view.js)
596
+ if (state.historyPick && !picked && !selected) alpha = Math.min(alpha, dimmed); // a picked spec lights what it reached (history.js, spec 0014 D3)
595
597
  const greyed = grey && !!focus && !focus.touched.has(node.id);
596
598
  if (focus && !focus.touched.has(node.id)) alpha = Math.min(alpha, greyed ? GREY_ALPHA : PROPOSAL_DIM_ALPHA);
597
599
  if (look) alpha *= gone ? MARK.removed.alpha : look.alpha;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@popcorn245/cornfield",
3
- "version": "0.58.0",
3
+ "version": "0.60.0",
4
4
  "description": "A self-hostable dev dashboard with the topology map at its centre: proposals on the map, scenarios, outages and what-if edits, for any repo.",
5
5
  "license": "MIT",
6
6
  "author": "popcorn245 (https://github.com/popcorn245)",
package/server/server.js CHANGED
@@ -23,7 +23,8 @@
23
23
  * that says how to build them when this checkout has none (server/components.js)
24
24
  * GET /cornfield/brand/<key>.<ext> a brand image the config's `brand` names (logo, wordmark, favicon; svg or png, 512 KB each): those files only
25
25
  * GET /manifest.webmanifest the web app manifest: the repo's title, or built from `brand` when the config sets one
26
- * GET /api/forge/… issues, pull requests, their files and checks, release notes: read from the forge (server/forge-routes.js)
26
+ * GET /api/history the map's git history (core/history.js; spec 0014), when the config says `history: true`: a 404 otherwise
27
+ * GET /api/forge/… issues pull requests, their files and checks, release notes: read from the forge (server/forge-routes.js)
27
28
  * POST /api/forge/pulls/<n>/merge|rerun land a green pull request, re-run a failed check (server/forge-actions.js)
28
29
  * POST /api/forge/issues/<n>/spec, /pulls/<n>/build the pipeline's steps (server/pipeline.js, server/forge-actions.js)
29
30
  * POST /api/forge/release-drafts the release notes kept as a DRAFT release on the forge (never published, no tag made)
@@ -83,6 +84,7 @@ import { createRunnerWatch, runnerPresence } from './runner-presence.js';
83
84
  import { createTriggers } from './triggers.js';
84
85
  import { brandHead, escapeHtml, themeHead, themeHtmlTag } from './page-head.js';
85
86
  import { compressResponse } from './compress.js';
87
+ import { createHistory } from '../core/history.js';
86
88
 
87
89
  export const CORNFIELD_DIR = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
88
90
  const EXPLORER_DIR = path.join(CORNFIELD_DIR, 'explorer');
@@ -263,6 +265,8 @@ export function clientConfig(config, signIn = false) {
263
265
  forge: config.forge ? { type: config.forge.type, url: config.forge.url || (config.forge.type === 'github' ? 'https://github.com' : null), repo: config.forge.repo, mergeMethod: config.forge.mergeMethod || 'merge', ...(config.forge.baseBranch ? { baseBranch: config.forge.baseBranch } : {}), ...(config.approveLands ? { approveLands: true } : {}) } : null,
264
266
  // Threads (docs/threads.md): the idea label, or false when `threads: false` turns the Threads tab off
265
267
  threads: config.threads === false ? false : { label: ideaLabel(config) },
268
+ // The map's git history is read (spec 0014): the page then offers the History layer, a node's commits and Replay
269
+ history: config.history === true,
266
270
  sources: browserSources(config),
267
271
  // Agent runs are followed (and marked on the map) where there is a forge and a sign-in (docs/agents.md)
268
272
  ...(config.forge && signIn ? { agents: { runs: true } } : {}),
@@ -320,6 +324,8 @@ export function createCornfieldServer(config, opts = {}) {
320
324
  const components = createComponents({ dir: opts.componentsDir ?? path.join(CORNFIELD_DIR, 'components', 'dist') });
321
325
  const where = { root, proposals: config.proposals, worktrees: config.worktrees, worktreeMaxAgeDays: config.worktreeMaxAgeDays, topology: config.topology, dataDir: config.dataDir, publicHost, publicOrigin, embedOrigins: embed.origins };
322
326
  const fixtureCache = new Map();
327
+ // The repo's git history, read when first asked for and kept per HEAD and map (core/history.js); only with `history: true`
328
+ const history = config.history === true ? createHistory(root) : null;
323
329
  // What the line above Approve says an approval does besides posting (spec 0007 D1, server/decision.js): landing, and the run a trigger asks for
324
330
  const approvalRun = triggersOf(config).find(([event]) => event === 'spec.approved');
325
331
  const decisionFacts = {
@@ -517,6 +523,21 @@ export function createCornfieldServer(config, opts = {}) {
517
523
  if (!file) return sendJson(res, 404, { error: `${config.topology} is not there yet: run cornfield sync` });
518
524
  return sendFile(req, res, file, reqPath);
519
525
  }
526
+ if (reqPath === '/api/history') {
527
+ if (!history) return sendJson(res, 404, { ok: false, error: 'History is off. Set history: true in cornfield.config.js to read the repo\'s git history (docs/config.md#history).' });
528
+ const file = inside(root, config.topology);
529
+ const got = file && readPlain(file);
530
+ if (!got) return sendJson(res, 404, { ok: false, error: `${config.topology} is not there yet: run cornfield sync` });
531
+ let topology;
532
+ try { topology = JSON.parse(got.body.toString('utf8')); } catch { return sendJson(res, 422, { ok: false, error: `${config.topology} is not valid JSON` }); }
533
+ try {
534
+ const data = await history.get(topology, `${got.stats.mtimeMs}|${got.stats.size}`);
535
+ return sendJson(res, 200, { ok: true, ...data });
536
+ } catch (err) {
537
+ if (err.code !== 'ENOHISTORY') throw err;
538
+ return sendJson(res, 503, { ok: false, error: err.message });
539
+ }
540
+ }
520
541
  if (reqPath === '/topology.cloud.json') {
521
542
  const file = inside(root, CLOUD_FILE);
522
543
  const got = file && readPlain(file);