bareloop 0.54.1 → 0.55.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 (130) hide show
  1. package/CHANGELOG.md +75 -0
  2. package/bareloop.context.md +65 -6
  3. package/package.json +3 -3
  4. package/src/authorflow.js +148 -46
  5. package/src/authoring.js +21 -4
  6. package/src/authorjob.js +82 -3
  7. package/src/authorreadout.js +20 -3
  8. package/src/authorrun.js +1 -1
  9. package/src/authorscout.js +9 -6
  10. package/src/cardschedule.js +42 -0
  11. package/src/checkpick.js +576 -0
  12. package/src/checksuggest.js +28 -0
  13. package/src/checkwords.js +25 -0
  14. package/src/cli.js +1 -1
  15. package/src/config.js +24 -1
  16. package/src/declaredclose.js +1 -1
  17. package/src/destpoint.js +149 -0
  18. package/src/draftspend.js +39 -0
  19. package/src/factwords.js +14 -1
  20. package/src/job.js +81 -1
  21. package/src/jobblock.js +9 -0
  22. package/src/labelscan.js +11 -0
  23. package/src/launcher.js +3 -2
  24. package/src/mcpchecks.js +52 -0
  25. package/src/mcppick.js +36 -0
  26. package/src/mcpsources.js +77 -0
  27. package/src/mcpuse.js +97 -0
  28. package/src/natural.js +23 -0
  29. package/src/pagemap.js +5 -2
  30. package/src/panel/authorroutes.js +90 -15
  31. package/src/panel/authorsession.js +183 -21
  32. package/src/panel/index.html +686 -26
  33. package/src/panel/jobgrid.js +117 -0
  34. package/src/panel/jobplan.js +31 -15
  35. package/src/panel/scheduler.js +80 -13
  36. package/src/panel/schedules.js +189 -28
  37. package/src/panel/schedulestart.js +44 -13
  38. package/src/panel/server.js +419 -32
  39. package/src/panel/settingsroutes.js +133 -3
  40. package/src/panel/status.js +19 -1
  41. package/src/panel/tickets.js +44 -0
  42. package/src/pickrecord.js +145 -0
  43. package/src/plan.js +31 -2
  44. package/src/planrun.js +71 -15
  45. package/src/prcheckout.js +259 -0
  46. package/src/readshim.js +3 -2
  47. package/src/revises.js +56 -0
  48. package/src/rubricstep.js +62 -16
  49. package/src/run.js +10 -1
  50. package/src/runexport.js +2 -0
  51. package/src/runlist.js +3 -2
  52. package/src/schedulewords.js +46 -4
  53. package/src/source.js +81 -7
  54. package/src/stepmcp.js +86 -0
  55. package/src/ticket.js +113 -0
  56. package/src/ticketfilter.js +76 -0
  57. package/src/ticketlabels.js +79 -0
  58. package/src/ticketmcp.js +111 -0
  59. package/src/ticketnext.js +35 -0
  60. package/src/ticketrepo.js +98 -0
  61. package/src/ticketschedule.js +32 -0
  62. package/src/ticketshape.js +45 -0
  63. package/src/tools.js +9 -0
  64. package/src/trigger.js +14 -2
  65. package/src/triggerclock.js +7 -3
  66. package/src/triggerfiles.js +19 -11
  67. package/src/triggertickets.js +244 -0
  68. package/src/userrun.js +145 -9
  69. package/src/validate.js +3 -1
  70. package/src/worktree.js +43 -1
  71. package/types/authorflow.d.ts +128 -28
  72. package/types/authorjob.d.ts +16 -3
  73. package/types/authorreadout.d.ts +9 -2
  74. package/types/authorscout.d.ts +4 -2
  75. package/types/cardschedule.d.ts +24 -0
  76. package/types/checkpick.d.ts +297 -0
  77. package/types/checksuggest.d.ts +30 -0
  78. package/types/checkwords.d.ts +14 -0
  79. package/types/config.d.ts +7 -0
  80. package/types/destpoint.d.ts +87 -0
  81. package/types/draftspend.d.ts +16 -0
  82. package/types/factwords.d.ts +7 -0
  83. package/types/job.d.ts +13 -0
  84. package/types/jobblock.d.ts +9 -0
  85. package/types/labelscan.d.ts +7 -0
  86. package/types/launcher.d.ts +2 -2
  87. package/types/mcpchecks.d.ts +8 -0
  88. package/types/mcppick.d.ts +33 -0
  89. package/types/mcpsources.d.ts +51 -0
  90. package/types/mcpuse.d.ts +15 -0
  91. package/types/natural.d.ts +2 -0
  92. package/types/pagemap.d.ts +2 -1
  93. package/types/panel/authorroutes.d.ts +11 -2
  94. package/types/panel/authorsession.d.ts +58 -3
  95. package/types/panel/jobgrid.d.ts +405 -0
  96. package/types/panel/jobplan.d.ts +10 -4
  97. package/types/panel/scheduler.d.ts +7 -2
  98. package/types/panel/schedules.d.ts +124 -4
  99. package/types/panel/schedulestart.d.ts +21 -3
  100. package/types/panel/server.d.ts +427 -6
  101. package/types/panel/settingsroutes.d.ts +4 -2
  102. package/types/panel/status.d.ts +16 -2
  103. package/types/panel/tickets.d.ts +61 -0
  104. package/types/pickrecord.d.ts +88 -0
  105. package/types/plan.d.ts +1 -0
  106. package/types/prcheckout.d.ts +151 -0
  107. package/types/readshim.d.ts +4 -3
  108. package/types/revises.d.ts +23 -0
  109. package/types/rubricstep.d.ts +14 -5
  110. package/types/run.d.ts +18 -1
  111. package/types/runlist.d.ts +6 -3
  112. package/types/schedulewords.d.ts +29 -2
  113. package/types/source.d.ts +40 -4
  114. package/types/stepmcp.d.ts +40 -0
  115. package/types/ticket.d.ts +114 -0
  116. package/types/ticketfilter.d.ts +34 -0
  117. package/types/ticketlabels.d.ts +44 -0
  118. package/types/ticketmcp.d.ts +84 -0
  119. package/types/ticketnext.d.ts +33 -0
  120. package/types/ticketrepo.d.ts +118 -0
  121. package/types/ticketschedule.d.ts +21 -0
  122. package/types/ticketshape.d.ts +37 -0
  123. package/types/tools.d.ts +1 -0
  124. package/types/trigger.d.ts +9 -1
  125. package/types/triggerclock.d.ts +6 -2
  126. package/types/triggerfiles.d.ts +13 -5
  127. package/types/triggertickets.d.ts +110 -0
  128. package/types/userrun.d.ts +50 -0
  129. package/types/validate.d.ts +1 -0
  130. package/types/worktree.d.ts +19 -0
@@ -152,6 +152,8 @@
152
152
  .dot.red::before{content:"[✗]";color:var(--red);}
153
153
  /* stopped (hamr 2026-10-07): the person pressed Stop — its own sign, grey (RULED 2026-10-15) */
154
154
  .dot.stopped::before{content:"[■]";color:var(--grey-dot);}
155
+ /* R5 (piece 2): a ticket the job's signed filter did not let through ends skipped at run start: [–], grey, rests (fwd's sign) */
156
+ .dot.skipped::before{content:"[–]";color:var(--grey-dot);}
155
157
  /* Panel build P3 addition (2026-09-27, "yes, go"): the part cards below the
156
158
  step map (`partResultGlyph`/`attemptGlyph`) and the chat job card render
157
159
  their result glyph as PLAIN inline text inside a larger string (never
@@ -357,6 +359,7 @@
357
359
  .ended-text .sched-line2{display:block;}
358
360
  .run-actions{display:flex;gap:10px;align-items:center;flex-wrap:wrap;margin-bottom:12px;}
359
361
  .run-actions[hidden]{display:none;}
362
+ #run-content.actions-only > :not(.run-actions){display:none;}
360
363
  .run-actions .stopping{color:var(--amber);font-size:13px;overflow-wrap:anywhere;}
361
364
  .resume-err{color:var(--red);white-space:pre-wrap;overflow-wrap:anywhere;}
362
365
  /* P5-R: a resumed run is ONE card; its legs are told apart by a divider line, a dotted map connector, a small tag */
@@ -483,6 +486,45 @@
483
486
  #result-body details>summary{cursor:pointer;color:var(--text-dim);min-height:28px;}
484
487
  .rs-link{background:none;border:none;padding:0;min-height:44px;color:var(--accent);text-decoration:underline;font:inherit;cursor:pointer;}
485
488
  .rs-warn{color:var(--amber);overflow-wrap:anywhere;}
489
+ /* R7b item 4: the generic Result tab. A diff wraps inside its own box (no page scroll); a check row is a question and its word and number. */
490
+ .rs-diff{margin:0;white-space:pre-wrap;overflow-wrap:anywhere;font:12px/1.45 ui-monospace,"Courier New",monospace;}
491
+ .ro-value>.rs-diff{max-height:28em;overflow:auto;}
492
+ .rs-add{color:var(--green);} .rs-del{color:var(--red);} .rs-ctx{color:var(--text-dim);}
493
+ .rs-check{display:grid;grid-template-columns:minmax(0,1fr) minmax(8em,auto) 7em;gap:6px 12px;align-items:baseline;padding:3px 0;border-bottom:1px dotted var(--border);}
494
+ .rs-q{overflow-wrap:anywhere;} .rs-num{overflow-wrap:anywhere;} .rs-sign{white-space:nowrap;}
495
+ /* phone width: the number drops under the question, the sign stays in the right column */
496
+ @media (max-width:600px){ .rs-check{grid-template-columns:minmax(0,1fr) auto;} .rs-num{grid-column:1;grid-row:2;} .rs-sign{grid-column:2;grid-row:1;} .rs-num:empty{display:none;} }
497
+ /* R8 (piece 10): a ticket job's Result grid. borrowed-from: fwdloop src/panel/index.html@v0.29.0 tg- rules (the signed mockup .claude/scratch/mcp-tickets/r7b/result-tab-tickets.html). The table, cells and
498
+ step-sub are the Audit grid's own; these are the bucket fold rows, the stats line, the run column and the "Run it anyway" box. A long line wraps; the table scrolls inside its own box, never the page. */
499
+ #result-body .tg-stats{font-size:13px;margin:0 0 8px;overflow-wrap:anywhere;}
500
+ 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;text-align:left;}
501
+ table.grid.tg td.c{min-width:84px;}
502
+ table.grid.tg th{color:var(--accent);font-weight:700;}
503
+ .tg-rowname{display:flex;align-items:center;max-width:min(300px,60vw);}
504
+ table.grid.tg button.tg-name{flex:0 1 auto;min-width:0;display:block;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;text-align:left;border:0;background:none;padding:0;min-height:32px;font:inherit;font-size:12px;font-weight:700;color:var(--accent);cursor:pointer;}
505
+ table.grid.tg button.tg-name:hover{text-decoration:underline;}
506
+ table.grid.tg button.tg-name:focus-visible,table.grid.tg button.tg-arrow:focus-visible{outline:2px solid var(--accent);outline-offset:2px;}
507
+ table.grid.tg button.tg-arrow{flex:0 0 auto;width:auto;color:var(--accent);font-weight:700;}
508
+ .tg-unsure{flex:0 0 auto;margin-left:6px;}
509
+ table.grid.tg button.q-fold{border:0;background:none;color:var(--text);font:inherit;font-size:12px;text-align:left;padding:0;min-height:32px;cursor:pointer;}
510
+ table.grid.tg button.q-fold::before{content:"\25B8 ";color:var(--text-faint);white-space:pre;}
511
+ table.grid.tg button.q-fold[aria-expanded="true"]::before{content:"\25BE ";}
512
+ .tg-val{font-size:11px;color:var(--text-faint);margin-left:4px;}
513
+ tr.tg-grp td{background:var(--panel);border-bottom:1px solid var(--border-strong);padding:0 8px;}
514
+ .tg-fold{display:block;width:100%;text-align:left;background:none;border:0;color:var(--text);font:inherit;font-size:13px;font-weight:700;min-height:34px;cursor:pointer;}
515
+ .tg-fold:hover{color:var(--accent);}
516
+ .tg-fold:focus-visible{outline:2px solid var(--accent);outline-offset:2px;}
517
+ .tg-foldin{position:sticky;left:8px;}
518
+ .tg-skipwhy{display:flex;gap:8px;align-items:center;flex-wrap:wrap;}
519
+ table.grid.tg tr.step-sub td{white-space:normal;overflow-wrap:anywhere;text-align:left;}
520
+ .tg-line{padding:2px 0;font-size:12px;overflow-wrap:anywhere;}
521
+ .tg-line pre.rs-diff{max-height:18em;overflow:auto;}
522
+ .tk-rl{color:var(--accent);text-decoration:underline;cursor:pointer;background:none;border:0;padding:0;font:inherit;}
523
+ .tk-rl:focus-visible{outline:2px solid var(--accent);outline-offset:2px;}
524
+ .tk-anyway{margin-top:6px;}
525
+ .tk-anyway button{display:block;width:100%;box-sizing:border-box;}
526
+ .tk-anyway textarea{width:100%;min-height:52px;margin:4px 0;background:var(--bg);color:var(--text);border:1px solid var(--text-dim);font:inherit;font-size:16px;padding:6px;box-sizing:border-box;}
527
+ .tk-msg{font-size:12px;overflow-wrap:anywhere;}
486
528
  #result-door-card .stopping{color:var(--amber);font-size:13px;overflow-wrap:anywhere;}
487
529
  /* PRD v1.106 Part 5 C: the Audit step fold (tries, their numbered checks, the Round table). Every line wraps; nothing forces a page-wide scroll. */
488
530
  .actor-mark{color:var(--text-faint);font-size:12px;margin-left:6px;white-space:nowrap;}
@@ -634,6 +676,8 @@
634
676
  .jp .num{display:inline-block;text-indent:0;width:22px;text-align:right;color:var(--text-faint);margin-right:8px;}
635
677
  .jp .sub{color:var(--text-dim);padding-left:30px;}
636
678
  .jp .fold{padding-left:30px;color:var(--text);}
679
+ /* who added a check: the drafter's [agent] or the person's own [you picked] (fwdloop's `[added]` marker, in the dim of a ~ row) */
680
+ .jp .by,.draft-checks-row .by{color:var(--text-dim);white-space:nowrap;}
637
681
  .jp details.fold{padding-left:0;margin:6px 0;}
638
682
  .jp details>summary{cursor:pointer;list-style:none;}
639
683
  .jp details>summary::-webkit-details-marker{display:none;}
@@ -734,6 +778,40 @@
734
778
  .pv-typed{display:flex;flex-wrap:wrap;align-items:center;gap:6px 10px;margin-top:4px;}
735
779
  .pv-typed input{flex:1 1 160px;min-width:0;max-width:260px;min-height:28px;box-sizing:border-box;}
736
780
  .pv-typed .hint{flex:1 1 100%;margin:0;}
781
+ /* Settings > MCP (piece 7), borrowed-from: fwdloop src/panel/index.html@d71846c; reuses .pv-key/.pv-krow/.pv-mrow with other columns */
782
+ .mc-sect{font-size:12px;color:var(--text-dim);font-weight:700;margin:16px 0 6px;text-transform:uppercase;letter-spacing:.06em;}
783
+ .mc-sect:first-child{margin-top:0;}
784
+ .mc-grp{border-top:1px solid var(--border-strong);}
785
+ .mc-grp:first-of-type{border-top:none;}
786
+ .mc-prow{display:flex;align-items:center;flex-wrap:wrap;gap:4px 8px;padding:4px 8px;min-height:40px;background:var(--panel2);overflow-wrap:anywhere;}
787
+ .mc-prow .mc-grow{flex:1 1 100px;min-width:0;}
788
+ .mc-prow .btn{margin-left:auto;}
789
+ .mc-prow.faint{color:var(--text-faint);}
790
+ .mc-grp[data-open="0"] .mc-kids{display:none;}
791
+ .pv-head.mc-k,.pv-krow.mc-k{--pv-cols:minmax(0,1.6fr) minmax(0,1.5fr) minmax(0,.8fr) 150px;}
792
+ .mc-grp .pv-key:first-child{border-top:1px solid var(--border-strong);}
793
+ .mc-k .pv-name{padding-left:26px;}
794
+ .mc-grp .pv-more{padding-left:60px;}
795
+ .mc-grp .mc-use{padding-left:60px;}
796
+ .mc-use{padding:0 8px 6px 34px;margin:0;}
797
+ .mc-use .bad{color:var(--red);}
798
+ .pv-mrow.mc-t,.pv-mhead.mc-t{--pv-cols:minmax(0,1.6fr) minmax(0,1.5fr) minmax(0,.8fr) 150px;}
799
+ .pv-mrow.mc-t{display:grid;padding:0 8px;}
800
+ .mc-t .pv-m-name{padding-left:52px;}
801
+ .mc-t .n{text-align:left;font-variant-numeric:tabular-nums;}
802
+ .pv-key.faint{color:var(--text-faint);}
803
+ @media (max-width:1279px){
804
+ .pv-mhead.mc-t{display:grid;}
805
+ .pv-mrow.mc-t{display:grid;padding:0 8px;}
806
+ .mc-use{padding-left:8px;}
807
+ .mc-kids{margin-left:14px;border-left:2px solid var(--border-strong);}
808
+ .mc-k .pv-name{padding-left:0;}
809
+ .mc-grp .pv-more,.mc-grp .mc-use{padding-left:8px;}
810
+ .pv-mrow.mc-t,.pv-mhead.mc-t{--pv-cols:minmax(0,2fr) minmax(0,1fr) minmax(0,.6fr);}
811
+ .mc-t .n{text-align:right;}
812
+ .mc-t .pv-m-name{padding-left:0;}
813
+ .pv-refcell:empty{display:none;}
814
+ }
737
815
  .hint.bad{color:var(--red);}
738
816
  /* a refused Start (a $0 refusal, e.g. an Inputs line) is read like the red failure line of the progress list, not like a faint hint */
739
817
  .card-refusal:not(:empty){font-size:13px;margin-top:8px;line-height:1.4;}
@@ -861,6 +939,35 @@
861
939
  <div class="nbox-in"><textarea class="jf-wrap" id="jf-inputs" rows="2" data-testid="jf-inputs" spellcheck="false"></textarea><div class="nbox-mir" id="jf-inputs-mir" aria-hidden="true"></div></div>
862
940
  </div>
863
941
  </div>
942
+ <!-- ITEM33-BUILD piece 8 (fwd M13 p4): Flow type and the MCP pick. Signed WITH the job by code; the MCP list is Settings > MCP's (the page only reads it). -->
943
+ <div class="field" id="jf-flowtype-field" data-testid="jf-flowtype-field">
944
+ <label for="jf-flowtype">Flow type</label>
945
+ <select id="jf-flowtype" data-testid="jf-flowtype" aria-label="Flow type">
946
+ <option value="plain">plain</option>
947
+ <option value="mcp">MCP</option>
948
+ <option value="tickets">Tickets MCP</option>
949
+ </select>
950
+ </div>
951
+ <div class="field" id="jf-mcp-field" data-testid="jf-mcp-field" hidden>
952
+ <label for="jf-mcp">MCP</label>
953
+ <select id="jf-mcp" data-testid="jf-mcp" aria-label="MCP"></select>
954
+ <div class="hint"><a class="link" id="jf-mcp-manage" data-testid="jf-mcp-manage" href="#">manage in Settings &gt; MCP</a></div>
955
+ </div>
956
+ <!-- ITEM33-BUILD piece 9 (R7, fwd M13 p5): the Schedule is signed WITH the job; it is OFF until the job's first green run. The words are src/schedulewords.js SCHEDULE_WORDS.card, filled in by the server like the port. -->
957
+ <div class="field" id="jf-sched-field" data-testid="jf-sched-field">
958
+ <label for="jf-sched">__BARELOOP_SCHED_LABEL__</label>
959
+ <select id="jf-sched" data-testid="jf-sched" aria-label="Schedule">
960
+ <option value="hand">__BARELOOP_SCHED_OPT_HAND__</option>
961
+ <option value="new-ticket">__BARELOOP_SCHED_OPT_TICKET__</option>
962
+ <option value="daily">__BARELOOP_SCHED_OPT_DAILY__</option>
963
+ </select>
964
+ <div class="when-sub" id="jf-sched-clock" hidden>
965
+ <input id="jf-sched-time" type="time" value="09:00" data-testid="jf-sched-time" aria-label="Time, HH:MM">
966
+ </div>
967
+ <div class="hint" id="jf-sched-hint" data-testid="jf-sched-hint" hidden>__BARELOOP_SCHED_HINT__</div>
968
+ <div class="hint" id="jf-sched-hint-rubric" data-testid="jf-sched-hint-rubric" hidden>__BARELOOP_SCHED_HINT_RUBRIC__</div>
969
+ <div class="hint" id="jf-sched-ticket-hint" data-testid="jf-sched-ticket-hint" hidden>__BARELOOP_SCHED_HINT_TICKET__</div>
970
+ </div>
864
971
  <div class="field">
865
972
  <label for="jf-dest">Destination <span class="req">required</span></label>
866
973
  <textarea class="jf-wrap" id="jf-dest" rows="1" placeholder="the write fence — where in the repo this run may change files"></textarea>
@@ -877,6 +984,9 @@
877
984
  </select>
878
985
  <input id="jf-when-time" type="time" value="09:00" data-testid="jf-when-time" aria-label="Time, HH:MM">
879
986
  </div>
987
+ <div class="when-sub" id="jf-when-ticketbox" hidden>
988
+ <select id="jf-when-input" data-testid="jf-when-input" aria-label="The ticket list to watch"></select>
989
+ </div>
880
990
  <div class="when-sub" id="jf-when-filebox" hidden>
881
991
  <input id="jf-when-path" type="text" autocomplete="off" spellcheck="false" data-testid="jf-when-path" aria-label="File or folder">
882
992
  </div>
@@ -925,6 +1035,8 @@
925
1035
  <div class="hint" id="chat-main-hint" data-testid="chat-main-hint"></div>
926
1036
  <!-- hamr 2026-10-09: Revise = reopen the boxes, filled as drafted, and draft again. Shown only while a plan waits for the OK. -->
927
1037
  <button class="btn wide" type="button" id="chat-reopen-btn" data-testid="chat-reopen" hidden>Revise</button>
1038
+ <!-- fwd M4e am14 item 3: "N revises left"; after the second revise this same button reads Start over (a fresh draft, its own 2 revises) -->
1039
+ <span id="chat-left-count" data-testid="revises-left" class="hint" hidden></span>
928
1040
  <div class="hint">Only your click signs. The chat can't.</div>
929
1041
  </section>
930
1042
 
@@ -1042,6 +1154,7 @@
1042
1154
  <div class="field" id="details-description-field"><label>Description</label><div class="ro-value" id="details-description">—</div></div>
1043
1155
  <div class="field"><label>The job</label><div class="ro-value" id="details-plan" data-testid="details-plan">—</div></div>
1044
1156
  <div class="field"><label>Inputs</label><div class="ro-value" id="details-inputs" data-testid="details-inputs">—</div></div>
1157
+ <div class="field" id="details-mcp-field" data-testid="details-mcp-field" hidden><label>MCP</label><div class="ro-value" id="details-mcp" data-testid="details-mcp"></div></div>
1045
1158
  <div class="field"><label>Destination</label><div class="ro-value" id="details-dest">—</div></div>
1046
1159
  <div class="field"><label>Tools</label><div class="ro-value" id="details-tools">—</div></div>
1047
1160
  <div class="field-row">
@@ -1073,6 +1186,7 @@
1073
1186
 
1074
1187
  <div class="tabrow" role="tablist" aria-label="Settings views">
1075
1188
  <button role="tab" id="tab-providers" aria-controls="panel-providers" aria-selected="true" data-testid="settings-tab-providers">Providers</button>
1189
+ <button role="tab" id="tab-mcp" aria-controls="panel-mcp" aria-selected="false" data-testid="settings-tab-mcp">MCP</button>
1076
1190
  <button role="tab" id="tab-money" aria-controls="panel-money" aria-selected="false" data-testid="settings-tab-money">Money &amp; limits</button>
1077
1191
  </div>
1078
1192
 
@@ -1099,6 +1213,22 @@
1099
1213
  <div class="hint" id="pv-note" data-testid="pv-note" style="margin-top:6px;">&#10227; refresh models (free) &middot; old max_tokens: tick if the server wants the old field name</div>
1100
1214
  </section>
1101
1215
 
1216
+ <!-- MCP TAB (piece 7; borrowed-from fwdloop src/panel/index.html@d71846c: one list "Path and MCP", a path is a header and its MCPs sit under it) -->
1217
+ <section id="panel-mcp" class="tabpanel" role="tabpanel" aria-labelledby="tab-mcp" hidden>
1218
+ <div class="mc-sect">Path and MCP</div>
1219
+ <div class="table-wrap" data-testid="mcp-table-wrap">
1220
+ <div id="mcp-paths" data-testid="mcp-paths"></div>
1221
+ <div class="pv-more" style="padding-left:10px;border-top:1px solid var(--border-strong)">
1222
+ <button class="btn small" type="button" id="mcp-add-open" data-testid="mcp-add-open">+ add a path</button>
1223
+ <div class="pv-typed" id="mcp-add-box" hidden></div>
1224
+ </div>
1225
+ </div>
1226
+ <div class="hint" id="mcp-problem" data-testid="mcp-problem"></div>
1227
+ <div class="hint" style="margin-top:6px;">Read only. bareloop never edits these files and never shows keys. A project folder's .mcp.json is never read.</div>
1228
+ <div class="hint">check tools starts the server once, only when pressed.</div>
1229
+ <div class="hint">&mdash; = no hint; shown, not blocked. Hints are info only.</div>
1230
+ </section>
1231
+
1102
1232
  <!-- MONEY & LIMITS TAB -->
1103
1233
  <section id="panel-money" class="tabpanel" role="tabpanel" aria-labelledby="tab-money" hidden>
1104
1234
  <div class="money-strip" data-testid="money-strip">
@@ -1458,6 +1588,7 @@
1458
1588
  if(g === "✓") return "green";
1459
1589
  if(g === "✗") return "red";
1460
1590
  if(g === "■") return "stopped";
1591
+ if(g === "–") return "skipped";
1461
1592
  if(g === "▶") return "amber";
1462
1593
  if(g === "?") return "magenta";
1463
1594
  return "grey";
@@ -2675,7 +2806,8 @@
2675
2806
  html += '<button class="btn primary" type="button" data-testid="btn-accept-run">Accept</button>';
2676
2807
  }
2677
2808
  // Reuse workflow: ONE door on every ending (v1.101), a died run included - the Chat card opens with every box open
2678
- if(!live && !!detail.ended && (detail.ended.actions || []).some(function(a){ return a.id === "reuse"; })){
2809
+ // a run refused before it started / skipped has no `ended`; the server marks it `reuseOffered`
2810
+ if(!live && ((!!detail.ended && (detail.ended.actions || []).some(function(a){ return a.id === "reuse"; })) || detail.reuseOffered === true)){
2679
2811
  html += '<button class="btn" type="button" data-testid="btn-reuse">Reuse workflow</button>';
2680
2812
  }
2681
2813
  // T Part 7: the schedule button is LAST, right after Reuse workflow. The SERVER decides (detail.schedule): `scheduled` shows
@@ -2752,6 +2884,7 @@
2752
2884
  }
2753
2885
 
2754
2886
  function renderRun(detail){
2887
+ document.getElementById("run-content").classList.remove("actions-only");
2755
2888
  if(detail.fileMissing){
2756
2889
  syncResultTab({});
2757
2890
  setRunHeader("\u00B7", runName(detail.job, detail.runNo, detail.runid), "file missing");
@@ -2764,16 +2897,19 @@
2764
2897
  return;
2765
2898
  }
2766
2899
 
2767
- if(detail.refused){
2768
- // refused before it started (e.g. the page could not be fetched): the server's plain words, status word from the table
2900
+ if(detail.refused || detail.skipped){
2901
+ // refused before it started (e.g. the page could not be fetched) or skipped by the job's ticket filter (R5): the server's plain words, status word from the table
2769
2902
  syncResultTab({});
2770
2903
  setRunHeader(detail.glyph, runName(detail.job, detail.runNo, detail.runid), statusWordHtml(detail.status, "") + " \u00B7 " + escapeXml("started " + fmtLocalDateTime(detail.at)));
2771
2904
  document.getElementById("run-empty").hidden = false;
2772
2905
  document.getElementById("run-empty").textContent = detail.endedLine || "";
2773
- document.getElementById("run-content").hidden = true;
2906
+ // the Run tab shows the words above and ONLY the action row (Reuse workflow) below: the rest of run-content has nothing to show
2907
+ document.getElementById("run-content").hidden = false;
2908
+ document.getElementById("run-content").classList.add("actions-only");
2774
2909
  document.getElementById("audit-select-empty").hidden = false;
2775
2910
  document.getElementById("audit-select-empty").textContent = detail.endedLine || "";
2776
2911
  document.getElementById("audit-body").hidden = true;
2912
+ renderRunActions(detail); // the SAME owner: the server's detail says which buttons (Reuse workflow on every ending)
2777
2913
  return;
2778
2914
  }
2779
2915
 
@@ -3475,7 +3611,7 @@
3475
3611
  // line 2 of a part's card / Audit body: the drafting step names, or a worker part's tool breakdown
3476
3612
  function partLine2Text(part){
3477
3613
  if(part && part.kind === "door") return part.doorView ? "last answer: " + part.doorView.last : "";
3478
- if(part && part.kind === "drafting") return (part.draftSteps || []).map(function(x){ return x.label; }).join(" · ");
3614
+ if(part && part.kind === "drafting") return (part.draftLabel ? part.draftLabel + " \u00B7 " : "") + (part.draftSteps || []).map(function(x){ return x.label; }).join(" · ");
3479
3615
  return toolBreakdownLine(part.byTool);
3480
3616
  }
3481
3617
  function draftingCallCost(c){
@@ -3487,6 +3623,13 @@
3487
3623
  // call's own label (confirm#2, revise-1…); the last row is the total, equal to the header's money
3488
3624
  function draftingTableHtml(part){
3489
3625
  var rows = "";
3626
+ // fwd am14 item 6: a revise or a Start over says so, first, in the server's own words (`revise 1`, `revise 2`, `start over`); a first draft has no such row
3627
+ if(part.draftLabel) rows += '<tr class="draft-kind-row" data-testid="drafting-kind"><td colspan="5"><b>' + escapeXml(part.draftLabel) + "</b></td></tr>";
3628
+ // the checks this draft ended with, each marked who added it: the drafter ([agent]) or the person's pick ([you picked])
3629
+ (part.draftChecks || []).forEach(function(c){
3630
+ rows += '<tr class="draft-checks-row" data-testid="drafting-check"><td colspan="5" style="overflow-wrap:anywhere">line ' + escapeXml(String(c.line)) + " \u00B7 " + escapeXml(c.text) +
3631
+ (c.by === "you" ? ' <span class="by" data-by="you">[you picked]</span>' : c.by === "agent" ? ' <span class="by" data-by="agent">[agent]</span>' : "") + "</td></tr>";
3632
+ });
3490
3633
  (part.draftSteps || []).forEach(function(st){
3491
3634
  var wall = st.wallMs === null || st.wallMs === undefined ? "–" : duration(st.wallMs);
3492
3635
  var calls = Array.isArray(st.calls) ? st.calls : [];
@@ -3932,13 +4075,15 @@
3932
4075
  function renderJobPlan(plan){
3933
4076
  var h = '<div class="jp" data-testid="job-plan">' + (plan.older ? '<div class="older" data-testid="plan-older">older job \u2014 numbered lines were not saved</div>' : "") + '<div class="jp-legend">Done when every <b>\u203A</b> check passes</div>' +
3934
4077
  (plan.goal && !plan.older ? '<div class="jp-sum" data-testid="plan-goal"><span class="lbl">AI\'s summary</span>' + escapeXml(plan.goal) + "</div>" : "");
4078
+ var byTag = function(by){ return by === "you" ? ' <span class="by" data-testid="plan-by" data-by="you">[you picked]</span>' : by === "agent" ? ' <span class="by" data-testid="plan-by" data-by="agent">[agent]</span>' : ""; };
3935
4079
  var checkLine = function(c){
3936
- return '<div class="fold" data-testid="plan-check"><span class="mk">\u203A</span> check \u00B7 ' + escapeXml(c.name) + (c.cls ? " \u00B7 " + escapeXml(c.cls) : "") + "</div>";
4080
+ return '<div class="fold" data-testid="plan-check"><span class="mk">\u203A</span> check \u00B7 ' + escapeXml(c.name) + (c.cls ? " \u00B7 " + escapeXml(c.cls) : "") + byTag(c.by) + "</div>";
3937
4081
  };
3938
4082
  (plan.lines || []).forEach(function(l){
3939
4083
  h += '<div class="jl" data-testid="plan-line"><span class="num">' + escapeXml(String(l.n)) + "</span>" + escapeXml(l.text);
3940
4084
  // one `~` row per rule (fwdloop's shape); an older plan that carries only the joined `rule` still shows it
3941
4085
  (l.rules && l.rules.length ? l.rules : (l.rule ? [l.rule] : [])).forEach(function(r){ h += '<div class="sub">~ ' + escapeXml(r) + "</div>"; });
4086
+ (l.picked || []).forEach(function(p){ h += '<div class="fold" data-testid="plan-picked"><span class="mk">\u203A</span> check \u00B7 ' + escapeXml(p) + byTag("you") + "</div>"; });
3942
4087
  (l.checks || []).forEach(function(c){ h += checkLine(c); });
3943
4088
  (l.always || []).forEach(function(g){ h += '<div class="fold" data-testid="plan-always"><span class="mk">\u203A</span> check \u00B7 always-on: ' + escapeXml(g) + "</div>"; });
3944
4089
  (l.refused || []).forEach(function(r){ h += '<div class="fold" data-testid="plan-refused"><span class="mk">\u203A</span> not checked \u00B7 ' + escapeXml(r) + "</div>"; });
@@ -3955,6 +4100,7 @@
3955
4100
  h += fold("Not checked (the AI's own reading)", plan.notChecked, "plan-notchecked");
3956
4101
  h += fold("How the page was read", plan.readNotes, "plan-readnotes");
3957
4102
  h += fold("Always checked", plan.alwaysOn, "plan-alwayson");
4103
+ if(plan.ticketFilter) h += '<div class="fold" data-testid="plan-ticketfilter"><span class="mk">\u203A</span> ticket filter \u00B7 ' + escapeXml(plan.ticketFilter) + "</div>";
3958
4104
  return h + "</div>";
3959
4105
  }
3960
4106
 
@@ -3989,6 +4135,17 @@
3989
4135
  ? ins.map(function(i){ return '<div><span class="num-in">' + escapeXml(String(i.n)) + "</span> " + escapeXml(i.label + ": " + i.value) + "</div>"; }).join("")
3990
4136
  : "not recorded";
3991
4137
  document.getElementById("details-signed").textContent = job.signed || "not recorded";
4138
+ // piece 8 (fwd am4): a job with an MCP shows its signed flow type, server and tools (and a ticket filter / watched fields when it has them); a plain job shows no MCP row
4139
+ var mcpField = document.getElementById("details-mcp-field"), mcpBox = document.getElementById("details-mcp");
4140
+ mcpBox.innerHTML = "";
4141
+ var mcpJob = job.mcp && typeof job.mcp === "object" ? job.mcp : null;
4142
+ mcpField.hidden = mcpJob === null;
4143
+ if(mcpJob !== null){
4144
+ var rows = ["flow type \u00b7 " + mcpJob.flowType, "MCP \u00b7 " + mcpJob.server].concat((mcpJob.tools || []).map(function(t){ return "tools \u00b7 " + t; }));
4145
+ if(mcpJob.ticketFilter) rows.push("ticket filter \u00b7 " + (mcpJob.ticketFilterWords || JSON.stringify(mcpJob.ticketFilter)));
4146
+ if(Array.isArray(mcpJob.ticketWatch)) rows.push("watched field \u00b7 " + mcpJob.ticketWatch.join(", "));
4147
+ rows.forEach(function(r){ var d = document.createElement("div"); d.textContent = r; mcpBox.appendChild(d); });
4148
+ }
3992
4149
  document.getElementById("details-dest").textContent = job.destination;
3993
4150
  document.getElementById("details-tools").textContent = job.tools;
3994
4151
  document.getElementById("details-cap-money").textContent = panelMoney(job.budgetUsd);
@@ -3998,7 +4155,7 @@
3998
4155
  paintOfferedRow();
3999
4156
  }
4000
4157
 
4001
- // ---- Result tab (PRD v1.107 Part 6, rubric jobs only; signed visual design/result-tab-mock.html variant F) ----
4158
+ // ---- Result tab (PRD v1.107 Part 6, rubric jobs; every other ended job wears the generic tab below, R7b item 4; signed visual design/result-tab-mock.html variant F) ----
4002
4159
  // The server decides everything: `detail.hasResult` shows the tab, `/result` carries the signed lines, the facts' own sentences
4003
4160
  // (src/facts.js factSentence), the rows of the delivered file (sha256-checked against the run's own record) and `passed` (read from the
4004
4161
  // run's own check-run). The page only draws; it never decides a check and never searches a quote for a word.
@@ -4006,7 +4163,8 @@
4006
4163
  var resultData = null;
4007
4164
  function resultTabShown(){ return document.getElementById("tab-result").getAttribute("aria-selected") === "true"; }
4008
4165
  function clearResult(){
4009
- resultDetail = null; resultData = null;
4166
+ resultDetail = null; resultData = null; resultGrid = null; gridRowData = {};
4167
+ gridUi = { open: {}, rows: {}, anyway: null, msg: "", ownFor: null, focusAnyway: false };
4010
4168
  document.getElementById("result-body").hidden = true;
4011
4169
  document.getElementById("result-body").innerHTML = "";
4012
4170
  document.getElementById("result-empty").hidden = false;
@@ -4028,9 +4186,13 @@
4028
4186
  if(!show) clearResult();
4029
4187
  }
4030
4188
  function loadResult(runid){
4031
- return getJSON("/api/runs/" + encodeURIComponent(runid) + "/result").then(function(data){
4189
+ // R8: the job's ticket grid rides along; a job that is not a Tickets job answers 404, which is simply "no grid"
4190
+ var gridP = getJSON("/api/runs/" + encodeURIComponent(runid) + "/grid").catch(function(){ return null; });
4191
+ return Promise.all([getJSON("/api/runs/" + encodeURIComponent(runid) + "/result"), gridP]).then(function(both){
4032
4192
  if(runid !== currentRunid || !resultDetail || resultDetail.runid !== runid) return;
4033
- resultData = data;
4193
+ resultData = both[0];
4194
+ resultGrid = both[1] && Array.isArray(both[1].groups) ? both[1] : null;
4195
+ if(resultGrid) gridOpenOwn(resultGrid, runid);
4034
4196
  renderResult();
4035
4197
  }).catch(function(){ /* the tab keeps what it last drew */ });
4036
4198
  }
@@ -4119,6 +4281,74 @@
4119
4281
  (line.kind === "facts" ? resultFactsLine(line) : resultTextLine(line)) +
4120
4282
  resultNotChecked("Not checked", line.notChecked, "result-line-notchecked") + '</div>';
4121
4283
  }
4284
+ // ---- the generic Result tab (R7b item 4): every ended non-rubric run. The server sends the facts and the words (`kind: "generic"`); the page only draws.
4285
+ // The check words and numbers are the Run/Audit tabs' own owners (stageQuestionText, stageNumberText); the state word is the status table's (the server sends it).
4286
+ // a unified diff, one span per line: + added, - removed, anything else (headers, hunks, context) dim. Every piece is escaped.
4287
+ function resultDiffHtml(diff){
4288
+ return String(diff).split("\n").map(function(l){
4289
+ var cls = (l.charAt(0) === "+" && l.indexOf("+++") !== 0) ? "rs-add" : ((l.charAt(0) === "-" && l.indexOf("---") !== 0) ? "rs-del" : "rs-ctx");
4290
+ return '<span class="' + cls + '">' + escapeXml(l) + '</span>';
4291
+ }).join("\n");
4292
+ }
4293
+ function resultTicketCard(t){
4294
+ if(!t) return "";
4295
+ var link = typeof t.url === "string" && /^https?:\/\//i.test(t.url)
4296
+ ? '<div class="hint"><a data-testid="result-ticket-link" href="' + escapeXml(t.url) + '" target="_blank" rel="noopener noreferrer">' + escapeXml(t.url) + '</a></div>' : "";
4297
+ return '<div class="job-card" data-testid="result-ticket"><h4>The ticket</h4><div class="field"><div class="ro-value" data-testid="result-ticket-title" style="color:var(--text)">#' + escapeXml(String(t.number)) +
4298
+ ' &middot; ' + escapeXml(t.title || "") + '</div>' + link + '</div></div>';
4299
+ }
4300
+ function resultJobCard(job){
4301
+ return '<div class="job-card" data-testid="result-job"><h4>The job</h4>' +
4302
+ resultField("What it was asked", '<div class="ro-value" data-testid="result-asked" style="white-space:pre-wrap">' + escapeXml(job.asked) + '</div>') +
4303
+ (Array.isArray(job.scope) && job.scope.length ? resultField("Where it may change files", '<div class="ro-value" data-testid="result-scope">' + escapeXml(job.scope.join(", ")) + '</div>') : "") + '</div>';
4304
+ }
4305
+ function resultChangedCard(c){
4306
+ if(!c) return '<div class="job-card" data-testid="result-changed"><h4>What changed</h4><div class="hint" data-testid="result-changed-none">no edit was recorded for this run</div></div>';
4307
+ var last = c.last.files.map(function(f){ return resultDiffHtml(f.diff); }).join("\n") + (c.last.note ? '\n<span class="rs-ctx">' + escapeXml(c.last.note) + '</span>' : "");
4308
+ var all = c.all.map(function(e){
4309
+ return '<div class="hint">edit ' + e.n + (e.step ? ' &middot; ' + escapeXml(e.step) : "") + '</div>' + e.files.map(function(f){
4310
+ return '<pre class="rs-diff">' + resultDiffHtml(f.diff) + (f.cutNote ? '\n<span class="rs-ctx">' + escapeXml(f.cutNote) + '</span>' : "") + '</pre>';
4311
+ }).join("");
4312
+ }).join("");
4313
+ return '<div class="job-card" data-testid="result-changed"><h4>What changed</h4>' +
4314
+ resultField(c.head, '<div class="ro-value"><pre class="rs-diff" data-testid="result-diff">' + last + '</pre></div>') +
4315
+ '<details data-testid="result-all-edits"><summary>' + escapeXml(c.foldWords) + '</summary><div class="ro-value">' + all + '</div></details>' +
4316
+ (c.scopeLine ? '<div class="hint" data-testid="result-scopeline">' + escapeXml(c.scopeLine) + '</div>' : "") + '</div>';
4317
+ }
4318
+ // a check the STEPS ran (the close never did) says how many times its step tried; a close stage has no `tries`
4319
+ function stageTriedText(s){ return !s.passed && typeof s.tries === "number" && s.tries > 1 ? " (tried " + s.tries + " times)" : ""; }
4320
+ function resultChecksCard(k){
4321
+ if(!k) return '<div class="job-card" data-testid="result-checks"><h4>The checks</h4><div class="hint" data-testid="result-checks-none">the close did not run any check for this run</div></div>';
4322
+ var rows = k.stages.map(function(s){
4323
+ var num = stageNumberText(s);
4324
+ return '<div class="rs-check" data-testid="result-check"><span class="rs-q">' + escapeXml(stageQuestionText(s)) + '</span><span class="rs-num hint" data-testid="result-check-num">' +
4325
+ (num ? escapeXml(num) : "") + escapeXml(stageTriedText(s)) + '</span><span class="rs-sign">' + stateDotHTML(s.passed ? "green" : "red", s.status.word, "result-check-state") + '</span></div>';
4326
+ }).join("");
4327
+ var notes = k.notes.length ? '<details data-testid="result-close-notes"><summary>the close\'s own notes</summary><div class="ro-value" style="white-space:pre-wrap">' +
4328
+ k.notes.map(function(n){ return escapeXml(n.text); }).join("\n") + '</div></details>' : "";
4329
+ return '<div class="job-card" data-testid="result-checks"><h4>The checks</h4>' +
4330
+ resultField(k.head, '<div class="ro-value" data-testid="result-check-list">' + rows + '</div>') + notes + '</div>';
4331
+ }
4332
+ function resultWorkCard(w){
4333
+ if(!w) return "";
4334
+ return '<div class="job-card" data-testid="result-work"><h4>The work</h4>' +
4335
+ resultField("Branch", '<div class="ro-value" data-testid="result-branch">' + escapeXml(w.branch) + ' <span class="hint">&middot; final commit ' + escapeXml(w.finalCommit) + (w.madeFrom ? ' &middot; made from ' + escapeXml(w.madeFrom) : "") + '</span></div>') +
4336
+ resultField("In", '<div class="ro-value" data-testid="result-repo">' + escapeXml(w.repo) + '</div>') +
4337
+ resultField("Keep the work", '<div class="ro-value" data-testid="result-merge">' + escapeXml(w.merge) + '</div>') +
4338
+ resultField("Throw it away", '<div class="ro-value" data-testid="result-drop">' + escapeXml(w.drop) + '</div>') +
4339
+ '<div class="hint" data-testid="result-work-note">' + escapeXml(w.note) + '</div></div>';
4340
+ }
4341
+ function resultRunCard(run){
4342
+ return '<div class="job-card" data-testid="result-run"><h4>The run</h4><div class="field-row">' +
4343
+ resultField("Spent", '<div class="ro-value" data-testid="result-spent">' + escapeXml(run.spent) + (run.spentNote ? ' <span class="hint">(' + escapeXml(run.spentNote) + ')</span>' : "") + '</div>') +
4344
+ resultField("Time", '<div class="ro-value" data-testid="result-time">' + escapeXml(run.time) + '</div>') +
4345
+ (run.steps ? resultField("Steps", '<div class="ro-value" data-testid="result-steps">' + escapeXml(run.steps) + '</div>') : "") + '</div></div>';
4346
+ }
4347
+ // the whole generic tab, top to bottom; the Your call card is the rubric tab's own resultDoorHtml, only while the run waits at the door
4348
+ function resultGenericHtml(data, detail){
4349
+ return resultTicketCard(data.ticket) + resultJobCard(data.job) + resultChangedCard(data.changed) + resultChecksCard(data.checks) + resultWorkCard(data.work) + resultRunCard(data.run) +
4350
+ (detail.accept === true && !detail.live ? resultDoorHtml(data.door) : "");
4351
+ }
4122
4352
  function resultDoorHtml(door){
4123
4353
  return '<div class="job-card" id="result-door-card" data-testid="result-door"><h4>Your call</h4><div class="field"><div class="ro-value"><b class="st-word">' + escapeXml(door.head) + '</b> \u2014 ' + escapeXml(door.ask) + '</div></div>' +
4124
4354
  '<div class="run-actions" style="margin:6px 0 0;"><button class="btn primary" type="button" data-testid="result-accept">Accept</button>' +
@@ -4161,6 +4391,165 @@
4161
4391
  }).catch(function(x){ pause.disabled = false; say("resume-err", "could not reach the panel: " + x.message, "result-door-err"); });
4162
4392
  });
4163
4393
  }
4394
+ // ---- R8 (piece 10): a TICKET job's Result tab is ONE grid instead of the five generic boxes. borrowed-from: fwdloop src/panel/index.html@v0.29.0 (the grid markup and its wiring), drawn as the signed
4395
+ // mockup (.claude/scratch/mcp-tickets/r7b/result-tab-tickets.html). The server decides every bucket, mark, name, money word and reason (`GET /api/runs/:runid/grid`, src/panel/jobgrid.js); a row opens
4396
+ // through the generic payload of THAT run (`GET /api/runs/:runid/result`, the one owner), so no diff or check is read twice. Pure functions take the state they draw (`ui`, `rowData`, `cur`).
4397
+ var resultGrid = null;
4398
+ var gridUi = { open: {}, rows: {}, anyway: null, msg: "", ownFor: null, focusAnyway: false };
4399
+ var gridRowData = {};
4400
+ function tgMark(c){ return gridGlyph(c === "g" ? "✓" : (c === "r" ? "✗" : (c === "q" ? "?" : "·"))); }
4401
+ // no data = the panel's grey dash (the Audit grid's `cell none`), never a "?" or "unknown"
4402
+ function tgCell(cell){ if(cell.mark === "n" && !cell.text) return '<td class="c"><span class="cell none">\u2014</span></td>'; return '<td class="c">' + tgMark(cell.mark) + (cell.text ? '<span class="tg-val">' + escapeXml(cell.text) + '</span>' : "") + '</td>'; }
4403
+ // the row's own data: the open run's payload is already loaded; any other row's is fetched when it opens
4404
+ function tgRowData(runId){ return resultData && resultData.runid === runId ? resultData : (gridRowData[runId] || null); }
4405
+ // checks line of an opened row: the generic payload's stages, in the Run/Audit tabs' own question words and numbers
4406
+ function tgChecksLine(k){
4407
+ if(!k) return "checks: the close did not run any check for this run";
4408
+ var bits = k.stages.map(function(s){
4409
+ var num = stageNumberText(s);
4410
+ return s.passed ? escapeXml(stageQuestionText(s)) : gridGlyph("✗") + " " + escapeXml(stageQuestionText(s)) + (num ? " — " + escapeXml(num) : "") + escapeXml(stageTriedText(s));
4411
+ });
4412
+ return "checks: " + k.passed + " of " + k.total + " " + (k.allPassed ? gridGlyph("✓") : "") + (bits.length ? " &middot; " : "") + bits.join(" &middot; ");
4413
+ }
4414
+ // what an opened row says, top to bottom: the ticket, why it ended, what changed (+ the last diff), the checks, the work, the door (only for the run the person opened), the run id
4415
+ function tgOpenHtml(r, rd, canAct){
4416
+ var label = r.title ? r.name + " " + r.title : (r.ref || r.name);
4417
+ var link = typeof r.url === "string" && /^https?:\/\//i.test(r.url) ? ' &middot; <a data-testid="grid-ticket-link" class="link" href="' + escapeXml(r.url) + '" target="_blank" rel="noopener noreferrer">' + escapeXml(r.url) + '</a>' : "";
4418
+ var h = '<div class="tg-line" data-testid="grid-ticket"><b>' + escapeXml(label) + '</b>' + link + '</div>';
4419
+ var why = rd && typeof rd.endedWords === "string" && rd.endedWords !== "" ? rd.endedWords : r.reason;
4420
+ if(r.bucket === "stop" || (r.bucket === "wait" && r.status.key === "running")) h += '<div class="tg-line" data-testid="grid-why">' + escapeXml(r.status.word) + (why ? ": " + escapeXml(why) : "") + '</div>';
4421
+ if(r.unsure) h += '<div class="tg-line hint" data-testid="grid-unsure-line">' + escapeXml(r.unsureSay || "") + '</div>';
4422
+ if(!rd) h += '<div class="tg-line hint" data-testid="grid-loading">loading this run…</div>';
4423
+ else if(rd.none) h += "";
4424
+ else if(rd.kind !== "generic") h += '<div class="tg-line hint" data-testid="grid-own-result">this run’s own result is on its page: open it with the run id below.</div>';
4425
+ else {
4426
+ var c = rd.changed;
4427
+ if(c){
4428
+ var shown = c.paths.length > 4 ? c.paths.slice(0, 4).join(", ") + " and " + (c.paths.length - 4) + " more" : c.paths.join(", ");
4429
+ h += '<div class="tg-line" data-testid="grid-changed">changed: ' + escapeXml(shown) + " (+" + c.plus + " −" + c.minus + ")</div>" +
4430
+ '<div class="tg-line"><pre class="rs-diff" data-testid="grid-diff">' + c.last.files.map(function(f){ return resultDiffHtml(f.diff); }).join("\n") + (c.last.note ? '\n<span class="rs-ctx">' + escapeXml(c.last.note) + '</span>' : "") + '</pre></div>';
4431
+ } else h += '<div class="tg-line" data-testid="grid-changed">no edit was recorded for this run</div>';
4432
+ h += '<div class="tg-line" data-testid="grid-checks">' + tgChecksLine(rd.checks) + '</div>';
4433
+ if(rd.work) h += '<div class="tg-line" data-testid="grid-work">work: branch ' + escapeXml(rd.work.branch) + ' &middot; <code>' + escapeXml(rd.work.merge) + '</code> &middot; <code>' + escapeXml(rd.work.drop) + '</code></div>';
4434
+ if(canAct) h += resultDoorHtml(rd.door);
4435
+ }
4436
+ if(r.needs === "Accept" && !canAct) h += '<div class="tg-line hint" data-testid="grid-door-elsewhere">this run waits for your answer: open it with the run id below.</div>';
4437
+ return h + '<div class="tg-line"><button class="tk-rl" type="button" data-testid="ticket-run" data-run="' + escapeXml(r.runId) + '">' + escapeXml(r.runId) + '</button></div>';
4438
+ }
4439
+ function tgRowHTML(r, ui, cur){
4440
+ var skip = r.bucket === "skip";
4441
+ var open = skip || !!ui.rows[r.runId];
4442
+ var label = r.title ? r.name + " · " + r.title : r.name;
4443
+ var nameBtn = '<button class="tg-name" type="button" data-testid="grid-name" data-run="' + escapeXml(r.runId) + '" title="' + escapeXml(label) + '">' + escapeXml(label) + '</button>';
4444
+ var h = '<tr data-testid="grid-row" data-run="' + escapeXml(r.runId) + '"><td class="r"><div class="tg-rowname">' + (skip ? "" :
4445
+ '<button class="q-fold tg-arrow" type="button" data-testid="grid-open" data-run="' + escapeXml(r.runId) + '" aria-label="show ' + escapeXml(r.ref || r.name) + '" aria-expanded="' + open + '"></button>') + nameBtn +
4446
+ (r.unsure ? '<span class="badge grey tg-unsure" data-testid="grid-unsure" title="' + escapeXml(r.unsureSay || "") + '">unsure</span>' : "") + '</div></td>' +
4447
+ tgCell(r.steps) + tgCell(r.checks) + tgCell(r.cost) + tgCell(r.time) + '</tr>';
4448
+ if(skip){
4449
+ var mine = ui.anyway && ui.anyway.number === r.number;
4450
+ h += '<tr class="step-sub"><td colspan="5"><div class="tg-skipwhy"><span class="badge grey">' + escapeXml(r.status.word) + '</span><span data-testid="ticket-reason">' + escapeXml(r.reason || "") + '</span>' +
4451
+ (r.anyway && !mine ? '<button class="btn small" type="button" data-testid="ticket-anyway-open" data-number="' + r.number + '">Run it anyway</button>' : "") + '</div>';
4452
+ if(r.anyway && mine){
4453
+ h += '<div class="tk-anyway" data-testid="ticket-anyway-box"><textarea data-testid="ticket-anyway-text" aria-label="reason (needed to run it anyway)" placeholder="reason (needed to run it anyway)">' + escapeXml(ui.anyway.text) + '</textarea>' +
4454
+ '<button class="btn small" type="button" data-testid="ticket-anyway-go"' + (ui.anyway.text.trim() === "" ? " disabled" : "") + '>Run it anyway</button></div>';
4455
+ }
4456
+ h += '</td></tr>';
4457
+ } else if(open){
4458
+ h += '<tr class="step-sub"><td colspan="5">' + tgOpenHtml(r, tgRowData(r.runId), !!(cur && cur.runid === r.runId && cur.accept === true && !cur.live)) + '</td></tr>';
4459
+ }
4460
+ return h;
4461
+ }
4462
+ function tgStatsHTML(g){
4463
+ var c = g.stats.counts;
4464
+ return '<p class="tg-stats" data-testid="grid-stats">' + g.groups.map(function(b){ return '<b>' + c[b.key] + '</b> ' + escapeXml(b.label.toLowerCase()); }).join(" · ") + ' · spent <b>' + escapeXml(g.stats.spent) + '</b></p>';
4465
+ }
4466
+ function tgTableHTML(g, ui, cur){
4467
+ var h = '<div class="grid-wrap"><table class="grid tg" data-testid="grid-table"><thead><tr><th class="r">run</th><th class="t">steps<span class="hint">done</span></th><th class="t">checks<span class="hint">the close’s</span></th><th class="t">cost</th><th class="t">time</th></tr></thead><tbody>';
4468
+ g.groups.forEach(function(b){
4469
+ var open = ui.open[b.key] === undefined ? b.open : ui.open[b.key];
4470
+ h += '<tr class="tg-grp"><td colspan="5"><button class="tg-fold" type="button" data-testid="grid-fold-' + b.key + '" data-group="' + b.key + '" aria-expanded="' + open + '"><span class="tg-foldin">' + (open ? "▾" : "▸") + " " + escapeXml(b.label) + " (" + b.rows.length + ")</span></button></td></tr>";
4471
+ if(open) h += b.rows.map(function(r){ return tgRowHTML(r, ui, cur); }).join("");
4472
+ });
4473
+ return h + '</tbody></table></div>';
4474
+ }
4475
+ function gridCardHTML(g, ui, cur){
4476
+ return '<div class="audit-group" data-testid="result-grid"><h4><span class="badge grey">tickets</span></h4>' + tgStatsHTML(g) +
4477
+ (g.scheduleLine ? '<div class="hint" style="margin-bottom:6px" data-testid="grid-schedule">' + escapeXml(g.scheduleLine) + '</div>' : "") +
4478
+ '<div id="grid-host" data-testid="grid-host">' + tgTableHTML(g, ui, cur) + '</div><div class="tk-msg" id="ticket-msg" data-testid="ticket-msg">' + escapeXml(ui.msg) + '</div>' +
4479
+ '<div class="hint">newest first inside each bucket</div></div>';
4480
+ }
4481
+ // the grid opens with the row of the run the person came from, in its bucket, once per run
4482
+ function gridOpenOwn(g, runid){
4483
+ if(gridUi.ownFor === runid) return;
4484
+ gridUi.ownFor = runid;
4485
+ g.groups.forEach(function(b){ b.rows.forEach(function(r){ if(r.runId === runid){ gridUi.rows[runid] = true; gridUi.open[b.key] = true; } }); });
4486
+ }
4487
+ function gridRepaint(){
4488
+ var body = document.getElementById("result-body");
4489
+ var keepText = body.querySelector("#result-rerun-text");
4490
+ var typed = keepText ? keepText.value : "";
4491
+ var rerunOpen = !!body.querySelector("#result-rerun-box:not([hidden])");
4492
+ paintResultBody(body, gridCardHTML(resultGrid, gridUi, resultDetail), resultDetail, typed, rerunOpen);
4493
+ var ta = body.querySelector("[data-testid=ticket-anyway-text]");
4494
+ if(ta && gridUi.focusAnyway){ ta.focus(); ta.setSelectionRange(ta.value.length, ta.value.length); }
4495
+ }
4496
+ function gridClick(ev){
4497
+ var g = resultGrid;
4498
+ if(!g) return;
4499
+ var t = ev.target.closest ? ev.target.closest("button") : null;
4500
+ var host = document.getElementById("grid-host");
4501
+ if(!t || !host || !host.contains(t)) return;
4502
+ var tid = t.getAttribute("data-testid") || "";
4503
+ if(t.hasAttribute("data-group")){
4504
+ var k = t.getAttribute("data-group");
4505
+ var cur = g.groups.filter(function(x){ return x.key === k; })[0];
4506
+ gridUi.open[k] = !(gridUi.open[k] === undefined ? cur.open : gridUi.open[k]);
4507
+ gridRepaint();
4508
+ } else if(tid === "grid-open"){
4509
+ var id = t.getAttribute("data-run");
4510
+ gridUi.rows[id] = !gridUi.rows[id];
4511
+ gridRepaint();
4512
+ if(gridUi.rows[id] && !tgRowData(id)){
4513
+ getJSON("/api/runs/" + encodeURIComponent(id) + "/result").then(function(d){ gridRowData[id] = d; }).catch(function(){ gridRowData[id] = { runid: id, none: true, kind: "none" }; }).then(function(){ if(resultGrid === g) gridRepaint(); });
4514
+ }
4515
+ } else if(tid === "grid-name" || tid === "ticket-run"){
4516
+ selectRun(t.getAttribute("data-run")); document.getElementById("tab-run").click();
4517
+ } else if(tid === "ticket-anyway-open"){
4518
+ var n = Number(t.getAttribute("data-number"));
4519
+ gridUi.anyway = (gridUi.anyway && gridUi.anyway.number === n) ? null : { number: n, text: "" };
4520
+ gridUi.msg = ""; gridUi.focusAnyway = true; gridRepaint();
4521
+ } else if(tid === "ticket-anyway-go"){
4522
+ var a = gridUi.anyway;
4523
+ var msg = document.getElementById("ticket-msg");
4524
+ if(!a || a.text.trim() === ""){ gridUi.msg = "Please write a reason to run it anyway."; msg.textContent = gridUi.msg; return; }
4525
+ t.disabled = true;
4526
+ var anchor = g.runid;
4527
+ authorPost("/api/author/ticket-anyway", { job: g.job, ticket: a.number, reason: a.text.trim() }).then(function(r){
4528
+ var ok = r.status >= 200 && r.status < 300 && r.body && r.body.ok === true;
4529
+ gridUi.msg = (r.body && (r.body.say || r.body.error)) || (ok ? "Queued." : "Not queued. Nothing started.");
4530
+ if(ok){ gridUi.anyway = null; refreshRunsList(true); setTimeout(function(){ if(currentRunid === anchor) loadResult(anchor); }, 1500); }
4531
+ gridRepaint();
4532
+ }).catch(function(){ gridUi.msg = "Could not reach the panel. Nothing started."; document.getElementById("ticket-msg").textContent = gridUi.msg; t.disabled = false; });
4533
+ }
4534
+ }
4535
+ function gridWire(body){
4536
+ if(body.getAttribute("data-grid-wired") === "1") return;
4537
+ body.setAttribute("data-grid-wired", "1");
4538
+ body.addEventListener("click", gridClick);
4539
+ body.addEventListener("input", function(ev){
4540
+ var ta = ev.target;
4541
+ if(!resultGrid || !ta || !ta.getAttribute || ta.getAttribute("data-testid") !== "ticket-anyway-text" || !gridUi.anyway) return;
4542
+ gridUi.anyway.text = ta.value;
4543
+ var go = body.querySelector("[data-testid=ticket-anyway-go]");
4544
+ if(go) go.disabled = ta.value.trim() === "";
4545
+ });
4546
+ body.addEventListener("keydown", function(ev){
4547
+ if(ev.key !== "Escape" || !resultGrid || !ev.target.getAttribute || ev.target.getAttribute("data-testid") !== "ticket-anyway-text") return;
4548
+ gridUi.anyway = null; gridUi.focusAnyway = false; gridUi.msg = ""; gridRepaint();
4549
+ });
4550
+ body.addEventListener("focusin", function(ev){ if(ev.target.getAttribute && ev.target.getAttribute("data-testid") === "ticket-anyway-text") gridUi.focusAnyway = true; });
4551
+ body.addEventListener("focusout", function(ev){ if(ev.target.getAttribute && ev.target.getAttribute("data-testid") === "ticket-anyway-text") gridUi.focusAnyway = false; });
4552
+ }
4164
4553
  function renderResult(){
4165
4554
  var detail = resultDetail, data = resultData;
4166
4555
  var body = document.getElementById("result-body");
@@ -4171,6 +4560,9 @@
4171
4560
  var keepText = body.querySelector("#result-rerun-text");
4172
4561
  var typed = keepText ? keepText.value : "";
4173
4562
  var rerunOpen = !!body.querySelector("#result-rerun-box:not([hidden])");
4563
+ // R8: a TICKET job shows its one grid instead (the generic boxes and the rubric tab stay for every other job)
4564
+ if(resultGrid && resultGrid.runid === detail.runid){ gridWire(body); paintResultBody(body, gridCardHTML(resultGrid, gridUi, detail), detail, typed, rerunOpen); return; }
4565
+ if(data.kind === "generic"){ paintResultBody(body, resultGenericHtml(data, detail), detail, typed, rerunOpen); return; }
4174
4566
  var counters = document.getElementById("run-counters").textContent.split(" \u00b7 ");
4175
4567
  var h = '<div class="job-card" data-testid="result-head"><h4>Result</h4>' +
4176
4568
  resultField("Status", '<div class="ro-value">' + stateDotHTML(glyphClass(detail.glyph), detail.status && detail.status.word ? detail.status.word : "", "result-status") +
@@ -4197,6 +4589,10 @@
4197
4589
  : '<div class="run-actions" style="margin:6px 0 0;"><a class="btn" style="text-decoration:none;" data-testid="result-download" download href="/api/runs/' + encodeURIComponent(data.runid) + '/download?i=' + d.i + '">Download ' + escapeXml(d.name) + '</a></div>'));
4198
4590
  }).join("") + '</div>';
4199
4591
  }
4592
+ paintResultBody(body, h, detail, typed, rerunOpen);
4593
+ }
4594
+ // the one tail of both Result tabs: draw, then put back what the person was typing and wire the door
4595
+ function paintResultBody(body, h, detail, typed, rerunOpen){
4200
4596
  body.innerHTML = h;
4201
4597
  var ta = body.querySelector("#result-rerun-text");
4202
4598
  if(ta){
@@ -4486,6 +4882,7 @@
4486
4882
  settingsView.hidden = false;
4487
4883
  loadProviders(true);
4488
4884
  loadMoney();
4885
+ loadMcp();
4489
4886
  });
4490
4887
  document.getElementById("settings-back").addEventListener("click", function(){
4491
4888
  settingsView.hidden = true;
@@ -4813,7 +5210,137 @@
4813
5210
  }
4814
5211
 
4815
5212
  document.getElementById("tab-providers").addEventListener("click", function(){ loadProviders(); });
4816
- wireTabs([document.getElementById("tab-providers"), document.getElementById("tab-money")]);
5213
+
5214
+ // ---- Settings > MCP (piece 7; borrowed-from fwdloop src/panel/index.html@d71846c). One list "Path and MCP": a path is a header, its MCPs sit under it.
5215
+ // The page only READS: GET /api/settings/mcp (names, flags, counts; never a command or a key) and, on a press, POST .../mcp-check for that one MCP.
5216
+ var mcpRoot = document.getElementById("mcp-paths");
5217
+ var mcpData = null;
5218
+ var mcpPathFold = {}; // path -> false when folded (paths start open)
5219
+ var mcpSrvOpen = {}; // path + tab + name -> true when open (MCPs start folded)
5220
+ var mcpMoreOpen = {};
5221
+ var mcpBusy = {};
5222
+ var mcpFail = {}; // path + tab + name -> the sentence of a press that was refused
5223
+ var MCP_TOOLS_SHOWN = 5;
5224
+ function loadMcp(){
5225
+ return authorGet("/api/settings/mcp").then(function(d){
5226
+ if(!d || !d.ok){ setNote(document.getElementById("mcp-problem"), true, "Could not read your MCP list. Reload the page."); return; }
5227
+ mcpData = d; setNote(document.getElementById("mcp-problem"), true, d.problem || ""); paintMcp();
5228
+ }, function(){ setNote(document.getElementById("mcp-problem"), true, networkText()); });
5229
+ }
5230
+ function mcpClock(iso){
5231
+ var d = new Date(iso);
5232
+ if(isNaN(d.getTime())) return "";
5233
+ var two = function(n){ return ("0" + n).slice(-2); };
5234
+ var hm = two(d.getHours()) + ":" + two(d.getMinutes());
5235
+ var now = new Date();
5236
+ if(d.getFullYear() === now.getFullYear() && d.getMonth() === now.getMonth() && d.getDate() === now.getDate()) return { today: true, text: hm };
5237
+ return { today: false, text: d.getFullYear() + "-" + two(d.getMonth() + 1) + "-" + two(d.getDate()) + " " + hm };
5238
+ }
5239
+ function mcpUseLine(u){
5240
+ if(!u || (u.calls === 0 && u.denied === 0)) return "never used";
5241
+ var t = "used " + u.calls + (u.calls === 1 ? " time" : " times") + (u.calls > 0 ? " in " + u.runs + (u.runs === 1 ? " run" : " runs") : "");
5242
+ var c = u.last ? mcpClock(u.last) : "";
5243
+ if(c) t += " · last used " + (c.today ? "today " : "") + c.text;
5244
+ return '<span>' + escapeXml(t) + ' · <span class="' + (u.denied > 0 ? "bad" : "") + '">' + u.denied + ' denied</span></span>';
5245
+ }
5246
+ function mcpSrvHtml(s, pi, si, place){
5247
+ var key = place.path + "\t" + s.name;
5248
+ var open = mcpSrvOpen[key] === true;
5249
+ var ok = s.check && s.check.ok === true;
5250
+ var idle = s.remote || s.shadowedBy !== null;
5251
+ var tools = s.remote ? '<span class="hint">remote server, not supported yet</span>' : s.shadowedBy !== null ? '<span class="hint">same name as above, not used</span>' : idle ? "—" : ok ? s.check.tools.length + (s.check.tools.length === 1 ? " tool" : " tools") : s.check ? "—" : "never checked";
5252
+ var at = s.check ? mcpClock(s.check.at) : "";
5253
+ var checked = idle ? "—" : s.check ? "checked " + (at ? at.text : "") : "never checked";
5254
+ var busy = mcpBusy[key] === true;
5255
+ var btn = idle ? "" : (busy ? '<button class="btn small pv-refbtn" type="button" disabled>checking…</button>' : '<button class="btn small pv-refbtn' + (s.check ? "" : " primary") + '" type="button" data-chk="' + pi + "-" + si + '" data-testid="mcp-check">check tools</button>');
5256
+ var use = idle ? "" : mcpUseLine(s.use);
5257
+ var list = "";
5258
+ if(ok){
5259
+ var more = mcpMoreOpen[key] === true;
5260
+ var shown = more ? s.check.tools : s.check.tools.slice(0, MCP_TOOLS_SHOWN);
5261
+ list = '<div class="pv-mhead mc-t" aria-hidden="true"><span>TOOL</span><span>HINT</span><span class="n">USED</span></div>' +
5262
+ shown.map(function(t){
5263
+ var n = (s.use && s.use.tools && Object.prototype.hasOwnProperty.call(s.use.tools, t.name)) ? s.use.tools[t.name] : 0;
5264
+ return '<div class="pv-mrow mc-t" tabindex="-1" data-testid="mcp-tool"><span class="pv-m-name"><code>' + escapeXml(t.name) + '</code></span><span>' + escapeXml(t.hint || "—") + '</span><span class="n">' + n + '</span></div>';
5265
+ }).join("") +
5266
+ (s.check.tools.length > shown.length ? '<div class="pv-more"><button class="pv-add" type="button" data-more="' + pi + "-" + si + '">+' + (s.check.tools.length - shown.length) + ' more</button></div>' : "");
5267
+ } else if(s.check) list = '<div class="pv-more"><span class="hint bad">' + escapeXml(s.check.error || "") + '</span></div>';
5268
+ else if(!idle) list = '<div class="pv-more"><span class="hint">Press check tools to list its tools.</span></div>';
5269
+ if(mcpFail[key]) list += '<div class="pv-more"><span class="hint bad">' + escapeXml(mcpFail[key]) + '</span></div>';
5270
+ return '<div class="pv-key' + (s.shadowedBy !== null ? " faint" : "") + '" data-open="' + (open ? 1 : 0) + '" data-testid="mcp-row">' +
5271
+ '<div class="pv-krow mc-k">' +
5272
+ '<div class="pv-cell pv-name nolbl"><button class="pv-fold" type="button" data-fold="' + pi + "-" + si + '" aria-expanded="' + open + '">' + (open ? "▾" : "▸") + '</button><code>' + escapeXml(s.name) + '</code></div>' +
5273
+ '<div class="pv-cell"><span class="pv-lbl">Tools</span><span>' + tools + (busy ? ' <span class="mc-spin">…</span>' : "") + '</span></div>' +
5274
+ '<div class="pv-cell"><span class="pv-lbl">Checked</span><span>' + escapeXml(checked) + '</span></div>' +
5275
+ '<div class="pv-cell pv-refcell nolbl">' + btn + '</div>' +
5276
+ '</div>' +
5277
+ (use ? '<div class="hint mc-use">' + use + '</div>' : "") +
5278
+ '<div class="pv-models">' + list + '</div>' +
5279
+ '</div>';
5280
+ }
5281
+ function paintMcp(){
5282
+ if(!mcpData) return;
5283
+ var h = '<div class="pv-head mc-k" aria-hidden="true"><span>PATH / MCP</span><span>TOOLS</span><span>CHECKED</span><span></span></div>';
5284
+ mcpData.places.forEach(function(g, pi){
5285
+ var found = g.status === "found", n = g.servers.length, open = mcpPathFold[g.path] !== false;
5286
+ var note = found ? " — " + (g.added ? "(added) — " : "") + n + " server" + (n === 1 ? "" : "s") : " — " + (g.added ? "(added) — " : "") + (g.status === "not-json" ? "can't be read" : "not found");
5287
+ h += '<div class="mc-grp" data-open="' + (open ? 1 : 0) + '" data-testid="mcp-path"><div class="mc-prow' + (found ? "" : " faint") + '">' +
5288
+ (found ? '<button class="pv-fold" type="button" data-pfold="' + pi + '" aria-expanded="' + open + '">' + (open ? "▾" : "▸") + '</button><span class="pv-ok">✓</span>' : '<span class="pv-fold" style="display:inline-block">&nbsp;</span><span>–</span>') +
5289
+ '<span class="mc-grow"><code>' + escapeXml(g.path) + '</code>' + escapeXml(note) + '</span>' +
5290
+ (g.added ? '<button class="btn small" type="button" data-rm="' + pi + '" data-testid="mcp-remove">remove</button>' : "") + '</div>' +
5291
+ (found ? '<div class="mc-kids">' + g.servers.map(function(s, si){ return mcpSrvHtml(s, pi, si, g); }).join("") + '</div>' : "") + '</div>';
5292
+ });
5293
+ mcpRoot.innerHTML = h;
5294
+ }
5295
+ function mcpAt(id){ var a = id.split("-"); var g = mcpData.places[+a[0]]; return { place: g, srv: g.servers[+a[1]] }; }
5296
+ mcpRoot.addEventListener("click", function(e){
5297
+ if(!mcpData) return;
5298
+ var pf = e.target.closest("[data-pfold]");
5299
+ if(pf){ var g = mcpData.places[+pf.getAttribute("data-pfold")]; mcpPathFold[g.path] = mcpPathFold[g.path] === false; paintMcp(); return; }
5300
+ var r = e.target.closest("[data-rm]");
5301
+ if(r){
5302
+ var path = mcpData.places[+r.getAttribute("data-rm")].path;
5303
+ authorPost("/api/settings/mcp-path-remove", { path: path }).then(function(res){
5304
+ if(res.body && res.body.ok) loadMcp(); else setNote(document.getElementById("mcp-problem"), true, settingsRefusal(res));
5305
+ }, function(){ setNote(document.getElementById("mcp-problem"), true, networkText()); });
5306
+ return;
5307
+ }
5308
+ var f = e.target.closest("[data-fold]");
5309
+ if(f){ var x = mcpAt(f.getAttribute("data-fold")); var k = x.place.path + "\t" + x.srv.name; mcpSrvOpen[k] = mcpSrvOpen[k] !== true; paintMcp(); return; }
5310
+ var m = e.target.closest("[data-more]");
5311
+ if(m){ var y = mcpAt(m.getAttribute("data-more")); mcpMoreOpen[y.place.path + "\t" + y.srv.name] = true; paintMcp(); return; }
5312
+ var c = e.target.closest("[data-chk]");
5313
+ if(c){
5314
+ var z = mcpAt(c.getAttribute("data-chk")); var key = z.place.path + "\t" + z.srv.name;
5315
+ mcpBusy[key] = true; delete mcpFail[key]; paintMcp();
5316
+ authorPost("/api/settings/mcp-check", { server: z.srv.name }).then(function(res){
5317
+ mcpBusy[key] = false;
5318
+ if(res.body && res.body.ok) mcpSrvOpen[key] = true; else mcpFail[key] = settingsRefusal(res);
5319
+ loadMcp();
5320
+ }, function(){ mcpBusy[key] = false; mcpFail[key] = networkText(); paintMcp(); });
5321
+ }
5322
+ });
5323
+ // the typed-path box is built on the first press of "+ add a path" (like the Providers tab's typed-model box)
5324
+ document.getElementById("mcp-add-open").addEventListener("click", function(){
5325
+ var b = document.getElementById("mcp-add-box");
5326
+ if(!b.firstChild){
5327
+ b.innerHTML = '<input type="text" id="mcp-add-in" data-testid="mcp-add-in" autocomplete="off" spellcheck="false" aria-label="path" placeholder="type a path to an MCP config file"> <button class="btn small" type="button" id="mcp-add-go" data-testid="mcp-add-go">Add</button><div class="hint pv-msg" id="mcp-add-msg" data-testid="mcp-add-msg"></div>';
5328
+ document.getElementById("mcp-add-go").addEventListener("click", mcpAddPath);
5329
+ }
5330
+ b.hidden = !b.hidden; if(!b.hidden) document.getElementById("mcp-add-in").focus();
5331
+ });
5332
+ function mcpAddPath(){
5333
+ var inp = document.getElementById("mcp-add-in"), msg = document.getElementById("mcp-add-msg");
5334
+ var v = inp.value.trim();
5335
+ var say = function(bad, text){ setNote(msg, bad, text); msg.className += " pv-msg"; };
5336
+ if(!v){ say(true, "Type a path first."); return; }
5337
+ authorPost("/api/settings/mcp-path", { path: v }).then(function(res){
5338
+ if(res.body && res.body.ok){ inp.value = ""; say(false, "added"); loadMcp(); }
5339
+ else say(true, settingsRefusal(res));
5340
+ }, function(){ say(true, networkText()); });
5341
+ }
5342
+ document.getElementById("tab-mcp").addEventListener("click", function(){ loadMcp(); });
5343
+ wireTabs([document.getElementById("tab-providers"), document.getElementById("tab-mcp"), document.getElementById("tab-money")]);
4817
5344
  // Auto-save on a human edit (change = blur or Enter): POST carries the per-start token; the chat has no route here
4818
5345
  limitInput.addEventListener("change", function(){
4819
5346
  var text = limitInput.value.trim();
@@ -4840,6 +5367,10 @@
4840
5367
  var mainBtn = document.getElementById("chat-main-btn");
4841
5368
  var mainHint = document.getElementById("chat-main-hint");
4842
5369
  var reopenBtn = document.getElementById("chat-reopen-btn");
5370
+ var revisesLeftEl = document.getElementById("chat-left-count");
5371
+ // R10 (fwd am17/am20): the id of the draft the next Start drafting follows; the server hands its check picks on (words-keyed), so a pick already made is not asked again
5372
+ var carryFromId = null;
5373
+ var carryKindVal = null;
4843
5374
  var mainAction = "none";
4844
5375
  var knownRunIdsAtSign = null; // the run ids listed when Sign & run was pressed (M3: afterSignRefresh waits for a new one)
4845
5376
  var lastState = null;
@@ -4849,6 +5380,15 @@
4849
5380
  var moneyCapInput = document.getElementById("jf-cap-money");
4850
5381
  var modelSelect = document.getElementById("jf-model");
4851
5382
  var thinkingBox = document.getElementById("jf-thinking");
5383
+ // piece 8 (fwd M13 p4): the card's Flow type, the MCP pick and (the by-hand Ticket box is gone: fwd v0.28.0). Declared up here: syncCardLock reads them from the first refresh on.
5384
+ var flowTypeEl = document.getElementById("jf-flowtype");
5385
+ var mcpEl = document.getElementById("jf-mcp");
5386
+ var mcpFieldEl = document.getElementById("jf-mcp-field");
5387
+ // piece 9 (R7): the Schedule row, signed with the job; off until the first green run (a rubric job: until that run is accepted)
5388
+ var cardSchedEl = document.getElementById("jf-sched");
5389
+ var cardSchedTimeEl = document.getElementById("jf-sched-time");
5390
+ var cardSchedFieldEl = document.getElementById("jf-sched-field");
5391
+ var mcpServers = []; // the MCPs Settings > MCP lists as usable (not remote, not shadowed); the page only READS the list
4852
5392
  var thinkingNote = document.getElementById("jf-thinking-note");
4853
5393
  var lineThinking = {}; // option value -> the server's {support, canChange, say} for that Model line
4854
5394
  var modelStatusEl = document.getElementById("jf-model-status");
@@ -4915,14 +5455,75 @@
4915
5455
  // the Check type radios stay clickable on a reuse card (Deterministic / Rubric = leave reuse); a live session or a resume freezes them
4916
5456
  document.querySelectorAll('input[name="jf-verdict"]').forEach(function(r){ r.disabled = live || resuming; });
4917
5457
  document.getElementById("job-card").classList.toggle("reuse", reuseOn);
5458
+ // Flow type and MCP are JOB boxes (a change drafts a new workflow): locked like the job text on a schedule card, a live session or a resume.
5459
+ var flowLocked = reuseOn || live || resuming;
5460
+ flowTypeEl.disabled = flowLocked; mcpEl.disabled = flowLocked;
5461
+ [flowTypeEl, mcpEl].forEach(function(el){ el.classList.toggle("locked", flowLocked); });
5462
+ // the Schedule is chosen before the start and signed with the job: frozen while a session is live
5463
+ cardSchedEl.disabled = live; cardSchedTimeEl.disabled = live;
5464
+ cardSchedEl.classList.toggle("locked", live); cardSchedTimeEl.classList.toggle("locked", live);
5465
+ paintFlowType();
4918
5466
  syncThinking();
4919
5467
  }
4920
5468
  function setReuseLocked(on){ reuseOn = on; syncCardLock(); }
5469
+ // ---- Flow type / MCP (piece 8). The MCP menu is Settings > MCP's usable servers; a reused job's server that is no longer listed stays pickable by name
5470
+ // (the start refuses it with its cause).
5471
+ function paintMcpOptions(want){
5472
+ var names = mcpServers.slice();
5473
+ if(want && names.indexOf(want) === -1) names.push(want);
5474
+ mcpEl.innerHTML = "";
5475
+ names.forEach(function(n){ var o = document.createElement("option"); o.value = n; o.textContent = n; mcpEl.appendChild(o); });
5476
+ if(want) mcpEl.value = want;
5477
+ }
5478
+ function paintFlowType(){
5479
+ var f = flowTypeEl.value;
5480
+ mcpFieldEl.hidden = f === "plain";
5481
+ paintCardSchedule();
5482
+ }
5483
+ // The Schedule row (fwd's three words and two hints): "When a new ticket arrives" only for a Tickets job; the time box and the hints follow the pick. A rubric job's hint says Accepted.
5484
+ // Hidden on a resume (no run starts there) and on the two-click schedule card (its own When field).
5485
+ function paintCardSchedule(){
5486
+ var tk = cardSchedEl.querySelector('option[value="new-ticket"]');
5487
+ tk.hidden = tk.disabled = flowTypeEl.value !== "tickets";
5488
+ if(cardSchedEl.value === "new-ticket" && tk.disabled) cardSchedEl.value = "hand";
5489
+ cardSchedFieldEl.hidden = resumeRun !== null || sched !== null;
5490
+ var rubric = (verdictValue() === "reuse" ? reuseCheckType : verdictValue()) === "rubric";
5491
+ document.getElementById("jf-sched-clock").hidden = cardSchedEl.value !== "daily";
5492
+ document.getElementById("jf-sched-hint").hidden = cardSchedEl.value === "hand" || rubric;
5493
+ document.getElementById("jf-sched-hint-rubric").hidden = cardSchedEl.value === "hand" || !rubric;
5494
+ document.getElementById("jf-sched-ticket-hint").hidden = cardSchedEl.value !== "new-ticket";
5495
+ }
5496
+ // the typed Schedule the card sends: null (by hand) sends nothing, so the signed job carries no trigger and hashes as before
5497
+ function scheduleOfCard(){
5498
+ if(cardSchedEl.value === "new-ticket") return {kind: "new-ticket"};
5499
+ if(cardSchedEl.value !== "daily") return null;
5500
+ var t = /^(\d{2}):(\d{2})$/.exec(cardSchedTimeEl.value || "");
5501
+ return {kind: "daily", hour: t ? Number(t[1]) : NaN, minute: t ? Number(t[2]) : NaN};
5502
+ }
5503
+ function setCardSchedule(sc){
5504
+ cardSchedEl.value = sc && sc.kind === "daily" ? "daily" : (sc && sc.kind === "new-ticket" ? "new-ticket" : "hand");
5505
+ if(sc && sc.kind === "daily" && Number.isInteger(sc.hour) && Number.isInteger(sc.minute)) cardSchedTimeEl.value = ("0" + sc.hour).slice(-2) + ":" + ("0" + sc.minute).slice(-2);
5506
+ paintCardSchedule();
5507
+ }
5508
+ function setFlow(type, server){
5509
+ flowTypeEl.value = (type === "mcp" || type === "tickets") ? type : "plain";
5510
+ paintMcpOptions(server || "");
5511
+ paintFlowType();
5512
+ }
5513
+ function loadMcpServers(){
5514
+ return authorGet("/api/settings/mcp").then(function(d){
5515
+ var names = [];
5516
+ ((d && d.places) || []).forEach(function(p){ (p.servers || []).forEach(function(sv){ if(!sv.remote && !sv.shadowedBy && names.indexOf(sv.name) === -1) names.push(sv.name); }); });
5517
+ mcpServers = names; paintMcpOptions(mcpEl.value);
5518
+ }, function(){ /* the list stays as it was; a pick the server cannot start is refused with its cause */ });
5519
+ }
4921
5520
  function clearStartFrom(keepBoxes){
4922
5521
  // Clear after a reuse starts a genuinely new job: the reused values do not linger in the boxes — except when a Check type
4923
5522
  // radio click leaves reuse (keepBoxes): a radio never blanks what the person has on the card
4924
5523
  if(startFrom && !keepBoxes){
4925
5524
  CARD_BOX_IDS.forEach(function(id){ document.getElementById(id).value = ""; });
5525
+ setFlow("plain", "");
5526
+ setCardSchedule(null);
4926
5527
  NUMBERED_IDS.forEach(gutterSync);
4927
5528
  document.querySelectorAll('input[name="jf-verdict"]').forEach(function(r){ r.checked = (r.value === "deterministic"); });
4928
5529
  }
@@ -4957,6 +5558,8 @@
4957
5558
  }
4958
5559
  function clearCardBoxes(){
4959
5560
  CARD_BOX_IDS.forEach(function(id){ document.getElementById(id).value = ""; });
5561
+ setFlow("plain", "");
5562
+ setCardSchedule(null);
4960
5563
  NUMBERED_IDS.forEach(gutterSync);
4961
5564
  document.getElementById("jf-cap-note").textContent = "";
4962
5565
  }
@@ -5074,6 +5677,8 @@
5074
5677
  // back to a fresh empty card: every box, check type deterministic, the default (first) Model, origin/estimate/notes
5075
5678
  // hidden, progress list and thread cleared, reuse lock lifted
5076
5679
  function resetCard(){
5680
+ carryFromId = null;
5681
+ carryKindVal = null;
5077
5682
  clearCardBoxes();
5078
5683
  setVerdict("deterministic");
5079
5684
  modelSelect.selectedIndex = 0;
@@ -5109,10 +5714,15 @@
5109
5714
  jobText: document.getElementById("jf-job").value.trim(),
5110
5715
  inputs: document.getElementById("jf-inputs").value.trim(),
5111
5716
  destination: document.getElementById("jf-dest").value.trim(),
5717
+ ...(carryFromId ? {carryFrom: carryFromId, carryKind: carryKindVal === "startover" ? "startover" : "revise"} : {}),
5112
5718
  // the "Thinking on" tick: sent as a boolean; the server judges it per line and signs it only when ticked
5113
5719
  thinking: thinkingBox.checked === true,
5114
5720
  capUsd: moneyCap,
5115
5721
  maxWallMs: timeCapMin === "" ? undefined : Math.round(Number(timeCapMin) * 60000),
5722
+ // piece 8: a plain job sends neither key (the signed job carries neither); a by-hand Tickets run takes the newest ticket not run yet (no box, fwd v0.28.0)
5723
+ ...(flowTypeEl.value !== "plain" ? {flowType: flowTypeEl.value, mcp: mcpEl.value} : {}),
5724
+ // piece 9: by hand sends no key (the signed job carries no trigger); a pick is signed with the job and starts OFF
5725
+ ...(scheduleOfCard() !== null ? {schedule: scheduleOfCard()} : {}),
5116
5726
  };
5117
5727
  }
5118
5728
 
@@ -5457,12 +6067,20 @@
5457
6067
  function reviseShownFor(st){
5458
6068
  return !!st.session && !!st.pendingAsk && st.pendingAsk.kind === "menu";
5459
6069
  }
6070
+ // fwd M4e am14 item 3 (pure): 2 revises per draft, shown as "2 revises left" / "1 revise left"; with none left the same button reads Start over. The SERVER counts (revisesLeft); an
6071
+ // absent number (a state from before the count) reads as 2.
6072
+ function reviseButtonFor(left){
6073
+ var n = typeof left === "number" ? Math.max(0, Math.floor(left)) : 2;
6074
+ if(n <= 0) return {text: "Start over", kind: "startover", left: ""};
6075
+ return {text: "Revise", kind: "revise", left: n + (n === 1 ? " revise left" : " revises left")};
6076
+ }
5460
6077
  function renderMain(){
5461
6078
  var st = {session: sessionLive, startOk: startOk, signClicked: signClickedOnce, whenLocked: whenLocked};
5462
6079
  if(sched){ st.when = {changed: whenChanged(), refused: !!sched.refusal, cancel: byId("jf-when").value === "hand", confirm: whenConfirm, busy: whenBusy, words: sched.words}; }
5463
6080
  if(sessionLive && lastState){
5464
6081
  st.phase = lastState.phase; st.pendingAsk = lastState.pendingAsk;
5465
6082
  st.specHash = lastState.specHash;
6083
+ st.revisesLeft = lastState.revisesLeft;
5466
6084
  }
5467
6085
  // hamr 2026-10-05: the ask box is open only while something asks for a reply; otherwise dimmed and emptied
5468
6086
  var open = askBoxOpenFor(st);
@@ -5473,7 +6091,11 @@
5473
6091
  mainBtn.disabled = b.disabled;
5474
6092
  mainAction = b.action;
5475
6093
  mainHint.textContent = b.hint;
6094
+ var rv = reviseButtonFor(st.revisesLeft);
5476
6095
  reopenBtn.hidden = !reviseShownFor(st);
6096
+ reopenBtn.textContent = rv.text;
6097
+ revisesLeftEl.textContent = rv.left;
6098
+ revisesLeftEl.hidden = !reviseShownFor(st) || rv.left === "";
5477
6099
  fitBox(msgInput);
5478
6100
  fitCardBoxes();
5479
6101
  }
@@ -5544,8 +6166,16 @@
5544
6166
  }
5545
6167
  });
5546
6168
 
6169
+ // R7b (3): "yes" to the folder question changes the SESSION's Destination; the box is locked while a session is live, so the page re-fills it from the session's own card
6170
+ function syncDestinationFromSession(state){
6171
+ var d = state && state.card && state.card.destination;
6172
+ if(typeof d !== "string") return;
6173
+ var box = document.getElementById("jf-dest");
6174
+ if(box && box.value !== d){ box.value = d; fitCardBoxes(); }
6175
+ }
5547
6176
  function renderActions(state){
5548
6177
  lastState = state;
6178
+ syncDestinationFromSession(state);
5549
6179
  // a session's stop is shown ONCE, in the progress line (renderProgress); #chat-card-error carries only a
5550
6180
  // refused START (its own handler writes it) — echoing state.error here made the same refusal appear twice
5551
6181
  errEl.textContent = "";
@@ -5608,6 +6238,8 @@
5608
6238
  refreshStartEnabled();
5609
6239
  return;
5610
6240
  }
6241
+ // a draft that follows another stays in that line: a red one redrafted from the card is the next revise, not a fresh start (the server counts by this link)
6242
+ if(carryFromId) carryFromId = r.body.sessionId;
5611
6243
  sessionId = r.body.sessionId;
5612
6244
  // a same-job session has no confirm turn: it goes straight to `prepared`, and THIS click (Sign & run) is the
5613
6245
  // signature — the page signs the hash the server prepared as soon as it is ready (the server re-checks it)
@@ -5668,6 +6300,7 @@
5668
6300
  setVal("jf-name", c.jobName); setVal("jf-job", c.jobText); setVal("jf-inputs", c.inputs);
5669
6301
  setVal("jf-dest", c.destination); setVal("jf-cap-money", c.capUsd);
5670
6302
  setVal("jf-cap-time", typeof c.maxWallMs === "number" ? Math.round(c.maxWallMs / 60000) : "");
6303
+ setFlow(c.flowType, c.mcp); setCardSchedule(c.schedule);
5671
6304
  setThinkingTick(c.thinking === true);
5672
6305
  fitCardBoxes();
5673
6306
  }
@@ -5711,7 +6344,9 @@
5711
6344
  if(reuseOrigin === null) return false;
5712
6345
  var cur = currentCard(), o = reuseOrigin.card;
5713
6346
  var t = function(v){ return typeof v === "string" ? v.replace(/\s+/g, "") : ""; };
5714
- return t(cur.jobText) !== t(o.jobText) || cur.checkType !== (o.checkType === "rubric" ? "rubric" : "deterministic") || (cur.thinking === true) !== (o.thinking === true);
6347
+ // Flow type and MCP are job boxes too (piece 8): a plain card has neither key, so absent reads as plain with no MCP, the same as the server
6348
+ return t(cur.jobText) !== t(o.jobText) || cur.checkType !== (o.checkType === "rubric" ? "rubric" : "deterministic") || (cur.thinking === true) !== (o.thinking === true)
6349
+ || (cur.flowType || "plain") !== (o.flowType || "plain") || (cur.mcp || "") !== (o.mcp || "");
5715
6350
  }
