@v11g/agents-rock 1.0.5 → 1.0.7

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 (168) hide show
  1. package/README.md +1 -1
  2. package/package.json +1 -1
  3. package/plugins/business-analyst/skills/business-analyst/evals/evals.json +54 -0
  4. package/plugins/business-analyst/skills/business-analyst/evals/fixtures/pre-fed-ai-contract-review/kestrel-discovery-call.md +137 -0
  5. package/plugins/business-analyst/skills/business-analyst/evals/fixtures/thin-warehouse-brief/havenridge-thread.md +75 -0
  6. package/plugins/reasoning/.claude-plugin/plugin.json +9 -0
  7. package/plugins/reasoning/evals/guardrail-no-fabricated-figures/graders/names-missing-data.md +10 -0
  8. package/plugins/reasoning/evals/guardrail-no-fabricated-figures/graders/no-invented-numbers.md +23 -0
  9. package/plugins/reasoning/evals/guardrail-no-fabricated-figures/graders/one-framework.md +12 -0
  10. package/plugins/reasoning/evals/guardrail-no-fabricated-figures/graders/skill-fired.md +7 -0
  11. package/plugins/reasoning/evals/guardrail-no-fabricated-figures/prompt.md +44 -0
  12. package/plugins/reasoning/evals/guardrail-no-over-analysis/graders/no-diagram.md +8 -0
  13. package/plugins/reasoning/evals/guardrail-no-over-analysis/graders/no-padding.md +12 -0
  14. package/plugins/reasoning/evals/guardrail-no-over-analysis/graders/no-systems-thinking-vocabulary.md +12 -0
  15. package/plugins/reasoning/evals/guardrail-no-over-analysis/graders/one-framework-block.md +7 -0
  16. package/plugins/reasoning/evals/guardrail-no-over-analysis/graders/skill-fired.md +7 -0
  17. package/plugins/reasoning/evals/guardrail-no-over-analysis/prompt.md +7 -0
  18. package/plugins/reasoning/evals/guardrail-no-unsupported-root-cause/graders/chain-stops-at-speculation.md +10 -0
  19. package/plugins/reasoning/evals/guardrail-no-unsupported-root-cause/graders/inferred-links-are-assumptions.md +10 -0
  20. package/plugins/reasoning/evals/guardrail-no-unsupported-root-cause/graders/root-candidate-not-asserted.md +11 -0
  21. package/plugins/reasoning/evals/guardrail-no-unsupported-root-cause/graders/six-core-fields.md +21 -0
  22. package/plugins/reasoning/evals/guardrail-no-unsupported-root-cause/graders/skill-fired.md +7 -0
  23. package/plugins/reasoning/evals/guardrail-no-unsupported-root-cause/graders/uncertainties-present.md +9 -0
  24. package/plugins/reasoning/evals/guardrail-no-unsupported-root-cause/prompt.md +7 -0
  25. package/plugins/reasoning/evals/guardrail-unavailable-framework/graders/names-closest-available.md +11 -0
  26. package/plugins/reasoning/evals/guardrail-unavailable-framework/graders/names-owning-skill.md +9 -0
  27. package/plugins/reasoning/evals/guardrail-unavailable-framework/graders/no-improvised-levels.md +11 -0
  28. package/plugins/reasoning/evals/guardrail-unavailable-framework/graders/skill-fired.md +7 -0
  29. package/plugins/reasoning/evals/guardrail-unavailable-framework/graders/states-unavailable.md +10 -0
  30. package/plugins/reasoning/evals/guardrail-unavailable-framework/prompt.md +7 -0
  31. package/plugins/reasoning/evals/routing-adaptive-discriminator/graders/classifies-complex.md +13 -0
  32. package/plugins/reasoning/evals/routing-adaptive-discriminator/graders/names-the-test-applied.md +13 -0
  33. package/plugins/reasoning/evals/routing-adaptive-discriminator/graders/no-analysis.md +15 -0
  34. package/plugins/reasoning/evals/routing-adaptive-discriminator/graders/routes-to-systems-thinking.md +12 -0
  35. package/plugins/reasoning/evals/routing-adaptive-discriminator/graders/skill-fired.md +7 -0
  36. package/plugins/reasoning/evals/routing-adaptive-discriminator/prompt.md +15 -0
  37. package/plugins/reasoning/evals/routing-ambiguous-feature-request/graders/classifies-ambiguous.md +8 -0
  38. package/plugins/reasoning/evals/routing-ambiguous-feature-request/graders/every-rejection-has-a-reason.md +8 -0
  39. package/plugins/reasoning/evals/routing-ambiguous-feature-request/graders/recommends-double-diamond.md +7 -0
  40. package/plugins/reasoning/evals/routing-ambiguous-feature-request/graders/rejects-rca-and-five-whys.md +10 -0
  41. package/plugins/reasoning/evals/routing-ambiguous-feature-request/graders/skill-fired.md +7 -0
  42. package/plugins/reasoning/evals/routing-ambiguous-feature-request/prompt.md +6 -0
  43. package/plugins/reasoning/evals/routing-classify-only/graders/classifies-without-recommending.md +10 -0
  44. package/plugins/reasoning/evals/routing-classify-only/graders/no-diagnosis.md +9 -0
  45. package/plugins/reasoning/evals/routing-classify-only/graders/reason-drawn-from-prompt.md +10 -0
  46. package/plugins/reasoning/evals/routing-classify-only/graders/skill-fired.md +7 -0
  47. package/plugins/reasoning/evals/routing-classify-only/prompt.md +6 -0
  48. package/plugins/reasoning/evals/routing-complex-adaptive-org-change/graders/classifies-complex-adaptive.md +8 -0
  49. package/plugins/reasoning/evals/routing-complex-adaptive-org-change/graders/names-both-skills-in-order.md +18 -0
  50. package/plugins/reasoning/evals/routing-complex-adaptive-org-change/graders/no-downgrade.md +9 -0
  51. package/plugins/reasoning/evals/routing-complex-adaptive-org-change/graders/skill-fired.md +7 -0
  52. package/plugins/reasoning/evals/routing-complex-adaptive-org-change/graders/states-systemic-design-unavailable.md +15 -0
  53. package/plugins/reasoning/evals/routing-complex-adaptive-org-change/prompt.md +6 -0
  54. package/plugins/reasoning/evals/routing-complex-delivery-slowdown/graders/classifies-complex-adaptive.md +14 -0
  55. package/plugins/reasoning/evals/routing-complex-delivery-slowdown/graders/no-analysis.md +23 -0
  56. package/plugins/reasoning/evals/routing-complex-delivery-slowdown/graders/no-fabricated-figures.md +13 -0
  57. package/plugins/reasoning/evals/routing-complex-delivery-slowdown/graders/no-hiring-remedy.md +9 -0
  58. package/plugins/reasoning/evals/routing-complex-delivery-slowdown/graders/routes-to-systems-thinking.md +14 -0
  59. package/plugins/reasoning/evals/routing-complex-delivery-slowdown/graders/skill-fired.md +7 -0
  60. package/plugins/reasoning/evals/routing-complex-delivery-slowdown/prompt.md +64 -0
  61. package/plugins/reasoning/evals/routing-simple-null-pointer/graders/classifies-simple.md +7 -0
  62. package/plugins/reasoning/evals/routing-simple-null-pointer/graders/no-heavy-frameworks.md +9 -0
  63. package/plugins/reasoning/evals/routing-simple-null-pointer/graders/routing-discipline.md +12 -0
  64. package/plugins/reasoning/evals/routing-simple-null-pointer/graders/six-core-fields.md +21 -0
  65. package/plugins/reasoning/evals/routing-simple-null-pointer/graders/skill-fired.md +7 -0
  66. package/plugins/reasoning/evals/routing-simple-null-pointer/prompt.md +6 -0
  67. package/plugins/reasoning/evals/routing-thin-input-provisional/graders/at-most-three-class-changing-questions.md +9 -0
  68. package/plugins/reasoning/evals/routing-thin-input-provisional/graders/confidence-low.md +9 -0
  69. package/plugins/reasoning/evals/routing-thin-input-provisional/graders/no-invented-detail.md +10 -0
  70. package/plugins/reasoning/evals/routing-thin-input-provisional/graders/skill-fired.md +7 -0
  71. package/plugins/reasoning/evals/routing-thin-input-provisional/graders/states-provisional.md +9 -0
  72. package/plugins/reasoning/evals/routing-thin-input-provisional/prompt.md +6 -0
  73. package/plugins/reasoning/evals/st-causal-loop-unclosed/graders/diagram-present.md +10 -0
  74. package/plugins/reasoning/evals/st-causal-loop-unclosed/graders/edges-carry-support-labels.md +12 -0
  75. package/plugins/reasoning/evals/st-causal-loop-unclosed/graders/no-invented-delays.md +10 -0
  76. package/plugins/reasoning/evals/st-causal-loop-unclosed/graders/open-chain-not-called-a-loop.md +13 -0
  77. package/plugins/reasoning/evals/st-causal-loop-unclosed/graders/skill-fired.md +7 -0
  78. package/plugins/reasoning/evals/st-causal-loop-unclosed/prompt.md +14 -0
  79. package/plugins/reasoning/evals/st-iceberg-thin-input/graders/empty-level-is-honest.md +14 -0
  80. package/plugins/reasoning/evals/st-iceberg-thin-input/graders/no-diagram.md +11 -0
  81. package/plugins/reasoning/evals/st-iceberg-thin-input/graders/no-invented-mental-model.md +13 -0
  82. package/plugins/reasoning/evals/st-iceberg-thin-input/graders/six-core-fields.md +12 -0
  83. package/plugins/reasoning/evals/st-iceberg-thin-input/graders/skill-fired.md +7 -0
  84. package/plugins/reasoning/evals/st-iceberg-thin-input/prompt.md +9 -0
  85. package/plugins/reasoning/evals/st-leverage-points-bound/graders/elements-carry-evidence-types.md +13 -0
  86. package/plugins/reasoning/evals/st-leverage-points-bound/graders/every-level-matches-an-element.md +13 -0
  87. package/plugins/reasoning/evals/st-leverage-points-bound/graders/no-adoption-plan.md +12 -0
  88. package/plugins/reasoning/evals/st-leverage-points-bound/graders/skill-fired.md +7 -0
  89. package/plugins/reasoning/evals/st-leverage-points-bound/graders/uncovered-kinds-are-stated.md +11 -0
  90. package/plugins/reasoning/evals/st-leverage-points-bound/prompt.md +11 -0
  91. package/plugins/reasoning/evals/st-selection-boundary/graders/first-match-wins.md +17 -0
  92. package/plugins/reasoning/evals/st-selection-boundary/graders/one-block-only.md +9 -0
  93. package/plugins/reasoning/evals/st-selection-boundary/graders/rejected-candidate-has-a-reason.md +11 -0
  94. package/plugins/reasoning/evals/st-selection-boundary/graders/six-core-fields.md +12 -0
  95. package/plugins/reasoning/evals/st-selection-boundary/graders/skill-fired.md +7 -0
  96. package/plugins/reasoning/evals/st-selection-boundary/prompt.md +13 -0
  97. package/plugins/reasoning/evals/st-system-map-boundary/graders/boundary-stated.md +9 -0
  98. package/plugins/reasoning/evals/st-system-map-boundary/graders/external-factors-hold-the-unconnected.md +15 -0
  99. package/plugins/reasoning/evals/st-system-map-boundary/graders/no-intervention-design.md +11 -0
  100. package/plugins/reasoning/evals/st-system-map-boundary/graders/no-invented-components.md +12 -0
  101. package/plugins/reasoning/evals/st-system-map-boundary/graders/skill-fired.md +7 -0
  102. package/plugins/reasoning/evals/st-system-map-boundary/prompt.md +15 -0
  103. package/plugins/reasoning/skills/problem-router/README.md +46 -0
  104. package/plugins/reasoning/skills/problem-router/SKILL.md +225 -0
  105. package/plugins/reasoning/skills/problem-router/references/contract.md +104 -0
  106. package/plugins/reasoning/skills/problem-solving/README.md +47 -0
  107. package/plugins/reasoning/skills/problem-solving/SKILL.md +194 -0
  108. package/plugins/reasoning/skills/problem-solving/frameworks/a3.md +46 -0
  109. package/plugins/reasoning/skills/problem-solving/frameworks/double-diamond.md +60 -0
  110. package/plugins/reasoning/skills/problem-solving/frameworks/five-whys.md +49 -0
  111. package/plugins/reasoning/skills/problem-solving/frameworks/pdca.md +46 -0
  112. package/plugins/reasoning/skills/problem-solving/frameworks/root-cause-analysis.md +59 -0
  113. package/plugins/reasoning/skills/problem-solving/references/contract.md +104 -0
  114. package/plugins/reasoning/skills/systems-thinking/README.md +39 -0
  115. package/plugins/reasoning/skills/systems-thinking/SKILL.md +206 -0
  116. package/plugins/reasoning/skills/systems-thinking/frameworks/causal-loop.md +58 -0
  117. package/plugins/reasoning/skills/systems-thinking/frameworks/iceberg.md +43 -0
  118. package/plugins/reasoning/skills/systems-thinking/frameworks/leverage-points.md +80 -0
  119. package/plugins/reasoning/skills/systems-thinking/frameworks/system-map.md +46 -0
  120. package/plugins/reasoning/skills/systems-thinking/references/contract.md +104 -0
  121. package/plugins/solution-architect/.claude-plugin/plugin.json +1 -1
  122. package/plugins/solution-architect/skills/analyze-requirements/evals/evals.json +66 -0
  123. package/plugins/solution-architect/skills/analyze-requirements/evals/fixtures/greenfield-llm-triage-spec/triage-service-spec.md +105 -0
  124. package/plugins/solution-architect/skills/estimate/SKILL.md +4 -2
  125. package/plugins/solution-architect/skills/estimate/assets/estimate-template.html +11 -2
  126. package/plugins/solution-architect/skills/estimate/assets/scores-review-template.html +304 -59
  127. package/plugins/solution-architect/skills/estimate/evals/evals.json +60 -0
  128. package/plugins/solution-architect/skills/estimate/evals/fixtures/gate-check-northgate/northgate-email.md +18 -0
  129. package/plugins/solution-architect/skills/estimate/evals/fixtures/pre-fed-agentic-halyard/measurements.jsonl +17 -0
  130. package/plugins/solution-architect/skills/estimate/evals/fixtures/pre-fed-agentic-halyard/requirements.json +62 -0
  131. package/plugins/solution-architect/skills/estimate/evals/fixtures/pre-fed-agentic-halyard/requirements.md +41 -0
  132. package/plugins/solution-architect/skills/estimate/evals/fixtures/pre-fed-traditional-trellis/ARCHITECTURE.md +71 -0
  133. package/plugins/solution-architect/skills/estimate/evals/fixtures/pre-fed-traditional-trellis/requirements.json +68 -0
  134. package/plugins/solution-architect/skills/estimate/evals/fixtures/pre-fed-traditional-trellis/requirements.md +43 -0
  135. package/plugins/solution-architect/skills/estimate/references/interview.md +19 -10
  136. package/plugins/solution-architect/skills/estimate/references/writing.md +7 -0
  137. package/plugins/solution-architect/skills/estimate/scripts/test/references.test.mjs +4 -1
  138. package/plugins/solution-architect/skills/estimate/scripts/test/xlsx-export.test.mjs +26 -5
  139. package/plugins/solution-architect/skills/new-lead/evals/evals.json +66 -0
  140. package/plugins/solution-architect/skills/new-lead/evals/fixtures/existing-root-pipeline/leads/harborline-logistics-tms/ARCHITECTURE.md +19 -0
  141. package/plugins/solution-architect/skills/new-lead/evals/fixtures/existing-root-pipeline/leads/harborline-logistics-tms/brief.md +5 -0
  142. package/plugins/solution-architect/skills/new-lead/evals/fixtures/existing-root-pipeline/leads/harborline-logistics-tms/dist/index.html +3 -0
  143. package/plugins/solution-architect/skills/new-lead/evals/fixtures/existing-root-pipeline/leads/harborline-logistics-tms/estimation.json +10 -0
  144. package/plugins/solution-architect/skills/new-lead/evals/fixtures/existing-root-pipeline/leads/harborline-logistics-tms/proposal.md +8 -0
  145. package/plugins/solution-architect/skills/new-lead/evals/fixtures/existing-root-pipeline/leads/harborline-logistics-tms/requirements.json +38 -0
  146. package/plugins/solution-architect/skills/new-lead/evals/fixtures/existing-root-pipeline/leads/sable-dental-booking/rfp.md +14 -0
  147. package/plugins/solution-architect/skills/new-lead/evals/fixtures/existing-root-pipeline/leads/vellum-books-checkout/ARCHITECTURE.md +18 -0
  148. package/plugins/solution-architect/skills/new-lead/evals/fixtures/existing-root-pipeline/leads/vellum-books-checkout/rfp.md +7 -0
  149. package/plugins/solution-architect/skills/new-lead/evals/fixtures/existing-root-pipeline/leads.json +35 -0
  150. package/plugins/solution-architect/skills/new-lead/evals/fixtures/fresh-lead-northwind/rfp-northwind.md +28 -0
  151. package/plugins/solution-architect/skills/new-lead/evals/fixtures/skips-to-proposal/leads/meridian-freight-portal/rfp.md +14 -0
  152. package/plugins/solution-architect/skills/new-lead/evals/fixtures/skips-to-proposal/leads.json +15 -0
  153. package/plugins/solution-architect/skills/proposal/evals/evals.json +67 -0
  154. package/plugins/solution-architect/skills/proposal/evals/fixtures/gate-check-rivet-gym/ARCHITECTURE.md +53 -0
  155. package/plugins/solution-architect/skills/proposal/evals/fixtures/gate-check-rivet-gym/brief.md +23 -0
  156. package/plugins/solution-architect/skills/proposal/evals/fixtures/pre-fed-harborline-dispatch/ARCHITECTURE.md +65 -0
  157. package/plugins/solution-architect/skills/proposal/evals/fixtures/pre-fed-harborline-dispatch/brief.md +21 -0
  158. package/plugins/solution-architect/skills/proposal/evals/fixtures/pre-fed-harborline-dispatch/dist/mermaid.js +5 -0
  159. package/plugins/solution-architect/skills/proposal/evals/fixtures/pre-fed-harborline-dispatch/estimation-inputs.json +88 -0
  160. package/plugins/solution-architect/skills/proposal/evals/fixtures/pre-fed-harborline-dispatch/estimation.json +407 -0
  161. package/plugins/solution-architect/skills/proposal/evals/fixtures/pre-fed-harborline-dispatch/estimation.md +41 -0
  162. package/plugins/solution-architect/skills/proposal/evals/fixtures/pre-fed-meridian-dental/ARCHITECTURE.md +68 -0
  163. package/plugins/solution-architect/skills/proposal/evals/fixtures/pre-fed-meridian-dental/brief.md +24 -0
  164. package/plugins/solution-architect/skills/proposal/evals/fixtures/pre-fed-meridian-dental/dist/mermaid.js +5 -0
  165. package/plugins/solution-architect/skills/proposal/evals/fixtures/pre-fed-meridian-dental/estimation-inputs.json +87 -0
  166. package/plugins/solution-architect/skills/proposal/evals/fixtures/pre-fed-meridian-dental/estimation.json +394 -0
  167. package/plugins/solution-architect/skills/proposal/evals/fixtures/pre-fed-meridian-dental/estimation.md +44 -0
  168. package/src/cli/install.mjs +7 -1
