@bugb-technologies/bravos 1.5.3 → 1.7.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 (38) hide show
  1. package/dist/cli.js +81 -9
  2. package/dist/context.js +387 -0
  3. package/dist/dashboard.js +19 -5
  4. package/dist/guide.js +5 -2
  5. package/dist/help.js +19 -0
  6. package/dist/palette.js +4 -4
  7. package/dist/review-server.js +4 -4
  8. package/dist/review.js +103 -18
  9. package/dist/rules.js +218 -0
  10. package/dist/uninstall.js +6 -0
  11. package/dist/watch-frame.js +67 -42
  12. package/dist/watch.js +21 -7
  13. package/docs/GUIDE.md +20 -2
  14. package/docs/UPGRADING.md +28 -0
  15. package/hooks/lib/autopilot.mjs +29 -7
  16. package/hooks/lib/briefing.mjs +214 -171
  17. package/hooks/lib/context.mjs +522 -0
  18. package/hooks/lib/palette.mjs +4 -4
  19. package/hooks/lib/pre-pr.mjs +70 -0
  20. package/hooks/lib/setup.mjs +5 -2
  21. package/hooks/session-start.mjs +24 -2
  22. package/package.json +1 -1
  23. package/skills/bravos/SKILL.md +1 -1
  24. package/skills/bravos-annotate/SKILL.md +5 -3
  25. package/skills/bravos-annotate/scripts/lib/gate.mjs +45 -0
  26. package/skills/bravos-annotate/scripts/slice.mjs +10 -0
  27. package/skills/bravos-campaign/SKILL.md +1 -1
  28. package/skills/bravos-context/SKILL.md +17 -10
  29. package/skills/bravos-context/intent.example.md +14 -1
  30. package/skills/bravos-recheck/SKILL.md +1 -1
  31. package/skills/bravos-ship/SKILL.md +2 -1
  32. package/skills/bravos-templatize/SKILL.md +1 -1
  33. package/templates/dashboard/dashboard.html +97 -0
  34. package/templates/review/review.html +368 -123
  35. package/templates/workflows/bravos-nightly-claude.yml +36 -2
  36. package/templates/workflows/bravos-nightly-codex.yml +36 -2
  37. package/templates/workflows/bravos-nightly-copilot.yml +23 -0
  38. package/templates/workflows/bravos-pr-gate.yml +76 -0
@@ -4,89 +4,135 @@
4
4
  <meta charset="utf-8">
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1">
6
6
  <meta http-equiv="Content-Security-Policy" content="default-src 'none'; style-src 'unsafe-inline'; script-src 'unsafe-inline'; connect-src 'self'; img-src data:; base-uri 'none'; form-action 'none'">
7
- <title>bravos review</title>
8
- <!-- bravos (managed by bravos review; regenerated from .guardlink/<kind>-draft.json) -->
7
+ <title>Bravos review</title>
8
+ <!-- bravos (managed by bravos review; regenerated from the review draft) -->
9
9
  <style>
10
10
  :root {
11
- --green: #33d49d; --navy: #1f3943; --blue: #0360a2; --light: #f0f0f0; --steel: #55899e; --red: #ea1d1d; --slate: #3b6779;
12
- --bg: #f6f8f9; --card: #ffffff; --ink: #10222a; --muted: #4c6b78; --line: #d8e2e6; --chip: #e9f2f4; --accent: #0360a2; --ok: #138a63;
11
+ color-scheme: dark;
12
+ --bg: #101817; --card: #172320; --ink: #e7efea; --muted: #a4b9af;
13
+ --line: #354b41; --chip: #21372d; --accent: #64e2b3; --warn: #ffc198;
14
+ --mono: ui-monospace, Menlo, Consolas, monospace;
13
15
  }
