fwdloop 0.38.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 (127) hide show
  1. package/bin/fwdloop +21 -19
  2. package/package.json +1 -1
  3. package/src/ask.js +70 -148
  4. package/src/audit-fold.js +5 -4
  5. package/src/auditchecks.js +6 -4
  6. package/src/authoring.js +32 -60
  7. package/src/blockasks.js +2 -1
  8. package/src/blockassemble.js +3 -2
  9. package/src/blockdraft.js +2 -2
  10. package/src/blockpick.js +5 -5
  11. package/src/books.js +217 -12
  12. package/src/checkblock.js +20 -41
  13. package/src/checklistsign.js +25 -3
  14. package/src/checklook.js +3 -1
  15. package/src/checkpick.js +5 -76
  16. package/src/cited-source.js +4 -4
  17. package/src/citedcheck.js +6 -11
  18. package/src/citedwords.js +9 -8
  19. package/src/closers.js +9 -6
  20. package/src/declaration.js +14 -49
  21. package/src/diary.js +23 -1
  22. package/src/draft-steps.js +11 -1
  23. package/src/drafter.js +13 -9
  24. package/src/draftfiles.js +127 -0
  25. package/src/draftspend.js +165 -17
  26. package/src/flow.js +42 -87
  27. package/src/flowmodel.js +1 -1
  28. package/src/index.js +3 -2
  29. package/src/inside.js +86 -0
  30. package/src/jsonl-append.js +33 -1
  31. package/src/learn.js +1 -1
  32. package/src/learnstore.js +20 -22
  33. package/src/line-checks.js +1 -1
  34. package/src/liveness.js +3 -0
  35. package/src/mcp-use.js +8 -9
  36. package/src/memo.js +13 -16
  37. package/src/model-step.js +2 -2
  38. package/src/page-words.js +8 -0
  39. package/src/pageask.js +8 -3
  40. package/src/pagebits.js +8 -1
  41. package/src/pagedropwords.js +1 -1
  42. package/src/pagerules.js +6 -3
  43. package/src/panel/author.js +99 -75
  44. package/src/panel/authorcard.js +21 -8
  45. package/src/panel/authorflows.js +3 -3
  46. package/src/panel/authorresume.js +3 -3
  47. package/src/panel/authorstart.js +15 -16
  48. package/src/panel/authortrigger.js +43 -70
  49. package/src/panel/data.js +125 -168
  50. package/src/panel/index.html +122 -61
  51. package/src/panel/jobgrid.js +3 -7
  52. package/src/panel/result.js +7 -10
  53. package/src/panel/resume.js +4 -3
  54. package/src/panel/scheduler.js +9 -9
  55. package/src/panel/server.js +8 -4
  56. package/src/panel/spawn.js +22 -11
  57. package/src/panel/tickets.js +2 -2
  58. package/src/pickrecord.js +51 -31
  59. package/src/placerule.js +3 -4
  60. package/src/planrebuild.js +19 -19
  61. package/src/primitives.js +1 -1
  62. package/src/provider.js +1 -1
  63. package/src/reasons.js +25 -0
  64. package/src/runfile.js +26 -2
  65. package/src/runner.js +57 -105
  66. package/src/runvalues.js +47 -24
  67. package/src/schedule-choices.js +41 -0
  68. package/src/schedule-shape.js +39 -0
  69. package/src/schedule.js +9 -8
  70. package/src/setup.js +20 -36
  71. package/src/shaperows.js +2 -2
  72. package/src/sheetblock.js +2 -2
  73. package/src/sheetbuild.js +5 -5
  74. package/src/sheetrun.js +4 -5
  75. package/src/summary-words.js +2 -1
  76. package/src/thinking.js +5 -2
  77. package/src/ticketrows.js +7 -28
  78. package/src/trigger-clock.js +9 -23
  79. package/src/trigger-files.js +30 -22
  80. package/src/trigger-tickets.js +15 -14
  81. package/src/try-checks.js +2 -1
  82. package/src/types.js +2 -0
  83. package/types/ask.d.ts +25 -20
  84. package/types/authoring.d.ts +7 -42
  85. package/types/blockpick.d.ts +1 -1
  86. package/types/books.d.ts +256 -4
  87. package/types/checkblock.d.ts +1 -23
  88. package/types/checklist.d.ts +3 -3
  89. package/types/checklistsign.d.ts +7 -0
  90. package/types/checkpick.d.ts +0 -21
  91. package/types/citedwords.d.ts +7 -4
  92. package/types/closers.d.ts +1 -0
  93. package/types/declaration.d.ts +4 -14
  94. package/types/diary.d.ts +14 -1
  95. package/types/draft-steps.d.ts +7 -0
  96. package/types/drafter.d.ts +1 -1
  97. package/types/draftfiles.d.ts +89 -0
  98. package/types/draftspend.d.ts +74 -0
  99. package/types/flow.d.ts +32 -54
  100. package/types/index.d.ts +3 -3
  101. package/types/inside.d.ts +58 -0
  102. package/types/jsonl-append.d.ts +20 -0
  103. package/types/learnstore.d.ts +0 -2
  104. package/types/liveness.d.ts +1 -0
  105. package/types/page-words.d.ts +6 -0
  106. package/types/pageask.d.ts +2 -0
  107. package/types/pagebits.d.ts +3 -0
  108. package/types/pagerules.d.ts +1 -0
  109. package/types/panel/author.d.ts +7 -3
  110. package/types/panel/authorcard.d.ts +0 -6
  111. package/types/panel/authorflows.d.ts +4 -4
  112. package/types/panel/authortrigger.d.ts +16 -2
  113. package/types/panel/data.d.ts +36 -11
  114. package/types/panel/spawn.d.ts +18 -2
  115. package/types/pickrecord.d.ts +29 -0
  116. package/types/reasons.d.ts +23 -0
  117. package/types/runfile.d.ts +14 -0
  118. package/types/runner.d.ts +6 -38
  119. package/types/runvalues.d.ts +17 -2
  120. package/types/schedule-choices.d.ts +9 -0
  121. package/types/schedule-shape.d.ts +15 -0
  122. package/types/sheetbuild.d.ts +1 -1
  123. package/types/thinking.d.ts +1 -0
  124. package/types/ticketrows.d.ts +0 -9
  125. package/types/trigger-clock.d.ts +3 -2
  126. package/types/trigger-files.d.ts +15 -4
  127. 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;}
