cornfield 0.62.0 → 0.64.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.
Files changed (44) hide show
  1. package/core/release-notes.js +2 -2
  2. package/explorer/css/changes.css +3 -7
  3. package/explorer/css/header.css +15 -0
  4. package/explorer/css/layers.css +11 -2
  5. package/explorer/css/map.css +0 -1
  6. package/explorer/css/node-panel.css +45 -0
  7. package/explorer/css/page.css +2 -7
  8. package/explorer/css/proposal.css +2 -3
  9. package/explorer/css/work.css +7 -7
  10. package/explorer/engine/hint.js +7 -7
  11. package/explorer/engine/keyboard.js +5 -4
  12. package/explorer/engine/map-rect.js +2 -2
  13. package/explorer/engine/render.js +2 -1
  14. package/explorer/forge-panel-model.js +24 -0
  15. package/explorer/history-model.js +21 -11
  16. package/explorer/history-replay.js +13 -5
  17. package/explorer/history.js +16 -7
  18. package/explorer/inbox-model.js +180 -0
  19. package/explorer/index.html +6 -3
  20. package/explorer/page.js +1 -2
  21. package/explorer/panel-model.js +103 -0
  22. package/explorer/panel-sections.js +140 -0
  23. package/explorer/pieces/inbox.js +201 -0
  24. package/explorer/pieces/layers.js +27 -6
  25. package/explorer/pieces/node-panel.js +78 -1
  26. package/explorer/pieces/search.js +22 -9
  27. package/explorer/pieces/work-deploys.js +13 -13
  28. package/explorer/pieces/work-issues.js +10 -5
  29. package/explorer/pieces/work-list.js +72 -9
  30. package/explorer/pieces/work-paint.js +45 -10
  31. package/explorer/pieces/work-prs.js +46 -34
  32. package/explorer/pieces/work-runs.js +17 -5
  33. package/explorer/pieces/work-specs.js +24 -4
  34. package/explorer/pieces/work-threads.js +59 -15
  35. package/explorer/pieces/work.js +6 -3
  36. package/explorer/proposal-model.js +3 -6
  37. package/explorer/runs-view.js +42 -8
  38. package/explorer/scene.js +5 -1
  39. package/explorer/work-model.js +266 -55
  40. package/explorer/work-view.css +60 -16
  41. package/explorer/work-view.js +175 -35
  42. package/package.json +1 -1
  43. package/server/server.js +1 -1
  44. package/server/work-graph.js +65 -8
@@ -15,9 +15,10 @@
15
15
  * deploy deploy:<id> ship a workflow run the config says is a deploy (server/deploys.js)
16
16
  *
17
17
  * Every node: `{ id, kind, stage, title, state, open, waiting, url, updated, ...}` and its number (`number`), slug (`slug`), run id (`runId`) or
