cornfield 0.28.0 → 0.30.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.
@@ -8,14 +8,16 @@
8
8
 
9
9
  import { state, nodeById, nameOf, escHtml, touchScene } from './state.js';
10
10
  import { render } from './render.js';
11
- import { FLOW_STYLES, flowSummary } from './flows.js';
11
+ import { flowSummary } from './flows.js';
12
12
  import { clearScenario } from './scenario-ui.js';
13
- import { proposalPanelHtml } from './proposal-model.js';
13
+ import { kindOfMark, fieldRows, MARK_WORDS } from './proposal-model.js';
14
14
  import { nodeMockupsHtml } from './mockups-model.js';
15
15
  import { collapseSheet } from './sheets.js';
16
16
  import { liveSection, hydrateLivePhotos } from './live.js';
17
17
  import { cloudPanelHtml } from './cloud-model.js';
18
18
  import { t } from './strings.js';
19
+ import { capped, toggleCapped } from './capped.js';
20
+ import { canStartAgent, openProposalStart } from './forge-panel.js';
19
21
 
20
22
  const $ = (id) => document.getElementById(id);
21
23
 
@@ -24,9 +26,23 @@ const $ = (id) => document.getElementById(id);
24
26
  // ---------------------------------------------------------------------------
25
27
  const code = (s) => `<code class="hx-code">${escHtml(s)}</code>`;
26
28
  const nm = (id) => `<span class="hx-name">${escHtml(nameOf(id))}</span>`;
27
- const line = (color, arrow, body) => `<div class="hx-line"><span class="hx-glyph" style="--glyph:${color}">${arrow}</span><span>${body}</span></div>`;
28
- const section = (title, rows) => (rows.length ? `<div class="hx-sec" data-corn="section"><strong class="hx-strong">${title}</strong>${rows.join('')}</div>` : '');
29
- const varList = (vars) => `<div class="hx-chips">${vars.map((v) => `<code class="hx-var">${escHtml(v)}</code>`).join('')}</div>`;
29
+ const line = (body) => `<div class="hx-line">${body}</div>`;
30
+ /** The words a fact goes by in the panel: short nouns, whatever the longer sentence it was built from */
31
+ const FACT_KEYS = {
32
+ 'Uses design tokens': 'Tokens', 'Loaded by the server per request': 'Loaded by', 'Domains served (Caddyfile → service)': 'Domains', 'Compose file': 'File',
33
+ 'Baked pages': 'Baked', 'Reads tables': 'Reads', 'Writes tables': 'Writes', 'Self-hosted': 'Role', 'Pushes to (webhook)': 'Pushes to',
34
+ 'Calls outside': 'Calls', 'Client modules': 'Modules', 'Data flows': 'Flows',
35
+ };
36
+ const FACT_COUNTED = /^(?:Defines )?\d+ (?:CSS )?(variable|service)\(s\)$/;
37
+ const factKey = (title) => {
38
+ const plain = title.replace(/:$/, '');
39
+ const counted = FACT_COUNTED.exec(plain);
40
+ if (counted) return counted[1] === 'service' ? 'Services' : plain.startsWith('Defines') ? 'Defines' : 'Variables';
41
+ return FACT_KEYS[plain] || plain;
42
+ };
43
+ /** One fact: its name, and what it says. A fact with nothing in it is not shown. */
44
+ const section = (title, rows) => (rows.length ? `<div class="hx-fact" data-corn="section"><div class="hx-fact-k">${escHtml(factKey(title))}</div><div class="hx-fact-v">${capped(rows)}</div></div>` : '');
45
+ const varList = (vars) => `<div class="hx-chips">${capped(vars.map((v) => `<code class="hx-var">${escHtml(v)}</code>`))}</div>`;
30
46
  const edgesOf = (kind, side, id) => state.edges.filter((e) => e.kind === kind && e[side] === id);
31
47
 
32
48
  /** Table <-> page data: which keys a page's render reads, which forms write, what ROM re-bakes */