@@ -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>
@@ -1679,6 +1674,27 @@
1679
1674
 
1680
1675
  var PORT = "__FWDLOOP_PANEL_PORT__";
1681
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
+ }
1682
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.
1683
1699
  document.getElementById("host-line").textContent = "127.0.0.1:" + PORT;
1684
1700
 
@@ -3122,12 +3138,13 @@
3122
3138
  var box = document.getElementById("ended-block");
3123
3139
  var note = document.getElementById("catchup-note");
3124
3140
  var sc = sm.schedule || null;
3125
- if(sm.ended || sc){
3141
+ var nowText = typeof sm.now === "string" && sm.now ? sm.now : null;
3142
+ if(sm.ended || sc || nowText){
3126
3143
  var tone = glyphClass(detail.glyph); // M9 am14: the colour of that run's card in the runs list, one decider (its dot)
3127
3144
  if(sc && sc.red === true) tone = "red";
3128
3145
  box.hidden = false;
3129
3146
  box.className = "ended-block" + (tone ? " " + tone : "");
3130
- 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) : "") +
3131
3148
  (sc ? summaryRow("SCHEDULE", sc.line1, "sched-line1", sc.red === true) + (sc.line2 ? summaryRow("", sc.line2, "sched-line2", sc.red === true, sc.grey === true) : "") : "");
3132
3149
  } else { box.hidden = true; box.innerHTML = ""; }
3133
3150
  note.hidden = !sm.catchUp;
