fwdloop 0.9.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;}
@@ -153,6 +154,26 @@
153
154
  arrow [▶], which this reserves for "running" alone. Its own class so
154
155
  the two states never share a ::before rule. */
155
156
  .dot.expired::before{content:"[!]";color:var(--amber);}
157
+ /* M4c amendment 2: stuck — answer saved, nobody carrying the run on. Its own glyph,
158
+ amber like the other "needs you" signs; it pulses (server-decided, glyphPulses). */
159
+ .dot.stuck::before{content:"[II]";color:var(--amber);}
160
+ /* M4c: only the two "alive" signs pulse — [▶] running and [·] waiting on
161
+ you — keyed to `.pulse`, which the server decides (glyphPulses), never to
162
+ a colour class (.grey is also the placeholder dot). A gentle opacity wave on the existing colors;
163
+ reduced-motion keeps the sign and drops only the animation. */
164
+ @keyframes signPulse{0%,100%{opacity:1;}50%{opacity:.35;}}
165
+ .dot.pulse::before{animation:signPulse 1.6s ease-in-out infinite;}
166
+ @media (prefers-reduced-motion: reduce){
167
+ .dot.pulse::before{animation:none;}
168
+ }
169
+
170
+ /* M4c inbox: section 1 (waiting on you) carries the page's amber accent
171
+ treatment; section 3 (answered/expired) is dimmed. Tokens only. */
172
+ .inbox-h{font-size:12px;color:var(--text-dim);font-weight:700;margin:12px 0 6px;}
173
+ .inbox-h:first-child{margin-top:0;}
174
+ .inbox-row.s1{border-left:4px solid var(--amber);background:var(--amber-bg);}
175
+ .inbox-row.s3{opacity:.6;}
176
+ .inbox-row .wf-line1{min-width:0;}
156
177
 
157
178
  .badge{display:inline-block;font-size:11px;padding:1px 4px;color:var(--text-dim);background:none;font-weight:700;}
158
179
  .badge::before{content:"[";color:var(--text-faint);}
@@ -178,6 +199,8 @@
178
199
  .answer-doors textarea{display:block;width:100%;max-width:100%;box-sizing:border-box;min-height:64px;padding:6px 8px;font:inherit;color:var(--text);background:var(--bg);border:1px solid var(--border-strong);resize:vertical;}
179
200
  .answer-doors .actions-row{display:flex;flex-wrap:wrap;gap:8px;margin-top:8px;}
180
201
  .answer-doors .btn{min-width:44px;}
202
+ .working-line{margin-top:4px;font-size:13px;color:var(--text);overflow-wrap:anywhere;}
203
+ .answer-line{font-size:13px;color:var(--text-dim);margin:2px 0;white-space:pre-wrap;overflow-wrap:anywhere;word-break:break-word;}
181
204
  .answer-msg{margin-top:8px;padding:6px 8px;border:1px solid var(--border-strong);font-size:13px;color:var(--text);white-space:pre-wrap;word-break:break-word;overflow-wrap:anywhere;}
182
205
  .answer-msg.refused{border-color:var(--red);}
183
206
  .answer-msg.refused::before{content:"refused: ";color:var(--red);font-weight:700;}
@@ -203,6 +226,10 @@
203
226
  applies everywhere, so this wraps onto more lines instead of clipping,
204
227
  the same behavior fix #7 already gave phone width alone. */
205
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;}
206
233
  .wf-meta{font-size:12px;color:var(--text-dim);}
207
234
  .wf-meta + .wf-meta::before{content:" · ";color:var(--text-faint);}
208
235
  .wf-row.selected,.hist-row.selected{border:2px solid var(--accent);border-radius:4px;}
@@ -216,10 +243,19 @@
216
243
  .wf-runs .hist-row{margin-bottom:4px;}
217
244
 
218
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;}
219
- .rp-header h2{margin:0;font-size:15px;}
220
- .rp-header h2::before{content:"┤ ";color:var(--text-faint);}
221
- .rp-header h2::after{content:" ├";color:var(--text-faint);}
222
- .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
+ }
223
259
  /* item 4: phone-only jump-back link — hidden on desktop (the two panes
224
260
  are already both on screen there, nothing to jump back to). */
225
261
  .back-to-list-link{display:none;font-size:12px;color:var(--accent);text-decoration:underline;background:none;border:none;padding:0;cursor:pointer;}
@@ -251,16 +287,16 @@
251
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;}
252
288
  .map-box::before{content:"┤ MAP ├";display:block;font-size:11px;color:var(--text-faint);letter-spacing:0.08em;margin:-2px 0 8px 0;}
253
289
  .map-box svg{display:block;max-width:100%;height:auto;margin:0 auto;}
254
- .map-legend{display:flex;gap:14px;font-size:11px;color:var(--text-dim);margin-top:6px;flex-wrap:wrap;}
255
290
 
256
291
  .step-card{position:relative;border:1px solid var(--border);padding:10px;margin-bottom:8px;background:var(--panel2);}
257
292
  .step-card.running{border:1px double var(--amber);}
258
- /* hamr's 2026-09-27 styling ruling: the card's HEADER line (number, step
259
- name, state chip, close-class chip) is upper case and bold; the state/
260
- close chips keep their own color from `.badge`'s existing classes —
261
- text-transform never touches color. */
262
- .step-card .step-head{display:flex;align-items:center;justify-content:space-between;gap:8px;flex-wrap:wrap;text-transform:uppercase;font-weight:700;}
263
- .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;}
264
300
  /* Every OTHER line on the card (goal, actions, granted, stopped reason) —
265
301
  lower case exactly as the data reads, normal weight; never inherits the
266
302
  header's uppercase/bold (same ruling, the non-header half of it). */
@@ -314,6 +350,30 @@
314
350
  `.audit-group h4` (0,1,1) and `.ask-question-heading` (0,1,0) alone, so
315
351
  this never un-bolds the ask question heading. */
316
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;}
317
377
  /* hamr's 2026-09-27 review: the group header's own state word (g.state,
318
378
  rendered as a <span class="badge STATE">) and its per-try marks
319
379
  (<span class="mark STATE">) reuse the SAME color vocabulary the runs
@@ -342,8 +402,8 @@
342
402
  ("resume-text"/"jd-text" etc.), never the faint `.hint` style. */
343
403
  .evidence-heading{font-size:11px;font-weight:700;color:var(--text-dim);margin:8px 0 3px;text-transform:uppercase;letter-spacing:0.04em;}
344
404
  .evidence-heading:first-child{margin-top:0;}
345
- /* review #3: the ask's own question, a real heading under the "Ask i of
346
- n · step · asked · status" meta line — reuses the box-drawing h4 look
405
+ /* review #3: the ask's own question, a real heading under the "step ·
406
+ draft N · asked · status" meta line — reuses the box-drawing h4 look
347
407
  the Audit/Job group headers already use, but inline (no absolute
348
408
  ┤ ├ pips — those are reserved for a whole-box title, not an in-flow
349
409
  line) so it reads as a clear, bold heading without a second border. */
@@ -379,28 +439,52 @@
379
439
  `buildAuditRowEl` already sets on every cell (never a second, separate
380
440
  label list to keep in sync). No horizontal scroll is possible once
381
441
  every cell is a full-width block. */
382
- @media (max-width: 480px){
383
- [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%;}
384
453
  [data-testid="audit-table"] thead, .audit-group table thead{
385
454
  position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap;
386
455
  }
387
456
  [data-testid="audit-table"] tbody, .audit-group table tbody{display:block;}
388
457
  [data-testid="audit-table"] tr, .audit-group table tr{
389
- 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;
390
459
  }
391
460
  [data-testid="audit-table"] td, .audit-group table td{
392
- display:block;border:none;border-bottom:1px dotted var(--border);padding:4px 8px;
393
- /* fix (2026-09-28): a pre-M4a-2 row's Time cell shows the longer
394
- `atWhy` text ("not recorded (before M4a-2)") instead of a
395
- timestamp — overflow-wrap:anywhere (on top of the existing
396
- break-word/word-break) makes sure that text wraps inside the
397
- cell's own border at 390px instead of spilling past it. */
398
- 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;
399
462
  }
400
- [data-testid="audit-table"] td:last-child, .audit-group table td:last-child{border-bottom:none;}
401
- [data-testid="audit-table"] td::before, .audit-group table td::before{
402
- 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);
403
485
  }
486
+ td.am-detail .am-d{margin:0 0 3px;}
487
+ td.am-detail .am-d b{color:var(--text);font-weight:600;}
404
488
  }
405
489
  </style>
406
490
  </head>
@@ -425,10 +509,10 @@
425
509
  <div class="tabrow" role="tablist" aria-label="Left panel views">
426
510
  <button role="tab" id="tab-chat" aria-controls="panel-chat" aria-selected="true" data-testid="left-tab-chat">Chat</button>
427
511
  <button role="tab" id="tab-runs" aria-controls="panel-runs" aria-selected="false" data-testid="left-tab-runs">Runs</button>
428
- <button role="tab" id="tab-inbox" aria-controls="panel-inbox" aria-selected="false" data-testid="left-tab-inbox">Inbox<span id="inbox-count-label"></span></button>
512
+ <button role="tab" id="tab-inbox" aria-controls="panel-inbox" aria-selected="false" data-testid="left-tab-inbox">Inbox<span id="inbox-count-label"> (0)</span></button>
429
513
  </div>
430
514
 
431
- <div class="pane-body">
515
+ <div class="pane-body" id="left-pane-body">
432
516
 
433
517
  <section id="panel-chat" class="tabpanel active" role="tabpanel" aria-labelledby="tab-chat">
434
518
  <div class="chat-thread">
@@ -469,10 +553,10 @@
469
553
  <div class="rp-header">
470
554
  <button type="button" class="back-to-list-link" id="back-to-list" data-testid="back-to-list">&#8593; list</button>
471
555
  <div class="rp-header-title">
472
- <span class="dot grey" id="active-wf-dot"></span>
473
- <h2 id="active-wf-name">(none selected)</h2>
474
- <span class="badge" id="active-wf-verdict">—</span>
475
- <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>
476
560
  </div>
477
561
  </div>
478
562
 
@@ -483,7 +567,7 @@
483
567
  <button role="tab" id="tab-ask" aria-controls="panel-ask" aria-selected="false" data-testid="right-tab-ask">Ask</button>
