fwdloop 0.17.0 → 0.19.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.
@@ -182,8 +182,8 @@
182
182
 
183
183
  /* M4c inbox: section 1 (waiting on you) carries the page's amber accent
184
184
  treatment; section 3 (answered/expired) is dimmed. Tokens only. */
185
- .inbox-h{font-size:12px;color:var(--text-dim);font-weight:700;margin:12px 0 6px;}
186
- .inbox-h:first-child{margin-top:0;}
185
+ .rl-sect,.inbox-h{font-size:12px;color:var(--text-dim);font-weight:700;margin:12px 0 6px;}
186
+ .rl-sect:first-child,.inbox-h:first-child{margin-top:0;}
187
187
  .inbox-row.s1{border-left:4px solid var(--amber);background:var(--amber-bg);}
188
188
  .inbox-row.s3{opacity:.6;}
189
189
  .inbox-row .wf-line1{min-width:0;}
@@ -221,13 +221,11 @@
221
221
  .answer-msg.stuck{border-color:var(--amber);}
222
222
  .answer-msg.info::before{content:"[·] ";color:var(--amber);font-weight:700;}
223
223
 
224
- .wf-row,.hist-row{
224
+ .hist-row{
225
225
  display:flex;flex-direction:column;row-gap:4px;min-width:0;
226
226
  padding:8px 8px 8px 18px;position:relative;border:1px solid var(--border);margin-bottom:6px;background:var(--panel2);cursor:pointer;
227
227
  }
228
- .wf-row::before{content:" ";position:absolute;left:6px;top:8px;color:var(--accent);font-weight:700;}
229
- .wf-row:hover,.hist-row:hover{border-color:var(--border-strong);}
230
- .wf-row.selected::before{content:">";}
228
+ .hist-row:hover{border-color:var(--border-strong);}
231
229
  /* line 1: glyph + name, kept on ONE line — truncated with an ellipsis
232
230
  (never wrapped) when the job/runid text is longer than the row; the
233
231
  full text is still reachable via the span's own title attribute. */
@@ -246,15 +244,37 @@
246
244
  .hdr-verdict{font-size:12px;color:var(--text-dim);min-width:0;overflow-wrap:anywhere;}
247
245
  .wf-meta{font-size:12px;color:var(--text-dim);}
248
246
  .wf-sep{font-size:12px;color:var(--text-faint);}
249
- .wf-row.selected,.hist-row.selected{border:2px solid var(--accent);border-radius:4px;}
250
- /* item 2 (2026-09-26 merge): a Workflows-view job row expands inline to
251
- list ALL its runs (build spec's own design) — the caret glyph on the
252
- job row, and the indent wrapper the expanded runs render into. */
253
- .wf-job{margin-bottom:6px;}
254
- .wf-job .wf-row{margin-bottom:0;}
255
- .wf-caret{display:inline-block;width:11px;flex:none;color:var(--text-faint);font-size:10px;}
256
- .wf-runs{margin:4px 0 8px 16px;padding-left:8px;border-left:2px solid var(--border);}
257
- .wf-runs .hist-row{margin-bottom:4px;}
247
+ .hist-row.selected{border:2px solid var(--accent);border-radius:4px;}
248
+ /* 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
+ (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
+ :root{--rl-accent-bg:rgba(122,162,247,.12);--rl-accent-bg-strong:rgba(122,162,247,.2);}
251
+ .rl-card{display:block;width:100%;text-align:left;background:var(--panel2);border:1px solid var(--border);padding:6px 8px;margin:0 0 6px;cursor:pointer;min-height:44px;color:inherit;font:inherit;}
252
+ div.rl-card{cursor:default;}
253
+ .rl-card:hover{border-color:var(--accent);background:var(--rl-accent-bg);}
254
+ div.rl-card:hover{border-color:var(--border);background:var(--panel2);}
255
+ .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
+ .rl-card:focus-visible,.rl-fold:focus-visible{outline:2px solid var(--accent);outline-offset:2px;}
257
+ .rl-card.rl-live{border-color:var(--amber);}
258
+ .rl-card.rl-need{border-color:var(--accent);}
259
+ .rl-l1{display:flex;gap:6px;align-items:center;min-width:0;overflow:hidden;}
260
+ .rl-nm{font-weight:700;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0;}
261
+ .rl-rn{color:var(--accent);flex:none;}
262
+ .rl-l2{display:block;font-size:12px;color:var(--text-dim);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}
263
+ .rl-l2 .sign-word{color:var(--text);}
264
+ .rl-dim{color:var(--text-dim);font-size:12px;flex:none;}
265
+ .rl-faint{color:var(--text-faint);font-size:12px;}
266
+ .rl-cnt{color:var(--text-faint);font-size:inherit;flex:none;}
267
+ .rl-runs{margin:6px 0 0 6px;padding-left:8px;border-left:2px solid var(--border);}
268
+ .rl-runs .rl-card{background:var(--bg);}
269
+ .rl-runs .rl-card.rl-sel{background:var(--rl-accent-bg-strong);}
270
+ .rl-fold{background:none;border:0;color:var(--text-dim);font:inherit;font-size:12px;padding:4px 0;cursor:pointer;min-height:32px;}
271
+ .rl-fold:hover{color:var(--accent);}
272
+ .rl-hint{font-size:12px;color:var(--text-faint);padding:2px 0 6px;}
273
+ .rl-pill{font-size:11px;border:1px solid var(--amber);color:var(--amber);padding:0 5px;margin-left:auto;flex:none;}
274
+ .rl-pill-need{border-color:var(--accent);color:var(--accent);}
275
+ .rl-dash{border-top:1px dashed var(--border-strong);margin:10px 0 6px;}
276
+ #panel-runs .rl-faint{margin-bottom:4px;}
277
+ @media (max-width:899px){ .rl-fold{min-height:44px;} }
258
278
 
259
279
  .rp-header{display:flex;align-items:center;justify-content:space-between;padding:10px 16px;border-bottom:2px solid var(--border-strong);background:var(--panel);flex-wrap:wrap;gap:8px;}
260
280
  .rp-header h2{margin:0;font-size:15px;min-width:0;overflow-wrap:anywhere;text-transform:none;letter-spacing:normal;}
@@ -283,6 +303,20 @@
283
303
  .counters{display:block;padding:9px 12px;border:none;border-bottom:2px solid var(--border-strong);background:var(--panel2);color:var(--text-dim);margin:-12px -12px 14px;font-size:12px;font-weight:700;white-space:normal;overflow-wrap:break-word;}
284
304
  .counters b,.counters span{color:var(--accent);}
285
305
 
306
+ /* borrowed-from: bareloop src/panel/index.html@f845ee7 (the ENDED block, P5); amber added for stopped/expired, a SCHEDULED twin */
307
+ .ended-block{position:relative;border:1px solid var(--border-strong);padding:12px;margin-bottom:12px;background:var(--panel2);font-size:13px;}
308
+ .ended-block.magenta{border-color:var(--magenta);}
309
+ .ended-block.red{border-color:var(--red);}
310
+ .ended-text.is-red{color:var(--red);}
311
+ .ended-block.green{border-color:var(--green);}
312
+ .ended-block.amber{border-color:var(--amber);}
313
+ .ended-row{display:flex;gap:10px;align-items:baseline;flex-wrap:wrap;margin-bottom:6px;}
314
+ .ended-row:last-child{margin-bottom:0;}
315
+ .ended-label{color:var(--text-faint);font-size:11px;letter-spacing:0.08em;min-width:84px;}
316
+ .ended-text{flex:1 1 220px;min-width:0;overflow-wrap:anywhere;}
317
+ .when-sub{display:flex;gap:8px;flex-wrap:wrap;margin-top:6px;}
318
+ .when-sub > *{flex:1 1 120px;min-width:0;}
319
+ .when-sub[hidden]{display:none;}
286
320
  .summary-box{position:relative;border:1px solid var(--border-strong);padding:16px 12px 12px;margin-top:16px;background:var(--panel2);font-size:12px;}
287
321
  .summary-box.red{border-color:var(--red);}
288
322
  .summary-box.amber{border-color:var(--amber);}
@@ -340,7 +374,7 @@
340
374
  .chip::before{content:"[ ";color:var(--text-faint);}
341
375
  .chip::after{content:" ]";color:var(--text-faint);}
342
376
  .chip[aria-pressed="true"]{background:var(--panel);color:var(--accent);border-color:var(--accent);font-weight:700;}
343
- /* Compact filter-bar chips (History + Workflows, shared component): single
377
+ /* Compact filter-bar chips (the runs list's filter bar): single
344
378
  letters/bare glyphs, no "[ ]" brackets — hamr's 2026-09-25 feedback on
345
379
  the live panel ("icons are taking too much space", "one letter without
346
380
  brackets"). */
@@ -961,6 +995,30 @@
961
995
  <div id="jf-run-inputs" data-testid="jf-run-inputs"></div>
962
996
  <div class="jf-err" id="jf-err-run-inputs" data-testid="jf-err-run-inputs"></div>
963
997
  </div>
998
+ <div class="field" id="jf-when-field" data-testid="jf-when-field">
999
+ <label for="jf-when">When</label>
1000
+ <select id="jf-when" data-testid="jf-when" aria-label="When this job runs">
1001
+ <option value="hand">By hand</option>
1002
+ <option value="daily">Every day at HH:MM</option>
1003
+ <option value="weekdays">Weekdays at HH:MM</option>
1004
+ <option value="weekly">Every &lt;day&gt; at HH:MM</option>
1005
+ <option value="file-updated">When &lt;file&gt; is updated</option>
1006
+ <option value="new-file">When a new file arrives in &lt;folder&gt;</option>
1007
+ </select>
1008
+ <div class="when-sub" id="jf-when-clock" hidden>
1009
+ <select id="jf-when-day" data-testid="jf-when-day" aria-label="Day of the week">
1010
+ <option value="mon">Monday</option><option value="tue">Tuesday</option><option value="wed">Wednesday</option><option value="thu">Thursday</option>
1011
+ <option value="fri">Friday</option><option value="sat">Saturday</option><option value="sun">Sunday</option>
1012
+ </select>
1013
+ <input id="jf-when-time" type="time" value="09:00" data-testid="jf-when-time" aria-label="Time, HH:MM">
1014
+ </div>
1015
+ <div class="when-sub" id="jf-when-filebox" hidden>
1016
+ <select id="jf-when-role" data-testid="jf-when-role" aria-label="Which of the job's inputs"></select>
1017
+ <input id="jf-when-path" type="text" autocomplete="off" spellcheck="false" data-testid="jf-when-path" aria-label="File or folder">
1018
+ </div>
1019
+ <div class="hint" id="jf-when-now" data-testid="jf-when-now"></div>
1020
+ <div class="jf-err" id="jf-err-when" data-testid="jf-err-when"></div>
1021
+ </div>
964
1022
  <div class="cap-row">
965
1023
  <div class="cap-field">
966
1024
  <label for="jf-run-cap">Cap $</label>
@@ -1053,16 +1111,19 @@
1053
1111
  — the wide right pane is where the evidence lives now. The
1054
1112
  answer doors are in the Ask tab, not here (M4b). -->
1055
1113
  <div id="inbox-list" data-testid="inbox-list"></div>
1114
+ <div class="rl-dash"></div>
1115
+ <div class="rl-faint" data-testid="inbox-filter-note">filters below act on answered and expired only</div>
1116
+ <div id="inbox-filterbar-anchor"></div>
1117
+ <div id="inbox-list-old" data-testid="inbox-list-old"></div>
1056
1118
  </section>
1057
1119
 
1058
1120
  <section id="panel-runs" class="tabpanel" role="tabpanel" aria-labelledby="tab-runs" hidden>
1059
- <div class="chips" role="group" aria-label="Runs view" style="margin-bottom:8px;">
1060
- <button class="chip" type="button" aria-pressed="true" data-runs-view="workflows" data-testid="runs-view-workflows">Workflows</button>
1061
- <button class="chip" type="button" aria-pressed="false" data-runs-view="history" data-testid="runs-view-history">History</button>
1062
- </div>
1121
+ <!-- M11: ONE list. Running now, Needs you and Scheduled are not filtered; the filters below act on Jobs and quiet jobs only. -->
1122
+ <div id="rl-top" data-testid="rl-top"></div>
1123
+ <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>
1063
1125
  <div id="runs-filterbar-anchor"></div>
1064
1126
  <div id="wf-list" data-testid="wf-list"></div>
1065
- <div id="history-list" data-testid="history-list" hidden></div>
1066
1127
  </section>
1067
1128
 
1068
1129
  </div>
@@ -1089,8 +1150,13 @@
1089
1150
  <div class="pane-body" id="right-pane-body">
1090
1151
 
1091
1152
  <section id="panel-run" class="tabpanel active" role="tabpanel" aria-labelledby="tab-run">
1092
- <div id="run-empty" class="hint" style="font-size:13px;padding:24px 0;">select a run from Workflows or History</div>
1153
+ <div id="run-empty" class="hint" style="font-size:13px;padding:24px 0;">select a run from the list</div>
1093
1154
  <div id="run-content" hidden>
1155
+ <div id="summary-blocks" data-testid="summary-blocks">
1156
+ <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
+ <div class="hint" id="catchup-note" data-testid="catchup-note" hidden></div>
1159
+ </div>
1094
1160
  <div class="run-actions" id="run-actions" data-testid="run-actions" hidden></div>
1095
1161
  <div class="counters" id="run-counters" data-testid="live-counters"></div>
1096
1162
  <div class="summary-box" id="run-summary" data-testid="run-summary"></div>
@@ -1533,9 +1599,9 @@
1533
1599
  // says this sign is [▶] running or [·] waiting on you (data.js glyphPulses).
1534
1600
  // M4c-fix amendment 2 (g): one bold word after every sign, then " — " and the plain line. The word comes from the
1535
1601
  // server's one sign->word table (data.js SIGN_WORDS) on `word`; this only draws it, the same in Runs, Inbox and the header.
1536
- function signHtml(word, line, fallback){
1602
+ function signHtml(word, line, fallback, sep){
1537
1603
  if(!word) return escapeXml(fallback || "unknown");
1538
- return '<b class="sign-word">' + escapeXml(word) + '</b>' + (line ? " &mdash; " + escapeXml(line) : "");
1604
+ return '<b class="sign-word">' + escapeXml(word) + '</b>' + (line ? (sep || " &mdash; ") + escapeXml(line) : "");
1539
1605
  }
1540
1606
  function dotClass(g, pulse){ return "dot " + glyphClass(g) + (pulse ? " pulse" : ""); }
1541
1607
  function glyphClass(g){
@@ -1679,56 +1745,6 @@
1679
1745
  window.addEventListener("resize", reflowMapSoon);
1680
1746
  }
1681
1747
 
1682
- // ---- Runs tab: ONE run-row builder shared by History (flat) and the
1683
- // Workflows view's per-flow expansion — the two never drift on how a run
1684
- // row reads. Rekeyed from bareloop's job/runid to fwdloop's flow/runId
1685
- // (GET /api/runs row shape: src/panel/data.js's listRuns).
1686
- // opts.sub (amendment 12): a Workflows sub-card drops the flow name from its visible text; no other caller passes opts.
1687
- function buildRunRowEl(r, opts){
1688
- var row = document.createElement("div");
1689
- // Selected state is computed here, off the module's own `currentRunId`,
1690
- // so a row freshly built by a RE-RENDER (switching Runs view mode, or a
1691
- // Workflows parent auto-expanding onto an older run picked from
1692
- // History) shows selected without needing a click on this exact
1693
- // element — `selectRun`'s imperative class toggle (used when a click
1694
- // passes its own `rowEl`) stays layered on top of this, never replaced.
1695
- var selected = r.flow === currentFlow && r.runId === currentRunId;
1696
- row.className = "hist-row" + (selected ? " selected" : "");
1697
- row.setAttribute("data-testid", "hist-row-" + r.flow + "-" + (r.runId || "none"));
1698
- row.setAttribute("tabindex", "0");
1699
- row.setAttribute("role", "button");
1700
- row.setAttribute("aria-pressed", selected ? "true" : "false");
1701
- var fullName = r.flow + (r.runId ? ' (' + r.runId + ')' : '');
1702
- if(r.runId === null){
1703
- // this flow has no runs yet — empty state names why, never a made-up row.
1704
- row.innerHTML =
1705
- '<span class="wf-line1"><span class="dot grey"></span>' +
1706
- '<span class="wf-name" title="' + escapeXml(fullName) + '">' + escapeXml(fullName) + '</span></span>' +
1707
- '<span class="wf-meta-line"><span class="wf-meta">' + escapeXml(r.why || "no runs yet") + '</span></span>';
1708
- row.removeAttribute("tabindex");
1709
- row.removeAttribute("role");
1710
- return row;
1711
- }
1712
- if(opts && opts.sub){
1713
- // amendment 12: line 1 `(run-<n>) <word> — <label>`; the flow name stays in title/aria only
1714
- row.setAttribute("aria-label", fullName);
1715
- row.innerHTML =
1716
- '<span class="wf-line1"><span class="' + dotClass(r.glyph, r.pulse) + '"></span>' +
1717
- '<span class="wf-name" title="' + escapeXml(fullName) + '">(' + escapeXml(r.runId) + ')</span> ' +
1718
- '<span class="wf-sign-line" data-testid="run-sign-word">' + signHtml(r.word, (r.word === 'passed' && r.glyph === '[✓]' && !r.line) ? 'goal met' : r.line, r.label) + '</span></span>' +
1719
- runMetaLineHtml(r, null);
1720
- } else {
1721
- row.innerHTML =
1722
- '<span class="wf-line1"><span class="' + dotClass(r.glyph, r.pulse) + '"></span>' +
1723
- '<span class="wf-name" title="' + escapeXml(fullName) + '">' + escapeXml(fullName) + '</span></span>' +
1724
- '<span class="wf-sign-line" data-testid="run-sign-word">' + signHtml(r.word, r.line, r.label) + '</span>' +
1725
- runMetaLineHtml(r, null);
1726
- }
1727
- row.addEventListener("click", function(){ openRunFromRuns(r, row); });
1728
- row.addEventListener("keydown", function(e){ if(e.key === "Enter" || e.key === " "){ e.preventDefault(); row.click(); } });
1729
- return row;
1730
- }
1731
-
1732
1748
  // M4c amendment 1 (a): the ONE place a click on a run in Runs decides where it lands.
1733
1749
  // Right side: that run, on the Run tab, at once. Whether the run has an ask waiting on the human (or is
1734
1750
  // stuck, which counts as waiting: M4c amendment 2 (b)) is decided from THAT RUN's own asks, fetched on
@@ -1760,22 +1776,10 @@
1760
1776
  }).catch(function(){ /* unreadable books: the run stays open on the Run tab, the left side stays on Runs */ });
