@v11g/agents-rock 1.0.3 → 1.0.5

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 (61) hide show
  1. package/README.md +4 -2
  2. package/package.json +1 -1
  3. package/plugins/business-analyst/.claude-plugin/plugin.json +1 -1
  4. package/plugins/business-analyst/skills/business-analyst/README.md +4 -1
  5. package/plugins/business-analyst/skills/business-analyst/SKILL.md +6 -2
  6. package/plugins/business-analyst/skills/business-analyst/scripts/test/python-parity.test.mjs +50 -0
  7. package/plugins/business-analyst/skills/business-analyst/scripts/validate.py +288 -0
  8. package/plugins/solution-architect/.claude-plugin/plugin.json +1 -1
  9. package/plugins/solution-architect/skills/analyze-requirements/assets/viewer-template.html +4 -2
  10. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/chrome.mjs +4 -1
  11. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/viewer-template.test.mjs +3 -2
  12. package/plugins/solution-architect/skills/estimate/README.md +8 -5
  13. package/plugins/solution-architect/skills/estimate/SKILL.md +9 -5
  14. package/plugins/solution-architect/skills/estimate/assets/estimate-template-agentic.html +142 -376
  15. package/plugins/solution-architect/skills/estimate/assets/estimate-template.html +610 -601
  16. package/plugins/solution-architect/skills/estimate/assets/scores-review-template.html +118 -0
  17. package/plugins/solution-architect/skills/estimate/references/ai-multipliers.md +5 -9
  18. package/plugins/solution-architect/skills/estimate/references/interview.md +121 -10
  19. package/plugins/solution-architect/skills/estimate/references/scoring-guide.md +23 -0
  20. package/plugins/solution-architect/skills/estimate/references/techniques.md +9 -2
  21. package/plugins/solution-architect/skills/estimate/references/writing.md +21 -5
  22. package/plugins/solution-architect/skills/estimate/scripts/lib/agentic-checks.mjs +1 -1
  23. package/plugins/solution-architect/skills/estimate/scripts/lib/checks.mjs +4 -30
  24. package/plugins/solution-architect/skills/estimate/scripts/lib/estimate-math.mjs +14 -10
  25. package/plugins/solution-architect/skills/estimate/scripts/lib/inline.mjs +6 -8
  26. package/plugins/solution-architect/skills/estimate/scripts/lib/md-tables.mjs +31 -0
  27. package/plugins/solution-architect/skills/estimate/scripts/lib/redact.mjs +14 -3
  28. package/plugins/solution-architect/skills/estimate/scripts/lib/rollup.mjs +5 -4
  29. package/plugins/solution-architect/skills/estimate/scripts/lib/scenario-schema.mjs +39 -0
  30. package/plugins/solution-architect/skills/estimate/scripts/lib/schema.mjs +4 -14
  31. package/plugins/solution-architect/skills/estimate/scripts/lib/score-csv.mjs +58 -0
  32. package/plugins/solution-architect/skills/estimate/scripts/lib/score-diff.mjs +30 -0
  33. package/plugins/solution-architect/skills/estimate/scripts/lib/score-html.mjs +17 -0
  34. package/plugins/solution-architect/skills/estimate/scripts/lib/scoring-checks.mjs +24 -0
  35. package/plugins/solution-architect/skills/estimate/scripts/lib/scoring-schema.mjs +48 -0
  36. package/plugins/solution-architect/skills/estimate/scripts/lib/scoring.mjs +45 -0
  37. package/plugins/solution-architect/skills/estimate/scripts/render.mjs +14 -13
  38. package/plugins/solution-architect/skills/estimate/scripts/score-review.mjs +59 -0
  39. package/plugins/solution-architect/skills/estimate/scripts/test/browser.test.mjs +403 -316
  40. package/plugins/solution-architect/skills/estimate/scripts/test/compute.test.mjs +25 -1
  41. package/plugins/solution-architect/skills/estimate/scripts/test/estimate-math.test.mjs +29 -10
  42. package/plugins/solution-architect/skills/estimate/scripts/test/fixtures/agentic-inputs.json +2 -2
  43. package/plugins/solution-architect/skills/estimate/scripts/test/fixtures/booking-inputs.json +21 -3
  44. package/plugins/solution-architect/skills/estimate/scripts/test/fixtures/estimation-fail.md +1 -1
  45. package/plugins/solution-architect/skills/estimate/scripts/test/fixtures/estimation-pass.md +4 -4
  46. package/plugins/solution-architect/skills/estimate/scripts/test/references.test.mjs +61 -6
  47. package/plugins/solution-architect/skills/estimate/scripts/test/render.test.mjs +96 -13
  48. package/plugins/solution-architect/skills/estimate/scripts/test/schema.test.mjs +105 -4
  49. package/plugins/solution-architect/skills/estimate/scripts/test/score-review.test.mjs +187 -0
  50. package/plugins/solution-architect/skills/estimate/scripts/test/scoring.test.mjs +49 -0
  51. package/plugins/solution-architect/skills/estimate/scripts/test/url-state.test.mjs +198 -0
  52. package/plugins/solution-architect/skills/estimate/scripts/test/validate.test.mjs +38 -0
  53. package/plugins/solution-architect/skills/estimate/scripts/test/xlsx-export.test.mjs +93 -28
  54. package/plugins/solution-architect/skills/new-lead/assets/dashboard/detail.html +25 -50
  55. package/plugins/solution-architect/skills/new-lead/assets/dashboard/index.html +20 -40
  56. package/plugins/solution-architect/skills/new-lead/scripts/lib/map-nodes.mjs +13 -5
  57. package/plugins/solution-architect/skills/new-lead/scripts/serve.mjs +8 -3
  58. package/plugins/solution-architect/skills/new-lead/scripts/test/map.test.mjs +4 -0
  59. package/plugins/solution-architect/skills/new-lead/scripts/test/serve.test.mjs +25 -21
  60. package/plugins/solution-architect/skills/proposal/scripts/test/checks-client.test.mjs +2 -2
  61. package/plugins/solution-architect/skills/proposal/scripts/test/figures.test.mjs +1 -1
@@ -13,8 +13,8 @@
13
13
  /* color-scheme is declared, not left at `normal`: a page that never states its
14
14
  scheme is the page a force-dark browser rewrites, and then the toggle flips
15
15
  data-theme with nothing visible changing — the button reads as broken. Stated
16
- per theme, forced dark is off and the native controls in the what-if rail
17
- (number, range, select) follow the page instead of fighting it.
16
+ per theme, forced dark is off and the native controls (the breakdown's
17
+ selects and buttons) follow the page instead of fighting it.
18
18
 
19
19
  The light palette is unconditional and the dark one is scoped to @media screen
20
20
  below, so this block doubles as the paper palette: the page opens dark on a
@@ -83,12 +83,6 @@ header h1 {
83
83
  #confidence-badge.high { color:var(--ok); border-color:var(--ok); background:rgba(21,128,61,.08); }
84
84
  #confidence-badge.med { color:var(--warn); border-color:var(--warn); background:var(--warn-soft); }
85
85
  #confidence-badge.low { color:var(--bad); border-color:var(--bad); background:rgba(185,28,28,.08); }
86
- #modified-banner {
87
- margin:0; padding:.5rem max(1.25rem, calc((100% - 1160px) / 2));
88
- background:var(--warn-soft); color:var(--warn); font-size:.85rem;
89
- border-bottom:1px solid var(--border);
90
- }
91
- #modified-banner button { margin-left:.5rem; }
92
86
  main {
93
87
  display:grid; grid-template-columns:1fr; gap:1.1rem;
94
88
  max-width:1160px; margin:0 auto; padding:1.25rem 1.25rem 3rem;
@@ -99,17 +93,35 @@ main section h2, main aside h2 {
99
93
  font-size:.82rem; font-weight:600; color:var(--ink-dim);
100
94
  margin:0 0 .8rem; letter-spacing:.01em;
101
95
  }
102
- /* panels: every section except the scenario card grid reads as one surface */
96
+ /* panels: every section reads as one surface */
103
97
  .col > section {
104
98
  background:var(--card); border:1px solid var(--border); border-radius:.6rem;
105
99
  padding:1.1rem 1.2rem; box-shadow:var(--shadow);
106
100
  }
107
- #scenario-cards { background:none; border:none; box-shadow:none; padding:0; display:flex; flex-direction:column; }
108
- #scenario-cards .cards {
109
- flex:1; display:grid; grid-template-columns:repeat(auto-fit, minmax(190px, 1fr)); gap:.9rem;
110
- }
111
101
  .sec-head { display:flex; align-items:center; gap:.45rem; margin:0 0 .8rem; }
112
102
  .sec-head h2 { margin:0; }
103
+ /* summary: the estimate's headline — team, months and cost stated once, then
104
+ the committed alternatives as one small table (internal view only). */
105
+ #summary .lead { font-size:1.02rem; font-weight:600; margin:0 0 .25rem; }
106
+ #summary .figures {
107
+ font-size:1.7rem; font-weight:600; letter-spacing:-.02em; line-height:1.15;
108
+ font-variant-numeric:tabular-nums; margin:0 0 .4rem;
109
+ }
110
+ #summary .sep { color:var(--ink-dim); margin:0 .4rem; font-weight:400; }
111
+ #summary .range, #summary .meta {
112
+ margin:.15rem 0; font-family:'IBM Plex Mono',monospace; font-size:.78rem; color:var(--ink-dim);
113
+ }
114
+ #summary .alts { margin-top:.9rem; padding-top:.7rem; border-top:1px solid var(--border); }
115
+ #summary .alts caption {
116
+ text-align:left; font-size:.72rem; text-transform:uppercase; letter-spacing:.05em;
117
+ color:var(--ink-dim); margin-bottom:.3rem;
118
+ }
119
+ #summary .why { font-size:.84rem; margin:0 0 .5rem; }
120
+ #summary .delta {
121
+ font-family:'IBM Plex Mono',monospace; font-size:.72rem; color:var(--warn);
122
+ background:var(--warn-soft); padding:.12rem .4rem; border-radius:.25rem;
123
+ }
124
+ #summary .insight { font-size:.86rem; margin:.6rem 0 0; }
113
125
  details.help { position:relative; display:inline-block; line-height:1; }