@@ -35,93 +51,93 @@ function dataSummary(node) {
35
51
  const writes = state.edges.filter((e) => e.kind === 'writes');
36
52
  const usesOut = state.edges.filter((e) => e.kind === 'uses' && e.from === node.id);
37
53
  const extendsOut = state.edges.filter((e) => e.kind === 'extends' && e.from === node.id);
38
- const common = section('Extends:', extendsOut.map((e) => line(FLOW_STYLES.extends.color, '↑', nm(e.to))))
39
- + section('Uses design tokens:', usesOut.map((e) => line(FLOW_STYLES.uses.color, '→', `${nm(e.to)} · ${e.vars.length}${varList(e.vars)}`)))
54
+ const common = section('Extends:', extendsOut.map((e) => line(nm(e.to))))
55
+ + section('Uses design tokens:', usesOut.map((e) => line(`${nm(e.to)} · ${e.vars.length}${varList(e.vars)}`)))
40
56
  + (node.type !== 'token' && node.vars ? section(`Defines ${node.vars.length} CSS variable(s):`, [varList(node.vars)]) : '');
41
57
 
42
58
  if (node.type === 'app') {
43
59
  const served = node.deployed
44
- ? line('#93c5fd', '⇢', `<a class="hx-link" href="${escHtml(node.url)}" target="_blank" rel="noreferrer">${escHtml(node.url)}</a> → ${(node.upstreams || []).map(code).join(' ')}${node.stack ? ` <span class="hx-faint">[${escHtml(node.stack)}]</span>` : ''}`)
45
- : line('#f87171', '✕', 'Not deployed by any stack in this repo');
60
+ ? line(`${/^https?:\/\//.test(node.url) ? `<a class="hx-link" href="${escHtml(node.url)}" target="_blank" rel="noreferrer">${escHtml(node.url)}</a>` : code(node.url)} → ${(node.upstreams || []).map(code).join(' ')}${node.stack ? ` <span class="hx-faint">[${escHtml(node.stack)}]</span>` : ''}`)
61
+ : line('Not deployed by any stack in this repo');
46
62
  const runsOn = state.edges.filter((e) => e.kind === 'runs-on' && e.from === node.id)
47
- .map((e) => line(FLOW_STYLES['runs-on'].color, '⇢', `${nm(e.to)}${(e.mappings || []).map((m) => `<div class="hx-faint">${code(m.host)} → ${code(m.upstream)}${m.service ? ` = ${code(m.service)}` : ''}</div>`).join('')}`));
63
+ .map((e) => line(`${nm(e.to)}${(e.mappings || []).map((m) => `<div class="hx-faint">${code(m.host)} → ${code(m.upstream)}${m.service ? ` = ${code(m.service)}` : ''}</div>`).join('')}`));
48
64
  return section('Served:', [served])
49
65
  + section('Runs on:', runsOn)
50
- + section('Loaded by the server per request:', reads.filter((e) => e.to === node.id).map((e) => line(FLOW_STYLES.reads.color, '←', nm(e.from))))
66
+ + section('Loaded by the server per request:', reads.filter((e) => e.to === node.id).map((e) => line(nm(e.from))))
51
67
  + common;
52
68
  }
53
69
  if (node.type === 'token') {
54
70
  const users = state.edges.filter((e) => e.kind === 'uses' && e.to === node.id);
55
71
  return section(`${node.vars.length} variable(s):`, [varList(node.vars)])
56
- + section('Used by:', users.map((e) => line(FLOW_STYLES.uses.color, '←', `${nm(e.from)} · ${escHtml(e.vars.join(' '))}`)));
72
+ + section('Used by:', users.map((e) => line(`${nm(e.from)} · ${escHtml(e.vars.join(' '))}`)));
57
73
  }
58
74
  if (['atom', 'molecule', 'core'].includes(node.type)) {
59
- const pages = state.edges.filter((e) => e.dashed && e.to === node.id).map((e) => line('#818cf8', '←', nm(e.from)));
60
- return (node.table ? section('Record of:', [line(FLOW_STYLES.reads.color, '◆', `${escHtml(node.model)} · table ${code(node.table)}`)]) : '')
75
+ const pages = state.edges.filter((e) => e.dashed && e.to === node.id).map((e) => line(nm(e.from)));
76
+ return (node.table ? section('Record of:', [line(`${escHtml(node.model)} · table ${code(node.table)}`)]) : '')
61
77
  + section('Rendered by:', pages) + common;
62
78
  }
63
79
  if (node.type === 'stack') {
64
80
  const served = state.edges.filter((e) => e.kind === 'runs-on' && e.to === node.id);
65
- return section('Domains served (Caddyfile → service):', served.flatMap((e) => (e.mappings || []).map((m) => line(FLOW_STYLES['runs-on'].color, '←', `<span class="hx-name">${escHtml(m.host)}</span> → ${code(m.upstream)}${m.service ? ` = ${code(m.service)}` : ''}`))))
66
- + section(`${(node.services || []).length} service(s):`, (node.services || []).map((s) => line('#a8a29e', '▣', `<span class="hx-name">${escHtml(s.name)}</span>${s.image ? ` <span class="hx-faint">${escHtml(s.image)}</span>` : ''}${s.ports.length ? `<div>${s.ports.map(code).join(' ')}</div>` : ''}${s.volumes.length ? `<div class="hx-faint">${s.volumes.map(escHtml).join('<br>')}</div>` : ''}`)))
67
- + section('Compose file:', [line('#93c5fd', '📄', code(node.file))]);
81
+ return section('Domains served (Caddyfile → service):', served.flatMap((e) => (e.mappings || []).map((m) => line(`<span class="hx-name">${escHtml(m.host)}</span> → ${code(m.upstream)}${m.service ? ` = ${code(m.service)}` : ''}`))))
82
+ + section(`${(node.services || []).length} service(s):`, (node.services || []).map((s) => line(`<span class="hx-name">${escHtml(s.name)}</span>${s.image ? ` <span class="hx-faint">${escHtml(s.image)}</span>` : ''}${s.ports.length ? `<div>${s.ports.map(code).join(' ')}</div>` : ''}${s.volumes.length ? `<div class="hx-faint">${s.volumes.map(escHtml).join('<br>')}</div>` : ''}`)))
83
+ + section('Compose file:', [line(code(node.file))]);
68
84
  }
69
85
  if (node.type === 'table') {
70
86
  const readers = reads.filter((e) => e.from === node.id);
71
87
  const writers = writes.filter((e) => e.to === node.id);
72
88
  const baked = readers.filter((e) => (nodeById(e.to) || {}).render?.rom === 'bake');
73
- return (node.model ? section('Model:', [line(FLOW_STYLES.reads.color, '◆', escHtml(node.model))]) : '')
74
- + section('Read by:', readers.map((e) => line(FLOW_STYLES.reads.color, '→', `${nm(e.to)} · ${e.keys.map(code).join(' ')}`)))
75
- + section('Written by:', writers.map((e) => line(FLOW_STYLES.writes.color, '←', `${nm(e.from)} · ${escHtml(e.label)}`)))
76
- + (baked.length ? section('Baked pages:', [line(FLOW_STYLES.rom.color, '♻', `a write here re-bakes <span class="hx-rom hx-bold">${baked.length}</span> file(s): ${baked.map((e) => escHtml(nameOf(e.to))).join(', ')}`)]) : '');
89
+ return (node.model ? section('Model:', [line(escHtml(node.model))]) : '')
90
+ + section('Read by:', readers.map((e) => line(`${nm(e.to)} · ${e.keys.map(code).join(' ')}`)))
91
+ + section('Written by:', writers.map((e) => line(`${nm(e.from)} · ${escHtml(e.label)}`)))
92
+ + (baked.length ? section('Baked pages:', [line(`a write here re-bakes <span class="hx-rom hx-bold">${baked.length}</span> file(s): ${baked.map((e) => escHtml(nameOf(e.to))).join(', ')}`)]) : '');
77
93
  }
78
94
  if (node.type === 'service') {
79
95
  const row = (e, side) => `${nm(e[side])}${e.label && e.label !== 'imports' ? ` · ${escHtml(e.label)}` : ''}`;
80
- return section('Kind:', [line(FLOW_STYLES.triggers.color, '◆', `${code(node.kind)}${node.summary ? `<div class="hx-faint">${escHtml(node.summary)}</div>` : ''}`)])
81
- + section('Started by:', [...(node.triggers || []).map((t) => line(FLOW_STYLES.triggers.color, '⏱', escHtml(t))), ...edgesOf('triggers', 'to', node.id).map((e) => line(FLOW_STYLES.triggers.color, '←', row(e, 'from')))])
82
- + section('Jobs:', (node.jobs || []).map((j) => line(FLOW_STYLES.triggers.color, '↻', `${code(j.name)} · cron ${code(j.cron)}`)))
83
- + section('Runs:', edgesOf('triggers', 'from', node.id).map((e) => line(FLOW_STYLES.triggers.color, '→', row(e, 'to'))))
84
- + section('Calls:', edgesOf('calls', 'from', node.id).map((e) => line(FLOW_STYLES.calls.color, '→', row(e, 'to'))))
85
- + section('Called by:', edgesOf('calls', 'to', node.id).map((e) => line(FLOW_STYLES.calls.color, '←', row(e, 'from'))))
86
- + section('Reads tables:', reads.filter((e) => e.to === node.id).map((e) => line(FLOW_STYLES.reads.color, '←', nm(e.from))))
87
- + section('Writes tables:', writes.filter((e) => e.from === node.id).map((e) => line(FLOW_STYLES.writes.color, '→', nm(e.to))))
88
- + section('Mechanisms:', (node.mechanisms || []).map((m) => line('#93c5fd', '◆', escHtml(m))));
96
+ return section('Kind:', [line(`${code(node.kind)}${node.summary ? `<div class="hx-faint">${escHtml(node.summary)}</div>` : ''}`)])
97
+ + section('Started by:', [...(node.triggers || []).map((t) => line(escHtml(t))), ...edgesOf('triggers', 'to', node.id).map((e) => line(row(e, 'from')))])
98
+ + section('Jobs:', (node.jobs || []).map((j) => line(`${code(j.name)} · cron ${code(j.cron)}`)))
99
+ + section('Runs:', edgesOf('triggers', 'from', node.id).map((e) => line(row(e, 'to'))))
100
+ + section('Calls:', edgesOf('calls', 'from', node.id).map((e) => line(row(e, 'to'))))
101
+ + section('Called by:', edgesOf('calls', 'to', node.id).map((e) => line(row(e, 'from'))))
102
+ + section('Reads tables:', reads.filter((e) => e.to === node.id).map((e) => line(nm(e.from))))
103
+ + section('Writes tables:', writes.filter((e) => e.from === node.id).map((e) => line(nm(e.to))))
104
+ + section('Mechanisms:', (node.mechanisms || []).map((m) => line(escHtml(m))));
89
105
  }
90
106
  if (node.type === 'container' && node.selfHosted) {
91
107
  // A self-hosted service is the container that runs it (spec 0031 section 3): what the API uses it for, who calls it, its webhook
92
108
  const row = (e, side) => `${nm(e[side])}${e.label && e.label !== 'calls' ? ` · ${escHtml(e.label)}` : ''}`;
93
109
  const into = state.edges.filter((e) => e.to === node.id && (e.kind === 'calls' || (e.kind === 'flow' && e.flow === 'api')));
94
- const calledBy = (type) => into.filter((e) => nodeById(e.from)?.type === type).map((e) => line(FLOW_STYLES.calls.color, '←', row(e, 'from')));
110
+ const calledBy = (type) => into.filter((e) => nodeById(e.from)?.type === type).map((e) => line(row(e, 'from')));
95
111
  const stackmates = new Set(state.nodes.filter((n) => n.type === 'container' && n.stack === node.stack).map((n) => n.id));
96
- return section('Self-hosted:', [line(FLOW_STYLES.calls.color, '◆', escHtml(node.summary || ''))])
112
+ return section('Self-hosted:', [line(escHtml(node.summary || ''))])
97
113
  + section('Called by services:', calledBy('service'))
98
114
  + section('Called by endpoints:', calledBy('page'))
99
115
  + section('Called by apps:', calledBy('app'))
100
- + section('Pushes to (webhook):', state.edges.filter((e) => e.kind === 'delivers' && stackmates.has(e.from) && nodeById(e.to)?.type === 'page').map((e) => line(FLOW_STYLES.delivers.color, '→', `${nm(e.to)}${e.from === node.id ? '' : ` <span class="hx-faint">from ${escHtml(nameOf(e.from))}</span>`}`)));
116
+ + section('Pushes to (webhook):', state.edges.filter((e) => e.kind === 'delivers' && stackmates.has(e.from) && nodeById(e.to)?.type === 'page').map((e) => line(`${nm(e.to)}${e.from === node.id ? '' : ` <span class="hx-faint">from ${escHtml(nameOf(e.from))}</span>`}`)));
101
117
  }
102
118
  if (node.type === 'external' && node.kind) { // a cloud node or the public web (spec 0031 section 6)
103
119
  return cloudPanelHtml(node, state.nodes, state.edges); // its File line is the registry
104
120
  }
105
121
  if (node.type === 'external') {
106
122
  const calledBy = (type) => edgesOf('calls', 'to', node.id).filter((e) => nodeById(e.from)?.type === type);
107
- return section('System:', [line(FLOW_STYLES.calls.color, '◆', `${escHtml(node.summary || '')}${node.host ? `<div class="hx-faint">Runs here as ${code(node.host)}</div>` : '<div class="hx-faint">Not run by this stack</div>'}`)])
108
- + section('Client modules:', (node.modules || []).map((m) => line('#fbbf24', 'ƒ', code(m))))
109
- + section('Called by services:', calledBy('service').map((e) => line(FLOW_STYLES.calls.color, '←', nm(e.from))))
110
- + section('Called by endpoints:', calledBy('page').map((e) => line(FLOW_STYLES.calls.color, '←', nm(e.from))))
111
- + section('Pushes to (webhook):', edgesOf('delivers', 'from', node.id).map((e) => line(FLOW_STYLES.delivers.color, '→', nm(e.to))));
123
+ return section('System:', [line(`${escHtml(node.summary || '')}${node.host ? `<div class="hx-faint">Runs here as ${code(node.host)}</div>` : '<div class="hx-faint">Not run by this stack</div>'}`)])
124
+ + section('Client modules:', (node.modules || []).map((m) => line(code(m))))
125
+ + section('Called by services:', calledBy('service').map((e) => line(nm(e.from))))
126
+ + section('Called by endpoints:', calledBy('page').map((e) => line(nm(e.from))))
127
+ + section('Pushes to (webhook):', edgesOf('delivers', 'from', node.id).map((e) => line(nm(e.to))));
112
128
  }
113
129
  if (node.type === 'page') {
114
130
  const r = node.render;
115
- const components = state.edges.filter((e) => e.dashed && e.from === node.id).map((e) => line('#818cf8', '→', nm(e.to)));
116
- return (node.methods ? section('Methods:', [line('#93c5fd', '⇢', node.methods.map(code).join(' '))]) : '')
117
- + (node.render_fn ? section('Rendered by:', [line('#93c5fd', 'ƒ', `${code(node.render_fn)} · ${escHtml(node.file)}`)]) : '')
118
- + section('Calls outside:', edgesOf('calls', 'from', node.id).map((e) => line(FLOW_STYLES.calls.color, '→', nm(e.to))))
119
- + section('Pushed to by:', edgesOf('delivers', 'to', node.id).map((e) => line(FLOW_STYLES.delivers.color, '←', `${nm(e.from)} · ${escHtml(e.label)}`)))
120
- + section('Starts:', edgesOf('triggers', 'from', node.id).map((e) => line(FLOW_STYLES.triggers.color, '→', `${nm(e.to)} · ${escHtml(e.label)}`)))
131
+ const components = state.edges.filter((e) => e.dashed && e.from === node.id).map((e) => line(nm(e.to)));
132
+ return (node.methods ? section('Methods:', [line(node.methods.map(code).join(' '))]) : '')
133
+ + (node.render_fn ? section('Rendered by:', [line(`${code(node.render_fn)} · ${escHtml(node.file)}`)]) : '')
134
+ + section('Calls outside:', edgesOf('calls', 'from', node.id).map((e) => line(nm(e.to))))
135
+ + section('Pushed to by:', edgesOf('delivers', 'to', node.id).map((e) => line(`${nm(e.from)} · ${escHtml(e.label)}`)))
136
+ + section('Starts:', edgesOf('triggers', 'from', node.id).map((e) => line(`${nm(e.to)} · ${escHtml(e.label)}`)))
121
137
  + section('Renders:', components)
122
- + section('Reads:', reads.filter((e) => e.to === node.id).map((e) => line(FLOW_STYLES.reads.color, '←', `${nm(e.from)} · ${e.keys.map(code).join(' ')}`)))
123
- + section('Writes:', writes.filter((e) => e.from === node.id).map((e) => line(FLOW_STYLES.writes.color, '→', `${nm(e.to)} · ${escHtml(e.label)}`)))
124
- + (r ? section('Render:', [line(FLOW_STYLES.rom.color, '◆', `today: ${code(r.now)} · ROM: ${r.rom === 'bake' ? '<span class="hx-rom hx-bold">bake</span>' : '<span class="hx-faint">skip (per request)</span>'}${r.note ? `<div class="hx-faint">${escHtml(r.note)}</div>` : ''}`)]) : '');
138
+ + section('Reads:', reads.filter((e) => e.to === node.id).map((e) => line(`${nm(e.from)} · ${e.keys.map(code).join(' ')}`)))
139
+ + section('Writes:', writes.filter((e) => e.from === node.id).map((e) => line(`${nm(e.to)} · ${escHtml(e.label)}`)))
140
+ + (r ? section('Render:', [line(`today: ${code(r.now)} · ROM: ${r.rom === 'bake' ? '<span class="hx-rom hx-bold">bake</span>' : '<span class="hx-faint">skip (per request)</span>'}${r.note ? `<div class="hx-faint">${escHtml(r.note)}</div>` : ''}`)]) : '');
125
141
  }
126
142
  return '';
127
143
  }
