@hegemonart/get-design-done 1.19.5 → 1.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/.claude-plugin/marketplace.json +4 -4
  2. package/.claude-plugin/plugin.json +2 -2
  3. package/CHANGELOG.md +90 -0
  4. package/README.md +12 -0
  5. package/agents/design-auditor.md +12 -0
  6. package/agents/design-discussant.md +14 -0
  7. package/agents/design-reflector.md +23 -0
  8. package/connections/connections.md +3 -0
  9. package/connections/figma.md +2 -0
  10. package/connections/gdd-state.md +186 -0
  11. package/hooks/budget-enforcer.ts +716 -0
  12. package/hooks/context-exhaustion.ts +251 -0
  13. package/hooks/gdd-read-injection-scanner.ts +172 -0
  14. package/hooks/hooks.json +3 -3
  15. package/package.json +29 -7
  16. package/reference/authority-feeds.md +4 -2
  17. package/reference/checklists.md +30 -0
  18. package/reference/component-authoring.md +184 -0
  19. package/reference/config-schema.md +2 -2
  20. package/reference/emotional-design.md +124 -0
  21. package/reference/error-recovery.md +58 -0
  22. package/reference/first-principles.md +89 -0
  23. package/reference/heuristics.md +70 -0
  24. package/reference/motion-advanced.md +192 -3
  25. package/reference/registry.json +28 -0
  26. package/reference/schemas/budget.schema.json +42 -0
  27. package/reference/schemas/events.schema.json +55 -0
  28. package/reference/schemas/generated.d.ts +419 -0
  29. package/reference/schemas/iteration-budget.schema.json +36 -0
  30. package/reference/schemas/mcp-gdd-state-tools.schema.json +89 -0
  31. package/reference/schemas/rate-limits.schema.json +31 -0
  32. package/reference/shared-preamble.md +10 -0
  33. package/scripts/aggregate-agent-metrics.ts +282 -0
  34. package/scripts/codegen-schema-types.ts +149 -0
  35. package/scripts/lib/error-classifier.cjs +232 -0
  36. package/scripts/lib/error-classifier.d.cts +44 -0
  37. package/scripts/lib/event-stream/emitter.ts +88 -0
  38. package/scripts/lib/event-stream/index.ts +154 -0
  39. package/scripts/lib/event-stream/types.ts +127 -0
  40. package/scripts/lib/event-stream/writer.ts +154 -0
  41. package/scripts/lib/gdd-errors/classification.ts +124 -0
  42. package/scripts/lib/gdd-errors/index.ts +218 -0
  43. package/scripts/lib/gdd-state/gates.ts +216 -0
  44. package/scripts/lib/gdd-state/index.ts +167 -0
  45. package/scripts/lib/gdd-state/lockfile.ts +232 -0
  46. package/scripts/lib/gdd-state/mutator.ts +574 -0
  47. package/scripts/lib/gdd-state/parser.ts +523 -0
  48. package/scripts/lib/gdd-state/types.ts +179 -0
  49. package/scripts/lib/iteration-budget.cjs +205 -0
  50. package/scripts/lib/iteration-budget.d.cts +32 -0
  51. package/scripts/lib/jittered-backoff.cjs +112 -0
  52. package/scripts/lib/jittered-backoff.d.cts +38 -0
  53. package/scripts/lib/lockfile.cjs +177 -0
  54. package/scripts/lib/lockfile.d.cts +21 -0
  55. package/scripts/lib/prompt-sanitizer/index.ts +435 -0
  56. package/scripts/lib/prompt-sanitizer/patterns.ts +173 -0
  57. package/scripts/lib/rate-guard.cjs +365 -0
  58. package/scripts/lib/rate-guard.d.cts +38 -0
  59. package/scripts/mcp-servers/gdd-state/schemas/add_blocker.schema.json +67 -0
  60. package/scripts/mcp-servers/gdd-state/schemas/add_decision.schema.json +68 -0
  61. package/scripts/mcp-servers/gdd-state/schemas/add_must_have.schema.json +68 -0
  62. package/scripts/mcp-servers/gdd-state/schemas/checkpoint.schema.json +51 -0
  63. package/scripts/mcp-servers/gdd-state/schemas/frontmatter_update.schema.json +62 -0
  64. package/scripts/mcp-servers/gdd-state/schemas/get.schema.json +51 -0
  65. package/scripts/mcp-servers/gdd-state/schemas/probe_connections.schema.json +75 -0
  66. package/scripts/mcp-servers/gdd-state/schemas/resolve_blocker.schema.json +66 -0
  67. package/scripts/mcp-servers/gdd-state/schemas/set_status.schema.json +47 -0
  68. package/scripts/mcp-servers/gdd-state/schemas/transition_stage.schema.json +70 -0
  69. package/scripts/mcp-servers/gdd-state/schemas/update_progress.schema.json +58 -0
  70. package/scripts/mcp-servers/gdd-state/server.ts +288 -0
  71. package/scripts/mcp-servers/gdd-state/tools/add_blocker.ts +72 -0
  72. package/scripts/mcp-servers/gdd-state/tools/add_decision.ts +89 -0
  73. package/scripts/mcp-servers/gdd-state/tools/add_must_have.ts +113 -0
  74. package/scripts/mcp-servers/gdd-state/tools/checkpoint.ts +60 -0
  75. package/scripts/mcp-servers/gdd-state/tools/frontmatter_update.ts +91 -0
  76. package/scripts/mcp-servers/gdd-state/tools/get.ts +51 -0
  77. package/scripts/mcp-servers/gdd-state/tools/index.ts +51 -0
  78. package/scripts/mcp-servers/gdd-state/tools/probe_connections.ts +73 -0
  79. package/scripts/mcp-servers/gdd-state/tools/resolve_blocker.ts +84 -0
  80. package/scripts/mcp-servers/gdd-state/tools/set_status.ts +54 -0
  81. package/scripts/mcp-servers/gdd-state/tools/shared.ts +194 -0
  82. package/scripts/mcp-servers/gdd-state/tools/transition_stage.ts +80 -0
  83. package/scripts/mcp-servers/gdd-state/tools/update_progress.ts +81 -0
  84. package/scripts/validate-frontmatter.ts +114 -0
  85. package/scripts/validate-schemas.ts +401 -0
  86. package/skills/brief/SKILL.md +15 -6
  87. package/skills/design/SKILL.md +31 -13
  88. package/skills/explore/SKILL.md +41 -17
  89. package/skills/health/SKILL.md +15 -4
  90. package/skills/optimize/SKILL.md +3 -3
  91. package/skills/pause/SKILL.md +16 -10
  92. package/skills/plan/SKILL.md +33 -17
  93. package/skills/progress/SKILL.md +15 -11
  94. package/skills/resume/SKILL.md +19 -10
  95. package/skills/settings/SKILL.md +11 -3
  96. package/skills/todo/SKILL.md +12 -3
  97. package/skills/verify/SKILL.md +65 -29
  98. package/hooks/budget-enforcer.js +0 -329
  99. package/hooks/context-exhaustion.js +0 -127
  100. package/hooks/gdd-read-injection-scanner.js +0 -39
  101. package/scripts/aggregate-agent-metrics.js +0 -173
  102. package/scripts/validate-frontmatter.cjs +0 -68
  103. package/scripts/validate-schemas.cjs +0 -242