@@ -0,0 +1,105 @@
1
+ # Triage Service — build spec v0.4
2
+
3
+ Status: approved for build. Nothing here is implemented yet — there is no repo.
4
+ Owner: Platform squad. Reviewed by Legal (2026-08-11) and SRE (2026-08-19).
5
+
6
+ ## 1. What it does
7
+
8
+ Inbound customer support email lands in a shared mailbox. Today two humans read
9
+ every message and drag it into a queue in Zendesk. The Triage Service replaces
10
+ the reading step: it classifies each message into a queue, assigns a priority,
11
+ extracts the customer's order reference if one is present, and writes the result
12
+ back to Zendesk as a ticket with tags. A human still owns every reply.
13
+
14
+ Out of scope for v1: drafting replies, closing tickets, any outbound email,
15
+ non-English messages (they route to `queue-manual` untouched).
16
+
17
+ ## 2. Actors
18
+
19
+ | Actor | What they do |
20
+ |---|---|
21
+ | Customer | Sends the inbound email. Never interacts with this service directly. |
22
+ | Support agent | Works the queues in Zendesk. Sees our tags and priority. |
23
+ | Triage reviewer | A support agent on rotation who audits the daily sample of low-confidence classifications. |
24
+ | Platform on-call | Gets paged when the service drops messages. |
25
+
26
+ ## 3. Vocabulary
27
+
28
+ - **Message** — one inbound email, as delivered by the mail provider webhook.
29
+ - **Classification** — one model output: queue, priority, confidence, extracted
30
+ order reference. Immutable once written.
31
+ - **Queue** — one of six fixed destinations: billing, shipping, returns,
32
+ technical, abuse, manual. Not configurable at runtime.
33
+ - **Confidence floor** — 0.72. Below it the classification is still stored but
34
+ the ticket is created in `queue-manual` and flagged for the daily audit.
35
+ - **Replay** — re-running classification for a message we already stored, after
36
+ a prompt or model change. Produces a new Classification; never mutates the old.
37
+
38
+ ## 4. Interfaces we consume and expose
39
+
40
+ | Interface | Direction | Notes |
41
+ |---|---|---|
42
+ | Mail provider webhook (Postmark inbound) | inbound | HTTPS POST, JSON, signed with a shared secret in the `X-Postmark-Signature` header. At-least-once: duplicates are expected and must be idempotent on `MessageID`. |
43
+ | Zendesk Tickets API | outbound | REST, OAuth2 client credentials. Rate limit 700 requests/minute on our plan. |
44
+ | Anthropic Messages API | outbound | Classification. Model pinned per deploy, never "latest". |
45
+ | Internal admin HTTP API | exposed | Used only by the reviewer UI: list low-confidence classifications, trigger a replay. Behind the corporate SSO proxy, no public route. |
46
+
47
+ ## 5. Data and sensitivity
48
+
49
+ Inbound email bodies contain customer PII: names, postal addresses, order
50
+ references, and occasionally card last-four digits pasted by the customer.
51
+ Legal's ruling (2026-08-11):
52
+
53
+ - Message bodies are **personal data under GDPR**. Store in eu-central-1 only.
54
+ - Retention: raw message body 30 days, then hard delete. Classification rows
55
+ (no body, no address) retained 24 months for model-quality analysis.
56
+ - The card last-four is redacted before the body is sent to the model or stored.
57
+ Redaction failures fail the message closed — the message routes to
58
+ `queue-manual` and the body is not persisted.
59
+ - Right-to-erasure requests must delete every row for a customer email within
60
+ 72 hours.
61
+ - No customer data may leave the EU. The model vendor must be called through an
62
+ EU endpoint or the design must state the residency gap explicitly.
63
+
64
+ ## 6. Deployment target
65
+
66
+ Decided, not open for discussion:
67
+
68
+ - AWS, `eu-central-1`, single region. No multi-region for v1.
69
+ - ECS Fargate, two services behind one ALB: the webhook receiver and the
70
+ classification worker. Worker scales on queue depth.
71
+ - Amazon SQS between them, with a dead-letter queue after 5 receives.
72
+ - Amazon RDS for PostgreSQL 16, Multi-AZ, encrypted at rest with a customer-
73
+ managed KMS key.
74
+ - Secrets in AWS Secrets Manager. No secret in an environment variable or image.
75
+ - CI/CD is GitHub Actions → ECR → ECS rolling deploy. Two environments, staging
76
+ and production. No manual deploys.
77
+
78
+ ## 7. Quality requirements
79
+
80
+ | Attribute | Target | Why this number |
81
+ |---|---|---|
82
+ | Durability of inbound messages | Zero dropped messages. Every accepted webhook is either classified or in the DLQ. | This is the one thing we cannot be wrong about — a dropped message is a customer who never got an answer. |
83
+ | Latency | p99 under 45 seconds from webhook accept to Zendesk ticket created. | Agents start their shift at 08:00 and want the overnight queue already sorted. |
84
+ | Availability | 99.5% monthly for the webhook receiver. | The mail provider retries for 12 hours, so a short receiver outage is recoverable. |
85
+ | RPO | 5 minutes (RDS automated backups + SQS retention cover this). | |
86
+ | RTO | 4 hours. | Manual triage is the fallback and it works; it is just slow. |
87
+ | Classification accuracy | ≥ 88% agreement with the reviewer on the daily sample. | Below that, agents stop trusting the tags and the service is worse than nothing. |
88
+
89
+ ## 8. Constraints
90
+
91
+ - Budget ceiling: $1,400/month all-in for production at 40k messages/month.
92
+ - Team: three engineers, no dedicated SRE. Anything that needs a human at 03:00
93
+ will not get one.
94
+ - Must ship a first production message by 2026-11-30.
95
+ - Company standard is TypeScript on Node 22. Python is not approved for
96
+ production services here.
97
+ - Mandated: every LLM call and its output is logged to the existing audit log
98
+ service (`audit-log`, already running, gRPC, owned by the Security team).
99
+
100
+ ## 9. Known risks flagged by the reviewers
101
+
102
+ - Prompt injection from the email body. An attacker controls the entire input.
103
+ - Model vendor residency: unresolved at spec time, see §5.
104
+ - Zendesk rate limit during a morning burst after an overnight outage.
105
+ - Cost drift if message volume grows past 40k/month.
@@ -27,8 +27,10 @@ interactive page served on localhost.
27
27
 
