arbiterdesign 0.1.4 → 0.1.7

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.
@@ -59,6 +59,7 @@
59
59
  .group { display: flex; align-items: baseline; gap: 10px; margin: 32px 0 10px; }
60
60
  .group h2 { margin: 0; text-transform: none; letter-spacing: 0; font-size: 15px; color: var(--ink); }
61
61
  .group span { color: var(--muted); font-size: 13px; }
62
+ .group .nopic { color: var(--warn); cursor: help; }
62
63
  .polish { background: var(--card); border: 1px dashed var(--line); border-radius: 12px; padding: 12px 20px; margin-bottom: 12px; }
63
64
  .polish .row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
64
65
  .polish .row .n { color: var(--muted); flex: 1; }
@@ -123,6 +124,12 @@
123
124
  .comments { border-top: 1px solid var(--line); margin-top: 10px; padding-top: 10px; font-size: 14px; }
124
125
  .comments .ok { color: var(--ok); }
125
126
  .comments p { margin: 4px 0; } .comments b { font-weight: 500; }
127
+ /* requests */
128
+ .card .asker { margin: 0 0 4px; color: var(--muted); font-size: 13px; }
129
+ .card h3.ask { font-weight: 500; white-space: pre-line; }
130
+ .card.approved { border-style: dashed; }
131
+ .card.approved h3.ask { color: var(--muted); }
132
+ code { font: 13px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; background: var(--tag); padding: 1px 5px; border-radius: 4px; }
126
133
  #lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.85); display: none; align-items: center; justify-content: center; cursor: zoom-out; z-index: 10; padding: 24px; }
127
134
  #lightbox img { max-width: 100%; max-height: 100%; border-radius: 6px; }
