cornfield 0.34.2 → 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 CHANGED
@@ -23,6 +23,8 @@ import path from 'node:path';
23
23
  import { fileURLToPath } from 'node:url';
24
24
  import { MAX_MIX_DEPTH, readColor, over, toHex, luminance, ratio, splitTop } from './color.js';
25
25
  import { MAX_THEME_BYTES, cssProblems, withoutComments } from './theme.js';
26
+ import { DIFF_MARK_COLORS, DIFF_LABEL_ALPHA, markOpacity } from '../explorer/diff-marks.js';
27
+ import { lightColor } from '../explorer/theme-model.js';
26
28
 
27
29
  /** WCAG 2.1 AA: text, and large text and user-interface parts */
28
30
  export const MIN_TEXT = 4.5;
@@ -345,11 +347,13 @@ const tint = (token, pct) => `color-mix(in srgb, var(${token}) ${pct}%, transpar
345
347
  const toText = (token, pct) => `color-mix(in srgb, var(${token}) ${pct}%, var(--corn-text))`;
346
348
 
347
349
  /** Text tokens: read on the ground and on every surface */
348
- 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']);
349
352
  /** The tinted backgrounds, with the text that sits on each */
350
353
  export const SOFT_PAIRS = Object.freeze([
351
354
  ['--corn-ok', '--corn-ok-soft'],
352
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
353
357
  ]);
354
358
  /** Solid fills that carry `--corn-ground` as their text (a pressed data-flow button, a chip, the What-if toggle, the House chip) */
355
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']);
@@ -397,6 +401,9 @@ export const UI_PAIRS = Object.freeze([
397
401
  ...['--corn-ok', '--corn-edit-text', '--corn-bad', '--corn-warn', '--corn-text-3'].flatMap((fg) => ['--corn-surface-2', '--corn-surface-3'].map((bg) => [fg, bg, 'a state pill\'s border'])),
398
402
  ]);
399
403
 
404
+ /** The dots that name a diff mark in the bar, the change list and the legend (explorer.css `.hx-mark-dot--*`), each a ring on the ground */
405
+ const DIFF_DOT_PAIRS = Object.freeze(['added', 'changed', 'removed', 'edit'].map((m) => [`--corn-${m}`, GROUND, `the ${m} mark's dot`]));
406
+
400
407
  /**
401
408
  * Every pair that is read against each other: `{ fg, bg, min, kind, use? }`, `fg` and `bg` each a token or a CSS colour value. A pair
402
409
  * listed twice is checked once, at the higher minimum. How a translucent `bg` is composited: see checkState.
@@ -415,6 +422,7 @@ export function contrastPairs() {
415
422
  for (const bg of SOLID_FILLS) add(GROUND, bg, MIN_TEXT, 'text');
416
423
  for (const [fg, bg] of PAINTED_TEXT) add(fg, bg, MIN_TEXT, 'text');
417
424
  for (const [fg, bg, use] of UI_PAIRS) add(fg, bg, MIN_UI, 'ui', use);
425
+ for (const [fg, bg, use] of DIFF_DOT_PAIRS) add(fg, bg, MIN_UI, 'ui', use);
418
426
  return [...pairs.values()];
419
427
  }
420
428
 
@@ -500,6 +508,62 @@ function checkState(props, theme, mode) {
500
508
  const { image, ...rest } = worst;
501
509
  out.push({ ...finding, ...rest, ...(image ? { groundImage: true } : {}) });
502
510
  }
511
+ out.push(...diffMapFindings(props, theme, mode, grounds, isColor(g) ? over(g, canvas) : null));
512
+ return out;
513
+ }
514
+
515
+ // ---------------------------------------------------------------------------
516
+ // The map's diff marks and dimmed labels (0.34 review, F19 and F23)
517
+ //
518
+ // The canvas draws a proposal's marks in `--corn-map-added|changed|removed|edit` (`auto` is the default look, explorer/diff-marks.js)
519
+ // and a label a diff dims at DIFF_LABEL_ALPHA. Each is read at 3:1 against every ground the map draws: the ground, each glow of
520
+ // `--corn-ground-image` at its strongest, and all of them laid over each other (the darkest and the lightest the map shows), at the
521
+ // opacity it is drawn at (a removed mark is faded, an edge is never fainter than EDGE_MIN_ALPHA). Nothing here reads node fills:
522
+ // those are another check.
523
+ // ---------------------------------------------------------------------------
524
+
525
+ /** Every ground the map can show: the page ground, each glow at its peak over it, and all the glows stacked */
526
+ function mapGrounds(grounds, base, props) {
527
+ const out = grounds.map((x) => ({ ...x }));
528
+ if (base && props.has('--corn-ground-image')) {
529
+ const r = expand('var(--corn-ground-image)', props);
530
+ if ('text' in r) {
531
+ let stack = base;
532
+ for (const layer of layerTexts(r.text).slice(0, 16)) {
533
+ let peak = null;
534
+ for (const c of colorsIn(layer, 0)) if (!peak || c[3] > peak[3]) peak = c;
535
+ if (peak && peak[3] > 0) stack = over(peak, stack);
536
+ }
537
+ if (stack !== base) out.push({ color: stack, image: true });
538
+ }
539
+ }
540
+ return out;
541
+ }
542
+
543
+ /** The pairs the map's diff marks make: `[token, default colour (auto), opacity, what it is]` */
544
+ const DIFF_MAP_PAIRS = (mode) => [
545
+ ...['added', 'changed', 'removed', 'edit'].map((m) => [`--corn-map-${m}`, DIFF_MARK_COLORS[mode][m], markOpacity(m), `the ${m} mark on the map, drawn at ${Math.round(markOpacity(m) * 100)}% opacity`]),
546
+ ['--corn-map-label', mode === 'light' ? lightColor('#f8fafc', 'text') : '#f8fafc', DIFF_LABEL_ALPHA, `a label the diff dims, drawn at ${Math.round(DIFF_LABEL_ALPHA * 100)}% opacity`],
547
+ ];
548
+
549
+ function diffMapFindings(props, theme, mode, grounds, base) {
550
+ const out = [];
551
+ const list = mapGrounds(grounds, base, props);
552
+ for (const [token, auto, opacity, use] of DIFF_MAP_PAIRS(mode)) {
553
+ const finding = { theme, mode, fg: token, bg: GROUND, min: MIN_UI, kind: 'ui', use };
554
+ const raw = (props.get(token) || 'auto').trim();
555
+ const fg0 = raw.toLowerCase() === 'auto' ? readColor(auto) : resolveColor(props, token);
556
+ if (!isColor(fg0)) { out.push({ ...finding, problem: fg0 ? fg0.problem : `${token} is not a colour cornfield reads` }); continue; }
557
+ if (!list.length) continue;
558
+ let worst = null;
559
+ for (const { color: ground, image } of list) {
560
+ const fg = over([fg0[0], fg0[1], fg0[2], fg0[3] * opacity], ground);
561
+ const r = ratio(luminance(fg), luminance(ground));
562
+ if (!worst || r < worst.ratio) worst = { fgValue: toHex(fg), bgValue: toHex(ground), ratio: r, image };
563
+ }
564
+ const { image, ...rest } = worst;
565
+ out.push({ ...finding, ...rest, ...(image ? { groundImage: true } : {}) });
566
+ }
503
567
  return out;
504
568
  }