1761
1777
  }
1762
1778
 
1763
- // ---- History view: every row exactly as /api/runs returned it. ----
1764
- function renderHistory(runs){
1765
- var el = document.getElementById("history-list");
1766
- el.innerHTML = "";
1767
- if(!(runs || []).length){
1768
- el.innerHTML = '<div class="hint">no runs listed yet — no flow under this root has been run</div>';
1769
- return;
1770
- }
1771
- runs.forEach(function(r){ el.appendChild(buildRunRowEl(r)); });
1772
- }
1773
-
1774
- // ---- Workflows view: groups the ONE /api/runs payload by flow name
1775
- // client-side. Runs arrive newest-first within a flow (server contract,
1776
- // listRuns), so the first run seen for a flow is its latest.
1777
- // The words for a run row's spend and time cells — the Workflows card (a flow's latest run) and
1778
- // every History/expanded row say the same thing, from the same server fields.
1779
+ // ---- Jobs: groups the ONE /api/runs payload by flow name client-side. Runs arrive in
1780
+ // the server's order within a flow (listRuns), so the first run seen for a flow is its head.
1781
+ // The words for a run card's spend and time — every card of the runs list says the same
1782
+ // thing, from the same server fields.
1779
1783
  function runSpendText(r){
1780
1784
  return r.spend || r.spendWhy || "unknown";
1781
1785
  }
