@bugb-technologies/bravos 1.6.0 → 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.
- package/dist/cli.js +4 -4
- package/dist/context.js +36 -0
- package/dist/guide.js +2 -2
- package/dist/palette.js +4 -4
- package/dist/review-server.js +4 -4
- package/dist/review.js +103 -18
- package/dist/watch-frame.js +67 -42
- package/dist/watch.js +21 -7
- package/docs/GUIDE.md +2 -2
- package/docs/UPGRADING.md +8 -0
- package/hooks/lib/briefing.mjs +185 -166
- package/hooks/lib/palette.mjs +4 -4
- package/hooks/session-start.mjs +24 -2
- package/package.json +1 -1
- package/skills/bravos-context/SKILL.md +1 -0
- package/templates/review/review.html +368 -123
|
@@ -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>
|
|
8
|
-
<!-- bravos (managed by bravos review; regenerated from
|
|
7
|
+
<title>Bravos review</title>
|
|
8
|
+
<!-- bravos (managed by bravos review; regenerated from the review draft) -->
|
|
9
9
|
<style>
|
|
10
10
|
:root {
|
|
11
|
-
|
|
12
|
-
--bg: #
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
.
|
|
24
|
-
.
|
|
25
|
-
|
|
26
|
-
.
|
|
27
|
-
|
|
28
|
-
.
|
|
29
|
-
.
|
|
30
|
-
|
|
31
|
-
button { font: inherit;
|
|
32
|
-
button
|
|
33
|
-
button
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
.
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
.
|
|
42
|
-
.
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
.
|
|
48
|
-
|
|
49
|
-
.
|
|
50
|
-
.
|
|
51
|
-
.
|
|
52
|
-
|
|
53
|
-
.
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
.
|
|
57
|
-
.
|
|
58
|
-
.
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
.
|
|
65
|
-
|
|
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
|
-
<
|
|
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
|
-
<
|
|
81
|
-
<
|
|
82
|
-
<
|
|
83
|
-
<div class="
|
|
84
|
-
<
|
|
85
|
-
<
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
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 =
|
|
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
|
-
|
|
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
|
|
150
|
-
const
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
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
|
-
//
|
|
158
|
-
const
|
|
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
|
-
|
|
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) => {
|
|
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.
|
|
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.
|
|
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
|
-
|
|
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'}
|
|
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
|
-
|
|
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('
|
|
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
|
-
|
|
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
|
|