28
28
  1. **Detect evidence**: requirements/RFP? ARCHITECTURE.md? codebase? none?
29
29
  State findings; the user can override. (`references/interview.md` §1)
30
- 2. **Depth and delivery mode**: ask QUICK / STANDARD / DEEP, then TRADITIONAL
31
- / AGENTIC (`references/interview.md` §2b). Delivery mode decides step 4.
30
+ 2. **Depth and delivery mode**: ask QUICK / STANDARD / DEEP, then assume
31
+ AGENTIC and ask only "humans writing the code?" as the opt-out
32
+ (`references/interview.md` §2b). Delivery mode decides step 4, and is
33
+ written to `estimation-inputs.json` explicitly either way.
32
34
  3. **Interview**: follow `references/interview.md` — pre-fill from evidence,
33
35
  ask only holes, run the clear-vs-assumed gate before sizing. Read
34
36
  `references/scoring-guide.md` before proposing any score; offer the
@@ -1401,12 +1401,21 @@ function buildTaskSheet(rows) {
1401
1401
 
1402
1402
  // --- Score Rationale tab: one row per feature × factor — the engineer's
1403
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'];
1404
+ // Two source columns, because `provenance` and `scoreProvenance` answer
1405
+ // different questions about different people: did the client ask for this
1406
+ // feature, and did a reviewer override the agent's score. They share the
1407
+ // vocabulary `stated`/`proposed`, which read side by side looks like the same
1408
+ // column disagreeing with itself — so the score's half is spelled out in the
1409
+ // words it actually means, while the feature's half keeps the page's wording.
1410
+ const RATIONALE_HEADERS = ['FEATURE', 'FACTOR', 'SCORE', 'ANCHOR', 'EVIDENCE',
1411
+ 'FEATURE SOURCE', 'SCORE ORIGIN'];
1412
+ const SCORE_ORIGIN = { proposed: 'agent proposed', stated: 'reviewer changed' };
1405
1413
 
1406
1414
  function rationaleRowXml(f, key, r) {
1407
1415
  const s = f.scores[key];
1408
1416
  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>';
1417
+ + sCell(`D${r}`, 0, s.anchor) + sCell(`E${r}`, 0, s.cite) + sCell(`F${r}`, 0, f.provenance)
1418
+ + sCell(`G${r}`, 0, SCORE_ORIGIN[f.scoreProvenance] ?? '') + '</row>';
1410
1419
  }
1411
1420
 
1412
1421
  function buildRationaleSheet(rows) {
@@ -7,112 +7,357 @@
7
7
  <style>
8
8
  :root {
9
9
  color-scheme:light;
10
- --bg:#f7f5f0; --ink:#1c1b18; --ink-dim:#6f6a5e;
11
- --accent:#0f766e; --accent-ink:#0b5a54; --accent-soft:rgba(15,118,110,.08);
12
- --warn:#b45309; --warn-soft:rgba(180,83,9,.1);
13
- --bad:#b91c1c; --card:#fffdf9; --border:#e6e1d5;
10
+ --paper:#e8ecef; --sheet:#fbfcfd; --ink:#141c24; --ink-dim:#5d6c78;
11
+ --rule:#d3dbe1; --grid:#edf1f4; --meter:#44586a; --mark:#b4232f; --mark-soft:#b4232f14;
12
+ --t-s:#dfe6ec; --t-s-ink:#4a5a68; --t-m:#c3d2df; --t-m-ink:#2b3d4c;
13
+ --t-l:#7d96ab; --t-l-ink:#fff; --t-xl:#2f4a60; --t-xl-ink:#fff;
14
+ --serif:"Iowan Old Style","Palatino Linotype",Palatino,Georgia,"Liberation Serif",serif;
15
+ --sans:system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;
16
+ }
17
+ @media (prefers-color-scheme:dark) {
18
+ :root:not([data-theme="light"]) {
19
+ color-scheme:dark;
20
+ --paper:#11171c; --sheet:#1a2229; --ink:#e6ecf1; --ink-dim:#93a3b0;
21
+ --rule:#2c3740; --grid:#222c34; --meter:#8fa8bb; --mark:#e26c60; --mark-soft:#e26c6021;
22
+ --t-s:#263039; --t-s-ink:#9fb0bd; --t-m:#3a4a57; --t-m-ink:#d3dfe8;
23
+ --t-l:#7d96ab; --t-l-ink:#0f161b; --t-xl:#bacdda; --t-xl-ink:#0f161b;
24
+ }
25
+ }
26
+ :root[data-theme="dark"] {
27
+ color-scheme:dark;
28
+ --paper:#11171c; --sheet:#1a2229; --ink:#e6ecf1; --ink-dim:#93a3b0;
29
+ --rule:#2c3740; --grid:#222c34; --meter:#8fa8bb; --mark:#e26c60; --mark-soft:#e26c6021;
30
+ --t-s:#263039; --t-s-ink:#9fb0bd; --t-m:#3a4a57; --t-m-ink:#d3dfe8;
31
+ --t-l:#7d96ab; --t-l-ink:#0f161b; --t-xl:#bacdda; --t-xl-ink:#0f161b;
14
32
  }
15
33
  * { box-sizing:border-box; }
16
- body { margin:0; padding:1.5rem; font-family:system-ui,sans-serif; font-size:.9rem; background:var(--bg); color:var(--ink); }
17
- h1 { font-size:1.2rem; margin:0 0 .3rem; }
18
- p.lead { color:var(--ink-dim); margin:0 0 1rem; max-width:60rem; }
19
- table { border-collapse:collapse; width:100%; background:var(--card); }
20
- th, td { border-bottom:1px solid var(--border); padding:.4rem .5rem; text-align:left; vertical-align:top; }
21
- th.score, td.score { text-align:center; width:3.6rem; }
22
- td.score select { font:inherit; font-family:ui-monospace,monospace; width:3.2rem; text-align:center; }
23
- td.score select.hot { color:var(--bad); font-weight:600; }
24
- .tier { font-family:ui-monospace,monospace; font-size:.72rem; font-weight:600; padding:.12rem .45rem; border-radius:.25rem; background:var(--border); }
25
- .tier.l { background:var(--warn-soft); color:var(--warn); }
26
- .tier.xl { background:rgba(185,28,28,.1); color:var(--bad); }
27
- .edge { color:var(--warn); cursor:help; margin-left:.15rem; }
28
- .cite { color:var(--ink-dim); font-size:.78rem; }
29
- .cite.stale { opacity:.5; }
30
- td.note textarea { width:100%; min-height:2.6rem; font:inherit; font-size:.82rem; }
31
- details.guide { margin:1.2rem 0; }
32
- details.guide summary { cursor:pointer; font-weight:600; color:var(--ink-dim); }
33
- .guide-table { font-size:.8rem; margin-top:.6rem; }
34
+ body {
35
+ margin:0; padding:2rem 1.5rem 4rem; background:var(--paper); color:var(--ink);
36
+ font-family:var(--sans); font-size:.9rem; line-height:1.5;
37
+ }
38
+ .page { max-width:78rem; margin:0 auto; }
39
+ :focus-visible { outline:2px solid var(--ink); outline-offset:2px; }
40
+
41
+ /* ---- header ---- */
42
+ .head { display:flex; align-items:flex-start; justify-content:space-between; gap:1rem; }
43
+ #theme {
44
+ flex:none; font-size:.78rem; font-weight:600; padding:.3rem .7rem; color:var(--ink-dim);
45
+ border:1px solid var(--rule); border-radius:.2rem; background:var(--sheet); cursor:pointer;
46
+ }
47
+ #theme:hover { color:var(--ink); border-color:var(--ink-dim); }
48
+ h1 { font-family:var(--serif); font-size:2.1rem; font-weight:600; letter-spacing:-.015em; margin:0; }
49
+ .sub { margin:.15rem 0 .9rem; color:var(--ink-dim); font-size:.82rem; }
50
+ .lead { margin:0 0 1.4rem; max-width:64ch; color:var(--ink-dim); }
51
+
52
+ /* ---- the spine: one dot per feature, placed on the total ---- */
53
+ .spine-wrap { max-width:46rem; background:var(--sheet); border:1px solid var(--rule); padding:.9rem 1rem .7rem; margin-bottom:2rem; }
54
+ .spine, .zones { display:grid; grid-template-columns:repeat(21,1fr); }
55
+ .spine { align-items:end; min-height:2.6rem; }
56
+ .spine .col { display:flex; flex-direction:column-reverse; align-items:center; gap:2px; border-left:1px solid var(--grid); }
57
+ .dot {
58
+ width:11px; height:11px; padding:0; border:1px solid var(--ink); border-radius:50%;
59
+ background:var(--sheet); cursor:pointer;
60
+ }
61
+ .dot span { position:absolute; width:1px; height:1px; overflow:hidden; clip-path:inset(50%); }
62
+ .dot:hover { background:var(--ink); }
63
+ .dot.changed { border-color:var(--mark); background:var(--mark); }
64
+ .zones { border-top:1px solid var(--rule); margin-top:.35rem; padding-top:.3rem; font-size:.72rem; color:var(--ink-dim); }
65
+ .zones span { border-left:1px solid var(--rule); padding-left:.35rem; }
66
+ .zones span:first-child { border-left:0; }
67
+ .zones b { font-weight:600; color:var(--ink); }
68
+ .spine-note { margin:.45rem 0 0; font-size:.75rem; color:var(--ink-dim); }
69
+
70
+ /* ---- feature bands ---- */
71
+ .feat { display:grid; grid-template-columns:16rem 1fr; gap:1.6rem; padding:1rem 0; border-top:1px solid var(--rule); }
72
+ .feat:last-child { border-bottom:1px solid var(--rule); }
73
+ .feat.flash { background:var(--sheet); }
74
+ .rail h2 { font-family:var(--serif); font-size:1.05rem; font-weight:600; margin:0 0 .15rem; }
75
+ .rail .meta { margin:0; font-size:.74rem; color:var(--ink-dim); }
76
+ .verdict { display:flex; align-items:center; gap:.5rem; margin:.6rem 0 .25rem; }
77
+ .total { font-variant-numeric:tabular-nums; font-size:.8rem; color:var(--ink-dim); }
78
+ .total b { font-size:1.05rem; color:var(--ink); }
79
+ .tier { font-size:.75rem; font-weight:600; padding:.1rem .45rem; border:1px solid var(--rule); border-radius:.2rem; }
80
+ .tier.t-s { background:var(--t-s); color:var(--t-s-ink); }
81
+ .tier.t-m { background:var(--t-m); color:var(--t-m-ink); }
82
+ .tier.t-l { background:var(--t-l); border-color:var(--t-l); color:var(--t-l-ink); }
83
+ .tier.t-xl { background:var(--t-xl); border-color:var(--t-xl); color:var(--t-xl-ink); }
84
+ .hint, .prov { margin:0; font-size:.74rem; color:var(--ink-dim); }
85
+ .prov.edited { color:var(--mark); }
86
+
87
+ /* ---- five factors ---- */
88
+ .factors { display:grid; grid-template-columns:repeat(auto-fit,minmax(9rem,1fr)); gap:.9rem 1.1rem; }
89
+ .factor label { display:flex; align-items:center; gap:.45rem; }
90
+ .flabel { font-size:.74rem; font-weight:600; color:var(--ink-dim); }
91
+ .factor select {
92
+ font:inherit; font-variant-numeric:tabular-nums; padding:.1rem .15rem;
93
+ border:1px solid var(--rule); border-radius:.2rem; background:var(--sheet); color:var(--ink);
94
+ }
95
+ .factor select.hot { font-weight:700; border-color:var(--meter); }
96
+ .meter { display:flex; gap:2px; margin:.3rem 0 .25rem; }
97
+ .meter i { flex:1; height:3px; background:var(--rule); }
98
+ .meter i.on { background:var(--meter); }
99
+ .cite { margin:0; font-size:.76rem; line-height:1.4; color:var(--ink-dim); }
100
+ .was { margin:.15rem 0 0; font-size:.72rem; color:var(--mark); }
101
+ .factor.changed select { border-color:var(--mark); background:var(--mark-soft); }
102
+ .factor.changed .cite { text-decoration:line-through; opacity:.55; }
103
+
104
+ /* ---- the note ---- */
105
+ .note { display:block; max-width:68ch; margin-top:.7rem; }
106
+ .note textarea {
107
+ display:block; width:100%; margin-top:.25rem; padding:.4rem .5rem; min-height:2.3rem; field-sizing:content;
108
+ font-family:var(--serif); font-size:.88rem; line-height:1.45; color:var(--ink);
109
+ border:1px solid var(--rule); border-radius:.2rem; background:var(--sheet); resize:vertical;
110
+ }
111
+
112
+ /* ---- guide + feedback ---- */
113
+ details.guide { margin:2rem 0 1.4rem; }
114
+ details.guide summary { cursor:pointer; font-weight:600; }
115
+ .guide-scroll { overflow-x:auto; }
116
+ .guide-table { min-width:34rem; border-collapse:collapse; width:100%; margin-top:.7rem; font-size:.78rem; background:var(--sheet); }
117
+ .guide-table th, .guide-table td { border:1px solid var(--rule); padding:.35rem .45rem; text-align:left; vertical-align:top; }
118
+ .guide-table th { font-weight:600; color:var(--ink-dim); }
34
119
  .guide-table td.dim { font-weight:600; white-space:nowrap; }
35
- #feedback-wrap { margin-top:1.2rem; }
36
- #feedback { width:100%; min-height:7rem; font-family:ui-monospace,monospace; font-size:.75rem; }
37
- button { font:inherit; padding:.35rem .8rem; border:1px solid var(--border); border-radius:.3rem; background:var(--card); cursor:pointer; }
38
- button:hover { border-color:var(--accent); color:var(--accent-ink); }
120
+ #feedback-wrap { border-top:1px solid var(--rule); padding-top:1.2rem; }
121
+ #feedback-wrap h2 { font-family:var(--serif); font-size:1.1rem; font-weight:600; margin:0 0 .2rem; }
122
+ #feedback-wrap p { margin:0 0 .7rem; color:var(--ink-dim); font-size:.82rem; }
123
+ button {
124
+ font:inherit; font-weight:600; padding:.4rem .9rem; border:1px solid var(--ink);
125
+ border-radius:.2rem; background:var(--ink); color:var(--sheet); cursor:pointer;
126
+ }
127
+ button:hover { filter:brightness(.85); }
128
+ #copied { margin-left:.6rem; font-size:.8rem; color:var(--ink-dim); }
129
+ #feedback {
130
+ display:block; width:100%; min-height:6rem; margin-top:.8rem; padding:.5rem;
131
+ font-family:ui-monospace,SFMono-Regular,Menlo,monospace; font-size:.72rem;
132
+ border:1px solid var(--rule); background:var(--sheet); color:var(--ink-dim);
133
+ }
134
+
135
+ @media (max-width:820px) {
136
+ .feat { grid-template-columns:1fr; gap:.9rem; }
137
+ }
138
+ @media (prefers-reduced-motion:no-preference) {
139
+ .dot { transition:background .15s ease, border-color .15s ease; }
140
+ .feat { transition:background .5s ease; }
141
+ }
39
142
  </style>
