fwdloop 0.37.0 → 0.39.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 (140) hide show
  1. package/README.md +5 -19
  2. package/bin/fwdloop +51 -29
  3. package/package.json +1 -1
  4. package/src/ask.js +70 -148
  5. package/src/audit-fold.js +5 -4
  6. package/src/auditchecks.js +6 -4
  7. package/src/authoring.js +36 -64
  8. package/src/blockasks.js +2 -1
  9. package/src/blockassemble.js +7 -9
  10. package/src/blockdraft.js +2 -2
  11. package/src/blockpick.js +5 -5
  12. package/src/books.js +217 -12
  13. package/src/checkblock.js +25 -55
  14. package/src/checked.js +2 -3
  15. package/src/checklistsign.js +26 -5
  16. package/src/checklook.js +3 -1
  17. package/src/checkpick.js +5 -76
  18. package/src/cited-source.js +4 -4
  19. package/src/citedcheck.js +6 -11
  20. package/src/citedwords.js +9 -8
  21. package/src/closers.js +9 -6
  22. package/src/declaration.js +22 -55
  23. package/src/diary.js +23 -1
  24. package/src/draft-steps.js +11 -1
  25. package/src/drafter.js +28 -23
  26. package/src/draftfiles.js +127 -0
  27. package/src/draftspend.js +165 -17
  28. package/src/flow.js +42 -87
  29. package/src/flowmodel.js +1 -1
  30. package/src/index.js +3 -2
  31. package/src/inside.js +86 -0
  32. package/src/isrec.js +2 -0
  33. package/src/jsonl-append.js +33 -1
  34. package/src/learn.js +1 -1
  35. package/src/learnstore.js +20 -22
  36. package/src/line-checks.js +2 -3
  37. package/src/liveness.js +3 -0
  38. package/src/mcp-use.js +8 -9
  39. package/src/memo.js +13 -16
  40. package/src/minrule.js +16 -0
  41. package/src/model-step.js +3 -3
  42. package/src/page-words.js +8 -0
  43. package/src/pageask.js +8 -3
  44. package/src/pagebits.js +8 -1
  45. package/src/pagedropwords.js +1 -1
  46. package/src/pagerules.js +6 -3
  47. package/src/panel/author.js +121 -78
  48. package/src/panel/authorcard.js +21 -8
  49. package/src/panel/authorflows.js +3 -3
  50. package/src/panel/authorresume.js +3 -3
  51. package/src/panel/authorstart.js +15 -16
  52. package/src/panel/authortrigger.js +43 -70
  53. package/src/panel/data.js +125 -168
  54. package/src/panel/index.html +154 -63
  55. package/src/panel/jobgrid.js +3 -7
  56. package/src/panel/result.js +7 -10
  57. package/src/panel/resume.js +4 -3
  58. package/src/panel/scheduler.js +9 -9
  59. package/src/panel/server.js +8 -4
  60. package/src/panel/spawn.js +22 -11
  61. package/src/panel/tickets.js +2 -2
  62. package/src/pickrecord.js +51 -31
  63. package/src/placerule.js +3 -4
  64. package/src/planrebuild.js +19 -19
  65. package/src/primitives.js +1 -1
  66. package/src/provider.js +1 -1
  67. package/src/reasons.js +25 -0
  68. package/src/report.js +2 -1
  69. package/src/runfile.js +26 -2
  70. package/src/runner.js +57 -105
  71. package/src/runvalues.js +47 -24
  72. package/src/schedule-choices.js +41 -0
  73. package/src/schedule-shape.js +39 -0
  74. package/src/schedule.js +9 -8
  75. package/src/setup.js +20 -36
  76. package/src/shaperows.js +2 -2
  77. package/src/sheet-record.js +1 -2
  78. package/src/sheetblock.js +3 -4
  79. package/src/sheetbuild.js +5 -5
  80. package/src/sheetchecks.js +1 -2
  81. package/src/sheetclaims.js +1 -2
  82. package/src/sheetoffer.js +1 -1
  83. package/src/sheetrun.js +5 -7
  84. package/src/summary-words.js +2 -1
  85. package/src/thinking.js +5 -2
  86. package/src/ticketrows.js +8 -30
  87. package/src/trigger-clock.js +9 -23
  88. package/src/trigger-files.js +30 -22
  89. package/src/trigger-tickets.js +15 -14
  90. package/src/try-checks.js +2 -1
  91. package/src/types.js +2 -0
  92. package/types/ask.d.ts +25 -20
  93. package/types/authoring.d.ts +8 -42
  94. package/types/blockassemble.d.ts +0 -1
  95. package/types/blockpick.d.ts +1 -1
  96. package/types/books.d.ts +256 -4
  97. package/types/checkblock.d.ts +2 -25
  98. package/types/checklist.d.ts +3 -3
  99. package/types/checklistsign.d.ts +7 -0
  100. package/types/checkpick.d.ts +0 -21
  101. package/types/citedwords.d.ts +7 -4
  102. package/types/closers.d.ts +1 -0
  103. package/types/declaration.d.ts +4 -14
  104. package/types/diary.d.ts +14 -1
  105. package/types/draft-steps.d.ts +7 -0
  106. package/types/drafter.d.ts +3 -2
  107. package/types/draftfiles.d.ts +89 -0
  108. package/types/draftspend.d.ts +74 -0
  109. package/types/flow.d.ts +32 -54
  110. package/types/index.d.ts +3 -3
  111. package/types/inside.d.ts +58 -0
  112. package/types/isrec.d.ts +1 -0
  113. package/types/jsonl-append.d.ts +20 -0
  114. package/types/learnstore.d.ts +0 -2
  115. package/types/liveness.d.ts +1 -0
  116. package/types/minrule.d.ts +6 -0
  117. package/types/page-words.d.ts +6 -0
  118. package/types/pageask.d.ts +2 -0
  119. package/types/pagebits.d.ts +3 -0
  120. package/types/pagerules.d.ts +1 -0
  121. package/types/panel/author.d.ts +7 -3
  122. package/types/panel/authorcard.d.ts +0 -6
  123. package/types/panel/authorflows.d.ts +4 -4
  124. package/types/panel/authortrigger.d.ts +16 -2
  125. package/types/panel/data.d.ts +36 -11
  126. package/types/panel/spawn.d.ts +18 -2
  127. package/types/pickrecord.d.ts +29 -0
  128. package/types/reasons.d.ts +23 -0
  129. package/types/runfile.d.ts +14 -0
  130. package/types/runner.d.ts +6 -38
  131. package/types/runvalues.d.ts +17 -2
  132. package/types/schedule-choices.d.ts +9 -0
  133. package/types/schedule-shape.d.ts +15 -0
  134. package/types/sheetbuild.d.ts +1 -1
  135. package/types/sheetclaims.d.ts +0 -1
  136. package/types/thinking.d.ts +1 -0
  137. package/types/ticketrows.d.ts +0 -9
  138. package/types/trigger-clock.d.ts +3 -2
  139. package/types/trigger-files.d.ts +15 -4
  140. package/types/types.d.ts +8 -0
@@ -744,11 +744,10 @@
744
744
  .audit-raw{color:var(--text-faint);font-size:11px;word-break:break-word;white-space:pre-wrap;margin-top:2px;}
745
745
  .chat-steps .step-raw{margin-top:2px;color:var(--text-faint);}
746
746
  .chat-steps .step-raw summary{cursor:pointer;}