484
568
  </div>
485
569
 
486
- <div class="pane-body">
570
+ <div class="pane-body" id="right-pane-body">
487
571
 
488
572
  <section id="panel-run" class="tabpanel active" role="tabpanel" aria-labelledby="tab-run">
489
573
  <div id="run-empty" class="hint" style="font-size:13px;padding:24px 0;">select a run from Workflows or History</div>
@@ -595,9 +679,8 @@
595
679
  "use strict";
596
680
 
597
681
  var PORT = "__FWDLOOP_PANEL_PORT__";
598
- // M4b piece 1: per-process answer token, replaced at serve time; sent only as
599
- // the x-fwdloop-token header of the two POSTs (postJSON below).
600
- 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.
601
684
  document.getElementById("host-line").textContent = "127.0.0.1:" + PORT;
602
685
 
603
686
  function wireTabs(tabButtons){
@@ -620,20 +703,28 @@
620
703
 
621
704
  // ---- fetch helpers. Reads are GET. The ONLY non-GET requests on this page are
622
705
  // the two POSTs below (M4b): /api/answer (a human clicking a door) and
623
- // /api/resume ("try the resume again"). The token goes in the request header
624
- // 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. ----
625
708
  function getJSON(path){
626
709
  return fetch(path, { method: "GET", headers: { accept: "application/json" } }).then(function(r){
627
- 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; }
628
711
  return r.json();
629
712
  });
630
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
+ }
631
722
  // Resolves { status, body } for ANY HTTP status (a refusal is data to show by
632
723
  // name, never an exception); rejects only on a network failure.
633
724
  function postJSON(path, payload){
634
725
  return fetch(path, {
635
726
  method: "POST",
636
- headers: { "content-type": "application/json", accept: "application/json", "x-fwdloop-token": TOKEN },
727
+ headers: { "content-type": "application/json", accept: "application/json" },
637
728
  body: JSON.stringify(payload),
638
729
  credentials: "same-origin"
639
730
  }).then(function(r){
@@ -696,6 +787,12 @@
696
787
  var short = d.toLocaleTimeString();
697
788
  return '<span title="' + escapeXml(full) + '">' + escapeXml(short) + '</span>';
698
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
+ }
699
796
  function duration(ms){
700
797
  if(typeof ms !== "number" || ms < 0) return "unknown";
701
798
  var s = ms / 1000;
@@ -704,6 +801,14 @@
704
801
  if(rem === 60){ m += 1; rem = 0; }
705
802
  return m + "m" + String(rem).padStart(2, "0") + "s";
706
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
+ }
707
812
  // A readable local date/time instead of a raw ISO timestamp (fix #5) — an
708
813
  // unparseable value still shows the raw string (never blank/nothing), so
709
814
  // a books bug is visible rather than silently swallowed.
@@ -719,10 +824,14 @@
719
824
  // parked on a human) reads "waiting on you", matching the SAME words the
720
825
  // run-row `[·]` glyph already uses (src/panel/data.js's computeGlyph) —
721
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]" };
722
831
  function stateWord(state){
723
832
  if(state === "pending") return "not started";
724
- if(state === "waiting") return "waiting on you";
725
- return state; // "done" / "stopped"
833
+ var g = STEP_SIGN[state];
834
+ return g && signWords[g] ? g + " " + signWords[g] : state;
726
835
  }
727
836
  // fwdloop's close-class vocabulary (M4a scope item 4): `green` -> "cited"
728
837
  // (a mechanical, exact-match close), `softgreen` -> "shape" (a shape/
@@ -783,6 +892,8 @@
783
892
  if(verdict === "paused") return "paused for you";
784
893
  if(verdict === "refused") return "refused — no reason given";
785
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";
786
897
  if(verdict === "green") return "passed";
787
898
  if(verdict === "hitl") return "human check";
788
899
  if(verdict === "not-done") return "not done";
@@ -795,12 +906,21 @@
795
906
  // would misread a pause as a failure (fix #3).
796
907
  function verdictGlyph(verdict, closeClass){
797
908
  if(closeClass === "hitl" && verdict === "red") return null;
798
- 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;
799
910
  return verdictPassed(verdict) ? "✓" : "✗";
800
911
  }
801
912
  // The run-row glyph strings src/panel/data.js's computeGlyph emits are
802
- // already bracketed ("[✓]", "[✗]", "[·]", "[?]") — this only ever picks a
913
+ // already bracketed ("[✓]", "[✗]", "[·]", "[▶]", "[?]") — this only ever picks a
803
914
  // CSS color class off them, never re-derives the glyph itself.
915
+ // the dot's class list: colour from the glyph, `pulse` only when the server
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
+ }
923
+ function dotClass(g, pulse){ return "dot " + glyphClass(g) + (pulse ? " pulse" : ""); }
804
924
  function glyphClass(g){
805
925
  if(g === "[✓]") return "green";
806
926
  if(g === "[✗]") return "red";
@@ -813,6 +933,7 @@
813
933
  // "running", but a different glyph, so it gets its own dot class
814
934
  // (never "amber", which draws the reserved running arrow [▶]).
815
935
  if(g === "[!]") return "expired";
936
+ if(g === "[II]") return "stuck";
816
937
  return "grey"; // "[·]" — waiting on a human, or answered-not-resumed
817
938
  }
818
939
 
@@ -930,8 +1051,16 @@
930
1051
  }
931
1052
  return {perRow:1, boxW:Math.max(MIN_BOX_W, Math.min(usableW, ceiling))};
932
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
+ }
933
1059
  function wrapTitleLines(text, maxWidth){
934
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){
935
1064
  if(text.length <= maxChars) return [text];
936
1065
  var words = text.split(' ');
937
1066
  var line1 = '', i = 0;
@@ -982,7 +1111,7 @@
982
1111
  // into a jump to the Audit tab's matching group is wired AFTER
983
1112
  // insertion (renderStepMap, below), never inline here (this function
984
1113
  // only ever builds a markup string).
985
- 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>';
986
1115
  body += '<rect x="' + x + '" y="' + y + '" width="' + boxW + '" height="' + boxH +
987
1116
  '" rx="0" fill="var(--panel2)" stroke="' + colors.stroke + '" stroke-width="2"></rect>';
988
1117
  if(lines.length === 1){
@@ -1038,21 +1167,6 @@
1038
1167
  });
1039
1168
  return '<svg width="' + totalW + '" height="' + totalH + '" viewBox="0 0 ' + totalW + ' ' + totalH + '" role="img" aria-label="step map">' + body + '</svg>';
1040
1169
  }
1041
- // Legend glyphs match the scope's own vocabulary (fix #4): `[✓]` done,
1042
- // `[✗]` stopped, `[·]` waiting on you (the default/grey dot — never the
1043
- // amber `[▶]`, which the scope reserves for "running", a state this panel
1044
- // cannot tell apart from "died" at all today — M4a's own open POC
1045
- // question). "not started" gets no dot/glyph at all, so it can never be
1046
- // confused with a reserved one.
1047
- function stepMapLegendHTML(){
1048
- return '<div class="map-legend">' +
1049
- '<span><span class="dot green"></span>done</span>' +
1050
- '<span><span class="dot red"></span>stopped</span>' +
1051
- '<span><span class="dot"></span>waiting on you</span>' +
1052
- '<span>not started</span>' +
1053
- '<span>⤾ dashed = retry</span>' +
1054
- '</div>';
1055
- }
1056
1170
  var lastSteps = null;
1057
1171
  var lastWidth = null;
1058
1172
  function mapAvailWidth(wrapper){
@@ -1086,7 +1200,7 @@
1086
1200
  wrapper.hidden = false;
1087
1201
  var w = mapAvailWidth(wrapper);
1088
1202
  lastWidth = w;
1089
- mount.innerHTML = buildStepMapSVG(steps, w) + stepMapLegendHTML();
1203
+ mount.innerHTML = buildStepMapSVG(steps, w);
1090
1204
  wireMapClicks(mount);
1091
1205
  }
1092
1206
  function reflowMap(){
@@ -1096,7 +1210,7 @@
1096
1210
  if(w === null || w === lastWidth) return;
1097
1211
  lastWidth = w;
1098
1212
  var mount = document.getElementById("map-mount");
1099
- mount.innerHTML = buildStepMapSVG(lastSteps, w) + stepMapLegendHTML();
1213
+ mount.innerHTML = buildStepMapSVG(lastSteps, w);
1100
1214
  wireMapClicks(mount);
1101
1215
  }
1102
1216
  if(typeof ResizeObserver !== "undefined"){
@@ -1137,18 +1251,49 @@
1137
1251
  return row;
1138
1252
  }
1139
1253
  row.innerHTML =
1140
- '<span class="wf-line1"><span class="dot ' + glyphClass(r.glyph) + '"></span>' +
1254
+ '<span class="wf-line1"><span class="' + dotClass(r.glyph, r.pulse) + '"></span>' +
1141
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>' +
1142
1257
  '<span class="wf-meta-line">' +
1143
- '<span class="wf-meta">' + escapeXml(r.label || "unknown") + '</span>' +
1144
- '<span class="wf-meta">' + escapeXml(r.spend || r.spendWhy || "unknown") + '</span>' +
1145
- '<span class="wf-meta">' + escapeXml(r.at ? r.at.slice(0,10) : (r.askedAt ? "asked " + readableDateTime(r.askedAt) : (r.atWhy || "unknown"))) + '</span>' +
1258
+ '<span class="wf-meta">' + escapeXml(runSpendText(r)) + '</span>' +
1259
+ '<span class="wf-meta">' + escapeXml(runAtText(r)) + '</span>' +
1146
1260
  '</span>';
1147
- row.addEventListener("click", function(){ selectRun(r.flow, r.runId, row, ".hist-row"); document.getElementById("tab-run").click(); scrollRunIntoViewMobile(); });
1261
+ row.addEventListener("click", function(){ openRunFromRuns(r, row); });
1148
1262
  row.addEventListener("keydown", function(e){ if(e.key === "Enter" || e.key === " "){ e.preventDefault(); row.click(); } });
1149
1263
  return row;
1150
1264
  }
1151
1265
 
