fwdloop 0.10.0 → 0.11.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.
@@ -53,6 +53,7 @@
53
53
  breakpoints, and also owns the horizontal scroll for the Path column
54
54
  on narrow (390px) screens instead of leaving it to .pane-body. */
55
55
  .audit-table-scroll{overflow:auto;max-height:min(60vh,520px);}
56
+ [data-testid="audit-table"] td.am, .audit-group table td.am{display:none;}
56
57
  /* z-index keeps rows from showing through the solid th background as
57
58
  they scroll under it. */
58
59
  [data-testid="audit-table"] th{position:sticky;top:0;z-index:1;}
@@ -225,6 +226,10 @@
225
226
  applies everywhere, so this wraps onto more lines instead of clipping,
226
227
  the same behavior fix #7 already gave phone width alone. */
227
228
  .wf-meta-line{white-space:normal;overflow:visible;text-overflow:clip;min-width:0;}
229
+ /* M4c-fix amendment 2 (g), line 2 of a run row: **word** — plain why. Wraps, never clips. */
230
+ .wf-sign-line{font-size:12px;color:var(--text-dim);white-space:normal;overflow-wrap:anywhere;min-width:0;}
231
+ .wf-sign-line .sign-word,.hdr-verdict .sign-word{color:var(--text);}
232
+ .hdr-verdict{font-size:12px;color:var(--text-dim);min-width:0;overflow-wrap:anywhere;}
228
233
  .wf-meta{font-size:12px;color:var(--text-dim);}
229
234
  .wf-meta + .wf-meta::before{content:" · ";color:var(--text-faint);}
230
235
  .wf-row.selected,.hist-row.selected{border:2px solid var(--accent);border-radius:4px;}
@@ -238,10 +243,19 @@
238
243
  .wf-runs .hist-row{margin-bottom:4px;}
239
244
 
240
245
  .rp-header{display:flex;align-items:center;justify-content:space-between;padding:10px 16px;border-bottom:2px solid var(--border-strong);background:var(--panel);flex-wrap:wrap;gap:8px;}
241
- .rp-header h2{margin:0;font-size:15px;}
242
- .rp-header h2::before{content:"┤ ";color:var(--text-faint);}
243
- .rp-header h2::after{content:" ├";color:var(--text-faint);}
244
- .rp-header-title{display:flex;align-items:center;gap:8px;flex-wrap:wrap;}
246
+ .rp-header h2{margin:0;font-size:15px;min-width:0;overflow-wrap:anywhere;text-transform:none;letter-spacing:normal;}
247
+ /* M4c-fix amendment 2 (k): the header reads like its Runs row — sign + name │ word — why · time; no frame, no capitals. */
248
+ .hdr-name-line{display:inline-flex;align-items:center;gap:8px;min-width:0;max-width:100%;}
249
+ .hdr-sep{color:var(--text-faint);}
250
+ .hdr-time{font-size:11px;color:var(--text-dim);min-width:0;overflow-wrap:anywhere;}
251
+ .hdr-verdict:has(+ .hdr-time:not(:empty))::after{content:" \00B7";}
252
+ .rp-header-title{display:flex;align-items:center;gap:8px;flex-wrap:wrap;min-width:0;max-width:100%;}
253
+ @media (max-width: 640px){
254
+ /* (k) a phone: the same three parts on three lines — sign + name / word — why / time */
255
+ .rp-header-title{flex-direction:column;align-items:flex-start;gap:2px;}
256
+ .rp-header-title .hdr-sep{display:none;}
257
+ .hdr-verdict:has(+ .hdr-time:not(:empty))::after{content:none;}
258
+ }
245
259
  /* item 4: phone-only jump-back link — hidden on desktop (the two panes
246
260
  are already both on screen there, nothing to jump back to). */
247
261
  .back-to-list-link{display:none;font-size:12px;color:var(--accent);text-decoration:underline;background:none;border:none;padding:0;cursor:pointer;}
@@ -273,16 +287,16 @@
273
287
  .map-box{border:1px solid var(--border-strong);padding:10px;overflow-x:auto;margin-top:16px;margin-bottom:14px;background:var(--panel2);text-align:center;}
274
288
  .map-box::before{content:"┤ MAP ├";display:block;font-size:11px;color:var(--text-faint);letter-spacing:0.08em;margin:-2px 0 8px 0;}
275
289
  .map-box svg{display:block;max-width:100%;height:auto;margin:0 auto;}
276
- .map-legend{display:flex;gap:14px;font-size:11px;color:var(--text-dim);margin-top:6px;flex-wrap:wrap;}
277
290
 
278
291
  .step-card{position:relative;border:1px solid var(--border);padding:10px;margin-bottom:8px;background:var(--panel2);}
279
292
  .step-card.running{border:1px double var(--amber);}
280
- /* hamr's 2026-09-27 styling ruling: the card's HEADER line (number, step
281
- name, state chip, close-class chip) is upper case and bold; the state/
282
- close chips keep their own color from `.badge`'s existing classes —
283
- text-transform never touches color. */
284
- .step-card .step-head{display:flex;align-items:center;justify-content:space-between;gap:8px;flex-wrap:wrap;text-transform:uppercase;font-weight:700;}
285
- .step-card h4{margin:0;font-size:13px;}
293
+ /* hamr's 2026-09-27 ruling made the card header bold; his 2026-10-04 ruling (amendment 4) put it in its
294
+ real case — `1 · resume-text [✓] passed [human check]`. The global `h2,h4` uppercase is turned off
295
+ for the card's h4. The chips keep their color from `.badge`. A signed state chip already carries its own
296
+ `[✓]`, so it draws no second pair of brackets (`.sign-badge`). */
297
+ .step-card .step-head{display:flex;align-items:center;justify-content:space-between;gap:8px;flex-wrap:wrap;text-transform:none;font-weight:700;}
298
+ .step-card h4{margin:0;font-size:13px;text-transform:none;letter-spacing:normal;}
299
+ .step-card .sign-badge::before,.step-card .sign-badge::after{content:none;}
286
300
  /* Every OTHER line on the card (goal, actions, granted, stopped reason) —
287
301
  lower case exactly as the data reads, normal weight; never inherits the
288
302
  header's uppercase/bold (same ruling, the non-header half of it). */
@@ -336,6 +350,30 @@
336
350
  `.audit-group h4` (0,1,1) and `.ask-question-heading` (0,1,0) alone, so
337
351
  this never un-bolds the ask question heading. */
338
352
  .audit-group h4.audit-status-header{font-weight:400;}
353
+ /* M4c-fix amendment 2 (f): a foldable step group. The header sits IN the box (not pinned over its top edge),
354
+ so a long header wraps inside its own box and never lands on the next group; a closed group is that one
355
+ header line with a caret and no empty table under it. */
356
+ .audit-group.audit-fold{padding:6px 10px;margin-top:6px;margin-bottom:6px;min-width:0;max-width:100%;box-sizing:border-box;}
357
+ .audit-group.audit-fold h4.audit-status-header{position:static;margin:0;padding:0;background:none;min-width:0;max-width:100%;overflow-wrap:anywhere;word-break:break-word;}
358
+ .audit-group.audit-fold h4.audit-status-header{display:flex;align-items:baseline;gap:6px;overflow:hidden;}
359
+ .audit-group.audit-fold h4.audit-status-header > .badge,.audit-group.audit-fold h4.audit-status-header::before{flex:none;white-space:pre;}
360
+ .audit-fold-name{flex:0 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}
361
+ .audit-fold-tail{flex:none;white-space:nowrap;}
362
+ .audit-group.audit-fold h4.audit-status-header::before{content:"\25B6 ";color:var(--text-faint);}
363
+ .audit-group.audit-fold h4.audit-status-header[aria-expanded="true"]::before{content:"\25BC ";}
364
+ .audit-group.audit-fold h4.audit-status-header::after{content:none;}
365
+ @media (max-width: 640px){
366
+ /* (l) a phone: the name is the only thing that shrinks — drop the dots and the word "try", tighten the gaps */
367
+ .audit-group.audit-fold{padding-left:8px;padding-right:8px;}
368
+ .audit-group.audit-fold h4.audit-status-header{gap:3px;font-size:12px;}
369
+ .audit-group.audit-fold h4.audit-status-header > .badge{padding-left:0;padding-right:0;font-size:10px;}
370
+ .audit-group.audit-fold h4.audit-status-header::before{content:"\25B6";}
371
+ .audit-group.audit-fold h4.audit-status-header[aria-expanded="true"]::before{content:"\25BC";}
372
+ .audit-fold-sep,.audit-fold-try{display:none;}
373
+ .audit-fold-n{margin-left:.4em;}
374
+ }
375
+ .audit-group.audit-fold table{margin-top:8px;}
376
+ .audit-group.audit-fold table[hidden]{display:none !important;}
339
377
  /* hamr's 2026-09-27 review: the group header's own state word (g.state,
340
378
  rendered as a <span class="badge STATE">) and its per-try marks
341
379
  (<span class="mark STATE">) reuse the SAME color vocabulary the runs
@@ -401,28 +439,52 @@
401
439
  `buildAuditRowEl` already sets on every cell (never a second, separate
402
440
  label list to keep in sync). No horizontal scroll is possible once
403
441
  every cell is a full-width block. */
