fwdloop 0.21.0 → 0.23.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 (104) hide show
  1. package/bin/fwdloop +85 -34
  2. package/package.json +4 -3
  3. package/src/ask.js +20 -4
  4. package/src/audit-fold.js +5 -1
  5. package/src/authoring.js +36 -6
  6. package/src/canrun.js +5 -0
  7. package/src/checked.js +32 -4
  8. package/src/cited-record.js +138 -0
  9. package/src/cited-source.js +49 -0
  10. package/src/citedcheck.js +321 -0
  11. package/src/citedwords.js +197 -0
  12. package/src/closers.js +37 -198
  13. package/src/csv.js +69 -12
  14. package/src/ctx-tools.js +2 -14
  15. package/src/declaration.js +143 -5
  16. package/src/diary.js +2 -2
  17. package/src/docx.js +16 -2
  18. package/src/draft-steps.js +1 -1
  19. package/src/drafter.js +322 -33
  20. package/src/flow.js +33 -7
  21. package/src/flowmodel.js +21 -0
  22. package/src/input-facts.js +20 -3
  23. package/src/model-step.js +38 -21
  24. package/src/pageask.js +136 -0
  25. package/src/pagebits.js +107 -0
  26. package/src/pagedropwords.js +171 -0
  27. package/src/pagedry.js +120 -0
  28. package/src/pagefetch.js +164 -0
  29. package/src/pagelook.js +155 -0
  30. package/src/pagemap.js +55 -0
  31. package/src/pageplace.js +103 -0
  32. package/src/pagerules.js +318 -0
  33. package/src/panel/author.js +43 -21
  34. package/src/panel/authorcard.js +20 -3
  35. package/src/panel/authorflows.js +21 -15
  36. package/src/panel/authorstart.js +2 -4
  37. package/src/panel/authortrigger.js +14 -4
  38. package/src/panel/data.js +102 -6
  39. package/src/panel/index.html +321 -12
  40. package/src/panel/result.js +301 -0
  41. package/src/panel/server.js +27 -3
  42. package/src/primitives.js +2 -3
  43. package/src/provider.js +5 -2
  44. package/src/redact.js +17 -0
  45. package/src/runner.js +102 -14
  46. package/src/schedule.js +3 -3
  47. package/src/setup.js +16 -1
  48. package/src/sheet-record.js +57 -0
  49. package/src/sheetblock.js +170 -0
  50. package/src/sheetchecks.js +206 -0
  51. package/src/sheetclaims.js +78 -0
  52. package/src/sheetfind.js +50 -0
  53. package/src/sheetlook.js +157 -0
  54. package/src/sheetoffer.js +125 -0
  55. package/src/sheetrun.js +105 -0
  56. package/src/signed-text.js +11 -1
  57. package/src/thinking.js +1 -1
  58. package/src/try-checks.js +12 -0
  59. package/src/types.js +4 -11
  60. package/types/ask.d.ts +2 -1
  61. package/types/authoring.d.ts +19 -2
  62. package/types/checked.d.ts +19 -3
  63. package/types/cited-record.d.ts +21 -0
  64. package/types/cited-source.d.ts +18 -0
  65. package/types/citedcheck.d.ts +95 -0
  66. package/types/citedwords.d.ts +97 -0
  67. package/types/closers.d.ts +37 -10
  68. package/types/csv.d.ts +25 -4
  69. package/types/ctx-tools.d.ts +0 -1
  70. package/types/declaration.d.ts +20 -1
  71. package/types/docx.d.ts +14 -0
  72. package/types/drafter.d.ts +264 -8
  73. package/types/flow.d.ts +21 -0
  74. package/types/flowmodel.d.ts +15 -0
  75. package/types/input-facts.d.ts +12 -2
  76. package/types/model-step.d.ts +40 -19
  77. package/types/pageask.d.ts +75 -0
  78. package/types/pagebits.d.ts +32 -0
  79. package/types/pagedropwords.d.ts +40 -0
  80. package/types/pagedry.d.ts +38 -0
  81. package/types/pagefetch.d.ts +86 -0
  82. package/types/pagelook.d.ts +75 -0
  83. package/types/pagemap.d.ts +31 -0
  84. package/types/pageplace.d.ts +22 -0
  85. package/types/pagerules.d.ts +86 -0
  86. package/types/panel/authorcard.d.ts +4 -1
  87. package/types/panel/authorflows.d.ts +2 -0
  88. package/types/panel/data.d.ts +26 -0
  89. package/types/panel/result.d.ts +156 -0
  90. package/types/provider.d.ts +3 -1
  91. package/types/redact.d.ts +1 -0
  92. package/types/runner.d.ts +162 -9
  93. package/types/schedule.d.ts +0 -11
  94. package/types/setup.d.ts +13 -0
  95. package/types/sheet-record.d.ts +24 -0
  96. package/types/sheetblock.d.ts +116 -0
  97. package/types/sheetchecks.d.ts +70 -0
  98. package/types/sheetclaims.d.ts +26 -0
  99. package/types/sheetfind.d.ts +46 -0
  100. package/types/sheetlook.d.ts +120 -0
  101. package/types/sheetoffer.d.ts +25 -0
  102. package/types/sheetrun.d.ts +35 -0
  103. package/types/thinking.d.ts +1 -1
  104. package/types/types.d.ts +27 -14
@@ -396,7 +396,6 @@
396
396
  .filterbar .chips{gap:4px;margin-bottom:4px;}
397
397
  .chip.fchip{padding:3px 7px;min-height:28px;min-width:28px;font-size:12px;text-align:center;}
398
398
  .chip.fchip::before,.chip.fchip::after{content:"";}
399
- /* M11 am20 item 4: the ◷ glyph is drawn smaller than ✓ and ✗ at the same font-size (a fallback font); this chip alone is scaled up to match. */
400
399
  .row-blocked{background:var(--red-bg);}