114
126
  details.help summary {
115
127
  list-style:none; cursor:help; width:1.05rem; height:1.05rem; border-radius:50%;
@@ -126,7 +138,7 @@ details.help > p {
126
138
  color:var(--ink); text-transform:none; letter-spacing:normal; text-align:left;
127
139
  box-shadow:var(--shadow);
128
140
  }
129
- #controls details.help > p, td details.help > p, caption details.help > p { left:auto; right:0; }
141
+ td details.help > p, caption details.help > p { left:auto; right:0; }
130
142
  #method summary { list-style:none; display:flex; align-items:baseline; gap:.6rem; cursor:pointer; }
131
143
  #method summary::-webkit-details-marker { display:none; }
132
144
  #method summary h2 { margin:0; }
@@ -137,69 +149,6 @@ details.help > p {
137
149
  #method li { margin-bottom:.35rem; }
138
150
  #method .sources { font-size:.78rem; color:var(--ink-dim); margin:0; }
139
151
  #method .sources span { display:block; margin-bottom:.2rem; }
140
- .card {
141
- position:relative; background:var(--card); border:1px solid var(--border);
142
- border-radius:.6rem; padding:1rem 1.1rem; box-shadow:var(--shadow);
143
- }
144
- /* card anatomy: header, hero (top-aligned so the months figures sit on the
145
- same line across cards), facts pinned to the bottom. */
146
- .scenario { display:flex; flex-direction:column; gap:.7rem; padding:1.2rem; }
147
- .scenario h3 {
148
- font-family:'IBM Plex Mono',monospace; font-size:.78rem; font-weight:600;
149
- color:var(--ink-dim); margin:0; overflow-wrap:anywhere;
150
- }
151
- .hero { flex:1; display:flex; flex-direction:column; justify-content:flex-start; gap:.55rem; }
152
- .hero .num {
153
- font-size:2.2rem; font-weight:600; line-height:1.05; letter-spacing:-.02em;
154
- font-variant-numeric:tabular-nums;
155
- }
156
- .hero .unit { font-size:.8rem; color:var(--ink-dim); }
157
- .gauge { height:.45rem; background:var(--border); border-radius:.3rem; overflow:hidden; }
158
- .gauge span { display:block; height:100%; background:var(--accent); border-radius:.3rem; }
159
- .delta {
160
- align-self:flex-start; font-family:'IBM Plex Mono',monospace; font-size:.68rem;
161
- color:var(--warn); background:var(--warn-soft); padding:.14rem .45rem; border-radius:.25rem;
162
- }
163
- .facts {
164
- display:grid; grid-template-columns:1fr 1fr; gap:.7rem 1.1rem;
165
- border-top:1px solid var(--border); padding-top:.8rem; margin:0;
166
- }
167
- .facts dt { font-size:.66rem; text-transform:uppercase; letter-spacing:.05em; color:var(--ink-dim); }
168
- .facts dd { margin:.1rem 0 0; font-family:'IBM Plex Mono',monospace; font-size:.86rem; }
169
- .scenario.recommended { border-color:var(--accent); background:linear-gradient(var(--accent-soft), transparent 55%) var(--card); }
170
- .flag {
171
- position:absolute; top:.7rem; right:.8rem; font-size:.62rem; font-weight:600;
172
- letter-spacing:.04em; color:var(--accent-ink); background:var(--accent-soft);
173
- padding:.14rem .4rem; border-radius:.25rem;
174
- }
175
- .months { margin:.2rem 0 .9rem; font-size:.8rem; color:var(--ink-dim); }
176
- .months .num {
177
- display:block; font-size:2.4rem; font-weight:600; line-height:1.15;
178
- color:var(--ink); font-variant-numeric:tabular-nums; letter-spacing:-.02em;
179
- }
180
- #whatif-readout dl { display:flex; gap:1.2rem; margin:0; }
181
- #whatif-readout dt { font-size:.66rem; text-transform:uppercase; letter-spacing:.05em; color:var(--ink-dim); }
182
- #whatif-readout dd { margin:0; font-family:'IBM Plex Mono',monospace; font-size:.88rem; }
183
- #whatif-readout { border-top:1px solid var(--border); padding-top:.7rem; }
184
- #whatif-readout .months { display:flex; align-items:baseline; gap:.4rem; margin:0 0 .4rem; }
185
- #whatif-readout .months .num { font-size:1.3rem; color:var(--accent-ink); }
186
- /* bars are styled divs — width set inline from data, no canvas, printable */
187
- /* when the section is stretched to match the rail beside it, the bars float
188
- to the vertical center instead of leaving a dead band at the bottom. */
189
- #cost-bars { display:flex; flex-direction:column; }
190
- #cost-bars .bar-group { flex:1; display:flex; flex-direction:column; justify-content:center; }
191
- .bar-row { display:flex; align-items:center; gap:.6rem; margin-bottom:.85rem; }
192
- .bar-label {
193
- flex:0 0 170px; font-size:.78rem; color:var(--ink-dim);
194
- white-space:nowrap; overflow:hidden; text-overflow:ellipsis;
195
- }
196
- .bar-track { flex:1; height:1.05rem; background:var(--border); border-radius:.3rem; overflow:hidden; }
197
- .bar-fill { display:block; height:100%; background:var(--accent); opacity:.5; border-radius:.3rem; }
198
- .bar-fill.is-rec { opacity:1; }
199
- .bar-val {
200
- flex:0 0 auto; min-width:5.5rem; text-align:right;
201
- font-family:'IBM Plex Mono',monospace; font-size:.76rem; font-variant-numeric:tabular-nums;
202
- }
203
152
  /* roadmap: Gantt-style shared axis. Every row is a flex triple (label |
204
153
  track | months) with the same label/months widths as the axis strip below
205
154
  it, so a given month lines up under the same x-position in every row's
@@ -261,7 +210,25 @@ tr.conf-low .conf { color:var(--bad); }
261
210
  /* container stripe on a row's first cell: inset shadow — no gap to the table
262
211
  edge. The color arrives per row as --ct-color; the shadow lives here. */
263
212
  td.ct-edge { box-shadow:inset 4px 0 0 var(--ct-color); }
264
- .bd-filters { display:flex; flex-wrap:wrap; gap:.9rem; margin:0 0 .8rem; }
213
+ .bd-filters { display:flex; flex-wrap:wrap; gap:.9rem; margin:0 0 .8rem; align-items:center; }
214
+ /* the tab strip carries the rule under it; the selected tab paints over that
215
+ rule in the accent, so the two read as one edge rather than two lines. */
216
+ .bd-tabs {
217
+ display:flex; flex-wrap:wrap; align-items:flex-end; gap:.9rem;
218
+ margin:0 0 .8rem; border-bottom:1px solid var(--border);
219
+ }
220
+ .tablist { display:flex; gap:1.1rem; margin-bottom:-1px; }
221
+ .tablist [role="tab"] {
222
+ border:none; border-bottom:2px solid transparent; border-radius:0;
223
+ background:none; padding:.3rem .1rem; font-size:.84rem; font-weight:600; color:var(--ink-dim);
224
+ }
225
+ .tablist [role="tab"]:hover { color:var(--accent-ink); }
226
+ .tablist [role="tab"][aria-selected="true"] { color:var(--ink); border-bottom-color:var(--accent); }
227
+ .bd-tabs .bd-filter-group { margin-left:auto; padding-bottom:.35rem; }
228
+ .bd-tabs .bd-filter-group button { font-size:.7rem; padding:.2rem .55rem; border-radius:1rem; }
229
+ /* on screen a panel is named by its tab; the caption is for paper */
230
+ #feature-table caption.panel-name { display:none; }
231
+ .bd-count { font-size:.72rem; color:var(--ink-dim); font-variant-numeric:tabular-nums; }
265
232
  /* effort-by-container donut: slices are stroked circles (pathLength=100 turns
266
233
  stroke-dasharray into percent), legend carries the exact numbers. */
267
234
  #containers .pie-wrap { display:flex; flex-wrap:wrap; align-items:center; gap:1.8rem; }
@@ -303,29 +270,26 @@ td.ct-edge { box-shadow:inset 4px 0 0 var(--ct-color); }
303
270
  color:var(--accent-ink);
304
271
  }
305
272
  #feature-table td.num { white-space:nowrap; }
306
- /* scoring mode: centred mono score cells; a 5 reads hot (review it), the tier
307
- pill warms with size. Task-row .wt cells are that task's score inputs. */
273
+ /* score cells: centred mono; a 5 reads hot (review it), the tier pill warms with size. */
308
274
  #feature-table th.score, #feature-table td.score { text-align:center; }
309
275
  #feature-table td.score { font-family:'IBM Plex Mono',monospace; font-variant-numeric:tabular-nums; }
310
276
  #feature-table td.score.hot { color:var(--bad); font-weight:600; }
311
- #feature-table td.score.total { font-weight:600; }
277
+ #feature-table td.score.total { font-weight:600; white-space:nowrap; }
312
278
  .tier {
313
279
  font-family:'IBM Plex Mono',monospace; font-size:.68rem; font-weight:600;
314
280
  padding:.12rem .45rem; border-radius:.25rem; background:var(--border); color:var(--ink-dim);
315
281
  }
316
282
  .tier.l { background:var(--warn-soft); color:var(--warn); }
317
283
  .tier.xl { background:rgba(185,28,28,.1); color:var(--bad); }
318
- .wt, #feature-table td.score .wt { font-family:'IBM Plex Mono',monospace; font-size:.7rem; color:var(--ink-dim); }
284
+ #feature-table .edge { color:var(--warn); font-size:.7rem; margin-left:.15rem; cursor:help; }
285
+ #feature-table .oob { color:var(--warn); margin-left:.3rem; cursor:help; }
286
+ #feature-table .feat-note { margin-left:1.4rem; }
319
287
  #feature-table details.guide { margin:.9rem 0 0; border-top:1px solid var(--border); padding-top:.7rem; }
320
288
  #feature-table details.guide summary { cursor:pointer; font-size:.78rem; font-weight:600; color:var(--ink-dim); }
321
289
  #feature-table details.guide summary:hover { color:var(--accent-ink); }
322
290
  .guide-table { min-width:860px; font-size:.78rem; margin-top:.6rem; }
323
291
  .guide-table td { color:var(--ink-dim); vertical-align:top; }
324
292
  .guide-table td.dim { color:var(--ink); font-weight:600; white-space:nowrap; }
325
- .guide-table td.dim small {
326
- display:block; font-weight:400; color:var(--ink-dim); font-size:.7rem;
327
- max-width:15rem; white-space:normal; margin-top:.15rem;
328
- }
329
293
  /* hanging indent: the chevron is its own flex item, so 2-line names wrap
330
294
  against their own left edge instead of sliding under the button. */
331
295
  .feat-cell { display:flex; align-items:baseline; gap:.45rem; }
@@ -356,40 +320,39 @@ tr.task-row td { background:var(--bg); }
356
320
  tr.task-row td:first-child { padding-left:2.1rem; }
357
321
  tr.task-row .bd-cell { justify-content:flex-end; }
358
322
  .task-assump { font-size:.76rem; color:var(--ink-dim); }
323
+ /* a score's reasoning: the rubric sentence the number was anchored to, and
324
+ under it the evidence that sentence rests on. Indented to the name above,
325
+ two columns so the factor labels form their own edge. */
326
+ tr.rat-row td { background:var(--bg); }
327
+ /* justify-content pins the pair to the left: an `auto` track absorbs the free
328
+ width of a full-span cell, which opened a hand's width of nothing between
329
+ each factor and the sentence it labels. */
330
+ .rationale {
331
+ display:grid; grid-template-columns:max-content minmax(0, 68ch); justify-content:start;
332
+ gap:.3rem .9rem; margin:0; padding:.1rem 0 .3rem 2.1rem; font-size:.78rem;
333
+ }
334
+ .rationale dt {
335
+ font-family:'IBM Plex Mono',monospace; font-size:.72rem; color:var(--ink-dim); white-space:nowrap;
336
+ }
337
+ .rationale dd { margin:0; }
338
+ .rationale .cite { display:block; color:var(--ink-dim); font-size:.74rem; }
359
339
  #register > div + table, #register > table + table { margin-top:1.4rem; }
360
- /* compact rail: the team roster, the plan select, the sliders, and the
361
- readout stack full-width. Keeps the rail near the height of the two
362
- scenario sections beside it. */
363
- #controls {
364
- background:var(--card); border:1px solid var(--border); border-radius:.6rem;
365
- padding:1.1rem 1.2rem; box-shadow:var(--shadow);
366
- display:grid; grid-template-columns:1fr; gap:.7rem; align-content:start;
367
- }
368
- #controls label { display:flex; flex-direction:column; font-size:.76rem; gap:.3rem; color:var(--ink-dim); }
369
- /* the roster: one row per engineer (seniority + rate + remove), plus add.
370
- Styled by class — the container id is internal-only page text and must
371
- never appear in the head CSS a client render keeps. */
372
- #controls .team { display:flex; flex-direction:column; gap:.4rem; font-size:.76rem; color:var(--ink-dim); }
373
- #controls .team-row { display:flex; gap:.4rem; align-items:center; }
374
- #controls .team-row .cur { margin-right:-.15rem; }
375
- #controls .team-row select { flex:1; min-width:0; }
376
- #controls .team-row input { width:4.6rem; }
377
- #controls .team button { font-size:.76rem; padding:.3rem .5rem; background:var(--bg); color:var(--ink-dim); }
378
- #controls .team button:disabled { opacity:.4; cursor:default; }
379
- #controls .lab { display:flex; justify-content:space-between; align-items:baseline; }
380
- #controls output { font-family:'IBM Plex Mono',monospace; font-size:.74rem; color:var(--ink); }
381
- #controls input, #controls select {
382
- font:inherit; padding:.35rem .45rem; border:1px solid var(--border-strong);
383
- border-radius:.35rem; background:var(--bg); color:var(--ink);
384
- }
385
- #controls input:hover, #controls select:hover { border-color:var(--accent); }
386
- #controls input[type="range"] { padding:0; border:none; background:none; accent-color:var(--accent); }
387
340
  .view-client [data\2d internal] { display:none !important; }
341
+ /* every exception to the rule above: the control that leaves client view
342
+ cannot be one of the things client view hides. */
343
+ .view-client #view-toggle { display:revert !important; }
388
344
  @media print {
389
345
  header { position:static; }
390
- header button, #viewer-link, #controls, #modified-banner, details.help, .bd-filters, .expand { display:none; }
346
+ header button, #viewer-link, details.help, .bd-filters, .bd-tabs, .expand { display:none; }
391
347
  main { grid-template-columns:1fr; }
392
- main > section, .card { box-shadow:none; }
348
+ main > section { box-shadow:none; }
349
+ /* a tab is a screen affordance: on paper both tables print, each under the
350
+ name its tab carried. */
351
+ [role="tabpanel"][hidden] { display:block !important; }
352
+ [role="tabpanel"] + [role="tabpanel"] { margin-top:1.4rem; }
353
+ #feature-table caption.panel-name {
354
+ display:table-caption; text-align:left; font-weight:600; padding-bottom:.4rem;
355
+ }
393
356
  }
394
357
  </style>
395
358
  </head>
@@ -403,61 +366,21 @@ tr.task-row .bd-cell { justify-content:flex-end; }
403
366
  <button id="theme-toggle" type="button">theme</button>
404
367
  <!-- internal:start --><!-- slot:VIEWER --><button id="view-toggle" type="button" data-internal>client view</button><!-- internal:end -->
405
368
  </header>
406
- <p id="modified-banner" role="status" hidden>modified from committed estimate — <button id="reset" type="button">reset</button></p>
407
369
  <main>
408
- <div class="col col-wide">
409
- <section id="method"></section>
410
- </div>
411
370
  <div class="col">
