qualia-framework 4.1.1 → 4.4.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 (43) hide show
  1. package/README.md +15 -11
  2. package/agents/builder.md +28 -0
  3. package/agents/research-synthesizer.md +7 -0
  4. package/bin/agent-runs.js +233 -0
  5. package/bin/cli.js +355 -16
  6. package/bin/install.js +87 -6
  7. package/bin/knowledge-flush.js +164 -0
  8. package/bin/knowledge.js +317 -0
  9. package/bin/plan-contract.js +220 -0
  10. package/bin/state.js +15 -9
  11. package/docs/agent-runs.md +273 -0
  12. package/docs/journey-demo.html +1008 -0
  13. package/docs/plan-contract.md +321 -0
  14. package/docs/reviews/v4.1.0-audit.html +1488 -0
  15. package/docs/reviews/v4.1.0-audit.md +263 -0
  16. package/hooks/auto-update.js +3 -7
  17. package/hooks/git-guardrails.js +167 -0
  18. package/hooks/pre-compact.js +22 -11
  19. package/hooks/pre-deploy-gate.js +16 -2
  20. package/hooks/pre-push.js +22 -2
  21. package/hooks/stop-session-log.js +180 -0
  22. package/package.json +8 -2
  23. package/skills/qualia-build/SKILL.md +5 -5
  24. package/skills/qualia-debug/SKILL.md +1 -1
  25. package/skills/qualia-design/SKILL.md +15 -0
  26. package/skills/qualia-flush/SKILL.md +200 -0
  27. package/skills/qualia-learn/SKILL.md +47 -37
  28. package/skills/qualia-new/SKILL.md +1 -1
  29. package/skills/qualia-plan/SKILL.md +3 -2
  30. package/skills/qualia-postmortem/SKILL.md +238 -0
  31. package/skills/qualia-quick/SKILL.md +1 -1
  32. package/skills/qualia-report/SKILL.md +1 -1
  33. package/skills/qualia-review/SKILL.md +3 -2
  34. package/skills/qualia-ship/SKILL.md +12 -10
  35. package/skills/qualia-verify/SKILL.md +60 -0
  36. package/templates/help.html +13 -7
  37. package/templates/knowledge/agents.md +71 -0
  38. package/templates/knowledge/index.md +47 -0
  39. package/tests/bin.test.sh +322 -12
  40. package/tests/hooks.test.sh +131 -20
  41. package/tests/lib.test.sh +217 -0
  42. package/tests/runner.js +103 -77
  43. package/tests/state.test.sh +4 -3