@@ -1783,14 +1787,16 @@
1783
1787
  function runWallText(r){
1784
1788
  return typeof r.wallMs === "number" ? duration(r.wallMs) : null;
1785
1789
  }
1786
- // ONE builder for a Runs card's last line, job card and sub-card alike: "$0.0616 · 6m23s · 2026-10-06 · 1 run". The separators are real
1787
- // text between the parts (a CSS ::before is not text: a text read of the card ran "2026-10-061 run" together).
1788
- function runMetaLineHtml(r, extra){
1789
- var bits = [runSpendText(r), runWallText(r), runAtText(r), extra].filter(function(b){ return b !== null && b !== undefined; });
1790
- return '<span class="wf-meta-line">' + bits.map(function(b){ return '<span class="wf-meta">' + escapeXml(b) + '</span>'; }).join('<span class="wf-sep"> · </span>') + '</span>';
1790
+ // The ONE date of every card in the runs list: local `MM/DD HH:MM` (the mockup's "10/13 19:12"). An unparseable stamp is shown raw, never blank.
1791
+ function rlShortDate(iso){
1792
+ var d = new Date(iso);
1793
+ if(isNaN(d.getTime())) return String(iso);
1794
+ var t = function(n){ return ("0" + n).slice(-2); };
1795
+ return t(d.getMonth() + 1) + "/" + t(d.getDate()) + " " + t(d.getHours()) + ":" + t(d.getMinutes());
1791
1796
  }
1792
1797
  function runAtText(r){
1793
- return r.at ? r.at.slice(0,10) : (r.askedAt ? "asked " + readableDateTime(r.askedAt) : (r.startedAt ? "started " + readableDateTime(r.startedAt) : (r.atWhy || "unknown")));
1798
+ var when = r.at || r.askedAt || r.startedAt;
1799
+ return when ? rlShortDate(when) : (r.atWhy || "unknown");
1794
1800
  }
1795
1801
  function groupRunsByFlow(runs){
1796
1802
  var byFlow = {};
@@ -1807,8 +1813,6 @@
1807
1813
  runs: flowRuns,
1808
1814
  runCount: last.runId === null ? 0 : flowRuns.length,
1809
1815
  lastRunId: last.runId,
1810
- lastGlyph: last.glyph,
1811
- lastLabel: last.label,
1812
1816
  lastRow: last,
1813
1817
  };
1814
1818
  });
@@ -1831,137 +1835,207 @@
1831
1835
  ));
1832
1836
  }
1833
1837
 
1834
- // Pure rule: when filters/search are active, a flow whose LATEST run
1835
- // doesn't match but an older one does auto-expands so the matching run is
1836
- // visible without an extra click; inactive filters never force an expand.
1837
- function autoExpandFlow(group, matchingRuns, active){
1838
- if(!active || !matchingRuns.length) return false;
1839
- var latestId = group.runs.length ? group.runs[0].runId : null;
1840
- var latestIncluded = matchingRuns.some(function(r){ return r.runId === latestId; });
1841
- return !latestIncluded;
1838
+ // ---- 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
1840
+ // 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
+ // 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
+ var rlData = { rows: [], jobs: [], scheduled: [], limits: { quietDays: 0, olderRuns: 0 } };
1843
+ // 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
+ var rlOpen = {};
1845
+ // 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 };
1847
+ // The ONE writer of `rlData`: the whole /api/runs payload, as the server sent it.
1848
+ function setRunsData(r){
1849
+ rlData = { rows: r.rows || [], jobs: r.jobs || [], scheduled: r.scheduled || [], limits: r.limits || rlData.limits };
1850
+ }
1851
+ function rlModel(data, groups, filters, limits, sel, open){
1852
+ var active = filtersActive(filters);
1853
+ var place = {};
1854
+ (data.jobs || []).forEach(function(j, i){ place[j.flow] = { quiet: j.quiet === true, at: i }; });
1855
+ var cards = groups.slice().sort(function(a, b){
1856
+ return (place[a.flow] ? place[a.flow].at : Infinity) - (place[b.flow] ? place[b.flow].at : Infinity);
1857
+ }).map(function(g){
1858
+ 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 } };
1860
+ var head = g.runs[0];
1861
+ var matching = active ? filterRuns(g.runs, filters, Date.now()) : g.runs;
1862
+ var older = g.runs.slice(1);
1863
+ 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; }));
1868
+ // 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);
1870
+ return {
1871
+ flow: g.flow, group: g, head: head, empty: false, quiet: quiet, count: g.runCount, sel: sel,
1872
+ 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 },
1874
+ };
1875
+ });
1876
+ var quietCards = cards.filter(function(c){ return c.quiet; });
1877
+ return {
1878
+ running: data.rows.filter(function(r){ return r.live === true; }),
1879
+ needs: data.rows.filter(function(r){ return typeof r.needs === "string" && r.needs !== ""; }),
1880
+ scheduled: data.scheduled || [],
1881
+ jobs: cards.filter(function(c){ return !c.quiet; }),
1882
+ quiet: quietCards,
1883
+ quietOpen: Object.prototype.hasOwnProperty.call(open, "__quiet") ? open.__quiet : quietCards.some(function(c){ return c.selected; }),
1884
+ limits: limits,
1885
+ noRows: data.rows.length === 0,
1886
+ };
1842
1887
  }