40
143
  </head>
41
144
  <body>
42
- <h1><!-- slot:TITLE --> — score review</h1>
43
- <p class="lead">Each score is the agent's proposal; hover a dropdown for the rubric sentence it matched, read the evidence beside it. Change any cell, rewrite the plain-words note if it reads wrong, then copy the feedback block back into the chat.</p>
145
+ <div class="page">
146
+ <div class="head">
147
+ <div>
148
+ <h1><!-- slot:TITLE --></h1>
149
+ <p class="sub">Score review. <span id="tally"></span></p>
150
+ </div>
151
+ <button type="button" id="theme" aria-live="polite">Dark theme</button>
152
+ </div>
153
+ <p class="lead">Every score below is the agent's proposal. Hover a number to read the rubric sentence it
154
+ matched; the line under it is the evidence that score rests on. Change what reads wrong, rewrite the note
155
+ in your own words, then copy the feedback block at the bottom back into the chat.</p>
156
+
157
+ <div class="spine-wrap">
158
+ <div class="spine" id="spine"></div>
159
+ <div class="zones">
160
+ <span style="grid-column:1/8">S <b>&le;11</b></span>
161
+ <span style="grid-column:8/14">M <b>12&ndash;17</b></span>
162
+ <span style="grid-column:14/19">L <b>18&ndash;22</b></span>
163
+ <span style="grid-column:19/22">XL <b>23+</b></span>
164
+ </div>
165
+ <p class="spine-note">Each dot is one feature, placed on its total. Click a dot to jump to it; a red dot is one you changed.</p>
166
+ </div>
167
+
44
168
  <div id="review"></div>