401
400
 
402
401
  /* hamr review #5/#6: Audit tab grouped-by-step sections. */
@@ -492,6 +491,23 @@
492
491
  .job-card h4{margin:0 0 8px;font-size:13px;position:absolute;top:-10px;left:10px;background:var(--panel2);padding:0 6px;}
493
492
  .job-card h4::before{content:"┤ ";color:var(--text-faint);}
494
493
  .job-card h4::after{content:" ├";color:var(--text-faint);}
494
+ /* M10 am4: the Result tab. borrowed-from: bareloop src/panel/index.html@2959217 :188 :192 :397-408 (the Your-call card's rules are below, am5 item 2) */
495
+ .st-word{font-weight:700;color:var(--text);}
496
+ .step-state{display:inline-flex;align-items:center;gap:2px;font-size:12px;}
497
+ /* PRD v1.107 Part 6: the Result tab. Boxes are the Job tab's own (.job-card, .field, .ro-value, .field-row); text wraps, nothing scrolls the page. */
498
+ #result-body{min-width:0;overflow-wrap:anywhere;}
499
+ .rs-ok{color:var(--green);font-weight:700;}
500
+ .rs-bad{color:var(--red);font-weight:700;}
501
+ #result-body mark{background:var(--rl-accent-bg-strong);color:var(--text);border-radius:2px;padding:0 1px;}
502
+ #result-body details>summary{cursor:pointer;color:var(--text-dim);min-height:28px;}
503
+ .rs-warn{color:var(--amber);overflow-wrap:anywhere;}
504
+ /* M10 am5 item 2: the Your-call card. borrowed-from: bareloop src/panel/index.html@2959217 :401-403 :407 */
505
+ #result-door-card{border-color:var(--amber);}
506
+ #result-door-card .st-word{color:var(--amber);}
507
+ #result-door-card textarea{width:100%;min-height:60px;margin:6px 0;background:var(--bg);color:var(--text);border:1px solid var(--text-dim);font:inherit;padding:6px;box-sizing:border-box;}
508
+ #result-door-card .stopping{color:var(--amber);font-size:13px;overflow-wrap:anywhere;}
509
+ /* M10 am4 item 8 (bareloop never looked on a phone): a long saved-file name wraps inside its button instead of pushing it past the screen */
510
+ #result-body .btn{max-width:100%;box-sizing:border-box;white-space:normal;overflow-wrap:anywhere;}
495
511
  .field{margin-bottom:10px;}
496
512
  label{display:block;font-size:11px;font-weight:700;color:var(--text-dim);margin-bottom:2px;text-transform:uppercase;letter-spacing:0.04em;}
497
513
  /* hamr's 2026-09-27 exit-check review #3: Ask tab box headers — same
@@ -623,6 +639,8 @@
623
639
  .jf-inrow{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,2fr) auto;gap:6px;margin-bottom:4px;align-items:start;}
624
640
  .jf-inrow .btn.small{height:32px;padding:0 8px;}
625
641
  .jf-inrow .jf-role-ro{padding:5px 7px;min-height:32px;overflow-wrap:anywhere;border:1px solid var(--border);background:var(--bg);color:var(--text-dim);}
642
+ #details-schedule{overflow-wrap:anywhere;} /* M10: a page input's full address in the Schedule field wraps, never spills */
643
+ .jf-inrow .jf-path{text-overflow:ellipsis;} /* M10: a web page's address is cut with an ellipsis (the whole is the title) */
626
644
  .jf-inrow .jf-err{grid-column:1 / -1;}
627
645
  /* M4e amendment 4/5: what a Run or a Resume cannot change shows dimmed (the signature fixes it); only the open boxes are bright */
628
646
  .field.dimmed{opacity:.6;}
@@ -973,7 +991,7 @@
973
991
  <div class="jf-gut" id="jf-inputs-gut" data-testid="jf-inputs-gut" aria-hidden="true"><div class="jf-gut-in"></div></div>
974
992
  <textarea class="jf-wrap" id="jf-inputs" rows="3" data-testid="jf-inputs" autocomplete="off" spellcheck="false" placeholder="resume: /full/path/to/resume.md"></textarea>
975
993
  </div>
976
- <div class="hint">One line per file: a name, a colon, its full path starting with /. The page never reads the file.</div>
994
+ <div class="hint">One line per file: a name, a colon, its full path starting with /, or a web address (http:// or https://). The page never reads the file.</div>
977
995
  <div class="jf-err" id="jf-err-inputs" data-testid="jf-err-inputs"></div>
978
996
  </div>
979
997
  <div class="field">
@@ -1194,6 +1212,7 @@
1194
1212
  <button role="tab" id="tab-audit" aria-controls="panel-audit" aria-selected="false" data-testid="right-tab-audit">Audit / logs</button>
1195
1213
  <button role="tab" id="tab-details" aria-controls="panel-details" aria-selected="false" data-testid="right-tab-details">Job</button>
1196
1214
  <button role="tab" id="tab-ask" aria-controls="panel-ask" aria-selected="false" data-testid="right-tab-ask">Ask</button>
1215
+ <button role="tab" id="tab-result" aria-controls="panel-result" aria-selected="false" data-testid="right-tab-result" hidden>Result</button>
1197
1216
  </div>
1198
1217
 
1199
1218
  <div class="pane-body" id="right-pane-body">
@@ -1315,6 +1334,11 @@
1315
1334
  <div id="ask-list" data-testid="ask-list" hidden></div>
1316
1335
  </section>
1317
1336
 
1337
+ <section id="panel-result" class="tabpanel" role="tabpanel" aria-labelledby="tab-result" hidden data-testid="panel-result">
1338
+ <div id="result-empty" class="hint" style="font-size:13px;padding:24px 0;">select a run first</div>
1339
+ <div id="result-body" data-testid="result-body" hidden></div>
1340
+ </section>
1341
+
1318
1342
  </div>
1319
1343
  </section>
1320
1344
 
@@ -1347,7 +1371,7 @@
1347
1371
  });