1266
+ // M4c amendment 1 (a): the ONE place a click on a run in Runs decides where it lands.
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
+ }
1279
+ function openRunFromRuns(r, rowEl){
1280
+ selectRun(r.flow, r.runId, rowEl, ".hist-row");
1281
+ document.getElementById("tab-run").click();
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 */ });
1295
+ }
1296
+
1152
1297
  // ---- History view: every row exactly as /api/runs returned it. ----
1153
1298
  function renderHistory(runs){
1154
1299
  var el = document.getElementById("history-list");
@@ -1163,6 +1308,14 @@
1163
1308
  // ---- Workflows view: groups the ONE /api/runs payload by flow name
1164
1309
  // client-side. Runs arrive newest-first within a flow (server contract,
1165
1310
  // listRuns), so the first run seen for a flow is its latest.
1311
+ // The words for a run row's spend and time cells — the Workflows card (a flow's latest run) and
1312
+ // every History/expanded row say the same thing, from the same server fields.
1313
+ function runSpendText(r){
1314
+ return r.spend || r.spendWhy || "unknown";
1315
+ }
1316
+ function runAtText(r){
1317
+ return r.at ? r.at.slice(0,10) : (r.askedAt ? "asked " + readableDateTime(r.askedAt) : (r.startedAt ? "started " + readableDateTime(r.startedAt) : (r.atWhy || "unknown")));
1318
+ }
1166
1319
  function groupRunsByFlow(runs){
1167
1320
  var byFlow = {};
1168
1321
  var order = [];
@@ -1178,10 +1331,8 @@
1178
1331
  runs: flowRuns,
1179
1332
  runCount: last.runId === null ? 0 : flowRuns.length,
1180
1333
  lastRunId: last.runId,
1181
- lastAt: last.at,
1182
1334
  lastGlyph: last.glyph,
1183
1335
  lastLabel: last.label,
1184
- lastSpend: last.spend,
1185
1336
  lastRow: last,
1186
1337
  };
1187
1338
  });
@@ -1285,21 +1436,19 @@
1285
1436
  row.setAttribute("aria-pressed", isSelected ? "true" : "false");
1286
1437
  var wfFullName = g.flow + ' (' + g.lastRunId + ')';
1287
1438
  row.innerHTML =
1288
- '<span class="wf-line1"><span class="wf-caret">' + (hasOtherRuns ? (expanded ? "▼" : "▶") : "") + '</span><span class="dot ' + glyphClass(g.lastGlyph) + '"></span>' +
1439
+ '<span class="wf-line1"><span class="wf-caret">' + (hasOtherRuns ? (expanded ? "▼" : "▶") : "") + '</span><span class="' + dotClass(g.lastGlyph, g.lastRow.pulse) + '"></span>' +
1289
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>' +
1290
1442
  '<span class="wf-meta-line">' +
1291
- '<span class="wf-meta">' + escapeXml(g.lastLabel || "unknown") + '</span>' +
1292
- '<span class="wf-meta">' + escapeXml(g.lastSpend || "unknown") + '</span>' +
1293
- '<span class="wf-meta">' + escapeXml(g.lastAt ? g.lastAt.slice(0,10) : "unknown") + '</span>' +
1443
+ '<span class="wf-meta">' + escapeXml(runSpendText(g.lastRow)) + '</span>' +
1444
+ '<span class="wf-meta">' + escapeXml(runAtText(g.lastRow)) + '</span>' +
1294
1445
  '<span class="wf-meta">' + g.runCount + ' run' + (g.runCount === 1 ? '' : 's') + '</span>' +
1295
1446
  '</span>';
1296
1447
  row.addEventListener("click", function(){
1297
1448
  // a single-run flow has nothing to expand — the click still opens
1298
1449
  // the run, it just never toggles `wfExpanded` for it.
1299
1450
  if(hasOtherRuns) wfExpanded[g.flow] = !expanded;
1300
- selectRun(g.flow, targetRunId, null, ".hist-row");
1301
- document.getElementById("tab-run").click();
1302
- scrollRunIntoViewMobile();
1451
+ openRunFromRuns(g.runs.filter(function(x){ return x.runId === targetRunId; })[0] || g.lastRow, null);
1303
1452
  renderWorkflows(flows);
1304
1453
  });
1305
1454
  row.addEventListener("keydown", function(e){ if(e.key === "Enter" || e.key === " "){ e.preventDefault(); row.click(); } });
@@ -1320,9 +1469,8 @@
1320
1469
  // the Workflows tab (filters by each flow's OWN latest-run fields).
1321
1470
  // bareloop's checkType (deterministic/rubric) chips are dropped — fwdloop
1322
1471
  // has no such concept; the result chips use fwdloop's own glyph
1323
- // vocabulary ([✓]/[✗]/[·]/[?] — `[▶]` never appears from listRuns today,
1324
- // see docs/wiki/the-module-ladder.md's M4a open POC question, so no chip
1325
- // for a state the books can't produce).
1472
+ // vocabulary ([✓]/[✗]/[·]/[▶]/[?] — `[▶]` running is known from M4c's pid
1473
+ // rows, src/liveness.js).
1326
1474
  function filterBarHTML(scope){
1327
1475
  return (
1328
1476
  '<div class="filterbar" data-scope="' + scope + '" data-testid="' + scope + '-filters">' +
@@ -1332,7 +1480,8 @@
1332
1480
  '<button class="chip fchip" type="button" aria-pressed="false" data-filter-group="result" data-filter-value="[✓]" title="passed" data-testid="chip-' + scope + '-res-pass">✓</button>' +
1333
1481
  '<button class="chip fchip" type="button" aria-pressed="false" data-filter-group="result" data-filter-value="[✗]" title="stopped" data-testid="chip-' + scope + '-res-fail">✗</button>' +
1334
1482
  '<button class="chip fchip" type="button" aria-pressed="false" data-filter-group="result" data-filter-value="[·]" title="waiting on a human" data-testid="chip-' + scope + '-res-waiting">&middot;</button>' +
1335
- '<button class="chip fchip" type="button" aria-pressed="false" data-filter-group="result" data-filter-value="[?]" title="running or died: unknown" data-testid="chip-' + scope + '-res-unknown">?</button>' +
1483
+ '<button class="chip fchip" type="button" aria-pressed="false" data-filter-group="result" data-filter-value="[▶]" title="running" data-testid="chip-' + scope + '-res-running">▶</button>' +
1484
+ '<button class="chip fchip" type="button" aria-pressed="false" data-filter-group="result" data-filter-value="[?]" title="died or unknown" data-testid="chip-' + scope + '-res-unknown">?</button>' +
1336
1485
  '<button class="chip fchip" type="button" aria-pressed="false" data-filter-group="time" data-filter-value="7d" title="last 7 days" data-testid="chip-' + scope + '-time-7d">7d</button>' +
1337
1486
  '<button class="chip fchip" type="button" aria-pressed="false" data-filter-group="time" data-filter-value="30d" title="last 30 days" data-testid="chip-' + scope + '-time-30d">30d</button>' +
1338
1487
  '<button class="chip fchip" type="button" aria-pressed="true" data-filter-group="time" data-filter-value="all" title="all time" data-testid="chip-' + scope + '-time-all">all</button>' +
@@ -1554,15 +1703,16 @@
1554
1703
  var verdict = document.getElementById("active-wf-verdict");
1555
1704
  var date = document.getElementById("active-wf-date");
1556
1705
 
1706
+ if(detail.signWords) signWords = detail.signWords;
1557
1707
  name.textContent = detail.flow + " (" + detail.runId + ")";
1558
- dot.className = "dot " + glyphClass(detail.glyph);
1559
- verdict.textContent = detail.label || "unknown";
1708
+ dot.className = dotClass(detail.glyph, detail.pulse);
1709
+ verdict.innerHTML = signHtml(detail.word, detail.line, detail.label);
1560
1710
  // browser re-walk bug #4: this is the DATE field — it must use its own
1561
1711
  // why (`detail.atWhy`), never `detail.outcomeWhy` (a different book
1562
1712
  // fact borrowed by mistake). A parked run's ask.json `askedAt` is a
1563
1713
  // real timestamp the books hold, shown ahead of any generic why text.
1564
1714
  date.textContent = detail.at ? readableDateTime(detail.at)
1565
- : (detail.askedAt ? "asked " + readableDateTime(detail.askedAt) : (detail.atWhy || "unknown"));
1715
+ : (detail.askedAt ? "asked " + readableDateTime(detail.askedAt) : (detail.startedAt ? "started " + readableDateTime(detail.startedAt) : (detail.atWhy || "unknown")));
1566
1716
 
1567
1717
  document.getElementById("run-empty").hidden = true;
1568
1718
  document.getElementById("run-content").hidden = false;
@@ -1571,13 +1721,13 @@
1571
1721
  // wallMs (never derived/guessed) — a died/parked run or one whose
1572
1722
  // history row predates the field both say why instead (fix #5).
1573
1723
  var capText = typeof detail.capUsd === "number" ? ("$" + detail.capUsd.toFixed(2)) : "unknown";
1574
- var spendText = detail.spend || "unknown — no spend recorded yet";
1724
+ var spendText = detail.spend || (detail.glyph === "[▶]" ? "no priced spend yet" : "unknown — no spend recorded yet");
1575
1725
  var wallText = typeof detail.wallMs === "number" ? ("took " + duration(detail.wallMs)) : (detail.wallMsWhy || "wall time unknown");
1576
1726
  document.getElementById("run-counters").innerHTML =
1577
1727
  escapeXml(spendText) + " of " + escapeXml(capText) + " cap &middot; " + escapeXml(wallText);
1578
1728
 
1579
1729
  var box = document.getElementById("run-summary");
1580
- box.className = "summary-box " + (detail.glyph === "[✗]" ? "red" : (detail.glyph === "[·]" ? "amber" : (detail.glyph === "[?]" ? "magenta" : "")));
1730
+ box.className = "summary-box " + (detail.glyph === "[✗]" ? "red" : ((detail.glyph === "[·]" || detail.glyph === "[▶]" || detail.glyph === "[II]") ? "amber" : (detail.glyph === "[?]" ? "magenta" : "")));
1581
1731
  var stepBoxes = buildStepBoxes(detail.steps);
1582
1732
  var stepsDone = stepBoxes.filter(function(s){ return s.state === "done"; }).length;
1583
1733
  var stepsText = stepBoxes.length === 0
@@ -1593,7 +1743,7 @@
1593
1743
  var modelText = detail.model || (detail.modelWhy || "no model call recorded yet");
1594
1744
  var closeText = closeClassSummaryText(detail.steps) || (detail.stepsWhy || "no steps recorded");
1595
1745
  box.innerHTML =
1596
- '<div class="summary-headline"><span class="dot ' + glyphClass(detail.glyph) + '"></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>' +
1597
1747
  '<div class="summary-row" data-testid="summary-model"><span class="sum-label">model:</span><span class="sum-val">' + escapeXml(modelText) + '</span></div>' +
1598
1748
  '<div class="summary-row"><span class="sum-label">steps:</span><span class="sum-val">' + stepsText + '</span></div>' +
1599
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>' +
@@ -1648,8 +1798,8 @@
1648
1798
  div.textContent = text;
1649
1799
  return div;
1650
1800
  }
1651
- // The card's HEADER line: "N · step-name [state] [close class]" — upper
1652
- // 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
1653
1803
  // keeping their own `.badge` color. `auditStateClass` is the SAME
1654
1804
  // function the Audit tab's group headers use to color their own state
1655
1805
  // word — never a second color scheme for the Run tab's cards.
@@ -1660,7 +1810,7 @@
1660
1810
  h4.textContent = (idx + 1) + " · " + box.emits;
1661
1811
  head.appendChild(h4);
1662
1812
  var stateBadge = document.createElement("span");
1663
- stateBadge.className = "badge " + auditStateClass(box.state);
1813
+ stateBadge.className = "badge " + auditStateClass(box.state) + (STEP_SIGN[box.state] ? " sign-badge" : "");
1664
1814
  stateBadge.setAttribute("data-testid", "step-card-state-" + idx);
1665
1815
  stateBadge.textContent = stateWord(box.state);
1666
1816
  head.appendChild(stateBadge);
@@ -1762,12 +1912,28 @@
1762
1912
  var header = row.querySelector("h4");
1763
1913
  if(table && table.hidden){
1764
1914
  table.hidden = false;
1915
+ row.classList.remove("closed");
1916
+ auditExpanded[step] = true;
1765
1917
  if(header) header.setAttribute("aria-expanded", "true");
1766
1918
  }
1767
1919
  if(typeof row.scrollIntoView === "function") row.scrollIntoView({ block: "center" });
1768
1920
  row.classList.add("audit-group-highlight");
1769
1921
  setTimeout(function(){ row.classList.remove("audit-group-highlight"); }, 1600);
1770
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
+ }
1771
1937
  // ONE row-cell builder for both views — `includeStep` controls only