404
- @media (max-width: 480px){
405
- [data-testid="audit-table"], .audit-group table{width:100%;}
442
+ /* hamr's exit walk: ONE ROW PER LINE on a phone. Each audit entry is a single flex line — glyph, #attempt,
443
+ step (flat view only), verdict word, short cost, HH:MM — built from the `.am-*` cells `buildAuditRowEl`
444
+ adds (hidden on desktop, where the table is unchanged). Everything the line cut short hides behind a tap: the
445
+ row toggles `.open` and its full step, verdict, gap, refused list and tools show as wrapped lines under it. Every other cell hides. Nothing is wider
446
+ than the viewport: the step cell shrinks and ellipsizes, the rest are nowrap and short. The line never wraps
447
+ (flex-wrap:nowrap, overflow hidden), so a larger system font or a long verdict word shrinks the step and
448
+ ellipsizes rather than pushing cost and time onto a second line. It applies up to 640px — the whole
449
+ phone/narrow-window range, not only 480 (a 500 px window showed the wide table, rows 49-607 px tall). */
450
+ @media (max-width: 640px){
451
+ /* display:block: a table would size itself to its nowrap cells' content and run wider than the screen */
452
+ [data-testid="audit-table"], .audit-group table{display:block;width:100%;max-width:100%;}
406
453
  [data-testid="audit-table"] thead, .audit-group table thead{
407
454
  position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap;
408
455
  }
409
456
  [data-testid="audit-table"] tbody, .audit-group table tbody{display:block;}
410
457
  [data-testid="audit-table"] tr, .audit-group table tr{
411
- display:block;border:1px solid var(--border-strong);margin-bottom:8px;padding:4px 0;
458
+ display:flex;flex-wrap:nowrap;align-items:center;column-gap:8px;border-bottom:1px solid var(--border);padding:4px 6px;box-sizing:border-box;max-width:100%;overflow:hidden;
412
459
  }
413
460
  [data-testid="audit-table"] td, .audit-group table td{
414
- display:block;border:none;border-bottom:1px dotted var(--border);padding:4px 8px;
415
- /* fix (2026-09-28): a pre-M4a-2 row's Time cell shows the longer
416
- `atWhy` text ("not recorded (before M4a-2)") instead of a
417
- timestamp — overflow-wrap:anywhere (on top of the existing
418
- break-word/word-break) makes sure that text wraps inside the
419
- cell's own border at 390px instead of spilling past it. */
420
- white-space:normal;overflow-wrap:anywhere;word-break:break-word;max-width:100%;box-sizing:border-box;
461
+ display:none;border:none;padding:0;min-width:0;box-sizing:border-box;white-space:nowrap;
421
462
  }
422
- [data-testid="audit-table"] td:last-child, .audit-group table td:last-child{border-bottom:none;}
423
- [data-testid="audit-table"] td::before, .audit-group table td::before{
424
- content:attr(data-label) ": ";font-weight:700;color:var(--text-dim);
463
+ [data-testid="audit-table"] td.am, .audit-group table td.am,
464
+ [data-testid="audit-table"] td[data-label="Attempt"], .audit-group table td[data-label="Attempt"],
465
+ [data-testid="audit-table"] td[data-label="Step"], .audit-group table td[data-label="Step"],
466
+ [data-testid="audit-table"] td[data-label="Verdict"], .audit-group table td[data-label="Verdict"]{display:block;}
467
+ [data-testid="audit-table"] td[data-label="Attempt"]::before, .audit-group table td[data-label="Attempt"]::before{content:"#";}
468
+ [data-testid="audit-table"] td.am-glyph, .audit-group table td.am-glyph{order:1;flex:0 0 auto;}
469
+ [data-testid="audit-table"] td[data-label="Attempt"], .audit-group table td[data-label="Attempt"]{order:2;flex:0 0 auto;color:var(--text-dim);}
470
+ [data-testid="audit-table"] td[data-label="Step"], .audit-group table td[data-label="Step"]{order:3;flex:1 1 0;overflow:hidden;text-overflow:ellipsis;}
471
+ [data-testid="audit-table"] td[data-label="Verdict"], .audit-group table td[data-label="Verdict"]{order:4;flex:0 1 auto;max-width:9em;overflow:hidden;text-overflow:ellipsis;}
472
+ [data-testid="audit-table"] td.am-cost, .audit-group table td.am-cost{order:5;flex:0 0 auto;}
473
+ [data-testid="audit-table"] td.am-time, .audit-group table td.am-time{order:6;flex:0 0 auto;color:var(--text-dim);}
474
+ /* no step cell (grouped view): the verdict takes the slack so cost and time sit at the right */
475
+ .audit-group table td[data-label="Verdict"]{flex:1 1 0;}
476
+ /* EVERY entry opens on a tap (not only one with a gap): the line above shortens the step and verdict with an
477
+ ellipsis, so the tap is the one way to read all of it. The open block is wrapped lines under the one line. */
478
+ tr.audit-tap{cursor:pointer;}
479
+ tr.audit-tap td.am-glyph::after{content:"\25B8";margin-left:2px;color:var(--text-faint);}
480
+ tr.audit-tap.open td.am-glyph::after{content:"\25BE";}
481
+ [data-testid="audit-table"] td.am.am-detail, .audit-group table td.am.am-detail{display:none;}
482
+ [data-testid="audit-table"] tr.open, .audit-group table tr.open{flex-wrap:wrap;}
483
+ [data-testid="audit-table"] tr.open td.am-detail, .audit-group table tr.open td.am-detail{
484
+ display:block;order:7;flex:0 0 100%;min-width:0;white-space:normal;overflow-wrap:anywhere;padding:4px 0 2px;color:var(--text-dim);
425
485
  }
486
+ td.am-detail .am-d{margin:0 0 3px;}
487
+ td.am-detail .am-d b{color:var(--text);font-weight:600;}
426
488
  }
427
489
  </style>
428
490
  </head>
@@ -491,10 +553,10 @@
491
553
  <div class="rp-header">
492
554
  <button type="button" class="back-to-list-link" id="back-to-list" data-testid="back-to-list">&#8593; list</button>
493
555
  <div class="rp-header-title">
494
- <span class="dot grey" id="active-wf-dot"></span>
495
- <h2 id="active-wf-name">(none selected)</h2>
496
- <span class="badge" id="active-wf-verdict">—</span>
497
- <span class="badge" id="active-wf-date">—</span>
556
+ <span class="hdr-name-line"><span class="dot grey" id="active-wf-dot"></span><h2 id="active-wf-name">(none selected)</h2></span>
557
+ <span class="hdr-sep" aria-hidden="true">&#9474;</span>
558
+ <span class="hdr-verdict" id="active-wf-verdict">—</span>
559
+ <span class="hdr-time" id="active-wf-date">—</span>
498
560
  </div>
499
561
  </div>
500
562
 
@@ -617,9 +679,8 @@
617
679
  "use strict";
618
680
 
619
681
  var PORT = "__FWDLOOP_PANEL_PORT__";
620
- // M4b piece 1: per-process answer token, replaced at serve time; sent only as
621
- // the x-fwdloop-token header of the two POSTs (postJSON below).
622
- var TOKEN = "__FWDLOOP_PANEL_TOKEN__";
682
+ // M4c-fix item 2: the page carries NO token. The panel link sets an HttpOnly cookie; every
683
+ // request (reads and the two POSTs) is authenticated by that cookie, sent by the browser itself.
623
684
  document.getElementById("host-line").textContent = "127.0.0.1:" + PORT;
624
685
 
625
686
  function wireTabs(tabButtons){
@@ -642,20 +703,28 @@
642
703
 
643
704
  // ---- fetch helpers. Reads are GET. The ONLY non-GET requests on this page are
644
705
  // the two POSTs below (M4b): /api/answer (a human clicking a door) and
645
- // /api/resume ("try the resume again"). The token goes in the request header
646
- // and nowhere else — never the DOM, a URL, storage or a log. Same-origin. ----
706
+ // /api/resume ("try the resume again"). Auth is the HttpOnly cookie
707
+ // (never the DOM, a URL, storage or a log). Same-origin. ----
647
708
  function getJSON(path){
648
709
  return fetch(path, { method: "GET", headers: { accept: "application/json" } }).then(function(r){
649
- if(!r.ok) throw new Error(path + ": HTTP " + r.status);
710
+ if(!r.ok){ var err = new Error(path + ": HTTP " + r.status); err.status = r.status; throw err; }
650
711
  return r.json();
651
712
  });
652
713
  }
714
+ // The ONE place a failed load becomes words (amendment 2 (b)): a plain sentence, never the thrown
715
+ // message (it carries the path and the HTTP code), never a status number.
716
+ function loadFailureText(e){
717
+ var status = e && e.status;
718
+ if(status === 403) return "The panel does not recognise this page. Open the link the terminal printed.";
719
+ if(status === 404) return "This run is no longer there.";
720
+ return "Could not load this; reload the page.";
721
+ }
653
722
  // Resolves { status, body } for ANY HTTP status (a refusal is data to show by
654
723
  // name, never an exception); rejects only on a network failure.
655
724
  function postJSON(path, payload){
656
725
  return fetch(path, {
657
726
  method: "POST",
658
- headers: { "content-type": "application/json", accept: "application/json", "x-fwdloop-token": TOKEN },
727
+ headers: { "content-type": "application/json", accept: "application/json" },
659
728
  body: JSON.stringify(payload),
660
729
  credentials: "same-origin"
661
730
  }).then(function(r){
@@ -718,6 +787,12 @@
718
787
  var short = d.toLocaleTimeString();
719
788
  return '<span title="' + escapeXml(full) + '">' + escapeXml(short) + '</span>';
720
789
  }
790
+ // phone one-liner: local HH:MM only; a row with no recorded time reads a dash (never a made-up time).
791
+ function auditShortTime(r){
792
+ var d = new Date(r.at);
793
+ if(typeof r.at !== "string" || isNaN(d.getTime())) return "—";
794
+ return ("0" + d.getHours()).slice(-2) + ":" + ("0" + d.getMinutes()).slice(-2);
795
+ }
721
796
  function duration(ms){
722
797
  if(typeof ms !== "number" || ms < 0) return "unknown";
723
798
  var s = ms / 1000;
@@ -726,6 +801,14 @@
726
801
  if(rem === 60){ m += 1; rem = 0; }
727
802
  return m + "m" + String(rem).padStart(2, "0") + "s";
728
803
  }
804
+ // A signed wait in words: "30 min", "2 h"; anything not a whole minute falls back to `duration`.
805
+ function waitText(ms){
806
+ if(typeof ms !== "number" || !(ms > 0)) return "unknown";
807
+ var m = ms / 60000;
808
+ if(m >= 60 && m % 60 === 0) return (m / 60) + " h";
809
+ if(m >= 1 && Number.isInteger(m)) return m + " min";
810
+ return duration(ms);
811
+ }
729
812
  // A readable local date/time instead of a raw ISO timestamp (fix #5) — an
730
813
  // unparseable value still shows the raw string (never blank/nothing), so
731
814
  // a books bug is visible rather than silently swallowed.
@@ -741,10 +824,14 @@
741
824
  // parked on a human) reads "waiting on you", matching the SAME words the
742
825
  // run-row `[·]` glyph already uses (src/panel/data.js's computeGlyph) —
743
826
  // never the bracket glyph `[▶]`, which the scope reserves for "running".
827
+ // M4c-fix amendment 2 (g): a step's own sign + word come from the SAME one table the run rows use (the server's
828
+ // SIGN_WORDS, sent on the run detail as `signWords`); the page keeps no table of its own. Not started: no sign.
829
+ var signWords = {};
830
+ var STEP_SIGN = { done: "[\u2713]", stopped: "[\u2717]", waiting: "[\u00b7]" };
744
831
  function stateWord(state){
745
832
  if(state === "pending") return "not started";
746
- if(state === "waiting") return "waiting on you";
747
- return state; // "done" / "stopped"
833
+ var g = STEP_SIGN[state];
834
+ return g && signWords[g] ? g + " " + signWords[g] : state;
748
835
  }
749
836
  // fwdloop's close-class vocabulary (M4a scope item 4): `green` -> "cited"
750
837
  // (a mechanical, exact-match close), `softgreen` -> "shape" (a shape/
@@ -805,6 +892,8 @@
805
892
  if(verdict === "paused") return "paused for you";
806
893
  if(verdict === "refused") return "refused — no reason given";
807
894
  if(verdict === "ask-timeout" || verdict === "ask-expired") return "expired waiting for you";
895
+ if(verdict === "ask-reopened") return "reopened by you";
896
+ if(verdict === "lock-removed") return "old lock removed by you";
808
897
  if(verdict === "green") return "passed";
809
898
  if(verdict === "hitl") return "human check";
810
899
  if(verdict === "not-done") return "not done";
@@ -817,7 +906,7 @@
817
906
  // would misread a pause as a failure (fix #3).
818
907
  function verdictGlyph(verdict, closeClass){
819
908
  if(closeClass === "hitl" && verdict === "red") return null;
820
- if(verdict === "paused" || verdict === "refused" || verdict === "ask-timeout" || verdict === "ask-expired") return null;
909
+ if(verdict === "paused" || verdict === "refused" || verdict === "ask-timeout" || verdict === "ask-expired" || verdict === "ask-reopened" || verdict === "lock-removed") return null;
821
910
  return verdictPassed(verdict) ? "✓" : "✗";
822
911
  }
823
912
  // The run-row glyph strings src/panel/data.js's computeGlyph emits are
@@ -825,6 +914,12 @@
825
914
  // CSS color class off them, never re-derives the glyph itself.
826
915
  // the dot's class list: colour from the glyph, `pulse` only when the server
827
916
  // says this sign is [▶] running or [·] waiting on you (data.js glyphPulses).
917
+ // M4c-fix amendment 2 (g): one bold word after every sign, then " — " and the plain line. The word comes from the
918
+ // server's one sign->word table (data.js SIGN_WORDS) on `word`; this only draws it, the same in Runs, Inbox and the header.
919
+ function signHtml(word, line, fallback){
920
+ if(!word) return escapeXml(fallback || "unknown");
921
+ return '<b class="sign-word">' + escapeXml(word) + '</b>' + (line ? " &mdash; " + escapeXml(line) : "");
922
+ }
828
923
  function dotClass(g, pulse){ return "dot " + glyphClass(g) + (pulse ? " pulse" : ""); }
829
924
  function glyphClass(g){
830
925
  if(g === "[✓]") return "green";
@@ -956,8 +1051,16 @@
956
1051
  }
957
1052
  return {perRow:1, boxW:Math.max(MIN_BOX_W, Math.min(usableW, ceiling))};
958
1053
  }
1054
+ // M4c-fix amendment 2 (l): a line longer than the box is cut with … (the whole name stays in the node's <title>
1055
+ // and on its step card below the map).
1056
+ function mapLabel(line, maxChars){
1057
+ return line.length <= maxChars ? line : line.slice(0, Math.max(1, maxChars - 1)) + "\u2026";
1058
+ }
959
1059
  function wrapTitleLines(text, maxWidth){
960
1060
  var maxChars = Math.max(1, Math.floor((maxWidth - TITLE_HPAD) / CHAR_W));
1061
+ return wrapTitleLinesRaw(text, maxChars).map(function(l){ return mapLabel(l, maxChars); });
1062
+ }
1063
+ function wrapTitleLinesRaw(text, maxChars){
961
1064
  if(text.length <= maxChars) return [text];
962
1065
  var words = text.split(' ');
963
1066
  var line1 = '', i = 0;
@@ -1008,7 +1111,7 @@
1008
1111
  // into a jump to the Audit tab's matching group is wired AFTER
1009
1112
  // insertion (renderStepMap, below), never inline here (this function
1010
1113
  // only ever builds a markup string).
1011
- body += '<g class="map-step" data-emits="' + escapeXml(s.emits) + '" tabindex="0" role="button" aria-label="open ' + escapeXml(s.emits) + ' in Audit">';
1114
+ body += '<g class="map-step" data-emits="' + escapeXml(s.emits) + '" tabindex="0" role="button" aria-label="open ' + escapeXml(s.emits) + ' in Audit"><title>' + escapeXml(stepTitleText(idx, s)) + '</title>';
1012
1115
  body += '<rect x="' + x + '" y="' + y + '" width="' + boxW + '" height="' + boxH +
1013
1116
  '" rx="0" fill="var(--panel2)" stroke="' + colors.stroke + '" stroke-width="2"></rect>';
1014
1117
  if(lines.length === 1){
@@ -1064,21 +1167,6 @@
1064
1167
  });
1065
1168
  return '<svg width="' + totalW + '" height="' + totalH + '" viewBox="0 0 ' + totalW + ' ' + totalH + '" role="img" aria-label="step map">' + body + '</svg>';
1066
1169
  }
1067
- // Legend glyphs match the scope's own vocabulary (fix #4): `[✓]` done,
1068
- // `[✗]` stopped, `[·]` waiting on you (the default/grey dot — never the
1069
- // amber `[▶]`, which the scope reserves for "running", a state this panel
1070
- // cannot tell apart from "died" at all today — M4a's own open POC
1071
- // question). "not started" gets no dot/glyph at all, so it can never be
1072
- // confused with a reserved one.
1073
- function stepMapLegendHTML(){
1074
- return '<div class="map-legend">' +
1075
- '<span><span class="dot green"></span>done</span>' +
1076
- '<span><span class="dot red"></span>stopped</span>' +
1077
- '<span><span class="dot"></span>waiting on you</span>' +
1078
- '<span>not started</span>' +
1079
- '<span>⤾ dashed = retry</span>' +
1080
- '</div>';
1081
- }
1082
1170
  var lastSteps = null;
1083
1171
  var lastWidth = null;
1084
1172
  function mapAvailWidth(wrapper){
@@ -1112,7 +1200,7 @@
1112
1200
  wrapper.hidden = false;
1113
1201
  var w = mapAvailWidth(wrapper);
1114
1202
  lastWidth = w;
1115
- mount.innerHTML = buildStepMapSVG(steps, w) + stepMapLegendHTML();
1203
+ mount.innerHTML = buildStepMapSVG(steps, w);
1116
1204
  wireMapClicks(mount);
1117
1205
  }
1118
1206
  function reflowMap(){
@@ -1122,7 +1210,7 @@
1122
1210
  if(w === null || w === lastWidth) return;
1123
1211
  lastWidth = w;
1124
1212
  var mount = document.getElementById("map-mount");
1125
- mount.innerHTML = buildStepMapSVG(lastSteps, w) + stepMapLegendHTML();
1213
+ mount.innerHTML = buildStepMapSVG(lastSteps, w);
1126
1214
  wireMapClicks(mount);
1127
1215
  }
1128
1216
  if(typeof ResizeObserver !== "undefined"){
@@ -1165,8 +1253,8 @@
1165
1253
  row.innerHTML =
1166
1254
  '<span class="wf-line1"><span class="' + dotClass(r.glyph, r.pulse) + '"></span>' +
1167
1255
  '<span class="wf-name" title="' + escapeXml(fullName) + '">' + escapeXml(fullName) + '</span></span>' +
1256
+ '<span class="wf-sign-line" data-testid="run-sign-word">' + signHtml(r.word, r.line, r.label) + '</span>' +
1168
1257
  '<span class="wf-meta-line">' +
1169
- '<span class="wf-meta">' + escapeXml(r.label || "unknown") + '</span>' +
1170
1258
  '<span class="wf-meta">' + escapeXml(runSpendText(r)) + '</span>' +
1171
1259
  '<span class="wf-meta">' + escapeXml(runAtText(r)) + '</span>' +
1172
1260
  '</span>';
@@ -1176,20 +1264,34 @@
1176
1264
  }
1177
1265
 
1178
1266
  // M4c amendment 1 (a): the ONE place a click on a run in Runs decides where it lands.
1179
- // Right side: that run, on the Run tab. A run with an ask waiting on the human also
1180
- // moves the left side to the Inbox with that ask's row selected; any other run leaves
1181
- // the left side on Runs.
1267
+ // Right side: that run, on the Run tab, at once. Whether the run has an ask waiting on the human (or is
1268
+ // stuck, which counts as waiting: M4c amendment 2 (b)) is decided from THAT RUN's own asks, fetched on
1269
+ // the click — never from the cached list row, which can be up to LISTS_POLL_MS old (a run that has just
1270
+ // parked, been reopened or answered would read wrong). If it does, the left side moves to the Inbox with
1271
+ // that ask's row selected (the Inbox is refreshed first) and the right side moves to the Ask tab, where its
1272
+ // buttons are (M4c-fix amendment 2 (i)). "Needs you" = waiting, stuck, or expired with the Reopen offer (the
1273
+ // same `!open && reopen` test answerControls uses); any other run leaves the left side on Runs, right on Run.
1274
+ function askNeedingYou(result){
1275
+ var found = null;
1276
+ ((result && result.asks) || []).forEach(function(a){ if(a.waiting || a.stuck || (!a.open && a.reopen)) found = a; });
1277
+ return found;
1278
+ }
1182
1279
  function openRunFromRuns(r, rowEl){
1183
- if(r.waiting){
1184
- var inboxId = "inbox-row-" + r.flow + "-" + r.runId + "-" + r.waitingAskId;
1185
- var inboxRow = Array.prototype.find.call(document.querySelectorAll(".inbox-row"), function(el){ return el.getAttribute("data-testid") === inboxId; }) || null;
1186
- selectRun(r.flow, r.runId, inboxRow, ".inbox-row", r.waitingAskId);
1187
- document.getElementById("tab-inbox").click();
1188
- } else {
1189
- selectRun(r.flow, r.runId, rowEl, ".hist-row");
1190
- }
1280
+ selectRun(r.flow, r.runId, rowEl, ".hist-row");
1191
1281
  document.getElementById("tab-run").click();
1192
1282
  scrollRunIntoViewMobile();
1283
+ getJSON("/api/runs/" + encodeURIComponent(r.flow) + "/" + encodeURIComponent(r.runId) + "/asks").then(function(result){
1284
+ // the user already clicked another run: this answer is for a run they left
1285
+ if(currentFlow !== r.flow || currentRunId !== r.runId) return;
1286
+ var ask = askNeedingYou(result);
1287
+ if(!ask) return;
1288
+ reloadLists();
1289
+ var inboxId = "inbox-row-" + r.flow + "-" + r.runId + "-" + ask.askId;
1290
+ var inboxRow = Array.prototype.find.call(document.querySelectorAll(".inbox-row"), function(el){ return el.getAttribute("data-testid") === inboxId; }) || null;
1291
+ selectRun(r.flow, r.runId, inboxRow, ".inbox-row", ask.askId);
1292
+ document.getElementById("tab-inbox").click();
1293
+ document.getElementById("tab-ask").click();
1294
+ }).catch(function(){ /* unreadable books: the run stays open on the Run tab, the left side stays on Runs */ });
1193
1295
  }
1194
1296
 
1195
1297
  // ---- History view: every row exactly as /api/runs returned it. ----
@@ -1336,8 +1438,8 @@
1336
1438
  row.innerHTML =
1337
1439
  '<span class="wf-line1"><span class="wf-caret">' + (hasOtherRuns ? (expanded ? "▼" : "▶") : "") + '</span><span class="' + dotClass(g.lastGlyph, g.lastRow.pulse) + '"></span>' +
1338
1440
  '<span class="wf-name" title="' + escapeXml(wfFullName) + '">' + escapeXml(wfFullName) + '</span></span>' +
1441
+ '<span class="wf-sign-line" data-testid="run-sign-word">' + signHtml(g.lastRow.word, g.lastRow.line, g.lastLabel) + '</span>' +
1339
1442
  '<span class="wf-meta-line">' +
1340
- '<span class="wf-meta">' + escapeXml(g.lastLabel || "unknown") + '</span>' +
1341
1443
  '<span class="wf-meta">' + escapeXml(runSpendText(g.lastRow)) + '</span>' +
1342
1444
  '<span class="wf-meta">' + escapeXml(runAtText(g.lastRow)) + '</span>' +
1343
1445
  '<span class="wf-meta">' + g.runCount + ' run' + (g.runCount === 1 ? '' : 's') + '</span>' +
@@ -1601,9 +1703,10 @@
1601
1703
  var verdict = document.getElementById("active-wf-verdict");
1602
1704
  var date = document.getElementById("active-wf-date");
1603
1705
 
1706
+ if(detail.signWords) signWords = detail.signWords;
1604
1707
  name.textContent = detail.flow + " (" + detail.runId + ")";
1605
1708
  dot.className = dotClass(detail.glyph, detail.pulse);
1606
- verdict.textContent = detail.label || "unknown";
1709
+ verdict.innerHTML = signHtml(detail.word, detail.line, detail.label);
1607
1710
  // browser re-walk bug #4: this is the DATE field — it must use its own
1608
1711
  // why (`detail.atWhy`), never `detail.outcomeWhy` (a different book
1609
1712
  // fact borrowed by mistake). A parked run's ask.json `askedAt` is a
@@ -1640,7 +1743,7 @@
1640
1743
  var modelText = detail.model || (detail.modelWhy || "no model call recorded yet");
1641
1744
  var closeText = closeClassSummaryText(detail.steps) || (detail.stepsWhy || "no steps recorded");
1642
1745
  box.innerHTML =
1643
- '<div class="summary-headline"><span class="' + dotClass(detail.glyph, detail.pulse) + '"></span><b>' + escapeXml(detail.label || "unknown") + '</b> &middot; <span class="num">' + escapeXml(spendText) + '</span></div>' +
1746
+ '<div class="summary-headline"><span class="' + dotClass(detail.glyph, detail.pulse) + '"></span>' + signHtml(detail.word, detail.line, detail.label) + ' &middot; <span class="num">' + escapeXml(spendText) + '</span></div>' +
1644
1747
  '<div class="summary-row" data-testid="summary-model"><span class="sum-label">model:</span><span class="sum-val">' + escapeXml(modelText) + '</span></div>' +
1645
1748
  '<div class="summary-row"><span class="sum-label">steps:</span><span class="sum-val">' + stepsText + '</span></div>' +
1646
1749
  '<div class="summary-row" data-testid="summary-why"><span class="sum-label">why:</span><span class="sum-val">' + escapeXml(detail.stopReason || detail.stopReasonWhy || "not recorded") + '</span></div>' +
@@ -1695,8 +1798,8 @@
1695
1798
  div.textContent = text;
1696
1799
  return div;
1697
1800
  }
1698
- // The card's HEADER line: "N · step-name [state] [close class]" — upper
1699
- // case/bold from CSS (`.step-card .step-head`), the state/close chips
1801
+ // The card's HEADER line: "N · step-name [state] [close class]" — real
1802
+ // case, bold from CSS (`.step-card .step-head`), the state/close chips
1700
1803
  // keeping their own `.badge` color. `auditStateClass` is the SAME
1701
1804
  // function the Audit tab's group headers use to color their own state
1702
1805
  // word — never a second color scheme for the Run tab's cards.
@@ -1707,7 +1810,7 @@
1707
1810
  h4.textContent = (idx + 1) + " · " + box.emits;
1708
1811
  head.appendChild(h4);
1709
1812
  var stateBadge = document.createElement("span");
1710
- stateBadge.className = "badge " + auditStateClass(box.state);
1813
+ stateBadge.className = "badge " + auditStateClass(box.state) + (STEP_SIGN[box.state] ? " sign-badge" : "");
1711
1814
  stateBadge.setAttribute("data-testid", "step-card-state-" + idx);
1712
1815
  stateBadge.textContent = stateWord(box.state);
1713
1816
  head.appendChild(stateBadge);
@@ -1809,12 +1912,28 @@
1809
1912
  var header = row.querySelector("h4");
1810
1913
  if(table && table.hidden){
1811
1914
  table.hidden = false;
1915
+ row.classList.remove("closed");
1916
+ auditExpanded[step] = true;
1812
1917
  if(header) header.setAttribute("aria-expanded", "true");
1813
1918
  }
1814
1919
  if(typeof row.scrollIntoView === "function") row.scrollIntoView({ block: "center" });
1815
1920
  row.classList.add("audit-group-highlight");
1816
1921
  setTimeout(function(){ row.classList.remove("audit-group-highlight"); }, 1600);
1817
1922
  }
1923
+ // What a phone tap shows under the one-line entry: everything the line cut short, in full, as wrapped lines.
1924
+ // Only fields the row actually has — a line with nothing to say is left out, never filled with a made-up value.
1925
+ function auditDetailHtml(r, word, actionText, isRejectRow){
1926
+ var lines = [["step", r.step], ["result", word], ["action", actionText]];
1927
+ if(!isRejectRow && r.gap) lines.push(["gap", r.gap]);
1928
+ if(Array.isArray(r.refused) && r.refused.length > 0){
1929
+ lines.push(["refused", r.refused.map(function(x){ return x.verb + " " + x.path + " (" + x.rule + ")"; }).join("; ")]);
1930
+ }
1931
+ if(Array.isArray(r.ungranted) && r.ungranted.length > 0) lines.push(["not granted, called anyway", r.ungranted.join(", ")]);
1932
+ lines.push(["close", closeClassLabel(r.class)], ["cost", auditCostCellText(r)]);
1933
+ var when = readableDateTime(r.at);
1934
+ lines.push(["time", (typeof r.atWhy === "string" && r.atWhy.length > 0) ? r.atWhy : (when || "unknown")]);
1935
+ return lines.map(function(l){ return "<div class=\"am-d\"><b>" + escapeXml(l[0]) + ":</b> " + escapeXml(l[1]) + "</div>"; }).join("");
1936
+ }
1818
1937
  // ONE row-cell builder for both views — `includeStep` controls only
1819
1938
  // whether the Step cell is rendered (Grouped drops it; the group's own
1820
1939
  // header already names the step). Column order: Attempt, [Step], Action,
@@ -1842,8 +1961,20 @@
1842
1961
  "<td data-label=\"Cost\">" + escapeXml(auditCostCellText(r)) + "</td>" +
1843
1962
  "<td data-label=\"Verdict\"><span class=\"badge " + badgeClass + "\">" + escapeXml(word) + "</span></td>" +
1844
1963
  "<td data-label=\"Close\">" + escapeXml(closeClassLabel(r.class)) + "</td>" +
1845
- "<td data-label=\"Time\">" + auditTimeCellHtml(r) + "</td>";
1964
+ "<td data-label=\"Time\">" + auditTimeCellHtml(r) + "</td>" +
1965
+ // phone-only one-line cells (CSS shows these and hides the rest below 640px; hidden on desktop)
1966
+ "<td class=\"am am-glyph\" aria-hidden=\"true\">" + escapeXml(glyph || "·") + "</td>" +
1967
+ "<td class=\"am am-cost\">" + escapeXml(money(r.usd, r.spendComplete)) + "</td>" +
1968
+ "<td class=\"am am-time\">" + escapeXml(auditShortTime(r)) + "</td>" +
1969
+ "<td class=\"am am-detail\">" + auditDetailHtml(r, word, actionText, isRejectRow) + "</td>";
1846
1970
  tr.innerHTML = cells;
1971
+ // every entry opens on a tap, by finger or keyboard; only the phone layout shows what opening reveals
1972
+ tr.className = "audit-tap";
1973
+ tr.tabIndex = 0;
1974
+ tr.setAttribute("aria-expanded", "false");
1975
+ var toggle = function(){ tr.setAttribute("aria-expanded", tr.classList.toggle("open") ? "true" : "false"); };
1976
+ tr.addEventListener("click", toggle);
1977
+ tr.addEventListener("keydown", function(ev){ if(ev.key === "Enter" || ev.key === " "){ ev.preventDefault(); toggle(); } });
1847
1978
  return tr;
1848
1979
  }
