cornfield 0.34.3 → 0.35.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/contrast.js +3 -1
- package/explorer/connection.js +62 -0
- package/explorer/corn-state.js +34 -2
- package/explorer/explorer.css +61 -3
- package/explorer/feedback.js +49 -0
- package/explorer/forge-panel-model.js +41 -7
- package/explorer/forge-panel.js +223 -56
- package/explorer/index.html +4 -0
- package/explorer/panels.js +10 -4
- package/explorer/proposal-model.js +34 -5
- package/explorer/proposal.js +33 -10
- package/explorer/review.js +48 -7
- package/explorer/runs-model.js +42 -18
- package/explorer/runs-view.js +58 -20
- package/explorer/tokens.css +10 -0
- package/package.json +1 -1
- package/server/forge-http.js +1 -1
package/core/contrast.js
CHANGED
|
@@ -347,11 +347,13 @@ const tint = (token, pct) => `color-mix(in srgb, var(${token}) ${pct}%, transpar
|
|
|
347
347
|
const toText = (token, pct) => `color-mix(in srgb, var(${token}) ${pct}%, var(--corn-text))`;
|
|
348
348
|
|
|
349
349
|
/** Text tokens: read on the ground and on every surface */
|
|
350
|
-
export const TEXT_TOKENS = Object.freeze(['--corn-text', '--corn-text-2', '--corn-text-3', '--corn-accent-text', '--corn-ok', '--corn-warn', '--corn-bad', '--corn-info', '--corn-added-text', '--corn-edit-text'
|
|
350
|
+
export const TEXT_TOKENS = Object.freeze(['--corn-text', '--corn-text-2', '--corn-text-3', '--corn-accent-text', '--corn-ok', '--corn-warn', '--corn-bad', '--corn-info', '--corn-added-text', '--corn-edit-text',
|
|
351
|
+
'--corn-run-requested', '--corn-run-claimed', '--corn-run-working', '--corn-run-waiting', '--corn-run-done', '--corn-run-failed', '--corn-run-stopped']);
|
|
351
352
|
/** The tinted backgrounds, with the text that sits on each */
|
|
352
353
|
export const SOFT_PAIRS = Object.freeze([
|
|
353
354
|
['--corn-ok', '--corn-ok-soft'],
|
|
354
355
|
['--corn-accent-text', '--corn-accent-soft'], ['--corn-hue-orange-text', '--corn-hue-orange-soft'],
|
|
356
|
+
['--corn-run-waiting-ink', '--corn-run-waiting'], // the waiting pill is solid: its word and icon in the ink, on the fill
|
|
355
357
|
]);
|
|
356
358
|
/** Solid fills that carry `--corn-ground` as their text (a pressed data-flow button, a chip, the What-if toggle, the House chip) */
|
|
357
359
|
export const SOLID_FILLS = Object.freeze(['--corn-ok', '--corn-warn', '--corn-bad', '--corn-info', '--corn-hue-orange', '--corn-hue-lime', '--corn-added-text', '--corn-edit-text']);
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module explorer/connection
|
|
3
|
+
*
|
|
4
|
+
* Whether the browser is online, said once and in one place. `isOffline()` is `navigator.onLine === false`; when it changes a banner
|
|
5
|
+
* (`#offline-banner`, index.html) says "You are offline" or "You are back online" and the live region announces it once. Every failure
|
|
6
|
+
* that has no answer from the server (a failed fetch) is worded by the caller with `isOffline()`: offline it is "You are offline", not
|
|
7
|
+
* "cornfield could not be reached", and an action says it was not sent and keeps what the person typed.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { announce } from './keyboard.js';
|
|
11
|
+
|
|
12
|
+
export const OFFLINE_WORDS = 'You are offline. Nothing is sent until you are back; what you have typed is kept.';
|
|
13
|
+
export const ONLINE_WORDS = 'You are back online.';
|
|
14
|
+
/** How long "back online" stays on the banner */
|
|
15
|
+
export const BACK_MS = 5000;
|
|
16
|
+
|
|
17
|
+
let wired = false;
|
|
18
|
+
let hideTimer = 0;
|
|
19
|
+
|
|
20
|
+
/** Whether the browser says it has no network */
|
|
21
|
+
export const isOffline = () => typeof navigator !== 'undefined' && navigator.onLine === false;
|
|
22
|
+
|
|
23
|
+
/** The words for an action that got no answer: offline, it was not sent (and what was typed is still there); online, the server did not answer */
|
|
24
|
+
export function notSentWords(what) {
|
|
25
|
+
return isOffline() ? `You are offline. ${what} was not sent; what you typed is kept. Try again when you are back.` : `cornfield did not answer. ${what} was not sent; what you typed is kept.`;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function paint(said) {
|
|
29
|
+
const el = document.getElementById('offline-banner');
|
|
30
|
+
if (!el) return;
|
|
31
|
+
clearTimeout(hideTimer);
|
|
32
|
+
el.hidden = false;
|
|
33
|
+
el.textContent = said;
|
|
34
|
+
el.dataset.cornState = isOffline() ? 'failure' : 'success';
|
|
35
|
+
if (!isOffline()) hideTimer = setTimeout(() => { el.hidden = true; }, BACK_MS);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function onChange() {
|
|
39
|
+
const words = isOffline() ? OFFLINE_WORDS : ONLINE_WORDS;
|
|
40
|
+
paint(words);
|
|
41
|
+
announce(words);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Listens for the browser going offline and coming back (once); says so now if the page opened offline */
|
|
45
|
+
export function initConnection() {
|
|
46
|
+
if (wired || typeof window === 'undefined') return;
|
|
47
|
+
wired = true;
|
|
48
|
+
window.addEventListener('offline', onChange);
|
|
49
|
+
window.addEventListener('online', onChange);
|
|
50
|
+
if (isOffline()) paint(OFFLINE_WORDS);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** For tests: forget the wiring */
|
|
54
|
+
export function resetConnectionForTests() {
|
|
55
|
+
if (wired && typeof window !== 'undefined') {
|
|
56
|
+
window.removeEventListener('offline', onChange);
|
|
57
|
+
window.removeEventListener('online', onChange);
|
|
58
|
+
}
|
|
59
|
+
wired = false;
|
|
60
|
+
clearTimeout(hideTimer);
|
|
61
|
+
hideTimer = 0;
|
|
62
|
+
}
|
package/explorer/corn-state.js
CHANGED
|
@@ -5,12 +5,16 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
/** Every value `data-corn-state` can take */
|
|
8
|
-
export const CORN_STATES = Object.freeze(['open', 'merged', 'closed', 'draft', 'queued', 'running', 'waiting', 'done', 'failed', 'stopped', 'success', 'failure']);
|
|
8
|
+
export const CORN_STATES = Object.freeze(['open', 'merged', 'closed', 'draft', 'queued', 'running', 'requested', 'claimed', 'working', 'waiting', 'done', 'failed', 'stopped', 'success', 'failure']);
|
|
9
|
+
|
|
10
|
+
/** The seven states of an agent run, in the order of its life: each has its own `data-corn-state`, colour token (`--corn-run-<state>`) and icon */
|
|
11
|
+
export const RUN_STATES = Object.freeze(['requested', 'claimed', 'working', 'waiting', 'done', 'failed', 'stopped']);
|
|
9
12
|
|
|
10
13
|
/** The internal words that map onto a public one: a run's status, a check's or deploy's conclusion, a mockup's review, a verdict, a notice */
|
|
11
14
|
const WORDS = Object.freeze({
|
|
12
15
|
// A run's status: it is waiting to start, it is running, it waits on someone, or it ended
|
|
13
|
-
|
|
16
|
+
// (a run that went quiet waits on someone; one asked to stop has not stopped yet, but is no longer under way)
|
|
17
|
+
quiet: 'waiting', 'stop-requested': 'stopped',
|
|
14
18
|
// A check's or deploy's conclusion
|
|
15
19
|
neutral: 'done', skipped: 'done', cancelled: 'stopped',
|
|
16
20
|
// A mockup's review state
|
|
@@ -32,3 +36,31 @@ export function cornStateAttr(word) {
|
|
|
32
36
|
const s = cornState(word);
|
|
33
37
|
return s ? ` data-corn-state="${s}"` : '';
|
|
34
38
|
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The icon of a state: a shape as well as a colour, so the states differ in greyscale and for a person who cannot tell the colours apart.
|
|
42
|
+
* Each shape is its own silhouette (a dashed ring, a ring with a dot, an arc that turns, a warning triangle, a tick, a cross, a square),
|
|
43
|
+
* drawn with `currentColor` so the pill's colour carries it. Only `working` and `running` move, and not under `prefers-reduced-motion`.
|
|
44
|
+
*/
|
|
45
|
+
const ICONS = Object.freeze({
|
|
46
|
+
requested: '<circle cx="6" cy="6" r="4.2" stroke-dasharray="2 1.8"/>',
|
|
47
|
+
queued: '<circle cx="6" cy="6" r="4.2" stroke-dasharray="2 1.8"/>',
|
|
48
|
+
claimed: '<circle cx="6" cy="6" r="4.2"/><circle cx="6" cy="6" r="1.4" fill="currentColor" stroke="none"/>',
|
|
49
|
+
working: '<path class="hx-state-spin" d="M6 1.8a4.2 4.2 0 1 1-4.2 4.2"/>',
|
|
50
|
+
running: '<path class="hx-state-spin" d="M6 1.8a4.2 4.2 0 1 1-4.2 4.2"/>',
|
|
51
|
+
waiting: '<path d="M6 1.2L11 10.4H1Z" stroke-linejoin="round"/><path d="M6 4.6v2.7M6 8.6v.1"/>',
|
|
52
|
+
done: '<path d="M2 6.4l2.6 2.6L10 3.4"/>',
|
|
53
|
+
success: '<path d="M2 6.4l2.6 2.6L10 3.4"/>',
|
|
54
|
+
failed: '<path d="M2.6 2.6l6.8 6.8M9.4 2.6L2.6 9.4"/>',
|
|
55
|
+
failure: '<path d="M2.6 2.6l6.8 6.8M9.4 2.6L2.6 9.4"/>',
|
|
56
|
+
stopped: '<rect x="2.4" y="2.4" width="7.2" height="7.2" rx="1" fill="currentColor"/>',
|
|
57
|
+
neutral: '<path d="M2.4 6h7.2"/>',
|
|
58
|
+
skipped: '<path d="M2.4 6h7.2"/>',
|
|
59
|
+
cancelled: '<circle cx="6" cy="6" r="4.2"/><path d="M3 9L9 3"/>',
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
/** The icon for a state word (a public `data-corn-state` value, or an internal word such as a check's `neutral`), as an inline SVG; '' when it has none */
|
|
63
|
+
export function stateIconHtml(word) {
|
|
64
|
+
const shape = ICONS[String(word || '')] || ICONS[cornState(word)];
|
|
65
|
+
return shape ? `<svg class="hx-state-icon" data-corn="state-icon" width="12" height="12" viewBox="0 0 12 12" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" aria-hidden="true" focusable="false">${shape}</svg>` : '';
|
|
66
|
+
}
|
package/explorer/explorer.css
CHANGED
|
@@ -737,7 +737,7 @@ button.hx-proposal-item:focus-visible { outline: var(--corn-focus-width) solid v
|
|
|
737
737
|
.hx-forge:not(.forge-open) { display: none; }
|
|
738
738
|
.hx-forge { max-height: 60dvh; }
|
|
739
739
|
.hx-forge[data-sheet-state="peek"] .hx-forge-body { flex: none; padding: 0 var(--corn-space-5) var(--corn-space-3); gap: var(--corn-space-1); overflow: hidden; }
|
|
740
|
-
.hx-forge[data-sheet-state="peek"] .hx-forge-body > :not(.hx-forge-
|
|
740
|
+
.hx-forge[data-sheet-state="peek"] .hx-forge-body > :not(.hx-forge-top):not(#forge-bar), .hx-forge[data-sheet-state="peek"] #forge-filter-chip, .hx-forge[data-sheet-state="peek"] .hx-forge-tabs { display: none; }
|
|
741
741
|
.hx-forge[data-sheet-state="peek"] .hx-forge-head { padding-bottom: 0; border-bottom: 0; }
|
|
742
742
|
.hx-forge[data-sheet-state="peek"] .hx-forge-head .hx-btn { display: none; }
|
|
743
743
|
}
|
|
@@ -838,7 +838,9 @@ a.hx-forge-row:hover, button.hx-forge-row:hover { background: var(--corn-surface
|
|
|
838
838
|
.hx-tokens-form { display: grid; grid-template-columns: 1fr 5rem; gap: var(--corn-space-3); align-items: end; }
|
|
839
839
|
.hx-tokens-form .hx-btn { grid-column: 1 / -1; justify-self: start; }
|
|
840
840
|
.hx-forge-nodes { flex-basis: 100%; display: flex; flex-wrap: wrap; gap: var(--corn-space-1); padding-left: calc(var(--hx-forge-status-w) + var(--corn-space-2)); }
|
|
841
|
-
|
|
841
|
+
/* A node button is a button (a square corner, a filled face, an arrow), never a state pill */
|
|
842
|
+
.hx-forge-node { padding: calc(var(--corn-space-1) / 2) var(--corn-space-3); border-radius: var(--corn-radius-sm); border: var(--corn-border) solid var(--corn-line); background: var(--corn-surface-3); color: var(--corn-text); font-size: var(--corn-text-xs); }
|
|
843
|
+
.hx-forge-node::after { content: ' \2192'; }
|
|
842
844
|
.hx-forge-node:hover { background: var(--corn-surface-3); }
|
|
843
845
|
.hx-forge-work-filters { display: flex; flex-wrap: wrap; gap: var(--corn-space-2) var(--corn-space-4); }
|
|
844
846
|
.hx-forge-work-filters[hidden], .hx-forge-filters[hidden] { display: none; }
|
|
@@ -876,7 +878,7 @@ a.hx-forge-row:hover, button.hx-forge-row:hover { background: var(--corn-surface
|
|
|
876
878
|
.hx-forge-cta .hx-btn--approve { flex: 1; }
|
|
877
879
|
.hx-forge-cta .hx-btn[disabled] { background: var(--corn-surface-3); border-color: var(--corn-line); color: var(--corn-text-3); box-shadow: none; cursor: default; }
|
|
878
880
|
.hx-forge-open { text-decoration: none; color: var(--corn-text-2); }
|
|
879
|
-
.hx-forge-runline { display: flex; flex-wrap: wrap; align-items: center; gap: var(--corn-space-2);
|
|
881
|
+
.hx-forge-runline { display: flex; flex-wrap: wrap; align-items: center; gap: var(--corn-space-2); margin: 0; color: var(--corn-text-2); } /* a line of text with a state pill, not a box: it is not a control */
|
|
880
882
|
/* The foot of a list: Release notes … on PRs, New idea on Specs and Threads */
|
|
881
883
|
.hx-forge-foot { display: flex; flex-direction: column; gap: var(--corn-space-3); margin-top: auto; padding-top: var(--corn-space-3); border-top: var(--corn-border) solid var(--corn-line); }
|
|
882
884
|
.hx-forge-foot > .hx-btn { align-self: flex-start; }
|
|
@@ -1068,3 +1070,59 @@ a.hx-proposal-source:focus-visible { outline: var(--corn-focus-width) solid var(
|
|
|
1068
1070
|
.hx-sheet-handle { height: 44px; } /* the grip is drawn the same; the button itself is 44px (a hit area stretched past it is clipped by the sheet above, and covers its title below) */
|
|
1069
1071
|
.hx-run .hx-link, .hx-forge-check .hx-link { display: inline-flex; align-items: center; min-height: 44px; }
|
|
1070
1072
|
}
|
|
1073
|
+
|
|
1074
|
+
/* ==========================================================================
|
|
1075
|
+
The Work panel's states, results, disabled controls, loading and empty lists, and its fixed top (the 0.34 design review)
|
|
1076
|
+
========================================================================== */
|
|
1077
|
+
|
|
1078
|
+
/* A state is a word, an icon and a colour: the colour comes from a --corn-run-<state> token, the icon is a shape of its own (corn-state.js), and
|
|
1079
|
+
the waiting pill is solid, since a run that waits needs the maintainer and should stand out most. A pill is never a button: it has no hover. */
|
|
1080
|
+
.hx-forge-state { display: inline-flex; align-items: center; gap: var(--corn-space-1); }
|
|
1081
|
+
.hx-state-icon { flex: none; width: 1em; height: 1em; }
|
|
1082
|
+
.hx-forge-state--requested { color: var(--corn-run-requested); }
|
|
1083
|
+
.hx-forge-state--claimed { color: var(--corn-run-claimed); }
|
|
1084
|
+
.hx-forge-state--working { color: var(--corn-run-working); }
|
|
1085
|
+
.hx-forge-state--waiting { color: var(--corn-run-waiting-ink); background: var(--corn-run-waiting); border-color: var(--corn-run-waiting); border-width: var(--corn-border-strong); }
|
|
1086
|
+
.hx-forge-state--done { color: var(--corn-run-done); }
|
|
1087
|
+
.hx-forge-state--failed { color: var(--corn-run-failed); }
|
|
1088
|
+
.hx-forge-state--stopped { color: var(--corn-run-stopped); }
|
|
1089
|
+
.hx-state-spin { transform-origin: 6px 6px; animation: hx-state-turn 1.2s linear infinite; }
|
|
1090
|
+
@keyframes hx-state-turn { to { transform: rotate(360deg); } }
|
|
1091
|
+
@media (prefers-reduced-motion: reduce) { .hx-state-spin { animation: none; } }
|
|
1092
|
+
|
|
1093
|
+
/* What an action came to, by the control that was used: the words, and a mark that is not a colour */
|
|
1094
|
+
.hx-forge-result { margin: 0; padding: var(--corn-space-1) var(--corn-space-3); border-left: calc(var(--corn-border-strong) * 2) solid var(--corn-line); border-radius: var(--corn-radius-sm); background: var(--corn-surface-2); color: var(--corn-text); line-height: 1.5; overflow-wrap: anywhere; }
|
|
1095
|
+
.hx-forge-result[hidden] { display: none; }
|
|
1096
|
+
.hx-forge-result[data-corn-state="success"] { border-left-color: var(--corn-ok); }
|
|
1097
|
+
.hx-forge-result[data-corn-state="failure"] { border-left-color: var(--corn-bad); }
|
|
1098
|
+
.hx-forge-result[data-corn-state="success"]::before { content: '\2713 '; }
|
|
1099
|
+
.hx-forge-result[data-corn-state="failure"]::before { content: '\2715 '; }
|
|
1100
|
+
.hx-drawer-foot .hx-forge-result { flex-basis: 100%; }
|
|
1101
|
+
|
|
1102
|
+
/* A disabled control looks disabled: no fill, a dashed edge, the quiet text colour and a cursor that says so */
|
|
1103
|
+
.hx-forge .hx-btn:disabled, .hx-forge-act:disabled, .hx-forge-cta .hx-btn[disabled] { background: none; border-style: dashed; color: var(--corn-text-3); box-shadow: none; cursor: not-allowed; }
|
|
1104
|
+
|
|
1105
|
+
/* Retry, in a notice, sits at the end of the line */
|
|
1106
|
+
.hx-forge-notice .hx-btn { margin-left: var(--corn-space-2); }
|
|
1107
|
+
.hx-forge-runs .hx-forge-notice[hidden], .hx-forge-notice[hidden] { display: none; }
|
|
1108
|
+
|
|
1109
|
+
/* A list that is being read holds its height: rows of a row's size, a quiet bar in each */
|
|
1110
|
+
.hx-forge-skeleton { display: flex; flex-direction: column; gap: var(--corn-space-2); min-height: 64px; padding: var(--corn-space-3); border: var(--corn-border) solid var(--corn-line-soft); border-radius: var(--corn-radius); list-style: none; }
|
|
1111
|
+
.hx-forge-skeleton > span { display: block; height: 10px; border-radius: var(--corn-radius-sm); background: var(--corn-surface-3); }
|
|
1112
|
+
.hx-forge-skeleton > span:last-child { width: 55%; }
|
|
1113
|
+
.hx-forge-empty { line-height: 1.5; }
|
|
1114
|
+
|
|
1115
|
+
/* The panel's title row and tabs stay in place while a list scrolls; the body's padding is taken up by the top so nothing shows above it */
|
|
1116
|
+
.hx-forge-body { --hx-forge-pad: calc(var(--corn-space-5) + var(--corn-space-1)); --hx-forge-padx: var(--corn-space-5); }
|
|
1117
|
+
@media (min-width: 640px) { .hx-forge-body { --hx-forge-pad: var(--corn-space-6); --hx-forge-padx: calc(var(--corn-space-5) + var(--corn-space-1)); } }
|
|
1118
|
+
.hx-forge-top { position: sticky; top: calc(var(--hx-forge-pad) * -1); z-index: 3; display: flex; flex-direction: column; gap: var(--corn-space-4); margin: calc(var(--hx-forge-pad) * -1) calc(var(--hx-forge-padx) * -1) 0; padding: var(--hx-forge-pad) var(--hx-forge-padx) 0; background: linear-gradient(var(--corn-surface-1), var(--corn-surface-1)), var(--corn-ground); } /* opaque: the panel's surface over the ground, so a list scrolls under it without showing through */
|
|
1119
|
+
.hx-forge-top .hx-forge-tabs { margin: 0 calc(var(--hx-forge-padx) * -1); padding: 0 var(--hx-forge-padx); }
|
|
1120
|
+
/* Where the tabs run on past an edge (a phone), they fade out on that side: a mask (only its alpha counts, so any opaque token does), so it works on any surface and in any theme */
|
|
1121
|
+
.hx-forge-top .hx-forge-tabs { mask-image: linear-gradient(to right, transparent 0, var(--corn-ground) var(--hx-fade-l, 0px), var(--corn-ground) calc(100% - var(--hx-fade-r, 0px)), transparent 100%); -webkit-mask-image: linear-gradient(to right, transparent 0, var(--corn-ground) var(--hx-fade-l, 0px), var(--corn-ground) calc(100% - var(--hx-fade-r, 0px)), transparent 100%); }
|
|
1122
|
+
.hx-forge-top[data-more~="start"] { --hx-fade-l: calc(var(--corn-space-6) * 1.5); }
|
|
1123
|
+
.hx-forge-top[data-more~="end"] { --hx-fade-r: calc(var(--corn-space-6) * 1.5); }
|
|
1124
|
+
|
|
1125
|
+
/* The page's one offline notice */
|
|
1126
|
+
.hx-offline { position: fixed; top: 64px; /* below the header */ left: 50%; transform: translateX(-50%); z-index: 70; max-width: min(560px, calc(100% - 32px)); margin: 0; padding: var(--corn-space-2) var(--corn-space-4); border: var(--corn-border-strong) solid var(--corn-warn); border-radius: var(--corn-radius); background: var(--corn-surface-1); color: var(--corn-text); box-shadow: var(--corn-shadow); line-height: 1.5; }
|
|
1127
|
+
.hx-offline[hidden] { display: none; }
|
|
1128
|
+
.hx-offline[data-corn-state="success"] { border-color: var(--corn-ok); }
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module explorer/feedback
|
|
3
|
+
*
|
|
4
|
+
* One way to say what an action came to: **where the person is looking** (by the control they used) and **to a screen reader** (the live
|
|
5
|
+
* region), together. A result is kept under its key (a run's id) until the next action on that key, so a card that is drawn again shows
|
|
6
|
+
* it again; a result that has no next action to end it (Copy spec) goes after `RESULT_MS`, which is never less than five seconds.
|
|
7
|
+
*
|
|
8
|
+
* sayResult(key, words, ok) keep the result for `key` and announce it
|
|
9
|
+
* resultOf(key) { text, ok } or null
|
|
10
|
+
* clearResult(key) the next action on `key` begins: the old result goes
|
|
11
|
+
* showResultIn(el, key) paints the result of `key` into a result element (`data-corn="result"`), hidden when there is none
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { announce } from './keyboard.js';
|
|
15
|
+
|
|
16
|
+
/** How long a result with no next action to end it stays (ms): at least five seconds */
|
|
17
|
+
export const RESULT_MS = 6000;
|
|
18
|
+
|
|
19
|
+
const results = new Map();
|
|
20
|
+
|
|
21
|
+
/** Keeps the result of an action under `key` and announces it through the live region */
|
|
22
|
+
export function sayResult(key, text, ok = true) {
|
|
23
|
+
results.set(key, { text, ok });
|
|
24
|
+
announce(text);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** The result kept under `key`, or null */
|
|
28
|
+
export function resultOf(key) {
|
|
29
|
+
return results.get(key) || null;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** The next action on `key` begins: its old result goes */
|
|
33
|
+
export function clearResult(key) {
|
|
34
|
+
results.delete(key);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Paints the result of `key` into `el` (a result element), hidden when there is none */
|
|
38
|
+
export function showResultIn(el, key) {
|
|
39
|
+
if (!el) return;
|
|
40
|
+
const r = results.get(key);
|
|
41
|
+
el.hidden = !r;
|
|
42
|
+
el.textContent = r ? r.text : '';
|
|
43
|
+
if (r) el.dataset.cornState = r.ok ? 'success' : 'failure'; else delete el.dataset.cornState;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** For tests: forget every result */
|
|
47
|
+
export function resetFeedbackForTests() {
|
|
48
|
+
results.clear();
|
|
49
|
+
}
|
|
@@ -402,15 +402,30 @@ export function mergeBlock(detail) {
|
|
|
402
402
|
const { pull, checks } = detail;
|
|
403
403
|
if (pull.state === 'merged') return 'It has landed already.';
|
|
404
404
|
if (pull.state !== 'open') return 'It is closed, so it cannot be landed.';
|
|
405
|
-
if (pull.draft) return 'It is a draft: mark it ready on the forge
|
|
406
|
-
if (!checks.length) return 'It has no checks, so nothing says it works.';
|
|
405
|
+
if (pull.draft) return 'It is a draft. Next: mark it ready for review on the forge, then press Refresh here.';
|
|
406
|
+
if (!checks.length) return 'It has no checks, so nothing says it works. Next: wait for the forge to start them, then press Refresh.';
|
|
407
407
|
const words = { queued: 'is waiting to run', running: 'is still running', failure: 'failed', cancelled: 'was cancelled' };
|
|
408
408
|
const not = checks.filter((c) => !GREEN.includes(c.state));
|
|
409
|
-
if (not.length)
|
|
409
|
+
if (not.length) {
|
|
410
|
+
// What to do about each, in words: a failure is re-run (here when the forge lets cornfield, else there); a check that is not done is waited for
|
|
411
|
+
const next = not.map((c) => (c.state === 'failure' || c.state === 'cancelled' ? `re-run ${c.name}${c.canRerun ? ' below' : ' on the forge'}` : `wait for ${c.name} to ${c.state === 'queued' ? 'start and finish' : 'finish'}`));
|
|
412
|
+
return `Can't land yet: ${not.map((c) => `${c.name} ${words[c.state] || c.state}`).join(', ')}. Next: ${next.join(', then ')}, then press Refresh.`;
|
|
413
|
+
}
|
|
410
414
|
if (detail.stale) return 'This is an older answer from the forge: refresh before landing it.';
|
|
411
415
|
return null;
|
|
412
416
|
}
|
|
413
417
|
|
|
418
|
+
/**
|
|
419
|
+
* A line of warning for a spec pull request whose proposal is not approved yet ('' when it is, or the pull request is not a spec's). Only words:
|
|
420
|
+
* what Land does is not changed by it.
|
|
421
|
+
* @param {{ pull: { state: string }, specs?: { slug: string, approved: boolean }[] }} detail
|
|
422
|
+
*/
|
|
423
|
+
export function approvalWarning(detail) {
|
|
424
|
+
if (!detail || detail.pull.state !== 'open') return '';
|
|
425
|
+
const open = (detail.specs || []).filter((s) => !s.approved).map((s) => s.slug);
|
|
426
|
+
return open.length ? `Its proposal${open.length > 1 ? 's' : ''} ${open.join(', ')} ${open.length > 1 ? 'are' : 'is'} not approved yet. Next: approve ${open.length > 1 ? 'them' : 'it'} first (Specs, open the proposal, Approve), then land this.` : '';
|
|
427
|
+
}
|
|
428
|
+
|
|
414
429
|
/**
|
|
415
430
|
* Why a failed check has no Re-run button; null when it has one or is not a failed check (nothing to say).
|
|
416
431
|
* @param {{ state: string, canRerun?: boolean }} check
|
|
@@ -483,11 +498,30 @@ export function actionWords(action, status, body, number) {
|
|
|
483
498
|
* @param {{ error?: string } | null} body the JSON the server gave, if it did
|
|
484
499
|
* @returns {string}
|
|
485
500
|
*/
|
|
486
|
-
export function errorWords(status, body) {
|
|
487
|
-
|
|
501
|
+
export function errorWords(status, body, { offline = false, what = '' } = {}) {
|
|
502
|
+
const head = what ? `Could not load ${what}. ` : '';
|
|
503
|
+
if (status === null) return `${head}${offline ? 'You are offline.' : 'cornfield could not be reached. Check that it is still running, then try again.'}`;
|
|
488
504
|
if (status === 401) return 'Your sign-in has ended. Sign in again to see issues and pull requests.';
|
|
489
|
-
|
|
490
|
-
|
|
505
|
+
// The server's own sentence says what went wrong in plain words (the forge's name, what it could not find); nothing a parser or a runtime said is passed on
|
|
506
|
+
if (body && typeof body.error === 'string' && body.error) return `${head}${body.error}`;
|
|
507
|
+
if (status >= 200 && status < 300) return `${head}cornfield sent an answer this page could not read. Try again.`;
|
|
508
|
+
if (status === 404) return `${head}It was not found. It may have been removed. Try again.`;
|
|
509
|
+
if (status === 403) return `${head}This sign-in may not see it. Ask a maintainer, or sign in as another account.`;
|
|
510
|
+
if (status === 429) return `${head}The forge asked cornfield to slow down. Try again in a minute.`;
|
|
511
|
+
if (status >= 500) return `${head}The server had a problem (error ${status}). Try again in a minute.`;
|
|
512
|
+
return `${head}The server refused (error ${status}). Try again.`;
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
/** What a list says when it has nothing in it: what would appear here and how to make one (the `kind` is the tab) */
|
|
516
|
+
export function emptyWords(kind, forgeName = 'the forge') {
|
|
517
|
+
return {
|
|
518
|
+
specs: 'No proposals yet. A proposal is a change to the map written down before it is built. Start one from an issue (Issues, then Start a spec), or push one as a file to the proposals folder.',
|
|
519
|
+
pulls: `No open pull requests. Agents open one when a run makes code, and you can open one on ${forgeName}.`,
|
|
520
|
+
issues: `No open issues. Open one on ${forgeName}, or write a New idea in Threads.`,
|
|
521
|
+
threads: 'No threads. A thread is an idea or a spec conversation; start one with New idea below.',
|
|
522
|
+
deploys: `No deploys to show. They appear here when a workflow runs on ${forgeName}.`,
|
|
523
|
+
work: 'No work here yet. Start an agent from an issue or a proposal and its pull request shows here.',
|
|
524
|
+
}[kind] || 'Nothing here yet.';
|
|
491
525
|
}
|
|
492
526
|
|
|
493
527
|
// ---------------------------------------------------------------------------
|