45
- <details class="guide" open><summary>Scoring guide — what each 1–5 means</summary><!-- slot:GUIDE --></details>
169
+
170
+ <details class="guide" open><summary>Scoring guide — what each 1–5 means</summary>
171
+ <div class="guide-scroll"><!-- slot:GUIDE --></div>
172
+ </details>
173
+
46
174
  <div id="feedback-wrap">
47
- <button type="button" id="copy">copy feedback</button> <span id="copied" hidden>copied</span>
175
+ <h2>Send it back</h2>
176
+ <p>Copy this block into the chat. The agent re-reads the rubric for every score you moved and asks why.</p>
177
+ <button type="button" id="copy">Copy feedback</button> <span id="copied" role="status" hidden>Copied. Paste it into the chat.</span>
48
178
  <textarea id="feedback" readonly aria-label="feedback JSON"></textarea>
49
179
  </div>
180
+ </div>
50
181
  <script type="application/json" id="draft-data"><!-- slot:DATA --></script>
51
182
  <script>
52
183
  <!-- slot:MATH -->
53
184
  const DRAFT = JSON.parse(document.getElementById('draft-data').textContent);
54
185
  const KEYS = ['tech', 'size', 'deps', 'unc', 'risk'];
55
186
  const LABELS = { tech: 'Tech', size: 'Size', deps: 'Deps', unc: 'Unc', risk: 'Risk' };