1849
1980
  // ---- hamr's 2026-09-27 exit-check review #2: the Audit tab's All/Human/
@@ -1915,22 +2046,41 @@
1915
2046
  stateSpan.setAttribute("data-testid", "audit-group-state");
1916
2047
  stateSpan.textContent = g.state;
1917
2048
  h4.appendChild(stateSpan);
1918
- h4.appendChild(document.createTextNode(" · " + g.step + " · " + duration(g.timeMs) + " · " + (g.cost || "cost unknown")));
1919
- if(typeof g.tokensTotal === "number") h4.appendChild(document.createTextNode(" · " + g.tokensTotal + " tokens"));
1920
- h4.appendChild(document.createTextNode(" · try " + g.tryCount + " "));
2049
+ // M4c-fix amendment 2 (l): the title is `[sign] name · cost · try N ✗✓` — the name alone is cut with … (own flex child),
2050
+ // cost and tries never; time and tokens live in each try's detail. The whole name is in the title attribute and aria-label.
2051
+ var nameSpan = document.createElement("span");
2052
+ nameSpan.className = "audit-fold-name";
2053
+ nameSpan.setAttribute("data-testid", "audit-group-name");
2054
+ nameSpan.title = g.step;
2055
+ nameSpan.textContent = g.step;
2056
+ h4.appendChild(nameSpan);
2057
+ var tail = document.createElement("span");
2058
+ tail.className = "audit-fold-tail";
2059
+ // the dots and the word "try" are their own spans so a phone can drop them (keeping cost, N and the marks)
2060
+ function tailPart(cls, text){ var sp = document.createElement("span"); sp.className = cls; sp.textContent = text; tail.appendChild(sp); }
2061
+ tailPart("audit-fold-sep", "· ");
2062
+ tail.appendChild(document.createTextNode(g.cost || "cost unknown"));
2063
+ tailPart("audit-fold-sep", " · ");
2064
+ tailPart("audit-fold-try", "try ");
2065
+ tailPart("audit-fold-n", g.tryCount + " ");
1921
2066
  g.tryMarks.forEach(function(mark){
1922
2067
  var markSpan = document.createElement("span");
1923
2068
  markSpan.className = "mark " + auditMarkClass(mark);
1924
2069
  markSpan.textContent = mark;
1925
- h4.appendChild(markSpan);
2070
+ tail.appendChild(markSpan);
1926
2071
  });