1348
1372
  }
1349
1373
  wireTabs([document.getElementById("tab-chat"), document.getElementById("tab-runs"), document.getElementById("tab-inbox")]);
1350
- wireTabs([document.getElementById("tab-run"), document.getElementById("tab-audit"), document.getElementById("tab-details"), document.getElementById("tab-ask")]);
1374
+ wireTabs([document.getElementById("tab-run"), document.getElementById("tab-audit"), document.getElementById("tab-details"), document.getElementById("tab-ask"), document.getElementById("tab-result")]);
1351
1375
 
1352
1376
  // ---- fetch helpers. Reads are GET. The ONLY non-GET requests on this page are
1353
1377
  // the two POSTs below (M4b): /api/answer (a human clicking a door) and
@@ -2301,7 +2325,6 @@
2301
2325
  if(!ok || !sc || !ink(sc)) return;
2302
2326
  sc.style.fontSize = (parseFloat(getComputedStyle(ok).fontSize) * ink(ok) / ink(sc)) + "px";
2303
2327
  }
2304
- window.fwdloopFitChips = fitChips;
2305
2328
  fitChips();
2306
2329
 
2307
2330
  function runsFilterFn(items, filters, nowMs){
@@ -2345,6 +2368,243 @@
2345
2368
  document.querySelectorAll(".inbox-row").forEach(function(r){ r.classList.remove("selected"); r.setAttribute("aria-pressed","false"); });
2346
2369
  }
2347
2370
 