@@ -0,0 +1,238 @@
1
+ ---
2
+ name: qualia-postmortem
3
+ description: "Self-healing AI layer — when /qualia-verify returns FAIL, identify which agent/rule/skill should have caught the failure and propose a delta to that file so the same class of bug never recurs. Trigger on 'postmortem', 'why did the framework miss this', 'self-heal', 'qualia-postmortem', or auto-invoked by /qualia-verify on FAIL with --auto."
4
+ allowed-tools:
5
+ - Bash
6
+ - Read
7
+ - Write
8
+ - Edit
9
+ - Grep
10
+ - Glob
11
+ ---
12
+
13
+ # /qualia-postmortem — Self-Healing AI Layer
14
+
15
+ When the verifier finds a gap, fixing the **code** alone is not enough.
16
+ The framework let the bug through — that means a rule, agent prompt,
17
+ plan-checker check, or skill instruction was insufficient. This skill
18
+ runs after a verify FAIL and asks: *which file in the AI layer should
19
+ have caught this, and what delta would catch the next one like it?*
20
+
21
+ This is Cole Medin's **pillar 5** from the parallel-worktrees playbook
22
+ (NotebookLM 2026-04-25): "anytime we encounter a bug in a pull request,
23
+ we don't just fix the bug and move on, we fix the underlying system that
24
+ allowed for the bug." Without this loop, the same class of bug ships in
25
+ PR-3, PR-7, PR-11 of every project.
26
+
27
+ ## When to run
28
+
29
+ - **Manually:** `/qualia-postmortem` after any verify FAIL where the gap
30
+ feels preventable — i.e. a rule could have flagged it, a builder
31
+ instruction could have steered around it, a plan-checker rule could
32
+ have rejected the plan that produced it.
33
+ - **Auto:** `/qualia-verify --auto` will invoke this skill on every FAIL
34
+ before the gap-closure loop fires. The postmortem write happens before
35
+ the user re-plans, so the next planner spawn benefits from the
36
+ updated AI layer immediately.
37
+
38
+ ## Inputs
39
+
40
+ - `--phase N` (default: current phase from STATE.md)
41
+ - `--apply` (optional) — apply the proposed delta to disk. Without
42
+ `--apply`, the skill writes `.planning/phase-{N}-postmortem.md` for
43
+ human review and stops there.
44
+ - `--report-only` (optional) — just emit the analysis, write nothing.
45
+
46
+ If invoked from `/qualia-verify --auto`, default to writing the
47
+ postmortem report but **not** applying — applying touches the AI layer
48
+ itself, which is high-stakes. The user reviews and types `/qualia-learn`
49
+ or applies manually.
50
+
51
+ ## Process
52
+
53
+ ### 1. Load the failure
54
+
55
+ ```bash
56
+ node ~/.claude/bin/qualia-ui.js banner postmortem 2>/dev/null || true
57
+
58
+ PHASE="${PHASE:-$(node ~/.claude/bin/state.js check 2>/dev/null | node -e 'let s=""; process.stdin.on("data",d=>s+=d).on("end",()=>{try{console.log(JSON.parse(s).phase)}catch{console.log("")}})')}"
59
+ [ -z "$PHASE" ] && { echo "QUALIA: Could not resolve current phase. Pass --phase N explicitly."; exit 1; }
60
+
61
+ VERIFY_FILE=".planning/phase-${PHASE}-verification.md"
62
+ PLAN_FILE=".planning/phase-${PHASE}-plan.md"
63
+
64
+ [ -f "$VERIFY_FILE" ] || { echo "QUALIA: $VERIFY_FILE missing — nothing to post-mortem."; exit 1; }
65
+ [ -f "$PLAN_FILE" ] || echo "QUALIA: $PLAN_FILE missing — analysis will be partial."
66
+ ```
67
+
68
+ Read both files. The verification report tells you *what failed*. The
69
+ plan tells you *what was supposed to happen*. The gap between them is
70
+ where the AI layer fell short.
71
+
72
+ ### 2. Read the AI layer
73
+
74
+ The framework's prompts live in three places. Load all three so you can
75
+ match a finding to the file most likely responsible:
76
+
77
+ ```bash
78
+ # Agent prompts (planner, builder, plan-checker, verifier, etc.)
79
+ ls ~/.claude/agents/
80
+ # Skill descriptions (qualia-plan, qualia-build, qualia-verify, etc.)
81
+ ls ~/.claude/skills/
82
+ # Project rules + grounding
83
+ ls ~/.claude/rules/
84
+ # Already-curated knowledge
85
+ node ~/.claude/bin/knowledge.js
86
+ ```
87
+
88
+ You don't read all of them — you read the ones whose job description
89
+ matches the failure. Use this lookup:
90
+
91
+ | Failure shape | Likely AI-layer owner |
92
+ |---|---|
93
+ | Builder produced a stub / placeholder | `agents/builder.md` (Read Before Write, no-stub rule) |
94
+ | Plan listed Validation: `test -f file.ts` only — missed behavior check | `agents/plan-checker.md` (Rule 8: at least one grep-match or command-exit per task) |
95
+ | Wave 2 task ran before wave 1 committed | `agents/planner.md` (dependency graph) |
96
+ | Build passed locally, broke in CI | `rules/deployment.md` or a missing pre-deploy-gate scan |
97
+ | RLS missing on new table | `rules/security.md` + `agents/builder.md` (security persona handling) |
98
+ | Design regression — fonts off, contrast fail | `rules/frontend.md` + `skills/qualia-design/SKILL.md` |
99
+ | Migration unsafe (DROP without IF EXISTS, etc.) | `hooks/migration-guard.js` |
100
+ | Verifier missed it | `agents/verifier.md` — most embarrassing case, address with extra care |
101
+
102
+ ### 3. Diagnose
103
+
104
+ For **each** gap in the verification report (process them one at a time
105
+ when there are multiple), produce a four-field analysis:
106
+
107
+ ```markdown
108
+ ## Gap: {gap title from verification report}
109
+
110
+ **Severity:** {CRITICAL | HIGH | MEDIUM | LOW} (from verifier's rubric)
111
+ **Owner file:** `agents/builder.md` (or rules/X.md, skills/Y/SKILL.md, etc.)
112
+ **Why it slipped:**
113
+ Quote the relevant section of the owner file. Show the gap. The owner
114
+ file SHOULD have prevented this — either the rule wasn't there, or it
115
+ was there but not enforceable, or a rule was there but the agent was
116
+ free to ignore it.
117
+
118
+ **Proposed delta:**
119
+ Concrete diff for the owner file. New line, edited section, or rule
120
+ addition. Keep it minimal — one new sentence is better than a new
121
+ paragraph. The goal is "the next planner/builder spawn catches this
122
+ class of bug."
123
+ ```
124
+
125
+ ### 4. Write the postmortem report
126
+
127
+ ```bash
128
+ cat > .planning/phase-${PHASE}-postmortem.md <<'EOF'
129
+ # Phase {N} Postmortem
130
+
131
+ **Phase:** {N}
132
+ **Verify result:** FAIL ({gap_count} gaps)
133
+ **Date:** {ISO date}
134
+ **Run ID:** {short uid}
135
+
136
+ ## Findings
137
+
138
+ {one ## Gap section per gap, format from step 3}
139
+
140
+ ## Cumulative AI-layer drift
141
+
142
+ {If multiple postmortems exist for this project, group recurring owner
143
+ files: "agents/builder.md has been flagged 3 times this milestone — its
144
+ no-stub rule may need reinforcement or wave-2 stubs need a hard hook."}
145
+
146
+ ## Apply?
147
+
148
+ To apply all proposed deltas:
149
+ /qualia-postmortem --apply --phase {N}
150
+
151
+ To save the recurring patterns to knowledge instead (recommended for
152
+ project-spanning lessons):
153
+ /qualia-learn (pick the relevant entries from this report)
154
+
155
+ EOF
156
+ ```
157
+
158
+ ### 5. (Optional) Apply
159
+
160
+ If invoked with `--apply`, walk each "Proposed delta" and use the Edit
161
+ tool to make the literal change to the owner file. After every edit, run
162
+ the framework's own type/test gates (`node --test tests/runner.js` if you
163
+ modified anything in `bin/`, `agents/`, or `rules/`) to confirm no
164
+ regression.
165
+
166
+ If a proposed delta is to a `~/.claude/agents/X.md` file (the installed
167
+ copy), edit that copy directly — the user re-running the installer will
168
+ overwrite it next release, so also flag a TODO in the postmortem report
169
+ saying "this delta should be PR'd back to the framework repo at
170
+ `agents/X.md`" so it survives reinstall.
171
+
172
+ ### 6. Promote durable lessons to the knowledge layer
173
+
174
+ For lessons that apply across projects (e.g. "Supabase RLS must be in
175
+ the same migration as the table — applying it later creates a window
176
+ where data is unprotected"), append to the curated tier so future
177
+ builders pick it up:
178
+
179
+ ```bash
180
+ node ~/.claude/bin/knowledge.js append \
181
+ --type pattern \
182
+ --title "{lesson title}" \
183
+ --body "{lesson body}" \
184
+ --project "{project name from .planning/PROJECT.md or 'general' if cross-project}" \
185
+ --context "Postmortem from phase ${PHASE}, verify FAIL on {date}"
186
+ ```
187
+
188
+ ### 7. Summarize
189
+
190
+ ```
191
+ ⬢ Postmortem complete — phase {N}
192
+ {G} gaps analyzed
193
+ Owner files implicated:
194
+ - agents/builder.md (gap 1, gap 3)
195
+ - rules/security.md (gap 2)
196
+ Report: .planning/phase-${PHASE}-postmortem.md
197
+ {if --apply: deltas applied; framework reinstall TODO'd}
198
+ {if no --apply: review and run --apply OR /qualia-learn the patterns}
199
+ ```
200
+
201
+ ## Style
202
+
203
+ - **Be charitable.** The framework didn't fail because someone was
204
+ careless. It failed because a contract wasn't tight enough. Frame
205
+ every finding as "the contract was X; it should have been Y."
206
+ - **Keep deltas surgical.** A 2-line addition to a rule is durable; a
207
+ paragraph rewrite is brittle. Smaller deltas survive future framework
208
+ updates.
209
+ - **Don't reach.** If a gap genuinely doesn't map to an AI-layer file
210
+ (e.g. it's an external service outage), say so explicitly — don't
211
+ invent a rule to retroactively own it.
212
+ - **Rate limit yourself.** Don't propose more than 3 deltas per
213
+ postmortem. If there are 8 gaps, the top 3 by severity get deltas; the
214
+ rest get noted but not deltad. Otherwise the AI layer becomes a museum
215
+ of edge cases.
216
+
217
+ ## Anti-patterns
218
+
219
+ - **Re-fixing the same code as the verifier.** This skill is about the
220
+ AI layer, not the codebase. The gap-closure loop (`/qualia-plan
221
+ {N} --gaps`) handles the code. Postmortem only touches `agents/`,
222
+ `rules/`, `skills/`, and the knowledge layer.
223
+ - **Auto-applying deltas to `~/.claude/agents/X.md` without flagging a
224
+ framework PR TODO.** That edit lasts until the next reinstall. Always
225
+ note the TODO so the lesson reaches the framework repo.
226
+ - **Promoting every postmortem finding to knowledge.** Most are
227
+ project-specific contract tightening — they belong in the project's
228
+ AI-layer files, not in cross-project knowledge. Only generalizable
229
+ patterns get appended via `knowledge.js`.
230
+
231
+ ## Output contract
232
+
233
+ The skill writes `.planning/phase-{N}-postmortem.md` and either applies
234
+ deltas (with `--apply`) or stops with a summary that points the user at
235
+ the next step (`--apply` to apply, or `/qualia-learn` to promote
236
+ specific patterns). No follow-up prompts. Idempotent: re-running on the
237
+ same phase appends `### Re-run {timestamp}` to the existing report
238
+ rather than overwriting.
@@ -24,7 +24,7 @@ node ~/.claude/bin/qualia-ui.js banner quick
24
24
  2. **Build:** Do it directly — read before write, MVP only
25
25
  3. **Verify:** Run `npx tsc --noEmit`, test locally
26
26
  4. **Commit:** Atomic commit with clear message
27
- 5. **Update:** Update tracking.json notes field
27
+ 5. **Update:** Record the work through `state.js`
28
28
 
29
29
  End with:
30
30
  ```bash
@@ -134,7 +134,7 @@ SUBMITTED_AT=$(date -u +%Y-%m-%dT%H:%M:%SZ)
134
134
  # returns a generic 401 that is hard to diagnose.
135
135
  if [ "$ERP_ENABLED" = "true" ] && [ -z "$API_KEY" ] && [ "$DRY_RUN" != "true" ]; then
136
136
  node ~/.claude/bin/qualia-ui.js warn "ERP API key missing (~/.claude/.erp-api-key is empty or unreadable). Skipping upload."
137
- node ~/.claude/bin/qualia-ui.js info "Ask Fawzi for the ERP key, save to ~/.claude/.erp-api-key, then re-run /qualia-report --upload-only."
137
+ node ~/.claude/bin/qualia-ui.js info "Ask Fawzi for the ERP key, run 'qualia-framework set-erp-key <key>', then run 'qualia-framework erp-ping'."
138
138
  ERP_ENABLED="false"
139
139
  fi
140
140
 
@@ -29,8 +29,9 @@ node ~/.claude/bin/qualia-ui.js banner review
29
29
  ### 0. Load Context
30
30
 
31
31
  ```bash
32
- cat ~/.claude/knowledge/common-fixes.md 2>/dev/null
33
- cat ~/.claude/knowledge/learned-patterns.md 2>/dev/null
32
+ node ~/.claude/bin/knowledge.js
33
+ node ~/.claude/bin/knowledge.js load fixes
34
+ node ~/.claude/bin/knowledge.js load patterns
34
35
  ```
35
36
 
36
37
  Detect project shape:
@@ -37,13 +37,14 @@ VERIFICATION=$(echo "$STATE" | node -e "try{const d=JSON.parse(require('fs').rea
37
37
  # verified+pass — final phase verified; skipping polish is allowed for hotfixes
38
38
  # Anything else (setup, planned, built, shipped, handed_off, verified+fail) is refused.
39
39
  if [ "$STATUS" != "polished" ] && ! { [ "$STATUS" = "verified" ] && [ "$VERIFICATION" = "pass" ]; }; then
40
+ if [ "${QUALIA_SHIP_FORCE:-0}" = "1" ]; then
41
+ node ~/.claude/bin/qualia-ui.js warn "Forced ship from state '$STATUS' (verification: ${VERIFICATION:-none}). Record the reason in the final report."
42
+ else
40
43
  node ~/.claude/bin/qualia-ui.js fail "Cannot ship from state '$STATUS' (verification: ${VERIFICATION:-none})."
41
44
  node ~/.claude/bin/qualia-ui.js info "Run /qualia-polish first, or /qualia-verify {phase} if verification is still pending."
42
- node ~/.claude/bin/qualia-ui.js info "Override: add --force to the skill invocation (hotfix escape hatch, use with care)."
43
- # The --force escape hatch exists for production hotfixes where the polished
44
- # state was never reached. The operator is expected to have read and
45
- # understood the pending verification findings.
45
+ node ~/.claude/bin/qualia-ui.js info "Hotfix override: set QUALIA_SHIP_FORCE=1 only when the user explicitly approved it."
46
46
  exit 1
47
+ fi
47
48
  fi
48
49
  ```
49
50
 
@@ -53,7 +54,8 @@ Run in sequence. Auto-fix failures (up to 2 attempts).
53
54
 
54
55
  ```bash
55
56
  npx tsc --noEmit # TypeScript — must pass
56
- npx eslint . --max-warnings 0 # Lint auto-fix first
57
+ if node -e "const p=require('./package.json');process.exit(p.scripts&&p.scripts.lint?0:1)"; then npm run lint; fi
58
+ if node -e "const p=require('./package.json');process.exit(p.scripts&&p.scripts.test?0:1)"; then npm test; fi
57
59
  npm run build # Build — must succeed
58
60
  ```
59
61
 
@@ -130,15 +132,15 @@ wrangler deploy # Cloudflare Workers
130
132
 
131
133
  ### 5. Post-Deploy Verification
132
134
 
133
- Read the deployed URL from `tracking.json.deployed_url` — set by the deploy tool's output parser, or passed via `--url` to this skill. Do NOT use a `{domain}` placeholder — that expects the LLM to hallucinate the URL, which is exactly the kind of silent fail the state guard above prevents.
135
+ Read the deployed URL from `tracking.json.deployed_url` or from an explicit user-provided URL. Do NOT use a `{domain}` placeholder — that expects the LLM to hallucinate the URL, which is exactly the kind of silent fail the state guard above prevents.
134
136
 
135
137
  ```bash
136
- # Read URL from tracking.json (set by /qualia-handoff or previous ship), or
137
- # let the operator pass it as an argument. Never assume a placeholder.
138
- URL=$(node -e "try{const t=JSON.parse(require('fs').readFileSync('.planning/tracking.json','utf8'));process.stdout.write(t.deployed_url||'')}catch{}")
138
+ # If the user invoked `/qualia-ship --url ...`, set QUALIA_SHIP_URL to that
139
+ # exact value before running this block. Otherwise use tracking.json.
140
+ URL="${QUALIA_SHIP_URL:-$(node -e 'try{const t=JSON.parse(require("fs").readFileSync(".planning/tracking.json","utf8"));process.stdout.write(t.deployed_url||"")}catch{}')}"
139
141
  if [ -z "$URL" ]; then
140
142
  node ~/.claude/bin/qualia-ui.js warn "No deployed_url in tracking.json — parse it from the deploy command output (vercel/supabase/wrangler all print the URL on success)."
141
- node ~/.claude/bin/qualia-ui.js info "Re-run with: /qualia-ship --url https://your-site.com"
143
+ node ~/.claude/bin/qualia-ui.js info "Re-run with: /qualia-ship --url https://your-site.com, then export that value as QUALIA_SHIP_URL for this check."
142
144
  exit 1
143
145
  fi
144
146
 
@@ -19,6 +19,7 @@ Spawn a verifier agent to check if the phase goal was achieved. Does NOT trust b
19
19
  `/qualia-verify` — verify the current built phase
20
20
  `/qualia-verify {N}` — verify specific phase
21
21
  `/qualia-verify {N} --auto` — verify + auto-chain: PASS → next phase (or milestone close); FAIL → gap closure; gap limit → halt with escalation
22
+ `/qualia-verify {N} --adversarial` — run a SECOND verifier in fresh context with an adversarial prompt ("find what's wrong, not what's right"). Union the findings. Recommended for high-stakes phases (Handoff milestone, payment/auth/migration code) where a biased single-pass review would silently approve a bad change. v4.3.0+.
22
23
 
23
24
  ## Process
24
25
 
@@ -80,6 +81,52 @@ Drive the running dev server and test the routes this phase touched. Append a '#
80
81
 
81
82
  Wait for both the main verifier and the QA browser agent before moving to step 3. If Playwright MCP is unavailable, the QA browser agent returns BLOCKED — that's not a phase failure, just a note in the report.
82
83
 
84
+ ### 2c. Adversarial Second Opinion (--adversarial flag, optional)
85
+
86
+ When `--adversarial` is in the args, OR when the current milestone is
87
+ `Handoff` OR the phase plan touches files matching `auth|payment|migration|rls|service_role`, spawn a SECOND verifier in fresh context with an
88
+ adversarial prompt. This is the "kid-grading-their-own-homework"
89
+ mitigation — a single verifier instance trained on the same rubric the
90
+ planner+builder optimized against gets ~70% fewer real findings than a
91
+ fresh-context adversarial pass (Cole Medin, NotebookLM 2026-04-25, citing
92
+ PR-acceptance studies).
93
+
94
+ ```bash
95
+ node ~/.claude/bin/qualia-ui.js spawn verifier "Adversarial pass — find what's wrong"
96
+ ```
97
+
98
+ ```
99
+ Agent(prompt="
100
+ Read your role: @~/.claude/agents/verifier.md
101
+ Grounding + rubrics: @~/.claude/rules/grounding.md
102
+
103
+ You are an ADVERSARIAL reviewer. Your job is to find what's WRONG with
104
+ this phase, not to confirm it works. Assume the previous verifier missed
105
+ something. Use the same Severity Rubric, the same evidence-citation
106
+ requirement, but bias your search toward edge cases the cooperative
107
+ verifier would skip:
108
+ • What untested error path exists?
109
+ • What input would crash this?
110
+ • What concurrent access pattern is unhandled?
111
+ • What downstream consumer breaks if this contract changes?
112
+ • Where is a security assumption (auth, RLS, secrets) implicit
113
+ instead of enforced?
114
+
115
+ Project conventions: @.planning/PROJECT.md
116
+ Phase plan: @.planning/phase-{N}-plan.md
117
+ Cooperative verifier's report (do NOT re-find what they found, find
118
+ what they MISSED): @.planning/phase-{N}-verification.md
119
+
120
+ Append a '## Adversarial Findings' section to the verification file.
121
+ Empty section is fine if you genuinely found nothing — better that than
122
+ inventing findings to look productive.
123
+ ", subagent_type="qualia-verifier", description="Adversarial verify phase {N}")
124
+ ```
125
+
126
+ Findings from the adversarial pass merge into the main verification
127
+ report. The combined PASS/FAIL is the union: if either pass found a
128
+ CRITICAL or HIGH gap, the phase is FAIL.
129
+
83
130
  ### 3. Present Results
84
131
 
85
132
  Read the verification report. Present:
@@ -102,6 +149,19 @@ Then for each gap:
102
149
  node ~/.claude/bin/qualia-ui.js fail "{gap description}"
103
150
  ```
104
151
 
152
+ **Self-healing layer (v4.3.0+):** before re-planning the gaps, run a
153
+ postmortem so the framework itself learns from the miss. This is Cole
154
+ Medin's pillar 5: don't just fix the bug, fix the AI-layer file that
155
+ should have caught it. The postmortem writes a report to
156
+ `.planning/phase-{N}-postmortem.md` for review — it does NOT auto-apply
157
+ deltas to agents/rules unless the user runs `/qualia-postmortem --apply`
158
+ explicitly. Without this loop, the same class of bug ships in PR-3, PR-7,
159
+ PR-11 of the next project.
160
+
161
+ ```
162
+ /qualia-postmortem --phase {N}
163
+ ```
164
+
105
165
  End:
106
166
  ```bash
107
167
  node ~/.claude/bin/qualia-ui.js end "PHASE {N} GAPS FOUND" "/qualia-plan {N} --gaps"
@@ -297,7 +297,7 @@
297
297
  <div class="header-content">
298
298
  <h1><span>Qualia</span> Framework</h1>
299
299
  <p>Plan, build, verify, ship. The AI-powered workflow for Qualia Solutions.</p>
300
- <div class="version">{{VERSION}} &middot; 26 skills</div>
300
+ <div class="version">{{VERSION}} &middot; 28 skills</div>
301
301
  </div>
302
302
  </div>
303
303
 
@@ -328,7 +328,7 @@
328
328
 
329
329
  <!-- Skills -->
330
330
  <section>
331
- <h2>Skills (26)</h2>
331
+ <h2>Skills (28)</h2>
332
332
 
333
333
  <!-- Road (core flow) -->
334
334
  <div class="cmd-group">
@@ -336,7 +336,7 @@
336
336
  <p class="cmd-group-note">The seven steps every project walks through.</p>
337
337
  <div class="commands">
338
338
  <div class="cmd"><span class="cmd-name">/qualia-new</span><span class="cmd-desc">Set up a new project from scratch &mdash; deep questioning, parallel research, REQUIREMENTS.md, ROADMAP.md, approval gate. Use when starting any new client project.</span></div>
339
- <div class="cmd"><span class="cmd-name">/qualia-plan</span><span class="cmd-desc">Plan the current phase &mdash; spawns planner, validates with plan-checker in a revision loop (max 3), optionally runs discuss/research first. Use when ready to plan a phase.</span></div>
339
+ <div class="cmd"><span class="cmd-name">/qualia-plan</span><span class="cmd-desc">Plan the current phase &mdash; spawns planner, validates with plan-checker in a revision loop (max 2), optionally runs discuss/research first. Use when ready to plan a phase.</span></div>
340
340
  <div class="cmd"><span class="cmd-name">/qualia-build</span><span class="cmd-desc">Execute the current phase &mdash; spawns builder subagents per task with wave-based parallelization. Fresh context per task.</span></div>
341
341
  <div class="cmd"><span class="cmd-name">/qualia-verify</span><span class="cmd-desc">Goal-backward verification &mdash; checks if the phase ACTUALLY works, not just if tasks completed. Spawns verifier agent.</span></div>
342
342
  <div class="cmd"><span class="cmd-name">/qualia-polish</span><span class="cmd-desc">Design and UX pass &mdash; anti-AI-slop, genuine craft, responsive, accessible. Run after all phases are verified.</span></div>
@@ -365,7 +365,6 @@
365
365
  <div class="cmd"><span class="cmd-name">/qualia-debug</span><span class="cmd-desc">Structured debugging &mdash; symptom gathering, diagnosis confirmation, root cause analysis. Trigger on 'debug', 'find bug', 'fix error', 'something is broken'.</span></div>
366
366
  <div class="cmd"><span class="cmd-name">/qualia-review</span><span class="cmd-desc">Production audit with scored diagnostics. Runs real commands, scores findings by severity. Trigger on 'review', 'audit', 'code review', 'security check'.</span></div>
367
367
  <div class="cmd"><span class="cmd-name">/qualia-optimize</span><span class="cmd-desc">Deep optimization pass &mdash; reads .planning/ AND codebase to find performance, design, UI, backend, and frontend issues. Spawns parallel specialist agents. Supports --perf, --ui, --backend, --alignment, --fix flags.</span></div>
368
- <div class="cmd"><span class="cmd-name">/qualia-polish</span><span class="cmd-desc">Design and UX pass &mdash; anti-AI-slop, genuine craft, responsive, accessible. Run after all phases are verified.</span></div>
369
368
  <div class="cmd"><span class="cmd-name">/qualia-test</span><span class="cmd-desc">Generate or run tests for client projects. Trigger on 'write tests', 'add tests', 'test this', 'test coverage'.</span></div>
370
369
  </div>
371
370
  </div>
@@ -387,6 +386,7 @@
387
386
  <p class="cmd-group-note">Persist learnings and log work.</p>
388
387
  <div class="commands">
389
388
  <div class="cmd"><span class="cmd-name">/qualia-learn</span><span class="cmd-desc">Save a learning, pattern, fix, or client preference to the knowledge base. Persists across projects and sessions.</span></div>
389
+ <div class="cmd"><span class="cmd-name">/qualia-flush</span><span class="cmd-desc">Promote raw daily logs into curated knowledge concepts. Use weekly or when session logs contain durable lessons.</span></div>
390
390
  <div class="cmd"><span class="cmd-name">/qualia-report</span><span class="cmd-desc">Generate session report and commit to repo. Mandatory before clock-out.</span></div>
391
391
  </div>
392
392
  </div>
@@ -418,6 +418,7 @@
418
418
  <p class="cmd-group-note">Extend the framework itself.</p>
419
419
  <div class="commands">
420
420
  <div class="cmd"><span class="cmd-name">/qualia-skill-new</span><span class="cmd-desc">Author a new Qualia skill or agent. Generates the SKILL.md, registers it in the right location, and optionally ships to the framework repo.</span></div>
421
+ <div class="cmd"><span class="cmd-name">/qualia-postmortem</span><span class="cmd-desc">Analyze a verification failure and turn the lesson into a framework improvement.</span></div>
421
422
  </div>
422
423
  </div>
423
424
  </section>
@@ -430,8 +431,13 @@
430
431
  <div class="cmd"><span class="cmd-name">qualia-framework install</span><span class="cmd-desc">Install or reinstall the framework.</span></div>
431
432
  <div class="cmd"><span class="cmd-name">qualia-framework update</span><span class="cmd-desc">Update to the latest version.</span></div>
432
433
  <div class="cmd"><span class="cmd-name">qualia-framework version</span><span class="cmd-desc">Show installed version + check for updates.</span></div>
434
+ <div class="cmd"><span class="cmd-name">qualia-framework uninstall</span><span class="cmd-desc">Clean removal from ~/.claude/ while preserving user-owned settings.</span></div>
433
435
  <div class="cmd"><span class="cmd-name">qualia-framework migrate</span><span class="cmd-desc">Upgrade legacy settings.json to the current hook layout.</span></div>
434
436
  <div class="cmd"><span class="cmd-name">qualia-framework analytics</span><span class="cmd-desc">Hook telemetry, verification pass rates, gap cycles.</span></div>
437
+ <div class="cmd"><span class="cmd-name">qualia-framework set-erp-key</span><span class="cmd-desc">Save and enable the ERP API key.</span></div>
438
+ <div class="cmd"><span class="cmd-name">qualia-framework erp-ping</span><span class="cmd-desc">Verify ERP connectivity and API key health.</span></div>
439
+ <div class="cmd"><span class="cmd-name">qualia-framework doctor</span><span class="cmd-desc">Health-check installed files, hooks, settings, and knowledge layer.</span></div>
440
+ <div class="cmd"><span class="cmd-name">qualia-framework flush</span><span class="cmd-desc">Run the non-interactive knowledge flush.</span></div>
435
441
  <div class="cmd"><span class="cmd-name">qualia-framework team</span><span class="cmd-desc">List, add, or remove team members.</span></div>
436
442
  <div class="cmd"><span class="cmd-name">qualia-framework traces</span><span class="cmd-desc">View recent hook activity.</span></div>
437
443
  </div>
@@ -470,11 +476,11 @@
470
476
  <section>
471
477
  <h2>Rules</h2>
472
478
  <ul class="rules">
473
- <li><span class="rule-icon">1</span> Feature branches only &mdash; never push to main</li>
479
+ <li><span class="rule-icon">1</span> Feature branches by default &mdash; OWNER overrides must be explicit</li>
474
480
  <li><span class="rule-icon">2</span> Read before write &mdash; understand files before editing</li>
475
481
  <li><span class="rule-icon">3</span> MVP first &mdash; build what's asked, nothing extra</li>
476
482
  <li><span class="rule-icon">4</span> /qualia-report before clock-out &mdash; mandatory, enforced by ERP</li>
477
- <li><span class="rule-icon">5</span> No .env edits &mdash; ask Fawzi for secrets</li>
483
+ <li><span class="rule-icon">5</span> Secrets through approved flows &mdash; use set-erp-key or ask Fawzi</li>
478
484
  <li><span class="rule-icon">6</span> Stuck 30+ minutes? Ask Fawzi</li>
479
485
  </ul>
480
486
  </section>
@@ -536,7 +542,7 @@
536
542
  <div class="footer">
537
543
  <strong>Welcome to the future with Qualia.</strong><br>
538
544
  Qualia Solutions &mdash; Nicosia, Cyprus
539
- <span class="footer-version">qualia-framework {{VERSION}} &middot; 26 skills</span>
545
+ <span class="footer-version">qualia-framework {{VERSION}} &middot; 28 skills</span>
540
546
  </div>
541
547
 
542
548
  </body>
@@ -0,0 +1,71 @@
1
+ # Memory Layer — How This Works
2
+
3
+ You are operating inside the **Qualia Framework memory layer**. This file
4
+ describes the system you're in so you can navigate it deliberately. Read this
5
+ once at session start.
6
+
7
+ ## What's here
8
+
9
+ `~/.claude/knowledge/` is the project-spanning memory tier. It holds three
10
+ kinds of files, each with a clear purpose. Treat the structure as a contract.
11
+
12
+ ```
13
+ ~/.claude/knowledge/
14
+ ├── agents.md ← this file (system overview)
15
+ ├── index.md ← entry point — start here when answering questions
16
+ ├── daily-log/
17
+ │ └── YYYY-MM-DD.md ← raw session checkpoints (auto-written by Stop hook)
18
+ ├── concepts/ ← (future) promoted, durable patterns
19
+ ├── connections/ ← (future) cross-references between concepts
20
+ ├── learned-patterns.md ← curated patterns from /qualia-learn
21
+ ├── common-fixes.md ← recurring fix recipes
22
+ ├── supabase-patterns.md ← Supabase-specific patterns
23
+ ├── voice-agent-patterns.md
24
+ ├── deployment-map.md
25
+ └── employees.md ← team roster
26
+ ```
27
+
28
+ ## How to use it
29
+
30
+ **To answer a question that might be in memory:**
31
+ 1. Read `index.md` first. It tells you which file is likely to have what you
32
+ need. Do **not** scan every file — that defeats the index.
33
+ 2. Follow the index to one or two specific files. Read those.
34
+ 3. If the answer is not there, say so and (when the user agrees) add it via
35
+ `/qualia-learn`.
36
+
37
+ **To remember something new:**
38
+ - Use `/qualia-learn`. It writes to the right tier (pattern vs. fix vs.
39
+ client preference) and updates the index.
40
+ - Do not write to these files directly without an explicit user instruction —
41
+ the index will fall out of sync.
42
+
43
+ **Do not pretend something is in memory if it is not.** Better to say
44
+ "INSUFFICIENT EVIDENCE: searched index.md and learned-patterns.md, no entry
45
+ matches" than to hallucinate a recalled pattern. The grounding protocol
46
+ (`~/.claude/rules/grounding.md`) applies here too.
47
+
48
+ ## Tiers
49
+
50
+ The memory layer follows a Karpathy-style **raw → wiki** progression. Most of
51
+ this is still being built — v4.2.0 ships the daily-log raw tier; v4.3.0 will
52
+ add the LLM-driven flush job that promotes raw entries into concepts and
53
+ connections.
54
+
55
+ | Tier | Files | How it's written | When to read |
56
+ |------|-------|------------------|--------------|
57
+ | Raw | `daily-log/*.md` | Stop hook (auto, mechanical) | Resuming a recent session, debugging a regression |
58
+ | Curated | `learned-patterns.md`, `common-fixes.md`, `*-patterns.md` | `/qualia-learn` (manual, deliberate) | Answering "how do we usually do X?" |
59
+ | Index | `index.md` | `/qualia-learn` updates it; auto-rebuilt by `bin/knowledge.js` | Always read first |
60
+
61
+ ## Cross-cutting rules
62
+
63
+ - **Stale data is dangerous.** If a memory file has not been touched in
64
+ months and the codebase has changed, the memory may be lying. Verify
65
+ current state in the actual files before recommending anything based on
66
+ memory.
67
+ - **Project memory ≠ global memory.** Project-specific decisions belong in
68
+ that project's `.planning/` directory, not here. This directory is for
69
+ patterns that apply across multiple projects.
70
+ - **Never put secrets here.** API keys, tokens, passwords — never. The
71
+ knowledge layer is plain markdown checked into a non-encrypted directory.
@@ -0,0 +1,47 @@
1
+ # Knowledge Index
2
+
3
+ Entry point for `~/.claude/knowledge/`. When answering a question, **read this
4
+ file first**, then jump to the specific file(s) that match.
5
+
6
+ > Auto-maintained by `/qualia-learn`. Do not hand-edit unless the file is out
7
+ > of sync (e.g. after a manual move). Last manual edit: framework install.
8
+
9
+ ## What's where
10
+
11
+ | If the user asks about… | Read… |
12
+ |--------------------------|-------|
13
+ | "How do we usually X?" / patterns we've used before | `learned-patterns.md` |
14
+ | Recurring bug + fix recipes | `common-fixes.md` |
15
+ | Supabase auth, RLS, migrations, edge functions | `supabase-patterns.md` |
16
+ | Retell, ElevenLabs, voice agent flows | `voice-agent-patterns.md` |
17
+ | Where a project is deployed, env vars, domains | `deployment-map.md` |
18
+ | Who is on the team, their role, their access | `employees.md` |
19
+ | What I worked on yesterday / last week | `daily-log/YYYY-MM-DD.md` |
20
+ | Memory layer architecture itself | `agents.md` |
21
+
22
+ ## Daily log conventions
23
+
24
+ `daily-log/YYYY-MM-DD.md` is raw, mechanical, and append-only. Each line is a
25
+ single Stop-hook checkpoint with project, branch, phase, task counts, commit
26
+ count, and up to 3 touched files. **Do not promote daily-log content into the
27
+ curated tier by hand** — the upcoming `bin/knowledge-flush.js` will do that
28
+ deliberately. Hand-promoted entries break the source-of-truth invariant.
29
+
30
+ ## Adding new knowledge
31
+
32
+ Use `/qualia-learn` with the type that matches:
33
+
34
+ - `pattern` → `learned-patterns.md`
35
+ - `fix` → `common-fixes.md`
36
+ - `client preference` → the relevant project's `.planning/`, **not** this
37
+ directory
38
+ - `team member info` → `employees.md`
39
+
40
+ If a new top-level file is needed (e.g. a new technology stack), update this
41
+ index in the same commit.
42
+
43
+ ## Empty / new-install state
44
+
45
+ If a tier file does not exist yet, that means we have not learned anything in
46
+ that domain yet. Don't pretend we have. Either say "no entries" or, if the
47
+ user is asking you to learn it now, run `/qualia-learn`.