412
- <section id="scenario-cards"></section>
413
- <section id="cost-bars"></section>
414
- </div>
415
- <!-- internal:start -->
416
- <style>
417
- /* internal-only layout: the what-if rail sits beside the scenario sections
418
- only — its readout (months, cost, effort) is comparable to nothing below
419
- the cost bars, so the lower sections take the full width instead of
420
- reserving an empty rail column. Lives in the internal range so the
421
- client-only render collapses back to one column. @media screen so the
422
- print rules in the head keep winning on paper. */
423
- @media screen {
424
- main { grid-template-columns:minmax(0, 1fr) 300px; }
425
- .col-wide { grid-column:1 / -1; }
426
- /* no hole under the cost bars: the scenario-cards row stretches so the
427
- left column always ends level with the rail beside it, and the cards
428
- stay the dominant section. */
429
- .col:not(.col-wide) { grid-template-rows:1fr auto; }
430
- .view-client main { grid-template-columns:1fr; }
431
- }
432
- @media screen and (max-width:900px) {
433
- main { grid-template-columns:1fr; }
434
- }
435
- </style>
436
- <aside class="rail" data-internal>
437
- <div class="sec-head"><h2>What-if</h2><details class="help"><summary aria-label="explain this panel">?</summary>
438
- <p>The levers re-run the exact same formulas as the committed numbers, in your browser. Nothing here changes the committed estimate — it answers "what would it look like if&hellip;". The readout below updates live.</p></details></div>
439
- <div id="controls" data-internal>
440
- <div id="ctl-team" class="team" role="group" aria-label="team"></div>
441
- <label>claude plan <select id="ctl-plan"><option>none</option><option>max5x</option><option>max20x</option></select></label>
442
- <label><span class="lab">AI multiplier <output></output></span><input id="ctl-ai" type="range" min="0" max="1.5" step="0.05"></label>
443
- <label><span class="lab">risk buffer <output></output></span><input id="ctl-buffer" type="range" min="0" max="2" step="0.1"></label>
444
- <label><span class="lab">overhead % <output></output></span><input id="ctl-overhead" type="range" min="0" max="0.6" step="0.05"></label>
445
- <div id="whatif-readout" aria-live="polite"></div>
446
- </div>
447
- </aside>
448
- <!-- internal:end -->
449
- <div class="col col-wide">
371
+ <section id="summary"></section>
450
372
  <section id="containers"></section>
451
373
  <section id="roadmap"></section>
452
374
  <section id="feature-table"></section>
375
+ <template id="scoring-guide"><!-- slot:GUIDE --></template>
453
376
  <section id="register"></section>
377
+ <section id="method"></section>
454
378
  </div>
455
379
  </main>
456
380
  <script type="application/json" id="estimation-data"><!-- slot:DATA --></script>
457
381
  <script>
458
- <!-- slot:MATH -->
459
- /* boot: parse the data island, stamp the title + confidence badge, then wire
460
- the sections, what-if controls, and view/theme toggles. */
382
+ /* boot: parse the data island, stamp the title + confidence badge, then
383
+ render the sections and wire the view/theme toggles. */
461
384
  const DATA = JSON.parse(document.getElementById('estimation-data').textContent);
462
385
  document.querySelector('header h1').textContent = DATA.inputs.project;
463
386
  const confLevel = (c) => `conf-${c.toLowerCase()}`;
@@ -465,196 +388,125 @@ const badge = document.getElementById('confidence-badge');
465
388
  badge.textContent = DATA.computed.projectConfidence;
466
389
  badge.className = `${DATA.computed.projectConfidence.toLowerCase()} ${confLevel(DATA.computed.projectConfidence)}`;
467
390
 