@@ -4189,12 +4206,13 @@
4189
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`).
4190
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
4191
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
4192
- 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] : ""; }
4193
4210
  // borrowed-from: bareloop src/panel/index.html@v0.61.0 (fc56e1f3) byTagOf (the sign before the tag, section 3.7: `~ [you]`, `! [agent]`, `$ [default]`)
4194
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>' : ""); }
4195
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,
4196
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.
4197
- 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>"; }
4198
4216
  function ckRowHtml(o){
4199
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>" : "";
4200
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>";
@@ -5276,7 +5294,7 @@
5276
5294
  // The server's own refusal name (`refused`) is matched first; a library refusal is matched by what it says.
5277
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."; }
5278
5296
  // A redo or rerun needs a reason. The page only saves the round trip: the library still judges every answer.
5279
- 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() === ""; }
5280
5298
  function blankReasonText(decision){ return "Please write a reason for the " + (decision === "rerun" ? "rerun" : "redo") + "."; }
5281
5299
  function refusalText(r, decision){
5282
5300
  var byName = {
@@ -5937,7 +5955,7 @@
5937
5955
  if(st.phase === "drafting"){
5938
5956
  return {text: "Draft", action: "none", disabled: true};
5939
5957
  }
5940
- if((st.phase === "red" || st.phase === "stopped") && st.revisable){
5958
+ if(inWords(PAGE_WORDS.notGreen, st.phase) && st.revisable){
5941
5959
  // amendment 14 items 3-4: a red revise keeps the edits; Draft is another revise, Start over (no revises left) a fresh draft
5942
5960
  return (st.left || 0) > 0 ? {text: "Draft", action: "revise", disabled: blocked} : {text: "Start over", action: "draft", startOver: true, disabled: blocked};
5943
5961
  }
@@ -5947,7 +5965,7 @@
5947
5965
  if(st.phase === "stopped"){
5948
5966
  return {text: "Draft again", action: "draft", disabled: blocked};
5949
5967
  }
5950
- if(st.phase === "revising" || st.phase === "redrafting"){
5968
+ if(inWords(PAGE_WORDS.reviseRunning, st.phase)){
5951
5969
  return {text: "Sign & run", action: "none", disabled: true};
5952
5970
  }
5953
5971
  if(st.phase === "questions-open"){
@@ -6020,7 +6038,8 @@
6020
6038
  function draftLines(fallback){
6021
6039
  if(!state || !Array.isArray(state.stepList) || state.stepList.length === 0) return fallback();
6022
6040
  state.stepList.forEach(function(st){
6023
- 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;
6024
6043
  if(st.note === true) row.note = true;
6025
6044
  out.push(row);
6026
6045
  });
@@ -6029,7 +6048,8 @@
6029
6048
  var capPart = cap !== "" ? ", run cap $" + cap : "";
6030
6049
  if(state){
6031
6050
  if(state.phase === "drafting"){
6032
- 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: []}); });
6033
6053
  } else if(Array.isArray(state.revises)){
6034
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).
6035
6055
  draftLines(function(){ out.push({id: "drafted", label: "drafted with " + who, status: "done", details: []}); });
@@ -6038,10 +6058,12 @@
6038
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,
6039
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)
6040
6060
  var label = rv.name || (rv.kind === "answers" ? "drafted again with your answers" : "revise " + (reviseNo += 1));
6041
- 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: []});
6042
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
6043
6064
  rv.lines.forEach(function(l){
6044
- 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;
6045
6067
  if(l.note === true) row.note = true;
6046
6068
  out.push(row);
6047
6069
  });
@@ -6256,18 +6278,45 @@
6256
6278
  }
6257
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
6258
6280
  function paintSchedule(){
6259
- var tk = schedEl.querySelector('option[value="new-ticket"]');
6260
- tk.hidden = tk.disabled = flowTypeEl.value !== "tickets";
6261
- if(schedEl.value === "new-ticket" && tk.disabled) schedEl.value = "hand";
6262
- byId("jf-sched-clock").hidden = schedEl.value !== "daily";
6263
- byId("jf-sched-hint").hidden = schedEl.value === "hand";
6264
- 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;
6265
6306
  }
6266
6307
  function scheduleOfCard(){
6267
- if(schedEl.value === "new-ticket") return {kind: "new-ticket"};
6268
- 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
+ }
6269
6316
  var t = /^(\d{2}):(\d{2})$/.exec(schedTimeEl.value || "");
6270
- 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;
6271
6320
  }
6272
6321
  function paintFlowType(){
6273
6322
  var generic = flowTypeEl.value === "mcp", tickets = flowTypeEl.value === "tickets";
@@ -6283,11 +6332,16 @@
6283
6332
  byId("jf-run-req-inputs").hidden = runInputsEl.children.length === 0;
6284
6333
  }
6285
6334
  function setFlow(type, server, sched){
6286
- flowTypeEl.value = (type === "mcp" || type === "tickets") ? type : "plain";
6335
+ flowTypeEl.value = flowTypeOr(type);
6287
6336
  paintMcpOptions(server || "");
6288
- schedEl.value = sched && sched.kind === "daily" ? "daily" : (sched && sched.kind === "new-ticket" ? "new-ticket" : "hand");
6289
- 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;
6290
6343
  paintFlowType();
6344
+ if(sched && sched.role) byId("jf-sched-role").value = sched.role;
6291
6345
  }
6292
6346
  function loadMcpServers(){
6293
6347
  return getJSON("/api/settings/mcp").then(function(d){
@@ -6300,6 +6354,9 @@
6300
6354
  mcpEl.addEventListener("change", function(){ byId("jf-err-mcp").textContent = ""; });
6301
6355
  schedEl.addEventListener("change", function(){ paintSchedule(); byId("jf-err-schedule").textContent = ""; });
6302
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
6303
6360
  runFlowTypeEl.addEventListener("change", function(){ runMcpFieldEl.hidden = runFlowTypeEl.value === "plain"; });
6304
6361
  byId("jf-run-mcp-manage").addEventListener("click", function(ev){ ev.preventDefault(); document.getElementById("settings-open").click(); document.getElementById("stab-mcp").click(); });
6305
6362
  byId("jf-mcp-manage").addEventListener("click", function(ev){ ev.preventDefault(); document.getElementById("settings-open").click(); document.getElementById("stab-mcp").click(); });
@@ -6477,7 +6534,7 @@
6477
6534
  var on = cardLocked();
6478
6535
  whenSyncButton();
6479
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
6480
- 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;
6481
6538
  flowTypeEl.classList.toggle("locked", on); mcpEl.classList.toggle("locked", on); schedEl.classList.toggle("locked", on); schedTimeEl.classList.toggle("locked", on);
6482
6539
  runFlowTypeEl.disabled = on; runMcpEl.disabled = on;
6483
6540
  runFlowSel.disabled = on;
@@ -6602,7 +6659,7 @@
6602
6659
  jobBoxEl.hidden = !jobOpen; byId("jf-run-jobwrap").hidden = !jobOpen; byId("jf-run-job").hidden = jobOpen;
6603
6660
  jobBoxEl.value = jobOpen ? f.edit.card.job : "";
6604
6661
  fitCardBoxes();
6605
- runFlowTypeEl.value = f && (f.flowType === "mcp" || f.flowType === "tickets") ? f.flowType : "plain";
6662
+ runFlowTypeEl.value = flowTypeOr(f ? f.flowType : undefined);
6606
6663
  paintMcpInto(runMcpEl, f && f.mcp ? f.mcp : "");
6607
6664
  runMcpFieldEl.hidden = runFlowTypeEl.value === "plain";
6608
6665
  byId("jf-err-run-job").textContent = (f && f.edit && f.edit.ok === false) ? f.edit.say : "";
@@ -6637,6 +6694,7 @@
6637
6694
  var whenConfirmText = ""; // the words the button shows after click 1 ("every day at 13:15", "cancel schedule"); read only while whenHash is set
6638
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
6639
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
6640
6698
  function whenCanon(t){
6641
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
6642
6700
  return t === null ? "null" : JSON.stringify(Object.keys(t).sort().map(function(k){ return [k, t[k]]; }));
@@ -6644,7 +6702,7 @@
6644
6702
  function whenTriggerFromBoxes(){
6645
6703
  var kind = byId("jf-when").value;
6646
6704
  if(kind === "hand") return null;
6647
- if(kind === "daily" || kind === "weekdays" || kind === "weekly"){
6705
+ if(isClockKind(kind)){
6648
6706
  var m = /^(\d{2}):(\d{2})$/.exec(byId("jf-when-time").value);
6649
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
6650
6708
  if(kind === "weekly") o.day = byId("jf-when-day").value;
@@ -6657,9 +6715,9 @@
6657
6715
  }
6658
6716
  function whenShowSubs(){
6659
6717
  var kind = byId("jf-when").value;
6660
- byId("jf-when-clock").hidden = !(kind === "daily" || kind === "weekdays" || kind === "weekly");
6718
+ byId("jf-when-clock").hidden = !isClockKind(kind);
6661
6719
  byId("jf-when-day").hidden = kind !== "weekly";
6662
- 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");
6663
6721
  byId("jf-when-path").hidden = kind === "new-ticket";
6664
6722
  byId("jf-when-path").placeholder = kind === "new-file" ? "/full/path/to/folder" : "/full/path/to/file";
6665
6723
  }
@@ -6694,10 +6752,10 @@
6694
6752
  var roleSel = byId("jf-when-role");
6695
6753
  var fileRoles = whenFileRoles(f), ticketRoles = whenTicketRoles(f);
6696
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
6697
- var generic = !!f && f.flowType === "mcp";
6698
- ["file-updated", "new-file"].forEach(function(k){ var o = byId("jf-when").querySelector('option[value="' + k + '"]'); o.hidden = o.disabled = generic || fileRoles.length === 0; });
6699
- ["weekdays", "weekly"].forEach(function(k){ var o = byId("jf-when").querySelector('option[value="' + k + '"]'); o.hidden = o.disabled = generic; });
6700
- 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
6701
6759
  var t = c ? c.trigger : null;
6702
6760
  sel.querySelector('option[value="hand"]').textContent = t ? "Cancel schedule" : "By hand"; // M9 am5: on a scheduled job, By hand reads Cancel schedule
6703
6761
  sel.value = t ? t.kind : "hand";
@@ -6912,22 +6970,24 @@
6912
6970
  var key = e.target && e.target.getAttribute ? e.target.getAttribute("data-fold") : null;
6913
6971
  if(key) progressOpen[key] = e.target.open === true;
6914
6972
  }, true);
6915
- function renderProgress(steps){
6973
+ function renderProgress(steps, soFar){
6916
6974
  progressRow.hidden = steps.length === 0;
6917
6975
  var html = steps.map(function(st){
6918
6976
  var cls = st.status === "waiting" ? "wait" : (st.status === "running" ? "run" : (st.status === "failed" ? "bad" : "ok"));
6919
- 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>' : "";
6920
6980
  // M4d am15: a line with no ✓/✗ (the Fix line under a red plan check)
6921
6981
  if(st.note) cls += " note";
6922
6982
  return '<li class="step ' + cls + '" data-step="' + escapeXml(st.id) + '"><div class="step-line"><span class="step-label">' + escapeXml(st.label) + '</span>' +
6923
- '<span class="step-sign">' + sign + '</span></div>' +
6983
+ '<span class="step-sign">' + sign + '</span>' + time + '</div>' +
6924
6984
  (st.details || []).map(function(d, k){
6925
6985
  var raw = st.raw || [];
6926
6986
  var key = st.id + ":" + k;
6927
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>' : "";
6928
6988
  return '<div class="step-detail">' + escapeXml("> " + d) + fold + '</div>';
6929
6989
  }).join("") + '</li>';
6930
- }).join("");
6990
+ }).join("") + (steps.length && typeof soFar === "string" && soFar ? '<li class="step-so-far" data-testid="drafting-so-far">' + escapeXml(soFar) + '</li>' : "");
6931
6991
  if(html === progressHtml) return false;
6932
6992
  progressHtml = html;
6933
6993
  progressRow.innerHTML = html;
@@ -6944,11 +7004,12 @@
6944
7004
  }
6945
7005
  function renderThread(state){
6946
7006
  // a revise being drafted leaves the plan on show until the new one replaces it (the view carries no plan meanwhile)
6947
- if(state && (state.phase === "revising" || state.phase === "redrafting")) return;
7007
+ if(state && inWords(PAGE_WORDS.reviseRunning, state.phase)) return;
6948
7008
  var html = "";
6949
7009
  if(state && state.phase === "green" && state.readout){
6950
7010
  html = '<div class="msg bot" data-testid="chat-plan"><div class="who">fwdloop</div>' + readoutHtml(state) +
6951
- '\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>';
6952
7013
  }
6953
7014
  if(html !== threadKey){ threadKey = html; thread.innerHTML = html; }
6954
7015
  }
@@ -6997,7 +7058,7 @@
6997
7058
  }
6998
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
6999
7060
  function renderExtras(state){
7000
- if(state && (state.phase === "revising" || state.phase === "redrafting")) return;
7061
+ if(state && inWords(PAGE_WORDS.reviseRunning, state.phase)) return;
7001
7062
  var v = extrasFor(state);
7002
7063
  var html = v ? v.blocks.map(function(b){
7003
7064
  var inner = b.action ? '<div class="who">fwdloop</div>' + actionRowHtml(b.action)
@@ -7056,7 +7117,7 @@
7056
7117
  var jt = state && state.card && state.card.job;
7057
7118
  var box = document.getElementById("jf-job");
7058
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
7059
- if(!sessionLive || reviseOpen || state.phase === "stopped" || state.phase === "red" || typeof jt !== "string" || jt === box.value) return;
7120
+ if(!sessionLive || reviseOpen || inWords(PAGE_WORDS.notGreen, state.phase) || typeof jt !== "string" || jt === box.value) return;
7060
7121
  setVal("jf-job", jt); fitCardBoxes();
7061
7122
  }
7062
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).
@@ -7089,8 +7150,8 @@
7089
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).
7090
7151
  var refusal = (state.phase === "stopped" && state.refusal && typeof state.refusal === "object") ? state.refusal : null;
7091
7152
  paintRefusal(state, refusal);
7092
- errEl.textContent = (!refusal && (state.phase === "red" || state.phase === "stopped") && state.say) ? state.say : "";
7093
- var progressChanged = renderProgress(stepsFor(state, {model: drafterModel, starting: startId !== null, signClicked: signClickedOnce}));
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);
7094
7155
  sessionLive = CLIENT_TERMINAL_PHASES.indexOf(state.phase) === -1;
7095
7156
  refreshStartEnabled();
7096
7157
  syncJobBoxFromSession(state);
@@ -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;
@@ -14,15 +14,14 @@
14
14
  // 2. file kinds: `poll` of this job's file trigger; each file taken is already in the ledger (`ran`) BEFORE the fire.
15
15
  // A schedule change or a Cancel settles the queue in its own click (src/schedule.js `dropQueue` / `carryQueue`): no tick settles anything.
16
16
  // A failure on one job (a folder that went away) is written once to `triggers.jsonl` as `refused` and never stops the other jobs.
17
- import { due, readRows, recordFire } from '../trigger-clock.js';
18
- import {
19
- createFileTrigger, queueOf, readSeen, recheck, recordArrived, recordDropped, recordRan,
20
- } from '../trigger-files.js';
17
+ import { due, recordFire } from '../trigger-clock.js';
18
+ import { createFileTrigger, isFileKind, queueOf, recheck, recordArrived, recordDropped, recordRan } from '../trigger-files.js';
21
19
  import { ledgerOf } from '../schedule.js';
22
20
  import {
23
21
  TICKET_LOOK_MS, hasBaseline, lastSeen, lookTickets, recordLook, seenNumbers,
24
22
  } from '../trigger-tickets.js';
25
23
  import { readOutcomes } from './authortrigger.js';
24
+ import { readTriggerLedger } from '../jsonl-append.js';
26
25
 
27
26
  /**
28
27
  * @param {{ door: ReturnType<typeof import('./authortrigger.js').createTriggerDoor>, now?: () => number, intervalMs?: number, look?: typeof lookTickets, mcpConfig?: string }} opts
@@ -49,7 +48,7 @@ export function createScheduler(opts) {
49
48
  */
50
49
  function runQueue(job, ledger, nowMs) {
51
50
  const { sig } = job;
52
- let queue = queueOf(readSeen(ledger, sig));
51
+ let queue = queueOf(readTriggerLedger(ledger, sig));
53
52
  if (queue.length === 0) return;
54
53
  const key = (/** @type {string} */ sha, /** @type {Record<string, any>} */ r) => `${sha}|${r.outcome}|${r.why ?? ''}`; // a refusal is told once PER REASON; busy / monthly carry no `why`
55
54
  const spoken = new Set(readOutcomes(job.flowDir).filter((r) => typeof r.sha === 'string' && r.sig === sig).map((r) => key(r.sha, r)));
@@ -92,7 +91,7 @@ export function createScheduler(opts) {
92
91
  const first = !hasBaseline(ledger, sig);
93
92
  const watch = Array.isArray(trigger.watch) ? trigger.watch : [];
94
93
  // M13 piece 5 (F114f): the turn-on wrote the ticket number the first green run read; the first look baselines only tickets up to it
95
- const armedRow = first ? readRows(ledger, sig).find((r) => r.kind === 'armed') : undefined;
94
+ const armedRow = first ? readTriggerLedger(ledger, sig).find((r) => r.kind === 'armed') : undefined;
96
95
  const cut = Number.isInteger(armedRow?.ticketN) ? armedRow?.ticketN : undefined;
97
96
  const out = Promise.resolve(look({
98
97
  listUrl: trigger.list, mcp: { server: trigger.server, tool: trigger.tool }, ...(mcpConfig ? { configPath: mcpConfig } : {}),
@@ -119,11 +118,12 @@ export function createScheduler(opts) {
119
118
  if (trigger.kind === 'new-ticket') {
120
119
  startLook(job, key, ledger, nowMs);
121
120
  runQueue(job, ledger, nowMs);
122
- } else if (trigger.kind === 'file-updated' || trigger.kind === 'new-file') {
121
+ } else if (isFileKind(trigger.kind)) {
123
122
  let w = watchers.get(key);
124
123
  if (!w) {
124
+ const ft = /** @type {{kind: 'file-updated', path: string} | {kind: 'new-file', folder: string}} */ (trigger);
125
125
  w = createFileTrigger({
126
- mode: trigger.kind === 'new-file' ? 'new' : 'updated', target: trigger.kind === 'new-file' ? trigger.folder : trigger.path, ledger, sig,
126
+ mode: ft.kind === 'new-file' ? 'new' : 'updated', target: ft.kind === 'new-file' ? ft.folder : ft.path, ledger, sig,
127
127
  });
128
128
  watchers.set(key, w);
129
129
  }
@@ -132,7 +132,7 @@ export function createScheduler(opts) {
132
132
  for (const f of arrived) recordArrived(ledger, f, nowMs, sig); // THE writer of the file ledger: arrival time is this clock, never the file's mtime
133
133
  runQueue(job, ledger, nowMs);
134
134
  } else {
135
- const d = due(trigger, readRows(ledger, sig), nowMs);
135
+ const d = due(/** @type {import('../trigger-clock.js').Schedule} */ (trigger), readTriggerLedger(ledger, sig), nowMs);
136
136
  if (d.fire) {
137
137
  recordFire(ledger, d, nowMs, sig); // BEFORE the fire: a crash loses a run, never doubles one
138
138
  door.fire(job, {