@@ -130,25 +146,71 @@ function dataSummary(node) {
130
146
  // Threads that mention the node
131
147
  // ---------------------------------------------------------------------------
132
148
 
133
- /** "Mentioned in": the threads whose text names the node (an idea, or a spec PR's conversation); each opens in the issues and PRs panel */
149
+ /** "Threads": the threads whose text names the node (an idea, or a spec PR's conversation); each opens in the Work panel */
134
150
  function threadsSection(node) {
135
151
  const index = state.threadIndex;
136
152
  if (!index) return '';
137
153
  const threads = index.for(node.id);
138
154
  // "Start a thread about this" shows whenever threads are on and a maintainer is signed in (the panel only sets `start` then)
139
- const start = index.start ? `<div class="hx-line"><button type="button" class="hx-btn" data-thread-start="${escHtml(node.id)}" aria-label="Start a thread about this: opens the New idea form for ${escHtml(index.forge())}, with this node mentioned">Start a thread about this</button></div>` : '';
155
+ const start = index.start ? `<button type="button" class="hx-btn hx-btn--quiet hx-textact" data-thread-start="${escHtml(node.id)}" aria-label="Start a thread about this: opens the New idea form for ${escHtml(index.forge())}, with this node mentioned">Start a thread about this</button>` : '';
140
156
  if (!threads || !threads.length) return start;
141
- const rows = threads.map((t) => `<div class="hx-line"><span class="hx-glyph" style="--glyph:#fbbf24">◆</span><span><button type="button" class="hx-btn hx-thread-open" data-thread-open="${t.number}" aria-label="Open thread #${t.number}, ${escHtml(t.title)}, in the issues and pull requests panel">#${t.number} ${escHtml(t.title)}</button> <span class="hx-faint">${t.kind === 'proposal' ? 'proposal' : 'idea'}</span></span></div>`);
142
- return section(`Mentioned in ${threads.length} ${threads.length === 1 ? 'thread' : 'threads'}:`, rows) + start;
157
+ const rows = threads.map((th) => {
158
+ const count = Number(th.comments) || 0;
159
+ return `<li><button type="button" class="hx-row hx-thread-open" data-thread-open="${escHtml(th.number)}" data-corn="row" aria-label="Open thread #${escHtml(th.number)}, ${escHtml(th.title)}, ${count} ${count === 1 ? 'comment' : 'comments'}, in the issues and pull requests panel"><span class="hx-row-title">${escHtml(th.title)}</span><span class="hx-row-meta">#${escHtml(th.number)} · ${count}</span></button></li>`;
160
+ });
161
+ return `<div class="hx-sec-block" data-corn="section"><h3 class="hx-sec-title">Threads</h3><ul class="hx-rows">${rows.join('')}</ul>${start}</div>`;
143
162
  }
144
163
 
145
- /** Draws "Mentioned in" again in the open panel (the list was just read, or the map changed); nothing else in the panel moves */
164
+ /** Draws "Threads" again in the open panel (the list was just read, or the map changed); nothing else in the panel moves */
146
165
  export function repaintThreads() {
147
166
  const box = $('drawer-threads');
148
167
  if (!box || !state.selectedNode) return;
149
168
  box.innerHTML = threadsSection(state.selectedNode);
150
169
  }
151
170
 
171
+ // ---------------------------------------------------------------------------
172
+ // The head: type · host, and what the open proposal does to the node
173
+ // ---------------------------------------------------------------------------
174
+
175
+ /** "Page", "Cloud", "Public web": the kind of node, in words */
176
+ function typeWords(node) {
177
+ if (node.type === 'external' && node.kind) return node.kind === 'web' ? 'Public web' : 'Cloud';
178
+ return node.type.charAt(0).toUpperCase() + node.type.slice(1);
179
+ }
180
+
181
+ /** The host a node answers on, when it has one */
182
+ function hostOf(node) {
183
+ if (node.url) { try { return new URL(node.url).host; } catch { /* not a URL: no host */ } }
184
+ return node.host || '';
185
+ }
186
+
187
+ /** "Added by Checkout": the pill for a node the open proposal touches; '' for one it leaves alone */
188
+ export function diffPillWords(node) {
189
+ const mark = node && node.mark;
190
+ if (!mark || mark === 'none') return '';
191
+ if (mark === 'edit') return `${node.editOp === 'removed' ? 'Removed' : 'Added'} by your edit`;
192
+ const title = state.proposal && typeof state.proposal.title === 'string' ? state.proposal.title : '';
193
+ return title ? `${MARK_WORDS[mark] || mark} by ${title}` : `${MARK_WORDS[mark] || mark} by this proposal`;
194
+ }
195
+
196
+ /** "In this proposal": the diff for a changed node as key/value rows (id, parent, edges +2; a change shows each field before and after) */
197
+ function diffSection(node) {
198
+ const kind = kindOfMark(node);
199
+ if (!diffPillWords(node)) return '';
200
+ const row = (k, v) => `<div class="hx-diff-k">${escHtml(k)}</div><div class="hx-diff-v">${v}</div>`;
201
+ const rows = [row('id', escHtml(node.id))];
202
+ const parent = state.edges.find((e) => !e.kind && !e.dashed && e.to === node.id);
203
+ if (parent) rows.push(row('parent', escHtml(parent.from)));
204
+ const touching = state.edges.filter((e) => e.from === node.id || e.to === node.id);
205
+ const added = touching.filter((e) => kindOfMark(e) === 'added').length;
206
+ const removed = touching.filter((e) => kindOfMark(e) === 'removed').length;
207
+ if (added || removed) rows.push(row('edges', escHtml([added ? `+${added}` : '', removed ? `−${removed}` : ''].filter(Boolean).join(' '))));
208
+ if (kind === 'changed') {
209
+ for (const r of fieldRows(node)) rows.push(row(r.field, `<span class="hx-change-before">${escHtml(r.before) || '<em>nothing</em>'}</span> <span aria-hidden="true">→</span><span class="hx-sr-only"> became </span> <span class="hx-change-after">${escHtml(r.after) || '<em>nothing</em>'}</span>`));
210
+ }
211
+ return `<div class="hx-sec-block" data-proposal-mark="${escHtml(node.mark)}" data-corn="section"><h3 class="hx-sec-title">In this proposal</h3>${node.why ? `<p class="hx-why">${escHtml(node.why)}</p>` : ''}<div class="hx-diff hx-diff--${escHtml(kind)}">${rows.join('')}</div></div>`;
212
+ }
213
+
152
214
  // ---------------------------------------------------------------------------
153
215
  // The drawer
154
216
  // ---------------------------------------------------------------------------
@@ -164,58 +226,55 @@ export async function selectNode(node) {
164
226
  touchScene();
165
227
  render();
166
228
 
167
- const propsList = $('drawer-props-list');
168
229
  const metaList = $('drawer-meta-list');
230
+ if (!metaList.dataset.moreBound) { metaList.dataset.moreBound = '1'; metaList.addEventListener('click', (e) => { toggleCapped(e.target); }); }
169
231
  const openBtn = $('drawer-open-btn');
232
+ const title = $('drawer-title');
170
233
 
171
- $('drawer-title').textContent = node.tag ? `<${node.tag}>` : node.label;
172
- $('drawer-badge').textContent = node.type === 'external' && node.kind ? (node.kind === 'web' ? 'PUBLIC WEB' : 'CLOUD') : node.type.toUpperCase();
173
- $('drawer-description').textContent = node.desc || '';
234
+ title.textContent = node.tag ? `<${node.tag}>` : node.label;
235
+ title.classList.toggle('hx-mono', node.type === 'page' || !!node.tag); // a route or a tag reads as code
236
+ $('drawer-badge').textContent = typeWords(node);
237
+ const host = hostOf(node);
238
+ $('drawer-host').textContent = host ? ` · ${host}` : '';
239
+ const pill = diffPillWords(node);
240
+ $('drawer-diff').textContent = pill;
241
+ $('drawer-diff').hidden = !pill;
242
+ const lead = $('drawer-description');
243
+ lead.textContent = node.desc || '';
244
+ lead.hidden = !node.desc;
174
245
  if (token !== selectToken) return;
175
246
 
176
- propsList.innerHTML = `
177
- <div class="hx-prop">
178
- <div class="hx-prop-head">
179
- <span class="hx-accent hx-bold">Node Degree</span>
180
- <span class="hx-good hx-bold">${node.degree || 0} edges</span>
181
- </div>
182
- <div class="hx-faint">Radius: ${node.r}px (${node.scaleDelta > 0 ? '+' : ''}${(node.scaleDelta || 0).toFixed(1)}px subtle degree sizing)</div>
183
- </div>`;
184
- metaList.innerHTML = `
185
- <div><strong class="hx-strong">ID:</strong> ${escHtml(node.id)}</div>
186
- <div><strong class="hx-strong">Category:</strong> ${escHtml(node.type)}</div>
187
- <div><strong class="hx-strong">Connected Edges:</strong> <span class="hx-accent hx-bold">${node.degree || 0}</span></div>
188
- ${node.file ? `<div><strong class="hx-strong">File:</strong> <code class="hx-code">${escHtml(node.file)}</code></div>` : ''}
189
- ${flowSummary(node)}
190
- ${dataSummary(node)}`;
247
+ const facts = `${node.file ? section('File', [code(node.file)]) : ''}${flowSummary(node)}${dataSummary(node)}`;
248
+ metaList.innerHTML = `${facts ? `<div class="hx-facts">${facts}</div>` : ''}
249
+ <div id="drawer-live">${liveSection(node)}</div>
250
+ ${nodeMockupsHtml(node.id)}
251
+ <div id="drawer-threads">${threadsSection(node)}</div>
252
+ ${diffSection(node)}`;
253
+ if (state.threadIndex) state.threadIndex.ensure();
254
+ hydrateLivePhotos($('drawer-live'));
255
+
256
+ // The actions: Open (when the node has an address) is the primary one; Start a run, when the open proposal can be handed to an agent
191
257
  if (node.url && /^https?:\/\//.test(node.url)) {
192
258
  openBtn.href = node.url;
193
259
  openBtn.textContent = `${t('openRoute')} ↗`;
260
+ openBtn.hidden = false;
194
261
  } else {
195
262
  openBtn.removeAttribute('href');
196
- openBtn.textContent = 'Internal Workspace Node';
263
+ openBtn.hidden = true;
197
264
  }
198
-
199
- // A node a proposal touches: why, and what changes (before and after), above the rest
200
- const proposed = proposalPanelHtml(node);
201
- if (proposed) metaList.insertAdjacentHTML('afterbegin', proposed);
202
- // The screens the proposal lists for it, which open from here (mockups.js)
203
- const mockups = nodeMockupsHtml(node.id);
204
- if (mockups) (proposed ? metaList.firstElementChild : metaList).insertAdjacentHTML(proposed ? 'afterend' : 'afterbegin', mockups);
205
-
206
- // The threads that mention it (docs/threads.md): filled in place once the list is read
207
- metaList.insertAdjacentHTML('beforeend', `<div id="drawer-threads">${threadsSection(node)}</div>`);
208
- if (state.threadIndex) state.threadIndex.ensure();
209
-
210
- // What the live layer knows of it (spec 0029): a count, a linked machine's item, contents and sets; repainted in place by live.js
211
- metaList.insertAdjacentHTML('beforeend', `<div id="drawer-live">${liveSection(node)}</div>`);
212
- hydrateLivePhotos($('drawer-live'));
265
+ const run = $('drawer-run-btn');
266
+ run.hidden = !(state.proposalSlug && canStartAgent());
213
267
 
214
268
  $('spec-drawer').classList.add('drawer-open');
215
269
  $('spec-drawer').inert = false; // closed, it waits off screen: inert, so Tab never reaches its buttons (MAP-02)
216
270
  $('drawer-backdrop').hidden = false;
217
271
  }
218
272
 
273
+ /** Start a run: the Start dialog of the Work panel, on the proposal that is open */
274
+ export function startRun() {
275
+ if (state.proposalSlug) openProposalStart(state.proposalSlug, '#drawer-run-btn');
276
+ }
277
+
219
278
  export function closeDrawer() {
220
279
  selectToken++;
221
280
  state.selectedEdge = null;
@@ -109,6 +109,19 @@ export function chipText(counts) {
109
109
  return parts.length ? parts.join(' · ') : 'No changes';
110
110
  }
111
111
 
112
+ /**
113
+ * The counts on the toolbar as parts, so each mark can carry its dot: "+4 added", "1 changed", "1 removed", then
114
+ * "3 scenarios". Zero counts are left out; nothing at all reads "No changes".
115
+ * @param {{added?:number, changed?:number, removed?:number, scenarios?:number}} counts `summarize(proposal)`
116
+ * @returns {{mark: string|null, text: string}[]}
117
+ */
118
+ export function barCounts(counts) {
119
+ const n = (k) => counts?.[k] || 0;
120
+ const parts = MARKS.filter((m) => n(m) > 0).map((m) => ({ mark: m, text: `${m === 'added' ? '+' : ''}${n(m)} ${m}` }));
121
+ if (n('scenarios') > 0) parts.push({ mark: null, text: `${n('scenarios')} ${n('scenarios') === 1 ? 'scenario' : 'scenarios'}` });
122
+ return parts.length ? parts : [{ mark: null, text: 'No changes' }];
123
+ }
124
+
112
125
  const SLUG = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
113
126
 
114
127
  /**
@@ -26,7 +26,7 @@ import { edgePoint, looksFor } from './scene.js';
26
26
  import { onThemeChange } from './theme.js';
27
27
  import { looksWith, onMapStyleChange } from './map-style.js';
28
28
  import {
29
- PROPOSAL_VIEWS, MARKS, MARK_WORDS, chipText, parseProposalQuery, proposalPanelHtml, touchedIds,
29
+ PROPOSAL_VIEWS, MARKS, MARK_WORDS, chipText, barCounts, parseProposalQuery, proposalPanelHtml, touchedIds,
30
30
  } from './proposal-model.js';
31
31
  import { applyProposal, edgeKey, proposalProblems, summarize } from '../core/proposal.js';
32
32
  import { reviewWords } from './review-model.js';
@@ -242,7 +242,7 @@ export function renderBar() {
242
242
  bar.hidden = !open;
243
243
  const legend = $('proposal-legend');
244
244
  if (legend) legend.hidden = !open;
245
- if (!open) { collapseSheet('proposal'); if (hooks.bar) hooks.bar(false); return; }
245
+ if (!open) { closeMore(); toggleMode(false); collapseSheet('proposal'); if (hooks.bar) hooks.bar(false); return; }
246
246
 
247
247
  bar.classList.remove('is-error');
248
248
  $('proposal-message').hidden = true;
@@ -251,12 +251,15 @@ export function renderBar() {
251
251
  $('proposal-title').textContent = (p && typeof p.title === 'string' && p.title) || state.proposalSlug || 'Proposal';
252
252
  const summary = $('proposal-summary');
253
253
  summary.textContent = (p && typeof p.summary === 'string' && p.summary) || '';
254
- summary.hidden = !summary.textContent;
254
+ const title = $('proposal-title');
255
+ title.title = summary.textContent; // the toolbar stays one row: the summary is the title's tooltip, and shows above the list of changes
256
+ summary.hidden = !summary.textContent || $('proposal-changes').hidden;
255
257
 
256
258
  const counts = summarize(p);
257
259
  const chip = $('proposal-chip');
258
- chip.textContent = chipText(counts);
259
- chip.title = counts.scenarios ? `${plural(counts.scenarios, 'scenario')}. Click for the list of changes.` : 'Click for the list of changes.';
260
+ chip.innerHTML = barCounts(counts).map((c) => `${c.mark ? `<span class="hx-mark-dot hx-mark-dot--${c.mark}" aria-hidden="true"></span>` : ''}${escHtml(c.text)}`).join('<span class="hx-proposal-sep" aria-hidden="true"> · </span>');
261
+ chip.title = 'Click for the list of changes.';
262
+ $('proposal-mode').textContent = t(state.proposalView);
260
263
 
261
264
  for (const btn of bar.querySelectorAll('[data-action="proposal-view"]')) {
262
265
  const on = btn.dataset.view === state.proposalView;
@@ -297,6 +300,7 @@ function toggleChanges() {
297
300
  const list = $('proposal-changes');
298
301
  if (!list) return;
299
302
  list.hidden = !list.hidden;
303
+ $('proposal-summary').hidden = list.hidden || !$('proposal-summary').textContent;
300
304
  $('proposal-chip').setAttribute('aria-expanded', String(!list.hidden));
301
305
  }
302
306
 
@@ -314,6 +318,57 @@ function focusChange(kind, key) {
314
318
  else selectNode(item);
315
319
  }
316
320
 
321
+ // ---------------------------------------------------------------------------
322
+ // The ⋯ menu (a menu button) and the phone's Before / Diff / After switcher
323
+ // ---------------------------------------------------------------------------
324
+
325
+ const moreItems = () => [...document.querySelectorAll('#proposal-more-menu [role="menuitem"]')];
326
+
327
+ function moreOpen() {
328
+ const menu = $('proposal-more-menu');
329
+ return !!menu && !menu.hidden;
330
+ }
331
+
332
+ /** Closes the ⋯ menu; `refocus` puts focus back on its button (Escape, or a choice made) */
333
+ function closeMore(refocus = false) {
334
+ const menu = $('proposal-more-menu');
335
+ const btn = $('proposal-more');
336
+ if (menu) menu.hidden = true;
337
+ if (btn) { btn.setAttribute('aria-expanded', 'false'); if (refocus) btn.focus(); }
338
+ }
339
+
340
+ function openMore(which = 'first') {
341
+ const menu = $('proposal-more-menu');
342
+ if (!menu) return;
343
+ menu.hidden = false;
344
+ $('proposal-more').setAttribute('aria-expanded', 'true');
345
+ const items = moreItems();
346
+ (which === 'last' ? items[items.length - 1] : items[0])?.focus();
347
+ }
348
+
349
+ /** On a phone the mode button shows the compare switcher under the counts; from 768px the switcher is always there */
350
+ function toggleMode(force) {
351
+ const bar = $('proposal-bar');
352
+ const on = typeof force === 'boolean' ? force : bar.dataset.modeOpen !== 'true';
353
+ bar.dataset.modeOpen = String(on);
354
+ $('proposal-mode').setAttribute('aria-expanded', String(on));
355
+ }
356
+
357
+ function onMoreKey(e) {
358
+ const btn = $('proposal-more');
359
+ if (e.target === btn && (e.key === 'ArrowDown' || e.key === 'ArrowUp')) { e.preventDefault(); openMore(e.key === 'ArrowUp' ? 'last' : 'first'); return; }
360
+ if (!moreOpen()) return;
361
+ if (e.key === 'Escape') { e.preventDefault(); closeMore(true); return; }
362
+ if (e.key === 'Tab') { closeMore(); return; }
363
+ const items = moreItems();
364
+ const at = items.indexOf(document.activeElement);
365
+ if (at < 0) return;
366
+ const next = { ArrowDown: (at + 1) % items.length, ArrowUp: (at - 1 + items.length) % items.length, Home: 0, End: items.length - 1 }[e.key];
367
+ if (next === undefined) return;
368
+ e.preventDefault();
369
+ items[next].focus();
370
+ }
371
+
317
372
  // ---------------------------------------------------------------------------
318
373
  // The picker
319
374
  // ---------------------------------------------------------------------------
@@ -407,18 +462,23 @@ export function markedEdgeAt(x, y, tolerance) {
407
462
  export function showEdgePanel(edge) {
408
463
  closeDrawer(); // clears a node selection and any panel still loading
409
464
  state.selectedEdge = edge;
410
- const row = (label, value) => (value ? `<div class="hx-prop"><div class="hx-prop-head"><span class="hx-accent hx-bold">${escHtml(label)}</span><span>${escHtml(value)}</span></div></div>` : '');
465
+ const row = (label, value) => (value ? `<div class="hx-fact"><div class="hx-fact-k">${escHtml(label)}</div><div class="hx-fact-v">${escHtml(value)}</div></div>` : '');
466
+ const facts = row('Kind', kindOf(edge)) + row('Flow', edge.flow) + row('Label', edge.label) + row('Reads', Array.isArray(edge.keys) ? edge.keys.join(', ') : '');
411
467
 
412
468
  $('drawer-title').textContent = `${nameOf(edge.from)} → ${nameOf(edge.to)}`;
413
- $('drawer-badge').textContent = 'EDGE';
414
- $('drawer-description').textContent = edge.label || '';
415
- $('drawer-props-list').innerHTML = row('Kind', kindOf(edge)) + row('Flow', edge.flow) + row('Label', edge.label) + row('Reads', Array.isArray(edge.keys) ? edge.keys.join(', ') : '');
416
- $('drawer-meta-list').innerHTML = `${proposalPanelHtml(edge)}
417
- <div><strong class="hx-strong">From:</strong> <button type="button" class="hx-linkbtn" data-action="select-node" data-id="${escHtml(edge.from)}">${escHtml(nameOf(edge.from))}</button></div>
418
- <div><strong class="hx-strong">To:</strong> <button type="button" class="hx-linkbtn" data-action="select-node" data-id="${escHtml(edge.to)}">${escHtml(nameOf(edge.to))}</button></div>`;
419
- const open = $('drawer-open-btn');
420
- open.removeAttribute('href');
421
- open.textContent = 'A link between two nodes';
469
+ $('drawer-title').classList.remove('hx-mono');
470
+ $('drawer-badge').textContent = 'Edge';
471
+ $('drawer-host').textContent = '';
472
+ $('drawer-diff').hidden = true;
473
+ $('drawer-description').textContent = '';
474
+ $('drawer-description').hidden = true;
475
+ $('drawer-meta-list').innerHTML = `${facts ? `<div class="hx-facts">${facts}</div>` : ''}
476
+ <div class="hx-facts">
477
+ <div class="hx-fact"><div class="hx-fact-k">From</div><div class="hx-fact-v"><button type="button" class="hx-linkbtn" data-action="select-node" data-id="${escHtml(edge.from)}">${escHtml(nameOf(edge.from))}</button></div></div>
478
+ <div class="hx-fact"><div class="hx-fact-k">To</div><div class="hx-fact-v"><button type="button" class="hx-linkbtn" data-action="select-node" data-id="${escHtml(edge.to)}">${escHtml(nameOf(edge.to))}</button></div></div>
479
+ </div>${proposalPanelHtml(edge)}`;
480
+ $('drawer-open-btn').hidden = true;
481
+ $('drawer-run-btn').hidden = true;
422
482
  $('spec-drawer').classList.add('drawer-open');
423
483
  $('drawer-backdrop').hidden = false;
424
484
  touchScene();
@@ -452,7 +512,9 @@ const ACTIONS = {
452
512
  'toggle-proposals-menu': () => toggleMenu(),
453
513
  'open-proposal': (el) => openProposal(el.dataset.slug, el.dataset.source || null),
454
514
  'close-proposal': () => closeProposal(),
455
- 'proposal-view': (el) => setProposalView(el.dataset.view),
515
+ 'proposal-view': (el) => { setProposalView(el.dataset.view); toggleMode(false); },
516
+ 'toggle-proposal-mode': () => toggleMode(),
517
+ 'toggle-proposal-more': () => (moreOpen() ? closeMore() : openMore()),
456
518
  'toggle-proposal-changes': () => toggleChanges(),
457
519
  'proposal-focus': (el) => focusChange(el.dataset.kind, el.dataset.key),
458
520
  };
@@ -461,6 +523,8 @@ function onClick(e) {
461
523
  const target = e.target.closest ? e.target.closest('[data-action]') : null;
462
524
  const action = target && ACTIONS[target.dataset.action];
463
525
  if (action) action(target);
526
+ // A choice in the ⋯ menu closes it back onto its button (Close may stop at the what-if confirm); a click anywhere else just closes it
527
+ if (moreOpen() && !(target && target.dataset.action === 'toggle-proposal-more')) closeMore(!!(target && target.closest('#proposal-more-menu')));
464
528
  // Any click outside the picker closes it
465
529
  const wrap = $('proposal-wrap');
466
530
  if (menuOpen() && wrap && !wrap.contains(e.target)) closeMenu();
@@ -468,6 +532,7 @@ function onClick(e) {
468
532
 
469
533
  function onKey(e) {
470
534
  if (e.key === 'Escape' && menuOpen()) closeMenu();
535
+ onMoreKey(e);
471
536
  }
472
537
 
473
538
  /** The marks' colours for the legend and the panel (the --hx-mark-* variables), the same the map draws on this ground */