747
- .chat-steps .step.run .step-sign::after{content:"\2026";}
748
- @keyframes step-dots{0%{content:"";}25%{content:".";}50%{content:"..";}75%{content:"...";}}
749
- @media (prefers-reduced-motion: no-preference){
750
- .chat-steps .step.run .step-sign::after{content:"";animation:step-dots 1.2s steps(1,end) infinite;}
751
- }
747
+ /* borrowed-from: bareloop src/panel/index.html@v0.63.0 (7bc2719b): the step time and the "Drafting so far" line; the animated dots are gone */
748
+ .chat-steps .step-time{color:var(--text-faint);}
749
+ .chat-steps .step-so-far{padding:3px 0 0;color:var(--text-faint);}
750
+ .drafted-line{color:var(--text-faint);font-size:12px;margin-top:6px;}
752
751
 
753
752
  .chat-thread{display:flex;flex-direction:column;gap:10px;margin-bottom:10px;}
754
753
  .chat-thread:empty{display:none;}
@@ -1253,7 +1252,7 @@
1253
1252
  <div class="jf-gut" id="jf-job-gut" data-testid="jf-job-gut" aria-hidden="true"><div class="jf-gut-in"></div></div>
1254
1253
  <textarea class="jf-wrap" id="jf-job" rows="6" data-testid="jf-job" autocomplete="off" spellcheck="false" placeholder="Read my resume&#10;~keep it under 600 words&#10;Ask: check it with me&#10;Write it out"></textarea>
1255
1254
  </div>
1256
- <div class="hint">One step per line. A line starting with <code>~</code> is a guardrail of the step above it. <code>Ask:</code> stops for you; <code>Ask 2h:</code> sets that ask's own wait. Your last line writes the result to the Destination. Leave it out and fwdloop suggests one.</div>
1255
+ <div class="hint">One step per line. A <code>~</code> line under a step is its rule; add at least one. <code>Ask:</code> stops for you (<code>Ask 2h:</code> waits 2h). The last line writes the result to the Destination.</div>
1257
1256
  <div class="jf-err" id="jf-err-job" data-testid="jf-err-job"></div>
1258
1257
  </div>
1259
1258
  <div class="field">
@@ -1282,14 +1281,18 @@
1282
1281
  </div>
1283
1282
  <div class="field" id="jf-sched-field" data-testid="jf-sched-field">
1284
1283
  <label for="jf-sched">Schedule</label>
1285
- <select id="jf-sched" data-testid="jf-sched" aria-label="Schedule">
1286
- <option value="hand">By hand</option>
1287
- <option value="new-ticket">When a new ticket arrives</option>
1288
- <option value="daily">Every day at HH:MM</option>
1289
- </select>
1284
+ <select id="jf-sched" data-testid="jf-sched" aria-label="Schedule"></select>
1290
1285
  <div class="when-sub" id="jf-sched-clock" hidden>
1286
+ <select id="jf-sched-day" data-testid="jf-sched-day" aria-label="Day of the week">
1287
+ <option value="mon">Monday</option><option value="tue">Tuesday</option><option value="wed">Wednesday</option><option value="thu">Thursday</option>
1288
+ <option value="fri">Friday</option><option value="sat">Saturday</option><option value="sun">Sunday</option>
1289
+ </select>
1291
1290
  <input id="jf-sched-time" type="time" value="09:00" data-testid="jf-sched-time" aria-label="Time, HH:MM">
1292
1291
  </div>
1292
+ <div class="when-sub" id="jf-sched-filebox" hidden>
1293
+ <select id="jf-sched-role" data-testid="jf-sched-role" aria-label="Which of the job's inputs"></select>
1294
+ <input id="jf-sched-path" type="text" autocomplete="off" spellcheck="false" data-testid="jf-sched-path" aria-label="File or folder">
1295
+ </div>
1293
1296
  <div class="hint" id="jf-sched-hint" data-testid="jf-sched-hint" hidden>off until the first green run, then turns on</div>
1294
1297
  <div class="hint" id="jf-sched-ticket-hint" data-testid="jf-sched-ticket-hint" hidden>the first run reads the newest ticket at the time it starts; older tickets never run</div>
1295
1298
  <div class="jf-err" id="jf-err-schedule" data-testid="jf-err-schedule"></div>
@@ -1374,15 +1377,7 @@
1374
1377
  </div>
1375
1378
  <div class="field" id="jf-when-field" data-testid="jf-when-field">
1376
1379
  <label for="jf-when">When</label>
1377
- <select id="jf-when" data-testid="jf-when" aria-label="When this job runs">
1378
- <option value="hand">By hand</option>
1379
- <option value="daily">Every day at HH:MM</option>
1380
- <option value="weekdays">Weekdays at HH:MM</option>
1381
- <option value="weekly">Every &lt;day&gt; at HH:MM</option>
1382
- <option value="file-updated">When &lt;file&gt; is updated</option>
1383
- <option value="new-file">When a new file arrives in &lt;folder&gt;</option>
1384
- <option value="new-ticket">When a new ticket arrives in &lt;input name&gt;</option>
1385
- </select>
1380
+ <select id="jf-when" data-testid="jf-when" aria-label="When this job runs"></select>
1386
1381
  <div class="when-sub" id="jf-when-clock" hidden>
1387
1382
  <select id="jf-when-day" data-testid="jf-when-day" aria-label="Day of the week">
1388
1383
  <option value="mon">Monday</option><option value="tue">Tuesday</option><option value="wed">Wednesday</option><option value="thu">Thursday</option>
@@ -1480,6 +1475,8 @@
1480
1475
  <div class="hint" id="chat-action-error" data-testid="chat-action-error"></div>
1481
1476
 
1482
1477
  <button class="btn primary wide" type="button" id="chat-main-btn" data-testid="chat-main" disabled>Draft</button>
1478
+ <!-- M19 am14: POLL-OWNED, written only by renderActions from state.refusal (the words after "draft refused at $0 — "); never by a click handler -->
1479
+ <div class="jf-err" id="chat-draft-refusal" data-testid="chat-draft-refusal"></div>
1483
1480
  <div class="hint" id="chat-main-hint" data-testid="chat-main-hint"></div>
1484
1481
  <!-- M4e amendment 14 item 2: on a green plan, Revise opens every card field (the main button then reads Draft) -->
1485
1482
  <button class="btn wide" type="button" id="chat-revise-btn" data-testid="chat-revise" hidden>Revise</button>
@@ -1677,6 +1674,27 @@
1677
1674
 
1678
1675
  var PORT = "__FWDLOOP_PANEL_PORT__";
1679
1676
  var PLAN_CHECK_RULES = __FWDLOOP_PLAN_CHECK_RULES__;