505
569
 
package/core/proposal.js CHANGED
@@ -721,11 +721,18 @@ export function proposalProblems(topology, proposal) {
721
721
  /**
722
722
  * The numbers behind the counts chip ("3 added · 1 changed · 1 removed"): nodes and edges counted together.
723
723
  * @param {object} proposal
724
- * @returns {{ added: number, changed: number, removed: number, scenarios: number }}
724
+ * `nodes` and `edges` give the same counts apart, for the words that say what is counted.
725
+ * @param {object} proposal
726
+ * @returns {{ added: number, changed: number, removed: number, scenarios: number, nodes: { added: number, changed: number, removed: number }, edges: { added: number, changed: number, removed: number } }}
725
727
  */
726
728
  export function summarize(proposal) {
727
- const count = (op) => asList(proposal?.nodes?.[op]).length + asList(proposal?.edges?.[op]).length;
728
- return { added: count('add'), changed: count('change'), removed: count('remove'), scenarios: asList(proposal?.scenarios).length };
729
+ const of = (group) => ({ added: asList(group?.add).length, changed: asList(group?.change).length, removed: asList(group?.remove).length });
730
+ const nodes = of(proposal?.nodes);
731
+ const edges = of(proposal?.edges);
732
+ return {
733
+ added: nodes.added + edges.added, changed: nodes.changed + edges.changed, removed: nodes.removed + edges.removed,
734
+ scenarios: asList(proposal?.scenarios).length, nodes, edges,
735
+ };
729
736
  }
730
737
 
731
738
  /**
package/explorer/check.js CHANGED
@@ -195,6 +195,9 @@ function summary() {
195
195
  }
196
196
 
197
197
  /** Paints the step's state on the bar: called with every bar update */
198
+ /** The words last written into each player's check line (paintChecks) */
199
+ const lineHtml = new WeakMap();
200
+
198
201
  export function paintChecks(bar, snap) {
199
202
  if (!bar || !current) return;
200
203
  if (!bar.querySelector('.hx-player-as')) {
@@ -214,7 +217,9 @@ export function paintChecks(bar, snap) {
214
217
  pill.textContent = words.pill;
215
218
  pill.title = words.line;
216
219
  line.dataset.tone = words.tone;
217
- line.innerHTML = `${escHtml(words.line)}${words.detail ? ` <span class="hx-player-check-detail">${escHtml(words.detail)}</span>` : ''}`;
220
+ // painted every frame: the live line is rewritten only when its words change, so a verdict is said once
221
+ const html = `${escHtml(words.line)}${words.detail ? ` <span class="hx-player-check-detail">${escHtml(words.detail)}</span>` : ''}`;
222
+ if (lineHtml.get(line) !== html) { lineHtml.set(line, html); line.innerHTML = html; }
218
223
  }
219
224
  fillMenu(row.querySelector('[data-check=as]'));
220
225
  row.querySelector('[data-check=recheck]').disabled = current.answer.status === 'pending';
@@ -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
+ }
@@ -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
- requested: 'queued', claimed: 'queued', working: 'running', quiet: 'waiting', 'stop-requested': 'stopped',
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
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * @module explorer/diff-marks
3
+ *
4
+ * What the map draws for a proposal's diff marks, as plain data with no imports, so the scene (scene.js), the renderers and the
5
+ * contrast check (core/contrast.js, for `cornfield validate`) read one list. The colours are the defaults behind `--corn-map-added|
6
+ * changed|removed|edit: auto`, and the same hexes are `--corn-added|changed|removed|edit` in tokens.css (the dots in the bar).
7
+ *
8
+ * Every mark is at least 3:1 (WCAG 1.4.11) against the darkest and lightest ground the map draws, at the opacity it is drawn at:
9
+ * an edge never fainter than EDGE_MIN_ALPHA, and a removed mark at REMOVED_ALPHA over that. A label a diff dims is drawn at
10
+ * DIFF_LABEL_ALPHA: de-emphasised, never hidden (3:1 as well).
11
+ */
12
+
13
+ /** The default mark colours, for the dark and the light ground */
14
+ export const DIFF_MARK_COLORS = Object.freeze({
15
+ dark: Object.freeze({ added: '#2dd4bf', changed: '#fbbf24', removed: '#fa9292', edit: '#b49cfb' }),
16
+ light: Object.freeze({ added: '#197c6f', changed: '#8f6703', removed: '#e20b0b', edit: '#6839f6' }),
17
+ });
18
+
19
+ /** How much of a removed node and its edge is left: faded, but still 3:1 */
20
+ export const REMOVED_ALPHA = 0.85;
21
+ /** The least opacity a mark's edge is drawn at (scene.js lifts an edge to this before the mark's own fade) */
22
+ export const EDGE_MIN_ALPHA = 0.9;
23
+ /** The opacity each mark is drawn at at its faintest (an edge; a what-if edit that removes something is faded like a removal): the contrast check measures this */
24
+ export const markOpacity = (mark) => EDGE_MIN_ALPHA * (mark === 'removed' || mark === 'edit' ? REMOVED_ALPHA : 1);
25
+
26
+ /** The opacity of the label of a node a diff dims (the node itself is at PROPOSAL_DIM_ALPHA) */
27
+ export const DIFF_LABEL_ALPHA = 0.6;
28
+
29
+ /** How a mark differs without colour: the ring's dash (`null` is solid) and whether it is struck through. Four marks, four styles. */
30
+ export const MARK_SHAPES = Object.freeze({
31
+ added: Object.freeze({ ringDash: Object.freeze([5, 4]), edgeDash: Object.freeze([7, 5]), strike: false }), // a dashed ring
32
+ changed: Object.freeze({ ringDash: null, edgeDash: null, strike: false }), // a plain solid ring
33
+ removed: Object.freeze({ ringDash: null, edgeDash: Object.freeze([3, 4]), strike: true }), // a faded ring, struck through
34
+ edit: Object.freeze({ ringDash: Object.freeze([2, 5]), edgeDash: Object.freeze([2, 5]), strike: false }), // a dotted ring: short marks, wide gaps (a 1.5/3.5 dot blurred into a solid ring at 1x)
35
+ });
@@ -428,8 +428,8 @@ button.hx-proposal-item:focus-visible { outline: var(--corn-focus-width) solid v
428
428
  .hx-legend-row .hx-mark-dot, .hx-change-row .hx-mark-dot { margin-right: 0; }
429
429
  .hx-mark-dot--added { border-color: var(--corn-added); border-style: dashed; }
430
430
  .hx-mark-dot--changed { border-color: var(--corn-changed); }
431
- .hx-mark-dot--removed { border-color: var(--corn-removed); background: color-mix(in srgb, var(--corn-removed) 25%, transparent); opacity: 0.7; }
432
- .hx-mark-dot--edit { border-color: var(--corn-edit); }
431
+ .hx-mark-dot--removed { border-color: var(--corn-removed); background: color-mix(in srgb, var(--corn-removed) 25%, transparent); }
432
+ .hx-mark-dot--edit { border-color: var(--corn-edit); border-style: dotted; } /* a dotted ring: not the changed mark's solid one, with or without colour */
433
433
 
434
434
  /* The panel's proposal block: why, and what changes */
435
435
  .hx-proposal-sec { padding: var(--corn-space-3) var(--corn-space-3); border: var(--corn-border) solid var(--corn-line); border-left-width: var(--corn-border-strong); border-radius: var(--corn-radius-sm); background: color-mix(in srgb, var(--corn-ground) 55%, transparent); margin: 0 0 var(--corn-space-2); font-family: var(--corn-font); }
@@ -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-head):not(#forge-bar), .hx-forge[data-sheet-state="peek"] #forge-filter-chip { display: none; }
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
- .hx-forge-node { padding: calc(var(--corn-space-1) / 2) var(--corn-space-3); border-radius: var(--corn-radius-pill); border: var(--corn-border) solid var(--corn-warn); background: color-mix(in srgb, var(--corn-ground) 55%, transparent); color: var(--corn-text-2); font-size: var(--corn-text-xs); }
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); padding: var(--corn-space-2) var(--corn-space-3); border: var(--corn-border) solid var(--corn-line); border-radius: var(--corn-radius-sm); background: var(--corn-surface-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; }
@@ -1053,3 +1055,74 @@ a.hx-proposal-source:focus-visible { outline: var(--corn-focus-width) solid var(
1053
1055
 
1054
1056
  /* The node panel's facts break at word boundaries only (F60): "hook" is never "hoo / k". A long path or name still wraps, at its slashes and dashes, and only as a last resort anywhere. */
1055
1057
  .hx-fact-v { overflow-wrap: break-word; word-break: normal; }
1058
+
1059
+ /* ---------------------------------------------------------------------------
1060
+ Target sizes (0.34 review, F57): a thumb target is 44x44 (hit area, the drawn size may be smaller), and a change row is
1061
+ 28px at a desk. Phone width or a coarse pointer. test/explorer/target-size.test.js holds this list.
1062
+ --------------------------------------------------------------------------- */
1063
+ .hx-change-row { min-height: 28px; }
1064
+ .hx-run .hx-link { display: inline-flex; align-items: center; min-height: 24px; } /* a run card's links sit on lines 14px apart: 24px at a desk (WCAG 2.5.8) */
1065
+ @media (max-width: 767px), (pointer: coarse) {
1066
+ .hx-change-row, .hx-toggle-row, .hx-textbtn, .hx-player-speed, .hx-player .hx-close,
1067
+ .hx-confirm .hx-btn, .hx-confirm .hx-forge-input, .hx-confirm .hx-forge-select, .hx-mobile-search .hx-input { min-height: 44px; }
1068
+ .hx-textbtn, .hx-player-speed, .hx-player .hx-close, .hx-confirm .hx-btn { min-width: 44px; }
1069
+ .hx-proposal-chip { flex-wrap: wrap; white-space: normal; text-align: left; } /* the counts say what they count, so they are longer: they wrap rather than clip */
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) */
1071
+ .hx-run .hx-link, .hx-forge-check .hx-link { display: inline-flex; align-items: center; min-height: 44px; }
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
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * The one list of what the keyboard can stop on, shared by every dialog that keeps the focus inside itself
3
+ * (Review tokens, Start an agent, the confirm step, the mockup window). A trap that names its own selector leaves
4
+ * something out (the Kind of token select once), so they all ask here.
5
+ */
6
+
7
+ /** Every control a Tab can land on: links, buttons, fields, selects, summaries, frames and anything with a tabindex that is not -1 */
8
+ export const FOCUSABLE = 'a[href], button, input:not([type="hidden"]), select, textarea, summary, iframe, [contenteditable="true"], [tabindex]:not([tabindex="-1"])';
9
+
10
+ /**
11
+ * The stops inside `root`, in DOM order: not disabled, not hidden, not inert and not under a hidden or inert ancestor.
12
+ * @param {Element} root
13
+ * @returns {HTMLElement[]}
14
+ */
15
+ export function focusableIn(root) {
16
+ if (!root) return [];
17
+ return [...root.querySelectorAll(FOCUSABLE)].filter((el) => !el.disabled && !el.closest('[hidden], [inert]') && el.getAttribute('tabindex') !== '-1');
18
+ }
19
+
20
+ /**
21
+ * Keeps a Tab inside `root`: from the last stop it goes to the first, and Shift+Tab the other way round.
22
+ * @param {KeyboardEvent} e a keydown; nothing happens unless it is a Tab
23
+ * @param {Element} root
24
+ * @returns {boolean} whether it handled the key
25
+ */
26
+ export function trapTab(e, root) {
27
+ if (e.key !== 'Tab') return false;
28
+ const stops = focusableIn(root);
29
+ e.preventDefault();
30
+ if (!stops.length) return true;
31
+ const at = stops.indexOf(document.activeElement);
32
+ const next = e.shiftKey ? (at <= 0 ? stops.length - 1 : at - 1) : (at === -1 || at === stops.length - 1 ? 0 : at + 1);
33
+ stops[next].focus();
34
+ return true;
35
+ }
@@ -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 first.';
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) return `Can't land yet: ${not.map((c) => `${c.name} ${words[c.state] || c.state}`).join(', ')}.`;
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
- if (status === null) return 'cornfield could not be reached; check that it is still running, then refresh.';
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
- if (body && typeof body.error === 'string' && body.error) return body.error;
490
- return `cornfield answered ${status} for the forge.`;
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
  // ---------------------------------------------------------------------------