14
- @media (prefers-color-scheme: dark) {
15
- :root:not([data-theme="light"]) { --bg: #0e1b21; --card: #15262e; --ink: #f0f0f0; --muted: #8fb0bd; --line: #24404b; --chip: #1f3943; --accent: #33d49d; --ok: #33d49d; }
16
- }
17
- :root[data-theme="dark"] { --bg: #0e1b21; --card: #15262e; --ink: #f0f0f0; --muted: #8fb0bd; --line: #24404b; --chip: #1f3943; --accent: #33d49d; --ok: #33d49d; }
18
16
  * { box-sizing: border-box; }
19
- body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif; }
20
- header { background: #0e1b21; color: var(--light); padding: 20px 16px; }
21
- .brand { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; max-width: 980px; margin: 0 auto; }
22
- pre.art { margin: 0; font: 9px/1.05 ui-monospace, "SF Mono", Menlo, monospace; white-space: pre; }
23
- .brand h1 { margin: 0; font-size: 18px; font-weight: 600; }
24
- .brand p { margin: 4px 0 0; color: #8fb0bd; font-size: 13px; }
25
- main { max-width: 980px; margin: 0 auto; padding: 16px; }
26
- .bar { position: sticky; top: 0; z-index: 2; background: var(--bg); padding: 12px 0; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; border-bottom: 1px solid var(--line); }
27
- .bar label { font-size: 13px; color: var(--muted); }
28
- .bar input { font: inherit; padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); color: var(--ink); min-width: 180px; }
29
- .progress { flex: 1; min-width: 140px; height: 8px; background: var(--chip); border-radius: 99px; overflow: hidden; }
30
- .progress > div { height: 100%; width: 0; background: var(--green); transition: width .2s; }
31
- button { font: inherit; border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--ink); padding: 6px 12px; cursor: pointer; }
32
- button.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
33
- button.on { outline: 2px solid var(--accent); outline-offset: 1px; font-weight: 600; }
34
- h2 { font-size: 13px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin: 24px 0 8px; }
35
- .card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; margin: 10px 0; }
36
- .card.done { border-left: 4px solid var(--green); }
37
- .card .id { font: 12px ui-monospace, Menlo, monospace; color: var(--muted); }
38
- .card .title { font-weight: 600; margin: 2px 0 4px; }
39
- .card .why { font-size: 13px; color: var(--muted); }
40
- .card .text { white-space: pre-wrap; margin: 6px 0; }
41
- .sources { font: 12px ui-monospace, Menlo, monospace; color: var(--muted); overflow-wrap: anywhere; }
42
- .choices, .verdicts { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0; }
43
- textarea { width: 100%; font: inherit; border: 1px solid var(--line); border-radius: 8px; padding: 8px; background: var(--bg); color: var(--ink); min-height: 56px; }
44
- .others { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
45
- .chip { background: var(--chip); border-radius: 99px; padding: 2px 10px; font-size: 12px; }
46
- .chip.no { color: var(--red); }
47
- .chip.agree { color: var(--ok); }
48
- .note { padding: 10px 14px; border-radius: 10px; background: var(--chip); margin: 12px 0; font-size: 14px; }
49
- .hidden { display: none; }
50
- .top { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
51
- .badge { font-size: 11px; border-radius: 99px; padding: 1px 8px; border: 1px solid var(--line); }
52
- .badge.sugg { color: var(--accent); }
53
- .badge.must { background: #ea1d1d; color: #fff; border-color: #ea1d1d; }
54
- .badge.edited { color: var(--blue); border-color: var(--blue); }
55
- .badge.chosen { color: var(--ok); border-color: var(--ok); }
56
- .badge.low { color: #b26b00; border-color: #b26b00; }
57
- .card.must { border-left: 4px solid #ea1d1d; }
58
- .reason { font-size: 13px; color: var(--muted); margin: 4px 0; }
59
- button.keep { margin: 4px 0 8px; }
60
- button:disabled { opacity: .55; cursor: not-allowed; }
61
- textarea.comment { min-height: 36px; margin-top: 6px; }
62
- details.facts { margin: 8px 0 16px; }
63
- details.facts > summary { cursor: pointer; color: var(--muted); padding: 8px 0; }
64
- .chip.edit { color: var(--blue); }
65
- @media (max-width: 600px) { pre.art { font-size: 6px; } .bar input { min-width: 0; width: 100%; } }
17
+ [hidden], .hidden { display: none !important; }
18
+ body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 system-ui, sans-serif; }
19
+ main { max-width: 1600px; margin: auto; display: grid; grid-template-columns: minmax(195px, 235px) minmax(0, 1fr); align-items: start; gap: clamp(20px, 3vw, 52px); padding: 34px clamp(18px, 4vw, 64px); }
20
+ aside { min-width: 0; position: sticky; top: 20px; max-height: calc(100vh - 40px); overflow: auto; scrollbar-width: thin; }
21
+ .identity { display: flex; gap: 11px; align-items: center; margin: 10px 0 36px; }
22
+ .identity svg { width: 50px; height: 50px; }
23
+ .identity strong { display: block; font-size: 34px; line-height: .95; letter-spacing: -.075em; }
24
+ .identity small { font: 12px var(--mono); color: var(--muted); }
25
+ aside h2,.metakey,.sectiontitle { color: var(--muted); margin: 0; font: 600 11px/1.5 var(--mono); text-transform: uppercase; letter-spacing: .09em; }
26
+ .totals { display: flex; align-items: baseline; gap: 8px; color: var(--muted); font-size: 14px; }
27
+ .totals b { font: 600 46px/1.4 system-ui; color: var(--ink); letter-spacing: -.06em; }
28
+ #segments { display: grid; grid-template-columns: repeat(20, minmax(0,1fr)); gap: 3px; margin: 9px 0; }
29
+ button, input, textarea { font: inherit; color: var(--ink); }
30
+ button { cursor: pointer; background: transparent; border: 1px solid var(--line); border-radius: 4px; padding: 6px 12px; }
31
+ button:disabled { cursor: not-allowed; opacity: .62; }
32
+ button:not(:disabled):hover { border-color: var(--accent); }
33
+ :focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
34
+ .segment { min-width: 0; height: 12px; border: 0; padding: 0; border-radius: 3px; }
35
+ [data-kind="pending"] { background: #e29368; }
36
+ [data-kind="reviewed"] { background: #49cd9d; }
37
+ [data-kind="suggested"] { background: #5b9582; }
38
+ [data-kind="optional"] { background: #8a9892; }
39
+ .legendrow { display: grid; grid-template-columns: 9px 1fr auto; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
40
+ .legendrow i { height: 8px; border-radius: 2px; }
41
+ .legendrow b, .sectiontitle { color: var(--ink); }
42
+ nav { margin-top: 20px; padding-top: 10px; border-top: 1px solid var(--line); }
43
+ nav a { color: var(--ink); text-decoration: none; display: flex; justify-content: space-between; gap: 10px; padding: 5px 0; }
44
+ nav a:hover, a { color: var(--accent); }
45
+ nav a span, .metakey { font: 11px/1.5 var(--mono); color: var(--muted); }
46
+ article { min-width: 0; overflow-wrap: anywhere; padding: clamp(20px,3.5vw,53px); background: var(--card); border: 1px solid var(--line); border-top: 4px solid #32c498; }
47
+ .foliohead, .bar, .top, .choices, .others { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
48
+ .foliohead { justify-content: space-between; padding-bottom: 16px; border-bottom: 1px solid var(--line); }
49
+ .foliohead b,.metakey { display: block; }
50
+ #repo { font-size: 22px; letter-spacing: -.045em; }
51
+ .lens { text-align: right; }
52
+ h1 { margin: 26px 0 7px; font: 600 clamp(44px,5.1vw,76px)/1.08 Georgia, serif; letter-spacing: -.055em; }
53
+ #sub { max-width: 75ch; margin: 0 0 20px; color: var(--muted); }
54
+ .scope h2 { font: 600 23px Georgia, serif; margin: 16px 0 4px; }
55
+ .scope p, .srcs, .why, .reason, .prior, .scope small, .matrixwrap th, .note { font-size: 13px; color: var(--muted); }
56
+ .scope p { margin: 0 0 10px; }
57
+ summary { cursor: pointer; padding: 7px 0; }
58
+ .policy-note { padding-left: 10px; border-left: 2px solid var(--warn); margin: 7px 0; }
59
+ .policy-note button { margin: 1px 3px; font-size: 12px; color: var(--accent); }
60
+ .policy .uncertain { color: var(--warn); margin-left: 3px; }
61
+ .policygroup { border-bottom: 1px solid var(--line); }
62
+ .policygroup summary { font-weight: 600; }
63
+ .policygroup small { font-weight: 400; }
64
+ .matrixwrap { max-height: 245px; overflow: auto; }
65
+ table { border-collapse: separate; border-spacing: 0; width: 100%; }
66
+ th,td { text-align: left; padding: 4px 7px; border-bottom: 1px solid var(--line); }
67
+ .matrixwrap thead th { position: sticky; top: 0; z-index: 1; background: var(--card); vertical-align: bottom; }
68
+ .policy { font: 12px var(--mono); padding: 4px 8px; }
69
+ .allow { color: #a4dcc4; background: #20352b; border-color: #3c6854; }
70
+ .deny { color: #ffc3a1; background: #362920; border-color: #745142; }
71
+ .srcs { margin: 12px 0; }
72
+ .srcs details { margin: 6px 0 6px 12px; }
73
+ .srcs pre { white-space: pre-wrap; overflow-wrap: anywhere; max-height: 16em; overflow: auto; }
74
+ .bar { background: #14201b; border: 1px solid var(--line); padding: 10px 12px; border-radius: 4px; }
75
+ .bar label { font-size: 13px; }
76
+ .bar input, textarea { background: #111b17; border: 1px solid #64796c; border-radius: 4px; padding: 7px 9px; }
77
+ .bar input { width: min(180px,100%); }
78
+ .bar .primary { margin-left: auto; background: var(--accent); color: #103426; font-weight: 600; }
79
+ .sectiontitle { color: var(--accent); margin: 24px 0 5px; }
80
+ .card { padding: 13px 0; border-top: 1px solid var(--line); }
81
+ .card .id, .sources { font: 12px/1.6 var(--mono); color: var(--muted); }
82
+ .card .title { margin: 6px 0; font: 600 23px/1.25 Georgia, serif; letter-spacing: -.024em; }
83
+ .text,.why,.reason { white-space: pre-wrap; }
84
+ .reason { margin: 6px 0; padding-left: 9px; border-left: 2px solid #4d7762; }
85
+ .badge,.chip { display: inline-block; font-size: 11px; border: 1px solid var(--line); border-radius: 4px; padding: 1px 6px; color: var(--muted); }
86
+ .badge.must,.badge.low,.chip.no { color: var(--warn); border-color: #865d40; }
87
+ .badge.chosen,.badge.edited,.chip.edit,.chip.agree { color: var(--accent); }
88
+ .choices { margin: 9px 0; }
89
+ .choices button { text-align: left; background: #121d18; }
90
+ .choices .on { background: #223d30; color: #caf3dc; border-color: #649a7b; font-weight: 600; }
91
+ .keep, .srcs button, #draftfile { color: var(--accent); font-size: 12px; }
92
+ textarea { width: 100%; min-height: 64px; margin: 5px 0; resize: vertical; }
93
+ textarea.comment { min-height: 37px; }
94
+ .note { padding: 10px; background: var(--chip); margin: 12px 0; }
95
+ .skip { position: absolute; left: -10000px; }
96
+ .skip:focus { left: 12px; top: 6px; z-index: 2; background: var(--bg); }
97
+ @media(max-width:780px) {
98
+ main { display: block; padding: 12px; }
99
+ aside { position: static; max-height: none; margin-bottom: 15px; }
100
+ .identity { margin-bottom: 14px; }
101
+ #segments { grid-template-columns: repeat(auto-fit,minmax(9px,1fr)); }
102
+ #sectionnav { display: flex; flex-wrap: wrap; column-gap: 12px; margin-top: 8px; }
103
+ nav a { font-size: 12px; }
104
+ .legendrow { display: inline-flex; gap: 4px; margin-right: 10px; }
105
+ .legendrow i { width: 8px; }
106
+ .bar .primary { margin-left: 0; }
107
+ .matrixwrap th,.matrixwrap td { min-width: 72px; }
108
+ .matrixwrap th:first-child { min-width: 115px; }
109
+ }
110
+ @font-face { font-family: Monoska; src: local("Monoska"); }
111
+ .identity small { font-family: Monoska, var(--mono); }
112
+ @media print { aside, .bar, .skip { display: none; } main { display: block; } }
66
113
  </style>
67
114
  </head>
68
115
  <body>
69
- <header>
70
- <div class="brand">
71
- <pre class="art" id="mascot" aria-hidden="true"></pre>
72
- <div>
73
- <pre class="art" id="wordmark" aria-label="bravos"></pre>
74
- <h1 id="heading"></h1>
75
- <p id="sub"></p>
76
- </div>
77
- </div>
78
- </header>
116
+ <a class="skip" href="#heading">Skip to review</a>
79
117
  <main>
80
- <div class="bar">
81
- <label for="who">Your name</label>
82
- <input id="who" autocomplete="name" placeholder="e.g. Sam Lee">
83
- <div class="progress" aria-label="answered"><div id="progress"></div></div>
84
- <span id="count" class="chip"></span>
85
- <button id="save" class="primary">Confirm</button>
86
- <button id="done">Done</button>
87
- </div>
88
- <div id="status" class="note hidden" role="status"></div>
89
- <div id="questions"></div>
118
+ <aside aria-label="Review overview">
119
+ <div class="identity"><svg aria-hidden="true" focusable="false" xmlns="http://www.w3.org/2000/svg" width="73.903" height="73.904" viewBox="0 0 73.903 73.904"><g transform="translate(0)"><path d="M55.427,46.189V18.476a18.476,18.476,0,0,0-36.952,0V46.189H13.857A4.619,4.619,0,0,1,9.238,41.57V27.714H0V41.578A13.857,13.857,0,0,0,13.857,55.427H26.022l-2.852,4.753a9.238,9.238,0,0,1-7.921,4.485H4.619V73.9h10.63a18.476,18.476,0,0,0,15.843-8.97l5.7-9.506h.312l5.7,9.506A18.476,18.476,0,0,0,58.654,73.9h10.63V64.666H58.654a9.238,9.238,0,0,1-7.921-4.485L47.88,55.427H60.046A13.857,13.857,0,0,0,73.9,41.578V27.714H64.665V41.57a4.619,4.619,0,0,1-4.619,4.619ZM50.808,41.57a4.619,4.619,0,1,1-4.619-4.619A4.619,4.619,0,0,1,50.808,41.57ZM27.714,46.189a4.619,4.619,0,1,0-4.619-4.619A4.619,4.619,0,0,0,27.714,46.189Z" transform="translate(0 0)" fill="#2dd4a7" fill-rule="evenodd"/></g></svg><div><strong>Bravos</strong><small>by bugb</small></div></div>
120
+ <h2>Review progress</h2>
121
+ <div class="totals" aria-live="polite"><b id="remaining">0</b><span>required decisions left</span></div>
122
+ <div id="segments" role="group" aria-label="Jump to a question"></div><div id="legend"></div>
123
+ <nav id="sectionnav" aria-label="Intake sections"></nav>
124
+ </aside>
125
+ <article>
126
+ <header class="foliohead"><div id="record" hidden><span class="metakey">Repository</span><b id="repo"></b></div>
127
+ <div id="lens" class="lens" hidden><span class="metakey">Draft perspective</span><b id="perspective"></b></div></header>
128
+ <h1 id="heading" tabindex="-1">Review</h1><p id="sub"></p>
129
+ <section class="scope" id="matrix" hidden><h2>Who may do what</h2><p>Each cell opens a proposed permission for review.</p></section>
130
+ <details id="sources" class="srcs" hidden><summary id="sourcecount"></summary><div id="sourcelist"></div></details>
131
+ <div class="bar" id="review-actions"><label for="who">Reviewer</label><input id="who" placeholder="Your name" autocomplete="name" maxlength="80">
132
+ <button id="save" class="primary">Confirm</button><button id="draftfile">Download review inputs</button><button id="done">Done</button></div>
133
+ <div id="status" class="note hidden" role="status"></div><div id="questions"></div>
134
+ <a href="#review-actions">Return to review actions ↑</a>
135
+ </article>
90
136
  </main>
91
137
  <script type="application/json" id="bravos-data">__BRAVOS_DATA__</script>
92
138
  <script>
@@ -99,31 +145,83 @@ details.facts > summary { cursor: pointer; color: var(--muted); padding: 8px 0;
99
145
  // Every piece of draft text is untrusted (it came from repo files): built with textContent only.
100
146
  const el = (tag, cls, text) => { const e = document.createElement(tag); if (cls) e.className = cls; if (text !== undefined) e.textContent = String(text); return e; };
101
147
 
102
- const C = { '▓': '#3b6779', '▄': '#55899e', '▀': '#55899e', '█': '#33d49d', '▐': '#33d49d', '▌': '#33d49d' };
103
- const W = { '█': '#33d49d' };
104
- const paint = (pre, lines, map, fallback) => {
105
- for (const line of lines) {
106
- for (const ch of line) {
107
- const s = el('span', '', ch);
108
- const c = map[ch] || (fallback && ch !== ' ' ? fallback : null);
109
- if (c) s.style.color = c;
110
- pre.appendChild(s);
111
- }
112
- pre.appendChild(document.createTextNode('\n'));
148
+ const isIntent = draft.kind === 'intent' || draft.kind === 'intent-refresh';
149
+ const owner = draft.perspective === 'owner';
150
+ $('heading').textContent = isIntent ? (owner ? 'Owner intake' : 'Context intake') : DATA.heading;
151
+ document.title = $('heading').textContent + ' · Bravos';
152
+ $('sub').textContent = isIntent
153
+ ? owner ? 'Confirm what the product is for, who may act, and which outcomes must never occur.'
154
+ : 'Review the proposed scope, assumptions and boundaries. Make each decision marked as needing your call.'
155
+ : 'Review the questions below and confirm your answers.';
156
+ if (draft.repo) {
157
+ const label = DATA.repoUrl ? el('a') : el('span');
158
+ if (DATA.repoUrl) {
159
+ label.href = DATA.repoUrl;
160
+ label.target = '_blank';
161
+ label.rel = 'noopener noreferrer';
113
162
  }
114
- };
115
- paint($('mascot'), DATA.mascot, C);
116
- paint($('wordmark'), DATA.logo, W, '#0360a2');
117
- $('heading').textContent = DATA.heading;
118
- $('sub').textContent = `${draft.repo || ''} · drafted ${draft.drafted || ''} · ${draft.questions.length} questions`;
163
+ const split = draft.repo.lastIndexOf('/');
164
+ if (split > 0) label.append(el('span', 'org', draft.repo.slice(0, split) + ' / '));
165
+ label.append(document.createTextNode(draft.repo.slice(split + 1)));
166
+ $('repo').append(label);
167
+ $('record').hidden = false;
168
+ }
169
+ if (draft.perspective) {
170
+ $('perspective').textContent = owner ? 'Owner' : 'Researcher';
171
+ $('lens').hidden = false;
172
+ }
173
+ $('done').hidden = mode.kind !== 'serve';
174
+ const sources = DATA.sources || [];
175
+ const citations = [...new Set(draft.questions.flatMap((q) => q.sources || []))];
176
+ function downloadJson(filename, value) {
177
+ const link = document.createElement('a');
178
+ const url = URL.createObjectURL(new Blob([JSON.stringify(value, null, 2) + '\n'], { type: 'application/json' }));
179
+ link.href = url;
180
+ link.download = filename;
181
+ link.click();
182
+ setTimeout(() => URL.revokeObjectURL(url), 1500);
183
+ }
184
+ // The export contains review inputs already visible to this reviewer. Never serialize mode (its loopback token), prior answers, or a local path as a document request.
185
+ $('draftfile').addEventListener('click', () => {
186
+ downloadJson(draft.kind + '-review-inputs.json', { draft, citations, sources });
187
+ });
188
+ if (citations.length || sources.length) {
189
+ $('sources').hidden = false;
190
+ $('sourcecount').textContent = 'Sources · ' + citations.length + ' cited reference' + (citations.length === 1 ? '' : 's');
191
+ const list = $('sourcelist');
192
+ if (mode.kind === 'artifact') {
193
+ list.append(el('p', '', 'Shared reviews include citations only. Read the documents in the source repository.'));
194
+ } else if (citations.length) {
195
+ list.append(el('p', '', 'Each included snapshot matches the SHA-256 in the current source store. Other references are listed as citations.'));
196
+ }
197
+ for (const source of sources) {
198
+ const details = el('details');
199
+ details.append(el('summary', '', source.id + ' · ' + source.title));
200
+ details.append(el('div', '', 'Current stored source · ' + source.kind + ' · SHA-256 ' + source.sha256));
201
+ details.append(el('pre', '', source.text));
202
+ list.append(details);
203
+ }
204
+ if (citations.length) {
205
+ const refs = el('details');
206
+ refs.append(el('summary', '', 'Cited references'));
207
+ const items = el('ul');
208
+ for (const ref of citations) items.append(el('li', '', ref));
209
+ refs.append(items);
210
+ list.append(refs);
211
+ }
212
+ const draftDownload = el('button', '', 'Download draft JSON');
213
+ draftDownload.type = 'button';
214
+ draftDownload.onclick = () => downloadJson(draft.kind + '-draft.json', draft);
215
+ list.append(draftDownload);
216
+ }
119
217
 
120
218
  const store = { get: (k) => { try { return localStorage.getItem(k); } catch { return null; } }, set: (k, v) => { try { localStorage.setItem(k, v); } catch { /* private window */ } } };
121
219
  $('who').value = store.get('bravos-review-name') || '';
122
220
  $('who').addEventListener('change', () => store.set('bravos-review-name', $('who').value.trim()));
123
221
 
124
222
  const qs = draft.questions;
125
- const state = {}; // id -> { verdict, value, touched, comment }
126
- const cards = {};
223
+ const state = Object.create(null); // id -> { verdict, value, touched, comment }
224
+ const cards = Object.create(null);
127
225
  const sameValue = (a, b) => JSON.stringify(Array.isArray(a) ? [...a].sort() : a) === JSON.stringify(Array.isArray(b) ? [...b].sort() : b);
128
226
  const status = (msg) => { const s = $('status'); s.textContent = msg; s.classList.remove('hidden'); };
129
227
 
@@ -134,32 +232,155 @@ details.facts > summary { cursor: pointer; color: var(--muted); padding: 8px 0;
134
232
  }
135
233
 
136
234
  const needsCall = (q) => q.mustTouch && !state[q.id].touched;
137
- const decide = (q, value, explicit) => {
235
+ const decide = (q, value, explicit, editInPlace = false) => {
138
236
  const s = state[q.id];
139
237
  s.value = value;
140
238
  s.touched = s.touched || explicit;
141
- if (value === 'no') s.verdict = 'no';
239
+ if (q.type === 'item' && value === 'no') s.verdict = 'no';
142
240
  else if (q.suggested !== undefined && sameValue(value, q.suggested)) s.verdict = q.mustTouch ? (s.touched ? 'chosen' : 'accepted') : 'accepted';
143
241
  else s.verdict = value === null || (Array.isArray(value) && value.length === 0 && q.type !== 'multi') ? null : 'edited';
144
- render(q);
242
+ if (editInPlace) {
243
+ const card = cards[q.id];
244
+ card.replaceChild(badges(q), card.firstElementChild);
245
+ const keep = card.querySelector('.keep');
246
+ if (keep && !needsCall(q)) keep.remove();
247
+ } else {
248
+ const old = document.activeElement;
249
+ const oldIndex = Array.from(cards[q.id].querySelectorAll('button')).indexOf(old);
250
+ render(q);
251
+ const focusTarget = cards[q.id].querySelectorAll('button')[oldIndex];
252
+ if (oldIndex >= 0) (focusTarget || cards[q.id]).focus({preventScroll: true});
253
+ }
145
254
  refresh();
146
255
  };
147
256
 
257
+ const stateLabels = {
258
+ pending: 'Needs your call', reviewed: 'Reviewed', suggested: 'Suggested', optional: 'Optional',
259
+ };
260
+ const segments = new Map();
261
+ const counters = new Map();
262
+ function jump(q) {
263
+ const card = cards[q.id];
264
+ const group = card.closest('details');
265
+ if (group) group.open = true;
266
+ card.scrollIntoView({block: 'start'});
267
+ card.focus({preventScroll: true});
268
+ }
269
+ for (const [kind, label] of Object.entries(stateLabels)) {
270
+ const row = el('div', 'legendrow');
271
+ const mark = el('i');
272
+ mark.dataset.kind = kind;
273
+ const count = el('b');
274
+ counters.set(kind, count);
275
+ row.append(mark, el('span', '', label), count);
276
+ $('legend').append(row);
277
+ }
278
+ for (const q of qs) {
279
+ const btn = el('button', 'segment');
280
+ btn.type = 'button';
281
+ btn.addEventListener('click', () => jump(q));
282
+ $('segments').append(btn);
283
+ segments.set(q.id, btn);
284
+ }
148
285
  const refresh = () => {
149
- const left = qs.filter(needsCall);
150
- const answered = qs.filter((q) => state[q.id].verdict).length;
151
- $('progress').style.width = `${Math.round((answered / qs.length) * 100)}%`;
152
- $('count').textContent = left.length ? `${left.length} decision${left.length === 1 ? '' : 's'} left` : `${answered} / ${qs.length} answered`;
153
- $('save').disabled = left.length > 0;
154
- $('save').textContent = left.length ? `Confirm (${left.length} left)` : 'Confirm';
286
+ const counts = { pending: 0, reviewed: 0, suggested: 0, optional: 0 };
287
+ for (const q of qs) {
288
+ const kind = needsCall(q) ? 'pending' : state[q.id].touched ? 'reviewed' : q.suggested !== undefined ? 'suggested' : 'optional';
289
+ counts[kind]++;
290
+ const btn = segments.get(q.id);
291
+ if (btn.dataset.kind === kind) continue;
292
+ btn.dataset.kind = kind;
293
+ btn.title = stateLabels[kind] + ' · ' + (q.title || q.text || q.id);
294
+ btn.setAttribute('aria-label', btn.title);
295
+ }
296
+ for (const [kind, count] of Object.entries(counts)) counters.get(kind).textContent = count;
297
+ $('remaining').textContent = counts.pending;
298
+ $('save').disabled = counts.pending > 0;
299
+ $('save').textContent = mode.kind === 'file' ? 'Download answers' : 'Confirm';
155
300
  };
156
301
 
157
- // Each card is rebuilt from state on change; draft text is set with textContent only.
158
- const render = (q) => {
302
+ // Optional, explicit role/action proposals. Missing cells have no rule. Clicking only navigates to the source question.
303
+ const groups = new Map();
304
+ for (const q of qs) {
305
+ if (!q.permission) continue;
306
+ const key = q.permission.group || q.section || 'Permissions';
307
+ if (!groups.has(key)) groups.set(key, { roles: new Set(), actions: new Map() });
308
+ const group = groups.get(key);
309
+ const {action, role} = q.permission;
310
+ group.roles.add(role);
311
+ if (!group.actions.has(action)) group.actions.set(action, new Map());
312
+ group.actions.get(action).set(role, q);
313
+ }
314
+ for (const [name, group] of groups) {
315
+ const details = el('details', 'policygroup');
316
+ details.open = !$('matrix').querySelector('details');
317
+ const summary = el('summary', '', name + ' ');
318
+ summary.append(el('small', '', group.actions.size + (group.actions.size === 1 ? ' action' : ' actions')));
319
+ const wrap = el('div', 'matrixwrap');
320
+ wrap.tabIndex = 0;
321
+ wrap.setAttribute('role', 'region');
322
+ wrap.setAttribute('aria-label', name);
323
+ const table = el('table');
324
+ table.setAttribute('aria-label', name);
325
+ const uncertain = [];
326
+ const header = table.createTHead().insertRow();
327
+ function heading(row, label, scope) {
328
+ const cell = el('th', '', label);
329
+ cell.scope = scope;
330
+ row.append(cell);
331
+ }
332
+ heading(header, 'Action', 'col');
333
+ for (const role of group.roles) heading(header, role, 'col');
334
+ const body = table.createTBody();
335
+ for (const [action, proposals] of group.actions) {
336
+ const tr = body.insertRow();
337
+ heading(tr, action, 'row');
338
+ for (const role of group.roles) {
339
+ const td = tr.insertCell();
340
+ const q = proposals.get(role);
341
+ if (!q) {
342
+ td.textContent = '—';
343
+ td.setAttribute('aria-label', 'No proposal');
344
+ continue;
345
+ }
346
+ const effect = q.permission.effect;
347
+ const label = effect === 'allow' ? 'Allow' : 'Deny';
348
+ const b = el('button', 'policy ' + effect, label);
349
+ b.type = 'button';
350
+ let accessibleLabel = role + ' · ' + action + ' · proposed ' + label;
351
+ if (q.confidence === 'low') {
352
+ const mark = el('span', 'uncertain', '?');
353
+ mark.setAttribute('aria-hidden', 'true');
354
+ b.append(mark);
355
+ b.title = 'Low confidence · review this proposal';
356
+ accessibleLabel += ' · low confidence';
357
+ uncertain.push(q);
358
+ }
359
+ b.setAttribute('aria-label', accessibleLabel);
360
+ b.addEventListener('click', () => jump(q));
361
+ td.append(b);
362
+ }
363
+ }
364
+ wrap.append(table);
365
+ details.append(summary, wrap);
366
+ $('matrix').append(details);
367
+ if (uncertain.length) {
368
+ const note = el('details', 'policy-note');
369
+ const summary = el('summary', '', 'Needs clarification · ' + uncertain.length + ' in ' + name);
370
+ note.append(summary);
371
+ for (const q of uncertain) {
372
+ const link = el('button', '', q.permission.role + ' · ' + q.permission.action);
373
+ link.type = 'button';
374
+ link.onclick = () => jump(q);
375
+ note.append(link);
376
+ }
377
+ $('matrix').append(note);
378
+ }
379
+ $('matrix').hidden = false;
380
+ }
381
+
382
+ const badges = (q) => {
159
383
  const s = state[q.id];
160
- const card = cards[q.id];
161
- card.replaceChildren();
162
- card.className = `card${s.verdict ? ' done' : ''}${needsCall(q) ? ' must' : ''}`;
163
384
  const top = el('div', 'top');
164
385
  top.appendChild(el('span', 'id', q.id));
165
386
  if (needsCall(q)) top.appendChild(el('span', 'badge must', 'needs your call'));
@@ -167,7 +388,14 @@ details.facts > summary { cursor: pointer; color: var(--muted); padding: 8px 0;
167
388
  else if (s.verdict === 'chosen') top.appendChild(el('span', 'badge chosen', 'your call'));
168
389
  else if (s.verdict === 'accepted') top.appendChild(el('span', 'badge sugg', 'suggested'));
169
390
  if (q.confidence === 'low') top.appendChild(el('span', 'badge low', 'bravos is unsure'));
170
- card.appendChild(top);
391
+ return top;
392
+ };
393
+
394
+ // @comment -- "All repository-controlled review and source strings, and other people's answers, are rendered as DOM text. Permission links navigate to a question and never record consent."
395
+ const render = (q) => {
396
+ const s = state[q.id];
397
+ const card = cards[q.id];
398
+ card.replaceChildren(badges(q));
171
399
  if (q.title) card.appendChild(el('div', 'title', q.title));
172
400
  if (q.why) card.appendChild(el('div', 'why', q.why));
173
401
  if (q.type === 'item' && q.text) card.appendChild(el('div', 'text', q.text));
@@ -175,7 +403,13 @@ details.facts > summary { cursor: pointer; color: var(--muted); padding: 8px 0;
175
403
  if (q.sources && q.sources.length) card.appendChild(el('div', 'sources', `from ${q.sources.join(' · ')}`));
176
404
 
177
405
  const row = el('div', 'choices');
178
- const btn = (label, on, fn) => { const b = el('button', on ? 'on' : '', label); b.type = 'button'; b.addEventListener('click', fn); row.appendChild(b); return b; };
406
+ const btn = (label, on, fn) => {
407
+ const button = el('button', on ? 'on' : '', label);
408
+ button.type = 'button';
409
+ button.setAttribute('aria-pressed', String(on));
410
+ button.addEventListener('click', fn);
411
+ row.append(button);
412
+ };
179
413
  if (q.type === 'choice') {
180
414
  for (const o of q.options) btn(`${o.id === q.suggested ? '★ ' : ''}${o.label}`, s.value === o.id, () => decide(q, o.id, true));
181
415
  } else if (q.type === 'multi') {
@@ -194,16 +428,20 @@ details.facts > summary { cursor: pointer; color: var(--muted); padding: 8px 0;
194
428
  btn('No', s.value === 'no', () => decide(q, 'no', true));
195
429
  if (isText) {
196
430
  const t = el('textarea');
431
+ t.setAttribute('aria-label', q.title || q.id);
197
432
  t.value = s.value;
198
- t.addEventListener('change', () => decide(q, t.value, true));
433
+ t.maxLength = 4000;
434
+ t.addEventListener('input', () => decide(q, t.value, true, true));
199
435
  card.appendChild(row);
200
436
  card.appendChild(t);
201
437
  }
202
438
  }
203
439
  if (q.type === 'text') {
204
440
  const t = el('textarea');
441
+ t.setAttribute('aria-label', q.title || q.id);
205
442
  t.value = typeof s.value === 'string' ? s.value : '';
206
- t.addEventListener('change', () => decide(q, t.value, true));
443
+ t.maxLength = 4000;
444
+ t.addEventListener('input', () => decide(q, t.value, true, true));
207
445
  card.appendChild(t);
208
446
  }
209
447
  if (q.type !== 'text' && !card.contains(row)) card.appendChild(row);
@@ -214,7 +452,9 @@ details.facts > summary { cursor: pointer; color: var(--muted); padding: 8px 0;
214
452
  card.appendChild(keep);
215
453
  }
216
454
  const c = el('textarea', 'comment');
455
+ c.setAttribute('aria-label', 'Comment on ' + (q.title || q.id));
217
456
  c.placeholder = 'Comment (optional)';
457
+ c.maxLength = 4000;
218
458
  c.value = s.comment;
219
459
  c.addEventListener('input', () => { s.comment = c.value; });
220
460
  card.appendChild(c);
@@ -227,15 +467,21 @@ details.facts > summary { cursor: pointer; color: var(--muted); padding: 8px 0;
227
467
  const name = q.section || 'Questions';
228
468
  let sec = sections.find((x) => x.name === name);
229
469
  if (!sec) sections.push((sec = { name, open: [], folded: [] }));
230
- (q.folded ? sec.folded : sec.open).push(q);
470
+ (q.folded && !q.mustTouch ? sec.folded : sec.open).push(q);
231
471
  }
232
- const mount = (parent, q) => { const card = el('div', 'card'); cards[q.id] = card; parent.appendChild(card); render(q); };
472
+ const mount = (parent, q) => { const card = el('div', 'card'); card.tabIndex = -1; cards[q.id] = card; parent.appendChild(card); render(q); };
233
473
  for (const sec of sections) {
234
- $('questions').appendChild(el('h2', '', sec.name));
474
+ const heading = el('h2', 'sectiontitle', sec.name);
475
+ heading.id = 'section-' + sections.indexOf(sec);
476
+ $('questions').append(heading);
477
+ const link = el('a', '', sec.name);
478
+ link.href = '#' + heading.id;
479
+ link.append(el('span', '', sec.open.length + sec.folded.length));
480
+ $('sectionnav').append(link);
235
481
  for (const q of sec.open) mount($('questions'), q);
236
482
  if (sec.folded.length) {
237
483
  const d = el('details', 'facts');
238
- d.appendChild(el('summary', '', `${sec.folded.length} fact${sec.folded.length === 1 ? '' : 's'} bravos drafted — accepted unless you open one to object`));
484
+ d.appendChild(el('summary', '', `${sec.folded.length} fact${sec.folded.length === 1 ? '' : 's'} in this section`));
239
485
  for (const q of sec.folded) mount(d, q);
240
486
  $('questions').appendChild(d);
241
487
  }
@@ -247,17 +493,19 @@ details.facts > summary { cursor: pointer; color: var(--muted); padding: 8px 0;
247
493
  const box = cards[q.id]._others;
248
494
  box.replaceChildren();
249
495
  for (const f of all) {
250
- const a = f.answers && f.answers[q.id];
496
+ const a = f && f.answers && Object.hasOwn(f.answers, q.id) && f.answers[q.id];
251
497
  if (!a) continue;
252
498
  const v = a.value !== undefined ? (Array.isArray(a.value) ? a.value.join(', ') : a.value) : a.choice || a.text || '';
253
- box.appendChild(el('span', `chip ${a.verdict === 'no' ? 'no' : a.verdict === 'edited' ? 'edit' : 'agree'}`, `${f.by}: ${a.verdict}${v && a.verdict !== 'accepted' ? ` — ${v}` : ''}`));
499
+ const chip = el('span', 'chip ' + (a.verdict === 'no' ? 'no' : a.verdict === 'edited' ? 'edit' : 'agree'));
500
+ chip.textContent = f.by + ': ' + a.verdict + (v && a.verdict !== 'accepted' ? ' — ' + v : '') + (a.comment ? ' · ' + a.comment : '');
501
+ box.append(chip);
254
502
  }
255
503
  }
256
504
  };
257
505
 
258
506
  const payload = () => {
259
507
  const by = $('who').value.trim();
260
- const answers = {};
508
+ const answers = Object.create(null);
261
509
  for (const q of qs) {
262
510
  const s = state[q.id];
263
511
  if (!s.verdict && !s.comment) continue;
@@ -291,7 +539,7 @@ details.facts > summary { cursor: pointer; color: var(--muted); padding: 8px 0;
291
539
 
292
540
  $('save').addEventListener('click', async () => {
293
541
  const p = payload();
294
- if (!p.by) { status('Add your name first, so your answers are confirmed by you.'); $('who').focus(); return; }
542
+ if (!slug(p.by)) { status('Enter a name containing a letter a–z or a digit to identify your answers file.'); $('who').focus(); return; }
295
543
  store.set('bravos-review-name', p.by);
296
544
  try {
297
545
  if (mode.kind === 'serve') {
@@ -310,10 +558,7 @@ details.facts > summary { cursor: pointer; color: var(--muted); padding: 8px 0;
310
558
  return;
311
559
  }
312
560
  } catch (e) { status(`Could not save to the server (${e.message || e}); downloading the file instead.`); }
313
- const a = document.createElement('a');
314
- a.href = URL.createObjectURL(new Blob([JSON.stringify(p, null, 2) + '\n'], { type: 'application/json' }));
315
- a.download = `${slug(p.by)}.json`;
316
- a.click();
561
+ downloadJson(slug(p.by) + '.json', p);
317
562
  status(`Downloaded ${slug(p.by)}.json. Put it in .guardlink/${draft.kind}-answers/ and commit it.`);
318
563
  });
319
564