fwdloop 0.19.1 → 0.21.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.
Files changed (68) hide show
  1. package/README.md +2 -0
  2. package/bin/fwdloop +22 -13
  3. package/package.json +1 -1
  4. package/src/audit-fold.js +177 -0
  5. package/src/authoring.js +24 -4
  6. package/src/books.js +4 -3
  7. package/src/closers.js +49 -2
  8. package/src/ctx-tools.js +1 -1
  9. package/src/diary.js +49 -0
  10. package/src/flow.js +218 -2
  11. package/src/flowmodel.js +42 -5
  12. package/src/jobkey.js +25 -0
  13. package/src/jsonl-append.js +29 -0
  14. package/src/model-step.js +103 -5
  15. package/src/monthly.js +3 -2
  16. package/src/panel/author.js +44 -18
  17. package/src/panel/authorcard.js +7 -13
  18. package/src/panel/authorflows.js +118 -24
  19. package/src/panel/authorresume.js +8 -4
  20. package/src/panel/authorstart.js +63 -18
  21. package/src/panel/authortrigger.js +250 -125
  22. package/src/panel/authorvalues.js +13 -2
  23. package/src/panel/data.js +279 -43
  24. package/src/panel/index.html +547 -150
  25. package/src/panel/needsyou.js +29 -0
  26. package/src/panel/scheduler.js +21 -22
  27. package/src/panel/server.js +30 -6
  28. package/src/primitives.js +44 -2
  29. package/src/provider.js +3 -2
  30. package/src/runner.js +58 -22
  31. package/src/runvalues.js +10 -2
  32. package/src/schedule.js +135 -0
  33. package/src/setup.js +0 -21
  34. package/src/summary-words.js +180 -7
  35. package/src/thinking.js +39 -0
  36. package/src/trigger-clock.js +18 -16
  37. package/src/trigger-files.js +37 -24
  38. package/src/trigger-line.js +6 -15
  39. package/src/try-checks.js +62 -0
  40. package/src/types.js +2 -1
  41. package/types/audit-fold.d.ts +54 -0
  42. package/types/authoring.d.ts +33 -2
  43. package/types/books.d.ts +17 -0
  44. package/types/ctx-tools.d.ts +1 -0
  45. package/types/diary.d.ts +57 -0
  46. package/types/flow.d.ts +106 -0
  47. package/types/flowmodel.d.ts +25 -3
  48. package/types/jobkey.d.ts +11 -0
  49. package/types/jsonl-append.d.ts +6 -0
  50. package/types/model-step.d.ts +4 -1
  51. package/types/panel/author.d.ts +47 -17
  52. package/types/panel/authorcard.d.ts +3 -6
  53. package/types/panel/authorflows.d.ts +38 -10
  54. package/types/panel/authorstart.d.ts +15 -2
  55. package/types/panel/authortrigger.d.ts +73 -41
  56. package/types/panel/authorvalues.d.ts +6 -0
  57. package/types/panel/data.d.ts +101 -19
  58. package/types/panel/needsyou.d.ts +20 -0
  59. package/types/runvalues.d.ts +5 -0
  60. package/types/schedule.d.ts +69 -0
  61. package/types/setup.d.ts +0 -19
  62. package/types/summary-words.d.ts +105 -2
  63. package/types/thinking.d.ts +31 -0
  64. package/types/trigger-clock.d.ts +8 -7
  65. package/types/trigger-files.d.ts +17 -10
  66. package/types/trigger-line.d.ts +16 -8
  67. package/types/try-checks.d.ts +55 -0
  68. package/types/types.d.ts +10 -1
@@ -245,6 +245,8 @@
245
245
  .wf-meta{font-size:12px;color:var(--text-dim);}
246
246
  .wf-sep{font-size:12px;color:var(--text-faint);}
247
247
  .hist-row.selected{border:2px solid var(--accent);border-radius:4px;}
248
+ /* M11 am10: the selected Inbox card wears the same blue overlay as a selected Jobs run card (.rl-sel); after .inbox-row.s1 so it wins over the amber fill */
249
+ .inbox-row.selected,.inbox-row.s1.selected{background:var(--rl-accent-bg-strong);}
248
250
  /* M11: the one runs list. Copied from docs/product/m11-runs-list-mock.html (the right box, "F - fwdloop"); only the class names carry the rl- prefix
249
251
  (the page already has .chip, .hint, .live ...), a card's lines clip with an ellipsis exactly as the mockup does (the full text is on the run page). */
250
252
  :root{--rl-accent-bg:rgba(122,162,247,.12);--rl-accent-bg-strong:rgba(122,162,247,.2);}
@@ -254,6 +256,8 @@
254
256
  div.rl-card:hover{border-color:var(--border);background:var(--panel2);}
255
257
  .rl-card.rl-sel,div.rl-card.rl-sel:hover{border:2px solid var(--accent);border-radius:4px;background:var(--rl-accent-bg-strong);}
256
258
  .rl-card:focus-visible,.rl-fold:focus-visible{outline:2px solid var(--accent);outline-offset:2px;}
259
+ /* M11 am13: a run card a search matched (in a job where an older run matched); not the selected look (no fill, a dashed accent frame) */
260
+ .rl-card.rl-hit{outline:2px dashed var(--accent);outline-offset:-2px;}
257
261
  .rl-card.rl-live{border-color:var(--amber);}
258
262
  .rl-card.rl-need{border-color:var(--accent);}
259
263
  .rl-l1{display:flex;gap:6px;align-items:center;min-width:0;overflow:hidden;}
@@ -263,6 +267,7 @@
263
267
  .rl-l2 .sign-word{color:var(--text);}
264
268
  .rl-dim{color:var(--text-dim);font-size:12px;flex:none;}
265
269
  .rl-faint{color:var(--text-faint);font-size:12px;}
270
+ .rl-rest{color:var(--text-faint);min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}
266
271
  .rl-cnt{color:var(--text-faint);font-size:inherit;flex:none;}
267
272
  .rl-runs{margin:6px 0 0 6px;padding-left:8px;border-left:2px solid var(--border);}
268
273
  .rl-runs .rl-card{background:var(--bg);}
@@ -307,19 +312,23 @@
307
312
  .ended-block{position:relative;border:1px solid var(--border-strong);padding:12px;margin-bottom:12px;background:var(--panel2);font-size:13px;}
308
313
  .ended-block.magenta{border-color:var(--magenta);}
309
314
  .ended-block.red{border-color:var(--red);}
310
- .ended-text.is-red{color:var(--red);}
315
+ .ended-text.is-red,.ended-label.is-red{color:var(--red);}
311
316
  .ended-block.green{border-color:var(--green);}
312
- .ended-block.amber{border-color:var(--amber);}
317
+ .ended-block.grey,.ended-block.stopped{border-color:var(--grey-dot);}
318
+ .ended-block.amber,.ended-block.expired,.ended-block.stuck{border-color:var(--amber);}
313
319
  .ended-row{display:flex;gap:10px;align-items:baseline;flex-wrap:wrap;margin-bottom:6px;}
314
320
  .ended-row:last-child{margin-bottom:0;}
315
321
  .ended-label{color:var(--text-faint);font-size:11px;letter-spacing:0.08em;min-width:84px;}
316
322
  .ended-text{flex:1 1 220px;min-width:0;overflow-wrap:anywhere;}
323
+ .audit-sched-start{padding:6px 10px;margin-bottom:8px;border:1px solid var(--border-strong);background:var(--panel2);font-size:12px;overflow-wrap:anywhere;}
317
324
  .when-sub{display:flex;gap:8px;flex-wrap:wrap;margin-top:6px;}
318
325
  .when-sub > *{flex:1 1 120px;min-width:0;}
319
326
  .when-sub[hidden]{display:none;}
320
327
  .summary-box{position:relative;border:1px solid var(--border-strong);padding:16px 12px 12px;margin-top:16px;background:var(--panel2);font-size:12px;}
321
328
  .summary-box.red{border-color:var(--red);}
322
- .summary-box.amber{border-color:var(--amber);}
329
+ .summary-box.green{border-color:var(--green);}
330
+ .summary-box.grey,.summary-box.stopped{border-color:var(--grey-dot);}
331
+ .summary-box.amber,.summary-box.expired,.summary-box.stuck{border-color:var(--amber);}
323
332
  .summary-box.magenta{border-color:var(--magenta);}
324
333
  .summary-box::before{content:"┤ SUMMARY ├";position:absolute;top:-10px;left:10px;background:var(--panel2);padding:0 6px;font-size:11px;color:var(--text-faint);letter-spacing:0.08em;}
325
334
  .summary-headline{font-weight:700;margin-bottom:8px;font-size:13px;}
@@ -387,6 +396,7 @@
387
396
  .filterbar .chips{gap:4px;margin-bottom:4px;}
388
397
  .chip.fchip{padding:3px 7px;min-height:28px;min-width:28px;font-size:12px;text-align:center;}
389
398
  .chip.fchip::before,.chip.fchip::after{content:"";}
399
+ /* M11 am20 item 4: the ◷ glyph is drawn smaller than ✓ and ✗ at the same font-size (a fallback font); this chip alone is scaled up to match. */
390
400
  .row-blocked{background:var(--red-bg);}
391
401
 
392
402
  /* hamr review #5/#6: Audit tab grouped-by-step sections. */
@@ -421,6 +431,9 @@
421
431
  .audit-fold-name{flex:0 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}
422
432
  .audit-fold-tail{flex:none;white-space:nowrap;}
423
433
  .audit-fold-dot{flex:none;}
434
+ /* the schedule head: the title word always shows in full; its long head words wrap instead */
435
+ .audit-group.audit-fold h4.audit-status-header > .audit-fold-name.keep{flex:none;overflow:visible;}
436
+ .audit-group.audit-fold h4.audit-status-header > .audit-fold-tail.wrap{flex:0 1 auto;min-width:0;white-space:normal;overflow-wrap:anywhere;}
424
437
  .audit-group.audit-fold h4.audit-status-header::before{content:"\25B6 ";color:var(--text-faint);}
425
438
  .audit-group.audit-fold h4.audit-status-header[aria-expanded="true"]::before{content:"\25BC ";}
426
439
  .audit-group.audit-fold h4.audit-status-header::after{content:none;}
@@ -441,6 +454,24 @@
441
454
  }
442
455
  .audit-group.audit-fold table{margin-top:8px;}
443
456
  .audit-group.audit-fold table[hidden]{display:none !important;}