56
- const EDGE = [11, 17, 22];
187
+ const NEXT_TIER = { 11: 'M', 17: 'L', 22: 'XL' };
188
+ const ORIGIN = { proposed: 'agent proposed', stated: 'reviewer changed' };
189
+ const MIN_TOTAL = 5;
190
+ const MAX_TOTAL = 25;
57
191
  const esc = (s) => String(s).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/"/g, '&quot;');
58
192
  const state = Object.fromEntries(DRAFT.features.map((f) => [f.id, {
59
193
  scores: Object.fromEntries(KEYS.map((k) => [k, f.scores[k].n])), scoreNote: f.scoreNote,
60
194
  }]));
61
195
 
62
- // The number comes from `state`, never from the draft: render() rebuilds the
63
- // whole table, so a select that re-read f.scores[k].n would snap back to the
64
- // agent's proposal and disagree with the Σ beside it. The anchor and cite stay
65
- // the draft's — re-anchoring a changed score is the CLI's job, not the page's
66
- // — so an edited cell says so instead of showing the old score's sentence as
67
- // if it explained the new one.
196
+ // The number comes from `state`, never from the draft: a select that re-read
197
+ // f.scores[k].n would snap back to the agent's proposal and disagree with the
198
+ // Σ beside it. The anchor and cite stay the draft's — re-anchoring a changed
199
+ // score is the CLI's job, not the page's — so an edited cell strikes its old
200
+ // evidence through instead of showing it as if it explained the new score.
68
201
  const STALE_TITLE = 'rubric sentence changes with the score — re-anchored when the agent reads this back';