2371
+ // borrowed-from: bareloop src/panel/index.html@2959217 :2839 (stateDotHTML)
2372
+ function stateDotHTML(cls, word, testid){
2373
+ return '<span class="step-state" data-testid="' + testid + '"><span class="dot ' + cls + (cls === "amber" ? " pulse" : "") + '"></span><b class="st-word">' + escapeXml(word) + '</b></span>';
2374
+ }
2375
+ // ---- Result tab (M10 am4: a copy of bareloop's, PRD v1.107 Part 6) ----
2376
+ // borrowed-from: bareloop src/panel/index.html@2959217 :3646-3833, adjusted to fwdloop's shape: the run is (flow, runId); the status word is `detail.word`;
2377
+ // the run name is `<flow> (<runId>)`; no Your-call card or pointer here (item 5 waits).
2378
+ // The server decides everything: `detail.hasResult` shows the tab, `/result` carries the signed lines, the facts' own sentences
2379
+ // (src/facts.js factSentence), the rows of the delivered file (sha256-checked against the run's own record) and `passed` (read from the
2380
+ // run's own check-run). The page only draws; it never decides a check and never searches a quote for a word.
2381
+ var resultDetail = null;
2382
+ var resultData = null;
2383
+ function resultTabShown(){ return document.getElementById("tab-result").getAttribute("aria-selected") === "true"; }
2384
+ function clearResult(){
2385
+ resultDetail = null; resultData = null;
2386
+ document.getElementById("result-body").hidden = true;
2387
+ document.getElementById("result-body").innerHTML = "";
2388
+ document.getElementById("result-empty").hidden = false;
2389
+ }
2390
+ // called by renderRun for every detail it draws: shows or removes the tab button
2391
+ function syncResultTab(detail){
2392
+ var btn = document.getElementById("tab-result");
2393
+ var show = detail.hasResult === true;
2394
+ if(!show && resultTabShown()) document.getElementById("tab-run").click();
2395
+ btn.hidden = !show;
2396
+ var same = !!resultData && resultData.flow === detail.flow && resultData.runId === detail.runId;
2397
+ if(!show || !same) clearResult(); // another run's rows never stay on screen
2398
+ resultDetail = show ? detail : null;
2399
+ if(show && same) renderResult();
2400
+ }
2401
+ function loadResult(flow, runId){
2402
+ return getJSON("/api/runs/" + encodeURIComponent(flow) + "/" + encodeURIComponent(runId) + "/result").then(function(data){
2403
+ if(currentFlow !== flow || currentRunId !== runId || !resultDetail || resultDetail.flow !== data.flow || resultDetail.runId !== data.runId) return;
2404
+ resultData = data;
2405
+ renderResult();
2406
+ }).catch(function(){ /* the tab keeps what it last drew */ });
2407
+ }
2408
+ document.getElementById("tab-result").addEventListener("click", function(){ if(currentRunId !== null) loadResult(currentFlow, currentRunId); });
2409
+
2410
+ // a RED run's own file words (the last file its check judged: "the file is gone" / "the file changed after the check") and the one note that says
2411
+ // what those rows are. A DELIVERED file's gone/changed words are said once, in the Saved card, never here.
2412
+ function resultFileWords(file){
2413
+ var note = file && file.judged && file.note ? '<div class="hint" data-testid="result-judged-note">' + escapeXml(file.note) + '</div>' : "";
2414
+ return note + (file && file.judged && file.words ? '<div class="rs-warn" data-testid="result-file-words">' + escapeXml(file.words) + '</div>' : "");
2415
+ }
2416
+ // M10b am2: what a job line that reads a sheet shows, drawn from the server's ONE block ({guardrails, checked: [{text, ...}], notChecked: [..] | "none"}): its
2417
+ // guardrails, "Checked:" with one line per sheet check (name, plain words, covers), then "Not checked:" with the guardrails no check covers, or "none".
2418
+ // Pure: the Chat plan card and the Job tab step rows both draw these strings; the server wrote every one of them.
2419
+ function sheetBlockLines(sheet){
2420
+ if(!sheet) return [];
2421
+ var out = [];
2422
+ if((sheet.guardrails || []).length){
2423
+ out.push("Guardrails:");
2424
+ sheet.guardrails.forEach(function(g){ out.push("- " + g); });
2425
+ }
2426
+ out.push("Checked:");
2427
+ (sheet.checked || []).forEach(function(c){ out.push("- " + c.text); });
2428
+ if(sheet.notChecked === "none" || !(sheet.notChecked || []).length) out.push("Not checked: none");
2429
+ else { out.push("Not checked:"); sheet.notChecked.forEach(function(g){ out.push("- " + g); }); }
2430
+ return out;
2431
+ }
2432
+ // the Result tab's drawing of the same block, after the run: each check carries \u2713 or \u2717 and what was found (the server's `found`), then its plain words and
2433
+ // covers; "Not checked" again. A check with no verdict (the run never reached it) draws with no mark. Every string is escaped.
2434
+ function resultSheetBlock(sheet){
2435
+ if(!sheet) return "";
2436
+ var rows = (sheet.checked || []).map(function(c){
2437
+ var mark = c.ok === true ? '<span class="rs-ok">\u2713</span> ' : (c.ok === false ? '<span class="rs-bad">\u2717</span> ' : "");
2438
+ var more = [c.words, c.coversWords].filter(function(x){ return x; }).join(" \u00b7 ");
2439
+ return '<div data-testid="result-sheet-check">' + mark + escapeXml(typeof c.found === "string" ? c.found : c.name) +
2440
+ (more ? ' <span class="hint">' + escapeXml(more) + '</span>' : "") + '</div>';
2441
+ }).join("");
2442
+ var nc = sheet.notChecked === "none" || !(sheet.notChecked || []).length ? "none" : null;
2443
+ return resultField("Checked", '<div class="ro-value" data-testid="result-sheet-checked">' + rows + '</div>') +
2444
+ resultField("Not checked", nc !== null ? '<div class="ro-value" data-testid="result-sheet-notchecked">none</div>' :
2445
+ '<div class="ro-value" data-testid="result-sheet-notchecked"><ul style="margin:0;padding-left:18px">' + sheet.notChecked.map(function(t){ return '<li>' + escapeXml(t) + '</li>'; }).join("") + '</ul></div>');
2446
+ }
2447
+ function resultField(label, inner){
2448
+ return '<div class="field"><label>' + escapeXml(label) + '</label>' + inner + '</div>';
2449
+ }
2450
+ // the numbered job line and its ~ rules, one box (the Job tab's "N. text" spelling, a space after the number)
2451
+ function resultLineBox(line){
2452
+ return resultField("The job line", '<div class="ro-value" data-testid="result-linetext">' + escapeXml(line.n + ". " + line.text) +
2453
+ (line.rules || []).map(function(r){ return '<br>~ ' + escapeXml(r); }).join("") + '</div>');
2454
+ }
2455
+ // no saved result to show: one line, never the file-state words (those are in Saved)
2456
+ var RESULT_NONE = "no saved result to show";
2457
+ // the proof quote, with the words the check read marked. The server sends the check's own text and offsets (`r.proof`: bareguard's
2458
+ // `full.evidence`, spans already chosen and merged); the page only cuts the text at those offsets, escapes every piece and marks.
2459
+ // It never searches a quote for a word. No proof (an old run, a quote the check did not read): the plain quote, unmarked.
2460
+ function resultProofHtml(r){
2461
+ var p = r.proof;
2462
+ if(!p || typeof p.text !== "string" || !Array.isArray(p.marks)) return escapeXml(r.quote);
2463
+ var h = "", at = 0;
2464
+ p.marks.forEach(function(m){
2465
+ h += escapeXml(p.text.slice(at, m[0])) + "<mark>" + escapeXml(p.text.slice(m[0], m[1])) + "</mark>";
2466
+ at = m[1];
2467
+ });
2468
+ return h + escapeXml(p.text.slice(at));
2469
+ }
2470
+ function resultFactsLine(line){
2471
+ var facts = line.facts || [];
2472
+ var n = facts.length;
2473
+ var ok = line.passed === true ? ' <span class="rs-ok" data-testid="result-ok">\u2713</span>' : "";
2474
+ var h = resultFileWords(line.file);
2475
+ if(Array.isArray(line.rows) && line.rows.length){
2476
+ h += resultField("Results (" + line.rows.length + ")", '<div class="ro-value" data-testid="result-results">' + line.rows.map(function(r){
2477
+ return '<div class="ro-value" data-testid="result-row" style="margin-bottom:8px">' +
2478
+ '<div style="display:flex;justify-content:space-between;flex-wrap:wrap;gap:6px"><b style="color:var(--text)">Result ' + r.n + '</b>' +
2479
+ (line.passed === true ? '<span class="rs-ok" data-testid="result-count">' + n + ' of ' + n + ' \u2713</span>' : "") + '</div>' +
2480
+ '<div class="field-row" style="margin-top:6px">' + r.cells.map(function(c, i){
2481
+ return '<div class="field"><label>' + escapeXml(facts[i] ? facts[i].name : "") + '</label><div class="ro-value" data-testid="result-cell">' + escapeXml(c) + ok + '</div></div>';
2482
+ }).join("") + '</div>' +
2483
+ '<details data-testid="result-proof"><summary>proof \u2014 the page\'s own words</summary><div class="ro-value" data-testid="result-quote" style="overflow-wrap:anywhere">' + resultProofHtml(r) + '</div></details></div>';
2484
+ }).join("") + '</div>');
2485
+ } else if(!(line.file && line.file.judged && line.file.words)){
2486
+ h += '<div class="hint" data-testid="result-nofile">' + RESULT_NONE + '</div>';
2487
+ }
2488
+ if(facts.length){
2489
+ h += resultField("The checks", '<div class="ro-value" data-testid="result-rules">' +
2490
+ facts.map(function(f){ return escapeXml(f.sentence) + (f.note ? ' ' + escapeXml(f.note) : ""); }).join("<br>") +
2491
+ (line.passed === true && Array.isArray(line.rows) && line.rows.length ? '<br><span class="hint">\u2713 = code checked it against the saved page</span>' : "") + '</div>');
2492
+ }
2493
+ return h;
2494
+ }
2495
+ // M10 am9 item 2: what the line's step checked, one row each, ✓ or ✗, in the Audit try line's words (the server's `text` and `result`; code wrote them).
2496
+ // A line with none draws nothing.
2497
+ function resultChecksList(line){
2498
+ var cs = line.checks || [];
2499
+ if(!cs.length) return "";
2500
+ return resultField(line.kind === "facts" ? "What the step checked" : "The checks", '<div class="ro-value" data-testid="result-checklist">' + cs.map(function(c){
2501
+ return '<div data-testid="result-check"><span class="' + (c.ok ? "rs-ok" : "rs-bad") + '">' + (c.ok ? "\u2713" : "\u2717") + '</span> ' + escapeXml(c.text) +
2502
+ (c.result ? ' (' + escapeXml(c.result) + ')' : "") + '</div>';
2503
+ }).join("") + '</div>');
2504
+ }
2505
+ function resultTextLine(line){
2506
+ var h = resultFileWords(line.file);
2507
+ if(typeof line.answer === "string") h += resultField("Answer", '<div class="ro-value" data-testid="result-answer" style="color:var(--text);white-space:pre-wrap">' + escapeXml(line.answer) + '</div>');
2508
+ else if(!(line.file && line.file.judged && line.file.words)) h += '<div class="hint" data-testid="result-nofile">' + RESULT_NONE + '</div>';
2509
+ (line.cites || []).forEach(function(c){
2510
+ h += resultField("Quotes from " + c.label + " (" + c.items.length + ")", '<details data-testid="result-cites"><summary>show</summary><div class="ro-value" style="white-space:pre-wrap">' +
2511
+ c.items.map(function(it){ return '<b>' + escapeXml(it.claim) + '</b>\n' + escapeXml(it.quote); }).join("\n\n") + '</div></details>');
2512
+ });
2513
+ return h;
2514
+ }
2515
+ // a list, one row per item (the Job tab lists the same items one per row)
2516
+ function resultNotChecked(label, items, testid){
2517
+ if(!items || !items.length) return "";
2518
+ return resultField(label, '<div class="ro-value" data-testid="' + testid + '"><ul style="margin:0;padding-left:18px">' +
2519
+ items.map(function(t){ return '<li>' + escapeXml(t) + '</li>'; }).join("") + '</ul></div>');
2520
+ }
2521
+ // the web page a result was read from: a link (http/https only, new tab) and the server's words that the page may have moved on
2522
+ function resultPageLink(url, note, testid){
2523
+ if(typeof url !== "string" || !/^https?:\/\//i.test(url)) return "";
2524
+ return resultField("Page read", '<div class="ro-value" data-testid="' + testid + '" style="overflow-wrap:anywhere"><a href="' + escapeXml(url) +
2525
+ '" target="_blank" rel="noopener noreferrer">' + escapeXml(url) + '</a><div class="hint" data-testid="result-page-note">' + escapeXml(note || "") + '</div></div>');
2526
+ }
2527
+ // `own` = the Result tab read 2+ pages, so this line's box shows its own page
2528
+ function resultLineCard(line, own, note){
2529
+ return '<div class="job-card" data-testid="result-line"><h4>Line ' + escapeXml(String(line.n)) + '</h4>' + resultLineBox(line) +
2530
+ (own ? resultPageLink(line.page, note, "result-page-line") : "") +
2531
+ (line.kind === "facts" ? resultFactsLine(line) : resultTextLine(line)) + (line.sheet ? resultSheetBlock(line.sheet) : resultChecksList(line)) +
2532
+ resultNotChecked("Not checked", line.notChecked, "result-line-notchecked") + '</div>';
2533
+ }
2534
+ function renderResult(){
2535
+ var detail = resultDetail, data = resultData;
2536
+ var body = document.getElementById("result-body");
2537
+ if(!detail || !data || data.flow !== detail.flow || data.runId !== detail.runId){ return; }
2538
+ document.getElementById("result-empty").hidden = true;
2539
+ body.hidden = false;
2540
+ // keep what the person is typing (and the box they opened) across a poll-driven redraw
2541
+ var keepText = body.querySelector("#result-rerun-text");
2542
+ var typed = keepText ? keepText.value : "";
2543
+ var rerunOpen = !!body.querySelector("#result-rerun-box:not([hidden])");
2544
+ var counters = document.getElementById("run-counters").textContent.split(" \u00b7 ");
2545
+ var h = '<div class="job-card" data-testid="result-head"><h4>Result</h4>' +
2546
+ resultField("Status", '<div class="ro-value">' + stateDotHTML(glyphClass(detail.glyph), detail.word || "", "result-status") +
2547
+ ' \u00b7 ' + escapeXml(detail.checkType) + ' \u00b7 ' + escapeXml(detail.flow + " (" + detail.runId + ")") + '</div>') +
2548
+ '<div class="field-row">' + resultField("Money", '<div class="ro-value" data-testid="result-counters">' + escapeXml(counters[0] || "") + '</div>') +
2549
+ resultField("Time", '<div class="ro-value">' + escapeXml((counters[1] || "").replace(/^took /, "")) + '</div>') + '</div>' +
2550
+ ((data.pages || []).length === 1 ? resultPageLink(data.pages[0], data.pageNote, "result-page-top") : "") + '</div>';
2551
+ var ownPages = (data.pages || []).length >= 2;
2552
+ (data.lines || []).forEach(function(line){ h += resultLineCard(line, ownPages, data.pageNote); });
2553
+ if(data.gap){
2554
+ h += '<div class="rs-warn" data-testid="result-gap">The check said: ' + escapeXml(data.gap.line) + (data.gap.moreText ? ' ' + escapeXml(data.gap.moreText) : "") + '</div>';
2555
+ }
2556
+ if((data.notChecked || []).length){
2557
+ h += '<div class="job-card"><h4>Not checked</h4>' + resultNotChecked(data.notCheckedLabel, data.notChecked, "result-notchecked") + '</div>';
2558
+ }
2559
+ if((data.readNotes || []).length){
2560
+ h += '<div class="job-card"><h4>How the page was read</h4>' + resultNotChecked("How the page was read \u00b7 " + data.readNotes.length, data.readNotes, "result-readnotes") + '</div>';
2561
+ }
2562
+ if(data.door) h += resultDoorHtml(data.door);
2563
+ if((data.delivered || []).length){
2564
+ h += '<div class="job-card" data-testid="result-saved"><h4>Saved</h4>' + data.delivered.map(function(d){
2565
+ return resultField(d.name, '<div class="ro-value" data-testid="result-path" style="overflow-wrap:anywhere">' + escapeXml(d.path) + '</div>' +
2566
+ (d.words ? '<div class="rs-warn" data-testid="result-file-gone">' + escapeXml(d.words) + '</div>'
2567
+ : '<div class="run-actions" style="margin:6px 0 0;"><a class="btn" style="text-decoration:none;" data-testid="result-download" download href="/api/runs/' + encodeURIComponent(data.flow) + '/' + encodeURIComponent(data.runId) + '/download?i=' + d.i + '">Download ' + escapeXml(d.name) + '</a></div>'));
2568
+ }).join("") + '</div>';
2569
+ }
2570
+ body.innerHTML = h;
2571
+ var ta = body.querySelector("#result-rerun-text");
2572
+ if(ta){
2573
+ ta.value = typed;
2574
+ if(rerunOpen){ body.querySelector("#result-rerun-box").hidden = false; body.querySelector('[data-testid="result-rerun"]').disabled = typed.trim() === ""; }
2575
+ wireResultDoor(body, data.door, data.flow, data.runId);
2576
+ }
2577
+ paintAnswerMsg();
2578
+ }
2579
+ // M10 am5 item 2: the Your-call card. Bareloop's words and layout; no Pause (a run waiting for you stays open and spends nothing until you answer or its ask wait ends).
2580
+ // Accept and Rerun with my words are the Ask tab's own: the same `sendAnswer` and POST /api/answer (decision accept / rerun, the words as the reason), so an
2581
+ // answer given here is the answer on every tab. The server decides when the card is shown (`door`); the page types none of its words.
2582
+ function resultDoorHtml(door){
2583
+ return '<div class="job-card" id="result-door-card" data-testid="result-door"><h4>Your call</h4><div class="field"><div class="ro-value"><b class="st-word">' + escapeXml(door.head) + '</b> \u2014 ' + escapeXml(door.ask) + '</div></div>' +
2584
+ '<div class="run-actions" style="margin:6px 0 0;"><button class="btn primary" type="button" data-testid="result-accept">Accept</button>' +
2585
+ '<button class="btn" type="button" data-testid="result-rerun-open">Rerun with my words</button></div>' +
2586
+ '<div id="result-rerun-box" data-testid="result-rerun-box" hidden><textarea id="result-rerun-text" data-testid="result-rerun-text" aria-label="your words for the rerun" placeholder="e.g. only morning flights, and show the airline"></textarea>' +
2587
+ '<button class="btn" type="button" data-testid="result-rerun" disabled>Rerun</button></div>' +
2588
+ '<div id="result-door-msg" data-testid="result-door-msg"></div></div>';
2589
+ }
2590
+ function wireResultDoor(body, door, flow, runId){
2591
+ var card = body.querySelector("#result-door-card");
2592
+ if(!card) return;
2593
+ var ask = {askId: door.askId};
2594
+ var ctx = {flow: flow, runId: runId, draftNo: door.draftNo};
2595
+ card.querySelector('[data-testid="result-accept"]').addEventListener("click", function(){ sendAnswer(card, ask, ctx, "accept"); });
2596
+ var box = card.querySelector("#result-rerun-box");
2597
+ var txt = card.querySelector("#result-rerun-text");
2598
+ var go = card.querySelector('[data-testid="result-rerun"]');
2599
+ card.querySelector('[data-testid="result-rerun-open"]').addEventListener("click", function(){ box.hidden = !box.hidden; if(!box.hidden) txt.focus(); });
2600
+ // required: the button stays off while the words are empty, and the click re-checks (the engine refuses empty words too)
2601
+ txt.addEventListener("input", function(){ go.disabled = txt.value.trim() === ""; });
2602
+ go.addEventListener("click", function(){
2603
+ if(txt.value.trim() === ""){ say(flow, runId, "refused", "Write what you want done differently, then press Rerun."); return; }
2604
+ sendAnswer(card, ask, ctx, "rerun");
2605
+ });
2606
+ }
2607
+
2348
2608
  // ---- Run tab: header + summary + step map + one card per step ATTEMPT
2349
2609
  // (ruling A, 2026-09-26: "no per-round parts") — built off getRunDetail's
2350
2610
  // `steps[]` (declaration.steps joined with audit.jsonl attempts), never a
@@ -2432,6 +2692,7 @@
2432
2692
  '<div class="summary-row" data-testid="summary-checks"><span class="sum-label">checks:</span><span class="sum-val">' + escapeXml((detail.runLines && detail.runLines.checks) || "\u2014") + '</span></div>';
2433
2693
 
2434
2694
  renderRunActions(detail);
2695
+ syncResultTab(detail); // M10 am4: shows or hides the Result tab; the ONE caller
2435
2696
  // amendment 7 item 2: the Draft is the first box of the Map (an arrow runs on to step 1); the steps keep their own numbers
2436
2697
  renderStepMap(stepBoxes.length ? [draftBox(detail.draft)].concat(stepBoxes.map(function(b, i){ return Object.assign({}, b, {n: i + 1}); })) : stepBoxes);
2437
2698
 
@@ -3272,7 +3533,11 @@
3272
3533
  fold.appendChild(textDiv("plan-row", "reads: " + ((st.reads || []).length ? st.reads.join(", ") : "nothing")));
3273
3534
  fold.appendChild(textDiv("plan-row", "makes: " + (st.makes || "unknown")));
3274
3535
  fold.appendChild(textDiv("plan-row", "may do: " + ((st.mayDo || []).length ? st.mayDo.join(", ") : "nothing (pure stop)")));
3275
- fold.appendChild(textDiv("plan-row", "check: " + (st.ask ? "ASK · waits " + plainWait(st.waitMs) : (st.check || []).join(" "))));
3536
+ // M10 am11: each check sentence is its own row
3537
+ if(st.ask || !(st.check || []).length) fold.appendChild(textDiv("plan-row", "check: " + (st.ask ? "ASK · waits " + plainWait(st.waitMs) : "")));
3538
+ else st.check.forEach(function(s){ fold.appendChild(textDiv("plan-row", "check: " + s)); });
3539
+ // M10b am2: a step that reads a sheet shows its line's block under the check sentence
3540
+ sheetBlockLines(st.sheet).forEach(function(t){ fold.appendChild(textDiv("plan-row", t)); });
3276
3541
  return fold;
3277
3542
  }