1772
1938
  // whether the Step cell is rendered (Grouped drops it; the group's own
1773
1939
  // header already names the step). Column order: Attempt, [Step], Action,
@@ -1795,8 +1961,20 @@
1795
1961
  "<td data-label=\"Cost\">" + escapeXml(auditCostCellText(r)) + "</td>" +
1796
1962
  "<td data-label=\"Verdict\"><span class=\"badge " + badgeClass + "\">" + escapeXml(word) + "</span></td>" +
1797
1963
  "<td data-label=\"Close\">" + escapeXml(closeClassLabel(r.class)) + "</td>" +
1798
- "<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>";
1799
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(); } });
1800
1978
  return tr;
1801
1979
  }
1802
1980
  // ---- hamr's 2026-09-27 exit-check review #2: the Audit tab's All/Human/
@@ -1868,22 +2046,41 @@
1868
2046
  stateSpan.setAttribute("data-testid", "audit-group-state");
1869
2047
  stateSpan.textContent = g.state;
1870
2048
  h4.appendChild(stateSpan);
1871
- h4.appendChild(document.createTextNode(" · " + g.step + " · " + duration(g.timeMs) + " · " + (g.cost || "cost unknown")));
1872
- if(typeof g.tokensTotal === "number") h4.appendChild(document.createTextNode(" · " + g.tokensTotal + " tokens"));
1873
- 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 + " ");
1874
2066
  g.tryMarks.forEach(function(mark){
1875
2067
  var markSpan = document.createElement("span");
1876
2068
  markSpan.className = "mark " + auditMarkClass(mark);
1877
2069
  markSpan.textContent = mark;
1878
- h4.appendChild(markSpan);
2070
+ tail.appendChild(markSpan);
1879
2071
  });
2072
+ h4.appendChild(tail);
1880
2073
  return h4;
1881
2074
  }
1882
2075
  // Grouped view: one section per step, server order preserved (first-seen
1883
2076
  // order of `r.step` across this run's own rows — never re-sorted).
1884
2077
  // review item #1: COLLAPSED by default — a map/step-card click
1885
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;
1886
2081
  function renderAuditGroups(result){
2082
+ var runKey = currentFlow + "/" + currentRunId;
2083
+ if(auditExpandedRun !== runKey){ auditExpanded = {}; auditExpandedRun = runKey; }
1887
2084
  var container = document.getElementById("audit-groups");
1888
2085
  container.innerHTML = "";
1889
2086
  if(!result || result.empty) return;
@@ -1902,24 +2099,42 @@
1902
2099
  // COLLAPSED by default now (`aria-expanded` starts "false", the
1903
2100
  // table starts `hidden`) — expanding is something a human (or a
1904
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");
1905
2108
  var header = buildAuditGroupHeaderEl(g);
1906
2109
  header.setAttribute("role", "button");
1907
2110
  header.setAttribute("tabindex", "0");
1908
- header.setAttribute("aria-expanded", "false");
2111
+ header.setAttribute("aria-expanded", isOpen ? "true" : "false");
1909
2112
  header.setAttribute("aria-label", auditGroupHeaderText(g));
1910
2113
  header.style.cursor = "pointer";
1911
2114
  wrap.appendChild(header);
1912
2115
  var table = document.createElement("table");
1913
- table.hidden = true;
2116
+ table.hidden = !isOpen;
1914
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>";
1915
2118
  var tbody = table.querySelector("tbody");
1916
2119
  rows.forEach(function(r){ tbody.appendChild(buildAuditRowEl(r, false)); });
1917
2120
  table.setAttribute("data-testid", "audit-table-grouped-" + g.step);
1918
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);
1919
2131
  function toggleAuditGroup(){
1920
2132
  var next = table.hidden;
1921
2133
  table.hidden = !next;
2134
+ wrap.classList.toggle("closed", !next);
2135
+ auditExpanded[g.step] = next;
1922
2136
  header.setAttribute("aria-expanded", next ? "true" : "false");
2137
+ syncSingleRow(next);
1923
2138
  }
1924
2139
  header.addEventListener("click", toggleAuditGroup);
1925
2140
  header.addEventListener("keydown", function(e){
@@ -2075,6 +2290,39 @@
2075
2290
  // ---- selection + loading ----
2076
2291
  var currentFlow = null;
2077
2292
  var currentRunId = null;
2293
+ // The ask the last click named (null = none): an Inbox row is "selected" only when its own
2294
+ // flow, run AND ask match, so two stops of one run never both light up.
2295
+ var currentAskId = null;
2296
+ // borrowed-from: bareloop src/panel/index.html@0a45f40 (sig / withScrollPreserved), adjusted to fwdloop's shape
2297
+ // One last-payload signature per render. Equal payload = the DOM is not touched. `selectRun` resets
2298
+ // the ones a different selection invalidates.
2299
+ var lastSig = { inbox: null, runs: null, detail: null, asks: null, audit: null };
2300
+ function sig(obj){
2301
+ try { return JSON.stringify(obj); } catch(e){ return null; }
2302
+ }
2303
+ // Saves/restores scrollTop of the given element ids around a re-render.
2304
+ function withScrollPreserved(ids, fn){
2305
+ var saved = ids.map(function(id){
2306
+ var el = document.getElementById(id);
2307
+ return el ? el.scrollTop : null;
2308
+ });
2309
+ fn();
2310
+ ids.forEach(function(id, i){
2311
+ if(saved[i] === null) return;
2312
+ var el = document.getElementById(id);
2313
+ if(el) el.scrollTop = saved[i];
2314
+ });
2315
+ }
2316
+ // If keyboard focus sits on a row inside `listEl`, put it back on the rebuilt row with the same
2317
+ // data-testid. Lookup is by attribute equality (never a selector built from ids).
2318
+ function withFocusPreserved(listEl, fn){
2319
+ var a = document.activeElement;
2320
+ var id = (a && a !== listEl && listEl.contains && listEl.contains(a) && a.getAttribute) ? a.getAttribute("data-testid") : null;
2321
+ fn();
2322
+ if(!id) return;
2323
+ var again = Array.prototype.find.call(listEl.querySelectorAll("[data-testid]"), function(el){ return el.getAttribute("data-testid") === id; });
2324
+ if(again && again.focus) again.focus();
2325
+ }
2078
2326
  // `focusAskId` (M4a-1): when a click on an Inbox stop calls `selectRun`,
2079
2327
  // it names the ONE ask that stop is about — `renderAsk` expands exactly
2080
2328
  // that ask and scrolls it into view, rather than whatever this run's
@@ -2085,6 +2333,10 @@
2085
2333
  if(rowEl){ rowEl.classList.add("selected"); rowEl.setAttribute("aria-pressed","true"); }
2086
2334
  currentFlow = flow;
2087
2335
  currentRunId = runId;
2336
+ currentAskId = focusAskId || null;
2337
+ openRunLive = true; // unknown until this run's own detail says it is finished
2338
+ // a different selection: every payload-equality skip for the selection's own panes is void
2339
+ lastSig.runs = lastSig.detail = lastSig.asks = lastSig.audit = null;
2088
2340
  var base = "/api/runs/" + encodeURIComponent(flow) + "/" + encodeURIComponent(runId);
2089
2341
  // detail, audit, job, and asks each load independently — the Run tab's
2090
2342
  // step cards get everything they need (including a step's own attempt-
@@ -2092,40 +2344,119 @@
2092
2344
  // src/panel/data.js works out the boundary server-side, off the run's
2093
2345
  // full audit-row order, so the client no longer needs a second,
2094
2346
  // separately-fetched copy of the audit rows to cross-reference (fix #6).
2095
- getJSON(base).then(renderRun).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
2096
2352
  document.getElementById("run-empty").hidden = false;
2097
- document.getElementById("run-empty").textContent = "failed to load run: " + e.message;
2353
+ document.getElementById("run-empty").textContent = loadFailureText(e);
2098
2354
  document.getElementById("run-content").hidden = true;
2099
2355
  });