18
- * deploy id (`deployId`). `waiting` is spec 0010 D1's rule, worked out by the same functions the page's number uses (explorer/waiting-model.js
18
+ * deploy id (`deployId`). A run also carries `note` (its report's last word, the question when it waits), `brief` and `pull` (`{ number, state }` of the pull
19
+ * request it opened); an open pull request `checks` (`checkCounts`: failed, running, passed, green and the names), or null when they could not be read (spec 0016 D9). `waiting` is spec 0010 D1's rule, worked out by the same functions the page's number uses (explorer/waiting-model.js
19
20
  * `specStateOf`, explorer/runs-model.js `canAnswer`): a spec to decide, a run waiting on an answer; nothing else asks the maintainer a question.
20
- * The code a proposal adds, and the map does not hold yet, comes as `{ id, kind: 'code', planned: true, label, type }`; the code that exists is
21
+ * The code a proposal adds, and the map does not hold yet, comes as `{ id, kind: 'code', planned: true, label, type, parent }`; the code that exists is
21
22
  * on the map the page already has, and is only named by edges.
22
23
  *
23
24
  * Rel From -> to Comes from
@@ -51,7 +52,7 @@
51
52
  */
52
53
 
53
54
  import fs from 'node:fs';
54
- import { DEFAULT_LIMIT, ForgeError } from './forge.js';
55
+ import { DEFAULT_LIMIT, ForgeError, isGreen, RERUN_STATES } from './forge.js';
55
56
  import { filesAt, forgeWords, pullProposals, readPullProposal, reviewStates } from './proposal-pulls.js';
56
57
  import { listProposalFiles } from './files.js';
57
58
  import { deploysOf } from './deploys.js';
@@ -115,13 +116,13 @@ const list = (v) => (Array.isArray(v) ? v : []);
115
116
  const text = (v) => (typeof v === 'string' ? v : '');
116
117
 
117
118
  /**
118
- * What a proposal does to the map: the nodes it adds (`{ id, label, type }`), and the ids it changes or removes. Anything that is not a proposal does nothing.
119
+ * What a proposal does to the map: the nodes it adds (`{ id, label, type, parent }`: the page groups a planned node under the area its parent is in), and the ids it changes or removes. Anything that is not a proposal does nothing.
119
120
  * @param {any} proposal
120
- * @returns {{ adds: { id: string, label: string, type: string | null }[], changes: string[] }}
121
+ * @returns {{ adds: { id: string, label: string, type: string | null, parent: string | null }[], changes: string[] }}
121
122
  */
122
123
  export function touchesOf(proposal) {
123
124
  const nodes = proposal !== null && typeof proposal === 'object' ? proposal.nodes : null;
124
- const adds = list(nodes && nodes.add).filter((n) => n && typeof n.id === 'string' && n.id !== '').map((n) => ({ id: n.id, label: text(n.label) || n.id, type: text(n.type) || null }));
125
+ const adds = list(nodes && nodes.add).filter((n) => n && typeof n.id === 'string' && n.id !== '').map((n) => ({ id: n.id, label: text(n.label) || n.id, type: text(n.type) || null, parent: text(n.parent) || null }));
125
126
  const changes = [...list(nodes && nodes.change), ...list(nodes && nodes.remove)].map((n) => (typeof n === 'string' ? n : n && n.id)).filter((id) => typeof id === 'string' && id !== '');
126
127
  return { adds, changes: [...new Set(changes)] };
127
128
  }
@@ -152,6 +153,48 @@ async function each(items, fn) {
152
153
  return out;
153
154
  }
154
155
 
156
+ /** The longest a run's note or brief is carried, in characters */
157
+ export const NOTE_CUT = 300;
158
+ const clip = (s, n) => (s.length > n ? `${s.slice(0, n - 1)}…` : s);
159
+ /** The states a check is still on its way in */
160
+ const GOING = new Set(['queued', 'running', 'pending', 'in_progress', 'waiting']);
161
+
162
+ /**
163
+ * A commit's checks as counts (spec 0016 D9): failed (failed or cancelled), running (queued or running), passed, and `green` as landing reads it
164
+ * (server/forge.js `isGreen`). The inbox says "lint failed · test running" from the names of the failed and running ones (`failedNames`, `runningNames`, at most five each).
165
+ * @param {{ name: string, state: string }[]} checks
166
+ */
167
+ export function checkCounts(checks) {
168
+ const list = Array.isArray(checks) ? checks : [];
169
+ const failed = list.filter((c) => RERUN_STATES.includes(c.state));
170
+ const going = list.filter((c) => GOING.has(c.state));
171
+ return {
172
+ failed: failed.length, running: going.length, passed: list.filter((c) => c.state === 'success').length, green: isGreen(list),
173
+ failedNames: failed.slice(0, 5).map((c) => text(c.name)), runningNames: going.slice(0, 5).map((c) => text(c.name)),
174
+ };
175
+ }
176
+
177
+ /** How long a head's checks are kept: while one runs, a minute (the page asks every minute); once all are over, ten (a re-run starts them again) */
178
+ export const CHECKS_KEEP_RUNNING_MS = 60_000;
179
+ export const CHECKS_KEEP_DONE_MS = 10 * 60_000;
180
+ const CHECKS_KEPT_MAX = 500;
181
+ /** where -> sha -> { at, keep, counts } */
182
+ const checkCaches = new WeakMap();
183
+
184
+ /** The checks at a head sha as counts, kept per `where` (CHECKS_KEEP_*); a failed read is never kept */
185
+ async function checksAt(forge, where, sha, nowMs) {
186
+ const key = where && typeof where === 'object' ? where : checkCaches;
187
+ let kept = checkCaches.get(key);
188
+ if (!kept) checkCaches.set(key, (kept = new Map()));
189
+ const got = kept.get(sha);
190
+ if (got && nowMs - got.at < got.keep) return got.counts;
191
+ const counts = checkCounts(await forge.checks(sha));
192
+ kept.delete(sha);
193
+ kept.set(sha, { at: nowMs, keep: counts.running ? CHECKS_KEEP_RUNNING_MS : CHECKS_KEEP_DONE_MS, counts });
194
+ while (kept.size > CHECKS_KEPT_MAX) kept.delete(kept.keys().next().value);
195
+ return counts;
196
+ }
197
+
155
198
  /** An id of the work graph's own: a map node with one would be two things */
156
199
  const WORK_ID = /^(?:thread|issue|proposal|run|pull|deploy):/;
157
200
  /** A link the page may open: http(s) only; anything else (a runner's report saying `javascript:`) is no link */
@@ -338,10 +381,21 @@ export async function workGraph(forge, config, map, { where = config, runs = nul
338
381
  }
339
382
  }
340
383
 
384
+ // The checks on each open pull request's head, as counts (spec 0016 D9): asked each time, since a head's checks move while it stays
385
+ const checkable = pulls.filter((p) => !specEntries.has(p.number) && p.state === 'open' && p.head && p.head.sha);
386
+ const gotChecks = await each(checkable, (pull) => attempt(() => checksAt(forge, where, pull.head.sha, nowMs)));
387
+ const checksOf = new Map();
388
+ const noChecks = [];
389
+ for (const [i, pull] of checkable.entries()) {
390
+ if (gotChecks[i].err) noChecks.push(pull.number);
391
+ else checksOf.set(pull.number, gotChecks[i].value);
392
+ }
393
+ if (noChecks.length) say('pulls', `The checks of ${noChecks.length === 1 ? 'pull request' : 'pull requests'} ${numbers(noChecks)} could not be read, so they are not said.`);
394
+
341
395
  for (const pull of pulls) {
342
396
  if (specEntries.has(pull.number)) continue;
343
397
  const id = `pull:${pull.number}`;
344
- put({ id, kind: 'pull', title: pull.title, state: pull.state, open: pull.state === 'open', number: pull.number, url: webUrl(pull.url), updated: pull.updatedAt, draft: pull.draft, author: pull.author ? pull.author.login : null });
398
+ put({ id, kind: 'pull', title: pull.title, state: pull.state, open: pull.state === 'open', number: pull.number, url: webUrl(pull.url), updated: pull.updatedAt, draft: pull.draft, author: pull.author ? pull.author.login : null, checks: checksOf.get(pull.number) ?? null });
345
399
  byPull.set(pull.number, [id]);
346
400
  if (filesOf.has(pull.number)) for (const to of nodesOfFiles(filesOf.get(pull.number), mapNodes)) edge(id, to, 'changes');
347
401
  }
@@ -459,6 +513,9 @@ export async function workGraph(forge, config, map, { where = config, runs = nul
459
513
  put({
460
514
  id, kind: 'run', title: runName(run), state: run.status, open: run.open === true, waiting: canAnswer(run), runId: run.runId, number: null, url: webUrl(run.report && run.report.url) || webUrl(run.comment && run.comment.url) || webUrl(run.pull && run.pull.url),
461
515
  updated: ended, requestedBy: run.requestedBy ?? null,
516
+ // what the inbox says of it (spec 0016 D9): its question or last word, what it was asked to do, and the pull request it opened
517
+ note: clip(text(run.report && run.report.note), NOTE_CUT) || null, brief: clip(text(run.brief), NOTE_CUT) || null,
518
+ pull: run.pull && Number.isInteger(run.pull.number) ? { number: run.pull.number, state: text(run.pull.state) || null } : null,
462
519
  });
463
520
  const about = [run.refs && run.refs.issue, run.refs && run.refs.thread].filter((n) => n != null).map(talkNode).filter(Boolean);
464
521
  for (const from of new Set(about)) edge(from, id, 'agent-on');
@@ -501,6 +558,6 @@ export async function workGraph(forge, config, map, { where = config, runs = nul
501
558
  return true;
502
559
  }).sort((a, b) => (a.from < b.from ? -1 : a.from > b.from ? 1 : a.to < b.to ? -1 : a.to > b.to ? 1 : a.rel < b.rel ? -1 : a.rel > b.rel ? 1 : 0));
503
560
  const out = [...nodes.values()].sort((a, b) => KINDS.indexOf(a.kind) - KINDS.indexOf(b.kind) || newest(a, b));
504
- const plannedOut = [...planned.values()].filter((p) => kept.some((e) => e.to === p.id)).sort((a, b) => (a.id < b.id ? -1 : 1)).map((p) => ({ id: p.id, kind: 'code', planned: true, label: p.label, type: p.type }));
561
+ const plannedOut = [...planned.values()].filter((p) => kept.some((e) => e.to === p.id)).sort((a, b) => (a.id < b.id ? -1 : 1)).map((p) => ({ id: p.id, kind: 'code', planned: true, label: p.label, type: p.type, parent: p.parent ?? null }));
505
562
  return { nodes: [...out, ...plannedOut], edges: kept, problems };
506
563
  }