2072
+ h4.appendChild(tail);
1927
2073
  return h4;
1928
2074
  }
1929
2075
  // Grouped view: one section per step, server order preserved (first-seen
1930
2076
  // order of `r.step` across this run's own rows — never re-sorted).
1931
2077
  // review item #1: COLLAPSED by default — a map/step-card click
1932
2078
  // (`openAuditGroup`) is the only thing that force-expands one.
2079
+ var auditExpanded = {}; // step -> true/false once a human toggled it; reset when the run changes
2080
+ var auditExpandedRun = null;
1933
2081
  function renderAuditGroups(result){
2082
+ var runKey = currentFlow + "/" + currentRunId;
2083
+ if(auditExpandedRun !== runKey){ auditExpanded = {}; auditExpandedRun = runKey; }
1934
2084
  var container = document.getElementById("audit-groups");
1935
2085
  container.innerHTML = "";
1936
2086
  if(!result || result.empty) return;
@@ -1949,24 +2099,42 @@
1949
2099
  // COLLAPSED by default now (`aria-expanded` starts "false", the
1950
2100
  // table starts `hidden`) — expanding is something a human (or a
1951
2101
  // map/step-card jump) does, never the initial state.
2102
+ // M4c-fix amendment 2 (f): a step with any failed try (a row with a gap) starts OPEN so its gap is
2103
+ // seen without a click; the rest start closed. A manual toggle wins on re-render (auditExpanded).
2104
+ var failed = (g.rows || []).some(function(r){ return !!r.gap; });
2105
+ var isOpen = Object.prototype.hasOwnProperty.call(auditExpanded, g.step) ? auditExpanded[g.step] : failed;
2106
+ wrap.classList.add("audit-fold");
2107
+ if(!isOpen) wrap.classList.add("closed");
1952
2108
  var header = buildAuditGroupHeaderEl(g);
1953
2109
  header.setAttribute("role", "button");
1954
2110
  header.setAttribute("tabindex", "0");
1955
- header.setAttribute("aria-expanded", "false");
2111
+ header.setAttribute("aria-expanded", isOpen ? "true" : "false");
1956
2112
  header.setAttribute("aria-label", auditGroupHeaderText(g));
1957
2113
  header.style.cursor = "pointer";
1958
2114
  wrap.appendChild(header);
1959
2115
  var table = document.createElement("table");
1960
- table.hidden = true;
2116
+ table.hidden = !isOpen;
1961
2117
  table.innerHTML = "<thead><tr><th>Attempt</th><th>Action</th><th>Gap</th><th>Cost</th><th>Verdict</th><th>Close</th><th>Time</th></tr></thead><tbody></tbody>";
1962
2118
  var tbody = table.querySelector("tbody");
1963
2119
  rows.forEach(function(r){ tbody.appendChild(buildAuditRowEl(r, false)); });
1964
2120
  table.setAttribute("data-testid", "audit-table-grouped-" + g.step);
1965
2121
  wrap.appendChild(table);
2122
+ // M4c-fix amendment 2 (j): a step with exactly one try opens that try's detail with the group, closes with it
2123
+ // (the same `.open` tap-detail the row's own tap toggles; only the phone layout shows it).
2124
+ function syncSingleRow(open){
2125
+ if(rows.length !== 1) return;
2126
+ var only = tbody.firstChild;
2127
+ only.classList.toggle("open", open);
2128
+ only.setAttribute("aria-expanded", open ? "true" : "false");
2129
+ }
2130
+ syncSingleRow(isOpen);
1966
2131
  function toggleAuditGroup(){
1967
2132
  var next = table.hidden;
1968
2133
  table.hidden = !next;
2134
+ wrap.classList.toggle("closed", !next);
2135
+ auditExpanded[g.step] = next;
1969
2136
  header.setAttribute("aria-expanded", next ? "true" : "false");
2137
+ syncSingleRow(next);
1970
2138
  }
1971
2139
  header.addEventListener("click", toggleAuditGroup);
1972
2140
  header.addEventListener("keydown", function(e){
@@ -2176,15 +2344,20 @@
2176
2344
  // src/panel/data.js works out the boundary server-side, off the run's
2177
2345
  // full audit-row order, so the client no longer needs a second,
2178
2346
  // separately-fetched copy of the audit rows to cross-reference (fix #6).
2179
- getJSON(base).then(paintRun).catch(function(e){
2347
+ // same guard as reloadRun: a late reply for a run the user already left paints nothing and writes no polling flag
2348
+ var still = function(){ return currentFlow === flow && currentRunId === runId; };
2349
+ getJSON(base).then(function(d){ if(still()) paintRun(d); }).catch(function(e){
2350
+ if(!still()) return;
2351
+ openRunLive = false; // unreadable books: the list rate, not 2 s forever
2180
2352
  document.getElementById("run-empty").hidden = false;
2181
- document.getElementById("run-empty").textContent = "failed to load run: " + e.message;
2353
+ document.getElementById("run-empty").textContent = loadFailureText(e);
2182
2354
  document.getElementById("run-content").hidden = true;
2183
2355
  });
2184
- getJSON(base + "/audit").then(renderAudit).catch(function(){ renderAudit(null); });
2185
- getJSON(base + "/job").then(renderJob).catch(function(){ renderJob(null); });
2186
- getJSON(base + "/asks").then(function(result){ renderAsk(result, focusAskId || null); }).catch(function(e){
2187
- renderAsk(null, null, e.message);
2356
+ // the same late-reply guard on audit, job and asks: a reply for a run the user already left paints nothing
2357
+ getJSON(base + "/audit").then(function(a){ if(still()) renderAudit(a); }).catch(function(){ if(still()) renderAudit(null); });
2358
+ getJSON(base + "/job").then(function(j){ if(still()) renderJob(j); }).catch(function(){ if(still()) renderJob(null); });
2359
+ getJSON(base + "/asks").then(function(result){ if(still()) renderAsk(result, focusAskId || null); }).catch(function(e){
2360
+ if(still()) renderAsk(null, null, loadFailureText(e));
2188
2361
  });
2189
2362
  }
2190
2363
 
@@ -2231,7 +2404,7 @@
2231
2404
  function reloadRun(flow, runId, skipLists){
2232
2405
  var base = "/api/runs/" + encodeURIComponent(flow) + "/" + encodeURIComponent(runId);
2233
2406
  var still = function(){ return currentFlow === flow && currentRunId === runId; };
2234
- var detailP = getJSON(base).then(function(d){ if(still()) paintRun(d); return d; }).catch(function(){ return null; });
2407
+ var detailP = getJSON(base).then(function(d){ if(still()) paintRun(d); return d; }).catch(function(){ if(still()) openRunLive = false; return null; }); // unreadable books: the list rate, not 2 s forever
2235
2408
  var asksP = getJSON(base + "/asks").then(function(a){
2236
2409
  if(still()){
2237
2410
  // the Ask tab is drawn from the books AND the page's own pending answer ("working…" block)
@@ -2241,7 +2414,7 @@
2241
2414
  if(next === null || next !== lastSig.asks){ lastSig.asks = renderAsk(a, null) ? next : null; }
2242
2415
  }
2243
2416
  return a;
2244
- }).catch(function(e){ if(still()){ lastSig.asks = null; renderAsk(null, null, e.message); } return null; });
2417
+ }).catch(function(e){ if(still()){ lastSig.asks = null; renderAsk(null, null, loadFailureText(e)); } return null; });
2245
2418
  getJSON(base + "/audit").then(function(a){
2246
2419
  if(!still()) return;
2247
2420
  var next = sig(a);
@@ -2264,8 +2437,9 @@
2264
2437
  var listsDue = catchUp || (Date.now() - lastListsAt) >= LISTS_POLL_MS;
2265
2438
  var wasLive = openRunLive;
2266
2439
  var selP;
2267
- // the open run's own panes: every tick, but only while it is live (or being watched), or on catch-up
2268
- if(sel && (openRunLive || watchIsSelected || catchUp)) selP = reloadRun(currentFlow, currentRunId, true);
2440
+ // the open run's own panes: every tick while it is live (or being watched); a finished run (or one whose
2441
+ // books can't be read) at the list rate, so a late change shows without a re-click; or on catch-up
2442
+ if(sel && (openRunLive || watchIsSelected || catchUp || listsDue)) selP = reloadRun(currentFlow, currentRunId, true);
2269
2443
  else selP = Promise.resolve([null, null]);
2270
2444
  if(listsDue) reloadLists();
2271
2445
  // the watched run, when it is not the one on screen: read it for its outcome only (no paint — `still()` is false)
@@ -2281,6 +2455,8 @@
2281
2455
  function stopLive(){ live = null; }
2282
2456
  // What the books say now, in words (pure; `null` = keep waiting).
2283
2457
  function liveOutcome(askId, detail, asks){
2458
+ // amendment 1 (a): within the watch the saved answer turned out to have no readable time — say why; the doors come back
2459
+ if(asks && asks.resume && asks.resume.state === "broken") return { done: true, cls: "refused", text: asks.resume.label + ": " + (asks.resume.reason || "") };
2284
2460
  if(asks && asks.resume && asks.resume.state === "not-started") return { done: true, cls: null, text: null };
2285
2461
  var list = (asks && asks.asks) || [];
2286
2462
  var fresh = list.find(function(a){ return a.waiting && a.askId !== askId; });
@@ -2339,8 +2515,8 @@
2339
2515
  runsFilterBar.refresh();
2340
2516
  }
2341
2517
  }).catch(function(e){
2342
- document.getElementById("wf-list").innerHTML = '<div class="hint">failed to load: ' + escapeXml(e.message) + '</div>';
2343
- document.getElementById("history-list").innerHTML = '<div class="hint">failed to load: ' + escapeXml(e.message) + '</div>';
2518
+ document.getElementById("wf-list").innerHTML = '<div class="hint">' + escapeXml(loadFailureText(e)) + '</div>';
2519
+ document.getElementById("history-list").innerHTML = '<div class="hint">' + escapeXml(loadFailureText(e)) + '</div>';
2344
2520
  });
2345
2521
 
2346
2522
  // ---- shared text-node helper — book text (question/draft/artifact
@@ -2365,7 +2541,7 @@
2365
2541
  // Ask tab, focused on that one ask. The answer doors live in the Ask tab. --
2366
2542
  function stopStatusLine(row){
2367
2543
  if(row.waiting) return "time left: " + duration(row.timeLeftMs);
2368
- if(row.stuck) return row.stuckLabel;
2544
+ if(row.stuck) return row.stuckLine || row.stuckLabel;
2369
2545
  if(row.working) return "working on your " + row.working + "…";
2370
2546
  if(row.open && row.resume) return row.resume.label;
2371
2547
  var bits = [row.status];
@@ -2403,7 +2579,10 @@
2403
2579
  flowName.className = "wf-name";
2404
2580
  head.appendChild(flowName);
2405
2581
  wrap.appendChild(head);
2406
- wrap.appendChild(textDiv("wf-meta", stopStatusLine(row)));
2582
+ var meta = textDiv("wf-sign-line", "");
2583
+ meta.setAttribute("data-testid", "inbox-sign-word");
2584
+ meta.innerHTML = signHtml(row.word, stopStatusLine(row), stopStatusLine(row));
2585
+ wrap.appendChild(meta);
2407
2586
  if(typeof row.question === "string"){
2408
2587
  wrap.appendChild(textDiv("step-meta", "question: " + row.question));
2409
2588
  } else if(row.questionWhy){
@@ -2446,7 +2625,7 @@
2446
2625
  }
2447
2626
  getJSON("/api/inbox").then(function(result){ renderInbox(result.rows || [], result.openCount); }).catch(function(e){
2448
2627
  lastSig.inbox = null;
2449
- document.getElementById("inbox-list").innerHTML = '<div class="hint">failed to load: ' + escapeXml(e.message) + '</div>';
2628
+ document.getElementById("inbox-list").innerHTML = '<div class="hint">' + escapeXml(loadFailureText(e)) + '</div>';
2450
2629
  });
2451
2630
 
2452
2631
  // ---- Ask tab (M4a-1): every ask of the SELECTED run, collapsed by
@@ -2465,6 +2644,7 @@
2465
2644
  var bits = [ask.status];
2466
2645
  if(ask.reason) bits.push("reason: " + ask.reason);
2467
2646
  if(ask.answeredAt) bits.push("answered " + (readableDateTime(ask.answeredAt) || ask.answeredAt));
2647
+ if(ask.why) bits.push(ask.why);
2468
2648
  return textDiv("wf-meta", bits.join(" · "));
2469
2649
  }
2470
2650
  // ---- M4b piece 4: answer doors. The panel is a CLIENT of the arbiter: it sends
@@ -2482,19 +2662,27 @@
2482
2662
  }
2483
2663
  function answerControls(ask, resume, pending){
2484
2664
  if(pending && ask && pending.askId === ask.askId){
2485
- return { kind: "working", text: pendingText(pending), why: "no answer doors: the answer was sent" };
2665
+ return { kind: "working", text: pendingText(pending) };
2666
+ }
2667
+ // amendment 1 (b): an expired ask offers one human action, the reopen (never an answer word)
2668
+ if(ask && !ask.open && ask.reopen){
2669
+ return { kind: "expired", waitMs: ask.reopen.waitMs, late: !!ask.reopen.late, line: ask.reopen.why, why: "no answer doors: this ask expired — reopen it to answer" };
2486
2670
  }
2487
2671
  if(!ask || !ask.open){
2488
- return { kind: "none", why: "no answer doors: this ask is " + ((ask && ask.status) || "closed") + " — there is nothing left to answer" };
2672
+ return { kind: "none", why: "This ask is " + ((ask && ask.status) || "closed") + ". There is nothing left to answer." };
2489
2673
  }
2490
2674
  if(resume && resume.askId === ask.askId){
2675
+ // amendment 1 (a): a saved answer with no readable time gives the doors back, with a note saying why
2676
+ if(resume.state === "broken"){
2677
+ return { kind: "doors", note: resume.label + (resume.reason ? " " + resume.reason : "") };
2678
+ }
2491
2679
  if(resume.state === "starting"){
2492
- return { kind: "starting", label: resume.label, why: "no answer doors: this ask already has a saved answer" };
2680
+ return { kind: "starting", text: "Your answer is saved; the run is starting up." };
2493
2681
  }
2494
2682
  if(resume.state === "not-started"){
2495
- return { kind: "stuck", label: resume.label, lockPath: resume.lockPath || null, reason: resume.reason || "no reason recorded", why: "no answer doors: this ask already has a saved answer" };
2683
+ return { kind: "stuck", lockPath: resume.lockPath || null };
2496
2684
  }
2497
- return { kind: "none", why: "no answer doors: " + resume.label };
2685
+ return { kind: "none", why: resume.label + "." };
2498
2686
  }
2499
2687
  return { kind: "doors" };
2500
2688
  }
@@ -2525,10 +2713,53 @@
2525
2713
  el.textContent = mine ? m.text : "";
2526
2714
  });
2527
2715
  }
2528
- function refusalText(r){
2529
- var b = r.body;
2530
- var name = b && typeof b.red === "string" ? b.red : (r.text || "no detail");
2531
- return "HTTP " + r.status + " — " + name;
2716
+ // Every refusal the page shows is a plain sentence — never an HTTP status, a refusal code, an askId or a path.
2717
+ // `r` is { status, body, text } from postJSON; `decision` is the answer word of an answer click (else null).
2718
+ // The server's own refusal name (`refused`) is matched first; a library refusal is matched by what it says.
2719
+ function networkText(){ return "Could not reach the panel, so nothing is confirmed. Check it is still running; the header above shows what the books say."; }
2720
+ // A redo or rerun needs a reason. The page only saves the round trip: the library still judges every answer.
2721
+ function reasonMissing(decision, value){ return (decision === "redo" || decision === "rerun") && String(value).trim() === ""; }
2722
+ function blankReasonText(decision){ return "Please write a reason for the " + (decision === "rerun" ? "rerun" : "redo") + "."; }
2723
+ function refusalText(r, decision){
2724
+ var byName = {
2725
+ "already-resuming": "This run is already carrying on. Wait a moment, then look again.",
2726
+ "no-saved-answer": "There is no saved answer to continue from.",
2727
+ "run-ended": "This run has already ended.",
2728
+ "lock-has-holder": "Something is working on this run now, so the old lock was left alone. Look again in a moment.",
2729
+ "no-lock": "The old lock is already gone. Continue the run instead.",
2730
+ "lock-outside-run": "That run can't be found.",
2731
+ "flow-outside-root": "That run can't be found.",
2732
+ "bad-flow": "That run can't be found.",
2733
+ "bad-runId": "That run can't be found.",
2734
+ "askid-required": "That click was not understood. Reload the page and try again.",
2735
+ "body-not-json": "That click was not understood. Reload the page and try again.",
2736
+ "body-too-large": "That is too long to send. Please shorten your reason.",
2737
+ "cookie-missing-or-wrong": "The panel does not recognise this page. Open the link the terminal printed.",
2738
+ "origin-not-own": "The panel does not recognise this page. Open the link the terminal printed.",
2739
+ "host-not-own-address": "The panel does not recognise this page. Open the link the terminal printed.",
2740
+ "internal": "Something went wrong inside the panel. Nothing was changed."
2741
+ };
2742
+ var byWords = [
2743
+ [/needs a non-blank reason/, null],
2744
+ [/expired at/, "The time to answer ran out. Reopen it to give it more time."],
2745
+ [/already answered/, "This ask was already answered."],
2746
+ [/answer saved in time|has an answer saved/, "Your answer is saved. Continue the run instead."],
2747
+ [/has not expired/, "This ask has not run out of time yet."],
2748
+ [/already reopened/, "This ask was already reopened."],
2749
+ [/unrecognised decision/, "That answer is not recognised."],
2750
+ [/no readable artifact/, "There is no draft to accept."],
2751
+ [/no open ask|is unknown for run/, "This ask is no longer open."],
2752
+ [/nothing was reopened/, "Could not clear the late answer; nothing was reopened."],
2753
+ [/could not write|set aside/, "Your answer could not be saved. Nothing was changed."]
2754
+ ];
2755
+ var b = r && r.body;
2756
+ var name = b && typeof b.refused === "string" ? b.refused : "";
2757
+ var red = b && typeof b.red === "string" ? b.red : "";
2758
+ if(Object.prototype.hasOwnProperty.call(byName, name)) return byName[name];
2759
+ for(var i = 0; i < byWords.length; i++){
2760
+ if(byWords[i][0].test(red)) return byWords[i][1] === null ? blankReasonText(decision) : byWords[i][1];
2761
+ }
2762
+ return "That did not go through. Reload the page to see where this run stands.";
2532
2763
  }
2533
2764
  // While a POST is out the buttons are disabled (stops a double click) — nothing else is ever disabled.
2534
2765
  function setBusy(root, busy){
@@ -2539,6 +2770,12 @@
2539
2770
  function sendAnswer(root, ask, ctx, decision){
2540
2771
  var ta = root.querySelector("textarea");
2541
2772
  var payload = { flow: ctx.flow, runId: ctx.runId, askId: ask.askId, decision: decision, reason: ta ? ta.value : "" };
2773
+ var hintEl = root.querySelector("[data-testid='reason-hint']");
2774
+ if(hintEl){ hintEl.hidden = true; hintEl.textContent = ""; }
2775
+ if(reasonMissing(decision, payload.reason)){
2776
+ if(hintEl){ hintEl.textContent = blankReasonText(decision); hintEl.hidden = false; }
2777
+ return;
2778
+ }
2542
2779
  say(ctx.flow, ctx.runId, "info", "sending " + decision + "…");
2543
2780
  setBusy(root, true);
2544
2781
  postJSON("/api/answer", payload).then(function(r){
@@ -2546,29 +2783,67 @@
2546
2783
  delete reasonDrafts[ask.askId];
2547
2784
  pendingAnswer = { flow: ctx.flow, runId: ctx.runId, askId: ask.askId, decision: decision, draftNo: ctx.draftNo };
2548
2785
  answerMsg = null; paintAnswerMsg();
2786
+ // a broken earlier answer was moved aside to make room: say so, once
2787
+ if(r.body.setAside) say(ctx.flow, ctx.runId, "info", "your earlier saved answer was broken; it is kept aside. This answer is saved.");
2549
2788
  startLive(ctx.flow, ctx.runId, ask.askId);
2550
2789
  } else {
2551
- say(ctx.flow, ctx.runId, "refused", refusalText(r));
2790
+ say(ctx.flow, ctx.runId, "refused", refusalText(r, decision));
2552
2791
  }
2553
2792
  return reloadRun(ctx.flow, ctx.runId);
2554
2793
  }).catch(function(e){
2555
- say(ctx.flow, ctx.runId, "refused", "network failure: " + e.message + " — nothing is confirmed; what the books say is shown in the ask header above");
2794
+ say(ctx.flow, ctx.runId, "refused", networkText());
2556
2795
  return reloadRun(ctx.flow, ctx.runId);
2557
2796
  }).then(function(){ if(root.isConnected) setBusy(root, false); });
2558
2797
  }
2559
2798
  function sendResumeAgain(root, ctx, askId){
2560
- say(ctx.flow, ctx.runId, "info", "asking for the resume again…");
2799
+ say(ctx.flow, ctx.runId, "info", "continuing the run…");
2561
2800
  setBusy(root, true);
2562
2801
  postJSON("/api/resume", { flow: ctx.flow, runId: ctx.runId }).then(function(r){
2563
2802
  if(r.status === 202 && r.body && r.body.ok){
2564
- say(ctx.flow, ctx.runId, "info", "resume requested — waiting for the run's books to show whether it took over");
2803
+ say(ctx.flow, ctx.runId, "info", "asked the run to continue — waiting to see that it picked up your answer");
2565
2804
  startLive(ctx.flow, ctx.runId, askId);
2566
2805
  } else {
2567
2806
  say(ctx.flow, ctx.runId, "refused", refusalText(r));
2568
2807
  }
2569
2808
  return reloadRun(ctx.flow, ctx.runId);
2570
2809
  }).catch(function(e){
2571
- say(ctx.flow, ctx.runId, "refused", "network failure: " + e.message + " — nothing is confirmed; what the books say is shown in the ask header above");
2810
+ say(ctx.flow, ctx.runId, "refused", networkText());
2811
+ return reloadRun(ctx.flow, ctx.runId);
2812
+ }).then(function(){ if(root.isConnected) setBusy(root, false); });
2813
+ }
2814
+ // M4c-fix amendment 2 (h): the human's one button for a lock with no recorded holder. One confirm, then a gated POST;
2815
+ // the server re-checks the lock at that moment, removes it, records it in the audit and continues the run. Cancel = nothing.
2816
+ var REMOVE_LOCK_CONFIRM = "Only do this if nothing else is working on this run. Remove it?";
2817
+ function sendRemoveLock(root, ctx, askId){
2818
+ if(!window.confirm(REMOVE_LOCK_CONFIRM)) return;
2819
+ say(ctx.flow, ctx.runId, "info", "removing the old lock…");
2820
+ setBusy(root, true);
2821
+ postJSON("/api/remove-lock", { flow: ctx.flow, runId: ctx.runId }).then(function(r){
2822
+ if(r.status === 202 && r.body && r.body.ok){
2823
+ say(ctx.flow, ctx.runId, "info", "old lock removed; asked the run to continue — waiting to see that it picked up your answer");
2824
+ startLive(ctx.flow, ctx.runId, askId);
2825
+ } else {
2826
+ say(ctx.flow, ctx.runId, "refused", refusalText(r));
2827
+ }
2828
+ return reloadRun(ctx.flow, ctx.runId);
2829
+ }).catch(function(e){
2830
+ say(ctx.flow, ctx.runId, "refused", networkText());
2831
+ return reloadRun(ctx.flow, ctx.runId);
2832
+ }).then(function(){ if(root.isConnected) setBusy(root, false); });
2833
+ }
2834
+ function sendReopen(root, ctx, askId){
2835
+ say(ctx.flow, ctx.runId, "info", "reopening…");
2836
+ setBusy(root, true);
2837
+ postJSON("/api/reopen", { flow: ctx.flow, runId: ctx.runId, askId: askId }).then(function(r){
2838
+ if(r.status === 200 && r.body && r.body.ok){
2839
+ say(ctx.flow, ctx.runId, "info", "reopened until " + (readableDateTime(r.body.expiresAt) || r.body.expiresAt)
2840
+ + (r.body.setAside ? "; your late answer is kept aside" : ""));
2841
+ } else {
2842
+ say(ctx.flow, ctx.runId, "refused", refusalText(r));
2843
+ }
2844
+ return reloadRun(ctx.flow, ctx.runId);
2845
+ }).catch(function(e){
2846
+ say(ctx.flow, ctx.runId, "refused", networkText());
2572
2847
  return reloadRun(ctx.flow, ctx.runId);
2573
2848
  }).then(function(){ if(root.isConnected) setBusy(root, false); });
2574
2849
  }
@@ -2587,6 +2862,11 @@
2587
2862
  root.className = "answer-doors";
2588
2863
  root.setAttribute("data-testid", "answer-doors");
2589
2864
  if(model.kind === "doors"){
2865
+ if(model.note){
2866
+ var note = textDiv("answer-msg refused", model.note);
2867
+ note.setAttribute("data-testid", "answer-note");
2868
+ root.appendChild(note);
2869
+ }
2590
2870
  var idSafe = "reason-" + String(ask.askId).replace(/[^A-Za-z0-9_-]/g, "_");
2591
2871
  var lab = document.createElement("label");
2592
2872
  lab.setAttribute("for", idSafe);
@@ -2597,9 +2877,14 @@
2597
2877
  ta.setAttribute("data-testid", "answer-reason");
2598
2878
  ta.setAttribute("data-askid", ask.askId);
2599
2879
  ta.value = reasonDrafts[ask.askId] || "";
2600
- ta.addEventListener("input", function(){ reasonDrafts[ask.askId] = ta.value; });
2880
+ ta.addEventListener("input", function(){ reasonDrafts[ask.askId] = ta.value; reasonHint.hidden = true; });
2601
2881
  root.appendChild(lab);
2602
2882
  root.appendChild(ta);
2883
+ // shown next to the box when a redo or rerun is clicked with no reason (page-side check, before anything is sent)
2884
+ var reasonHint = textDiv("answer-msg refused", "");
2885
+ reasonHint.hidden = true;
2886
+ reasonHint.setAttribute("data-testid", "reason-hint");
2887
+ root.appendChild(reasonHint);
2603
2888
  var bar = document.createElement("div");
2604
2889
  bar.className = "actions-row";
2605
2890
  bar.setAttribute("data-testid", "action-bar");
@@ -2618,15 +2903,28 @@
2618
2903
  wk.appendChild(document.createTextNode(model.text));
2619
2904
  root.appendChild(wk);
2620
2905
  } else if(model.kind === "starting"){
2621
- root.appendChild(textDiv("hint", model.label + " — " + model.why));
2906
+ root.appendChild(textDiv("hint", model.text));
2907
+ } else if(model.kind === "expired"){
2908
+ // [!] expired: the time ran out. One button, the human's: a fresh window of the same signed length on the same draft.
2909
+ var bar3 = document.createElement("div");
2910
+ bar3.className = "actions-row";
2911
+ bar3.appendChild(makeButton("Reopen for another " + waitText(model.waitMs), "btn-reopen", function(){ sendReopen(root, ctx, ask.askId); }));
2912
+ root.appendChild(bar3);
2913
+ root.appendChild(textDiv("hint", model.line));
2622
2914
  } else if(model.kind === "stuck"){
2623
- root.appendChild(textDiv("answer-msg stuck", model.label + ": " + model.reason));
2624
- if(model.lockPath) root.appendChild(textDiv("hint", "lock file: " + model.lockPath));
2625
- root.appendChild(textDiv("hint", model.why + ". Trying again starts a resume only; it cannot answer."));
2915
+ // stuck: an answer is saved and no resume took it. One button, one line under it saying why.
2626
2916
  var bar2 = document.createElement("div");
2627
2917
  bar2.className = "actions-row";
2628
- bar2.appendChild(makeButton("Try the resume again", "btn-resume-again", function(){ sendResumeAgain(root, ctx, ask.askId); }));
2918
+ if(model.lockPath){
2919
+ // the lock has no recorded holder, so "Continue the run" could only be refused: the one button removes it, then continues
2920
+ bar2.appendChild(makeButton("Remove the old lock", "btn-remove-lock", function(){ sendRemoveLock(root, ctx, ask.askId); }));
2921
+ } else {
2922
+ bar2.appendChild(makeButton("Continue the run", "btn-resume-again", function(){ sendResumeAgain(root, ctx, ask.askId); }));
2923
+ }
2629
2924
  root.appendChild(bar2);
2925
+ root.appendChild(textDiv("hint", model.lockPath
2926
+ ? "An old resume lock is in the way."
2927
+ : "Your answer is saved; the run stopped before using it."));
2630
2928
  } else {
2631
2929
  root.appendChild(textDiv("hint", model.why));
2632
2930
  }
@@ -2702,9 +3000,10 @@
2702
3000
  // never re-derived here), when it was asked, and its status. `stepWhy` is
2703
3001
  // shown verbatim (never a guessed step name) when the books can't name
2704
3002
  // one — the honest word "before" a real value never invents.
2705
- function blockMetaText(block){
3003
+ function blockMetaText(block, ctx){
2706
3004
  var ask = block.current;
2707
- var bits = [];
3005
+ // every ask says which run it belongs to: the buttons below act on THIS run only
3006
+ var bits = [ctx.flow + " (" + ctx.runId + ")"];
2708
3007
  var stepBit = typeof block.stepName === "string" && block.stepName.length > 0
2709
3008
  ? block.stepName + (typeof block.stepLine === "number" ? " (line " + block.stepLine + ")" : "")
2710
3009
  : (ask.stepWhy || "step not determinable");
@@ -2738,7 +3037,7 @@
2738
3037
  badge.textContent = ask.open ? "·" : ask.status;
2739
3038
  }
2740
3039
  metaLine.appendChild(badge);
2741
- metaLine.appendChild(textDiv("wf-meta", blockMetaText(block)));
3040
+ metaLine.appendChild(textDiv("wf-meta", blockMetaText(block, ctx)));
2742
3041
  head.appendChild(metaLine);
2743
3042
  // The question itself — a real, bold heading (review #3: "the question
2744
3043
  // as a clear heading"), never folded into the same small meta line.
@@ -2772,7 +3071,7 @@
2772
3071
  function renderAsk(result, focusAskId, loadError){
2773
3072
  var empty = document.getElementById("ask-empty");
2774
3073
  var list = document.getElementById("ask-list");
2775
- if(loadError){ empty.hidden = false; empty.textContent = "failed to load asks: " + loadError; list.hidden = true; list.innerHTML = ""; return true; }
3074
+ if(loadError){ empty.hidden = false; empty.textContent = loadError; list.hidden = true; list.innerHTML = ""; return true; }
2776
3075
  if(!result){ empty.hidden = false; empty.textContent = "select a run first"; list.hidden = true; list.innerHTML = ""; return true; }
2777
3076
  var blocks = result.blocks || [];
2778
3077
  if(!blocks.length){