468
- // Same math path as the committed numbers: recompute() is both the page's
469
- // what-if engine and the parity hook the browser tests call directly.
470
- // p.team is a real roster ([{seniority, rate}, …]) — effort follows the
471
- // dominant seniority exactly like the committed rollup, cost follows each
472
- // member's own rate.
473
- function recompute(p) {
474
- const tasks = DATA.inputs.features.flatMap((f) => f.tasks);
475
- const seniority = dominantSeniority(p.team);
476
- const hoursOf = (t) => taskHours({ e: pert(t).e, seniority, plan: p.plan,
477
- category: t.category, verificationPct: DATA.inputs.verificationPct, scale: p.aiScale });
478
- const dev = tasks.reduce((s, t) => s + hoursOf(t), 0);
479
- const buffers = (riskBufferHours(DATA.inputs.risks)
480
- + projectBuffer(tasks.map((t) => pert(t).sigma))) * p.bufferScale;
481
- const hours = dev + dev * p.overheadPct + buffers;
482
- return { hours, ...scenarioRollup({ hours, team: p.team, plan: p.plan }) };
483
- }
484
- window.__recompute = recompute;
485
-
486
- function defaultsFromRecommended() {
487
- const rec = DATA.inputs.scenarios.find((s) => s.id === DATA.inputs.recommendedScenario);
488
- return {
489
- team: rec.team.map((m) => ({ ...m })),
490
- plan: rec.plan,
491
- aiScale: 1,
492
- bufferScale: 1,
493
- overheadPct: DATA.inputs.overheadPct,
494
- };
391
+ // Summary: the recommended scenario stated once — team, AI assistance,
392
+ // months, cost — then the committed alternatives as one small table. Every
393
+ // number is read from estimation.json; nothing is recomputed on the page.
394
+ const recScenario = () => DATA.inputs.scenarios.find((s) => s.id === DATA.inputs.recommendedScenario);
395
+ const sameTeam = (a, b) => a.team.length === b.team.length
396
+ && a.team.every((m, i) => m.seniority === b.team[i].seniority && m.rate === b.team[i].rate);
397
+ const byMonths = (a, b) => DATA.computed.scenarios[a.id].months - DATA.computed.scenarios[b.id].months;
398
+
399
+ function scenarioLabel(s) {
400
+ const n = s.team.length;
401
+ const who = n === 1 ? `1 ${s.team[0].seniority} engineer`
402
+ : `${n} engineers (${s.team.map((m) => m.seniority).join(' · ')})`;
403
+ return `${who}, ${s.aiAssisted ? 'AI-assisted' : 'humans unaided'}`;
495
404
  }
496
405
 
497
- // Control ids are assembled at runtime (never one static "ctl-*" literal)
498
- // so the client-only render, which keeps this whole script but drops the
499
- // controls markup, never carries an internal control id as page text.
500
- const CTL_SUFFIX = { plan: 'plan', aiScale: 'ai', bufferScale: 'buffer', overheadPct: 'overhead' };
501
- const CTL_KEYS = Object.keys(CTL_SUFFIX);
502
- const ctlId = (key) => `ctl-${CTL_SUFFIX[key]}`;
503
- // The roster container is found by its class — its id is internal-only page
504
- // text, and the class already ships in the head CSS either way.
505
- const teamBox = () => document.querySelector('#controls .team');
506
- const TEAM_MAX = 8;
507
-
508
- function setControls(values) {
509
- CTL_KEYS.forEach((key) => {
510
- const el = document.getElementById(ctlId(key));
511
- if (el) el.value = values[key];
512
- });
406
+ // Signed month and cost deltas against the recommended scenario.
407
+ function deltaText(c, rec) {
408
+ const dm = c.months - rec.months;
409
+ const dc = c.totalCost - rec.totalCost;
410
+ const sign = (v) => (v >= 0 ? '+' : '−');
411
+ return `${sign(dm)}${Math.abs(dm).toFixed(2)} mo · ${sign(dc)}${fmtMoney(Math.abs(dc))}`;
513
412
  }
514
413
 
515
- function syncOutputs() {
516
- CTL_KEYS.forEach((key) => {
517
- const el = document.getElementById(ctlId(key));
518
- const out = el?.parentElement.querySelector('output');
519
- if (out) out.textContent = el.value;
520
- });
414
+ function altRow(s, rec) {
415
+ const c = DATA.computed.scenarios[s.id];
416
+ return `<tr><td>${scenarioLabel(s)}</td><td class="num">${c.months.toFixed(2)}</td>
417
+ <td class="num">${fmtMoney(c.totalCost)}</td><td><span class="delta">${deltaText(c, rec)}</span></td></tr>`;
521
418
  }
522
419
 
523
- // The committed scenarios are the page's only rate table: the first rate
524
- // seen per seniority re-seeds a row's rate when its level changes.
525
- const RATE_BY_SENIORITY = {};
526
- for (const s of DATA.inputs.scenarios) {
527
- for (const m of s.team) if (m.rate != null) RATE_BY_SENIORITY[m.seniority] ??= m.rate;
528
- }
529
-
530
- function teamRow({ seniority, rate }) {
531
- const row = document.createElement('div');
532
- row.className = 'team-row';
533
- const sel = document.createElement('select');
534
- for (const s of Object.keys(SENIORITY_FACTOR)) sel.add(new Option(s, s));
535
- sel.value = seniority;
536
- const cur = Object.assign(document.createElement('span'), { className: 'cur', textContent: '$' });
537
- const rateEl = Object.assign(document.createElement('input'),
538
- { type: 'number', min: 10, max: 300, step: 5, value: rate });
539
- rateEl.setAttribute('aria-label', 'hourly rate');
540
- const del = Object.assign(document.createElement('button'),
541
- { type: 'button', className: 'team-del', textContent: '×' });
542
- del.setAttribute('aria-label', 'remove engineer');
543
- row.append(sel, cur, rateEl, del);
544
- return row;
545
- }
546
-
547
- function syncTeamButtons() {
548
- const box = teamBox();
549
- const rows = box.querySelectorAll('.team-row');
550
- box.querySelector('.team-add').disabled = rows.length >= TEAM_MAX;
551
- rows.forEach((r) => { r.querySelector('.team-del').disabled = rows.length <= 1; });
552
- }
553
-
554
- // Rebuild-from-array is the only write path (boot, reset), so reset can
555
- // never leave stale rows behind.
556
- function renderTeam(team) {
557
- const box = teamBox();
558
- if (!box) return;
559
- box.replaceChildren(
560
- Object.assign(document.createElement('span'), { textContent: 'team' }),
561
- ...team.map(teamRow),
562
- Object.assign(document.createElement('button'),
563
- { type: 'button', className: 'team-add', textContent: '+ engineer' }),
564
- );
565
- syncTeamButtons();
566
- }
567
-
568
- function currentTeam(defaults) {
569
- const box = teamBox();
570
- if (!box) return defaults.team;
571
- return [...box.querySelectorAll('.team-row')].map((r) => ({
572
- seniority: r.querySelector('select').value,
573
- rate: Number(r.querySelector('input').value),
574
- }));
420
+ // A same-roster scenario that differs only in AI assistance is one line, not
421
+ // a row: the roster is what a reader chooses between.
422
+ function aiVariantLine(s, rec) {
423
+ const c = DATA.computed.scenarios[s.id];
424
+ return `<p class="meta">${s.aiAssisted ? 'With' : 'Without'} AI assistance: ${c.months.toFixed(2)} months · `
425
+ + `${fmtMoney(c.totalCost)} (${deltaText(c, rec)})</p>`;
575
426
  }
576
427
 
577
- function currentParams(defaults) {
578
- const p = { team: currentTeam(defaults) };
579
- CTL_KEYS.forEach((key) => {
580
- const raw = document.getElementById(ctlId(key))?.value ?? defaults[key];
581
- p[key] = key === 'plan' ? raw : Number(raw);
582
- });
583
- return p;
428
+ // One sentence, only when an alternative beats the recommendation on both
429
+ // axes — the page must not bury a dominated choice.
430
+ function insightLine(alts, rec) {
431
+ const c = (s) => DATA.computed.scenarios[s.id];
432
+ const win = alts.find((s) => c(s).months < rec.months && c(s).totalCost < rec.totalCost);
433
+ if (!win) return '';
434
+ return `<p class="insight">&#9656; ${scenarioLabel(win)} finishes ${(rec.months - c(win).months).toFixed(2)} months `
435
+ + `sooner for ${fmtMoney(rec.totalCost - c(win).totalCost)} less than the recommended plan.</p>`;
584
436
  }
585
437
 
586
- const fmtMoney = (v) => `$${Math.round(v).toLocaleString()}`;
438
+ function summaryAlts(rec, recC) {
439
+ const others = DATA.inputs.scenarios.filter((s) => s.id !== rec.id);
440
+ if (!others.length) return '';
441
+ const teams = others.filter((s) => !sameTeam(s, rec)).sort(byMonths);
442
+ const variants = others.filter((s) => sameTeam(s, rec)).map((s) => aiVariantLine(s, recC)).join('');
443
+ const table = teams.length ? `<table><caption>Alternatives</caption><thead><tr><th>Team</th>
444
+ <th class="num">Months</th><th class="num">Cost</th><th></th></tr></thead>
445
+ <tbody>${teams.map((s) => altRow(s, recC)).join('')}</tbody></table>` : '';
446
+ const why = DATA.inputs.recommendedReason
447
+ ? `<p class="why">Recommended because ${esc(DATA.inputs.recommendedReason)}.</p>` : '';
448
+ return `<div class="alts" ${INTERNAL_ATTR}>${why}${variants}${table}${insightLine(teams, recC)}</div>`;
449
+ }
587
450
 
588
- const help = (text) => `<details class="help"><summary aria-label="explain this section">?</summary><p>${text}</p></details>`;
589
- const secHead = (title, text) => `<div class="sec-head"><h2>${title}</h2>${help(text)}</div>`;
590
-
591
- function barRow({ label, value, max, text, cls }) {
592
- const pct = max > 0 ? Math.round((value / max) * 100) : 0;
593
- return `<div class="bar-row"><span class="bar-label" title="${label}">${label}</span>
594
- <span class="bar-track"><span class="bar-fill${cls ? ` ${cls}` : ''}" style="width:${pct}%"></span></span>
595
- <span class="bar-val">${text}</span></div>`;
596
- }
597
-
598
- function teamSummary(team) {
599
- const counts = new Map();
600
- for (const m of team) counts.set(m.seniority, (counts.get(m.seniority) ?? 0) + 1);
601
- return [...counts].map(([s, n]) => `${n}&times; ${s}`).join(' &middot; ');
602
- }
603
-
604
- // Derived in-browser from committed numbers, like every bar width on the
605
- // page — never written into the JSON.
606
- function deltaChip(id, s) {
607
- if (id === DATA.inputs.recommendedScenario) return '';
608
- const rec = DATA.computed.scenarios[DATA.inputs.recommendedScenario];
609
- if (!rec) return '';
610
- const dm = s.months - rec.months;
611
- const dc = s.totalCost - rec.totalCost;
612
- return `<span class="delta">${dm >= 0 ? '+' : '-'}${Math.abs(dm).toFixed(2)} mo &middot; `
613
- + `${dc >= 0 ? '+' : '-'}$${Math.round(Math.abs(dc)).toLocaleString()} vs recommended</span>`;
614
- }
615
-
616
- function scenarioCard(id, s) {
617
- const rec = id === DATA.inputs.recommendedScenario;
618
- const input = DATA.inputs.scenarios.find((x) => x.id === id);
619
- const max = Math.max(...Object.values(DATA.computed.scenarios).map((x) => x.months));
620
- return `<article class="card scenario${rec ? ' recommended' : ''}">
621
- ${rec ? '<span class="flag">recommended</span>' : ''}<h3>${id}</h3>
622
- <div class="hero"><div><span class="num">${s.months.toFixed(2)}</span> <span class="unit">months</span></div>
623
- <div class="gauge"><span style="width:${Math.round((s.months / max) * 100)}%"></span></div>
624
- ${deltaChip(id, s)}</div>
625
- <dl class="facts"><div><dt>team</dt><dd>${teamSummary(input.team)}</dd></div>
626
- <div><dt>claude plan</dt><dd>${input.plan}</dd></div>
627
- <div><dt>effort</dt><dd>${s.hours.toFixed(1)}h</dd></div>
628
- <div><dt>total cost</dt><dd>${fmtMoney(s.totalCost)}</dd></div></dl></article>`;
629
- }
630
-
631
- function renderCards() {
632
- const el = document.getElementById('scenario-cards');
633
- if (!el) return;
634
- const entries = Object.entries(DATA.computed.scenarios);
635
- el.innerHTML = secHead('Delivery scenarios',
636
- 'Each card is one committed way to staff and deliver the same scope. Months and cost are '
637
- + 'computed from the same task hours; the highlighted card is the recommended estimate. '
638
- + 'Sandbox variations live in the what-if panel.')
639
- + `<div class="cards">${entries.map(([id, s]) => scenarioCard(id, s)).join('')}</div>`;
451
+ // The client-facing range from proposal-figures.json, when render.mjs was
452
+ // handed it — the number the client is actually quoted.
453
+ function summaryRange() {
454
+ const f = DATA.figures;
455
+ if (!f?.cost || !f?.months) return '';
456
+ return `<p class="range">range ${f.months.low} – ${f.months.high} months · ${fmtMoney(f.cost.low)} – ${fmtMoney(f.cost.high)}</p>`;
457
+ }
458
+
459
+ function summarySize(recC) {
460
+ const feats = DATA.inputs.features;
461
+ const tasks = feats.reduce((n, f) => n + f.tasks.length, 0);
462
+ const milestones = new Set(feats.map((f) => f.milestone).filter(Boolean)).size;
463
+ const parts = [`${Math.round(recC.hours).toLocaleString()} h`, `${feats.length} features`, `${tasks} tasks`];
464
+ if (milestones) parts.push(`${milestones} milestones`);
465
+ return parts.join(' · ');
466
+ }
467
+
468
+ function summaryMethod() {
469
+ const feats = DATA.inputs.features;
470
+ const stated = feats.filter((f) => f.provenance === 'stated').length;
471
+ return `${DATA.inputs.technique}, ${DATA.inputs.depth} depth · scope ${stated}/${feats.length} stated`;
472
+ }
473
+
474
+ function summaryRisks() {
475
+ return `${DATA.inputs.risks.length} risks priced in (${DATA.computed.riskBufferHours} h) · `
476
+ + `${DATA.inputs.assumptions.length} assumptions`;
640
477
  }
641
478
 
642
- function renderBars() {
643
- const el = document.getElementById('cost-bars');
479
+ function renderSummary() {
480
+ const el = document.getElementById('summary');
644
481
  if (!el) return;
645
- const entries = Object.entries(DATA.computed.scenarios);
646
- const max = Math.max(...entries.map(([, s]) => s.totalCost));
647
- el.innerHTML = secHead('Total cost by scenario',
648
- 'Labor (months × team rates) plus Claude plan seats, per scenario. Bar lengths are '
649
- + 'proportional to the most expensive scenario.')
650
- + `<div class="bar-group">${entries.map(([id, s]) => barRow({ label: id, value: s.totalCost,
651
- max, text: fmtMoney(s.totalCost),
652
- cls: id === DATA.inputs.recommendedScenario ? 'is-rec' : '' })).join('')}</div>`;
482
+ const rec = recScenario();
483
+ const recC = DATA.computed.scenarios[rec.id];
484
+ el.innerHTML = secHead('Summary',
485
+ 'The recommended way to deliver this scope, stated once: team, months and cost from the '
486
+ + 'committed estimate. Alternatives compare other rosters against it.')
487
+ + `<p class="lead">${scenarioLabel(rec)}</p>
488
+ <p class="figures">${recC.months.toFixed(2)} months<span class="sep">&middot;</span>${fmtMoney(recC.totalCost)}</p>
489
+ ${summaryRange()}
490
+ <p class="meta">${summarySize(recC)}</p>
491
+ <p class="meta">${summaryMethod()}</p>
492
+ <p class="meta">${summaryRisks()}</p>
493
+ ${summaryAlts(rec, recC)}`;
653
494
  }
654
495
 
496
+ const fmtMoney = (v) => `$${Math.round(v).toLocaleString()}`;
497
+
498
+ const help = (text) => `<details class="help"><summary aria-label="explain this section">?</summary><p>${text}</p></details>`;
499
+ const secHead = (title, text, actions = '') => `<div class="sec-head"><h2>${title}</h2>${help(text)}${actions}</div>`;
500
+
501
+
502
+
503
+
504
+
505
+
506
+
655
507
  // One interactive section owns the feature story: bar-in-cell effort (was the
656
508
  // effort chart), the sortable feature table, and the per-task drill-down (was
657
- // the flat task register). Committed numbers only — never the what-if rail's.
509
+ // the flat task register). Committed numbers only.
658
510
  const CONF_RANK = { HIGH: 0, MED: 1, LOW: 2 };
659
511
  // Two levels max (schema-enforced), so a component's container is one parent
660
512
  // hop at most; a top-level id is its own container.
@@ -677,79 +529,77 @@ function ctEdge(component) {
677
529
  const id = containerOf(component);
678
530
  return ` class="ct-edge" style="--ct-color:${ctColor(id)}" title="${esc(CT_NAMES[id] ?? id)}"`;
679
531
  }
680
- // Each 1–5 score is the count of thresholds the metric clears, plus one.
681
- function band(value, thresholds) {
682
- return thresholds.reduce((s, t) => s + (value > t ? 1 : 0), 1);
683
- }
684
-
685
- // The workbook's five scoring dimensions, derived from what the estimate
686
- // already knows and matching its Scoring Guide tab: tech is the
687
- // hours-weighted task-category score (CRUD → custom logic → R&D), size is
688
- // absolute expected-hour bands (<1 day → epic). Shared by the page's
689
- // scoring mode and the xlsx export, so table and sheet cannot drift.
690
- const TECH_CATEGORY_SCORE = { boilerplate: 1.5, logic: 3, novel: 5 };
691
- function deriveScores(f) {
692
- const weighted = f.tasks.reduce((s, t) => s + TECH_CATEGORY_SCORE[t.category] * pert(t).e, 0);
693
- const totalE = f.tasks.reduce((s, t) => s + pert(t).e, 0);
694
- const assumptions = f.tasks.reduce((s, t) => s + t.assumptions.length, 0);
695
- return [Math.round(weighted / totalE), band(f.hours, [8, 24, 64, 128]),
696
- band(assumptions, [0, 2, 4, 6]), band(f.spread / f.hours, [0.3, 0.6, 0.9, 1.2]),
697
- { HIGH: 2, MED: 3, LOW: 5 }[f.conf]];
698
- }
699
-
700
- // The workbook's tier scale (its sheet-1 formula verbatim), not the QUICK-depth
701
- // technique breaks in estimate-math — the page mirrors what it exports.
702
- const bdTotal = (f) => f.scores.reduce((a, b) => a + b, 0);
703
- const scoreTier = (total) => ['S', 'M', 'L', 'XL'][band(total, [11, 17, 22]) - 1];
704
-
705
- const bdState = { sortKey: 'hours', dir: -1, milestone: '', component: '', prov: '', group: false, expanded: new Set(), mode: 'estimate', guideSeen: false };
706
- const BD_COLS = [
707
- { key: 'name', label: 'Feature', val: (f) => f.name, hint: 'sort by name' },
708
- { key: 'hours', label: 'Effort (h)', val: (f) => f.hours, hint: 'sort by expected hours' },
709
- { key: 'spread', label: 'Range', val: (f) => f.spread, cls: 'num',
710
- hint: 'sort by spread (pessimistic minus optimistic)' },
711
- { key: 'conf', label: 'Confidence', val: (f) => CONF_RANK[f.conf], hint: 'sort by confidence' },
712
- { key: 'provenance', label: 'Source', val: (f) => f.provenance, hint: 'sort by source' },
713
- ];
532
+ // Scores are the interview's judgments (features[].scores), never derived
533
+ // from hours; Σ and tier were copied into computed.features by rollup.mjs.
534
+ // A page with no scored feature (QUICK depth) shows the four estimate columns.
535
+ const SCORED = DATA.inputs.features.length > 0 && DATA.inputs.features.every((f) => f.scores);
536
+ const SCORE_KEYS = ['tech', 'size', 'deps', 'unc', 'risk'];
537
+ const SCORE_LABELS = { tech: 'Tech', size: 'Size', deps: 'Deps', unc: 'Unc', risk: 'Risk' };
538
+ const EDGE_TOTALS = [11, 17, 22];
539
+
540
+ // Two tabs, two jobs: effort is arithmetic over tasks, scoring is the
541
+ // interview's judgment of the feature. One grid holding both ran eleven
542
+ // columns wide and scrolled sideways on every screen. Each tab keeps its own
543
+ // sort — a reader ordering by Σ has not asked to lose their effort order —
544
+ // while the filters, the grouping and the expanded set are shared, because
545
+ // they are questions about features rather than about either view.
546
+ const TABS = [['estimate', 'Estimate'], ['scoring', 'Scoring']];
547
+ const TAB_LABELS = Object.fromEntries(TABS);
548
+ const SORT_DEFAULTS = { estimate: { key: 'hours', dir: -1 }, scoring: { key: 'total', dir: -1 } };
549
+ const bdState = {
550
+ tab: 'estimate',
551
+ sort: { estimate: { ...SORT_DEFAULTS.estimate }, scoring: { ...SORT_DEFAULTS.scoring } },
552
+ milestone: '', component: '', prov: '', group: false, expanded: new Set(), guideOpen: true,
553
+ };
554
+ const DESC_FIRST = ['hours', 'total'];
714
555
 
715
- // Scoring mode swaps the estimate columns for the workbook's five scores plus
716
- // total and tier; Feature and Effort stay put in both modes.
717
- const SCORE_COLS = [BD_COLS[0], BD_COLS[1],
718
- { key: 'tech', label: 'Tech', val: (f) => f.scores[0], cls: 'score',
719
- hint: 'hours-weighted task category: boilerplate 1.5 / logic 3 / novel 5' },
720
- { key: 'size', label: 'Size', val: (f) => f.scores[1], cls: 'score',
721
- hint: 'expected hours banded at 8 / 24 / 64 / 128' },
722
- { key: 'deps', label: 'Deps', val: (f) => f.scores[2], cls: 'score', hint: 'assumption count across tasks' },
723
- { key: 'unc', label: 'Unc', val: (f) => f.scores[3], cls: 'score', hint: 'estimate spread ÷ expected hours' },
724
- { key: 'risk', label: 'Risk', val: (f) => f.scores[4], cls: 'score', hint: 'worst task confidence' },
725
- { key: 'total', label: 'Σ', val: bdTotal, cls: 'score', hint: 'sum of the five scores' },
726
- { key: 'tier', label: 'Tier', val: bdTotal, cls: 'score', hint: 'S ≤ 11 / M ≤ 17 / L ≤ 22 / XL above' },
727
- ];
728
- const activeCols = () => (bdState.mode === 'scores' ? SCORE_COLS : BD_COLS);
556
+ const BASE_COLS = {
557
+ name: { key: 'name', label: 'Feature', val: (f) => f.name, hint: 'sort by name' },
558
+ hours: { key: 'hours', label: 'Effort (h)', val: (f) => f.hours, hint: 'sort by expected hours' },
559
+ conf: { key: 'conf', label: 'Confidence', val: (f) => CONF_RANK[f.conf], hint: 'sort by confidence' },
560
+ prov: { key: 'provenance', label: 'Source', val: (f) => f.provenance, hint: 'sort by source' },
561
+ };
562
+
563
+ function bdCols(tab) {
564
+ if (!SCORED || tab === 'estimate') {
565
+ return [BASE_COLS.name, BASE_COLS.hours, BASE_COLS.conf, BASE_COLS.prov];
566
+ }
567
+ const scoreCols = SCORE_KEYS.map((k) => ({
568
+ key: k, label: SCORE_LABELS[k], cls: 'score', val: (f) => f.scores[k].n, hint: `sort by ${SCORE_LABELS[k]} score`,
569
+ }));
570
+ return [BASE_COLS.name, ...scoreCols,
571
+ { key: 'total', label: '&Sigma;', cls: 'score', val: (f) => f.scoreTotal, hint: 'sum of the five scores' },
572
+ { key: 'tier', label: 'Tier', cls: 'score', val: (f) => f.scoreTotal, hint: 'S ≤ 11 / M ≤ 17 / L ≤ 22 / XL above' }];
573
+ }
574
+
575
+ const bdTabs = () => (SCORED ? TABS.map(([id]) => id) : ['estimate']);
729
576
 
730
577
  function breakdownData() {
731
578
  return DATA.inputs.features.map((f) => {
732
579
  const c = DATA.computed.features[f.id];
733
580
  const conf = f.tasks.reduce(
734
581
  (w, t) => (CONF_RANK[t.confidence] > CONF_RANK[w] ? t.confidence : w), 'HIGH');
735
- const row = { id: f.id, name: f.name, milestone: f.milestone, component: f.component, provenance: f.provenance,
736
- tasks: f.tasks, conf, hours: c.hours, low: c.low, high: c.high, spread: c.high - c.low };
737
- row.scores = deriveScores(row);
738
- return row;
582
+ const band = c.tier ? DATA.inputs.calibration?.[c.tier] : undefined;
583
+ return { id: f.id, name: f.name, milestone: f.milestone, component: f.component, provenance: f.provenance,
584
+ tasks: f.tasks, conf, hours: c.hours, low: c.low, high: c.high, spread: c.high - c.low,
585
+ scores: f.scores, scoreNote: f.scoreNote, scoreProvenance: f.scoreProvenance,
586
+ scoreTotal: c.scoreTotal, tier: c.tier,
587
+ outOfBand: band && (c.hours < band[0] || c.hours > band[1]) ? band : null };
739
588
  });
740
589
  }
741
590
 
742
591
  // group is a primary key layered over the column sort: rows cluster by
743
592
  // container (roster order — the palette's order) so the stripes read as the
744
593
  // same blocks of color as the roadmap band that set the filter.
745
- function bdSorted(list) {
746
- const col = activeCols().find((c) => c.key === bdState.sortKey);
594
+ function bdSorted(list, tab) {
595
+ const { key, dir } = bdState.sort[tab];
596
+ const col = bdCols(tab).find((c) => c.key === key);
747
597
  const ctRank = (f) => CT_TOPS.indexOf(containerOf(f.component));
748
598
  return list.slice().sort((a, b) => {
749
599
  const byGroup = bdState.group ? ctRank(a) - ctRank(b) : 0;
750
600
  if (byGroup) return byGroup;
751
601
  const [x, y] = [col.val(a), col.val(b)];
752
- return (x < y ? -1 : x > y ? 1 : 0) * bdState.dir;
602
+ return (x < y ? -1 : x > y ? 1 : 0) * dir;
753
603
  });
754
604
  }
755
605
 
@@ -759,24 +609,109 @@ function bdVisible(list) {
759
609
  && (!bdState.prov || f.provenance === bdState.prov));
760
610
  }
761
611
 
762
- function pillGroup({ name, pairs, attr, current }) {
763
- return `<span class="bd-filter-group" role="group" aria-label="${name}">${pairs.map(([v, text]) =>
764
- `<button type="button" ${attr}="${v}" aria-pressed="${v === current}" title="${v || text}">${text}</button>`).join('')}</span>`;
612
+ // Which features someone is looking at is a question about the estimate, not
613
+ // about their session, so the answer travels: every breakdown choice is
614
+ // written into the fragment and a pasted link reopens that exact table. A
615
+ // fragment rather than a query because the page is as often opened off a disk
616
+ // copy as served, and a fragment survives both without reaching a server.
617
+ // Defaults are never written, so an untouched page has no hash to copy.
618
+ const FEAT_IDS = DATA.inputs.features.map((f) => f.id);
619
+
620
+ function bdOpenParam() {
621
+ if (!bdState.expanded.size) return '';
622
+ return bdState.expanded.size === FEAT_IDS.length ? 'all'
623
+ : FEAT_IDS.filter((id) => bdState.expanded.has(id)).join(',');
624
+ }
625
+
626
+ function bdSortParams(p) {
627
+ bdTabs().forEach((tab) => {
628
+ const { key, dir } = bdState.sort[tab];
629
+ const d = SORT_DEFAULTS[tab];
630
+ if (key !== d.key || dir !== d.dir) p.append('sort', `${tab}:${key}:${dir}`);
631
+ });
632
+ }
633
+
634
+ function bdEncode() {
635
+ const p = new URLSearchParams();
636
+ const put = (k, v) => { if (v) p.append(k, v); };
637
+ put('tab', bdState.tab === 'estimate' ? '' : bdState.tab);
638
+ put('ms', bdState.milestone);
639
+ put('ct', bdState.component);
640
+ put('src', bdState.prov);
641
+ put('group', bdState.group ? '1' : '');
642
+ put('open', bdOpenParam());
643
+ put('guide', bdState.guideOpen ? '' : '0');
644
+ bdSortParams(p);
645
+ return p.toString();
646
+ }
647
+
648
+ // A colleague's copy can hold different features. A filter naming a milestone
649
+ // that copy has never heard of would empty the table with no hint why, so
650
+ // anything the data does not know is dropped rather than applied.
651
+ const bdPick = (value, allowed) => (allowed.includes(value) ? value : '');
652
+
653
+ function bdDecodeSort(p) {
654
+ p.getAll('sort').forEach((s) => {
655
+ const [tab, key, dir] = s.split(':');
656
+ if (!SORT_DEFAULTS[tab] || !bdCols(tab).some((c) => c.key === key)) return;
657
+ bdState.sort[tab] = { key, dir: dir === '1' ? 1 : -1 };
658
+ });
659
+ }
660
+
661
+ function bdDecodeOpen(value) {
662
+ if (value === 'all') return new Set(FEAT_IDS);
663
+ return new Set((value ?? '').split(',').filter((id) => FEAT_IDS.includes(id)));
765
664
  }
766
665
 
666
+ function bdDecode(hash) {
667
+ const p = new URLSearchParams(hash);
668
+ const all = breakdownData();
669
+ bdState.tab = bdPick(p.get('tab'), bdTabs()) || 'estimate';
670
+ bdState.milestone = bdPick(p.get('ms'), all.map((f) => f.milestone));
671
+ bdState.component = bdPick(p.get('ct'), all.map((f) => containerOf(f.component)));
672
+ bdState.prov = bdPick(p.get('src'), all.map((f) => f.provenance));
673
+ bdState.group = p.get('group') === '1';
674
+ bdState.guideOpen = p.get('guide') !== '0';
675
+ bdState.expanded = bdDecodeOpen(p.get('open'));
676
+ bdDecodeSort(p);
677
+ }
678
+
679
+ // replaceState, not pushState: someone clicking through four sorts has not
680
+ // asked for four back-button stops. A few browsers refuse a history write on
681
+ // a file:// page, so the fragment is assigned directly when that throws — the
682
+ // hashchange that assignment fires arrives at a state already matching this
683
+ // one, and the guard below stops it there.
684
+ function bdSyncUrl() {
685
+ const q = bdEncode();
686
+ if (q === location.hash.slice(1)) return;
687
+ try { history.replaceState(null, '', location.pathname + location.search + (q ? `#${q}` : '')); }
688
+ catch { location.hash = q; }
689
+ }
690
+
691
+ // The chevron opens tasks on the estimate tab and the scoring reasoning on
692
+ // the other, so the control that drives every chevron is internal-only for
693
+ // the first and open to the client for the second — tasks and their
694
+ // assumptions are ours, the rubric sentences are theirs to read.
767
695
  function bdExpandControls() {
768
- return `<span class="bd-filter-group" ${INTERNAL_ATTR} role="group" aria-label="tasks">
696
+ const internal = bdState.tab === 'estimate' ? ` ${INTERNAL_ATTR}` : '';
697
+ const what = bdState.tab === 'estimate' ? 'tasks' : 'score reasoning';
698
+ return `<span class="bd-filter-group"${internal} role="group" aria-label="${what}">
769
699
  <button type="button" data-expand="all">expand all</button>
770
700
  <button type="button" data-expand="none">collapse all</button></span>`;
771
701
  }
772
702
 
773
- // Internal-only, like the drill-down it re-maps: the client render keeps the
774
- // estimate columns and never sees this switch.
775
- function bdModePill() {
776
- return `<span class="bd-filter-group" ${INTERNAL_ATTR} role="group" aria-label="columns">${
777
- [['estimate', 'estimate'], ['scores', 'scoring']].map(([v, text]) =>
778
- `<button type="button" data-mode="${v}" aria-pressed="${v === bdState.mode}"
779
- title="${text} columns">${text}</button>`).join('')}</span>`;
703
+ // A tab strip, not a pill filter: each tab owns a panel, arrow keys move
704
+ // between them, and the selected one is the page's single source of truth for
705
+ // which columns are on screen. One view needs no strip, so QUICK depth gets
706
+ // the expand controls alone.
707
+ function bdTabStrip() {
708
+ const strip = SCORED ? `<div class="tablist" role="tablist" aria-label="feature views">${
709
+ TABS.map(([id, label]) => {
710
+ const on = bdState.tab === id;
711
+ return `<button type="button" role="tab" id="tab-${id}" data-tab="${id}"
712
+ aria-selected="${on}" aria-controls="panel-${id}" tabindex="${on ? 0 : -1}">${label}</button>`;
713
+ }).join('')}</div>` : '';
714
+ return `<div class="bd-tabs">${strip}${bdExpandControls()}</div>`;
780
715
  }
781
716
 
782
717
  // The handler lives in a separate internal-only script (the embedded workbook
@@ -794,33 +729,47 @@ function selectBox({ name, key, current, pairs }) {
794
729
  `<option value="${esc(v)}"${v === current ? ' selected' : ''}>${esc(text)}</option>`).join('')}</select></label>`;
795
730
  }
796
731
 
797
- function bdFilters(all) {
798
- let milestones = '';
732
+ // Three filters, one widget, one row: source used to be a pill group beside
733
+ // two selects, which read as three unrelated controls doing one job. They ask
734
+ // the same question of both tabs, so they sit above the strip, not inside a
735
+ // panel.
736
+ function bdFilters(all, shown) {
737
+ const boxes = [];
799
738
  if (all.every((f) => f.milestone)) {
800
739
  const labels = [...new Set(all.map((f) => f.milestone))];
801
- milestones = selectBox({ name: 'milestone', key: 'milestone', current: bdState.milestone,
802
- pairs: [['', 'all milestones'], ...labels.map((l) => [l, l])] });
740
+ boxes.push(selectBox({ name: 'milestone', key: 'milestone', current: bdState.milestone,
741
+ pairs: [['', 'all milestones'], ...labels.map((l) => [l, l])] }));
803
742
  }
804
- let components = '';
805
743
  if (DATA.inputs.components) {
806
744
  const names = Object.fromEntries(DATA.inputs.components.map((c) => [c.id, c.name]));
807
745
  const tops = [...new Set(all.map((f) => containerOf(f.component)))];
808
- components = selectBox({ name: 'container', key: 'component', current: bdState.component,
809
- pairs: [['', 'all containers'], ...tops.map((id) => [id, names[id] ?? id])] });
746
+ boxes.push(selectBox({ name: 'container', key: 'component', current: bdState.component,
747
+ pairs: [['', 'all containers'], ...tops.map((id) => [id, names[id] ?? id])] }));
810
748
  }
811
- const source = pillGroup({ name: 'source', attr: 'data-prov', current: bdState.prov,
812
- pairs: [['', 'all sources'], ['stated', 'stated'], ['proposed', 'proposed']] });
813
- return `<div class="bd-filters">${milestones}${components}<span class="bd-right">${bdModePill()}${bdExpandControls()}${bdDownloadBtn()}${source}</span></div>`;
749
+ boxes.push(selectBox({ name: 'source', key: 'prov', current: bdState.prov,
750
+ pairs: [['', 'all sources'], ['stated', 'stated'], ['proposed', 'proposed']] }));
751
+ return `<div class="bd-filters">${boxes.join('')}${bdCount(all.length, shown)}</div>`;
752
+ }
753
+
754
+ // Filters moved out of the table's own header row, so the count is how a
755
+ // reader sees that rows are missing rather than absent. It states the plain
756
+ // total until something is actually filtered.
757
+ function bdCount(total, shown) {
758
+ const filtered = shown < total;
759
+ const text = filtered ? `${shown} of ${total} features` : `${total} features`;
760
+ const clear = filtered ? '<button type="button" data-clear>clear</button>' : '';
761
+ return `<span class="bd-right"><span class="bd-count">${text}</span>${clear}</span>`;
814
762
  }
815
763
 
816
- function bdHead() {
817
- return `<thead><tr>${activeCols().map((c) => {
764
+ function bdHead(tab) {
765
+ const { key, dir } = bdState.sort[tab];
766
+ return `<thead><tr>${bdCols(tab).map((c) => {
818
767
  // grouping overrides the column order, so no header may claim its sort
819
- const active = !bdState.group && bdState.sortKey === c.key;
820
- const aria = active ? (bdState.dir === 1 ? 'ascending' : 'descending') : 'none';
821
- const arrow = active ? (bdState.dir === 1 ? ' &#9650;' : ' &#9660;') : '';
768
+ const active = !bdState.group && key === c.key;
769
+ const aria = active ? (dir === 1 ? 'ascending' : 'descending') : 'none';
770
+ const arrow = active ? (dir === 1 ? ' &#9650;' : ' &#9660;') : '';
822
771
  return `<th aria-sort="${aria}"${c.cls ? ` class="${c.cls}"` : ''}>
823
- <button type="button" data-sort="${c.key}" title="${c.hint}">${c.label}${arrow}</button></th>`;
772
+ <button type="button" data-sort="${c.key}" data-panel="${tab}" title="${c.hint}">${c.label}${arrow}</button></th>`;
824
773
  }).join('')}</tr></thead>`;
825
774
  }
826
775
 
@@ -834,131 +783,158 @@ function bdBar(f, max) {
834
783
  // A feature row's score cells: the five 1–5s, their sum, and the tier. A 5 is
835
784
  // flagged hot — the score a human should eyeball before the sheet goes out.
836
785
  function scoreCells(f) {
837
- const total = bdTotal(f);
838
- const tier = scoreTier(total);
839
- return f.scores.map((v) => `<td class="score${v === 5 ? ' hot' : ''}">${v}</td>`).join('')
840
- + `<td class="score total">${total}</td>
841
- <td class="score"><span class="tier ${tier.toLowerCase()}">${tier}</span></td>`;
786
+ const cells = SCORE_KEYS.map((k) => {
787
+ const s = f.scores[k];
788
+ // A client render carries no cites (redact.mjs blanks them), so the title
789
+ // is the anchor alone rather than a sentence with a dangling dash.
790
+ const title = s.cite ? `${esc(s.anchor)} — ${esc(s.cite)}` : esc(s.anchor);
791
+ return `<td class="score${s.n === 5 ? ' hot' : ''}" title="${title}">${s.n}</td>`;
792
+ });
793
+ const edge = EDGE_TOTALS.includes(f.scoreTotal)
794
+ ? ' <span class="edge" title="one point from the next tier">&#9873;</span>' : '';
795
+ return `${cells.join('')}<td class="score total">${f.scoreTotal}${edge}</td>
796
+ <td class="score"><span class="tier ${f.tier.toLowerCase()}">${f.tier}</span></td>`;
797
+ }
798
+
799
+ function hoursCell(f, max) {
800
+ const warn = f.outOfBand
801
+ ? `<span class="oob" title="PERT ${f.hours} h outside ${f.tier} band ${f.outOfBand[0]}–${f.outOfBand[1]} h">&#9888;</span>` : '';
802
+ return `<td><span class="bd-cell">${bdBar(f, max)}<span class="bd-num">${f.hours}</span>${warn}</span></td>`;
842
803
  }
843
804
 
844
805
  function estimateCells(f) {
845
- return `<td class="num">${f.low}&ndash;${f.high}</td>
846
- <td><span class="conf">${f.conf}</span></td>
806
+ return `<td><span class="conf">${f.conf}</span></td>
847
807
  <td><span class="tag ${f.provenance}">${f.provenance}</span></td>`;
848
808
  }
849
809
 
850
- function featRow(f, max) {
810
+ // The name cell is the spine both tabs share: container stripe, the chevron
811
+ // that opens this feature's detail, the name. What the chevron opens, and
812
+ // whether a client may open it, is the caller's call.
813
+ function nameCell(f, internal, note) {
851
814
  const open = bdState.expanded.has(f.id);
852
- return `<tr class="feat-row ${confLevel(f.conf)}" data-id="${f.id}">
853
- <td${ctEdge(f.component)}><span class="feat-cell"><button type="button" class="expand" ${INTERNAL_ATTR}
854
- aria-expanded="${open}" aria-label="show tasks">&#9656;</button>
855
- <span>${f.name}</span></span></td>
856
- <td><span class="bd-cell">${bdBar(f, max)}<span class="bd-num">${f.hours}</span></span></td>
857
- ${bdState.mode === 'scores' ? scoreCells(f) : estimateCells(f)}</tr>`;
858
- }
859
-
860
- // In scoring mode a task row shows its inputs to each score column above it:
861
- // category × weight under Tech, expected hours under Size, assumption count
862
- // under Deps, o–p span under Unc, its confidence under Risk. Σ and Tier only
863
- // exist per feature, so those cells stay blank.
864
- function taskScoreCells(t) {
865
- return `<td class="score"><span class="tag">${t.category}</span> <span class="wt">&times;${TECH_CATEGORY_SCORE[t.category]}</span></td>
866
- <td class="score wt">${pert(t).e.toFixed(1)}h</td>
867
- <td class="score wt">${t.assumptions.length}</td>
868
- <td class="score wt">${t.o}&ndash;${t.p}h</td>
869
- <td class="score"><span class="conf">${t.confidence}</span></td><td class="score"></td><td class="score"></td>`;
870
- }
871
-
872
- function taskEstimateCells(t) {
873
- return `<td class="task-assump">${t.assumptions.join('; ') || 'none'}</td>
874
- <td><span class="conf">${t.confidence}</span></td>
875
- <td><span class="tag">${t.category}</span></td>`;
815
+ const label = internal ? 'show tasks' : 'show score reasoning';
816
+ return `<td${ctEdge(f.component)}><span class="feat-cell"><button type="button" class="expand"${internal ? ` ${INTERNAL_ATTR}` : ''}
817
+ aria-expanded="${open}" aria-label="${label}">&#9656;</button>
818
+ <span>${f.name}</span></span>${note}</td>`;
819
+ }
820
+
821
+ function featRow(f, max) {
822
+ return `<tr class="feat-row ${confLevel(f.conf)}" data-id="${esc(f.id)}">
823
+ ${nameCell(f, true, '')}${hoursCell(f, max)}${estimateCells(f)}</tr>`;
824
+ }
825
+
826
+ // The note is the plain sentence the interview wrote for the client about why
827
+ // this tier — it belongs beside the scores it summarises, not under an
828
+ // effort bar it never described.
829
+ function scoreRow(f) {
830
+ const note = f.scoreNote ? `<div class="task-assump feat-note">${esc(f.scoreNote)}</div>` : '';
831
+ return `<tr class="feat-row" data-id="${esc(f.id)}">${nameCell(f, false, note)}${scoreCells(f)}</tr>`;
876
832
  }
877
833
 
834
+ // Task rows sit under the feature's name and fill the estimate tab's four
835
+ // columns exactly — tasks carry three-point hours, a confidence and a
836
+ // category, never scores, which is why they have no home on the other tab.
878
837
  function taskRows(f) {
879
838
  return f.tasks.map((t) => `<tr class="task-row ${confLevel(t.confidence)}" ${INTERNAL_ATTR}>
880
- <td${ctEdge(f.component)}>${t.name}</td>
839
+ <td${ctEdge(f.component)}>${t.name}<div class="task-assump">${t.assumptions.join('; ') || 'none'}</div></td>
881
840
  <td><span class="bd-cell"><span class="bd-num">${t.o}/${t.m}/${t.p}</span></span></td>
882
- ${bdState.mode === 'scores' ? taskScoreCells(t) : taskEstimateCells(t)}</tr>`).join('');
841
+ <td><span class="conf">${t.confidence}</span></td>
842
+ <td><span class="tag">${t.category}</span></td></tr>`).join('');
843
+ }
844
+
845
+ // Every score is required to carry the rubric sentence it was anchored to and
846
+ // the evidence that sentence rests on. Both lived in a title attribute, which
847
+ // no touch screen, printer or find-in-page has ever shown anyone. A client
848
+ // render keeps the anchors and loses the cites (redact.mjs blanks them), so
849
+ // the block degrades to five sentences rather than five empty quotes.
850
+ function rationaleRows(f) {
851
+ const items = SCORE_KEYS.map((k) => {
852
+ const s = f.scores[k];
853
+ // A cite is internal shorthand twice over: redact.mjs blanks it for a
854
+ // --client-only render, and the view toggle — which previews that render
855
+ // without re-rendering — has to hide it too, or an internal ticket phrase
856
+ // stays on screen through a client call.
857
+ const cite = s.cite ? `<span class="cite" ${INTERNAL_ATTR}>${esc(s.cite)}</span>` : '';
858
+ return `<dt>${SCORE_LABELS[k]} ${s.n}</dt><dd>${esc(s.anchor)}${cite}</dd>`;
859
+ }).join('');
860
+ return `<tr class="rat-row"><td${ctEdge(f.component)} colspan="${SCORE_KEYS.length + 3}">
861
+ <dl class="rationale">${items}</dl></td></tr>`;
883
862
  }
884
863
 
885
- function bdMode(mode) {
886
- bdState.mode = mode;
887
- // a sort keyed to the other mode's columns has nothing to point at
888
- if (!activeCols().some((c) => c.key === bdState.sortKey)) bdState.sortKey = 'hours';
889
- renderBreakdown();
864
+ function bdRows(f, tab, max) {
865
+ const open = bdState.expanded.has(f.id);
866
+ if (tab === 'scoring') return scoreRow(f) + (open ? rationaleRows(f) : '');
867
+ return featRow(f, max) + (open ? taskRows(f) : '');
890
868
  }
891
869
 
892
- // The workbook's Scoring Guide tab, verbatim, so page and sheet explain a
893
- // score in the same words; each row also states how the page derives it.
894
- const SCORE_GUIDE = [
895
- ['Tech complexity', 'derived: hours-weighted task category — boilerplate 1.5, logic 3, novel 5',
896
- 'Standard CRUD, well-documented library usage, copy-paste patterns',
897
- 'Minor customisation of standard patterns, simple state management',
898
- 'Custom business logic, moderate algorithm complexity, multiple states',
899
- 'Non-trivial algorithms, real-time systems, ML inference, complex data transforms',
900
- 'Novel architecture, distributed systems, low-level optimisation, R&amp;D territory'],
901
- ['Feature size', 'derived: expected hours banded at 8 / 24 / 64 / 128',
902
- 'Single UI element or micro-function, &lt;1 day of work',
903
- 'Small self-contained feature, simple form or display component',
904
- 'Medium feature with multiple components and backend logic',
905
- 'Large feature spanning frontend, backend, DB, and tests',
906
- 'Epic-scale feature, multiple sub-features or screens'],
907
- ['Dependencies', 'derived: assumption count across the feature&rsquo;s tasks',
908
- 'Fully standalone, no external services or shared state',
909
- 'One internal dependency (e.g. auth check)',
910
- '2&ndash;3 internal services or one third-party API',
911
- 'Multiple third-party APIs or tightly coupled internal systems',
912
- 'Deep cross-system dependencies, legacy integrations, or shared infrastructure changes'],
913
- ['Uncertainty', 'derived: estimate spread &divide; expected hours',
914
- 'Fully defined spec, clear acceptance criteria, precedent exists',
915
- 'Minor ambiguities, can be resolved with one clarifying question',
916
- 'Some open questions, design decisions to be made during build',
917
- 'Significant unknowns, exploratory work needed, spec may change',
918
- 'Highly experimental, no clear solution path, outcomes unclear'],
919
- ['Risk', 'derived: worst task confidence — review by hand, no business-impact input yet',
920
- 'Fully reversible, no user data, isolated module',
921
- 'Low stakes, easy rollback, minimal user impact',
922
- 'Moderate impact if broken, requires testing, affects multiple users',
923
- 'Payments, auth, data migrations, or PII &mdash; high business impact',
924
- 'Core infrastructure, compliance requirements, irreversible operations'],
925
- ];
926
-
927
- const bdGuideRow = ([dim, how, ...anchors]) => `<tr><td class="dim">${dim}<small>${how}</small></td>
928
- ${anchors.map((a) => `<td>${a}</td>`).join('')}</tr>`;
929
-
870
+ // The rubric comes from references/scoring-guide.md through the GUIDE slot,
871
+ // so the page and the interviewer explain a score in the same sentences. The
872
+ // fold opens on first view and then keeps whatever the reader chose: every
873
+ // sort and filter rebuilds this markup, so its state lives in bdState.
930
874
  function bdGuide() {
931
- if (bdState.mode !== 'scores') return '';
932
- const open = bdState.guideSeen ? '' : ' open';
933
- bdState.guideSeen = true;
934
- return `<details class="guide"${open}><summary>Scoring guide &mdash; what each 1&ndash;5 means</summary>
935
- <div class="bd-scroll"><table class="guide-table"><thead><tr><th>Dimension</th>
936
- ${[1, 2, 3, 4, 5].map((n) => `<th class="score">${n}</th>`).join('')}</tr></thead>
937
- <tbody>${SCORE_GUIDE.map(bdGuideRow).join('')}</tbody></table></div></details>`;
938
- }
875
+ const guide = document.getElementById('scoring-guide');
876
+ if (!SCORED || !guide) return '';
877
+ const open = bdState.guideOpen ? ' open' : '';
878
+ return `<details class="guide" data-guide${open}><summary>Scoring guide &mdash; what each 1&ndash;5 means</summary>
879
+ <div class="bd-scroll">${guide.innerHTML}</div></details>`;
880
+ }
881
+
882
+ // Both panels render; the idle one is `hidden`. That keeps every tab's
883
+ // aria-controls pointing at a node that exists, makes the switch instant, and
884
+ // lets print simply unhide the pair — a tab is a screen affordance, and paper
885
+ // has room for both tables.
886
+ function bdPanel(tab, all, max) {
887
+ const rows = bdVisible(bdSorted(all, tab)).map((f) => bdRows(f, tab, max)).join('');
888
+ const tabbed = SCORED ? ` role="tabpanel" aria-labelledby="tab-${tab}" tabindex="0"` : '';
889
+ const caption = SCORED ? `<caption class="panel-name">${TAB_LABELS[tab]}</caption>` : '';
890
+ const guide = tab === 'scoring' ? bdGuide() : '';
891
+ return `<div id="panel-${tab}"${tabbed}${bdState.tab === tab ? '' : ' hidden'}>
892
+ <div class="bd-scroll"><table>${caption}${bdHead(tab)}<tbody>${rows}</tbody></table></div>${guide}</div>`;
893
+ }
894
+
895
+ const BD_HELP = 'Estimate is the arithmetic: hours is the PERT expected value '
896
+ + 'E = (O + 4M + P) / 6 summed over the feature’s tasks, and the bar shows E with a '
897
+ + 'lighter tail to the pessimistic bound, so a long tail means an uncertain feature. '
898
+ + 'Scoring is the judgment behind it: the interview’s five factors, their sum and the '
899
+ + 'tier they fall in. Filters apply to both tabs. Sort any column, and expand a row for '
900
+ + 'the tasks behind an estimate or the rubric sentence and evidence behind a score.';
939
901
 
940
902
  function renderBreakdown() {
941
903
  const el = document.getElementById('feature-table');
942
904
  if (!el) return;
943
905
  const all = breakdownData();
944
906
  const max = Math.max(...all.map((f) => f.high));
945
- const rows = bdVisible(bdSorted(all))
946
- .map((f) => featRow(f, max) + (bdState.expanded.has(f.id) ? taskRows(f) : '')).join('');
947
- el.innerHTML = secHead('Feature breakdown',
948
- 'Hours is the PERT expected value E = (O + 4M + P) / 6 summed over the feature’s tasks; '
949
- + 'the bar shows E with a lighter tail to the pessimistic bound, so a long tail means an '
950
- + 'uncertain feature. Sort any column, filter by milestone or source, and expand a row '
951
- + 'for the tasks behind its number.')
952
- + bdFilters(all) + `<div class="bd-scroll"><table>${bdHead()}<tbody>${rows}</tbody></table></div>` + bdGuide();
907
+ const panels = bdTabs().map((tab) => bdPanel(tab, all, max)).join('');
908
+ el.innerHTML = secHead('Feature breakdown', BD_HELP, bdDownloadBtn())
909
+ + bdTabStrip() + bdFilters(all, bdVisible(all).length) + panels;
910
+ bdSyncUrl();
953
911
  }
954
912
 
955
- function bdSort(key) {
913
+ function bdSort(key, tab) {
956
914
  // an explicit sort takes control back from the roadmap grouping — and starts
957
915
  // fresh at the column's default direction, since no sort was showing.
958
- const fresh = bdState.group || bdState.sortKey !== key;
916
+ const s = bdState.sort[tab];
917
+ const fresh = bdState.group || s.key !== key;
918
+ bdState.group = false;
919
+ if (fresh) { s.key = key; s.dir = DESC_FIRST.includes(key) ? -1 : 1; }
920
+ else s.dir = -s.dir;
921
+ renderBreakdown();
922
+ }
923
+
924
+ // Re-rendering replaces the strip, so the newly selected tab has to be handed
925
+ // the focus back — otherwise a keyboard reader lands at the top of the page.
926
+ function bdSelectTab(tab) {
927
+ if (bdState.tab === tab) return;
928
+ bdState.tab = tab;
929
+ renderBreakdown();
930
+ document.getElementById(`tab-${tab}`)?.focus();
931
+ }
932
+
933
+ function bdClearFilters() {
934
+ bdState.milestone = '';
935
+ bdState.component = '';
936
+ bdState.prov = '';
959
937
  bdState.group = false;
960
- if (fresh) { bdState.sortKey = key; bdState.dir = key === 'hours' || key === 'spread' ? -1 : 1; }
961
- else bdState.dir = -bdState.dir;
962
938
  renderBreakdown();
963
939
  }
964
940
 
@@ -977,14 +953,25 @@ function bdExpandAll(mode) {
977
953
  function onBreakdownClick(e) {
978
954
  const btn = e.target.closest('button');
979
955
  if (!btn) return;
980
- if (btn.dataset.sort) bdSort(btn.dataset.sort);
981
- else if (btn.dataset.mode) bdMode(btn.dataset.mode);
956
+ if (btn.dataset.sort) bdSort(btn.dataset.sort, btn.dataset.panel);
957
+ else if (btn.dataset.tab) bdSelectTab(btn.dataset.tab);
982
958
  else if (btn.dataset.expand) bdExpandAll(btn.dataset.expand);
959
+ else if (btn.dataset.clear !== undefined) bdClearFilters();
983
960
  else if (btn.dataset.download !== undefined) window.__downloadXlsx?.();
984
- else if (btn.dataset.prov !== undefined) { bdState.prov = btn.dataset.prov; renderBreakdown(); }
985
961
  else if (btn.classList.contains('expand')) bdToggle(btn.closest('tr').dataset.id);
986
962
  }
987
963
 
964
+ // Arrow keys move within the strip, as a tablist is expected to: the strip is
965
+ // one tab stop and Left/Right choose inside it.
966
+ function onBreakdownKeydown(e) {
967
+ const tab = e.target.closest?.('[role="tab"]');
968
+ const step = { ArrowRight: 1, ArrowLeft: -1 }[e.key];
969
+ if (!tab || !step) return;
970
+ e.preventDefault();
971
+ const ids = bdTabs();
972
+ bdSelectTab(ids[(ids.indexOf(tab.dataset.tab) + step + ids.length) % ids.length]);
973
+ }
974
+
988
975
  function onBreakdownChange(e) {
989
976
  const sel = e.target.closest('select[data-select]');
990
977
  if (!sel) return;
@@ -1097,7 +1084,7 @@ function roadmapAxis({ total, ticks }) {
1097
1084
  }
1098
1085
 
1099
1086
  // Committed numbers only: the roadmap draws the recommended scenario as
1100
- // computed — the what-if rail owns every live number on this page.
1087
+ // computed — nothing on this page recomputes a month or a cost.
1101
1088
  function renderRoadmap() {
1102
1089
  const el = document.getElementById('roadmap');
1103
1090
  if (!el) return;
@@ -1158,7 +1145,8 @@ function renderContainers() {
1158
1145
  <ul class="pie-legend">${entries.map((e) => pieLegendRow(e, { ...ctx, acc: 0 })).join('')}</ul></div>${pieNote()}`;
1159
1146
  }
1160
1147
 
1161
- // Assembled at runtime for the same reason as CTL_SUFFIX above: the task
1148
+ // Assembled at runtime (never one static literal, so the client-only render's
1149
+ // page text can't carry it): the task
1162
1150
  // drill-down is per-task WBS detail, not meant for the client view, so its
1163
1151
  // rows and expand buttons carry the internal-hide attribute — but that
1164
1152
  // attribute name must never appear as page text in a --client-only export.
@@ -1209,82 +1197,75 @@ function renderMethod() {
1209
1197
  github.com/Modular-Earth-LLC/solutions-architecture-agent.</span></p></details>`;
1210
1198
  }
1211
1199
 
1212
- // Live feedback at the point of interaction: the sticky rail is usually on
1213
- // screen while the custom card is not, so the rail repeats the custom rollup.
1214
- function renderReadout(custom) {
1215
- const el = document.getElementById('whatif-readout');
1216
- if (!el) return;
1217
- el.innerHTML = Number.isFinite(custom.totalCost)
1218
- ? `<p class="months"><span class="num">${custom.months.toFixed(2)}</span>months</p>
1219
- <dl><div><dt>total cost</dt><dd>${fmtMoney(custom.totalCost)}</dd></div>
1220
- <div><dt>effort</dt><dd>${custom.hours.toFixed(1)}h</dd></div></dl>`
1221
- : '';
1222
- }
1223
-
1224
- function renderAll(defaults) {
1225
- renderCards();
1226
- renderBars();
1200
+ function renderAll() {
1201
+ renderSummary();
1227
1202
  renderRoadmap();
1228
1203
  renderContainers();
1229
1204
  renderBreakdown();
1230
1205
  renderRegister();
1231
1206
  renderMethod();
1232
- renderReadout(recompute(currentParams(defaults)));
1233
- }
1234
-
1235
- const defaults = defaultsFromRecommended();
1236
-
1237
- function applyDefaults() {
1238
- setControls(defaults);
1239
- renderTeam(defaults.team);
1240
- syncOutputs();
1241
- renderAll(defaults);
1242
- }
1243
- applyDefaults();
1244
-
1245
- function onWhatIfChange() {
1246
- syncOutputs();
1247
- renderAll(defaults);
1248
- const banner = document.getElementById('modified-banner');
1249
- if (banner) banner.hidden = false;
1250
1207
  }
1208
+ bdDecode(location.hash.slice(1));
1209
+ renderAll();
1251
1210
 
1252
- CTL_KEYS.forEach((key) => document.getElementById(ctlId(key))?.addEventListener('input', onWhatIfChange));
1253
- teamBox()?.addEventListener('input', (e) => {
1254
- if (e.target.matches('select')) {
1255
- const rate = RATE_BY_SENIORITY[e.target.value];
1256
- if (rate != null) e.target.closest('.team-row').querySelector('input').value = rate;
1257
- }
1258
- onWhatIfChange();
1259
- });
1260
- teamBox()?.addEventListener('click', (e) => {
1261
- if (e.target.matches('.team-add')) {
1262
- e.target.before(teamRow(currentTeam(defaults).at(-1)));
1263
- } else if (e.target.matches('.team-del')) {
1264
- e.target.closest('.team-row').remove();
1265
- } else return;
1266
- syncTeamButtons();
1267
- onWhatIfChange();
1268
- });
1269
-
1270
- document.getElementById('reset')?.addEventListener('click', () => {
1271
- applyDefaults();
1272
- const banner = document.getElementById('modified-banner');
1273
- if (banner) banner.hidden = true;
1211
+ // The back button, and a hash pasted into the address bar, both arrive here.
1212
+ // Our own writes use replaceState and so never fire this; the guard catches
1213
+ // the file:// fallback, which does.
1214
+ window.addEventListener('hashchange', () => {
1215
+ if (bdEncode() === location.hash.slice(1)) return;
1216
+ bdDecode(location.hash.slice(1));
1217
+ renderBreakdown();
1274
1218
  });
1275
1219
 
1276
1220
  document.getElementById('feature-table')?.addEventListener('click', onBreakdownClick);
1277
1221
  document.getElementById('feature-table')?.addEventListener('change', onBreakdownChange);
1222
+ document.getElementById('feature-table')?.addEventListener('keydown', onBreakdownKeydown);
1223
+ // `toggle` does not bubble, so this one listens in the capture phase instead.
1224
+ document.getElementById('feature-table')?.addEventListener('toggle', (e) => {
1225
+ if (!e.target.matches('[data-guide]')) return;
1226
+ bdState.guideOpen = e.target.open;
1227
+ bdSyncUrl(); // the fold does not re-render, so it syncs for itself
1228
+ }, true);
1278
1229
  document.getElementById('roadmap')?.addEventListener('click', onRoadmapClick);
1279
1230
  document.getElementById('containers')?.addEventListener('mouseover', onPieHover);
1280
1231
  document.getElementById('containers')?.addEventListener('mouseout', onPieHover);
1281
1232
 
1282
- document.getElementById('view-toggle')?.addEventListener('click', () => {
1283
- const client = document.body.classList.toggle('view-client');
1284
- // scoring mode is internal-only; the client view falls back to the estimate
1285
- // columns rather than showing scores with their switch hidden.
1286
- if (client && bdState.mode !== 'estimate') bdMode('estimate');
1287
- });
1233
+ // Which view you were reading travels with the link like the filters do. It
1234
+ // rides the query string rather than the fragment because it picks a
1235
+ // rendering of the whole page, not a position inside it — and it only ever
1236
+ // switches the preview ON. A --client-only render has already had its
1237
+ // internal markup stripped; no URL should look like it can put that back.
1238
+ // The preview is a preview: the internal text is still in an internal page's
1239
+ // DOM, hidden by CSS. `--client-only` is what actually removes it.
1240
+ function setViewParam(on) {
1241
+ const p = new URLSearchParams(location.search);
1242
+ if (on) p.set('view', 'client');
1243
+ else p.delete('view');
1244
+ const q = p.toString();
1245
+ // A file:// page may refuse a history write; the toggle still works, the
1246
+ // URL just does not record it.
1247
+ try { history.replaceState(null, '', location.pathname + (q ? `?${q}` : '') + location.hash); }
1248
+ catch { /* the view is showing either way */ }
1249
+ }
1250
+
1251
+ // The button names where it goes, not where it is. Guarded on the button's
1252
+ // presence: a --client-only render has no toggle and its body class is the
1253
+ // render, not a preview, so nothing here may touch it.
1254
+ const viewToggle = document.getElementById('view-toggle');
1255
+
1256
+ function applyView(on) {
1257
+ document.body.classList.toggle('view-client', on);
1258
+ viewToggle.textContent = on ? 'internal view' : 'client view';
1259
+ }
1260
+
1261
+ if (viewToggle) {
1262
+ if (new URLSearchParams(location.search).get('view') === 'client') applyView(true);
1263
+ viewToggle.addEventListener('click', () => {
1264
+ const on = !document.body.classList.contains('view-client');
1265
+ applyView(on);
1266
+ setViewParam(on);
1267
+ });
1268
+ }
1288
1269
 
1289
1270
  document.getElementById('theme-toggle')?.addEventListener('click', () => {
1290
1271
  const root = document.documentElement;
@@ -1317,10 +1298,6 @@ const fCell = (ref, s, f) => `<c r="${ref}" s="${s}"><f>${xmlEsc(f)}</f></c>`;
1317
1298
  const sCell = (ref, s, text) => `<c r="${ref}" s="${s}" t="inlineStr"><is><t>${xmlEsc(text)}</t></is></c>`;
1318
1299
  const nCell = (ref, s, v) => `<c r="${ref}" s="${s}"><v>${v}</v></c>`;
1319
1300
 
1320
- // deriveScores lives with the breakdown table in the main script (the page's
1321
- // scoring mode renders the same five dimensions); rows arrive here with
1322
- // .scores already derived.
1323
-
1324
1301
  // The sample's own formulas, re-emitted per row (explicit, not shared, so a
1325
1302
  // regenerated row never dangles a shared-formula anchor).
1326
1303
  function rowFormulas(r) {
@@ -1334,12 +1311,15 @@ function rowFormulas(r) {
1334
1311
  const fxCells = (r) => Object.entries(rowFormulas(r))
1335
1312
  .map(([col, f]) => fCell(col + r, XLSX_STYLE[col], f)).join('');
1336
1313
 
1314
+ const blankCell = (ref) => `<c r="${ref}" s="${XLSX_STYLE.blank}"/>`;
1315
+
1337
1316
  function featureRowXml(f, r) {
1338
- const scores = f.scores;
1339
- return `<row r="${r}" ht="29.25" customHeight="1">` + sCell(`A${r}`, XLSX_STYLE.A, f.name)
1340
- + ['B', 'C', 'D', 'E', 'F'].map((col, i) => nCell(col + r, XLSX_STYLE.score, scores[i])).join('')
1317
+ const scoreCols = ['B', 'C', 'D', 'E', 'F'];
1318
+ const scores = scoreCols.map((col, i) => (f.scores
1319
+ ? nCell(col + r, XLSX_STYLE.score, f.scores[SCORE_KEYS[i]].n) : blankCell(col + r))).join('');
1320
+ return `<row r="${r}" ht="29.25" customHeight="1">` + sCell(`A${r}`, XLSX_STYLE.A, f.name) + scores
1341
1321
  + fxCells(r) + sCell(`L${r}`, XLSX_STYLE.A, f.milestone ?? '')
1342
- + sCell(`M${r}`, XLSX_STYLE.A, xlsxContainer(f)) + '</row>';
1322
+ + sCell(`M${r}`, XLSX_STYLE.A, xlsxContainer(f)) + sCell(`N${r}`, XLSX_STYLE.A, f.scoreNote ?? '') + '</row>';
1343
1323
  }
1344
1324
 
1345
1325
  function emptyRowXml(r) {
@@ -1367,7 +1347,7 @@ function xlsxContainer(f) {
1367
1347
  // appearance), the table's current sort preserved within each milestone.
1368
1348
  function exportRows() {
1369
1349
  const msRank = [...new Set(DATA.inputs.features.map((f) => f.milestone))];
1370
- return bdVisible(bdSorted(breakdownData())).slice()
1350
+ return bdVisible(bdSorted(breakdownData(), bdState.tab)).slice()
1371
1351
  .sort((a, b) => msRank.indexOf(a.milestone) - msRank.indexOf(b.milestone));
1372
1352
  }
1373
1353
 
@@ -1380,8 +1360,8 @@ function buildSheet1(xml, rows) {
1380
1360
  + totalRowXml(total);
1381
1361
  return xml
1382
1362
  .replace(/<row r="7"[\s\S]*(?=<\/sheetData>)/, body)
1383
- .replace(/(<row r="6".*?)(<\/row>)/, `$1${sCell('L6', XLSX_STYLE.head, 'MILESTONE')}${sCell('M6', XLSX_STYLE.head, 'CONTAINER')}$2`)
1384
- .replace('</sheetData>', `</sheetData><autoFilter ref="A6:M${total - 1}"/>`)
1363
+ .replace(/(<row r="6".*?)(<\/row>)/, `$1${sCell('L6', XLSX_STYLE.head, 'MILESTONE')}${sCell('M6', XLSX_STYLE.head, 'CONTAINER')}${sCell('N6', XLSX_STYLE.head, 'WHY THIS TIER')}$2`)
1364
+ .replace('</sheetData>', `</sheetData><autoFilter ref="A6:N${total - 1}"/>`)
1385
1365
  .replace('"A27:F27"', `"A${total}:F${total}"`)
1386
1366
  .replaceAll('H7:H26', `H7:H${total - 1}`);
1387
1367
  }
@@ -1401,29 +1381,56 @@ function taskRowXml(f, t, r) {
1401
1381
  + Object.entries(texts).slice(3).map(([c, v]) => sCell(c + r, 0, v)).join('') + '</row>';
1402
1382
  }
1403
1383
 
1404
- function buildTaskSheet(rows) {
1405
- const body = rows.flatMap((f) => f.tasks.map((t) => [f, t]))
1406
- .map(([f, t], i) => taskRowXml(f, t, i + 2)).join('');
1407
- const last = 1 + rows.reduce((s, f) => s + f.tasks.length, 0);
1408
- const head = `<row r="1">${TASK_HEADERS.map((h, i) =>
1384
+ // A generated tab: frozen header row, autofilter over the data, nothing else.
1385
+ function sheetXml({ headers, body, last }) {
1386
+ const head = `<row r="1">${headers.map((h, i) =>
1409
1387
  sCell(String.fromCharCode(65 + i) + 1, XLSX_STYLE.head, h)).join('')}</row>`;
1410
1388
  return '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'
1411
1389
  + '<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">'
1412
1390
  + '<sheetViews><sheetView workbookViewId="0"><pane ySplit="1" topLeftCell="A2" '
1413
1391
  + 'activePane="bottomLeft" state="frozen"/></sheetView></sheetViews>'
1414
- + `<sheetData>${head}${body}</sheetData><autoFilter ref="A1:K${last}"/></worksheet>`;
1392
+ + `<sheetData>${head}${body}</sheetData><autoFilter ref="A1:${String.fromCharCode(64 + headers.length)}${last}"/></worksheet>`;
1393
+ }
1394
+
1395
+ function buildTaskSheet(rows) {
1396
+ const body = rows.flatMap((f) => f.tasks.map((t) => [f, t]))
1397
+ .map(([f, t], i) => taskRowXml(f, t, i + 2)).join('');
1398
+ const last = 1 + rows.reduce((s, f) => s + f.tasks.length, 0);
1399
+ return sheetXml({ headers: TASK_HEADERS, body, last });
1415
1400
  }
1416
1401
 
1417
- // Registers sheet4 in the three package indexes the clone does not have yet.
1418
- function registerTaskSheet(files, enc) {
1402
+ // --- Score Rationale tab: one row per feature × factor — the engineer's
1403
+ // view of why each score is what it is (Sheet 1's column N is the sales one).
1404
+ const RATIONALE_HEADERS = ['FEATURE', 'FACTOR', 'SCORE', 'ANCHOR', 'EVIDENCE', 'PROVENANCE'];
1405
+
1406
+ function rationaleRowXml(f, key, r) {
1407
+ const s = f.scores[key];
1408
+ return `<row r="${r}">` + sCell(`A${r}`, 0, f.name) + sCell(`B${r}`, 0, SCORE_LABELS[key]) + nCell(`C${r}`, 0, s.n)
1409
+ + sCell(`D${r}`, 0, s.anchor) + sCell(`E${r}`, 0, s.cite) + sCell(`F${r}`, 0, f.scoreProvenance) + '</row>';
1410
+ }
1411
+
1412
+ function buildRationaleSheet(rows) {
1413
+ const scored = rows.filter((f) => f.scores);
1414
+ const body = scored.flatMap((f) => SCORE_KEYS.map((k) => [f, k]))
1415
+ .map(([f, k], i) => rationaleRowXml(f, k, i + 2)).join('');
1416
+ return sheetXml({ headers: RATIONALE_HEADERS, body, last: 1 + scored.length * SCORE_KEYS.length });
1417
+ }
1418
+
1419
+ const EXTRA_SHEETS = [
1420
+ { file: 'sheet4.xml', name: 'Task Breakdown', id: 100, rid: 'rIdTasks', build: buildTaskSheet },
1421
+ { file: 'sheet5.xml', name: 'Score Rationale', id: 101, rid: 'rIdScores', build: buildRationaleSheet },
1422
+ ];
1423
+
1424
+ // Registers a generated sheet in the three package indexes the clone lacks.
1425
+ function registerSheet(files, enc, sheet) {
1419
1426
  const patch = (path, find, add) => files.set(path,
1420
1427
  enc.encode(new TextDecoder().decode(files.get(path)).replace(find, add + find)));
1421
1428
  patch('xl/workbook.xml', '</sheets>',
1422
- '<sheet state="visible" name="Task Breakdown" sheetId="100" r:id="rIdTasks"/>');
1429
+ `<sheet state="visible" name="${sheet.name}" sheetId="${sheet.id}" r:id="${sheet.rid}"/>`);
1423
1430
  patch('xl/_rels/workbook.xml.rels', '</Relationships>',
1424
- '<Relationship Id="rIdTasks" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet4.xml"/>');
1431
+ `<Relationship Id="${sheet.rid}" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/${sheet.file}"/>`);
1425
1432
  patch('[Content_Types].xml', '</Types>',
1426
- '<Override PartName="/xl/worksheets/sheet4.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"/>');
1433
+ `<Override PartName="/xl/worksheets/${sheet.file}" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"/>`);
1427
1434
  }
1428
1435
 
1429
1436
  // --- minimal zip: read the deflated template, write a stored archive ---
@@ -1526,8 +1533,10 @@ async function buildWorkbook() {
1526
1533
  const rows = exportRows();
1527
1534
  const xml = new TextDecoder().decode(files.get('xl/worksheets/sheet1.xml'));
1528
1535
  files.set('xl/worksheets/sheet1.xml', enc.encode(buildSheet1(xml, rows)));
1529
- files.set('xl/worksheets/sheet4.xml', enc.encode(buildTaskSheet(rows)));
1530
- registerTaskSheet(files, enc);
1536
+ for (const sheet of EXTRA_SHEETS) {
1537
+ files.set(`xl/worksheets/${sheet.file}`, enc.encode(sheet.build(rows)));
1538
+ registerSheet(files, enc, sheet);
1539
+ }
1531
1540
  return zipStore(files);
1532
1541
  }
1533
1542
  window.__buildWorkbook = async () => bytesB64(await buildWorkbook());