qualia-framework 4.4.0 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +24 -0
- package/CLAUDE.md +12 -63
- package/README.md +24 -18
- package/agents/builder.md +13 -33
- package/agents/plan-checker.md +18 -0
- package/agents/planner.md +17 -0
- package/agents/verifier.md +70 -0
- package/agents/visual-evaluator.md +132 -0
- package/bin/cli.js +64 -23
- package/bin/install.js +375 -29
- package/bin/qualia-ui.js +208 -1
- package/bin/slop-detect.mjs +362 -0
- package/bin/state.js +218 -2
- package/docs/erp-contract.md +5 -0
- package/docs/install-redesign-builder-prompt.md +290 -0
- package/docs/install-redesign-pilot.md +234 -0
- package/docs/playwright-loop-builder-prompt.md +185 -0
- package/docs/playwright-loop-design-notes.md +108 -0
- package/docs/playwright-loop-pilot-results.md +170 -0
- package/docs/playwright-loop-review-2026-05-03.md +65 -0
- package/docs/playwright-loop-tester-prompt.md +213 -0
- package/docs/reviews/matt-pocock-skills-analysis.md +300 -0
- package/guide.md +9 -5
- package/hooks/env-empty-guard.js +74 -0
- package/hooks/pre-compact.js +19 -9
- package/hooks/pre-deploy-gate.js +8 -2
- package/hooks/pre-push.js +26 -12
- package/hooks/supabase-destructive-guard.js +62 -0
- package/hooks/vercel-account-guard.js +91 -0
- package/package.json +2 -1
- package/rules/design-brand.md +114 -0
- package/rules/design-laws.md +148 -0
- package/rules/design-product.md +114 -0
- package/rules/design-rubric.md +157 -0
- package/rules/grounding.md +4 -0
- package/skills/qualia-build/SKILL.md +40 -46
- package/skills/qualia-discuss/SKILL.md +51 -68
- package/skills/qualia-handoff/SKILL.md +1 -0
- package/skills/qualia-issues/SKILL.md +151 -0
- package/skills/qualia-map/SKILL.md +78 -35
- package/skills/qualia-new/REFERENCE.md +139 -0
- package/skills/qualia-new/SKILL.md +85 -124
- package/skills/qualia-optimize/REFERENCE.md +202 -0
- package/skills/qualia-optimize/SKILL.md +72 -237
- package/skills/qualia-plan/SKILL.md +58 -65
- package/skills/qualia-polish/SKILL.md +180 -136
- package/skills/qualia-polish-loop/REFERENCE.md +265 -0
- package/skills/qualia-polish-loop/SKILL.md +201 -0
- package/skills/qualia-polish-loop/fixtures/broken.html +117 -0
- package/skills/qualia-polish-loop/fixtures/clean.html +196 -0
- package/skills/qualia-polish-loop/scripts/loop.mjs +302 -0
- package/skills/qualia-polish-loop/scripts/playwright-capture.mjs +197 -0
- package/skills/qualia-polish-loop/scripts/score.mjs +176 -0
- package/skills/qualia-report/SKILL.md +141 -180
- package/skills/qualia-research/SKILL.md +28 -33
- package/skills/qualia-road/SKILL.md +103 -0
- package/skills/qualia-ship/SKILL.md +1 -0
- package/skills/qualia-task/SKILL.md +1 -1
- package/skills/qualia-test/SKILL.md +50 -2
- package/skills/qualia-triage/SKILL.md +152 -0
- package/skills/qualia-verify/SKILL.md +63 -104
- package/skills/qualia-zoom/SKILL.md +51 -0
- package/skills/zoho-workflow/SKILL.md +64 -0
- package/templates/CONTEXT.md +36 -0
- package/templates/DESIGN.md +229 -435
- package/templates/PRODUCT.md +95 -0
- package/templates/decisions/ADR-template.md +30 -0
- package/tests/bin.test.sh +451 -7
- package/tests/state.test.sh +58 -0
- package/skills/qualia-design/SKILL.md +0 -169
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
# /qualia-optimize Reference Templates
|
|
2
|
+
|
|
3
|
+
Agent-prompt templates for SKILL.md. Copy, fill `{placeholders}`, spawn.
|
|
4
|
+
|
|
5
|
+
## Frontend agent prompt
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
Agent(
|
|
9
|
+
prompt="Optimize frontend. Analyze planning docs + rules, then code.
|
|
10
|
+
|
|
11
|
+
<planning>
|
|
12
|
+
{PROJECT.md content}
|
|
13
|
+
{REQUIREMENTS.md content}
|
|
14
|
+
{DESIGN.md content}
|
|
15
|
+
</planning>
|
|
16
|
+
|
|
17
|
+
<rules>
|
|
18
|
+
{rules/frontend.md content}
|
|
19
|
+
</rules>
|
|
20
|
+
|
|
21
|
+
<task>
|
|
22
|
+
Analyze frontend:
|
|
23
|
+
|
|
24
|
+
1. **UI Quality**
|
|
25
|
+
- Loading: every async op needs indicator
|
|
26
|
+
- Error: data-fetching components handle errors
|
|
27
|
+
- Empty: lists/tables handle zero items helpfully
|
|
28
|
+
- Responsive: no fixed px widths, breakpoints handled
|
|
29
|
+
- A11y: alt text, ARIA, keyboard nav
|
|
30
|
+
|
|
31
|
+
2. **Design Alignment**
|
|
32
|
+
- Components vs DESIGN.md (colors, typography, spacing)
|
|
33
|
+
- rules/frontend.md compliance: distinctive fonts? sharp accents? transitions? No card grids / gradients?
|
|
34
|
+
- Consistency across app (buttons, spacing, colors)
|
|
35
|
+
|
|
36
|
+
3. **Frontend Perf**
|
|
37
|
+
- Bundle: large imports -> tree-shake or dynamic import
|
|
38
|
+
- Images: next/image? width/height? lazy below fold?
|
|
39
|
+
- Fonts: next/font? No render-blocking?
|
|
40
|
+
- CSS: unused Tailwind? conflicts?
|
|
41
|
+
- Rendering: unnecessary re-renders, missing memo, heavy computations
|
|
42
|
+
|
|
43
|
+
Per finding: What / Where (file:line) / Why (impact) / Fix / Severity (CRITICAL|HIGH|MEDIUM|LOW)
|
|
44
|
+
</task>",
|
|
45
|
+
subagent_type="general-purpose",
|
|
46
|
+
description="Frontend optimization analysis"
|
|
47
|
+
)
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Backend agent prompt
|
|
51
|
+
|
|
52
|
+
```
|
|
53
|
+
Agent(
|
|
54
|
+
prompt="Optimize backend. Analyze planning docs + security rules, then code.
|
|
55
|
+
|
|
56
|
+
<planning>
|
|
57
|
+
{PROJECT.md content}
|
|
58
|
+
{REQUIREMENTS.md content}
|
|
59
|
+
</planning>
|
|
60
|
+
|
|
61
|
+
<rules>
|
|
62
|
+
{rules/security.md content}
|
|
63
|
+
</rules>
|
|
64
|
+
|
|
65
|
+
<task>
|
|
66
|
+
Analyze backend:
|
|
67
|
+
|
|
68
|
+
1. **Security**
|
|
69
|
+
- RLS: every table needs RLS + policies
|
|
70
|
+
- Service role: grep client code (app/, components/, src/) for service_role -> must be ZERO
|
|
71
|
+
- Auth: mutations use server-side auth (supabase.auth.getUser())
|
|
72
|
+
- Validation: Zod before DB ops
|
|
73
|
+
- No dangerouslySetInnerHTML / eval()
|
|
74
|
+
|
|
75
|
+
2. **Data Access**
|
|
76
|
+
- Writes via 'use server' actions, not direct client calls
|
|
77
|
+
- try/catch with meaningful errors
|
|
78
|
+
- revalidatePath/revalidateTag after mutations
|
|
79
|
+
|
|
80
|
+
3. **Edge Functions** (if supabase/functions/ exists)
|
|
81
|
+
- Cold start: bundle size, dep count
|
|
82
|
+
- Error handling + logging
|
|
83
|
+
- CORS config
|
|
84
|
+
- Timeout protection
|
|
85
|
+
|
|
86
|
+
4. **API Quality**
|
|
87
|
+
- Rate limiting on public endpoints
|
|
88
|
+
- Proper HTTP status codes
|
|
89
|
+
- Consistent error format
|
|
90
|
+
|
|
91
|
+
Per finding: What / Where (file:line) / Why (impact) / Fix / Severity (CRITICAL|HIGH|MEDIUM|LOW)
|
|
92
|
+
</task>",
|
|
93
|
+
subagent_type="general-purpose",
|
|
94
|
+
description="Backend optimization analysis"
|
|
95
|
+
)
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Performance oracle prompt
|
|
99
|
+
|
|
100
|
+
```
|
|
101
|
+
Agent(
|
|
102
|
+
prompt="Analyze cross-cutting perf issues.
|
|
103
|
+
|
|
104
|
+
<planning>
|
|
105
|
+
{PROJECT.md content}
|
|
106
|
+
</planning>
|
|
107
|
+
|
|
108
|
+
<task>
|
|
109
|
+
Full-stack perf analysis:
|
|
110
|
+
|
|
111
|
+
1. **DB Queries**
|
|
112
|
+
- N+1: .from() inside loops/.map()
|
|
113
|
+
- Missing indexes on .eq()/.filter()/.order() columns
|
|
114
|
+
- Sequential -> parallel (Promise.all)
|
|
115
|
+
- Over-fetching: SELECT * when specific columns suffice
|
|
116
|
+
|
|
117
|
+
2. **API Latency**
|
|
118
|
+
- Sequential client calls -> batch
|
|
119
|
+
- Missing caching (stale times, HTTP cache headers)
|
|
120
|
+
- Large payloads without pagination
|
|
121
|
+
|
|
122
|
+
3. **Bundle Size**
|
|
123
|
+
- Barrel exports blocking tree-shaking
|
|
124
|
+
- Large libs for single fns (lodash, moment)
|
|
125
|
+
- Missing dynamic imports for heavy components
|
|
126
|
+
|
|
127
|
+
4. **Render Perf**
|
|
128
|
+
- Expensive computations without useMemo
|
|
129
|
+
- Handlers recreated per render without useCallback
|
|
130
|
+
- Large lists without virtualization
|
|
131
|
+
- Context providers causing unnecessary re-renders
|
|
132
|
+
|
|
133
|
+
Per finding: What / Where (file:line) / Why (impact, quantified) / Fix / Severity (CRITICAL|HIGH|MEDIUM|LOW)
|
|
134
|
+
</task>",
|
|
135
|
+
subagent_type="general-purpose",
|
|
136
|
+
description="Performance optimization analysis"
|
|
137
|
+
)
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## Architecture strategist prompt (deepening lens)
|
|
141
|
+
|
|
142
|
+
`full`: after Wave 1 (synthesizes + deepens). `deepen`: sole agent (no Wave 1).
|
|
143
|
+
|
|
144
|
+
```
|
|
145
|
+
Agent(
|
|
146
|
+
prompt="Arch strategist: Ousterhout deepening lens + cross-cutting issues. Use domain language from CONTEXT.md.
|
|
147
|
+
|
|
148
|
+
<wave1_findings>
|
|
149
|
+
{Wave 1 findings; empty in --deepen mode}
|
|
150
|
+
</wave1_findings>
|
|
151
|
+
|
|
152
|
+
<planning>
|
|
153
|
+
{PROJECT.md content}
|
|
154
|
+
{REQUIREMENTS.md content}
|
|
155
|
+
{CONTEXT.md content (domain glossary)}
|
|
156
|
+
{decisions/*.md content (ADRs constraining refactor space)}
|
|
157
|
+
</planning>
|
|
158
|
+
|
|
159
|
+
<vocabulary>
|
|
160
|
+
- **Module**: construct with interface + impl (fn, class, package, slice)
|
|
161
|
+
- **Interface**: everything caller must know (types, invariants, error modes, ordering, config)
|
|
162
|
+
- **Depth**: leverage at interface. Deep = high leverage. Shallow = interface ~ impl.
|
|
163
|
+
- **Seam**: where interface lives; alterable without in-place editing.
|
|
164
|
+
- **Locality**: change, bug, knowledge concentrated in one location.
|
|
165
|
+
- **Deletion test**: deleting module makes complexity vanish across N callers -> earning keep.
|
|
166
|
+
</vocabulary>
|
|
167
|
+
|
|
168
|
+
<task>
|
|
169
|
+
TWO sections:
|
|
170
|
+
|
|
171
|
+
A) **Cross-cutting** (skip in --deepen):
|
|
172
|
+
1. Recurring Wave 1 patterns -> structural problem
|
|
173
|
+
2. Frontend-backend coupling
|
|
174
|
+
3. Inconsistent patterns (server actions vs API routes)
|
|
175
|
+
4. Missing abstractions (pattern repeated 3+ times)
|
|
176
|
+
5. Dead code / unused exports
|
|
177
|
+
|
|
178
|
+
B) **Deepening candidates** (always):
|
|
179
|
+
Per candidate:
|
|
180
|
+
- **Files**: file:line ranges
|
|
181
|
+
- **Problem**: what's shallow, what leaks
|
|
182
|
+
- **Solution**: new interface, what gets hidden
|
|
183
|
+
- **Benefits**: locality, leverage, testability
|
|
184
|
+
- **Deletion test**: deleting X -> N callers no longer need what?
|
|
185
|
+
- **Domain terms**: CONTEXT.md terms touched or surfaced
|
|
186
|
+
- **Severity**: CRITICAL | HIGH | MEDIUM | LOW
|
|
187
|
+
|
|
188
|
+
Look for:
|
|
189
|
+
- Shallow wrappers (interface ~ impl)
|
|
190
|
+
- Pure fns extracted for testability only (no locality)
|
|
191
|
+
- Concept-bouncing (1 concept -> 5+ files)
|
|
192
|
+
- Cross-seam coupling (private detail leaking)
|
|
193
|
+
- Untested/untestable sections (bad seams)
|
|
194
|
+
|
|
195
|
+
REFUSE: 'extract helper fn' failing deletion test. More shallow modules = disease.
|
|
196
|
+
|
|
197
|
+
Format: What/Where/Why/Fix/Severity.
|
|
198
|
+
</task>",
|
|
199
|
+
subagent_type="general-purpose",
|
|
200
|
+
description="Architecture synthesis + deepening"
|
|
201
|
+
)
|
|
202
|
+
```
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: qualia-optimize
|
|
3
|
-
description: "Deep optimization pass — reads .planning/ AND codebase to find performance, design, UI, backend,
|
|
3
|
+
description: "Deep optimization pass — reads .planning/ AND codebase to find performance, design, UI, backend, frontend, AND architecture-deepening opportunities. Spawns parallel specialist agents. Use whenever the user says 'optimize', 'optimization pass', 'find issues', 'qualia-optimize', 'deep optimize', 'performance audit', 'design alignment check', 'speed up', 'slow', 'bundle size', 'refactor architecture', 'shallow modules', 'simplify', or wants a comprehensive quality sweep. Supports --perf, --ui, --backend, --alignment, --deepen, --fix flags."
|
|
4
4
|
allowed-tools:
|
|
5
5
|
- Bash
|
|
6
6
|
- Read
|
|
@@ -13,30 +13,35 @@ allowed-tools:
|
|
|
13
13
|
|
|
14
14
|
# Qualia Optimize — Deep Codebase + Planning Optimization
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
## Reference templates
|
|
17
|
+
|
|
18
|
+
Detailed agent-prompt templates live in `REFERENCE.md` (in this same skill folder). When a step below says "see REFERENCE.md section X", read that section before generating the spawn.
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
Reads `.planning/` docs AND codebase. Never analyze one without the other.
|
|
17
23
|
|
|
18
24
|
## Usage
|
|
19
25
|
|
|
20
|
-
- `/qualia-optimize` — Full
|
|
26
|
+
- `/qualia-optimize` — Full (all 7 dimensions + architecture deepening)
|
|
21
27
|
- `/qualia-optimize --perf` — Performance only (queries, bundle, render, latency)
|
|
22
28
|
- `/qualia-optimize --ui` — Frontend/design/UI only
|
|
23
|
-
- `/qualia-optimize --backend` — Backend only (RLS, auth, queries, edge
|
|
24
|
-
- `/qualia-optimize --alignment` — Planning-code alignment
|
|
25
|
-
- `/qualia-optimize --
|
|
29
|
+
- `/qualia-optimize --backend` — Backend only (RLS, auth, queries, edge fns)
|
|
30
|
+
- `/qualia-optimize --alignment` — Planning-code alignment only
|
|
31
|
+
- `/qualia-optimize --deepen` — Architecture deepening only (Ousterhout: shallow modules, deeper interfaces)
|
|
32
|
+
- `/qualia-optimize --fix` — Auto-fix LOW/MEDIUM from existing OPTIMIZE.md
|
|
26
33
|
|
|
27
34
|
## Process
|
|
28
35
|
|
|
29
36
|
### Step 1: Parse Arguments
|
|
30
37
|
|
|
31
|
-
|
|
38
|
+
Mode from $ARGUMENTS. Default: `full`.
|
|
39
|
+
Modes: `full`, `perf`, `ui`, `backend`, `alignment`, `deepen`, `fix`.
|
|
40
|
+
`--fix` skips to Step 9 (requires `.planning/OPTIMIZE.md`).
|
|
32
41
|
|
|
33
|
-
|
|
42
|
+
### Step 2: Load Planning Context (MANDATORY)
|
|
34
43
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
### Step 2: Load Planning Context (MANDATORY — never skip)
|
|
38
|
-
|
|
39
|
-
Read ALL of these (skip silently if file doesn't exist, but always attempt):
|
|
44
|
+
Read all (skip silently if missing):
|
|
40
45
|
|
|
41
46
|
```bash
|
|
42
47
|
cat .planning/PROJECT.md 2>/dev/null || echo "NO_PROJECT"
|
|
@@ -58,15 +63,23 @@ cat .planning/STATE.md 2>/dev/null || echo "NO_STATE"
|
|
|
58
63
|
cat .planning/DESIGN.md 2>/dev/null || echo "NO_DESIGN"
|
|
59
64
|
```
|
|
60
65
|
|
|
61
|
-
|
|
66
|
+
```bash
|
|
67
|
+
cat .planning/CONTEXT.md 2>/dev/null || echo "NO_CONTEXT"
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
ls .planning/decisions/ 2>/dev/null && cat .planning/decisions/*.md 2>/dev/null || echo "NO_ADRS"
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Also read rules:
|
|
62
75
|
```bash
|
|
63
76
|
cat ~/.claude/rules/frontend.md 2>/dev/null
|
|
64
77
|
cat ~/.claude/rules/security.md 2>/dev/null
|
|
65
78
|
```
|
|
66
79
|
|
|
67
|
-
Store all
|
|
80
|
+
Store all; inline into agent prompts.
|
|
68
81
|
|
|
69
|
-
**
|
|
82
|
+
**No planning docs:** warn, proceed. Can optimize raw codebase; can't check alignment.
|
|
70
83
|
|
|
71
84
|
### Step 3: Discover Codebase
|
|
72
85
|
|
|
@@ -87,224 +100,49 @@ git diff --stat HEAD~10..HEAD 2>/dev/null | tail -5
|
|
|
87
100
|
ls -d app/ src/ pages/ components/ lib/ actions/ hooks/ supabase/ types/ 2>/dev/null
|
|
88
101
|
```
|
|
89
102
|
|
|
90
|
-
Classify
|
|
103
|
+
Classify: `web` | `voice` | `mobile` | `agent` | `edge-functions` | `unknown`
|
|
91
104
|
|
|
92
105
|
### Step 4: Spawn Wave 1 Agents (parallel)
|
|
93
106
|
|
|
94
|
-
|
|
107
|
+
Spawn in **single message** with multiple Agent() calls per mode:
|
|
95
108
|
|
|
96
109
|
| Mode | Agents |
|
|
97
110
|
|------|--------|
|
|
98
|
-
| `full` | frontend
|
|
99
|
-
| `perf` |
|
|
100
|
-
| `ui` | frontend
|
|
101
|
-
| `backend` | backend
|
|
102
|
-
| `alignment` |
|
|
103
|
-
|
|
104
|
-
**CRITICAL**: Inline ALL planning context into each agent prompt. `@` references don't work across Agent() boundaries.
|
|
105
|
-
|
|
106
|
-
#### Frontend Agent Prompt
|
|
111
|
+
| `full` | frontend + backend + perf-oracle (3 parallel), then arch-strategist (Wave 2) |
|
|
112
|
+
| `perf` | perf-oracle only |
|
|
113
|
+
| `ui` | frontend only |
|
|
114
|
+
| `backend` | backend only |
|
|
115
|
+
| `alignment` | alignment prompt only |
|
|
116
|
+
| `deepen` | arch-strategist only (skip Wave 1) |
|
|
107
117
|
|
|
108
|
-
|
|
109
|
-
Agent(
|
|
110
|
-
prompt="You are optimizing a project's frontend. Read the planning docs and codebase rules below, then analyze the actual code.
|
|
111
|
-
|
|
112
|
-
<planning>
|
|
113
|
-
{PROJECT.md content}
|
|
114
|
-
{REQUIREMENTS.md content}
|
|
115
|
-
{DESIGN.md content}
|
|
116
|
-
</planning>
|
|
117
|
-
|
|
118
|
-
<rules>
|
|
119
|
-
{rules/frontend.md content}
|
|
120
|
-
</rules>
|
|
121
|
-
|
|
122
|
-
<task>
|
|
123
|
-
Analyze the frontend codebase for issues in these categories:
|
|
124
|
-
|
|
125
|
-
1. **UI Quality**
|
|
126
|
-
- Loading states: every async operation should show a loading indicator
|
|
127
|
-
- Error states: every data-fetching component should handle errors gracefully
|
|
128
|
-
- Empty states: lists/tables should handle zero items with helpful messaging
|
|
129
|
-
- Responsive: check for fixed pixel widths on containers, missing breakpoint handling
|
|
130
|
-
- Accessibility: alt text on images, ARIA labels on interactive elements, keyboard navigation
|
|
131
|
-
|
|
132
|
-
2. **Design Alignment**
|
|
133
|
-
- Compare actual components against DESIGN.md decisions (colors, typography, spacing)
|
|
134
|
-
- Check rules/frontend.md compliance: distinctive fonts? sharp accents? transitions? No card grids or blue-purple gradients?
|
|
135
|
-
- Consistency: are the same patterns used throughout? (button styles, spacing, color usage)
|
|
136
|
-
|
|
137
|
-
3. **Frontend Performance**
|
|
138
|
-
- Bundle: large library imports that could be tree-shaken or dynamically imported
|
|
139
|
-
- Images: using next/image? width/height set? lazy loading below fold?
|
|
140
|
-
- Fonts: using next/font? No render-blocking font loads?
|
|
141
|
-
- CSS: unused Tailwind classes? conflicting styles?
|
|
142
|
-
- Rendering: unnecessary re-renders, missing React.memo on list items, heavy computations in render
|
|
143
|
-
|
|
144
|
-
For EVERY finding, output in this exact format:
|
|
145
|
-
- **What**: [description]
|
|
146
|
-
- **Where**: [file:line]
|
|
147
|
-
- **Why**: [impact on users/performance]
|
|
148
|
-
- **Fix**: [concrete fix suggestion]
|
|
149
|
-
- **Severity**: CRITICAL | HIGH | MEDIUM | LOW
|
|
150
|
-
</task>",
|
|
151
|
-
subagent_type="general-purpose",
|
|
152
|
-
description="Frontend optimization analysis"
|
|
153
|
-
)
|
|
154
|
-
```
|
|
155
|
-
|
|
156
|
-
#### Backend Agent Prompt
|
|
157
|
-
|
|
158
|
-
```
|
|
159
|
-
Agent(
|
|
160
|
-
prompt="You are optimizing a project's backend. Read the planning docs and security rules below, then analyze the actual code.
|
|
161
|
-
|
|
162
|
-
<planning>
|
|
163
|
-
{PROJECT.md content}
|
|
164
|
-
{REQUIREMENTS.md content}
|
|
165
|
-
</planning>
|
|
166
|
-
|
|
167
|
-
<rules>
|
|
168
|
-
{rules/security.md content}
|
|
169
|
-
</rules>
|
|
170
|
-
|
|
171
|
-
<task>
|
|
172
|
-
Analyze the backend codebase for issues:
|
|
173
|
-
|
|
174
|
-
1. **Security**
|
|
175
|
-
- RLS: every Supabase table must have ROW LEVEL SECURITY enabled with policies
|
|
176
|
-
- Service role: grep for service_role key usage in client-side code (app/, components/, src/) — should be ZERO
|
|
177
|
-
- Auth: all mutations use server-side auth check (supabase.auth.getUser())
|
|
178
|
-
- Validation: input validated with Zod before database operations
|
|
179
|
-
- No dangerouslySetInnerHTML or eval()
|
|
180
|
-
|
|
181
|
-
2. **Data Access Patterns**
|
|
182
|
-
- Server actions vs client mutations: data writes should use 'use server' actions, not direct Supabase client calls
|
|
183
|
-
- Proper error handling: try/catch with meaningful error messages
|
|
184
|
-
- Revalidation: revalidatePath/revalidateTag after mutations
|
|
185
|
-
|
|
186
|
-
3. **Edge Functions** (if supabase/functions/ exists)
|
|
187
|
-
- Cold start optimization: bundle size, dependency count
|
|
188
|
-
- Error handling and logging
|
|
189
|
-
- CORS configuration
|
|
190
|
-
- Timeout protection (maxDuration)
|
|
191
|
-
|
|
192
|
-
4. **API Quality**
|
|
193
|
-
- Rate limiting on public endpoints
|
|
194
|
-
- Proper HTTP status codes
|
|
195
|
-
- Consistent error response format
|
|
196
|
-
|
|
197
|
-
For EVERY finding, output:
|
|
198
|
-
- **What**: [description]
|
|
199
|
-
- **Where**: [file:line]
|
|
200
|
-
- **Why**: [impact]
|
|
201
|
-
- **Fix**: [concrete suggestion]
|
|
202
|
-
- **Severity**: CRITICAL | HIGH | MEDIUM | LOW
|
|
203
|
-
</task>",
|
|
204
|
-
subagent_type="general-purpose",
|
|
205
|
-
description="Backend optimization analysis"
|
|
206
|
-
)
|
|
207
|
-
```
|
|
208
|
-
|
|
209
|
-
#### Performance Oracle Prompt
|
|
118
|
+
**CRITICAL**: Inline ALL planning context into each prompt. `@` refs don't work across Agent() boundaries.
|
|
210
119
|
|
|
211
|
-
|
|
212
|
-
Agent(
|
|
213
|
-
prompt="You are analyzing cross-cutting performance issues. Read the project context, then analyze the codebase.
|
|
214
|
-
|
|
215
|
-
<planning>
|
|
216
|
-
{PROJECT.md content}
|
|
217
|
-
</planning>
|
|
218
|
-
|
|
219
|
-
<task>
|
|
220
|
-
Analyze for performance issues across the full stack:
|
|
221
|
-
|
|
222
|
-
1. **Database Queries**
|
|
223
|
-
- N+1 queries: Supabase .from() calls inside loops or .map()
|
|
224
|
-
- Missing indexes: .eq()/.filter()/.order() columns without corresponding indexes in migrations
|
|
225
|
-
- Sequential queries that could be parallel (Promise.all)
|
|
226
|
-
- Over-fetching: SELECT * when only specific columns needed
|
|
227
|
-
|
|
228
|
-
2. **API Latency**
|
|
229
|
-
- Sequential API calls from client that could be batched
|
|
230
|
-
- Missing caching (SWR/React Query stale times, HTTP cache headers)
|
|
231
|
-
- Large payloads without pagination
|
|
232
|
-
|
|
233
|
-
3. **Bundle Size**
|
|
234
|
-
- Barrel exports (index.ts re-exporting everything) preventing tree-shaking
|
|
235
|
-
- Large libraries imported for single functions (lodash, moment)
|
|
236
|
-
- Missing dynamic imports for heavy components (charts, editors, maps)
|
|
237
|
-
|
|
238
|
-
4. **Render Performance**
|
|
239
|
-
- Expensive computations in render path without useMemo
|
|
240
|
-
- Event handlers recreated on every render without useCallback
|
|
241
|
-
- Large lists without virtualization
|
|
242
|
-
- Context providers causing unnecessary re-renders
|
|
243
|
-
|
|
244
|
-
For EVERY finding, output:
|
|
245
|
-
- **What**: [description]
|
|
246
|
-
- **Where**: [file:line]
|
|
247
|
-
- **Why**: [performance impact, quantified if possible]
|
|
248
|
-
- **Fix**: [concrete suggestion]
|
|
249
|
-
- **Severity**: CRITICAL | HIGH | MEDIUM | LOW
|
|
250
|
-
</task>",
|
|
251
|
-
subagent_type="general-purpose",
|
|
252
|
-
description="Performance optimization analysis"
|
|
253
|
-
)
|
|
254
|
-
```
|
|
120
|
+
Spawn parallel: **frontend** (@REFERENCE.md "Frontend agent prompt"), **backend** (@REFERENCE.md "Backend agent prompt"), **perf oracle** (@REFERENCE.md "Performance oracle prompt").
|
|
255
121
|
|
|
256
|
-
### Step 5:
|
|
122
|
+
### Step 5: Wave 2 -- Architecture Strategist
|
|
257
123
|
|
|
258
|
-
|
|
124
|
+
`full`: after Wave 1 (synthesizes + deepens). `deepen`: sole agent (no Wave 1).
|
|
259
125
|
|
|
260
|
-
|
|
261
|
-
Agent(
|
|
262
|
-
prompt="You are synthesizing optimization findings from 3 specialist agents. Look for cross-cutting architectural issues.
|
|
263
|
-
|
|
264
|
-
<wave1_findings>
|
|
265
|
-
{All findings from frontend-agent, backend-agent, performance-oracle}
|
|
266
|
-
</wave1_findings>
|
|
267
|
-
|
|
268
|
-
<planning>
|
|
269
|
-
{PROJECT.md content}
|
|
270
|
-
{REQUIREMENTS.md content}
|
|
271
|
-
</planning>
|
|
272
|
-
|
|
273
|
-
<task>
|
|
274
|
-
1. Identify patterns across findings — recurring issues that point to a structural problem
|
|
275
|
-
2. Find coupling issues between frontend and backend
|
|
276
|
-
3. Check for inconsistent patterns (e.g., some routes use server actions, others use API routes)
|
|
277
|
-
4. Identify missing abstractions (same pattern repeated 3+ times)
|
|
278
|
-
5. Check for dead code and unused exports
|
|
279
|
-
|
|
280
|
-
Output:
|
|
281
|
-
- **Structural findings** (architectural issues, not covered by Wave 1)
|
|
282
|
-
- **Pattern consolidation** (where Wave 1 findings share a root cause)
|
|
283
|
-
- Each finding in the same format: What/Where/Why/Fix/Severity
|
|
284
|
-
</task>",
|
|
285
|
-
subagent_type="general-purpose",
|
|
286
|
-
description="Architecture synthesis"
|
|
287
|
-
)
|
|
288
|
-
```
|
|
126
|
+
Spawn **arch strategist** (@REFERENCE.md "Architecture strategist prompt (deepening lens)").
|
|
289
127
|
|
|
290
|
-
**Skip Wave 2 for single-mode
|
|
128
|
+
**Skip Wave 2 for single-mode** (`--perf`, `--ui`, `--backend`, `--alignment`). Run for `full` and `deepen`.
|
|
291
129
|
|
|
292
|
-
### Step 6: Alignment Check (
|
|
130
|
+
### Step 6: Alignment Check (`full` and `alignment` modes)
|
|
293
131
|
|
|
294
|
-
|
|
132
|
+
`alignment`: sole analysis. `full`: alongside Wave 1.
|
|
295
133
|
|
|
296
|
-
Read REQUIREMENTS.md
|
|
134
|
+
Read REQUIREMENTS.md + ROADMAP.md. Per req marked "Complete" or mapped to completed phase:
|
|
297
135
|
|
|
298
136
|
```bash
|
|
299
137
|
# Find completed requirements
|
|
300
138
|
grep -E "Complete|✓" .planning/REQUIREMENTS.md 2>/dev/null
|
|
301
139
|
```
|
|
302
140
|
|
|
303
|
-
|
|
304
|
-
- Grep
|
|
305
|
-
-
|
|
141
|
+
Per completed req:
|
|
142
|
+
- Grep for evidence (routes, components, endpoints)
|
|
143
|
+
- Not found: flag "Claimed complete but not implemented"
|
|
306
144
|
|
|
307
|
-
|
|
145
|
+
Orphan scan:
|
|
308
146
|
```bash
|
|
309
147
|
# Find all routes/pages
|
|
310
148
|
find app -name "page.tsx" -o -name "route.ts" 2>/dev/null
|
|
@@ -312,16 +150,15 @@ find app -name "page.tsx" -o -name "route.ts" 2>/dev/null
|
|
|
312
150
|
find app/api -name "route.ts" 2>/dev/null
|
|
313
151
|
```
|
|
314
152
|
|
|
315
|
-
Cross-
|
|
153
|
+
Cross-ref with REQUIREMENTS.md; route NOT in reqs: "Undocumented feature".
|
|
316
154
|
|
|
317
|
-
### Step 7: Collect and Score
|
|
155
|
+
### Step 7: Collect and Score
|
|
318
156
|
|
|
319
|
-
|
|
320
|
-
1. Deduplicate (same file:line
|
|
321
|
-
2. Sort
|
|
322
|
-
3. Group by dimension:
|
|
323
|
-
|
|
324
|
-
Count totals per severity.
|
|
157
|
+
All agents done:
|
|
158
|
+
1. Deduplicate (same file:line, keep most detailed)
|
|
159
|
+
2. Sort: CRITICAL first
|
|
160
|
+
3. Group by dimension: Perf, Design, UI, Backend, Frontend, Alignment, Architecture
|
|
161
|
+
4. Count per severity.
|
|
325
162
|
|
|
326
163
|
### Step 8: Write OPTIMIZE.md and Present Results
|
|
327
164
|
|
|
@@ -399,27 +236,25 @@ Run /qualia-optimize --fix to auto-fix LOW/MEDIUM findings.
|
|
|
399
236
|
|
|
400
237
|
### Step 9: --fix Mode
|
|
401
238
|
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
1. Read existing `.planning/OPTIMIZE.md` — if not found, error: "Run /qualia-optimize first"
|
|
405
|
-
2. Filter to LOW and MEDIUM findings only
|
|
406
|
-
3. For each finding with a clear, safe fix:
|
|
407
|
-
- Read the target file
|
|
408
|
-
- Apply the fix
|
|
409
|
-
- Verify it doesn't break (npx tsc --noEmit if TypeScript)
|
|
410
|
-
4. Update OPTIMIZE.md: mark fixed findings, recount severities
|
|
411
|
-
5. Commit changes
|
|
412
|
-
6. Report what was fixed and what remains
|
|
239
|
+
`--fix` mode:
|
|
413
240
|
|
|
414
|
-
|
|
241
|
+
1. Read `.planning/OPTIMIZE.md`; missing: "Run /qualia-optimize first"
|
|
242
|
+
2. Filter to LOW + MEDIUM only
|
|
243
|
+
3. Per finding with clear, safe fix:
|
|
244
|
+
- Read target file
|
|
245
|
+
- Apply fix
|
|
246
|
+
- Verify (npx tsc --noEmit if TS)
|
|
247
|
+
4. Update OPTIMIZE.md: mark fixed, recount severities
|
|
248
|
+
5. Commit
|
|
249
|
+
6. Report fixed vs remaining
|
|
415
250
|
|
|
416
|
-
|
|
251
|
+
**Never auto-fix CRITICAL/HIGH.** Require human judgment.
|
|
417
252
|
|
|
418
|
-
|
|
253
|
+
### Step 10: Gap Phase Creation (user picks option 1)
|
|
419
254
|
|
|
420
|
-
1. Read ROADMAP.md, find current phase
|
|
421
|
-
2. Insert
|
|
422
|
-
3. Map CRITICAL
|
|
255
|
+
1. Read ROADMAP.md, find current phase
|
|
256
|
+
2. Insert `Phase {N}.1: Optimization Fixes (INSERTED)`
|
|
257
|
+
3. Map CRITICAL + HIGH findings as success criteria
|
|
423
258
|
4. Update STATE.md
|
|
424
259
|
5. Commit
|
|
425
260
|
6. Suggest: "Fix phase created. Run `/qualia-plan {N}.1`"
|