fwdloop 0.36.0 → 0.37.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 (98) hide show
  1. package/README.md +1 -1
  2. package/bin/fwdloop +5 -2
  3. package/package.json +3 -3
  4. package/src/action-stop.js +1 -1
  5. package/src/auditchecks.js +41 -9
  6. package/src/authoring.js +74 -16
  7. package/src/blockasks.js +10 -12
  8. package/src/blockassemble.js +49 -43
  9. package/src/blockdraft.js +4 -2
  10. package/src/blockpick.js +10 -0
  11. package/src/canrun.js +2 -1
  12. package/src/cardlist.js +28 -5
  13. package/src/checkblock.js +610 -64
  14. package/src/checked.js +28 -33
  15. package/src/checklistsign.js +2 -1
  16. package/src/checklook.js +45 -0
  17. package/src/checkrows.js +202 -0
  18. package/src/cited-record.js +2 -2
  19. package/src/citedcheck.js +53 -12
  20. package/src/citedwords.js +7 -4
  21. package/src/closers.js +49 -2
  22. package/src/declaration.js +26 -4
  23. package/src/drafter.js +85 -61
  24. package/src/factwords.js +7 -4
  25. package/src/globprefix.js +26 -0
  26. package/src/model-step.js +22 -4
  27. package/src/pageask.js +0 -3
  28. package/src/pagedropwords.js +3 -11
  29. package/src/pagedry.js +75 -1
  30. package/src/pagefetch.js +11 -6
  31. package/src/pagelook.js +2 -1
  32. package/src/pagerules.js +8 -2
  33. package/src/panel/author.js +9 -3
  34. package/src/panel/data.js +3 -2
  35. package/src/panel/index.html +143 -33
  36. package/src/panel/result.js +34 -1
  37. package/src/pickrecord.js +14 -0
  38. package/src/planrebuild.js +55 -19
  39. package/src/ratelimit.js +117 -0
  40. package/src/report.js +14 -3
  41. package/src/rowresults.js +111 -0
  42. package/src/rubricstep.js +65 -2
  43. package/src/runner.js +38 -5
  44. package/src/shapebuild.js +281 -0
  45. package/src/shapelook.js +91 -0
  46. package/src/shapemenu.js +64 -0
  47. package/src/shaperesult.js +104 -0
  48. package/src/shaperows.js +263 -0
  49. package/src/shapewords.js +140 -0
  50. package/src/sheetbuild.js +41 -29
  51. package/src/sheetclaims.js +1 -1
  52. package/src/sheetrows.js +10 -64
  53. package/src/ticketrows.js +1 -1
  54. package/src/try-checks.js +39 -6
  55. package/src/types.js +1 -0
  56. package/src/whole-job.js +24 -8
  57. package/types/action-stop.d.ts +1 -1
  58. package/types/auditchecks.d.ts +13 -2
  59. package/types/authoring.d.ts +20 -2
  60. package/types/blockasks.d.ts +6 -10
  61. package/types/blockassemble.d.ts +13 -13
  62. package/types/blockdraft.d.ts +3 -2
  63. package/types/blockpick.d.ts +4 -0
  64. package/types/cardlist.d.ts +18 -2
  65. package/types/checkblock.d.ts +278 -28
  66. package/types/checked.d.ts +15 -6
  67. package/types/checklook.d.ts +36 -0
  68. package/types/checkrows.d.ts +119 -0
  69. package/types/citedcheck.d.ts +4 -2
  70. package/types/closers.d.ts +10 -1
  71. package/types/drafter.d.ts +8 -4
  72. package/types/globprefix.d.ts +5 -0
  73. package/types/model-step.d.ts +43 -2
  74. package/types/pageask.d.ts +0 -1
  75. package/types/pagedropwords.d.ts +0 -1
  76. package/types/pagedry.d.ts +27 -0
  77. package/types/pagefetch.d.ts +3 -2
  78. package/types/pagerules.d.ts +4 -0
  79. package/types/panel/result.d.ts +16 -1
  80. package/types/pickrecord.d.ts +10 -0
  81. package/types/ratelimit.d.ts +59 -0
  82. package/types/report.d.ts +2 -1
  83. package/types/rowresults.d.ts +28 -0
  84. package/types/rubricstep.d.ts +21 -0
  85. package/types/runner.d.ts +3 -1
  86. package/types/shapebuild.d.ts +97 -0
  87. package/types/shapelook.d.ts +76 -0
  88. package/types/shapemenu.d.ts +40 -0
  89. package/types/shaperesult.d.ts +40 -0
  90. package/types/shaperows.d.ts +102 -0
  91. package/types/shapewords.d.ts +43 -0
  92. package/types/sheetbuild.d.ts +31 -13
  93. package/types/sheetclaims.d.ts +1 -0
  94. package/types/sheetrows.d.ts +5 -36
  95. package/types/ticketrows.d.ts +1 -1
  96. package/types/try-checks.d.ts +2 -1
  97. package/types/types.d.ts +4 -0
  98. package/types/whole-job.d.ts +20 -4
@@ -612,6 +612,22 @@
612
612
  /* M12 piece 3: the ticket list in the Result tab (mockup docs/product/m12-ticket-results-mock.html, variant E). Its boxes are the panel's own: .audit-group, .filterbar, .chips, .btn.small. */
613
613
  /* M13 piece 6: the job's Result grid (mock docs/product/m13-setup-mock.html Part 3). The table, cells, q-fold and step-sub are the Audit grid's own; these are the bucket fold rows, the stats line and the run column. */
614
614
  #result-body .tg-stats{font-size:13px;margin:0 0 8px;overflow-wrap:anywhere;}
615
+ /* borrowed-from: bareloop src/panel/index.html@v0.61.0 (.sf-*). a shape line with many fields: one folded row per item (signed mock A2); a failed item is open and tinted; nothing scrolls sideways */
616
+ .sf-item{border-bottom:1px dotted var(--border-strong);}
617
+ .sf-item>summary{list-style:none;cursor:pointer;display:flex;align-items:center;gap:8px;min-height:36px;font-size:12px;padding:0 4px;}
618
+ .sf-item>summary::-webkit-details-marker{display:none;}
619
+ .sf-nm{flex:1 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}
620
+ .sf-ct{flex:0 0 auto;white-space:nowrap;}
621
+ .sf-ar{flex:0 0 auto;color:var(--accent);font-weight:700;}
622
+ .sf-ar::before{content:"\25B8";}
623
+ .sf-item[open]>summary .sf-ar::before{content:"\25BE";}
624
+ .sf-item.bad>summary{background:var(--red-bg);}
625
+ .sf-fl{padding:4px 8px 8px 22px;font-size:12px;}
626
+ .sf-fl>div{display:flex;gap:8px;padding:2px 0;border-bottom:1px dotted var(--border);}
627
+ .sf-fl .k{flex:0 0 84px;color:var(--text-dim);overflow:hidden;text-overflow:ellipsis;}
628
+ .sf-fl .g{flex:0 0 14px;}
629
+ .sf-fl .v{flex:1 1 auto;min-width:0;overflow-wrap:anywhere;}
630
+ .sf-fl .why{color:var(--red);}
615
631
  table.grid.tg td.r,table.grid.tg th.r{position:sticky;left:0;background:var(--panel2);z-index:1;min-width:84px;white-space:nowrap;}
616
632
  table.grid.tg td.c{min-width:84px;}
617
633
  table.grid.tg th{color:var(--accent);font-weight:700;}
@@ -769,6 +785,22 @@
769
785
  /* the confirm card's Drop / Add: wraps with its row, a comfortable touch target, no horizontal scroll at phone width */
770
786
  .jp .jp-btn{margin:2px 0 2px 8px;padding:4px 12px;min-height:32px;font-size:inherit;}
771
787
  .jp .fold{overflow-wrap:anywhere;}