1677
+ // M20 am5 item 1: the one list of schedule choices per flow type (src/schedule-choices.js); the New job card's Schedule and the Run card's When both fill from it
1678
+ var SCHEDULE_CHOICES = __FWDLOOP_SCHEDULE_CHOICES__;
1679
+ // M20 am8a item 1: the origin tag words, the decisions that need a reason and the draft phases (a revise or redraft running; red or stopped) come from their owners (src/page-words.js); the page asks this list, never spells them
1680
+ var PAGE_WORDS = __FWDLOOP_PAGE_WORDS__;
1681
+ function inWords(list, word){ return list.indexOf(word) >= 0; }
1682
+ // M20 am6: "is this a clock kind" is answered by the server (isClockKind in src/trigger-clock.js), carried on every choice as `clock`
1683
+ function isClockKind(kind){
1684
+ return Object.keys(SCHEDULE_CHOICES).some(function(t){ return SCHEDULE_CHOICES[t].some(function(c){ return c.kind === kind && c.clock; }); });
1685
+ }
1686
+ // M20 am7: "is this a file kind" is answered by the server (isFileKind in src/trigger-files.js), carried on every choice as `file`
1687
+ function isFileKind(kind){
1688
+ return Object.keys(SCHEDULE_CHOICES).some(function(t){ return SCHEDULE_CHOICES[t].some(function(c){ return c.kind === kind && c.file; }); });
1689
+ }
1690
+ // M20 am8: "is this a flow type" is answered by the server (isFlowType in src/declaration.js): the page takes the flow types from the keys of the schedule choices it gets (a test pins the keys to FLOW_TYPES)
1691
+ function flowTypeOr(type){ return typeof type === "string" && Object.prototype.hasOwnProperty.call(SCHEDULE_CHOICES, type) ? type : "plain"; }
1692
+ function fillScheduleOptions(sel, flowType, newCard){
1693
+ var list = SCHEDULE_CHOICES[flowTypeOr(flowType)], keep = sel.value;
1694
+ sel.innerHTML = "";
1695
+ list.forEach(function(c){ var o = document.createElement("option"); o.value = c.kind; o.textContent = newCard ? c.newCardLabel : c.label; sel.appendChild(o); });
1696
+ if(keep && list.some(function(c){ return c.kind === keep; })) sel.value = keep;
1697
+ }
1680
1698
  // No token, no cookie (M4e amendment 4 item 8): the panel is local and trusted; the server checks Host and, on a POST, Origin.
1681
1699
  document.getElementById("host-line").textContent = "127.0.0.1:" + PORT;
1682
1700
 
@@ -3120,12 +3138,13 @@
3120
3138
  var box = document.getElementById("ended-block");
3121
3139
  var note = document.getElementById("catchup-note");
3122
3140
  var sc = sm.schedule || null;