3278
3543
  // The tail: any step that came from no listed line, then the folded Not-checked summary (its label comes from the payload, src/checked.js; always shown).
@@ -3293,6 +3558,17 @@
3293
3558
  else if(!(nc.items || []).length) fold.appendChild(textDiv("plan-row", "the AI listed nothing"));
3294
3559
  else nc.items.forEach(function(it){ fold.appendChild(textDiv("plan-row", it)); });
3295
3560
  tail.appendChild(fold);
3561
+ // M10 am11: code's notes about written forms it did not use, their own fold after Not checked (none = no fold)
3562
+ if((nc.readNotes || []).length){
3563
+ var rn = document.createElement("details");
3564
+ rn.className = "plan-fold plan-readnotes";
3565
+ var rs = document.createElement("summary");
3566
+ rs.className = "plan-sum";
3567
+ rs.textContent = "How the page was read";
3568
+ rn.appendChild(rs);
3569
+ nc.readNotes.forEach(function(it){ rn.appendChild(textDiv("plan-row", it)); });
3570
+ tail.appendChild(rn);
3571
+ }
3296
3572
  }
3297
3573
  function renderJob(job){
3298
3574
  var empty = document.getElementById("job-empty");
@@ -3461,7 +3737,7 @@
3461
3737
  // separately-fetched copy of the audit rows to cross-reference (fix #6).
3462
3738
  // same guard as reloadRun: a late reply for a run the user already left paints nothing and writes no polling flag
3463
3739
  var still = function(){ return currentFlow === flow && currentRunId === runId; };
3464
- getJSON(base).then(function(d){ if(still()) paintRun(d); }).catch(function(e){
3740
+ getJSON(base).then(function(d){ if(still()){ paintRun(d); if(d.hasResult === true) loadResult(flow, runId); } }).catch(function(e){
3465
3741
  if(!still()) return;
3466
3742
  openRunLive = false; // unreadable books: the list rate, not 2 s forever
3467
3743
  document.getElementById("run-empty").hidden = false;
@@ -3891,6 +4167,13 @@
3891
4167
  el.className = "answer-msg" + (mine ? " " + m.cls : "");
3892
4168
  el.textContent = mine ? m.text : "";
3893
4169
  });
4170
+ // the Result tab's Your-call card shows the same message for its own run (no attribute is added while there is none)
4171
+ var rm = document.getElementById("result-door-msg");
4172
+ if(rm){
4173
+ var m2 = answerMsg;
4174
+ if(m2 && resultDetail && m2.flow === resultDetail.flow && m2.runId === resultDetail.runId){ rm.className = "answer-msg " + m2.cls; rm.textContent = m2.text; }
4175
+ else if(rm.textContent !== "" || rm.hasAttribute("class")){ rm.removeAttribute("class"); rm.textContent = ""; }
4176
+ }
3894
4177
  }
3895
4178
  // Every refusal the page shows is a plain sentence — never an HTTP status, a refusal code, an askId or a path.
3896
4179
  // `r` is { status, body, text } from postJSON; `decision` is the answer word of an answer click (else null).
@@ -4142,6 +4425,13 @@
4142
4425
  // style a footnote/why-text uses.
4143
4426
  ev.appendChild(textDiv("evidence-heading", "draft " + ctx.draftNo));
4144
4427
  ev.appendChild(draftEl);
4428
+ } else if(evidence.sheet){
4429
+ // M10b am4: a sheet step's ask shows the Result tab's own lines (resultSheetBlock) and the step's answer value by value, where the error line was
4430
+ var sheetBox = document.createElement("div");
4431
+ sheetBox.setAttribute("data-testid", "ask-sheet");
4432
+ sheetBox.innerHTML = resultSheetBlock(evidence.sheet.block) + resultField("Answer", '<div class="ro-value" data-testid="ask-sheet-answers">' +
4433
+ (evidence.sheet.answer || []).map(function(t){ return '<div data-testid="ask-sheet-answer">' + escapeXml(t) + '</div>'; }).join("") + '</div>');
4434
+ ev.appendChild(sheetBox);
4145
4435
  } else {
4146
4436
  ev.appendChild(textDiv("hint", evidence.why || "no draft on file"));
4147
4437
  }
@@ -4645,6 +4935,10 @@
4645
4935
  if(!state || state.phase !== "questions-open" || !Array.isArray(state.questions)) return null;
4646
4936
  var q = state.questions.filter(function(x){ return x.k === state.openK; })[0];
4647
4937
  if(!q) return null;
4938
+ // M10 am2 item 1 / am5 item 1: a question the page look raised is ONE plain chat message (bareloop's words); the head and line rows stay empty
4939
+ if(q.source === "look"){
4940
+ return { key: String(state.draftId) + ":" + q.k, k: q.k, head: "", line: "", question: "A question the plan raised (" + q.k + " of " + state.total + "), about job line " + q.line + ": " + q.question };
4941
+ }
4648
4942
  return {
4649
4943
  key: String(state.draftId) + ":" + q.k, k: q.k,
4650
4944
  head: "A question the plan raised (" + q.k + " of " + state.total + ")",
@@ -4662,11 +4956,20 @@
4662
4956
  return "line " + a.line + (a.lineText ? ": " + a.lineText : "") + "\n > " + a.answer;
4663
4957
  })});
