fwdloop 0.13.0 → 0.14.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.
@@ -24,7 +24,7 @@
24
24
  the CSS is harmless dead weight rather than a second stylesheet to maintain). */
25
25
  :root{
26
26
  --bg:#1a1b26; --panel:#1f2335; --panel2:#24283b; --border:#292e42; --border-strong:#3b4261;
27
- --text:#c0caf5; --text-dim:#a9b1d6; --text-faint:#565f89;
27
+ --text:#c0caf5; --text-dim:#a9b1d6; --text-faint:#565f89; --plan:#7aa2f7;
28
28
  --green:#9ece6a; --green-bg:#1c2b23;
29
29
  --red:#f7768e; --red-bg:#2b1822;
30
30
  --amber:#e0af68; --amber-bg:#2b2416;
@@ -66,7 +66,7 @@
66
66
  @media (prefers-color-scheme: light){
67
67
  :root:not([data-theme="dark"]){
68
68
  --bg:#e1e2e7; --panel:#d0d5e3; --panel2:#e9e9ed; --border:#c4c8da; --border-strong:#a8b0cc;
69
- --text:#3760bf; --text-dim:#58679f; --text-faint:#848cb5;
69
+ --text:#3760bf; --text-dim:#58679f; --text-faint:#848cb5; --plan:#2668c2;
70
70
  --green:#567238; --green-bg:#dfe7d4;
71
71
  --red:#c92353; --red-bg:#fbe0e8;
72
72
  --amber:#82643a; --amber-bg:#f0e6d3;
@@ -81,7 +81,7 @@
81
81
  }
82
82
  :root[data-theme="light"]{
83
83
  --bg:#e1e2e7; --panel:#d0d5e3; --panel2:#e9e9ed; --border:#c4c8da; --border-strong:#a8b0cc;
84
- --text:#3760bf; --text-dim:#58679f; --text-faint:#848cb5;
84
+ --text:#3760bf; --text-dim:#58679f; --text-faint:#848cb5; --plan:#2668c2;
85
85
  --green:#567238; --green-bg:#dfe7d4;
86
86
  --red:#c92353; --red-bg:#fbe0e8;
87
87
  --amber:#82643a; --amber-bg:#f0e6d3;
@@ -289,13 +289,24 @@
289
289
  .sum-val{color:var(--text);}
290
290
  .summary-box .num{color:var(--accent);font-weight:700;}
291
291
 
292
- /* hamr review #3: "map cards taking page full width, should be smaller" —
293
- the SVG's own natural width is centered in the box rather than the box
294
- stretching each node to fill the pane (computeMapLayout below is also
295
- capped to stop a node from stretching past a modest ceiling). */
296
- .map-box{border:1px solid var(--border-strong);padding:10px;overflow-x:auto;margin-top:16px;margin-bottom:14px;background:var(--panel2);text-align:center;}
292
+ /* borrowed-from: bareloop src/panel/index.html@9edb3e1 (on d25e52a) — boxes as wide as their own text, side by side,
293
+ wrapping; a name is never cut. A box + its trailing arrow are ONE unit (the arrow never wraps alone); the lead arrow
294
+ of a wrapped line hangs in the container's left padding (absolute, zero layout impact — toggling it moves nothing). */
295
+ .map-box{border:1px solid var(--border-strong);padding:10px;margin-top:16px;margin-bottom:14px;background:var(--panel2);}
297
296
  .map-box::before{content:"┤ MAP ├";display:block;font-size:11px;color:var(--text-faint);letter-spacing:0.08em;margin:-2px 0 8px 0;}
298
- .map-box svg{display:block;max-width:100%;height:auto;margin:0 auto;}
297
+ .map-chips{display:flex;flex-wrap:wrap;gap:8px 4px;align-items:flex-start;padding-left:1.4em;}
298
+ .map-item{position:relative;display:inline-flex;align-items:center;gap:4px;max-width:100%;}
299
+ .map-arrow{color:var(--text-dim);font-size:13px;flex:none;}
300
+ .map-lead{display:none;position:absolute;left:-1.3em;top:50%;transform:translateY(-50%);color:var(--text-dim);font-size:13px;}
301
+ .map-item.line-start .map-lead{display:block;}
302
+ .map-chip{display:flex;flex-direction:column;align-items:flex-start;width:auto;max-width:100%;min-width:0;box-sizing:border-box;font:inherit;font-size:12px;line-height:1.4;text-align:left;padding:4px 8px;border:2px solid var(--border-strong);border-radius:0;background:var(--panel2);color:var(--text);white-space:normal;overflow-wrap:anywhere;cursor:pointer;}
303
+ .map-chip .chip-state{font-size:10px;color:var(--text-faint);}
304
+ .map-chip.s-done{border-color:var(--green);} .map-chip.s-done .chip-state{color:#2e7d32;}
305
+ .map-chip.s-stopped{border-color:var(--red);} .map-chip.s-stopped .chip-state{color:var(--red);}
306
+ .map-chip.s-waiting{border-color:var(--amber);} .map-chip.s-waiting .chip-state{color:#b8860b;}
307
+ .map-chip.s-user-stopped{border-color:var(--grey-dot);} .map-chip.s-user-stopped .chip-state{color:var(--grey-dot);}
308
+ .map-chip .chip-retry{font-size:10px;color:var(--text-faint);}
309
+ .map-chip.retry{border-style:dashed;} /* borrowed-from: bareloop src/panel/index.html@9edb3e1 */
299
310
 
300
311
  .step-card{position:relative;border:1px solid var(--border);padding:10px;margin-bottom:8px;background:var(--panel2);}
301
312
  .step-card.running{border:1px double var(--amber);}
@@ -428,6 +439,20 @@
428
439
  .ro-value{padding:6px 8px;min-height:32px;box-sizing:border-box;border:1px solid var(--border);background:var(--bg);color:var(--text-dim);}
429
440
  .art-head{color:var(--accent);}
430
441
  .ro-value.sub{margin-left:20px;min-height:0;padding-top:2px;padding-bottom:2px;border-top-width:0;overflow-wrap:anywhere;}
442
+ /* M4e amendment 37 (changes 34's layout): the Job tab is ONE column at every width. Each signed line, its ~ rows, then its step(s) folded under it:
443
+ a native <details> whose <summary> is one short line in the text colour with a › / ⌄ marker in the plan colour; open, it shows reads / makes / may do / check. */
444
+ .job-line{margin-bottom:6px;}
445
+ .plan-fold{margin:0 0 0 20px;min-width:0;overflow-wrap:anywhere;}
446
+ .plan-sum{color:var(--text);cursor:pointer;list-style:none;padding:3px 0;font-size:12px;}
447
+ .plan-sum::-webkit-details-marker{display:none;}
448
+ .plan-sum::before{content:"› ";color:var(--plan);font-weight:700;}
449
+ .plan-fold[open] > .plan-sum::before{content:"⌄ ";}
450
+ .plan-legend{color:var(--text-dim);font-size:12px;margin-top:12px;overflow-wrap:anywhere;}
451
+ .plan-legend .plan-mark{color:var(--plan);font-weight:700;}
452
+ .plan-fold .plan-head,.plan-fold .plan-row{color:var(--text-dim);}
453
+ .plan-fold .plan-head{font-weight:400;}
454
+ .plan-fold .plan-row{padding-left:12px;}
455
+ #details-plan-tail{margin-bottom:16px;}
431
456
  .ro-value.scroll{max-height:160px;overflow-y:auto;white-space:pre-wrap;word-break:break-word;}
432
457
  .field-row{display:flex;flex-wrap:wrap;gap:10px;}
433
458
  .field-row .field{flex:1 1 140px;margin-bottom:10px;}
@@ -484,19 +509,17 @@
484
509
  .chat-thread:empty{display:none;}
485
510
  .msg{padding:8px 10px;border:1px solid var(--border);max-width:100%;background:var(--panel2);font-size:13px;word-break:break-word;white-space:pre-wrap;}
486
511
  .msg.bot{border-left:3px solid var(--border-strong);}
512
+ /* M4e amendments 24/25: the question the plan raised (one at a time), then Your answers / Checked / Not checked beside the plan */
513
+ .chat-question{border:1px solid var(--border);border-left:3px solid var(--amber);background:var(--panel2);padding:8px 10px;margin-bottom:10px;max-width:100%;box-sizing:border-box;}
514
+ .chat-question .q-head{font-size:11px;color:var(--text-faint);}
515
+ .chat-question .q-line{font-size:12px;color:var(--text-faint);margin-top:4px;overflow-wrap:anywhere;}
516
+ .chat-question .q-text{font-size:13px;margin-top:4px;overflow-wrap:anywhere;white-space:pre-wrap;}
517
+ .chat-question textarea{display:block;width:100%;max-width:100%;box-sizing:border-box;margin-top:8px;min-height:3.4em;font:inherit;padding:6px 8px;border:1px solid var(--border-strong);border-radius:0;background:var(--bg);color:var(--text);resize:vertical;}
518
+ .chat-question .q-err{color:var(--red);}
519
+ .chat-extras{display:flex;flex-direction:column;gap:10px;margin-bottom:10px;}
520
+ .chat-extras:empty{display:none;}
487
521
  .msg.bot .who::before{content:"$ ";}
488
522
  .msg .who{font-size:11px;color:var(--text-faint);margin-bottom:3px;text-transform:none;font-weight:400;}
489
- /* borrowed-from: bareloop src/panel/index.html@c1d87ce (the "you" bubble: indented, accent left border) */
490
- .msg.you{background:var(--bg);margin-left:20px;border-left:3px solid var(--accent);}
491
- .msg.you .who::before{content:"> ";}
492
- .chat-input-row{margin-top:10px;border-top:1px dotted var(--border-strong);padding-top:10px;}
493
- .chat-input-row input{width:100%;box-sizing:border-box;}
494
- /* borrowed-from: bareloop src/panel/index.html@d151ec7 (the ask box: a wrapping textarea, 2x height, thick border, dimmed while it cannot be used).
495
- M4e amendment 3 item 3: it opens only on a green plan ("Ask for a change to the plan"); `hidden` closes it. */
496
- .chat-input-row[hidden]{display:none;}
497
- textarea[data-testid="chat-msg"]{width:100%;box-sizing:border-box;font:inherit;color:var(--text);resize:vertical;overflow-y:auto;max-height:200px;}
498
- #chat-msg{min-height:64px;padding:8px 12px;border:2px solid var(--field-border);background:var(--field-bg);}
499
- #chat-msg:read-only{background:var(--bg);opacity:.55;cursor:not-allowed;}
500
523
  /* the card's free-text boxes wrap (textarea): grow a few rows (fitBox), then scroll inside */
501
524
  .job-card textarea.jf-wrap{width:100%;box-sizing:border-box;font:inherit;padding:6px 8px;border:1px solid var(--border-strong);border-radius:0;background:var(--bg);color:var(--text);resize:vertical;overflow-y:auto;max-height:200px;}
502
525
  /* the focused/selected Chat-card field gets a blue border (the accent), no outline ring */
@@ -511,9 +534,9 @@
511
534
  .jf-mirror{position:absolute;left:0;top:0;visibility:hidden;pointer-events:none;white-space:pre-wrap;overflow-wrap:break-word;word-wrap:break-word;box-sizing:content-box;padding:0;border:0;margin:0;}
512
535
  .jf-mirror div{margin:0;padding:0;}
513
536
  /* editable Chat-card fields get the standard soft white (a step below the ask box); disabled/readonly keep the base colour */
514
- #panel-chat input:not(:disabled):not([readonly]):not(#chat-msg):not([type="radio"]):not([type="checkbox"]),
537
+ #panel-chat input:not(:disabled):not([readonly]):not([type="radio"]):not([type="checkbox"]),
515
538
  #panel-chat select:not(:disabled),
516
- #panel-chat textarea:not(:disabled):not([readonly]):not(#chat-msg){background:var(--field-soft-bg);}
539
+ #panel-chat textarea:not(:disabled):not([readonly]){background:var(--field-soft-bg);}
517
540
  /* ONE wide button below the message box; its wording comes from mainButtonFor */
518
541
  .btn.wide{width:100%;margin-top:10px;white-space:normal;}
519
542
  /* amendment 2 item 7: the main button's label ("Sign <hash8> & run · $<cap>") stays on ONE line inside the card */
@@ -885,21 +908,31 @@
885
908
  <!-- ONE progress list: every step is one line that updates in place; a waiting step has no check -->
886
909
  <ol class="chat-steps" id="chat-progress-row" data-testid="chat-steps" aria-live="polite" hidden></ol>
887
910
 
888
- <!-- M4e amendment 6 item 3: bubbles (oldest first), then the current plan, then the note box and the main button: the plan sits next to Sign & run -->
911
+ <!-- M4e amendment 14: the plan, then the main button (no bubbles, no note box): the plan sits next to Sign & run -->
889
912
  <div class="chat-thread" id="chat-thread" data-testid="chat-thread"></div>
890
913
 
914
+ <!-- M4e amendments 24/25: a question the plan raised, one at a time. No Skip. Static markup: the poll only rewrites the texts when the question changes, never the answer box -->
915
+ <div class="chat-question" id="chat-question" data-testid="chat-question" hidden>
916
+ <div class="q-head" id="chat-q-head" data-testid="chat-q-head"></div>
917
+ <div class="q-line" id="chat-q-line" data-testid="chat-q-line"></div>
918
+ <div class="q-text" id="chat-q-text" data-testid="chat-q-text"></div>
919
+ <textarea id="chat-q-answer" data-testid="chat-q-answer" rows="2" autocomplete="off" spellcheck="false" aria-label="Your answer" placeholder="Your answer, on one line"></textarea>
920
+ <div class="hint q-err" id="chat-q-error" data-testid="chat-q-error" role="alert"></div>
921
+ <button class="btn primary wide" type="button" id="chat-q-send" data-testid="chat-q-send">Send</button>
922
+ </div>
923
+
924
+ <!-- M4e amendments 24/25: beside a green plan, Your answers (if it was drafted with any), Checked (built by code from the typed checks) and Not checked (the drafter's own reading) -->
925
+ <div class="chat-extras" id="chat-extras" data-testid="chat-extras"></div>
926
+
891
927
  <!-- a refused draft / run / sign / abandon POST (or a refused start) shows here and STAYS: set only by this tab's own
892
928
  action handlers, never cleared by the poll (the poll owns #chat-card-error instead) -->
893
929
  <div class="hint" id="chat-action-error" data-testid="chat-action-error"></div>
894
930
 
895
- <!-- M4e amendment 3 item 3: opens when a green plan shows (bareloop's ask box); a typed note turns the main button into Send -->
896
- <div class="chat-input-row" id="chat-msg-row" data-testid="chat-msg-row" hidden>
897
- <label for="chat-msg" style="display:none">Message</label>
898
- <textarea id="chat-msg" rows="2" placeholder="Ask for a change to the plan" autocomplete="off" data-testid="chat-msg"></textarea>
899
- </div>
900
931
  <button class="btn primary wide" type="button" id="chat-main-btn" data-testid="chat-main" disabled>Draft</button>
901
932
  <div class="hint" id="chat-main-hint" data-testid="chat-main-hint"></div>
902
- <!-- M4e amendment 4 item 3: after the second change the ask box is closed; Start over drafts again from the card as it is (a fresh draft) -->
933
+ <!-- M4e amendment 14 item 2: on a green plan, Revise opens every card field (the main button then reads Draft) -->
934
+ <button class="btn wide" type="button" id="chat-revise-btn" data-testid="chat-revise" hidden>Revise</button>
935
+ <!-- M4e amendment 14 item 3: after the second revise, on a green plan: Start over drafts the card as it is, a fresh draft with 2 new revises -->
903
936
  <button class="btn wide" type="button" id="chat-startover-btn" data-testid="chat-startover" hidden>Start over</button>
904
937
  <div class="hint">Only your click signs.</div>
905
938
  </section>
@@ -1009,7 +1042,7 @@
1009
1042
  piece within a field — replaces the old split asks/sends/
1010
1043
  sources/signed-lines blocks. Field order (signed): Job
1011
1044
  (prose) · Ask · Model · $ cap (+ redo cap) · Source ·
1012
- Destination · Success · Signed (M4e amendment 6: each guardrail sits under its own line in Job). At 390px every
1045
+ Destination · Signed (am34: Success is gone; the plan block holds each step check) (M4e amendment 6: each guardrail sits under its own line in Job). At 390px every
1013
1046
  field's own `label` already sits above its value (the
1014
1047
  existing global `label{display:block}` rule — no separate
1015
1048
  narrow-width override needed). -->
@@ -1017,13 +1050,18 @@
1017
1050
  <div class="job-card" id="job-card" hidden data-testid="job-card-readonly">
1018
1051
  <h4 id="details-title">Job card — signed</h4>
1019
1052
  <div class="field"><label>Model</label><div class="ro-value" id="details-model">—</div></div>
1020
- <div class="field"><label>$ cap</label><div class="ro-value" id="details-cap">—</div></div>
1021
- <div class="field"><label>Job (prose)</label><div id="details-prose"></div></div>
1022
- <div class="field"><label>Ask</label><div id="details-asks"></div></div>
1023
- <div class="field"><label>Source</label><div id="details-sources"></div></div>
1024
- <div class="field"><label>Destination</label><div id="details-sends"></div></div>
1025
- <div class="field"><label>Success</label><div id="details-success"></div></div>
1026
- <div class="field"><label>Signed</label><div class="ro-value" id="details-signature">—</div></div>
1053
+ <!-- M4e amendment 37: ONE column. #details-prose holds one wrapper per signed line (the line, its ~ rows, its steps folded under it);
1054
+ #details-plan-tail holds any step from no listed line, then the folded "not checked" line; then Ask, Destination, $ cap, Source, Signed. -->
1055
+ <div id="job-grid" data-testid="job-grid">
1056
+ <div id="details-prose"></div>
1057
+ <div id="details-plan-tail"></div>
1058
+ <div class="field"><label>Ask</label><div id="details-asks"></div></div>
1059
+ <div class="field"><label>Destination</label><div id="details-sends"></div></div>
1060
+ <div class="field"><label>$ cap</label><div class="ro-value" id="details-cap">—</div></div>
1061
+ <div class="field"><label>Source</label><div id="details-sources"></div></div>
1062
+ <div class="field"><label>Signed</label><div class="ro-value" id="details-signature">—</div></div>
1063
+ <div class="plan-legend" data-testid="plan-legend"><span class="plan-mark">›</span> = the approved plan</div>
1064
+ </div>
1027
1065
  </div>
1028
1066
  </section>
1029
1067
 
@@ -1086,7 +1124,14 @@
1086
1124
  // Origin). Same-origin. ----
1087
1125
  function getJSON(path){
1088
1126
  return fetch(path, { method: "GET", headers: { accept: "application/json" } }).then(function(r){
1089
- if(!r.ok){ var err = new Error(path + ": HTTP " + r.status); err.status = r.status; throw err; }
1127
+ if(!r.ok){
1128
+ // the refusal's own name rides on the error (C1): the one load-failure sentence tells "outside the folder" from the other 403
1129
+ return r.json().then(function(b){ return b; }, function(){ return null; }).then(function(b){
1130
+ var err = new Error(path + ": HTTP " + r.status); err.status = r.status;
1131
+ if(b && typeof b.refused === "string") err.refused = b.refused;
1132
+ throw err;
1133
+ });
1134
+ }
1090
1135
  return r.json();
1091
1136
  });
1092
1137
  }
@@ -1094,6 +1139,7 @@
1094
1139
  // message (it carries the path and the HTTP code), never a status number.
1095
1140
  function loadFailureText(e){
1096
1141
  var status = e && e.status;
1142
+ if(status === 403 && e.refused === "flow-outside-root") return "This flow is outside the panel's folder.";
1097
1143
  if(status === 403) return "The panel does not recognise this page. Reload it.";
1098
1144
  if(status === 404) return "This run is no longer there.";
1099
1145
  return "Could not load this; reload the page.";
@@ -1400,23 +1446,9 @@
1400
1446
  }
1401
1447
 
1402
1448
  // ---- step map renderer (box-drawing geometry kept from the borrowed
1403
- // page's buildStepMapSVG; the DATA it draws is fwdloop's own: one box per
1449
+ // page's step-map builder; the DATA it draws is fwdloop's own: one box per
1404
1450
  // `declaration.steps` entry, no scout/plan/judge/fix-loop/rounds — ruling
1405
1451
  // A, "no per-round parts"). ----
1406
- function stepMapColors(state){
1407
- if(state === "done") return {stroke:"var(--green)", textFill:"#2e7d32"};
1408
- if(state === "stopped") return {stroke:"var(--red)", textFill:"var(--red)"};
1409
- if(state === "waiting") return {stroke:"var(--amber)", textFill:"#b8860b"};
1410
- if(state === "user-stopped") return {stroke:"var(--grey-dot)", textFill:"var(--grey-dot)"}; // a Stop the human asked: grey, never red
1411
- return {stroke:"var(--border-strong)", textFill:"var(--text-faint)"}; // not started yet
1412
- }
1413
- var stepMapUidCounter = 0;
1414
- var MAP_MARGIN = 10, MAP_GAP = 28;
1415
- var CHAR_W = 7.2;
1416
- var TITLE_HPAD = 16;
1417
- var MIN_BOX_W = 100;
1418
- var BOX_H = 60, BOX_H_2LINE = 78;
1419
- var ROW_GAP = 70;
1420
1452
  // hamr review #2: "map cards missing try 2 if multiple attempts/iteration"
1421
1453
  // — a plain "try N" count whenever a step has been attempted more than
1422
1454
  // once, plus a mark when the LATEST attempt followed a human redo (the
@@ -1439,13 +1471,11 @@
1439
1471
  // failed · attempt 2 passed · …") is a map node's single biggest source of
1440
1472
  // width — that level of detail belongs in the Audit tab, never on the
1441
1473
  // node. A node's title is just
1442
- // step number + name + try N + state, kept short so naturalBoxWidth stays
1474
+ // step number + name + state, kept short so naturalBoxWidth stays
1443
1475
  // small and the map stays compact instead of stretching to the pane width.
1444
1476
  function stepTitleText(idx, s){
1445
1477
  if(s.draft) return "drafting";
1446
1478
  var base = (s.n || idx + 1) + ' ' + s.emits;
1447
- var tryText = tryCountText(s.tryCount, s.attempts);
1448
- if(tryText) base += ' — ' + tryText;
1449
1479
  return base;
1450
1480
  }
1451
1481
  // The declared step's own run-state (map box, card, "which step stopped and why") is the server's `groupState` (src/panel/data.js
@@ -1482,151 +1512,36 @@
1482
1512
  };
1483
1513
  });
1484
1514
  }
1485
- function naturalBoxWidth(steps){
1486
- var maxChars = 0;
1487
- steps.forEach(function(s, idx){ maxChars = Math.max(maxChars, stepTitleText(idx, s).length); });
1488
- return Math.max(MIN_BOX_W, Math.ceil(maxChars * CHAR_W) + TITLE_HPAD);
1489
- }
1490
- // hamr review #3: nodes stay compact — a box never stretches past a modest
1491
- // ceiling over its own natural (text-fit) width, even when the available
1492
- // pane is much wider (the bug: every node used to grow to fill the row).
1493
- var MAX_BOX_STRETCH = 1.25;
1494
- function computeMapLayout(n, availW, naturalW){
1495
- if(!availW) return {perRow:n, boxW:naturalW};
1496
- var usableW = availW - MAP_MARGIN * 2;
1497
- var ceiling = naturalW * MAX_BOX_STRETCH;
1498
- for(var perRow = n; perRow >= 2; perRow--){
1499
- var totalW = perRow * naturalW + (perRow - 1) * MAP_GAP;
1500
- if(totalW <= usableW){
1501
- var stretched = (usableW - (perRow - 1) * MAP_GAP) / perRow;
1502
- return {perRow:perRow, boxW:Math.max(naturalW, Math.min(stretched, ceiling))};
1503
- }
1515
+ // borrowed-from: bareloop src/panel/index.html@9edb3e1 (on d25e52a). The map is plain HTML + CSS (.map-chips / .map-item /
1516
+ // .map-chip): the browser wraps it, so no width arithmetic and no sideways scroll. Each box keeps its two lines — the name
1517
+ // (stepTitleText) then the status word (stateWord); a retried box (am35) is dashed and its status line starts with "↻N".
1518
+ function buildStepMapHTML(steps){
1519
+ var last = steps.length - 1;
1520
+ var body = steps.map(function(s, idx){
1521
+ var tries = boxRetryTry(s);
1522
+ var cls = "map-chip s-" + String(s.state).replace(/[^a-z-]/g, "") + (tries ? " retry" : "");
1523
+ var name = escapeXml(stepTitleText(idx, s));
1524
+ var state = escapeXml(s.noRecord ? "no draft record" : stateWord(s.state));
1525
+ // hamr review #4: each box is a clickable button tagged with the step's own `emits` id — the click listener that
1526
+ // jumps to the Audit tab's matching group is wired AFTER insertion (wireMapClicks), never inline here.
1527
+ var chip = '<button type="button" class="' + cls + ' map-step" data-emits="' + escapeXml(s.emits) + '"' + (tries ? ' data-retry="' + tries + '"' : '') +
1528
+ ' title="' + name + '" aria-label="open ' + escapeXml(s.emits) + ' in Audit">' +
1529
+ '<span class="chip-name">' + name + '</span><span class="chip-state">' +
1530
+ (tries ? '<span class="chip-retry">\u21bb' + tries + '</span> ' : '') + state + '</span></button>';
1531
+ return '<span class="map-item" role="listitem">' +
1532
+ (idx > 0 ? '<span class="map-lead" aria-hidden="true">\u2192</span>' : '') +
1533
+ chip + (idx < last ? '<span class="map-arrow" aria-hidden="true">\u2192</span>' : '') + '</span>';
1534
+ }).join("");
1535
+ return '<div class="map-chips" role="list" aria-label="step map">' + body + '</div>';
1536
+ }
1537
+ // The first box of each WRAPPED line shows a leading arrow. CSS cannot know which box starts a line, so after render/resize
1538
+ // this compares each item's offsetTop with the previous item's (same line = same top). Takes anything with offsetTop +
1539
+ // classList (real elements, or stubs in tests). The lead arrow is absolute, so toggling never reflows a box — no loop.
1540
+ function markLineStarts(items){
1541
+ for(var i = 0; i < items.length; i++){
1542
+ var starts = i > 0 && items[i].offsetTop > items[i - 1].offsetTop;
1543
+ if(starts) items[i].classList.add("line-start"); else items[i].classList.remove("line-start");
1504
1544
  }
1505
- return {perRow:1, boxW:Math.max(MIN_BOX_W, Math.min(usableW, ceiling))};
1506
- }
1507
- // M4c-fix amendment 2 (l): a line longer than the box is cut with … (the whole name stays in the node's <title>
1508
- // and on its step card below the map).
1509
- function mapLabel(line, maxChars){
1510
- return line.length <= maxChars ? line : line.slice(0, Math.max(1, maxChars - 1)) + "\u2026";
1511
- }
1512
- function wrapTitleLines(text, maxWidth){
1513
- var maxChars = Math.max(1, Math.floor((maxWidth - TITLE_HPAD) / CHAR_W));
1514
- return wrapTitleLinesRaw(text, maxChars).map(function(l){ return mapLabel(l, maxChars); });
1515
- }
1516
- function wrapTitleLinesRaw(text, maxChars){
1517
- if(text.length <= maxChars) return [text];
1518
- var words = text.split(' ');
1519
- var line1 = '', i = 0;
1520
- for(; i < words.length; i++){
1521
- var cand = line1 ? line1 + ' ' + words[i] : words[i];
1522
- if(line1 && cand.length > maxChars) break;
1523
- line1 = cand;
1524
- }
1525
- if(!line1) return [text.slice(0, maxChars), text.slice(maxChars)];
1526
- var line2 = words.slice(i).join(' ');
1527
- return line2 ? [line1, line2] : [line1];
1528
- }
1529
- function buildStepMapSVG(steps, availWidth){
1530
- var n = steps.length;
1531
- var naturalW = naturalBoxWidth(steps);
1532
- var layout = computeMapLayout(n, availWidth, naturalW);
1533
- var perRow = layout.perRow, boxW = layout.boxW, gap = MAP_GAP;
1534
- var rows = Math.ceil(n / perRow);
1535
- var margin = MAP_MARGIN;
1536
- var titleLines = steps.map(function(s, idx){ return wrapTitleLines(stepTitleText(idx, s), boxW); });
1537
- var maxLines = titleLines.reduce(function(m, l){ return Math.max(m, l.length); }, 1);
1538
- var boxH = maxLines > 1 ? BOX_H_2LINE : BOX_H;
1539
- var rowH = boxH + ROW_GAP;
1540
- var totalW = margin * 2 + perRow * boxW + (perRow - 1) * gap;
1541
- var totalH = rows * rowH;
1542
- var uid = "sm" + (stepMapUidCounter++);
1543
- var body =
1544
- '<defs>' +
1545
- '<marker id="' + uid + '-arrow" markerWidth="8" markerHeight="8" refX="6" refY="3" orient="auto">' +
1546
- '<path d="M0,0 L6,3 L0,6 z" fill="var(--text-dim)"></path></marker>' +
1547
- '<marker id="' + uid + '-arrow-grey" markerWidth="8" markerHeight="8" refX="6" refY="3" orient="auto">' +
1548
- '<path d="M0,0 L6,3 L0,6 z" fill="var(--text-faint)"></path></marker>' +
1549
- '</defs>';
1550
- steps.forEach(function(s, idx){
1551
- var row = Math.floor(idx / perRow);
1552
- var col = idx % perRow;
1553
- var rtl = (row % 2) === 1;
1554
- var slotCol = rtl ? (perRow - 1 - col) : col;
1555
- var x = margin + slotCol * (boxW + gap);
1556
- var y = 30 + row * rowH;
1557
- var colors = stepMapColors(s.state);
1558
- var lines = titleLines[idx];
1559
- var nextRowIdx = idx < n - 1 ? Math.floor((idx + 1) / perRow) : null;
1560
- var hasDrop = nextRowIdx !== null && nextRowIdx !== row;
1561
- var stateY = y + boxH - 18;
1562
- // hamr review #4: each node is a clickable group ("map-step", tagged
1563
- // with the step's own `emits` id) — the click listener that turns this
1564
- // into a jump to the Audit tab's matching group is wired AFTER
1565
- // insertion (renderStepMap, below), never inline here (this function
1566
- // only ever builds a markup string).
1567
- body += '<g class="map-step" data-emits="' + escapeXml(s.emits) + '" tabindex="0" role="button" aria-label="open ' + escapeXml(s.emits) + ' in Audit"><title>' + escapeXml(stepTitleText(idx, s)) + '</title>';
1568
- body += '<rect x="' + x + '" y="' + y + '" width="' + boxW + '" height="' + boxH +
1569
- '" rx="0" fill="var(--panel2)" stroke="' + colors.stroke + '" stroke-width="2"></rect>';
1570
- if(lines.length === 1){
1571
- body += '<text x="' + (x + boxW / 2) + '" y="' + (y + 25) +
1572
- '" text-anchor="middle" font-size="12" fill="var(--text)">' + escapeXml(lines[0]) + '</text>';
1573
- } else {
1574
- body += '<text x="' + (x + boxW / 2) + '" y="' + (y + 17) +
1575
- '" text-anchor="middle" font-size="12" fill="var(--text)">' + escapeXml(lines[0]) + '</text>';
1576
- body += '<text x="' + (x + boxW / 2) + '" y="' + (y + 29) +
1577
- '" text-anchor="middle" font-size="12" fill="var(--text)">' + escapeXml(lines[1]) + '</text>';
1578
- }
1579
- body += '<text x="' + (x + boxW / 2) + '" y="' + stateY +
1580
- '" text-anchor="middle" font-size="10" fill="' + colors.textFill + '">' + escapeXml(s.noRecord ? "no draft record" : stateWord(s.state)) + '</text>';
1581
- body += '</g>';
1582
- // hamr's 2026-09-27 retry-loop review: a step whose server-computed
1583
- // tryCount is >1 gets a dashed grey self-loop under its box, labelled
1584
- // "try N" — ported from bareloop commit 16825a7's own curve (same
1585
- // control-point proportions, scaled to THIS box's own width). When the
1586
- // same box also carries the row-to-row snake drop below (which leaves
1587
- // from dead-center, x=cx), the loop's start is shifted off-center by a
1588
- // fixed pixel offset so the two paths never begin at the same point.
1589
- var retryTry = boxRetryTry(s);
1590
- if(retryTry){
1591
- var retryShift = hasDrop ? 14 : 0;
1592
- var bottom = y + boxH;
1593
- var sx = x + boxW * 0.50 - retryShift, sy = bottom + 5;
1594
- var c1x = x + boxW * 0.278 - retryShift, c1y = bottom + 30;
1595
- var c2x = x + boxW * 0.167 - retryShift, c2y = bottom + 30;
1596
- var ex = x + boxW * 0.028 - retryShift, ey = bottom + 2;
1597
- body += '<path d="M ' + sx + ' ' + sy + ' C ' + c1x + ' ' + c1y + ', ' + c2x + ' ' + c2y + ', ' + ex + ' ' + ey +
1598
- '" fill="none" stroke="var(--text-faint)" stroke-width="1.5" stroke-dasharray="3,3" marker-end="url(#' + uid + '-arrow-grey)"></path>';
1599
- body += '<text x="' + (x + boxW * 0.267 - retryShift) + '" y="' + (bottom + 32) +
1600
- '" text-anchor="middle" font-size="10" fill="var(--text-faint)">try ' + retryTry + '</text>';
1601
- }
1602
- if(idx < n - 1){
1603
- if(nextRowIdx === row){
1604
- var midY = y + boxH / 2;
1605
- if(!rtl){
1606
- var nx = x + boxW + gap;
1607
- body += '<line x1="' + (x + boxW) + '" y1="' + midY + '" x2="' + (nx - 2) + '" y2="' + midY +
1608
- '" stroke="var(--text-dim)" stroke-width="2" marker-end="url(#' + uid + '-arrow)"></line>';
1609
- } else {
1610
- var px = x - gap - boxW;
1611
- body += '<line x1="' + x + '" y1="' + midY + '" x2="' + (px + boxW + 2) + '" y2="' + midY +
1612
- '" stroke="var(--text-dim)" stroke-width="2" marker-end="url(#' + uid + '-arrow)"></line>';
1613
- }
1614
- } else {
1615
- var cx = x + boxW / 2;
1616
- body += '<line x1="' + cx + '" y1="' + (y + boxH) + '" x2="' + cx + '" y2="' + (y + rowH - 2) +
1617
- '" stroke="var(--text-dim)" stroke-width="2" marker-end="url(#' + uid + '-arrow)"></line>';
1618
- }
1619
- }
1620
- });
1621
- return '<svg width="' + totalW + '" height="' + totalH + '" viewBox="0 0 ' + totalW + ' ' + totalH + '" role="img" aria-label="step map">' + body + '</svg>';
1622
- }
1623
- var lastSteps = null;
1624
- var lastWidth = null;
1625
- function mapAvailWidth(wrapper){
1626
- if(!wrapper) return null;
1627
- var w = wrapper.getBoundingClientRect().width;
1628
- if(!w) return null;
1629
- return Math.max(0, w - 20);
1630
1545
  }
1631
1546
  // hamr review #4: "clicking on cards below codegraph maps should take you
1632
1547
  // to audit trail" — a map node's click (or Enter/Space, since the node
@@ -1644,34 +1559,32 @@
1644
1559
  function renderStepMap(steps){
1645
1560
  var mount = document.getElementById("map-mount");
1646
1561
  var wrapper = document.getElementById("map-box");
1647
- lastSteps = steps;
1648
1562
  if(!steps || !steps.length){
1649
1563
  mount.innerHTML = "";
1650
1564
  wrapper.hidden = true;
1651
1565
  return;
1652
1566
  }
1653
1567
  wrapper.hidden = false;
1654
- var w = mapAvailWidth(wrapper);
1655
- lastWidth = w;
1656
- mount.innerHTML = buildStepMapSVG(steps, w);
1568
+ mount.innerHTML = buildStepMapHTML(steps);
1657
1569
  wireMapClicks(mount);
1570
+ reflowMap();
1658
1571
  }
1659
1572
  function reflowMap(){
1660
- var wrapper = document.getElementById("map-box");
1661
- if(!wrapper || wrapper.hidden || !lastSteps) return;
1662
- var w = mapAvailWidth(wrapper);
1663
- if(w === null || w === lastWidth) return;
1664
- lastWidth = w;
1665
- var mount = document.getElementById("map-mount");
1666
- mount.innerHTML = buildStepMapSVG(lastSteps, w);
1667
- wireMapClicks(mount);
1573
+ var box = document.getElementById("map-box");
1574
+ if(!box || box.hidden) return;
1575
+ markLineStarts(Array.prototype.slice.call(box.querySelectorAll(".map-item")));
1576
+ }
1577
+ var reflowTimer = null;
1578
+ function reflowMapSoon(){
1579
+ if(reflowTimer) clearTimeout(reflowTimer);
1580
+ reflowTimer = setTimeout(function(){ reflowTimer = null; reflowMap(); }, 60);
1668
1581
  }
1669
1582
  if(typeof ResizeObserver !== "undefined"){
1670
- var ro = new ResizeObserver(function(){ reflowMap(); });
1671
- var mb = document.getElementById("map-box");
1672
- if(mb) ro.observe(mb);
1583
+ var mapRo = new ResizeObserver(reflowMapSoon);
1584
+ var mapBoxEl = document.getElementById("map-box");
1585
+ if(mapBoxEl) mapRo.observe(mapBoxEl);
1673
1586
  } else {
1674
- window.addEventListener("resize", reflowMap);
1587
+ window.addEventListener("resize", reflowMapSoon);
1675
1588
  }
1676
1589
 
1677
1590
  // ---- Runs tab: ONE run-row builder shared by History (flat) and the
@@ -2815,8 +2728,7 @@
2815
2728
  return [h ? h + "h" : "", m ? m + "m" : "", sec ? sec + "s" : ""].filter(Boolean).join(" ");
2816
2729
  }
2817
2730
  // hamr's 2026-09-27 exit-check review #5: ONE row-per-piece renderer,
2818
- // shared by every multi-row Job field (prose/asks/sources/sends/
2819
- // guardrails/success) — a real `.ro-value` per item (never a single
2731
+ // shared by the multi-row Job fields (asks/sources/sends) — a real `.ro-value` per item (never a single
2820
2732
  // " · "-joined line, which used to hide a book text value if it happened
2821
2733
  // to contain " · " itself), an explicit "none signed" hint for an empty
2822
2734
  // list, book text always via `.textContent`.
@@ -2831,6 +2743,53 @@
2831
2743
  el.appendChild(textDiv("ro-value", rowTextFn(item)));
2832
2744
  });
2833
2745
  }
2746
+ // M4e amendments 34 + 37: one step of the signed plan, folded under its job line. All of it is read off `job.plan` (src/panel/data.js
2747
+ // `buildJobPlan`: declaration.json and the setup.jsonl sign row); the page words nothing of its own except "nothing" for an empty list.
2748
+ // The summary is one short line: `step 3 · read → summaryResume · machine check` (may do, then what it makes, then the check kind from the
2749
+ // step's TYPED close class: green/softgreen = machine check, anything else = you check). A write/send step on a line with a signed destination
2750
+ // adds `→ <destination>`. The ask step reads `step 4 · ASK · waits 1h`.
2751
+ function stepSummaryText(st, job){
2752
+ var head = "step " + st.step + " · ";
2753
+ if(st.ask) return head + "ASK · waits " + plainWait(st.waitMs);
2754
+ var out = ((st.mayDo || []).length ? st.mayDo.join(", ") + " " : "") + "→ " + (st.makes || "unknown");
2755
+ var sends = (job.sends || []).filter(function(sd){ return sd.line === st.line; });
2756
+ var writes = (st.mayDo || []).some(function(p){ return p === "write" || p === "send"; });
2757
+ if(writes && sends.length) out += " → " + (sends[0].target || "unknown");
2758
+ return head + out + " · " + (st.checkClass === "green" || st.checkClass === "softgreen" ? "machine check" : "you check");
2759
+ }
2760
+ function jobStepFold(st, job){
2761
+ var fold = document.createElement("details");
2762
+ fold.className = "plan-fold";
2763
+ var sum = document.createElement("summary");
2764
+ sum.className = "plan-sum";
2765
+ sum.textContent = stepSummaryText(st, job);
2766
+ fold.appendChild(sum);
2767
+ fold.appendChild(textDiv("plan-head", "step " + st.step + " · from line " + (st.line === null || st.line === undefined ? "none" : st.line)));
2768
+ fold.appendChild(textDiv("plan-row", "reads: " + ((st.reads || []).length ? st.reads.join(", ") : "nothing")));
2769
+ fold.appendChild(textDiv("plan-row", "makes: " + (st.makes || "unknown")));
2770
+ fold.appendChild(textDiv("plan-row", "may do: " + ((st.mayDo || []).length ? st.mayDo.join(", ") : "nothing (pure stop)")));
2771
+ fold.appendChild(textDiv("plan-row", "check: " + (st.ask ? "ASK · waits " + plainWait(st.waitMs) : (st.check || []).join(" "))));
2772
+ return fold;
2773
+ }
2774
+ // The tail: any step that came from no listed line, then the folded "not checked (the AI's own reading)" summary (its label is always shown).
2775
+ // `placed` (step numbers already folded under a line) is filled by renderJob's line loop before this runs.
2776
+ function paintJobPlan(job, placed){
2777
+ var plan = job.plan || {steps: [], notChecked: {recorded: false, items: []}};
2778
+ var tail = document.getElementById("details-plan-tail");
2779
+ tail.innerHTML = "";
2780
+ (plan.steps || []).filter(function(st){ return !placed[st.step]; }).forEach(function(st){ tail.appendChild(jobStepFold(st, job)); });
2781
+ var nc = plan.notChecked || {};
2782
+ var fold = document.createElement("details");
2783
+ fold.className = "plan-fold plan-notchecked";
2784
+ var sum = document.createElement("summary");
2785
+ sum.className = "plan-sum";
2786
+ sum.textContent = "not checked (the AI's own reading)";
2787
+ fold.appendChild(sum);
2788
+ if(!nc.recorded) fold.appendChild(textDiv("plan-row", "not recorded (signed before amendment 34)"));
2789
+ else if(!(nc.items || []).length) fold.appendChild(textDiv("plan-row", "the AI listed nothing"));
2790
+ else nc.items.forEach(function(it){ fold.appendChild(textDiv("plan-row", it)); });
2791
+ tail.appendChild(fold);
2792
+ }
2834
2793
  function renderJob(job){
2835
2794
  var empty = document.getElementById("job-empty");
2836
2795
  var card = document.getElementById("job-card");
@@ -2845,22 +2804,32 @@
2845
2804
  // wait, a send line's destination. (The separate Guardrails field is gone.) `job` already carries the values in force for this run.
2846
2805
  var jobEl = document.getElementById("details-prose");
2847
2806
  jobEl.innerHTML = "";
2807
+ // 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).
2808
+ var placed = {};
2848
2809
  if(!job.prose || !job.prose.length){
2849
2810
  jobEl.appendChild(textDiv("hint", "no signed prose lines"));
2850
2811
  } else {
2851
2812
  job.prose.forEach(function(l){
2852
- jobEl.appendChild(textDiv("ro-value", l.line + ". " + l.text));
2813
+ var cell = document.createElement("div");
2814
+ cell.className = "job-line";
2815
+ cell.appendChild(textDiv("ro-value", l.line + ". " + l.text));
2853
2816
  (job.guardrails || []).filter(function(g){ return g.line === l.line; }).forEach(function(g){
2854
- jobEl.appendChild(textDiv("ro-value sub", "~ " + g.guardrail));
2817
+ cell.appendChild(textDiv("ro-value sub", "~ " + g.guardrail));
2855
2818
  });
2856
2819
  (job.asks || []).filter(function(ak){ return ak.line === l.line; }).forEach(function(ak){
2857
- jobEl.appendChild(textDiv("ro-value sub", "~ waits " + plainWait(ak.waitMs)));
2820
+ cell.appendChild(textDiv("ro-value sub", "~ waits " + plainWait(ak.waitMs)));
2858
2821
  });
2859
2822
  (job.sends || []).filter(function(sd){ return sd.line === l.line; }).forEach(function(sd){
2860
- jobEl.appendChild(textDiv("ro-value sub", "~ writes out to " + (sd.target || "unknown")));
2823
+ cell.appendChild(textDiv("ro-value sub", "~ writes out to " + (sd.target || "unknown")));
2861
2824
  });
2825
+ ((job.plan && job.plan.steps) || []).filter(function(st){ return st.line === l.line; }).forEach(function(st){
2826
+ placed[st.step] = true;
2827
+ cell.appendChild(jobStepFold(st, job));
2828
+ });
2829
+ jobEl.appendChild(cell);
2862
2830
  });
2863
2831
  }
2832
+ paintJobPlan(job, placed);
2864
2833
  // review #5: "Ask" — one row per signed ask line.
2865
2834
  renderRowsField("details-asks", job.asks, "no signed asks", function(ak){
2866
2835
  return "line " + ak.line + " · \"" + ak.question + "\" · waits " + plainWait(ak.waitMs);
@@ -2887,11 +2856,6 @@
2887
2856
  renderRowsField("details-sends", job.sends, "no signed sends", function(s){
2888
2857
  return "line " + s.line + " · " + (s.kind || "unknown") + " → " + (s.target || "unknown");
2889
2858
  });
2890
- // review #5: "Success" — one row per declared step, off data.js's own
2891
- // deriveStepSuccessText (never re-derived client-side).
2892
- renderRowsField("details-success", job.success, "no declared steps", function(s){
2893
- return s.step + " · " + s.text;
2894
- });
2895
2859
  var sig = job.signature;
2896
2860
  // hamr's 2026-09-27 final tweak #2: `sig.signedAt` is the raw signed ISO
2897
2861
  // stamp (e.g. "2026-09-24T13:22:40.950Z") — rendered readable/local via
@@ -3160,7 +3124,7 @@
3160
3124
  if(row.stuck) return row.stuckLine || row.stuckLabel;
3161
3125
  if(row.working) return "working on your " + row.working + "…";
3162
3126
  if(row.open && row.resume) return row.resume.label;
3163
- var bits = [row.status];
3127
+ var bits = [row.statusText || row.status];
3164
3128
  if(row.reason) bits.push("reason: " + row.reason);
3165
3129
  if(row.answeredAt) bits.push("answered " + (readableDateTime(row.answeredAt) || row.answeredAt));
3166
3130
  if(row.why) bits.push(row.why);
@@ -3257,7 +3221,7 @@
3257
3221
  if(ask.waiting) return textDiv("wf-meta", "time left: " + duration(ask.timeLeftMs));
3258
3222
  // an open ask with a saved answer: the header meta line already says the resume label (stuck or starting) — once.
3259
3223
  if(ask.open && ask.resume) return null;
3260
- var bits = [ask.status];
3224
+ var bits = [ask.statusText || ask.status];
3261
3225
  if(ask.reason) bits.push("reason: " + ask.reason);
3262
3226
  if(ask.answeredAt) bits.push("answered " + (readableDateTime(ask.answeredAt) || ask.answeredAt));
3263
3227
  if(ask.why) bits.push(ask.why);
@@ -3668,7 +3632,7 @@
3668
3632
  bits.push(stepBit);
3669
3633
  bits.push("draft " + block.draftNo);
3670
3634
  bits.push(typeof ask.askedAt === "string" ? "asked " + (readableDateTime(ask.askedAt) || ask.askedAt) : "asked: unknown");
3671
- bits.push(ask.waiting ? "waiting on you" : (ask.open && ask.resume ? ask.resume.label : ask.status));
3635
+ bits.push(ask.waiting ? "waiting on you" : (ask.open && ask.resume ? ask.resume.label : (ask.statusText || ask.status)));
3672
3636
  return bits.join(" · ");
3673
3637
  }
3674
3638
  // One block per signed ask line (M4c item 5), drawn from the server's `blocks`.
@@ -3791,7 +3755,7 @@
3791
3755
  // borrowed-from: bareloop src/panel/index.html@ca7195e — `mainButtonFor`, `renderMain`, `renderProgress`, the
3792
3756
  // scroll-on-change block in `renderActions`, `attachSession`/`reattachLive` (without the reuse/auto-sign branch), `syncCardLock`,
3793
3757
  // `CLIENT_TERMINAL_PHASES`, `openNewCard`/`resetCard`/`refreshStartEnabled`, `authorPost`/`authorGet`, `fitBox`. fwdloop differs where its shape does: the draft is a detached CLI child whose state is
3794
- // READ from files (GET /api/author/live and /:id), a start is polled (GET /api/author/start/:id), no token or cookie. Sign is two clicks, no typed name (M4e amendment 2); the ask box is bareloop's "Ask for a change to the plan" (amendment 3 item 3).
3758
+ // READ from files (GET /api/author/live and /:id), a start is polled (GET /api/author/start/:id), no token or cookie. Sign is two clicks, no typed name (M4e amendment 2); Revise reopens the card fields and drafts the card again, no note (amendment 14).
3795
3759
  (function(){
3796
3760
  var card = document.getElementById("chat-job-card");
3797
3761
  var clearBtn = document.getElementById("chat-clear-btn");
@@ -3803,11 +3767,18 @@
3803
3767
  var mainBtn = document.getElementById("chat-main-btn");
3804
3768
  var mainHint = document.getElementById("chat-main-hint");
3805
3769
  var startOverBtn = document.getElementById("chat-startover-btn");
3806
- var msgEl = document.getElementById("chat-msg"); // the ask box: a note asking for a change to the green plan
3807
- var msgRow = document.getElementById("chat-msg-row");
3770
+ var reviseBtn = document.getElementById("chat-revise-btn");
3808
3771
  var errEl = document.getElementById("chat-card-error"); // POLL-OWNED: the draft's own sentence (red / stopped)
3809
3772
  var actionErrEl = document.getElementById("chat-action-error"); // ACTION-OWNED: only a click's refusal; the poll never wipes it
3810
3773
  var progressRow = document.getElementById("chat-progress-row");
3774
+ var questionBox = document.getElementById("chat-question");
3775
+ var qHead = document.getElementById("chat-q-head");
3776
+ var qLine = document.getElementById("chat-q-line");
3777
+ var qText = document.getElementById("chat-q-text");
3778
+ var qAnswer = document.getElementById("chat-q-answer");
3779
+ var qError = document.getElementById("chat-q-error");
3780
+ var qSend = document.getElementById("chat-q-send");
3781
+ var extrasEl = document.getElementById("chat-extras");
3811
3782
  var newBox = document.getElementById("jf-new");
3812
3783
  var runBox = document.getElementById("jf-run");
3813
3784
  var runInputsEl = document.getElementById("jf-run-inputs");
@@ -3831,12 +3802,17 @@
3831
3802
  var resumeSignInfo = null; // Resume form, first Sign & resume click: { hash }
3832
3803
  var modeBeforeResume = "new";
3833
3804
  var mainAction = "none";
3805
+ var mainStartOver = false; // the main button reads Start over (amendment 14 item 6: that draft names the one it started over from)
3834
3806
  var startOk = false;
3835
3807
  var sessionId = null; // the draft's id (GET /api/author/<id>)
3836
3808
  var sessionLive = false; // a draft exists that is not abandoned or signed
3837
3809
  var lastState = null; // the draft as the server last described it
3838
3810
  var signInfo = null; // the first Sign click's reply: { hash, flowName, capUsd, runId }
3839
3811
  var signClickedOnce = false;
3812
+ var reviseOpen = false; // amendment 14 item 2: Revise was pressed on a green plan, so every card field is open (ONE writer: setReviseOpen)
3813
+ var qKey = ""; // which question the box is showing (draft id + k): the answer box is rewritten only when this changes
3814
+ var qBusy = false; // an answer POST is in flight
3815
+ var extrasKey = "";
3840
3816
  var busy = false; // a POST is in flight (disabled from the click until the reply)
3841
3817
  var startId = null; // the run start being watched (GET /api/author/start/<id>)
3842
3818
  var refusedStartId = null; // a refused start whose sentence is on the card; Clear dismisses it on the server (cleared.json)
@@ -3892,19 +3868,27 @@
3892
3868
  if(st.phase === "drafting"){
3893
3869
  return {text: "Draft", action: "none", disabled: true};
3894
3870
  }
3871
+ if((st.phase === "red" || st.phase === "stopped") && st.revisable){
3872
+ // amendment 14 items 3-4: a red revise keeps the edits; Draft is another revise, Start over (no revises left) a fresh draft
3873
+ return (st.left || 0) > 0 ? {text: "Draft", action: "revise", disabled: blocked} : {text: "Start over", action: "draft", startOver: true, disabled: blocked};
3874
+ }
3895
3875
  if(st.phase === "red"){
3896
3876
  return {text: "Fix and draft again", action: "draft", disabled: blocked};
3897
3877
  }
3898
3878
  if(st.phase === "stopped"){
3899
3879
  return {text: "Draft again", action: "draft", disabled: blocked};
3900
3880
  }
3901
- if(st.phase === "revising"){
3881
+ if(st.phase === "revising" || st.phase === "redrafting"){
3882
+ return {text: "Sign & run", action: "none", disabled: true};
3883
+ }
3884
+ if(st.phase === "questions-open"){
3885
+ // amendments 24/25: nothing is signable, and a revise is no way round it: the question is answered first
3902
3886
  return {text: "Sign & run", action: "none", disabled: true};
3903
3887
  }
3904
3888
  if(st.phase === "green"){
3905
- // amendment 3 item 3: a note in the ask box makes the one button Send (a change to the plan); empty, it is Sign & run
3906
- if(st.boxOpen && !st.textEmpty){
3907
- return {text: "Send", action: "revise", disabled: !!st.busy};
3889
+ // amendment 14 item 2: Revise opened the card, so the one button is Draft (the card posted to the revise route)
3890
+ if(st.reviseOpen && st.revisable && (st.left || 0) > 0){
3891
+ return {text: "Draft", action: "revise", disabled: blocked};
3908
3892
  }
3909
3893
  if(st.signClicked){
3910
3894
  var signCap = (cap !== undefined && cap !== null && cap !== "") ? " \u00b7 $" + cap : "";
@@ -3914,28 +3898,20 @@
3914
3898
  }
3915
3899
  return {text: "Draft", action: "none", disabled: true};
3916
3900
  }
3917
- // pure: the ask box is open on a green plan with changes left (bareloop: it closes at 0); the hint under the button says how many.
3918
- function askBoxOpenFor(st){
3919
- return st.mode === "new" && !!st.session && st.phase === "green" && (st.left || 0) > 0;
3901
+ // pure: the green plan's Revise button (amendment 14 item 2): on a green plan with revises left, before Revise is pressed
3902
+ function reviseShownFor(st){
3903
+ return st.mode === "new" && !!st.session && st.phase === "green" && !!st.revisable && (st.left || 0) > 0 && !st.reviseOpen;
3920
3904
  }
3921
- // pure: Start over shows only when the plan on show has used both changes (the ask box is closed): the second choice beside Sign & run
3905
+ // pure: Start over beside Sign & run (amendment 14 item 3): a green plan whose revises are all used. (A red or stopped one has it as the main button.)
3922
3906
  function startOverShownFor(st){
3923
- return st.mode === "new" && !!st.session && st.phase === "green" && st.left === 0;
3907
+ return st.mode === "new" && !!st.session && st.phase === "green" && !!st.revisable && st.left === 0;
3924
3908
  }
3925
- // borrowed-from: bareloop src/panel/index.html@c1d87ce (renderMessages: "you" / bot bubbles, each with a who label)
3926
- // pure: the bubbles above the plan (amendment 6 item 3), from the draft's notes: each note is a you bubble in the human's words, each green change a fwdloop bubble.
3927
- // A red or stopped change gets no bubble of its own: its reds are in the progress list, shown once.
3928
- function bubblesFor(state){
3929
- var out = [];
3930
- if(!state || (state.phase !== "green" && state.phase !== "revising")) return out;
3931
- (state.notes || []).forEach(function(nt){
3932
- out.push({role: "you", who: "you", text: String(nt.text || "").replace(/\s+$/, "")});
3933
- if(nt.phase === "green") out.push({role: "bot", who: "fwdloop", text: "New plan, hash " + String(nt.hash || "").slice(0, 8) + ". " + changesLeftText(nt.left) + "."});
3934
- });
3935
- return out;
3909
+ // pure: are the card fields open on a green plan? After Revise, or when no revise is left (amendment 14 item 3: all fields stay open)
3910
+ function greenFieldsOpenFor(st){
3911
+ return !!st.revisable && (!!st.reviseOpen || st.left === 0);
3936
3912
  }
3937
- function changesLeftText(left){
3938
- return left + (left === 1 ? " change left" : " changes left");
3913
+ function revisesLeftText(left){
3914
+ return left + (left === 1 ? " revise left" : " revises left");
3939
3915
  }
3940
3916
  // pure: the gutter beside a box (amendment 2, plain numbers by amendment 3), one entry per LOGICAL line. The job: `N` on a step line (numbers go on), `~` on a
3941
3917
  // guardrail line, nothing on an empty line. The inputs: a number per non-empty line.
@@ -3959,6 +3935,22 @@
3959
3935
  if(state){
3960
3936
  if(state.phase === "drafting"){
3961
3937
  out.push({id: "drafting", label: "drafting with " + who + capPart, status: "running", details: []});
3938
+ } else if(Array.isArray(state.revises)){
3939
+ // amendment 14: a draft whose first plan was green. One line per revise with its result; a red one shows its reds (its sentence is on the card error line).
3940
+ out.push({id: "drafted", label: "drafted with " + who, status: "done", details: []});
3941
+ var reviseNo = 0;
3942
+ state.revises.forEach(function(rv){
3943
+ // an answer redraft (amendment 24 item 4) is not a revise and is not counted as one
3944
+ var label = rv.kind === "answers" ? "drafted again with your answers" : "revise " + (reviseNo += 1);
3945
+ if(rv.phase === "running") out.push({id: "revise-" + rv.n, label: label, status: "running", details: []});
3946
+ else if(rv.phase === "green") out.push({id: "revise-" + rv.n, label: label, status: "done", details: []});
3947
+ else out.push({id: "revise-" + rv.n, label: label, status: "failed", details: (rv.reds && rv.reds.length ? rv.reds.slice() : [])});
3948
+ });
3949
+ if(state.phase === "green"){
3950
+ if(ctx.starting) out.push({id: "signed", label: "signed", status: "done", details: []});
3951
+ else out.push({id: "sign", label: ctx.signClicked ? "waiting for your second click" : "waiting for your signature", status: "waiting", details: []});
3952
+ }
3953
+ if(state.phase === "questions-open") out.push({id: "question", label: "waiting for your answer (" + state.openK + " of " + state.total + ")", status: "waiting", details: []});
3962
3954
  } else if(state.phase === "red"){
3963
3955
  out.push({id: "drafted", label: "drafted with " + who, status: "done", details: []});
3964
3956
  out.push({id: "checks", label: "plan checks", status: "failed", details: (state.reds || []).slice()});
@@ -3966,19 +3958,9 @@
3966
3958
  out.push({id: "drafting", label: "drafting with " + who + capPart, status: "failed", details: []});
3967
3959
  } else if(state.phase === "green" || state.phase === "revising"){
3968
3960
  out.push({id: "drafted", label: "drafted with " + who, status: "done", details: []});
3969
- // amendment 3 item 3: each note the human sent is a line of its own, with its result (a red change shows its reds)
3970
- (state.notes || []).forEach(function(nt){
3971
- var body = String(nt.text || "").replace(/\s+$/, "");
3972
- var label = "change " + nt.n + ": " + body;
3973
- if(nt.phase === "running") out.push({id: "change-" + nt.n, label: label, status: "running", details: []});
3974
- else if(nt.phase === "green") out.push({id: "change-" + nt.n, label: label, status: "done", details: []});
3975
- else out.push({id: "change-" + nt.n, label: label, status: "failed", details: (nt.reds && nt.reds.length ? nt.reds.slice() : []).concat(nt.say ? [nt.say] : [])});
3976
- });
3977
- if(state.phase === "revising"){
3978
- // the last green plan stays on show; nothing to sign until the change comes back
3979
- } else if(ctx.starting){
3961
+ if(ctx.starting){
3980
3962
  out.push({id: "signed", label: "signed", status: "done", details: []});
3981
- } else {
3963
+ } else if(state.phase !== "revising"){
3982
3964
  out.push({id: "sign", label: ctx.signClicked ? "waiting for your second click" : "waiting for your signature", status: "waiting", details: []});
3983
3965
  }
3984
3966
  }
@@ -3986,6 +3968,35 @@
3986
3968
  if(ctx.starting) out.push({id: "starting", label: "starting the run", status: "running", details: []});
3987
3969
  return out.filter(function(s, i){ return i === 0 || JSON.stringify(s) !== JSON.stringify(out[i - 1]); });
3988
3970
  }
3971
+ // pure: the question box's content (amendments 24/25), or null when no question is open. One question at a time: `openK` of `total`.
3972
+ function questionViewFor(state){
3973
+ if(!state || state.phase !== "questions-open" || !Array.isArray(state.questions)) return null;
3974
+ var q = state.questions.filter(function(x){ return x.k === state.openK; })[0];
3975
+ if(!q) return null;
3976
+ return {
3977
+ key: String(state.draftId) + ":" + q.k, k: q.k,
3978
+ head: "A question the plan raised (" + q.k + " of " + state.total + ")",
3979
+ line: q.lineText ? "About job line " + q.line + ": " + q.lineText : "About job line " + q.line,
3980
+ question: q.question
3981
+ };
3982
+ }
3983
+ // pure: what sits beside a green plan: Your answers (only when the plan was drafted with some), Checked (the machine's sentences from the
3984
+ // typed checks) and Not checked (the drafter's own list, ALWAYS with its label), or null when there is no plan to show
3985
+ function extrasFor(state){
3986
+ if(!state || state.phase !== "green" || !Array.isArray(state.checked)) return null;
3987
+ var blocks = [];
3988
+ if(Array.isArray(state.answers) && state.answers.length){
3989
+ blocks.push({id: "chat-answers", head: "Your answers", sub: "", lines: state.answers.map(function(a){
3990
+ return "line " + a.line + (a.lineText ? ": " + a.lineText : "") + "\n > " + a.answer;
3991
+ })});
3992
+ }
3993
+ blocks.push({id: "chat-checked", head: "Checked", sub: "built by the machine from the plan's checks", lines: state.checked.map(function(c){
3994
+ return (c.line !== null && c.line !== undefined ? "line " + c.line : "step " + c.step) + ": " + c.sentences.join(" ");
3995
+ })});
3996
+ var nc = state.notChecked || {};
3997
+ blocks.push({id: "chat-notchecked", head: "Not checked", sub: nc.label || "the drafter's own reading, not a guarantee", lines: (nc.items && nc.items.length) ? nc.items.map(function(x){ return "- " + x; }) : ["The drafter listed nothing."]});
3998
+ return {blocks: blocks};
3999
+ }
3989
4000
  // pure: did this POST succeed (one decision for every handler)
3990
4001
  function chatPostOutcome(r){
3991
4002
  var ok = !!(r && r.status >= 200 && r.status < 300 && r.body && r.body.ok === true);
@@ -4211,7 +4222,9 @@
4211
4222
  // is editable (the draft was made from these values). ONE function owns it. A red or stopped draft unlocks the card (fix, draft again).
4212
4223
  function cardLocked(){
4213
4224
  var ph = (sessionLive && lastState) ? lastState.phase : null;
4214
- return busy || startId !== null || (mode === "new" && (ph === "drafting" || ph === "revising" || ph === "green"));
4225
+ // amendment 14: a green plan locks the card until Revise opens it (or no revise is left); a red or stopped one is open
4226
+ var greenOpen = ph === "green" && greenFieldsOpenFor({revisable: Array.isArray(lastState.revises), reviseOpen: reviseOpen, left: lastState.revisesLeft});
4227
+ return busy || startId !== null || (mode === "new" && (ph === "drafting" || ph === "revising" || ph === "redrafting" || ph === "questions-open" || (ph === "green" && !greenOpen)));
4215
4228
  }
4216
4229
  function syncCardLock(){
4217
4230
  var on = cardLocked();
@@ -4382,25 +4395,49 @@
4382
4395
  }).join("\n");
4383
4396
  }
4384
4397
  function renderThread(state){
4398
+ // a revise being drafted leaves the plan on show until the new one replaces it (the view carries no plan meanwhile)
4399
+ if(state && (state.phase === "revising" || state.phase === "redrafting")) return;
4385
4400
  var html = "";
4386
- if(state && (state.phase === "green" || state.phase === "revising") && state.readout){
4387
- // M4e amendment 6 item 3: bubbles (oldest first), THEN the current plan, so the plan sits right above the note box and the button
4388
- html = bubblesFor(state).map(function(m){
4389
- return '<div class="msg ' + m.role + '"><div class="who">' + escapeXml(m.who) + '</div>' + escapeXml(m.text) + '</div>';
4390
- }).join("") +
4391
- '<div class="msg bot" data-testid="chat-plan"><div class="who">fwdloop</div>' + readoutHtml(state) +
4401
+ if(state && state.phase === "green" && state.readout){
4402
+ html = '<div class="msg bot" data-testid="chat-plan"><div class="who">fwdloop</div>' + readoutHtml(state) +
4392
4403
  '\n\nPlan hash: ' + escapeXml(state.hash || "") + '</div>';
4393
4404
  }
4394
4405
  if(html !== threadKey){ threadKey = html; thread.innerHTML = html; }
4395
4406
  }
4407
+ // the question box: static markup, so the poll never re-renders over an unsent answer. The texts and the empty answer box are written only
4408
+ // when the QUESTION changes (a new key); the same question on the next tick touches nothing.
4409
+ function renderQuestion(state){
4410
+ var v = questionViewFor(state);
4411
+ if(!v){
4412
+ if(qKey !== ""){ qKey = ""; qAnswer.value = ""; qError.textContent = ""; }
4413
+ questionBox.hidden = true;
4414
+ return;
4415
+ }
4416
+ questionBox.hidden = false;
4417
+ if(v.key !== qKey){
4418
+ qKey = v.key;
4419
+ qHead.textContent = v.head; qLine.textContent = v.line; qText.textContent = v.question;
4420
+ qAnswer.value = ""; qError.textContent = "";
4421
+ }
4422
+ }
4423
+ // Your answers / Checked / Not checked; a plan being drafted again leaves them on show (like the plan), anything else without a green plan clears them
4424
+ function renderExtras(state){
4425
+ if(state && (state.phase === "revising" || state.phase === "redrafting")) return;
4426
+ var v = extrasFor(state);
4427
+ var html = v ? v.blocks.map(function(b){
4428
+ return '<div class="msg" id="' + b.id + '" data-testid="' + b.id + '"><b class="readout-head">' + escapeXml(b.head) + '</b>' +
4429
+ (b.sub ? ' <span class="hint">(' + escapeXml(b.sub) + ')</span>' : '') + '\n' + b.lines.map(escapeXml).join("\n") + '</div>';
4430
+ }).join("") : "";
4431
+ if(html !== extrasKey){ extrasKey = html; extrasEl.innerHTML = html; }
4432
+ }
4396
4433
  function renderMain(){
4397
- var st = {mode: mode, session: sessionLive, startOk: startOk, busy: busy || startId !== null, signClicked: signClickedOnce, textEmpty: msgEl.value.trim() === ""};
4434
+ var st = {mode: mode, session: sessionLive, startOk: startOk, busy: busy || startId !== null, signClicked: signClickedOnce, reviseOpen: reviseOpen};
4398
4435
  if(sessionLive && lastState){
4399
4436
  st.phase = lastState.phase;
4400
4437
  st.hash = signInfo ? signInfo.hash : lastState.hash;
4401
- st.left = lastState.changesLeft;
4438
+ st.revisable = Array.isArray(lastState.revises);
4439
+ st.left = lastState.revisesLeft;
4402
4440
  }
4403
- st.boxOpen = askBoxOpenFor(st);
4404
4441
  if(mode === "run"){
4405
4442
  st.capUsd = runCapEl.value.trim();
4406
4443
  st.runDiffers = runDiffers();
@@ -4418,19 +4455,19 @@
4418
4455
  var b = mainButtonFor(st);
4419
4456
  mainBtn.textContent = b.text;
4420
4457
  mainBtn.disabled = b.disabled;
4421
- mainAction = b.action;
4422
- // the ask box: open on a green plan with changes left, shown but locked while a change is being drafted, closed at 0 left
4423
- var boxShown = st.boxOpen || (mode === "new" && sessionLive && st.phase === "revising");
4424
- msgRow.hidden = !boxShown;
4425
- msgEl.readOnly = !st.boxOpen || !!busy;
4426
- mainHint.textContent = st.boxOpen ? changesLeftText(st.left) : "";
4458
+ mainAction = b.action; mainStartOver = !!b.startOver;
4459
+ // amendment 14 item 3: the count shows while a draft has revises to count; at 0 the way on is Start over
4460
+ mainHint.textContent = (mode === "new" && sessionLive && st.revisable && st.phase !== "signed" && st.phase !== "questions-open") ? (st.left > 0 ? revisesLeftText(st.left) : "No revises left: Start over keeps the fields and gives 2 new ones.") : "";
4461
+ reviseBtn.hidden = !reviseShownFor(st);
4462
+ reviseBtn.disabled = !!st.busy;
4427
4463
  startOverBtn.hidden = !startOverShownFor(st);
4428
4464
  startOverBtn.disabled = !!st.busy;
4429
4465
  fitCardBoxes();
4430
- if(boxShown) fitBox(msgEl);
4431
4466
  }
4432
4467
  function renderActions(state){
4433
4468
  lastState = state;
4469
+ renderQuestion(state);
4470
+ renderExtras(state);
4434
4471
  // a newer plan than the one the first Sign click showed (a change came back, or another tab): the first click is void; sign re-checks on the server too
4435
4472
  if(signInfo && state.hash && state.hash !== signInfo.hash){ signInfo = null; signClickedOnce = false; }
4436
4473
  // #chat-card-error is POLL-OWNED: it carries only the draft's own sentence (a red plan or a stopped child), written here and
@@ -4454,20 +4491,21 @@
4454
4491
  // the boxes. Touches neither error line, so a refusal on screen stays on screen.
4455
4492
  function endSession(){
4456
4493
  stopPoll();
4457
- sessionId = null; sessionLive = false; lastState = null; signInfo = null; signClickedOnce = false;
4494
+ sessionId = null; sessionLive = false; lastState = null; signInfo = null; signClickedOnce = false; reviseOpen = false;
4458
4495
  threadKey = ""; thread.innerHTML = "";
4496
+ renderQuestion(null); renderExtras(null);
4459
4497
  errEl.textContent = "";
4460
4498
  progressRow.hidden = true; progressRow.innerHTML = "";
4461
4499
  refreshStartEnabled();
4462
4500
  }
4463
4501
  function openNewCard(){
4464
4502
  thread.innerHTML = ""; threadKey = "";
4465
- msgEl.value = "";
4503
+ renderQuestion(null); renderExtras(null);
4466
4504
  errEl.textContent = "";
4467
4505
  actionErrEl.textContent = "";
4468
4506
  clearFieldErrors();
4469
4507
  stopStart();
4470
- sessionId = null; sessionLive = false; lastState = null; signInfo = null; signClickedOnce = false; busy = false;
4508
+ sessionId = null; sessionLive = false; lastState = null; signInfo = null; signClickedOnce = false; busy = false; reviseOpen = false;
4471
4509
  stopPoll();
4472
4510
  progressRow.hidden = true;
4473
4511
  progressRow.innerHTML = "";
@@ -4560,20 +4598,34 @@
4560
4598
  }).catch(function(){ /* transient — next tick tries again */ });
4561
4599
  }
4562
4600
 
4563
- function doDraft(){
4601
+ // Send (amendments 24/25): the answer to the question now open. A blank answer is refused by the server in plain words and the question stays open.
4602
+ function doAnswer(){
4603
+ if(qBusy || !sessionId || !lastState || lastState.phase !== "questions-open") return;
4604
+ qBusy = true; qSend.disabled = true; qError.textContent = "";
4605
+ var id = sessionId;
4606
+ authorPost("/api/author/" + id + "/answer", {k: lastState.openK, answer: qAnswer.value}).then(function(r){
4607
+ qBusy = false; qSend.disabled = false;
4608
+ if(id !== sessionId) return;
4609
+ if(!(r.status >= 200 && r.status < 300 && r.body && r.body.ok === true)){ qError.textContent = refusalText(r); return; }
4610
+ qAnswer.value = "";
4611
+ poll();
4612
+ }).catch(function(){ qBusy = false; qSend.disabled = false; qError.textContent = NETWORK_SAY; });
4613
+ }
4614
+ function doDraft(startedOverFrom){
4564
4615
  clearFieldErrors();
4565
4616
  chatActionOk();
4566
4617
  // disabled from the click until the reply; unlocked below only if the draft is refused
4567
4618
  busy = true;
4568
4619
  refreshStartEnabled();
4569
4620
  var body = currentCard();
4621
+ if(startedOverFrom) body.startedOverFrom = startedOverFrom;
4570
4622
  authorPost("/api/author/draft", body).then(function(r){
4571
4623
  busy = false;
4572
4624
  var o = chatPostOutcome(r);
4573
4625
  if(!o.ok){ failFrom(r); refreshStartEnabled(); return; }
4574
4626
  sessionId = r.body.draftId;
4575
4627
  sessionLive = true;
4576
- signInfo = null; signClickedOnce = false;
4628
+ signInfo = null; signClickedOnce = false; reviseOpen = false;
4577
4629
  thread.innerHTML = ""; threadKey = "";
4578
4630
  renderActions({draftId: sessionId, phase: "drafting", card: {capUsd: body.capUsd}});
4579
4631
  startPoll();
@@ -4718,22 +4770,23 @@
4718
4770
  beginStart(r.body.startId);
4719
4771
  }).catch(function(){ busy = false; chatActionFailed(NETWORK_SAY); refreshStartEnabled(); });
4720
4772
  }
4721
- // amendment 3 item 3: send the note; the server drafts a changed plan beside the old one (the old one stays signable until a new green one exists).
4722
- // A refused note stays in the box (unsent input is never wiped).
4773
+ // amendment 14 item 2: Draft on an open card posts the card (the same shape as the draft call) to the revise route; the model gets the card only.
4774
+ // A refused revise leaves every field as typed (unsent input is never wiped). The new plan replaces the shown one when it comes back.
4723
4775
  function doRevise(){
4724
4776
  if(!sessionId) return;
4725
4777
  var id = sessionId;
4726
- var text = msgEl.value;
4778
+ var body = currentCard();
4779
+ clearFieldErrors();
4727
4780
  chatActionOk();
4728
4781
  busy = true;
4729
4782
  refreshStartEnabled();
4730
- authorPost("/api/author/" + id + "/revise", {text: text}).then(function(r){
4783
+ authorPost("/api/author/" + id + "/revise", body).then(function(r){
4731
4784
  busy = false;
4732
4785
  var o = chatPostOutcome(r);
4733
4786
  if(!o.ok){ failFrom(r); refreshStartEnabled(); return; }
4734
- msgEl.value = "";
4787
+ reviseOpen = false;
4735
4788
  signInfo = null; signClickedOnce = false;
4736
- refreshStartEnabled();
4789
+ renderActions(Object.assign({}, lastState, {phase: "revising"}));
4737
4790
  poll();
4738
4791
  }).catch(function(){ busy = false; chatActionFailed(NETWORK_SAY); refreshStartEnabled(); });
4739
4792
  }
@@ -4791,22 +4844,21 @@
4791
4844
  if(refusedStartId){ var rid = refusedStartId; refusedStartId = null; authorPost("/api/author/start/" + rid + "/clear", {}).catch(function(){}); }
4792
4845
  resetCard();
4793
4846
  });
4794
- // Start over (amendment 4 item 3): the same draft call as Draft, from the card as it is now; the old draft's files stay (a new draft id)
4795
- startOverBtn.addEventListener("click", function(){ if(!startOverBtn.disabled) doDraft(); });
4847
+ // Revise (amendment 14 item 2): opens every card field, filled as last submitted; nothing is sent
4848
+ reviseBtn.addEventListener("click", function(){ if(reviseBtn.disabled) return; reviseOpen = true; refreshStartEnabled(); });
4849
+ // Start over (amendment 14 item 3): the same draft call as Draft, from the card as it is now; the old draft's files stay (a new draft id, 2 new revises)
4850
+ startOverBtn.addEventListener("click", function(){ if(!startOverBtn.disabled) doDraft(sessionId); });
4851
+ qSend.addEventListener("click", doAnswer);
4852
+ qAnswer.addEventListener("keydown", function(e){ if(e.key === "Enter" && !e.shiftKey){ e.preventDefault(); doAnswer(); } });
4796
4853
  mainBtn.addEventListener("click", function(){
4797
4854
  if(mainBtn.disabled) return;
4798
- if(mainAction === "draft") doDraft();
4855
+ if(mainAction === "draft") doDraft(mainStartOver ? sessionId : null);
4799
4856
  else if(mainAction === "run") doRun();
4800
4857
  else if(mainAction === "run-sign-prepare" || mainAction === "run-sign") doRunSign();
4801
4858
  else if(mainAction === "resume-sign-prepare" || mainAction === "resume-sign") doResumeSign();
4802
4859
  else if(mainAction === "revise") doRevise();
4803
4860
  else if(mainAction === "sign-prepare" || mainAction === "sign") doSign();
4804
4861
  });
4805
- msgEl.addEventListener("input", function(){ fitBox(msgEl); renderMain(); });
4806
- // Enter sends the note, Shift+Enter is a newline (bareloop's ask box)
4807
- msgEl.addEventListener("keydown", function(e){
4808
- if(e.key === "Enter" && !e.shiftKey && mainAction === "revise"){ e.preventDefault(); if(!mainBtn.disabled) doRevise(); }
4809
- });
4810
4862
  card.addEventListener("input", function(e){
4811
4863
  var grp = e.target && e.target.closest ? e.target.closest(".field, .cap-field, .jf-inrow") : null;
4812
4864
  if(grp) grp.querySelectorAll(".jf-err").forEach(function(x){ x.textContent = ""; });