457
+ /* M4d am29 (design lab C): the step fold's body - tally, a line per try with its checks, then the Round table. The marker ends the header. */
458
+ .audit-fold-body[hidden]{display:none !important;}
459
+ .audit-fold-body{margin-top:8px;font-size:12px;min-width:0;max-width:100%;}
460
+ .audit-fold-who{flex:none;margin-left:auto;font-weight:700;font-size:11px;white-space:nowrap;}
461
+ .audit-fold-who.model{color:var(--cyan);} .audit-fold-who.human{color:var(--magenta,#9854f1);}
462
+ .audit-tally{color:var(--text-dim);margin:2px 0 4px;}
463
+ .audit-try{margin:4px 0 2px;overflow-wrap:anywhere;}
464
+ .audit-checks{margin:2px 0 6px 14px;}
465
+ .audit-chk{overflow-wrap:anywhere;}
466
+ .audit-chk > span{margin-right:6px;}
467
+ .audit-chk .src,.audit-judged{color:var(--text-faint);}
468
+ .audit-fold-label{color:var(--text-faint);text-transform:uppercase;font-size:10px;letter-spacing:.05em;margin-top:8px;}
469
+ .audit-fold-body table.rounds-table{width:100%;border-collapse:collapse;margin-top:4px;}
470
+ .audit-fold-body table.rounds-table th{position:sticky;top:0;z-index:1;}
471
+ .audit-fold-body table.rounds-table tr.trysep td{border-top:1px solid var(--border-strong);}
472
+ .rounds-pager{color:var(--text-faint);font-size:11px;margin-top:4px;display:flex;gap:10px;align-items:center;flex-wrap:wrap;}
473
+ .step-card .step-head .who{font-weight:700;font-size:11px;}
474
+ .step-card .step-head .who.model{color:var(--cyan);} .step-card .step-head .who.human{color:var(--magenta,#9854f1);}
444
475
  /* hamr's 2026-09-27 review: the group header's own state word (g.state,
445
476
  rendered as a <span class="badge STATE">) and its per-try marks
446
477
  (<span class="mark STATE">) reuse the SAME color vocabulary the runs
@@ -691,6 +722,12 @@
691
722
  }
692
723
  td.am-detail .am-d{margin:0 0 3px;}
693
724
  td.am-detail .am-d b{color:var(--text);font-weight:600;}
725
+ /* the Round table keeps its real table layout on a phone and scrolls inside its own box (.audit-table-scroll), never the page */
726
+ .audit-group table.rounds-table{display:table;width:max-content;min-width:100%;max-width:none;}
727
+ .audit-group table.rounds-table thead{position:static;width:auto;height:auto;overflow:visible;clip:auto;white-space:normal;}
728
+ .audit-group table.rounds-table tbody{display:table-row-group;}
729
+ .audit-group table.rounds-table tr{display:table-row;padding:0;overflow:visible;}
730
+ .audit-group table.rounds-table td{display:table-cell;padding:4px 6px;white-space:normal;overflow-wrap:anywhere;border-right:1px dotted var(--border);}
694
731
  }
695
732
 
696
733
  /* M4d piece 4: the Settings view (a sibling of #main-view, opened from the header). Layout borrowed from bareloop:
@@ -974,15 +1011,24 @@
974
1011
  <div class="hint" id="jf-run-empty" data-testid="jf-run-empty"></div>
975
1012
  <div class="jf-err" id="jf-err-flow" data-testid="jf-err-flow"></div>
976
1013
  </div>
977
- <div class="field dimmed" data-testid="jf-run-job-field">
978
- <label>The job</label>
1014
+ <div class="field" data-testid="jf-run-job-field">
1015
+ <label for="jf-run-jobbox">The job</label>
1016
+ <div class="jf-gutbox" id="jf-run-jobwrap" hidden>
1017
+ <div class="jf-gut" id="jf-run-jobbox-gut" data-testid="jf-run-jobbox-gut" aria-hidden="true"><div class="jf-gut-in"></div></div>
1018
+ <textarea class="jf-wrap" id="jf-run-jobbox" rows="6" data-testid="jf-run-jobbox" autocomplete="off" spellcheck="false" hidden></textarea>
1019
+ </div>
979
1020
  <div class="ro-lines" id="jf-run-job" data-testid="jf-run-job"></div>
1021
+ <div class="jf-err" id="jf-err-run-job" data-testid="jf-err-run-job"></div>
1022
+ <div class="hint" id="jf-run-job-hint" data-testid="jf-run-job-hint">Change anything here. A changed job line, guardrail, ask or step drafts a new workflow; a changed destination, cap, wait or model signs a new run; new files just run.</div>
980
1023
  <div class="hint" id="jf-run-model" data-testid="jf-run-model"></div>
981
1024
  <select id="jf-run-pick" data-testid="jf-run-pick" aria-label="Model to run this job with" hidden disabled><option value="">Reading your models…</option></select>
982
1025
  <div class="jf-err" id="jf-err-run-model" data-testid="jf-err-run-model"></div>
983
- <div class="hint">Fixed by the signature (the steps, the job lines and the asks). To change them, edit the job: the AI drafts a new plan, and signing it replaces this job.</div>
984
- <button class="btn" type="button" id="jf-run-edit" data-testid="jf-run-edit">Edit this job</button>
985
- <div class="hint" id="jf-run-edit-why" data-testid="jf-run-edit-why"></div>
1026
+ </div>
1027
+ <div class="field" id="jf-run-newname-field" data-testid="jf-run-newname-field" hidden>
1028
+ <label for="jf-run-newname">Name of the new workflow</label>
1029
+ <input id="jf-run-newname" type="text" autocomplete="off" spellcheck="false" data-testid="jf-run-newname">
1030
+ <div class="hint">A changed job is a new workflow. This is the next free name; type another if you like.</div>
1031
+ <div class="jf-err" id="jf-err-run-flowName" data-testid="jf-err-run-flowName"></div>
986
1032
  </div>
987
1033
  <div class="field">
988
1034
  <label for="jf-run-dest">Destination</label>
@@ -1111,18 +1157,21 @@
1111
1157
  — the wide right pane is where the evidence lives now. The
1112
1158
  answer doors are in the Ask tab, not here (M4b). -->
1113
1159
  <div id="inbox-list" data-testid="inbox-list"></div>
1160
+ <div id="inbox-filters">
1114
1161
  <div class="rl-dash"></div>
1115
1162
  <div class="rl-faint" data-testid="inbox-filter-note">filters below act on answered and expired only</div>
1116
1163
  <div id="inbox-filterbar-anchor"></div>
1164
+ </div>
1117
1165
  <div id="inbox-list-old" data-testid="inbox-list-old"></div>
1118
1166
  </section>
1119
1167
 
1120
1168
  <section id="panel-runs" class="tabpanel" role="tabpanel" aria-labelledby="tab-runs" hidden>
1121
- <!-- M11: ONE list. Running now, Needs you and Scheduled are not filtered; the filters below act on Jobs and quiet jobs only. -->
1169
+ <!-- M11: ONE list. Running now and Needs you are never filtered and sit above the grey line; Scheduled (the search also finds it, am17; the ◷ chip shows only it, am19) sits BELOW the search box and chips, above Jobs (am20). -->
1122
1170
  <div id="rl-top" data-testid="rl-top"></div>
1123
1171
  <div class="rl-dash"></div>
1124
- <div class="rl-faint" data-testid="rl-filter-note">filters below act on Jobs and quiet jobs only</div>
1172
+ <div class="rl-faint" data-testid="rl-filter-note">search also finds Scheduled; ◷ shows only Scheduled</div>
1125
1173
  <div id="runs-filterbar-anchor"></div>
1174
+ <div id="rl-sched" data-testid="rl-sched"></div>
1126
1175
  <div id="wf-list" data-testid="wf-list"></div>
1127
1176
  </section>
1128
1177
 
@@ -1154,12 +1203,11 @@
1154
1203
  <div id="run-content" hidden>
1155
1204
  <div id="summary-blocks" data-testid="summary-blocks">
1156
1205
  <div id="ended-block" class="ended-block" data-testid="ended-block" hidden></div>
1157
- <div id="sched-block" class="ended-block" data-testid="sched-block" hidden></div>
1158
1206
  <div class="hint" id="catchup-note" data-testid="catchup-note" hidden></div>
1159
1207
  </div>
1160
1208
  <div class="run-actions" id="run-actions" data-testid="run-actions" hidden></div>
1161
1209
  <div class="counters" id="run-counters" data-testid="live-counters"></div>
1162
- <div class="summary-box" id="run-summary" data-testid="run-summary"></div>
1210
+ <div class="summary-box" id="summary-box" data-testid="summary-box"></div>
1163
1211
  <div class="map-box" data-testid="step-map" id="map-box"><div id="map-mount"></div></div>
1164
1212
  <div id="step-list"></div>
1165
1213
  </div>
@@ -1222,7 +1270,14 @@
1222
1270
  <div class="job-card" id="job-card" hidden data-testid="job-card-readonly">
1223
1271
  <h4 id="details-title">Job card — signed</h4>
1224
1272
  <div class="hint" id="details-jobfrom" data-testid="details-jobfrom"></div>
1225
- <div class="field"><label>Model</label><div class="ro-value" id="details-model">—</div></div>
1273
+ <!-- M4d am28: Model and Thinking side by side on one row (.field-row, the paired-field row bareloop's Job tab uses for its caps) -->
1274
+ <div class="field-row">
1275
+ <div class="field"><label>Model</label><div class="ro-value" id="details-model">—</div></div>
1276
+ <div class="field" id="details-thinking-field"><label>Thinking</label><div class="ro-value" id="details-thinking" data-testid="details-thinking">—</div></div>
1277
+ </div>
1278
+ <!-- M9 am6: how this run began, then the workflow's schedule now; both are words built on the server (src/summary-words.js) -->
1279
+ <div class="field"><label>Started</label><div class="ro-value" id="details-started" data-testid="details-started">—</div></div>
1280
+ <div class="field"><label>Schedule</label><div class="ro-value" id="details-schedule" data-testid="details-schedule">—</div></div>
1226
1281
  <!-- am41 item 6: the same "The job" label the Chat card carries, over the signed lines -->
1227
1282
  <div class="field" style="margin-bottom:0"><label id="details-job-title">The job</label></div>
1228
1283
  <!-- M4e amendment 37: ONE column. #details-prose holds one wrapper per signed line (the line, its ~ rows, its steps folded under it);
@@ -1666,6 +1721,7 @@
1666
1721
  // book-derived list, never guessed from `primitives` by exclusion.
1667
1722
  toolsTotal: s.toolsTotal || null, toolsWhy: s.toolsWhy || null, ungranted: s.ungranted || [],
1668
1723
  stoppedReason: s.stoppedReason || null,
1724
+ who: s.who || null, newLine: typeof s.newLine === "string" ? s.newLine : "\u2014", lastAnswerAt: s.lastAnswerAt || null,
1669
1725
  state: s.groupState || "pending", // the server's one decider (deriveStepGroupState); no group = no row yet = not started
1670
1726
  };
1671
1727
  });
@@ -1758,23 +1814,29 @@
1758
1814
  ((result && result.asks) || []).forEach(function(a){ if(a.waiting || a.stuck || (!a.open && a.reopen)) found = a; });
1759
1815
  return found;
1760
1816
  }
1761
- function openRunFromRuns(r, rowEl){
1762
- selectRun(r.flow, r.runId, rowEl, ".hist-row");
1763
- document.getElementById("tab-run").click();
1764
- scrollRunIntoViewMobile();
1765
- getJSON("/api/runs/" + encodeURIComponent(r.flow) + "/" + encodeURIComponent(r.runId) + "/asks").then(function(result){
1817
+ // The ONE place that judges a click from that run's fresh asks. `rightTab` is where the right side lands when the
1818
+ // run is at an ask: the Jobs run card says "tab-ask" (its buttons are there); a Needs you card says "tab-run" (M11 am10).
1819
+ function followAsk(flow, runId, rightTab){
1820
+ getJSON("/api/runs/" + encodeURIComponent(flow) + "/" + encodeURIComponent(runId) + "/asks").then(function(result){
1766
1821
  // the user already clicked another run: this answer is for a run they left
1767
- if(currentFlow !== r.flow || currentRunId !== r.runId) return;
1822
+ if(currentFlow !== flow || currentRunId !== runId) return;
1768
1823
  var ask = askNeedingYou(result);
1769
1824
  if(!ask) return;
1770
1825
  reloadLists();
1771
- var inboxId = "inbox-row-" + r.flow + "-" + r.runId + "-" + ask.askId;
1826
+ var inboxId = "inbox-row-" + flow + "-" + runId + "-" + ask.askId;
1772
1827
  var inboxRow = Array.prototype.find.call(document.querySelectorAll(".inbox-row"), function(el){ return el.getAttribute("data-testid") === inboxId; }) || null;
1773
- selectRun(r.flow, r.runId, inboxRow, ".inbox-row", ask.askId);
1828
+ selectRun(flow, runId, inboxRow, ".inbox-row", ask.askId);
1774
1829
  document.getElementById("tab-inbox").click();
1775
- document.getElementById("tab-ask").click();
1830
+ if(inboxRow && inboxRow.scrollIntoView) inboxRow.scrollIntoView({ block: "nearest" }); // the card is in focus; a rebuild keeps the list's scroll (withScrollPreserved)
1831
+ document.getElementById(rightTab).click();
1776
1832
  }).catch(function(){ /* unreadable books: the run stays open on the Run tab, the left side stays on Runs */ });
1777
1833
  }
1834
+ function openRunFromRuns(r, rowEl){
1835
+ selectRun(r.flow, r.runId, rowEl, ".hist-row");
1836
+ document.getElementById("tab-run").click();
1837
+ scrollRunIntoViewMobile();
1838
+ followAsk(r.flow, r.runId, "tab-ask");
1839
+ }
1778
1840
 
1779
1841
  // ---- Jobs: groups the ONE /api/runs payload by flow name client-side. Runs arrive in
1780
1842
  // the server's order within a flow (listRuns), so the first run seen for a flow is its head.
@@ -1836,14 +1898,14 @@
1836
1898
  }
1837
1899
 
1838
1900
  // ---- M11: ONE runs list (docs/wiki/the-module-ladder.md "M11 scope", amendments 1 and 2; docs/product/m11-runs-list-mock.html, the right box).
1839
- // Top to bottom: Running now, Needs you, Scheduled (never filtered), a dashed line and the filters (they act on Jobs and quiet jobs only), Jobs, the
1901
+ // Top to bottom: Running now, Needs you (never filtered), a dashed line, the search box and chips, Scheduled (am20: the search narrows it), Jobs, the
1840
1902
  // quiet fold. The page works out NOTHING: `live`, the Needs-you tag (`needs`), the job order and quiet split (`jobs`), the Scheduled cards and the two
1841
1903
  // limits all come from GET /api/runs (src/panel/data.js). `rlModel` is pure (payload in, cards out); the rl*Html functions only draw it.
1842
1904
  var rlData = { rows: [], jobs: [], scheduled: [], limits: { quietDays: 0, olderRuns: 0 } };
1843
1905
  // manual fold memory, keyed by flow ("__quiet" is the quiet fold): a per-viewer convenience, reset on reload. A manual click wins over an automatic open.
1844
1906
  var rlOpen = {};
1845
1907
  // the last markup written into each box: an identical repaint (every poll) writes nothing, so focus, scroll and a half-read card survive it
1846
- var rlLast = { top: null, jobs: null };
1908
+ var rlLast = { top: null, sched: null, jobs: null };
1847
1909
  // The ONE writer of `rlData`: the whole /api/runs payload, as the server sent it.
1848
1910
  function setRunsData(r){
1849
1911
  rlData = { rows: r.rows || [], jobs: r.jobs || [], scheduled: r.scheduled || [], limits: r.limits || rlData.limits };
@@ -1856,21 +1918,23 @@
1856
1918
  return (place[a.flow] ? place[a.flow].at : Infinity) - (place[b.flow] ? place[b.flow].at : Infinity);
1857
1919
  }).map(function(g){
1858
1920
  var quiet = !!(place[g.flow] && place[g.flow].quiet);
1859
- if(g.lastRunId === null) return { flow: g.flow, group: g, head: g.lastRow, empty: true, quiet: quiet, selected: false, count: 0, sel: sel, older: { open: false, shown: [], hidden: 0, total: 0 } };
1921
+ if(g.lastRunId === null) return { flow: g.flow, group: g, head: g.lastRow, empty: true, quiet: quiet, selected: false, count: 0, sel: sel, older: { open: false, hits: [], shown: [], hidden: 0, left: [], active: active, total: 0 } };
1860
1922
  var head = g.runs[0];
1861
1923
  var matching = active ? filterRuns(g.runs, filters, Date.now()) : g.runs;
1862
1924
  var older = g.runs.slice(1);
1863
1925
  var isSel = function(r){ return sel.flow === g.flow && r.runId === sel.runId; };
1864
- // the fold is capped; past the cap only the selected run stays, plus (search or filter active) the ONE newest older run that matches (when it is past the cap)
1865
- var past = older.slice(limits.olderRuns);
1866
- var firstMatch = active ? older.filter(function(r){ return matching.indexOf(r) !== -1; })[0] : undefined;
1867
- var shown = older.slice(0, limits.olderRuns).concat(past.filter(function(r){ return isSel(r) || r === firstMatch; }));
1926
+ // M11 am5 item 4: the fold is capped at limits.olderRuns, newest first. With a search or chip on, only the older runs that match count; the selected run stays shown either way.
1927
+ var pool = active ? older.filter(function(r){ return matching.indexOf(r) !== -1; }) : older;
1928
+ var top = pool.slice(0, limits.olderRuns);
1929
+ var shown = top.concat(older.filter(function(r){ return isSel(r) && top.indexOf(r) === -1; }));
1930
+ var left = pool.filter(function(r){ return shown.indexOf(r) === -1; });
1868
1931
  // the fold opens by itself when any older run matches (even if the head matches too), or when the selected run is an older one
1869
- var auto = (active && older.some(function(r){ return matching.indexOf(r) !== -1; })) || older.some(isSel);
1932
+ var olderHit = active && older.some(function(r){ return matching.indexOf(r) !== -1; });
1933
+ var auto = olderHit || older.some(isSel);
1870
1934
  return {
1871
1935
  flow: g.flow, group: g, head: head, empty: false, quiet: quiet, count: g.runCount, sel: sel,
1872
1936
  selected: g.runs.some(isSel),
1873
- older: { open: Object.prototype.hasOwnProperty.call(open, g.flow) ? open[g.flow] : auto, shown: shown, hidden: older.length - shown.length, total: older.length },
1937
+ older: { open: Object.prototype.hasOwnProperty.call(open, g.flow) ? open[g.flow] : auto, hits: olderHit ? matching : [], shown: shown, hidden: left.length, left: left, active: active, total: older.length },
1874
1938
  };
1875
1939
  });
1876
1940
  var quietCards = cards.filter(function(c){ return c.quiet; });