4664
4958
  }
4665
- blocks.push({id: "chat-checked", head: "Checked", sub: "built by the machine from the plan's checks", lines: state.checked.map(function(c){
4666
- return (c.line !== null && c.line !== undefined ? "line " + c.line : "step " + c.step) + ": " + c.sentences.join(" ");
4667
- })});
4959
+ // M10 am11: each check sentence is its own line (the step's label leads its first; the rest sit under it)
4960
+ var checkedLines = [];
4961
+ state.checked.forEach(function(c){
4962
+ c.sentences.forEach(function(s, i){
4963
+ checkedLines.push(i === 0 ? (c.line !== null && c.line !== undefined ? "line " + c.line : "step " + c.step) + ": " + s : " " + s);
4964
+ });
4965
+ // M10b am2: a line that reads a sheet: its guardrails, Checked (name, words, covers), Not checked
4966
+ sheetBlockLines(c.sheet).forEach(function(t){ checkedLines.push(" " + t); });
4967
+ });
4968
+ blocks.push({id: "chat-checked", head: "Checked", sub: "built by the machine from the plan's checks", lines: checkedLines});
4668
4969
  var nc = state.notChecked || {};
4669
4970
  blocks.push({id: "chat-notchecked", head: nc.label || "", sub: "", lines: (nc.items && nc.items.length) ? nc.items.map(function(x){ return "- " + x; }) : ["The drafter listed nothing."]});