202
+ const featureOf = (id) => DRAFT.features.find((f) => f.id === id);
203
+ const edited = (f) => KEYS.some((k) => state[f.id].scores[k] !== f.scores[k].n)
204
+ || state[f.id].scoreNote !== f.scoreNote;
205
+ const originText = (f) => (edited(f) ? 'you changed this' : ORIGIN[f.scoreProvenance] ?? '');
206
+ const hintFor = (total) => (NEXT_TIER[total] ? `one point from ${NEXT_TIER[total]}` : (total >= 23 ? 'big enough to split' : ''));
207
+ const meter = (n) => `<span class="meter" aria-hidden="true">${
208
+ [1, 2, 3, 4, 5].map((i) => `<i class="${i <= n ? 'on' : ''}"></i>`).join('')}</span>`;
69
209
 
70
- function scoreCell(f, k) {
210
+ function factorCell(f, k) {
71
211
  const s = f.scores[k];
72
212
  const n = state[f.id].scores[k];
73
213
  const stale = n !== s.n;
74
214
  const opts = [1, 2, 3, 4, 5].map((v) => `<option value="${v}"${v === n ? ' selected' : ''}>${v}</option>`).join('');
75
- return `<td class="score"><select data-id="${esc(f.id)}" data-key="${k}" class="${n === 5 ? 'hot' : ''}"
76
- title="${stale ? STALE_TITLE : esc(s.anchor)}">${opts}</select><div class="cite${stale ? ' stale' : ''}">${esc(s.cite)}</div></td>`;
215
+ return `<div class="factor${stale ? ' changed' : ''}">
216
+ <label><span class="flabel">${LABELS[k]}</span><select data-id="${esc(f.id)}" data-key="${k}"
217
+ class="${n === 5 ? 'hot' : ''}" title="${stale ? STALE_TITLE : esc(s.anchor)}">${opts}</select></label>
218
+ ${meter(n)}
219
+ <p class="cite">${esc(s.cite)}</p>
220
+ <p class="was">${stale ? `changed from ${s.n}` : ''}</p>
221
+ </div>`;
77
222
  }
78
223
 
79
- function row(f) {
224
+ function rail(f) {
80
225
  const { total, tier } = tierFor(state[f.id].scores);
81
- const edge = EDGE.includes(total) ? ' <span class="edge" title="one point from the next tier">&#9873;</span>' : '';
82
- return `<tr><td><strong>${esc(f.name)}</strong><div class="cite">${esc(f.id)} · ${esc(f.scoreProvenance)}</div></td>
83
- ${KEYS.map((k) => scoreCell(f, k)).join('')}
84
- <td class="score"><span data-total="${esc(f.id)}">${total}</span>${edge}</td>
85
- <td class="score"><span class="tier ${tier.toLowerCase()}" data-tier="${esc(f.id)}">${tier}</span></td>
86
- <td class="note"><textarea data-note="${esc(f.id)}" aria-label="why this tier">${esc(state[f.id].scoreNote)}</textarea></td></tr>`;
87
- }
88
-
89
- function render() {
90
- const head = `<tr><th>Feature</th>${KEYS.map((k) => `<th class="score">${LABELS[k]}</th>`).join('')}
91
- <th class="score">&Sigma;</th><th class="score">Tier</th><th>Why this tier (plain words, for the client)</th></tr>`;
92
- document.getElementById('review').innerHTML = `<table><thead>${head}</thead><tbody>${DRAFT.features.map(row).join('')}</tbody></table>`;
226
+ return `<div class="rail">
227
+ <h2>${esc(f.name)}</h2>
228
+ <p class="meta">${esc(f.id)}</p>
229
+ <p class="verdict"><span class="total">&Sigma; <b data-total="${esc(f.id)}">${total}</b></span>
230
+ <span class="tier t-${tier.toLowerCase()}" data-tier="${esc(f.id)}">${tier}</span></p>
231
+ <p class="hint" data-hint="${esc(f.id)}">${hintFor(total)}</p>
232
+ <p class="prov${edited(f) ? ' edited' : ''}" data-prov="${esc(f.id)}">${originText(f)}</p>
233
+ </div>`;
234
+ }
235
+
236
+ function band(f) {
237
+ return `<article class="feat" id="feat-${esc(f.id)}">${rail(f)}
238
+ <div class="body">
239
+ <div class="factors">${KEYS.map((k) => factorCell(f, k)).join('')}</div>
240
+ <label class="note"><span class="flabel">Why this tier, in plain words for the client</span>
241
+ <textarea data-note="${esc(f.id)}">${esc(state[f.id].scoreNote)}</textarea></label>
242
+ </div>
243
+ </article>`;
244
+ }
245
+
246
+ function dotsAt(total) {
247
+ return DRAFT.features.filter((f) => tierFor(state[f.id].scores).total === total)
248
+ .map((f) => `<button type="button" class="dot${edited(f) ? ' changed' : ''}" data-goto="${esc(f.id)}"
249
+ title="${esc(f.name)} — &Sigma; ${total}"><span>${esc(f.name)}</span></button>`).join('');
250
+ }
251
+
252
+ function tallyText() {
253
+ const n = DRAFT.features.filter(edited).length;
254
+ const features = `${DRAFT.features.length} ${DRAFT.features.length === 1 ? 'feature' : 'features'}.`;
255
+ return `${features} ${n === 0 ? 'Nothing changed yet.' : `${n} changed.`}`;
256
+ }
257
+
258
+ // The spine, the tally and the feedback block all read every feature, so they
259
+ // refresh together whenever any one score or note moves.
260
+ function refreshSpine() {
261
+ const cols = [];
262
+ for (let t = MIN_TOTAL; t <= MAX_TOTAL; t += 1) cols.push(`<div class="col">${dotsAt(t)}</div>`);
263
+ document.getElementById('spine').innerHTML = cols.join('');
264
+ document.getElementById('tally').textContent = tallyText();
93
265
  document.getElementById('feedback').value = JSON.stringify(window.__feedback(), null, 1);
94
266
  }
95
267
 
268
+ // Surgical, not a full rebuild: the reviewer is standing in this select with
269
+ // the keyboard, and re-rendering the page under them would drop the focus and
270
+ // the scroll position on every arrow press.
271
+ function syncCell(sel) {
272
+ const s = featureOf(sel.dataset.id).scores[sel.dataset.key];
273
+ const n = Number(sel.value);
274
+ const cell = sel.closest('.factor');
275
+ const stale = n !== s.n;
276
+ cell.classList.toggle('changed', stale);
277
+ sel.classList.toggle('hot', n === 5);
278
+ sel.title = stale ? STALE_TITLE : s.anchor;
279
+ cell.querySelector('.meter').outerHTML = meter(n);
280
+ cell.querySelector('.was').textContent = stale ? `changed from ${s.n}` : '';
281
+ }
282
+
283
+ function syncBand(id) {
284
+ const f = featureOf(id);
285
+ const { total, tier } = tierFor(state[id].scores);
286
+ const pick = (attr) => document.querySelector(`[data-${attr}="${CSS.escape(id)}"]`);
287
+ pick('total').textContent = total;
288
+ const chip = pick('tier');
289
+ chip.textContent = tier;
290
+ chip.className = `tier t-${tier.toLowerCase()}`;
291
+ pick('hint').textContent = hintFor(total);
292
+ const prov = pick('prov');
293
+ prov.textContent = originText(f);
294
+ prov.classList.toggle('edited', edited(f));
295
+ refreshSpine();
296
+ }
297
+
96
298
  window.__feedback = () => ({ features: DRAFT.features.map((f) => ({ id: f.id, ...state[f.id] })) });
97
299
 
98
300
  function onChange(e) {
99
301
  const sel = e.target.closest('select[data-id]');
100
302
  const note = e.target.closest('textarea[data-note]');
101
- if (sel) state[sel.dataset.id].scores[sel.dataset.key] = Number(sel.value);
102
- if (note) state[note.dataset.note].scoreNote = note.value;
103
- if (sel || note) render();
303
+ if (sel) {
304
+ state[sel.dataset.id].scores[sel.dataset.key] = Number(sel.value);
305
+ syncCell(sel);
306
+ syncBand(sel.dataset.id);
307
+ }
308
+ if (note) {
309
+ state[note.dataset.note].scoreNote = note.value;
310
+ syncBand(note.dataset.note);
311
+ }
312
+ }
313
+
314
+ function goTo(id) {
315
+ const el = document.getElementById(`feat-${id}`);
316
+ if (!el) return;
317
+ const still = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
318
+ el.scrollIntoView({ behavior: still ? 'auto' : 'smooth', block: 'center' });
319
+ el.classList.add('flash');
320
+ setTimeout(() => el.classList.remove('flash'), 900);
104
321
  }
105
322
 
323
+ // The reader's choice outlives the page; a browser that refuses storage
324
+ // (file:// in some setups) still gets a toggle that works for this sitting.
325
+ const THEME_KEY = 'scores-review-theme';
326
+ const stored = (() => { try { return localStorage.getItem(THEME_KEY); } catch { return null; } })();
327
+ const systemDark = () => window.matchMedia('(prefers-color-scheme: dark)').matches;
328
+ const themeBtn = document.getElementById('theme');
329
+
330
+ function applyTheme(mode) {
331
+ const dark = mode ? mode === 'dark' : systemDark();
332
+ if (mode) document.documentElement.dataset.theme = mode;
333
+ themeBtn.textContent = dark ? 'Light theme' : 'Dark theme';
334
+ themeBtn.dataset.dark = String(dark);
335
+ }
336
+
337
+ themeBtn.addEventListener('click', () => {
338
+ const next = themeBtn.dataset.dark === 'true' ? 'light' : 'dark';
339
+ applyTheme(next);
340
+ try { localStorage.setItem(THEME_KEY, next); } catch { /* this sitting only */ }
341
+ });
342
+ window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => {
343
+ if (!document.documentElement.dataset.theme) applyTheme(null);
344
+ });
345
+ applyTheme(stored === 'dark' || stored === 'light' ? stored : null);
346
+
106
347
  document.getElementById('review').addEventListener('change', onChange);
107
- document.getElementById('review').addEventListener('input', (e) => {
108
- if (e.target.matches('textarea[data-note]')) state[e.target.dataset.note].scoreNote = e.target.value;
348
+ document.getElementById('review').addEventListener('input', onChange);
349
+ document.getElementById('spine').addEventListener('click', (e) => {
350
+ const dot = e.target.closest('[data-goto]');
351
+ if (dot) goTo(dot.dataset.goto);
109
352
  });
110
353
  document.getElementById('copy').addEventListener('click', async () => {
111
354
  const text = JSON.stringify(window.__feedback());
112
355
  document.getElementById('feedback').value = text;
113
356
  try { await navigator.clipboard.writeText(text); document.getElementById('copied').hidden = false; } catch { /* file:// may refuse; the textarea holds it */ }
114
357
  });
115
- render();
358
+
359
+ document.getElementById('review').innerHTML = DRAFT.features.map(band).join('');
360
+ refreshSpine();
116
361
  </script>
117
362
  </body>
118
363
  </html>