788
+ /* borrowed-from: bareloop src/panel/index.html@v0.61.0 (fc56e1f3) .ck-* (the signed check-list look, M19 S6) */
789
+ .jp .ck-g{margin:6px 0 6px 16px;text-indent:0;}
790
+ .jp .ck-h{font-weight:700;font-size:12px;color:var(--text-dim);margin:6px 0 2px;}
791
+ .jp .ck-row{display:flex;flex-wrap:wrap;align-items:baseline;gap:0 8px;padding-left:12px;text-indent:0;overflow-wrap:anywhere;}
792
+ .jp .ck-row .tagcol{display:inline-block;min-width:82px;}
793
+ .jp .ck-row .kind{display:inline-block;min-width:48px;color:var(--text-faint);}
794
+ .jp .ck-row .ck-t{flex:1 1 220px;min-width:0;}
795
+ .jp .ck-row .ck-right{margin-left:auto;white-space:nowrap;}
796
+ .jp .ck-row .ck-under{flex-basis:100%;padding-left:138px;}
797
+ .jp .ck-why{display:inline;}
798
+ .jp .ck-why>summary::before{content:none;margin:0;}
799
+ .jp .ck-why>summary{font-weight:400;}
800
+ .jp .jl>.lbl{font-weight:700;margin-right:6px;}
801
+ .jp .ck-why summary{display:inline;cursor:pointer;color:var(--text-dim);list-style:none;margin-left:6px;}
802
+ .jp .ck-why summary::-webkit-details-marker{display:none;}
803
+ .jp .ck-why[open]{display:block;}
772
804
  .jp-sug .lbl{display:block;margin-top:6px;font-weight:700;}
773
805
  .jp details.fold{padding-left:0;margin:6px 0;}
774
806
  .jp details>summary{cursor:pointer;list-style:none;font-weight:700;}
@@ -2842,8 +2874,30 @@
2842
2874
  '/download?i=' + d.i + '&view=1" target="_blank" rel="noopener noreferrer">' + escapeXml(d.name) + '</a>' + renamed + '</div>');
2843
2875
  }).join("");
2844
2876
  }
2877
+ // ---- SHAPE JOBS (M19 S8; borrowed-from: bareloop src/panel/index.html@v0.61.0 shapeFoldHtml, shapeResultCard): a shape line's answer is a FOLD (every shape line, any field count): one row per item, opening to its fields, the stats line and the Not checked line. The server decides every mark and word (`line.shape`, src/shaperesult.js); the page only draws. An item's name is plain text.
2878
+ // one row per item `N \u00B7 name \u2713 k of n \u25B8`, a native <details> opening to one line per field; a failed item starts open (signed mock A2)
2879
+ function shapeFoldHtml(m){
2880
+ var n = m.columns.length;
2881
+ return '<div class="sf-list" data-testid="shape-fold">' + m.rows.map(function(r){
2882
+ var bad = r.cells.filter(function(c){ return c.mark === "r"; }).length;
2883
+ return '<details class="sf-item' + (bad ? ' bad' : '') + '" data-testid="shape-item"' + (bad ? ' open' : '') + '><summary><span class="sf-nm" data-testid="shape-name" title="' + escapeXml(r.name) + '">' + escapeXml(r.name) + '</span><span class="sf-ct" data-testid="shape-count">' + gridMarkOf(bad ? "r" : "g") + ' ' + (n - bad) + ' of ' + n + '</span><span class="sf-ar"></span></summary><div class="sf-fl">' +
2884
+ r.cells.map(function(c, j){ return '<div data-testid="shape-field" data-result="' + (c.mark === "r" ? "failed" : "passed") + '"><span class="k">' + escapeXml(m.columns[j].name) + '</span><span class="g">' + gridMarkOf(c.mark) + '</span><span class="v">' + escapeXml(c.text || "") + (c.why ? ' <span class="why">\u00B7 ' + escapeXml(c.why) + '</span>' : '') + '</span></div>'; }).join("") + '</div></details>';
2885
+ }).join("") + '</div>';
2886
+ }
2887
+ function shapeResultCard(line, detail, many){
2888
+ var m = line.shape;
2889
+ var h = '<div class="job-card" data-testid="result-shape"><h4>Result' + (many ? " \u00B7 line " + escapeXml(String(line.n)) : "") + '</h4>';
2890
+ if(!m){
2891
+ h += '<div class="hint" data-testid="result-nofile">' + RESULT_NONE + '</div>';
2892
+ } else {
2893
+ h += '<p class="tg-stats" data-testid="shape-stats"><b>' + escapeXml(String(detail.flow || "")) + '</b> \u00B7 ' + escapeXml(String(detail.runId || "")) + ' \u00B7 <b>' + m.total + '</b> items \u00B7 <b>' + m.passed + '</b> passed \u00B7 <b>' + m.failed + '</b> failed</p>';
2894
+ h += shapeFoldHtml(m);
2895
+ }
2896
+ return h + resultNotChecked("Not checked", line.notChecked, "result-line-notchecked") + '</div>';
2897
+ }
2845
2898
  // `own` = the Result tab read 2+ pages, so this line's box shows its own page