4971
+ // M10 am11: code's notes about written forms it did not use are their own list, after Not checked (none = no block)
4972
+ if(nc.readNotes && nc.readNotes.length) blocks.push({id: "chat-readnotes", head: "How the page was read", sub: "", lines: nc.readNotes.map(function(x){ return "- " + x; })});
4670
4973
  return {blocks: blocks};
4671
4974
  }
4672
4975
  // pure: did this POST succeed (one decision for every handler)
@@ -4752,7 +5055,9 @@
4752
5055
  var ro = document.createElement("div");
4753
5056
  ro.className = "jf-role-ro"; ro.textContent = role; ro.setAttribute("data-role", role);
4754
5057
  row.appendChild(ro);
4755
- row.appendChild(makeInput("jf-path", "/full/path/to/file", sources ? sources[role] : ""));
5058
+ var pathEl = makeInput("jf-path", "/full/path/to/file", sources ? sources[role] : "");
5059
+ if(f && f.pages && f.pages[role]){ pathEl.value = f.pages[role]; pathEl.readOnly = true; pathEl.setAttribute("data-page", "1"); pathEl.title = "A web page: its address is signed with the job and can't be changed here."; } // M10 am3
5060
+ row.appendChild(pathEl);
4756
5061
  row.appendChild(makeErr());