@@ -1892,33 +1956,48 @@
1892
1956
  function rlJumpCardHtml(r, need){
1893
1957
  var cost = r.spend || "unknown";
1894
1958
  var faint = r.startedAt ? '<span data-rl-since="' + escapeXml(r.startedAt) + '"></span>' : 'time unknown';
1895
- return '<button class="rl-card ' + (need ? 'rl-need' : 'rl-live') + '" type="button" data-rl-jump="' + escapeXml(r.flow + "|" + r.runId) + '" data-testid="rl-' + (need ? 'need' : 'live') + '-' + escapeXml(r.flow) + '-' + escapeXml(r.runId) + '">' +
1896
- '<span class="rl-l1"><span class="' + dotClass(r.glyph, r.pulse) + '"></span><span class="rl-nm" title="' + escapeXml(r.flow) + '">' + escapeXml(r.flow) + '</span> <span class="rl-rn">' + escapeXml(r.runId) + '</span>' +
1897
- (need ? '<span class="rl-pill rl-pill-need">' + escapeXml(r.needs) + '</span>' : ' <span class="rl-faint">' + faint + ' &middot; ' + escapeXml(cost) + '</span>') + '</span>' +
1959
+ return '<button class="rl-card ' + (need ? 'rl-need' : 'rl-live') + '" type="button" data-rl-jump="' + escapeXml(r.flow + "|" + r.runId) + '"' + (need ? ' data-rl-need="1"' : '') + ' data-testid="rl-' + (need ? 'need' : 'live') + '-' + escapeXml(r.flow) + '-' + escapeXml(r.runId) + '">' +
1960
+ '<span class="rl-l1"><span class="' + dotClass(r.glyph, r.pulse) + '"></span><span class="rl-nm" title="' + escapeXml(r.flow) + '">' + escapeXml(r.flow) + '</span> <span class="rl-rest">&middot;</span> <span class="rl-rn">' + escapeXml(r.runId) + '</span>' + // M11 am12: job, a middle dot, run-N (Running now and Needs you only)
1961
+ (need ? '<span class="rl-pill rl-pill-need">' + escapeXml(r.needs) + '</span>' : ' <span class="rl-rest">&middot; ' + faint + ' &middot; ' + escapeXml(cost) + '</span>') + '</span>' +
1898
1962
  '<span class="rl-l2">' + escapeXml(r.label || "unknown") + (need ? ' &middot; ' + escapeXml(runAtText(r)) : '') + '</span></button>';
1899
1963
  }
1900
1964
  // Scheduled: a click does what Running now does (rlJump to the job's newest run, `runId` from the server). `at` / `in` are null when the job has no next clock time (a file trigger): nothing is made up.
1901
1965
  // A job with no run has nothing to open: that card stays a plain box.
1902
1966
  function rlScheduledCardHtml(s){
1903
1967
  var body = '<span class="rl-l1"><span class="dot grey"></span><span class="rl-nm" title="' + escapeXml(s.flow) + '">' + escapeXml(s.flow) + '</span>' +
1904
- (s.at ? ' <span class="rl-faint">' + escapeXml(s.at) + '</span>' : '') + '</span>' +
1968
+ (s.at ? ' <span class="rl-rest">&middot; ' + escapeXml(s.at) + '</span>' : '') + '</span>' +
1905
1969
  '<span class="rl-l2">' + escapeXml([s.in, s.words].filter(function(x){ return x; }).join(" · ")) + '</span>';
1906
1970
  if(typeof s.runId !== "string" || s.runId === "") return '<div class="rl-card" data-testid="rl-sched-' + escapeXml(s.flow) + '">' + body + '</div>';
1907
1971
  return '<button class="rl-card" type="button" data-rl-jump="' + escapeXml(s.flow + "|" + s.runId) + '" data-testid="rl-sched-' + escapeXml(s.flow) + '">' + body + '</button>';
1908
1972
  }
1909
- function rlTopHtml(m){
1973
+ // M11 am17: the ONE search box narrows the Scheduled cards by job name (matchesSearch in nameOnly mode: a run number or a date word is skipped, so it narrows only Jobs).
1974
+ // The result and time chips never touch Scheduled. With the `scheduled` chip pressed and nothing matching, the list says so; otherwise an empty Scheduled draws nothing, header included.
1975
+ // M11 am20: Running now and Needs you only (never filtered); they sit above the search box. Scheduled is drawn by rlSchedHtml, below it.
1976
+ function rlTopHtml(m, filters){
1910
1977
  var h = "";
1911
1978
  if(m.running.length) h += rlSectHtml("Running now", m.running.length) + m.running.map(function(r){ return rlJumpCardHtml(r, false); }).join("");
1912
1979
  if(m.needs.length) h += rlSectHtml("Needs you", m.needs.length) + m.needs.map(function(r){ return rlJumpCardHtml(r, true); }).join("");
1913
- if(m.scheduled.length) h += rlSectHtml("Scheduled", m.scheduled.length) + m.scheduled.map(rlScheduledCardHtml).join("");
1914
1980
  return h;
1915
1981
  }
1982
+ // the Scheduled cards the search leaves (the ONE place that narrows them); the count line and rlSchedHtml both read it
1983
+ function rlSchedShown(scheduled, q){
1984
+ return (scheduled || []).filter(function(s){ return matchesSearch(s.flow, null, q, null, true); });
1985
+ }
1986
+ function rlSchedCountText(n){
1987
+ return "showing " + n + " scheduled job" + (n === 1 ? "" : "s");
1988
+ }
1989
+ function rlSchedHtml(m, filters){
1990
+ var shown = rlSchedShown(m.scheduled, filters && filters.search ? filters.search : "");
1991
+ if(shown.length) return rlSectHtml("Scheduled", shown.length) + shown.map(rlScheduledCardHtml).join("");
1992
+ if(filters && filters.scheduled === true) return '<div class="rl-hint">no scheduled job matches</div>';
1993
+ return "";
1994
+ }
1916
1995
  // a run card inside a job: `[sign] run-N date · model` / `word — why · $cost · wall`
1917
- function rlRunCardHtml(r, selected){
1996
+ function rlRunCardHtml(r, selected, hit){
1918
1997
  var why = (r.word === "passed" && r.glyph === "[✓]" && !r.line) ? "goal met" : r.line;
1919
1998
  var bits = [runSpendText(r), runWallText(r)].filter(function(b){ return b !== null && b !== undefined; });
1920
- return '<button class="rl-card' + (selected ? ' rl-sel' : '') + (r.live ? ' rl-live' : '') + '" type="button" data-rl-run="' + escapeXml(r.flow + "|" + r.runId) + '" data-testid="rl-run-' + escapeXml(r.flow) + '-' + escapeXml(r.runId) + '" aria-pressed="' + (selected ? 'true' : 'false') + '" title="' + escapeXml(r.flow + " (" + r.runId + ")") + '">' +
1921
- '<span class="rl-l1"><span class="' + dotClass(r.glyph, r.pulse) + '"></span><span class="rl-rn">' + escapeXml(r.runId) + '</span> <span class="rl-faint">' + escapeXml([runAtText(r), r.model].filter(function(b){ return b; }).join(" · ")) + '</span></span>' +
1999
+ return '<button class="rl-card' + (selected ? ' rl-sel' : (hit ? ' rl-hit' : '')) + (r.live ? ' rl-live' : '') + '" type="button" data-rl-run="' + escapeXml(r.flow + "|" + r.runId) + '" data-testid="rl-run-' + escapeXml(r.flow) + '-' + escapeXml(r.runId) + '" aria-pressed="' + (selected ? 'true' : 'false') + '" title="' + escapeXml(r.flow + " (" + r.runId + ")") + '">' +
2000
+ '<span class="rl-l1"><span class="' + dotClass(r.glyph, r.pulse) + '"></span><span class="rl-rn">' + escapeXml(r.runId) + '</span> <span class="rl-rest">&middot; ' + escapeXml([runAtText(r), r.model].filter(function(b){ return b; }).join(" · ")) + '</span></span>' +
1922
2001
  '<span class="rl-l2">' + signHtml(r.word, why, r.label) + ' &middot; ' + escapeXml(bits.join(" · ")) + '</span></button>';
1923
2002
  }
1924
2003
  // a job card: `[sign] job k runs` / `word · why` of its newest run, highlighted when the selected run is one of its runs; not clickable. Inside: the newest run's card, then the older-runs fold.
@@ -1930,14 +2009,37 @@
1930
2009
  }
1931
2010
  var why = (h.word === "passed" && h.glyph === "[✓]" && !h.line) ? "goal met" : h.line;
1932
2011
  var isSel = function(r){ return c.sel.flow === c.flow && r.runId === c.sel.runId; };
2012
+ var hits = c.older.hits;
1933
2013
  var out = top + '<span class="rl-l1"><span class="' + dotClass(h.glyph, h.pulse) + '"></span><span class="rl-nm" title="' + escapeXml(c.flow) + '">' + escapeXml(c.flow) + '</span> <span class="rl-cnt">&middot; ' + c.count + ' run' + (c.count === 1 ? '' : 's') + '</span></span>' +
1934
2014
  '<span class="rl-l2">' + signHtml(h.word, why, h.label, " &middot; ") + '</span>' +
1935
- '<div class="rl-runs">' + rlRunCardHtml(h, isSel(h));
2015
+ '<div class="rl-runs">' + rlRunCardHtml(h, isSel(h), hits.indexOf(h) !== -1);
1936
2016
  if(c.older.total > 0){
1937
2017
  out += '<button class="rl-fold" type="button" data-rl-fold="' + escapeXml(c.flow) + '" data-testid="rl-fold-' + escapeXml(c.flow) + '" aria-expanded="' + (c.older.open ? 'true' : 'false') + '">' + (c.older.open ? '▾' : '▸') + ' older runs (' + c.older.total + ')</button>';
1938
2018
  if(c.older.open){
1939
- out += c.older.shown.map(function(r){ return rlRunCardHtml(r, isSel(r)); }).join("");
1940
- if(c.older.hidden > 0) out += '<div class="rl-hint">(and ' + c.older.hidden + ' older: use search)</div>';
2019
+ out += c.older.shown.map(function(r){ return rlRunCardHtml(r, isSel(r), hits.indexOf(r) !== -1); }).join("");
2020
+ if(c.older.hidden > 0){
2021
+ // M11 am7 item 4 + am9, the line after the 7: the range of the hidden runs' real start days
2022
+ // (the time the card shows), the MIN to the MAX over ALL of `left` whatever its order: `k more older runs, MM/DD to MM/DD. Search to find one.`, or one day
2023
+ // `k more runs on MM/DD. Search to find one.`; searching, the same days with `matches` and `Add a date or run number to narrow it.` (one day: `Add a run number`). A hidden run with no date drops the date part; nothing is made up.
2024
+ var days = c.older.left.map(function(x){
2025
+ var w = x.at || x.askedAt || x.startedAt;
2026
+ var d = w ? new Date(w) : null;
2027
+ return d && !isNaN(d.getTime()) ? new Date(d.getFullYear(), d.getMonth(), d.getDate()) : null;
2028
+ });
2029
+ var md = function(d){ return ("0" + (d.getMonth() + 1)).slice(-2) + "/" + ("0" + d.getDate()).slice(-2); };
2030
+ var dated = days.indexOf(null) === -1 && days.length > 0;
2031
+ var lo = dated ? new Date(Math.min.apply(null, days)) : null, hi = dated ? new Date(Math.max.apply(null, days)) : null;
2032
+ var k = c.older.hidden;
2033
+ var one = dated && md(lo) === md(hi) && lo.getFullYear() === hi.getFullYear();
2034
+ var hint = c.older.active ?
2035
+ (!dated ? k + ' more matches. Add a date or run number to narrow it.' :
2036
+ one ? k + ' more matches on ' + md(lo) + '. Add a run number to narrow it.' :
2037
+ k + ' more matches, ' + md(lo) + ' to ' + md(hi) + '. Add a date or run number to narrow it.') :
2038
+ (!dated ? k + ' more older runs. Search to find one.' :
2039
+ one ? k + ' more runs on ' + md(lo) + '. Search to find one.' :
2040
+ k + ' more older runs, ' + md(lo) + ' to ' + md(hi) + '. Search to find one.');
2041
+ out += '<div class="rl-hint">' + hint + '</div>';
2042
+ }
1941
2043
  }
1942
2044
  }
1943
2045
  return out + '</div></div>';
@@ -1965,17 +2067,22 @@
1965
2067
  var groups = filterWorkflows(groupRunsByFlow(rlData.rows), filters, Date.now());
1966
2068
  var m = rlModel(rlData, groups, filters, rlData.limits, { flow: currentFlow, runId: currentRunId }, rlOpen);
1967
2069
  var topEl = document.getElementById("rl-top");
2070
+ var schedEl = document.getElementById("rl-sched");
1968
2071
  var listEl = document.getElementById("wf-list");
1969
- var top = rlTopHtml(m);
1970
- var jobs = rlJobsHtml(m);
2072
+ var top = rlTopHtml(m, filters);
2073
+ var sched = rlSchedHtml(m, filters);
2074
+ var jobs = filters.scheduled === true ? "" : rlJobsHtml(m); // M11 am17: the scheduled chip hides Jobs and the quiet fold
1971
2075
  if(top !== rlLast.top){ rlLast.top = top; withFocusPreserved(topEl, function(){ topEl.innerHTML = top; }); }
2076
+ if(sched !== rlLast.sched){ rlLast.sched = sched; withFocusPreserved(schedEl, function(){ schedEl.innerHTML = sched; }); }
1972
2077
  if(jobs !== rlLast.jobs){ rlLast.jobs = jobs; withFocusPreserved(listEl, function(){ listEl.innerHTML = jobs; }); }
1973
2078
  tickSince();
1974
2079
  }
1975
2080
  // Running now / Needs you / Scheduled click: select that run, show it on the Run tab and scroll its job card into view. (A run card inside a job is the old click, `openRunFromRuns`.)