1843
-
1844
- // ONE owner for "which run does this parent row stand for" — both its own
1845
- // selected state and what its click opens read this, never two separate
1846
- // rules that could drift. Unfiltered (or when the latest still matches),
1847
- // a flow's parent always stands for its latest run. With a filter/search
1848
- // that matches an OLDER run but excludes the latest, the parent stands
1849
- // for the newest MATCHING run instead.
1850
- function representedRun(group, candidateRuns, active){
1851
- if(active && candidateRuns.length){
1852
- var latestIncluded = candidateRuns.some(function(r){ return r.runId === group.lastRunId; });
1853
- if(!latestIncluded) return candidateRuns[0].runId;
1854
- }
1855
- return group.lastRunId;
1888
+ function rlSectHtml(label, n, note){
1889
+ return '<div class="rl-sect">' + label + ' (' + n + ')' + (note ? ' ' + note : '') + '</div>';
1890
+ }
1891
+ // line 1 and 2 of a Running now / Needs you card; both jump to the run (rlJump). The tag is a label (a span), never a button.
1892
+ function rlJumpCardHtml(r, need){
1893
+ var cost = r.spend || "unknown";
1894
+ 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>' +
1898
+ '<span class="rl-l2">' + escapeXml(r.label || "unknown") + (need ? ' &middot; ' + escapeXml(runAtText(r)) : '') + '</span></button>';
1899
+ }
1900
+ // 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
+ // A job with no run has nothing to open: that card stays a plain box.
1902
+ function rlScheduledCardHtml(s){
1903
+ 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>' +
1905
+ '<span class="rl-l2">' + escapeXml([s.in, s.words].filter(function(x){ return x; }).join(" · ")) + '</span>';
1906
+ if(typeof s.runId !== "string" || s.runId === "") return '<div class="rl-card" data-testid="rl-sched-' + escapeXml(s.flow) + '">' + body + '</div>';
1907
+ 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
+ }
1909
+ function rlTopHtml(m){
1910
+ var h = "";
1911
+ if(m.running.length) h += rlSectHtml("Running now", m.running.length) + m.running.map(function(r){ return rlJumpCardHtml(r, false); }).join("");
1912
+ 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
+ return h;
1915
+ }
1916
+ // a run card inside a job: `[sign] run-N date · model` / `word — why · $cost · wall`
1917
+ function rlRunCardHtml(r, selected){
1918
+ var why = (r.word === "passed" && r.glyph === "[✓]" && !r.line) ? "goal met" : r.line;
1919
+ 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>' +
1922
+ '<span class="rl-l2">' + signHtml(r.word, why, r.label) + ' &middot; ' + escapeXml(bits.join(" · ")) + '</span></button>';
1923
+ }
1924
+ // 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.
1925
+ function rlJobCardHtml(c){
1926
+ var h = c.head;
1927
+ var top = '<div class="rl-card' + (c.selected ? ' rl-sel' : '') + '" id="rl-job-' + escapeXml(c.flow) + '" data-testid="rl-job-' + escapeXml(c.flow) + '">';
1928
+ if(c.empty){
1929
+ return top + '<span class="rl-l1"><span class="dot grey"></span><span class="rl-nm" title="' + escapeXml(c.flow) + '">' + escapeXml(c.flow) + '</span></span><span class="rl-l2">' + escapeXml(h.why || "no runs yet") + '</span></div>';
1930
+ }
1931
+ var why = (h.word === "passed" && h.glyph === "[✓]" && !h.line) ? "goal met" : h.line;
1932
+ var isSel = function(r){ return c.sel.flow === c.flow && r.runId === c.sel.runId; };
1933
+ 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
+ '<span class="rl-l2">' + signHtml(h.word, why, h.label, " &middot; ") + '</span>' +
1935
+ '<div class="rl-runs">' + rlRunCardHtml(h, isSel(h));
1936
+ if(c.older.total > 0){
1937
+ 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
+ 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>';
1941
+ }
1942
+ }
1943
+ return out + '</div></div>';
1856
1944
  }