3123
- if(sm.ended || sc){
3141
+ var nowText = typeof sm.now === "string" && sm.now ? sm.now : null;
3142
+ if(sm.ended || sc || nowText){
3124
3143
  var tone = glyphClass(detail.glyph); // M9 am14: the colour of that run's card in the runs list, one decider (its dot)
3125
3144
  if(sc && sc.red === true) tone = "red";
3126
3145
  box.hidden = false;
3127
3146
  box.className = "ended-block" + (tone ? " " + tone : "");
3128
- box.innerHTML = (sm.ended ? summaryRow("ENDED", sm.ended.reason, "ended-reason") + nextRow(sm.ended) : "") +
3147
+ box.innerHTML = (nowText ? summaryRow("NOW", nowText, "now-row") : "") + (sm.ended ? summaryRow("ENDED", sm.ended.reason, "ended-reason") + nextRow(sm.ended) : "") +
3129
3148
  (sc ? summaryRow("SCHEDULE", sc.line1, "sched-line1", sc.red === true) + (sc.line2 ? summaryRow("", sc.line2, "sched-line2", sc.red === true, sc.grey === true) : "") : "");
3130
3149
  } else { box.hidden = true; box.innerHTML = ""; }
3131
3150
  note.hidden = !sm.catchUp;
@@ -4187,12 +4206,13 @@
4187
4206
  // M16 item 5 (hamr ruling A, 2026-11-13): the card's own sections - Checks, Not checked, Always checked - each row with its tag and, after the run, its recorded result (server: `auditChecks`).
4188
4207
  // borrowed-from: bareloop src/panel/index.html@v0.56.0 (3383cce) :3845-3885 (auditCheckRowHtml, auditChecksSignClass, auditChecksEl), drawn in fwdloop's own fold (the learnings fold's header and body shape), appended inside #audit-groups
4189
4208
  // the tag of a row by its kind (M16 item 5, one spelling: src/checkwords.js TAG): `~` rows [you], `!` rows [agent], `$` rows [default]; the plan card and the Audit both draw it
4190
- function tagWordOf(by){ return by === "you" || by === "agent" || by === "default" ? "[" + by + "]" : ""; }
4209
+ function tagWordOf(by){ return typeof by === "string" && Object.prototype.hasOwnProperty.call(PAGE_WORDS.tags, by) ? PAGE_WORDS.tags[by] : ""; }
4191
4210
  // borrowed-from: bareloop src/panel/index.html@v0.61.0 (fc56e1f3) byTagOf (the sign before the tag, section 3.7: `~ [you]`, `! [agent]`, `$ [default]`)
4192
4211
  function byTagOf(by, form){ return (tagWordOf(by) === "" ? "" : ' <span class="by" data-testid="plan-by" data-by="' + by + '">' + (by === "you" ? "~ " : by === "agent" ? "! " : "$ ") + tagWordOf(by) + '</span>') + (form === "shape" ? ' <span class="by" data-testid="plan-form" data-form="shape">[shape]</span>' : ""); }
4193
4212
  // borrowed-from: bareloop src/panel/index.html@v0.61.0 (fc56e1f3) ckTagHtml, ckRowHtml, ckGroupHtml (the signed check-list look): a row is `[tag] kind words ... right`, the tag first in a fixed column,
4194
4213
  // the kind word second (`truth`, `shape`, `file`), the Drop / Add or the result at the right; a long reason sits behind "why", a failed row's red reason indented under it.
4195
- function ckTagHtml(by){ return '<span class="by tagcol" data-testid="plan-by"' + (by ? ' data-by="' + escapeXml(by) + '"' : "") + ">" + (by ? "[" + escapeXml(by) + "]" : "") + "</span>"; }
4214
+ // M20 am8b: the text inside the tag span is tagWordOf(by), the page's one answer to "what is the tag word of this row" (v0.61.0 built the brackets here itself)
4215
+ function ckTagHtml(by){ return '<span class="by tagcol" data-testid="plan-by"' + (by ? ' data-by="' + escapeXml(by) + '"' : "") + ">" + tagWordOf(by) + "</span>"; }
4196
4216
  function ckRowHtml(o){
4197
4217
  var why = o.why ? ' <details class="ck-why" data-testid="ck-why"><summary>\u25B8 why</summary><div class="hint">' + escapeXml(o.why) + "</div></details>" : "";
4198
4218
  return '<div class="ck-row" data-testid="' + (o.testid || "plan-check") + '"' + (o.attrs || "") + (o.title ? ' title="' + escapeXml(o.title) + '"' : "") + ">" + ckTagHtml(o.by) + '<span class="kind" data-testid="ck-kind">' + (o.kind ? escapeXml(o.kind) : "") + '</span><span class="ck-t">' + escapeXml(o.text) + why + "</span>" + (o.right ? '<span class="ck-right">' + o.right + "</span>" : "") + (o.under || "") + "</div>";
@@ -5274,7 +5294,7 @@
5274
5294
  // The server's own refusal name (`refused`) is matched first; a library refusal is matched by what it says.
5275
5295
  function networkText(){ return "Could not reach the panel, so nothing is confirmed. Check it is still running; the header above shows what the books say."; }
5276
5296
  // A redo or rerun needs a reason. The page only saves the round trip: the library still judges every answer.
5277
- function reasonMissing(decision, value){ return (decision === "redo" || decision === "rerun") && String(value).trim() === ""; }
5297
+ function reasonMissing(decision, value){ return inWords(PAGE_WORDS.reasonDecisions, decision) && String(value).trim() === ""; }
5278
5298
  function blankReasonText(decision){ return "Please write a reason for the " + (decision === "rerun" ? "rerun" : "redo") + "."; }
5279
5299
  function refusalText(r, decision){
5280
5300
  var byName = {
@@ -5814,6 +5834,7 @@
5814
5834
  var startOverBtn = document.getElementById("chat-startover-btn");
5815
5835
  var reviseBtn = document.getElementById("chat-revise-btn");
5816
5836
  var errEl = document.getElementById("chat-card-error"); // POLL-OWNED: the draft's own sentence (red / stopped)
5837
+ var refusalEl = document.getElementById("chat-draft-refusal"); // POLL-OWNED: the pointer to a refusal under a box, or the words of one with no box (M19 am14b)
5817
5838
  var actionErrEl = document.getElementById("chat-action-error"); // ACTION-OWNED: only a click's refusal; the poll never wipes it
5818
5839
  var progressRow = document.getElementById("chat-progress-row");
5819
5840
  var questionBox = document.getElementById("chat-question");
@@ -5934,7 +5955,7 @@
5934
5955
  if(st.phase === "drafting"){
5935
5956
  return {text: "Draft", action: "none", disabled: true};
5936
5957
  }
5937
- if((st.phase === "red" || st.phase === "stopped") && st.revisable){
5958
+ if(inWords(PAGE_WORDS.notGreen, st.phase) && st.revisable){
5938
5959
  // amendment 14 items 3-4: a red revise keeps the edits; Draft is another revise, Start over (no revises left) a fresh draft
5939
5960
  return (st.left || 0) > 0 ? {text: "Draft", action: "revise", disabled: blocked} : {text: "Start over", action: "draft", startOver: true, disabled: blocked};
5940
5961
  }
@@ -5944,7 +5965,7 @@
5944
5965
  if(st.phase === "stopped"){
5945
5966
  return {text: "Draft again", action: "draft", disabled: blocked};
5946
5967
  }
5947
- if(st.phase === "revising" || st.phase === "redrafting"){
5968
+ if(inWords(PAGE_WORDS.reviseRunning, st.phase)){
5948
5969
  return {text: "Sign & run", action: "none", disabled: true};
5949
5970
  }
5950
5971
  if(st.phase === "questions-open"){
@@ -6017,7 +6038,8 @@
6017
6038
  function draftLines(fallback){
6018
6039
  if(!state || !Array.isArray(state.stepList) || state.stepList.length === 0) return fallback();
6019
6040
  state.stepList.forEach(function(st){
6020
- var row = {id: st.id, label: st.label, status: st.status === "failed" ? "failed" : (st.status === "waiting" ? "waiting" : "done"), details: st.details || []};
6041
+ var row = {id: st.id, label: st.label, status: st.status === "failed" ? "failed" : (st.status === "waiting" ? "waiting" : (st.status === "running" ? "running" : "done")), details: st.details || []};
6042
+ if(typeof st.time === "string" && st.time) row.time = st.time;
6021
6043
  if(st.note === true) row.note = true;
6022
6044
  out.push(row);
6023
6045
  });
@@ -6026,7 +6048,8 @@
6026
6048
  var capPart = cap !== "" ? ", run cap $" + cap : "";
6027
6049
  if(state){
6028
6050
  if(state.phase === "drafting"){
6029
- out.push({id: "drafting", label: "drafting with " + who + capPart, status: "running", details: []});
6051
+ // M20 am1 item 5: the steps the drafter has started (its step lines), else the one line it always had
6052
+ draftLines(function(){ out.push({id: "drafting", label: "drafting with " + who + capPart, status: "running", details: []}); });
6030
6053
  } else if(Array.isArray(state.revises)){
6031
6054
  // amendment 14: a draft whose first plan was green. One line per revise with its result; a red one shows its reds (its sentence is on the card error line).
6032
6055
  draftLines(function(){ out.push({id: "drafted", label: "drafted with " + who, status: "done", details: []}); });
@@ -6035,10 +6058,12 @@
6035
6058
  // an answer redraft (amendment 24 item 4) is not a revise and is not counted as one; the server names each one (`rv.name`) and, from the plan's own log,
6036
6059
  // writes its line (`rv.lines`, src/draft-steps.js `reviseStepList`): one line, facts joined by " · ", a red one with one plain reason and a Fix line (am15)
6037
6060
  var label = rv.name || (rv.kind === "answers" ? "drafted again with your answers" : "revise " + (reviseNo += 1));
6038
- if(rv.phase === "running") out.push({id: "revise-" + rv.n, label: label, status: "running", details: []});
6061
+ if(rv.phase === "running" && !(Array.isArray(rv.lines) && rv.lines.length)) out.push({id: "revise-" + rv.n, label: label, status: "running", details: []});
6039
6062
  else if(Array.isArray(rv.lines) && rv.lines.length){
6063
+ // M20 am1 item 5: a running revise lists its own started steps (its step lines), like the first draft
6040
6064
  rv.lines.forEach(function(l){
6041
- var row = {id: "revise-" + rv.n + "-" + l.id, label: l.label, status: l.status === "failed" ? "failed" : "done", details: []};
6065
+ var row = {id: "revise-" + rv.n + "-" + l.id, label: l.label, status: l.status === "failed" ? "failed" : (l.status === "running" ? "running" : "done"), details: []};
6066
+ if(typeof l.time === "string" && l.time) row.time = l.time;
6042
6067
  if(l.note === true) row.note = true;
6043
6068
  out.push(row);
6044
6069
  });
@@ -6253,18 +6278,45 @@
6253
6278
  }
6254
6279
  // M13 p5 (signed item 7, the mock's Schedule row): "When a new ticket arrives" only for Tickets; the time box and the two hints follow the pick
6255
6280
  function paintSchedule(){
6256
- var tk = schedEl.querySelector('option[value="new-ticket"]');
6257
- tk.hidden = tk.disabled = flowTypeEl.value !== "tickets";
6258
- if(schedEl.value === "new-ticket" && tk.disabled) schedEl.value = "hand";
6259
- byId("jf-sched-clock").hidden = schedEl.value !== "daily";
6260
- byId("jf-sched-hint").hidden = schedEl.value === "hand";
6261
- byId("jf-sched-ticket-hint").hidden = schedEl.value !== "new-ticket";
6281
+ // M20 am5 item 1: the choices are the Run card's, from the one list (fillScheduleOptions); the file boxes name an Inputs line that is a file (a web page is never offered)
6282
+ fillScheduleOptions(schedEl, flowTypeEl.value, true);
6283
+ var roles = schedFileRoles();
6284
+ Array.prototype.forEach.call(schedEl.options, function(o){ if(isFileKind(o.value)) o.hidden = o.disabled = roles.length === 0; });
6285
+ if(schedEl.selectedOptions.length && schedEl.selectedOptions[0].disabled) schedEl.value = "hand";
6286
+ var kind = schedEl.value;
6287
+ var roleSel = byId("jf-sched-role"), keep = roleSel.value;
6288
+ roleSel.innerHTML = "";
6289
+ roles.forEach(function(r){ var o = document.createElement("option"); o.value = r; o.textContent = r; roleSel.appendChild(o); });
6290
+ if(roles.indexOf(keep) >= 0) roleSel.value = keep;
6291
+ byId("jf-sched-clock").hidden = !isClockKind(kind);
6292
+ byId("jf-sched-day").hidden = kind !== "weekly";
6293
+ byId("jf-sched-filebox").hidden = !isFileKind(kind);
6294
+ byId("jf-sched-path").placeholder = kind === "new-file" ? "/full/path/to/folder" : "/full/path/to/file";
6295
+ byId("jf-sched-hint").hidden = kind === "hand";
6296
+ byId("jf-sched-ticket-hint").hidden = kind !== "new-ticket";
6297
+ }
6298
+ // the Inputs lines (`name: path`) that name a file: the roles the file choices can watch
6299
+ function schedFileRoles(){
6300
+ var out = [];
6301
+ inputsBox.value.split("\n").forEach(function(line){
6302
+ var m = /^\s*([^:\s]+)\s*:\s*(.*)$/.exec(line);
6303
+ if(m && m[2].trim() !== "" && !/^https?:\/\//i.test(m[2].trim()) && out.indexOf(m[1]) === -1) out.push(m[1]);
6304
+ });
6305
+ return out;
6262
6306
  }
6263
6307
  function scheduleOfCard(){
6264
- if(schedEl.value === "new-ticket") return {kind: "new-ticket"};
6265
- if(schedEl.value !== "daily") return null;
6308
+ var kind = schedEl.value;
6309
+ if(kind === "hand") return null;
6310
+ if(kind === "new-ticket") return {kind: "new-ticket"};
6311
+ if(isFileKind(kind)){
6312
+ var q = {kind: kind, role: byId("jf-sched-role").value};
6313
+ q[kind === "new-file" ? "folder" : "path"] = byId("jf-sched-path").value.trim();
6314
+ return q;
6315
+ }
6266
6316
  var t = /^(\d{2}):(\d{2})$/.exec(schedTimeEl.value || "");
6267
- return {kind: "daily", hour: t ? Number(t[1]) : NaN, minute: t ? Number(t[2]) : NaN};
6317
+ var o = {kind: kind, hour: t ? Number(t[1]) : NaN, minute: t ? Number(t[2]) : NaN};
6318
+ if(kind === "weekly") o.day = byId("jf-sched-day").value;
6319
+ return o;
6268
6320
  }
6269
6321
  function paintFlowType(){
6270
6322
  var generic = flowTypeEl.value === "mcp", tickets = flowTypeEl.value === "tickets";
@@ -6280,11 +6332,16 @@
6280
6332
  byId("jf-run-req-inputs").hidden = runInputsEl.children.length === 0;
6281
6333
  }
6282
6334
  function setFlow(type, server, sched){
6283
- flowTypeEl.value = (type === "mcp" || type === "tickets") ? type : "plain";
6335
+ flowTypeEl.value = flowTypeOr(type);
6284
6336
  paintMcpOptions(server || "");
6285
- schedEl.value = sched && sched.kind === "daily" ? "daily" : (sched && sched.kind === "new-ticket" ? "new-ticket" : "hand");
6286
- if(sched && sched.kind === "daily" && Number.isInteger(sched.hour) && Number.isInteger(sched.minute)) schedTimeEl.value = ("0" + sched.hour).slice(-2) + ":" + ("0" + sched.minute).slice(-2);
6337
+ fillScheduleOptions(schedEl, flowTypeEl.value, true);
6338
+ schedEl.value = sched && schedEl.querySelector('option[value="' + sched.kind + '"]') ? sched.kind : "hand";
6339
+ if(sched && Number.isInteger(sched.hour) && Number.isInteger(sched.minute)) schedTimeEl.value = ("0" + sched.hour).slice(-2) + ":" + ("0" + sched.minute).slice(-2);
6340
+ if(sched && sched.day) byId("jf-sched-day").value = sched.day;
6341
+ if(sched && sched.path !== undefined) byId("jf-sched-path").value = sched.path;
6342
+ if(sched && sched.folder !== undefined) byId("jf-sched-path").value = sched.folder;
6287
6343
  paintFlowType();
6344
+ if(sched && sched.role) byId("jf-sched-role").value = sched.role;
6288
6345
  }
6289
6346
  function loadMcpServers(){
6290
6347
  return getJSON("/api/settings/mcp").then(function(d){
@@ -6297,6 +6354,9 @@
6297
6354
  mcpEl.addEventListener("change", function(){ byId("jf-err-mcp").textContent = ""; });
6298
6355
  schedEl.addEventListener("change", function(){ paintSchedule(); byId("jf-err-schedule").textContent = ""; });
6299
6356
  schedTimeEl.addEventListener("input", function(){ byId("jf-err-schedule").textContent = ""; });
6357
+ ["jf-sched-day", "jf-sched-role"].forEach(function(id){ byId(id).addEventListener("change", function(){ byId("jf-err-schedule").textContent = ""; }); });
6358
+ byId("jf-sched-path").addEventListener("input", function(){ byId("jf-err-schedule").textContent = ""; });
6359
+ inputsBox.addEventListener("input", paintSchedule); // the file choices follow the Inputs lines
6300
6360
  runFlowTypeEl.addEventListener("change", function(){ runMcpFieldEl.hidden = runFlowTypeEl.value === "plain"; });
6301
6361
  byId("jf-run-mcp-manage").addEventListener("click", function(ev){ ev.preventDefault(); document.getElementById("settings-open").click(); document.getElementById("stab-mcp").click(); });
6302
6362
  byId("jf-mcp-manage").addEventListener("click", function(ev){ ev.preventDefault(); document.getElementById("settings-open").click(); document.getElementById("stab-mcp").click(); });
@@ -6436,7 +6496,8 @@
6436
6496
 
6437
6497
  // ---- a refusal shows next to its box ----
6438
6498
  function clearFieldErrors(){
6439
- card.querySelectorAll(".jf-err").forEach(function(e){ e.textContent = ""; });
6499
+ // the painted refusal's box line belongs to paintRefusal / clearRefusal (the one writer): a late flows answer repaints the Run form and must not wipe it
6500
+ card.querySelectorAll(".jf-err").forEach(function(e){ if(e !== refusalBoxEl) e.textContent = ""; });
6440
6501
  }
6441
6502
  function errElFor(field){
6442
6503
  var m = /^inputs\.(\d+)$/.exec(field);
@@ -6473,7 +6534,7 @@
6473
6534
  var on = cardLocked();
6474
6535
  whenSyncButton();
6475
6536
  card.querySelectorAll("input[type=text], textarea").forEach(function(el){ el.readOnly = on || el.hasAttribute("data-page"); el.classList.toggle("locked", on); }); // M10: a web-page row is always read-only
6476
- flowTypeEl.disabled = on; mcpEl.disabled = on; schedEl.disabled = on; schedTimeEl.disabled = on;
6537
+ flowTypeEl.disabled = on; mcpEl.disabled = on; schedEl.disabled = on; schedTimeEl.disabled = on; byId("jf-sched-day").disabled = on; byId("jf-sched-role").disabled = on; byId("jf-sched-path").disabled = on;
6477
6538
  flowTypeEl.classList.toggle("locked", on); mcpEl.classList.toggle("locked", on); schedEl.classList.toggle("locked", on); schedTimeEl.classList.toggle("locked", on);
6478
6539
  runFlowTypeEl.disabled = on; runMcpEl.disabled = on;
6479
6540
  runFlowSel.disabled = on;
@@ -6598,7 +6659,7 @@
6598
6659
  jobBoxEl.hidden = !jobOpen; byId("jf-run-jobwrap").hidden = !jobOpen; byId("jf-run-job").hidden = jobOpen;
6599
6660
  jobBoxEl.value = jobOpen ? f.edit.card.job : "";
6600
6661
  fitCardBoxes();
6601
- runFlowTypeEl.value = f && (f.flowType === "mcp" || f.flowType === "tickets") ? f.flowType : "plain";
6662
+ runFlowTypeEl.value = flowTypeOr(f ? f.flowType : undefined);
6602
6663
  paintMcpInto(runMcpEl, f && f.mcp ? f.mcp : "");
6603
6664
  runMcpFieldEl.hidden = runFlowTypeEl.value === "plain";
6604
6665
  byId("jf-err-run-job").textContent = (f && f.edit && f.edit.ok === false) ? f.edit.say : "";
@@ -6633,6 +6694,7 @@
6633
6694
  var whenConfirmText = ""; // the words the button shows after click 1 ("every day at 13:15", "cancel schedule"); read only while whenHash is set
6634
6695
  var whenLocked = false; // ~1.5 s after a successful sign the main button is disabled, so a fast extra click cannot start a run
6635
6696
  var whenReady = false; // the lock sync can run before this block has
6697
+ fillScheduleOptions(document.getElementById("jf-when"), "plain", false); // the list before a flow is picked; paintWhen fills it again for the picked flow's type
6636
6698
  function whenCanon(t){
6637
6699
  if(t !== null && t.kind === "new-ticket") t = {kind: t.kind, role: t.role}; // M12: the list, server and tool are filled by the server from the signed job
6638
6700
  return t === null ? "null" : JSON.stringify(Object.keys(t).sort().map(function(k){ return [k, t[k]]; }));
@@ -6640,7 +6702,7 @@
6640
6702
  function whenTriggerFromBoxes(){
6641
6703
  var kind = byId("jf-when").value;
6642
6704
  if(kind === "hand") return null;
6643
- if(kind === "daily" || kind === "weekdays" || kind === "weekly"){
6705
+ if(isClockKind(kind)){
6644
6706
  var m = /^(\d{2}):(\d{2})$/.exec(byId("jf-when-time").value);
6645
6707
  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
6646
6708
  if(kind === "weekly") o.day = byId("jf-when-day").value;
@@ -6653,9 +6715,9 @@
6653
6715
  }
6654
6716
  function whenShowSubs(){
6655
6717
  var kind = byId("jf-when").value;
6656
- byId("jf-when-clock").hidden = !(kind === "daily" || kind === "weekdays" || kind === "weekly");
6718
+ byId("jf-when-clock").hidden = !isClockKind(kind);
6657
6719
  byId("jf-when-day").hidden = kind !== "weekly";
6658
- byId("jf-when-filebox").hidden = !(kind === "file-updated" || kind === "new-file" || kind === "new-ticket");
6720
+ byId("jf-when-filebox").hidden = !(isFileKind(kind) || kind === "new-ticket");
6659
6721
  byId("jf-when-path").hidden = kind === "new-ticket";
6660
6722
  byId("jf-when-path").placeholder = kind === "new-file" ? "/full/path/to/folder" : "/full/path/to/file";
6661
6723
  }
@@ -6690,10 +6752,10 @@
6690
6752
  var roleSel = byId("jf-when-role");
6691
6753
  var fileRoles = whenFileRoles(f), ticketRoles = whenTicketRoles(f);
6692
6754
  // M13 p4 (signed item 5): MCP offers By hand and Every day at... only; Tickets adds "When a new ticket arrives" to today's options; plain keeps today's
6693
- var generic = !!f && f.flowType === "mcp";
6694
- ["file-updated", "new-file"].forEach(function(k){ var o = byId("jf-when").querySelector('option[value="' + k + '"]'); o.hidden = o.disabled = generic || fileRoles.length === 0; });
6695
- ["weekdays", "weekly"].forEach(function(k){ var o = byId("jf-when").querySelector('option[value="' + k + '"]'); o.hidden = o.disabled = generic; });
6696
- var tk = byId("jf-when").querySelector('option[value="new-ticket"]'); tk.hidden = tk.disabled = generic || ticketRoles.length === 0; // M12: only a Tickets job with a ticket-list input offers it
6755
+ // M20 am5 item 1: the choices a flow type offers are the one list (SCHEDULE_CHOICES), the same the New job card's Schedule fills from; what the job has (a file input, a ticket list) decides which of them show
6756
+ fillScheduleOptions(byId("jf-when"), f ? f.flowType : "plain", false);
6757
+ Array.prototype.forEach.call(byId("jf-when").options, function(o){ if(isFileKind(o.value)) o.hidden = o.disabled = fileRoles.length === 0; });
6758
+ var tk = byId("jf-when").querySelector('option[value="new-ticket"]'); if(tk) tk.hidden = tk.disabled = ticketRoles.length === 0; // M12: only a Tickets job with a ticket-list input offers it
6697
6759
  var t = c ? c.trigger : null;
6698
6760
  sel.querySelector('option[value="hand"]').textContent = t ? "Cancel schedule" : "By hand"; // M9 am5: on a scheduled job, By hand reads Cancel schedule
6699
6761
  sel.value = t ? t.kind : "hand";
@@ -6908,22 +6970,24 @@
6908
6970
  var key = e.target && e.target.getAttribute ? e.target.getAttribute("data-fold") : null;
6909
6971
  if(key) progressOpen[key] = e.target.open === true;
6910
6972
  }, true);
6911
- function renderProgress(steps){
6973
+ function renderProgress(steps, soFar){
6912
6974
  progressRow.hidden = steps.length === 0;
6913
6975
  var html = steps.map(function(st){
6914
6976
  var cls = st.status === "waiting" ? "wait" : (st.status === "running" ? "run" : (st.status === "failed" ? "bad" : "ok"));
6915
- var sign = st.note ? "" : (cls === "ok" ? "✓" : (cls === "bad" ? "✗" : ""));
6977
+ var sign = st.note ? "" : (cls === "ok" ? "✓" : (cls === "bad" ? "✗" : (cls === "run" ? "▶" : "")));
6978
+ // M20 am1 item 5: "took M:SS" / "M:SS so far", the server's words (src/draftspend.js withDraftTimes)
6979
+ var time = typeof st.time === "string" && st.time ? '<span class="step-time" data-testid="step-time">' + escapeXml(st.time) + '</span>' : "";
6916
6980
  // M4d am15: a line with no ✓/✗ (the Fix line under a red plan check)
6917
6981
  if(st.note) cls += " note";
6918
6982
  return '<li class="step ' + cls + '" data-step="' + escapeXml(st.id) + '"><div class="step-line"><span class="step-label">' + escapeXml(st.label) + '</span>' +
6919
- '<span class="step-sign">' + sign + '</span></div>' +
6983
+ '<span class="step-sign">' + sign + '</span>' + time + '</div>' +
6920
6984
  (st.details || []).map(function(d, k){
6921
6985
  var raw = st.raw || [];
6922
6986
  var key = st.id + ":" + k;
6923
6987
  var fold = typeof raw[k] === "string" && raw[k] !== "" ? '<details class="step-raw" data-fold="' + escapeXml(key) + '"' + (progressOpen[key] ? " open" : "") + '><summary>details</summary>' + escapeXml(raw[k]) + '</details>' : "";
6924
6988
  return '<div class="step-detail">' + escapeXml("> " + d) + fold + '</div>';
6925
6989
  }).join("") + '</li>';
6926
- }).join("");
6990
+ }).join("") + (steps.length && typeof soFar === "string" && soFar ? '<li class="step-so-far" data-testid="drafting-so-far">' + escapeXml(soFar) + '</li>' : "");
6927
6991
  if(html === progressHtml) return false;
6928
6992
  progressHtml = html;
6929
6993
  progressRow.innerHTML = html;
@@ -6940,11 +7004,12 @@
6940
7004
  }
6941
7005
  function renderThread(state){
6942
7006
  // a revise being drafted leaves the plan on show until the new one replaces it (the view carries no plan meanwhile)
6943
- if(state && (state.phase === "revising" || state.phase === "redrafting")) return;
7007
+ if(state && inWords(PAGE_WORDS.reviseRunning, state.phase)) return;
6944
7008
  var html = "";
6945
7009
  if(state && state.phase === "green" && state.readout){
6946
7010
  html = '<div class="msg bot" data-testid="chat-plan"><div class="who">fwdloop</div>' + readoutHtml(state) +
6947
- '\n\nPlan hash: ' + escapeXml(state.hash || "") + '</div>';
7011
+ '\n\nPlan hash: ' + escapeXml(state.hash || "") +
7012
+ (typeof state.draftedLine === "string" && state.draftedLine ? '\n<span class="drafted-line" data-testid="drafted-line">' + escapeXml(state.draftedLine) + '</span>' : "") + '</div>';
6948
7013
  }
6949
7014
  if(html !== threadKey){ threadKey = html; thread.innerHTML = html; }
6950
7015
  }
@@ -6993,7 +7058,7 @@
6993
7058
  }
6994
7059
  // Your answers / Checked / Not checked; a plan being drafted again leaves them on show (like the plan), anything else without a green plan clears them
6995
7060
  function renderExtras(state){
6996
- if(state && (state.phase === "revising" || state.phase === "redrafting")) return;
7061
+ if(state && inWords(PAGE_WORDS.reviseRunning, state.phase)) return;
6997
7062
  var v = extrasFor(state);
6998
7063
  var html = v ? v.blocks.map(function(b){
6999
7064
  var inner = b.action ? '<div class="who">fwdloop</div>' + actionRowHtml(b.action)
@@ -7051,9 +7116,28 @@
7051
7116
  function syncJobBoxFromSession(state){
7052
7117
  var jt = state && state.card && state.card.job;
7053
7118
  var box = document.getElementById("jf-job");
7054
- if(!sessionLive || reviseOpen || typeof jt !== "string" || jt === box.value) return;
7119
+ // F259: a red or stopped draft has left the boxes to the person (the card is open to fix and draft again); the poll never writes them back
7120
+ if(!sessionLive || reviseOpen || inWords(PAGE_WORDS.notGreen, state.phase) || typeof jt !== "string" || jt === box.value) return;
7055
7121
  setVal("jf-job", jt); fitCardBoxes();
7056
7122
  }
7123
+ // M19 am14b: the ONE writer of a draft refusal's lines. The box error is painted once per refusal (so a poll never brings back a line the person cleared by pressing Draft).
7124
+ var REFUSAL_POINTER = "Not drafted: fix the red line above.";
7125
+ var refusalKey = ""; // which refusal is painted
7126
+ var refusalBoxEl = null; // the box error line it was painted into (null: none)
7127
+ function clearRefusal(){
7128
+ if(refusalBoxEl) refusalBoxEl.textContent = "";
7129
+ refusalBoxEl = null; refusalKey = ""; refusalEl.textContent = "";
7130
+ }
7131
+ function paintRefusal(state, r){
7132
+ var key = r ? String(state.draftId) + "|" + r.box + "|" + r.words : "";
7133
+ if(key === refusalKey) return;
7134
+ clearRefusal();
7135
+ refusalKey = key;
7136
+ if(!r) return;
7137
+ var boxEl = r.box ? errElFor(r.box) : null;
7138
+ if(boxEl){ boxEl.textContent = r.words; refusalBoxEl = boxEl; refusalEl.textContent = REFUSAL_POINTER; }
7139
+ else refusalEl.textContent = r.words;
7140
+ }
7057
7141
  function renderActions(state){
7058
7142
  lastState = state;
7059
7143
  renderQuestion(state);
@@ -7062,8 +7146,12 @@
7062
7146
  if(signInfo && state.hash && state.hash !== signInfo.hash){ signInfo = null; signClickedOnce = false; }
7063
7147
  // #chat-card-error is POLL-OWNED: it carries only the draft's own sentence (a red plan or a stopped child), written here and
7064
7148
  // nowhere else. A refused click goes to #chat-action-error, which this function never touches.
7065
- errEl.textContent = ((state.phase === "red" || state.phase === "stopped") && state.say) ? state.say : "";
7066
- var progressChanged = renderProgress(stepsFor(state, {model: drafterModel, starting: startId !== null, signClicked: signClickedOnce}));
7149
+ // M19 am14b: a draft refused at $0 shows its words under the box it is about (red, like "required") with one pointer by the Draft button; a refusal with no box shows
7150
+ // its words under the button. No grey copy: the grey card line carries every other sentence (a red plan from the AI keeps its own).
7151
+ var refusal = (state.phase === "stopped" && state.refusal && typeof state.refusal === "object") ? state.refusal : null;
7152
+ paintRefusal(state, refusal);
7153
+ errEl.textContent = (!refusal && inWords(PAGE_WORDS.notGreen, state.phase) && state.say) ? state.say : "";
7154
+ var progressChanged = renderProgress(stepsFor(state, {model: drafterModel, starting: startId !== null, signClicked: signClickedOnce}), state && state.draftSoFar);
7067
7155
  sessionLive = CLIENT_TERMINAL_PHASES.indexOf(state.phase) === -1;
7068
7156
  refreshStartEnabled();
7069
7157
  syncJobBoxFromSession(state);
@@ -7086,6 +7174,7 @@
7086
7174
  threadKey = ""; thread.innerHTML = "";
7087
7175
  renderQuestion(null); renderExtras(null);
7088
7176
  errEl.textContent = "";
7177
+ clearRefusal();
7089
7178
  progressRow.hidden = true; progressRow.innerHTML = ""; progressHtml = "";
7090
7179
  refreshStartEnabled();
7091
7180
  }
@@ -7093,6 +7182,7 @@
7093
7182
  thread.innerHTML = ""; threadKey = "";
7094
7183
  renderQuestion(null); renderExtras(null);
7095
7184
  errEl.textContent = "";
7185
+ clearRefusal();
7096
7186
  actionErrEl.textContent = "";
7097
7187
  clearFieldErrors();
7098
7188
  stopStart();
@@ -7230,6 +7320,7 @@
7230
7320
  }).catch(function(){ qBusy = false; qSend.disabled = false; qAgree.disabled = false; qDrop.disabled = false; qColumn.disabled = false; qError.textContent = NETWORK_SAY; });
7231
7321
  }
7232
7322
  function doDraft(startedOverFrom){
7323
+ clearRefusal();
7233
7324
  clearFieldErrors();
7234
7325
  chatActionOk();
7235
7326
  // disabled from the click until the reply; unlocked below only if the draft is refused
@@ -8,6 +8,7 @@
8
8
  import { GROUP_OF, TICKET_GROUPS } from './tickets.js';
9
9
  import { EVERY_STEP } from '../try-checks.js';
10
10
  import { compareNatural } from '../natural.js';
11
+ import { newestChecksOf } from '../diary.js';
11
12
 
12
13
  /** the buckets, in the mock's order (the same four as the M12 ticket list: one list of words) */
13
14
  export const GRID_BUCKETS = TICKET_GROUPS;
@@ -45,13 +46,8 @@ export function sumMoney(moneys) {
45
46
  * @param {any[]} diary @returns {Array<{step: string, checks: Array<{n: number, text: string, ok: boolean, result: string|null, source: string|null}>}>}
46
47
  */
47
48
  function newestTries(diary) {
48
- const by = new Map();
49
- for (const r of diary ?? []) {
50
- if (!r || typeof r.step !== 'string' || !Number.isInteger(r.try) || !Array.isArray(r.checks)) continue;
51
- const prev = by.get(r.step);
52
- if (!prev || r.try >= prev.try) by.set(r.step, r);
53
- }
54
- return [...by.values()].map((r) => ({
49
+ const steps = [...new Set((diary ?? []).filter((r) => r && typeof r.step === 'string' && Number.isInteger(r.try) && Array.isArray(r.checks)).map((r) => r.step))];
50
+ return steps.map((step) => /** @type {any} */ (newestChecksOf(diary, step))).map((r) => ({
55
51
  step: r.step,
56
52
  checks: r.checks.filter((c) => c && typeof c.text === 'string' && typeof c.ok === 'boolean')
57
53
  .map((c) => ({ n: c.n, text: c.text, ok: c.ok, result: typeof c.result === 'string' ? c.result : null, source: typeof c.source === 'string' ? c.source : null })),
@@ -11,7 +11,8 @@
11
11
  import { createHash } from 'node:crypto';
12
12
  import { basename, join } from 'node:path';
13
13
 
14
- import { readFileInside } from '../flow.js';
14
+ import { readFileInside } from '../inside.js';
15
+ import { isFailedEnding, redWhyOf } from '../books.js';
15
16
  import { isCellsPath } from '../closers.js';
16
17
  import { readAcceptedHashesByEmits } from '../ask.js';
17
18
  import { notCheckedLabelOf } from '../checked.js';
@@ -21,7 +22,7 @@ import { flowTypeOf } from '../declaration.js';
21
22
  import { isAgree, readingOfQuestion } from '../pageask.js';
22
23
  import { lineRules } from '../pagebits.js';
23
24
  import { readLineSection, LINE_CHECKS_FILE } from '../line-checks.js';
24
- import { readChecks } from '../diary.js';
25
+ import { readChecks, newestChecksOf } from '../diary.js';
25
26
  import { sheetLineBlocks, csvRolesOf } from '../sheetblock.js';
26
27
  import { readSheetChecks } from '../sheet-record.js';
27
28
  import { tagged } from '../checkwords.js';
@@ -41,8 +42,6 @@ export const RESULT_YOU_CONFIRMED = '(you confirmed)';
41
42
  export const RESULT_DOOR_HEAD = 'waiting for you';
42
43
  export const RESULT_DOOR_ASK = 'the checks passed; is this what you wanted?';
43
44
 
44
- /** end-row outcomes that are not a failure of the job */
45
- const NOT_FAILED = new Set(['complete', 'stopped', 'cap-halt', 'rerun', 'ask-expired']);
46
45
  const FACT_KINDS = new Set(['phrase', 'value']);
47
46
  const isInt = (x) => Number.isInteger(x);
48
47
  const isStr = (x) => typeof x === 'string';
@@ -224,9 +223,8 @@ export function deliveredOf({
224
223
  function checksOfLine(stepsOfLine, diary) {
225
224
  const out = [];
226
225
  for (const st of stepsOfLine) {
227
- const rows = diary.filter((r) => r && r.step === st.emits && isInt(r.try) && Array.isArray(r.checks));
228
- const newest = rows.reduce((m, r) => (m === null || r.try >= m.try ? r : m), null);
229
- for (const c of newest ? newest.checks : []) if (c && isStr(c.text) && typeof c.ok === 'boolean') out.push({ ok: c.ok, text: c.by === 'you' || c.by === 'agent' || c.by === 'default' ? tagged(c.text, c.by) : c.text, result: isStr(c.result) ? c.result : null }); // hamr 2026-11-14: a check the plan's list built carries the tag of its row
226
+ const newest = newestChecksOf(diary, st.emits);
227
+ for (const c of newest ? newest.checks : []) if (c && isStr(c.text) && typeof c.ok === 'boolean') out.push({ ok: c.ok, text: tagged(c.text, c.by), result: isStr(c.result) ? c.result : null }); // hamr 2026-11-14: a check the plan's list built carries the tag of its row
230
228
  }
231
229
  return out;
232
230
  }
@@ -325,9 +323,8 @@ export function buildResult({
325
323
  // a run that failed delivered nothing: say its own first gap, never rows. A stop, a cap halt, a rerun and an expired ask are not a failure (the same
326
324
  // set `computeGlyph` colours `[✗]` by exclusion); a pause has no end row at all.
327
325
  let gap = null;
328
- if (historyRow && !NOT_FAILED.has(historyRow.outcome)) {
329
- const redRow = auditRows.findLast((r) => r.verdict === 'red' || r.verdict === 'not-done');
330
- gap = gapOf(isStr(logJson?.red) && logJson.red !== '' ? logJson.red : (redRow ? `${redRow.step}: ${redRow.gap}` : null));
326
+ if (historyRow && isFailedEnding(historyRow.outcome)) {
327
+ gap = gapOf(redWhyOf(logJson, auditRows));
331
328
  }
332
329
  const pages = [...new Set(urls.values())];
333
330
  return {
@@ -41,9 +41,10 @@ import {
41
41
  import { tmpdir } from 'node:os';
42
42
  import { dirname, join } from 'node:path';
43
43
  import { fileURLToPath } from 'node:url';
44
- import { scrub } from '../authoring.js';
44
+ import { scrub } from '../draftfiles.js';
45
45
  import { keyValues } from '../keysfile.js';
46
46
  import { spawnDetached } from './spawn.js';
47
+ import { consumedAnswerName } from '../books.js';
47
48
 
48
49
  const HERE = dirname(fileURLToPath(import.meta.url));
49
50
  const BIN = join(HERE, '..', '..', 'bin', 'fwdloop');
@@ -101,7 +102,7 @@ export function createResumer(opts) {
101
102
  /** One resume process. Resolves as soon as the books show the answer consumed,
102
103
  * or the child exited, or `deadline` passed — never waits for a long resume. */
103
104
  function tryOnce({ flow, runId, runDir, askId, logPath, deadline }) {
104
- const consumedPath = join(runDir, `answer.${askId}.consumed.json`);
105
+ const consumedPath = join(runDir, consumedAnswerName(askId));
105
106
  const loaded = loadEnv ? loadEnv() : { ok: true, env, refusal: null };
106
107
  if (!loaded.ok) return Promise.resolve({ kind: 'exited', code: null, sig: null, text: String(loaded.refusal) });
107
108
  const runEnv = loaded.env; // ONE object: the spawn env below AND the scrub list further down (POC (a) wiring rule)
@@ -163,7 +164,7 @@ export function createResumer(opts) {
163
164
  // append to, nor have its log deleted by, the first one's clean exit (M4c-fix item 7).
164
165
  const logPath = join(ensureLogDir(opts.logDir), `resume-${rootTag}-${rec.flow}-${rec.runId}-${randomBytes(4).toString('hex')}.log`);
165
166
  rec.logPath = logPath;
166
- const consumed = () => existsSync(join(runDir, `answer.${rec.askId}.consumed.json`));
167
+ const consumed = () => existsSync(join(runDir, consumedAnswerName(rec.askId)));
167
168
  for (let n = 1; n <= maxTries; n += 1) {
168
169
  if (rec.superseded) return;
169
170
  rec.tries = n;