2100
- getJSON(base + "/audit").then(renderAudit).catch(function(){ renderAudit(null); });
2101
- getJSON(base + "/job").then(renderJob).catch(function(){ renderJob(null); });
2102
- getJSON(base + "/asks").then(function(result){ renderAsk(result, focusAskId || null); }).catch(function(e){
2103
- 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));
2104
2361
  });
2105
2362
  }
2106
2363
 
2107
- // ---- M4b piece 4: re-read the run from the BOOKS. There was no refresh loop
2108
- // before (the page loaded once), so: `reloadRun` re-reads one run's detail,
2109
- // asks, audit, job + the inbox and runs lists, applied only if that run is
2110
- // still the selected one; `startLive` calls it every LIVE_POLL_MS for up to
2111
- // LIVE_MAX_MS after an answer (or a resume retry) and stops at the first
2112
- // outcome the books show. Success is only ever said from what this reads. ----
2364
+ // ---- The ONE refresh loop (M4b piece 4, widened by the M4c exit walk). The page used to load
2365
+ // once, so a run that parked after load kept `[▶]`, Inbox stayed (0) and the run header kept its
2366
+ // first words. Now `pageTick` runs every LIVE_POLL_MS for the whole life of the page: it re-reads
2367
+ // the Runs list, History/Workflows, the Inbox list + (N), and the selected run's detail, asks and
2368
+ // audit — all through the SAME render functions, so the same guards hold (`holdAskRender` never
2369
+ // redraws over a typed reason; a refusal lives in `answerMsg` and is repainted). `startLive` no
2370
+ // longer owns a timer: it only names the answer being watched, and the tick judges it from the
2371
+ // books it just read (`liveOutcome`), up to LIVE_MAX_MS. `reloadRun` is also called straight
2372
+ // after an answer POST. Success is only ever said from what this reads. ----
2113
2373
  var LIVE_POLL_MS = 2000;
2374
+ // borrowed-from: bareloop src/panel/index.html@0a45f40 (RUNS_LIST_POLL_MS throttle inside the one tick), adjusted:
2375
+ // the open run's own panes keep the 2 s tick (only while that run is live); the Inbox and Runs lists
2376
+ // refresh at most every LISTS_POLL_MS. ONE timer: the throttle lives in `pageTick`, never a second timer.
2377
+ var LISTS_POLL_MS = 10000;
2114
2378
  var LIVE_MAX_MS = 5 * 60 * 1000;
2115
- var live = null; // { flow, runId, askId, until, timer }
2116
- function reloadRun(flow, runId){
2379
+ var live = null; // { flow, runId, askId, until } — the answer being watched, if any
2380
+ var pollTimer = null;
2381
+ var lastListsAt = 0; // when the lists were last asked for (any caller)
2382
+ var openRunLive = true; // is the open run still changing? (true until its detail says otherwise)
2383
+ var wasHidden = false;
2384
+ // One writer of `openRunLive`: every paint of the open run's detail goes through here.
2385
+ function paintRun(d){
2386
+ openRunLive = !(d && (d.glyph === "[\u2713]" || d.glyph === "[\u2717]"));
2387
+ var next = sig(d);
2388
+ if(next !== null && next === lastSig.detail) return;
2389
+ lastSig.detail = next;
2390
+ withScrollPreserved(["right-pane-body"], function(){ renderRun(d); });
2391
+ }
2392
+ // Immediate (every user action that re-reads calls this); the tick uses `listsDue` to throttle.
2393
+ function reloadLists(){
2394
+ lastListsAt = Date.now();
2395
+ getJSON("/api/inbox").then(function(r){ renderInbox(r.rows || [], r.openCount); }).catch(function(){});
2396
+ getJSON("/api/runs").then(function(r){
2397
+ var rows = r.rows || [];
2398
+ var next = sig(rows);
2399
+ if(next !== null && next === lastSig.runs) return;
2400
+ lastSig.runs = next;
2401
+ withScrollPreserved(["left-pane-body"], function(){ runsFilterBar.setItems(rows); runsFilterBar.refresh(); });
2402
+ }).catch(function(){});
2403
+ }
2404
+ function reloadRun(flow, runId, skipLists){
2117
2405
  var base = "/api/runs/" + encodeURIComponent(flow) + "/" + encodeURIComponent(runId);
2118
2406
  var still = function(){ return currentFlow === flow && currentRunId === runId; };
2119
- var detailP = getJSON(base).then(function(d){ if(still()) renderRun(d); return d; }).catch(function(){ return null; });
2120
- var asksP = getJSON(base + "/asks").then(function(a){ if(still()) renderAsk(a, null); return a; }).catch(function(e){ if(still()) renderAsk(null, null, e.message); return null; });
2121
- getJSON(base + "/audit").then(function(a){ if(still()) renderAudit(a); }).catch(function(){});
2122
- getJSON("/api/inbox").then(function(r){ renderInbox(r.rows || []); }).catch(function(){});
2123
- getJSON("/api/runs").then(function(r){ runsFilterBar.setItems(r.rows || []); runsFilterBar.refresh(); }).catch(function(){});
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
2408
+ var asksP = getJSON(base + "/asks").then(function(a){
2409
+ if(still()){
2410
+ // the Ask tab is drawn from the books AND the page's own pending answer ("working…" block)
2411
+ var next = sig({ asks: a, pending: pendingAnswer });
2412
+ // the signature is stamped only when renderAsk REALLY drew (it returns false when held over a typed
2413
+ // reason): a held redraw leaves the stamp unset, so the next tick retries it against the same payload
2414
+ if(next === null || next !== lastSig.asks){ lastSig.asks = renderAsk(a, null) ? next : null; }
2415
+ }
2416
+ return a;
2417
+ }).catch(function(e){ if(still()){ lastSig.asks = null; renderAsk(null, null, loadFailureText(e)); } return null; });
2418
+ getJSON(base + "/audit").then(function(a){
2419
+ if(!still()) return;
2420
+ var next = sig(a);
2421
+ if(next !== null && next === lastSig.audit) return;
2422
+ lastSig.audit = next;
2423
+ renderAudit(a);
2424
+ }).catch(function(){});
2425
+ if(!skipLists) reloadLists();
2124
2426
  return Promise.all([detailP, asksP]);
2125
2427
  }
2126
- function stopLive(){ if(live){ clearTimeout(live.timer); live = null; } }
2428
+ function schedulePoll(ms){ clearTimeout(pollTimer); pollTimer = setTimeout(pageTick, ms); }
2429
+ function pageTick(){
2430
+ pollTimer = null;
2431
+ if(document.hidden){ wasHidden = true; schedulePoll(LIVE_POLL_MS); return; }
2432
+ var catchUp = wasHidden; // first tick after the tab came back: force both
2433
+ wasHidden = false;
2434
+ var watch = live;
2435
+ var sel = currentFlow !== null && currentRunId !== null;
2436
+ var watchIsSelected = watch && sel && watch.flow === currentFlow && watch.runId === currentRunId;
2437
+ var listsDue = catchUp || (Date.now() - lastListsAt) >= LISTS_POLL_MS;
2438
+ var wasLive = openRunLive;
2439
+ var selP;
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);
2443
+ else selP = Promise.resolve([null, null]);
2444
+ if(listsDue) reloadLists();
2445
+ // the watched run, when it is not the one on screen: read it for its outcome only (no paint — `still()` is false)
2446
+ var watchP = (watch && !watchIsSelected) ? reloadRun(watch.flow, watch.runId, true) : selP;
2447
+ watchP.then(function(res){
2448
+ if(watch && live === watch) watchStep(watch, res);
2449
+ }).catch(function(){}).then(function(){
2450
+ // the open run just stopped being live: its list glyph must not wait up to LISTS_POLL_MS
2451
+ if(sel && wasLive && !openRunLive && !listsDue) reloadLists();
2452
+ if(!pollTimer) schedulePoll(LIVE_POLL_MS);
2453
+ });
2454
+ }
2455
+ function stopLive(){ live = null; }
2127
2456
  // What the books say now, in words (pure; `null` = keep waiting).
2128
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 || "") };
2129
2460
  if(asks && asks.resume && asks.resume.state === "not-started") return { done: true, cls: null, text: null };
2130
2461
  var list = (asks && asks.asks) || [];
2131
2462
  var fresh = list.find(function(a){ return a.waiting && a.askId !== askId; });
@@ -2136,27 +2467,38 @@
2136
2467
  var st = asks && asks.resume ? asks.resume.label : null;
2137
2468
  return { done: false, cls: "info", text: (st || "answer applied") + " — run: " + ((detail && detail.label) || "state unknown") };
2138
2469
  }
2470
+ // A watch outcome never overwrites a refusal the human has not yet clicked past (M4c item 7).
2471
+ function sayLive(flow, runId, o){
2472
+ if(answerMsg && answerMsg.cls === "refused") return;
2473
+ if(o.text) say(flow, runId, o.cls, o.text);
2474
+ else if(o.done){ answerMsg = null; paintAnswerMsg(); }
2475
+ }
2476
+ // The books showed the next state (or the watch gave up): the "working…" block ends and the Ask tab
2477
+ // is drawn from what the books say now. Uses the SAME renderAsk guard as every refresh.
2478
+ function endPending(flow, runId, asks){
2479
+ if(!pendingAnswer) return;
2480
+ pendingAnswer = null;
2481
+ if(currentFlow === flow && currentRunId === runId && asks) renderAsk(asks, null);
2482
+ }
2139
2483
  function startLive(flow, runId, askId){
2140
- stopLive();
2141
- live = { flow: flow, runId: runId, askId: askId, until: Date.now() + LIVE_MAX_MS, timer: null };
2142
- var mine = live;
2143
- function tick(){
2144
- if(live !== mine) return;
2145
- reloadRun(flow, runId).then(function(res){
2146
- if(live !== mine) return;
2147
- var o = liveOutcome(askId, res[0], res[1]);
2148
- if(o.text) say(flow, runId, o.cls, o.text); else if(o.done){ answerMsg = null; paintAnswerMsg(); }
2149
- if(o.done){ stopLive(); return; }
2150
- if(Date.now() > mine.until){
2151
- say(flow, runId, "info", "no outcome after " + Math.round(LIVE_MAX_MS / 60000) + " minutes of watching — reload the page to check the run's books");
2152
- stopLive();
2153
- return;
2154
- }
2155
- mine.timer = setTimeout(tick, LIVE_POLL_MS);
2156
- });
2484
+ live = { flow: flow, runId: runId, askId: askId, until: Date.now() + LIVE_MAX_MS };
2485
+ schedulePoll(600);
2486
+ }
2487
+ function watchStep(mine, res){
2488
+ var o = liveOutcome(mine.askId, res[0], res[1]);
2489
+ sayLive(mine.flow, mine.runId, o);
2490
+ if(o.done){ endPending(mine.flow, mine.runId, res[1]); stopLive(); return; }
2491
+ if(Date.now() > mine.until){
2492
+ say(mine.flow, mine.runId, "info", "no outcome after " + Math.round(LIVE_MAX_MS / 60000) + " minutes of watching — reload the page to check the run's books");
2493
+ endPending(mine.flow, mine.runId, res[1]);
2494
+ stopLive();
2157
2495
  }
2158
- mine.timer = setTimeout(tick, 600);
2159
2496
  }
2497
+ schedulePoll(LIVE_POLL_MS);
2498
+ // Back on the tab: one catch-up tick now (forcing both rates) instead of waiting out the 2 s beat.
2499
+ document.addEventListener("visibilitychange", function(){
2500
+ if(!document.hidden){ wasHidden = true; schedulePoll(0); }
2501
+ });
2160
2502
 
2161
2503
  getJSON("/api/runs").then(function(result){
2162
2504
  var runs = result.rows || [];
@@ -2173,8 +2515,8 @@
2173
2515
  runsFilterBar.refresh();
2174
2516
  }
2175
2517
  }).catch(function(e){
2176
- document.getElementById("wf-list").innerHTML = '<div class="hint">failed to load: ' + escapeXml(e.message) + '</div>';
2177
- 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>';
2178
2520
  });
2179
2521
 
2180
2522
  // ---- shared text-node helper — book text (question/draft/artifact
@@ -2199,6 +2541,8 @@
2199
2541
  // Ask tab, focused on that one ask. The answer doors live in the Ask tab. --
2200
2542
  function stopStatusLine(row){
2201
2543
  if(row.waiting) return "time left: " + duration(row.timeLeftMs);
2544
+ if(row.stuck) return row.stuckLine || row.stuckLabel;
2545
+ if(row.working) return "working on your " + row.working + "…";
2202
2546
  if(row.open && row.resume) return row.resume.label;
2203
2547
  var bits = [row.status];
2204
2548
  if(row.reason) bits.push("reason: " + row.reason);
@@ -2208,22 +2552,37 @@
2208
2552
  }
2209
2553
  function renderStopRow(row){
2210
2554
  var wrap = document.createElement("div");
2211
- wrap.className = "hist-row inbox-row";
2555
+ wrap.className = "hist-row inbox-row s" + row.section;
2212
2556
  wrap.setAttribute("role", "button");
2213
2557
  wrap.setAttribute("tabindex", "0");
2214
- wrap.setAttribute("aria-pressed", "false");
2558
+ // Selected is derived here, off the page's own selection (flow + run + ask), so a rebuild keeps it.
2559
+ var selected = row.flow === currentFlow && row.runId === currentRunId && (row.askId || null) === currentAskId;
2560
+ if(selected) wrap.className += " selected";
2561
+ wrap.setAttribute("aria-pressed", selected ? "true" : "false");
2215
2562
  wrap.setAttribute("data-testid", "inbox-row-" + row.flow + "-" + row.runId + (row.askId ? "-" + row.askId : ""));
2216
2563
  var head = document.createElement("div");
2217
2564
  head.className = "wf-line1";
2218
- var badge = document.createElement("span");
2219
- badge.className = "badge " + (row.open ? "amber" : (row.status === "accepted" ? "green" : (row.status === "redo" ? "red" : "grey")));
2220
- badge.textContent = row.open ? "·" : row.status;
2221
- head.appendChild(badge);
2565
+ // section 1: [·] waiting on you (pulses); section 2 working: [▶] (pulses);
2566
+ // a stuck run (answer saved, nobody carrying it on): [II] pulses, in section 1;
2567
+ // resume starting: [·] still; section 3: the status word.
2568
+ if(row.section === 1 || row.working || row.resume){
2569
+ var sign = document.createElement("span");
2570
+ sign.className = "dot " + (row.working ? "amber pulse" : (row.stuck ? "stuck pulse" : (row.waiting ? "grey pulse" : "grey")));
2571
+ head.appendChild(sign);
2572
+ } else {
2573
+ var badge = document.createElement("span");
2574
+ badge.className = "badge " + (row.status === "accepted" ? "green" : (row.status === "redo" ? "red" : "grey"));
2575
+ badge.textContent = row.status;
2576
+ head.appendChild(badge);
2577
+ }
2222
2578
  var flowName = textDiv(null, row.flow + " (" + row.runId + ")");
2223
2579
  flowName.className = "wf-name";
2224
2580
  head.appendChild(flowName);
2225
2581
  wrap.appendChild(head);
2226
- 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);
2227
2586
  if(typeof row.question === "string"){
2228
2587
  wrap.appendChild(textDiv("step-meta", "question: " + row.question));
2229
2588
  } else if(row.questionWhy){
@@ -2239,20 +2598,34 @@
2239
2598
  });
2240
2599
  return wrap;
2241
2600
  }