1976
- function rlJump(flow, runId){
2081
+ // A Needs you card (`need`) also moves the left side to the Inbox when the run is at an ask (M11 am10); the right side stays on Run.
2082
+ function rlJump(flow, runId, need){
1977
2083
  selectRun(flow, runId, null, ".inbox-row");
1978
2084
  document.getElementById("tab-run").click();
2085
+ if(need) followAsk(flow, runId, "tab-run");
1979
2086
  paintRunsList();
1980
2087
  var card = document.getElementById("rl-job-" + flow);
1981
2088
  if(card && card.scrollIntoView) card.scrollIntoView({ block: "nearest" });
@@ -1997,7 +2104,7 @@
1997
2104
  var jump = t.closest("[data-rl-jump]");
1998
2105
  if(jump){
1999
2106
  var j = String(jump.getAttribute("data-rl-jump")).split("|");
2000
- rlJump(j[0], j[1]);
2107
+ rlJump(j[0], j[1], jump.getAttribute("data-rl-need") === "1");
2001
2108
  return;
2002
2109
  }
2003
2110
  var card = t.closest("[data-rl-run]");
@@ -2022,7 +2129,7 @@
2022
2129
  function filterBarHTML(scope, noSigns){
2023
2130
  return (
2024
2131
  '<div class="filterbar" data-scope="' + scope + '" data-testid="' + scope + '-filters">' +
2025
- '<input type="text" class="search-input" placeholder="' + (noSigns ? 'search job, run, status, question or reason…' : 'search flow or run id…') + '" ' +
2132
+ '<input type="text" class="search-input" placeholder="' + (noSigns ? 'search job, run, status, question or reason…' : 'job, run-23, or date 10/13') + '" ' +
2026
2133
  'id="' + scope + '-filter-search" data-testid="' + scope + '-filter-search" autocomplete="off">' +
2027
2134
  '<div class="chips" role="group" aria-label="Filter">' +
2028
2135
  (noSigns ?
@@ -2039,6 +2146,7 @@
2039
2146
  '<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>' +
2040
2147
  '<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>' +
2041
2148
  '<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>' +
2149
+ (noSigns ? '' : '<button class="chip fchip" type="button" aria-pressed="false" data-filter-group="view" data-filter-value="scheduled" title="scheduled jobs only" aria-label="scheduled jobs only" data-testid="chip-' + scope + '-scheduled">◷</button>') +
2042
2150
  '<button class="chip fchip" type="button" id="' + scope + '-filter-clear" data-testid="' + scope + '-filter-clear">clear</button>' +
2043
2151
  '</div>' +
2044
2152
  '<div class="hint" id="' + scope + '-filter-count" data-testid="' + scope + '-filter-count"></div>' +
@@ -2050,15 +2158,28 @@
2050
2158
  // OR within a group (an empty group array means "no filter" for that
2051
2159
  // group). `time` is single-select, default "all". `nowMs` is injectable
2052
2160
  // for tests. Field names (flow/runId/glyph/at) match a run row's own
2053
- // shape (src/panel/data.js's listRuns). Search is case-insensitive
2054
- // substring match on flow name AND runId.
2055
- function matchesSearch(flow, runId, query){
2056
- if(!query) return true;
2057
- var q = String(query).trim().toLowerCase();
2058
- if(!q) return true;
2161
+ // shape (src/panel/data.js's listRuns). M11 am5: the search splits at spaces and EVERY word must match, case-insensitive. A word shaped run-N is
2162
+ // that run exactly; a word shaped MM/DD, MM-DD or YYYY-MM-DD (a real day) is the run's LOCAL start day (`when`, the time the card shows; MM/DD = any year);
2163
+ // any other word (a part date like 10/1 too) is a substring of the flow name or the runId.
2164
+ function matchesSearch(flow, runId, query, when, nameOnly){
2165
+ var words = String(query || "").toLowerCase().replace(/[()]/g, "").split(/\s+/).filter(function(w){ return w; });
2166
+ if(!words.length) return true;
2059
2167
  var f = String(flow || "").toLowerCase();
2060
2168
  var r = String(runId || "").toLowerCase();
2061
- return f.indexOf(q) !== -1 || r.indexOf(q) !== -1;
2169
+ var d = when ? new Date(when) : null;
2170
+ var ok = d && !isNaN(d.getTime());
2171
+ return words.every(function(w){
2172
+ if(/^run-\d+$/.test(w)) return nameOnly ? true : r === w;
2173
+ var day = /^(?:(\d{4})-)?(\d\d)[-\/](\d\d)$/.exec(w);
2174
+ if(day && (day[1] ? w.charAt(4) === "-" && w.charAt(7) === "-" : w.charAt(2) === "/" || w.charAt(2) === "-")){
2175
+ var mo = Number(day[2]), da = Number(day[3]);
2176
+ if(mo >= 1 && mo <= 12 && da >= 1 && da <= 31){
2177
+ if(nameOnly) return true;
2178
+ return !!ok && d.getMonth() + 1 === mo && d.getDate() === da && (!day[1] || d.getFullYear() === Number(day[1]));
2179
+ }
2180
+ }
2181
+ return f.indexOf(w) !== -1 || (!nameOnly && r.indexOf(w) !== -1);
2182
+ });
2062
2183
  }
2063
2184
  function filterRuns(runs, filters, nowMs){
2064
2185
  nowMs = (typeof nowMs === "number") ? nowMs : Date.now();
@@ -2068,7 +2189,7 @@
2068
2189
  return (runs || []).filter(function(r){
2069
2190
  if(r.runId === null) return true; // the "this flow has no runs yet" row always shows
2070
2191
  if(rs.length && rs.indexOf(r.glyph) === -1) return false;
2071
- if(!matchesSearch(r.flow, r.runId, q)) return false;
2192
+ if(!matchesSearch(r.flow, r.runId, q, r.at || r.askedAt || r.startedAt)) return false;
2072
2193
  if(time !== "all"){
2073
2194
  var days = time === "7d" ? 7 : 30;
2074
2195
  var t = typeof r.at === "string" ? Date.parse(r.at) : NaN;
@@ -2088,7 +2209,7 @@
2088
2209
  function createFilterBar(opts){
2089
2210
  var scope = opts.scope;
2090
2211
  var storageKey = opts.storageKey;
2091
- var state = { results: [], time: "all", search: "" };
2212
+ var state = { results: [], time: "all", search: "", scheduled: false };
2092
2213
  var allItems = [];
2093
2214
 
2094
2215
  function load(){
@@ -2101,6 +2222,7 @@
2101
2222
  results: Array.isArray(parsed.results) ? parsed.results : [],
2102
2223
  time: typeof parsed.time === "string" ? parsed.time : "all",
2103
2224
  search: typeof parsed.search === "string" ? parsed.search : "",
2225
+ scheduled: parsed.scheduled === true,
2104
2226
  };
2105
2227
  }
2106
2228
  }
@@ -2113,7 +2235,7 @@
2113
2235
  document.querySelectorAll('.filterbar[data-scope="' + scope + '"] .chip[data-filter-group]').forEach(function(chip){
2114
2236
  var group = chip.getAttribute("data-filter-group");
2115
2237
  var value = chip.getAttribute("data-filter-value");
2116
- var active = group === "time" ? state.time === value : state.results.indexOf(value) !== -1;
2238
+ var active = group === "time" ? state.time === value : group === "view" ? state.scheduled : state.results.indexOf(value) !== -1;
2117
2239
  chip.setAttribute("aria-pressed", active ? "true" : "false");
2118
2240
  });
2119
2241
  var searchEl = document.getElementById(scope + "-filter-search");
@@ -2123,7 +2245,7 @@
2123
2245
  var filtered = opts.filterFn(allItems, state, Date.now());
2124
2246
  opts.applyFn(filtered);
2125
2247
  var countEl = document.getElementById(scope + "-filter-count");
2126
- if(countEl) countEl.textContent = "showing " + filtered.length + " of " + allItems.length + " " + (opts.noun || "runs");
2248
+ if(countEl) countEl.textContent = (opts.countFn && opts.countFn(state)) || ("showing " + filtered.length + " of " + allItems.length + " " + (opts.noun || "runs"));
2127
2249
  }
2128
2250
  document.querySelectorAll('.filterbar[data-scope="' + scope + '"] .chip[data-filter-group]').forEach(function(chip){
2129
2251
  chip.addEventListener("click", function(){
@@ -2131,6 +2253,8 @@
2131
2253
  var value = chip.getAttribute("data-filter-value");
2132
2254
  if(group === "time"){
2133
2255
  state.time = value; // single-select within time
2256
+ } else if(group === "view"){
2257
+ state.scheduled = !state.scheduled; // M11 am17: the scheduled chip, the one writer of state.scheduled
2134
2258
  } else {
2135
2259
  var idx = state.results.indexOf(value);
2136
2260
  if(idx === -1) state.results.push(value); else state.results.splice(idx, 1);
@@ -2143,7 +2267,7 @@
2143
2267
  var clearBtn = document.getElementById(scope + "-filter-clear");
2144
2268
  if(clearBtn){
2145
2269
  clearBtn.addEventListener("click", function(){
2146
- state = { results: [], time: "all", search: "" };
2270
+ state = { results: [], time: "all", search: "", scheduled: false };
2147
2271
  paint();
2148
2272
  save();
2149
2273
  apply();
@@ -2167,8 +2291,18 @@
2167
2291
  };
2168
2292
  }
2169
2293
 
2170
- // ONE filter bar, mounted between the unfiltered sections and Jobs (M11). It acts on Jobs and quiet jobs only: `runsFilterFn` keeps a job when ANY of its runs match.
2294
+ // ONE filter bar, mounted below the unfiltered sections (Running now, Needs you); Scheduled and Jobs sit below it (M11 am20). The search narrows Scheduled; the chips act on Jobs and quiet jobs only: `runsFilterFn` keeps a job when ANY of its runs match.
2171
2295
  document.getElementById("runs-filterbar-anchor").innerHTML = filterBarHTML("runs");
2296
+ // M11 am21: ◷'s ink is as tall as ✓'s, whatever font draws it. Canvas measureText of each chip's own font (works in a hidden tab) at 100px; ◷ gets the size that makes its ink match ✓'s.
2297
+ function fitChips(){
2298
+ var cv = document.createElement("canvas").getContext("2d");
2299
+ var ink = function(e){ var cs = getComputedStyle(e); cv.font = cs.fontWeight + " 100px " + cs.fontFamily; var m = cv.measureText(e.textContent); return m.actualBoundingBoxAscent + m.actualBoundingBoxDescent; };
2300
+ var ok = document.querySelector('[data-testid="chip-runs-res-pass"]'), sc = document.querySelector('[data-testid="chip-runs-scheduled"]');
2301
+ if(!ok || !sc || !ink(sc)) return;
2302
+ sc.style.fontSize = (parseFloat(getComputedStyle(ok).fontSize) * ink(ok) / ink(sc)) + "px";
2303
+ }
2304
+ window.fwdloopFitChips = fitChips;
2305
+ fitChips();
2172
2306
 
2173
2307
  function runsFilterFn(items, filters, nowMs){
2174
2308
  return filterWorkflows(groupRunsByFlow(items), filters, nowMs);
@@ -2181,9 +2315,10 @@
2181
2315
  storageKey: "fwdloop-panel-runs-filters",
2182
2316
  filterFn: runsFilterFn,
2183
2317
  applyFn: runsApplyFn,
2318
+ countFn: function(st){ return st.scheduled === true ? rlSchedCountText(rlSchedShown(rlData.scheduled, st.search).length) : null; }, // M11 am20: ◷ pressed, the line counts scheduled jobs
2184
2319
  });
2185
2320
  function currentRunsFilters(){
2186
- return runsFilterBar ? runsFilterBar.getState() : { results: [], time: "all", search: "" };
2321
+ return runsFilterBar ? runsFilterBar.getState() : { results: [], time: "all", search: "", scheduled: false };
2187
2322
  }
2188
2323
 
2189
2324
  // item 4: phone-only "scroll the run view into view" on row select, and
@@ -2217,26 +2352,24 @@
2217
2352
  // ---- M9 piece 6: the summary block, first thing on the run page. The sentences are CODE-OWNED on the server (`summary` of the run detail,
2218
2353
  // src/summary-words.js); this only paints them. ENDED / NEXT while a finished run; SCHEDULED / NEXT for a job with a trigger.
2219
2354
  // borrowed-from: bareloop src/panel/index.html@f845ee7 (renderEnded)
2220
- function summaryRows(a, b){
2221
- return '<div class="ended-row"><span class="ended-label">' + a[0] + '</span><span class="ended-text" data-testid="' + a[2] + '">' + escapeXml(a[1]) + '</span></div>' +
2222
- '<div class="ended-row"><span class="ended-label">' + b[0] + '</span><span class="ended-text" data-testid="' + b[2] + '">' + escapeXml(b[1]) + '</span></div>';
2355
+ // M9 am13: ONE framed box, rows `label | value`. Frame: red on a SCHEDULE problem (sm.schedule.red, the one owner is scheduleBlockOf), else the colour of the run's card (glyphClass; M9 am14). ENDED and NEXT text are never red; only a problem reddens SCHEDULE.
2356
+ function summaryRow(label, value, testid, red){
2357
+ var c = red ? ' is-red' : '';
2358
+ return '<div class="ended-row"><span class="ended-label' + c + '">' + label + '</span><span class="ended-text' + c + '"' + (testid ? ' data-testid="' + testid + '"' : '') + '>' + escapeXml(value) + '</span></div>';
2223
2359
  }
2224
2360
  function renderSummary(detail){
2225
2361
  var sm = detail.summary || {};
2226
- var ended = document.getElementById("ended-block");
2227
- var sched = document.getElementById("sched-block");
2362
+ var box = document.getElementById("ended-block");
2228
2363
  var note = document.getElementById("catchup-note");
2229
- if(sm.ended){
2230
- ended.hidden = false;
2231
- ended.className = "ended-block " + (detail.glyph === "[✓]" ? "green" : (detail.glyph === "[?]" ? "magenta" : ((detail.glyph === "[■]" || detail.glyph === "[!]") ? "amber" : "red")));
2232
- ended.innerHTML = summaryRows(["ENDED", sm.ended.reason, "ended-reason"], ["NEXT", sm.ended.next, "ended-next"]);
2233
- } else { ended.hidden = true; ended.innerHTML = ""; }
2234
- if(sm.scheduled){
2235
- sched.hidden = false;
2236
- sched.className = "ended-block" + (sm.scheduled.nextRed === true ? " red" : "");
2237
- sched.innerHTML = summaryRows(["SCHEDULED", sm.scheduled.text, "sched-text"], ["NEXT", sm.scheduled.next, "sched-next"]);
2238
- if(sm.scheduled.nextRed === true) sched.querySelector('[data-testid="sched-next"]').classList.add("is-red");
2239
- } else { sched.hidden = true; sched.innerHTML = ""; }
2364
+ var sc = sm.schedule || null;
2365
+ if(sm.ended || sc){
2366
+ var tone = glyphClass(detail.glyph); // M9 am14: the colour of that run's card in the runs list, one decider (its dot)
2367
+ if(sc && sc.red === true) tone = "red";
2368
+ box.hidden = false;
2369
+ box.className = "ended-block" + (tone ? " " + tone : "");
2370
+ box.innerHTML = (sm.ended ? summaryRow("ENDED", sm.ended.reason, "ended-reason") + summaryRow("NEXT", sm.ended.next, "ended-next") : "") +
2371
+ (sc ? summaryRow("SCHEDULE", sc.line1, "sched-line1", sc.red === true) + (sc.line2 ? summaryRow("", sc.line2, "sched-line2", sc.red === true) : "") : "");
2372
+ } else { box.hidden = true; box.innerHTML = ""; }
2240
2373
  note.hidden = !sm.catchUp;
2241
2374
  note.textContent = sm.catchUp || "";
2242
2375
  }
@@ -2270,8 +2403,8 @@
2270
2403
  document.getElementById("run-counters").innerHTML =
2271
2404
  escapeXml(spendText) + " of " + escapeXml(capText) + " cap &middot; " + escapeXml(wallText);
2272
2405
 
2273
- var box = document.getElementById("run-summary");
2274
- box.className = "summary-box " + (detail.glyph === "[✗]" ? "red" : ((detail.glyph === "[·]" || detail.glyph === "[▶]" || detail.glyph === "[II]") ? "amber" : (detail.glyph === "[?]" ? "magenta" : "")));
2406
+ var box = document.getElementById("summary-box");
2407
+ box.className = "summary-box " + glyphClass(detail.glyph); // M9 am19: the same colour rule as the frame above (glyphClass, the card dot's)
2275
2408
  var stepBoxes = buildStepBoxes(detail.steps);
2276
2409
  var stepsDone = stepBoxes.filter(function(s){ return s.state === "done"; }).length;
2277
2410
  var stepsText = stepBoxes.length === 0
@@ -2285,14 +2418,18 @@
2285
2418
  // read straight off detail.steps/detail.spendSummary, never re-derived
2286
2419
  // from a second, separately-fetched copy of the audit rows.
2287
2420
  var modelText = detail.model || (detail.modelWhy || "no model call recorded yet");
2421
+ // M9 am21/am22: the run's time follows its cost on the top line, after a middle dot like the cost's: the same number as the `took ...` line (one source, detail.wallMs); a finished run without one says so, never 0; a run still going or waiting shows none.
2422
+ var headTime = !runFinished(detail) ? "" : (typeof detail.wallMs === "number" ? duration(detail.wallMs) : "time not recorded");
2288
2423
  var closeText = closeClassSummaryText(detail.steps) || (detail.stepsWhy || "no steps recorded");
2289
2424
  box.innerHTML =
2290
- '<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>' +
2425
+ '<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>' + (headTime ? ' &middot; ' + escapeXml(headTime) : '') + '</div>' +
2291
2426
  '<div class="summary-row" data-testid="summary-model"><span class="sum-label">model:</span><span class="sum-val">' + escapeXml(modelText) + '</span></div>' +
2292
2427
  '<div class="summary-row"><span class="sum-label">steps:</span><span class="sum-val">' + stepsText + '</span></div>' +
2293
2428
  '<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>' +
2294
2429
  '<div class="summary-row" data-testid="summary-close"><span class="sum-label">close:</span><span class="sum-val">' + escapeXml(closeText) + '</span></div>' +
2295
- '<div class="summary-row" data-testid="summary-spend"><span class="sum-label">spend:</span><span class="sum-val">' + spendSummaryText(detail.spendSummary) + '</span></div>';
2430
+ '<div class="summary-row" data-testid="summary-spend"><span class="sum-label">spend:</span><span class="sum-val">' + spendSummaryText(detail.spendSummary) + '</span></div>' +
2431
+ '<div class="summary-row" data-testid="summary-calls"><span class="sum-label">calls:</span><span class="sum-val">' + escapeXml((detail.runLines && detail.runLines.calls) || "\u2014") + '</span></div>' +
2432
+ '<div class="summary-row" data-testid="summary-checks"><span class="sum-label">checks:</span><span class="sum-val">' + escapeXml((detail.runLines && detail.runLines.checks) || "\u2014") + '</span></div>';
2296
2433
 
2297
2434
  renderRunActions(detail);
2298
2435
  // amendment 7 item 2: the Draft is the first box of the Map (an arrow runs on to step 1); the steps keep their own numbers
@@ -2313,6 +2450,8 @@
2313
2450
  // unknown" row.
2314
2451
  if(box.attempts.length) card.appendChild(buildStepActionsLineEl(box, idx));
2315
2452
  else card.appendChild(textLineEl("hint", "not attempted yet", "step-card-actions-" + idx));
2453
+ // M4d am29 item 6: the one new line, the server's words (`—` with no record); a human step's answer time is formatted here, in the viewer's clock
2454
+ card.appendChild(textLineEl("step-meta", box.newLine + (box.who === "human" && box.lastAnswerAt ? " \u00b7 " + (new Date(box.lastAnswerAt).toLocaleTimeString()) : ""), "step-card-new-" + idx));
2316
2455
  // Amendment M4a-3 (hamr's request): "tools: read 3 · write 1" (this
2317
2456
  // step's own tool tally, `summarizeStepTools`) plus "allowed: read,
2318
2457
  // write" (the signed grant, unchanged from the old "granted:" line) —
@@ -2349,8 +2488,8 @@
2349
2488
  var el = document.getElementById("run-actions");
2350
2489
  var c = detail.controls || {};
2351
2490
  el.innerHTML = "";
2352
- // amendment 7 item 6: Run again sits first, with Stop and Resume — every run control in this one row
2353
- el.appendChild(makeButton("Run again", "run-again", function(){ if(window.fwdloopRunAgain) window.fwdloopRunAgain(detail); }));
2491
+ // M6 am7: Reuse workflow (the one door: it replaced Run again and Edit this job) sits first, with Stop and Resume — every run control in this one row
2492
+ el.appendChild(makeButton("Reuse workflow", "run-again", function(){ if(window.fwdloopRunAgain) window.fwdloopRunAgain(detail); }));
2354
2493
  // M9 am5 item 3: a scheduled job's Run tab offers the schedule's own door, next to Run again: the same route, the Run card showing When
2355
2494
  // M11 am3 item 1: a job with a green run and no schedule reads Schedule run (the server's `canSchedule`); the same door either way
2356
2495
  var schedDoor = function(){ if(window.fwdloopRunAgain) window.fwdloopRunAgain(detail); };
@@ -2381,6 +2520,9 @@
2381
2520
  } else if(c.canResume){
2382
2521
  el.appendChild(makeButton("Resume", "run-resume", function(){ if(window.fwdloopOpenResume) window.fwdloopOpenResume(detail); }));
2383
2522
  }
2523
+ else if(c.noCopySay){ var nc = document.createElement("div"); nc.className = "answer-msg refused"; nc.setAttribute("data-testid", "run-no-copy-say"); nc.textContent = c.noCopySay; el.appendChild(nc); }
2524
+ // M11 am11 item 3: a stopped / stuck run in Needs you can leave it; the Run tab's own button, shown only when the server says it is removable
2525
+ if(detail.needsYou && detail.needsYou.removable) el.appendChild(makeRemoveNeedsButton(detail.flow, detail.runId, function(){ return reloadRun(detail.flow, detail.runId); }));
2384
2526
  if(stopSay){ var m = document.createElement("div"); m.className = "answer-msg refused"; m.setAttribute("data-testid", "run-stop-say"); m.textContent = stopSay.text; el.appendChild(m); }
2385
2527
  el.hidden = el.children.length === 0;
2386
2528
  }
@@ -2444,6 +2586,14 @@
2444
2586
  closeBadge.className = "badge cyan";
2445
2587
  closeBadge.textContent = closeClassLabel(box.closeClass);
2446
2588
  head.appendChild(closeBadge);
2589
+ // M4d am29 item 6: the same marker as the Audit header; only a step with a record has one
2590
+ if(box.who){
2591
+ var who = document.createElement("span");
2592
+ who.className = "who " + box.who;
2593
+ who.setAttribute("data-testid", "step-card-who-" + idx);
2594
+ who.textContent = foldWhoWords(box.who);
2595
+ head.appendChild(who);
2596
+ }
2447
2597
  return head;
2448
2598
  }
2449
2599
  // The actions line: "<time> · <cost> · [N tokens ·] try N <marks>" — every
@@ -2534,7 +2684,7 @@
2534
2684
  // hamr's 2026-09-27 review item (b): a jump from the Run tab must land
2535
2685
  // on an OPEN group even if a human had folded it — never scroll to a
2536
2686
  // collapsed section with nothing visible in it.
2537
- var table = row.querySelector("table");
2687
+ var table = row.querySelector("table, .audit-fold-body");
2538
2688
  var header = row.querySelector("h4");
2539
2689
  if(table && table.hidden){
2540
2690
  table.hidden = false;
@@ -2577,6 +2727,8 @@
2577
2727
  if(!Array.isArray(r.raw) || r.raw.length === 0) return "";
2578
2728
  return r.raw.map(function(t){ return "<div class=\"audit-raw\">" + escapeXml(String(t)) + "</div>"; }).join("");
2579
2729
  }
2730
+ // M4d am26: ` · thinking off` after a model try's verdict, the server's words (`r.thinkingPhrase`); nothing for a row that has none
2731
+ function auditThinkingHtml(r){ return typeof r.thinkingPhrase === "string" && r.thinkingPhrase.length > 0 ? " \u00b7 " + escapeXml(r.thinkingPhrase) : ""; }
2580
2732
  function buildAuditRowEl(r, includeStep){
2581
2733
  var tr = document.createElement("tr");
2582
2734
  var glyph = verdictGlyph(r.verdict, r.class);
@@ -2595,7 +2747,7 @@
2595
2747
  "<td data-label=\"Action\">" + escapeXml(actionText) + "</td>" +
2596
2748
  "<td data-label=\"Gap\">" + escapeXml(isRejectRow ? "" : auditGapText(r)) + auditRawHtml(r) + "</td>" +
2597
2749
  "<td data-label=\"Cost\">" + escapeXml(auditCostCellText(r)) + "</td>" +
2598
- "<td data-label=\"Verdict\"><span class=\"badge " + badgeClass + "\">" + escapeXml(word) + "</span></td>" +
2750
+ "<td data-label=\"Verdict\"><span class=\"badge " + badgeClass + "\">" + escapeXml(word) + "</span>" + auditThinkingHtml(r) + "</td>" +
2599
2751
  "<td data-label=\"Close\">" + escapeXml(auditCloseText(r)) + "</td>" +
2600
2752
  "<td data-label=\"Time\">" + auditTimeCellHtml(r) + "</td>" +
2601
2753
  // phone-only one-line cells (CSS shows these and hides the rest below 640px; hidden on desktop)
@@ -2604,7 +2756,10 @@
2604
2756
  "<td class=\"am am-time\">" + escapeXml(auditShortTime(r)) + "</td>" +
2605
2757
  "<td class=\"am am-detail\">" + auditDetailHtml(r, word, actionText, isRejectRow) + "</td>";
2606
2758
  tr.innerHTML = cells;
2607
- // every entry opens on a tap, by finger or keyboard; only the phone layout shows what opening reveals
2759
+ return wireAuditRowEl(tr);
2760
+ }
2761
+ // every entry opens on a tap, by finger or keyboard; only the phone layout shows what opening reveals. The ONE place a row gets its class and tap: the step sections and the schedule section both end here.
2762
+ function wireAuditRowEl(tr){
2608
2763
  tr.className = "audit-tap";
2609
2764
  tr.tabIndex = 0;
2610
2765
  tr.setAttribute("aria-expanded", "false");
@@ -2613,6 +2768,34 @@
2613
2768
  tr.addEventListener("keydown", function(ev){ if(ev.key === "Enter" || ev.key === " "){ ev.preventDefault(); toggle(); } });
2614
2769
  return tr;
2615
2770
  }
2771
+ // M9 am9 item 1: a schedule row in the Audit row family. Desktop: label | stamp | words (the Step, Action and Verdict cells, the same dotted cells as a step's table).
2772
+ // Phone: the same one line (glyph, label, words, time) and a tap opens the full words, through the same `.am-*` cells. `r` is the server's {label, stamp, text}.
2773
+ function buildAuditScheduleRowEl(r){
2774
+ var tr = document.createElement("tr");
2775
+ var shortStamp = (typeof r.stamp === "string" && r.stamp.length > 0) ? r.stamp : "\u2014"; // the signed `MM/DD HH:MM`, date included, at every width
2776
+ var cells = [
2777
+ ["", "Step", r.label], ["", "Action", r.stamp], ["", "Verdict", r.text],
2778
+ ["am am-glyph", null, "\u00b7"], ["am am-time", null, shortStamp],
2779
+ ["am am-detail", null, null]
2780
+ ];
2781
+ cells.forEach(function(c, i){
2782
+ var td = document.createElement("td");
2783
+ if(c[0]) td.className = c[0];
2784
+ if(c[1]) td.setAttribute("data-label", c[1]);
2785
+ if(c[0].indexOf("am-glyph") >= 0) td.setAttribute("aria-hidden", "true");
2786
+ if(c[2] === null){
2787
+ [["", r.label], ["when", r.stamp], ["words", r.text]].forEach(function(l){
2788
+ if(!l[1]) return;
2789
+ var d = document.createElement("div"); d.className = "am-d";
2790
+ if(l[0]){ var b = document.createElement("b"); b.textContent = l[0] + ":"; d.appendChild(b); d.appendChild(document.createTextNode(" ")); }
2791
+ d.appendChild(document.createTextNode(l[1])); td.appendChild(d);
2792
+ });
2793
+ } else td.textContent = c[2];
2794
+ tr.appendChild(td);
2795
+ if(i < cells.length - 1) tr.appendChild(document.createTextNode(" ")); // a gap between label, stamp and words in the text too
2796
+ });
2797
+ return wireAuditRowEl(tr);
2798
+ }
2616
2799
  // ---- hamr's 2026-09-27 exit-check review #2: the Audit tab's All/Human/
2617
2800
  // Blocked filter — ONE predicate, applied identically to the Grouped and
2618
2801
  // Flat views (never two separate filter implementations). "Human" reads
@@ -2662,6 +2845,7 @@
2662
2845
  if(g.draft) return draftLineText(g.summary);
2663
2846
  var line = [p.status, p.name, p.cost].join(" " + p.dot + " ");
2664
2847
  if(p.tries) line += " \u00b7 try " + p.tries.n + " " + p.tries.marks.join("");
2848
+ if(g.fold) line += " " + foldWhoWords(g.fold.who);
2665
2849
  return line;
2666
2850
  }
2667
2851
  // hamr's 2026-09-27 review: the header's status word gets the SAME color
@@ -2739,12 +2923,106 @@
2739
2923
  });
2740
2924
  }
2741
2925
  h4.appendChild(tail);
2926
+ // M4d am29 item 4: the header ends with who acted on the step; only a step with a fold (a run with records) has it
2927
+ if(g.fold){
2928
+ var who = document.createElement("span");
2929
+ who.className = "audit-fold-who " + g.fold.who;
2930
+ who.setAttribute("data-testid", "audit-group-who");
2931
+ who.textContent = foldWhoWords(g.fold.who);
2932
+ h4.appendChild(who);
2933
+ }
2742
2934
  return h4;
2743
2935
  }
2744
2936
  // Grouped view: one section per step, server order preserved (first-seen
2745
2937
  // order of `r.step` across this run's own rows — never re-sorted).
2746
2938
  // review item #1: COLLAPSED by default — a map/step-card click
2747
2939
  // (`openAuditGroup`) is the only thing that force-expands one.
2940
+ // M4d am29 (items 4-6): the step fold's words, all from the server's `fold` (src/audit-fold.js); this page only draws them.
2941
+ function foldWhoWords(who){ return who === "human" ? "[human \u00b7 ask]" : "[model]"; }
2942
+ function foldSize(n){ return n < 1024 ? n + " B" : (n < 1048576 ? (n / 1024).toFixed(1) + " KB" : (n / 1048576).toFixed(1) + " MB"); }
2943
+ function foldEl(tag, cls, text, testId){
2944
+ var e = document.createElement(tag);
2945
+ if(cls) e.className = cls;
2946
+ if(text !== null && text !== undefined) e.textContent = text;
2947
+ if(testId) e.setAttribute("data-testid", testId);
2948
+ return e;
2949
+ }
2950
+ function foldTryEl(t, human){
2951
+ var wrap = document.createElement("div");
2952
+ var line = foldEl("div", "audit-try", null, "audit-try-line");
2953
+ line.appendChild(document.createTextNode("try " + t.n + " "));
2954
+ line.appendChild(foldEl("span", "mark " + auditMarkClass(t.mark), t.mark));
2955
+ var rest = human
2956
+ ? [t.answer, t.about ? "about " + t.about : null]
2957
+ : [t.thinking, t.gap];
2958
+ rest.forEach(function(x){ if(x) line.appendChild(document.createTextNode(" \u00b7 " + x)); });
2959
+ wrap.appendChild(line);
2960
+ if(!human && t.checks && t.checks.length){
2961
+ var box = foldEl("div", "audit-checks", null, "audit-checks");
2962
+ t.checks.forEach(function(c){
2963
+ var row = foldEl("div", "audit-chk", null, "audit-check");
2964
+ row.appendChild(foldEl("span", "mark " + (c.ok ? "green" : "red"), c.ok ? "\u2713" : "\u2717"));
2965
+ row.appendChild(foldEl("span", null, "#" + c.n + " " + c.text + (c.result ? " (" + c.result + ")" : "")));
2966
+ row.appendChild(foldEl("span", "src", "\u00b7 from " + c.source));
2967
+ box.appendChild(row);
2968
+ });
2969
+ if(t.output){
2970
+ var sha = String(t.output.sha256);
2971
+ box.appendChild(foldEl("div", "audit-judged", "output judged: " + t.output.file + " \u00b7 " + foldSize(t.output.bytes) + " \u00b7 sha256 " + sha.slice(0, 4) + "\u2026" + sha.slice(-2), "audit-judged"));
2972
+ }
2973
+ wrap.appendChild(box);
2974
+ }
2975
+ return wrap;
2976
+ }
2977
+ var ROUNDS_PAGE = 20;
2978
+ function foldRowEl(r, prevTry){
2979
+ var tr = document.createElement("tr");
2980
+ if(prevTry !== null && r.try !== prevTry) tr.className = "trysep";
2981
+ [r.round === null || r.round === undefined ? "\u2014" : String(r.round), r.try === null || r.try === undefined ? "\u2014" : String(r.try), r.action, r.path || "\u2014", r.decision, auditShortTime(r)].forEach(function(t){
2982
+ tr.appendChild(foldEl("td", null, t));
2983
+ });
2984
+ return tr;
2985
+ }
2986
+ // the Round table, 20 rows at a time (bareloop's "showing A\u2013B of N" + load more), table scrolling inside its own box
2987
+ function foldRoundsEl(g){
2988
+ var rows = g.fold.rows || [];
2989
+ var wrap = document.createElement("div");
2990
+ wrap.appendChild(foldEl("div", "audit-fold-label", "rounds"));
2991
+ var scroll = foldEl("div", "audit-table-scroll");
2992
+ var table = document.createElement("table");
2993
+ table.className = "rounds-table";
2994
+ table.setAttribute("data-testid", "rounds-table-" + g.step);
2995
+ table.innerHTML = "<thead><tr><th>Round</th><th>Try</th><th>Action</th><th>Path</th><th>Decision</th><th>Time</th></tr></thead><tbody></tbody>";
2996
+ var tbody = table.querySelector("tbody");
2997
+ scroll.appendChild(table);
2998
+ wrap.appendChild(scroll);
2999
+ var pager = foldEl("div", "rounds-pager", null, "rounds-pager");
3000
+ wrap.appendChild(pager);
3001
+ var shown = 0;
3002
+ function more(){
3003
+ var to = Math.min(rows.length, shown + ROUNDS_PAGE);
3004
+ for(var i = shown; i < to; i += 1) tbody.appendChild(foldRowEl(rows[i], i === 0 ? null : rows[i - 1].try));
3005
+ shown = to;
3006
+ pager.innerHTML = "";
3007
+ pager.appendChild(foldEl("span", null, rows.length === 0 ? "no rows" : "showing 1\u2013" + shown + " of " + rows.length));
3008
+ if(shown < rows.length){
3009
+ var b = foldEl("button", "btn small", "load more", "rounds-load-more");
3010
+ b.type = "button";
3011
+ b.addEventListener("click", function(ev){ ev.stopPropagation(); more(); });
3012
+ pager.appendChild(b);
3013
+ }
3014
+ }
3015
+ more();
3016
+ return wrap;
3017
+ }
3018
+ function buildFoldBodyEl(g){
3019
+ var f = g.fold, human = f.who === "human";
3020
+ var body = foldEl("div", "audit-fold-body", null, "audit-fold-body-" + g.step);
3021
+ if(f.tally) body.appendChild(foldEl("div", "audit-tally", f.tally, "audit-tally"));
3022
+ (f.tries || []).forEach(function(t){ body.appendChild(foldTryEl(t, human)); });
3023
+ body.appendChild(foldRoundsEl(g));
3024
+ return body;
3025
+ }
2748
3026
  var auditExpanded = {}; // step -> true/false once a human toggled it; reset when the run changes
2749
3027
  var auditExpandedRun = null;
2750
3028
  function renderAuditGroups(result){
@@ -2756,6 +3034,46 @@
2756
3034
  var anyVisible = false;
2757
3035
  // amendment 7 item 2: the Draft is the first group, a normal card (collapsed by default); a run with no audit rows yet still has it
2758
3036
  var draftG = draftGroupFor(result);
3037
+ // M9 am9 / am11: the `schedule` section, first in the Audit of every run of a job that has a schedule; always folded on open; the words and the sign come from the server
3038
+ if(result.schedule){
3039
+ var sc = result.schedule;
3040
+ var sw = document.createElement("div");
3041
+ sw.className = "audit-group audit-fold closed";
3042
+ sw.setAttribute("data-testid", "audit-group-schedule");
3043
+ var sh = document.createElement("h4");
3044
+ sh.className = "audit-status-header";
3045
+ sh.setAttribute("role", "button"); sh.setAttribute("tabindex", "0"); sh.setAttribute("aria-expanded", "false");
3046
+ sh.style.cursor = "pointer";
3047
+ // M9 am23: sign + word (one badge, as a step header's), then `schedule`, then ` · ` and the parts. The word is the server's (`sc.word`, from SIGN_WORDS); no table here.
3048
+ var ssign = document.createElement("span");
3049
+ ssign.className = "badge sign-badge " + (sc.sign === "[\u25B6]" ? "amber" : sc.sign === "[\u2717]" ? "red" : "grey");
3050
+ ssign.setAttribute("data-testid", "audit-schedule-sign"); ssign.textContent = sc.word ? sc.sign + " " + sc.word : sc.sign; sh.appendChild(ssign);
3051
+ var sname = document.createElement("span"); sname.className = "audit-fold-name keep"; sname.textContent = "schedule"; sh.appendChild(sname);
3052
+ var slead = document.createElement("span"); slead.setAttribute("data-testid", "audit-schedule-lead"); slead.textContent = "\u00b7"; sh.appendChild(slead); // plain span: a phone keeps this dot (the signed header has it)
3053
+ var stail = document.createElement("span"); stail.className = "audit-fold-tail wrap"; stail.setAttribute("data-testid", "audit-schedule-head"); stail.textContent = sc.head; sh.appendChild(stail);
3054
+ var sl = document.createElement("table");
3055
+ sl.setAttribute("data-testid", "audit-table-schedule"); sl.hidden = true;
3056
+ sl.innerHTML = "<thead><tr><th>Row</th><th>When</th><th>What</th></tr></thead><tbody></tbody>";
3057
+ var sbody = sl.querySelector("tbody");
3058
+ sc.rows.forEach(function(r){ sbody.appendChild(buildAuditScheduleRowEl(r)); });
3059
+ function paintSched(open){ sl.hidden = !open; sw.classList.toggle("closed", !open); sh.setAttribute("aria-expanded", open ? "true" : "false"); }
3060
+ function toggleSched(){ var open = sl.hidden; auditExpanded["\u0000schedule"] = open; paintSched(open); } // folded on open; a re-render keeps what you chose for this run
3061
+ if(auditExpanded["\u0000schedule"] === true) paintSched(true);
3062
+ sh.addEventListener("click", toggleSched);
3063
+ sh.addEventListener("keydown", function(e){ if(e.key === "Enter" || e.key === " "){ e.preventDefault(); toggleSched(); } });
3064
+ sw.appendChild(sh); sw.appendChild(sl);
3065
+ container.appendChild(sw);
3066
+ anyVisible = true;
3067
+ }
3068
+ // M11 am11 items 3-4: why the card left Needs you, in the server's words
3069
+ if(result.needsLeft){
3070
+ var nrow = document.createElement("div");
3071
+ nrow.className = "audit-sched-start";
3072
+ nrow.setAttribute("data-testid", "audit-needs-left");
3073
+ nrow.textContent = result.needsLeft;
3074
+ container.appendChild(nrow);
3075
+ anyVisible = true;
3076
+ }
2759
3077
  var groups = (draftG ? [draftG] : []).concat(result.empty ? [] : (result.groups || []));
2760
3078
  groups.forEach(function(g){
2761
3079
  var rows = (g.rows || []).filter(auditRowMatchesFilter);
@@ -2790,12 +3108,20 @@
2790
3108
  header.style.cursor = "pointer";
2791
3109
  wrap.appendChild(header);
2792
3110
  if(noRecord){ container.appendChild(wrap); return; } // nothing to open: the header already says "no draft record"
2793
- var table = document.createElement("table");
2794
- table.hidden = !isOpen;
2795
- 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>";
2796
- var tbody = table.querySelector("tbody");
2797
- rows.forEach(function(r){ tbody.appendChild(buildAuditRowEl(r, false)); });
2798
- table.setAttribute("data-testid", "audit-table-grouped-" + g.step);
3111
+ // M4d am29: a step with a fold draws it (design lab C); a step without one (an older run, the Draft, the run's own group) keeps its table as before
3112
+ var table, tbody;
3113
+ if(g.fold){
3114
+ table = buildFoldBodyEl(g);
3115
+ table.hidden = !isOpen;
3116
+ rows = []; // a fold has no per-try table row to open with the group (`syncSingleRow` below leaves it alone)
3117
+ } else {
3118
+ table = document.createElement("table");
3119
+ table.hidden = !isOpen;
3120
+ 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>";
3121
+ tbody = table.querySelector("tbody");
3122
+ rows.forEach(function(r){ tbody.appendChild(buildAuditRowEl(r, false)); });
3123
+ table.setAttribute("data-testid", "audit-table-grouped-" + g.step);
3124
+ }
2799
3125
  wrap.appendChild(table);
2800
3126
  // M4c-fix amendment 2 (j): a step with exactly one try opens that try's detail with the group, closes with it
2801
3127
  // (the same `.open` tap-detail the row's own tap toggles; only the phone layout shows it).
@@ -2872,7 +3198,7 @@
2872
3198
  var content = document.getElementById("audit-content");
2873
3199
  lastAuditResult = result;
2874
3200
  // a run with no audit rows yet still has its Draft: say so in words, and show the card
2875
- var hasDraft = !!(result && result.draft);
3201
+ var hasDraft = !!(result && (result.draft || result.schedule || result.needsLeft));
2876
3202
  if(!result || (result.empty && !hasDraft)){
2877
3203
  empty.hidden = false;
2878
3204
  empty.textContent = (result && result.why) || "no audit rows for this run";
@@ -3021,6 +3347,9 @@
3021
3347
  document.getElementById("details-model").textContent = job.model
3022
3348
  ? ("model used: " + job.model + " (from this run's rows)")
3023
3349
  : (job.modelWhy || "no model call recorded yet");
3350
+ document.getElementById("details-thinking").textContent = typeof job.thinkingRule === "string" ? job.thinkingRule : "—";
3351
+ document.getElementById("details-started").textContent = job.started || "—";
3352
+ document.getElementById("details-schedule").textContent = job.schedule || "none";
3024
3353
  // M4e amendment 6 item 5 + amendment 7 item 4: "$<cap> per run · 1h wait · redo up to <n>"; several asks: "waits 1h, 30m", each through plainWait.
3025
3354
  // fwdloop has no run-wide time limit (each ask has its own wait), so no ask means no wait part at all.
3026
3355
  var waitParts = (job.asks || []).filter(function(ak){ return typeof ak.waitMs === "number"; }).map(function(ak){ return plainWait(ak.waitMs); });
@@ -3168,8 +3497,12 @@
3168
3497
  var openRunLive = true; // is the open run still changing? (true until its detail says otherwise)
3169
3498
  var wasHidden = false;
3170
3499
  // One writer of `openRunLive`: every paint of the open run's detail goes through here.
3500
+ // M9 am21: the ONE decider of a finished run ([✓] [✗] [■]); the open-run poll and the summary line's time both ask it.
3501
+ function runFinished(d){
3502
+ return !!d && (d.glyph === "[\u2713]" || d.glyph === "[\u2717]" || d.glyph === "[\u25A0]");
3503
+ }
3171
3504
  function paintRun(d){
3172
- openRunLive = !(d && (d.glyph === "[\u2713]" || d.glyph === "[\u2717]" || d.glyph === "[\u25A0]"));
3505
+ openRunLive = !runFinished(d);
3173
3506
  var next = sig(d);
3174
3507
  if(next !== null && next === lastSig.detail) return;
3175
3508
  lastSig.detail = next;
@@ -3448,6 +3781,7 @@
3448
3781
  el.innerHTML = "";
3449
3782
  old.innerHTML = "";
3450
3783
  document.getElementById("inbox-count-label").textContent = " (" + (typeof openCount === "number" ? openCount : 0) + ")";
3784
+ document.getElementById("inbox-filters").hidden = !inboxTotal; // am14: no rows, no dashed line, note or search/chips
3451
3785
  if(!inboxTotal){
3452
3786
  el.innerHTML = '<div class="hint">nothing waiting on you — no stops recorded under this root</div>';
3453
3787
  return;
@@ -3691,6 +4025,14 @@
3691
4025
  return reloadRun(ctx.flow, ctx.runId);
3692
4026
  }).then(function(){ if(root.isConnected) setBusy(root, false); });
3693
4027
  }
4028
+ // M11 am11 item 3: Remove from Needs you. One door for the Ask tab (expired ask) and the Run tab (stopped / stuck): the server writes the marker and changes nothing else.
4029
+ function makeRemoveNeedsButton(flow, runId, after){
4030
+ var b = makeButton("Remove from Needs you", "needs-remove", function(){
4031
+ b.disabled = true;
4032
+ postJSON("/api/needs-remove", { flow: flow, runId: runId }).then(function(){ reloadLists(); return after(); }).catch(function(){ b.disabled = false; });
4033
+ });
4034
+ return b;
4035
+ }
3694
4036
  function makeButton(label, testid, onClick){
3695
4037
  var b = document.createElement("button");
3696
4038
  b.type = "button";
@@ -3753,6 +4095,8 @@
3753
4095
  var bar3 = document.createElement("div");
3754
4096
  bar3.className = "actions-row";
3755
4097
  bar3.appendChild(makeButton("Reopen for another " + waitText(model.waitMs), "btn-reopen", function(){ sendReopen(root, ctx, ask.askId); }));
4098
+ // M11 am11 item 3: an expired-ask run that is in Needs you can leave it; the server (`needsYou.removable`) says so, never a live ask
4099
+ if(ctx.removable) bar3.appendChild(makeRemoveNeedsButton(ctx.flow, ctx.runId, function(){ return reloadRun(ctx.flow, ctx.runId); }));
3756
4100
  root.appendChild(bar3);
3757
4101
  root.appendChild(textDiv("hint", model.line));
3758
4102
  } else if(model.kind === "stuck"){
@@ -3903,7 +4247,7 @@
3903
4247
  // One block per signed ask line (M4c item 5), drawn from the server's `blocks`.
3904
4248
  function renderAskRow(block, expanded, ctx){
3905
4249
  var ask = block.current;
3906
- ctx = { flow: ctx.flow, runId: ctx.runId, resume: ctx.resume, draftNo: block.draftNo };
4250
+ ctx = { flow: ctx.flow, runId: ctx.runId, resume: ctx.resume, removable: ctx.removable, draftNo: block.draftNo };
3907
4251
  var wrap = document.createElement("div");
3908
4252
  wrap.className = "audit-group";
3909
4253
  wrap.setAttribute("data-testid", "ask-block-" + (block.stepName || "no-step"));
@@ -4001,7 +4345,7 @@
4001
4345
  var expanded = focusAskId ? block.askIds.indexOf(focusAskId) !== -1 : (ask.open || blocks.length === 1);
4002
4346
  var prev = kept["ask-block-" + (block.stepName || "no-step")];
4003
4347
  if(prev && prev.open === String(!!ask.open)) expanded = prev.expanded;
4004
- var row = renderAskRow(block, expanded, { flow: result.flow, runId: result.runId, resume: result.resume || null });
4348
+ var row = renderAskRow(block, expanded, { flow: result.flow, runId: result.runId, resume: result.resume || null, removable: !!(result.needsYou && result.needsYou.removable) });
4005
4349
  // hamr's 2026-09-27 exit-check review #3: "the ask opened from the
4006
4350
  // Inbox gets a visible highlight" — a REAL Inbox click (`focusAskId`
4007
4351
  // set) on THIS ask, never a run's own default open-ask expansion
@@ -4039,6 +4383,7 @@
4039
4383
  var clearBtn = document.getElementById("chat-clear-btn");
4040
4384
  var thread = document.getElementById("chat-thread");
4041
4385
  var jobEl = document.getElementById("jf-job");
4386
+ var jobBoxEl = document.getElementById("jf-run-jobbox"); // the Reuse card's job box: the SAME component as #jf-job
4042
4387
  var inputsBox = document.getElementById("jf-inputs"); // the New-job inputs textarea (`name: path` per line)
4043
4388
  var destEl = document.getElementById("jf-dest-folder");
4044
4389
  var askWaitEl = document.getElementById("jf-ask-wait");
@@ -4074,7 +4419,12 @@
4074
4419
  var modeRow = document.getElementById("jf-mode-row");
4075
4420
  var titleEl = document.getElementById("job-card-title");
4076
4421
 
4077
- var editOf = null; // M6: the signed job this card EDITS: { flow, flowHash } (ONE writer each: startEdit sets it, leaveEdit clears it); null = a new job
4422
+ var reuseOf = null; // M6 am5/am6: the signed workflow this New card drafts a CHANGED job from: { flow } (ONE writer each: startReuseDraft sets it, leaveReuse clears it); null = a new job
4423
+ var reuseKind = null; // the server's answer for the Reuse card: "run" | "sign-run" | "draft" (null = not asked yet); ONE writer: checkReuse
4424
+ var reuseName = ""; // the next free name the server suggested for a "draft"
4425
+ var reuseRunOf = false; // M6 am9: the "draft" is a RED run's redraft of an unchanged job: a run of the SAME workflow, no new name (ONE writer: checkReuse)
4426
+ var reuseSeq = 0, reuseTimer = null;
4427
+ var reuseBusy = false; // an edit was made and the server has not answered yet: the main button waits, so it never shows a stale label
4078
4428
  var mode = "new"; // "new" | "run" | "resume"
4079
4429
  var runSignInfo = null; // Run form, first Sign & run click: { hash } (cleared by any edit)
4080
4430
  var resumeCtx = null; // the run being resumed: { flow, runId, form }
@@ -4124,6 +4474,8 @@
4124
4474
  var spends = (cap !== undefined && cap !== null && cap !== "") ? " — spends up to $" + cap : "";
4125
4475
  var blocked = !st.startOk || !!st.busy;
4126
4476
  if(st.mode === "run"){
4477
+ // M6 am6 item 2: the server said a job field changed: the button costs drafting, then signs a NEW workflow (checked before When: a changed job is not a schedule)
4478
+ if(st.reuseKind === "draft") return {text: "Start drafting", action: "reuse-draft", disabled: blocked};
4127
4479
  // M9 am5: When changed from the signed value = the one button is Sign schedule (or Cancel schedule when the choice is By hand), two clicks, $0,
4128
4480
  // starts nothing; after click 1 it reads "Confirm: <words>". It never reaches the run routes.
4129
4481
  if(st.whenChanged){
@@ -4371,10 +4723,10 @@
4371
4723
  inner.style.transform = "translateY(" + (-ta.scrollTop) + "px)";
4372
4724
  }
4373
4725
  function fitCardBoxes(){
4374
- fitBox(jobEl); fitBox(inputsBox);
4375
- paintGutter(jobEl, "job"); paintGutter(inputsBox, "inputs");
4726
+ fitBox(jobEl); fitBox(inputsBox); fitBox(jobBoxEl);
4727
+ paintGutter(jobEl, "job"); paintGutter(inputsBox, "inputs"); paintGutter(jobBoxEl, "job");
4376
4728
  }
4377
- [[jobEl, "job"], [inputsBox, "inputs"]].forEach(function(pair){
4729
+ [[jobEl, "job"], [inputsBox, "inputs"], [jobBoxEl, "job"]].forEach(function(pair){
4378
4730
  pair[0].addEventListener("scroll", function(){
4379
4731
  var inner = document.getElementById(pair[0].id + "-gut").firstChild;
4380
4732
  inner.style.transform = "translateY(" + (-pair[0].scrollTop) + "px)";
@@ -4424,7 +4776,7 @@
4424
4776
  provider: modelPick().provider,
4425
4777
  model: modelPick().model,
4426
4778
  thinking: thinkingEl.checked && !thinkingEl.disabled,
4427
- editOf: editOf
4779
+ ...(reuseOf !== null ? {reuseOf: reuseOf} : {})
4428
4780
  };
4429
4781
  }
4430
4782
  function runWaits(){
@@ -4437,7 +4789,9 @@
4437
4789
  flow: pickedFlow || "", inputs: readRows(runInputsEl), runId: (byId("jf-run-id").value.trim() === autoRunId ? "" : byId("jf-run-id").value.trim()),
4438
4790
  destination: runDestEl.value.trim(), capUsd: runCapEl.value.trim(), askWaits: runWaits(),
4439
4791
  // a flow with no recorded model runs with the pick (am7b); a flow with one sends none
4440
- ...(runPickEl.hidden ? {} : { provider: runPickChoice().provider, model: runPickChoice().model })
4792
+ ...(runPickEl.hidden ? {} : { provider: runPickChoice().provider, model: runPickChoice().model }),
4793
+ // M6 am9: a run picked from the list is reused WITH its plan; the server decides whether that plan is the workflow's own (a plain run) or a different kept one
4794
+ planOf: pickedRun ? pickedRun.runId : undefined
4441
4795
  };
4442
4796
  }
4443
4797
  // pure-ish (reads the boxes): does the Run form differ from the flow's own signed values? Only a convenience that picks the button's wording
@@ -4465,7 +4819,7 @@
4465
4819
  function startReady(){
4466
4820
  if(moneyRed) return false; // amendment 4 item 1: a cap that does not fit this month stops you before the click (the server still refuses)
4467
4821
  if(mode === "run"){
4468
- return !!selectedFlow() && readRows(runInputsEl).every(function(r){ return r.path !== ""; }) && capValid(runCapEl.value.trim());
4822
+ return !!selectedFlow() && readRows(runInputsEl).every(function(r){ return r.path !== ""; }) && capValid(runCapEl.value.trim()) && (reuseKind !== "draft" || reuseRunOf || newNameEl.value.trim() !== "");
4469
4823
  }
4470
4824
  if(mode === "resume"){
4471
4825
  return !!resumeCtx && capValid(resumeCapEl.value.trim());
@@ -4570,10 +4924,8 @@
4570
4924
  var on = cardLocked();
4571
4925
  whenSyncButton();
4572
4926
  card.querySelectorAll("input[type=text], textarea").forEach(function(el){ el.readOnly = on; el.classList.toggle("locked", on); });
4573
- if(editOf !== null){ byId("jf-name").readOnly = true; byId("jf-name").classList.add("locked"); } // M6: an edit keeps its job's name
4574
4927
  runFlowSel.disabled = on;
4575
4928
  runFlowSel.classList.toggle("locked", on);
4576
- syncEditBtn();
4577
4929
  rwPickedEl.classList.toggle("locked", on);
4578
4930
  card.querySelectorAll('input[name="jf-mode"]').forEach(function(r){ r.disabled = on || sessionLive; });
4579
4931
  }
@@ -4611,47 +4963,88 @@
4611
4963
  el.appendChild(row);
4612
4964
  });
4613
4965
  }
4614
- // ---- M6: Edit a signed job. The list entry carries the job as a card (`edit`); Edit fills the New-job boxes from it and keeps the job's name and
4615
- // the signature hash it was opened at. Nothing is written until the normal Draft -> Sign. Clear / Abandon leave the job exactly as it was.
4616
- var editBtn = document.getElementById("jf-run-edit");
4617
- var editWhyEl = document.getElementById("jf-run-edit-why");
4966
+ // ---- M6 am5/am6/am7: Reuse workflow. The Run card opens EVERY field of the signed job. The SERVER says what the one button is (reuse-check):
4967
+ // Run (files only), Sign & run (destination, cap, wait or model), or Start drafting (a job field changed: it drafts again and signs as a NEW
4968
+ // workflow, the old one untouched). The page decides nothing: it asks after every edit and shows the answer; undoing the edit asks again.
4618
4969
  var editBannerEl = document.getElementById("jf-edit-banner");
4619
- function syncEditBtn(){
4620
- if(!editBtn) return; // called by the first lock sync, before this block has run
4621
- var f = selectedFlow();
4622
- var can = !!(f && f.edit && f.edit.ok === true);
4623
- editBtn.disabled = !can || cardLocked() || sessionLive || startId !== null;
4624
- editWhyEl.textContent = (f && f.edit && f.edit.ok === false) ? f.edit.say : "";
4625
- }
4626
- function startEdit(){
4970
+ var newNameEl = document.getElementById("jf-run-newname");
4971
+ var newNameField = document.getElementById("jf-run-newname-field");
4972
+ function reuseBody(){
4973
+ var b = currentRun();
4974
+ delete b.runId;
4975
+ b.job = jobBoxEl.hidden ? undefined : jobBoxEl.value;
4976
+ b.fromRun = pickedRun ? pickedRun.runId : undefined;
4977
+ return b;
4978
+ }
4979
+ function paintReuseKind(){
4980
+ newNameField.hidden = !(mode === "run" && reuseKind === "draft" && !reuseRunOf);
4981
+ }
4982
+ function checkReuse(){
4983
+ if(mode !== "run" || !selectedFlow()){ reuseKind = null; reuseBusy = false; paintReuseKind(); return; }
4984
+ var seq = ++reuseSeq;
4985
+ reuseBusy = true;
4986
+ authorPost("/api/author/reuse-check", reuseBody()).then(function(r){
4987
+ if(seq !== reuseSeq) return; // a newer edit asked again: only the last answer is shown
4988
+ reuseBusy = false;
4989
+ reuseKind = (r.status === 200 && r.body && r.body.ok === true) ? r.body.kind : null;
4990
+ reuseRunOf = reuseKind === "draft" && r.body.runOf === true;
4991
+ if(reuseRunOf){ newNameEl.value = ""; reuseName = ""; }
4992
+ else if(reuseKind === "draft"){ if(r.body.suggestedName !== reuseName){ reuseName = r.body.suggestedName; newNameEl.value = reuseName; } }
4993
+ else { newNameEl.value = ""; reuseName = ""; }
4994
+ paintReuseKind(); refreshStartEnabled();
4995
+ }).catch(function(){ if(seq === reuseSeq){ reuseBusy = false; reuseKind = null; paintReuseKind(); refreshStartEnabled(); } });
4996
+ }
4997
+ function scheduleReuseCheck(){
4998
+ if(reuseTimer) clearTimeout(reuseTimer);
4999
+ reuseBusy = true; // until the server answers the main button waits; the page never guesses the label
5000
+ reuseTimer = setTimeout(checkReuse, 200);
5001
+ }
5002
+ // Start drafting: the New card is filled from the Reuse card (job, boxes, the new name) and the normal draft starts; `reuseOf` makes the server
5003
+ // refuse it if no job field changed. Nothing is written to the signed workflow.
5004
+ function startReuseDraft(){
4627
5005
  var f = selectedFlow();
4628
- if(!f || !f.edit || f.edit.ok !== true || cardLocked() || sessionLive) return;
4629
- var c = f.edit.card;
4630
- editOf = {flow: f.flow, flowHash: f.edit.flowHash};
5006
+ if(!f || mode !== "run" || cardLocked() || sessionLive) return;
5007
+ reuseOf = reuseRunOf ? {flow: f.flow, fromRun: pickedRun ? pickedRun.runId : ""} : {flow: f.flow, fromRun: pickedRun ? pickedRun.runId : undefined};
5008
+ var rows = readRows(runInputsEl);
5009
+ var waits = runWaits();
5010
+ var firstWait = Object.keys(waits).map(function(k){ return waits[k]; }).filter(function(w){ return w !== ""; })[0] || "1h";
5011
+ var pk = runPickChoice();
4631
5012
  setMode("new");
4632
- setVal("jf-name", f.flow); setVal("jf-job", c.job); setVal("jf-cap-money", c.capUsd);
4633
- setVal("jf-dest-folder", c.destination); setVal("jf-inputs", c.inputs); setVal("jf-ask-wait", c.askWait || "1h");
4634
- // M9 am1: a job with a trigger is told, before it signs, that the edit clears the trigger back to By hand (the sentence is the server's)
4635
- editBannerEl.textContent = "Editing \u201c" + f.flow + "\u201d. Draft it, read the new plan, then sign: signing replaces this job. Clear leaves it exactly as it was." + (f.trigger && f.trigger.editNote ? " " + f.trigger.editNote : "");
5013
+ setVal("jf-name", reuseRunOf ? f.flow : newNameEl.value.trim()); setVal("jf-job", jobBoxEl.value); setVal("jf-cap-money", runCapEl.value.trim());
5014
+ setVal("jf-dest-folder", runDestEl.value.trim()); setVal("jf-inputs", rows.map(function(r){ return r.role + ": " + r.path; }).join("\n")); setVal("jf-ask-wait", firstWait);
5015
+ if(pk.provider !== "") setModelPick(pk.provider, pk.model);
5016
+ editBannerEl.textContent = reuseRunOf
5017
+ ? "Reusing \u201c" + f.flow + "\u201d after a failed run. Draft a new plan, read it, then sign: it becomes the next run of \u201c" + f.flow + "\u201d, which is not changed."
5018
+ : "Reusing \u201c" + f.flow + "\u201d with a changed job. Draft it, read the new plan, then sign: it becomes a new workflow and \u201c" + f.flow + "\u201d is not touched.";
4636
5019
  editBannerEl.hidden = false;
4637
5020
  chatActionOk();
4638
- refreshCapNote(); fitCardBoxes(); refreshStartEnabled();
5021
+ refreshCapNote(); fitCardBoxes();
5022
+ doDraft(null);
4639
5023
  }
4640
- // the card stops editing a job: the name box is free again
4641
- function leaveEdit(){
4642
- editOf = null;
5024
+ // the card stops reusing: the name box is free again
5025
+ function leaveReuse(){
5026
+ reuseOf = null;
4643
5027
  editBannerEl.hidden = true; editBannerEl.textContent = "";
4644
- var nm = byId("jf-name"); nm.readOnly = false; nm.classList.remove("locked");
4645
5028
  }
4646
- editBtn.addEventListener("click", startEdit);
4647
5029
  function paintRunFlow(){
4648
5030
  var f = selectedFlow();
4649
5031
  var v = f ? (pickedRun ? pickedRun.values : f.values) : null; // a picked run's own values, else the flow's own
4650
5032
  paintedFlow = pickedKey();
4651
5033
  runSignInfo = null;
4652
5034
  paintJobDim(byId("jf-run-job"), f ? f.jobLines : []);
4653
- byId("jf-run-model").textContent = f && f.model ? "Model: " + f.model.label : (f ? "No model is recorded for this job. Pick the one to run it with; it is then remembered for this job." : "");
4654
- runPickEl.hidden = !(f && !f.model);
5035
+ // M6 am6 item 1: the job opens like every other field (the card the server built from the signed job); a job with a setting the card has no box for keeps the read-only lines and says why
5036
+ var jobOpen = !!(f && f.edit && f.edit.ok === true);
5037
+ jobBoxEl.hidden = !jobOpen; byId("jf-run-jobwrap").hidden = !jobOpen; byId("jf-run-job").hidden = jobOpen;
5038
+ jobBoxEl.value = jobOpen ? f.edit.card.job : "";
5039
+ fitCardBoxes();
5040
+ byId("jf-err-run-job").textContent = (f && f.edit && f.edit.ok === false) ? f.edit.say : "";
5041
+ byId("jf-run-job-hint").hidden = !jobOpen;
5042
+ byId("jf-run-model").textContent = f && f.model ? "Model: " + f.model.label + ". Pick another to run it with that model (signed with the run)." : (f ? "No model is recorded for this job. Pick the one to run it with; it is then remembered for this job." : "");
5043
+ runPickEl.hidden = !f;
5044
+ var pm = (pickedRun && pickedRun.model) ? pickedRun.model : (f && f.model ? f.model : null);
5045
+ if(pm){ runPicked = {provider: pm.slot, model: pm.model}; }
5046
+ syncRunPick();
5047
+ reuseKind = null; reuseRunOf = false; reuseName = ""; newNameEl.value = ""; paintReuseKind();
4655
5048
  runDestEl.value = v && v.destination ? v.destination : "";
4656
5049
  runDestEl.readOnly = !(f && f.hasSend);
4657
5050
  runDestEl.classList.toggle("locked", !(f && f.hasSend));
@@ -4674,8 +5067,8 @@
4674
5067
  byId("jf-run-id").value = autoRunId;
4675
5068
  clearFieldErrors();
4676
5069
  refreshCapNote();
4677
- syncEditBtn();
4678
5070
  paintWhen();
5071
+ if(f) checkReuse();
4679
5072
  }
4680
5073
  // ---- M9 piece 5: When [By hand v] on the Run card (ladder M9 item 1, item 2). One dropdown, no cron text. Changing it asks the server what
4681
5074
  // would be signed (click 1, signs nothing, returns a hash), click 2 signs it with that hash: the Run door's two clicks. $0, no drafter.
@@ -4746,6 +5139,12 @@
4746
5139
  var f = selectedFlow();
4747
5140
  if(!f || whenBusy || cardLocked()) return;
4748
5141
  var body = {flow: f.flow, trigger: whenTriggerFromBoxes()};
5142
+ var rp = runPickChoice(); // M6 am5 item 3: the model picked on this card (the run's own, by default) is scheduled with it; the server drops one equal to the job's
5143
+ if(body.trigger !== null && rp.provider !== ""){ body.provider = rp.provider; body.model = rp.model; }
5144
+ // ... and so are its destination and inputs (the card's boxes, as filled from the run or changed here); the server drops a destination equal to the job's
5145
+ if(body.trigger !== null){ body.destination = runDestEl.value.trim(); body.inputs = readRows(runInputsEl); }
5146
+ // M6 am9: the schedule uses the plan of the run whose Run tab it was set from (the server binds it only when that plan differs from the workflow's own)
5147
+ if(body.trigger !== null && pickedRun){ body.planOf = pickedRun.runId; }
4749
5148
  var second = whenHash !== null;
4750
5149
  if(second) body.hash = whenHash;
4751
5150
  whenBusy = true; whenSyncButton();
@@ -4817,7 +5216,7 @@
4817
5216
  if(!j || j.ok !== true) return;
4818
5217
  flows = j.flows || [];
4819
5218
  if(pickedFlow !== null && !selectedFlow()){ pickedFlow = null; pickedRun = null; againEntry = null; pickedLabel = ""; runFlowSel.value = ""; }
4820
- byId("jf-run-empty").textContent = flows.length ? "" : "No signed flow has a passed run yet. Run a job first, or use Run again on one of its runs.";
5219
+ byId("jf-run-empty").textContent = flows.length ? "" : "No signed flow has a passed run yet. Run a job first, or use Reuse workflow on one of its runs.";
4821
5220
  renderFlowSearch();
4822
5221
  if(force || paintedFlow !== pickedKey() || (flows.length === 0 && runInputsEl.children.length > 0)) paintRunFlow();
4823
5222
  refreshCapNote();
@@ -4838,8 +5237,8 @@
4838
5237
  function thinkingBoxState(line, wasChecked){
4839
5238
  if(!line || !line.thinking) return {disabled: true, checked: false, note: ""};
4840
5239
  if(line.thinking.canChange !== true) return {disabled: true, checked: false, note: line.thinking.say || ""};
4841
- // an unchecked model's note (am11 item 2) says "thinking off"; ticked, it would be wrong, so it goes
4842
- return {disabled: false, checked: wasChecked === true, note: wasChecked === true ? "" : (line.thinking.say || "")};
5240
+ // M4d am22: the note shows whether the box is ticked or not
5241
+ return {disabled: false, checked: wasChecked === true, note: line.thinking.say || ""};
4843
5242
  }
4844
5243
  function paintThinking(){
4845
5244
  var st = thinkingBoxState(modelLines[Number(modelEl.value)], thinkingEl.checked);
@@ -4989,7 +5388,7 @@
4989
5388
  if(html !== extrasKey){ extrasKey = html; extrasEl.innerHTML = html; }
4990
5389
  }
4991
5390
  function renderMain(){
4992
- var st = {mode: mode, session: sessionLive, startOk: startOk, busy: busy || startId !== null, signClicked: signClickedOnce, reviseOpen: reviseOpen};
5391
+ var st = {mode: mode, session: sessionLive, startOk: startOk, busy: busy || startId !== null || (mode === "run" && reuseBusy), signClicked: signClickedOnce, reviseOpen: reviseOpen};
4993
5392
  if(sessionLive && lastState){
4994
5393
  st.phase = lastState.phase;
4995
5394
  st.hash = signInfo ? signInfo.hash : lastState.hash;
@@ -4998,7 +5397,8 @@
4998
5397
  }
4999
5398
  if(mode === "run"){
5000
5399
  st.capUsd = runCapEl.value.trim();
5001
- st.runDiffers = runDiffers();
5400
+ st.reuseKind = reuseKind;
5401
+ st.runDiffers = reuseKind !== null ? reuseKind === "sign-run" : runDiffers();
5002
5402
  st.runSignClicked = !!runSignInfo;
5003
5403
  st.hash = runSignInfo ? runSignInfo.hash : "";
5004
5404
  st.whenChanged = whenChanged();
@@ -5080,7 +5480,7 @@
5080
5480
  // back to a fresh empty card: every box, the inputs, the progress list, the ask box
5081
5481
  function resetCard(){
5082
5482
  if(mode === "resume"){ resumeCtx = null; setMode(modeBeforeResume === "resume" ? "new" : modeBeforeResume); }
5083
- leaveEdit();
5483
+ leaveReuse();
5084
5484
  ["jf-name", "jf-job", "jf-cap-money", "jf-dest-folder", "jf-inputs"].forEach(function(id){ byId(id).value = ""; });
5085
5485
  askWaitEl.value = "1h";
5086
5486
  thinkingEl.checked = false; // per job: unticked for the next one
@@ -5156,7 +5556,7 @@
5156
5556
  window.fwdloopResuming = null; // a refused start leaves the run stopped: Resume is offered again
5157
5557
  refusedStartId = j.startId;
5158
5558
  chatActionFailed(signed ? j.say + " The flow is signed; start it from \"Run a signed flow\"." : j.say);
5159
- if(signed){ leaveEdit(); endSession(); loadFlows(true); } else { progressRow.hidden = true; progressRow.innerHTML = ""; progressHtml = ""; refreshStartEnabled(); }
5559
+ if(signed){ leaveReuse(); endSession(); loadFlows(true); } else { progressRow.hidden = true; progressRow.innerHTML = ""; progressHtml = ""; refreshStartEnabled(); }
5160
5560
  return;
5161
5561
  }
5162
5562
  if(j.ok === false && j.refused === "no-such-start"){
@@ -5295,8 +5695,8 @@
5295
5695
  function openRunAgain(detail){
5296
5696
  authorGet("/api/author/run-again?flow=" + encodeURIComponent(detail.flow) + "&runId=" + encodeURIComponent(detail.runId)).then(function(j){
5297
5697
  document.getElementById("tab-chat").click();
5298
- if(!j || j.ok !== true){ chatActionFailed((j && j.say) || "This run cannot be run again."); return; }
5299
- if(startId !== null || sessionLive || mode === "resume"){ chatActionFailed("Finish or clear what is on the card first, then Run again."); return; }
5698
+ if(!j || j.ok !== true){ chatActionFailed((j && j.say) || "This run cannot be reused."); return; }
5699
+ if(startId !== null || sessionLive || mode === "resume"){ chatActionFailed("Finish or clear what is on the card first, then Reuse workflow."); return; }
5300
5700
  chatActionOk();
5301
5701
  againEntry = j.flow; pickedFlow = j.flow.flow; pickedRun = j.pick; pickedLabel = j.flow.flow + " (" + j.pick.runId + ")";
5302
5702
  runFlowSel.value = pickedLabel;
@@ -5331,7 +5731,7 @@
5331
5731
  if(!o.ok){
5332
5732
  busy = false;
5333
5733
  failFrom(r);
5334
- if(r.body && r.body.signed === true){ leaveEdit(); endSession(); loadFlows(true); } else { refreshStartEnabled(); }
5734
+ if(r.body && r.body.signed === true){ leaveReuse(); endSession(); loadFlows(true); } else { refreshStartEnabled(); }
5335
5735
  return;
5336
5736
  }
5337
5737
  chatActionOk();
@@ -5383,11 +5783,6 @@
5383
5783
  setModelPick(c.provider || "", c.model || ""); thinkingEl.checked = c.thinking === true && !thinkingEl.disabled;
5384
5784
  refreshCapNote();
5385
5785
  setVal("jf-dest-folder", typeof c.destination === "string" ? c.destination : ""); setVal("jf-inputs", typeof c.inputs === "string" ? c.inputs : ""); setVal("jf-ask-wait", c.askWait || "1h");
5386
- if(c.editOf && typeof c.editOf.flow === "string"){
5387
- editOf = {flow: c.editOf.flow, flowHash: c.editOf.flowHash};
5388
- editBannerEl.textContent = "Editing \u201c" + c.editOf.flow + "\u201d. Draft it, read the new plan, then sign: signing replaces this job. Clear leaves it exactly as it was.";
5389
- editBannerEl.hidden = false;
5390
- }
5391
5786
  sessionId = d.draftId;
5392
5787
  sessionLive = CLIENT_TERMINAL_PHASES.indexOf(d.phase) === -1;
5393
5788
  renderThread(d);
@@ -5430,6 +5825,7 @@
5430
5825
  if(mainBtn.disabled) return;
5431
5826
  if(mainAction === "draft") doDraft(mainStartOver ? sessionId : null);
5432
5827
  else if(mainAction === "when-sign-prepare" || mainAction === "when-sign") doWhenSign();
5828
+ else if(mainAction === "reuse-draft") startReuseDraft();
5433
5829
  else if(mainAction === "run") doRun();
5434
5830
  else if(mainAction === "run-sign-prepare" || mainAction === "run-sign") doRunSign();
5435
5831
  else if(mainAction === "resume-sign-prepare" || mainAction === "resume-sign") doResumeSign();
@@ -5441,6 +5837,7 @@
5441
5837
  if(grp) grp.querySelectorAll(".jf-err").forEach(function(x){ x.textContent = ""; });
5442
5838
  dropFixBoxesBanner();
5443
5839
  fitCardBoxes();
5840
+ if(mode === "run" && e.target && e.target.id !== "jf-run-flow" && e.target.id !== "jf-run-newname" && e.target.closest && e.target.closest("#jf-run")) scheduleReuseCheck();
5444
5841
  if(e.target && (e.target.id === "jf-cap-money" || e.target.id === "jf-job" || e.target.id === "jf-run-cap" || e.target.id === "jf-resume-cap")) scheduleCapNote();
5445
5842
  // any edit voids the first Sign click of the Run / Resume form: what is shown must be what is signed
5446
5843
  runSignInfo = null; resumeSignInfo = null;
@@ -5448,7 +5845,7 @@
5448
5845
  });
5449
5846
  document.querySelectorAll('input[name="jf-mode"]').forEach(function(r){
5450
5847
  r.addEventListener("change", function(){
5451
- if(r.checked && editOf !== null && r.value !== "new" && !sessionLive){ leaveEdit(); ["jf-name", "jf-job", "jf-cap-money", "jf-dest-folder", "jf-inputs"].forEach(function(id){ byId(id).value = ""; }); }
5848
+ if(r.checked && reuseOf !== null && r.value !== "new" && !sessionLive){ leaveReuse(); ["jf-name", "jf-job", "jf-cap-money", "jf-dest-folder", "jf-inputs"].forEach(function(id){ byId(id).value = ""; }); }
5452
5849
  if(r.checked) setMode(r.value);
5453
5850
  });
5454
5851
  });