128
135
  footer {
@@ -146,13 +153,17 @@
146
153
  <script>
147
154
  const DIMS = ['structure','interaction','states','content','visual','motion','access'];
148
155
  const LABEL = { structure:'Structure', interaction:'Interaction', states:'States', content:'Content', visual:'Visual', motion:'Motion', access:'Accessibility' };
149
- const STATE_LABEL = { generated:'Generated', in_review:'In review', approved:'Approved', rejected:'Rejected', superseded:'Superseded' };
156
+ const STATE_LABEL = { generated:'Draft', in_review:'In review', approved:'Approved', rejected:'Rejected', superseded:'Replaced' };
150
157
  const results = {}; // pending id -> {item, kind, text}
151
158
  let state = null;
152
159
  let tab = 'decisions';
153
160
 
161
+ let first = true;
154
162
  async function load() {
155
163
  state = await (await fetch('/api/state')).json();
164
+ // Someone is waiting on an answer: open there.
165
+ if (first && state.requests.some(r => r.status === 'open')) tab = 'requests';
166
+ first = false;
156
167
  render();
157
168
  }
158
169
 
@@ -161,11 +172,13 @@ function render() {
161
172
  document.getElementById('count').textContent = `${state.active} of ${state.cap} rules`;
162
173
  const nav = document.getElementById('nav');
163
174
  nav.innerHTML = '';
175
+ const asks = state.requests.filter(r => r.status === 'open').length;
176
+ if (state.requests.length || Object.keys(answered).length) nav.appendChild(tabBtn('requests', `Requests · ${asks}`));
164
177
  nav.appendChild(tabBtn('decisions', `Decisions · ${state.pending.length}`));
165
178
  nav.appendChild(tabBtn('candidates', `Candidates · ${state.candidates.length}`));
166
179
  const main = document.getElementById('main');
167
180
  main.innerHTML = '';
168
- (tab === 'decisions' ? renderDecisions : renderCandidates)(main);
181
+ ({ requests: renderRequests, decisions: renderDecisions, candidates: renderCandidates })[tab](main);
169
182
  }
170
183
 
171
184
  function tabBtn(id, label) {
@@ -223,6 +236,9 @@ function renderDecisions(main) {
223
236
  head.appendChild(el('h2', null, g.trigger));
224
237
  const n = items.filter(d => !results[d.id]).length;
225
238
  head.appendChild(el('span', null, `${n} decision${n === 1 ? '' : 's'}${polish.length ? ` · +${polish.length} polish` : ''}`));
239
+ // The board shows an icon where a picture is missing, so this is the place to notice.
240
+ const pics = [...new Map(items.filter(d => !results[d.id] && d.picture).map(d => [d.picture.command, d.picture])).values()];
241
+ if (pics.length) { const p = el('span', 'nopic', '· No picture'); p.title = 'Take one while the screen is open:\n' + pics.map(m => m.command).join('\n'); head.appendChild(p); }
226
242
  main.appendChild(head);
227
243
  for (const d of items) main.appendChild(results[d.id] ? doneCard(d) : card(d));
228
244
  for (const d of g.polish.filter(d => promoted[d.id])) main.appendChild(results[d.id] ? doneCard(d) : card(d));
@@ -280,6 +296,7 @@ function card(d) {
280
296
  const line = (k, v, cls) => { dl.appendChild(el('dt', null, k)); dl.appendChild(el('dd', cls, v)); };
281
297
  if (d.change) line('Pattern', d.decision);
282
298
  for (const r of d.rejected) line('Rejected', r);
299
+ if (d.againstRule) line('Clashes', `${d.againstRule.id} · ${d.againstRule.decision}`);
283
300
  line('Why', d.rationale, 'muted');
284
301
  body.appendChild(dl);
285
302
  const meta = el('div', 'meta');
@@ -318,6 +335,16 @@ async function sendRow(d, li, body) {
318
335
 
319
336
  function actions(d, c) {
320
337
  const a = el('div', 'actions');
338
+ // Goes against a rule: someone has to say which wins. Same three choices as the review in chat.
339
+ const r = d.againstRule;
340
+ if (r) {
341
+ // The page records; it can't change code. Following the rule still needs the agent to do it.
342
+ a.appendChild(btn(`Follow ${r.id}`, 'primary', () => send(d, c, { as: 'fix', to: r.decision }, `Recorded. Ask your agent to change it to match ${r.id}.`)));
343
+ a.appendChild(btn(`Replace ${r.id}`, null, () => send(d, c, { as: 'rule', supersedes: r.id })));
344
+ a.appendChild(btn('Keep as exception', null, () => send(d, c, { as: 'accept' }, `Recorded as an exception to ${r.id}.`)));
345
+ a.appendChild(btn('Skip', 'quiet', () => send(d, c, { as: 'skip' })));
346
+ return a;
347
+ }
321
348
  a.appendChild(btn('Confirm', d.level === 'polish' ? 'primary' : null, () => send(d, c, { as: 'accept' })));
322
349
  if (d.level !== 'polish') a.appendChild(btn('Make it a rule', 'primary', () => send(d, c, { as: 'rule' })));
323
350
  a.appendChild(btn('Skip', 'quiet', () => send(d, c, { as: 'skip' })));
@@ -367,7 +394,7 @@ function contradictedPanel(d, c, res) {
367
394
  c.appendChild(p);
368
395
  }
369
396
 
370
- async function send(d, c, body) {
397
+ async function send(d, c, body, done) {
371
398
  c.querySelectorAll('button').forEach(b => b.disabled = true);
372
399
  const res = await (await fetch('/api/judge', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ id: d.id, ...body }) })).json();
373
400
  c.querySelectorAll('button').forEach(b => b.disabled = false);
@@ -376,7 +403,7 @@ async function send(d, c, body) {
376
403
  if (res.exitCode === 4) return contradictedPanel(d, c, res);
377
404
  if (res.exitCode !== 0) return messagePanel(c, (res.errors || ['Something went wrong']).join(' · '), 'bad');
378
405
  results[d.id] = { item: d, kind: res.status === 'skipped' ? 'skip' : 'ok',
379
- text: res.status === 'skipped' ? 'Skipped' : `Recorded ${res.id} as ${res.verdict}${res.supersedes ? ', replacing ' + res.supersedes : ''}` };
406
+ text: res.status === 'skipped' ? 'Skipped' : done ?? `Recorded ${res.id} as ${res.verdict}${res.supersedes ? ', replacing ' + res.supersedes : ''}` };
380
407
  await load();
381
408
  }
382
409
 
@@ -391,6 +418,100 @@ function doneCard(d) {
391
418
  return c;
392
419
  }
393
420
 
421
+ /* ── requests tab ────────────────────────────────────────────────────── */
422
+ const answered = {}; // request id -> {item, text} once declined here
423
+
424
+ function renderRequests(main) {
425
+ const open = state.requests.filter(r => r.status === 'open');
426
+ const approved = state.requests.filter(r => r.status === 'approved');
427
+ const declined = Object.values(answered);
428
+ if (!open.length && !approved.length && !declined.length) {
429
+ main.innerHTML = '<div class="empty"><h2>No requests.</h2><p>When someone presses Request change on the board, it lands here after <code>npx arbiter pull</code>.</p></div>';
430
+ return;
431
+ }
432
+ if (open.length || declined.length) {
433
+ main.appendChild(el('h2', null, 'To answer'));
434
+ for (const r of open) main.appendChild(requestCard(r));
435
+ for (const a of declined) {
436
+ const c = el('div', 'card done'); const row = el('div', 'result');
437
+ row.appendChild(el('span', 'skip', '—')); row.appendChild(el('span', null, a.item.body)); row.appendChild(el('span', 'meta', a.text));
438
+ c.appendChild(row); main.appendChild(c);
439
+ }
440
+ }
441
+ if (approved.length) {
442
+ main.appendChild(el('h2', null, 'Approved — the agent makes these at your next /arbiter'));
443
+ for (const r of approved) main.appendChild(requestCard(r));
444
+ }
445
+ }
446
+
447
+ function requestCard(r) {
448
+ const c = el('div', 'card' + (r.status === 'approved' ? ' approved' : '')); c.dataset.id = r.id;
449
+ const split = el('div', 'split');
450
+ const body = el('div', 'body');
451
+ body.appendChild(el('p', 'asker', `${r.author} asks`));
452
+ body.appendChild(el('h3', 'ask', r.body));
453
+ const meta = el('div', 'meta');
454
+ meta.appendChild(el('span', null, r.screenName ? `on ${r.screenName}` : `on ${r.screen}`));
455
+ if (r.decision) meta.appendChild(el('span', null, `· about ${r.decision}`));
456
+ meta.appendChild(el('span', null, '· ' + r.date.slice(0, 10)));
457
+ if (r.earlierVersion) { const s = el('span', null, '· earlier version'); s.title = 'Asked about a version of the board that has since been republished'; meta.appendChild(s); }
458
+ meta.appendChild(el('span', null, '· ' + r.id));
459
+ body.appendChild(meta);
460
+ if (r.status === 'approved') {
461
+ const dl = el('dl', 'lines');
462
+ dl.appendChild(el('dt', null, 'Doing')); dl.appendChild(el('dd', null, r.instead ? r.instead : 'As asked'));
463
+ body.appendChild(dl);
464
+ } else {
465
+ const a = el('div', 'actions');
466
+ a.appendChild(btn('Apply', 'primary', () => sendRequest(r, c, { as: 'apply' })));
467
+ a.appendChild(btn('Apply, but…', null, () => insteadPanel(r, c)));
468
+ a.appendChild(btn('Decline', 'quiet', () => declinePanel(r, c)));
469
+ body.appendChild(a);
470
+ }
471
+ split.appendChild(body);
472
+ if (r.snapshotUrl) {
473
+ const t = el('div', 'thumb'); t.onclick = () => zoom(r.snapshotUrl);
474
+ const img = el('img'); img.src = r.snapshotUrl; img.alt = r.screenName || r.screen; t.appendChild(img);
475
+ t.appendChild(el('div', 'cap', r.screenName || r.screen));
476
+ split.appendChild(t);
477
+ }
478
+ c.appendChild(split);
479
+ return c;
480
+ }
481
+
482
+ function insteadPanel(r, c) {
483
+ clearPanel(c);
484
+ const p = el('div', 'panel');
485
+ p.appendChild(el('p', null, `What should happen instead? ${r.author} sees what was actually done.`));
486
+ const ta = el('textarea'); ta.placeholder = 'e.g. keep it where it is, make the button red'; p.appendChild(ta);
487
+ const row = el('div', 'actions');
488
+ row.appendChild(btn('Apply this instead', 'primary', () => { if (ta.value.trim()) sendRequest(r, c, { as: 'apply', to: ta.value.trim() }); }));
489
+ row.appendChild(btn('Cancel', 'quiet', () => clearPanel(c)));
490
+ p.appendChild(row);
491
+ c.appendChild(p); ta.focus();
492
+ }
493
+
494
+ function declinePanel(r, c) {
495
+ clearPanel(c);
496
+ const p = el('div', 'panel');
497
+ p.appendChild(el('p', null, `Why not? ${r.author} reads this on the board.`));
498
+ const ta = el('textarea'); ta.placeholder = 'One line'; p.appendChild(ta);
499
+ const row = el('div', 'actions');
500
+ row.appendChild(btn('Decline', 'primary', () => { if (ta.value.trim()) sendRequest(r, c, { as: 'decline', why: ta.value.trim() }); else ta.focus(); }));
501
+ row.appendChild(btn('Cancel', 'quiet', () => clearPanel(c)));
502
+ p.appendChild(row);
503
+ c.appendChild(p); ta.focus();
504
+ }
505
+
506
+ async function sendRequest(r, c, body) {
507
+ c.querySelectorAll('button').forEach(b => b.disabled = true);
508
+ const res = await (await fetch('/api/request', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ id: r.id, ...body }) })).json();
509
+ c.querySelectorAll('button').forEach(b => b.disabled = false);
510
+ if (res.exitCode !== 0) return messagePanel(c, (res.errors || ['Something went wrong']).join(' · '), 'bad');
511
+ if (res.status === 'declined') answered[r.id] = { item: r, text: `Declined — ${res.reason}` };
512
+ await load();
513
+ }
514
+
394
515
  /* ── candidates tab ──────────────────────────────────────────────────── */
395
516
  function renderCandidates(main) {
396
517
  const all = state.candidates;
@@ -442,7 +563,7 @@ function candCard(c) {
442
563
  grid.appendChild(body);
443
564
  const shot = el('div', 'shot');
444
565
  if (c.snapshotUrl) { const img = el('img'); img.src = c.snapshotUrl; img.alt = c.name; shot.appendChild(img); shot.onclick = () => zoom(c.snapshotUrl); }
445
- else { shot.textContent = 'No snapshot'; shot.style.cursor = 'default'; shot.title = `npx arbiter candidate ${c.id} --capture`; }
566
+ else { shot.textContent = 'No picture'; shot.style.cursor = 'default'; shot.title = `npx arbiter candidate ${c.id} --snapshot shot.png`; }
446
567
  grid.appendChild(shot);
447
568
  card.appendChild(grid);
448
569
  return card;
@@ -469,7 +590,7 @@ async function sendCand(card, c, body) {
469
590
  }
470
591
 
471
592
  document.getElementById('done').onclick = async () => {
472
- await fetch('/api/done', { method: 'POST' });
593
+ await fetch('/api/done', { method: 'POST', headers: { 'content-type': 'application/json' }, body: '{}' });
473
594
  document.body.innerHTML = '<div class="empty"><h2>Review closed.</h2><p>You can close this tab.</p></div>';
474
595
  };
475
596