2242
- function renderInbox(rows){
2601
+ var INBOX_HEADS = { 1: "waiting on you", 2: "working on your answer", 3: "answered and expired" };
2602
+ // N comes from the server (data.js inboxOpenCount); the page only shows it.
2603
+ function renderInbox(rows, openCount){
2243
2604
  var el = document.getElementById("inbox-list");
2605
+ var next = sig({ rows: rows, openCount: openCount });
2606
+ if(next !== null && next === lastSig.inbox) return; // unchanged payload — never rebuild the DOM for nothing
2607
+ lastSig.inbox = next;
2608
+ withScrollPreserved(["left-pane-body"], function(){ withFocusPreserved(el, function(){ buildInbox(el, rows, openCount); }); });
2609
+ }
2610
+ function buildInbox(el, rows, openCount){
2244
2611
  el.innerHTML = "";
2245
- var openCount = 0;
2246
- (rows || []).forEach(function(r){ if(r.waiting) openCount += 1; });
2247
- document.getElementById("inbox-count-label").textContent = openCount > 0 ? (" (" + openCount + ")") : "";
2612
+ document.getElementById("inbox-count-label").textContent = " (" + (typeof openCount === "number" ? openCount : 0) + ")";
2248
2613
  if(!rows || !rows.length){
2249
2614
  el.innerHTML = '<div class="hint">nothing waiting on you — no stops recorded under this root</div>';
2250
2615
  return;
2251
2616
  }
2252
- rows.forEach(function(row){ el.appendChild(renderStopRow(row)); });
2617
+ var lastSection = 0;
2618
+ rows.forEach(function(row){
2619
+ if(row.section !== lastSection){
2620
+ lastSection = row.section;
2621
+ el.appendChild(textDiv("inbox-h", INBOX_HEADS[row.section] || ""));
2622
+ }
2623
+ el.appendChild(renderStopRow(row));
2624
+ });
2253
2625
  }
2254
- getJSON("/api/inbox").then(function(result){ renderInbox(result.rows || []); }).catch(function(e){
2255
- document.getElementById("inbox-list").innerHTML = '<div class="hint">failed to load: ' + escapeXml(e.message) + '</div>';
2626
+ getJSON("/api/inbox").then(function(result){ renderInbox(result.rows || [], result.openCount); }).catch(function(e){
2627
+ lastSig.inbox = null;
2628
+ document.getElementById("inbox-list").innerHTML = '<div class="hint">' + escapeXml(loadFailureText(e)) + '</div>';
2256
2629
  });
2257
2630
 
2258
2631
  // ---- Ask tab (M4a-1): every ask of the SELECTED run, collapsed by
@@ -2266,10 +2639,12 @@
2266
2639
  // own SVG nodes elsewhere on this page. ----
2267
2640
  function askStatusBlock(ask){
2268
2641
  if(ask.waiting) return textDiv("wf-meta", "time left: " + duration(ask.timeLeftMs));
2269
- if(ask.open && ask.resume) return textDiv("wf-meta", ask.resume.label);
2642
+ // an open ask with a saved answer: the header meta line already says the resume label (stuck or starting) — once.
2643
+ if(ask.open && ask.resume) return null;
2270
2644
  var bits = [ask.status];
2271
2645
  if(ask.reason) bits.push("reason: " + ask.reason);
2272
2646
  if(ask.answeredAt) bits.push("answered " + (readableDateTime(ask.answeredAt) || ask.answeredAt));
2647
+ if(ask.why) bits.push(ask.why);
2273
2648
  return textDiv("wf-meta", bits.join(" · "));
2274
2649
  }
2275
2650
  // ---- M4b piece 4: answer doors. The panel is a CLIENT of the arbiter: it sends
@@ -2277,18 +2652,37 @@
2277
2652
  // never decides that a reason is "good enough". ----
2278
2653
  // Pure: which controls does this ask get? `resume` is the run's own
2279
2654
  // `resume` field (src/panel/data.js deriveResumeState), never guessed here.
2280
- function answerControls(ask, resume){
2655
+ // `pending` (M4c item 6) = the answer this page just sent and got a 202 for,
2656
+ // for THIS ask: until the books show the next state there are no doors, only
2657
+ // what is happening. Null when nothing was sent (or the send was refused).
2658
+ function pendingText(p){
2659
+ if(p.decision === "redo") return "working on your redo… draft " + (p.draftNo + 1) + " is coming";
2660
+ if(p.decision === "accept") return "shipping draft " + p.draftNo + "…";
2661
+ return "ending this run, starting a fresh one…";
2662
+ }
2663
+ function answerControls(ask, resume, pending){
2664
+ if(pending && ask && pending.askId === ask.askId){
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" };
2670
+ }
2281
2671
  if(!ask || !ask.open){
2282
- 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." };
2283
2673
  }
2284
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
+ }
2285
2679
  if(resume.state === "starting"){
2286
- 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." };
2287
2681
  }
2288
2682
  if(resume.state === "not-started"){
2289
- return { kind: "stuck", label: resume.label, 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 };
2290
2684
  }
2291
- return { kind: "none", why: "no answer doors: " + resume.label };
2685
+ return { kind: "none", why: resume.label + "." };
2292
2686
  }
2293
2687
  return { kind: "doors" };
2294
2688
  }
@@ -2296,6 +2690,19 @@
2296
2690
  // action. Set by `say`, never by a guess that the answer worked.
2297
2691
  var answerMsg = null; // { flow, runId, cls: "refused"|"info", text }
2298
2692
  var reasonDrafts = {}; // askId -> what the human has typed so far
2693
+ var pendingAnswer = null; // { flow, runId, askId, decision, draftNo } — set on a 202, cleared by the live watch
2694
+ // M4c item 7: should a periodic refresh skip re-drawing the Ask tab? Only while the
2695
+ // human is mid-answer (text typed, or the box focused) on an ask that is STILL
2696
+ // waiting in the new books — a dead ask's box never pins the page. A refusal needs no
2697
+ // hold: it lives in `answerMsg` and is repainted after every render, until the next click.
2698
+ function holdAskRender(box, result){
2699
+ if(!box || !(box.value !== "" || box.focused)) return false;
2700
+ return ((result && result.asks) || []).some(function(a){ return a.waiting && a.askId === box.askId; });
2701
+ }
2702
+ function readReasonBox(){
2703
+ var ta = document.querySelector("#ask-list textarea[data-testid='answer-reason']");
2704
+ return ta ? { askId: ta.getAttribute("data-askid"), value: ta.value, focused: document.activeElement === ta } : null;
2705
+ }
2299
2706
  function say(flow, runId, cls, text){ answerMsg = { flow: flow, runId: runId, cls: cls, text: text }; paintAnswerMsg(); }
2300
2707
  function paintAnswerMsg(){
2301
2708
  document.querySelectorAll("[data-answer-msg]").forEach(function(el){
@@ -2306,10 +2713,53 @@
2306
2713
  el.textContent = mine ? m.text : "";
2307
2714
  });
2308
2715
  }
2309
- function refusalText(r){
2310
- var b = r.body;
2311
- var name = b && typeof b.red === "string" ? b.red : (r.text || "no detail");
2312
- 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.";
2313
2763
  }
2314
2764
  // While a POST is out the buttons are disabled (stops a double click) — nothing else is ever disabled.
2315
2765
  function setBusy(root, busy){
@@ -2320,35 +2770,80 @@
2320
2770
  function sendAnswer(root, ask, ctx, decision){
2321
2771
  var ta = root.querySelector("textarea");
2322
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
+ }
2323
2779
  say(ctx.flow, ctx.runId, "info", "sending " + decision + "…");
2324
2780
  setBusy(root, true);
2325
2781
  postJSON("/api/answer", payload).then(function(r){
2326
2782
  if(r.status === 202 && r.body && r.body.ok){
2327
2783
  delete reasonDrafts[ask.askId];
2328
- say(ctx.flow, ctx.runId, "info", "answer sent (" + decision + ") — waiting for the run's books to show what happened");
2784
+ pendingAnswer = { flow: ctx.flow, runId: ctx.runId, askId: ask.askId, decision: decision, draftNo: ctx.draftNo };
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.");
2329
2788
  startLive(ctx.flow, ctx.runId, ask.askId);
2330
2789
  } else {
2331
- say(ctx.flow, ctx.runId, "refused", refusalText(r));
2790
+ say(ctx.flow, ctx.runId, "refused", refusalText(r, decision));
2332
2791
  }
2333
2792
  return reloadRun(ctx.flow, ctx.runId);
2334
2793
  }).catch(function(e){
2335
- 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());
2336
2795
  return reloadRun(ctx.flow, ctx.runId);
2337
2796
  }).then(function(){ if(root.isConnected) setBusy(root, false); });
2338
2797
  }
2339
2798
  function sendResumeAgain(root, ctx, askId){
2340
- say(ctx.flow, ctx.runId, "info", "asking for the resume again…");
2799
+ say(ctx.flow, ctx.runId, "info", "continuing the run…");
2341
2800
  setBusy(root, true);
2342
2801
  postJSON("/api/resume", { flow: ctx.flow, runId: ctx.runId }).then(function(r){
2343
2802
  if(r.status === 202 && r.body && r.body.ok){
2344
- 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");
2804
+ startLive(ctx.flow, ctx.runId, askId);
2805
+ } else {
2806
+ say(ctx.flow, ctx.runId, "refused", refusalText(r));
2807
+ }
2808
+ return reloadRun(ctx.flow, ctx.runId);
2809
+ }).catch(function(e){
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");
2345
2824
  startLive(ctx.flow, ctx.runId, askId);
2346
2825
  } else {
2347
2826
  say(ctx.flow, ctx.runId, "refused", refusalText(r));
2348
2827
  }
2349
2828
  return reloadRun(ctx.flow, ctx.runId);
2350
2829
  }).catch(function(e){
2351
- say(ctx.flow, ctx.runId, "refused", "network failure: " + e.message + " — nothing is confirmed; what the books say is shown in the ask header above");
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());
2352
2847
  return reloadRun(ctx.flow, ctx.runId);
2353
2848
  }).then(function(){ if(root.isConnected) setBusy(root, false); });
2354
2849
  }
@@ -2362,11 +2857,16 @@
2362
2857
  return b;
2363
2858
  }
2364
2859
  function renderAnswerBlock(ask, ctx){
2365
- var model = answerControls(ask, ctx.resume);
2860
+ var model = answerControls(ask, ctx.resume, pendingAnswer);
2366
2861
  var root = document.createElement("div");
2367
2862
  root.className = "answer-doors";
2368
2863
  root.setAttribute("data-testid", "answer-doors");
2369
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
+ }
2370
2870
  var idSafe = "reason-" + String(ask.askId).replace(/[^A-Za-z0-9_-]/g, "_");
2371
2871
  var lab = document.createElement("label");
2372
2872
  lab.setAttribute("for", idSafe);
@@ -2375,10 +2875,16 @@
2375
2875
  ta.id = idSafe;
2376
2876
  ta.rows = 3;
2377
2877
  ta.setAttribute("data-testid", "answer-reason");
2878
+ ta.setAttribute("data-askid", ask.askId);
2378
2879
  ta.value = reasonDrafts[ask.askId] || "";
2379
- ta.addEventListener("input", function(){ reasonDrafts[ask.askId] = ta.value; });
2880
+ ta.addEventListener("input", function(){ reasonDrafts[ask.askId] = ta.value; reasonHint.hidden = true; });
2380
2881
  root.appendChild(lab);
2381
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);
2382
2888
  var bar = document.createElement("div");
2383
2889
  bar.className = "actions-row";
2384
2890
  bar.setAttribute("data-testid", "action-bar");
@@ -2387,15 +2893,38 @@
2387
2893
  bar.appendChild(makeButton("Rerun", "btn-rerun", function(){ sendAnswer(root, ask, ctx, "rerun"); }));
2388
2894
  root.appendChild(bar);
2389
2895
  root.appendChild(textDiv("hint", "accept ships this draft; redo: redo the last step with your reason; rerun: end this run and start a fresh one from the top"));
2896
+ } else if(model.kind === "working"){
2897
+ var wk = document.createElement("div");
2898
+ wk.className = "working-line";
2899
+ wk.setAttribute("data-testid", "answer-working");
2900
+ var wsign = document.createElement("span");
2901
+ wsign.className = "dot amber pulse";
2902
+ wk.appendChild(wsign);
2903
+ wk.appendChild(document.createTextNode(model.text));
2904
+ root.appendChild(wk);
2390
2905
  } else if(model.kind === "starting"){
2391
- 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));
2392
2914
  } else if(model.kind === "stuck"){
2393
- root.appendChild(textDiv("answer-msg stuck", model.label + ": " + model.reason));
2394
- 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.
2395
2916
  var bar2 = document.createElement("div");
2396
2917
  bar2.className = "actions-row";
2397
- 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
+ }
2398
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."));
2399
2928
  } else {
2400
2929
  root.appendChild(textDiv("hint", model.why));
2401
2930
  }
@@ -2423,7 +2952,7 @@
2423
2952
  // bolder" — a real heading class (same weight/size/uppercase posture
2424
2953
  // as the Job tab's own field `<label>`s), never the plain `.hint`
2425
2954
  // style a footnote/why-text uses.
2426
- ev.appendChild(textDiv("evidence-heading", "draft under review"));
2955
+ ev.appendChild(textDiv("evidence-heading", "draft " + ctx.draftNo));
2427
2956
  ev.appendChild(draftEl);
2428
2957
  } else {
2429
2958
  ev.appendChild(textDiv("hint", evidence.why || "no draft on file"));
@@ -2447,32 +2976,51 @@
2447
2976
  art.textContent = typeof u.text === "string" ? u.text : "no artifact text on file";
2448
2977
  ev.appendChild(art);
2449
2978
  });
2450
- // M4b piece 4: the answer doors (or the reason there are none) live here.
2451
- ev.appendChild(renderAnswerBlock(ask, ctx));
2452
2979
  return ev;
2453
2980
  }
2981
+ // M4c item 5: "your answers so far" — one line per answered draft, every field from
2982
+ // the server's block (data.js groupAskBlocks); the page only lays it out.
2983
+ function answerLineText(a){
2984
+ return "draft " + a.draft + " → " + a.decision + (a.reason ? ' "' + a.reason + '"' : "")
2985
+ + (a.answeredAt ? " " + (readableDateTime(a.answeredAt) || a.answeredAt) : "");
2986
+ }
2987
+ function renderAnswersSoFar(block){
2988
+ var box = document.createElement("div");
2989
+ box.setAttribute("data-testid", "answers-so-far");
2990
+ if(!block.answers.length) return box;
2991
+ box.appendChild(textDiv("evidence-heading", "your answers so far"));
2992
+ block.answers.forEach(function(a){ box.appendChild(textDiv("answer-line", answerLineText(a))); });
2993
+ return box;
2994
+ }
2454
2995
  // hamr's 2026-09-27 exit-check review #3: "when opened from an Inbox
2455
2996
  // click it's not clear which ask is shown" — one line naming exactly