@@ -0,0 +1,184 @@
1
+ # Component Authoring Principles
2
+
3
+ Source: Emil Kowalski's work on Sonner, Vaul, and cmdk — synthesised from his published writing and talks. See also: `reference/framer-motion-patterns.md`, `reference/motion-advanced.md`.
4
+
5
+ Use this file when authoring, reviewing, or auditing UI components. The 6 principles apply as a lens during code review and design verification. Each principle has a grep-able audit signal.
6
+
7
+ ---
8
+
9
+ ## The 6 Principles
10
+
11
+ ### P-01: Minimal API Surface
12
+
13
+ > Expose only what the consumer needs. Every prop is a contract you must maintain forever.
14
+
15
+ A component with the right API surface works in 1 line for 80% of cases and 3 lines for 95% of cases. A component that requires 7 props for basic usage has too much surface.
16
+
17
+ **Audit signal:**
18
+ ```bash
19
+ # Count required (non-optional) props in a component interface
20
+ grep -E "^\s+\w+: " src/components/Button.tsx | grep -v "?" | wc -l
21
+ ```
22
+
23
+ **Thresholds:**
24
+ - ≤5 props total: excellent
25
+ - 6–9 props total: acceptable if logically grouped
26
+ - ≥10 props: flag for decomposition
27
+
28
+ **Pattern — variant over prop explosion:**
29
+ ```tsx
30
+ // BAD — prop explosion
31
+ <Button color="blue" size="md" rounded={true} shadow={true} uppercase={false} />
32
+
33
+ // GOOD — variant collapses 5 props to 1
34
+ <Button variant="primary" size="md" />
35
+ ```
36
+
37
+ ---
38
+
39
+ ### P-02: Composability Over Configuration
40
+
41
+ > Components should compose, not configure. Accepting `backgroundColor` or `textColor` is a sign the abstraction boundary is wrong.
42
+
43
+ The right abstraction lets consumers build what they need by combining small pieces, not by passing increasingly specific configuration. Slot-based APIs > configuration-object APIs.
44
+
45
+ **Audit signal:**
46
+ ```bash
47
+ # Configuration props that should be design tokens instead
48
+ grep -rE "(backgroundColor|textColor|borderRadius|fontSize)=" src/components/ --include="*.tsx"
49
+ ```
50
+
51
+ **Pattern — slot composition:**
52
+ ```tsx
53
+ // BAD — too much configuration
54
+ <Card title="Hello" subtitle="World" icon="user" rightContent={<Badge />} />
55
+
56
+ // GOOD — slot composition; parent controls layout
57
+ <Card>
58
+ <Card.Header>
59
+ <Card.Icon><UserIcon /></Card.Icon>
60
+ <Card.Title>Hello</Card.Title>
61
+ <Card.Subtitle>World</Card.Subtitle>
62
+ <Badge />
63
+ </Card.Header>
64
+ </Card>
65
+ ```
66
+
67
+ ---
68
+
69
+ ### P-03: Sensible Defaults
70
+
71
+ > The zero-config case should work and look correct. Options are for exceptions.
72
+
73
+ A component with sensible defaults doesn't require the consumer to know its internals. The defaults encode the design system's opinion about what "normal" looks like.
74
+
75
+ **Audit signal:**
76
+ ```bash
77
+ # Props with no default values (every prop is required = red flag)
78
+ grep -E "^\s+\w+: " src/components/Toast.tsx | grep -v "?" | wc -l
79
+ ```
80
+
81
+ **The Sonner model:** `<Toaster />` with zero props renders a toast system that follows the OS color scheme, positions correctly on all viewports, stacks properly, and auto-dismisses at a sensible duration. All options exist — but the zero-prop case works.
82
+
83
+ **Anti-pattern:** Required props for things with a logical default (e.g., `position` on a modal that should always default to `center`).
84
+
85
+ ---
86
+
87
+ ### P-04: Animation as State Communication
88
+
89
+ > Transitions communicate state change. They are not decoration. An animation that fires without a state change is noise.
90
+
91
+ Every motion in a component should answer: "What did the system just do?" If the animation doesn't have a clear answer, remove it.
92
+
93
+ **Audit signal:**
94
+ ```bash
95
+ # Animations not tied to state change (decorative loops = red flag)
96
+ grep -rE "animate.*loop|animation.*infinite|keyframes.*repeat" src/components/ --include="*.tsx"
97
+ ```
98
+
99
+ **The Sonner model:**
100
+ - Toast enters → communicates: "event occurred"
101
+ - Toast stacks → communicates: "multiple events queued"
102
+ - Toast exits → communicates: "event acknowledged or expired"
103
+ - No animation fires without a state change triggering it
104
+
105
+ **Thresholds:**
106
+ - All animations tied to state: excellent
107
+ - ≤1 decorative animation (e.g., a loading shimmer): acceptable
108
+ - ≥2 decorative animations: flag for review
109
+
110
+ See `reference/motion-advanced.md` for implementation patterns.
111
+
112
+ ---
113
+
114
+ ### P-05: Accessibility Before Visuals
115
+
116
+ > If a component isn't accessible by keyboard and screen reader, it isn't done. Accessibility is not a post-processing step.
117
+
118
+ Build the ARIA contract before the visual. The visual is a rendering of the semantic layer, not the other way around.
119
+
120
+ **Audit signal:**
121
+ ```bash
122
+ # Interactive divs/spans without ARIA role (missing semantic contract)
123
+ grep -rE "<(div|span)[^>]*onClick" src/components/ --include="*.tsx" | grep -v "role="
124
+ ```
125
+
126
+ **Required ARIA contracts by component type:**
127
+
128
+ | Component | Required attributes |
129
+ |---|---|
130
+ | Dialog / Modal | `role="dialog"`, `aria-modal="true"`, `aria-labelledby` |
131
+ | Combobox / Select | `role="combobox"`, `aria-expanded`, `aria-controls` |
132
+ | Menu | `role="menu"`, `role="menuitem"`, keyboard trap |
133
+ | Toast / Alert | `role="status"` (polite) or `role="alert"` (assertive) |
134
+ | Toggle / Switch | `role="switch"`, `aria-checked` |
135
+ | Tabs | `role="tablist"`, `role="tab"`, `role="tabpanel"`, `aria-selected` |
136
+ | Tooltip | `role="tooltip"`, `aria-describedby` on trigger |
137
+
138
+ ---
139
+
140
+ ### P-06: Edge Case Honesty
141
+
142
+ > Document the cases where the component fails. If you know it breaks with strings longer than 30 characters, say so.
143
+
144
+ Undocumented edge cases become production bugs. A component spec that acknowledges failure modes is more trustworthy than one that claims universal correctness.
145
+
146
+ **Audit signal:**
147
+ ```bash
148
+ # Look for documented edge cases
149
+ grep -rE "// KNOWN:|// EDGE:|// LIMIT:" src/components/ --include="*.tsx"
150
+ ```
151
+
152
+ **Template for component edge case documentation:**
153
+ ```tsx
154
+ // KNOWN: Toast title truncates at ~80 chars on 320px viewport; use short titles
155
+ // KNOWN: Stacking > 5 toasts simultaneously is unsupported; excess toasts are queued
156
+ // EDGE: If `duration` is set to Infinity, a visible dismiss button is required
157
+ ```
158
+
159
+ The presence of these comments is a quality signal, not a code smell. It means the author thought about the boundary conditions.
160
+
161
+ ---
162
+
163
+ ## Lens Application in Audits
164
+
165
+ When auditing a component, apply these six principles as a checklist:
166
+
167
+ | Principle | Pass condition | Fail condition |
168
+ |---|---|---|
169
+ | P-01 Minimal API | ≤9 props; zero-config case works | ≥10 props; required props for things with defaults |
170
+ | P-02 Composability | Slot-based composition; no style props | `backgroundColor`/`textColor` props present |
171
+ | P-03 Defaults | Zero-prop case renders correctly | Most props required for basic usage |
172
+ | P-04 Animation | All motion tied to state change | Decorative loops or orphaned animations present |
173
+ | P-05 Accessibility | ARIA contract complete; keyboard navigable | `onClick` on `div`; missing `role`; no keyboard trap |
174
+ | P-06 Edge honesty | Known limits documented with `// KNOWN:` | No documentation of failure modes |
175
+
176
+ ---
177
+
178
+ ## Wiring
179
+
180
+ **design-auditor:** Apply as an optional sub-check within Pillar 7 (Micro-Polish) for component-heavy UIs. Cite principle ID (P-01 through P-06) in findings.
181
+
182
+ **design-discussant:** In `--spec` mode, ask one component-authoring question per component under review: "For [ComponentName]: does the API surface expose only what consumers need, or are there configuration props that reveal implementation details?"
183
+
184
+ **design-verifier:** When verifying component-library phases, include P-01 through P-06 in the must-have checklist as a component quality gate.
@@ -185,7 +185,7 @@ If `.design/budget.json` is missing when any `/gdd:*` command runs, `scripts/boo
185
185
 
186
186
  ## .design/telemetry/costs.jsonl + .design/agent-metrics.json (Phase 10.1)
187
187
 
188
- Phase 10.1 introduces two measurement artifacts written by `hooks/budget-enforcer.js` (PreToolUse on `Agent` spawns) and `scripts/aggregate-agent-metrics.js` (detached child of the hook + refresh step of `/gdd:optimize`). Both files live under the gitignored `.design/` directory — they are local session state, not committed.
188
+ Phase 10.1 introduces two measurement artifacts written by `hooks/budget-enforcer.js` (PreToolUse on `Agent` spawns) and `scripts/aggregate-agent-metrics.ts` (detached child of the hook + refresh step of `/gdd:optimize`). Both files live under the gitignored `.design/` directory — they are local session state, not committed.
189
189
 
190
190
  ### .design/telemetry/costs.jsonl
191
191
 
@@ -223,7 +223,7 @@ Append-only ledger. One JSON object per line. Written by `hooks/budget-enforcer.
223
223
 