5716
6351
  // the reuse path (signed plan verbatim, no drafting, $0): a card made by Reuse workflow from a GREEN run with no job box changed
5717
6352
  function reusePathNow(){
@@ -5728,6 +6363,11 @@
5728
6363
  function reuseBoxesEdited(){ syncReuseName(); renderMain(); }
5729
6364
  document.getElementById("jf-job").addEventListener("input", reuseBoxesEdited);
5730
6365
  thinkingBox.addEventListener("change", reuseBoxesEdited);
6366
+ flowTypeEl.addEventListener("change", function(){ paintFlowType(); reuseBoxesEdited(); refreshStartEnabled(); });
6367
+ cardSchedEl.addEventListener("change", function(){ paintCardSchedule(); renderMain(); });
6368
+ mcpEl.addEventListener("change", reuseBoxesEdited);
6369
+ document.getElementById("jf-mcp-manage").addEventListener("click", function(ev){ ev.preventDefault(); document.getElementById("btn-settings").click(); document.getElementById("tab-mcp").click(); });
6370
+ loadMcpServers();
5731
6371
  document.getElementById("jf-name").addEventListener("input", function(){
5732
6372
  if(reuseOrigin === null || reuseOn) return;
5733
6373
  if(jobBoxesChangedNow()) nameTouched = true; else syncReuseName();
@@ -5867,18 +6507,28 @@
5867
6507
  // hamr 2026-10-09 (as fwdloop's Revise): the draft is ended and the New job card opens with the SAME values in every
5868
6508
  // box, all editable; Start drafting then drafts fresh from whatever the boxes now say. No typed change request goes
5869
6509
  // to the model. The ended draft is an Abandon: money already spent stays booked.
5870
- function doReopen(){
6510
+ // Revise and Start over both end this draft and open the boxes as the draft left them: the job box now holds the `~` lines the answers added (the server's card), and the
6511
+ // check picks of this draft ride along to the next one. Neither drafts at once (fwd am14: the fields are open, the person edits and drafts). A Revise is one of the draft's 2
6512
+ // (the server counts it and refuses the third, before this draft is ended); Start over gives the next draft 2 new ones.
6513
+ function doReopen(kind){
5871
6514
  if(!sessionId) return;
5872
- authorPost("/api/author/" + sessionId + "/abandon", {}).then(function(r){
5873
- var o = chatPostOutcome(r);
5874
- if(!o.ok){ chatActionFailed(o.error); return; }
5875
- openNewCard();
5876
- chatActionOk();
5877
- lastMsgSig = null;
5878
- thread.innerHTML = '<div class="msg system">' + escapeXml("The boxes are open as you drafted them. Edit what you want, then Start drafting. The first draft's cost stays counted.") + "</div>";
6515
+ var from = sessionId;
6516
+ authorGet("/api/author/" + from).then(function(j){
6517
+ var jt = j && j.state && j.state.card && typeof j.state.card.jobText === "string" ? j.state.card.jobText : "";
6518
+ return authorPost("/api/author/" + from + "/abandon", {kind: kind}).then(function(r){
6519
+ var o = chatPostOutcome(r);
6520
+ if(!o.ok){ chatActionFailed(o.error); return; }
6521
+ openNewCard();
6522
+ carryFromId = from;
6523
+ carryKindVal = kind === "startover" ? "startover" : "revise";
6524
+ if(jt){ setVal("jf-job", jt); fitCardBoxes(); }
6525
+ chatActionOk();
6526
+ lastMsgSig = null;
6527
+ thread.innerHTML = '<div class="msg system">' + escapeXml("The boxes are open as you drafted them. Edit what you want, then Start drafting. The first draft's cost stays counted.") + "</div>";
6528
+ });
5879
6529
  }).catch(function(){ chatActionFailed("network error — could not reach the panel server, not revised"); });
5880
6530
  }
5881
- reopenBtn.addEventListener("click", doReopen);
6531
+ reopenBtn.addEventListener("click", function(){ doReopen(reviseButtonFor(lastState && lastState.revisesLeft).kind); });
5882
6532
 
5883
6533
  function doSign(){
5884
6534
  if(!sessionId) return;
@@ -5910,7 +6560,7 @@
5910
6560
  // The Reuse card plus the When field, copied from fwdloop's Run card (index.html:998-1019, 4690-4772). The page works out nothing: the
5911
6561
  // server's words, refusals and hashes. Click 1 (schedule-prepare) is $0 and signs nothing; click 2 (schedule) signs; NOTHING runs.
5912
6562
  function byId(id){ return document.getElementById(id); }
5913
- var WHEN_KINDS = ["hand", "daily", "weekdays", "weekly", "file-updated", "new-file"];
6563
+ var WHEN_KINDS = ["hand", "daily", "weekdays", "weekly", "file-updated", "new-file", "new-ticket"];
5914
6564
  function whenTriggerFromBoxes(){
5915
6565
  var kind = byId("jf-when").value;
5916
6566
  if(kind === "hand") return null;
@@ -5920,6 +6570,7 @@
5920
6570
  if(kind === "weekly") o.day = byId("jf-when-day").value;
5921
6571
  return o;
5922
6572
  }
6573
+ if(kind === "new-ticket") return {kind: kind, input: byId("jf-when-input").value}; // MCP + tickets piece 3: the person picks the input; the server fills the rest from the signed job
5923
6574
  var q = {kind: kind};
5924
6575
  q[kind === "new-file" ? "folder" : "path"] = byId("jf-when-path").value.trim();
5925
6576
  return q;
@@ -5927,7 +6578,7 @@
5927
6578
  // one comparable spelling of a trigger (or By hand), so "changed" is a plain string compare
5928
6579
  function whenCanon(t){
5929
6580
  if(!t) return "hand";
5930
- return [t.kind, t.hour === undefined ? "" : t.hour, t.minute === undefined ? "" : t.minute, t.day || "", t.path || t.folder || ""].join("|");
6581
+ return [t.kind, t.hour === undefined ? "" : t.hour, t.minute === undefined ? "" : t.minute, t.day || "", t.path || t.folder || t.input || ""].join("|");
5931
6582
  }
5932
6583
  // Is the card changed from what was signed? The ONE reader. A schedule card (Schedule run, Cancel / modify schedule) never starts a run: the main
5933
6584
  // button is Sign schedule while this is true and disabled while it is not. On a scheduled job any When, Inputs, Destination or cap edit counts
@@ -5945,6 +6596,7 @@
5945
6596
  byId("jf-when-clock").hidden = !(kind === "daily" || kind === "weekdays" || kind === "weekly");
5946
6597
  byId("jf-when-day").hidden = kind !== "weekly";
5947
6598
  byId("jf-when-filebox").hidden = !(kind === "file-updated" || kind === "new-file");
6599
+ byId("jf-when-ticketbox").hidden = kind !== "new-ticket";
5948
6600
  byId("jf-when-path").placeholder = kind === "new-file" ? "/full/path/to/folder" : "/full/path/to/file";
5949
6601
  }
5950
6602
  function paintWhen(){
@@ -5956,7 +6608,9 @@
5956
6608
  byId("jf-when-label").textContent = w.whenLabel || "";
5957
6609
  var sel = byId("jf-when");
5958
6610
  sel.innerHTML = "";
6611
+ var ticketInputs = sched.ticketInputs || [];
5959
6612
  WHEN_KINDS.forEach(function(k){
6613
+ if(k === "new-ticket" && ticketInputs.length === 0 && !(sched.cur && sched.cur.kind === "new-ticket")) return; // only a Tickets MCP job with list_issues signed offers it
5960
6614
  var op = document.createElement("option");
5961
6615
  op.value = k;
5962
6616
  // on a scheduled job the first option reads Cancel schedule instead of By hand
@@ -5968,9 +6622,15 @@
5968
6622
  if(t && t.hour !== undefined){ byId("jf-when-time").value = ("0" + t.hour).slice(-2) + ":" + ("0" + t.minute).slice(-2); }
5969
6623
  if(t && t.day) byId("jf-when-day").value = t.day;
5970
6624
  byId("jf-when-path").value = t ? (t.path || t.folder || "") : "";
6625
+ var inSel = byId("jf-when-input");
6626
+ inSel.innerHTML = "";
6627
+ (ticketInputs.length ? ticketInputs : (t && t.input ? [t.input] : [])).forEach(function(label){
6628
+ var o = document.createElement("option"); o.value = label; o.textContent = label; inSel.appendChild(o);
6629
+ });
6630
+ if(t && t.input) inSel.value = t.input;
5971
6631
  // refused = the select and every sub-box are DISABLED and the reason stands where "Now:" would be
5972
6632
  var refused = !!sched.refusal;
5973
- sel.disabled = byId("jf-when-day").disabled = byId("jf-when-time").disabled = byId("jf-when-path").disabled = refused;
6633
+ sel.disabled = byId("jf-when-day").disabled = byId("jf-when-time").disabled = byId("jf-when-path").disabled = byId("jf-when-input").disabled = refused;
5974
6634
  byId("jf-when-now").textContent = refused ? sched.refusal : (sched.now ? (w.nowPrefix || "") + sched.now : "");
5975
6635
  byId("jf-err-when").textContent = "";
5976
6636
  whenShowSubs();
@@ -5986,7 +6646,7 @@
5986
6646
  whenShowSubs();
5987
6647
  renderMain();
5988
6648
  }
5989
- ["jf-when", "jf-when-day", "jf-when-time"].forEach(function(id){ byId(id).addEventListener("change", whenEdited); });
6649
+ ["jf-when", "jf-when-day", "jf-when-time", "jf-when-input"].forEach(function(id){ byId(id).addEventListener("change", whenEdited); });
5990
6650
  byId("jf-when-path").addEventListener("input", whenEdited);
5991
6651
  // the hash binds the WHOLE card (inputs, destination, caps), so a change to any of them drops it too (and repaints the button: on a scheduled job a box edit is Sign schedule)
5992
6652
  ["jf-inputs", "jf-dest", "jf-cap-money", "jf-cap-time"].forEach(function(id){ byId(id).addEventListener("input", function(){ if(!sched) return; if(whenHash !== null) whenEdited(); else renderMain(); }); });
@@ -6035,7 +6695,7 @@
6035
6695
  if(sessionLive || resumeRun !== null){ errEl.textContent = "Finish or clear what is on the card first, then try again."; return; }
6036
6696
  applyReuse({runid: d.runid, prefill: d.prefill, lock: true});
6037
6697
  var sc = (d.prefill || {}).scheduleCard || {};
6038
- sched = {job: d.job, runid: d.runid, words: sc.words || {}, cur: sc.trigger || null, scheduled: sc.scheduled === true, refusal: sc.refusal || null, now: sc.now || null,
6698
+ sched = {job: d.job, runid: d.runid, words: sc.words || {}, ticketInputs: sc.ticketInputs || [], cur: sc.trigger || null, scheduled: sc.scheduled === true, refusal: sc.refusal || null, now: sc.now || null,
6039
6699
  base: {inputs: byId("jf-inputs").value.trim(), dest: byId("jf-dest").value.trim(), capUsd: byId("jf-cap-money").value.trim(), capTime: byId("jf-cap-time").value.trim()}};
6040
6700
  whenHash = null; whenConfirm = null; whenBusy = false;
6041
6701
  paintWhen();