1857
-
1858
- // Is `currentRunId` one of this flow's OLDER runs (i.e. a run that
1859
- // belongs to this flow but isn't its latest)? Selecting a run from
1860
- // History and switching to Workflows lands here: the flow must
1861
- // auto-expand and its matching child row must carry the selected marker
1862
- // even though no filter/search is active.
1863
- function activeOlderRun(group){
1864
- if(currentFlow !== group.flow || !currentRunId || currentRunId === group.lastRunId) return null;
1865
- var found = group.runs.some(function(r){ return r.runId === currentRunId; });
1866
- return found ? currentRunId : null;
1945
+ function rlJobsHtml(m){
1946
+ var h = "";
1947
+ if(m.jobs.length) h += rlSectHtml("Jobs", m.jobs.length, "· run in the last " + m.limits.quietDays + " days") + m.jobs.map(rlJobCardHtml).join("");
1948
+ if(m.quiet.length){
1949
+ h += '<button class="rl-fold" type="button" data-rl-fold="__quiet" data-testid="rl-fold-quiet" aria-expanded="' + (m.quietOpen ? 'true' : 'false') + '">' + (m.quietOpen ? '▾' : '▸') + ' quiet jobs (' + m.quiet.length + ') · no run in ' + m.limits.quietDays + ' days</button>';
1950
+ if(m.quietOpen) h += m.quiet.map(rlJobCardHtml).join("");
1951
+ }
1952
+ if(h === "" && m.noRows) h = '<div class="hint">no runs listed yet — no flow under this root has been run</div>';
1953
+ return h;
1867
1954
  }
1868
-
1869
- // manual expand/collapse memory, keyed by flow name — survives a
1870
- // re-render triggered by a filter/search change within the same page
1871
- // load, reset on full page reload (per-viewer convenience only, never
1872
- // persisted). A manual collapse click still wins over auto-expand-for-
1873
- // selection on the next render.
1874
- var wfExpanded = {};
1875
-
1876
- // am41 item 5: a job card shows its latest 7 sub-cards (`runs` is newest first); the rest are reached by search.
1877
- function capChildRuns(runs){
1878
- return {shown: runs.slice(0, 7), hidden: Math.max(0, runs.length - 7)};
1955
+ // Running now / Needs you: "time so far" counts up IN PLACE from the run's start time (no rebuild): the page's 2 s tick calls this.
1956
+ function tickSince(){
1957
+ document.querySelectorAll("[data-rl-since]").forEach(function(el){
1958
+ var t = Date.parse(el.getAttribute("data-rl-since"));
1959
+ el.textContent = isNaN(t) ? "time unknown" : duration(Math.max(0, Date.now() - t));
1960
+ });
1879
1961
  }
1880
-
1881
- function renderWorkflows(flows){
1882
- var el = document.getElementById("wf-list");
1883
- el.innerHTML = "";
1884
- if(!flows.length){
1885
- el.innerHTML = '<div class="hint">no runs listed yet — no flow under this root has been run</div>';
1962
+ // The ONE painter of the list. Called by the filter bar (a poll, a chip, the search box) and by every click here; it writes a box only when its markup changed.
1963
+ function paintRunsList(){
1964
+ var filters = currentRunsFilters();
1965
+ var groups = filterWorkflows(groupRunsByFlow(rlData.rows), filters, Date.now());
1966
+ var m = rlModel(rlData, groups, filters, rlData.limits, { flow: currentFlow, runId: currentRunId }, rlOpen);
1967
+ var topEl = document.getElementById("rl-top");
1968
+ var listEl = document.getElementById("wf-list");
1969
+ var top = rlTopHtml(m);
1970
+ var jobs = rlJobsHtml(m);
1971
+ if(top !== rlLast.top){ rlLast.top = top; withFocusPreserved(topEl, function(){ topEl.innerHTML = top; }); }
1972
+ if(jobs !== rlLast.jobs){ rlLast.jobs = jobs; withFocusPreserved(listEl, function(){ listEl.innerHTML = jobs; }); }
1973
+ tickSince();
1974
+ }
1975
+ // 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){
1977
+ selectRun(flow, runId, null, ".inbox-row");
1978
+ document.getElementById("tab-run").click();
1979
+ paintRunsList();
1980
+ var card = document.getElementById("rl-job-" + flow);
1981
+ if(card && card.scrollIntoView) card.scrollIntoView({ block: "nearest" });
1982
+ }
1983
+ function rlRowOf(key){
1984
+ var p = String(key).split("|");
1985
+ return rlData.rows.find(function(r){ return r.flow === p[0] && r.runId === p[1]; }) || null;
1986
+ }
1987
+ // one delegated click handler for the whole list: a fold, a jump card or a run card
1988
+ function rlClick(ev){
1989
+ var t = ev.target && ev.target.closest ? ev.target : null;
1990
+ if(!t) return;
1991
+ var fold = t.closest("[data-rl-fold]");
1992
+ if(fold){
1993
+ rlOpen[fold.getAttribute("data-rl-fold")] = fold.getAttribute("aria-expanded") !== "true";
1994
+ paintRunsList();
1886
1995
  return;
1887
1996
  }
1888
- var active = filtersActive(currentRunsFilters());
1889
- flows.forEach(function(g){
1890
- if(g.lastRunId === null){ el.appendChild(buildRunRowEl(g.lastRow)); return; } // "this flow has no runs yet"
1891
- // the parent row IS the flow's latest run (clicking it opens that
1892
- // run), so the inline child list must be the flow's OTHER runs only.
1893
- // Expand affordance (caret, aria-expanded, toggle) is gated on there
1894
- // being a child to actually show.
1895
- var candidateRuns = active ? filterRuns(g.runs, currentRunsFilters(), Date.now()) : g.runs;
1896
- var childRuns = candidateRuns.filter(function(r){ return r.runId !== g.lastRunId; });
1897
- var hasOtherRuns = childRuns.length > 0;
1898
- var olderSelected = activeOlderRun(g);
1899
- var autoExpand = hasOtherRuns && (autoExpandFlow(g, candidateRuns, active) || !!olderSelected);
1900
- var expanded = hasOtherRuns && (Object.prototype.hasOwnProperty.call(wfExpanded, g.flow) ? wfExpanded[g.flow] : autoExpand);
1901
- var targetRunId = representedRun(g, candidateRuns, active);
1902
-
1903
- var wrap = document.createElement("div");
1904
- wrap.className = "wf-job";
1905
-
1906
- var row = document.createElement("div");
1907
- // a flow (parent) row also opens its latest run in the Run tab, same
1908
- // as a child row — computed HERE, at render time (this function tears
1909
- // down and rebuilds every row on every click).
1910
- var isSelected = currentFlow === g.flow && currentRunId === targetRunId;
1911
- row.className = "wf-row" + (isSelected ? " selected" : "");
1912
- row.setAttribute("data-wf", g.flow);
1913
- row.setAttribute("data-testid", "wf-row-" + g.flow);
1914
- row.setAttribute("tabindex", "0");
1915
- row.setAttribute("role", "button");
1916
- row.setAttribute("aria-expanded", expanded ? "true" : "false");
1917
- row.setAttribute("aria-pressed", isSelected ? "true" : "false");
1918
- var wfFullName = g.flow + ' (' + g.lastRunId + ')';
1919
- row.innerHTML =
1920
- '<span class="wf-line1"><span class="wf-caret">' + (hasOtherRuns ? (expanded ? "▼" : "▶") : "") + '</span><span class="' + dotClass(g.lastGlyph, g.lastRow.pulse) + '"></span>' +
1921
- '<span class="wf-name" title="' + escapeXml(wfFullName) + '">' + escapeXml(wfFullName) + '</span></span>' +
1922
- '<span class="wf-sign-line" data-testid="run-sign-word">' + signHtml(g.lastRow.word, g.lastRow.line, g.lastLabel) + '</span>' +
1923
- runMetaLineHtml(g.lastRow, g.runCount + ' run' + (g.runCount === 1 ? '' : 's'));
1924
- row.addEventListener("click", function(){
1925
- // a single-run flow has nothing to expand — the click still opens
1926
- // the run, it just never toggles `wfExpanded` for it.
1927
- if(hasOtherRuns) wfExpanded[g.flow] = !expanded;
1928
- openRunFromRuns(g.runs.filter(function(x){ return x.runId === targetRunId; })[0] || g.lastRow, null);
1929
- renderWorkflows(flows);
1930
- });
1931
- row.addEventListener("keydown", function(e){ if(e.key === "Enter" || e.key === " "){ e.preventDefault(); row.click(); } });
1932
- wrap.appendChild(row);
1933
-
1934
- if(expanded){
1935
- var runsWrap = document.createElement("div");
1936
- runsWrap.className = "wf-runs";
1937
- var capped = capChildRuns(childRuns);
1938
- capped.shown.forEach(function(r){ runsWrap.appendChild(buildRunRowEl(r, { sub: true })); });
1939
- if(capped.hidden > 0) runsWrap.appendChild(textDiv("hint wf-older", "older runs: use search"));
1940
- wrap.appendChild(runsWrap);
1941
- }
1942
- el.appendChild(wrap);
1943
- });
1997
+ var jump = t.closest("[data-rl-jump]");
1998
+ if(jump){
1999
+ var j = String(jump.getAttribute("data-rl-jump")).split("|");
2000
+ rlJump(j[0], j[1]);
2001
+ return;
2002
+ }
2003
+ var card = t.closest("[data-rl-run]");
2004
+ var row = card ? rlRowOf(card.getAttribute("data-rl-run")) : null;
2005
+ if(row){
2006
+ openRunFromRuns(row, null);
2007
+ paintRunsList();
2008
+ }
1944
2009
  }
2010
+ document.getElementById("panel-runs").addEventListener("click", rlClick);
1945
2011
 
1946
2012
  // ---- Filter bar — ONE component, ONE state shape ({results, time,
1947
- // search}), used by BOTH the History tab (filters individual runs) and
1948
- // the Workflows tab (filters by each flow's OWN latest-run fields).
2013
+ // search}), used by the one runs list (a job stays when ANY of its runs match).
1949
2014
  // bareloop's checkType (deterministic/rubric) chips are dropped — fwdloop
1950
2015
  // has no such concept; the result chips use fwdloop's own glyph
1951
2016
  // vocabulary ([✓]/[✗]/[·]/[▶]/[?] — `[▶]` running is known from M4c's pid
1952
2017
  // rows, src/liveness.js).
1953
- function filterBarHTML(scope){
2018
+ // `noSigns`: M11 am3 item 4 — the Inbox has no sign chips; M11 am4 item 4 — it has the status chips instead (accepted / redo / rerun / expired, the
2019
+ // row status the server sends; the rerun chip is the status `reran`), picked into the same `results` list.
2020
+ // The ONE map of an Inbox row's status to the word on its chip (`reran` reads "rerun"); the Inbox search matches the chip word too.
2021
+ var INBOX_CHIP_WORD = { accepted: "accepted", redo: "redo", reran: "rerun", expired: "expired" };
2022
+ function filterBarHTML(scope, noSigns){
1954
2023
  return (
1955
2024
  '<div class="filterbar" data-scope="' + scope + '" data-testid="' + scope + '-filters">' +
1956
- '<input type="text" class="search-input" placeholder="search flow or run id…" ' +
2025
+ '<input type="text" class="search-input" placeholder="' + (noSigns ? 'search job, run, status, question or reason…' : 'search flow or run id…') + '" ' +
1957
2026
  'id="' + scope + '-filter-search" data-testid="' + scope + '-filter-search" autocomplete="off">' +
1958
2027
  '<div class="chips" role="group" aria-label="Filter">' +
2028
+ (noSigns ?
2029
+ Object.keys(INBOX_CHIP_WORD).map(function(st){
2030
+ var w = INBOX_CHIP_WORD[st];
2031
+ return '<button class="chip fchip" type="button" aria-pressed="false" data-filter-group="result" data-filter-value="' + st + '" title="' + w + '" data-testid="chip-' + scope + '-st-' + w + '">' + w + '</button>';
2032
+ }).join('') :
1959
2033
  '<button class="chip fchip" type="button" aria-pressed="false" data-filter-group="result" data-filter-value="[✓]" title="passed" data-testid="chip-' + scope + '-res-pass">✓</button>' +
1960
2034
  '<button class="chip fchip" type="button" aria-pressed="false" data-filter-group="result" data-filter-value="[✗]" title="stopped" data-testid="chip-' + scope + '-res-fail">✗</button>' +
1961
2035
  '<button class="chip fchip" type="button" aria-pressed="false" data-filter-group="result" data-filter-value="[■]" title="stopped, can be resumed" data-testid="chip-' + scope + '-res-stopped">■</button>' +
1962
2036
  '<button class="chip fchip" type="button" aria-pressed="false" data-filter-group="result" data-filter-value="[·]" title="waiting on a human" data-testid="chip-' + scope + '-res-waiting">&middot;</button>' +
1963
2037
  '<button class="chip fchip" type="button" aria-pressed="false" data-filter-group="result" data-filter-value="[▶]" title="running" data-testid="chip-' + scope + '-res-running">▶</button>' +
1964
- '<button class="chip fchip" type="button" aria-pressed="false" data-filter-group="result" data-filter-value="[?]" title="died or unknown" data-testid="chip-' + scope + '-res-unknown">?</button>' +
2038
+ '<button class="chip fchip" type="button" aria-pressed="false" data-filter-group="result" data-filter-value="[?]" title="died or unknown" data-testid="chip-' + scope + '-res-unknown">?</button>') +
1965
2039
  '<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>' +
1966
2040
  '<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>' +
1967
2041
  '<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>' +
@@ -2009,7 +2083,7 @@
2009
2083
  * One filter-bar instance: its own localStorage key, its own DOM scope
2010
2084
  * (`.filterbar[data-scope="..."]`), its own item list — but the same
2011
2085
  * wiring as every other instance.
2012
- * @param {{scope:string, storageKey:string, filterFn:Function, applyFn:Function}} opts
2086
+ * @param {{scope:string, storageKey:string, noun?:string, filterFn:Function, applyFn:Function}} opts
2013
2087
  */
2014
2088
  function createFilterBar(opts){
2015
2089
  var scope = opts.scope;
@@ -2049,7 +2123,7 @@
2049
2123
  var filtered = opts.filterFn(allItems, state, Date.now());
2050
2124
  opts.applyFn(filtered);
2051
2125
  var countEl = document.getElementById(scope + "-filter-count");
2052
- if(countEl) countEl.textContent = "showing " + filtered.length + " of " + allItems.length + " runs";
2126
+ if(countEl) countEl.textContent = "showing " + filtered.length + " of " + allItems.length + " " + (opts.noun || "runs");
2053
2127
  }
2054
2128
  document.querySelectorAll('.filterbar[data-scope="' + scope + '"] .chip[data-filter-group]').forEach(function(chip){
2055
2129
  chip.addEventListener("click", function(){
@@ -2093,33 +2167,14 @@
2093
2167
  };
2094
2168
  }
2095
2169
 
2096
- // Workflows/History view-mode memory — same per-viewer-convenience
2097
- // posture as every other localStorage read/write on this page.
2098
- var RUNS_VIEW_KEY = "fwdloop-panel-runs-view";
2099
- function loadRunsViewMode(){
2100
- try{
2101
- var v = localStorage.getItem(RUNS_VIEW_KEY);
2102
- if(v === "workflows" || v === "history") return v;
2103
- }catch(e){ /* per-viewer convenience only */ }
2104
- return "workflows";
2105
- }
2106
- function saveRunsViewMode(v){
2107
- try{ localStorage.setItem(RUNS_VIEW_KEY, v); }catch(e){ /* best-effort only */ }
2108
- }
2109
-
2110
- // ONE shared filter bar drives whichever view (Workflows/History) is
2111
- // currently on — one scope, one localStorage key, so switching views
2112
- // never loses the search/chip state.
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.
2113
2171
  document.getElementById("runs-filterbar-anchor").innerHTML = filterBarHTML("runs");
2114
2172
 
2115
- var runsViewMode = loadRunsViewMode();
2116
2173
  function runsFilterFn(items, filters, nowMs){
2117
- if(runsViewMode === "history") return filterRuns(items, filters, nowMs);
2118
2174
  return filterWorkflows(groupRunsByFlow(items), filters, nowMs);
2119
2175
  }
2120
- function runsApplyFn(filtered){
2121
- if(runsViewMode === "history") renderHistory(filtered);
2122
- else renderWorkflows(filtered);
2176
+ function runsApplyFn(){
2177
+ paintRunsList();
2123
2178
  }
2124
2179
  var runsFilterBar = createFilterBar({
2125
2180
  scope: "runs",
@@ -2130,24 +2185,6 @@
2130
2185
  function currentRunsFilters(){
2131
2186
  return runsFilterBar ? runsFilterBar.getState() : { results: [], time: "all", search: "" };
2132
2187
  }
2133
- function paintRunsViewToggle(){
2134
- document.querySelectorAll('.chip[data-runs-view]').forEach(function(c){
2135
- c.setAttribute("aria-pressed", c.getAttribute("data-runs-view") === runsViewMode ? "true" : "false");
2136
- });
2137
- document.getElementById("wf-list").hidden = runsViewMode !== "workflows";
2138
- document.getElementById("history-list").hidden = runsViewMode !== "history";
2139
- }
2140
- document.querySelectorAll('.chip[data-runs-view]').forEach(function(chip){
2141
- chip.addEventListener("click", function(){
2142
- var next = chip.getAttribute("data-runs-view");
2143
- if(next === runsViewMode) return;
2144
- runsViewMode = next;
2145
- saveRunsViewMode(runsViewMode);
2146
- paintRunsViewToggle();
2147
- runsFilterBar.refresh();
2148
- });
2149
- });
2150
- paintRunsViewToggle();
2151
2188
 
2152
2189
  // item 4: phone-only "scroll the run view into view" on row select, and
2153
2190
  // the matching "↑ list" jump back. Desktop never runs either — both panes
@@ -2170,13 +2207,39 @@
2170
2207
  }
2171
2208
 
2172
2209
  function clearSelection(selector){
2173
- document.querySelectorAll(".wf-row, .hist-row, .inbox-row").forEach(function(r){ r.classList.remove("selected"); r.setAttribute("aria-pressed","false"); });
2210
+ document.querySelectorAll(".inbox-row").forEach(function(r){ r.classList.remove("selected"); r.setAttribute("aria-pressed","false"); });
2174
2211
  }
2175
2212
 
2176
2213
  // ---- Run tab: header + summary + step map + one card per step ATTEMPT
2177
2214
  // (ruling A, 2026-09-26: "no per-round parts") — built off getRunDetail's
2178
2215
  // `steps[]` (declaration.steps joined with audit.jsonl attempts), never a
2179
2216
  // second client-side re-derivation of the step list. ----
2217
+ // ---- 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
+ // src/summary-words.js); this only paints them. ENDED / NEXT while a finished run; SCHEDULED / NEXT for a job with a trigger.
2219
+ // 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>';
2223
+ }
2224
+ function renderSummary(detail){
2225
+ var sm = detail.summary || {};
2226
+ var ended = document.getElementById("ended-block");
2227
+ var sched = document.getElementById("sched-block");
2228
+ 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 = ""; }
2240
+ note.hidden = !sm.catchUp;
2241
+ note.textContent = sm.catchUp || "";
2242
+ }
2180
2243
  function renderRun(detail){
2181
2244
  var name = document.getElementById("active-wf-name");
2182
2245
  var dot = document.getElementById("active-wf-dot");
@@ -2196,6 +2259,7 @@
2196
2259
 
2197
2260
  document.getElementById("run-empty").hidden = true;
2198
2261
  document.getElementById("run-content").hidden = false;
2262
+ renderSummary(detail);
2199
2263
 
2200
2264
  // "took Xs" for a finished run, straight off the history row's own
2201
2265
  // wallMs (never derived/guessed) — a died/parked run or one whose
@@ -2287,6 +2351,11 @@
2287
2351
  el.innerHTML = "";
2288
2352
  // amendment 7 item 6: Run again sits first, with Stop and Resume — every run control in this one row
2289
2353
  el.appendChild(makeButton("Run again", "run-again", function(){ if(window.fwdloopRunAgain) window.fwdloopRunAgain(detail); }));
2354
+ // 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
+ // 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
+ var schedDoor = function(){ if(window.fwdloopRunAgain) window.fwdloopRunAgain(detail); };
2357
+ if(detail.summary && detail.summary.scheduled) el.appendChild(makeButton("Cancel / modify schedule", "run-cancel-schedule", schedDoor));
2358
+ else if(detail.summary && detail.summary.canSchedule) el.appendChild(makeButton("Schedule run", "run-schedule", schedDoor));
2290
2359
  if(stopSay && stopSay.key !== detail.flow + "/" + detail.runId) stopSay = null;
2291
2360
  if(c.canStop){
2292
2361
  var stopBtn = makeButton(c.stopRequested ? "stopping after this step\u2026" : "Stop", "run-stop", function(){
@@ -3081,7 +3150,7 @@
3081
3150
  // ---- The ONE refresh loop (M4b piece 4, widened by the M4c exit walk). The page used to load
3082
3151
  // once, so a run that parked after load kept `[▶]`, Inbox stayed (0) and the run header kept its
3083
3152
  // first words. Now `pageTick` runs every LIVE_POLL_MS for the whole life of the page: it re-reads
3084
- // the Runs list, History/Workflows, the Inbox list + (N), and the selected run's detail, asks and
3153
+ // the Runs list, the Inbox list + (N), and the selected run's detail, asks and
3085
3154
  // audit — all through the SAME render functions, so the same guards hold (`holdAskRender` never
3086
3155
  // redraws over a typed reason; a refusal lives in `answerMsg` and is repainted). `startLive` no
3087
3156
  // longer owns a timer: it only names the answer being watched, and the tick judges it from the
@@ -3111,11 +3180,11 @@
3111
3180
  lastListsAt = Date.now();
3112
3181
  getJSON("/api/inbox").then(function(r){ renderInbox(r.rows || [], r.openCount); paintUpdateBar(r.version); }).catch(function(){});
3113
3182
  getJSON("/api/runs").then(function(r){
3114
- var rows = r.rows || [];
3115
- var next = sig(rows);
3183
+ var next = sig(r);
3116
3184
  if(next !== null && next === lastSig.runs) return;
3117
3185
  lastSig.runs = next;
3118
- withScrollPreserved(["left-pane-body"], function(){ runsFilterBar.setItems(rows); runsFilterBar.refresh(); });
3186
+ setRunsData(r);
3187
+ withScrollPreserved(["left-pane-body"], function(){ runsFilterBar.setItems(rlData.rows); runsFilterBar.refresh(); });
3119
3188
  }).catch(function(){});
3120
3189
  }
3121
3190
  // The ONE way the Ask tab is drawn from the books: the Ask tab is drawn from the books AND the page's own pending answer ("working…" block).
@@ -3153,6 +3222,7 @@
3153
3222
  var catchUp = wasHidden; // first tick after the tab came back: force both
3154
3223
  wasHidden = false;
3155
3224
  tickLeft();
3225
+ tickSince();
3156
3226
  var watch = live;
3157
3227
  var sel = currentFlow !== null && currentRunId !== null;
3158
3228
  var watchIsSelected = watch && sel && watch.flow === currentFlow && watch.runId === currentRunId;
@@ -3224,12 +3294,13 @@
3224
3294
  });
3225
3295
 
3226
3296
  getJSON("/api/runs").then(function(result){
3227
- var runs = result.rows || [];
3297
+ setRunsData(result);
3298
+ var runs = rlData.rows;
3228
3299
  runsFilterBar.setItems(runs);
3229
3300
  var first = runs.find(function(r){ return r.runId !== null; });
3230
3301
  if(first){
3231
3302
  // the LEFT side is not switched here: a load or refresh always opens on the Chat tab (hamr 2026-10-06)
3232
- // newest run overall, opened directly — the Workflows view starts
3303
+ // newest run overall, opened directly — the job's older runs start
3233
3304
  // collapsed, but its flow row still renders "selected" since
3234
3305
  // `runsFilterBar.refresh()` re-renders AFTER currentFlow/currentRunId
3235
3306
  // are set.
@@ -3239,7 +3310,6 @@
3239
3310
  }
3240
3311
  }).catch(function(e){
3241
3312
  document.getElementById("wf-list").innerHTML = '<div class="hint">' + escapeXml(loadFailureText(e)) + '</div>';
3242
- document.getElementById("history-list").innerHTML = '<div class="hint">' + escapeXml(loadFailureText(e)) + '</div>';
3243
3313
  });
3244
3314
 
3245
3315
  // ---- shared text-node helper — book text (question/draft/artifact
@@ -3326,28 +3396,72 @@
3326
3396
  return wrap;
3327
3397
  }
3328
3398
  var INBOX_HEADS = { 1: "waiting on you", 2: "working on your answer", 3: "answered and expired" };
3399
+ // M11 am3 item 3: every Inbox header carries its count, counted off the rows the server sent (after the filters, for section 3)
3400
+ function inboxHeadText(section, n){ return (INBOX_HEADS[section] || "") + " (" + n + ")"; }
3401
+ // M11 am3 item 4: the Inbox filters act on "answered and expired" (section 3) only; sections 1 and 2 are never hidden. M11 am4 item 4: the status chips
3402
+ // (`results`, none = all) match the row's `status`.
3403
+ // A row's time is its answer, else its expiry (the server orders section 3 by the same two). No date + a time chip = out, as in Runs.
3404
+ // M11 am4 item 3: the Inbox search reads the whole row — job, run, status word, question, answer reason — case-insensitive. (`matchesSearch` stays Runs': job and run only.)
3405
+ function inboxMatchesSearch(r, query){
3406
+ var q = String(query || "").trim().toLowerCase();
3407
+ if(!q) return true;
3408
+ return [r.flow, r.runId, r.status, INBOX_CHIP_WORD[r.status], r.question, r.reason].some(function(x){ return typeof x === "string" && x.toLowerCase().indexOf(q) !== -1; });
3409
+ }
3410
+ function inboxFilterRows(rows, filters, nowMs){
3411
+ var time = (filters && filters.time) || "all";
3412
+ var q = (filters && filters.search) || "";
3413
+ var rs = (filters && filters.results) || [];
3414
+ return (rows || []).filter(function(r){
3415
+ if(r.section !== 3) return true;
3416
+ if(rs.length && rs.indexOf(r.status) === -1) return false;
3417
+ if(!inboxMatchesSearch(r, q)) return false;
3418
+ if(time !== "all"){
3419
+ var days = time === "7d" ? 7 : 30;
3420
+ var t = Date.parse(r.answeredAt || r.expiresAt);
3421
+ if(!isFinite(t) || nowMs - t > days * 24 * 60 * 60 * 1000) return false;
3422
+ }
3423
+ return true;
3424
+ });
3425
+ }
3426
+ document.getElementById("inbox-filterbar-anchor").innerHTML = filterBarHTML("inbox", true);
3427
+ var inboxOpenN = 0, inboxTotal = 0;
3428
+ var inboxBar = createFilterBar({
3429
+ scope: "inbox",
3430
+ storageKey: "fwdloop-panel-inbox-filters",
3431
+ noun: "asks",
3432
+ filterFn: inboxFilterRows,
3433
+ applyFn: function(shown){ buildInbox(document.getElementById("inbox-list"), shown, inboxOpenN); },
3434
+ });
3329
3435
  // N comes from the server (data.js inboxOpenCount); the page only shows it.
3330
3436
  function renderInbox(rows, openCount){
3331
3437
  var el = document.getElementById("inbox-list");
3332
3438
  var next = sig({ rows: rows, openCount: openCount });
3333
3439
  if(next !== null && next === lastSig.inbox) return; // unchanged payload — never rebuild the DOM for nothing
3334
3440
  lastSig.inbox = next;
3335
- withScrollPreserved(["left-pane-body"], function(){ withFocusPreserved(el, function(){ buildInbox(el, rows, openCount); }); });
3441
+ inboxOpenN = openCount;
3442
+ inboxTotal = rows ? rows.length : 0;
3443
+ var old = document.getElementById("inbox-list-old");
3444
+ withScrollPreserved(["left-pane-body"], function(){ withFocusPreserved(old, function(){ withFocusPreserved(el, function(){ inboxBar.setItems(rows); }); }); });
3336
3445
  }
3337
3446
  function buildInbox(el, rows, openCount){
3447
+ var old = document.getElementById("inbox-list-old");
3338
3448
  el.innerHTML = "";
3449
+ old.innerHTML = "";
3339
3450
  document.getElementById("inbox-count-label").textContent = " (" + (typeof openCount === "number" ? openCount : 0) + ")";
3340
- if(!rows || !rows.length){
3451
+ if(!inboxTotal){
3341
3452
  el.innerHTML = '<div class="hint">nothing waiting on you — no stops recorded under this root</div>';
3342
3453
  return;
3343
3454
  }
3455
+ var counts = {};
3456
+ rows.forEach(function(row){ counts[row.section] = (counts[row.section] || 0) + 1; });
3344
3457
  var lastSection = 0;
3345
3458
  rows.forEach(function(row){
3459
+ var into = row.section === 3 ? old : el;
3346
3460
  if(row.section !== lastSection){
3347
3461
  lastSection = row.section;
3348
- el.appendChild(textDiv("inbox-h", INBOX_HEADS[row.section] || ""));
3462
+ into.appendChild(textDiv("inbox-h", inboxHeadText(row.section, counts[row.section])));
3349
3463
  }
3350
- el.appendChild(renderStopRow(row));
3464
+ into.appendChild(renderStopRow(row));
3351
3465
  });
3352
3466
  }
3353
3467
  getJSON("/api/inbox").then(function(result){ renderInbox(result.rows || [], result.openCount); }).catch(function(e){
@@ -4010,6 +4124,12 @@
4010
4124
  var spends = (cap !== undefined && cap !== null && cap !== "") ? " — spends up to $" + cap : "";
4011
4125
  var blocked = !st.startOk || !!st.busy;
4012
4126
  if(st.mode === "run"){
4127
+ // 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
+ // starts nothing; after click 1 it reads "Confirm: <words>". It never reaches the run routes.
4129
+ if(st.whenChanged){
4130
+ var whenText = st.whenConfirm ? "Confirm: " + st.whenConfirm : (st.whenCancel ? "Cancel schedule" : "Sign schedule");
4131
+ return {text: whenText, action: st.whenSigning ? "when-sign" : "when-sign-prepare", disabled: !!st.whenBusy || !!st.busy || !!st.whenLocked};
4132
+ }
4013
4133
  // amendment 5 item 3: inputs alone = Run (one click); a Destination, Cap $ or ask wait different from the flow's = Sign & run (two clicks, bound to a hash)
4014
4134
  if(st.runDiffers){
4015
4135
  if(st.runSignClicked){
@@ -4018,7 +4138,7 @@
4018
4138
  }
4019
4139
  return {text: "Sign & run", action: "run-sign-prepare", disabled: blocked};
4020
4140
  }
4021
- return {text: "Run" + spends, action: "run", disabled: blocked};
4141
+ return {text: "Run now" + spends, action: "run", disabled: blocked || !!st.whenLocked};
4022
4142
  }
4023
4143
  if(st.mode === "resume"){
4024
4144
  if(st.runSignClicked){
@@ -4448,6 +4568,7 @@
4448
4568
  }
4449
4569
  function syncCardLock(){
4450
4570
  var on = cardLocked();
4571
+ whenSyncButton();
4451
4572
  card.querySelectorAll("input[type=text], textarea").forEach(function(el){ el.readOnly = on; el.classList.toggle("locked", on); });
4452
4573
  if(editOf !== null){ byId("jf-name").readOnly = true; byId("jf-name").classList.add("locked"); } // M6: an edit keeps its job's name
4453
4574
  runFlowSel.disabled = on;
@@ -4510,7 +4631,8 @@
4510
4631
  setMode("new");
4511
4632
  setVal("jf-name", f.flow); setVal("jf-job", c.job); setVal("jf-cap-money", c.capUsd);
4512
4633
  setVal("jf-dest-folder", c.destination); setVal("jf-inputs", c.inputs); setVal("jf-ask-wait", c.askWait || "1h");
4513
- 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.";
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 : "");
4514
4636
  editBannerEl.hidden = false;
4515
4637
  chatActionOk();
4516
4638
  refreshCapNote(); fitCardBoxes(); refreshStartEnabled();
@@ -4553,7 +4675,101 @@
4553
4675
  clearFieldErrors();
4554
4676
  refreshCapNote();
4555
4677
  syncEditBtn();
4678
+ paintWhen();
4679
+ }
4680
+ // ---- 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
+ // 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.
4682
+ // A job with no good run gets the dropdown refused with the SERVER's sentence (`trigger.refusal`); the page writes no sentence of its own.
4683
+ var whenHash = null;
4684
+ var whenBusy = false;
4685
+ var whenConfirmText = ""; // the words the button shows after click 1 ("every day at 13:15", "cancel schedule"); read only while whenHash is set
4686
+ var whenLocked = false; // ~1.5 s after a successful sign the main button is disabled, so a fast extra click cannot start a run
4687
+ var whenReady = false; // the lock sync can run before this block has
4688
+ function whenCanon(t){ return t === null ? "null" : JSON.stringify(Object.keys(t).sort().map(function(k){ return [k, t[k]]; })); }
4689
+ function whenTriggerFromBoxes(){
4690
+ var kind = byId("jf-when").value;
4691
+ if(kind === "hand") return null;
4692
+ if(kind === "daily" || kind === "weekdays" || kind === "weekly"){
4693
+ var m = /^(\d{2}):(\d{2})$/.exec(byId("jf-when-time").value);
4694
+ var o = m ? {kind: kind, hour: Number(m[1]), minute: Number(m[2])} : {kind: kind}; // an empty time goes to the server, which says so
4695
+ if(kind === "weekly") o.day = byId("jf-when-day").value;
4696
+ return o;
4697
+ }
4698
+ var q = {kind: kind, role: byId("jf-when-role").value};
4699
+ q[kind === "new-file" ? "folder" : "path"] = byId("jf-when-path").value.trim();
4700
+ return q;
4701
+ }
4702
+ function whenShowSubs(){
4703
+ var kind = byId("jf-when").value;
4704
+ byId("jf-when-clock").hidden = !(kind === "daily" || kind === "weekdays" || kind === "weekly");
4705
+ byId("jf-when-day").hidden = kind !== "weekly";
4706
+ byId("jf-when-filebox").hidden = !(kind === "file-updated" || kind === "new-file");
4707
+ byId("jf-when-path").placeholder = kind === "new-file" ? "/full/path/to/folder" : "/full/path/to/file";
4708
+ }
4709
+ // M9 am4: is When changed from the signed value? The ONE reader; the main button turns into Sign schedule while it is.
4710
+ function whenChanged(){
4711
+ if(!whenReady) return false;
4712
+ var f = selectedFlow();
4713
+ var c = f && f.trigger;
4714
+ return !!c && !c.refusal && whenCanon(whenTriggerFromBoxes()) !== whenCanon(c.trigger);
4715
+ }
4716
+ function whenSyncButton(){
4717
+ if(!whenReady) return;
4718
+ renderMain();
4719
+ }
4720
+ function paintWhen(){
4721
+ var f = selectedFlow();
4722
+ var c = f ? f.trigger : null;
4723
+ var sel = byId("jf-when");
4724
+ whenHash = null; whenBusy = false;
4725
+ byId("jf-err-when").textContent = "";
4726
+ var roleSel = byId("jf-when-role");
4727
+ roleSel.innerHTML = "";
4728
+ ((f && f.roles) || []).forEach(function(r){ var o = document.createElement("option"); o.value = r; o.textContent = r; roleSel.appendChild(o); });
4729
+ var t = c ? c.trigger : null;
4730
+ sel.querySelector('option[value="hand"]').textContent = t ? "Cancel schedule" : "By hand"; // M9 am5: on a scheduled job, By hand reads Cancel schedule
4731
+ sel.value = t ? t.kind : "hand";
4732
+ if(t && t.hour !== undefined){ byId("jf-when-time").value = ("0" + t.hour).slice(-2) + ":" + ("0" + t.minute).slice(-2); }
4733
+ if(t && t.day) byId("jf-when-day").value = t.day;
4734
+ if(t && t.role) roleSel.value = t.role;
4735
+ byId("jf-when-path").value = t ? (t.path || t.folder || "") : "";
4736
+ var refused = !f || !c || !!c.refusal;
4737
+ sel.disabled = refused;
4738
+ byId("jf-when-day").disabled = byId("jf-when-time").disabled = roleSel.disabled = byId("jf-when-path").disabled = refused;
4739
+ byId("jf-when-now").textContent = !c ? "" : (c.refusal ? c.refusal : (c.words ? "Now: " + c.words : ""));
4740
+ whenShowSubs(); whenSyncButton();
4741
+ }
4742
+ function whenEdited(){ whenHash = null; byId("jf-err-when").textContent = ""; whenShowSubs(); whenSyncButton(); }
4743
+ ["jf-when", "jf-when-day", "jf-when-time", "jf-when-role"].forEach(function(id){ document.getElementById(id).addEventListener("change", whenEdited); });
4744
+ document.getElementById("jf-when-path").addEventListener("input", whenEdited);
4745
+ function doWhenSign(){
4746
+ var f = selectedFlow();
4747
+ if(!f || whenBusy || cardLocked()) return;
4748
+ var body = {flow: f.flow, trigger: whenTriggerFromBoxes()};
4749
+ var second = whenHash !== null;
4750
+ if(second) body.hash = whenHash;
4751
+ whenBusy = true; whenSyncButton();
4752
+ authorPost(second ? "/api/author/trigger" : "/api/author/trigger-prepare", body).then(function(r){
4753
+ whenBusy = false;
4754
+ if(!(r.status >= 200 && r.status < 300 && r.body && r.body.ok === true)){
4755
+ whenHash = null; byId("jf-err-when").textContent = refusalText(r); whenSyncButton(); return;
4756
+ }
4757
+ var words = typeof r.body.words === "string" ? r.body.words : "";
4758
+ if(!second){
4759
+ whenHash = r.body.hash;
4760
+ whenConfirmText = words ? words.charAt(0).toLowerCase() + words.slice(1) : "cancel schedule";
4761
+ byId("jf-err-when").textContent = ""; whenSyncButton(); return;
4762
+ }
4763
+ // M9 am5: after click 2 the card clears (like Clear) and nothing runs; the signed schedule is read back by the flows list
4764
+ whenHash = null;
4765
+ whenLocked = true; setTimeout(function(){ whenLocked = false; renderMain(); }, 1500);
4766
+ var say = typeof r.body.say === "string" ? r.body.say : "";
4767
+ resetCard();
4768
+ setMode("new"); // the default empty card a fresh page load shows, not Run a signed flow with the pick emptied
4769
+ if(say) chatActionFailed(say);
4770
+ }).catch(function(){ whenBusy = false; whenHash = null; byId("jf-err-when").textContent = NETWORK_SAY; whenSyncButton(); });
4556
4771
  }
4772
+ whenReady = true;
4557
4773
  // borrowed-from: bareloop src/panel/index.html@b5e37b8 — the Reuse workflow picker: ONE function shows the search box + list before a pick and the
4558
4774
  // picked box after; a row is the name (the typed part marked) over the flow's track record line.
4559
4775
  function rwMark(name, q){
@@ -4785,6 +5001,12 @@
4785
5001
  st.runDiffers = runDiffers();
4786
5002
  st.runSignClicked = !!runSignInfo;
4787
5003
  st.hash = runSignInfo ? runSignInfo.hash : "";
5004
+ st.whenChanged = whenChanged();
5005
+ st.whenSigning = whenHash !== null;
5006
+ st.whenConfirm = whenHash !== null ? whenConfirmText : "";
5007
+ st.whenCancel = whenTriggerFromBoxes() === null;
5008
+ st.whenBusy = whenBusy;
5009
+ st.whenLocked = whenLocked;
4788
5010
  } else if(mode === "resume"){
4789
5011
  st.capUsd = resumeCapEl.value.trim();
4790
5012
  st.runSignClicked = !!resumeSignInfo;
@@ -5207,6 +5429,7 @@
5207
5429
  mainBtn.addEventListener("click", function(){
5208
5430
  if(mainBtn.disabled) return;
5209
5431
  if(mainAction === "draft") doDraft(mainStartOver ? sessionId : null);
5432
+ else if(mainAction === "when-sign-prepare" || mainAction === "when-sign") doWhenSign();
5210
5433
  else if(mainAction === "run") doRun();
5211
5434
  else if(mainAction === "run-sign-prepare" || mainAction === "run-sign") doRunSign();
5212
5435
  else if(mainAction === "resume-sign-prepare" || mainAction === "resume-sign") doResumeSign();