2846
2899
  function resultLineCard(line, own, note){
2900
+ if(line.kind === "shape") return shapeResultCard(line, resultDetail || {}, !!(resultData && (resultData.lines || []).length > 1));
2847
2901
  return '<div class="job-card" data-testid="result-line"><h4>Line ' + escapeXml(String(line.n)) + '</h4>' + resultLineBox(line) +
2848
2902
  (own ? resultPageLink(line.page, note, "result-page-line") : "") +
2849
2903
  (line.kind === "facts" ? resultFactsLine(line) : resultTextLine(line)) + (line.sheet ? resultSheetBlock(line.sheet) : resultChecksList(line)) +
@@ -4134,43 +4188,73 @@
4134
4188
  // 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
4135
4189
  // 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
4136
4190
  function tagWordOf(by){ return by === "you" || by === "agent" || by === "default" ? "[" + by + "]" : ""; }
4137
- function byTagOf(by){ return tagWordOf(by) === "" ? "" : ' <span class="by" data-testid="plan-by" data-by="' + by + '">' + tagWordOf(by) + '</span>'; }
4191
+ // borrowed-from: bareloop src/panel/index.html@v0.61.0 (fc56e1f3) byTagOf (the sign before the tag, section 3.7: `~ [you]`, `! [agent]`, `$ [default]`)
4192
+ 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
+ // 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
+ // 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>"; }
4196
+ function ckRowHtml(o){
4197
+ 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
+ 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>";
4199
+ }
4200
+ function ckGroupHtml(title, rows, testid, tail){
4201
+ return rows.length ? '<div class="ck-g" data-testid="' + testid + '"><div class="ck-h">' + escapeXml(title) + " \u00B7 " + rows.length + (tail ? " \u00B7 " + escapeXml(tail) : "") + "</div>" + rows.join("") + "</div>" : "";
4202
+ }
4138
4203
  // M16 P4c: the plan view of bareloop's card and Job tab, one drawing for both. `plan` = {lines: [{n, text, rules, leads, checks, extra}], suggested, notChecked, notCheckedBy, readNotes, alwaysOn}; the server wrote every string.
4139
4204
  // `ctl` (the card only) draws the Drop / Add button of a row. fwdloop's own rows keep their place in bareloop's structure: a line's lead sentence (src/checked.js) and a sheet line's block draw as a row under their line.
4140
4205
  // borrowed-from: bareloop src/panel/index.html@v0.56.0 (3383cce) :4157-4196 (planViewHtml: the line, its `~` rows, `\u203A check` rows, Suggested, the Not checked / How the page was read / Always checked folds)
4141
- function planCheckRowHtml(name, cls, by, ctlHtml){
4142
- return '<div class="fold" data-testid="plan-check"><span class="mk">\u203A</span> check \u00B7 ' + escapeXml(name) + (cls ? " \u00B7 " + escapeXml(cls) : "") + byTagOf(by) + (ctlHtml || "") + "</div>";
4143
- }
4144
4206
  function planFoldHtml(title, items, testid, byOf){
4145
4207
  if(!items || !items.length) return "";
4146
4208
  return '<details class="fold" data-testid="' + testid + '"><summary>' + escapeXml(title) + " \u00B7 " + items.length + "</summary><ul>" +
4147
4209
  items.map(function(x){ return "<li>" + escapeXml(x) + byTagOf(byOf(x)) + "</li>"; }).join("") + "</ul></details>";
4148
4210
  }
4211
+ // borrowed-from: bareloop src/panel/index.html@v0.61.0 (fc56e1f3) renderJobPlan (the groups of the signed look); fwd's own rows (a line's lead sentence, a sheet line's block, "How the page was read") keep their words inside it
4212
+ function planLegend(){
4213
+ return "Done when every check below passes";
4214
+ }
4149
4215
  function planViewHtml(plan, ctl){
4150
- var hasCheck = (plan.lines || []).some(function(l){ return (l.checks || []).length; });
4151
- var h = '<div class="jp" data-testid="job-plan">' + (hasCheck ? '<div class="jp-legend">Done when every <b>\u203A</b> check passes</div>' : "");
4152
- (plan.lines || []).forEach(function(l){
4216
+ var lines = plan.lines || [];
4217
+ var hasCheck = (plan.alwaysOn || []).length > 0 || lines.some(function(l){ return (l.checks || []).length; });
4218
+ var h = '<div class="jp" data-testid="job-plan">' + (hasCheck ? '<div class="jp-legend">' + planLegend() + "</div>" : "");
4219
+ var checkRow = function(c){
4220
+ var kind = c.kind || (c.shape ? "shape" : "truth");
4221
+ return ckRowHtml({ by: c.by, kind: kind, text: c.name, right: ctl && c.drop && c.key ? ctl("drop", c.key) : "", title: c.cls || "", attrs: c.shape ? ' data-shape="1"' : "" });
4222
+ };
4223
+ // borrowed-from: bareloop src/panel/index.html@v0.61.0 (ncRow: a dropped rule's Not checked row has an Add back button)
4224
+ var ncRow = function(r){ return ckRowHtml({ by: r.by, text: r.text, why: r.why, testid: "plan-refused", right: ctl && r.addBack ? ctl("add", r.addBack, "Add back") : "" }); };
4225
+ var suggRow = function(x){ return ckRowHtml({ by: "agent", kind: /\.shape\./.test(x.key) ? "shape" : "truth", text: x.text + (x.dropped ? " (you dropped it)" : ""), right: ctl ? ctl("add", x.key) : "", testid: "plan-suggest-row" }); };
4226
+ var nc = plan.ncRows || [];
4227
+ // the rows no one line owns (the two checks every step has, a Not checked note naming no line): in the block of a one-line job, in a block of their own when there are several lines
4228
+ var jobChecks = (plan.alwaysOn || []).map(function(g){ return ckRowHtml({ by: "default", kind: "file", text: g, testid: "plan-always" }); });
4229
+ var jobNc = nc.filter(function(r){ return !r.line || !lines.some(function(l){ return l.n === r.line; }); });
4230
+ var sugg = plan.suggested || [];
4231
+ var oneLine = lines.length === 1;
4232
+ var groups = function(l, own){
4233
+ var checked = (l ? l.checks.map(checkRow) : []).concat(own ? jobChecks : []);
4234
+ var notc = (l ? nc.filter(function(r){ return r.line === l.n; }) : []).concat(own ? jobNc : []).map(ncRow);
4235
+ var sg = sugg.filter(function(x){ return l ? (x.line === l.n || (own && !lines.some(function(y){ return y.n === x.line; }))) : !lines.some(function(y){ return y.n === x.line; }); }).map(suggRow);
4236
+ return ckGroupHtml("CHECKED", checked, "plan-checked") + ckGroupHtml("NOT CHECKED", notc, "plan-notchecked", "you judge these at Accept") + (sg.length ? '<div class="ck-g jp-sug" data-testid="plan-suggested"><div class="ck-h">SUGGESTED \u00B7 add if you want it</div>' + sg.join("") + "</div>" : "");
4237
+ };
4238
+ lines.forEach(function(l){
4153
4239
  h += '<div class="jl" data-testid="plan-line"><span class="num">' + escapeXml(String(l.n)) + "</span>" + escapeXml(l.text);
4154
4240
  (l.rules || []).forEach(function(r){ h += '<div class="sub">~ ' + escapeXml(r) + "</div>"; });
4155
- // fwdloop's own words under the line, plain grey after its `~` rows and before its checks: the line's lead sentence (src/checked.js) and a sheet line's block (hamr 2026-11-14)
4241
+ // fwdloop's own words under the line, plain grey after its `~` rows and before its groups: the line's lead sentence (src/checked.js) and a sheet line's block (hamr 2026-11-14)
4156
4242
  (l.leads || []).concat(l.extra || []).forEach(function(t){ h += '<div class="sub" data-testid="plan-lead">' + escapeXml(t) + "</div>"; });
4157
- (l.checks || []).forEach(function(c){ h += planCheckRowHtml(c.name, c.cls, c.by, ctl && c.drop && c.key ? ctl("drop", c.key) : ""); });
4158
- h += "</div>";
4243
+ h += groups(l, oneLine) + "</div>";
4159
4244
  });
4160
- if((plan.suggested || []).length){
4161
- h += '<div class="jl jp-sug" data-testid="plan-suggested"><span class="num"></span><span class="lbl">Suggested \u00B7 not in your job, not checked unless you add it</span>' + plan.suggested.map(function(x){
4162
- return '<div class="fold" data-testid="plan-suggest-row"><span class="mk">\u203A</span> line ' + escapeXml(String(x.line)) + " \u00B7 " + escapeXml(x.text) + byTagOf("agent") + (x.dropped ? " (you dropped it)" : "") + (ctl ? ctl("add", x.key) : "") + "</div>";
4163
- }).join("") + "</div>";
4245
+ if(!oneLine){
4246
+ var rest = groups(null, true);
4247
+ if(rest) h += '<div class="jl" data-testid="plan-job-level"><span class="num"></span><span class="lbl">Every line</span>' + rest + "</div>";
4164
4248
  }
4165
- var ncBy = plan.notCheckedBy || {};
4166
- h += planFoldHtml("Not checked", plan.notChecked, "plan-notchecked", function(x){ return ncBy[x]; });
4167
4249
  h += planFoldHtml("How the page was read", plan.readNotes, "plan-readnotes", function(){ return ""; });
4168
- h += planFoldHtml("Always checked", plan.alwaysOn, "plan-alwayson", function(){ return "default"; });
4169
4250
  return h + "</div>";
4170
4251
  }
4252
+ // borrowed-from: bareloop src/panel/index.html@v0.61.0 (fc56e1f3) auditCheckRowHtml: `[tag] kind words ... result`, the result word at the right, a failed row's red reason indented under it; a Not checked row has no result word, only its "why"
4171
4253
  function auditCheckRowHtml(r){
4172
4254
  var res = r.result === "passed" ? ["green", "passed"] : r.result === "failed" ? ["red", "failed"] : r.result === "not-checked" ? ["grey", "not checked"] : ["grey", "no result recorded"];
4173
- return '<div class="audit-check-row" data-testid="audit-check-row" data-result="' + escapeXml(r.result) + '" style="overflow-wrap:anywhere;margin:2px 0">' + escapeXml(r.text) + byTagOf(r.by) + " " + stateDotHTML(res[0], res[1], "audit-check-state") + "</div>";
4255
+ var nc = r.result === "not-checked";
4256
+ return ckRowHtml({ by: r.by, kind: nc ? "" : r.kind, text: r.text, why: nc ? r.why : "", testid: "audit-check-row", attrs: ' data-result="' + escapeXml(r.result) + '"', right: nc ? "" : stateDotHTML(res[0], res[1], "audit-check-state"),
4257
+ under: r.result === "failed" && r.why ? '<div class="hint ck-under" data-testid="audit-check-why">' + escapeXml(r.why) + "</div>" : "" });
4174
4258
  }
4175
4259
  // the fold's one state sign: any row failed = [\u2717]; else any row with no recorded result = [\u00B7]; else [\u2713] ("not checked" rows never move it)
4176
4260
  function auditChecksSignClass(rows){
@@ -4205,15 +4289,24 @@
4205
4289
  body.className = "audit-fold-body";
4206
4290
  body.hidden = true;
4207
4291
  body.setAttribute("data-testid", "audit-checks-body");
4208
- var sec = function(title, rows, tid){
4209
- if(!rows || !rows.length) return "";
4210
- return '<div data-testid="' + tid + '" style="margin:6px 0"><div><b>' + escapeXml(title) + "</b></div>" + rows.map(auditCheckRowHtml).join("") + "</div>";
4211
- };
4292
+ var grp = function(title, rows, tid, tail){ return ckGroupHtml(title, rows.map(auditCheckRowHtml), tid, tail); };
4212
4293
  var readSec = function(notes){
4213
4294
  if(!notes || !notes.length) return "";
4214
4295
  return '<div data-testid="audit-checks-readnotes" style="margin:6px 0"><div><b>How the page was read</b></div>' + notes.map(function(t){ return '<div class="audit-check-row" data-testid="audit-read-note" style="overflow-wrap:anywhere;margin:2px 0">' + escapeXml(t) + "</div>"; }).join("") + "</div>";
4215
4296
  };
4216
- body.innerHTML = '<div class="jp">' + sec("Checks", ac.checks, "audit-checks-checks") + sec("Not checked", ac.notChecked, "audit-checks-notchecked") + readSec(ac.readNotes) + sec("Always checked", ac.always, "audit-checks-always") + "</div>";
4297
+ // borrowed-from: bareloop src/panel/index.html@v0.61.0 (fc56e1f3) auditChecksEl: one block per job line (signed look): `Line N text`, its CHECKED rows, its NOT CHECKED rows; the rows no line owns (the two every step has, a Not checked note naming no line) join the block of a one-line job, else have a block of their own
4298
+ var lineBlocks = ac.lines || [];
4299
+ var blocks = lineBlocks.map(function(l, i, all){
4300
+ var own = all.length === 1;
4301
+ return '<div class="jl" data-testid="audit-line"><span class="lbl">Line ' + escapeXml(String(l.n)) + "</span> " + escapeXml(l.text) +
4302
+ grp("CHECKED", (l.checks || []).concat(own ? (ac.always || []) : []), "audit-checks-checks") + grp("NOT CHECKED", (l.notChecked || []).concat(own ? (ac.jobNotChecked || []) : []), "audit-checks-notchecked", "you judge these at Accept") + "</div>";
4303
+ });
4304
+ if(lineBlocks.length !== 1){
4305
+ var rest = grp("CHECKED", ac.always || [], "audit-checks-always") + grp("NOT CHECKED", ac.jobNotChecked || [], "audit-checks-notchecked", "you judge these at Accept");
4306
+ if(rest) blocks.push('<div class="jl" data-testid="audit-job-level"><span class="lbl">Every line</span>' + rest + "</div>");
4307
+ }
4308
+ // a run read without its per-line data (an older record, a row owned by a line the job text lacks) keeps the flat groups, no row lost
4309
+ body.innerHTML = '<div class="jp">' + (lineBlocks.length ? blocks.join("") : grp("CHECKED", (ac.checks || []).concat(ac.always || []), "audit-checks-checks") + grp("NOT CHECKED", ac.notChecked || [], "audit-checks-notchecked", "you judge these at Accept")) + readSec(ac.readNotes) + "</div>";
4217
4310
  function paint(open){ body.hidden = !open; wrap.classList.toggle("closed", !open); btn.setAttribute("aria-expanded", open ? "true" : "false"); }
4218
4311
  function toggle(){ var open = body.hidden; auditExpanded["\u0000checks"] = open; paint(open); }
4219
4312
  btn.addEventListener("click", toggle);
@@ -4493,12 +4586,16 @@
4493
4586
  tail.innerHTML = "";
4494
4587
  (plan.steps || []).filter(function(st){ return !placed[st.step]; }).forEach(function(st){ tail.appendChild(jobStepFold(st, job)); });
4495
4588
  var nc = plan.notChecked || {};
4496
- // M16 P4c: a plan with a list draws bareloop's three folds (Not checked, How the page was read, Always checked), each line tagged
4589
+ // M19 S6: a plan with a list draws the signed look's rows no line owns in an "Every line" block (a one-line job's sit in its Line 1 block, above), then "How the page was read"
4497
4590
  if(plan.always && nc.recorded){
4498
4591
  var jpFolds = document.createElement("div");
4499
4592
  jpFolds.className = "jp";
4500
- var ncBy = nc.by || {};
4501
- jpFolds.innerHTML = planFoldHtml("Not checked", nc.items, "plan-notchecked", function(x){ return ncBy[x]; }) + planFoldHtml("How the page was read", nc.readNotes, "plan-readnotes", function(){ return ""; }) + planFoldHtml("Always checked", plan.always, "plan-alwayson", function(){ return "default"; });
4593
+ var many = (job.prose || []).length !== 1;
4594
+ var lineNos = (job.prose || []).map(function(x){ return x.line; });
4595
+ var restNc = (nc.rows || []).filter(function(r){ return (many && !r.line) || (r.line && lineNos.indexOf(r.line) < 0); }).map(function(r){ return ckRowHtml({ by: r.by, text: r.text, why: r.why, testid: "plan-refused" }); });
4596
+ var restChecked = many ? (plan.always || []).map(function(g){ return ckRowHtml({ by: "default", kind: "file", text: g, testid: "plan-always" }); }) : [];
4597
+ var rest = ckGroupHtml("CHECKED", restChecked, "plan-checked") + ckGroupHtml("NOT CHECKED", restNc, "plan-notchecked", "you judge these at Accept");
4598
+ jpFolds.innerHTML = (rest ? '<div class="jl" data-testid="plan-job-level"><span class="lbl">Every line</span>' + rest + "</div>" : "") + planFoldHtml("How the page was read", nc.readNotes, "plan-readnotes", function(){ return ""; });
4502
4599
  tail.appendChild(jpFolds);
4503
4600
  return;
4504
4601
  }
@@ -4542,6 +4639,9 @@
4542
4639
  jobEl.innerHTML = "";
4543
4640
  // M4e amendment 37: one wrapper per signed line: the human's words, its `~` rows, then its step(s) folded under it (the plan, never in the same row).
4544
4641
  var placed = {};
4642
+ // am2 item 1: the Job tab's legend, first in the box, only when the plan has a check (bareloop v0.61.0 renderJobPlan's hasCheck); the same string as the card's
4643
+ var jobPlan = job.plan || {};
4644
+ if((jobPlan.always || []).length > 0 || (jobPlan.steps || []).some(function(st){ return (st.listRows || []).length; })) jobEl.appendChild(textDiv("jp-legend", planLegend()));
4545
4645
  if(!job.prose || !job.prose.length){
4546
4646
  jobEl.appendChild(textDiv("hint", "no signed prose lines"));
4547
4647
  } else {
@@ -4560,11 +4660,16 @@
4560
4660
  });
4561
4661
  // M16 P4c: the checks of a list line sit under the job line as `\u203A check` rows with their tags (bareloop's Job tab); the step fold keeps the rest
4562
4662
  // the line's lead sentence and a sheet block draw as plain grey lines first (hamr 2026-11-14), then the rows
4563
- var listRowsHtml = "";
4663
+ var listRowsHtml = "", listChecked = [];
4564
4664
  ((job.plan && job.plan.steps) || []).filter(function(st){ return st.line === l.line; }).forEach(function(st){
4565
4665
  if(job.plan.always && !st.ask) (st.check || []).concat(sheetBlockLines(st.sheet, true)).forEach(function(t){ listRowsHtml += '<div class="sub" data-testid="plan-lead">' + escapeXml(t) + "</div>"; });
4566
- (st.listRows || []).forEach(function(r){ listRowsHtml += planCheckRowHtml(r.text, "", r.by, ""); });
4666
+ (st.listRows || []).forEach(function(r){ listChecked.push(ckRowHtml({ by: r.by, kind: r.kind || "truth", text: r.text })); });
4567
4667
  });
4668
+ var ncAll = (job.plan && job.plan.notChecked && job.plan.notChecked.rows) || [];
4669
+ var oneJobLine = job.prose.length === 1;
4670
+ var ownNc = ncAll.filter(function(r){ return r.line === l.line || (oneJobLine && !r.line); }).map(function(r){ return ckRowHtml({ by: r.by, text: r.text, why: r.why, testid: "plan-refused" }); });
4671
+ var ownChecked = listChecked.concat(oneJobLine && job.plan && job.plan.always ? job.plan.always.map(function(g){ return ckRowHtml({ by: "default", kind: "file", text: g, testid: "plan-always" }); }) : []);
4672
+ if(listChecked.length || ownNc.length || (oneJobLine && job.plan && job.plan.always)) listRowsHtml += ckGroupHtml("CHECKED", ownChecked, "plan-checked") + ckGroupHtml("NOT CHECKED", ownNc, "plan-notchecked", "you judge these at Accept");
4568
4673
  if(listRowsHtml){ var jpRows = document.createElement("div"); jpRows.className = "jp"; jpRows.innerHTML = listRowsHtml; cell.appendChild(jpRows); }
4569
4674
  ((job.plan && job.plan.steps) || []).filter(function(st){ return st.line === l.line; }).forEach(function(st){
4570
4675
  placed[st.step] = true;
@@ -5983,17 +6088,22 @@
5983
6088
  // pure: the plan view's model for a plan with a list: each job line with its `~` rules, its lead sentence (src/checked.js), the built rows of the list, a sheet line's block; then the suggestions and the three folds
5984
6089
  function planOfState(state, list){
5985
6090
  var nc = state.notChecked || {};
5986
- var plan = {lines: [], suggested: list.suggested || [], notChecked: nc.items || [], notCheckedBy: nc.by && typeof nc.by === "object" ? nc.by : {}, readNotes: nc.readNotes || [], alwaysOn: state.always || []};
6091
+ var plan = {lines: [], suggested: list.suggested || [], notChecked: nc.items || [], notCheckedBy: nc.by && typeof nc.by === "object" ? nc.by : {}, readNotes: nc.readNotes || [], alwaysOn: state.always || [], ncRows: (nc.rows || []).map(function(r){ return Object.assign({}, r); })};
5987
6092
  (state.planLines || []).forEach(function(pl){
5988
6093
  var l = {n: pl.n, text: pl.text, rules: pl.rules || [], leads: [], checks: [], extra: []};
5989
6094
  state.checked.forEach(function(c){
5990
6095
  if(c.line !== pl.n) return;
5991
- if(c.sentences.length) l.leads.push(c.sentences[0]);
6096
+ if(typeof c.lead === "string") l.leads.push(c.lead);
5992
6097
  sheetBlockLines(c.sheet, true).forEach(function(t){ l.extra.push(t); });
5993
6098
  });
5994
- list.rows.filter(function(r){ return r.line === pl.n && r.state === "built"; }).forEach(function(r){ l.checks.push({name: r.text, cls: "", by: r.by, key: r.key, drop: r.drop === true}); });
6099
+ list.rows.filter(function(r){ return r.line === pl.n && r.state === "built"; }).forEach(function(r){ l.checks.push({name: r.text, cls: "", by: r.by, key: r.key, drop: r.drop === true, kind: r.kind}); });
5995
6100
  plan.lines.push(l);
5996
6101
  });
6102
+ // borrowed-from: bareloop src/panel/jobplan.js@v0.61.0 (planFromConfirm: a rule the person dropped, confirm card only: its Not checked row carries the key the Add back button posts)
6103
+ (list.restorable || []).forEach(function(x){
6104
+ var n = plan.ncRows.find(function(r){ return r.addBack === undefined && r.text === x.text && (r.line === x.line || r.line === 0); });
6105
+ if(n) n.addBack = x.key;
6106
+ });
5997
6107
  return plan;
5998
6108
  }
5999
6109
  // pure: what sits beside a green plan: Your answers (only when the plan was drafted with some), Checked (the machine's sentences from the
@@ -6872,8 +6982,8 @@
6872
6982
  return escapeXml(l.text) + byTagOf(l.by);
6873
6983
  }
6874
6984
  // the Drop / Add button of the plan view (bareloop's control; the click is handled once on the extras box)
6875
- function planControlHTML(op, key){
6876
- return ' <button type="button" class="btn jp-btn" data-testid="plan-' + op + '" data-rowop="' + op + '" data-rowkey="' + escapeXml(key) + '">' + (op === "add" ? "Add" : "Drop") + "</button>";
6985
+ function planControlHTML(op, key, label){
6986
+ return ' <button type="button" class="btn jp-btn" data-testid="plan-' + op + '" data-rowop="' + op + '" data-rowkey="' + escapeXml(key) + '">' + (label || (op === "add" ? "Add" : "Drop")) + "</button>";
6877
6987
  }
6878
6988
  // M13 am11c: the action row, two cases, never a Drop (to change it, Revise). You picked it (Agree or typed): [you]. The AI's pick, or an old log with no `by`: [agent].
6879
6989
  function actionRowHtml(a){
@@ -25,6 +25,10 @@ import { readChecks } from '../diary.js';
25
25
  import { sheetLineBlocks, csvRolesOf } from '../sheetblock.js';
26
26
  import { readSheetChecks } from '../sheet-record.js';
27
27
  import { tagged } from '../checkwords.js';
28
+ import { shapeResultModel } from '../shaperesult.js';
29
+ import { shapeItemOfPlain } from '../shapewords.js';
30
+ import { SHAPE_TRUTH_WORDS } from '../shaperows.js';
31
+ import { lineRulesOf } from '../whole-job.js';
28
32
 
29
33
  /** the two sentences for a saved file that is no longer what the run wrote (code-owned, one spelling) */
30
34
  export const RESULT_FILE_GONE = 'the saved file is gone';
@@ -179,7 +183,7 @@ export function readDelivered(rec) {
179
183
  }
180
184
 
181
185
  /**
182
- * The files this run's signed sends wrote: for each signed send whose send step ended green in the audit, the file `<flow>-<runId>-<emits>.md`
186
+ * The files this run's signed sends wrote: for each signed send whose send step ended green in the audit, the file `<job>-YYYY-MM-DD[-n].md` (`sentName`, M15 am3; older runs: `<flow>-<runId>-<emits>.md`)
183
187
  * in the signed folder with the sha256 the send recorded for it (M15), or, for a send older than M15, `.json` with the sha256 the human's accept recorded for the ask that
184
188
  * send reads (`readAcceptedHashesByEmits`, the same record the send itself checked). No accepted hash = recorded as null, which reads as "changed", never as ok.
185
189
  * @returns {{path: string, dir: string|null, name: string, note: string|null, sha256: string|null}[]}
@@ -235,6 +239,26 @@ function gapOf(text) {
235
239
  return { line: rows[0], more, moreText: more > 0 ? `(+${more} more)` : null };
236
240
  }
237
241
 
242
+ /**
243
+ * borrowed-from: bareloop src/panel/server.js@v0.61.0 (`shapeRedsFromRecords`, the gap-line half), adjusted to fwdloop's books: a run records the close's plain gap lines on its audit and log.json attempt rows (never bareguard's per-row record),
244
+ * and a red run's judged answer is the model output of that attempt in log.json. A shape line's answer for the Result tab: the delivered artifact (the step closed green: no item is red) or, for a red run, the step's last red attempt
245
+ * with the item reds read back from its plain gap lines through `shapeItemOfPlain`. Third outcome: nothing readable is `null` (the page says "no saved result to show").
246
+ * @param {{runDir: string, step: any, line: number, logJson: any}} a @returns {{results: any[], reds: string[]}|null}
247
+ */
248
+ export function shapeAnswerOf({ runDir, step, line, logJson }) {
249
+ const a = readArtifactResult(runDir, step.emits);
250
+ if (a.ok && a.value && typeof a.value === 'object' && Array.isArray(a.value.results)) return { results: a.value.results, reds: [] };
251
+ const last = (Array.isArray(logJson?.attempts) ? logJson.attempts : []).filter((t) => t && t.step === step.emits && t.verdict === 'red').at(-1);
252
+ const out = last?.modelOutput;
253
+ if (!out || typeof out !== 'object' || !Array.isArray(out.results)) return null;
254
+ const reds = String(last.gap ?? '').split('\n').flatMap((l) => {
255
+ const m = /^line (\d+): (item \d+.*)$/s.exec(l);
256
+ const red = m && Number(m[1]) === line ? shapeItemOfPlain(m[2]) : null;
257
+ return red ? [red] : [];
258
+ });
259
+ return { results: out.results, reds: [...new Set(reds)] };
260
+ }
261
+
238
262
  /**
239
263
  * The Result tab's JSON for one run (`GET /api/runs/:flow/:runId/result`).
240
264
  * @param {{flow: string, runId: string, runDir: string, root: string, flowRead: any, arbiter: any, historyRow: any, auditRows: any[], logJson: any, notChecked: string[], readNotes?: string[], setupRows?: any[], door?: {askId: string, draftNo: number}|null}} a
@@ -268,6 +292,15 @@ export function buildResult({
268
292
  }).filter((x) => x !== null);
269
293
  if (written.length > 0) out.answer = written.join('\n\n');
270
294
  }
295
+ // M19 S8 (the signed mock A2): a line whose close holds a list-of-items check (`close.itemShape`) shows its answer as a fold of items; the model is src/shaperesult.js's (bareloop v0.61.0), the marks and words the server's
296
+ const shapeStep = (declaration?.steps ?? []).find((st) => st.fromLine === l.n && st.close && typeof st.close.itemShape === 'object' && st.close.itemShape !== null && Array.isArray(st.close.itemShape.fields));
297
+ if (shapeStep) {
298
+ out.kind = 'shape';
299
+ const got = shapeAnswerOf({ runDir, step: shapeStep, line: l.n, logJson });
300
+ out.shape = got === null ? null : shapeResultModel({ part: shapeStep.close.itemShape, results: got.results, reds: got.reds, rules: lineRulesOf(l) });
301
+ if (!out.notChecked.includes(SHAPE_TRUTH_WORDS)) out.notChecked = [...out.notChecked, SHAPE_TRUTH_WORDS];
302
+ return out;
303
+ }
271
304
  if (c) {
272
305
  out.source = c.source;
273
306
  out.page = urls.get(c.source) ?? null;
package/src/pickrecord.js CHANGED
@@ -118,6 +118,20 @@ export function readRowChoices(file) {
118
118
  } catch { return null; }
119
119
  }
120
120
 
121
+ // borrowed-from: bareloop src/pickrecord.js@v0.61.0 (fc56e1f3) (readShapeDropped; read through readFileInside like readSheetDropped; writeRecordPart not taken: fwd's writers are src/authoring.js and src/planrebuild.js)
122
+ /**
123
+ * Shape jobs (clause 4): the shape fields a person dropped from a plan, carried like the sheet's (the block's `shapeDroppedRecord`: `{lineWords, occurrence, name}` or `{lineWords, occurrence, rule}`), so a Revise keeps a Drop of the very same field. A missing or unreadable record is no record.
124
+ * @param {string} file @returns {{lineWords: string, occurrence: number, name?: string, rule?: number}[]|null}
125
+ */
126
+ export function readShapeDropped(file) {
127
+ try {
128
+ const g = readFileInside(path.dirname(file), path.basename(file));
129
+ if (!g.ok) return null;
130
+ const j = JSON.parse(g.text);
131
+ return Array.isArray(j?.shapeDropped) ? j.shapeDropped.filter((/** @type {any} */ d) => d && typeof d.lineWords === 'string' && Number.isInteger(d.occurrence) && (typeof d.name === 'string' || Number.isInteger(d.rule))) : null;
132
+ } catch { return null; }
133
+ }
134
+
121
135
  /**
122
136
  * The sheet checks the person dropped from a plan (hamr 2026-11-14: a Revise keeps a sheet Drop), carried like the page-row choices: the record's `sheetDropped` entries, each `{key, line, index, check, text}`;
123
137
  * the next draft drops a new check with the same id again. Read through readFileInside; a missing or unreadable record is no record.
@@ -12,7 +12,8 @@ import { readInputFacts } from './input-facts.js';
12
12
  import { blockJobLines } from './blocklines.js';
13
13
  import { setUpBlock, ticketLeaveOut, pickEdits, ledgerEdits } from './blockdraft.js';
14
14
  import { assembleFromBlock } from './blockassemble.js';
15
- import { cardOfBlock } from './cardlist.js';
15
+ import { cardOfBlock, cardOfPlanBlock } from './cardlist.js';
16
+ import { ledgerRowsOf } from './checkrows.js';
16
17
  import { editsOf } from './rowedit.js';
17
18
  import { NOTE_KIND } from './noteask.js';
18
19
  import { offerRules, rowsFromAnswer, codeScope } from './checkpick.js';
@@ -20,12 +21,15 @@ import { matchRecord, readRowChoices, RECORD_FILE } from './pickrecord.js';
20
21
  import { listLinesOf, cardLinesOf } from './checklistsign.js';
21
22
  import { csvRolesOf } from './sheetblock.js';
22
23
  import { withTicketRows } from './ticketrows.js';
23
- import { isSheetKey, sheetChoice, withSheetRows, withSheetCard, droppedSheetOf } from './sheetrows.js';
24
+ import { isSheetKey, sheetRowsOf, withSheetRows, withSheetCard } from './sheetrows.js';
24
25
  import { validateDeclaration } from './declaration.js';
25
26
  import { loadCatalogue } from './catalogue.js';
26
27
  import { WIRED_VERBS } from './primitives.js';
27
28
  import { ticketSourcesOf } from './ticket-draft.js';
28
29
  import { docRolesOf } from './drafter.js';
30
+ import { buildShapes } from './shapebuild.js';
31
+ import { parseShapeAnswer, SHAPE_CALL_LABEL } from './shapelook.js';
32
+ import { lineRules } from './pagebits.js';
29
33
  import { buildReadout, specHash, PAGES_DIR, NOT_CHECKED_FILE } from './authoring.js';
30
34
 
31
35
  /** what a person is told when the saved inputs no longer give the saved list: nothing is written */
@@ -73,6 +77,12 @@ export function rebuildBlock({ planDir, asks }) {
73
77
  if (!plan.ok) return no('This plan could not be read. Nothing was changed.');
74
78
  const blockLineNums = new Set(plan.jobLines.map((l) => l.n));
75
79
  const inBlock = (/** @type {{line: number}} */ x) => blockLineNums.has(x.line);
80
+ // M19 S3: a sheet line is the block's too; the draft saved what code built from the AI's sheet suggestions (log.json `sheetBuilt`), so the block holds its sheet rows again without a call. A plan that has sheet checks
81
+ // and no such record was drafted before this and cannot be rebuilt: the same sentence as an input that changed
82
+ const sheetBuilt = isRec(log?.sheetBuilt) && isRec(log.sheetBuilt.built) ? log.sheetBuilt : null;
83
+ if (sheetBuilt === null && (declaration.steps ?? []).some((/** @type {any} */ st) => isRec(st?.close) && Array.isArray(st.close.sheet))) return no(REBUILD_CHANGED_SAY);
84
+ const sheetLineNums = sheetBuilt === null ? [] : Object.keys(sheetBuilt.built).map(Number).filter((n) => tied.includes(n));
85
+ const notSheet = (/** @type {{line: number}} */ x) => !sheetLineNums.includes(x.line);
76
86
  const lines = parsed.lines;
77
87
  const allShape = offerRules(lines, parsed.arbiter, look.facts);
78
88
  const matched = matchRecord(Array.isArray(record.picks) ? record.picks : [], lines, allShape);
@@ -83,16 +93,28 @@ export function rebuildBlock({ planDir, asks }) {
83
93
  const leftSaved = look.dropped.filter((/** @type {any} */ d) => d?.reason === 'person-left' && Number.isInteger(d.line) && Number.isInteger(d.rule)).map((/** @type {any} */ d) => ({ line: d.line, rule: d.rule }));
84
94
  const leftFresh = [...matched.left.filter((x) => !isKept(x)), ...leftSaved.filter((x) => !matched.left.some((m) => m.line === x.line && m.rule === x.rule))].filter(inBlock);
85
95
  const block = setUpBlock({
86
- texts, jobLines: plan.jobLines, look,
96
+ texts, jobLines: [...plan.jobLines, ...all.jobLines.filter((l) => sheetLineNums.includes(l.n))].sort((a, b) => a.n - b.n), look: { facts: look.facts.filter(notSheet), dropped: look.dropped.filter(notSheet) },
87
97
  kept: { picks: matched.picks.filter(inBlock).filter(isKept), left: matched.left.filter(inBlock).filter(isKept), askRules: matched.askRules.filter(inBlock) },
88
98
  fresh: { picks: matched.picks.filter(inBlock).filter((x) => !isKept(x)), left: leftFresh },
89
- asks, countScope: (t) => codeScope(parsed.arbiter.sources, t) === 'in', leaveOut: ticketLeaveOut(declaration.flowType, plan.jobLines),
99
+ asks, countScope: (t) => codeScope(parsed.arbiter.sources, t) === 'in', leaveOut: ticketLeaveOut(declaration.flowType, plan.jobLines), sheetLines: sheetLineNums,
90
100
  });
91
101
  // the AI's replies, in the order the draft took them (log.json keeps each reply as sent)
92
102
  const askRules = allShape.filter((r) => !isKept(r));
103
+ let shapeSet = false;
93
104
  for (const e of Array.isArray(log?.log) ? log.log : []) {
94
105
  // the note question's answers ride its entry, a failed turn's too (a `failed` answer is a Not checked row, so it must replay)
95
106
  if (isRec(e) && e.kind === NOTE_KIND) { block.setNotes(notesOfEntry(e)); continue; }
107
+ // M19 S9: the shape look's answer, as the draft saved it (log.json keeps the raw text of the one call it made). It is read again through the same parser and the same builder, so the block holds its shape rows
108
+ // without a call; the first answer that reads is the one the draft used (an unreadable first answer was asked once more). A plan with shape rows and no such entry does not rebuild (the list differs below)
109
+ if (isRec(e) && e.kind === SHAPE_CALL_LABEL) {
110
+ const got = e.outcome === 'answered' && typeof e.rawText === 'string' && !shapeSet ? parseShapeAnswer(e.rawText) : null;
111
+ if (got !== null && got.ok && got.shapes.length > 0) {
112
+ shapeSet = true;
113
+ block.setShape(buildShapes({ lines: plan.jobLines.filter((l) => lineRules(l).length > 0 && !block.isSheetLine(l.n)), labels: block.labels, suggestions: got.shapes }));
114
+ block.reconcile();
115
+ }
116
+ continue;
117
+ }
96
118
  if (!isRec(e) || e.outcome !== 'answered' || !isRec(e.args)) continue;
97
119
  if (e.kind === 'check-suggest') block.applyDelta({ label: 'pre:check-suggest', pre: true, edits: pickEdits(rowsFromAnswer(askRules, e.args), blockLineNums) });
98
120
  else if (e.kind === 'ledger-suggest') block.applyDelta({ label: 'pre:ledger-suggest', pre: true, edits: ledgerEdits(e.args.extra) });
@@ -103,6 +125,9 @@ export function rebuildBlock({ planDir, asks }) {
103
125
  // the choices the plan was made with (a Drop or an Add of an earlier edit), judged by the block again
104
126
  const choices = readRowChoices(path.join(planDir, RECORD_FILE));
105
127
  if (choices) block.carryChoices(choices);
128
+ // the sheet checks the draft built, in the draft's own order (after the AI's edits), and the Drops the plan was made with
129
+ if (sheetBuilt !== null) { block.setSheet(sheetBuilt); block.carrySheetDropped(Array.isArray(record.sheetDropped) ? record.sheetDropped : []); }
130
+ if (Array.isArray(record.shapeDropped) && record.shapeDropped.length) block.carryShapeDropped(record.shapeDropped);
106
131
  block.reconcile();
107
132
  return { ok: true, block, declaration, lines, lineSet, parsed, texts, look, record, log, proseText: prose.text };
108
133
  }
@@ -120,7 +145,7 @@ function assembleAgain(b, from = b.declaration) {
120
145
  const src = b.lineSet.has(st?.fromLine) && isRec(st.close) && isRec(st.close.cited) ? st.close.cited.source : undefined;
121
146
  return typeof src === 'string' && docs.has(src) && Array.isArray(st.reads) ? { ...st, reads: st.reads.filter((/** @type {string} */ r) => r !== src) } : st;
122
147
  }) };
123
- const built = assembleFromBlock({ declaration: rest, block: b.block, lines: b.lines, lineSet: b.lineSet, askLines: new Set(b.parsed.arbiter.asks.map((/** @type {any} */ a) => a.line)) });
148
+ const built = assembleFromBlock({ declaration: rest, block: b.block, lines: b.lines, lineSet: b.lineSet, askLines: new Set(b.parsed.arbiter.asks.map((/** @type {any} */ a) => a.line)), sheetRoles: csvRolesOf(b.parsed.arbiter) });
124
149
  // M16 am4: the sheet checks are rows on the list too, read from the steps the same way the draft read them
125
150
  const withSheet = withSheetRows({ declaration: built.declaration, lines: b.lines, csvRoles: csvRolesOf(b.parsed.arbiter) });
126
151
  // M17 am6: the Tickets filter and watch are rows on the list too, read from the declaration's fields the same way the draft read them
@@ -154,16 +179,22 @@ const fingerprint = (d) => JSON.stringify([d.checkList ?? null, (d.steps ?? []).
154
179
  export function rowEditPlan({ planDir, op, key, asks = true }) {
155
180
  const b = rebuildBlock({ planDir, asks });
156
181
  if (!b.ok) return { ok: false, say: b.say, refused: 'no-list' };
157
- const dropped = droppedSheetOf(b.record);
158
182
  const before = assembleAgain(b);
159
183
  if (!before.ok) return { ok: false, say: before.say, refused: 'rebuild' };
160
184
  if (fingerprint(before.declaration) !== fingerprint(b.declaration)) return { ok: false, say: REBUILD_CHANGED_SAY, refused: 'changed' };
161
- // a sheet row is a check of the AI's own sheet step: its Drop or Add changes `close.sheet` (src/sheetrows.js); any other row is the block's
162
- const sheetDone = isSheetKey(key) ? sheetChoice({ declaration: b.declaration, lines: b.lines, csvRoles: csvRolesOf(b.parsed.arbiter), op, key, dropped }) : null;
163
- const done = sheetDone ?? b.block.rowChoice(key, op);
185
+ // M19 S3: a sheet check is a row of the block like any other (its Drop or Add is the block's `rowChoice`). A `[you]` sheet row is drawn with the key of its check (src/sheetrows.js), which is no row of the block: the
186
+ // refusals for it are the words the plan card has always given
187
+ /** @type {string|null} */
188
+ let sheetKeyWhy = null;
189
+ if (isSheetKey(key) && !b.block.rows.some((r) => r.key === key)) {
190
+ const card = sheetRowsOf({ declaration: b.declaration, lines: b.lines, csvRoles: csvRolesOf(b.parsed.arbiter) }).card.find((r) => r.key === key);
191
+ sheetKeyWhy = op === 'drop' ? (card?.by === 'you' ? 'that check comes from a rule you wrote; edit the job to change it' : 'there is no such check on the list') : 'only a suggested check can be added';
192
+ }
193
+ const done = sheetKeyWhy !== null ? { ok: /** @type {const} */ (false), why: sheetKeyWhy } : b.block.rowChoice(key, op);
164
194
  if (!done.ok) return { ok: false, say: `${done.why[0].toUpperCase()}${done.why.slice(1)}${/[.!?]$/.test(done.why) ? '' : '.'} Nothing was changed.`, refused: 'bad-row' };
165
- const droppedNow = sheetDone && sheetDone.ok ? sheetDone.dropped : dropped;
166
- const after = assembleAgain(b, sheetDone && sheetDone.ok ? sheetDone.declaration : b.declaration);
195
+ const droppedNow = b.block.sheetDroppedRecord();
196
+ const shapeDroppedNow = b.block.shapeDroppedRecord();
197
+ const after = assembleAgain(b);
167
198
  if (!after.ok) return { ok: false, say: after.say, refused: 'rebuild' };
168
199
  const target = readJson(planDir, 'target.json');
169
200
  const inputFactsText = readFileInside(planDir, 'input-facts.json');
@@ -171,11 +202,6 @@ export function rowEditPlan({ planDir, op, key, asks = true }) {
171
202
  if (!targetText.ok || !inputFactsText.ok || !isRec(target)) return { ok: false, say: 'This plan could not be read. Nothing was changed.', refused: 'rebuild' };
172
203
  const dj = (/** @type {unknown} */ o) => `${JSON.stringify(o, null, 2)}\n`;
173
204
  const declarationText = dj(after.declaration);
174
- const readoutText = buildReadout({
175
- declaration: after.declaration, arbiter: b.parsed.arbiter, lines: b.lines, name: target.name, modelId: b.log?.modelId, costUsd: b.log?.costUsd ?? null, rounds: b.log?.rounds ?? 0, spendComplete: b.log?.spendComplete !== false, root: target.root,
176
- });
177
- const h = specHash({ proseText: b.proseText, declarationText, inputFactsText: inputFactsText.text, readoutText, targetText: targetText.text });
178
- if (!h.ok) return { ok: false, say: 'The changed plan could not be hashed. Nothing was changed.', refused: 'rebuild' };
179
205
  // the "Not checked" list: what the old plan listed, less what the old list made, plus what the changed list makes (the AI's own list stays)
180
206
  const oldNc = readJson(planDir, NOT_CHECKED_FILE)?.notChecked;
181
207
  const oldList = Array.isArray(oldNc) ? oldNc.filter((x) => typeof x === 'string') : [];
@@ -183,7 +209,17 @@ export function rowEditPlan({ planDir, op, key, asks = true }) {
183
209
  const notChecked = [...new Set([...oldList.filter((x) => !was.has(x)), ...after.notChecked])];
184
210
  const oldBy = isRec(readJson(planDir, NOT_CHECKED_FILE)?.by) ? readJson(planDir, NOT_CHECKED_FILE).by : {};
185
211
  const by = { ...Object.fromEntries(Object.entries(oldBy).filter(([t]) => !was.has(t))), ...after.notCheckedBy };
186
- const { sheetDropped: _sd, ...record } = isRec(b.record) ? b.record : {};
212
+ // M19 am4: the plan card the new plan saves is the one its readout reads (one model)
213
+ // M19 am8 item 1, am9 item 5: the new plan's ledger rows, one per Not checked row, in its own log; the card is read from the new plan (am6)
214
+ const ledger = ledgerRowsOf(after.declaration, b.lines, Object.fromEntries(b.block.rows.filter((/** @type {any} */ r) => r.kind !== 'rule').map((/** @type {any} */ r) => [r.key, r.name ? [r.name] : r.words ?? []])));
215
+ const card = (() => { const c = withSheetCard(cardOfBlock(b.block), after.sheet); return cardOfPlanBlock(b.block, after.tickets.card.length ? withSheetCard(c, { card: after.tickets.card }) : c, { declaration: after.declaration, lines: b.lines, csvRoles: csvRolesOf(b.parsed.arbiter), log: [...(Array.isArray(b.log?.log) ? b.log.log : []), ...ledger] }); })();
216
+ const readoutText = buildReadout({
217
+ declaration: after.declaration, arbiter: b.parsed.arbiter, lines: b.lines, name: target.name, modelId: b.log?.modelId, costUsd: b.log?.costUsd ?? null, rounds: b.log?.rounds ?? 0, spendComplete: b.log?.spendComplete !== false, root: target.root,
218
+ notChecked, notCheckedBy: by, suggested: card.suggested, checkCard: card,
219
+ });
220
+ const h = specHash({ proseText: b.proseText, declarationText, inputFactsText: inputFactsText.text, readoutText, targetText: targetText.text });
221
+ if (!h.ok) return { ok: false, say: 'The changed plan could not be hashed. Nothing was changed.', refused: 'rebuild' };
222
+ const { sheetDropped: _sd, shapeDropped: _shd, ...record } = isRec(b.record) ? b.record : {};
187
223
  const logRow = { round: (Array.isArray(b.log?.log) ? b.log.log.length : 0) + 1, kind: 'row-edit-human', op, key, outcome: 'answered', at: new Date().toISOString() };
188
224
  // the files the new plan keeps as they were (read through the gateway), then the ones it changes; `spec.hash` last, so a folder with one is whole
189
225
  /** @type {Record<string, string>} */
@@ -208,8 +244,8 @@ export function rowEditPlan({ planDir, op, key, asks = true }) {
208
244
  'declaration.json': declarationText,
209
245
  'readout.txt': readoutText,
210
246
  [NOT_CHECKED_FILE]: dj({ notChecked, ...(Object.keys(by).length ? { by } : {}) }),
211
- [RECORD_FILE]: dj({ ...record, rowChoices: b.block.choicesRecord(), ...(droppedNow.length ? { sheetDropped: droppedNow } : {}) }),
212
- 'log.json': dj({ ...(isRec(b.log) ? b.log : {}), log: [...(Array.isArray(b.log?.log) ? b.log.log : []), logRow], checkCard: (() => { const c = withSheetCard(cardOfBlock(b.block), after.sheet, droppedNow); return after.tickets.card.length ? withSheetCard(c, { card: after.tickets.card }) : c; })() }),
247
+ [RECORD_FILE]: dj({ ...record, rowChoices: b.block.choicesRecord(), ...(droppedNow.length ? { sheetDropped: droppedNow } : {}), ...(shapeDroppedNow.length ? { shapeDropped: shapeDroppedNow } : {}) }),
248
+ 'log.json': dj({ ...(isRec(b.log) ? b.log : {}), log: [...(Array.isArray(b.log?.log) ? b.log.log : []), logRow, ...ledger], checkCard: card }),
213
249
  'spec.hash': `${h.hash}\n`,
214
250
  },
215
251
  };