4757
5062
  runInputsEl.appendChild(row);
4758
5063
  });
@@ -4923,7 +5228,7 @@
4923
5228
  function syncCardLock(){
4924
5229
  var on = cardLocked();
4925
5230
  whenSyncButton();
4926
- card.querySelectorAll("input[type=text], textarea").forEach(function(el){ el.readOnly = on; el.classList.toggle("locked", on); });
5231
+ 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
4927
5232
  runFlowSel.disabled = on;
4928
5233
  runFlowSel.classList.toggle("locked", on);
4929
5234
  rwPickedEl.classList.toggle("locked", on);
@@ -5118,7 +5423,10 @@
5118
5423
  byId("jf-err-when").textContent = "";
5119
5424
  var roleSel = byId("jf-when-role");
5120
5425
  roleSel.innerHTML = "";
5121
- ((f && f.roles) || []).forEach(function(r){ var o = document.createElement("option"); o.value = r; o.textContent = r; roleSel.appendChild(o); });
5426
+ // M10: a file trigger watches a FILE; a web-page input is never offered (a job with only page inputs gets the clock options only)
5427
+ var fileRoles = ((f && f.roles) || []).filter(function(r){ return !(f.pages && f.pages[r]); });
5428
+ fileRoles.forEach(function(r){ var o = document.createElement("option"); o.value = r; o.textContent = r; roleSel.appendChild(o); });
5429
+ ["file-updated", "new-file"].forEach(function(k){ var o = byId("jf-when").querySelector('option[value="' + k + '"]'); o.hidden = o.disabled = fileRoles.length === 0; });
5122
5430
  var t = c ? c.trigger : null;
5123
5431
  sel.querySelector('option[value="hand"]').textContent = t ? "Cancel schedule" : "By hand"; // M9 am5: on a scheduled job, By hand reads Cancel schedule
5124
5432
  sel.value = t ? t.kind : "hand";
@@ -5374,6 +5682,7 @@
5374
5682
  if(v.key !== qKey){
5375
5683
  qKey = v.key;
5376
5684
  qHead.textContent = v.head; qLine.textContent = v.line; qText.textContent = v.question;
5685
+ qHead.hidden = v.head === ""; qLine.hidden = v.line === ""; // a look question is one plain message: no empty rows
5377
5686
  qAnswer.value = ""; qError.textContent = "";
5378
5687
  }
5379
5688
  }