224
224
  ### .design/agent-metrics.json
225
225
 
226
- Per-agent aggregate derived from `costs.jsonl` by `scripts/aggregate-agent-metrics.js`. Written atomically via tmp-file + rename. Overwritten in full on every refresh — not append-only. Consumers should treat it as a snapshot.
226
+ Per-agent aggregate derived from `costs.jsonl` by `scripts/aggregate-agent-metrics.ts`. Written atomically via tmp-file + rename. Overwritten in full on every refresh — not append-only. Consumers should treat it as a snapshot.
227
227
 
228
228
  **Schema:**
229
229
 
@@ -0,0 +1,124 @@
1
+ # Emotional Design — Norman's Three Levels
2
+
3
+ Source: Don Norman, *Emotional Design: Why We Love (or Hate) Everyday Things* (2004). See also: `jnd.org`.
4
+
5
+ Use this file as a **cross-cutting scoring lens** in design audits and reflections. The three levels apply simultaneously to every design decision — they are not sequential stages.
6
+
7
+ ---
8
+
9
+ ## The Three Levels
10
+
11
+ ### Visceral Level
12
+
13
+ > The immediate, pre-cognitive, automatic reaction to sensory input.
14
+
15
+ The visceral level operates before the user thinks. It is driven by appearance, proportion, colour, texture — the aesthetic surface. A user who says "I don't know why, but this feels cheap" is responding at the visceral level.
16
+
17
+ **What it governs:**
18
+ - First impression within 50ms of page load (aesthetic-usability effect)
19
+ - Color palettes and their emotional valence
20
+ - Typography weight, roundness, and whitespace generosity
21
+ - Illustration style, photography tone, iconography personality
22
+ - Whether motion feels fluid or mechanical
23
+
24
+ **Audit signals:**
25
+ - Does the visual system convey the intended emotional register within 3 seconds?
26
+ - Are there conflicting visceral signals? (e.g., playful illustration + harsh red error banners)
27
+ - Does the `style-vocabulary.md` aesthetic type match the product's emotional promise?
28
+
29
+ **Scoring rubric (visceral):**
30
+
31
+ | Score | Evidence |
32
+ |---|---|
33
+ | 4 | Emotional register clear within 3s; no conflicting signals; references a named design authority |
34
+ | 3 | Clear emotional intent; 1–2 minor conflicts (e.g., one off-brand icon) |
35
+ | 2 | Ambiguous emotional register; mixed signals across surfaces |
36
+ | 1 | No discernible emotional intent; generic or template appearance |
37
+
38
+ ---
39
+
40
+ ### Behavioral Level
41
+
42
+ > The experience of use — whether actions feel controllable, predictable, and rewarding.
43
+
44
+ The behavioral level is what UX heuristics primarily address. It covers usability, feedback, error recovery, and responsiveness. A user who says "This is frustrating to use" is responding at the behavioral level.
45
+
46
+ **What it governs:**
47
+ - Interaction feedback (loading states, error messages, success confirmations)
48
+ - Control and reversibility (undo, cancel, back navigation)
49
+ - Response latency — the Doherty Threshold: feedback within 400ms
50
+ - Error prevention and recovery
51
+ - Learnability and consistency across screens
52
+
53
+ **Audit signals:**
54
+ - Can the user always tell what the system is doing? (H-01 Visibility)
55
+ - Are errors expressed as human problems with solutions? (H-09 Error Recovery)
56
+ - Is every action reversible within 5 seconds?
57
+ - Does the system respond within 400ms (Doherty Threshold)?
58
+
59
+ **Scoring rubric (behavioral):**
60
+
61
+ | Score | Evidence |
62
+ |---|---|
63
+ | 4 | All states visible; errors human + actionable; Doherty Threshold met; all destructive actions reversible |
64
+ | 3 | Most states covered; 1–2 feedback gaps that don't block task completion |
65
+ | 2 | Notable feedback gaps; some irreversible actions without warning |
66
+ | 1 | System status invisible; errors developer-facing; no undo for destructive actions |
67
+
68
+ ---
69
+
70
+ ### Reflective Level
71
+
72
+ > The conscious, post-use evaluation — meaning, narrative, and self-image.
73
+
74
+ The reflective level is where brand identity, storytelling, and pride of ownership live. A user who says "I love showing this tool to colleagues" is responding at the reflective level. This level takes the longest to build and the longest to repair when damaged.
75
+
76
+ **What it governs:**
77
+ - Whether the product aligns with the user's self-image
78
+ - Brand narrative consistency across all touchpoints
79
+ - Delight and surprise moments — not gimmicks; earned moments
80
+ - The **Peak** moment in the Peak-End Rule: the highest positive moment in the flow
81
+ - Long-term loyalty and word-of-mouth referral
82
+
83
+ **Audit signals:**
84
+ - Is there an identifiable "peak" moment in the primary user flow?
85
+ - Does the brand voice (from `brand-voice.md`) carry through to microcopy and empty states?
86
+ - Is there a designed completion state that communicates personality?
87
+ - Does the product give users a story to tell? (e.g., a completion screen, an achievement, a shareable output)
88
+
89
+ **Scoring rubric (reflective):**
90
+
91
+ | Score | Evidence |
92
+ |---|---|
93
+ | 4 | Identifiable designed peak moment; brand voice consistent from entry to completion; users have a story to tell |
94
+ | 3 | Brand voice present in most surfaces; peak moment implicit but not deliberately designed |
95
+ | 2 | Brand voice inconsistent; no designed peak; product is functional but forgettable |
96
+ | 1 | Generic experience; no emotional arc; could be any product in the category |
97
+
98
+ ---
99
+
100
+ ## Cross-Cutting Lens Application
101
+
102
+ Apply this lens as a **secondary overlay** after scoring the primary audit pillars. For each of the three levels:
103
+
104
+ 1. Identify 1–2 evidence items from the primary audit (e.g., Pillar 3 Color → Visceral Level)
105
+ 2. Note conflicts between levels (e.g., Behavioral score 4 but Visceral score 1 = technically functional but aesthetically repellent)
106
+ 3. Flag the weakest level as the highest-leverage improvement opportunity
107
+
108
+ **Common cross-level conflict patterns:**
109
+
110
+ | Conflict pattern | Diagnosis | Remedy |
111
+ |---|---|---|
112
+ | High behavioral, low visceral | Technically usable but aesthetically generic | Audit against `style-vocabulary.md`; commit to a stronger aesthetic type |
113
+ | High visceral, low behavioral | Beautiful but broken | Fix H-01, H-09 violations first — UX before aesthetics |
114
+ | High visceral + behavioral, low reflective | Polished but forgettable | Design a peak moment; review `brand-voice.md` emotional arc |
115
+
116
+ ---
117
+
118
+ ## Wiring
119
+
120
+ **design-auditor:** After pillar scoring, apply emotional-design lens as a cross-cutting overlay. Add `## Emotional Design Overlay` section to `DESIGN-AUDIT.md` with scores for all three levels and any cross-level conflict notes.
121
+
122
+ **design-reflector:** In Section 1 (What Surprised Us), flag if visceral vs behavioral scores diverge by ≥2 points — this is a leading indicator of the "beautiful but broken" pattern.
123
+
124
+ **design-discussant:** In `--spec` mode, include one reflective-level confidence-scored question: "What story does this product help the user tell about themselves?"
@@ -0,0 +1,58 @@
1
+ # Error recovery
2
+
3
+ This is the recovery-action protocol for low-level errors inside the GDD pipeline. It sits on top of `scripts/lib/error-classifier.cjs` (Plan 20-14) and references the rate-guard, jittered-backoff, and iteration-budget primitives.
4
+
5
+ ## Recovery protocol
6
+
7
+ On `status=413` or `context_overflow`, re-emit with compressed context (drop oldest non-system turns, target 50% reduction, retry once).
8
+
9
+ On `status=429`, consult `scripts/lib/rate-guard.cjs` → `blockUntilReady(provider)` before retry.
10
+
11
+ On network-transient (5xx, ECONNRESET), use jittered backoff (`scripts/lib/jittered-backoff.cjs`); max 3 retries.
12
+
13
+ On auth-error, surface to user — do not retry.
14
+
15
+ ## Recovery-action table
16
+
17
+ The `FailoverReason` enum in `scripts/lib/error-classifier.cjs` has eight values. Each row below is the canonical recovery action for one of those values. The classifier's `suggestedAction` field returns a one-liner drawn from this table; this doc is the authoritative long form.
18
+
19
+ | FailoverReason | Retryable | Action |
20
+ | ------------------- | --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |
21
+ | `rate_limited` | yes | Call `rate-guard.ingestHeaders(provider, response.headers)` to record the rate-limit signal, then `rate-guard.blockUntilReady(provider)` before retrying. The blocker waits until `resetAt` on disk — synchronized siblings (watch-authorities + update-check) therefore share the backoff boundary. After the block returns, retry with jittered backoff at attempt 0. |
22
+ | `context_overflow` | yes | Compress context — drop the oldest non-system turns (or the oldest attachments) targeting roughly 50 % token reduction. Retry **once** with the compressed payload. If the retry also raises `context_overflow`, escalate to the user as an unrecoverable block — further compression destroys information. |
23
+ | `auth_error` | no | Surface the error to the user with actionable text: which credential, which provider, and the renewal path (OAuth re-auth URL, API-key environment variable, etc.). Do not retry automatically — a loop would just multiply the failure. |
24
+ | `network_transient` | yes | Retry with `scripts/lib/jittered-backoff.cjs` — `await sleep(attempt)` inside a bounded loop. Cap at 3 attempts before giving up. When retries exhaust, reclassify as `network_permanent` and surface to the user. |
25
+ | `network_permanent` | no | Surface to user. The endpoint is wrong, DNS is broken, or the resource was removed. A retry without operator action will just re-fail. |
26
+ | `tool_not_found` | no | Surface to user. Either the tool name drifted (common for MCP servers whose prefixes change across sessions) or the MCP is not registered. Reprobe via the connection's probe sequence before retrying anything. |
27
+ | `validation` | no | Surface the validation detail to the caller. Do not retry the same input — 4xx is the server saying "your payload is wrong". Fixing the payload is caller work. |
28
+ | `unknown` | no | Surface the raw error to the user. Do not retry — we can't tell whether it's safe. Add a telemetry row so we can tighten the classifier over time. |
29
+
30
+ ## Integration points
31
+
32
+ | Caller | When to classify | What to do with `reason` |
33
+ | ------------------------- | -------------------------------------------- | ------------------------------------------------------------------------------------------------------------------ |
34
+ | `hooks/budget-enforcer.ts` | pre-spawn rate-guard check (Plan 20-14) | If upstream state already shows `rate_limited`, emit `decision: 'rate-limited'` and short-circuit before any spawn. |
35
+ | Figma MCP probe | live `get_metadata` call errors | `network_transient` → jittered-backoff retry. `auth_error` → STOP with a reauth note. `rate_limited` → block then retry. |
36
+ | Watch-authorities fetcher | per-feed HTTP fetch | Same policy as Figma probe; `validation` also possible on ETag stalemate (304). |
37
+ | Update-check HTTP curl | GitHub `releases/latest` fetch | Silent failure by D-04 of Plan 13.3 — classify but don't surface; log and exit 0. |
38
+ | MCP transport | tool-call errors (gdd-state, figma, 21st-dev)| Map `tool_not_found` to a probe-reissue; map `auth_error` to STOP; retry transient classes via the caller's own loop. |
39
+
40
+ ## Fix-loop iteration interaction
41
+
42
+ Retries consume iteration budget when paired with the Layer-B cache:
43
+
44
+ 1. On cache hit, `iteration-budget.refund(1)` preserves the iteration that would otherwise have been spent.
45
+ 2. On each actual retry that does real work (no cache hit), the caller `iteration-budget.consume(1)` before the spawn.
46
+ 3. When the budget's `remaining === 0`, further retries throw `IterationBudgetExhaustedError` and the caller must surface to user — a retry cycle has become pathological.
47
+
48
+ This protects the "infinite fix loop" case — a blocker that regenerates after every fix — from burning unbounded context.
49
+
50
+ ## Telemetry
51
+
52
+ Every classification result that leads to a retry or a surfaced error should append an event to `.design/telemetry/events.jsonl`:
53
+
54
+ ```json
55
+ { "type": "error.classified", "timestamp": "…", "sessionId": "…", "payload": { "reason": "rate_limited", "retryable": true, "caller": "figma-probe" } }
56
+ ```
57
+
58
+ The event subtype is defined in `scripts/lib/event-stream/types.ts`. Consumers (`gdd-reflector`, dashboard) aggregate by `reason` to detect classifier drift — if `unknown` spikes, the classifier needs tightening.
@@ -0,0 +1,89 @@
1
+ # First Principles — Invariant Design Constraints
2
+
3
+ > These are the three invariants that no design decision can override. They are facts about human biology and cognition, not preferences or conventions. Every design choice is downstream of these three constraints.
4
+
5
+ Use during the brief/discover stage (`design-discussant`) as a sanity check: does the proposed direction respect all three invariants? Use during verify as a reducibility check: can each element be removed without breaking the user's ability to complete their goal?
6
+
7
+ ---
8
+
9
+ ## Invariant 1: Body
10
+
11
+ The user has a physical body with physiological limits. No amount of design skill overrides human motor physiology.
12
+
13
+ **Principle → Code pairs:**
14
+
15
+ | Principle | Code Pattern |
16
+ |---|---|
17
+ | Touch targets must accommodate tremor and fat-finger error | `min-h-[44px] min-w-[44px]` on all interactive elements |
18
+ | Precision degrades with distance (Fitts's Law) | Destructive actions separated from primary actions by ≥24px or significantly smaller |
19
+ | Scroll fatigue is real | Sticky headers + back-to-top anchor for content > 3 viewport heights |
20
+ | Physical feedback confirms action | `scale(0.96)` press feedback on all clickable surfaces |
21
+ | Eye strain limits reading distance | Body text ≥16px; line-length 60–75ch |
22
+
23
+ **Reducibility check:** Can the user complete this task without a mouse? Without a precise pointer? On a 4-inch screen in a moving vehicle?
24
+
25
+ ---
26
+
27
+ ## Invariant 2: Attention
28
+
29
+ Attention is finite and non-renewable per unit of time. Every element on screen competes for the same fixed budget.
30
+
31
+ **Principle → Code pairs:**
32
+
33
+ | Principle | Code Pattern |
34
+ |---|---|
35
+ | Attention capacity: 5–9 items (Miller's Law) | Navigation: ≤7 top-level items; dropdown > 7 items gets search |
36
+ | Decision cost grows with choice count (Hick's Law) | Pricing: ≤3 tiers; feature lists: ≤4 items per group |
37
+ | One primary action per screen | Single `.btn-primary` per viewport; all others `.btn-secondary` or `.btn-ghost` |
38
+ | Animation hijacks attention | Motion only on state change; no decorative looping animations |
39
+ | Progressive disclosure reduces overload | Advanced options behind disclosure trigger, not visible by default |
40
+
41
+ **Reducibility check:** If you removed 30% of the elements on this screen, would task completion rate drop? If not, remove them.
42
+
43
+ ---
44
+
45
+ ## Invariant 3: Memory
46
+
47
+ Working memory holds approximately 7 items and degrades rapidly within seconds. Design that requires users to remember things between screens fails.
48
+
49
+ **Principle → Code pairs:**
50
+
51
+ | Principle | Code Pattern |
52
+ |---|---|
53
+ | Recognition over recall (H-06) | Visible navigation labels, not icon-only; breadcrumbs on deep paths |
54
+ | Context must be preserved | Multi-step forms: prior-step summary visible; form state not cleared on back-navigate |
55
+ | Error memory fades fast | Inline validation: errors adjacent to the field that caused them |
56
+ | Completion status reduces anxiety | Progress indicators: `Step 2 of 4`; Zeigarnik Effect — show percentage done |
57
+ | Last action should be reversible | Undo available for destructive/irreversible actions within 5 seconds |
58
+
59
+ **Reducibility check:** Does this screen require the user to remember something from a previous screen? If yes, surface that context inline.
60
+
61
+ ---
62
+
63
+ ## The Reducibility Test
64
+
65
+ For any proposed design element, apply in order:
66
+
67
+ 1. **Body test** — Is this element reachable by a person with limited motor precision on a small screen?
68
+ 2. **Attention test** — Does this element earn its place by directly supporting the primary task?
69
+ 3. **Memory test** — Does this element surface context the user would otherwise need to remember?
70
+
71
+ If an element fails all three tests, it is purely decorative. Decorative elements are not forbidden — but they are not invariant-justified, and they are the first candidates for removal when performance or clarity is at risk.
72
+
73
+ ---
74
+
75
+ ## Wiring to Design Discussant
76
+
77
+ When `design-discussant` runs the brief stage, it prepends this invariants question before the main interview:
78
+
79
+ > "Before we discuss the design direction, let me confirm three constraints: (1) Are there any accessibility requirements for motor-impaired users? (2) Is the primary use case on mobile or desktop — or both? (3) Are there any multi-step flows where the user must carry context between screens?"
80
+
81
+ Answers are recorded as D-XX decisions prefixed `[Invariant]` in STATE.md.
82
+
83
+ ---
84
+
85
+ ## Relationship to Other References
86
+
87
+ - `reference/heuristics.md` — H-01 through H-10 are the behavioral-level expression of Invariants 2 and 3
88
+ - `reference/emotional-design.md` — Invariant 1 (Body) maps to the Visceral level; Invariants 2–3 map to the Behavioral level
89
+ - `reference/component-authoring.md` — P-01 through P-06 are the component-level expression of all three invariants
@@ -181,6 +181,76 @@ People **remember incomplete tasks** better than completed ones. Implications:
181
181
 
182
182
  ---
183
183
 
184
+ ## Peak-End Rule
185
+
186
+ Users judge an experience primarily by how it felt at its most intense moment (the **peak**) and how it ended — not by the average across the whole session. Implications:
187
+ - Design a deliberate positive peak in every primary flow (e.g., a celebratory completion screen, an instant result, a delightful empty state).
188
+ - The **end state** of a flow matters disproportionately: the last screen the user sees shapes their memory of the whole interaction.
189
+ - Reduce negative peaks first (error states, loading hangs) — they weigh heavier than neutral moments.
190
+ - A long frustrating form followed by a satisfying completion screen is remembered more positively than a mildly annoying end to an otherwise smooth flow.
191
+
192
+ ---
193
+
194
+ ## Loss Aversion
195
+
196
+ Users feel the pain of loss approximately **twice as strongly** as the pleasure of an equivalent gain (Kahneman & Tversky). Implications:
197
+ - Frame CTAs around what users keep/save, not what they gain: "Don't lose your progress" over "Save your work."
198
+ - Subscription cancellation flows that show what the user will lose (features, data, streak) leverage loss aversion ethically to reduce churn — but only if the stated losses are real.
199
+ - Free trial countdowns ("3 days left") trigger loss aversion more effectively than benefit reminders.
200
+ - Destructive action confirmations should name what is lost: "Delete this project and all 47 files?" not just "Are you sure?"
201
+
202
+ ---
203
+
204
+ ## Cognitive Load Theory
205
+
206
+ Working memory is limited to approximately **7 ± 2 chunks** simultaneously (Miller, 1956) and degrades under conditions of stress, distraction, or novelty. Cognitive Load Theory (Sweller, 1988) distinguishes three types:
207
+
208
+ | Type | Definition | Design implication |
209
+ |---|---|---|
210
+ | **Intrinsic** | Load inherent to the task itself (complexity of the domain) | Cannot be reduced; must be scaffolded |
211
+ | **Extraneous** | Load imposed by poor design (navigation, unclear labels, visual noise) | Eliminate this completely |
212
+ | **Germane** | Load that builds understanding (learning, pattern recognition) | Preserve and support |
213
+
214
+ Practical rules:
215
+ - Every element of visual noise is extraneous load — remove it.
216
+ - New UI patterns create extraneous load (Jakob's Law); use platform conventions.
217
+ - Chunk complex tasks into steps of ≤3 decisions each.
218
+ - Error messages that require decoding ("Error 422") create extraneous load; plain language removes it.
219
+
220
+ ---
221
+
222
+ ## Aesthetic-Usability Effect
223
+
224
+ Users perceive **aesthetically pleasing designs as more usable**, even when functionality is identical — and this perception persists through initial usability problems. Implications:
225
+ - A polished visual appearance buys tolerance for minor UX rough edges in early releases.
226
+ - This effect is strongest on first impression; it degrades over time as behavioral friction compounds.
227
+ - The effect can mask genuine usability problems in user testing if participants rate overall satisfaction rather than task completion.
228
+ - Do NOT use the aesthetic-usability effect as a reason to defer fixing usability problems — it explains tolerance, not satisfaction.
229
+
230
+ ---
231
+
232
+ ## Doherty Threshold
233
+
234
+ A system that responds within **400ms** keeps users in a state of flow. Response times above 400ms cause users to shift attention, leading to a productivity drop that compounds with task complexity. Named after W.J. Doherty and R.H. Thadhani (IBM, 1982). Implications:
235
+ - Interactive responses (button click → visible feedback) must be ≤400ms.
236
+ - For operations > 400ms, show optimistic UI immediately and settle in the background.
237
+ - For operations > 1000ms, use a progress indicator.
238
+ - For operations > 10s, provide a way to continue other tasks (async notification on complete).
239
+ - Loading spinners that appear within 400ms reduce perceived wait; those that appear late increase it.
240
+
241
+ ---
242
+
243
+ ## Flow (Csikszentmihalyi)
244
+
245
+ Users enter a **flow state** when task difficulty matches their skill level exactly — high enough to engage, low enough to feel achievable. Flow is characterized by complete absorption, loss of time awareness, and intrinsic motivation. Implications:
246
+ - Progressive difficulty: onboarding tasks should be trivially easy; expert tasks should provide just enough challenge.
247
+ - Interruptions break flow permanently for that session; avoid modal interruptions in high-focus workflows.
248
+ - Clear goals + immediate feedback are the two design levers for inducing flow (H-01, H-05).
249
+ - Forms designed for flow: one question per screen, immediate validation, visible progress.
250
+ - Notification design: distinguish ambient notifications (don't break flow) from critical interruptions (must break flow).
251
+
252
+ ---
253
+
184
254
  ## How to Score During Verification
185
255
 
186
256
  For each NNG heuristic (H-01 through H-10), rate 0–4: