@bridge_gpt/mcp-server 0.2.78 → 0.2.80

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.
@@ -105,6 +105,11 @@ export function generateDecisionPageHtml(data, assets = DEFAULT_ASSETS) {
105
105
  const needsForm = hasDecisions || (isPlanning && stanceItemCount > 0);
106
106
  const effectiveLabels = resolveDecisionPageLabels(data.labels);
107
107
  const isFinish = isFinishCheckpointPage(data);
108
+ // BAPI-1897 — GAPS issues render only on a finish page. Refuse rather than
109
+ // render a page with them silently removed.
110
+ if (!isFinish && pageHasGapIssues(data)) {
111
+ throw new Error("GAPS issues (issues / issues_summary) render only on a finish-checkpoint page (page_revision).");
112
+ }
108
113
  const faviconLink = assets.faviconBase64
109
114
  ? `<link rel="icon" type="image/png" sizes="32x32" href="data:image/png;base64,${assets.faviconBase64}">`
110
115
  : "";
@@ -124,7 +129,7 @@ export function generateDecisionPageHtml(data, assets = DEFAULT_ASSETS) {
124
129
  <head>
125
130
  <meta charset="UTF-8">
126
131
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
127
- <title>${isFinish ? `${escapeHtml(ticket_key)} finish decision page (revision ${escapeHtml(data.page_revision)})` : `${escapeHtml(effectiveLabels.title)}: ${escapeHtml(ticket_key)}`}</title>
132
+ <title>${isFinish ? `${escapeHtml(ticket_key)} finish decisions` : `${escapeHtml(effectiveLabels.title)}: ${escapeHtml(ticket_key)}`}</title>
128
133
  ${faviconLink}
129
134
  <style>
130
135
  :root {
@@ -560,7 +565,7 @@ export function generateDecisionPageHtml(data, assets = DEFAULT_ASSETS) {
560
565
  gap: 0.75rem;
561
566
  }
562
567
  }
563
- </style>${isFinish ? FINISH_CHECKPOINT_CSS : ""}
568
+ </style>${isFinish ? FINISH_CHECKPOINT_CSS : ""}${isFinish && pageHasGapIssues(data) ? GAP_ISSUES_CSS : ""}
564
569
  </head>
565
570
  <body${isFinish ? ' class="finish-checkpoint"' : ""}>
566
571
  ${renderHeader(assets)}
@@ -584,17 +589,23 @@ ${needsForm ? renderScript(data, isPlanning, isFinish) : ""}
584
589
  // ---------------------------------------------------------------------------
585
590
  // Section renderers
586
591
  // ---------------------------------------------------------------------------
587
- // BAPI-1879 — the finish checkpoint's lead: epic and revision first, then the
588
- // one-answer instruction and the owner-only merge rule. Escaped plain text only.
592
+ // BAPI-1879 — the finish checkpoint's lead: the epic first, then the notes (the
593
+ // defaults are suggestions; only a submission decides; the owner merges).
594
+ // BAPI-1888 — the revision and the gap-list fingerprint sit in one collapsed
595
+ // "Technical details" block; the script still carries the revision for submission.
589
596
  function renderFinishLead(data) {
590
597
  const notes = (data.header_notes ?? [])
591
598
  .map((note) => `
592
599
  <li data-testid="finish-header-note">${escapeHtml(note)}</li>`)
593
600
  .join("");
594
- return ` <h1 data-testid="finish-title">${escapeHtml(data.ticket_key)}: finish decision page</h1>
595
- <p class="finish-revision" data-testid="finish-revision">Revision <code>${escapeHtml(data.page_revision)}</code></p>${notes ? `
601
+ const technical = hasDisplayText(data.technical_details) ? escapeHtml(data.technical_details) : `Page revision: ${escapeHtml(data.page_revision)}.`;
602
+ return ` <h1 data-testid="finish-title">${escapeHtml(data.ticket_key)}: final decisions</h1>${notes ? `
596
603
  <ul class="finish-header-notes" data-testid="finish-header-notes">${notes}
597
- </ul>` : ""}`;
604
+ </ul>` : ""}
605
+ <details class="finish-technical finish-page-technical" data-testid="finish-page-technical">
606
+ <summary>Technical details</summary>
607
+ <p class="finish-revision" data-testid="finish-revision">${technical}</p>
608
+ </details>`;
598
609
  }
599
610
  // BAPI-1879 — read-only fixed rules (re-listed entries, the rerun rule, test-only
600
611
  // and environment recovery, the serious-gap rule). Not a decision; never submitted.
@@ -629,8 +640,8 @@ const FINISH_CHECKPOINT_CSS = `
629
640
  line-height: 24px;
630
641
  }
631
642
  body.finish-checkpoint .main-content { max-width: 760px; margin: 32px auto; padding: 0 16px; }
632
- body.finish-checkpoint h1 { font-size: 24px; line-height: 30px; margin-bottom: 8px; }
633
- body.finish-checkpoint h2 { font-size: 18px; line-height: 24px; margin: 24px 0 12px; }
643
+ body.finish-checkpoint h1 { font-size: 28px; line-height: 34px; margin-bottom: 8px; }
644
+ body.finish-checkpoint h2 { font-size: 22px; line-height: 28px; margin: 32px 0 8px; }
634
645
  body.finish-checkpoint .card-title { font-size: 18px; line-height: 24px; }
635
646
  body.finish-checkpoint .card-section-body, body.finish-checkpoint .radio-option-consequence,
636
647
  body.finish-checkpoint .fixed-rule-text, body.finish-checkpoint .finish-header-notes, body.finish-checkpoint .finish-revision {
@@ -671,6 +682,28 @@ const FINISH_CHECKPOINT_CSS = `
671
682
  body.finish-checkpoint .radio-option .ai-recommendation { grid-column: 2; }
672
683
  body.finish-checkpoint .fixed-rule-title { font-size: 16px; line-height: 24px; font-weight: 600; }
673
684
  body.finish-checkpoint .finish-fixed-rules > p { margin-bottom: 12px; }
685
+ body.finish-checkpoint .card-section-body, body.finish-checkpoint .codebase-evidence-body, body.finish-checkpoint .finish-technical-body {
686
+ white-space: pre-line;
687
+ }
688
+ /* BAPI-1888: evidence on a finish page is plain-language prose; identifiers stay monospace in technical details. */
689
+ body.finish-checkpoint .codebase-evidence-body { font-family: inherit; font-size: 14px; line-height: 20px; }
690
+ body.finish-checkpoint .finish-group { margin-top: 8px; }
691
+ body.finish-checkpoint .finish-group-intro { margin: 0 0 16px; font-size: 16px; line-height: 24px; }
692
+ body.finish-checkpoint .finish-technical { margin-top: 16px; font-size: 14px; line-height: 20px; }
693
+ body.finish-checkpoint .finish-technical summary, body.finish-checkpoint .finish-test-inventory summary,
694
+ body.finish-checkpoint .finish-test-file summary { cursor: pointer; font-weight: 600; padding: 4px 0; }
695
+ body.finish-checkpoint .finish-technical-body, body.finish-checkpoint .finish-page-technical .finish-revision {
696
+ font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
697
+ overflow-wrap: anywhere;
698
+ word-break: break-word;
699
+ }
700
+ body.finish-checkpoint .finish-page-technical { margin: 0 0 24px; }
701
+ body.finish-checkpoint .finish-test-inventory { margin-top: 16px; }
702
+ body.finish-checkpoint .finish-test-file { margin: 4px 0 4px 16px; }
703
+ body.finish-checkpoint .finish-test-ids { margin: 4px 0 8px 20px; font-size: 14px; line-height: 20px; overflow-wrap: anywhere; }
704
+ body.finish-checkpoint .comment-hint { margin: 4px 0 0; font-size: 14px; line-height: 20px; font-weight: 600; color: #a63d28; }
705
+ body.finish-checkpoint input[type="radio"] { accent-color: #c0472f; width: 18px; height: 18px; }
706
+ body.finish-checkpoint input[type="radio"]:checked + label { font-weight: 600; }
674
707
  @media (max-width: 768px) {
675
708
  body.finish-checkpoint .main-content { margin: 16px auto; padding: 0 12px; }
676
709
  body.finish-checkpoint .card { padding: 16px; }
@@ -680,6 +713,64 @@ const FINISH_CHECKPOINT_CSS = `
680
713
  body.finish-checkpoint .btn { width: 100%; }
681
714
  }
682
715
  </style>`;
716
+ // BAPI-1897 — GAPS issue styling, emitted only on a finish page that carries
717
+ // issues so every other page stays byte-identical. Labels pair each color with
718
+ // text (all pairs reach at least 4.5:1); identities wrap anywhere; summaries get
719
+ // the finish page's visible focus ring; nothing animates.
720
+ const GAP_ISSUES_CSS = `
721
+ <style>
722
+ body.finish-checkpoint .card.has-gap-issues { padding: 32px; }
723
+ body.finish-checkpoint .gap-issues p { margin: 0 0 8px; }
724
+ body.finish-checkpoint .gap-issues-headline { font-size: 18px; line-height: 24px; font-weight: 600; }
725
+ body.finish-checkpoint .gap-issues-explanation, body.finish-checkpoint .gap-issues-recommendation,
726
+ body.finish-checkpoint .gap-issues-preview { font-size: 16px; line-height: 24px; }
727
+ body.finish-checkpoint .gap-issues-term { font-weight: 600; }
728
+ body.finish-checkpoint .gap-issues-state-note { font-size: 14px; line-height: 20px; color: #374151; border-left: 4px solid var(--border-color); padding-left: 8px; }
729
+ body.finish-checkpoint .gap-issue-list { list-style: none; margin: 8px 0; padding: 0; display: grid; gap: 8px; }
730
+ body.finish-checkpoint .gap-issue { border: 1px solid var(--border-color); border-radius: 6px; background: var(--surface-color); padding: 8px 16px; }
731
+ body.finish-checkpoint .gap-issue > summary, body.finish-checkpoint .gap-issues-overflow > summary {
732
+ cursor: pointer; padding: 4px 0; list-style: none; display: flex; align-items: flex-start; gap: 8px;
733
+ }
734
+ body.finish-checkpoint .gap-issue > summary::-webkit-details-marker,
735
+ body.finish-checkpoint .gap-issues-overflow > summary::-webkit-details-marker { display: none; }
736
+ body.finish-checkpoint .gap-issue > summary::before, body.finish-checkpoint .gap-issues-overflow > summary::before {
737
+ content: "\\25B6"; flex: none; width: 16px; font-size: 12px; line-height: 24px; text-align: center; color: #a63d28;
738
+ transition: transform 120ms ease-out;
739
+ }
740
+ body.finish-checkpoint .gap-issue[open] > summary::before,
741
+ body.finish-checkpoint .gap-issues-overflow[open] > summary::before { transform: rotate(90deg); }
742
+ body.finish-checkpoint .gap-issue-summary-text { display: block; flex: 1 1 auto; min-width: 0; }
743
+ body.finish-checkpoint .gap-issue-headline { display: block; font-size: 16px; line-height: 24px; font-weight: 600; overflow-wrap: anywhere; }
744
+ body.finish-checkpoint .gap-issue-labels { display: flex; flex-wrap: wrap; gap: 4px 8px; margin-top: 4px; }
745
+ body.finish-checkpoint .gap-label { display: inline-block; padding: 0 8px; border-radius: 4px; font-size: 13px; line-height: 20px; font-weight: 600; }
746
+ body.finish-checkpoint .gap-severity-serious { background: #fef2f2; color: #991b1b; }
747
+ body.finish-checkpoint .gap-severity-unknown { background: #fff7ed; color: #9a3412; }
748
+ body.finish-checkpoint .gap-severity-minor { background: #fef3c7; color: #78350f; }
749
+ body.finish-checkpoint .gap-context { background: #eff6ff; color: #1e3a8a; }
750
+ body.finish-checkpoint .gap-closer { background: #f3f4f6; color: #374151; }
751
+ body.finish-checkpoint .gap-rechecked { background: #dcfce7; color: #166534; }
752
+ body.finish-checkpoint .gap-person { background: #f5f3ff; color: #5b21b6; }
753
+ body.finish-checkpoint .gap-issue-body { margin: 8px 0 0; font-size: 14px; line-height: 20px; }
754
+ body.finish-checkpoint .gap-issue-body dt { font-weight: 600; margin-top: 8px; }
755
+ body.finish-checkpoint .gap-issue-body dd { margin: 4px 0 0; overflow-wrap: anywhere; }
756
+ body.finish-checkpoint .gap-person-checks { margin: 4px 0 0 16px; }
757
+ body.finish-checkpoint .gap-issues-overflow { margin: 8px 0 16px; }
758
+ body.finish-checkpoint .gap-issues-overflow > summary { font-weight: 600; }
759
+ body.finish-checkpoint .gap-technical-list { list-style: none; margin: 8px 0; padding: 0; display: grid; gap: 8px; }
760
+ body.finish-checkpoint .gap-technical-entry { display: grid; gap: 4px; }
761
+ body.finish-checkpoint .gap-issue-technical code, body.finish-checkpoint .gap-technical-fingerprint code {
762
+ overflow-wrap: anywhere; word-break: break-word;
763
+ }
764
+ @media (max-width: 768px) {
765
+ body.finish-checkpoint .card.has-gap-issues { padding: 16px; }
766
+ body.finish-checkpoint .gap-issue { padding: 8px; }
767
+ body.finish-checkpoint .gap-issue-labels { flex-direction: column; align-items: flex-start; }
768
+ }
769
+ @media (prefers-reduced-motion: reduce) {
770
+ body.finish-checkpoint .gap-issues, body.finish-checkpoint .gap-issue, body.finish-checkpoint .gap-issues-overflow,
771
+ body.finish-checkpoint .gap-issue > summary::before, body.finish-checkpoint .gap-issues-overflow > summary::before { transition: none; animation: none; }
772
+ }
773
+ </style>`;
683
774
  function renderHeader(assets) {
684
775
  const logoImg = assets.logoBase64
685
776
  ? `<img src="data:image/png;base64,${assets.logoBase64}" alt="Bridge">`
@@ -885,10 +976,15 @@ function renderForm(data, labels, hasDecisions = true) {
885
976
  <div id="form-status" class="form-status" role="status" aria-live="polite" data-testid="finish-form-status"></div>`;
886
977
  }
887
978
  if (hasDecisions && actionable_items.length > 0) {
888
- html += `
979
+ if (isFinishCheckpointPage(data) && data.categories !== undefined && data.categories.length > 0) {
980
+ html += renderFinishGroups(data);
981
+ }
982
+ else {
983
+ html += `
889
984
  <h2>${escapeHtml(labels.section_heading)}</h2>`;
890
- for (const item of actionable_items) {
891
- html += renderDecisionItem(item, isFinishCheckpointPage(data));
985
+ for (const item of actionable_items) {
986
+ html += renderDecisionItem(item, isFinishCheckpointPage(data), data.test_inventory);
987
+ }
892
988
  }
893
989
  }
894
990
  html += `
@@ -908,7 +1004,7 @@ function renderForm(data, labels, hasDecisions = true) {
908
1004
  <h2>Output JSON</h2>
909
1005
  <button type="button" class="btn btn-secondary" data-copy-json-btn data-default-label="Copy JSON">Copy JSON</button>
910
1006
  </div>
911
- <p>Copy the JSON below and paste it back to the agent.</p>
1007
+ <p${isFinishCheckpointPage(data) ? ' data-testid="finish-copy-instruction"' : ""}>${isFinishCheckpointPage(data) ? "Your answers are not recorded yet. Copy the JSON below and paste it back to the agent; the agent records them." : "Copy the JSON below and paste it back to the agent."}</p>
912
1008
  <pre id="json-output" data-testid="decision-output-json"></pre>
913
1009
  <div class="copy-area">
914
1010
  <button type="button" id="copy-btn" class="btn btn-secondary" data-copy-json-btn data-default-label="Copy to Clipboard">Copy to Clipboard</button>
@@ -916,7 +1012,63 @@ function renderForm(data, labels, hasDecisions = true) {
916
1012
  </div>`;
917
1013
  return html;
918
1014
  }
919
- function renderDecisionItem(item, isFinish = false) {
1015
+ // BAPI-1888 — finish groups: each non-empty category is an <h2> with its intro,
1016
+ // its cards beneath as <h3>. A card whose category matches no group is never
1017
+ // dropped: it renders in a trailing "Other decisions" group.
1018
+ function renderFinishGroups(data) {
1019
+ const categories = data.categories ?? [];
1020
+ const known = new Set(categories.map((c) => c.id));
1021
+ let html = "";
1022
+ const group = (id, heading, intro, items) => {
1023
+ if (items.length === 0)
1024
+ return;
1025
+ const headingId = `finish-group-${escapeHtml(id)}`;
1026
+ html += `
1027
+ <section class="finish-group" data-testid="finish-group" data-category="${escapeHtml(id)}" aria-labelledby="${headingId}">
1028
+ <h2 id="${headingId}" data-testid="finish-group-heading">${escapeHtml(heading)}</h2>
1029
+ <p class="finish-group-intro" data-testid="finish-group-intro">${escapeHtml(intro)}</p>`;
1030
+ for (const item of items)
1031
+ html += renderDecisionItem(item, true, data.test_inventory);
1032
+ html += `
1033
+ </section>`;
1034
+ };
1035
+ for (const cat of categories)
1036
+ group(cat.id, cat.heading, cat.intro, data.actionable_items.filter((item) => item.category === cat.id));
1037
+ group("other", "Other decisions", "Decisions that did not match a group above.", data.actionable_items.filter((item) => item.category === undefined || !known.has(item.category)));
1038
+ return html;
1039
+ }
1040
+ // BAPI-1888 — the focused plan's per-file test lists, collapsed, inside the TESTS card.
1041
+ function renderTestInventory(inventory, itemId) {
1042
+ if (!inventory || inventory.card_id !== itemId || inventory.files.length === 0)
1043
+ return "";
1044
+ const files = inventory.files
1045
+ .map((f) => {
1046
+ if (inventory.mode === "inline") {
1047
+ const ids = (f.ids ?? []).map((id) => `
1048
+ <li><code>${escapeHtml(id)}</code></li>`).join("");
1049
+ return `
1050
+ <details class="finish-test-file" data-testid="test-inventory-file">
1051
+ <summary><code>${escapeHtml(f.path)}</code> (${(f.ids ?? []).length} test${(f.ids ?? []).length === 1 ? "" : "s"})</summary>
1052
+ <ul class="finish-test-ids">${ids}
1053
+ </ul>
1054
+ </details>`;
1055
+ }
1056
+ return `
1057
+ <li data-testid="test-inventory-file"><code>${escapeHtml(f.path)}</code> (${f.count === null || f.count === undefined ? "count not available" : `${f.count} test${f.count === 1 ? "" : "s"}`})</li>`;
1058
+ })
1059
+ .join("");
1060
+ const body = inventory.mode === "inline"
1061
+ ? files
1062
+ : `
1063
+ <p>The list is too long to show here. Every test is in the private plan file${inventory.plan_file ? `: <code>${escapeHtml(inventory.plan_file)}</code>` : ""}.</p>
1064
+ <ul>${files}
1065
+ </ul>`;
1066
+ return `
1067
+ <details class="finish-test-inventory" data-testid="test-inventory">
1068
+ <summary>Every test in the focused plan</summary>${body}
1069
+ </details>`;
1070
+ }
1071
+ function renderDecisionItem(item, isFinish = false, inventory) {
920
1072
  const id = escapeHtml(item.id);
921
1073
  const radioName = `radio-${id}`;
922
1074
  const textareaId = `comment-${id}`;
@@ -932,8 +1084,11 @@ function renderDecisionItem(item, isFinish = false) {
932
1084
  const label = item.options[i];
933
1085
  const consequence = item.option_consequences[i] ?? "";
934
1086
  const isRecommended = i === item.recommendation_index;
935
- // BAPI-1879 — a finish checkpoint labels the recommendation but never selects it for the owner.
936
- const checked = isRecommended && !isFinish ? " checked" : "";
1087
+ // BAPI-1888 — the recommended option is selected on every page, finish pages
1088
+ // included (superseding BAPI-1879's "labelled, never pre-selected"). It is a
1089
+ // suggestion: only a submitted answer records a decision.
1090
+ const checked = isRecommended ? " checked" : "";
1091
+ const commentAttr = isFinish && item.comment_required !== undefined ? ` data-comment-required="${item.comment_required[i] ? "true" : "false"}"` : "";
937
1092
  const labelText = escapeHtml(label);
938
1093
  const recommendationMarker = isRecommended
939
1094
  ? isFinish
@@ -943,7 +1098,7 @@ function renderDecisionItem(item, isFinish = false) {
943
1098
  optionsHtml += `
944
1099
  <div class="radio-option-wrapper" data-testid="option-wrapper" data-option-index="${i}">
945
1100
  <div class="radio-option">
946
- <input type="radio" id="${radioName}-${val}" name="${radioName}" value="${val}"${checked} data-testid="decision-option">
1101
+ <input type="radio" id="${radioName}-${val}" name="${radioName}" value="${val}"${checked}${commentAttr} data-testid="decision-option">
947
1102
  <label for="${radioName}-${val}">${labelText}</label>${recommendationMarker}
948
1103
  </div>
949
1104
  <div class="radio-option-consequence" data-testid="option-consequence">${escapeHtml(consequence)}</div>
@@ -984,13 +1139,28 @@ function renderDecisionItem(item, isFinish = false) {
984
1139
  <div class="codebase-evidence-body" data-testid="codebase-evidence-body">${escapeHtml(item.codebase_evidence)}</div>
985
1140
  </details>`
986
1141
  : "";
1142
+ const hintId = `comment-hint-${id}`;
1143
+ const finishCommentHint = isFinish && item.comment_required !== undefined
1144
+ ? `
1145
+ <p class="comment-hint" id="${hintId}" data-testid="comment-required-hint" hidden>This choice needs a comment.</p>`
1146
+ : "";
1147
+ const technicalSection = isFinish && hasDisplayText(item.technical_details)
1148
+ ? `
1149
+ <details class="finish-technical" data-testid="technical-details">
1150
+ <summary>Technical details</summary>
1151
+ <div class="finish-technical-body" data-testid="technical-details-body">${escapeHtml(item.technical_details)}</div>
1152
+ </details>`
1153
+ : "";
1154
+ const inventorySection = isFinish ? renderTestInventory(inventory, item.id) : "";
1155
+ const issuesSection = isFinish ? renderGapIssues(item) : "";
1156
+ const issueCardClass = issuesSection ? " has-gap-issues" : "";
987
1157
  return `
988
- <section class="card" data-item-id="${id}" data-item-type="decision" data-source="${escapeHtml(item.source ?? "")}" data-labels="${labelsJson}"${optionIdsAttr} data-testid="decision-card" aria-labelledby="${titleId}">
1158
+ <section class="card${issueCardClass}" data-item-id="${id}" data-item-type="decision" data-source="${escapeHtml(item.source ?? "")}" data-labels="${labelsJson}"${optionIdsAttr} data-testid="decision-card" aria-labelledby="${titleId}">
989
1159
  <h3 class="card-title" id="${titleId}" data-testid="decision-card-title">${escapeHtml(item.question)}</h3>${originalQuestionSection}${renderRequirementClassification(item, requirementClassLabelId)}
990
1160
  <section class="card-section" data-testid="why-it-matters-section" aria-labelledby="${whyItMattersLabelId}">
991
1161
  <div class="card-section-label" id="${whyItMattersLabelId}">Why it matters</div>
992
1162
  <div class="card-section-body" data-testid="why-it-matters-body">${escapeHtml(item.why_it_matters)}</div>
993
- </section>
1163
+ </section>${issuesSection}
994
1164
  <section class="radio-group" role="radiogroup" data-testid="decision-radio-group" aria-labelledby="${radioGroupLabelId}">
995
1165
  <div class="card-section-label" id="${radioGroupLabelId}">Choose an option</div>${optionsHtml}
996
1166
  </section>
@@ -1000,10 +1170,147 @@ function renderDecisionItem(item, isFinish = false) {
1000
1170
  </section>
1001
1171
  <div class="comment-area">
1002
1172
  <label for="${textareaId}">Comment</label>
1003
- <textarea id="${textareaId}" name="${textareaId}" placeholder="${isFinish ? "Your reason or evidence reference (required where the card says so)" : "Required for None of these selections..."}" data-testid="decision-comment"></textarea>
1004
- </div>${codebaseEvidenceSection}
1173
+ <textarea id="${textareaId}" name="${textareaId}" placeholder="${isFinish ? "Your reason or evidence reference (required where the card says so)" : "Required for None of these selections..."}"${finishCommentHint ? ` aria-describedby="${hintId}"` : ""} data-testid="decision-comment"></textarea>${finishCommentHint}
1174
+ </div>${codebaseEvidenceSection}${inventorySection}${technicalSection}
1005
1175
  </section>`;
1006
1176
  }
1177
+ // ---------------------------------------------------------------------------
1178
+ // BAPI-1897 — GAPS issues: three layers
1179
+ // ---------------------------------------------------------------------------
1180
+ /** Issue rows shown before the collapsed "and N more" disclosure. */
1181
+ export const GAP_ISSUE_VISIBLE_ROWS = 8;
1182
+ function pageHasGapIssues(data) {
1183
+ return data.actionable_items.some((item) => item.issues !== undefined || item.issues_summary !== undefined);
1184
+ }
1185
+ const GAP_SUMMARY_STATE_NOTE = {
1186
+ issues: "",
1187
+ empty: "The gap list was read and it is empty. There is nothing to re-check here.",
1188
+ unavailable: "The gap evidence could not be read, so nothing on this card is confirmed.",
1189
+ };
1190
+ function severityLabel(issue) {
1191
+ if (issue.severity === "minor" && issue.severity_agent_assessed)
1192
+ return "minor — agent-assessed";
1193
+ return issue.severity;
1194
+ }
1195
+ /** Layer one row labels: severity, context, who can close it, then status badges. Every color is paired with text. */
1196
+ function renderGapIssueLabels(issue) {
1197
+ const labels = [
1198
+ `<span class="gap-label gap-severity gap-severity-${escapeHtml(issue.severity)}" data-testid="gap-issue-severity">Severity: ${escapeHtml(severityLabel(issue))}</span>`,
1199
+ ];
1200
+ for (const ctx of issue.contexts) {
1201
+ const state = ctx.state === "confirmed" ? "confirmed" : "reported, not confirmed";
1202
+ labels.push(`<span class="gap-label gap-context gap-context-${escapeHtml(ctx.state)}" data-testid="gap-issue-context">${escapeHtml(`${ctx.label} — ${state}`)}</span>`);
1203
+ }
1204
+ labels.push(`<span class="gap-label gap-closer" data-testid="gap-issue-closer">Who can close it: ${escapeHtml(issue.closer)}</span>`);
1205
+ if (issue.rechecked_passed) {
1206
+ labels.push(`<span class="gap-label gap-rechecked" data-testid="gap-issue-rechecked">Re-checked and passed at the final commit</span>`);
1207
+ }
1208
+ if (issue.human_checks.length > 0) {
1209
+ labels.push(`<span class="gap-label gap-person" data-testid="gap-issue-needs-person">Needs a person: ${escapeHtml(issue.human_checks.map((c) => c.check_id).join(", "))}</span>`);
1210
+ }
1211
+ return labels.join("");
1212
+ }
1213
+ /** Layer three: snapshot-derived values only, inside a nested collapsed disclosure. */
1214
+ function renderGapIssueTechnical(issue) {
1215
+ if (issue.technical === undefined)
1216
+ return "";
1217
+ const entries = issue.technical.entries
1218
+ .map((entry) => `
1219
+ <li class="gap-technical-entry" data-testid="gap-issue-technical-entry">
1220
+ <span>Type: <code>${escapeHtml(entry.entry_type)}</code></span>
1221
+ <span>Ticket: <code>${escapeHtml(entry.ticket_key)}</code></span>
1222
+ <span>Step: <code>${entry.step_id === null ? "none" : String(entry.step_id)}</code></span>
1223
+ <span>Exact identity: <code>${escapeHtml(entry.exact_identity)}</code></span>
1224
+ <span>Re-list identity: <code>${entry.relist_identity === null ? "none" : escapeHtml(entry.relist_identity)}</code></span>
1225
+ </li>`)
1226
+ .join("");
1227
+ const fingerprint = issue.technical.fingerprint === null ? "not available" : escapeHtml(issue.technical.fingerprint);
1228
+ return `
1229
+ <details class="finish-technical gap-issue-technical" data-testid="gap-issue-technical">
1230
+ <summary>Technical details</summary>
1231
+ <ul class="gap-technical-list">${entries}
1232
+ </ul>
1233
+ <p class="gap-technical-fingerprint">List fingerprint: <code>${fingerprint}</code></p>
1234
+ </details>`;
1235
+ }
1236
+ /** One issue: a collapsed row (layer one) that expands to the plain explanation (layer two). */
1237
+ function renderGapIssueRow(issue) {
1238
+ const reason = issue.severity_agent_assessed && issue.severity_reason !== null
1239
+ ? `
1240
+ <dt>Why the agent rated it minor</dt>
1241
+ <dd data-testid="gap-issue-severity-reason">${escapeHtml(issue.severity_reason)}</dd>`
1242
+ : "";
1243
+ const checks = issue.human_checks.length > 0
1244
+ ? `
1245
+ <dt>Needs a person</dt>
1246
+ <dd><ul class="gap-person-checks">${issue.human_checks
1247
+ .map((c) => `
1248
+ <li data-testid="gap-issue-human-check"><strong>${escapeHtml(c.check_id)}</strong> (${escapeHtml(c.ticket_key)}): ${escapeHtml(c.text)}</li>`)
1249
+ .join("")}
1250
+ </ul></dd>`
1251
+ : "";
1252
+ return `
1253
+ <li class="gap-issue-item">
1254
+ <details class="gap-issue" data-testid="gap-issue-row" data-issue-id="${escapeHtml(issue.issue_id)}">
1255
+ <summary>
1256
+ <span class="gap-issue-summary-text">
1257
+ <span class="gap-issue-headline" data-testid="gap-issue-headline">${escapeHtml(issue.headline)}</span>
1258
+ <span class="gap-issue-labels">${renderGapIssueLabels(issue)}</span>
1259
+ </span>
1260
+ </summary>
1261
+ <dl class="gap-issue-body" data-testid="gap-issue-body">
1262
+ <dt>What this was meant to prove</dt>
1263
+ <dd data-testid="gap-issue-proves">${escapeHtml(issue.proves)}</dd>
1264
+ <dt>What we know</dt>
1265
+ <dd data-testid="gap-issue-known">${escapeHtml(issue.known)}</dd>
1266
+ <dt>Why it matters</dt>
1267
+ <dd data-testid="gap-issue-why">${escapeHtml(issue.why)}</dd>
1268
+ <dt>What covers it</dt>
1269
+ <dd data-testid="gap-issue-covers">${escapeHtml(issue.covers)}</dd>${reason}${checks}
1270
+ </dl>${renderGapIssueTechnical(issue)}
1271
+ </details>
1272
+ </li>`;
1273
+ }
1274
+ /**
1275
+ * The GAPS card's three layers. Layer one is the summary plus up to eight rows;
1276
+ * the rest sit in a collapsed, keyboard-accessible "and N more" disclosure so
1277
+ * every issue stays reachable. Nothing here is a form control, so none of it
1278
+ * reaches the submitted or copied decision JSON.
1279
+ */
1280
+ function renderGapIssues(item) {
1281
+ if (item.issues === undefined && item.issues_summary === undefined)
1282
+ return "";
1283
+ const summary = item.issues_summary;
1284
+ const issues = item.issues ?? [];
1285
+ const state = summary?.state ?? "issues";
1286
+ const note = GAP_SUMMARY_STATE_NOTE[state];
1287
+ const summaryHtml = summary
1288
+ ? `
1289
+ <p class="gap-issues-headline" data-testid="gap-issues-headline">${escapeHtml(summary.headline)}</p>${summary.explanation ? `
1290
+ <p class="gap-issues-explanation" data-testid="gap-issues-explanation">${escapeHtml(summary.explanation)}</p>` : ""}${note ? `
1291
+ <p class="gap-issues-state-note gap-issues-state-${state}" data-testid="gap-issues-state-note">${escapeHtml(note)}</p>` : ""}
1292
+ <p class="gap-issues-recommendation" data-testid="gap-issues-recommendation"><span class="gap-issues-term">Recommendation:</span> ${escapeHtml(summary.recommendation)}</p>
1293
+ <p class="gap-issues-preview" data-testid="gap-issues-preview"><span class="gap-issues-term">What happens next:</span> ${escapeHtml(summary.preview)}</p>`
1294
+ : "";
1295
+ const visible = issues.slice(0, GAP_ISSUE_VISIBLE_ROWS).map(renderGapIssueRow).join("");
1296
+ const rest = issues.slice(GAP_ISSUE_VISIBLE_ROWS);
1297
+ const list = visible
1298
+ ? `
1299
+ <ol class="gap-issue-list">${visible}
1300
+ </ol>`
1301
+ : "";
1302
+ const overflow = rest.length > 0
1303
+ ? `
1304
+ <details class="gap-issues-overflow" data-testid="gap-issues-overflow">
1305
+ <summary>and ${rest.length} more</summary>
1306
+ <ol class="gap-issue-list" start="${GAP_ISSUE_VISIBLE_ROWS + 1}">${rest.map(renderGapIssueRow).join("")}
1307
+ </ol>
1308
+ </details>`
1309
+ : "";
1310
+ return `
1311
+ <section class="card-section gap-issues" data-testid="gap-issues-summary" data-state="${escapeHtml(state)}" aria-label="Gaps summary">${summaryHtml}
1312
+ </section>${list}${overflow}`;
1313
+ }
1007
1314
  function renderImprovements(improvements, labels) {
1008
1315
  if (improvements.length === 0)
1009
1316
  return "";
@@ -1071,7 +1378,27 @@ function renderScript(data, isPlanning = false, isFinish = false) {
1071
1378
  });
1072
1379
  });
1073
1380
  });` : `var stanceContainers = [];`}
1074
-
1381
+ ${isFinish ? `
1382
+ // BAPI-1888 — required-comment hints come from each option's structured
1383
+ // data-comment-required flag, set from the initially checked radio and on change.
1384
+ function updateCommentHint(card) {
1385
+ var selected = card.querySelector('input[type="radio"]:checked');
1386
+ var hint = card.querySelector('[data-testid="comment-required-hint"]');
1387
+ var textarea = card.querySelector("textarea");
1388
+ var needs = !!selected && selected.getAttribute("data-comment-required") === "true";
1389
+ if (hint) hint.hidden = !needs;
1390
+ if (textarea) {
1391
+ if (needs) textarea.setAttribute("aria-required", "true");
1392
+ else textarea.removeAttribute("aria-required");
1393
+ }
1394
+ }
1395
+ document.querySelectorAll(".card[data-item-id]").forEach(function(card) {
1396
+ updateCommentHint(card);
1397
+ card.querySelectorAll('input[type="radio"]').forEach(function(radio) {
1398
+ radio.addEventListener("change", function() { updateCommentHint(card); });
1399
+ });
1400
+ });
1401
+ ` : ""}
1075
1402
  submitBtn.addEventListener("click", function() {
1076
1403
  var cards = document.querySelectorAll(".card[data-item-id]");
1077
1404
  var valid = true;
@@ -1102,7 +1429,17 @@ function renderScript(data, isPlanning = false, isFinish = false) {
1102
1429
  msg.textContent = "A comment is required when selecting None of these.";
1103
1430
  textarea.parentNode.appendChild(msg);
1104
1431
  valid = false;
1105
- }
1432
+ }${isFinish ? `
1433
+ else if (selected.getAttribute("data-comment-required") === "true" && !textarea.value.trim()) {
1434
+ textarea.classList.add("validation-error");
1435
+ var needMsg = document.createElement("div");
1436
+ needMsg.className = "validation-msg";
1437
+ needMsg.id = "comment-error-" + itemId;
1438
+ needMsg.textContent = "This choice needs a comment.";
1439
+ textarea.setAttribute("aria-describedby", "comment-hint-" + itemId + " comment-error-" + itemId);
1440
+ textarea.parentNode.appendChild(needMsg);
1441
+ valid = false;
1442
+ }` : ""}
1106
1443
  });
1107
1444
 
1108
1445
  // Validate stance feedback: ask/disagree requires a comment.