2456
- // which ask this is (`Ask i of n`, from src/panel/data.js's own
2457
- // index/total), which declared step it belongs to (`stepName`, at its
2997
+ // which ask line this block is (M4c: one block per signed ask line, its
2998
+ // draft number from src/panel/data.js's groupAskBlocks), which declared step it belongs to (`stepName`, at its
2458
2999
  // signed prose `stepLine` — src/panel/data.js's `deriveAskStepInfo`,
2459
3000
  // never re-derived here), when it was asked, and its status. `stepWhy` is
2460
3001
  // shown verbatim (never a guessed step name) when the books can't name
2461
3002
  // one — the honest word "before" a real value never invents.
2462
- function askHeaderMetaText(ask){
2463
- var bits = ["Ask " + ask.index + " of " + ask.total];
2464
- var stepBit = typeof ask.stepName === "string" && ask.stepName.length > 0
2465
- ? ask.stepName + (typeof ask.stepLine === "number" ? " (line " + ask.stepLine + ")" : "")
3003
+ function blockMetaText(block, ctx){
3004
+ var ask = block.current;
3005
+ // every ask says which run it belongs to: the buttons below act on THIS run only
3006
+ var bits = [ctx.flow + " (" + ctx.runId + ")"];
3007
+ var stepBit = typeof block.stepName === "string" && block.stepName.length > 0
3008
+ ? block.stepName + (typeof block.stepLine === "number" ? " (line " + block.stepLine + ")" : "")
2466
3009
  : (ask.stepWhy || "step not determinable");
2467
3010
  bits.push(stepBit);
3011
+ bits.push("draft " + block.draftNo);
2468
3012
  bits.push(typeof ask.askedAt === "string" ? "asked " + (readableDateTime(ask.askedAt) || ask.askedAt) : "asked: unknown");
2469
3013
  bits.push(ask.waiting ? "waiting on you" : (ask.open && ask.resume ? ask.resume.label : ask.status));
2470
3014
  return bits.join(" · ");
2471
3015
  }
2472
- function renderAskRow(ask, expanded, ctx){
3016
+ // One block per signed ask line (M4c item 5), drawn from the server's `blocks`.
3017
+ function renderAskRow(block, expanded, ctx){
3018
+ var ask = block.current;
3019
+ ctx = { flow: ctx.flow, runId: ctx.runId, resume: ctx.resume, draftNo: block.draftNo };
2473
3020
  var wrap = document.createElement("div");
2474
3021
  wrap.className = "audit-group";
2475
- wrap.setAttribute("data-testid", "ask-row-" + (ask.askId || "no-id"));
3022
+ wrap.setAttribute("data-testid", "ask-block-" + (block.stepName || "no-step"));
3023
+ wrap.setAttribute("data-open", String(!!ask.open));
2476
3024
  var head = document.createElement("div");
2477
3025
  head.setAttribute("role", "button");
2478
3026
  head.setAttribute("tabindex", "0");
@@ -2481,14 +3029,19 @@
2481
3029
  var metaLine = document.createElement("div");
2482
3030
  metaLine.className = "wf-line1";
2483
3031
  var badge = document.createElement("span");
2484
- badge.className = "badge " + (ask.open ? "amber" : (ask.status === "accepted" ? "green" : (ask.status === "redo" ? "red" : "grey")));
2485
- badge.textContent = ask.open ? "·" : ask.status;
3032
+ if(ask.stuck){
3033
+ // the same sign as the Inbox card and run header: [II], pulsing (server-decided `stuck`, data.js getRunAsks)
3034
+ badge.className = "dot stuck pulse";
3035
+ } else {
3036
+ badge.className = "badge " + (ask.open ? "amber" : (ask.status === "accepted" ? "green" : (ask.status === "redo" ? "red" : "grey")));
3037
+ badge.textContent = ask.open ? "·" : ask.status;
3038
+ }
2486
3039
  metaLine.appendChild(badge);
2487
- metaLine.appendChild(textDiv("wf-meta", askHeaderMetaText(ask)));
3040
+ metaLine.appendChild(textDiv("wf-meta", blockMetaText(block, ctx)));
2488
3041
  head.appendChild(metaLine);
2489
3042
  // The question itself — a real, bold heading (review #3: "the question
2490
3043
  // as a clear heading"), never folded into the same small meta line.
2491
- var qText = typeof ask.question === "string" ? ask.question : (ask.questionWhy || "question not recorded");
3044
+ var qText = typeof block.question === "string" ? block.question : (block.questionWhy || "question not recorded");
2492
3045
  var qHeading = document.createElement("h4");
2493
3046
  qHeading.className = "ask-question-heading";
2494
3047
  qHeading.textContent = qText;
@@ -2496,8 +3049,12 @@
2496
3049
  wrap.appendChild(head);
2497
3050
  var body = document.createElement("div");
2498
3051
  body.hidden = !expanded;
2499
- body.appendChild(askStatusBlock(ask));
3052
+ var statusBlock = askStatusBlock(ask);
3053
+ if(statusBlock) body.appendChild(statusBlock);
2500
3054
  body.appendChild(renderAskEvidenceBlock(ask, ctx));
3055
+ body.appendChild(renderAnswersSoFar(block));
3056
+ // M4b piece 4: the answer doors (or the reason there are none) — for the CURRENT draft.
3057
+ body.appendChild(renderAnswerBlock(ask, ctx));
2501
3058
  wrap.appendChild(body);
2502
3059
  function toggle(){
2503
3060
  var next = body.hidden;
@@ -2510,33 +3067,44 @@
2510
3067
  });
2511
3068
  return wrap;
2512
3069
  }
3070
+ var askDrawnFor = null; // "flow/runId" whose blocks the Ask tab last drew
2513
3071
  function renderAsk(result, focusAskId, loadError){
2514
3072
  var empty = document.getElementById("ask-empty");
2515
3073
  var list = document.getElementById("ask-list");
2516
- if(loadError){ empty.hidden = false; empty.textContent = "failed to load asks: " + loadError; list.hidden = true; list.innerHTML = ""; return; }
2517
- if(!result){ empty.hidden = false; empty.textContent = "select a run first"; list.hidden = true; list.innerHTML = ""; return; }
2518
- var asks = result.asks || [];
2519
- if(!asks.length){
3074
+ if(loadError){ empty.hidden = false; empty.textContent = loadError; list.hidden = true; list.innerHTML = ""; return true; }
3075
+ if(!result){ empty.hidden = false; empty.textContent = "select a run first"; list.hidden = true; list.innerHTML = ""; return true; }
3076
+ var blocks = result.blocks || [];
3077
+ if(!blocks.length){
2520
3078
  empty.hidden = false;
2521
3079
  empty.textContent = "this run has never parked on a human — no asks recorded";
2522
3080
  list.hidden = true;
2523
3081
  list.innerHTML = "";
2524
- return;
3082
+ return true;
2525
3083
  }
3084
+ // M4c item 7: never redraw over a reason being typed (every periodic refresh comes through here).
3085
+ // Returns false when held (nothing drawn), true after every real draw — the one signal `reloadRun` stamps on.
3086
+ if(!focusAskId && holdAskRender(readReasonBox(), result)) return false;
2526
3087
  empty.hidden = true;
2527
3088
  list.hidden = false;
2528
- list.innerHTML = "";
2529
- // Default expansion: the ask named by a click from the Inbox
2530
- // (`focusAskId`) wins; otherwise this run's own open ask (if it has
2531
- // one) expands; otherwise every ask stays collapsed.
2532
- var defaultOpenId = focusAskId;
2533
- if(!defaultOpenId){
2534
- var openAsk = asks.find(function(a){ return a.open; });
2535
- if(openAsk) defaultOpenId = openAsk.askId;
3089
+ // The refresh redraws this tab every tick: a block the human opened or closed by hand keeps that
3090
+ // state while its own openness is unchanged (a Inbox click, `focusAskId`, resets to its default).
3091
+ var kept = {};
3092
+ if(!focusAskId && askDrawnFor === result.flow + "/" + result.runId){
3093
+ list.querySelectorAll("[data-testid^='ask-block-']").forEach(function(w){
3094
+ kept[w.getAttribute("data-testid")] = { open: w.getAttribute("data-open"), expanded: w.firstChild.getAttribute("aria-expanded") === "true" };
3095
+ });
2536
3096
  }
2537
- asks.forEach(function(ask){
2538
- var expanded = defaultOpenId != null && ask.askId === defaultOpenId;
2539
- var row = renderAskRow(ask, expanded, { flow: result.flow, runId: result.runId, resume: result.resume || null });
3097
+ askDrawnFor = result.flow + "/" + result.runId;
3098
+ list.innerHTML = "";
3099
+ // Default expansion: the block holding the ask a click from the Inbox
3100
+ // (`focusAskId`) named wins; otherwise a block with an open ask expands;
3101
+ // a run with a single ask line expands it; otherwise blocks stay collapsed.
3102
+ blocks.forEach(function(block){
3103
+ var ask = block.current;
3104
+ var expanded = focusAskId ? block.askIds.indexOf(focusAskId) !== -1 : (ask.open || blocks.length === 1);
3105
+ var prev = kept["ask-block-" + (block.stepName || "no-step")];
3106
+ if(prev && prev.open === String(!!ask.open)) expanded = prev.expanded;
3107
+ var row = renderAskRow(block, expanded, { flow: result.flow, runId: result.runId, resume: result.resume || null });
2540
3108
  // hamr's 2026-09-27 exit-check review #3: "the ask opened from the
2541
3109
  // Inbox gets a visible highlight" — a REAL Inbox click (`focusAskId`
2542
3110
  // set) on THIS ask, never a run's own default open-ask expansion
@@ -2545,7 +3113,7 @@
2545
3113
  // highlight`, this row already carries the `audit-group` class) —
2546
3114
  // persistent here, not momentary, since the human navigated here
2547
3115
  // specifically to see this one.
2548
- if(focusAskId && ask.askId === focusAskId){
3116
+ if(focusAskId && block.askIds.indexOf(focusAskId) !== -1){
2549
3117
  row.classList.add("audit-group-highlight");
2550
3118
  }
2551
3119
  list.appendChild(row);
@@ -2558,6 +3126,7 @@
2558
3126
  }
2559
3127
  }
2560
3128
  });
3129
+ return true;
2561
3130
  }
2562
3131
 
2563
3132
  // theme toggle